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

Side by Side Diff: media/mojo/services/mojo_demuxer_stream_adapter.cc

Issue 684963003: Add support for external video renderers in mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo_config
Patch Set: More MSVC... Created 6 years, 1 month 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/mojo/services/mojo_demuxer_stream_adapter.h" 5 #include "media/mojo/services/mojo_demuxer_stream_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "media/base/decoder_buffer.h" 9 #include "media/base/decoder_buffer.h"
10 #include "media/mojo/services/media_type_converters.h" 10 #include "media/mojo/services/media_type_converters.h"
11 11
12 namespace media { 12 namespace media {
13 13
14 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( 14 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter(
15 mojo::DemuxerStreamPtr demuxer_stream, 15 mojo::DemuxerStreamPtr demuxer_stream,
16 const base::Closure& stream_ready_cb) 16 const base::Closure& stream_ready_cb)
17 : demuxer_stream_(demuxer_stream.Pass()), 17 : demuxer_stream_(demuxer_stream.Pass()),
18 stream_ready_cb_(stream_ready_cb), 18 stream_ready_cb_(stream_ready_cb),
19 type_(DemuxerStream::UNKNOWN),
19 weak_factory_(this) { 20 weak_factory_(this) {
20 DVLOG(1) << __FUNCTION__; 21 DVLOG(1) << __FUNCTION__;
21 demuxer_stream_.set_client(this); 22 demuxer_stream_.set_client(this);
22 } 23 }
23 24
24 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() { 25 MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() {
25 DVLOG(1) << __FUNCTION__; 26 DVLOG(1) << __FUNCTION__;
26 } 27 }
27 28
28 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) { 29 void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) {
29 DVLOG(3) << __FUNCTION__; 30 DVLOG(3) << __FUNCTION__;
30 // We shouldn't be holding on to a previous callback if a new Read() came in. 31 // We shouldn't be holding on to a previous callback if a new Read() came in.
31 DCHECK(read_cb_.is_null()); 32 DCHECK(read_cb_.is_null());
32 read_cb_ = read_cb; 33 read_cb_ = read_cb;
33 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady, 34 demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady,
34 weak_factory_.GetWeakPtr())); 35 weak_factory_.GetWeakPtr()));
35 } 36 }
36 37
37 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() { 38 AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() {
38 DCHECK(!config_queue_.empty()); 39 DCHECK_EQ(type_, DemuxerStream::AUDIO);
39 return config_queue_.front(); 40 DCHECK(!audio_config_queue_.empty());
41 return audio_config_queue_.front();
40 } 42 }
41 43
42 VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() { 44 VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() {
43 NOTREACHED(); 45 DCHECK_EQ(type_, DemuxerStream::VIDEO);
44 return VideoDecoderConfig(); 46 DCHECK(!video_config_queue_.empty());
47 return video_config_queue_.front();
45 } 48 }
46 49
47 media::DemuxerStream::Type MojoDemuxerStreamAdapter::type() { 50 DemuxerStream::Type MojoDemuxerStreamAdapter::type() {
48 return media::DemuxerStream::AUDIO; 51 return type_;
49 } 52 }
50 53
51 void MojoDemuxerStreamAdapter::EnableBitstreamConverter() { 54 void MojoDemuxerStreamAdapter::EnableBitstreamConverter() {
52 NOTREACHED(); 55 NOTIMPLEMENTED();
53 } 56 }
54 57
55 bool MojoDemuxerStreamAdapter::SupportsConfigChanges() { 58 bool MojoDemuxerStreamAdapter::SupportsConfigChanges() {
56 return true; 59 return true;
57 } 60 }
58 61
59 VideoRotation MojoDemuxerStreamAdapter::video_rotation() { 62 VideoRotation MojoDemuxerStreamAdapter::video_rotation() {
60 NOTIMPLEMENTED(); 63 NOTIMPLEMENTED();
61 return VIDEO_ROTATION_0; 64 return VIDEO_ROTATION_0;
62 } 65 }
63 66
64 void MojoDemuxerStreamAdapter::OnStreamReady( 67 void MojoDemuxerStreamAdapter::OnStreamReady(
65 mojo::ScopedDataPipeConsumerHandle pipe) { 68 mojo::ScopedDataPipeConsumerHandle pipe) {
66 DVLOG(1) << __FUNCTION__; 69 DVLOG(1) << __FUNCTION__;
67 // TODO(tim): We don't support pipe streaming yet. 70 // TODO(tim): We don't support pipe streaming yet.
68 DCHECK(!pipe.is_valid()); 71 DCHECK(!pipe.is_valid());
69 DCHECK(!config_queue_.empty()); 72 DCHECK_NE(type_, DemuxerStream::UNKNOWN);
70 stream_ready_cb_.Run(); 73 stream_ready_cb_.Run();
71 } 74 }
72 75
73 void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged( 76 void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged(
74 mojo::AudioDecoderConfigPtr config) { 77 mojo::AudioDecoderConfigPtr config) {
75 config_queue_.push(config.To<media::AudioDecoderConfig>()); 78 DCHECK(type_ == DemuxerStream::UNKNOWN || type_ == DemuxerStream::AUDIO)
79 << type_;
80 type_ = DemuxerStream::AUDIO;
81
82 audio_config_queue_.push(config.To<AudioDecoderConfig>());
76 83
77 if (!read_cb_.is_null()) { 84 if (!read_cb_.is_null()) {
78 read_cb_.Run(media::DemuxerStream::Status::kConfigChanged, NULL); 85 read_cb_.Run(DemuxerStream::Status::kConfigChanged, NULL);
79 read_cb_.Reset(); 86 read_cb_.Reset();
80 } 87 }
81 } 88 }
89
90 void MojoDemuxerStreamAdapter::OnVideoDecoderConfigChanged(
91 mojo::VideoDecoderConfigPtr config) {
92 DCHECK(type_ == DemuxerStream::UNKNOWN || type_ == DemuxerStream::VIDEO)
93 << type_;
94 type_ = DemuxerStream::VIDEO;
95
96 video_config_queue_.push(config.To<VideoDecoderConfig>());
97
98 if (!read_cb_.is_null()) {
99 read_cb_.Run(DemuxerStream::Status::kConfigChanged, NULL);
100 read_cb_.Reset();
101 }
102 }
82 103
83 void MojoDemuxerStreamAdapter::OnBufferReady( 104 void MojoDemuxerStreamAdapter::OnBufferReady(
84 mojo::DemuxerStream::Status status, 105 mojo::DemuxerStream::Status status,
85 mojo::MediaDecoderBufferPtr buffer) { 106 mojo::MediaDecoderBufferPtr buffer) {
86 DVLOG(3) << __FUNCTION__; 107 DVLOG(3) << __FUNCTION__;
87 DCHECK(!read_cb_.is_null()); 108 DCHECK(!read_cb_.is_null());
88 DCHECK(!config_queue_.empty()); 109 DCHECK_NE(type_, DemuxerStream::UNKNOWN);
89 110
90 media::DemuxerStream::Status media_status( 111 DemuxerStream::Status media_status(
91 static_cast<media::DemuxerStream::Status>(status)); 112 static_cast<DemuxerStream::Status>(status));
92 scoped_refptr<media::DecoderBuffer> media_buffer( 113 scoped_refptr<DecoderBuffer> media_buffer(
93 buffer.To<scoped_refptr<media::DecoderBuffer> >()); 114 buffer.To<scoped_refptr<DecoderBuffer>>());
94 115
95 if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) { 116 if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) {
96 DCHECK(!media_buffer.get()); 117 DCHECK(!media_buffer.get());
97 config_queue_.pop();
98 118
99 // If the |config_queue_| is empty we need to wait for 119 // If the configuration queue is empty we need to wait for a config change
100 // OnAudioDecoderConfigChanged before invoking |read_cb|. 120 // event before invoking |read_cb_|.
101 if (config_queue_.empty()) 121
102 return; 122 if (type_ == DemuxerStream::AUDIO) {
123 audio_config_queue_.pop();
124 if (audio_config_queue_.empty())
125 return;
126 } else if (type_ == DemuxerStream::VIDEO) {
127 video_config_queue_.pop();
128 if (video_config_queue_.empty())
129 return;
130 }
103 } 131 }
132
104 read_cb_.Run(media_status, media_buffer); 133 read_cb_.Run(media_status, media_buffer);
105 read_cb_.Reset(); 134 read_cb_.Reset();
106 } 135 }
107 136
108 } // namespace media 137 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/mojo_demuxer_stream_adapter.h ('k') | media/mojo/services/mojo_demuxer_stream_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698