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