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

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: address review comments Created 7 years, 5 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 vda_thread_("vda_thread"),
30 idle_waiter_(false, false) {
31 memset(&codec_, 0, sizeof(codec_));
32 }
33
34 virtual void SetUp() OVERRIDE {
35 ASSERT_TRUE(vda_thread_.Start());
36 vda_loop_proxy_ = vda_thread_.message_loop_proxy();
37 mock_vda_ = new media::MockVideoDecodeAccelerator;
38 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop())
39 .WillRepeatedly(Return(vda_loop_proxy_));
40 EXPECT_CALL(*mock_gpu_factories_,
41 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _))
42 .WillOnce(Return(mock_vda_));
43 EXPECT_CALL(*mock_vda_, Destroy());
44 rtc_decoder_ = RTCVideoDecoder::Create(mock_gpu_factories_);
45 }
46
47 virtual void TearDown() OVERRIDE {
48 VLOG(2) << "TearDown";
49 if (vda_thread_.IsRunning()) {
50 RunUntilIdle(); // Wait until all callbascks complete.
51 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release());
52 // Make sure the decoder is released before stopping the thread.
53 RunUntilIdle();
54 vda_thread_.Stop();
55 } else {
56 rtc_decoder_.reset();
57 }
58 }
59
60 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE {
61 VLOG(2) << "Decoded";
62 EXPECT_EQ(vda_loop_proxy_, base::MessageLoopProxy::current());
63 return WEBRTC_VIDEO_CODEC_OK;
64 }
65
66 void Initialize() {
67 VLOG(2) << "Initialize";
68 codec_.codecType = webrtc::kVideoCodecVP8;
69 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1));
70 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
71 rtc_decoder_->RegisterDecodeCompleteCallback(this));
72 }
73
74 void NotifyResetDone() {
75 VLOG(2) << "NotifyResetDone";
76 vda_loop_proxy_->PostTask(FROM_HERE,
77 base::Bind(&RTCVideoDecoder::NotifyResetDone,
78 base::Unretained(rtc_decoder_.get())));
79 }
80
81 void RunUntilIdle() {
82 VLOG(2) << "RunUntilIdle";
83 vda_loop_proxy_->PostTask(FROM_HERE,
84 base::Bind(&base::WaitableEvent::Signal,
85 base::Unretained(&idle_waiter_)));
86 idle_waiter_.Wait();
87 }
88
89 protected:
90 scoped_refptr<media::MockGpuVideoDecoderFactories> mock_gpu_factories_;
91 media::MockVideoDecodeAccelerator* mock_vda_;
92 scoped_ptr<RTCVideoDecoder> rtc_decoder_;
93 webrtc::VideoCodec codec_;
94 base::Thread vda_thread_;
95
96 private:
97 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_;
98
99 base::Lock lock_;
100 base::WaitableEvent idle_waiter_;
101 };
102
103 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) {
104 codec_.codecType = webrtc::kVideoCodecVP8;
105 codec_.codecSpecific.VP8.feedbackModeOn = true;
106 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1));
107 }
108
109 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) {
110 webrtc::EncodedImage input_image;
111 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
112 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
113 }
114
115 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnIncompleteFrame) {
116 Initialize();
117 webrtc::EncodedImage input_image;
118 input_image._completeFrame = false;
119 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
120 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
121 }
122
123 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnMissingFrames) {
124 Initialize();
125 webrtc::EncodedImage input_image;
126 input_image._completeFrame = true;
127 bool missingFrames = true;
128 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
129 rtc_decoder_->Decode(input_image, missingFrames, NULL, NULL, 0));
130 }
131
132 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) {
133 Initialize();
134 EXPECT_CALL(*mock_vda_, Reset())
135 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
136 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset());
137 }
138
139 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) {
140 Initialize();
141 EXPECT_CALL(*mock_vda_, Reset())
142 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
143 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release());
144 }
145
146 TEST_F(RTCVideoDecoderTest, VdaThreadStops) {
147 EXPECT_CALL(*mock_gpu_factories_, Abort());
148 vda_thread_.Stop();
149 }
150
151 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698