Chromium Code Reviews| Index: media/remoting/remote_stream_provider.h |
| diff --git a/media/remoting/remote_stream_provider.h b/media/remoting/remote_stream_provider.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ce8b65451e5d8687a12a169323074167ef261315 |
| --- /dev/null |
| +++ b/media/remoting/remote_stream_provider.h |
| @@ -0,0 +1,132 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_REMOTING_REMOTE_STREAM_PROVIDER_H_ |
| +#define MEDIA_REMOTING_REMOTE_STREAM_PROVIDER_H_ |
| + |
| +#include <deque> |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "media/base/audio_decoder_config.h" |
| +#include "media/base/demuxer_stream.h" |
| +#include "media/base/media_resource.h" |
| +#include "media/base/video_decoder_config.h" |
| +#include "media/remoting/rpc_broker.h" |
| + |
| +namespace media { |
| +namespace remoting { |
| + |
| +// Simulates the DemuxerStream on Media Remoting receiver. Receives data from |
| +// mojo data pipe, and returns one frame or/and status when Read() is called. |
| +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.
|
| + public: |
| + RemoteMediaStream(RpcBroker* rpc_broker, Type type, int remote_handle); |
| + ~RemoteMediaStream() override; |
| + |
| + // DemuxerStream implementation. |
| + void Read(const ReadCB& read_cb) override; |
| + AudioDecoderConfig audio_decoder_config() override; |
| + VideoDecoderConfig video_decoder_config() override; |
| + DemuxerStream::Type type() const override; |
| + bool SupportsConfigChanges() override; |
| + VideoRotation video_rotation() override; |
| + bool enabled() const override; |
| + void set_enabled(bool enabled, base::TimeDelta timestamp) override {} |
| + void SetStreamStatusChangeCB(const StreamStatusChangeCB& cb) override {} |
| + |
| + void Initialize(const base::Closure& init_done_cb); |
| + void FlushUntil(int count); |
| + void AppendBuffer(scoped_refptr<DecoderBuffer> buffer); |
| + |
| + private: |
| + // RPC messages handlers. |
| + void OnReceivedRpc(std::unique_ptr<pb::RpcMessage> message); |
| + void OnInitializeCallback(std::unique_ptr<pb::RpcMessage> message); |
| + void OnReadUntilCallback(std::unique_ptr<pb::RpcMessage> message); |
| + |
| + // Issues the ReadUntil RPC message when read is pending and buffer is empty. |
| + void SendReadUntil(); |
| + |
| + // Run and reset the read callback. |
| + void CompleteRead(DemuxerStream::Status status); |
| + |
| + // Update the |audio/video_decoder_config_|. When config changes in the mid |
| + // stream, the new config will be pushed in the end of queue. Old config will |
| + // be droped when all associated frames are consumed. |
| + void UpdateConfig(const pb::AudioDecoderConfig* audio_message, |
| + const pb::VideoDecoderConfig* video_message); |
| + |
| + RpcBroker* rpc_broker_; // Outlives this class. |
|
miu
2017/03/29 01:39:14
const
xjz
2017/03/30 23:21:31
Done.
|
| + 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.
|
| + 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.
|
| + int rpc_handle_ = RpcBroker::kInvalidHandle; |
| + |
| + // Set when Initialize() is called, and will be run only once after |
| + // initialization is done. |
| + base::Closure init_done_callback_; |
| + |
| + // The read until count in the last ReadUntil RPC message. |
| + int last_read_until_count_ = 0; |
| + |
| + // Indicates whether Audio/VideoDecoderConfig changed and the frames with the |
| + // old config are not yet consumed. The new config is stored in the end of |
| + // |audio/video_decoder_config_|; |
| + bool config_changed_ = false; |
| + |
| + // Indicates whether a ReadUntil RPC message was sent without receiving the |
| + // ReadUntilCallback message yet. |
| + bool read_until_sent_ = false; |
| + |
| + // Set when Read() is called. Run only once when read completes. |
| + ReadCB read_complete_callback_; |
| + |
| + std::deque<scoped_refptr<DecoderBuffer>> buffers_; |
| + std::deque<AudioDecoderConfig> audio_decoder_config_; |
| + std::deque<VideoDecoderConfig> video_decoder_config_; |
| + |
| + base::WeakPtrFactory<RemoteMediaStream> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RemoteMediaStream); |
| +}; |
| + |
| +// Simulates a stream provider on Media Remoting receiver. |
| +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.*"
|
| + public: |
| + explicit RemoteStreamProvider(RpcBroker* rpc_broker); |
| + |
| + ~RemoteStreamProvider() override; |
| + |
| + // MediaResource implemenation. |
| + DemuxerStream* GetStream(DemuxerStream::Type type) override; |
| + |
| + void Initialize(int remote_audio_handle, |
| + int remote_video_handle, |
| + const base::Closure& callback); |
| + void AppendBuffer(DemuxerStream::Type type, |
| + scoped_refptr<DecoderBuffer> buffer); |
| + void FlushUntil(DemuxerStream::Type type, int count); |
| + |
| + private: |
| + // Called when audio/video stream is initialized. |
| + void AudioStreamInitialized(); |
| + void VideoStreamInitialized(); |
| + |
| + RpcBroker* rpc_broker_; |
|
miu
2017/03/29 01:39:14
const
xjz
2017/03/30 23:21:31
Done.
|
| + std::unique_ptr<RemoteMediaStream> video_stream_; |
| + std::unique_ptr<RemoteMediaStream> audio_stream_; |
| + bool audio_stream_initialized_ = false; |
| + bool video_stream_initialized_ = false; |
| + |
| + // Set when Initialize() is called, and will run only once when both video |
| + // and audio streams are initialized. |
| + base::Closure init_done_callback_; |
| + |
| + base::WeakPtrFactory<RemoteStreamProvider> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RemoteStreamProvider); |
| +}; |
| + |
| +} // namespace remoting |
| +} // namespace media |
| +#endif |