Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: content/renderer/media/video_capture_impl.cc

Issue 955253002: Add metadata to media::VideoFrame and plumb it through IPC/MediaStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Windows compile errors. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Notes about usage of this object by VideoCaptureImplManager. 5 // Notes about usage of this object by VideoCaptureImplManager.
6 // 6 //
7 // VideoCaptureImplManager access this object by using a Unretained() 7 // VideoCaptureImplManager access this object by using a Unretained()
8 // binding and tasks on the IO thread. It is then important that 8 // binding and tasks on the IO thread. It is then important that
9 // VideoCaptureImpl never post task to itself. All operations must be 9 // VideoCaptureImpl never post task to itself. All operations must be
10 // synchronous. 10 // synchronous.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 201 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
202 if (iter == client_buffers_.end()) 202 if (iter == client_buffers_.end())
203 return; 203 return;
204 204
205 DCHECK(!iter->second.get() || iter->second->HasOneRef()) 205 DCHECK(!iter->second.get() || iter->second->HasOneRef())
206 << "Instructed to delete buffer we are still using."; 206 << "Instructed to delete buffer we are still using.";
207 client_buffers_.erase(iter); 207 client_buffers_.erase(iter);
208 } 208 }
209 209
210 void VideoCaptureImpl::OnBufferReceived(int buffer_id, 210 void VideoCaptureImpl::OnBufferReceived(int buffer_id,
211 const media::VideoCaptureFormat& format, 211 const gfx::Size& coded_size,
212 const gfx::Rect& visible_rect, 212 const gfx::Rect& visible_rect,
213 base::TimeTicks timestamp) { 213 base::TimeTicks timestamp,
214 const base::DictionaryValue& metadata) {
214 DCHECK(thread_checker_.CalledOnValidThread()); 215 DCHECK(thread_checker_.CalledOnValidThread());
215 216
216 // The capture pipeline supports only I420 for now.
217 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420);
218
219 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { 217 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
220 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); 218 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0));
221 return; 219 return;
222 } 220 }
223 221
224 last_frame_format_ = format;
225 if (first_frame_timestamp_.is_null()) 222 if (first_frame_timestamp_.is_null())
226 first_frame_timestamp_ = timestamp; 223 first_frame_timestamp_ = timestamp;
227 224
228 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc 225 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc
229 TRACE_EVENT_INSTANT2( 226 TRACE_EVENT_INSTANT2(
230 "cast_perf_test", "OnBufferReceived", 227 "cast_perf_test", "OnBufferReceived",
231 TRACE_EVENT_SCOPE_THREAD, 228 TRACE_EVENT_SCOPE_THREAD,
232 "timestamp", timestamp.ToInternalValue(), 229 "timestamp", timestamp.ToInternalValue(),
233 "time_delta", (timestamp - first_frame_timestamp_).ToInternalValue()); 230 "time_delta", (timestamp - first_frame_timestamp_).ToInternalValue());
234 231
235 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 232 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
236 DCHECK(iter != client_buffers_.end()); 233 DCHECK(iter != client_buffers_.end());
237 scoped_refptr<ClientBuffer> buffer = iter->second; 234 scoped_refptr<ClientBuffer> buffer = iter->second;
238 scoped_refptr<media::VideoFrame> frame = 235 scoped_refptr<media::VideoFrame> frame =
239 media::VideoFrame::WrapExternalPackedMemory( 236 media::VideoFrame::WrapExternalPackedMemory(
240 media::VideoFrame::I420, 237 media::VideoFrame::I420,
241 last_frame_format_.frame_size, 238 coded_size,
242 visible_rect, 239 visible_rect,
243 gfx::Size(visible_rect.width(), visible_rect.height()), 240 gfx::Size(visible_rect.width(), visible_rect.height()),
244 reinterpret_cast<uint8*>(buffer->buffer->memory()), 241 reinterpret_cast<uint8*>(buffer->buffer->memory()),
245 buffer->buffer_size, 242 buffer->buffer_size,
246 buffer->buffer->handle(), 243 buffer->buffer->handle(),
247 0, 244 0,
248 timestamp - first_frame_timestamp_, 245 timestamp - first_frame_timestamp_,
249 media::BindToCurrentLoop( 246 media::BindToCurrentLoop(
250 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, 247 base::Bind(&VideoCaptureImpl::OnClientBufferFinished,
251 weak_factory_.GetWeakPtr(), 248 weak_factory_.GetWeakPtr(),
252 buffer_id, 249 buffer_id,
253 buffer, 250 buffer,
254 0))); 251 0)));
252 frame->metadata().MergeDictionary(&metadata);
253 DCHECK(frame->metadata().HasKey(media::VideoFrame::kFrameRateMetadataKey));
255 254
256 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); 255 for (const auto& entry : clients_)
257 ++it) { 256 entry.second.deliver_frame_cb.Run(frame, timestamp);
258 it->second.deliver_frame_cb.Run(frame, format, timestamp);
259 }
260 } 257 }
261 258
262 void VideoCaptureImpl::OnMailboxBufferReceived( 259 void VideoCaptureImpl::OnMailboxBufferReceived(
263 int buffer_id, 260 int buffer_id,
264 const gpu::MailboxHolder& mailbox_holder, 261 const gpu::MailboxHolder& mailbox_holder,
265 const media::VideoCaptureFormat& format, 262 const gfx::Size& packed_frame_size,
266 base::TimeTicks timestamp) { 263 base::TimeTicks timestamp,
264 const base::DictionaryValue& metadata) {
267 DCHECK(thread_checker_.CalledOnValidThread()); 265 DCHECK(thread_checker_.CalledOnValidThread());
268 266
269 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { 267 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
270 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); 268 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0));
271 return; 269 return;
272 } 270 }
273 271
274 last_frame_format_ = format;
275 if (first_frame_timestamp_.is_null()) 272 if (first_frame_timestamp_.is_null())
276 first_frame_timestamp_ = timestamp; 273 first_frame_timestamp_ = timestamp;
277 274
278 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( 275 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture(
279 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), 276 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)),
280 media::BindToCurrentLoop(base::Bind( 277 media::BindToCurrentLoop(base::Bind(
281 &VideoCaptureImpl::OnClientBufferFinished, weak_factory_.GetWeakPtr(), 278 &VideoCaptureImpl::OnClientBufferFinished, weak_factory_.GetWeakPtr(),
282 buffer_id, scoped_refptr<ClientBuffer>())), 279 buffer_id, scoped_refptr<ClientBuffer>())),
283 last_frame_format_.frame_size, gfx::Rect(last_frame_format_.frame_size), 280 packed_frame_size, gfx::Rect(packed_frame_size), packed_frame_size,
284 last_frame_format_.frame_size, timestamp - first_frame_timestamp_, false); 281 timestamp - first_frame_timestamp_, false);
282 frame->metadata().MergeDictionary(&metadata);
283 DCHECK(frame->metadata().HasKey(media::VideoFrame::kFrameRateMetadataKey));
285 284
286 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); 285 for (const auto& entry : clients_)
287 ++it) { 286 entry.second.deliver_frame_cb.Run(frame, timestamp);
288 it->second.deliver_frame_cb.Run(frame, format, timestamp);
289 }
290 } 287 }
291 288
292 void VideoCaptureImpl::OnClientBufferFinished( 289 void VideoCaptureImpl::OnClientBufferFinished(
293 int buffer_id, 290 int buffer_id,
294 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, 291 const scoped_refptr<ClientBuffer>& /* ignored_buffer */,
295 uint32 release_sync_point) { 292 uint32 release_sync_point) {
296 DCHECK(thread_checker_.CalledOnValidThread()); 293 DCHECK(thread_checker_.CalledOnValidThread());
297 Send(new VideoCaptureHostMsg_BufferReady( 294 Send(new VideoCaptureHostMsg_BufferReady(
298 device_id_, buffer_id, release_sync_point)); 295 device_id_, buffer_id, release_sync_point));
299 } 296 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 ClientInfoMap::iterator it = clients->find(client_id); 428 ClientInfoMap::iterator it = clients->find(client_id);
432 if (it != clients->end()) { 429 if (it != clients->end()) {
433 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); 430 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
434 clients->erase(it); 431 clients->erase(it);
435 found = true; 432 found = true;
436 } 433 }
437 return found; 434 return found;
438 } 435 }
439 436
440 } // namespace content 437 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698