OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/media/video_capture_manager.h" | 5 #include "content/browser/renderer_host/media/video_capture_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // Compares two VideoCaptureFormat by checking smallest frame_size area, then | 53 // Compares two VideoCaptureFormat by checking smallest frame_size area, then |
54 // by _largest_ frame_rate. Used to order a VideoCaptureFormats vector so that | 54 // by _largest_ frame_rate. Used to order a VideoCaptureFormats vector so that |
55 // the first entry for a given resolution has the largest frame rate, as needed | 55 // the first entry for a given resolution has the largest frame rate, as needed |
56 // by the ConsolidateCaptureFormats() method. | 56 // by the ConsolidateCaptureFormats() method. |
57 bool IsCaptureFormatSmaller(const media::VideoCaptureFormat& format1, | 57 bool IsCaptureFormatSmaller(const media::VideoCaptureFormat& format1, |
58 const media::VideoCaptureFormat& format2) { | 58 const media::VideoCaptureFormat& format2) { |
59 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); | 59 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); |
60 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); | 60 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); |
61 if (format1.frame_size.GetCheckedArea().ValueOrDefault(0) == | 61 if (format1.frame_size.GetCheckedArea().ValueOrDefault(0) == |
62 format2.frame_size.GetCheckedArea().ValueOrDefault(0)) { | 62 format2.frame_size.GetCheckedArea().ValueOrDefault(0)) { |
63 return format1.frame_rate > format2.frame_rate; | 63 return format1.frame_rate > format2.frame_rate || |
| 64 // Prefer Y16 capture format for the same frame rate. |
| 65 // This is workaround for e.g. Realsense R200 IR stream. |
| 66 (format1.frame_rate == format2.frame_rate && |
| 67 (format2.pixel_format != media::PIXEL_FORMAT_Y16)); |
64 } | 68 } |
65 return format1.frame_size.GetCheckedArea().ValueOrDefault(0) < | 69 return format1.frame_size.GetCheckedArea().ValueOrDefault(0) < |
66 format2.frame_size.GetCheckedArea().ValueOrDefault(0); | 70 format2.frame_size.GetCheckedArea().ValueOrDefault(0); |
67 } | 71 } |
68 | 72 |
69 bool IsCaptureFormatSizeEqual(const media::VideoCaptureFormat& format1, | 73 bool IsCaptureFormatSizeEqual(const media::VideoCaptureFormat& format1, |
70 const media::VideoCaptureFormat& format2) { | 74 const media::VideoCaptureFormat& format2) { |
71 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); | 75 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); |
72 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); | 76 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); |
73 return format1.frame_size.GetCheckedArea().ValueOrDefault(0) == | 77 return format1.frame_size.GetCheckedArea().ValueOrDefault(0) == |
74 format2.frame_size.GetCheckedArea().ValueOrDefault(0); | 78 format2.frame_size.GetCheckedArea().ValueOrDefault(0); |
75 } | 79 } |
76 | 80 |
77 // This function receives a list of capture formats, removes duplicated | 81 // This function receives a list of capture formats, removes duplicated |
78 // resolutions while keeping the highest frame rate for each, and forcing I420 | 82 // resolutions while keeping the highest frame rate for each, and forcing I420 |
79 // pixel format. | 83 // pixel format. |
80 void ConsolidateCaptureFormats(media::VideoCaptureFormats* formats) { | 84 void ConsolidateCaptureFormats(media::VideoCaptureFormats* formats) { |
81 if (formats->empty()) | 85 if (formats->empty()) |
82 return; | 86 return; |
83 std::sort(formats->begin(), formats->end(), IsCaptureFormatSmaller); | 87 std::sort(formats->begin(), formats->end(), IsCaptureFormatSmaller); |
84 // Due to the ordering imposed, the largest frame_rate is kept while removing | 88 // Due to the ordering imposed, the largest frame_rate is kept while removing |
85 // duplicated resolutions. | 89 // duplicated resolutions. |
86 media::VideoCaptureFormats::iterator last = | 90 media::VideoCaptureFormats::iterator last = |
87 std::unique(formats->begin(), formats->end(), IsCaptureFormatSizeEqual); | 91 std::unique(formats->begin(), formats->end(), IsCaptureFormatSizeEqual); |
88 formats->erase(last, formats->end()); | 92 formats->erase(last, formats->end()); |
89 // Mark all formats as I420, since this is what the renderer side will get | 93 // Mark all formats as I420, since this is what the renderer side will get |
90 // anyhow: the actual pixel format is decided at the device level. | 94 // anyhow: the actual pixel format is decided at the device level. |
| 95 // Don't do this for Y16 format as it is handled separatelly. |
91 for (media::VideoCaptureFormats::iterator it = formats->begin(); | 96 for (media::VideoCaptureFormats::iterator it = formats->begin(); |
92 it != formats->end(); ++it) { | 97 it != formats->end(); ++it) { |
93 it->pixel_format = media::PIXEL_FORMAT_I420; | 98 if (it->pixel_format != media::PIXEL_FORMAT_Y16) |
| 99 it->pixel_format = media::PIXEL_FORMAT_I420; |
94 } | 100 } |
95 } | 101 } |
96 | 102 |
97 // The maximum number of buffers in the capture pipeline. See | 103 // The maximum number of buffers in the capture pipeline. See |
98 // VideoCaptureController ctor comments for more details. | 104 // VideoCaptureController ctor comments for more details. |
99 const int kMaxNumberOfBuffers = 3; | 105 const int kMaxNumberOfBuffers = 3; |
100 // TODO(miu): The value for tab capture should be determined programmatically. | 106 // TODO(miu): The value for tab capture should be determined programmatically. |
101 // http://crbug.com/460318 | 107 // http://crbug.com/460318 |
102 const int kMaxNumberOfBuffersForTabCapture = 10; | 108 const int kMaxNumberOfBuffersForTabCapture = 10; |
103 | 109 |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 if (!device_in_queue) { | 1288 if (!device_in_queue) { |
1283 // Session ID is only valid for Screen capture. So we can fake it to | 1289 // Session ID is only valid for Screen capture. So we can fake it to |
1284 // resume video capture devices here. | 1290 // resume video capture devices here. |
1285 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); | 1291 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); |
1286 } | 1292 } |
1287 } | 1293 } |
1288 } | 1294 } |
1289 #endif // defined(OS_ANDROID) | 1295 #endif // defined(OS_ANDROID) |
1290 | 1296 |
1291 } // namespace content | 1297 } // namespace content |
OLD | NEW |