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 #ifndef MEDIA_MOJO_SERVICES_DEMUXER_STREAM_PROVIDER_SHIM_H_
6 #define MEDIA_MOJO_SERVICES_DEMUXER_STREAM_PROVIDER_SHIM_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/memory/weak_ptr.h"
11 #include "media/base/demuxer_stream_provider.h"
12 #include "media/mojo/services/mojo_demuxer_stream_adapter.h"
16 // DemuxerStreamProvider shim for mojo::DemuxerStreams.
17 class DemuxerStreamProviderShim
: public DemuxerStreamProvider
{
19 // Constructs the shim; at least a single audio or video stream must be
20 // provided. |demuxer_ready_cb| will be called once the streams have been
21 // initialized. Calling any method before then is an error.
22 DemuxerStreamProviderShim(mojo::DemuxerStreamPtr audio
,
23 mojo::DemuxerStreamPtr video
,
24 const base::Closure
& demuxer_ready_cb
);
25 ~DemuxerStreamProviderShim() override
;
27 // DemuxerStreamProvider interface.
28 DemuxerStream
* GetStream(DemuxerStream::Type type
) override
;
31 // Called as each mojo::DemuxerStream becomes ready. Once all streams are
32 // ready it will fire the |demuxer_ready_cb_| provided during construction.
35 // Stored copy the ready callback provided during construction; cleared once
36 // all streams are ready.
37 base::Closure demuxer_ready_cb_
;
39 // Scoped container for demuxer stream adapters which interface with the
40 // mojo level demuxer streams. |streams_ready_| tracks how many streams are
41 // ready and is used by OnStreamReady() to know when |demuxer_ready_cb_|
43 ScopedVector
<MojoDemuxerStreamAdapter
> streams_
;
44 size_t streams_ready_
;
46 // WeakPtrFactorys must always be the last member variable.
47 base::WeakPtrFactory
<DemuxerStreamProviderShim
> weak_factory_
;
49 DISALLOW_COPY_AND_ASSIGN(DemuxerStreamProviderShim
);
54 #endif // MEDIA_MOJO_SERVICES_DEMUXER_STREAM_PROVIDER_SHIM_H_