| Index: webrtc/media/engine/webrtcvideoframe.cc
|
| diff --git a/webrtc/media/engine/webrtcvideoframe.cc b/webrtc/media/engine/webrtcvideoframe.cc
|
| index 3a2d2def0e3af094681610aab54803ad0a98eba1..7ad0e88e066eeed7f263d1c0b36b7b5f9a1068ed 100644
|
| --- a/webrtc/media/engine/webrtcvideoframe.cc
|
| +++ b/webrtc/media/engine/webrtcvideoframe.cc
|
| @@ -22,17 +22,17 @@ using webrtc::kVPlane;
|
|
|
| namespace cricket {
|
|
|
| -WebRtcVideoFrame::WebRtcVideoFrame():
|
| - time_stamp_ns_(0),
|
| - rotation_(webrtc::kVideoRotation_0) {}
|
| +WebRtcVideoFrame::WebRtcVideoFrame()
|
| + : timestamp_us_(0), rotation_(webrtc::kVideoRotation_0) {}
|
|
|
| WebRtcVideoFrame::WebRtcVideoFrame(
|
| const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer,
|
| int64_t time_stamp_ns,
|
| webrtc::VideoRotation rotation)
|
| : video_frame_buffer_(buffer),
|
| - time_stamp_ns_(time_stamp_ns),
|
| rotation_(rotation) {
|
| + // Convert to usecs.
|
| + SetTimeStamp(time_stamp_ns);
|
| }
|
|
|
| WebRtcVideoFrame::~WebRtcVideoFrame() {}
|
| @@ -46,17 +46,31 @@ bool WebRtcVideoFrame::Init(uint32_t format,
|
| size_t sample_size,
|
| int64_t time_stamp_ns,
|
| webrtc::VideoRotation rotation) {
|
| - return Reset(format, w, h, dw, dh, sample, sample_size,
|
| - time_stamp_ns, rotation,
|
| - true /*apply_rotation*/);
|
| + if (!Reset(format, w, h, dw, dh, sample, sample_size, rotation,
|
| + true /*apply_rotation*/))
|
| + return false;
|
| +
|
| + SetTimeStamp(time_stamp_ns);
|
| + return true;
|
| }
|
|
|
| bool WebRtcVideoFrame::Init(const CapturedFrame* frame, int dw, int dh,
|
| bool apply_rotation) {
|
| - return Reset(frame->fourcc, frame->width, frame->height, dw, dh,
|
| - static_cast<uint8_t*>(frame->data), frame->data_size,
|
| - frame->time_stamp,
|
| - frame->rotation, apply_rotation);
|
| + if (!Reset(frame->fourcc, frame->width, frame->height, dw, dh,
|
| + static_cast<uint8_t*>(frame->data), frame->data_size,
|
| + frame->rotation, apply_rotation)) {
|
| + return false;
|
| + }
|
| + SetTimeStamp(frame->time_stamp);
|
| +
|
| + // Check that we always get the right epoch (with a 30s margin). If
|
| + // this is false for some camera, we need conversion logic adding
|
| + // the camera's clock offset.
|
| + RTC_DCHECK_LT(
|
| + std::abs(timestamp_us_ - static_cast<int64_t>(rtc::TimeMicros())),
|
| + 30 * rtc::kNumMicrosecsPerSec);
|
| +
|
| + return true;
|
| }
|
|
|
| bool WebRtcVideoFrame::InitToBlack(int w, int h,
|
| @@ -127,7 +141,9 @@ WebRtcVideoFrame::GetVideoFrameBuffer() const {
|
|
|
| VideoFrame* WebRtcVideoFrame::Copy() const {
|
| WebRtcVideoFrame* new_frame = new WebRtcVideoFrame(
|
| - video_frame_buffer_, time_stamp_ns_, rotation_);
|
| + video_frame_buffer_, 0 /* Dummy timestamp, overwridden below */,
|
| + rotation_);
|
| + new_frame->set_timestamp_us(timestamp_us_);
|
| return new_frame;
|
| }
|
|
|
| @@ -147,7 +163,6 @@ bool WebRtcVideoFrame::Reset(uint32_t format,
|
| int dh,
|
| uint8_t* sample,
|
| size_t sample_size,
|
| - int64_t time_stamp_ns,
|
| webrtc::VideoRotation rotation,
|
| bool apply_rotation) {
|
| if (!Validate(format, w, h, sample, sample_size)) {
|
| @@ -166,8 +181,7 @@ bool WebRtcVideoFrame::Reset(uint32_t format,
|
| new_height = dw;
|
| }
|
|
|
| - InitToEmptyBuffer(new_width, new_height,
|
| - time_stamp_ns);
|
| + InitToEmptyBuffer(new_width, new_height);
|
| rotation_ = apply_rotation ? webrtc::kVideoRotation_0 : rotation;
|
|
|
| int horiz_crop = ((w - dw) / 2) & ~1;
|
| @@ -197,16 +211,21 @@ bool WebRtcVideoFrame::Reset(uint32_t format,
|
|
|
| VideoFrame* WebRtcVideoFrame::CreateEmptyFrame(
|
| int w, int h,
|
| - int64_t time_stamp_ns) const {
|
| + int64_t timestamp_us) const {
|
| WebRtcVideoFrame* frame = new WebRtcVideoFrame();
|
| - frame->InitToEmptyBuffer(w, h, time_stamp_ns);
|
| + frame->InitToEmptyBuffer(w, h, rtc::kNumNanosecsPerMicrosec * timestamp_us);
|
| return frame;
|
| }
|
|
|
| +void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h) {
|
| + video_frame_buffer_ = new rtc::RefCountedObject<webrtc::I420Buffer>(w, h);
|
| + rotation_ = webrtc::kVideoRotation_0;
|
| +}
|
| +
|
| void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h,
|
| int64_t time_stamp_ns) {
|
| video_frame_buffer_ = new rtc::RefCountedObject<webrtc::I420Buffer>(w, h);
|
| - time_stamp_ns_ = time_stamp_ns;
|
| + SetTimeStamp(time_stamp_ns);
|
| rotation_ = webrtc::kVideoRotation_0;
|
| }
|
|
|
| @@ -237,8 +256,8 @@ const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const {
|
| rotated_height = orig_width;
|
| }
|
|
|
| - rotated_frame_.reset(CreateEmptyFrame(rotated_width, rotated_height,
|
| - GetTimeStamp()));
|
| + rotated_frame_.reset(
|
| + CreateEmptyFrame(rotated_width, rotated_height, timestamp_us_));
|
|
|
| // TODO(guoweis): Add a function in webrtc_libyuv.cc to convert from
|
| // VideoRotation to libyuv::RotationMode.
|
|
|