summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authortimav <timav@chromium.org>2016-03-18 21:52:03 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-19 05:03:15 +0000
commitaa65f0b204028f560fb98c3c7ab2f2eeca3aaca2 (patch)
treec8b75c7bb2f2dede0c67e70c90b75f50774226b2 /media
parent8986524a99ac80887e411924c692b3ba510f4868 (diff)
downloadchromium_src-aa65f0b204028f560fb98c3c7ab2f2eeca3aaca2.zip
chromium_src-aa65f0b204028f560fb98c3c7ab2f2eeca3aaca2.tar.gz
chromium_src-aa65f0b204028f560fb98c3c7ab2f2eeca3aaca2.tar.bz2
Implement MojoAudioDecoderService
Implemented the plumbing between the service and AudioDecoder except for the actual data transfer. BUG=542910 Review URL: https://codereview.chromium.org/1810293005 Cr-Commit-Position: refs/heads/master@{#382184}
Diffstat (limited to 'media')
-rw-r--r--media/mojo/services/mojo_audio_decoder_service.cc91
-rw-r--r--media/mojo/services/mojo_audio_decoder_service.h21
2 files changed, 105 insertions, 7 deletions
diff --git a/media/mojo/services/mojo_audio_decoder_service.cc b/media/mojo/services/mojo_audio_decoder_service.cc
index 8512845..51fdef5 100644
--- a/media/mojo/services/mojo_audio_decoder_service.cc
+++ b/media/mojo/services/mojo_audio_decoder_service.cc
@@ -2,15 +2,24 @@
// 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(
scoped_ptr<media::AudioDecoder> decoder,
mojo::InterfaceRequest<interfaces::AudioDecoder> request)
- : binding_(this, std::move(request)), decoder_(std::move(decoder)) {}
+ : binding_(this, std::move(request)),
+ decoder_(std::move(decoder)),
+ weak_factory_(this) {
+ weak_this_ = weak_factory_.GetWeakPtr();
+}
MojoAudioDecoderService::~MojoAudioDecoderService() {}
@@ -19,19 +28,87 @@ 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) {
+ // The client should prevent this situation.
+ NOTREACHED() << "Encrypted streams are not supported";
+ callback.Run(false, false);
+ return;
+ }
+
+ client_ = std::move(client);
+
+ // TODO(timav): Get CdmContext from cdm_id.
+ decoder_->Initialize(
+ config.To<media::AudioDecoderConfig>(),
+ nullptr, // no CdmContext
+ base::Bind(&MojoAudioDecoderService::OnInitialized, weak_this_, callback),
+ base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, weak_this_));
}
void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer,
const DecodeCallback& callback) {
- NOTIMPLEMENTED();
- callback.Run(DecodeStatus::DECODE_ERROR);
+ DVLOG(3) << __FUNCTION__;
+ decoder_->Decode(ReadDecoderBuffer(std::move(buffer)),
+ base::Bind(&MojoAudioDecoderService::OnDecodeStatus,
+ weak_this_, callback));
}
void MojoAudioDecoderService::Reset(const ResetCallback& callback) {
- NOTIMPLEMENTED();
+ DVLOG(1) << __FUNCTION__;
+ decoder_->Reset(
+ base::Bind(&MojoAudioDecoderService::OnResetDone, weak_this_, callback));
+}
+
+void MojoAudioDecoderService::OnInitialized(const InitializeCallback& callback,
+ bool success) {
+ DVLOG(1) << __FUNCTION__ << " success:" << success;
+ callback.Run(success, decoder_->NeedsBitstreamConversion());
+}
+
+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(
+ const DecodeCallback& callback,
+ media::AudioDecoder::Status status) {
+ DVLOG(3) << __FUNCTION__ << " status:" << status;
+ callback.Run(ConvertDecodeStatus(status));
+}
+
+void MojoAudioDecoderService::OnResetDone(const ResetCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
callback.Run();
}
+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();
+ return media_buffer;
+}
+
} // namespace media
diff --git a/media/mojo/services/mojo_audio_decoder_service.h b/media/mojo/services/mojo_audio_decoder_service.h
index bd5bc73..756e19c 100644
--- a/media/mojo/services/mojo_audio_decoder_service.h
+++ b/media/mojo/services/mojo_audio_decoder_service.h
@@ -7,6 +7,7 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "media/base/audio_decoder.h"
#include "media/mojo/interfaces/audio_decoder.mojom.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
@@ -33,6 +34,23 @@ class MojoAudioDecoderService : public interfaces::AudioDecoder {
void Reset(const ResetCallback& callback) final;
private:
+ // Called by |decoder_| upon finishing initialization.
+ void OnInitialized(const InitializeCallback& callback, bool success);
+
+ // Called by |decoder_| when DecoderBuffer is accepted or rejected.
+ void OnDecodeStatus(const DecodeCallback& callback,
+ media::AudioDecoder::Status status);
+
+ // Called by |decoder_| when reset sequence is finished.
+ void OnResetDone(const ResetCallback& callback);
+
+ // Called by |decoder_| for each decoded buffer.
+ void OnAudioBufferReady(const scoped_refptr<AudioBuffer>& audio_buffer);
+
+ // A helper method to read and deserialize DecoderBuffer from data pipe.
+ scoped_refptr<DecoderBuffer> ReadDecoderBuffer(
+ interfaces::DecoderBufferPtr buffer);
+
// A binding represents the association between the service and the
// communication channel, i.e. the pipe.
mojo::StrongBinding<interfaces::AudioDecoder> binding_;
@@ -43,6 +61,9 @@ class MojoAudioDecoderService : public interfaces::AudioDecoder {
// The destination for the decoded buffers.
interfaces::AudioDecoderClientPtr client_;
+ base::WeakPtr<MojoAudioDecoderService> weak_this_;
+ base::WeakPtrFactory<MojoAudioDecoderService> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(MojoAudioDecoderService);
};