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

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

Issue 2491043003: MediaResource refactoring to support multiple streams (Closed)
Patch Set: rebase Created 3 years, 10 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
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 std::vector<DemuxerStream*> MediaResourceShim::GetStreams() {
34 DCHECK(demuxer_ready_cb_.is_null());
35 std::vector<DemuxerStream*> result;
36 for (auto& stream : streams_)
37 result.push_back(stream.get());
38 return result;
32 } 39 }
33 40
34 // This function returns only the first stream of the given |type| for now. 41 void MediaResourceShim::SetStreamStatusChangeCB(
35 // TODO(servolk): Make this work with multiple streams. 42 const StreamStatusChangeCB& cb) {
36 DemuxerStream* DemuxerStreamProviderShim::GetStream(DemuxerStream::Type type) { 43 NOTIMPLEMENTED();
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 } 44 }
45 45
46 void DemuxerStreamProviderShim::OnStreamReady() { 46 void MediaResourceShim::OnStreamReady() {
47 if (++streams_ready_ == streams_.size()) 47 if (++streams_ready_ == streams_.size())
48 base::ResetAndReturn(&demuxer_ready_cb_).Run(); 48 base::ResetAndReturn(&demuxer_ready_cb_).Run();
49 } 49 }
50 50
51 } // namespace media 51 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698