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

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

Issue 366243003: VideoTrackAdapter: Add passing frames monitor, notify MSVCS -> MSVTrack(s) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
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/video_track_adapter.h" 5 #include "content/renderer/media/video_track_adapter.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "media/base/video_util.h" 14 #include "media/base/video_util.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 namespace { 18 namespace {
19 19
20 static const float kFirstFrameTimeoutInFrameIntervals = 100.0f;
Henrik Grunell 2014/07/08 11:39:53 Remove static. Comment on these.
mcasas 2014/07/08 16:12:01 Done.
21 static const float kNormalFrameTimeoutInFrameIntervals = 25.0f;
22
20 // Empty method used for keeping a reference to the original media::VideoFrame 23 // Empty method used for keeping a reference to the original media::VideoFrame
21 // in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed. 24 // in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed.
22 // The reference to |frame| is kept in the closure that calls this method. 25 // The reference to |frame| is kept in the closure that calls this method.
23 void ReleaseOriginalFrame( 26 void ReleaseOriginalFrame(
24 const scoped_refptr<media::VideoFrame>& frame) { 27 const scoped_refptr<media::VideoFrame>& frame) {
25 } 28 }
26 29
27 void ResetCallbackOnMainRenderThread( 30 void ResetCallbackOnMainRenderThread(
28 scoped_ptr<VideoCaptureDeliverFrameCB> callback) { 31 scoped_ptr<VideoCaptureDeliverFrameCB> callback) {
29 // |callback| will be deleted when this exits. 32 // |callback| will be deleted when this exits.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 297 }
295 298
296 bool VideoTrackAdapter::VideoFrameResolutionAdapter::IsEmpty() const { 299 bool VideoTrackAdapter::VideoFrameResolutionAdapter::IsEmpty() const {
297 DCHECK(io_thread_checker_.CalledOnValidThread()); 300 DCHECK(io_thread_checker_.CalledOnValidThread());
298 return callbacks_.empty(); 301 return callbacks_.empty();
299 } 302 }
300 303
301 VideoTrackAdapter::VideoTrackAdapter( 304 VideoTrackAdapter::VideoTrackAdapter(
302 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) 305 const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
303 : io_message_loop_(io_message_loop), 306 : io_message_loop_(io_message_loop),
304 renderer_task_runner_(base::MessageLoopProxy::current()) { 307 renderer_task_runner_(base::MessageLoopProxy::current()),
308 frame_counter_(0),
309 frame_rate_(0.0f) {
305 DCHECK(io_message_loop_); 310 DCHECK(io_message_loop_);
306 } 311 }
307 312
308 VideoTrackAdapter::~VideoTrackAdapter() { 313 VideoTrackAdapter::~VideoTrackAdapter() {
309 DCHECK(adapters_.empty()); 314 DCHECK(adapters_.empty());
310 } 315 }
311 316
312 void VideoTrackAdapter::AddTrack(const MediaStreamVideoTrack* track, 317 void VideoTrackAdapter::AddTrack(
313 VideoCaptureDeliverFrameCB frame_callback, 318 const MediaStreamVideoTrack* track,
314 int max_width, 319 VideoCaptureDeliverFrameCB frame_callback,
315 int max_height, 320 int max_width,
316 double min_aspect_ratio, 321 int max_height,
317 double max_aspect_ratio, 322 double min_aspect_ratio,
318 double max_frame_rate) { 323 double max_aspect_ratio,
324 double max_frame_rate,
325 double target_frame_rate,
326 const OnMutedCallback& set_muted_state_callback) {
319 DCHECK(thread_checker_.CalledOnValidThread()); 327 DCHECK(thread_checker_.CalledOnValidThread());
320 io_message_loop_->PostTask( 328 io_message_loop_->PostTask(
321 FROM_HERE, 329 FROM_HERE,
322 base::Bind(&VideoTrackAdapter::AddTrackOnIO, 330 base::Bind(&VideoTrackAdapter::AddTrackOnIO,
323 this, track, frame_callback, gfx::Size(max_width, max_height), 331 this, track, frame_callback, gfx::Size(max_width, max_height),
324 min_aspect_ratio, max_aspect_ratio, max_frame_rate)); 332 min_aspect_ratio, max_aspect_ratio, max_frame_rate));
333 io_message_loop_->PostTask(
Henrik Grunell 2014/07/08 11:39:53 Could the monitoring possibly be racy initially? S
mcasas 2014/07/08 16:12:01 The posting could be racy with respect to the fram
334 FROM_HERE,
335 base::Bind(&VideoTrackAdapter::StartTrackMonitoringOnIO,
336 this, set_muted_state_callback, target_frame_rate));
325 } 337 }
326 338
327 void VideoTrackAdapter::AddTrackOnIO( 339 void VideoTrackAdapter::AddTrackOnIO(
328 const MediaStreamVideoTrack* track, 340 const MediaStreamVideoTrack* track,
329 VideoCaptureDeliverFrameCB frame_callback, 341 VideoCaptureDeliverFrameCB frame_callback,
330 const gfx::Size& max_frame_size, 342 const gfx::Size& max_frame_size,
331 double min_aspect_ratio, 343 double min_aspect_ratio,
332 double max_aspect_ratio, 344 double max_aspect_ratio,
333 double max_frame_rate) { 345 double max_frame_rate) {
334 DCHECK(io_message_loop_->BelongsToCurrentThread()); 346 DCHECK(io_message_loop_->BelongsToCurrentThread());
(...skipping 18 matching lines...) Expand all
353 adapter->AddCallback(track, frame_callback); 365 adapter->AddCallback(track, frame_callback);
354 } 366 }
355 367
356 void VideoTrackAdapter::RemoveTrack(const MediaStreamVideoTrack* track) { 368 void VideoTrackAdapter::RemoveTrack(const MediaStreamVideoTrack* track) {
357 DCHECK(thread_checker_.CalledOnValidThread()); 369 DCHECK(thread_checker_.CalledOnValidThread());
358 io_message_loop_->PostTask( 370 io_message_loop_->PostTask(
359 FROM_HERE, 371 FROM_HERE,
360 base::Bind(&VideoTrackAdapter::RemoveTrackOnIO, this, track)); 372 base::Bind(&VideoTrackAdapter::RemoveTrackOnIO, this, track));
361 } 373 }
362 374
375 void VideoTrackAdapter::StartTrackMonitoringOnIO(
376 const OnMutedCallback& set_muted_state_callback,
377 double target_frame_rate) {
378 DCHECK(io_message_loop_->BelongsToCurrentThread());
379 frame_rate_ = target_frame_rate;
Henrik Grunell 2014/07/08 11:39:53 Should frame_rate_ be called target_frame_rate_?
mcasas 2014/07/08 16:12:01 Done.
380 DCHECK_NE(frame_rate_, 0.0f);
Henrik Grunell 2014/07/08 11:39:53 Put this dcheck before setting |frame_rate_| and c
mcasas 2014/07/08 16:12:01 Done.
381 DVLOG(1) << "Monitoring frame creation, first (large) delay: "
382 << (kFirstFrameTimeoutInFrameIntervals / frame_rate_) << "s";
383 io_message_loop_->PostDelayedTask(FROM_HERE,
384 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this,
385 set_muted_state_callback, frame_counter_),
386 base::TimeDelta::FromSecondsD(kFirstFrameTimeoutInFrameIntervals /
387 frame_rate_));
388 }
389
363 void VideoTrackAdapter::RemoveTrackOnIO(const MediaStreamVideoTrack* track) { 390 void VideoTrackAdapter::RemoveTrackOnIO(const MediaStreamVideoTrack* track) {
364 DCHECK(io_message_loop_->BelongsToCurrentThread()); 391 DCHECK(io_message_loop_->BelongsToCurrentThread());
365 for (FrameAdapters::iterator it = adapters_.begin(); 392 for (FrameAdapters::iterator it = adapters_.begin();
366 it != adapters_.end(); ++it) { 393 it != adapters_.end(); ++it) {
367 (*it)->RemoveCallback(track); 394 (*it)->RemoveCallback(track);
368 if ((*it)->IsEmpty()) { 395 if ((*it)->IsEmpty()) {
369 adapters_.erase(it); 396 adapters_.erase(it);
370 break; 397 break;
371 } 398 }
372 } 399 }
373 } 400 }
374 401
375 void VideoTrackAdapter::DeliverFrameOnIO( 402 void VideoTrackAdapter::DeliverFrameOnIO(
376 const scoped_refptr<media::VideoFrame>& frame, 403 const scoped_refptr<media::VideoFrame>& frame,
377 const media::VideoCaptureFormat& format, 404 const media::VideoCaptureFormat& format,
378 const base::TimeTicks& estimated_capture_time) { 405 const base::TimeTicks& estimated_capture_time) {
379 DCHECK(io_message_loop_->BelongsToCurrentThread()); 406 DCHECK(io_message_loop_->BelongsToCurrentThread());
380 TRACE_EVENT0("video", "VideoTrackAdapter::DeliverFrameOnIO"); 407 TRACE_EVENT0("video", "VideoTrackAdapter::DeliverFrameOnIO");
408 ++frame_counter_;
381 for (FrameAdapters::iterator it = adapters_.begin(); 409 for (FrameAdapters::iterator it = adapters_.begin();
382 it != adapters_.end(); ++it) { 410 it != adapters_.end(); ++it) {
383 (*it)->DeliverFrame(frame, format, estimated_capture_time); 411 (*it)->DeliverFrame(frame, format, estimated_capture_time);
384 } 412 }
385 } 413 }
386 414
415 void VideoTrackAdapter::CheckFramesReceivedOnIO(
416 const OnMutedCallback& set_muted_state_callback,
417 uint64 frame_counter_snapshot) {
Henrik Grunell 2014/07/08 11:39:53 I think the "snapshot" part of the name is somewha
mcasas 2014/07/08 16:12:01 Done.
418 DCHECK(io_message_loop_->BelongsToCurrentThread());
419 DVLOG_IF(1, frame_counter_snapshot == frame_counter_)
420 << "No frames have passed, setting source as Muted.";
421 set_muted_state_callback.Run(frame_counter_snapshot == frame_counter_);
422
423 io_message_loop_->PostDelayedTask(FROM_HERE,
424 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this,
425 set_muted_state_callback, frame_counter_),
426 base::TimeDelta::FromSecondsD(kNormalFrameTimeoutInFrameIntervals /
427 frame_rate_));
428 }
429
387 } // namespace content 430 } // namespace content
OLDNEW
« content/renderer/media/video_track_adapter.h ('K') | « content/renderer/media/video_track_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698