OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_device_impl.h" | 5 #include "content/browser/renderer_host/media/video_capture_device_impl.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // to because no output buffer was available. | 105 // to because no output buffer was available. |
106 TRACE_EVENT_INSTANT1("mirroring", "NearlyEncodeLimited", | 106 TRACE_EVENT_INSTANT1("mirroring", "NearlyEncodeLimited", |
107 TRACE_EVENT_SCOPE_THREAD, | 107 TRACE_EVENT_SCOPE_THREAD, |
108 "trigger", event_name); | 108 "trigger", event_name); |
109 return false; | 109 return false; |
110 } | 110 } |
111 int frame_number = oracle_->RecordCapture(); | 111 int frame_number = oracle_->RecordCapture(); |
112 TRACE_EVENT_ASYNC_BEGIN2("mirroring", "Capture", output_buffer.get(), | 112 TRACE_EVENT_ASYNC_BEGIN2("mirroring", "Capture", output_buffer.get(), |
113 "frame_number", frame_number, | 113 "frame_number", frame_number, |
114 "trigger", event_name); | 114 "trigger", event_name); |
115 *callback = base::Bind(&ThreadSafeCaptureOracle::DidCaptureFrame, | |
116 this, | |
117 output_buffer, | |
118 frame_number); | |
119 *storage = media::VideoFrame::WrapExternalPackedMemory( | 115 *storage = media::VideoFrame::WrapExternalPackedMemory( |
120 media::VideoFrame::I420, | 116 media::VideoFrame::I420, |
121 capture_size_, | 117 capture_size_, |
122 gfx::Rect(capture_size_), | 118 gfx::Rect(capture_size_), |
123 capture_size_, | 119 capture_size_, |
124 static_cast<uint8*>(output_buffer->data()), | 120 static_cast<uint8*>(output_buffer->data()), |
125 output_buffer->size(), | 121 output_buffer->size(), |
126 base::SharedMemory::NULLHandle(), | 122 base::SharedMemory::NULLHandle(), |
127 base::TimeDelta(), | 123 base::TimeDelta(), |
128 base::Closure()); | 124 base::Closure()); |
| 125 *callback = base::Bind(&ThreadSafeCaptureOracle::DidCaptureFrame, |
| 126 this, |
| 127 output_buffer, |
| 128 *storage, |
| 129 frame_number); |
129 return true; | 130 return true; |
130 } | 131 } |
131 | 132 |
132 void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { | 133 void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { |
133 base::AutoLock guard(lock_); | 134 base::AutoLock guard(lock_); |
134 | 135 |
135 // If this is the first call to UpdateCaptureSize(), or the receiver supports | 136 // If this is the first call to UpdateCaptureSize(), or the receiver supports |
136 // variable resolution, then determine the capture size by treating the | 137 // variable resolution, then determine the capture size by treating the |
137 // requested width and height as maxima. | 138 // requested width and height as maxima. |
138 if (!capture_size_updated_ || params_.allow_resolution_change) { | 139 if (!capture_size_updated_ || params_.allow_resolution_change) { |
(...skipping 18 matching lines...) Expand all Loading... |
157 client_.reset(); | 158 client_.reset(); |
158 } | 159 } |
159 | 160 |
160 void ThreadSafeCaptureOracle::ReportError() { | 161 void ThreadSafeCaptureOracle::ReportError() { |
161 base::AutoLock guard(lock_); | 162 base::AutoLock guard(lock_); |
162 if (client_) | 163 if (client_) |
163 client_->OnError(); | 164 client_->OnError(); |
164 } | 165 } |
165 | 166 |
166 void ThreadSafeCaptureOracle::DidCaptureFrame( | 167 void ThreadSafeCaptureOracle::DidCaptureFrame( |
167 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer, | 168 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
| 169 const scoped_refptr<media::VideoFrame>& frame, |
168 int frame_number, | 170 int frame_number, |
169 base::TimeTicks timestamp, | 171 base::TimeTicks timestamp, |
170 bool success) { | 172 bool success) { |
171 base::AutoLock guard(lock_); | 173 base::AutoLock guard(lock_); |
172 TRACE_EVENT_ASYNC_END2("mirroring", "Capture", buffer.get(), | 174 TRACE_EVENT_ASYNC_END2("mirroring", "Capture", buffer.get(), |
173 "success", success, | 175 "success", success, |
174 "timestamp", timestamp.ToInternalValue()); | 176 "timestamp", timestamp.ToInternalValue()); |
175 | 177 |
176 if (!client_) | 178 if (!client_) |
177 return; // Capture is stopped. | 179 return; // Capture is stopped. |
178 | 180 |
179 if (success) { | 181 if (success) { |
180 if (oracle_->CompleteCapture(frame_number, timestamp)) { | 182 if (oracle_->CompleteCapture(frame_number, timestamp)) { |
181 client_->OnIncomingCapturedBuffer(buffer, | 183 client_->OnIncomingCapturedVideoFrame( |
182 media::VideoFrame::I420, | 184 buffer, |
183 capture_size_, | 185 media::VideoCaptureFormat( |
184 timestamp, | 186 capture_size_, frame_rate_, media::PIXEL_FORMAT_I420), |
185 frame_rate_); | 187 frame, |
| 188 timestamp); |
186 } | 189 } |
187 } | 190 } |
188 } | 191 } |
189 | 192 |
190 void VideoCaptureDeviceImpl::AllocateAndStart( | 193 void VideoCaptureDeviceImpl::AllocateAndStart( |
191 const media::VideoCaptureParams& params, | 194 const media::VideoCaptureParams& params, |
192 scoped_ptr<media::VideoCaptureDevice::Client> client) { | 195 scoped_ptr<media::VideoCaptureDevice::Client> client) { |
193 DCHECK(thread_checker_.CalledOnValidThread()); | 196 DCHECK(thread_checker_.CalledOnValidThread()); |
194 | 197 |
195 if (state_ != kIdle) { | 198 if (state_ != kIdle) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 return; | 298 return; |
296 | 299 |
297 if (oracle_proxy_) | 300 if (oracle_proxy_) |
298 oracle_proxy_->ReportError(); | 301 oracle_proxy_->ReportError(); |
299 | 302 |
300 StopAndDeAllocate(); | 303 StopAndDeAllocate(); |
301 TransitionStateTo(kError); | 304 TransitionStateTo(kError); |
302 } | 305 } |
303 | 306 |
304 } // namespace content | 307 } // namespace content |
OLD | NEW |