OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_RENDERERS_RENDERER_IMPL_H_ | 5 #ifndef MEDIA_RENDERERS_RENDERER_IMPL_H_ |
6 #define MEDIA_RENDERERS_RENDERER_IMPL_H_ | 6 #define MEDIA_RENDERERS_RENDERER_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 RendererClient* client, | 54 RendererClient* client, |
55 const PipelineStatusCB& init_cb) final; | 55 const PipelineStatusCB& init_cb) final; |
56 void SetCdm(CdmContext* cdm_context, | 56 void SetCdm(CdmContext* cdm_context, |
57 const CdmAttachedCB& cdm_attached_cb) final; | 57 const CdmAttachedCB& cdm_attached_cb) final; |
58 void Flush(const base::Closure& flush_cb) final; | 58 void Flush(const base::Closure& flush_cb) final; |
59 void StartPlayingFrom(base::TimeDelta time) final; | 59 void StartPlayingFrom(base::TimeDelta time) final; |
60 void SetPlaybackRate(double playback_rate) final; | 60 void SetPlaybackRate(double playback_rate) final; |
61 void SetVolume(float volume) final; | 61 void SetVolume(float volume) final; |
62 base::TimeDelta GetMediaTime() final; | 62 base::TimeDelta GetMediaTime() final; |
63 | 63 |
64 void OnStreamStatusChanged(DemuxerStream* stream, | |
65 bool enabled, | |
66 base::TimeDelta time); | |
67 | |
68 // Helper functions for testing purposes. Must be called before Initialize(). | 64 // Helper functions for testing purposes. Must be called before Initialize(). |
69 void DisableUnderflowForTesting(); | 65 void DisableUnderflowForTesting(); |
70 void EnableClocklessVideoPlaybackForTesting(); | 66 void EnableClocklessVideoPlaybackForTesting(); |
71 void set_time_source_for_testing(TimeSource* time_source) { | 67 void set_time_source_for_testing(TimeSource* time_source) { |
72 time_source_ = time_source; | 68 time_source_ = time_source; |
73 } | 69 } |
74 void set_video_underflow_threshold_for_testing(base::TimeDelta threshold) { | 70 void set_video_underflow_threshold_for_testing(base::TimeDelta threshold) { |
75 video_underflow_threshold_ = threshold; | 71 video_underflow_threshold_ = threshold; |
76 } | 72 } |
77 | 73 |
(...skipping 17 matching lines...) Expand all Loading... |
95 | 91 |
96 void FinishInitialization(PipelineStatus status); | 92 void FinishInitialization(PipelineStatus status); |
97 | 93 |
98 // Helper functions and callbacks for Initialize(). | 94 // Helper functions and callbacks for Initialize(). |
99 void InitializeAudioRenderer(); | 95 void InitializeAudioRenderer(); |
100 void OnAudioRendererInitializeDone(PipelineStatus status); | 96 void OnAudioRendererInitializeDone(PipelineStatus status); |
101 void InitializeVideoRenderer(); | 97 void InitializeVideoRenderer(); |
102 void OnVideoRendererInitializeDone(PipelineStatus status); | 98 void OnVideoRendererInitializeDone(PipelineStatus status); |
103 | 99 |
104 // Helper functions and callbacks for Flush(). | 100 // Helper functions and callbacks for Flush(). |
| 101 void FlushInternal(); |
105 void FlushAudioRenderer(); | 102 void FlushAudioRenderer(); |
106 void OnAudioRendererFlushDone(); | 103 void OnAudioRendererFlushDone(); |
107 void FlushVideoRenderer(); | 104 void FlushVideoRenderer(); |
108 void OnVideoRendererFlushDone(); | 105 void OnVideoRendererFlushDone(); |
109 | 106 |
110 void RestartAudioRenderer(base::TimeDelta time); | 107 // This function notifies the renderer that the status of the demuxer |stream| |
111 void RestartVideoRenderer(base::TimeDelta time); | 108 // has been changed, the new status is |enabled| and the change occured while |
| 109 // playback position was |time|. |
| 110 void OnStreamStatusChanged(DemuxerStream* stream, |
| 111 bool enabled, |
| 112 base::TimeDelta time); |
| 113 |
| 114 // Reinitialize audio/video renderer during a demuxer stream switching. The |
| 115 // renderer must be flushed first, and when the re-init is completed the |
| 116 // corresponding callback will be invoked to restart playback. |
| 117 // The |stream| parameter specifies the new demuxer stream, and the |time| |
| 118 // parameter specifies the time on media timeline where the switch occured. |
| 119 void ReinitializeAudioRenderer(DemuxerStream* stream, base::TimeDelta time); |
| 120 void OnAudioRendererReinitialized(DemuxerStream* stream, |
| 121 base::TimeDelta time, |
| 122 PipelineStatus status); |
| 123 void ReinitializeVideoRenderer(DemuxerStream* stream, base::TimeDelta time); |
| 124 void OnVideoRendererReinitialized(DemuxerStream* stream, |
| 125 base::TimeDelta time, |
| 126 PipelineStatus status); |
| 127 |
| 128 // Restart audio/video renderer playback after a demuxer stream switch or |
| 129 // after a demuxer stream has been disabled and re-enabled. The |stream| |
| 130 // parameter specifies which stream needs to be restarted. The |time| |
| 131 // parameter specifies the position on the media timeline where the playback |
| 132 // needs to be restarted. It is necessary for demuxers with independent |
| 133 // streams (e.g. MSE / ChunkDemuxer) to synchronize data reading between those |
| 134 // streams. |
| 135 void RestartAudioRenderer(DemuxerStream* stream, base::TimeDelta time); |
| 136 void RestartVideoRenderer(DemuxerStream* stream, base::TimeDelta time); |
112 | 137 |
113 // Callback executed by filters to update statistics. | 138 // Callback executed by filters to update statistics. |
114 void OnStatisticsUpdate(const PipelineStatistics& stats); | 139 void OnStatisticsUpdate(const PipelineStatistics& stats); |
115 | 140 |
116 // Collection of callback methods and helpers for tracking changes in | 141 // Collection of callback methods and helpers for tracking changes in |
117 // buffering state and transition from paused/underflow states and playing | 142 // buffering state and transition from paused/underflow states and playing |
118 // states. | 143 // states. |
119 // | 144 // |
120 // While in the kPlaying state: | 145 // While in the kPlaying state: |
121 // - A waiting to non-waiting transition indicates preroll has completed | 146 // - A waiting to non-waiting transition indicates preroll has completed |
122 // and StartPlayback() should be called | 147 // and StartPlayback() should be called |
123 // - A non-waiting to waiting transition indicates underflow has occurred | 148 // - A non-waiting to waiting transition indicates underflow has occurred |
124 // and PausePlayback() should be called | 149 // and PausePlayback() should be called |
125 void OnBufferingStateChange(DemuxerStream::Type type, | 150 void OnBufferingStateChange(DemuxerStream::Type type, |
126 BufferingState new_buffering_state); | 151 BufferingState new_buffering_state); |
| 152 |
127 // Handles the buffering notifications that we might get while an audio or a | 153 // Handles the buffering notifications that we might get while an audio or a |
128 // video stream is being restarted. In those cases we don't want to report | 154 // video stream is being restarted. In those cases we don't want to report |
129 // underflows immediately and instead give decoders a chance to catch up with | 155 // underflows immediately and instead give decoders a chance to catch up with |
130 // currently playing stream. Returns true if the buffering nofication has been | 156 // currently playing stream. Returns true if the buffering nofication has been |
131 // handled and no further processing is necessary, returns false to indicate | 157 // handled and no further processing is necessary, returns false to indicate |
132 // that we should fall back to the regular OnBufferingStateChange logic. | 158 // that we should fall back to the regular OnBufferingStateChange logic. |
133 bool HandleRestartedStreamBufferingChanges( | 159 bool HandleRestartedStreamBufferingChanges( |
134 DemuxerStream::Type type, | 160 DemuxerStream::Type type, |
135 BufferingState new_buffering_state); | 161 BufferingState new_buffering_state); |
| 162 |
136 bool WaitingForEnoughData() const; | 163 bool WaitingForEnoughData() const; |
137 void PausePlayback(); | 164 void PausePlayback(); |
138 void StartPlayback(); | 165 void StartPlayback(); |
139 | 166 |
140 // Callbacks executed when a renderer has ended. | 167 // Callbacks executed when a renderer has ended. |
141 void OnRendererEnded(DemuxerStream::Type type); | 168 void OnRendererEnded(DemuxerStream::Type type); |
142 bool PlaybackHasEnded() const; | 169 bool PlaybackHasEnded() const; |
143 void RunEndedCallbackIfNeeded(); | 170 void RunEndedCallbackIfNeeded(); |
144 | 171 |
145 // Callback executed when a runtime error happens. | 172 // Callback executed when a runtime error happens. |
(...skipping 14 matching lines...) Expand all Loading... |
160 | 187 |
161 // Temporary callback used for Initialize() and Flush(). | 188 // Temporary callback used for Initialize() and Flush(). |
162 PipelineStatusCB init_cb_; | 189 PipelineStatusCB init_cb_; |
163 base::Closure flush_cb_; | 190 base::Closure flush_cb_; |
164 | 191 |
165 std::unique_ptr<RendererClientInternal> audio_renderer_client_; | 192 std::unique_ptr<RendererClientInternal> audio_renderer_client_; |
166 std::unique_ptr<RendererClientInternal> video_renderer_client_; | 193 std::unique_ptr<RendererClientInternal> video_renderer_client_; |
167 std::unique_ptr<AudioRenderer> audio_renderer_; | 194 std::unique_ptr<AudioRenderer> audio_renderer_; |
168 std::unique_ptr<VideoRenderer> video_renderer_; | 195 std::unique_ptr<VideoRenderer> video_renderer_; |
169 | 196 |
| 197 DemuxerStream* current_audio_stream_; |
| 198 DemuxerStream* current_video_stream_; |
| 199 |
170 // Renderer-provided time source used to control playback. | 200 // Renderer-provided time source used to control playback. |
171 TimeSource* time_source_; | 201 TimeSource* time_source_; |
172 std::unique_ptr<WallClockTimeSource> wall_clock_time_source_; | 202 std::unique_ptr<WallClockTimeSource> wall_clock_time_source_; |
173 bool time_ticking_; | 203 bool time_ticking_; |
174 double playback_rate_; | 204 double playback_rate_; |
175 | 205 |
176 // The time to start playback from after starting/seeking has completed. | 206 // The time to start playback from after starting/seeking has completed. |
177 base::TimeDelta start_time_; | 207 base::TimeDelta start_time_; |
178 | 208 |
179 BufferingState audio_buffering_state_; | 209 BufferingState audio_buffering_state_; |
(...skipping 14 matching lines...) Expand all Loading... |
194 | 224 |
195 // Used to defer underflow for audio when restarting audio playback. | 225 // Used to defer underflow for audio when restarting audio playback. |
196 base::CancelableClosure deferred_audio_restart_underflow_cb_; | 226 base::CancelableClosure deferred_audio_restart_underflow_cb_; |
197 | 227 |
198 // The amount of time to wait before declaring underflow if the video renderer | 228 // The amount of time to wait before declaring underflow if the video renderer |
199 // runs out of data but the audio renderer still has enough. | 229 // runs out of data but the audio renderer still has enough. |
200 base::TimeDelta video_underflow_threshold_; | 230 base::TimeDelta video_underflow_threshold_; |
201 | 231 |
202 bool restarting_audio_ = false; | 232 bool restarting_audio_ = false; |
203 bool restarting_video_ = false; | 233 bool restarting_video_ = false; |
204 std::list<base::Closure> pending_stream_status_notifications_; | 234 |
| 235 // Flush operations and media track status changes must be serialized to avoid |
| 236 // interfering with each other. This list will hold a list of postponed |
| 237 // actions that need to be completed after the current async operation is |
| 238 // completed. |
| 239 std::list<base::Closure> pending_actions_; |
205 | 240 |
206 base::WeakPtr<RendererImpl> weak_this_; | 241 base::WeakPtr<RendererImpl> weak_this_; |
207 base::WeakPtrFactory<RendererImpl> weak_factory_; | 242 base::WeakPtrFactory<RendererImpl> weak_factory_; |
208 | 243 |
209 DISALLOW_COPY_AND_ASSIGN(RendererImpl); | 244 DISALLOW_COPY_AND_ASSIGN(RendererImpl); |
210 }; | 245 }; |
211 | 246 |
212 } // namespace media | 247 } // namespace media |
213 | 248 |
214 #endif // MEDIA_RENDERERS_RENDERER_IMPL_H_ | 249 #endif // MEDIA_RENDERERS_RENDERER_IMPL_H_ |
OLD | NEW |