Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / media / mojo / services / demuxer_stream_provider_shim.cc
blobc3dbc2c7b828305ec69bf91db88f2d2a20ab0358
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 mojo::DemuxerStreamPtr audio,
15 mojo::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