Revert of Linux MSan: enable swarming/sharding for browser_tests. (patchset #1 id...
[chromium-blink-merge.git] / media / mojo / services / mojo_demuxer_stream_adapter.h
blobe56705b554a83f2b0fc7b2752f953b011eed2f4e
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 mojo::DemuxerStreamPtr and exposes it as a DemuxerStream for use by
21 // media components.
22 class MojoDemuxerStreamAdapter : public DemuxerStream,
23 public mojo::DemuxerStreamClient {
24 public:
25 // |demuxer_stream| is connected to the mojo::DemuxerStream that |this| will
26 // become the client of.
27 // |stream_ready_cb| will be invoked when |stream| has fully initialized
28 // and |this| is ready for use.
29 // NOTE: Illegal to call any methods until |stream_ready_cb| is invoked.
30 MojoDemuxerStreamAdapter(mojo::DemuxerStreamPtr demuxer_stream,
31 const base::Closure& stream_ready_cb);
32 ~MojoDemuxerStreamAdapter() override;
34 // DemuxerStream implementation.
35 void Read(const ReadCB& read_cb) override;
36 AudioDecoderConfig audio_decoder_config() override;
37 VideoDecoderConfig video_decoder_config() override;
38 Type type() const override;
39 void EnableBitstreamConverter() override;
40 bool SupportsConfigChanges() override;
41 VideoRotation video_rotation() override;
43 // mojo::DemuxerStreamClient implementation.
44 void OnStreamReady(mojo::ScopedDataPipeConsumerHandle pipe) override;
45 void OnAudioDecoderConfigChanged(mojo::AudioDecoderConfigPtr config) override;
46 void OnVideoDecoderConfigChanged(mojo::VideoDecoderConfigPtr config) override;
48 private:
49 // The callback from |demuxer_stream_| that a read operation has completed.
50 // |read_cb| is a callback from the client who invoked Read() on |this|.
51 void OnBufferReady(mojo::DemuxerStream::Status status,
52 mojo::MediaDecoderBufferPtr buffer);
54 // See constructor for descriptions.
55 mojo::DemuxerStreamPtr demuxer_stream_;
56 base::Closure stream_ready_cb_;
58 // The last ReadCB received through a call to Read().
59 // Used to store the results of OnBufferReady() in the event it is called
60 // with DemuxerStream::Status::kConfigChanged and we don't have an up to
61 // date AudioDecoderConfig yet. In that case we can't forward the results
62 // on to the caller of Read() until OnAudioDecoderConfigChanged is observed.
63 DemuxerStream::ReadCB read_cb_;
65 // The front of the queue is the current config. We pop when we observe
66 // DemuxerStatus::CONFIG_CHANGED.
67 std::queue<AudioDecoderConfig> audio_config_queue_;
68 std::queue<VideoDecoderConfig> video_config_queue_;
70 DemuxerStream::Type type_;
72 // DataPipe for deserializing the data section of DecoderBuffers from.
73 mojo::ScopedDataPipeConsumerHandle stream_pipe_;
75 base::WeakPtrFactory<MojoDemuxerStreamAdapter> weak_factory_;
76 DISALLOW_COPY_AND_ASSIGN(MojoDemuxerStreamAdapter);
79 } // namespace media
81 #endif // MEDIA_MOJO_SERVICES_MOJO_DEMUXER_STREAM_ADAPTER_H_