Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / mojo / services / demuxer_stream_provider_shim.cc
blob2c16cc52a4baa970231885861c09e4a37d13fe16
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.
5 #include "media/mojo/services/demuxer_stream_provider_shim.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback_helpers.h"
11 namespace media {
13 DemuxerStreamProviderShim::DemuxerStreamProviderShim(
14 interfaces::DemuxerStreamPtr audio,
15 interfaces::DemuxerStreamPtr video,
16 const base::Closure& demuxer_ready_cb)
17 : demuxer_ready_cb_(demuxer_ready_cb),
18 streams_ready_(0),
19 weak_factory_(this) {
20 DCHECK(audio || video);
21 DCHECK(!demuxer_ready_cb_.is_null());
23 if (audio) {
24 streams_.push_back(new MojoDemuxerStreamAdapter(
25 audio.Pass(),
26 base::Bind(&DemuxerStreamProviderShim::OnStreamReady,
27 weak_factory_.GetWeakPtr())));
30 if (video) {
31 streams_.push_back(new MojoDemuxerStreamAdapter(
32 video.Pass(),
33 base::Bind(&DemuxerStreamProviderShim::OnStreamReady,
34 weak_factory_.GetWeakPtr())));
38 DemuxerStreamProviderShim::~DemuxerStreamProviderShim() {
41 DemuxerStream* DemuxerStreamProviderShim::GetStream(DemuxerStream::Type type) {
42 DCHECK(demuxer_ready_cb_.is_null());
43 for (auto* stream : streams_) {
44 if (stream->type() == type)
45 return stream;
48 return nullptr;
51 void DemuxerStreamProviderShim::OnStreamReady() {
52 if (++streams_ready_ == streams_.size())
53 base::ResetAndReturn(&demuxer_ready_cb_).Run();
56 } // namespace media