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

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

Issue 19534002: Make RendererGpuVideoDecoderFactories live on arbitrary threads. (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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "content/renderer/media/rtc_video_decoder.h" 9 #include "content/renderer/media/rtc_video_decoder.h"
10 #include "media/base/gmock_callback_support.h" 10 #include "media/base/gmock_callback_support.h"
(...skipping 19 matching lines...) Expand all
30 idle_waiter_(false, false) { 30 idle_waiter_(false, false) {
31 memset(&codec_, 0, sizeof(codec_)); 31 memset(&codec_, 0, sizeof(codec_));
32 } 32 }
33 33
34 virtual void SetUp() OVERRIDE { 34 virtual void SetUp() OVERRIDE {
35 ASSERT_TRUE(vda_thread_.Start()); 35 ASSERT_TRUE(vda_thread_.Start());
36 vda_loop_proxy_ = vda_thread_.message_loop_proxy(); 36 vda_loop_proxy_ = vda_thread_.message_loop_proxy();
37 mock_vda_ = new media::MockVideoDecodeAccelerator; 37 mock_vda_ = new media::MockVideoDecodeAccelerator;
38 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop()) 38 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop())
39 .WillRepeatedly(Return(vda_loop_proxy_)); 39 .WillRepeatedly(Return(vda_loop_proxy_));
40 EXPECT_CALL(*mock_gpu_factories_, CreateVideoDecodeAccelerator(_, _))
41 .WillRepeatedly(
42 Return(static_cast<media::VideoDecodeAccelerator*>(NULL)));
40 EXPECT_CALL(*mock_gpu_factories_, 43 EXPECT_CALL(*mock_gpu_factories_,
41 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _)) 44 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _))
42 .WillOnce(Return(mock_vda_)); 45 .WillRepeatedly(Return(mock_vda_));
43 EXPECT_CALL(*mock_gpu_factories_, Abort()).WillRepeatedly(Return()); 46 EXPECT_CALL(*mock_gpu_factories_, Abort()).WillRepeatedly(Return());
44 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) 47 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_))
45 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); 48 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL)));
46 EXPECT_CALL(*mock_vda_, Destroy()); 49 EXPECT_CALL(*mock_vda_, Destroy());
47 rtc_decoder_ = RTCVideoDecoder::Create(mock_gpu_factories_); 50 rtc_decoder_ = RTCVideoDecoder::Create(
51 webrtc::kVideoCodecVP8, vda_loop_proxy_, mock_gpu_factories_);
48 } 52 }
49 53
50 virtual void TearDown() OVERRIDE { 54 virtual void TearDown() OVERRIDE {
51 VLOG(2) << "TearDown"; 55 VLOG(2) << "TearDown";
52 if (vda_thread_.IsRunning()) { 56 if (vda_thread_.IsRunning()) {
57 if (rtc_decoder_)
58 rtc_decoder_->Release();
53 RunUntilIdle(); // Wait until all callbascks complete. 59 RunUntilIdle(); // Wait until all callbascks complete.
54 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); 60 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release());
55 // Make sure the decoder is released before stopping the thread. 61 // Make sure the decoder is released before stopping the thread.
56 RunUntilIdle(); 62 RunUntilIdle();
57 vda_thread_.Stop(); 63 vda_thread_.Stop();
58 } else { 64 } else {
59 rtc_decoder_.reset(); 65 rtc_decoder_.reset();
60 } 66 }
61 } 67 }
62 68
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 webrtc::VideoCodec codec_; 102 webrtc::VideoCodec codec_;
97 base::Thread vda_thread_; 103 base::Thread vda_thread_;
98 104
99 private: 105 private:
100 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; 106 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_;
101 107
102 base::Lock lock_; 108 base::Lock lock_;
103 base::WaitableEvent idle_waiter_; 109 base::WaitableEvent idle_waiter_;
104 }; 110 };
105 111
112 TEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) {
113 scoped_ptr<RTCVideoDecoder> null_rtc_decoder(
114 RTCVideoDecoder::Create(webrtc::kVideoCodecI420,
115 vda_thread_.message_loop_proxy(),
116 mock_gpu_factories_));
117 EXPECT_EQ(NULL, null_rtc_decoder.get());
118 }
119
106 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) { 120 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) {
107 codec_.codecType = webrtc::kVideoCodecVP8; 121 codec_.codecType = webrtc::kVideoCodecVP8;
108 codec_.codecSpecific.VP8.feedbackModeOn = true; 122 codec_.codecSpecific.VP8.feedbackModeOn = true;
109 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1)); 123 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1));
110 } 124 }
111 125
112 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) { 126 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) {
113 webrtc::EncodedImage input_image; 127 webrtc::EncodedImage input_image;
114 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, 128 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
115 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); 129 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
(...skipping 18 matching lines...) Expand all
134 148
135 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) { 149 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) {
136 Initialize(); 150 Initialize();
137 EXPECT_CALL(*mock_vda_, Reset()) 151 EXPECT_CALL(*mock_vda_, Reset())
138 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); 152 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
139 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset()); 153 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset());
140 } 154 }
141 155
142 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) { 156 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) {
143 Initialize(); 157 Initialize();
144 EXPECT_CALL(*mock_vda_, Reset())
145 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
146 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); 158 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release());
147 } 159 }
148 160
Ami GONE FROM CHROMIUM 2013/07/22 19:46:21 Where's the test that multiple decoders can be cre
wuchengli 2013/07/23 16:29:28 Good point. That should be a new test file because
149 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); } 161 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); }
150 162
151 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { 163 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) {
152 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); 164 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID));
153 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 165 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
154 RTCVideoDecoder::ID_INVALID)); 166 RTCVideoDecoder::ID_INVALID));
155 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, 167 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2,
156 RTCVideoDecoder::ID_HALF + 2)); 168 RTCVideoDecoder::ID_HALF + 2));
157 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF + 2, 169 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF + 2,
158 RTCVideoDecoder::ID_HALF - 2)); 170 RTCVideoDecoder::ID_HALF - 2));
159 171
160 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(0, 0)); 172 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(0, 0));
161 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); 173 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_LAST));
162 EXPECT_FALSE( 174 EXPECT_FALSE(
163 rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF - 2)); 175 rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF - 2));
164 EXPECT_TRUE( 176 EXPECT_TRUE(
165 rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF + 2)); 177 rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF + 2));
166 178
167 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); 179 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0));
168 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 180 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
169 RTCVideoDecoder::ID_HALF - 2)); 181 RTCVideoDecoder::ID_HALF - 2));
170 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 182 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
171 RTCVideoDecoder::ID_HALF + 2)); 183 RTCVideoDecoder::ID_HALF + 2));
172 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 184 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
173 RTCVideoDecoder::ID_LAST)); 185 RTCVideoDecoder::ID_LAST));
174 } 186 }
175 187
176 } // content 188 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698