Commit fb961a66 authored by ziyangch's avatar ziyangch Committed by Commit Bot

[Chromecast] Add Observer in CmaBackend::AudioDecoder.

Bug: Internal b/162079069

Merge-With: eureka-internal/424693

Test: Check whether the observer receive the signal on device.

Change-Id: I44c15917a4104cfb94ca619d986587fd96b6857b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2349415Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Commit-Queue: Ziyang Cheng <ziyangch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798007}
parent e3acd9d0
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <stdint.h> #include <stdint.h>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/observer_list_types.h"
#include "chromecast/media/api/decoder_buffer_base.h" #include "chromecast/media/api/decoder_buffer_base.h"
#include "chromecast/public/media/decoder_config.h" #include "chromecast/public/media/decoder_config.h"
#include "chromecast/public/media/media_pipeline_backend.h" #include "chromecast/public/media/media_pipeline_backend.h"
...@@ -48,6 +49,18 @@ class CmaBackend { ...@@ -48,6 +49,18 @@ class CmaBackend {
using RenderingDelay = MediaPipelineBackend::AudioDecoder::RenderingDelay; using RenderingDelay = MediaPipelineBackend::AudioDecoder::RenderingDelay;
using Statistics = MediaPipelineBackend::AudioDecoder::Statistics; using Statistics = MediaPipelineBackend::AudioDecoder::Statistics;
class Observer : public base::CheckedObserver {
public:
// Called when the audio is ready to play. In general the audio will start
// playing immediately once it's ready to play, so no need to wait for
// this signal. But in multizone mode, we delay the playback in order to
// allow time for other devices to receive the audio.
virtual void OnAudioReadyToPlay() = 0;
protected:
~Observer() override = default;
};
// These methods have the same behavior as the corresponding methods on // These methods have the same behavior as the corresponding methods on
// MediaPipelineBackend::AudioDecoder. // MediaPipelineBackend::AudioDecoder.
// See chromecast/public/media/media_pipeline_backend.h for documentation. // See chromecast/public/media/media_pipeline_backend.h for documentation.
...@@ -61,6 +74,8 @@ class CmaBackend { ...@@ -61,6 +74,8 @@ class CmaBackend {
// change whenever SetConfig() is called or the backend is initialized. // change whenever SetConfig() is called or the backend is initialized.
virtual bool RequiresDecryption() = 0; virtual bool RequiresDecryption() = 0;
virtual void SetObserver(Observer* observer) = 0;
protected: protected:
~AudioDecoder() override = default; ~AudioDecoder() override = default;
}; };
......
...@@ -41,6 +41,7 @@ class MockCmaBackend : public CmaBackend { ...@@ -41,6 +41,7 @@ class MockCmaBackend : public CmaBackend {
MOCK_METHOD0(GetRenderingDelay, RenderingDelay()); MOCK_METHOD0(GetRenderingDelay, RenderingDelay());
MOCK_METHOD1(GetStatistics, void(Statistics*)); MOCK_METHOD1(GetStatistics, void(Statistics*));
MOCK_METHOD0(RequiresDecryption, bool()); MOCK_METHOD0(RequiresDecryption, bool());
MOCK_METHOD1(SetObserver, void(Observer*));
}; };
class VideoDecoder : public CmaBackend::VideoDecoder { class VideoDecoder : public CmaBackend::VideoDecoder {
......
...@@ -135,6 +135,7 @@ class FakeAudioDecoder : public CmaBackend::AudioDecoder { ...@@ -135,6 +135,7 @@ class FakeAudioDecoder : public CmaBackend::AudioDecoder {
} }
RenderingDelay GetRenderingDelay() override { return rendering_delay_; } RenderingDelay GetRenderingDelay() override { return rendering_delay_; }
bool RequiresDecryption() override { return false; } bool RequiresDecryption() override { return false; }
void SetObserver(CmaBackend::AudioDecoder::Observer* observer) override {}
const AudioConfig& config() const { return config_; } const AudioConfig& config() const { return config_; }
float volume() const { return volume_; } float volume() const { return volume_; }
......
...@@ -122,6 +122,14 @@ void CmaAudioOutput::Initialize( ...@@ -122,6 +122,14 @@ void CmaAudioOutput::Initialize(
timestamp_helper_.SetBaseTimestamp(base::TimeDelta()); timestamp_helper_.SetBaseTimestamp(base::TimeDelta());
} }
void CmaAudioOutput::SetObserver(CmaBackend::AudioDecoder::Observer* observer) {
DCHECK_CALLED_ON_VALID_THREAD(media_thread_checker_);
DCHECK(observer);
if (audio_decoder_) {
audio_decoder_->SetObserver(observer);
}
}
bool CmaAudioOutput::Start(int64_t start_pts) { bool CmaAudioOutput::Start(int64_t start_pts) {
DCHECK_CALLED_ON_VALID_THREAD(media_thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(media_thread_checker_);
if (!cma_backend_ || !cma_backend_->Start(start_pts)) { if (!cma_backend_ || !cma_backend_->Start(start_pts)) {
......
...@@ -41,6 +41,8 @@ class CmaAudioOutput { ...@@ -41,6 +41,8 @@ class CmaAudioOutput {
CmaAudioOutput& operator=(const CmaAudioOutput&) = delete; CmaAudioOutput& operator=(const CmaAudioOutput&) = delete;
~CmaAudioOutput(); ~CmaAudioOutput();
void SetObserver(CmaBackend::AudioDecoder::Observer* observer);
bool Start(int64_t start_pts); bool Start(int64_t start_pts);
void Stop(); void Stop();
bool Pause(); bool Pause();
......
...@@ -43,6 +43,7 @@ class RevokedAudioDecoderWrapper : public DestructableAudioDecoder { ...@@ -43,6 +43,7 @@ class RevokedAudioDecoderWrapper : public DestructableAudioDecoder {
*statistics = statistics_; *statistics = statistics_;
} }
bool RequiresDecryption() override { return requires_decryption_; } bool RequiresDecryption() override { return requires_decryption_; }
void SetObserver(CmaBackend::AudioDecoder::Observer* observer) override {}
const RenderingDelay rendering_delay_; const RenderingDelay rendering_delay_;
const Statistics statistics_; const Statistics statistics_;
......
...@@ -47,6 +47,7 @@ class ActiveAudioDecoderWrapper : public DestructableAudioDecoder { ...@@ -47,6 +47,7 @@ class ActiveAudioDecoderWrapper : public DestructableAudioDecoder {
RenderingDelay GetRenderingDelay() override; RenderingDelay GetRenderingDelay() override;
void GetStatistics(Statistics* statistics) override; void GetStatistics(Statistics* statistics) override;
bool RequiresDecryption() override; bool RequiresDecryption() override;
void SetObserver(CmaBackend::AudioDecoder::Observer* observer) override {}
AudioDecoderSoftwareWrapper decoder_; AudioDecoderSoftwareWrapper decoder_;
const AudioContentType content_type_; const AudioContentType content_type_;
...@@ -85,6 +86,7 @@ class AudioDecoderWrapper : public CmaBackend::AudioDecoder { ...@@ -85,6 +86,7 @@ class AudioDecoderWrapper : public CmaBackend::AudioDecoder {
RenderingDelay GetRenderingDelay() override; RenderingDelay GetRenderingDelay() override;
void GetStatistics(Statistics* statistics) override; void GetStatistics(Statistics* statistics) override;
bool RequiresDecryption() override; bool RequiresDecryption() override;
void SetObserver(CmaBackend::AudioDecoder::Observer* observer) override {}
bool decoder_revoked_; bool decoder_revoked_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment