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

Side by Side Diff: content/renderer/media/rtc_video_decoder_unittest.cc

Issue 13890012: Integrate VDA with WebRTC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, make Reset/Release async, and move RVD creation to RVDF::ctor Created 7 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/message_loop.h"
7 #include "base/synchronization/waitable_event.h"
8 #include "base/threading/thread.h"
9 #include "content/renderer/media/rtc_video_decoder.h"
10 #include "media/base/gmock_callback_support.h"
11 #include "media/filters/gpu_video_decoder.h"
12 #include "media/filters/mock_gpu_video_decoder_factories.h"
13 #include "media/video/mock_video_decode_accelerator.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using ::testing::_;
17 using ::testing::Invoke;
18 using ::testing::Return;
19 using ::testing::SaveArg;
20 using ::testing::WithArgs;
21
22 namespace content {
23
24 class RTCVideoDecoderTest : public ::testing::Test,
25 webrtc::DecodedImageCallback {
26 public:
27 RTCVideoDecoderTest()
28 : mock_gpu_factories_(new media::MockGpuVideoDecoderFactories),
29 num_delivered_frames_(0),
30 vda_thread_("vda_thread"),
31 idle_waiter_(false, false) {
32 memset(&codec_, 0, sizeof(codec_));
33 }
34
35 virtual void SetUp() OVERRIDE {
36 ASSERT_TRUE(vda_thread_.Start());
37 vda_loop_proxy_ = vda_thread_.message_loop_proxy();
38 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop())
39 .WillOnce(Return(vda_loop_proxy_));
40 rtc_decoder_.reset(new RTCVideoDecoder(mock_gpu_factories_));
41 }
42
43 virtual void TearDown() OVERRIDE { vda_thread_.Stop(); }
44
45 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE {
46 EXPECT_EQ(vda_loop_proxy_, base::MessageLoopProxy::current());
47 VLOG(2) << "Decoded";
48 ++num_delivered_frames_;
49 return WEBRTC_VIDEO_CODEC_OK;
50 }
51
52 void Initialize() {
53 VLOG(2) << "Initialize";
54 mock_vda_ = new media::MockVideoDecodeAccelerator;
55 EXPECT_CALL(*mock_gpu_factories_,
56 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _))
57 .WillOnce(Return(mock_vda_));
58 codec_.codecType = webrtc::kVideoCodecVP8;
59 EXPECT_EQ(true, rtc_decoder_->Initialize(codec_.codecType));
60 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1));
61 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
62 rtc_decoder_->RegisterDecodeCompleteCallback(this));
63 }
64
65 void NotifyResetDone() {
66 VLOG(2) << "NotifyResetDone";
67 vda_loop_proxy_->PostTask(FROM_HERE,
68 base::Bind(&RTCVideoDecoder::NotifyResetDone,
69 base::Unretained(rtc_decoder_.get())));
70 }
71
72 void RunUntilIdle() {
73 vda_loop_proxy_->PostTask(
74 FROM_HERE,
75 base::Bind(&RTCVideoDecoderTest::NotifyIdle, base::Unretained(this)));
76 idle_waiter_.Wait();
77 }
78
79 void NotifyIdle() { idle_waiter_.Signal(); }
80
81 protected:
82 media::MockGpuVideoDecoderFactories* mock_gpu_factories_;
83 media::MockVideoDecodeAccelerator* mock_vda_;
84 scoped_ptr<RTCVideoDecoder> rtc_decoder_;
85 webrtc::VideoCodec codec_;
86 int num_delivered_frames_;
87
88 private:
89 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_;
90 base::Thread vda_thread_;
91
92 base::Lock lock_;
93 base::WaitableEvent idle_waiter_;
94 };
95
96 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) {
97 codec_.codecType = webrtc::kVideoCodecVP8;
98 codec_.codecSpecific.VP8.feedbackModeOn = true;
99 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1));
100 }
101
102 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) {
103 webrtc::EncodedImage input_image;
104 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
105 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
106 }
107
108 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnIncompleteFrame) {
109 Initialize();
110 webrtc::EncodedImage input_image;
111 input_image._completeFrame = false;
112 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
113 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
114 }
115
116 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnMissingFrames) {
117 Initialize();
118 webrtc::EncodedImage input_image;
119 input_image._completeFrame = true;
120 bool missingFrames = true;
121 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
122 rtc_decoder_->Decode(input_image, missingFrames, NULL, NULL, 0));
123 }
124
125 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) {
126 Initialize();
127 EXPECT_CALL(*mock_vda_, Reset())
128 .WillRepeatedly(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
129 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset());
130 }
131
132 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) {
133 Initialize();
134 EXPECT_CALL(*mock_vda_, Destroy());
135 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release());
136 }
137
138 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698