OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_REMOTING_REMOTE_DEMUXER_STREAM_ADAPTER_H_ | 5 #ifndef MEDIA_REMOTING_REMOTE_DEMUXER_STREAM_ADAPTER_H_ |
6 #define MEDIA_REMOTING_REMOTE_DEMUXER_STREAM_ADAPTER_H_ | 6 #define MEDIA_REMOTING_REMOTE_DEMUXER_STREAM_ADAPTER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "base/callback_forward.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/optional.h" | 16 #include "base/optional.h" |
16 #include "media/base/audio_decoder_config.h" | 17 #include "media/base/audio_decoder_config.h" |
17 #include "media/base/demuxer_stream.h" | 18 #include "media/base/demuxer_stream.h" |
18 #include "media/base/video_decoder_config.h" | 19 #include "media/base/video_decoder_config.h" |
19 #include "media/mojo/interfaces/remoting.mojom.h" | 20 #include "media/mojo/interfaces/remoting.mojom.h" |
20 #include "media/remoting/rpc/rpc_broker.h" | 21 #include "media/remoting/rpc/rpc_broker.h" |
| 22 #include "media/remoting/triggers.h" |
21 #include "mojo/public/cpp/system/data_pipe.h" | 23 #include "mojo/public/cpp/system/data_pipe.h" |
22 | 24 |
23 namespace base { | 25 namespace base { |
24 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
25 } | 27 } |
26 | 28 |
27 namespace media { | 29 namespace media { |
28 | 30 |
29 class DemuxerStream; | 31 class DemuxerStream; |
30 | 32 |
31 namespace remoting { | 33 namespace remoting { |
32 | 34 |
33 // Class to fetch audio/video buffer from demuxer and send it to browser process | 35 // Class to fetch audio/video buffer from demuxer and send it to browser process |
34 // via mojo::Remoting interface. Note the class is created and run on media | 36 // via mojo::Remoting interface. Note the class is created and run on media |
35 // thread using |media_task_runner|, Mojo data pipe should run on media thread, | 37 // thread using |media_task_runner|, Mojo data pipe should run on media thread, |
36 // while RPC message should be sent on main thread using |main_task_runner|. | 38 // while RPC message should be sent on main thread using |main_task_runner|. |
37 class RemoteDemuxerStreamAdapter { | 39 class RemoteDemuxerStreamAdapter { |
38 public: | 40 public: |
| 41 using ErrorCallback = base::Callback<void(StopTrigger)>; |
| 42 |
39 // |main_task_runner|: Task runner to post RPC message on main thread | 43 // |main_task_runner|: Task runner to post RPC message on main thread |
40 // |media_task_runner|: Task runner to run whole class on media thread. | 44 // |media_task_runner|: Task runner to run whole class on media thread. |
41 // |name|: Demuxer stream name. For troubleshooting purposes. | 45 // |name|: Demuxer stream name. For troubleshooting purposes. |
42 // |demuxer_stream|: Demuxer component. | 46 // |demuxer_stream|: Demuxer component. |
43 // |rpc_broker|: Broker class to handle incoming and outgoing RPC message. It | 47 // |rpc_broker|: Broker class to handle incoming and outgoing RPC message. It |
44 // is used only on the main thread. | 48 // is used only on the main thread. |
45 // |rpc_handle|: Unique value that references this RemoteDemuxerStreamAdapter. | 49 // |rpc_handle|: Unique value that references this RemoteDemuxerStreamAdapter. |
46 // |stream_sender_info|: Transfer of pipe binding on the media thread. It is | 50 // |stream_sender_info|: Transfer of pipe binding on the media thread. It is |
47 // to access mojo interface for sending data stream. | 51 // to access mojo interface for sending data stream. |
48 // |producer_handle|: handle to send data using mojo data pipe. | 52 // |producer_handle|: handle to send data using mojo data pipe. |
| 53 // |error_callback|: Run if a fatal runtime error occurs and remoting should |
| 54 // be shut down. |
49 RemoteDemuxerStreamAdapter( | 55 RemoteDemuxerStreamAdapter( |
50 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 56 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
51 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, | 57 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, |
52 const std::string& name, | 58 const std::string& name, |
53 ::media::DemuxerStream* demuxer_stream, | 59 ::media::DemuxerStream* demuxer_stream, |
54 const base::WeakPtr<RpcBroker>& rpc_broker, | 60 const base::WeakPtr<RpcBroker>& rpc_broker, |
55 int rpc_handle, | 61 int rpc_handle, |
56 mojom::RemotingDataStreamSenderPtrInfo stream_sender_info, | 62 mojom::RemotingDataStreamSenderPtrInfo stream_sender_info, |
57 mojo::ScopedDataPipeProducerHandle producer_handle); | 63 mojo::ScopedDataPipeProducerHandle producer_handle, |
| 64 const ErrorCallback& error_callback); |
58 ~RemoteDemuxerStreamAdapter(); | 65 ~RemoteDemuxerStreamAdapter(); |
59 | 66 |
60 // Rpc handle for this class. This is used for sending/receiving RPC message | 67 // Rpc handle for this class. This is used for sending/receiving RPC message |
61 // with specific hanle using Rpcbroker. | 68 // with specific hanle using Rpcbroker. |
62 int rpc_handle() const { return rpc_handle_; } | 69 int rpc_handle() const { return rpc_handle_; } |
63 | 70 |
| 71 // Returns the number of bytes that have been written to the data pipe since |
| 72 // the last call to this method. This is polled periodically by |
| 73 // RemoteRendererImpl for metrics purposes. |
| 74 int64_t GetBytesWrittenAndReset(); |
| 75 |
64 // Signals if system is in flushing state. The caller uses |flushing| to | 76 // Signals if system is in flushing state. The caller uses |flushing| to |
65 // signal when flush starts and when is done. During flush operation, all | 77 // signal when flush starts and when is done. During flush operation, all |
66 // fetching data actions will be discarded. The return value indicates frame | 78 // fetching data actions will be discarded. The return value indicates frame |
67 // count in order to signal receiver what frames are in flight before flush, | 79 // count in order to signal receiver what frames are in flight before flush, |
68 // or base::nullopt if the flushing state was unchanged. | 80 // or base::nullopt if the flushing state was unchanged. |
69 base::Optional<uint32_t> SignalFlush(bool flushing); | 81 base::Optional<uint32_t> SignalFlush(bool flushing); |
70 | 82 |
71 private: | 83 private: |
72 friend class MockRemoteDemuxerStreamAdapter; | 84 friend class MockRemoteDemuxerStreamAdapter; |
73 | 85 |
(...skipping 13 matching lines...) Expand all Loading... |
87 void TryWriteData(MojoResult result); | 99 void TryWriteData(MojoResult result); |
88 void ResetPendingFrame(); | 100 void ResetPendingFrame(); |
89 bool IsProcessingReadRequest() const { | 101 bool IsProcessingReadRequest() const { |
90 // |read_until_callback_handle_| is set when RPC_DS_READUNTIL message is | 102 // |read_until_callback_handle_| is set when RPC_DS_READUNTIL message is |
91 // received, and will be reset to invalid value after | 103 // received, and will be reset to invalid value after |
92 // RPC_DS_READUNTIL_CALLBACK is sent back to receiver. Therefore it can be | 104 // RPC_DS_READUNTIL_CALLBACK is sent back to receiver. Therefore it can be |
93 // used to determine if the class is in the reading state or not. | 105 // used to determine if the class is in the reading state or not. |
94 return read_until_callback_handle_ != kInvalidHandle; | 106 return read_until_callback_handle_ != kInvalidHandle; |
95 } | 107 } |
96 | 108 |
97 // Callback function when data pipe error occurs. | 109 // Callback function when a fatal runtime error occurs. |
98 void OnFatalError(const char* reason); | 110 void OnFatalError(StopTrigger stop_trigger); |
99 | 111 |
100 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 112 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
101 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 113 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
102 | 114 |
103 // Name of demuxer stream. Debug only. | 115 // Name of demuxer stream. Debug only. |
104 const std::string name_; | 116 const std::string name_; |
105 | 117 |
106 // Weak pointer of RpcBroker. It should use |main_task_runner_| to access the | 118 // Weak pointer of RpcBroker. It should use |main_task_runner_| to access the |
107 // interfaces. | 119 // interfaces. |
108 const base::WeakPtr<RpcBroker> rpc_broker_; | 120 const base::WeakPtr<RpcBroker> rpc_broker_; |
109 | 121 |
110 // RPC handle for this demuxer stream service. | 122 // RPC handle for this demuxer stream service. |
111 const int rpc_handle_; | 123 const int rpc_handle_; |
112 | 124 |
113 // Demuxer stream and stream type. | 125 // Demuxer stream and stream type. |
114 ::media::DemuxerStream* const demuxer_stream_; | 126 ::media::DemuxerStream* const demuxer_stream_; |
115 const ::media::DemuxerStream::Type type_; | 127 const ::media::DemuxerStream::Type type_; |
116 | 128 |
| 129 // Run by OnFatalError to propagate StopTriggers back to the |
| 130 // RemoteRendererImpl that owns this instance. This is not-null at |
| 131 // construction time, and set to null the first time OnFatalError() is called. |
| 132 ErrorCallback error_callback_; |
| 133 |
117 // Remote RPC handle for demuxer initialization. The value is provided by | 134 // Remote RPC handle for demuxer initialization. The value is provided by |
118 // receiver from RPC_DS_INITIALIZE message and will be used as handle in | 135 // receiver from RPC_DS_INITIALIZE message and will be used as handle in |
119 // RPC_DS_INITIALIZE_CALLBACK message. | 136 // RPC_DS_INITIALIZE_CALLBACK message. |
120 int remote_callback_handle_; | 137 int remote_callback_handle_; |
121 | 138 |
122 // Remote RPC handle for reading data from demuxer. The value is provided by | 139 // Remote RPC handle for reading data from demuxer. The value is provided by |
123 // receiver from RPC_DS_READUNTIL message and will be used as handle in | 140 // receiver from RPC_DS_READUNTIL message and will be used as handle in |
124 // RPC_DS_READUNTIL_CALLBACK message. The handle can be used to indicate | 141 // RPC_DS_READUNTIL_CALLBACK message. The handle can be used to indicate |
125 // whether it is in reading state because not only each RPC_DS_READUNTIL | 142 // whether it is in reading state because not only each RPC_DS_READUNTIL |
126 // message provides different callback handle, but also it is only set to | 143 // message provides different callback handle, but also it is only set to |
(...skipping 22 matching lines...) Expand all Loading... |
149 mojo::Watcher write_watcher_; | 166 mojo::Watcher write_watcher_; |
150 | 167 |
151 // Keeps latest demuxer stream status and audio/video decoder config. | 168 // Keeps latest demuxer stream status and audio/video decoder config. |
152 ::media::DemuxerStream::Status media_status_; | 169 ::media::DemuxerStream::Status media_status_; |
153 ::media::AudioDecoderConfig audio_config_; | 170 ::media::AudioDecoderConfig audio_config_; |
154 ::media::VideoDecoderConfig video_config_; | 171 ::media::VideoDecoderConfig video_config_; |
155 | 172 |
156 ::media::mojom::RemotingDataStreamSenderPtr stream_sender_; | 173 ::media::mojom::RemotingDataStreamSenderPtr stream_sender_; |
157 mojo::ScopedDataPipeProducerHandle producer_handle_; | 174 mojo::ScopedDataPipeProducerHandle producer_handle_; |
158 | 175 |
| 176 // Tracks the number of bytes written to the pipe. |
| 177 int64_t bytes_written_to_pipe_; |
| 178 |
159 // WeakPtrFactory only for reading buffer from demuxer stream. This is used | 179 // WeakPtrFactory only for reading buffer from demuxer stream. This is used |
160 // for canceling all read callbacks provided to the |demuxer_stream_| before a | 180 // for canceling all read callbacks provided to the |demuxer_stream_| before a |
161 // flush. | 181 // flush. |
162 base::WeakPtrFactory<RemoteDemuxerStreamAdapter> request_buffer_weak_factory_; | 182 base::WeakPtrFactory<RemoteDemuxerStreamAdapter> request_buffer_weak_factory_; |
163 // WeakPtrFactory for normal usage. | 183 // WeakPtrFactory for normal usage. |
164 base::WeakPtrFactory<RemoteDemuxerStreamAdapter> weak_factory_; | 184 base::WeakPtrFactory<RemoteDemuxerStreamAdapter> weak_factory_; |
165 | 185 |
166 DISALLOW_COPY_AND_ASSIGN(RemoteDemuxerStreamAdapter); | 186 DISALLOW_COPY_AND_ASSIGN(RemoteDemuxerStreamAdapter); |
167 }; | 187 }; |
168 | 188 |
169 mojo::DataPipe* CreateDataPipe(); | 189 mojo::DataPipe* CreateDataPipe(); |
170 | 190 |
171 } // namespace remoting | 191 } // namespace remoting |
172 } // namespace media | 192 } // namespace media |
173 | 193 |
174 #endif // MEDIA_REMOTING_REMOTE_DEMUXER_STREAM_ADAPTER_H_ | 194 #endif // MEDIA_REMOTING_REMOTE_DEMUXER_STREAM_ADAPTER_H_ |
OLD | NEW |