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

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

Issue 1142063003: content/child: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build fix. Created 5 years, 7 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 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
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (keep_frame_counter_ >= 1) { 351 if (keep_frame_counter_ >= 1) {
352 keep_frame_counter_ -= 1; 352 keep_frame_counter_ -= 1;
353 // Keep the frame. 353 // Keep the frame.
354 return false; 354 return false;
355 } 355 }
356 DVLOG(3) << "Drop frame. Input frame_rate_ " << frame_rate_ << "."; 356 DVLOG(3) << "Drop frame. Input frame_rate_ " << frame_rate_ << ".";
357 return true; 357 return true;
358 } 358 }
359 359
360 VideoTrackAdapter::VideoTrackAdapter( 360 VideoTrackAdapter::VideoTrackAdapter(
361 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) 361 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
362 : io_message_loop_(io_message_loop), 362 : io_task_runner_(io_task_runner),
363 renderer_task_runner_(base::MessageLoopProxy::current()), 363 renderer_task_runner_(base::ThreadTaskRunnerHandle::Get()),
364 monitoring_frame_rate_(false), 364 monitoring_frame_rate_(false),
365 muted_state_(false), 365 muted_state_(false),
366 frame_counter_(0), 366 frame_counter_(0),
367 source_frame_rate_(0.0f) { 367 source_frame_rate_(0.0f) {
368 DCHECK(io_message_loop_.get()); 368 DCHECK(io_task_runner);
369 } 369 }
370 370
371 VideoTrackAdapter::~VideoTrackAdapter() { 371 VideoTrackAdapter::~VideoTrackAdapter() {
372 DCHECK(adapters_.empty()); 372 DCHECK(adapters_.empty());
373 } 373 }
374 374
375 void VideoTrackAdapter::AddTrack(const MediaStreamVideoTrack* track, 375 void VideoTrackAdapter::AddTrack(const MediaStreamVideoTrack* track,
376 VideoCaptureDeliverFrameCB frame_callback, 376 VideoCaptureDeliverFrameCB frame_callback,
377 int max_width, 377 int max_width,
378 int max_height, 378 int max_height,
379 double min_aspect_ratio, 379 double min_aspect_ratio,
380 double max_aspect_ratio, 380 double max_aspect_ratio,
381 double max_frame_rate) { 381 double max_frame_rate) {
382 DCHECK(thread_checker_.CalledOnValidThread()); 382 DCHECK(thread_checker_.CalledOnValidThread());
383 383
384 io_message_loop_->PostTask( 384 io_task_runner_->PostTask(
385 FROM_HERE, 385 FROM_HERE,
386 base::Bind(&VideoTrackAdapter::AddTrackOnIO, 386 base::Bind(&VideoTrackAdapter::AddTrackOnIO, this, track, frame_callback,
387 this, track, frame_callback, gfx::Size(max_width, max_height), 387 gfx::Size(max_width, max_height), min_aspect_ratio,
388 min_aspect_ratio, max_aspect_ratio, max_frame_rate)); 388 max_aspect_ratio, max_frame_rate));
389 } 389 }
390 390
391 void VideoTrackAdapter::AddTrackOnIO(const MediaStreamVideoTrack* track, 391 void VideoTrackAdapter::AddTrackOnIO(const MediaStreamVideoTrack* track,
392 VideoCaptureDeliverFrameCB frame_callback, 392 VideoCaptureDeliverFrameCB frame_callback,
393 const gfx::Size& max_frame_size, 393 const gfx::Size& max_frame_size,
394 double min_aspect_ratio, 394 double min_aspect_ratio,
395 double max_aspect_ratio, 395 double max_aspect_ratio,
396 double max_frame_rate) { 396 double max_frame_rate) {
397 DCHECK(io_message_loop_->BelongsToCurrentThread()); 397 DCHECK(io_task_runner_->BelongsToCurrentThread());
398 scoped_refptr<VideoFrameResolutionAdapter> adapter; 398 scoped_refptr<VideoFrameResolutionAdapter> adapter;
399 for (const auto& frame_adapter : adapters_) { 399 for (const auto& frame_adapter : adapters_) {
400 if (frame_adapter->ConstraintsMatch(max_frame_size, min_aspect_ratio, 400 if (frame_adapter->ConstraintsMatch(max_frame_size, min_aspect_ratio,
401 max_aspect_ratio, max_frame_rate)) { 401 max_aspect_ratio, max_frame_rate)) {
402 adapter = frame_adapter.get(); 402 adapter = frame_adapter.get();
403 break; 403 break;
404 } 404 }
405 } 405 }
406 if (!adapter.get()) { 406 if (!adapter.get()) {
407 adapter = new VideoFrameResolutionAdapter(renderer_task_runner_, 407 adapter = new VideoFrameResolutionAdapter(renderer_task_runner_,
408 max_frame_size, 408 max_frame_size,
409 min_aspect_ratio, 409 min_aspect_ratio,
410 max_aspect_ratio, 410 max_aspect_ratio,
411 max_frame_rate); 411 max_frame_rate);
412 adapters_.push_back(adapter); 412 adapters_.push_back(adapter);
413 } 413 }
414 414
415 adapter->AddCallback(track, frame_callback); 415 adapter->AddCallback(track, frame_callback);
416 } 416 }
417 417
418 void VideoTrackAdapter::RemoveTrack(const MediaStreamVideoTrack* track) { 418 void VideoTrackAdapter::RemoveTrack(const MediaStreamVideoTrack* track) {
419 DCHECK(thread_checker_.CalledOnValidThread()); 419 DCHECK(thread_checker_.CalledOnValidThread());
420 io_message_loop_->PostTask( 420 io_task_runner_->PostTask(
421 FROM_HERE, 421 FROM_HERE, base::Bind(&VideoTrackAdapter::RemoveTrackOnIO, this, track));
422 base::Bind(&VideoTrackAdapter::RemoveTrackOnIO, this, track));
423 } 422 }
424 423
425 void VideoTrackAdapter::StartFrameMonitoring( 424 void VideoTrackAdapter::StartFrameMonitoring(
426 double source_frame_rate, 425 double source_frame_rate,
427 const OnMutedCallback& on_muted_callback) { 426 const OnMutedCallback& on_muted_callback) {
428 DCHECK(thread_checker_.CalledOnValidThread()); 427 DCHECK(thread_checker_.CalledOnValidThread());
429 428
430 VideoTrackAdapter::OnMutedCallback bound_on_muted_callback = 429 VideoTrackAdapter::OnMutedCallback bound_on_muted_callback =
431 media::BindToCurrentLoop(on_muted_callback); 430 media::BindToCurrentLoop(on_muted_callback);
432 431
433 io_message_loop_->PostTask( 432 io_task_runner_->PostTask(
434 FROM_HERE, 433 FROM_HERE, base::Bind(&VideoTrackAdapter::StartFrameMonitoringOnIO, this,
435 base::Bind(&VideoTrackAdapter::StartFrameMonitoringOnIO, 434 bound_on_muted_callback, source_frame_rate));
436 this, bound_on_muted_callback, source_frame_rate));
437 } 435 }
438 436
439 void VideoTrackAdapter::StopFrameMonitoring() { 437 void VideoTrackAdapter::StopFrameMonitoring() {
440 DCHECK(thread_checker_.CalledOnValidThread()); 438 DCHECK(thread_checker_.CalledOnValidThread());
441 io_message_loop_->PostTask( 439 io_task_runner_->PostTask(
442 FROM_HERE, 440 FROM_HERE, base::Bind(&VideoTrackAdapter::StopFrameMonitoringOnIO, this));
443 base::Bind(&VideoTrackAdapter::StopFrameMonitoringOnIO, this));
444 } 441 }
445 442
446 void VideoTrackAdapter::StartFrameMonitoringOnIO( 443 void VideoTrackAdapter::StartFrameMonitoringOnIO(
447 const OnMutedCallback& on_muted_callback, 444 const OnMutedCallback& on_muted_callback,
448 double source_frame_rate) { 445 double source_frame_rate) {
449 DCHECK(io_message_loop_->BelongsToCurrentThread()); 446 DCHECK(io_task_runner_->BelongsToCurrentThread());
450 DCHECK(!monitoring_frame_rate_); 447 DCHECK(!monitoring_frame_rate_);
451 448
452 monitoring_frame_rate_ = true; 449 monitoring_frame_rate_ = true;
453 450
454 // If the source does not know the frame rate, set one by default. 451 // If the source does not know the frame rate, set one by default.
455 if (source_frame_rate == 0.0f) 452 if (source_frame_rate == 0.0f)
456 source_frame_rate = MediaStreamVideoSource::kDefaultFrameRate; 453 source_frame_rate = MediaStreamVideoSource::kDefaultFrameRate;
457 source_frame_rate_ = source_frame_rate; 454 source_frame_rate_ = source_frame_rate;
458 DVLOG(1) << "Monitoring frame creation, first (large) delay: " 455 DVLOG(1) << "Monitoring frame creation, first (large) delay: "
459 << (kFirstFrameTimeoutInFrameIntervals / source_frame_rate_) << "s"; 456 << (kFirstFrameTimeoutInFrameIntervals / source_frame_rate_) << "s";
460 io_message_loop_->PostDelayedTask(FROM_HERE, 457 io_task_runner_->PostDelayedTask(
461 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this, 458 FROM_HERE, base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this,
462 on_muted_callback, frame_counter_), 459 on_muted_callback, frame_counter_),
463 base::TimeDelta::FromSecondsD(kFirstFrameTimeoutInFrameIntervals / 460 base::TimeDelta::FromSecondsD(kFirstFrameTimeoutInFrameIntervals /
464 source_frame_rate_)); 461 source_frame_rate_));
465 } 462 }
466 463
467 void VideoTrackAdapter::StopFrameMonitoringOnIO() { 464 void VideoTrackAdapter::StopFrameMonitoringOnIO() {
468 DCHECK(io_message_loop_->BelongsToCurrentThread()); 465 DCHECK(io_task_runner_->BelongsToCurrentThread());
469 monitoring_frame_rate_ = false; 466 monitoring_frame_rate_ = false;
470 } 467 }
471 468
472 void VideoTrackAdapter::RemoveTrackOnIO(const MediaStreamVideoTrack* track) { 469 void VideoTrackAdapter::RemoveTrackOnIO(const MediaStreamVideoTrack* track) {
473 DCHECK(io_message_loop_->BelongsToCurrentThread()); 470 DCHECK(io_task_runner_->BelongsToCurrentThread());
474 for (FrameAdapters::iterator it = adapters_.begin(); 471 for (FrameAdapters::iterator it = adapters_.begin();
475 it != adapters_.end(); ++it) { 472 it != adapters_.end(); ++it) {
476 (*it)->RemoveCallback(track); 473 (*it)->RemoveCallback(track);
477 if ((*it)->IsEmpty()) { 474 if ((*it)->IsEmpty()) {
478 adapters_.erase(it); 475 adapters_.erase(it);
479 break; 476 break;
480 } 477 }
481 } 478 }
482 } 479 }
483 480
484 void VideoTrackAdapter::DeliverFrameOnIO( 481 void VideoTrackAdapter::DeliverFrameOnIO(
485 const scoped_refptr<media::VideoFrame>& frame, 482 const scoped_refptr<media::VideoFrame>& frame,
486 const base::TimeTicks& estimated_capture_time) { 483 const base::TimeTicks& estimated_capture_time) {
487 DCHECK(io_message_loop_->BelongsToCurrentThread()); 484 DCHECK(io_task_runner_->BelongsToCurrentThread());
488 TRACE_EVENT0("video", "VideoTrackAdapter::DeliverFrameOnIO"); 485 TRACE_EVENT0("video", "VideoTrackAdapter::DeliverFrameOnIO");
489 ++frame_counter_; 486 ++frame_counter_;
490 for (const auto& adapter : adapters_) 487 for (const auto& adapter : adapters_)
491 adapter->DeliverFrame(frame, estimated_capture_time); 488 adapter->DeliverFrame(frame, estimated_capture_time);
492 } 489 }
493 490
494 void VideoTrackAdapter::CheckFramesReceivedOnIO( 491 void VideoTrackAdapter::CheckFramesReceivedOnIO(
495 const OnMutedCallback& set_muted_state_callback, 492 const OnMutedCallback& set_muted_state_callback,
496 uint64 old_frame_counter_snapshot) { 493 uint64 old_frame_counter_snapshot) {
497 DCHECK(io_message_loop_->BelongsToCurrentThread()); 494 DCHECK(io_task_runner_->BelongsToCurrentThread());
498 495
499 if (!monitoring_frame_rate_) 496 if (!monitoring_frame_rate_)
500 return; 497 return;
501 498
502 DVLOG_IF(1, old_frame_counter_snapshot == frame_counter_) 499 DVLOG_IF(1, old_frame_counter_snapshot == frame_counter_)
503 << "No frames have passed, setting source as Muted."; 500 << "No frames have passed, setting source as Muted.";
504 501
505 bool muted_state = old_frame_counter_snapshot == frame_counter_; 502 bool muted_state = old_frame_counter_snapshot == frame_counter_;
506 if (muted_state_ != muted_state) { 503 if (muted_state_ != muted_state) {
507 set_muted_state_callback.Run(muted_state); 504 set_muted_state_callback.Run(muted_state);
508 muted_state_ = muted_state; 505 muted_state_ = muted_state;
509 } 506 }
510 507
511 io_message_loop_->PostDelayedTask(FROM_HERE, 508 io_task_runner_->PostDelayedTask(
512 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this, 509 FROM_HERE, base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this,
513 set_muted_state_callback, frame_counter_), 510 set_muted_state_callback, frame_counter_),
514 base::TimeDelta::FromSecondsD(kNormalFrameTimeoutInFrameIntervals / 511 base::TimeDelta::FromSecondsD(kNormalFrameTimeoutInFrameIntervals /
515 source_frame_rate_)); 512 source_frame_rate_));
516 } 513 }
517 514
518 } // namespace content 515 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_track_adapter.h ('k') | content/renderer/media/webrtc/media_stream_remote_video_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698