diff --git a/webrtc/media/base/fakevideorenderer.h b/webrtc/media/base/fakevideorenderer.h index 6ebc1ae141..9f03ea9d16 100644 --- a/webrtc/media/base/fakevideorenderer.h +++ b/webrtc/media/base/fakevideorenderer.h @@ -26,7 +26,7 @@ class FakeVideoRenderer : public rtc::VideoSinkInterface { width_(0), height_(0), rotation_(webrtc::kVideoRotation_0), - timestamp_us_(0), + timestamp_(0), num_rendered_frames_(0), black_frame_(false) {} @@ -43,7 +43,7 @@ class FakeVideoRenderer : public rtc::VideoSinkInterface { width_ = frame.width(); height_ = frame.height(); rotation_ = frame.rotation(); - timestamp_us_ = frame.timestamp_us(); + timestamp_ = frame.GetTimeStamp(); SignalRenderFrame(&frame); } @@ -61,9 +61,9 @@ class FakeVideoRenderer : public rtc::VideoSinkInterface { return rotation_; } - int64_t timestamp_us() const { + int64_t timestamp() const { rtc::CritScope cs(&crit_); - return timestamp_us_; + return timestamp_; } int num_rendered_frames() const { rtc::CritScope cs(&crit_); @@ -133,7 +133,7 @@ class FakeVideoRenderer : public rtc::VideoSinkInterface { int width_; int height_; webrtc::VideoRotation rotation_; - int64_t timestamp_us_; + int64_t timestamp_; int num_rendered_frames_; bool black_frame_; rtc::CriticalSection crit_; diff --git a/webrtc/media/base/videobroadcaster_unittest.cc b/webrtc/media/base/videobroadcaster_unittest.cc index 48b4ffec71..58efbf3545 100644 --- a/webrtc/media/base/videobroadcaster_unittest.cc +++ b/webrtc/media/base/videobroadcaster_unittest.cc @@ -143,9 +143,9 @@ TEST(VideoBroadcasterTest, SinkWantsBlackFrames) { 10 /* timestamp_us */, 0 /* frame_id */); broadcaster.OnFrame(frame1); EXPECT_TRUE(sink1.black_frame()); - EXPECT_EQ(10, sink1.timestamp_us()); + EXPECT_EQ(10000, sink1.timestamp()); EXPECT_FALSE(sink2.black_frame()); - EXPECT_EQ(10, sink2.timestamp_us()); + EXPECT_EQ(10000, sink2.timestamp()); // Switch the sink wants. wants1.black_frames = false; @@ -157,7 +157,7 @@ TEST(VideoBroadcasterTest, SinkWantsBlackFrames) { 30 /* timestamp_us */, 0 /* frame_id */); broadcaster.OnFrame(frame2); EXPECT_FALSE(sink1.black_frame()); - EXPECT_EQ(30, sink1.timestamp_us()); + EXPECT_EQ(30000, sink1.timestamp()); EXPECT_TRUE(sink2.black_frame()); - EXPECT_EQ(30, sink2.timestamp_us()); + EXPECT_EQ(30000, sink2.timestamp()); } diff --git a/webrtc/media/base/videoframe.h b/webrtc/media/base/videoframe.h index bd7393463b..156da25112 100644 --- a/webrtc/media/base/videoframe.h +++ b/webrtc/media/base/videoframe.h @@ -45,6 +45,13 @@ class VideoFrame { virtual int64_t timestamp_us() const = 0; virtual void set_timestamp_us(int64_t time_us) = 0; + // Deprecated methods, for backwards compatibility. + // TODO(nisse): Delete when usage in Chrome and other applications + // have been replaced. + virtual int64_t GetTimeStamp() const { + return rtc::kNumNanosecsPerMicrosec * timestamp_us(); + } + // Indicates the rotation angle in degrees. virtual webrtc::VideoRotation rotation() const = 0; diff --git a/webrtc/media/base/videoframe_unittest.h b/webrtc/media/base/videoframe_unittest.h index 9658f878f5..8040804f83 100644 --- a/webrtc/media/base/videoframe_unittest.h +++ b/webrtc/media/base/videoframe_unittest.h @@ -453,7 +453,7 @@ class VideoFrameTest : public testing::Test { static bool IsEqual(const cricket::VideoFrame& frame, int width, int height, - int64_t timestamp_us, + int64_t time_stamp, const uint8_t* y, uint32_t ypitch, const uint8_t* u, @@ -461,8 +461,7 @@ class VideoFrameTest : public testing::Test { const uint8_t* v, uint32_t vpitch, int max_error) { - return IsSize(frame, width, height) && - frame.timestamp_us() == timestamp_us && + return IsSize(frame, width, height) && frame.GetTimeStamp() == time_stamp && IsPlaneEqual("y", frame.video_frame_buffer()->DataY(), frame.video_frame_buffer()->StrideY(), y, ypitch, static_cast(width), @@ -482,7 +481,7 @@ class VideoFrameTest : public testing::Test { int max_error) { return IsEqual(frame1, frame2.width(), frame2.height(), - frame2.timestamp_us(), + frame2.GetTimeStamp(), frame2.video_frame_buffer()->DataY(), frame2.video_frame_buffer()->StrideY(), frame2.video_frame_buffer()->DataU(), @@ -500,7 +499,7 @@ class VideoFrameTest : public testing::Test { IsEqual(frame1, frame2.width() - hcrop * 2, frame2.height() - vcrop * 2, - frame2.timestamp_us(), + frame2.GetTimeStamp(), frame2.video_frame_buffer()->DataY() + vcrop * frame2.video_frame_buffer()->StrideY() + hcrop, diff --git a/webrtc/media/engine/webrtcvideoengine2.cc b/webrtc/media/engine/webrtcvideoengine2.cc index d2e44cb681..2dec8f43b6 100644 --- a/webrtc/media/engine/webrtcvideoengine2.cc +++ b/webrtc/media/engine/webrtcvideoengine2.cc @@ -1664,8 +1664,9 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( return; } - int64_t frame_delta_ms = frame.timestamp_us() / rtc::kNumMicrosecsPerMillisec; + int64_t frame_delta_ms = frame.GetTimeStamp() / rtc::kNumNanosecsPerMillisec; + // frame->GetTimeStamp() is essentially a delta, align to webrtc time if (!first_frame_timestamp_ms_) { first_frame_timestamp_ms_ = rtc::Optional(rtc::TimeMillis() - frame_delta_ms); diff --git a/webrtc/media/engine/webrtcvideoframe_unittest.cc b/webrtc/media/engine/webrtcvideoframe_unittest.cc index 3743e87899..37153bb47b 100644 --- a/webrtc/media/engine/webrtcvideoframe_unittest.cc +++ b/webrtc/media/engine/webrtcvideoframe_unittest.cc @@ -186,13 +186,15 @@ TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { webrtc::NativeHandleBuffer* buffer = new rtc::RefCountedObject( dummy_handle, 640, 480); - - WebRtcVideoFrame frame(buffer, webrtc::kVideoRotation_0, 20); + // Timestamp is converted from ns to us, so last three digits are lost. + WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle()); EXPECT_EQ(640, frame.width()); EXPECT_EQ(480, frame.height()); + EXPECT_EQ(20000, frame.GetTimeStamp()); EXPECT_EQ(20, frame.timestamp_us()); frame.set_timestamp_us(40); + EXPECT_EQ(40000, frame.GetTimeStamp()); EXPECT_EQ(40, frame.timestamp_us()); } diff --git a/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm b/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm index 55d3917845..73682d3eaf 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCVideoRendererAdapter.mm @@ -30,8 +30,7 @@ class VideoRendererAdapter RTCVideoFrame* videoFrame = [[RTCVideoFrame alloc] initWithVideoBuffer:nativeVideoFrame.video_frame_buffer() rotation:nativeVideoFrame.rotation() - timeStampNs:nativeVideoFrame.timestamp_us() * - rtc::kNumNanosecsPerMicrosec]; + timeStampNs:nativeVideoFrame.GetTimeStamp()]; CGSize current_size = (videoFrame.rotation % 180 == 0) ? CGSizeMake(videoFrame.width, videoFrame.height) : CGSizeMake(videoFrame.height, videoFrame.width);