OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BASE_PIPELINE_H_ | 5 #ifndef MEDIA_BASE_PIPELINE_H_ |
6 #define MEDIA_BASE_PIPELINE_H_ | 6 #define MEDIA_BASE_PIPELINE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 12 matching lines...) Loading... |
23 namespace base { | 23 namespace base { |
24 class MessageLoopProxy; | 24 class MessageLoopProxy; |
25 class TimeDelta; | 25 class TimeDelta; |
26 } | 26 } |
27 | 27 |
28 namespace media { | 28 namespace media { |
29 | 29 |
30 class Clock; | 30 class Clock; |
31 class FilterCollection; | 31 class FilterCollection; |
32 class MediaLog; | 32 class MediaLog; |
| 33 class TextRenderer; |
| 34 class TextTrackConfig; |
33 class VideoRenderer; | 35 class VideoRenderer; |
34 | 36 |
35 // Pipeline runs the media pipeline. Filters are created and called on the | 37 // Pipeline runs the media pipeline. Filters are created and called on the |
36 // message loop injected into this object. Pipeline works like a state | 38 // message loop injected into this object. Pipeline works like a state |
37 // machine to perform asynchronous initialization, pausing, seeking and playing. | 39 // machine to perform asynchronous initialization, pausing, seeking and playing. |
38 // | 40 // |
39 // Here's a state diagram that describes the lifetime of this object. | 41 // Here's a state diagram that describes the lifetime of this object. |
40 // | 42 // |
41 // [ *Created ] [ Any State ] | 43 // [ *Created ] [ Any State ] |
42 // | Start() | Stop() / SetError() | 44 // | Start() | Stop() / SetError() |
(...skipping 182 matching lines...) Loading... |
225 | 227 |
226 // DataSourceHost (by way of DemuxerHost) implementation. | 228 // DataSourceHost (by way of DemuxerHost) implementation. |
227 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; | 229 virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; |
228 virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE; | 230 virtual void AddBufferedByteRange(int64 start, int64 end) OVERRIDE; |
229 virtual void AddBufferedTimeRange(base::TimeDelta start, | 231 virtual void AddBufferedTimeRange(base::TimeDelta start, |
230 base::TimeDelta end) OVERRIDE; | 232 base::TimeDelta end) OVERRIDE; |
231 | 233 |
232 // DemuxerHost implementaion. | 234 // DemuxerHost implementaion. |
233 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; | 235 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; |
234 virtual void OnDemuxerError(PipelineStatus error) OVERRIDE; | 236 virtual void OnDemuxerError(PipelineStatus error) OVERRIDE; |
| 237 virtual void AddTextStream(DemuxerStream* text_stream, |
| 238 const TextTrackConfig& config) OVERRIDE; |
| 239 virtual void RemoveTextStream(DemuxerStream* text_stream) OVERRIDE; |
235 | 240 |
236 // Initiates teardown sequence in response to a runtime error. | 241 // Initiates teardown sequence in response to a runtime error. |
237 // | 242 // |
238 // Safe to call from any thread. | 243 // Safe to call from any thread. |
239 void SetError(PipelineStatus error); | 244 void SetError(PipelineStatus error); |
240 | 245 |
241 // Callback executed when the natural size of the video has changed. | 246 // Callback executed when the natural size of the video has changed. |
242 void OnNaturalVideoSizeChanged(const gfx::Size& size); | 247 void OnNaturalVideoSizeChanged(const gfx::Size& size); |
243 | 248 |
244 // Callbacks executed when a renderer has ended. | 249 // Callbacks executed when a renderer has ended. |
245 void OnAudioRendererEnded(); | 250 void OnAudioRendererEnded(); |
246 void OnVideoRendererEnded(); | 251 void OnVideoRendererEnded(); |
| 252 void OnTextRendererEnded(); |
247 | 253 |
248 // Callback executed by filters to update statistics. | 254 // Callback executed by filters to update statistics. |
249 void OnUpdateStatistics(const PipelineStatistics& stats); | 255 void OnUpdateStatistics(const PipelineStatistics& stats); |
250 | 256 |
251 // Callback executed by audio renderer when it has been disabled. | 257 // Callback executed by audio renderer when it has been disabled. |
252 void OnAudioDisabled(); | 258 void OnAudioDisabled(); |
253 | 259 |
254 // Callback executed by audio renderer to update clock time. | 260 // Callback executed by audio renderer to update clock time. |
255 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); | 261 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); |
256 | 262 |
(...skipping 19 matching lines...) Loading... |
276 | 282 |
277 // Carries out notifying filters that the playback rate has changed. | 283 // Carries out notifying filters that the playback rate has changed. |
278 void PlaybackRateChangedTask(float playback_rate); | 284 void PlaybackRateChangedTask(float playback_rate); |
279 | 285 |
280 // Carries out notifying filters that the volume has changed. | 286 // Carries out notifying filters that the volume has changed. |
281 void VolumeChangedTask(float volume); | 287 void VolumeChangedTask(float volume); |
282 | 288 |
283 // Carries out notifying filters that we are seeking to a new timestamp. | 289 // Carries out notifying filters that we are seeking to a new timestamp. |
284 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 290 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
285 | 291 |
286 // Handles audio/video ended logic and running |ended_cb_|. | 292 // Handles audio/video/text ended logic and running |ended_cb_|. |
287 void DoAudioRendererEnded(); | 293 void DoAudioRendererEnded(); |
288 void DoVideoRendererEnded(); | 294 void DoVideoRendererEnded(); |
| 295 void DoTextRendererEnded(); |
289 void RunEndedCallbackIfNeeded(); | 296 void RunEndedCallbackIfNeeded(); |
290 | 297 |
291 // Carries out disabling the audio renderer. | 298 // Carries out disabling the audio renderer. |
292 void AudioDisabledTask(); | 299 void AudioDisabledTask(); |
293 | 300 |
| 301 // Carries out adding a new text stream to the text renderer. |
| 302 void AddTextStreamTask(DemuxerStream* text_stream, |
| 303 const TextTrackConfig& config); |
| 304 |
| 305 // Carries out removing a text stream from the text renderer. |
| 306 void RemoveTextStreamTask(DemuxerStream* text_stream); |
| 307 |
294 // Kicks off initialization for each media object, executing |done_cb| with | 308 // Kicks off initialization for each media object, executing |done_cb| with |
295 // the result when completed. | 309 // the result when completed. |
296 void InitializeDemuxer(const PipelineStatusCB& done_cb); | 310 void InitializeDemuxer(const PipelineStatusCB& done_cb); |
297 void InitializeAudioRenderer(const PipelineStatusCB& done_cb); | 311 void InitializeAudioRenderer(const PipelineStatusCB& done_cb); |
298 void InitializeVideoRenderer(const PipelineStatusCB& done_cb); | 312 void InitializeVideoRenderer(const PipelineStatusCB& done_cb); |
299 | 313 |
300 // Kicks off destroying filters. Called by StopTask() and ErrorChangedTask(). | 314 // Kicks off destroying filters. Called by StopTask() and ErrorChangedTask(). |
301 // When we start to tear down the pipeline, we will consider two cases: | 315 // When we start to tear down the pipeline, we will consider two cases: |
302 // 1. when pipeline has not been initialized, we will transit to stopping | 316 // 1. when pipeline has not been initialized, we will transit to stopping |
303 // state first. | 317 // state first. |
(...skipping 81 matching lines...) Loading... |
385 // for an update of the clock greater than or equal to the elapsed time to | 399 // for an update of the clock greater than or equal to the elapsed time to |
386 // start the clock. | 400 // start the clock. |
387 bool waiting_for_clock_update_; | 401 bool waiting_for_clock_update_; |
388 | 402 |
389 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that | 403 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that |
390 // the pipeline is operating correctly. Any other value indicates that the | 404 // the pipeline is operating correctly. Any other value indicates that the |
391 // pipeline is stopped or is stopping. Clients can call the Stop() method to | 405 // pipeline is stopped or is stopping. Clients can call the Stop() method to |
392 // reset the pipeline state, and restore this to PIPELINE_OK. | 406 // reset the pipeline state, and restore this to PIPELINE_OK. |
393 PipelineStatus status_; | 407 PipelineStatus status_; |
394 | 408 |
395 // Whether the media contains rendered audio and video streams. | 409 // Whether the media contains rendered audio or video streams. |
396 // TODO(fischman,scherkus): replace these with checks for | 410 // TODO(fischman,scherkus): replace these with checks for |
397 // {audio,video}_decoder_ once extraction of {Audio,Video}Decoder from the | 411 // {audio,video}_decoder_ once extraction of {Audio,Video}Decoder from the |
398 // Filter heirarchy is done. | 412 // Filter heirarchy is done. |
399 bool has_audio_; | 413 bool has_audio_; |
400 bool has_video_; | 414 bool has_video_; |
401 | 415 |
402 // The following data members are only accessed by tasks posted to | 416 // The following data members are only accessed by tasks posted to |
403 // |message_loop_|. | 417 // |message_loop_|. |
404 | 418 |
405 // Member that tracks the current state. | 419 // Member that tracks the current state. |
406 State state_; | 420 State state_; |
407 | 421 |
408 // Whether we've received the audio/video ended events. | 422 // Whether we've received the audio/video/text ended events. |
409 bool audio_ended_; | 423 bool audio_ended_; |
410 bool video_ended_; | 424 bool video_ended_; |
| 425 bool text_ended_; |
411 | 426 |
412 // Set to true in DisableAudioRendererTask(). | 427 // Set to true in DisableAudioRendererTask(). |
413 bool audio_disabled_; | 428 bool audio_disabled_; |
414 | 429 |
415 // Temporary callback used for Start() and Seek(). | 430 // Temporary callback used for Start() and Seek(). |
416 PipelineStatusCB seek_cb_; | 431 PipelineStatusCB seek_cb_; |
417 | 432 |
418 // Temporary callback used for Stop(). | 433 // Temporary callback used for Stop(). |
419 base::Closure stop_cb_; | 434 base::Closure stop_cb_; |
420 | 435 |
421 // Permanent callbacks passed in via Start(). | 436 // Permanent callbacks passed in via Start(). |
422 base::Closure ended_cb_; | 437 base::Closure ended_cb_; |
423 PipelineStatusCB error_cb_; | 438 PipelineStatusCB error_cb_; |
424 BufferingStateCB buffering_state_cb_; | 439 BufferingStateCB buffering_state_cb_; |
425 base::Closure duration_change_cb_; | 440 base::Closure duration_change_cb_; |
426 | 441 |
427 // Contains the demuxer and renderers to use when initializing. | 442 // Contains the demuxer and renderers to use when initializing. |
428 scoped_ptr<FilterCollection> filter_collection_; | 443 scoped_ptr<FilterCollection> filter_collection_; |
429 | 444 |
430 // Holds the initialized demuxer. Used for seeking. Owned by client. | 445 // Holds the initialized demuxer. Used for seeking. Owned by client. |
431 Demuxer* demuxer_; | 446 Demuxer* demuxer_; |
432 | 447 |
433 // Holds the initialized renderers. Used for setting the volume, | 448 // Holds the initialized renderers. Used for setting the volume, |
434 // playback rate, and determining when playback has finished. | 449 // playback rate, and determining when playback has finished. |
435 scoped_ptr<AudioRenderer> audio_renderer_; | 450 scoped_ptr<AudioRenderer> audio_renderer_; |
436 scoped_ptr<VideoRenderer> video_renderer_; | 451 scoped_ptr<VideoRenderer> video_renderer_; |
| 452 scoped_ptr<TextRenderer> text_renderer_; |
437 | 453 |
438 PipelineStatistics statistics_; | 454 PipelineStatistics statistics_; |
439 | 455 |
440 // Time of pipeline creation; is non-zero only until the pipeline first | 456 // Time of pipeline creation; is non-zero only until the pipeline first |
441 // reaches "kStarted", at which point it is used & zeroed out. | 457 // reaches "kStarted", at which point it is used & zeroed out. |
442 base::TimeTicks creation_time_; | 458 base::TimeTicks creation_time_; |
443 | 459 |
444 scoped_ptr<SerialRunner> pending_callbacks_; | 460 scoped_ptr<SerialRunner> pending_callbacks_; |
445 | 461 |
446 base::ThreadChecker thread_checker_; | 462 base::ThreadChecker thread_checker_; |
447 | 463 |
448 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 464 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
449 }; | 465 }; |
450 | 466 |
451 } // namespace media | 467 } // namespace media |
452 | 468 |
453 #endif // MEDIA_BASE_PIPELINE_H_ | 469 #endif // MEDIA_BASE_PIPELINE_H_ |
OLD | NEW |