| OLD | NEW |
| (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/demuxer_stream_provider_shim.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/bind_helpers.h" | |
| 11 #include "base/callback_helpers.h" | |
| 12 | |
| 13 namespace media { | |
| 14 | |
| 15 DemuxerStreamProviderShim::DemuxerStreamProviderShim( | |
| 16 std::vector<mojom::DemuxerStreamPtr> streams, | |
| 17 const base::Closure& demuxer_ready_cb) | |
| 18 : demuxer_ready_cb_(demuxer_ready_cb), | |
| 19 streams_ready_(0), | |
| 20 weak_factory_(this) { | |
| 21 DCHECK(!streams.empty()); | |
| 22 DCHECK(!demuxer_ready_cb_.is_null()); | |
| 23 | |
| 24 for (auto& s : streams) { | |
| 25 streams_.emplace_back(new MojoDemuxerStreamAdapter( | |
| 26 std::move(s), base::Bind(&DemuxerStreamProviderShim::OnStreamReady, | |
| 27 weak_factory_.GetWeakPtr()))); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 DemuxerStreamProviderShim::~DemuxerStreamProviderShim() { | |
| 32 } | |
| 33 | |
| 34 // This function returns only the first stream of the given |type| for now. | |
| 35 // TODO(servolk): Make this work with multiple streams. | |
| 36 DemuxerStream* DemuxerStreamProviderShim::GetStream(DemuxerStream::Type type) { | |
| 37 DCHECK(demuxer_ready_cb_.is_null()); | |
| 38 for (auto& stream : streams_) { | |
| 39 if (stream->type() == type) | |
| 40 return stream.get(); | |
| 41 } | |
| 42 | |
| 43 return nullptr; | |
| 44 } | |
| 45 | |
| 46 void DemuxerStreamProviderShim::OnStreamReady() { | |
| 47 if (++streams_ready_ == streams_.size()) | |
| 48 base::ResetAndReturn(&demuxer_ready_cb_).Run(); | |
| 49 } | |
| 50 | |
| 51 } // namespace media | |
| OLD | NEW |