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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // Compares two VideoCaptureFormat by checking smallest frame_size area, then | 50 // Compares two VideoCaptureFormat by checking smallest frame_size area, then |
51 // by _largest_ frame_rate. Used to order a VideoCaptureFormats vector so that | 51 // by _largest_ frame_rate. Used to order a VideoCaptureFormats vector so that |
52 // the first entry for a given resolution has the largest frame rate, as needed | 52 // the first entry for a given resolution has the largest frame rate, as needed |
53 // by the ConsolidateCaptureFormats() method. | 53 // by the ConsolidateCaptureFormats() method. |
54 bool IsCaptureFormatSmaller(const media::VideoCaptureFormat& format1, | 54 bool IsCaptureFormatSmaller(const media::VideoCaptureFormat& format1, |
55 const media::VideoCaptureFormat& format2) { | 55 const media::VideoCaptureFormat& format2) { |
56 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); | 56 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); |
57 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); | 57 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); |
58 if (format1.frame_size.GetCheckedArea().ValueOrDefault(0) == | 58 if (format1.frame_size.GetCheckedArea().ValueOrDefault(0) == |
59 format2.frame_size.GetCheckedArea().ValueOrDefault(0)) { | 59 format2.frame_size.GetCheckedArea().ValueOrDefault(0)) { |
60 return format1.frame_rate > format2.frame_rate; | 60 return format1.frame_rate > format2.frame_rate || |
| 61 // Prefer Y8 and Y16 capture format for the same frame rate. |
| 62 (format1.frame_rate == format2.frame_rate && |
| 63 (format2.pixel_format != media::PIXEL_FORMAT_Y8 && |
| 64 format2.pixel_format != media::PIXEL_FORMAT_Y16)); |
61 } | 65 } |
62 return format1.frame_size.GetCheckedArea().ValueOrDefault(0) < | 66 return format1.frame_size.GetCheckedArea().ValueOrDefault(0) < |
63 format2.frame_size.GetCheckedArea().ValueOrDefault(0); | 67 format2.frame_size.GetCheckedArea().ValueOrDefault(0); |
64 } | 68 } |
65 | 69 |
66 bool IsCaptureFormatSizeEqual(const media::VideoCaptureFormat& format1, | 70 bool IsCaptureFormatSizeEqual(const media::VideoCaptureFormat& format1, |
67 const media::VideoCaptureFormat& format2) { | 71 const media::VideoCaptureFormat& format2) { |
68 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); | 72 DCHECK(format1.frame_size.GetCheckedArea().IsValid()); |
69 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); | 73 DCHECK(format2.frame_size.GetCheckedArea().IsValid()); |
70 return format1.frame_size.GetCheckedArea().ValueOrDefault(0) == | 74 return format1.frame_size.GetCheckedArea().ValueOrDefault(0) == |
71 format2.frame_size.GetCheckedArea().ValueOrDefault(0); | 75 format2.frame_size.GetCheckedArea().ValueOrDefault(0); |
72 } | 76 } |
73 | 77 |
74 // This function receives a list of capture formats, removes duplicated | 78 // This function receives a list of capture formats, removes duplicated |
75 // resolutions while keeping the highest frame rate for each, and forcing I420 | 79 // resolutions while keeping the highest frame rate for each, and forcing I420 |
76 // pixel format. | 80 // pixel format. |
77 void ConsolidateCaptureFormats(media::VideoCaptureFormats* formats) { | 81 void ConsolidateCaptureFormats(media::VideoCaptureFormats* formats) { |
78 if (formats->empty()) | 82 if (formats->empty()) |
79 return; | 83 return; |
80 std::sort(formats->begin(), formats->end(), IsCaptureFormatSmaller); | 84 std::sort(formats->begin(), formats->end(), IsCaptureFormatSmaller); |
81 // Due to the ordering imposed, the largest frame_rate is kept while removing | 85 // Due to the ordering imposed, the largest frame_rate is kept while removing |
82 // duplicated resolutions. | 86 // duplicated resolutions. |
83 media::VideoCaptureFormats::iterator last = | 87 media::VideoCaptureFormats::iterator last = |
84 std::unique(formats->begin(), formats->end(), IsCaptureFormatSizeEqual); | 88 std::unique(formats->begin(), formats->end(), IsCaptureFormatSizeEqual); |
85 formats->erase(last, formats->end()); | 89 formats->erase(last, formats->end()); |
86 // Mark all formats as I420, since this is what the renderer side will get | 90 // Mark all formats as I420, since this is what the renderer side will get |
87 // anyhow: the actual pixel format is decided at the device level. | 91 // anyhow: the actual pixel format is decided at the device level. |
88 for (media::VideoCaptureFormats::iterator it = formats->begin(); | 92 for (media::VideoCaptureFormats::iterator it = formats->begin(); |
89 it != formats->end(); ++it) { | 93 it != formats->end(); ++it) { |
90 it->pixel_format = media::PIXEL_FORMAT_I420; | 94 // TODO(astojilj) Force I420 for all except Y8 and Y16 in all |
| 95 // video_capture_device_factory_->GetDeviceSupportedFormats instead of |
| 96 // doing it here? |
| 97 if (it->pixel_format != media::PIXEL_FORMAT_Y8 && |
| 98 it->pixel_format != media::PIXEL_FORMAT_Y16) |
| 99 it->pixel_format = media::PIXEL_FORMAT_I420; |
91 } | 100 } |
92 } | 101 } |
93 | 102 |
94 // The maximum number of buffers in the capture pipeline. See | 103 // The maximum number of buffers in the capture pipeline. See |
95 // VideoCaptureController ctor comments for more details. | 104 // VideoCaptureController ctor comments for more details. |
96 const int kMaxNumberOfBuffers = 3; | 105 const int kMaxNumberOfBuffers = 3; |
97 // TODO(miu): The value for tab capture should be determined programmatically. | 106 // TODO(miu): The value for tab capture should be determined programmatically. |
98 // http://crbug.com/460318 | 107 // http://crbug.com/460318 |
99 const int kMaxNumberOfBuffersForTabCapture = 10; | 108 const int kMaxNumberOfBuffersForTabCapture = 10; |
100 | 109 |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 if (!device_in_queue) { | 1135 if (!device_in_queue) { |
1127 // Session ID is only valid for Screen capture. So we can fake it to | 1136 // Session ID is only valid for Screen capture. So we can fake it to |
1128 // resume video capture devices here. | 1137 // resume video capture devices here. |
1129 QueueStartDevice(kFakeSessionId, entry, entry->parameters); | 1138 QueueStartDevice(kFakeSessionId, entry, entry->parameters); |
1130 } | 1139 } |
1131 } | 1140 } |
1132 } | 1141 } |
1133 #endif // defined(OS_ANDROID) | 1142 #endif // defined(OS_ANDROID) |
1134 | 1143 |
1135 } // namespace content | 1144 } // namespace content |
OLD | NEW |