[M120 Migration][MM][CAPI] Fix the logic for media using capi player.
[platform/framework/web/chromium-efl.git] / media / mojo / services / mojo_demuxer_stream_adapter.h
1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_DEMUXER_STREAM_ADAPTER_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_DEMUXER_STREAM_ADAPTER_H_
7
8 #include <memory>
9
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/mojom/demuxer_stream.mojom.h"
15 #include "media/mojo/services/media_mojo_export.h"
16 #include "mojo/public/cpp/bindings/pending_remote.h"
17 #include "mojo/public/cpp/bindings/remote.h"
18 #include "third_party/abseil-cpp/absl/types/optional.h"
19
20 namespace media {
21
22 class MojoDecoderBufferReader;
23
24 // This class acts as a MojoRendererService-side stub for a real DemuxerStream
25 // that is part of a Pipeline in a remote application. Roughly speaking, it
26 // takes a mojo::Remote<mojom::DemuxerStream> and exposes it as a DemuxerStream
27 // for use by media components.
28 class MEDIA_MOJO_EXPORT MojoDemuxerStreamAdapter : public DemuxerStream {
29  public:
30   // |demuxer_stream| is connected to the mojom::DemuxerStream that |this|
31   // will
32   //     become the client of.
33   // |stream_ready_cb| will be invoked when |demuxer_stream| has fully
34   //     initialized and |this| is ready for use.
35   // NOTE: Illegal to call any methods until |stream_ready_cb| is invoked.
36   MojoDemuxerStreamAdapter(
37       mojo::PendingRemote<mojom::DemuxerStream> demuxer_stream,
38       base::OnceClosure stream_ready_cb);
39
40   MojoDemuxerStreamAdapter(const MojoDemuxerStreamAdapter&) = delete;
41   MojoDemuxerStreamAdapter& operator=(const MojoDemuxerStreamAdapter&) = delete;
42
43   ~MojoDemuxerStreamAdapter() override;
44
45   // DemuxerStream implementation.
46   void Read(uint32_t count, ReadCB read_cb) override;
47   AudioDecoderConfig audio_decoder_config() override;
48   VideoDecoderConfig video_decoder_config() override;
49   Type type() const override;
50   void EnableBitstreamConverter() override;
51   bool SupportsConfigChanges() override;
52
53  private:
54   void OnStreamReady(Type type,
55                      mojo::ScopedDataPipeConsumerHandle consumer_handle,
56                      const absl::optional<AudioDecoderConfig>& audio_config,
57                      const absl::optional<VideoDecoderConfig>& video_config);
58
59   // The callback from |demuxer_stream_| that a read operation has completed.
60   // |read_cb| is a callback from the client who invoked Read() on |this|.
61   void OnBufferReady(Status status,
62                      std::vector<mojom::DecoderBufferPtr> batch_buffers,
63                      const absl::optional<AudioDecoderConfig>& audio_config,
64                      const absl::optional<VideoDecoderConfig>& video_config);
65
66   void OnBufferRead(scoped_refptr<DecoderBuffer> buffer);
67
68   void UpdateConfig(const absl::optional<AudioDecoderConfig>& audio_config,
69                     const absl::optional<VideoDecoderConfig>& video_config);
70
71   // See constructor for descriptions.
72   mojo::Remote<mojom::DemuxerStream> demuxer_stream_;
73   base::OnceClosure stream_ready_cb_;
74
75   // The last ReadCB received through a call to Read().
76   // Used to store the results of OnBufferReady() in the event it is called
77   // with Status::kConfigChanged and we don't have an up to date
78   // AudioDecoderConfig yet. In that case we can't forward the results
79   // on to the caller of Read() until OnAudioDecoderConfigChanged is observed.
80   ReadCB read_cb_;
81
82   // The current config.
83   AudioDecoderConfig audio_config_;
84   VideoDecoderConfig video_config_;
85
86   Type type_ = Type::UNKNOWN;
87   Status status_ = Status::kOk;
88
89   size_t actual_read_count_ = 0;
90
91   DemuxerStream::DecoderBufferVector buffer_queue_;
92
93   std::unique_ptr<MojoDecoderBufferReader> mojo_decoder_buffer_reader_;
94
95   base::WeakPtrFactory<MojoDemuxerStreamAdapter> weak_factory_{this};
96 };
97
98 }  // namespace media
99
100 #endif  // MEDIA_MOJO_SERVICES_MOJO_DEMUXER_STREAM_ADAPTER_H_