Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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. | |
| 4 | |
| 5 #ifndef MEDIA_REMOTING_REMOTE_STREAM_PROVIDER_H_ | |
| 6 #define MEDIA_REMOTING_REMOTE_STREAM_PROVIDER_H_ | |
| 7 | |
| 8 #include <deque> | |
| 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/media_resource.h" | |
| 14 #include "media/base/video_decoder_config.h" | |
| 15 #include "media/remoting/rpc_broker.h" | |
| 16 | |
| 17 namespace media { | |
| 18 namespace remoting { | |
| 19 | |
| 20 // Simulates the DemuxerStream on Media Remoting receiver. Receives data from | |
| 21 // mojo data pipe, and returns one frame or/and status when Read() is called. | |
| 22 class RemoteMediaStream final : public DemuxerStream { | |
|
miu
2017/03/29 01:39:14
ditto: Same stuff here: Don't consider this only u
miu
2017/03/29 01:39:14
Consider just forward-declaring this class here, a
xjz
2017/03/30 23:21:31
Done.
xjz
2017/03/30 23:21:31
Done.
| |
| 23 public: | |
| 24 RemoteMediaStream(RpcBroker* rpc_broker, Type type, int remote_handle); | |
| 25 ~RemoteMediaStream() override; | |
| 26 | |
| 27 // DemuxerStream implementation. | |
| 28 void Read(const ReadCB& read_cb) override; | |
| 29 AudioDecoderConfig audio_decoder_config() override; | |
| 30 VideoDecoderConfig video_decoder_config() override; | |
| 31 DemuxerStream::Type type() const override; | |
| 32 bool SupportsConfigChanges() override; | |
| 33 VideoRotation video_rotation() override; | |
| 34 bool enabled() const override; | |
| 35 void set_enabled(bool enabled, base::TimeDelta timestamp) override {} | |
| 36 void SetStreamStatusChangeCB(const StreamStatusChangeCB& cb) override {} | |
| 37 | |
| 38 void Initialize(const base::Closure& init_done_cb); | |
| 39 void FlushUntil(int count); | |
| 40 void AppendBuffer(scoped_refptr<DecoderBuffer> buffer); | |
| 41 | |
| 42 private: | |
| 43 // RPC messages handlers. | |
| 44 void OnReceivedRpc(std::unique_ptr<pb::RpcMessage> message); | |
| 45 void OnInitializeCallback(std::unique_ptr<pb::RpcMessage> message); | |
| 46 void OnReadUntilCallback(std::unique_ptr<pb::RpcMessage> message); | |
| 47 | |
| 48 // Issues the ReadUntil RPC message when read is pending and buffer is empty. | |
| 49 void SendReadUntil(); | |
| 50 | |
| 51 // Run and reset the read callback. | |
| 52 void CompleteRead(DemuxerStream::Status status); | |
| 53 | |
| 54 // Update the |audio/video_decoder_config_|. When config changes in the mid | |
| 55 // stream, the new config will be pushed in the end of queue. Old config will | |
| 56 // be droped when all associated frames are consumed. | |
| 57 void UpdateConfig(const pb::AudioDecoderConfig* audio_message, | |
| 58 const pb::VideoDecoderConfig* video_message); | |
| 59 | |
| 60 RpcBroker* rpc_broker_; // Outlives this class. | |
|
miu
2017/03/29 01:39:14
const
xjz
2017/03/30 23:21:31
Done.
| |
| 61 Type type_ = DemuxerStream::UNKNOWN; | |
|
miu
2017/03/29 01:39:14
const (and no default value, since it is set by ct
xjz
2017/03/30 23:21:31
Done.
| |
| 62 int remote_handle_ = RpcBroker::kInvalidHandle; | |
|
miu
2017/03/29 01:39:14
ditto: no default assignments here, since ctor set
xjz
2017/03/30 23:21:31
Done.
| |
| 63 int rpc_handle_ = RpcBroker::kInvalidHandle; | |
| 64 | |
| 65 // Set when Initialize() is called, and will be run only once after | |
| 66 // initialization is done. | |
| 67 base::Closure init_done_callback_; | |
| 68 | |
| 69 // The read until count in the last ReadUntil RPC message. | |
| 70 int last_read_until_count_ = 0; | |
| 71 | |
| 72 // Indicates whether Audio/VideoDecoderConfig changed and the frames with the | |
| 73 // old config are not yet consumed. The new config is stored in the end of | |
| 74 // |audio/video_decoder_config_|; | |
| 75 bool config_changed_ = false; | |
| 76 | |
| 77 // Indicates whether a ReadUntil RPC message was sent without receiving the | |
| 78 // ReadUntilCallback message yet. | |
| 79 bool read_until_sent_ = false; | |
| 80 | |
| 81 // Set when Read() is called. Run only once when read completes. | |
| 82 ReadCB read_complete_callback_; | |
| 83 | |
| 84 std::deque<scoped_refptr<DecoderBuffer>> buffers_; | |
| 85 std::deque<AudioDecoderConfig> audio_decoder_config_; | |
| 86 std::deque<VideoDecoderConfig> video_decoder_config_; | |
| 87 | |
| 88 base::WeakPtrFactory<RemoteMediaStream> weak_factory_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(RemoteMediaStream); | |
| 91 }; | |
| 92 | |
| 93 // Simulates a stream provider on Media Remoting receiver. | |
| 94 class RemoteStreamProvider final : public MediaResource { | |
|
miu
2017/03/29 01:39:14
naming: How about just StreamProvider (you're alre
xjz
2017/03/30 23:21:31
Done. Will rename the files to "stream_provider.*"
| |
| 95 public: | |
| 96 explicit RemoteStreamProvider(RpcBroker* rpc_broker); | |
| 97 | |
| 98 ~RemoteStreamProvider() override; | |
| 99 | |
| 100 // MediaResource implemenation. | |
| 101 DemuxerStream* GetStream(DemuxerStream::Type type) override; | |
| 102 | |
| 103 void Initialize(int remote_audio_handle, | |
| 104 int remote_video_handle, | |
| 105 const base::Closure& callback); | |
| 106 void AppendBuffer(DemuxerStream::Type type, | |
| 107 scoped_refptr<DecoderBuffer> buffer); | |
| 108 void FlushUntil(DemuxerStream::Type type, int count); | |
| 109 | |
| 110 private: | |
| 111 // Called when audio/video stream is initialized. | |
| 112 void AudioStreamInitialized(); | |
| 113 void VideoStreamInitialized(); | |
| 114 | |
| 115 RpcBroker* rpc_broker_; | |
|
miu
2017/03/29 01:39:14
const
xjz
2017/03/30 23:21:31
Done.
| |
| 116 std::unique_ptr<RemoteMediaStream> video_stream_; | |
| 117 std::unique_ptr<RemoteMediaStream> audio_stream_; | |
| 118 bool audio_stream_initialized_ = false; | |
| 119 bool video_stream_initialized_ = false; | |
| 120 | |
| 121 // Set when Initialize() is called, and will run only once when both video | |
| 122 // and audio streams are initialized. | |
| 123 base::Closure init_done_callback_; | |
| 124 | |
| 125 base::WeakPtrFactory<RemoteStreamProvider> weak_factory_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(RemoteStreamProvider); | |
| 128 }; | |
| 129 | |
| 130 } // namespace remoting | |
| 131 } // namespace media | |
| 132 #endif | |
| OLD | NEW |