Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / mojo / services / mojo_demuxer_stream_adapter.h
blobb6b4d9372ede8f9e218604f96dee1ac68c00442c
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_
8 #include <queue>
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"
16 namespace media {
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 interfaces::DemuxerStreamPtr and exposes it as a DemuxerStream for
21 // use by
22 // media components.
23 class MojoDemuxerStreamAdapter : public DemuxerStream {
24 public:
25 // |demuxer_stream| is connected to the interfaces::DemuxerStream that |this|
26 // will
27 // become the client of.
28 // |stream_ready_cb| will be invoked when |demuxer_stream| has fully
29 // initialized and |this| is ready for use.
30 // NOTE: Illegal to call any methods until |stream_ready_cb| is invoked.
31 MojoDemuxerStreamAdapter(interfaces::DemuxerStreamPtr demuxer_stream,
32 const base::Closure& stream_ready_cb);
33 ~MojoDemuxerStreamAdapter() override;
35 // DemuxerStream implementation.
36 void Read(const ReadCB& read_cb) override;
37 AudioDecoderConfig audio_decoder_config() override;
38 VideoDecoderConfig video_decoder_config() override;
39 Type type() const override;
40 void EnableBitstreamConverter() override;
41 bool SupportsConfigChanges() override;
42 VideoRotation video_rotation() override;
44 private:
45 void OnStreamReady(interfaces::DemuxerStream::Type type,
46 mojo::ScopedDataPipeConsumerHandle pipe,
47 interfaces::AudioDecoderConfigPtr audio_config,
48 interfaces::VideoDecoderConfigPtr video_config);
50 // The callback from |demuxer_stream_| that a read operation has completed.
51 // |read_cb| is a callback from the client who invoked Read() on |this|.
52 void OnBufferReady(interfaces::DemuxerStream::Status status,
53 interfaces::DecoderBufferPtr buffer,
54 interfaces::AudioDecoderConfigPtr audio_config,
55 interfaces::VideoDecoderConfigPtr video_config);
57 void UpdateConfig(interfaces::AudioDecoderConfigPtr audio_config,
58 interfaces::VideoDecoderConfigPtr video_config);
60 // See constructor for descriptions.
61 interfaces::DemuxerStreamPtr demuxer_stream_;
62 base::Closure stream_ready_cb_;
64 // The last ReadCB received through a call to Read().
65 // Used to store the results of OnBufferReady() in the event it is called
66 // with DemuxerStream::Status::kConfigChanged and we don't have an up to
67 // date AudioDecoderConfig yet. In that case we can't forward the results
68 // on to the caller of Read() until OnAudioDecoderConfigChanged is observed.
69 DemuxerStream::ReadCB read_cb_;
71 // The current config.
72 AudioDecoderConfig audio_config_;
73 VideoDecoderConfig video_config_;
75 DemuxerStream::Type type_;
77 // DataPipe for deserializing the data section of DecoderBuffers from.
78 mojo::ScopedDataPipeConsumerHandle stream_pipe_;
80 base::WeakPtrFactory<MojoDemuxerStreamAdapter> weak_factory_;
81 DISALLOW_COPY_AND_ASSIGN(MojoDemuxerStreamAdapter);
84 } // namespace media
86 #endif // MEDIA_MOJO_SERVICES_MOJO_DEMUXER_STREAM_ADAPTER_H_