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" |
(...skipping 23 matching lines...) Expand all Loading... | |
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() |
41 ->UseDevice(device_info.session_id)), | 41 ->UseDevice(device_info.session_id)), |
42 is_screen_cast_(device_info.device.type == MEDIA_TAB_VIDEO_CAPTURE || | 42 is_screen_cast_(device_info.device.type == MEDIA_TAB_VIDEO_CAPTURE || |
43 device_info.device.type == MEDIA_DESKTOP_VIDEO_CAPTURE), | 43 device_info.device.type == MEDIA_DESKTOP_VIDEO_CAPTURE), |
44 got_first_frame_(false) { | 44 got_first_frame_(false), |
45 source_formats_callback_() { | |
perkj_chrome
2014/03/12 19:55:48
no need to initialize this here.
mcasas
2014/03/13 08:04:56
Done.
| |
45 DVLOG(3) << "VideoCapturerDelegate::ctor"; | 46 DVLOG(3) << "VideoCapturerDelegate::ctor"; |
46 DCHECK(capture_engine_); | 47 DCHECK(capture_engine_); |
47 } | 48 } |
48 | 49 |
49 VideoCapturerDelegate::~VideoCapturerDelegate() { | 50 VideoCapturerDelegate::~VideoCapturerDelegate() { |
50 DVLOG(3) << "VideoCapturerDelegate::dtor"; | 51 DVLOG(3) << "VideoCapturerDelegate::dtor"; |
51 DCHECK(new_frame_callback_.is_null()); | 52 DCHECK(new_frame_callback_.is_null()); |
52 } | 53 } |
53 | 54 |
54 void VideoCapturerDelegate::GetCurrentSupportedFormats( | 55 void VideoCapturerDelegate::GetCurrentSupportedFormats( |
(...skipping 12 matching lines...) Expand all Loading... | |
67 max_requested_height : MediaStreamVideoSource::kDefaultHeight; | 68 max_requested_height : MediaStreamVideoSource::kDefaultHeight; |
68 formats.push_back( | 69 formats.push_back( |
69 media::VideoCaptureFormat( | 70 media::VideoCaptureFormat( |
70 gfx::Size(width, height), | 71 gfx::Size(width, height), |
71 MediaStreamVideoSource::kDefaultFrameRate, | 72 MediaStreamVideoSource::kDefaultFrameRate, |
72 media::PIXEL_FORMAT_I420)); | 73 media::PIXEL_FORMAT_I420)); |
73 callback.Run(formats); | 74 callback.Run(formats); |
74 return; | 75 return; |
75 } | 76 } |
76 | 77 |
77 // This delegate implementation doesn't support capability enumeration. | 78 DCHECK(source_formats_callback_.is_null()); |
78 // We need to guess what it supports. | 79 source_formats_callback_ = callback; |
79 media::VideoCaptureFormats formats; | 80 RenderThreadImpl::current()->video_capture_impl_manager() |
perkj_chrome
2014/03/12 19:55:48
No... Do
capture_engine_->GetDeviceFormatInUse(bas
mcasas
2014/03/13 08:04:56
Done.
| |
80 for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { | 81 ->UseDevice(session_id_)->GetDeviceFormatsInUse( |
81 formats.push_back( | 82 base::Bind(&VideoCapturerDelegate::OnDeviceFormatsInUseReceived, |
82 media::VideoCaptureFormat( | 83 base::Unretained(this))); |
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 } | 84 } |
90 | 85 |
91 void VideoCapturerDelegate::StartDeliver( | 86 void VideoCapturerDelegate::StartDeliver( |
92 const media::VideoCaptureParams& params, | 87 const media::VideoCaptureParams& params, |
93 const NewFrameCallback& new_frame_callback, | 88 const NewFrameCallback& new_frame_callback, |
94 const StartedCallback& started_callback) { | 89 const StartedCallback& started_callback) { |
95 DCHECK(params.requested_format.IsValid()); | 90 DCHECK(params.requested_format.IsValid()); |
96 message_loop_proxy_ = base::MessageLoopProxy::current(); | 91 message_loop_proxy_ = base::MessageLoopProxy::current(); |
97 new_frame_callback_ = new_frame_callback; | 92 new_frame_callback_ = new_frame_callback; |
98 started_callback_ = started_callback; | 93 started_callback_ = started_callback; |
99 got_first_frame_ = false; | 94 got_first_frame_ = false; |
100 | 95 |
101 // Increase the reference count to ensure the object is not deleted until | 96 // Increase the reference count to ensure the object is not deleted until |
102 // it is unregistered in VideoCapturerDelegate::OnRemoved. | 97 // it is unregistered in VideoCapturerDelegate::OnRemoved. |
103 AddRef(); | 98 AddRef(); |
104 capture_engine_->StartCapture(this, params); | 99 capture_engine_->StartCapture(this, params); |
105 } | 100 } |
106 | 101 |
107 void VideoCapturerDelegate::StopDeliver() { | 102 void VideoCapturerDelegate::StopDeliver() { |
108 // Immediately make sure we don't provide more frames. | 103 // Immediately make sure we don't provide more frames. |
109 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; | 104 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; |
110 DCHECK(message_loop_proxy_ == base::MessageLoopProxy::current()); | 105 DCHECK(message_loop_proxy_ == base::MessageLoopProxy::current()); |
111 capture_engine_->StopCapture(this); | 106 capture_engine_->StopCapture(this); |
112 new_frame_callback_.Reset(); | 107 new_frame_callback_.Reset(); |
113 started_callback_.Reset(); | 108 started_callback_.Reset(); |
perkj_chrome
2014/03/12 19:55:48
Do source_formats_callback_.Reset() here to make s
mcasas
2014/03/13 08:04:56
Done.
| |
114 } | 109 } |
115 | 110 |
111 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( | |
112 const media::VideoCaptureFormats& formats_in_use) { | |
113 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); | |
114 if(!formats_in_use.empty()) { | |
115 source_formats_callback_.Run(formats_in_use); | |
perkj_chrome
2014/03/12 19:55:48
check for isnull.
mcasas
2014/03/13 08:04:56
Done.
| |
116 }else { | |
117 // If there are no formats in use, try to retrieve the whole list of them. | |
118 RenderThreadImpl::current()->video_capture_impl_manager() | |
perkj_chrome
2014/03/12 19:55:48
Same as above.
mcasas
2014/03/13 08:04:56
Done.
| |
119 ->UseDevice(session_id_)->GetDeviceSupportedFormats(base::Bind( | |
120 &VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated, | |
121 base::Unretained(this))); | |
122 } | |
123 } | |
124 | |
125 void VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated( | |
126 const media::VideoCaptureFormats& formats) { | |
127 DVLOG(3) << "OnDeviceSupportedFormatsEnumerated: " << formats.size() | |
128 << " received"; | |
129 if(formats.size()) { | |
130 source_formats_callback_.Run(formats); | |
perkj_chrome
2014/03/12 19:55:48
check for isnull.
mcasas
2014/03/13 08:04:56
Done.
| |
131 } else { | |
132 // The capture device doesn't seem to support capability enumeration, | |
133 // compose a fallback list of capabilities. | |
134 media::VideoCaptureFormats default_formats; | |
135 for (size_t i = 0; i < arraysize(kVideoFormats); ++i) { | |
136 default_formats.push_back(media::VideoCaptureFormat( | |
137 gfx::Size(kVideoFormats[i].width, kVideoFormats[i].height), | |
138 kVideoFormats[i].frame_rate, | |
139 media::PIXEL_FORMAT_I420)); | |
140 } | |
141 source_formats_callback_.Run(default_formats); | |
142 } | |
143 } | |
144 | |
116 void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { | 145 void VideoCapturerDelegate::OnStarted(media::VideoCapture* capture) { |
117 DVLOG(3) << "VideoCapturerDelegate::OnStarted"; | 146 DVLOG(3) << "VideoCapturerDelegate::OnStarted"; |
118 } | 147 } |
119 | 148 |
120 void VideoCapturerDelegate::OnStopped(media::VideoCapture* capture) { | 149 void VideoCapturerDelegate::OnStopped(media::VideoCapture* capture) { |
121 } | 150 } |
122 | 151 |
123 void VideoCapturerDelegate::OnPaused(media::VideoCapture* capture) { | 152 void VideoCapturerDelegate::OnPaused(media::VideoCapture* capture) { |
124 } | 153 } |
125 | 154 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 base::Unretained(this)), | 233 base::Unretained(this)), |
205 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, | 234 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, |
206 base::Unretained(this))); | 235 base::Unretained(this))); |
207 } | 236 } |
208 | 237 |
209 void MediaStreamVideoCapturerSource::StopSourceImpl() { | 238 void MediaStreamVideoCapturerSource::StopSourceImpl() { |
210 delegate_->StopDeliver(); | 239 delegate_->StopDeliver(); |
211 } | 240 } |
212 | 241 |
213 } // namespace content | 242 } // namespace content |
OLD | NEW |