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

Side by Side Diff: chromecast/media/cma/backend/media_pipeline_device_fake.cc

Issue 1074383002: Introduce VideoConfig/AudioConfig class for CMA backend (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO comments and fix unit test Created 5 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/cma/backend/media_pipeline_device_fake.h" 5 #include "chromecast/media/cma/backend/media_pipeline_device_fake.h"
6 6
7 #include <list> 7 #include <list>
8 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
11 #include "base/location.h" 12 #include "base/location.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
15 #include "chromecast/media/cma/backend/audio_pipeline_device.h" 16 #include "chromecast/media/cma/backend/audio_pipeline_device.h"
16 #include "chromecast/media/cma/backend/media_clock_device.h" 17 #include "chromecast/media/cma/backend/media_clock_device.h"
17 #include "chromecast/media/cma/backend/media_component_device.h" 18 #include "chromecast/media/cma/backend/media_component_device.h"
18 #include "chromecast/media/cma/backend/video_pipeline_device.h" 19 #include "chromecast/media/cma/backend/video_pipeline_device.h"
19 #include "chromecast/media/cma/base/decoder_buffer_base.h" 20 #include "chromecast/media/cma/base/decoder_buffer_base.h"
20 #include "media/base/audio_decoder_config.h" 21 #include "chromecast/public/media/decoder_config.h"
21 #include "media/base/buffers.h" 22 #include "media/base/buffers.h"
22 #include "media/base/video_decoder_config.h"
23 23
24 namespace chromecast { 24 namespace chromecast {
25 namespace media { 25 namespace media {
26 26
27 class MediaClockDeviceFake : public MediaClockDevice { 27 class MediaClockDeviceFake : public MediaClockDevice {
28 public: 28 public:
29 MediaClockDeviceFake(); 29 MediaClockDeviceFake();
30 ~MediaClockDeviceFake() override; 30 ~MediaClockDeviceFake() override;
31 31
32 // MediaClockDevice implementation. 32 // MediaClockDevice implementation.
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 void SetClient(const Client& client) override; 364 void SetClient(const Client& client) override;
365 State GetState() const override; 365 State GetState() const override;
366 bool SetState(State new_state) override; 366 bool SetState(State new_state) override;
367 bool SetStartPts(base::TimeDelta time) override; 367 bool SetStartPts(base::TimeDelta time) override;
368 FrameStatus PushFrame( 368 FrameStatus PushFrame(
369 const scoped_refptr<DecryptContext>& decrypt_context, 369 const scoped_refptr<DecryptContext>& decrypt_context,
370 const scoped_refptr<DecoderBufferBase>& buffer, 370 const scoped_refptr<DecoderBufferBase>& buffer,
371 const FrameStatusCB& completion_cb) override; 371 const FrameStatusCB& completion_cb) override;
372 base::TimeDelta GetRenderingTime() const override; 372 base::TimeDelta GetRenderingTime() const override;
373 base::TimeDelta GetRenderingDelay() const override; 373 base::TimeDelta GetRenderingDelay() const override;
374 bool SetConfig(const ::media::AudioDecoderConfig& config) override; 374 bool SetConfig(const AudioConfig& config) override;
375 void SetStreamVolumeMultiplier(float multiplier) override; 375 void SetStreamVolumeMultiplier(float multiplier) override;
376 bool GetStatistics(Statistics* stats) const override; 376 bool GetStatistics(Statistics* stats) const override;
377 377
378 private: 378 private:
379 scoped_ptr<MediaComponentDeviceFake> fake_pipeline_; 379 scoped_ptr<MediaComponentDeviceFake> fake_pipeline_;
380 380
381 ::media::AudioDecoderConfig config_; 381 AudioConfig config_;
382 std::vector<uint8_t> config_extra_data_;
382 383
383 DISALLOW_COPY_AND_ASSIGN(AudioPipelineDeviceFake); 384 DISALLOW_COPY_AND_ASSIGN(AudioPipelineDeviceFake);
384 }; 385 };
385 386
386 AudioPipelineDeviceFake::AudioPipelineDeviceFake( 387 AudioPipelineDeviceFake::AudioPipelineDeviceFake(
387 MediaClockDeviceFake* media_clock_device) 388 MediaClockDeviceFake* media_clock_device)
388 : fake_pipeline_(new MediaComponentDeviceFake(media_clock_device)) { 389 : fake_pipeline_(new MediaComponentDeviceFake(media_clock_device)) {
389 DetachFromThread(); 390 DetachFromThread();
390 } 391 }
391 392
392 AudioPipelineDeviceFake::~AudioPipelineDeviceFake() { 393 AudioPipelineDeviceFake::~AudioPipelineDeviceFake() {
393 } 394 }
394 395
395 void AudioPipelineDeviceFake::SetClient(const Client& client) { 396 void AudioPipelineDeviceFake::SetClient(const Client& client) {
396 fake_pipeline_->SetClient(client); 397 fake_pipeline_->SetClient(client);
397 } 398 }
398 399
399 MediaComponentDevice::State AudioPipelineDeviceFake::GetState() const { 400 MediaComponentDevice::State AudioPipelineDeviceFake::GetState() const {
400 return fake_pipeline_->GetState(); 401 return fake_pipeline_->GetState();
401 } 402 }
402 403
403 bool AudioPipelineDeviceFake::SetState(State new_state) { 404 bool AudioPipelineDeviceFake::SetState(State new_state) {
404 bool success = fake_pipeline_->SetState(new_state); 405 bool success = fake_pipeline_->SetState(new_state);
405 if (!success) 406 if (!success)
406 return false; 407 return false;
407 408
408 if (new_state == kStateIdle) { 409 if (new_state == kStateIdle) {
409 DCHECK(config_.IsValidConfig()); 410 DCHECK(IsValidConfig(config_));
410 } 411 }
411 if (new_state == kStateUninitialized) { 412 if (new_state == kStateUninitialized) {
412 config_ = ::media::AudioDecoderConfig(); 413 config_ = AudioConfig();
413 } 414 }
414 return true; 415 return true;
415 } 416 }
416 417
417 bool AudioPipelineDeviceFake::SetStartPts(base::TimeDelta time) { 418 bool AudioPipelineDeviceFake::SetStartPts(base::TimeDelta time) {
418 return fake_pipeline_->SetStartPts(time); 419 return fake_pipeline_->SetStartPts(time);
419 } 420 }
420 421
421 MediaComponentDevice::FrameStatus AudioPipelineDeviceFake::PushFrame( 422 MediaComponentDevice::FrameStatus AudioPipelineDeviceFake::PushFrame(
422 const scoped_refptr<DecryptContext>& decrypt_context, 423 const scoped_refptr<DecryptContext>& decrypt_context,
423 const scoped_refptr<DecoderBufferBase>& buffer, 424 const scoped_refptr<DecoderBufferBase>& buffer,
424 const FrameStatusCB& completion_cb) { 425 const FrameStatusCB& completion_cb) {
425 return fake_pipeline_->PushFrame(decrypt_context, buffer, completion_cb); 426 return fake_pipeline_->PushFrame(decrypt_context, buffer, completion_cb);
426 } 427 }
427 428
428 base::TimeDelta AudioPipelineDeviceFake::GetRenderingTime() const { 429 base::TimeDelta AudioPipelineDeviceFake::GetRenderingTime() const {
429 return fake_pipeline_->GetRenderingTime(); 430 return fake_pipeline_->GetRenderingTime();
430 } 431 }
431 432
432 base::TimeDelta AudioPipelineDeviceFake::GetRenderingDelay() const { 433 base::TimeDelta AudioPipelineDeviceFake::GetRenderingDelay() const {
433 return fake_pipeline_->GetRenderingDelay(); 434 return fake_pipeline_->GetRenderingDelay();
434 } 435 }
435 436
436 bool AudioPipelineDeviceFake::SetConfig( 437 bool AudioPipelineDeviceFake::SetConfig(const AudioConfig& config) {
437 const ::media::AudioDecoderConfig& config) {
438 DCHECK(CalledOnValidThread()); 438 DCHECK(CalledOnValidThread());
439 if (!config.IsValidConfig()) 439 if (!IsValidConfig(config))
440 return false; 440 return false;
441 config_ = config; 441 config_ = config;
442 if (config.extra_data_size > 0)
443 config_extra_data_.assign(config.extra_data,
444 config.extra_data + config.extra_data_size);
445 else
446 config_extra_data_.clear();
442 return true; 447 return true;
443 } 448 }
444 449
445 void AudioPipelineDeviceFake::SetStreamVolumeMultiplier(float multiplier) { 450 void AudioPipelineDeviceFake::SetStreamVolumeMultiplier(float multiplier) {
446 DCHECK(CalledOnValidThread()); 451 DCHECK(CalledOnValidThread());
447 } 452 }
448 453
449 bool AudioPipelineDeviceFake::GetStatistics(Statistics* stats) const { 454 bool AudioPipelineDeviceFake::GetStatistics(Statistics* stats) const {
450 return fake_pipeline_->GetStatistics(stats); 455 return fake_pipeline_->GetStatistics(stats);
451 } 456 }
452 457
453 458
454 class VideoPipelineDeviceFake : public VideoPipelineDevice { 459 class VideoPipelineDeviceFake : public VideoPipelineDevice {
455 public: 460 public:
456 explicit VideoPipelineDeviceFake(MediaClockDeviceFake* media_clock_device); 461 explicit VideoPipelineDeviceFake(MediaClockDeviceFake* media_clock_device);
457 ~VideoPipelineDeviceFake() override; 462 ~VideoPipelineDeviceFake() override;
458 463
459 // VideoPipelineDevice implementation. 464 // VideoPipelineDevice implementation.
460 void SetClient(const Client& client) override; 465 void SetClient(const Client& client) override;
461 State GetState() const override; 466 State GetState() const override;
462 bool SetState(State new_state) override; 467 bool SetState(State new_state) override;
463 bool SetStartPts(base::TimeDelta time) override; 468 bool SetStartPts(base::TimeDelta time) override;
464 FrameStatus PushFrame( 469 FrameStatus PushFrame(
465 const scoped_refptr<DecryptContext>& decrypt_context, 470 const scoped_refptr<DecryptContext>& decrypt_context,
466 const scoped_refptr<DecoderBufferBase>& buffer, 471 const scoped_refptr<DecoderBufferBase>& buffer,
467 const FrameStatusCB& completion_cb) override; 472 const FrameStatusCB& completion_cb) override;
468 base::TimeDelta GetRenderingTime() const override; 473 base::TimeDelta GetRenderingTime() const override;
469 base::TimeDelta GetRenderingDelay() const override; 474 base::TimeDelta GetRenderingDelay() const override;
470 void SetVideoClient(const VideoClient& client) override; 475 void SetVideoClient(const VideoClient& client) override;
471 bool SetConfig(const ::media::VideoDecoderConfig& config) override; 476 bool SetConfig(const VideoConfig& config) override;
472 bool GetStatistics(Statistics* stats) const override; 477 bool GetStatistics(Statistics* stats) const override;
473 478
474 private: 479 private:
475 scoped_ptr<MediaComponentDeviceFake> fake_pipeline_; 480 scoped_ptr<MediaComponentDeviceFake> fake_pipeline_;
476 481
477 ::media::VideoDecoderConfig config_; 482 VideoConfig config_;
483 std::vector<uint8_t> config_extra_data_;
478 484
479 DISALLOW_COPY_AND_ASSIGN(VideoPipelineDeviceFake); 485 DISALLOW_COPY_AND_ASSIGN(VideoPipelineDeviceFake);
480 }; 486 };
481 487
482 VideoPipelineDeviceFake::VideoPipelineDeviceFake( 488 VideoPipelineDeviceFake::VideoPipelineDeviceFake(
483 MediaClockDeviceFake* media_clock_device) 489 MediaClockDeviceFake* media_clock_device)
484 : fake_pipeline_(new MediaComponentDeviceFake(media_clock_device)) { 490 : fake_pipeline_(new MediaComponentDeviceFake(media_clock_device)) {
485 DetachFromThread(); 491 DetachFromThread();
486 } 492 }
487 493
488 VideoPipelineDeviceFake::~VideoPipelineDeviceFake() { 494 VideoPipelineDeviceFake::~VideoPipelineDeviceFake() {
489 } 495 }
490 496
491 void VideoPipelineDeviceFake::SetClient(const Client& client) { 497 void VideoPipelineDeviceFake::SetClient(const Client& client) {
492 fake_pipeline_->SetClient(client); 498 fake_pipeline_->SetClient(client);
493 } 499 }
494 500
495 MediaComponentDevice::State VideoPipelineDeviceFake::GetState() const { 501 MediaComponentDevice::State VideoPipelineDeviceFake::GetState() const {
496 return fake_pipeline_->GetState(); 502 return fake_pipeline_->GetState();
497 } 503 }
498 504
499 bool VideoPipelineDeviceFake::SetState(State new_state) { 505 bool VideoPipelineDeviceFake::SetState(State new_state) {
500 bool success = fake_pipeline_->SetState(new_state); 506 bool success = fake_pipeline_->SetState(new_state);
501 if (!success) 507 if (!success)
502 return false; 508 return false;
503 509
504 if (new_state == kStateIdle) { 510 if (new_state == kStateIdle) {
505 DCHECK(config_.IsValidConfig()); 511 DCHECK(IsValidConfig(config_));
506 } 512 }
507 if (new_state == kStateUninitialized) { 513 if (new_state == kStateUninitialized) {
508 config_ = ::media::VideoDecoderConfig(); 514 config_ = VideoConfig();
509 } 515 }
510 return true; 516 return true;
511 } 517 }
512 518
513 bool VideoPipelineDeviceFake::SetStartPts(base::TimeDelta time) { 519 bool VideoPipelineDeviceFake::SetStartPts(base::TimeDelta time) {
514 return fake_pipeline_->SetStartPts(time); 520 return fake_pipeline_->SetStartPts(time);
515 } 521 }
516 522
517 MediaComponentDevice::FrameStatus VideoPipelineDeviceFake::PushFrame( 523 MediaComponentDevice::FrameStatus VideoPipelineDeviceFake::PushFrame(
518 const scoped_refptr<DecryptContext>& decrypt_context, 524 const scoped_refptr<DecryptContext>& decrypt_context,
519 const scoped_refptr<DecoderBufferBase>& buffer, 525 const scoped_refptr<DecoderBufferBase>& buffer,
520 const FrameStatusCB& completion_cb) { 526 const FrameStatusCB& completion_cb) {
521 return fake_pipeline_->PushFrame(decrypt_context, buffer, completion_cb); 527 return fake_pipeline_->PushFrame(decrypt_context, buffer, completion_cb);
522 } 528 }
523 529
524 base::TimeDelta VideoPipelineDeviceFake::GetRenderingTime() const { 530 base::TimeDelta VideoPipelineDeviceFake::GetRenderingTime() const {
525 return fake_pipeline_->GetRenderingTime(); 531 return fake_pipeline_->GetRenderingTime();
526 } 532 }
527 533
528 base::TimeDelta VideoPipelineDeviceFake::GetRenderingDelay() const { 534 base::TimeDelta VideoPipelineDeviceFake::GetRenderingDelay() const {
529 return fake_pipeline_->GetRenderingDelay(); 535 return fake_pipeline_->GetRenderingDelay();
530 } 536 }
531 537
532 void VideoPipelineDeviceFake::SetVideoClient(const VideoClient& client) { 538 void VideoPipelineDeviceFake::SetVideoClient(const VideoClient& client) {
533 } 539 }
534 540
535 bool VideoPipelineDeviceFake::SetConfig( 541 bool VideoPipelineDeviceFake::SetConfig(const VideoConfig& config) {
536 const ::media::VideoDecoderConfig& config) {
537 DCHECK(CalledOnValidThread()); 542 DCHECK(CalledOnValidThread());
538 if (!config.IsValidConfig()) 543 if (!IsValidConfig(config))
539 return false; 544 return false;
540 config_ = config; 545 config_ = config;
546 if (config.extra_data_size > 0)
547 config_extra_data_.assign(config.extra_data,
548 config.extra_data + config.extra_data_size);
549 else
550 config_extra_data_.clear();
541 return true; 551 return true;
542 } 552 }
543 553
544 bool VideoPipelineDeviceFake::GetStatistics(Statistics* stats) const { 554 bool VideoPipelineDeviceFake::GetStatistics(Statistics* stats) const {
545 return fake_pipeline_->GetStatistics(stats); 555 return fake_pipeline_->GetStatistics(stats);
546 } 556 }
547 557
548 558
549 MediaPipelineDeviceFake::MediaPipelineDeviceFake() 559 MediaPipelineDeviceFake::MediaPipelineDeviceFake()
550 : media_clock_device_(new MediaClockDeviceFake()), 560 : media_clock_device_(new MediaClockDeviceFake()),
(...skipping 13 matching lines...) Expand all
564 VideoPipelineDevice* MediaPipelineDeviceFake::GetVideoPipelineDevice() const { 574 VideoPipelineDevice* MediaPipelineDeviceFake::GetVideoPipelineDevice() const {
565 return video_pipeline_device_.get(); 575 return video_pipeline_device_.get();
566 } 576 }
567 577
568 MediaClockDevice* MediaPipelineDeviceFake::GetMediaClockDevice() const { 578 MediaClockDevice* MediaPipelineDeviceFake::GetMediaClockDevice() const {
569 return media_clock_device_.get(); 579 return media_clock_device_.get();
570 } 580 }
571 581
572 } // namespace media 582 } // namespace media
573 } // namespace chromecast 583 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698