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

Side by Side Diff: media/renderers/audio_renderer_impl_unittest.cc

Issue 1447533006: media: Pass SetCdmReadyCB in {Audio|Video}Decoder::Initialize(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « media/filters/vpx_video_decoder.cc ('k') | media/renderers/video_renderer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/callback_helpers.h" 6 #include "base/callback_helpers.h"
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 static SampleFormat kSampleFormat = kSampleFormatPlanarF32; 47 static SampleFormat kSampleFormat = kSampleFormatPlanarF32;
48 static ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; 48 static ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO;
49 static int kChannelCount = 2; 49 static int kChannelCount = 2;
50 static int kChannels = ChannelLayoutToChannelCount(kChannelLayout); 50 static int kChannels = ChannelLayoutToChannelCount(kChannelLayout);
51 51
52 // Use a different output sample rate so the AudioBufferConverter is invoked. 52 // Use a different output sample rate so the AudioBufferConverter is invoked.
53 static int kInputSamplesPerSecond = 5000; 53 static int kInputSamplesPerSecond = 5000;
54 static int kOutputSamplesPerSecond = 10000; 54 static int kOutputSamplesPerSecond = 10000;
55 55
56 ACTION_P(EnterPendingDecoderInitStateAction, test) { 56 ACTION_P(EnterPendingDecoderInitStateAction, test) {
57 test->EnterPendingDecoderInitState(arg1); 57 test->EnterPendingDecoderInitState(arg2);
58 } 58 }
59 59
60 class AudioRendererImplTest : public ::testing::Test { 60 class AudioRendererImplTest : public ::testing::Test {
61 public: 61 public:
62 // Give the decoder some non-garbage media properties. 62 // Give the decoder some non-garbage media properties.
63 AudioRendererImplTest() 63 AudioRendererImplTest()
64 : hardware_config_(AudioParameters(), AudioParameters()), 64 : hardware_config_(AudioParameters(), AudioParameters()),
65 tick_clock_(new base::SimpleTestTickClock()), 65 tick_clock_(new base::SimpleTestTickClock()),
66 demuxer_stream_(DemuxerStream::AUDIO), 66 demuxer_stream_(DemuxerStream::AUDIO),
67 decoder_(new MockAudioDecoder()), 67 decoder_(new MockAudioDecoder()),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 new MediaLog())); 102 new MediaLog()));
103 renderer_->tick_clock_.reset(tick_clock_); 103 renderer_->tick_clock_.reset(tick_clock_);
104 tick_clock_->Advance(base::TimeDelta::FromSeconds(1)); 104 tick_clock_->Advance(base::TimeDelta::FromSeconds(1));
105 } 105 }
106 106
107 virtual ~AudioRendererImplTest() { 107 virtual ~AudioRendererImplTest() {
108 SCOPED_TRACE("~AudioRendererImplTest()"); 108 SCOPED_TRACE("~AudioRendererImplTest()");
109 } 109 }
110 110
111 void ExpectUnsupportedAudioDecoder() { 111 void ExpectUnsupportedAudioDecoder() {
112 EXPECT_CALL(*decoder_, Initialize(_, _, _)) 112 EXPECT_CALL(*decoder_, Initialize(_, _, _, _))
113 .WillOnce(DoAll(SaveArg<2>(&output_cb_), RunCallback<1>(false))); 113 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(false)));
114 } 114 }
115 115
116 void OnStatistics(const PipelineStatistics& stats) { 116 void OnStatistics(const PipelineStatistics& stats) {
117 last_statistics_.audio_memory_usage += stats.audio_memory_usage; 117 last_statistics_.audio_memory_usage += stats.audio_memory_usage;
118 } 118 }
119 119
120 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); 120 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState));
121 MOCK_METHOD1(OnError, void(PipelineStatus)); 121 MOCK_METHOD1(OnError, void(PipelineStatus));
122 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); 122 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void));
123 123
124 void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) { 124 void InitializeRenderer(const PipelineStatusCB& pipeline_status_cb) {
125 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); 125 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
126 renderer_->Initialize( 126 renderer_->Initialize(
127 &demuxer_stream_, pipeline_status_cb, SetCdmReadyCB(), 127 &demuxer_stream_, pipeline_status_cb, SetCdmReadyCB(),
128 base::Bind(&AudioRendererImplTest::OnStatistics, 128 base::Bind(&AudioRendererImplTest::OnStatistics,
129 base::Unretained(this)), 129 base::Unretained(this)),
130 base::Bind(&AudioRendererImplTest::OnBufferingStateChange, 130 base::Bind(&AudioRendererImplTest::OnBufferingStateChange,
131 base::Unretained(this)), 131 base::Unretained(this)),
132 base::Bind(&AudioRendererImplTest::OnEnded, base::Unretained(this)), 132 base::Bind(&AudioRendererImplTest::OnEnded, base::Unretained(this)),
133 base::Bind(&AudioRendererImplTest::OnError, base::Unretained(this)), 133 base::Bind(&AudioRendererImplTest::OnError, base::Unretained(this)),
134 base::Bind(&AudioRendererImplTest::OnWaitingForDecryptionKey, 134 base::Bind(&AudioRendererImplTest::OnWaitingForDecryptionKey,
135 base::Unretained(this))); 135 base::Unretained(this)));
136 } 136 }
137 137
138 void Initialize() { 138 void Initialize() {
139 EXPECT_CALL(*decoder_, Initialize(_, _, _)) 139 EXPECT_CALL(*decoder_, Initialize(_, _, _, _))
140 .WillOnce(DoAll(SaveArg<2>(&output_cb_), RunCallback<1>(true))); 140 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(true)));
141 InitializeWithStatus(PIPELINE_OK); 141 InitializeWithStatus(PIPELINE_OK);
142 142
143 next_timestamp_.reset(new AudioTimestampHelper(kInputSamplesPerSecond)); 143 next_timestamp_.reset(new AudioTimestampHelper(kInputSamplesPerSecond));
144 } 144 }
145 145
146 void InitializeWithStatus(PipelineStatus expected) { 146 void InitializeWithStatus(PipelineStatus expected) {
147 SCOPED_TRACE(base::StringPrintf("InitializeWithStatus(%d)", expected)); 147 SCOPED_TRACE(base::StringPrintf("InitializeWithStatus(%d)", expected));
148 148
149 WaitableMessageLoopEvent event; 149 WaitableMessageLoopEvent event;
150 InitializeRenderer(event.GetPipelineStatusCB()); 150 InitializeRenderer(event.GetPipelineStatusCB());
151 event.RunAndWaitForStatus(expected); 151 event.RunAndWaitForStatus(expected);
152 152
153 // We should have no reads. 153 // We should have no reads.
154 EXPECT_TRUE(decode_cb_.is_null()); 154 EXPECT_TRUE(decode_cb_.is_null());
155 } 155 }
156 156
157 void InitializeAndDestroy() { 157 void InitializeAndDestroy() {
158 EXPECT_CALL(*decoder_, Initialize(_, _, _)).WillOnce(RunCallback<1>(true)); 158 EXPECT_CALL(*decoder_, Initialize(_, _, _, _))
159 .WillOnce(RunCallback<2>(true));
159 160
160 WaitableMessageLoopEvent event; 161 WaitableMessageLoopEvent event;
161 InitializeRenderer(event.GetPipelineStatusCB()); 162 InitializeRenderer(event.GetPipelineStatusCB());
162 163
163 // Destroy the |renderer_| before we let the MessageLoop run, this simulates 164 // Destroy the |renderer_| before we let the MessageLoop run, this simulates
164 // an interleaving in which we end up destroying the |renderer_| while the 165 // an interleaving in which we end up destroying the |renderer_| while the
165 // OnDecoderSelected callback is in flight. 166 // OnDecoderSelected callback is in flight.
166 renderer_.reset(); 167 renderer_.reset();
167 event.RunAndWaitForStatus(PIPELINE_ERROR_ABORT); 168 event.RunAndWaitForStatus(PIPELINE_ERROR_ABORT);
168 } 169 }
169 170
170 void InitializeAndDestroyDuringDecoderInit() { 171 void InitializeAndDestroyDuringDecoderInit() {
171 EXPECT_CALL(*decoder_, Initialize(_, _, _)) 172 EXPECT_CALL(*decoder_, Initialize(_, _, _, _))
172 .WillOnce(EnterPendingDecoderInitStateAction(this)); 173 .WillOnce(EnterPendingDecoderInitStateAction(this));
173 174
174 WaitableMessageLoopEvent event; 175 WaitableMessageLoopEvent event;
175 InitializeRenderer(event.GetPipelineStatusCB()); 176 InitializeRenderer(event.GetPipelineStatusCB());
176 base::RunLoop().RunUntilIdle(); 177 base::RunLoop().RunUntilIdle();
177 DCHECK(!init_decoder_cb_.is_null()); 178 DCHECK(!init_decoder_cb_.is_null());
178 179
179 renderer_.reset(); 180 renderer_.reset();
180 event.RunAndWaitForStatus(PIPELINE_ERROR_ABORT); 181 event.RunAndWaitForStatus(PIPELINE_ERROR_ABORT);
181 } 182 }
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 // Advance far enough that we shouldn't be clamped to current time (tested 883 // Advance far enough that we shouldn't be clamped to current time (tested
883 // already above). 884 // already above).
884 tick_clock_->Advance(kOneSecond); 885 tick_clock_->Advance(kOneSecond);
885 EXPECT_EQ( 886 EXPECT_EQ(
886 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value), 887 current_time + timestamp_helper.GetFrameDuration(frames_to_consume.value),
887 CurrentMediaWallClockTime(&is_time_moving)); 888 CurrentMediaWallClockTime(&is_time_moving));
888 EXPECT_TRUE(is_time_moving); 889 EXPECT_TRUE(is_time_moving);
889 } 890 }
890 891
891 } // namespace media 892 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/vpx_video_decoder.cc ('k') | media/renderers/video_renderer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698