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_MOJO_DEMUXER_STREAM_ADAPTER_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_DEMUXER_STREAM_ADAPTER_H_
10 #include "base/memory/weak_ptr.h"
11 #include "media/base/audio_decoder_config.h"
12 #include "media/base/demuxer_stream.h"
13 #include "media/base/video_decoder_config.h"
14 #include "media/mojo/interfaces/demuxer_stream.mojom.h"
18 // This class acts as a MojoRendererService-side stub for a real DemuxerStream
19 // that is part of a Pipeline in a remote application. Roughly speaking, it
20 // takes a mojo::DemuxerStreamPtr and exposes it as a DemuxerStream for use by
22 class MojoDemuxerStreamAdapter
: public DemuxerStream
{
24 // |demuxer_stream| is connected to the mojo::DemuxerStream that |this| will
25 // become the client of.
26 // |stream_ready_cb| will be invoked when |demuxer_stream| has fully
27 // initialized and |this| is ready for use.
28 // NOTE: Illegal to call any methods until |stream_ready_cb| is invoked.
29 MojoDemuxerStreamAdapter(mojo::DemuxerStreamPtr demuxer_stream
,
30 const base::Closure
& stream_ready_cb
);
31 ~MojoDemuxerStreamAdapter() override
;
33 // DemuxerStream implementation.
34 void Read(const ReadCB
& read_cb
) override
;
35 AudioDecoderConfig
audio_decoder_config() override
;
36 VideoDecoderConfig
video_decoder_config() override
;
37 Type
type() const override
;
38 void EnableBitstreamConverter() override
;
39 bool SupportsConfigChanges() override
;
40 VideoRotation
video_rotation() override
;
43 void OnStreamReady(mojo::DemuxerStream::Type type
,
44 mojo::ScopedDataPipeConsumerHandle pipe
,
45 mojo::AudioDecoderConfigPtr audio_config
,
46 mojo::VideoDecoderConfigPtr video_config
);
48 // The callback from |demuxer_stream_| that a read operation has completed.
49 // |read_cb| is a callback from the client who invoked Read() on |this|.
50 void OnBufferReady(mojo::DemuxerStream::Status status
,
51 mojo::MediaDecoderBufferPtr buffer
,
52 mojo::AudioDecoderConfigPtr audio_config
,
53 mojo::VideoDecoderConfigPtr video_config
);
55 void UpdateConfig(mojo::AudioDecoderConfigPtr audio_config
,
56 mojo::VideoDecoderConfigPtr video_config
);
58 // See constructor for descriptions.
59 mojo::DemuxerStreamPtr demuxer_stream_
;
60 base::Closure stream_ready_cb_
;
62 // The last ReadCB received through a call to Read().
63 // Used to store the results of OnBufferReady() in the event it is called
64 // with DemuxerStream::Status::kConfigChanged and we don't have an up to
65 // date AudioDecoderConfig yet. In that case we can't forward the results
66 // on to the caller of Read() until OnAudioDecoderConfigChanged is observed.
67 DemuxerStream::ReadCB read_cb_
;
69 // The current config.
70 AudioDecoderConfig audio_config_
;
71 VideoDecoderConfig video_config_
;
73 DemuxerStream::Type type_
;
75 // DataPipe for deserializing the data section of DecoderBuffers from.
76 mojo::ScopedDataPipeConsumerHandle stream_pipe_
;
78 base::WeakPtrFactory
<MojoDemuxerStreamAdapter
> weak_factory_
;
79 DISALLOW_COPY_AND_ASSIGN(MojoDemuxerStreamAdapter
);
84 #endif // MEDIA_MOJO_SERVICES_MOJO_DEMUXER_STREAM_ADAPTER_H_