Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Change VideoTrackAdapter to not drop frames if the source frame rate …
Browse files Browse the repository at this point in the history
…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}
  • Loading branch information
perkj authored and Commit bot committed Aug 30, 2014
1 parent 3b74967 commit b18d81f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions content/renderer/media/media_stream_video_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
1 change: 1 addition & 0 deletions content/renderer/media/media_stream_video_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions content/renderer/media/video_track_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<media::VideoFrame>& frame);
bool MaybeDropFrame(const scoped_refptr<media::VideoFrame>& frame,
float source_frame_rate);

// Bound to the IO-thread.
base::ThreadChecker io_thread_checker_;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -224,8 +225,15 @@ void VideoTrackAdapter::VideoFrameResolutionAdapter::DeliverFrame(
}

bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame(
const scoped_refptr<media::VideoFrame>& frame) {
if (max_frame_rate_ == 0.0f)
const scoped_refptr<media::VideoFrame>& 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_;
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/webrtc/video_destination_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8*>(bitmap->getPixels()),
Expand Down

0 comments on commit b18d81f

Please sign in to comment.