Index: media/mojo/services/mojo_audio_decoder_service.cc |
diff --git a/media/mojo/services/mojo_audio_decoder_service.cc b/media/mojo/services/mojo_audio_decoder_service.cc |
index 85128453eb59614dcc748c086f97f05f0f1352d5..8ec71553fc04ded189997e6fd4c8ed3f4ad3361f 100644 |
--- a/media/mojo/services/mojo_audio_decoder_service.cc |
+++ b/media/mojo/services/mojo_audio_decoder_service.cc |
@@ -2,9 +2,14 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "base/logging.h" |
#include "media/mojo/services/mojo_audio_decoder_service.h" |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/logging.h" |
+#include "media/base/cdm_context.h" |
+#include "media/mojo/common/media_type_converters.h" |
+ |
namespace media { |
MojoAudioDecoderService::MojoAudioDecoderService( |
@@ -19,19 +24,102 @@ void MojoAudioDecoderService::Initialize( |
interfaces::AudioDecoderConfigPtr config, |
int32_t cdm_id, |
const InitializeCallback& callback) { |
- NOTIMPLEMENTED(); |
- callback.Run(false, false); |
+ DVLOG(1) << __FUNCTION__ << " " |
+ << config.To<media::AudioDecoderConfig>().AsHumanReadableString(); |
+ |
+ // Encrypted streams are not supported for now. |
+ if (config.To<media::AudioDecoderConfig>().is_encrypted() && |
+ cdm_id == CdmContext::kInvalidCdmId) { |
+ LOG(ERROR) << "AudioDecoderService: encrypted streams are not supported"; |
xhwang
2016/03/18 23:01:13
s/LOG(ERROR)/NOTREACHED()/
This should never happ
Tima Vaisburd
2016/03/19 03:09:05
Done.
|
+ callback.Run(false, false); |
+ return; |
+ } |
+ |
+ client_ = std::move(client); |
+ |
+ DCHECK(initialize_callback_.is_null()); |
+ initialize_callback_ = callback; |
xhwang
2016/03/18 23:01:13
You can also bind |callback| in OnInitialized(). S
Tima Vaisburd
2016/03/19 03:09:05
Done. This seems possible for the client side (i.e
|
+ |
+ decoder_->Initialize(config.To<media::AudioDecoderConfig>(), |
xhwang
2016/03/18 23:01:13
Add a TODO to get CdmContext from cdm_id.
Tima Vaisburd
2016/03/19 03:09:05
Done.
|
+ nullptr, // no CdmContext |
+ base::Bind(&MojoAudioDecoderService::OnInitialized, |
+ base::Unretained(this)), |
xhwang
2016/03/18 23:01:13
base::Unretained() is not safe. You need weak poin
Tima Vaisburd
2016/03/19 03:09:05
Done.
|
+ base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, |
+ base::Unretained(this))); |
} |
void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer, |
const DecodeCallback& callback) { |
- NOTIMPLEMENTED(); |
- callback.Run(DecodeStatus::DECODE_ERROR); |
+ DVLOG(3) << __FUNCTION__; |
+ |
+ DCHECK(decode_callback_.is_null()); |
+ decode_callback_ = callback; |
+ decoder_->Decode(ReadDecoderBuffer(std::move(buffer)), |
+ base::Bind(&MojoAudioDecoderService::OnDecodeStatus, |
+ base::Unretained(this))); |
} |
void MojoAudioDecoderService::Reset(const ResetCallback& callback) { |
+ DVLOG(1) << __FUNCTION__; |
+ |
+ DCHECK(reset_callback_.is_null()); |
+ reset_callback_ = callback; |
+ decoder_->Reset(base::Bind(&MojoAudioDecoderService::OnResetDone, |
+ base::Unretained(this))); |
+} |
+ |
+void MojoAudioDecoderService::OnInitialized(bool success) { |
+ DVLOG(1) << __FUNCTION__ << " success:" << success; |
+ |
+ initialize_callback_.Run(success, decoder_->NeedsBitstreamConversion()); |
+ initialize_callback_.reset(); |
+} |
+ |
+static interfaces::AudioDecoder::DecodeStatus ConvertDecodeStatus( |
+ media::AudioDecoder::Status status) { |
+ switch (status) { |
+ case media::AudioDecoder::kOk: |
+ return interfaces::AudioDecoder::DecodeStatus::OK; |
+ case media::AudioDecoder::kAborted: |
+ return interfaces::AudioDecoder::DecodeStatus::ABORTED; |
+ case media::AudioDecoder::kDecodeError: |
+ return interfaces::AudioDecoder::DecodeStatus::DECODE_ERROR; |
+ } |
+ NOTREACHED(); |
+ return interfaces::AudioDecoder::DecodeStatus::DECODE_ERROR; |
+} |
+ |
+void MojoAudioDecoderService::OnDecodeStatus( |
+ media::AudioDecoder::Status status) { |
+ DVLOG(3) << __FUNCTION__ << " status:" << status; |
+ |
+ decode_callback_.Run(ConvertDecodeStatus(status)); |
+ decode_callback_.reset(); |
+} |
+ |
+void MojoAudioDecoderService::OnResetDone() { |
+ DVLOG(1) << __FUNCTION__; |
+ |
+ // There should be no pending decode operation. |
+ DCHECK(decode_callback_.is_null()); |
+ |
+ reset_callback_.Run(); |
+ reset_callback_.reset(); |
+} |
+ |
+void MojoAudioDecoderService::OnAudioBufferReady( |
+ const scoped_refptr<AudioBuffer>& audio_buffer) { |
+ DVLOG(1) << __FUNCTION__; |
+ NOTIMPLEMENTED(); |
+} |
+ |
+scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( |
+ interfaces::DecoderBufferPtr buffer) { |
+ scoped_refptr<DecoderBuffer> media_buffer( |
+ buffer.To<scoped_refptr<DecoderBuffer>>()); |
+ |
NOTIMPLEMENTED(); |
- callback.Run(); |
+ return media_buffer; |
} |
} // namespace media |