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

Unified Diff: media/filters/audio_decoder_factory.cc

Issue 11492003: Encrypted Media: Support Audio Decrypt-Only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: media/filters/audio_decoder_factory.cc
diff --git a/media/filters/audio_decoder_factory.cc b/media/filters/audio_decoder_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c4f839f6ffef3987dca5ceeb5d89196ca2006fc9
--- /dev/null
+++ b/media/filters/audio_decoder_factory.cc
@@ -0,0 +1,138 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/filters/audio_decoder_factory.h"
+
+#include "base/bind.h"
+#include "base/callback_helpers.h"
+#include "base/logging.h"
+#include "base/message_loop_proxy.h"
+#include "media/base/audio_decoder_config.h"
+#include "media/base/demuxer_stream.h"
+#include "media/base/pipeline.h"
+#include "media/filters/decrypting_audio_decoder.h"
+#include "media/filters/decrypting_demuxer_stream.h"
+
+namespace media {
+
+// TODO(xhwang): Forcepost tasks? Check for current loop?
+
+AudioDecoderFactory::AudioDecoderFactory(
+ const scoped_refptr<base::MessageLoopProxy>& message_loop,
+ const AudioDecoderList& decoders,
+ const RequestDecryptorNotificationCB& request_decryptor_notification_cb)
+ : message_loop_(message_loop),
+ precreated_decoders_(decoders),
+ request_decryptor_notification_cb_(request_decryptor_notification_cb),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
+ weak_this_(weak_ptr_factory_.GetWeakPtr()) {
+}
+
+void AudioDecoderFactory::InitAudioDecoder(
+ const scoped_refptr<DemuxerStream>& stream,
+ const StatisticsCB& statistics_cb,
+ InitDoneCB init_done_cb) {
+ DVLOG(2) << "Initialize()";
+ DCHECK(stream);
+
+ const AudioDecoderConfig& config = stream->audio_decoder_config();
+ if (!config.IsValidConfig()) {
+ DLOG(ERROR) << "Invalid audio stream config.";
+ // TODO(xhwang): Force posting or not?
+ init_done_cb.Run(NULL, NULL);
+ return;
+ }
+
+ input_stream_ = stream;
+ statistics_cb_ = statistics_cb;
+ init_done_cb_ = init_done_cb;
+
+ if (!config.is_encrypted()) {
+ if (precreated_decoders_.empty()) {
+ base::ResetAndReturn(&init_done_cb_).Run(NULL, NULL);
+ return;
+ }
+
+ InitializeNextDecoder();
+ return;
+ }
+
+ if (request_decryptor_notification_cb_.is_null()) {
+ base::ResetAndReturn(&init_done_cb_).Run(NULL, NULL);
+ return;
+ }
+
+ audio_decoder_ = new DecryptingAudioDecoder(
+ message_loop_, request_decryptor_notification_cb_);
+ audio_decoder_->Initialize(
+ input_stream_,
+ base::Bind(&AudioDecoderFactory::OnDecryptingAudioDecoderInitDone,
+ weak_this_),
+ statistics_cb_);
+}
+
+void AudioDecoderFactory::OnDecryptingAudioDecoderInitDone(
+ PipelineStatus status) {
+ if (status == PIPELINE_OK) {
+ base::ResetAndReturn(&init_done_cb_).Run(audio_decoder_, NULL);
+ precreated_decoders_.clear();
+ return;
+ }
+
+ audio_decoder_ = NULL;
+
+ if (precreated_decoders_.empty()) {
+ base::ResetAndReturn(&init_done_cb_).Run(NULL, NULL);
+ return;
+ }
+
+ decrypted_stream_ = new DecryptingDemuxerStream(
+ message_loop_, request_decryptor_notification_cb_);
+ decrypted_stream_->Initialize(
+ input_stream_,
+ base::Bind(&AudioDecoderFactory::OnDecryptingDemuxerStreamInitDone,
+ weak_this_));
+}
+
+void AudioDecoderFactory::OnDecryptingDemuxerStreamInitDone(
+ PipelineStatus status) {
+ if (status != PIPELINE_OK) {
+ decrypted_stream_ = NULL;
+ base::ResetAndReturn(&init_done_cb_).Run(NULL, NULL);
+ return;
+ }
+
+ DCHECK(!decrypted_stream_->audio_decoder_config().is_encrypted());
+ input_stream_ = decrypted_stream_;
+ InitializeNextDecoder();
+}
+
+void AudioDecoderFactory::InitializeNextDecoder() {
+ DCHECK(!precreated_decoders_.empty());
+
+ audio_decoder_ = precreated_decoders_.front();
+ precreated_decoders_.pop_front();
+ DCHECK(audio_decoder_);
+ audio_decoder_->Initialize(
+ input_stream_,
+ base::Bind(&AudioDecoderFactory::OnDecoderInitDone, weak_this_),
+ statistics_cb_);
+}
+
+void AudioDecoderFactory::OnDecoderInitDone(PipelineStatus status) {
+ if (status != PIPELINE_OK) {
+ if (!precreated_decoders_.empty())
+ InitializeNextDecoder();
+ else
+ base::ResetAndReturn(&init_done_cb_).Run(NULL, NULL);
+ return;
+ }
+
+ precreated_decoders_.clear();
+ base::ResetAndReturn(&init_done_cb_).Run(audio_decoder_, decrypted_stream_);
+}
+
+AudioDecoderFactory::~AudioDecoderFactory() {}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698