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

Side by Side Diff: media/renderers/renderer_impl.h

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

Powered by Google App Engine
This is Rietveld 408576698