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"
8 #include "base/bind_helpers.h"
9 #include "base/callback_helpers.h"
13 DemuxerStreamProviderShim::DemuxerStreamProviderShim(
14 mojo::DemuxerStreamPtr audio
,
15 mojo::DemuxerStreamPtr video
,
16 const base::Closure
& demuxer_ready_cb
)
17 : demuxer_ready_cb_(demuxer_ready_cb
),
20 DCHECK(audio
|| video
);
21 DCHECK(!demuxer_ready_cb_
.is_null());
24 streams_
.push_back(new MojoDemuxerStreamAdapter(
26 base::Bind(&DemuxerStreamProviderShim::OnStreamReady
,
27 weak_factory_
.GetWeakPtr())));
31 streams_
.push_back(new MojoDemuxerStreamAdapter(
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
)
51 void DemuxerStreamProviderShim::OnStreamReady() {
52 if (++streams_ready_
== streams_
.size())
53 base::ResetAndReturn(&demuxer_ready_cb_
).Run();