OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "services/media/factory_service/media_source_impl.h" | 8 #include "services/media/factory_service/media_source_impl.h" |
9 #include "services/media/framework/callback_joiner.h" | 9 #include "services/media/framework/callback_joiner.h" |
10 #include "services/media/framework/conversion_pipeline_builder.h" | 10 #include "services/media/framework/conversion_pipeline_builder.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 base::Bind(&MediaSourceImpl::OnDemuxInitialized, | 69 base::Bind(&MediaSourceImpl::OnDemuxInitialized, |
70 base::Unretained(this), result)); | 70 base::Unretained(this), result)); |
71 }); | 71 }); |
72 } | 72 } |
73 | 73 |
74 MediaSourceImpl::~MediaSourceImpl() {} | 74 MediaSourceImpl::~MediaSourceImpl() {} |
75 | 75 |
76 void MediaSourceImpl::OnDemuxInitialized(Result result) { | 76 void MediaSourceImpl::OnDemuxInitialized(Result result) { |
77 demux_part_ = graph_.Add(demux_); | 77 demux_part_ = graph_.Add(demux_); |
78 | 78 |
79 auto demux_streams = demux_->streams(); | 79 const std::vector<Demux::DemuxStream*>& demux_streams = demux_->streams(); |
80 for (auto demux_stream : demux_streams) { | 80 for (Demux::DemuxStream* demux_stream : demux_streams) { |
81 streams_.push_back(std::unique_ptr<Stream>(new Stream( | 81 streams_.push_back(std::unique_ptr<Stream>(new Stream( |
82 demux_part_.output(demux_stream->index()), demux_stream->stream_type(), | 82 demux_part_.output(demux_stream->index()), demux_stream->stream_type(), |
83 Convert(allowed_media_types_), &graph_))); | 83 Convert(allowed_media_types_), &graph_))); |
84 } | 84 } |
85 | 85 |
86 allowed_media_types_.reset(); | 86 allowed_media_types_.reset(); |
87 | 87 |
88 init_complete_.Occur(); | 88 init_complete_.Occur(); |
89 } | 89 } |
90 | 90 |
91 void MediaSourceImpl::GetStreams(const GetStreamsCallback& callback) { | 91 void MediaSourceImpl::GetStreams(const GetStreamsCallback& callback) { |
92 init_complete_.When([this, callback]() { | 92 init_complete_.When([this, callback]() { |
93 auto result = Array<MediaSourceStreamDescriptorPtr>::New(streams_.size()); | 93 Array<MediaSourceStreamDescriptorPtr> result = |
| 94 Array<MediaSourceStreamDescriptorPtr>::New(streams_.size()); |
94 for (size_t i = 0; i < streams_.size(); i++) { | 95 for (size_t i = 0; i < streams_.size(); i++) { |
95 MediaSourceStreamDescriptorPtr descriptor = | 96 MediaSourceStreamDescriptorPtr descriptor = |
96 MediaSourceStreamDescriptor::New(); | 97 MediaSourceStreamDescriptor::New(); |
97 descriptor->index = i; | 98 descriptor->index = i; |
98 descriptor->media_type = streams_[i]->media_type(); | 99 descriptor->media_type = streams_[i]->media_type(); |
99 descriptor->original_media_type = streams_[i]->original_media_type(); | 100 descriptor->original_media_type = streams_[i]->original_media_type(); |
100 result[i] = descriptor.Pass(); | 101 result[i] = descriptor.Pass(); |
101 } | 102 } |
102 callback.Run(result.Pass()); | 103 callback.Run(result.Pass()); |
103 }); | 104 }); |
(...skipping 23 matching lines...) Expand all Loading... |
127 } | 128 } |
128 | 129 |
129 void MediaSourceImpl::GetStatus(uint64_t version_last_seen, | 130 void MediaSourceImpl::GetStatus(uint64_t version_last_seen, |
130 const GetStatusCallback& callback) { | 131 const GetStatusCallback& callback) { |
131 status_publisher_.Get(version_last_seen, callback); | 132 status_publisher_.Get(version_last_seen, callback); |
132 } | 133 } |
133 | 134 |
134 void MediaSourceImpl::Prepare(const PrepareCallback& callback) { | 135 void MediaSourceImpl::Prepare(const PrepareCallback& callback) { |
135 DCHECK(init_complete_.occurred()); | 136 DCHECK(init_complete_.occurred()); |
136 | 137 |
137 for (auto& stream : streams_) { | 138 for (std::unique_ptr<Stream>& stream : streams_) { |
138 stream->EnsureSink(); | 139 stream->EnsureSink(); |
139 } | 140 } |
140 graph_.Prepare(); | 141 graph_.Prepare(); |
141 state_ = MediaState::PAUSED; | 142 state_ = MediaState::PAUSED; |
142 callback.Run(); | 143 callback.Run(); |
143 status_publisher_.SendUpdates(); | 144 status_publisher_.SendUpdates(); |
144 } | 145 } |
145 | 146 |
146 void MediaSourceImpl::Prime(const PrimeCallback& callback) { | 147 void MediaSourceImpl::Prime(const PrimeCallback& callback) { |
147 DCHECK(init_complete_.occurred()); | 148 DCHECK(init_complete_.occurred()); |
148 | 149 |
149 std::shared_ptr<CallbackJoiner> callback_joiner = CallbackJoiner::Create(); | 150 std::shared_ptr<CallbackJoiner> callback_joiner = CallbackJoiner::Create(); |
150 | 151 |
151 for (auto& stream : streams_) { | 152 for (std::unique_ptr<Stream>& stream : streams_) { |
152 stream->PrimeConnection(callback_joiner->NewCallback()); | 153 stream->PrimeConnection(callback_joiner->NewCallback()); |
153 } | 154 } |
154 | 155 |
155 callback_joiner->WhenJoined(callback); | 156 callback_joiner->WhenJoined(callback); |
156 } | 157 } |
157 | 158 |
158 void MediaSourceImpl::Flush(const FlushCallback& callback) { | 159 void MediaSourceImpl::Flush(const FlushCallback& callback) { |
159 DCHECK(init_complete_.occurred()); | 160 DCHECK(init_complete_.occurred()); |
160 | 161 |
161 graph_.FlushAllOutputs(demux_part_); | 162 graph_.FlushAllOutputs(demux_part_); |
162 | 163 |
163 std::shared_ptr<CallbackJoiner> callback_joiner = CallbackJoiner::Create(); | 164 std::shared_ptr<CallbackJoiner> callback_joiner = CallbackJoiner::Create(); |
164 | 165 |
165 for (auto& stream : streams_) { | 166 for (std::unique_ptr<Stream>& stream : streams_) { |
166 stream->FlushConnection(callback_joiner->NewCallback()); | 167 stream->FlushConnection(callback_joiner->NewCallback()); |
167 } | 168 } |
168 | 169 |
169 callback_joiner->WhenJoined(callback); | 170 callback_joiner->WhenJoined(callback); |
170 } | 171 } |
171 | 172 |
172 void MediaSourceImpl::Seek(int64_t position, const SeekCallback& callback) { | 173 void MediaSourceImpl::Seek(int64_t position, const SeekCallback& callback) { |
173 DCHECK(init_complete_.occurred()); | 174 DCHECK(init_complete_.occurred()); |
174 | 175 |
175 demux_->Seek(position, [this, callback]() { | 176 demux_->Seek(position, [this, callback]() { |
(...skipping 18 matching lines...) Expand all Loading... |
194 | 195 |
195 output_ = output; | 196 output_ = output; |
196 | 197 |
197 if (allowed_stream_types == nullptr) { | 198 if (allowed_stream_types == nullptr) { |
198 // No conversion requested. | 199 // No conversion requested. |
199 stream_type_ = SafeClone(original_stream_type_); | 200 stream_type_ = SafeClone(original_stream_type_); |
200 } else if (!BuildConversionPipeline(*original_stream_type_, | 201 } else if (!BuildConversionPipeline(*original_stream_type_, |
201 *allowed_stream_types, graph, &output_, | 202 *allowed_stream_types, graph, &output_, |
202 &stream_type_)) { | 203 &stream_type_)) { |
203 // Can't convert to any allowed type. | 204 // Can't convert to any allowed type. |
204 stream_type_ = StreamType::Create(StreamType::Scheme::kNone); | 205 // TODO(dalesat): Indicate this in some way other than blowing up. |
| 206 LOG(ERROR) << "can't convert to any allowed type"; |
| 207 abort(); |
205 } | 208 } |
206 } | 209 } |
207 | 210 |
208 MediaSourceImpl::Stream::~Stream() {} | 211 MediaSourceImpl::Stream::~Stream() {} |
209 | 212 |
210 MediaTypePtr MediaSourceImpl::Stream::media_type() const { | 213 MediaTypePtr MediaSourceImpl::Stream::media_type() const { |
211 return Convert(stream_type_); | 214 return Convert(stream_type_); |
212 } | 215 } |
213 | 216 |
214 MediaTypePtr MediaSourceImpl::Stream::original_media_type() const { | 217 MediaTypePtr MediaSourceImpl::Stream::original_media_type() const { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 const MojoProducer::FlushConnectionCallback callback) { | 268 const MojoProducer::FlushConnectionCallback callback) { |
266 if (producer_ != nullptr) { | 269 if (producer_ != nullptr) { |
267 producer_->FlushConnection(callback); | 270 producer_->FlushConnection(callback); |
268 } else { | 271 } else { |
269 callback.Run(); | 272 callback.Run(); |
270 } | 273 } |
271 } | 274 } |
272 | 275 |
273 } // namespace media | 276 } // namespace media |
274 } // namespace mojo | 277 } // namespace mojo |
OLD | NEW |