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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/mojo/services/mojo_demuxer_stream_adapter.h"
6
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "media/base/decoder_buffer.h"
10 #include "media/mojo/services/media_type_converters.h"
11
12 namespace media {
13
14 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter(
scherkus (not reviewing) 2014/09/09 20:35:32 media/ loves us some clang-format ... we just have
15 mojo::DemuxerStreamPtr stream,
16 const base::Closure& stream_ready) : demuxer_stream_(stream.Pass()),
17 stream_ready_callback_(stream_ready),
18 weak_factory_(this) {
19 demuxer_stream_.set_client(this);
20 }
21
22 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() {
23 }
24
25 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) {
26 // We shouldn't be holding on to a previous callback if a new Read() came in.
27 DCHECK(on_config_change_cb_.is_null());
28 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady,
29 weak_factory_.GetWeakPtr(),
30 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.
31 }
32
33 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() {
34 DCHECK(!config_queue_.empty());
35 return config_queue_.front();
36 }
37
38 VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() {
39 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.
40 return VideoDecoderConfig();
41 }
42
43 media::DemuxerStream::Type MojoDemuxerStreamAdapter::type() {
44 return media::DemuxerStream::AUDIO;
45 }
46
47 void MojoDemuxerStreamAdapter::EnableBitstreamConverter() {
48 NOTIMPLEMENTED();
49 }
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.
50
51 bool MojoDemuxerStreamAdapter::SupportsConfigChanges() {
52 return true;
53 }
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
54
55 VideoRotation MojoDemuxerStreamAdapter::video_rotation() {
56 NOTIMPLEMENTED();
57 return VIDEO_ROTATION_0;
58 }
59
60 void MojoDemuxerStreamAdapter::OnStreamReady(
61 mojo::ScopedDataPipeConsumerHandle pipe) {
62 // TODO(tim): We don't support pipe streaming yet.
63 DCHECK(!pipe.is_valid());
64 DCHECK(!config_queue_.empty());
65 stream_ready_callback_.Run();
66 }
67
68 void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged(
69 mojo::AudioDecoderConfigPtr config) {
70 config_queue_.push(config.To<media::AudioDecoderConfig>());
71
72 if (!on_config_change_cb_.is_null())
73 base::ResetAndReturn(&on_config_change_cb_).Run();
74 }
75
76 void MojoDemuxerStreamAdapter::OnBufferReady(
77 const ReadCB& read_cb,
78 mojo::DemuxerStream::Status status,
79 mojo::MediaDecoderBufferPtr buffer) {
80 DCHECK(on_config_change_cb_.is_null());
81 DCHECK(!config_queue_.empty());
82
83 media::DemuxerStream::Status media_status(
84 static_cast<media::DemuxerStream::Status>(status));
85 scoped_refptr<media::DecoderBuffer> media_buffer(
86 buffer.To<scoped_refptr<media::DecoderBuffer> >());
87
88 if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) {
89 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.
90 config_queue_.pop();
91
92 // If the |config_queue_| is empty we need to wait for
93 // OnAudioDecoderConfigChanged before invoking |read_cb|.
94 if (config_queue_.empty()) {
95 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.
96 return;
97 }
98 }
99 read_cb.Run(media_status, media_buffer);
100 }
101
102 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698