Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/pipeline/audio_pipeline_impl.h" | 5 #include "chromecast/media/cma/pipeline/audio_pipeline_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chromecast/media/cma/base/buffering_defs.h" | 8 #include "chromecast/media/cma/base/buffering_defs.h" |
| 9 #include "chromecast/media/cma/base/cma_logging.h" | 9 #include "chromecast/media/cma/base/cma_logging.h" |
| 10 #include "chromecast/media/cma/base/coded_frame_provider.h" | 10 #include "chromecast/media/cma/base/coded_frame_provider.h" |
| 11 #include "chromecast/media/cma/base/decoder_config_adapter.h" | 11 #include "chromecast/media/cma/base/decoder_config_adapter.h" |
| 12 #include "chromecast/media/cma/pipeline/av_pipeline_impl.h" | 12 #include "chromecast/media/cma/pipeline/av_pipeline_impl.h" |
| 13 #include "chromecast/public/media/audio_pipeline_device.h" | |
| 14 #include "chromecast/public/media/decoder_config.h" | 13 #include "chromecast/public/media/decoder_config.h" |
| 15 #include "media/base/audio_decoder_config.h" | 14 #include "media/base/audio_decoder_config.h" |
| 16 | 15 |
| 17 namespace chromecast { | 16 namespace chromecast { |
| 18 namespace media { | 17 namespace media { |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 const size_t kMaxAudioFrameSize = 32 * 1024; | 20 const size_t kMaxAudioFrameSize = 32 * 1024; |
| 22 } | 21 } |
| 23 | 22 |
| 24 AudioPipelineImpl::AudioPipelineImpl(AudioPipelineDevice* audio_device) | 23 AudioPipelineImpl::AudioPipelineImpl( |
| 25 : audio_device_(audio_device), | 24 MediaPipelineBackend::AudioDecoder* decoder, |
| 26 weak_factory_(this) { | 25 const AvPipelineClient& client) |
| 26 : decoder_(decoder), audio_client_(client), weak_factory_(this) { | |
| 27 av_pipeline_impl_.reset(new AvPipelineImpl( | 27 av_pipeline_impl_.reset(new AvPipelineImpl( |
| 28 audio_device_, | 28 decoder_, |
| 29 base::Bind(&AudioPipelineImpl::OnUpdateConfig, base::Unretained(this)))); | 29 base::Bind(&AudioPipelineImpl::OnUpdateConfig, base::Unretained(this)))); |
| 30 weak_this_ = weak_factory_.GetWeakPtr(); | 30 weak_this_ = weak_factory_.GetWeakPtr(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 AudioPipelineImpl::~AudioPipelineImpl() { | 33 AudioPipelineImpl::~AudioPipelineImpl() { |
| 34 } | 34 } |
| 35 | 35 |
| 36 void AudioPipelineImpl::SetCodedFrameProvider( | 36 void AudioPipelineImpl::SetCodedFrameProvider( |
| 37 scoped_ptr<CodedFrameProvider> frame_provider) { | 37 scoped_ptr<CodedFrameProvider> frame_provider) { |
| 38 av_pipeline_impl_->SetCodedFrameProvider( | 38 av_pipeline_impl_->SetCodedFrameProvider( |
| 39 frame_provider.Pass(), kAppAudioBufferSize, kMaxAudioFrameSize); | 39 frame_provider.Pass(), kAppAudioBufferSize, kMaxAudioFrameSize); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void AudioPipelineImpl::SetClient(const AvPipelineClient& client) { | |
| 43 audio_client_ = client; | |
| 44 av_pipeline_impl_->SetClient(client); | |
| 45 } | |
| 46 | |
| 47 bool AudioPipelineImpl::StartPlayingFrom( | 42 bool AudioPipelineImpl::StartPlayingFrom( |
| 48 base::TimeDelta time, | 43 base::TimeDelta time, |
| 49 const scoped_refptr<BufferingState>& buffering_state) { | 44 const scoped_refptr<BufferingState>& buffering_state) { |
| 50 CMALOG(kLogControl) << "AudioPipelineImpl::StartPlayingFrom t0=" | 45 CMALOG(kLogControl) << "AudioPipelineImpl::StartPlayingFrom t0=" |
| 51 << time.InMilliseconds(); | 46 << time.InMilliseconds(); |
| 52 | 47 |
| 53 // Reset the pipeline statistics. | 48 // Reset the pipeline statistics. |
| 54 previous_stats_ = ::media::PipelineStatistics(); | 49 previous_stats_ = ::media::PipelineStatistics(); |
| 55 | 50 |
| 56 // Start playing. | 51 // Start playing. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 74 return; | 69 return; |
| 75 } | 70 } |
| 76 DCHECK_EQ(av_pipeline_impl_->GetState(), AvPipelineImpl::kPlaying); | 71 DCHECK_EQ(av_pipeline_impl_->GetState(), AvPipelineImpl::kPlaying); |
| 77 av_pipeline_impl_->TransitionToState(AvPipelineImpl::kFlushing); | 72 av_pipeline_impl_->TransitionToState(AvPipelineImpl::kFlushing); |
| 78 av_pipeline_impl_->Flush( | 73 av_pipeline_impl_->Flush( |
| 79 base::Bind(&AudioPipelineImpl::OnFlushDone, weak_this_, status_cb)); | 74 base::Bind(&AudioPipelineImpl::OnFlushDone, weak_this_, status_cb)); |
| 80 } | 75 } |
| 81 | 76 |
| 82 void AudioPipelineImpl::OnFlushDone( | 77 void AudioPipelineImpl::OnFlushDone( |
| 83 const ::media::PipelineStatusCB& status_cb) { | 78 const ::media::PipelineStatusCB& status_cb) { |
| 84 CMALOG(kLogControl) << "AudioPipelineImpl::OnFlushDone"; | 79 CMALOG(kLogControl) << "AudioPipelineImpl::OnFlushDone"; |
|
slan
2015/10/07 20:56:16
The __FUNCTION__ macros should be used here, simil
kmackay
2015/10/09 20:35:40
Done.
| |
| 85 if (av_pipeline_impl_->GetState() == AvPipelineImpl::kError) { | 80 if (av_pipeline_impl_->GetState() == AvPipelineImpl::kError) { |
| 86 status_cb.Run(::media::PIPELINE_ERROR_ABORT); | 81 status_cb.Run(::media::PIPELINE_ERROR_ABORT); |
| 87 return; | 82 return; |
| 88 } | 83 } |
| 89 av_pipeline_impl_->TransitionToState(AvPipelineImpl::kFlushed); | 84 av_pipeline_impl_->TransitionToState(AvPipelineImpl::kFlushed); |
| 90 status_cb.Run(::media::PIPELINE_OK); | 85 status_cb.Run(::media::PIPELINE_OK); |
| 91 } | 86 } |
| 92 | 87 |
| 93 void AudioPipelineImpl::Stop() { | 88 void AudioPipelineImpl::Stop() { |
| 94 CMALOG(kLogControl) << "AudioPipelineImpl::Stop"; | 89 CMALOG(kLogControl) << "AudioPipelineImpl::Stop"; |
| 95 av_pipeline_impl_->Stop(); | 90 av_pipeline_impl_->Stop(); |
| 96 av_pipeline_impl_->TransitionToState(AvPipelineImpl::kStopped); | 91 av_pipeline_impl_->TransitionToState(AvPipelineImpl::kStopped); |
| 97 } | 92 } |
| 98 | 93 |
| 99 void AudioPipelineImpl::SetCdm(BrowserCdmCast* media_keys) { | 94 void AudioPipelineImpl::SetCdm(BrowserCdmCast* media_keys) { |
| 100 av_pipeline_impl_->SetCdm(media_keys); | 95 av_pipeline_impl_->SetCdm(media_keys); |
| 101 } | 96 } |
| 102 | 97 |
| 103 void AudioPipelineImpl::Initialize( | 98 void AudioPipelineImpl::Initialize( |
| 104 const ::media::AudioDecoderConfig& audio_config, | 99 const ::media::AudioDecoderConfig& audio_config, |
| 105 scoped_ptr<CodedFrameProvider> frame_provider, | 100 scoped_ptr<CodedFrameProvider> frame_provider, |
| 106 const ::media::PipelineStatusCB& status_cb) { | 101 const ::media::PipelineStatusCB& status_cb) { |
| 107 CMALOG(kLogControl) << "AudioPipelineImpl::Initialize " | 102 CMALOG(kLogControl) << "AudioPipelineImpl::Initialize " |
| 108 << audio_config.AsHumanReadableString(); | 103 << audio_config.AsHumanReadableString(); |
| 109 if (frame_provider) | 104 if (frame_provider) |
| 110 SetCodedFrameProvider(frame_provider.Pass()); | 105 SetCodedFrameProvider(frame_provider.Pass()); |
| 111 | 106 |
| 112 DCHECK(audio_config.IsValidConfig()); | 107 DCHECK(audio_config.IsValidConfig()); |
| 113 if (!audio_device_->SetConfig( | 108 if (!decoder_->SetConfig( |
| 114 DecoderConfigAdapter::ToCastAudioConfig(kPrimary, audio_config)) || | 109 DecoderConfigAdapter::ToCastAudioConfig(kPrimary, audio_config))) { |
| 115 !av_pipeline_impl_->Initialize()) { | |
| 116 status_cb.Run(::media::PIPELINE_ERROR_INITIALIZATION_FAILED); | 110 status_cb.Run(::media::PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 117 return; | 111 return; |
| 118 } | 112 } |
| 119 av_pipeline_impl_->TransitionToState(AvPipelineImpl::kFlushed); | 113 av_pipeline_impl_->TransitionToState(AvPipelineImpl::kFlushed); |
| 120 status_cb.Run(::media::PIPELINE_OK); | 114 status_cb.Run(::media::PIPELINE_OK); |
| 121 } | 115 } |
| 122 | 116 |
| 123 void AudioPipelineImpl::SetVolume(float volume) { | 117 void AudioPipelineImpl::SetVolume(float volume) { |
| 124 audio_device_->SetStreamVolumeMultiplier(volume); | 118 decoder_->SetVolume(volume); |
| 119 } | |
| 120 | |
| 121 void AudioPipelineImpl::OnBufferPushed( | |
| 122 MediaPipelineBackend::BufferStatus status) { | |
| 123 av_pipeline_impl_->OnBufferPushed(status); | |
| 124 } | |
| 125 | |
| 126 void AudioPipelineImpl::OnEndOfStream() { | |
| 127 if (!audio_client_.eos_cb.is_null()) | |
| 128 audio_client_.eos_cb.Run(); | |
| 129 } | |
| 130 | |
| 131 void AudioPipelineImpl::OnError() { | |
| 132 if (!audio_client_.playback_error_cb.is_null()) { | |
| 133 audio_client_.playback_error_cb.Run( | |
| 134 ::media::PIPELINE_ERROR_COULD_NOT_RENDER); | |
| 135 } | |
| 125 } | 136 } |
| 126 | 137 |
| 127 void AudioPipelineImpl::OnUpdateConfig( | 138 void AudioPipelineImpl::OnUpdateConfig( |
| 128 StreamId id, | 139 StreamId id, |
| 129 const ::media::AudioDecoderConfig& audio_config, | 140 const ::media::AudioDecoderConfig& audio_config, |
| 130 const ::media::VideoDecoderConfig& video_config) { | 141 const ::media::VideoDecoderConfig& video_config) { |
| 131 if (audio_config.IsValidConfig()) { | 142 if (audio_config.IsValidConfig()) { |
| 132 CMALOG(kLogControl) << "AudioPipelineImpl::OnUpdateConfig id:" << id << " " | 143 CMALOG(kLogControl) << "AudioPipelineImpl::OnUpdateConfig id:" << id << " " |
| 133 << audio_config.AsHumanReadableString(); | 144 << audio_config.AsHumanReadableString(); |
| 134 | 145 |
| 135 bool success = audio_device_->SetConfig( | 146 bool success = decoder_->SetConfig( |
| 136 DecoderConfigAdapter::ToCastAudioConfig(id, audio_config)); | 147 DecoderConfigAdapter::ToCastAudioConfig(id, audio_config)); |
| 137 if (!success && !audio_client_.playback_error_cb.is_null()) | 148 if (!success && !audio_client_.playback_error_cb.is_null()) |
| 138 audio_client_.playback_error_cb.Run(::media::PIPELINE_ERROR_DECODE); | 149 audio_client_.playback_error_cb.Run(::media::PIPELINE_ERROR_DECODE); |
| 139 } | 150 } |
| 140 } | 151 } |
| 141 | 152 |
| 142 void AudioPipelineImpl::UpdateStatistics() { | 153 void AudioPipelineImpl::UpdateStatistics() { |
| 143 if (audio_client_.statistics_cb.is_null()) | 154 if (audio_client_.statistics_cb.is_null()) |
| 144 return; | 155 return; |
| 145 | 156 |
| 146 MediaComponentDevice::Statistics device_stats; | 157 MediaPipelineBackend::Decoder::Statistics device_stats; |
| 147 if (!audio_device_->GetStatistics(&device_stats)) | 158 decoder_->GetStatistics(&device_stats); |
| 148 return; | |
| 149 | 159 |
| 150 ::media::PipelineStatistics current_stats; | 160 ::media::PipelineStatistics current_stats; |
| 151 current_stats.audio_bytes_decoded = device_stats.decoded_bytes; | 161 current_stats.audio_bytes_decoded = device_stats.decoded_bytes; |
| 152 | 162 |
| 153 ::media::PipelineStatistics delta_stats; | 163 ::media::PipelineStatistics delta_stats; |
| 154 delta_stats.audio_bytes_decoded = | 164 delta_stats.audio_bytes_decoded = |
| 155 current_stats.audio_bytes_decoded - previous_stats_.audio_bytes_decoded; | 165 current_stats.audio_bytes_decoded - previous_stats_.audio_bytes_decoded; |
| 156 | 166 |
| 157 previous_stats_ = current_stats; | 167 previous_stats_ = current_stats; |
| 158 | 168 |
| 159 audio_client_.statistics_cb.Run(delta_stats); | 169 audio_client_.statistics_cb.Run(delta_stats); |
| 160 } | 170 } |
| 161 | 171 |
| 162 } // namespace media | 172 } // namespace media |
| 163 } // namespace chromecast | 173 } // namespace chromecast |
| OLD | NEW |