Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: media/remoting/courier_renderer.h

Issue 2643253003: Media Remoting Clean-up: Less-redundant naming, style consistency, etc. (Closed)
Patch Set: REBASE Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/remoting/adaptive_renderer_factory.cc ('k') | media/remoting/courier_renderer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_RENDERER_IMPL_H_ 5 #ifndef MEDIA_REMOTING_COURIER_RENDERER_H_
6 #define MEDIA_REMOTING_REMOTE_RENDERER_IMPL_H_ 6 #define MEDIA_REMOTING_COURIER_RENDERER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/optional.h" 16 #include "base/optional.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
19 #include "media/base/buffering_state.h"
20 #include "media/base/pipeline_status.h" 19 #include "media/base/pipeline_status.h"
21 #include "media/base/renderer.h" 20 #include "media/base/renderer.h"
22 #include "media/base/renderer_client.h"
23 #include "media/mojo/interfaces/remoting.mojom.h" 21 #include "media/mojo/interfaces/remoting.mojom.h"
22 #include "media/remoting/interstitial.h"
24 #include "media/remoting/metrics.h" 23 #include "media/remoting/metrics.h"
25 #include "media/remoting/remoting_interstitial_ui.h" 24 #include "media/remoting/rpc_broker.h"
26 #include "media/remoting/rpc/rpc_broker.h"
27 #include "mojo/public/cpp/system/data_pipe.h" 25 #include "mojo/public/cpp/system/data_pipe.h"
26 #include "third_party/skia/include/core/SkBitmap.h"
28 27
29 namespace media { 28 namespace media {
30 29
31 class RemotingRendererController; 30 class RendererClient;
32 class Renderer;
33 31
34 namespace remoting { 32 namespace remoting {
35 class RemoteDemuxerStreamAdapter;
36 };
37 33
38 // A media::Renderer implementation that use a media::Renderer to render 34 class DemuxerStreamAdapter;
39 // media streams. 35 class RendererController;
40 class RemoteRendererImpl : public Renderer { 36
37 // A media::Renderer implementation that proxies all operations to a remote
38 // renderer via RPCs. The CourierRenderer is instantiated by
39 // AdaptiveRendererFactory when media remoting is meant to take place.
40 //
41 // While the media content is rendered remotely, the CourierRenderer emits
42 // interstitial frames locally, to the VideoRendererSink, to indicate to the
43 // user that remoting is taking place.
44 class CourierRenderer : public Renderer {
41 public: 45 public:
42 // The whole class except for constructor and GetMediaTime() runs on 46 // The whole class except for constructor and GetMediaTime() runs on
43 // |media_task_runner|. The constructor and GetMediaTime() run on render main 47 // |media_task_runner|. The constructor and GetMediaTime() run on render main
44 // thread. 48 // thread.
45 RemoteRendererImpl( 49 CourierRenderer(scoped_refptr<base::SingleThreadTaskRunner> media_task_runner,
46 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, 50 const base::WeakPtr<RendererController>& controller,
47 const base::WeakPtr<RemotingRendererController>& 51 VideoRendererSink* video_renderer_sink);
48 remoting_renderer_controller, 52 ~CourierRenderer() final;
49 VideoRendererSink* video_renderer_sink);
50 ~RemoteRendererImpl() final;
51 53
52 private: 54 private:
53 // Callback when attempting to establish data pipe. The function is set to 55 // Callback when attempting to establish data pipe. The function is set to
54 // static in order to post task to media thread in order to avoid threading 56 // static in order to post task to media thread in order to avoid threading
55 // race condition. 57 // race condition.
56 static void OnDataPipeCreatedOnMainThread( 58 static void OnDataPipeCreatedOnMainThread(
57 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, 59 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner,
58 base::WeakPtr<RemoteRendererImpl> self, 60 base::WeakPtr<CourierRenderer> self,
59 base::WeakPtr<remoting::RpcBroker> rpc_broker, 61 base::WeakPtr<RpcBroker> rpc_broker,
60 mojom::RemotingDataStreamSenderPtrInfo audio, 62 mojom::RemotingDataStreamSenderPtrInfo audio,
61 mojom::RemotingDataStreamSenderPtrInfo video, 63 mojom::RemotingDataStreamSenderPtrInfo video,
62 mojo::ScopedDataPipeProducerHandle audio_handle, 64 mojo::ScopedDataPipeProducerHandle audio_handle,
63 mojo::ScopedDataPipeProducerHandle video_handle); 65 mojo::ScopedDataPipeProducerHandle video_handle);
64 66
65 // Callback function when RPC message is received. The function is set to 67 // Callback function when RPC message is received. The function is set to
66 // static in order to post task to media thread in order to avoid threading 68 // static in order to post task to media thread in order to avoid threading
67 // race condition. 69 // race condition.
68 static void OnMessageReceivedOnMainThread( 70 static void OnMessageReceivedOnMainThread(
69 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, 71 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner,
70 base::WeakPtr<RemoteRendererImpl> self, 72 base::WeakPtr<CourierRenderer> self,
71 std::unique_ptr<remoting::pb::RpcMessage> message); 73 std::unique_ptr<pb::RpcMessage> message);
72 74
73 // Callback when remoting interstitial needs to be updated. Will post task to 75 // Callback when remoting interstitial needs to be updated. Will post task to
74 // media thread to avoid threading race condition. 76 // media thread to avoid threading race condition.
75 static void RequestUpdateInterstitialOnMainThread( 77 static void RequestUpdateInterstitialOnMainThread(
76 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, 78 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner,
77 base::WeakPtr<RemoteRendererImpl> remote_renderer_impl, 79 base::WeakPtr<CourierRenderer> self,
78 const base::Optional<SkBitmap>& background_image, 80 const base::Optional<SkBitmap>& background_image,
79 const gfx::Size& canvas_size, 81 const gfx::Size& canvas_size,
80 RemotingInterstitialType interstitial_type); 82 InterstitialType interstitial_type);
81 83
82 public: 84 public:
83 // media::Renderer implementation. 85 // media::Renderer implementation.
84 void Initialize(DemuxerStreamProvider* demuxer_stream_provider, 86 void Initialize(DemuxerStreamProvider* demuxer_stream_provider,
85 media::RendererClient* client, 87 RendererClient* client,
86 const PipelineStatusCB& init_cb) final; 88 const PipelineStatusCB& init_cb) final;
87 void SetCdm(CdmContext* cdm_context, 89 void SetCdm(CdmContext* cdm_context,
88 const CdmAttachedCB& cdm_attached_cb) final; 90 const CdmAttachedCB& cdm_attached_cb) final;
89 void Flush(const base::Closure& flush_cb) final; 91 void Flush(const base::Closure& flush_cb) final;
90 void StartPlayingFrom(base::TimeDelta time) final; 92 void StartPlayingFrom(base::TimeDelta time) final;
91 void SetPlaybackRate(double playback_rate) final; 93 void SetPlaybackRate(double playback_rate) final;
92 void SetVolume(float volume) final; 94 void SetVolume(float volume) final;
93 base::TimeDelta GetMediaTime() final; 95 base::TimeDelta GetMediaTime() final;
94 96
95 private: 97 private:
96 friend class RemoteRendererImplTest; 98 friend class CourierRendererTest;
97 99
98 enum State { 100 enum State {
99 STATE_UNINITIALIZED, 101 STATE_UNINITIALIZED,
100 STATE_CREATE_PIPE, 102 STATE_CREATE_PIPE,
101 STATE_ACQUIRING, 103 STATE_ACQUIRING,
102 STATE_INITIALIZING, 104 STATE_INITIALIZING,
103 STATE_FLUSHING, 105 STATE_FLUSHING,
104 STATE_PLAYING, 106 STATE_PLAYING,
105 STATE_ERROR 107 STATE_ERROR
106 }; 108 };
107 109
108 // Callback when attempting to establish data pipe. Runs on media thread only. 110 // Callback when attempting to establish data pipe. Runs on media thread only.
109 void OnDataPipeCreated(mojom::RemotingDataStreamSenderPtrInfo audio, 111 void OnDataPipeCreated(mojom::RemotingDataStreamSenderPtrInfo audio,
110 mojom::RemotingDataStreamSenderPtrInfo video, 112 mojom::RemotingDataStreamSenderPtrInfo video,
111 mojo::ScopedDataPipeProducerHandle audio_handle, 113 mojo::ScopedDataPipeProducerHandle audio_handle,
112 mojo::ScopedDataPipeProducerHandle video_handle, 114 mojo::ScopedDataPipeProducerHandle video_handle,
113 int audio_rpc_handle, 115 int audio_rpc_handle,
114 int video_rpc_handle); 116 int video_rpc_handle);
115 117
116 // Callback function when RPC message is received. Runs on media thread only. 118 // Callback function when RPC message is received. Runs on media thread only.
117 void OnReceivedRpc(std::unique_ptr<remoting::pb::RpcMessage> message); 119 void OnReceivedRpc(std::unique_ptr<pb::RpcMessage> message);
118 120
119 // Function to post task to main thread in order to send RPC message. 121 // Function to post task to main thread in order to send RPC message.
120 void SendRpcToRemote(std::unique_ptr<remoting::pb::RpcMessage> message); 122 void SendRpcToRemote(std::unique_ptr<pb::RpcMessage> message);
121 123
122 // Functions when RPC message is received. 124 // Functions when RPC message is received.
123 void AcquireRendererDone(std::unique_ptr<remoting::pb::RpcMessage> message); 125 void AcquireRendererDone(std::unique_ptr<pb::RpcMessage> message);
124 void InitializeCallback(std::unique_ptr<remoting::pb::RpcMessage> message); 126 void InitializeCallback(std::unique_ptr<pb::RpcMessage> message);
125 void FlushUntilCallback(); 127 void FlushUntilCallback();
126 void SetCdmCallback(std::unique_ptr<remoting::pb::RpcMessage> message); 128 void SetCdmCallback(std::unique_ptr<pb::RpcMessage> message);
127 void OnTimeUpdate(std::unique_ptr<remoting::pb::RpcMessage> message); 129 void OnTimeUpdate(std::unique_ptr<pb::RpcMessage> message);
128 void OnBufferingStateChange( 130 void OnBufferingStateChange(std::unique_ptr<pb::RpcMessage> message);
129 std::unique_ptr<remoting::pb::RpcMessage> message); 131 void OnVideoNaturalSizeChange(std::unique_ptr<pb::RpcMessage> message);
130 void OnVideoNaturalSizeChange( 132 void OnVideoOpacityChange(std::unique_ptr<pb::RpcMessage> message);
131 std::unique_ptr<remoting::pb::RpcMessage> message); 133 void OnStatisticsUpdate(std::unique_ptr<pb::RpcMessage> message);
132 void OnVideoOpacityChange(std::unique_ptr<remoting::pb::RpcMessage> message); 134 void OnDurationChange(std::unique_ptr<pb::RpcMessage> message);
133 void OnStatisticsUpdate(std::unique_ptr<remoting::pb::RpcMessage> message);
134 void OnDurationChange(std::unique_ptr<remoting::pb::RpcMessage> message);
135 135
136 // Called to update the remoting interstitial. Update 136 // Called to update the remoting interstitial. Update
137 // |interstitial_background_| if |background_image| is set. 137 // |interstitial_background_| if |background_image| is set.
138 void UpdateInterstitial(const base::Optional<SkBitmap>& background_image, 138 void UpdateInterstitial(const base::Optional<SkBitmap>& background_image,
139 const gfx::Size& canvas_size, 139 const gfx::Size& canvas_size,
140 RemotingInterstitialType interstitial_type); 140 InterstitialType interstitial_type);
141 141
142 // Called when |current_media_time_| is updated. 142 // Called when |current_media_time_| is updated.
143 void OnMediaTimeUpdated(); 143 void OnMediaTimeUpdated();
144 144
145 // Called to update the |video_stats_queue_|. 145 // Called to update the |video_stats_queue_|.
146 void UpdateVideoStatsQueue(int video_frames_decoded, 146 void UpdateVideoStatsQueue(int video_frames_decoded,
147 int video_frames_dropped); 147 int video_frames_dropped);
148 148
149 // Called to clear all recent measurements history and schedule resuming after 149 // Called to clear all recent measurements history and schedule resuming after
150 // a stabilization period elapses. 150 // a stabilization period elapses.
151 void ResetMeasurements(); 151 void ResetMeasurements();
152 152
153 // Called when a fatal runtime error occurs. |stop_trigger| is the error code 153 // Called when a fatal runtime error occurs. |stop_trigger| is the error code
154 // handed to the RemotingRendererController. 154 // handed to the RendererController.
155 void OnFatalError(remoting::StopTrigger stop_trigger); 155 void OnFatalError(StopTrigger stop_trigger);
156 156
157 // Called periodically to measure the data flows from the 157 // Called periodically to measure the data flows from the
158 // DemuxerStreamAdapters and record this information in the metrics. 158 // DemuxerStreamAdapters and record this information in the metrics.
159 void MeasureAndRecordDataRates(); 159 void MeasureAndRecordDataRates();
160 160
161 State state_; 161 State state_;
162 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 162 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
163 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; 163 const scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
164 164
165 // Current renderer playback time information. 165 // Current renderer playback time information.
166 base::TimeDelta current_media_time_; 166 base::TimeDelta current_media_time_;
167 base::TimeDelta current_max_time_; 167 base::TimeDelta current_max_time_;
168 // Both |current_media_time_| and |current_max_time_| should be protected by 168 // Both |current_media_time_| and |current_max_time_| should be protected by
169 // lock because it can be accessed from both media and render main thread. 169 // lock because it can be accessed from both media and render main thread.
170 base::Lock time_lock_; 170 base::Lock time_lock_;
171 171
172 DemuxerStreamProvider* demuxer_stream_provider_; 172 DemuxerStreamProvider* demuxer_stream_provider_;
173 media::RendererClient* client_; 173 RendererClient* client_;
174 std::unique_ptr<remoting::RemoteDemuxerStreamAdapter> 174 std::unique_ptr<DemuxerStreamAdapter> audio_demuxer_stream_adapter_;
175 audio_demuxer_stream_adapter_; 175 std::unique_ptr<DemuxerStreamAdapter> video_demuxer_stream_adapter_;
176 std::unique_ptr<remoting::RemoteDemuxerStreamAdapter>
177 video_demuxer_stream_adapter_;
178 176
179 // Component to establish mojo remoting service on browser process. 177 // Component to establish mojo remoting service on browser process.
180 const base::WeakPtr<RemotingRendererController> remoting_renderer_controller_; 178 const base::WeakPtr<RendererController> controller_;
181 // Broker class to process incoming and outgoing RPC message. 179 // Broker class to process incoming and outgoing RPC message.
182 const base::WeakPtr<remoting::RpcBroker> rpc_broker_; 180 const base::WeakPtr<RpcBroker> rpc_broker_;
183 // RPC handle value for RemoteRendererImpl component. 181 // RPC handle value for CourierRenderer component.
184 const int rpc_handle_; 182 const int rpc_handle_;
185 183
186 // RPC handle value for render on receiver endpoint. 184 // RPC handle value for render on receiver endpoint.
187 int remote_renderer_handle_; 185 int remote_renderer_handle_;
188 186
189 // Callbacks. 187 // Callbacks.
190 PipelineStatusCB init_workflow_done_callback_; 188 PipelineStatusCB init_workflow_done_callback_;
191 CdmAttachedCB cdm_attached_cb_; 189 CdmAttachedCB cdm_attached_cb_;
192 base::Closure flush_cb_; 190 base::Closure flush_cb_;
193 191
(...skipping 24 matching lines...) Expand all
218 std::deque<std::tuple<base::TimeTicks, int, int>> video_stats_queue_; 216 std::deque<std::tuple<base::TimeTicks, int, int>> video_stats_queue_;
219 217
220 // The total number of frames decoded/dropped in the time window. 218 // The total number of frames decoded/dropped in the time window.
221 int sum_video_frames_decoded_ = 0; 219 int sum_video_frames_decoded_ = 0;
222 int sum_video_frames_dropped_ = 0; 220 int sum_video_frames_dropped_ = 0;
223 221
224 // Records the number of consecutive times that remoting playback was delayed. 222 // Records the number of consecutive times that remoting playback was delayed.
225 int times_playback_delayed_ = 0; 223 int times_playback_delayed_ = 0;
226 224
227 // Records events and measurements of interest. 225 // Records events and measurements of interest.
228 remoting::RendererMetricsRecorder metrics_recorder_; 226 RendererMetricsRecorder metrics_recorder_;
229 227
230 // A timer that polls the RemoteDemuxerStreamAdapters periodically to measure 228 // A timer that polls the DemuxerStreamAdapters periodically to measure
231 // the data flow rates for metrics. 229 // the data flow rates for metrics.
232 base::RepeatingTimer data_flow_poll_timer_; 230 base::RepeatingTimer data_flow_poll_timer_;
233 231
234 base::WeakPtrFactory<RemoteRendererImpl> weak_factory_; 232 base::WeakPtrFactory<CourierRenderer> weak_factory_;
235 233
236 DISALLOW_COPY_AND_ASSIGN(RemoteRendererImpl); 234 DISALLOW_COPY_AND_ASSIGN(CourierRenderer);
237 }; 235 };
238 236
237 } // namespace remoting
239 } // namespace media 238 } // namespace media
240 239
241 #endif // MEDIA_REMOTING_REMOTE_RENDERER_IMPL_H_ 240 #endif // MEDIA_REMOTING_COURIER_RENDERER_H_
OLDNEW
« no previous file with comments | « media/remoting/adaptive_renderer_factory.cc ('k') | media/remoting/courier_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698