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

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_ =
51 RTCVideoDecoder::Create(webrtc::kVideoCodecVP8, vda_loop_proxy_,
52 mock_gpu_factories_);
48 } 53 }
49 54
50 virtual void TearDown() OVERRIDE { 55 virtual void TearDown() OVERRIDE {
51 VLOG(2) << "TearDown"; 56 VLOG(2) << "TearDown";
52 if (vda_thread_.IsRunning()) { 57 if (vda_thread_.IsRunning()) {
58 if (rtc_decoder_)
59 rtc_decoder_->Release();
53 RunUntilIdle(); // Wait until all callbascks complete. 60 RunUntilIdle(); // Wait until all callbascks complete.
54 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); 61 vda_loop_proxy_->DeleteSoon(FROM_HERE, rtc_decoder_.release());
55 // Make sure the decoder is released before stopping the thread. 62 // Make sure the decoder is released before stopping the thread.
56 RunUntilIdle(); 63 RunUntilIdle();
57 vda_thread_.Stop(); 64 vda_thread_.Stop();
58 } else { 65 } else {
59 rtc_decoder_.reset(); 66 rtc_decoder_.reset();
60 } 67 }
61 } 68 }
62 69
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 webrtc::VideoCodec codec_; 103 webrtc::VideoCodec codec_;
97 base::Thread vda_thread_; 104 base::Thread vda_thread_;
98 105
99 private: 106 private:
100 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; 107 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_;
101 108
102 base::Lock lock_; 109 base::Lock lock_;
103 base::WaitableEvent idle_waiter_; 110 base::WaitableEvent idle_waiter_;
104 }; 111 };
105 112
113 TEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) {
114 scoped_ptr<RTCVideoDecoder> null_rtc_decoder(
115 RTCVideoDecoder::Create(webrtc::kVideoCodecI420,
116 vda_thread_.message_loop_proxy(),
117 mock_gpu_factories_));
118 EXPECT_EQ(NULL, null_rtc_decoder.get());
119 }
120
106 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) { 121 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) {
107 codec_.codecType = webrtc::kVideoCodecVP8; 122 codec_.codecType = webrtc::kVideoCodecVP8;
108 codec_.codecSpecific.VP8.feedbackModeOn = true; 123 codec_.codecSpecific.VP8.feedbackModeOn = true;
109 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1)); 124 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1));
110 } 125 }
111 126
112 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) { 127 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) {
113 webrtc::EncodedImage input_image; 128 webrtc::EncodedImage input_image;
114 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, 129 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
115 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); 130 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
(...skipping 18 matching lines...) Expand all
134 149
135 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) { 150 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) {
136 Initialize(); 151 Initialize();
137 EXPECT_CALL(*mock_vda_, Reset()) 152 EXPECT_CALL(*mock_vda_, Reset())
138 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); 153 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
139 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset()); 154 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset());
140 } 155 }
141 156
142 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) { 157 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) {
143 Initialize(); 158 Initialize();
144 EXPECT_CALL(*mock_vda_, Reset())
145 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
146 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); 159 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release());
147 } 160 }
148 161
149 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); } 162 TEST_F(RTCVideoDecoderTest, VdaThreadStops) { vda_thread_.Stop(); }
150 163
151 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { 164 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) {
152 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); 165 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID));
153 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 166 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
154 RTCVideoDecoder::ID_INVALID)); 167 RTCVideoDecoder::ID_INVALID));
155 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, 168 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2,
(...skipping 11 matching lines...) Expand all
167 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); 180 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0));
168 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 181 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
169 RTCVideoDecoder::ID_HALF - 2)); 182 RTCVideoDecoder::ID_HALF - 2));
170 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 183 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
171 RTCVideoDecoder::ID_HALF + 2)); 184 RTCVideoDecoder::ID_HALF + 2));
172 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 185 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
173 RTCVideoDecoder::ID_LAST)); 186 RTCVideoDecoder::ID_LAST));
174 } 187 }
175 188
176 } // content 189 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698