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

Unified Diff: content/renderer/media/gpu/rtc_video_encoder_unittest.cc

Issue 2435693004: Reland: Use webrtc::VideoFrame timestamp in RTCVideoEncoder (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/gpu/rtc_video_encoder.cc ('k') | media/gpu/android_video_encode_accelerator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/gpu/rtc_video_encoder_unittest.cc
diff --git a/content/renderer/media/gpu/rtc_video_encoder_unittest.cc b/content/renderer/media/gpu/rtc_video_encoder_unittest.cc
index a0e4fb79350d172bfcf3f1f75a4700b77a8743d2..72154004e42d41f90a63dd883f77b561ccb83788 100644
--- a/content/renderer/media/gpu/rtc_video_encoder_unittest.cc
+++ b/content/renderer/media/gpu/rtc_video_encoder_unittest.cc
@@ -15,8 +15,10 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libyuv/include/libyuv/planar_functions.h"
#include "third_party/webrtc/modules/video_coding/include/video_codec_interface.h"
+#include "third_party/webrtc/video_encoder.h"
using ::testing::_;
+using ::testing::AtLeast;
using ::testing::Invoke;
using ::testing::Return;
using ::testing::SaveArg;
@@ -34,6 +36,27 @@ const unsigned short kInputFrameHeight = 234;
const unsigned short kInputFrameWidth = 345;
const unsigned short kStartBitrate = 100;
+class EncodedImageCallbackWrapper : public webrtc::EncodedImageCallback {
+ public:
+ using EncodedCallback =
+ base::Callback<void(const webrtc::EncodedImage& encoded_image,
+ const webrtc::CodecSpecificInfo* codec_specific_info,
+ const webrtc::RTPFragmentationHeader* fragmentation)>;
+
+ EncodedImageCallbackWrapper(const EncodedCallback& encoded_callback)
+ : encoded_callback_(encoded_callback) {}
+
+ Result OnEncodedImage(
+ const webrtc::EncodedImage& encoded_image,
+ const webrtc::CodecSpecificInfo* codec_specific_info,
+ const webrtc::RTPFragmentationHeader* fragmentation) override {
+ encoded_callback_.Run(encoded_image, codec_specific_info, fragmentation);
+ return Result(Result::OK);
+ };
+
+ private:
+ EncodedCallback encoded_callback_;
+};
} // anonymous namespace
class RTCVideoEncoderTest
@@ -56,7 +79,7 @@ class RTCVideoEncoderTest
.WillRepeatedly(Return(mock_vea));
EXPECT_CALL(*mock_vea, Initialize(_, _, _, _, _))
.WillOnce(Invoke(this, &RTCVideoEncoderTest::Initialize));
- EXPECT_CALL(*mock_vea, UseOutputBitstreamBuffer(_)).Times(3);
+ EXPECT_CALL(*mock_vea, UseOutputBitstreamBuffer(_)).Times(AtLeast(3));
EXPECT_CALL(*mock_vea, Destroy()).Times(1);
return mock_vea;
}
@@ -100,11 +123,18 @@ class RTCVideoEncoderTest
uint32_t initial_bitrate,
media::VideoEncodeAccelerator::Client* client) {
DVLOG(3) << __func__;
- client->RequireBitstreamBuffers(0, input_visible_size,
- input_visible_size.GetArea());
+ client_ = client;
+ client_->RequireBitstreamBuffers(0, input_visible_size,
+ input_visible_size.GetArea());
return true;
}
+ void RegisterEncodeCompleteCallback(
+ const EncodedImageCallbackWrapper::EncodedCallback& callback) {
+ callback_wrapper_.reset(new EncodedImageCallbackWrapper(callback));
+ rtc_encoder_->RegisterEncodeCompleteCallback(callback_wrapper_.get());
+ }
+
webrtc::VideoCodec GetDefaultCodec() {
webrtc::VideoCodec codec = {};
memset(&codec, 0, sizeof(codec));
@@ -136,12 +166,27 @@ class RTCVideoEncoderTest
frame->visible_data(media::VideoFrame::kVPlane)[0]);
}
+ void ReturnFrameWithTimeStamp(const scoped_refptr<media::VideoFrame>& frame,
+ bool force_keyframe) {
+ client_->BitstreamBufferReady(0, 0, force_keyframe, frame->timestamp());
+ }
+
+ void VerifyTimestamp(uint32_t rtp_timestamp,
+ const webrtc::EncodedImage& encoded_image,
+ const webrtc::CodecSpecificInfo* codec_specific_info,
+ const webrtc::RTPFragmentationHeader* fragmentation) {
+ DVLOG(3) << __func__;
+ EXPECT_EQ(rtp_timestamp, encoded_image._timeStamp);
+ }
+
protected:
media::MockVideoEncodeAccelerator* mock_vea_;
std::unique_ptr<RTCVideoEncoder> rtc_encoder_;
private:
std::unique_ptr<media::MockGpuVideoAcceleratorFactories> mock_gpu_factories_;
+ media::VideoEncodeAccelerator::Client* client_;
+ std::unique_ptr<EncodedImageCallbackWrapper> callback_wrapper_;
base::Thread encoder_thread_;
base::WaitableEvent idle_waiter_;
};
@@ -187,10 +232,44 @@ TEST_F(RTCVideoEncoderTest, EncodeScaledFrame) {
const rtc::scoped_refptr<webrtc::I420Buffer> upscaled_buffer =
webrtc::I420Buffer::Create(2 * kInputFrameWidth, 2 * kInputFrameHeight);
FillFrameBuffer(upscaled_buffer);
+ webrtc::VideoFrame rtc_frame(upscaled_buffer, 0, 0, webrtc::kVideoRotation_0);
+ rtc_frame.set_ntp_time_ms(123456);
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
+ rtc_encoder_->Encode(rtc_frame, nullptr, &frame_types));
+}
+
+// We cannot run this test on Android because AndroidVideoEncodeAccelerator does
+// not preserve timestamps.
+#if defined(OS_ANDROID)
+#define MAYBE_PreserveTimestamps DISABLED_PreserveTimestamps
+#else
+#define MAYBE_PreserveTimestamps PreserveTimestamps
+#endif // defined(OS_ANDROID)
+
+TEST_F(RTCVideoEncoderTest, MAYBE_PreserveTimestamps) {
+ const webrtc::VideoCodecType codec_type = webrtc::kVideoCodecVP8;
+ CreateEncoder(codec_type);
+ webrtc::VideoCodec codec = GetDefaultCodec();
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_encoder_->InitEncode(&codec, 1, 12345));
+
+ const uint32_t rtp_timestamp = 1234567;
+ RegisterEncodeCompleteCallback(
+ base::Bind(&RTCVideoEncoderTest::VerifyTimestamp, base::Unretained(this),
+ rtp_timestamp));
+
+ EXPECT_CALL(*mock_vea_, Encode(_, _))
+ .WillOnce(Invoke(this, &RTCVideoEncoderTest::ReturnFrameWithTimeStamp));
+ const rtc::scoped_refptr<webrtc::I420Buffer> buffer =
+ webrtc::I420Buffer::Create(kInputFrameWidth, kInputFrameHeight);
+ FillFrameBuffer(buffer);
+ std::vector<webrtc::FrameType> frame_types;
+ webrtc::VideoFrame rtc_frame(buffer, rtp_timestamp, 0,
+ webrtc::kVideoRotation_0);
+ // We need to set ntp_time_ms because it will be used to derive
+ // media::VideoFrame timestamp.
+ rtc_frame.set_ntp_time_ms(4567891);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
- rtc_encoder_->Encode(webrtc::VideoFrame(upscaled_buffer, 0, 0,
- webrtc::kVideoRotation_0),
- nullptr, &frame_types));
+ rtc_encoder_->Encode(rtc_frame, nullptr, &frame_types));
}
INSTANTIATE_TEST_CASE_P(CodecProfiles,
« no previous file with comments | « content/renderer/media/gpu/rtc_video_encoder.cc ('k') | media/gpu/android_video_encode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698