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

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

Issue 551963004: media: scaffolding and plumbing for MojoRenderer{Impl, Service} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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(
scherkus (not reviewing) 2014/09/09 20:35:32 media/ loves us some clang-format ... we just have
+ 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));
xhwang 2014/09/10 00:00:52 Based on the DemuxerStream API, we should have at
tim (not reviewing) 2014/09/10 23:08:28 I see. I was going to say why bother adding state
xhwang 2014/09/15 04:57:28 For kConfigChanged, the buffer is always NULL.
tim (not reviewing) 2014/09/15 21:52:51 Acknowledged.
+}
+
+AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() {
+ DCHECK(!config_queue_.empty());
+ return config_queue_.front();
+}
+
+VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() {
+ DCHECK(false); // TODO(tim): Video unsupported.
scherkus (not reviewing) 2014/09/09 20:35:32 NOTREACHED()?
xhwang 2014/09/10 00:00:52 NOTREACHED() given l.44.
tim (not reviewing) 2014/09/10 23:08:28 Done.
tim (not reviewing) 2014/09/10 23:08:29 Done.
+ return VideoDecoderConfig();
+}
+
+media::DemuxerStream::Type MojoDemuxerStreamAdapter::type() {
+ return media::DemuxerStream::AUDIO;
+}
+
+void MojoDemuxerStreamAdapter::EnableBitstreamConverter() {
+ NOTIMPLEMENTED();
+}
xhwang 2014/09/10 00:00:52 In media pipeline this is only used by GpuVideoDec
tim (not reviewing) 2014/09/10 23:08:28 Done.
+
+bool MojoDemuxerStreamAdapter::SupportsConfigChanges() {
+ return true;
+}
xhwang 2014/09/10 00:00:52 This is only used by audio_renderer_impl.cc. So if
tim (not reviewing) 2014/09/10 23:08:28 For now I'm using ARI. In fact the test I added i
+
+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);
scherkus (not reviewing) 2014/09/09 20:35:32 DCHECK(!config_queue_.empty()) ?
tim (not reviewing) 2014/09/10 23:08:28 There should be at least 1 element in the queue at
xhwang 2014/09/15 04:57:28 scherkus was recommending to check !empty(), which
tim (not reviewing) 2014/09/15 21:52:51 Done.
+ 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);
xhwang 2014/09/10 00:00:52 If we keep a class member read_cb_, we don't need
tim (not reviewing) 2014/09/10 23:08:28 See my question at 30, I might be misunderstanding
xhwang 2014/09/15 04:57:28 See my reply above.
tim (not reviewing) 2014/09/15 21:52:51 Acknowledged.
+ return;
+ }
+ }
+ read_cb.Run(media_status, media_buffer);
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698