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

Side by Side Diff: media/mojo/clients/mojo_audio_decoder_unittest.cc

Issue 2624213006: media: Fix MojoAudioDecoder reinitialization (Closed)
Patch Set: Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 102
103 void ConnectToService(mojom::AudioDecoderRequest request) { 103 void ConnectToService(mojom::AudioDecoderRequest request) {
104 DCHECK(service_task_runner_->BelongsToCurrentThread()); 104 DCHECK(service_task_runner_->BelongsToCurrentThread());
105 105
106 std::unique_ptr<StrictMock<MockAudioDecoder>> mock_audio_decoder( 106 std::unique_ptr<StrictMock<MockAudioDecoder>> mock_audio_decoder(
107 new StrictMock<MockAudioDecoder>()); 107 new StrictMock<MockAudioDecoder>());
108 mock_audio_decoder_ = mock_audio_decoder.get(); 108 mock_audio_decoder_ = mock_audio_decoder.get();
109 109
110 EXPECT_CALL(*mock_audio_decoder_, Initialize(_, _, _, _)) 110 EXPECT_CALL(*mock_audio_decoder_, Initialize(_, _, _, _))
111 .WillOnce(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(true))); 111 .WillRepeatedly(DoAll(SaveArg<3>(&output_cb_), RunCallback<2>(true)));
112 EXPECT_CALL(*mock_audio_decoder_, Decode(_, _)) 112 EXPECT_CALL(*mock_audio_decoder_, Decode(_, _))
113 .WillRepeatedly( 113 .WillRepeatedly(
114 DoAll(InvokeWithoutArgs(this, &MojoAudioDecoderTest::ReturnOutput), 114 DoAll(InvokeWithoutArgs(this, &MojoAudioDecoderTest::ReturnOutput),
115 RunCallback<1>(DecodeStatus::OK))); 115 RunCallback<1>(DecodeStatus::OK)));
116 EXPECT_CALL(*mock_audio_decoder_, Reset(_))
117 .WillRepeatedly(RunCallback<0>());
116 118
117 mojo::MakeStrongBinding(base::MakeUnique<MojoAudioDecoderService>( 119 mojo::MakeStrongBinding(base::MakeUnique<MojoAudioDecoderService>(
118 mojo_cdm_service_context_.GetWeakPtr(), 120 mojo_cdm_service_context_.GetWeakPtr(),
119 std::move(mock_audio_decoder)), 121 std::move(mock_audio_decoder)),
120 std::move(request)); 122 std::move(request));
121 } 123 }
122 124
123 void InitializeAndExpect(bool success) { 125 void InitializeAndExpect(bool success) {
124 DVLOG(1) << __func__ << ": success=" << success; 126 DVLOG(1) << __func__ << ": success=" << success;
125 EXPECT_CALL(*this, OnInitialized(success)) 127 EXPECT_CALL(*this, OnInitialized(success))
126 .WillOnce(InvokeWithoutArgs(this, &MojoAudioDecoderTest::QuitLoop)); 128 .WillOnce(InvokeWithoutArgs(this, &MojoAudioDecoderTest::QuitLoop));
127 129
128 AudioDecoderConfig audio_config(kCodecVorbis, kSampleFormat, kChannelLayout, 130 AudioDecoderConfig audio_config(kCodecVorbis, kSampleFormat, kChannelLayout,
129 kDefaultSampleRate, EmptyExtraData(), 131 kDefaultSampleRate, EmptyExtraData(),
130 Unencrypted()); 132 Unencrypted());
131 133
132 mojo_audio_decoder_->Initialize( 134 mojo_audio_decoder_->Initialize(
133 audio_config, nullptr, base::Bind(&MojoAudioDecoderTest::OnInitialized, 135 audio_config, nullptr, base::Bind(&MojoAudioDecoderTest::OnInitialized,
134 base::Unretained(this)), 136 base::Unretained(this)),
135 base::Bind(&MojoAudioDecoderTest::OnOutput, base::Unretained(this))); 137 base::Bind(&MojoAudioDecoderTest::OnOutput, base::Unretained(this)));
136 138
137 RunLoop(); 139 RunLoop();
138 } 140 }
139 141
140 void Initialize() { InitializeAndExpect(true); } 142 void Initialize() { InitializeAndExpect(true); }
141 143
144 void Reset() {
145 DVLOG(1) << __func__;
146 EXPECT_CALL(*this, OnReset())
147 .WillOnce(InvokeWithoutArgs(this, &MojoAudioDecoderTest::QuitLoop));
148
149 mojo_audio_decoder_->Reset(
150 base::Bind(&MojoAudioDecoderTest::OnReset, base::Unretained(this)));
151 RunLoop();
152 }
153
142 void ReturnOutput() { 154 void ReturnOutput() {
143 for (int i = 0; i < kOutputPerDecode; ++i) { 155 for (int i = 0; i < kOutputPerDecode; ++i) {
144 scoped_refptr<AudioBuffer> audio_buffer = MakeAudioBuffer<float>( 156 scoped_refptr<AudioBuffer> audio_buffer = MakeAudioBuffer<float>(
145 kSampleFormat, kChannelLayout, kChannels, kDefaultSampleRate, 1.0, 157 kSampleFormat, kChannelLayout, kChannels, kDefaultSampleRate, 1.0,
146 0.0f, 100, input_timestamp_helper_.GetTimestamp()); 158 0.0f, 100, input_timestamp_helper_.GetTimestamp());
147 input_timestamp_helper_.AddFrames(kDefaultFrameSize); 159 input_timestamp_helper_.AddFrames(kDefaultFrameSize);
148 output_cb_.Run(audio_buffer); 160 output_cb_.Run(audio_buffer);
149 } 161 }
150 } 162 }
151 163
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 int decode_count_ = 0; 216 int decode_count_ = 0;
205 217
206 private: 218 private:
207 DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoderTest); 219 DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoderTest);
208 }; 220 };
209 221
210 TEST_F(MojoAudioDecoderTest, Initialize_Success) { 222 TEST_F(MojoAudioDecoderTest, Initialize_Success) {
211 Initialize(); 223 Initialize();
212 } 224 }
213 225
226 TEST_F(MojoAudioDecoderTest, Reinitialize_Success) {
227 Initialize();
228 DecodeMultipleTimes(10);
229 Reset();
230
231 // Reinitialize MojoAudioDecoder.
232 Initialize();
233 }
234
214 // Makes sure all callbacks and client calls are called in order. See 235 // Makes sure all callbacks and client calls are called in order. See
215 // http://crbug.com/646054 236 // http://crbug.com/646054
216 TEST_F(MojoAudioDecoderTest, Decode_MultipleTimes) { 237 TEST_F(MojoAudioDecoderTest, Decode_MultipleTimes) {
217 Initialize(); 238 Initialize();
218 239
219 // Choose a large number of decodes per test on purpose to expose potential 240 // Choose a large number of decodes per test on purpose to expose potential
220 // out of order delivery of mojo messages. See http://crbug.com/646054 241 // out of order delivery of mojo messages. See http://crbug.com/646054
221 DecodeMultipleTimes(100); 242 DecodeMultipleTimes(100);
222 } 243 }
223 244
224 // TODO(xhwang): Add more tests. 245 // TODO(xhwang): Add more tests.
225 246
226 } // namespace media 247 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698