| 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_COURIER_RENDERER_H_ | 5 #ifndef MEDIA_REMOTING_COURIER_RENDERER_H_ |
| 6 #define MEDIA_REMOTING_COURIER_RENDERER_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/pipeline_status.h" | 19 #include "media/base/pipeline_status.h" |
| 20 #include "media/base/renderer.h" | 20 #include "media/base/renderer.h" |
| 21 #include "media/mojo/interfaces/remoting.mojom.h" | 21 #include "media/mojo/interfaces/remoting.mojom.h" |
| 22 #include "media/remoting/interstitial.h" | |
| 23 #include "media/remoting/metrics.h" | 22 #include "media/remoting/metrics.h" |
| 24 #include "media/remoting/rpc_broker.h" | 23 #include "media/remoting/rpc_broker.h" |
| 25 #include "mojo/public/cpp/system/data_pipe.h" | 24 #include "mojo/public/cpp/system/data_pipe.h" |
| 26 | 25 |
| 27 namespace media { | 26 namespace media { |
| 28 | 27 |
| 29 class RendererClient; | 28 class RendererClient; |
| 30 class VideoRendererSink; | 29 class VideoRendererSink; |
| 31 | 30 |
| 32 namespace remoting { | 31 namespace remoting { |
| 33 | 32 |
| 34 class DemuxerStreamAdapter; | 33 class DemuxerStreamAdapter; |
| 35 class RendererController; | 34 class RendererController; |
| 36 | 35 |
| 37 // A media::Renderer implementation that proxies all operations to a remote | 36 // A media::Renderer implementation that proxies all operations to a remote |
| 38 // renderer via RPCs. The CourierRenderer is instantiated by | 37 // renderer via RPCs. The CourierRenderer is instantiated by |
| 39 // AdaptiveRendererFactory when media remoting is meant to take place. | 38 // 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 { | 39 class CourierRenderer : public Renderer { |
| 45 public: | 40 public: |
| 46 // The whole class except for constructor and GetMediaTime() runs on | 41 // The whole class except for constructor and GetMediaTime() runs on |
| 47 // |media_task_runner|. The constructor and GetMediaTime() run on render main | 42 // |media_task_runner|. The constructor and GetMediaTime() run on render main |
| 48 // thread. | 43 // thread. |
| 49 CourierRenderer(scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, | 44 CourierRenderer(scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, |
| 50 const base::WeakPtr<RendererController>& controller, | 45 const base::WeakPtr<RendererController>& controller, |
| 51 VideoRendererSink* video_renderer_sink); | 46 VideoRendererSink* video_renderer_sink); |
| 52 ~CourierRenderer() final; | 47 ~CourierRenderer() final; |
| 53 | 48 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 mojo::ScopedDataPipeProducerHandle video_handle); | 60 mojo::ScopedDataPipeProducerHandle video_handle); |
| 66 | 61 |
| 67 // Callback function when RPC message is received. The function is set to | 62 // Callback function when RPC message is received. The function is set to |
| 68 // static in order to post task to media thread in order to avoid threading | 63 // static in order to post task to media thread in order to avoid threading |
| 69 // race condition. | 64 // race condition. |
| 70 static void OnMessageReceivedOnMainThread( | 65 static void OnMessageReceivedOnMainThread( |
| 71 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, | 66 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, |
| 72 base::WeakPtr<CourierRenderer> self, | 67 base::WeakPtr<CourierRenderer> self, |
| 73 std::unique_ptr<pb::RpcMessage> message); | 68 std::unique_ptr<pb::RpcMessage> message); |
| 74 | 69 |
| 75 // Called to render the interstitial on the main thread. Then, trampoline to | |
| 76 // the media thread to have the CourierRenderer pass the resulting VideoFrame | |
| 77 // to the VideoRendererSink. | |
| 78 static void RenderInterstitialAndShow( | |
| 79 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, | |
| 80 base::WeakPtr<CourierRenderer> self, | |
| 81 const SkBitmap& background, | |
| 82 const gfx::Size& natural_size, | |
| 83 InterstitialType type); | |
| 84 | |
| 85 public: | 70 public: |
| 86 // media::Renderer implementation. | 71 // media::Renderer implementation. |
| 87 void Initialize(MediaResource* media_resource, | 72 void Initialize(MediaResource* media_resource, |
| 88 RendererClient* client, | 73 RendererClient* client, |
| 89 const PipelineStatusCB& init_cb) final; | 74 const PipelineStatusCB& init_cb) final; |
| 90 void SetCdm(CdmContext* cdm_context, | 75 void SetCdm(CdmContext* cdm_context, |
| 91 const CdmAttachedCB& cdm_attached_cb) final; | 76 const CdmAttachedCB& cdm_attached_cb) final; |
| 92 void Flush(const base::Closure& flush_cb) final; | 77 void Flush(const base::Closure& flush_cb) final; |
| 93 void StartPlayingFrom(base::TimeDelta time) final; | 78 void StartPlayingFrom(base::TimeDelta time) final; |
| 94 void SetPlaybackRate(double playback_rate) final; | 79 void SetPlaybackRate(double playback_rate) final; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 void InitializeCallback(std::unique_ptr<pb::RpcMessage> message); | 112 void InitializeCallback(std::unique_ptr<pb::RpcMessage> message); |
| 128 void FlushUntilCallback(); | 113 void FlushUntilCallback(); |
| 129 void SetCdmCallback(std::unique_ptr<pb::RpcMessage> message); | 114 void SetCdmCallback(std::unique_ptr<pb::RpcMessage> message); |
| 130 void OnTimeUpdate(std::unique_ptr<pb::RpcMessage> message); | 115 void OnTimeUpdate(std::unique_ptr<pb::RpcMessage> message); |
| 131 void OnBufferingStateChange(std::unique_ptr<pb::RpcMessage> message); | 116 void OnBufferingStateChange(std::unique_ptr<pb::RpcMessage> message); |
| 132 void OnVideoNaturalSizeChange(std::unique_ptr<pb::RpcMessage> message); | 117 void OnVideoNaturalSizeChange(std::unique_ptr<pb::RpcMessage> message); |
| 133 void OnVideoOpacityChange(std::unique_ptr<pb::RpcMessage> message); | 118 void OnVideoOpacityChange(std::unique_ptr<pb::RpcMessage> message); |
| 134 void OnStatisticsUpdate(std::unique_ptr<pb::RpcMessage> message); | 119 void OnStatisticsUpdate(std::unique_ptr<pb::RpcMessage> message); |
| 135 void OnDurationChange(std::unique_ptr<pb::RpcMessage> message); | 120 void OnDurationChange(std::unique_ptr<pb::RpcMessage> message); |
| 136 | 121 |
| 137 // Called to pass the newly-rendered interstitial VideoFrame to the | |
| 138 // VideoRendererSink. | |
| 139 void PaintInterstitial(scoped_refptr<VideoFrame> frame, | |
| 140 InterstitialType type); | |
| 141 | |
| 142 // Called when |current_media_time_| is updated. | 122 // Called when |current_media_time_| is updated. |
| 143 void OnMediaTimeUpdated(); | 123 void OnMediaTimeUpdated(); |
| 144 | 124 |
| 145 // Called to update the |video_stats_queue_|. | 125 // Called to update the |video_stats_queue_|. |
| 146 void UpdateVideoStatsQueue(int video_frames_decoded, | 126 void UpdateVideoStatsQueue(int video_frames_decoded, |
| 147 int video_frames_dropped); | 127 int video_frames_dropped); |
| 148 | 128 |
| 149 // Called to clear all recent measurements history and schedule resuming after | 129 // Called to clear all recent measurements history and schedule resuming after |
| 150 // a stabilization period elapses. | 130 // a stabilization period elapses. |
| 151 void ResetMeasurements(); | 131 void ResetMeasurements(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 199 |
| 220 // Records events and measurements of interest. | 200 // Records events and measurements of interest. |
| 221 RendererMetricsRecorder metrics_recorder_; | 201 RendererMetricsRecorder metrics_recorder_; |
| 222 | 202 |
| 223 std::unique_ptr<base::TickClock> clock_; | 203 std::unique_ptr<base::TickClock> clock_; |
| 224 | 204 |
| 225 // A timer that polls the DemuxerStreamAdapters periodically to measure | 205 // A timer that polls the DemuxerStreamAdapters periodically to measure |
| 226 // the data flow rates for metrics. | 206 // the data flow rates for metrics. |
| 227 base::RepeatingTimer data_flow_poll_timer_; | 207 base::RepeatingTimer data_flow_poll_timer_; |
| 228 | 208 |
| 229 // Current type of the interstitial frame. | |
| 230 InterstitialType interstitial_type_ = InterstitialType::BETWEEN_SESSIONS; | |
| 231 | |
| 232 base::WeakPtrFactory<CourierRenderer> weak_factory_; | 209 base::WeakPtrFactory<CourierRenderer> weak_factory_; |
| 233 | 210 |
| 234 DISALLOW_COPY_AND_ASSIGN(CourierRenderer); | 211 DISALLOW_COPY_AND_ASSIGN(CourierRenderer); |
| 235 }; | 212 }; |
| 236 | 213 |
| 237 } // namespace remoting | 214 } // namespace remoting |
| 238 } // namespace media | 215 } // namespace media |
| 239 | 216 |
| 240 #endif // MEDIA_REMOTING_COURIER_RENDERER_H_ | 217 #endif // MEDIA_REMOTING_COURIER_RENDERER_H_ |
| OLD | NEW |