Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/media/media_stream_video_capturer_source.h" | 5 #include "content/renderer/media/media_stream_video_capturer_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "content/renderer/media/video_capture_impl_manager.h" | 9 #include "content/renderer/media/video_capture_impl_manager.h" |
| 10 #include "content/renderer/render_thread_impl.h" | 10 #include "content/renderer/render_thread_impl.h" |
| 11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 struct SourceVideoFormat { | 15 struct SourceVideoFormat { |
| 16 int width; | 16 int width; |
| 17 int height; | 17 int height; |
| 18 int frame_rate; | 18 int frame_rate; |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 // List of formats used if the source doesn't support capability enumeration. | 21 // List of formats used if the source doesn't support capability enumeration. |
| 22 const SourceVideoFormat kVideoFormats[] = { | 22 const SourceVideoFormat kVideoFormats[] = { |
| 23 {1920, 1080, 30}, | 23 {1920, 1080, 30}, |
|
perkj_chrome
2014/03/14 14:29:33
I think the previous indentation was correct excep
mcasas
2014/03/16 10:18:02
Reformatted according to clang-format chromium.
| |
| 24 {1280, 720, 30}, | 24 {1280, 720, 30}, |
| 25 {960, 720, 30}, | 25 {960, 720, 30}, |
| 26 {640, 480, 30}, | 26 {640, 480, 30}, |
| 27 {640, 360, 30}, | 27 {640, 360, 30}, |
| 28 {320, 240, 30}, | 28 {320, 240, 30}, |
| 29 {320, 180, 30} | 29 {320, 180, 30} |
| 30 }; | 30 }; |
|
perkj_chrome
2014/03/14 14:29:33
}; should probably be on the previous line.
mcasas
2014/03/16 10:18:02
See above.
| |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 VideoCapturerDelegate::VideoCapturerDelegate( | 36 VideoCapturerDelegate::VideoCapturerDelegate( |
| 37 const StreamDeviceInfo& device_info) | 37 const StreamDeviceInfo& device_info) |
| 38 : session_id_(device_info.session_id), | 38 : session_id_(device_info.session_id), |
| 39 capture_engine_( | 39 capture_engine_( |
| 40 RenderThreadImpl::current()->video_capture_impl_manager() | 40 RenderThreadImpl::current()->video_capture_impl_manager() |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 67 max_requested_height : MediaStreamVideoSource::kDefaultHeight; | 67 max_requested_height : MediaStreamVideoSource::kDefaultHeight; |
| 68 formats.push_back( | 68 formats.push_back( |
| 69 media::VideoCaptureFormat( | 69 media::VideoCaptureFormat( |
| 70 gfx::Size(width, height), | 70 gfx::Size(width, height), |
| 71 MediaStreamVideoSource::kDefaultFrameRate, | 71 MediaStreamVideoSource::kDefaultFrameRate, |
| 72 media::PIXEL_FORMAT_I420)); | 72 media::PIXEL_FORMAT_I420)); |
| 73 callback.Run(formats); | 73 callback.Run(formats); |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // This delegate implementation doesn't support capability enumeration. | 77 DCHECK(source_formats_callback_.is_null()); |
| 78 // We need to guess what it supports. | 78 source_formats_callback_ = callback; |
| 79 media::VideoCaptureFormats formats; | 79 capture_engine_->GetDeviceFormatsInUse(base::Bind( |
| 80 for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { | 80 &VideoCapturerDelegate::OnDeviceFormatsInUseReceived, this)); |
| 81 formats.push_back( | |
| 82 media::VideoCaptureFormat( | |
| 83 gfx::Size(kVideoFormats[i].width, | |
| 84 kVideoFormats[i].height), | |
| 85 kVideoFormats[i].frame_rate, | |
| 86 media::PIXEL_FORMAT_I420)); | |
| 87 } | |
| 88 callback.Run(formats); | |
| 89 } | 81 } |
| 90 | 82 |
| 91 void VideoCapturerDelegate::StartDeliver( | 83 void VideoCapturerDelegate::StartDeliver( |
| 92 const media::VideoCaptureParams& params, | 84 const media::VideoCaptureParams& params, |
| 93 const NewFrameCallback& new_frame_callback, | 85 const NewFrameCallback& new_frame_callback, |
| 94 const StartedCallback& started_callback) { | 86 const StartedCallback& started_callback) { |
| 95 DCHECK(params.requested_format.IsValid()); | 87 DCHECK(params.requested_format.IsValid()); |
| 96 message_loop_proxy_ = base::MessageLoopProxy::current(); | 88 message_loop_proxy_ = base::MessageLoopProxy::current(); |
| 97 new_frame_callback_ = new_frame_callback; | 89 new_frame_callback_ = new_frame_callback; |
| 98 started_callback_ = started_callback; | 90 started_callback_ = started_callback; |
| 99 got_first_frame_ = false; | 91 got_first_frame_ = false; |
| 100 | 92 |
| 101 // Increase the reference count to ensure the object is not deleted until | 93 // Increase the reference count to ensure the object is not deleted until |
| 102 // it is unregistered in VideoCapturerDelegate::OnRemoved. | 94 // it is unregistered in VideoCapturerDelegate::OnRemoved. |
| 103 AddRef(); | 95 AddRef(); |
| 104 capture_engine_->StartCapture(this, params); | 96 capture_engine_->StartCapture(this, params); |
| 105 } | 97 } |
| 106 | 98 |
| 107 void VideoCapturerDelegate::StopDeliver() { | 99 void VideoCapturerDelegate::StopDeliver() { |
| 108 // Immediately make sure we don't provide more frames. | 100 // Immediately make sure we don't provide more frames. |
| 109 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; | 101 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; |
| 110 DCHECK(message_loop_proxy_ == base::MessageLoopProxy::current()); | 102 DCHECK(message_loop_proxy_ == base::MessageLoopProxy::current()); |
| 111 capture_engine_->StopCapture(this); | 103 capture_engine_->StopCapture(this); |
| 112 new_frame_callback_.Reset(); | 104 new_frame_callback_.Reset(); |
| 113 started_callback_.Reset(); | 105 started_callback_.Reset(); |
| 106 source_formats_callback_.Reset(); | |
| 114 } | 107 } |
| 115 | 108 |
| 116 void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { | 109 void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { |
| 117 DVLOG(3) << "VideoCapturerDelegate::OnStarted"; | 110 DVLOG(3) << "VideoCapturerDelegate::OnStarted"; |
| 118 } | 111 } |
| 119 | 112 |
| 120 void VideoCapturerDelegate::OnStopped(media::VideoCapture* capture) { | 113 void VideoCapturerDelegate::OnStopped(media::VideoCapture* capture) { |
| 121 } | 114 } |
| 122 | 115 |
| 123 void VideoCapturerDelegate::OnPaused(media::VideoCapture* capture) { | 116 void VideoCapturerDelegate::OnPaused(media::VideoCapture* capture) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 new_frame_callback_.Run(frame); | 158 new_frame_callback_.Run(frame); |
| 166 } | 159 } |
| 167 } | 160 } |
| 168 | 161 |
| 169 void VideoCapturerDelegate::OnErrorOnCaptureThread( | 162 void VideoCapturerDelegate::OnErrorOnCaptureThread( |
| 170 media::VideoCapture* capture) { | 163 media::VideoCapture* capture) { |
| 171 if (!started_callback_.is_null()) | 164 if (!started_callback_.is_null()) |
| 172 started_callback_.Run(false); | 165 started_callback_.Run(false); |
| 173 } | 166 } |
| 174 | 167 |
| 168 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( | |
| 169 const media::VideoCaptureFormats& formats_in_use) { | |
| 170 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); | |
|
perkj_chrome
2014/03/14 14:29:33
if (source_formats_callback_.is_null())
return;
mcasas
2014/03/16 10:18:02
Done.
| |
| 171 if (!formats_in_use.empty()) { | |
| 172 if (!source_formats_callback_.is_null()) { | |
| 173 source_formats_callback_.Run(formats_in_use); | |
| 174 source_formats_callback_.Reset(); | |
| 175 } | |
| 176 } else { | |
| 177 DCHECK(!source_formats_callback_.is_null()); | |
|
perkj_chrome
2014/03/14 14:29:33
remove this DCHECK
mcasas
2014/03/16 10:18:02
Done.
| |
| 178 // If there are no formats in use, try to retrieve the whole list of them. | |
| 179 capture_engine_->GetDeviceSupportedFormats(base::Bind( | |
| 180 &VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated, this)); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 void VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated( | |
| 185 const media::VideoCaptureFormats& formats) { | |
| 186 DVLOG(3) << "OnDeviceSupportedFormatsEnumerated: " << formats.size() | |
| 187 << " received"; | |
|
perkj_chrome
2014/03/14 14:29:33
use early exist
if (source_formats_callback_.is_nu
mcasas
2014/03/16 10:18:02
Done.
| |
| 188 if (formats.size()) { | |
| 189 if (!source_formats_callback_.is_null()) | |
| 190 source_formats_callback_.Run(formats); | |
| 191 } else { | |
| 192 // The capture device doesn't seem to support capability enumeration, | |
| 193 // compose a fallback list of capabilities. | |
| 194 media::VideoCaptureFormats default_formats; | |
| 195 for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { | |
| 196 default_formats.push_back(media::VideoCaptureFormat( | |
| 197 gfx::Size(kVideoFormats[i].width, kVideoFormats[i].height), | |
| 198 kVideoFormats[i].frame_rate, | |
| 199 media::PIXEL_FORMAT_I420)); | |
| 200 } | |
| 201 if (!source_formats_callback_.is_null()) | |
| 202 source_formats_callback_.Run(default_formats); | |
| 203 } | |
| 204 source_formats_callback_.Reset(); | |
| 205 } | |
| 206 | |
| 175 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( | 207 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( |
| 176 const StreamDeviceInfo& device_info, | 208 const StreamDeviceInfo& device_info, |
| 177 const SourceStoppedCallback& stop_callback, | 209 const SourceStoppedCallback& stop_callback, |
| 178 const scoped_refptr<VideoCapturerDelegate>& delegate, | 210 const scoped_refptr<VideoCapturerDelegate>& delegate, |
| 179 MediaStreamDependencyFactory* factory) | 211 MediaStreamDependencyFactory* factory) |
| 180 : MediaStreamVideoSource(factory), | 212 : MediaStreamVideoSource(factory), |
| 181 delegate_(delegate) { | 213 delegate_(delegate) { |
| 182 SetDeviceInfo(device_info); | 214 SetDeviceInfo(device_info); |
| 183 SetStopCallback(stop_callback); | 215 SetStopCallback(stop_callback); |
| 184 } | 216 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 204 base::Unretained(this)), | 236 base::Unretained(this)), |
| 205 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, | 237 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, |
| 206 base::Unretained(this))); | 238 base::Unretained(this))); |
| 207 } | 239 } |
| 208 | 240 |
| 209 void MediaStreamVideoCapturerSource::StopSourceImpl() { | 241 void MediaStreamVideoCapturerSource::StopSourceImpl() { |
| 210 delegate_->StopDeliver(); | 242 delegate_->StopDeliver(); |
| 211 } | 243 } |
| 212 | 244 |
| 213 } // namespace content | 245 } // namespace content |
| OLD | NEW |