Index: content/renderer/media/media_stream_video_capturer_source.cc |
diff --git a/content/renderer/media/media_stream_video_capturer_source.cc b/content/renderer/media/media_stream_video_capturer_source.cc |
index 722844bdbdf806429d3903c34cbcf552a7296ac5..1de6497ef8a9e1f65638765be804fe79fb843b9e 100644 |
--- a/content/renderer/media/media_stream_video_capturer_source.cc |
+++ b/content/renderer/media/media_stream_video_capturer_source.cc |
@@ -19,15 +19,13 @@ struct SourceVideoFormat { |
}; |
// List of formats used if the source doesn't support capability enumeration. |
-const SourceVideoFormat kVideoFormats[] = { |
- {1920, 1080, 30}, |
- {1280, 720, 30}, |
- {960, 720, 30}, |
- {640, 480, 30}, |
- {640, 360, 30}, |
- {320, 240, 30}, |
- {320, 180, 30} |
-}; |
+const SourceVideoFormat kVideoFormats[] = {{1920, 1080, 30}, |
+ {1280, 720, 30}, |
+ {960, 720, 30}, |
+ {640, 480, 30}, |
+ {640, 360, 30}, |
+ {320, 240, 30}, |
+ {320, 180, 30}}; |
} // namespace |
@@ -74,18 +72,10 @@ void VideoCapturerDelegate::GetCurrentSupportedFormats( |
return; |
} |
- // This delegate implementation doesn't support capability enumeration. |
- // We need to guess what it supports. |
- media::VideoCaptureFormats formats; |
- for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { |
- formats.push_back( |
- media::VideoCaptureFormat( |
- gfx::Size(kVideoFormats[i].width, |
- kVideoFormats[i].height), |
- kVideoFormats[i].frame_rate, |
- media::PIXEL_FORMAT_I420)); |
- } |
- callback.Run(formats); |
+ DCHECK(source_formats_callback_.is_null()); |
+ source_formats_callback_ = callback; |
+ capture_engine_->GetDeviceFormatsInUse(base::Bind( |
+ &VideoCapturerDelegate::OnDeviceFormatsInUseReceived, this)); |
} |
void VideoCapturerDelegate::StartDeliver( |
@@ -111,6 +101,7 @@ void VideoCapturerDelegate::StopDeliver() { |
capture_engine_->StopCapture(this); |
new_frame_callback_.Reset(); |
started_callback_.Reset(); |
+ source_formats_callback_.Reset(); |
} |
void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { |
@@ -172,6 +163,44 @@ void VideoCapturerDelegate::OnErrorOnCaptureThread( |
started_callback_.Run(false); |
} |
+void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( |
+ const media::VideoCaptureFormats& formats_in_use) { |
+ DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); |
+ if (!source_formats_callback_.is_null()) |
+ return; |
+ if (!formats_in_use.empty()) { |
+ source_formats_callback_.Run(formats_in_use); |
+ source_formats_callback_.Reset(); |
+ } else { |
+ // If there are no formats in use, try to retrieve the whole list of them. |
perkj_chrome
2014/03/17 11:05:40
nit: of supported formats
mcasas
2014/03/17 15:12:59
Done.
|
+ capture_engine_->GetDeviceSupportedFormats(base::Bind( |
+ &VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated, this)); |
+ } |
+} |
+ |
+void VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated( |
+ const media::VideoCaptureFormats& formats) { |
+ DVLOG(3) << "OnDeviceSupportedFormatsEnumerated: " << formats.size() |
+ << " received"; |
+ if (!source_formats_callback_.is_null()) |
tommi (sloooow) - chröme
2014/03/17 11:56:22
if we get here and source_formats_callback_ is nul
mcasas
2014/03/17 15:12:59
Done.
|
+ return; |
+ if (formats.size()) { |
+ source_formats_callback_.Run(formats); |
+ } else { |
+ // The capture device doesn't seem to support capability enumeration, |
+ // compose a fallback list of capabilities. |
+ media::VideoCaptureFormats default_formats; |
+ for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { |
+ default_formats.push_back(media::VideoCaptureFormat( |
+ gfx::Size(kVideoFormats[i].width, kVideoFormats[i].height), |
+ kVideoFormats[i].frame_rate, |
+ media::PIXEL_FORMAT_I420)); |
+ } |
+ source_formats_callback_.Run(default_formats); |
+ } |
+ source_formats_callback_.Reset(); |
+} |
+ |
MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( |
const StreamDeviceInfo& device_info, |
const SourceStoppedCallback& stop_callback, |