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

Unified Diff: media/mojo/services/mojo_demuxer_stream_adapter.cc

Issue 518163003: media: scaffolding and plumbing for MojoRenderer{Impl, Service} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@medr
Patch Set: add test Created 6 years, 3 months 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
« no previous file with comments | « media/mojo/services/mojo_demuxer_stream_adapter.h ('k') | media/mojo/services/mojo_demuxer_stream_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/services/mojo_demuxer_stream_adapter.cc
diff --git a/media/mojo/services/mojo_demuxer_stream_adapter.cc b/media/mojo/services/mojo_demuxer_stream_adapter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0e9c246e0504b8a6885eafffa04c263fe8f02338
--- /dev/null
+++ b/media/mojo/services/mojo_demuxer_stream_adapter.cc
@@ -0,0 +1,102 @@
+// Copyright 2014 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/mojo/services/mojo_demuxer_stream_adapter.h"
+
+#include "base/bind.h"
+#include "base/callback_helpers.h"
+#include "media/base/decoder_buffer.h"
+#include "media/mojo/services/media_type_converters.h"
+
+namespace media {
+
+MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter(
+ mojo::DemuxerStreamPtr stream,
+ const base::Closure& stream_ready) : demuxer_stream_(stream.Pass()),
+ stream_ready_callback_(stream_ready),
+ weak_factory_(this) {
+ demuxer_stream_.set_client(this);
+}
+
+MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() {
+}
+
+void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) {
+ // We shouldn't be holding on to a previous callback if a new Read() came in.
+ DCHECK(on_config_change_cb_.is_null());
+ demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady,
+ weak_factory_.GetWeakPtr(),
+ read_cb));
+}
+
+AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() {
+ DCHECK(!config_queue_.empty());
+ return config_queue_.front();
+}
+
+VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() {
+ DCHECK(false); // TODO(tim): Video unsupported.
+ return VideoDecoderConfig();
+}
+
+media::DemuxerStream::Type MojoDemuxerStreamAdapter::type() {
+ return media::DemuxerStream::AUDIO;
+}
+
+void MojoDemuxerStreamAdapter::EnableBitstreamConverter() {
+ NOTIMPLEMENTED();
+}
+
+bool MojoDemuxerStreamAdapter::SupportsConfigChanges() {
+ return true;
+}
+
+VideoRotation MojoDemuxerStreamAdapter::video_rotation() {
+ NOTIMPLEMENTED();
+ return VIDEO_ROTATION_0;
+}
+
+void MojoDemuxerStreamAdapter::OnStreamReady(
+ mojo::ScopedDataPipeConsumerHandle pipe) {
+ // TODO(tim): We don't support pipe streaming yet.
+ DCHECK(!pipe.is_valid());
+ DCHECK(!config_queue_.empty());
+ stream_ready_callback_.Run();
+}
+
+void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged(
+ mojo::AudioDecoderConfigPtr config) {
+ config_queue_.push(config.To<media::AudioDecoderConfig>());
+
+ if (!on_config_change_cb_.is_null())
+ base::ResetAndReturn(&on_config_change_cb_).Run();
+}
+
+void MojoDemuxerStreamAdapter::OnBufferReady(
+ const ReadCB& read_cb,
+ mojo::DemuxerStream::Status status,
+ mojo::MediaDecoderBufferPtr buffer) {
+ DCHECK(on_config_change_cb_.is_null());
+ DCHECK(!config_queue_.empty());
+
+ media::DemuxerStream::Status media_status(
+ static_cast<media::DemuxerStream::Status>(status));
+ scoped_refptr<media::DecoderBuffer> media_buffer(
+ buffer.To<scoped_refptr<media::DecoderBuffer> >());
+
+ if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) {
+ DCHECK_GE(config_queue_.size(), 1U);
+ config_queue_.pop();
+
+ // If the |config_queue_| is empty we need to wait for
+ // OnAudioDecoderConfigChanged before invoking |read_cb|.
+ if (config_queue_.empty()) {
+ on_config_change_cb_ = base::Bind(read_cb, media_status, media_buffer);
+ return;
+ }
+ }
+ read_cb.Run(media_status, media_buffer);
+}
+
+} // namespace media
« no previous file with comments | « media/mojo/services/mojo_demuxer_stream_adapter.h ('k') | media/mojo/services/mojo_demuxer_stream_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698