From b18d81f67b126ff6513b6b442d93138958fa156e Mon Sep 17 00:00:00 2001 From: perkj Date: Sat, 30 Aug 2014 11:29:44 -0700 Subject: [PATCH] Change VideoTrackAdapter to not drop frames if the source frame rate is known. Also change remote video and pepper plugin MediaStreamVideoSource implementations to not set a guessed frame rate. BUG= 394315 Review URL: https://codereview.chromium.org/517973002 Cr-Commit-Position: refs/heads/master@{#292800} --- .../media/media_stream_video_source.cc | 1 + .../renderer/media/media_stream_video_source.h | 1 + content/renderer/media/video_track_adapter.cc | 18 +++++++++++++----- .../webrtc/media_stream_remote_video_source.cc | 2 +- .../media/webrtc/video_destination_handler.cc | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/content/renderer/media/media_stream_video_source.cc b/content/renderer/media/media_stream_video_source.cc index 0bd016bd92fa4..eb6ac78ca9506 100644 --- a/content/renderer/media/media_stream_video_source.cc +++ b/content/renderer/media/media_stream_video_source.cc @@ -43,6 +43,7 @@ const char* kSupportedConstraints[] = { const int MediaStreamVideoSource::kDefaultWidth = 640; const int MediaStreamVideoSource::kDefaultHeight = 480; const int MediaStreamVideoSource::kDefaultFrameRate = 30; +const int MediaStreamVideoSource::kUnknownFrameRate = 0; namespace { diff --git a/content/renderer/media/media_stream_video_source.h b/content/renderer/media/media_stream_video_source.h index cbf8c826460d4..3aed40a84cd83 100644 --- a/content/renderer/media/media_stream_video_source.h +++ b/content/renderer/media/media_stream_video_source.h @@ -81,6 +81,7 @@ class CONTENT_EXPORT MediaStreamVideoSource static const int kDefaultWidth; static const int kDefaultHeight; static const int kDefaultFrameRate; + static const int kUnknownFrameRate; protected: virtual void DoStopSource() OVERRIDE; diff --git a/content/renderer/media/video_track_adapter.cc b/content/renderer/media/video_track_adapter.cc index 3f61a429c4696..914c54f0f4783 100644 --- a/content/renderer/media/video_track_adapter.cc +++ b/content/renderer/media/video_track_adapter.cc @@ -89,7 +89,8 @@ class VideoTrackAdapter::VideoFrameResolutionAdapter // Returns |true| if the input frame rate is higher that the requested max // frame rate and |frame| should be dropped. - bool MaybeDropFrame(const scoped_refptr& frame); + bool MaybeDropFrame(const scoped_refptr& frame, + float source_frame_rate); // Bound to the IO-thread. base::ThreadChecker io_thread_checker_; @@ -152,7 +153,7 @@ void VideoTrackAdapter::VideoFrameResolutionAdapter::DeliverFrame( const base::TimeTicks& estimated_capture_time) { DCHECK(io_thread_checker_.CalledOnValidThread()); - if (MaybeDropFrame(frame)) + if (MaybeDropFrame(frame, format.frame_rate)) return; // TODO(perkj): Allow cropping / scaling of textures once @@ -224,8 +225,15 @@ void VideoTrackAdapter::VideoFrameResolutionAdapter::DeliverFrame( } bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame( - const scoped_refptr& frame) { - if (max_frame_rate_ == 0.0f) + const scoped_refptr& frame, + float source_frame_rate) { + DCHECK(io_thread_checker_.CalledOnValidThread()); + + // Do not drop frames if max frame rate hasn't been specified or the source + // frame rate is known and is lower than max. + if (max_frame_rate_ == 0.0f || + (source_frame_rate > 0 && + source_frame_rate <= max_frame_rate_)) return false; base::TimeDelta delta = frame->timestamp() - last_time_stamp_; @@ -243,7 +251,7 @@ bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame( return true; } last_time_stamp_ = frame->timestamp(); - if (delta == last_time_stamp_) // First received frame. + if (delta == last_time_stamp_) // First received frame. return false; // Calculate the frame rate using a simple AR filter. // Use a simple filter with 0.1 weight of the current sample. diff --git a/content/renderer/media/webrtc/media_stream_remote_video_source.cc b/content/renderer/media/webrtc/media_stream_remote_video_source.cc index c1ec2673107b4..a1181e42d174c 100644 --- a/content/renderer/media/webrtc/media_stream_remote_video_source.cc +++ b/content/renderer/media/webrtc/media_stream_remote_video_source.cc @@ -106,7 +106,7 @@ RemoteVideoSourceDelegate::RenderFrame( media::VideoCaptureFormat format( gfx::Size(video_frame->natural_size().width(), video_frame->natural_size().height()), - MediaStreamVideoSource::kDefaultFrameRate, + MediaStreamVideoSource::kUnknownFrameRate, pixel_format); io_message_loop_->PostTask( diff --git a/content/renderer/media/webrtc/video_destination_handler.cc b/content/renderer/media/webrtc/video_destination_handler.cc index f9b1e03ef344c..2f8200dad0f13 100644 --- a/content/renderer/media/webrtc/video_destination_handler.cc +++ b/content/renderer/media/webrtc/video_destination_handler.cc @@ -146,7 +146,7 @@ void PpFrameWriter::PutFrame(PPB_ImageData_Impl* image_data, gfx::Rect(frame_size), frame_size, timestamp); media::VideoCaptureFormat format( frame_size, - MediaStreamVideoSource::kDefaultFrameRate, + MediaStreamVideoSource::kUnknownFrameRate, media::PIXEL_FORMAT_YV12); libyuv::BGRAToI420(reinterpret_cast(bitmap->getPixels()),