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