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