| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/media/audio/cast_audio_output_stream.h" | 5 #include "chromecast/media/audio/cast_audio_output_stream.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | |
| 14 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/thread_task_runner_handle.h" | |
| 16 #include "chromecast/base/metrics/cast_metrics_test_helper.h" | 14 #include "chromecast/base/metrics/cast_metrics_test_helper.h" |
| 17 #include "chromecast/media/audio/cast_audio_manager.h" | 15 #include "chromecast/media/audio/cast_audio_manager.h" |
| 18 #include "chromecast/media/base/media_message_loop.h" | 16 #include "chromecast/media/base/media_message_loop.h" |
| 19 #include "chromecast/media/cma/backend/media_pipeline_backend_default.h" | 17 #include "chromecast/media/cma/backend/media_pipeline_backend_default.h" |
| 20 #include "chromecast/public/media/cast_decoder_buffer.h" | 18 #include "chromecast/public/media/cast_decoder_buffer.h" |
| 21 #include "chromecast/public/media/decoder_config.h" | 19 #include "chromecast/public/media/decoder_config.h" |
| 22 #include "chromecast/public/media/decrypt_context.h" | 20 #include "chromecast/public/media/decrypt_context.h" |
| 23 #include "chromecast/public/media/media_pipeline_backend.h" | 21 #include "chromecast/public/media/media_pipeline_backend.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 23 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return audio_bus->frames(); | 177 return audio_bus->frames(); |
| 180 } | 178 } |
| 181 void OnError(::media::AudioOutputStream* stream) override { error_ = true; } | 179 void OnError(::media::AudioOutputStream* stream) override { error_ = true; } |
| 182 | 180 |
| 183 private: | 181 private: |
| 184 bool error_; | 182 bool error_; |
| 185 }; | 183 }; |
| 186 | 184 |
| 187 class FakeAudioManager : public CastAudioManager { | 185 class FakeAudioManager : public CastAudioManager { |
| 188 public: | 186 public: |
| 189 FakeAudioManager(scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 187 FakeAudioManager() |
| 190 : CastAudioManager(task_runner, task_runner, nullptr, nullptr), | 188 : CastAudioManager(nullptr, nullptr), media_pipeline_backend_(nullptr) {} |
| 191 media_pipeline_backend_(nullptr) {} | |
| 192 ~FakeAudioManager() override {} | 189 ~FakeAudioManager() override {} |
| 193 | 190 |
| 194 // CastAudioManager overrides. | 191 // CastAudioManager overrides. |
| 195 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( | 192 std::unique_ptr<MediaPipelineBackend> CreateMediaPipelineBackend( |
| 196 const MediaPipelineDeviceParams& params) override { | 193 const MediaPipelineDeviceParams& params) override { |
| 197 DCHECK(media::MediaMessageLoop::GetTaskRunner()->BelongsToCurrentThread()); | 194 DCHECK(media::MediaMessageLoop::GetTaskRunner()->BelongsToCurrentThread()); |
| 198 DCHECK(!media_pipeline_backend_); | 195 DCHECK(!media_pipeline_backend_); |
| 199 | 196 |
| 200 std::unique_ptr<FakeMediaPipelineBackend> backend( | 197 std::unique_ptr<FakeMediaPipelineBackend> backend( |
| 201 new FakeMediaPipelineBackend()); | 198 new FakeMediaPipelineBackend()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 227 channel_layout_(::media::CHANNEL_LAYOUT_MONO), | 224 channel_layout_(::media::CHANNEL_LAYOUT_MONO), |
| 228 sample_rate_(::media::AudioParameters::kAudioCDSampleRate), | 225 sample_rate_(::media::AudioParameters::kAudioCDSampleRate), |
| 229 bits_per_sample_(16), | 226 bits_per_sample_(16), |
| 230 frames_per_buffer_(256) {} | 227 frames_per_buffer_(256) {} |
| 231 ~CastAudioOutputStreamTest() override {} | 228 ~CastAudioOutputStreamTest() override {} |
| 232 | 229 |
| 233 protected: | 230 protected: |
| 234 void SetUp() override { | 231 void SetUp() override { |
| 235 metrics::InitializeMetricsHelperForTesting(); | 232 metrics::InitializeMetricsHelperForTesting(); |
| 236 | 233 |
| 237 audio_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 234 audio_manager_.reset(new FakeAudioManager); |
| 235 audio_task_runner_ = audio_manager_->GetTaskRunner(); |
| 238 backend_task_runner_ = media::MediaMessageLoop::GetTaskRunner(); | 236 backend_task_runner_ = media::MediaMessageLoop::GetTaskRunner(); |
| 239 audio_manager_.reset(new FakeAudioManager(audio_task_runner_)); | |
| 240 } | 237 } |
| 241 | 238 |
| 242 void TearDown() override { | 239 void TearDown() override { |
| 243 audio_manager_.reset(); | 240 audio_manager_.reset(); |
| 244 } | 241 } |
| 245 | 242 |
| 246 ::media::AudioParameters GetAudioParams() { | 243 ::media::AudioParameters GetAudioParams() { |
| 247 return ::media::AudioParameters(format_, channel_layout_, sample_rate_, | 244 return ::media::AudioParameters(format_, channel_layout_, sample_rate_, |
| 248 bits_per_sample_, frames_per_buffer_); | 245 bits_per_sample_, frames_per_buffer_); |
| 249 } | 246 } |
| 250 | 247 |
| 251 FakeMediaPipelineBackend* GetBackend() { | 248 FakeMediaPipelineBackend* GetBackend() { |
| 252 return audio_manager_->media_pipeline_backend(); | 249 return audio_manager_->media_pipeline_backend(); |
| 253 } | 250 } |
| 254 | 251 |
| 255 FakeAudioDecoder* GetAudio() { | 252 FakeAudioDecoder* GetAudio() { |
| 256 FakeMediaPipelineBackend* backend = GetBackend(); | 253 FakeMediaPipelineBackend* backend = GetBackend(); |
| 257 return (backend ? backend->decoder() : nullptr); | 254 return (backend ? backend->decoder() : nullptr); |
| 258 } | 255 } |
| 259 | 256 |
| 260 // Synchronous utility functions. | 257 // Synchronous utility functions. |
| 261 ::media::AudioOutputStream* CreateStream() { | 258 ::media::AudioOutputStream* CreateStream() { |
| 262 return audio_manager_->MakeAudioOutputStream(GetAudioParams(), | 259 ::media::AudioOutputStream* stream = nullptr; |
| 263 kDefaultDeviceId); | 260 |
| 261 base::WaitableEvent completion_event(false, false); |
| 262 audio_task_runner_->PostTask( |
| 263 FROM_HERE, |
| 264 base::Bind(&CastAudioOutputStreamTest::CreateStreamOnAudioThread, |
| 265 base::Unretained(this), GetAudioParams(), &stream, |
| 266 &completion_event)); |
| 267 completion_event.Wait(); |
| 268 |
| 269 return stream; |
| 264 } | 270 } |
| 265 bool OpenStream(::media::AudioOutputStream* stream) { | 271 bool OpenStream(::media::AudioOutputStream* stream) { |
| 266 bool success = stream->Open(); | 272 DCHECK(stream); |
| 273 |
| 274 bool success = false; |
| 275 base::WaitableEvent completion_event(false, false); |
| 276 audio_task_runner_->PostTask( |
| 277 FROM_HERE, |
| 278 base::Bind(&CastAudioOutputStreamTest::OpenStreamOnAudioThread, |
| 279 base::Unretained(this), stream, &success, |
| 280 &completion_event)); |
| 281 completion_event.Wait(); |
| 282 |
| 267 // Drain the backend task runner so that appropriate states are set on | 283 // Drain the backend task runner so that appropriate states are set on |
| 268 // the backend pipeline devices. | 284 // the backend pipeline devices. |
| 269 RunUntilIdle(backend_task_runner_.get()); | 285 RunUntilIdle(backend_task_runner_.get()); |
| 270 return success; | 286 return success; |
| 271 } | 287 } |
| 272 void CloseStream(::media::AudioOutputStream* stream) { | 288 void CloseStream(::media::AudioOutputStream* stream) { |
| 273 stream->Close(); | 289 audio_task_runner_->PostTask(FROM_HERE, |
| 290 base::Bind(&::media::AudioOutputStream::Close, |
| 291 base::Unretained(stream))); |
| 292 RunUntilIdle(audio_task_runner_.get()); |
| 274 RunUntilIdle(backend_task_runner_.get()); | 293 RunUntilIdle(backend_task_runner_.get()); |
| 275 // Backend task runner may have posted more tasks to the audio task runner. | 294 // Backend task runner may have posted more tasks to the audio task runner. |
| 276 // So we need to drain it once more. | 295 // So we need to drain it once more. |
| 277 message_loop_.RunUntilIdle(); | 296 RunUntilIdle(audio_task_runner_.get()); |
| 278 } | 297 } |
| 279 void StartStream( | 298 void StartStream( |
| 280 ::media::AudioOutputStream* stream, | 299 ::media::AudioOutputStream* stream, |
| 281 ::media::AudioOutputStream::AudioSourceCallback* source_callback) { | 300 ::media::AudioOutputStream::AudioSourceCallback* source_callback) { |
| 282 stream->Start(source_callback); | 301 audio_task_runner_->PostTask( |
| 283 // Drain the audio task runner so that tasks posted by | 302 FROM_HERE, base::Bind(&::media::AudioOutputStream::Start, |
| 303 base::Unretained(stream), source_callback)); |
| 304 // Drain the audio task runner twice so that tasks posted by |
| 284 // media::AudioOutputStream::Start are run as well. | 305 // media::AudioOutputStream::Start are run as well. |
| 285 message_loop_.RunUntilIdle(); | 306 RunUntilIdle(audio_task_runner_.get()); |
| 307 RunUntilIdle(audio_task_runner_.get()); |
| 286 // Drain the backend task runner so that appropriate states are set on | 308 // Drain the backend task runner so that appropriate states are set on |
| 287 // the backend pipeline devices. | 309 // the backend pipeline devices. |
| 288 RunUntilIdle(backend_task_runner_.get()); | 310 RunUntilIdle(backend_task_runner_.get()); |
| 289 // Drain the audio task runner again to run the tasks posted by the | 311 // Drain the audio task runner again to run the tasks posted by the |
| 290 // backend on audio task runner. | 312 // backend on audio task runner. |
| 291 message_loop_.RunUntilIdle(); | 313 RunUntilIdle(audio_task_runner_.get()); |
| 292 } | 314 } |
| 293 void StopStream(::media::AudioOutputStream* stream) { | 315 void StopStream(::media::AudioOutputStream* stream) { |
| 294 stream->Stop(); | 316 audio_task_runner_->PostTask(FROM_HERE, |
| 317 base::Bind(&::media::AudioOutputStream::Stop, |
| 318 base::Unretained(stream))); |
| 319 RunUntilIdle(audio_task_runner_.get()); |
| 295 // Drain the backend task runner so that appropriate states are set on | 320 // Drain the backend task runner so that appropriate states are set on |
| 296 // the backend pipeline devices. | 321 // the backend pipeline devices. |
| 297 RunUntilIdle(backend_task_runner_.get()); | 322 RunUntilIdle(backend_task_runner_.get()); |
| 298 } | 323 } |
| 299 void SetStreamVolume(::media::AudioOutputStream* stream, double volume) { | 324 void SetStreamVolume(::media::AudioOutputStream* stream, double volume) { |
| 300 stream->SetVolume(volume); | 325 audio_task_runner_->PostTask( |
| 326 FROM_HERE, base::Bind(&::media::AudioOutputStream::SetVolume, |
| 327 base::Unretained(stream), volume)); |
| 328 RunUntilIdle(audio_task_runner_.get()); |
| 301 // Drain the backend task runner so that appropriate states are set on | 329 // Drain the backend task runner so that appropriate states are set on |
| 302 // the backend pipeline devices. | 330 // the backend pipeline devices. |
| 303 RunUntilIdle(backend_task_runner_.get()); | 331 RunUntilIdle(backend_task_runner_.get()); |
| 304 } | 332 } |
| 305 double GetStreamVolume(::media::AudioOutputStream* stream) { | 333 double GetStreamVolume(::media::AudioOutputStream* stream) { |
| 306 double volume = 0.0; | 334 double volume = 0.0; |
| 307 stream->GetVolume(&volume); | 335 audio_task_runner_->PostTask( |
| 336 FROM_HERE, base::Bind(&::media::AudioOutputStream::GetVolume, |
| 337 base::Unretained(stream), &volume)); |
| 338 RunUntilIdle(audio_task_runner_.get()); |
| 308 // No need to drain the backend task runner because getting the volume | 339 // No need to drain the backend task runner because getting the volume |
| 309 // does not involve posting any task to the backend. | 340 // does not involve posting any task to the backend. |
| 310 return volume; | 341 return volume; |
| 311 } | 342 } |
| 312 | 343 |
| 313 void RunAudioLoopFor(int frames) { | 344 void CreateStreamOnAudioThread(const ::media::AudioParameters& audio_params, |
| 314 ::media::AudioParameters audio_params = GetAudioParams(); | 345 ::media::AudioOutputStream** stream, |
| 315 base::TimeDelta duration = audio_params.GetBufferDuration() * frames; | 346 base::WaitableEvent* completion_event) { |
| 316 | 347 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
| 317 base::RunLoop run_loop; | 348 *stream = audio_manager_->MakeAudioOutputStream(GetAudioParams(), |
| 318 message_loop_.task_runner()->PostDelayedTask( | 349 kDefaultDeviceId); |
| 319 FROM_HERE, run_loop.QuitClosure(), duration); | 350 completion_event->Signal(); |
| 320 run_loop.Run(); | 351 } |
| 352 void OpenStreamOnAudioThread(::media::AudioOutputStream* stream, |
| 353 bool* success, |
| 354 base::WaitableEvent* completion_event) { |
| 355 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
| 356 *success = stream->Open(); |
| 357 completion_event->Signal(); |
| 321 } | 358 } |
| 322 | 359 |
| 323 base::MessageLoop message_loop_; | |
| 324 std::unique_ptr<FakeAudioManager> audio_manager_; | 360 std::unique_ptr<FakeAudioManager> audio_manager_; |
| 325 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; | 361 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
| 326 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_; | 362 scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner_; |
| 327 | 363 |
| 328 // AudioParameters used to create AudioOutputStream. | 364 // AudioParameters used to create AudioOutputStream. |
| 329 // Tests can modify these parameters before calling CreateStream. | 365 // Tests can modify these parameters before calling CreateStream. |
| 330 ::media::AudioParameters::Format format_; | 366 ::media::AudioParameters::Format format_; |
| 331 ::media::ChannelLayout channel_layout_; | 367 ::media::ChannelLayout channel_layout_; |
| 332 int sample_rate_; | 368 int sample_rate_; |
| 333 int bits_per_sample_; | 369 int bits_per_sample_; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 469 |
| 434 FakeAudioDecoder* audio_decoder = GetAudio(); | 470 FakeAudioDecoder* audio_decoder = GetAudio(); |
| 435 ASSERT_TRUE(audio_decoder); | 471 ASSERT_TRUE(audio_decoder); |
| 436 // Verify initial state. | 472 // Verify initial state. |
| 437 EXPECT_EQ(0u, audio_decoder->pushed_buffer_count()); | 473 EXPECT_EQ(0u, audio_decoder->pushed_buffer_count()); |
| 438 EXPECT_FALSE(audio_decoder->last_buffer()); | 474 EXPECT_FALSE(audio_decoder->last_buffer()); |
| 439 | 475 |
| 440 std::unique_ptr<FakeAudioSourceCallback> source_callback( | 476 std::unique_ptr<FakeAudioSourceCallback> source_callback( |
| 441 new FakeAudioSourceCallback); | 477 new FakeAudioSourceCallback); |
| 442 StartStream(stream, source_callback.get()); | 478 StartStream(stream, source_callback.get()); |
| 443 RunAudioLoopFor(2); | |
| 444 StopStream(stream); | 479 StopStream(stream); |
| 445 | 480 |
| 446 // Verify that the stream pushed frames to the backend. | 481 // Verify that the stream pushed frames to the backend. |
| 447 EXPECT_LT(0u, audio_decoder->pushed_buffer_count()); | 482 EXPECT_LT(0u, audio_decoder->pushed_buffer_count()); |
| 448 EXPECT_TRUE(audio_decoder->last_buffer()); | 483 EXPECT_TRUE(audio_decoder->last_buffer()); |
| 449 | 484 |
| 450 // Verify decoder buffer. | 485 // Verify decoder buffer. |
| 451 ::media::AudioParameters audio_params = GetAudioParams(); | 486 ::media::AudioParameters audio_params = GetAudioParams(); |
| 452 const size_t expected_frame_size = | 487 const size_t expected_frame_size = |
| 453 static_cast<size_t>(audio_params.GetBytesPerBuffer()); | 488 static_cast<size_t>(audio_params.GetBytesPerBuffer()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 476 new FakeAudioSourceCallback); | 511 new FakeAudioSourceCallback); |
| 477 StartStream(stream, source_callback.get()); | 512 StartStream(stream, source_callback.get()); |
| 478 | 513 |
| 479 // Make sure that one frame was pushed. | 514 // Make sure that one frame was pushed. |
| 480 EXPECT_EQ(1u, audio_decoder->pushed_buffer_count()); | 515 EXPECT_EQ(1u, audio_decoder->pushed_buffer_count()); |
| 481 // No error must be reported to source callback. | 516 // No error must be reported to source callback. |
| 482 EXPECT_FALSE(source_callback->error()); | 517 EXPECT_FALSE(source_callback->error()); |
| 483 | 518 |
| 484 // Sleep for a few frames and verify that more frames were not pushed | 519 // Sleep for a few frames and verify that more frames were not pushed |
| 485 // because the backend device was busy. | 520 // because the backend device was busy. |
| 486 RunAudioLoopFor(5); | 521 ::media::AudioParameters audio_params = GetAudioParams(); |
| 522 base::TimeDelta pause = audio_params.GetBufferDuration() * 5; |
| 523 base::PlatformThread::Sleep(pause); |
| 524 RunUntilIdle(audio_task_runner_.get()); |
| 487 RunUntilIdle(backend_task_runner_.get()); | 525 RunUntilIdle(backend_task_runner_.get()); |
| 488 EXPECT_EQ(1u, audio_decoder->pushed_buffer_count()); | 526 EXPECT_EQ(1u, audio_decoder->pushed_buffer_count()); |
| 489 | 527 |
| 490 // Unblock the pipeline and verify that PushFrame resumes. | 528 // Unblock the pipeline and verify that PushFrame resumes. |
| 491 // (have to post because this directly calls buffer complete) | 529 // (have to post because this directly calls buffer complete) |
| 492 backend_task_runner_->PostTask( | 530 backend_task_runner_->PostTask( |
| 493 FROM_HERE, | 531 FROM_HERE, |
| 494 base::Bind(&FakeAudioDecoder::set_pipeline_status, | 532 base::Bind(&FakeAudioDecoder::set_pipeline_status, |
| 495 base::Unretained(audio_decoder), | 533 base::Unretained(audio_decoder), |
| 496 FakeAudioDecoder::PIPELINE_STATUS_OK)); | 534 FakeAudioDecoder::PIPELINE_STATUS_OK)); |
| 497 RunAudioLoopFor(5); | 535 |
| 536 base::PlatformThread::Sleep(pause); |
| 537 RunUntilIdle(audio_task_runner_.get()); |
| 498 RunUntilIdle(backend_task_runner_.get()); | 538 RunUntilIdle(backend_task_runner_.get()); |
| 499 EXPECT_LT(1u, audio_decoder->pushed_buffer_count()); | 539 EXPECT_LT(1u, audio_decoder->pushed_buffer_count()); |
| 500 EXPECT_FALSE(source_callback->error()); | 540 EXPECT_FALSE(source_callback->error()); |
| 501 | 541 |
| 502 StopStream(stream); | 542 StopStream(stream); |
| 503 CloseStream(stream); | 543 CloseStream(stream); |
| 504 } | 544 } |
| 505 | 545 |
| 506 TEST_F(CastAudioOutputStreamTest, DeviceError) { | 546 TEST_F(CastAudioOutputStreamTest, DeviceError) { |
| 507 ::media::AudioOutputStream* stream = CreateStream(); | 547 ::media::AudioOutputStream* stream = CreateStream(); |
| 508 ASSERT_TRUE(stream); | 548 ASSERT_TRUE(stream); |
| 509 EXPECT_TRUE(OpenStream(stream)); | 549 EXPECT_TRUE(OpenStream(stream)); |
| 510 | 550 |
| 511 FakeAudioDecoder* audio_decoder = GetAudio(); | 551 FakeAudioDecoder* audio_decoder = GetAudio(); |
| 512 ASSERT_TRUE(audio_decoder); | 552 ASSERT_TRUE(audio_decoder); |
| 513 audio_decoder->set_pipeline_status(FakeAudioDecoder::PIPELINE_STATUS_ERROR); | 553 audio_decoder->set_pipeline_status(FakeAudioDecoder::PIPELINE_STATUS_ERROR); |
| 514 | 554 |
| 515 std::unique_ptr<FakeAudioSourceCallback> source_callback( | 555 std::unique_ptr<FakeAudioSourceCallback> source_callback( |
| 516 new FakeAudioSourceCallback); | 556 new FakeAudioSourceCallback); |
| 517 StartStream(stream, source_callback.get()); | 557 StartStream(stream, source_callback.get()); |
| 518 RunAudioLoopFor(2); | |
| 519 | 558 |
| 520 // Make sure that AudioOutputStream attempted to push the initial frame. | 559 // Make sure that AudioOutputStream attempted to push the initial frame. |
| 521 EXPECT_LT(0u, audio_decoder->pushed_buffer_count()); | 560 EXPECT_LT(0u, audio_decoder->pushed_buffer_count()); |
| 522 // AudioOutputStream must report error to source callback. | 561 // AudioOutputStream must report error to source callback. |
| 523 EXPECT_TRUE(source_callback->error()); | 562 EXPECT_TRUE(source_callback->error()); |
| 524 | 563 |
| 525 StopStream(stream); | 564 StopStream(stream); |
| 526 CloseStream(stream); | 565 CloseStream(stream); |
| 527 } | 566 } |
| 528 | 567 |
| 529 TEST_F(CastAudioOutputStreamTest, DeviceAsyncError) { | 568 TEST_F(CastAudioOutputStreamTest, DeviceAsyncError) { |
| 530 ::media::AudioOutputStream* stream = CreateStream(); | 569 ::media::AudioOutputStream* stream = CreateStream(); |
| 531 ASSERT_TRUE(stream); | 570 ASSERT_TRUE(stream); |
| 532 EXPECT_TRUE(OpenStream(stream)); | 571 EXPECT_TRUE(OpenStream(stream)); |
| 533 | 572 |
| 534 FakeAudioDecoder* audio_decoder = GetAudio(); | 573 FakeAudioDecoder* audio_decoder = GetAudio(); |
| 535 ASSERT_TRUE(audio_decoder); | 574 ASSERT_TRUE(audio_decoder); |
| 536 audio_decoder->set_pipeline_status( | 575 audio_decoder->set_pipeline_status( |
| 537 FakeAudioDecoder::PIPELINE_STATUS_ASYNC_ERROR); | 576 FakeAudioDecoder::PIPELINE_STATUS_ASYNC_ERROR); |
| 538 | 577 |
| 539 std::unique_ptr<FakeAudioSourceCallback> source_callback( | 578 std::unique_ptr<FakeAudioSourceCallback> source_callback( |
| 540 new FakeAudioSourceCallback); | 579 new FakeAudioSourceCallback); |
| 541 StartStream(stream, source_callback.get()); | 580 StartStream(stream, source_callback.get()); |
| 542 RunAudioLoopFor(5); | |
| 543 | 581 |
| 544 // Make sure that one frame was pushed. | 582 // Make sure that one frame was pushed. |
| 545 EXPECT_EQ(1u, audio_decoder->pushed_buffer_count()); | 583 EXPECT_EQ(1u, audio_decoder->pushed_buffer_count()); |
| 546 | 584 |
| 547 // Unblock the pipeline and verify that PushFrame resumes. | 585 // Unblock the pipeline and verify that PushFrame resumes. |
| 548 // (have to post because this directly calls buffer complete) | 586 // (have to post because this directly calls buffer complete) |
| 549 backend_task_runner_->PostTask( | 587 backend_task_runner_->PostTask( |
| 550 FROM_HERE, | 588 FROM_HERE, |
| 551 base::Bind(&FakeAudioDecoder::set_pipeline_status, | 589 base::Bind(&FakeAudioDecoder::set_pipeline_status, |
| 552 base::Unretained(audio_decoder), | 590 base::Unretained(audio_decoder), |
| 553 FakeAudioDecoder::PIPELINE_STATUS_OK)); | 591 FakeAudioDecoder::PIPELINE_STATUS_OK)); |
| 554 | 592 |
| 555 RunAudioLoopFor(5); | 593 RunUntilIdle(audio_task_runner_.get()); |
| 556 RunUntilIdle(backend_task_runner_.get()); | 594 RunUntilIdle(backend_task_runner_.get()); |
| 557 // AudioOutputStream must report error to source callback. | 595 // AudioOutputStream must report error to source callback. |
| 558 EXPECT_TRUE(source_callback->error()); | 596 EXPECT_TRUE(source_callback->error()); |
| 559 | 597 |
| 560 StopStream(stream); | 598 StopStream(stream); |
| 561 CloseStream(stream); | 599 CloseStream(stream); |
| 562 } | 600 } |
| 563 | 601 |
| 564 TEST_F(CastAudioOutputStreamTest, Volume) { | 602 TEST_F(CastAudioOutputStreamTest, Volume) { |
| 565 ::media::AudioOutputStream* stream = CreateStream(); | 603 ::media::AudioOutputStream* stream = CreateStream(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 580 CloseStream(stream); | 618 CloseStream(stream); |
| 581 } | 619 } |
| 582 | 620 |
| 583 TEST_F(CastAudioOutputStreamTest, StartStopStart) { | 621 TEST_F(CastAudioOutputStreamTest, StartStopStart) { |
| 584 ::media::AudioOutputStream* stream = CreateStream(); | 622 ::media::AudioOutputStream* stream = CreateStream(); |
| 585 ASSERT_TRUE(stream); | 623 ASSERT_TRUE(stream); |
| 586 ASSERT_TRUE(OpenStream(stream)); | 624 ASSERT_TRUE(OpenStream(stream)); |
| 587 | 625 |
| 588 std::unique_ptr<FakeAudioSourceCallback> source_callback( | 626 std::unique_ptr<FakeAudioSourceCallback> source_callback( |
| 589 new FakeAudioSourceCallback); | 627 new FakeAudioSourceCallback); |
| 590 stream->Start(source_callback.get()); | 628 audio_task_runner_->PostTask( |
| 591 RunAudioLoopFor(2); | 629 FROM_HERE, base::Bind(&::media::AudioOutputStream::Start, |
| 592 stream->Stop(); | 630 base::Unretained(stream), source_callback.get())); |
| 593 stream->Start(source_callback.get()); | 631 audio_task_runner_->PostTask( |
| 594 RunAudioLoopFor(2); | 632 FROM_HERE, |
| 633 base::Bind(&::media::AudioOutputStream::Stop, base::Unretained(stream))); |
| 634 audio_task_runner_->PostTask( |
| 635 FROM_HERE, base::Bind(&::media::AudioOutputStream::Start, |
| 636 base::Unretained(stream), source_callback.get())); |
| 637 RunUntilIdle(audio_task_runner_.get()); |
| 595 RunUntilIdle(backend_task_runner_.get()); | 638 RunUntilIdle(backend_task_runner_.get()); |
| 596 | 639 |
| 597 FakeAudioDecoder* audio_device = GetAudio(); | 640 FakeAudioDecoder* audio_device = GetAudio(); |
| 598 EXPECT_TRUE(audio_device); | 641 EXPECT_TRUE(audio_device); |
| 599 EXPECT_EQ(FakeMediaPipelineBackend::kStateRunning, GetBackend()->state()); | 642 EXPECT_EQ(FakeMediaPipelineBackend::kStateRunning, GetBackend()->state()); |
| 600 | 643 |
| 601 CloseStream(stream); | 644 CloseStream(stream); |
| 602 } | 645 } |
| 603 | 646 |
| 604 TEST_F(CastAudioOutputStreamTest, CloseWithoutStart) { | 647 TEST_F(CastAudioOutputStreamTest, CloseWithoutStart) { |
| 605 ::media::AudioOutputStream* stream = CreateStream(); | 648 ::media::AudioOutputStream* stream = CreateStream(); |
| 606 ASSERT_TRUE(stream); | 649 ASSERT_TRUE(stream); |
| 607 ASSERT_TRUE(OpenStream(stream)); | 650 ASSERT_TRUE(OpenStream(stream)); |
| 608 CloseStream(stream); | 651 CloseStream(stream); |
| 609 } | 652 } |
| 610 | 653 |
| 611 } // namespace | 654 } // namespace |
| 612 } // namespace media | 655 } // namespace media |
| 613 } // namespace chromecast | 656 } // namespace chromecast |
| OLD | NEW |