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" |
11 #include "base/synchronization/condition_variable.h" | 11 #include "base/synchronization/condition_variable.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "media/base/audio_renderer.h" |
13 #include "media/base/demuxer.h" | 14 #include "media/base/demuxer.h" |
14 #include "media/base/filter_host.h" | 15 #include "media/base/filter_host.h" |
15 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
16 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
17 #include "media/base/ranges.h" | 18 #include "media/base/ranges.h" |
18 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
19 | 20 |
20 class MessageLoop; | 21 class MessageLoop; |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class MessageLoopProxy; | 24 class MessageLoopProxy; |
24 class TimeDelta; | 25 class TimeDelta; |
25 } | 26 } |
26 | 27 |
27 namespace media { | 28 namespace media { |
28 | 29 |
29 class AudioDecoder; | 30 class AudioDecoder; |
30 class AudioRenderer; | |
31 class Clock; | 31 class Clock; |
32 class Filter; | 32 class Filter; |
33 class FilterCollection; | 33 class FilterCollection; |
34 class MediaLog; | 34 class MediaLog; |
35 class VideoDecoder; | 35 class VideoDecoder; |
36 class VideoRenderer; | 36 class VideoRenderer; |
37 | 37 |
38 // Adapter for using asynchronous Pipeline methods in code that wants to run | 38 // Adapter for using asynchronous Pipeline methods in code that wants to run |
39 // synchronously. To use, construct an instance of this class and pass the | 39 // synchronously. To use, construct an instance of this class and pass the |
40 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for | 40 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // method was called. | 218 // method was called. |
219 bool DidLoadingProgress() const; | 219 bool DidLoadingProgress() const; |
220 | 220 |
221 // Gets the current pipeline statistics. | 221 // Gets the current pipeline statistics. |
222 PipelineStatistics GetStatistics() const; | 222 PipelineStatistics GetStatistics() const; |
223 | 223 |
224 void SetClockForTesting(Clock* clock); | 224 void SetClockForTesting(Clock* clock); |
225 | 225 |
226 private: | 226 private: |
227 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); | 227 FRIEND_TEST_ALL_PREFIXES(PipelineTest, GetBufferedTimeRanges); |
| 228 FRIEND_TEST_ALL_PREFIXES(PipelineTest, DisableAudioRenderer); |
228 friend class MediaLog; | 229 friend class MediaLog; |
229 | 230 |
230 // Only allow ourselves to be deleted by reference counting. | 231 // Only allow ourselves to be deleted by reference counting. |
231 friend class base::RefCountedThreadSafe<Pipeline>; | 232 friend class base::RefCountedThreadSafe<Pipeline>; |
232 virtual ~Pipeline(); | 233 virtual ~Pipeline(); |
233 | 234 |
234 // Pipeline states, as described above. | 235 // Pipeline states, as described above. |
235 enum State { | 236 enum State { |
236 kCreated, | 237 kCreated, |
237 kInitDemuxer, | 238 kInitDemuxer, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // DemuxerHost implementaion. | 295 // DemuxerHost implementaion. |
295 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; | 296 virtual void SetDuration(base::TimeDelta duration) OVERRIDE; |
296 virtual void OnDemuxerError(PipelineStatus error) OVERRIDE; | 297 virtual void OnDemuxerError(PipelineStatus error) OVERRIDE; |
297 | 298 |
298 // FilterHost implementation. | 299 // FilterHost implementation. |
299 virtual void SetError(PipelineStatus error) OVERRIDE; | 300 virtual void SetError(PipelineStatus error) OVERRIDE; |
300 virtual base::TimeDelta GetTime() const OVERRIDE; | 301 virtual base::TimeDelta GetTime() const OVERRIDE; |
301 virtual base::TimeDelta GetDuration() const OVERRIDE; | 302 virtual base::TimeDelta GetDuration() const OVERRIDE; |
302 virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; | 303 virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; |
303 virtual void NotifyEnded() OVERRIDE; | 304 virtual void NotifyEnded() OVERRIDE; |
304 virtual void DisableAudioRenderer() OVERRIDE; | |
305 | 305 |
306 // Callbacks executed by filters upon completing initialization. | 306 // Callbacks executed by filters upon completing initialization. |
307 void OnFilterInitialize(PipelineStatus status); | 307 void OnFilterInitialize(PipelineStatus status); |
308 | 308 |
309 // Callback executed by filters upon completing Play(), Pause(), or Stop(). | 309 // Callback executed by filters upon completing Play(), Pause(), or Stop(). |
310 void OnFilterStateTransition(); | 310 void OnFilterStateTransition(); |
311 | 311 |
312 // Callback executed by filters upon completing Seek(). | 312 // Callback executed by filters upon completing Seek(). |
313 void OnFilterStateTransitionWithStatus(PipelineStatus status); | 313 void OnFilterStateTransitionWithStatus(PipelineStatus status); |
314 | 314 |
315 // Callback executed by filters when completing teardown operations. | 315 // Callback executed by filters when completing teardown operations. |
316 void OnTeardownStateTransition(); | 316 void OnTeardownStateTransition(); |
317 | 317 |
318 // Callback executed by filters to update statistics. | 318 // Callback executed by filters to update statistics. |
319 void OnUpdateStatistics(const PipelineStatistics& stats); | 319 void OnUpdateStatistics(const PipelineStatistics& stats); |
320 | 320 |
| 321 // Callback executed by audio renderer when it has been disabled. |
| 322 void OnAudioDisabled(); |
| 323 |
321 // Callback executed by audio renderer to update clock time. | 324 // Callback executed by audio renderer to update clock time. |
322 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); | 325 void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time); |
323 | 326 |
324 // Callback executed by video renderer to update clock time. | 327 // Callback executed by video renderer to update clock time. |
325 void OnVideoTimeUpdate(base::TimeDelta max_time); | 328 void OnVideoTimeUpdate(base::TimeDelta max_time); |
326 | 329 |
327 // The following "task" methods correspond to the public methods, but these | 330 // The following "task" methods correspond to the public methods, but these |
328 // methods are run as the result of posting a task to the PipelineInternal's | 331 // methods are run as the result of posting a task to the PipelineInternal's |
329 // message loop. | 332 // message loop. |
330 void StartTask(scoped_ptr<FilterCollection> filter_collection, | 333 void StartTask(scoped_ptr<FilterCollection> filter_collection, |
(...skipping 21 matching lines...) Expand all Loading... |
352 // Carries out notifying filters that the volume has changed. | 355 // Carries out notifying filters that the volume has changed. |
353 void VolumeChangedTask(float volume); | 356 void VolumeChangedTask(float volume); |
354 | 357 |
355 // Carries out notifying filters that we are seeking to a new timestamp. | 358 // Carries out notifying filters that we are seeking to a new timestamp. |
356 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); | 359 void SeekTask(base::TimeDelta time, const PipelineStatusCB& seek_cb); |
357 | 360 |
358 // Carries out handling a notification from a filter that it has ended. | 361 // Carries out handling a notification from a filter that it has ended. |
359 void NotifyEndedTask(); | 362 void NotifyEndedTask(); |
360 | 363 |
361 // Carries out disabling the audio renderer. | 364 // Carries out disabling the audio renderer. |
362 void DisableAudioRendererTask(); | 365 void AudioDisabledTask(); |
363 | 366 |
364 // Carries out advancing to the next filter during Play()/Pause()/Seek(). | 367 // Carries out advancing to the next filter during Play()/Pause()/Seek(). |
365 void FilterStateTransitionTask(); | 368 void FilterStateTransitionTask(); |
366 | 369 |
367 // Carries out advancing to the next teardown operation. | 370 // Carries out advancing to the next teardown operation. |
368 void TeardownStateTransitionTask(); | 371 void TeardownStateTransitionTask(); |
369 | 372 |
370 // Carries out stopping filter threads, deleting filters, running | 373 // Carries out stopping filter threads, deleting filters, running |
371 // appropriate callbacks, and setting the appropriate pipeline state | 374 // appropriate callbacks, and setting the appropriate pipeline state |
372 // depending on whether we performing Stop() or SetError(). | 375 // depending on whether we performing Stop() or SetError(). |
(...skipping 30 matching lines...) Expand all Loading... |
403 // This will remove the race condition during stop between filters. | 406 // This will remove the race condition during stop between filters. |
404 void TearDownPipeline(); | 407 void TearDownPipeline(); |
405 | 408 |
406 // Compute the current time. Assumes that the lock has been acquired by the | 409 // Compute the current time. Assumes that the lock has been acquired by the |
407 // caller. | 410 // caller. |
408 base::TimeDelta GetCurrentTime_Locked() const; | 411 base::TimeDelta GetCurrentTime_Locked() const; |
409 | 412 |
410 // Compute the time corresponding to a byte offset. | 413 // Compute the time corresponding to a byte offset. |
411 base::TimeDelta TimeForByteOffset_Locked(int64 byte_offset) const; | 414 base::TimeDelta TimeForByteOffset_Locked(int64 byte_offset) const; |
412 | 415 |
413 // Initiates a Stop() on |demuxer_| & |pipeline_filter_|. |callback| | 416 // Initiates an asynchronous Pause/Flush/Play/Stop() call sequence executing |
414 // is called once both objects have been stopped. | 417 // |done_cb| when completed. |
415 void DoStop(const base::Closure& callback); | 418 void DoPause(const base::Closure& done_cb); |
| 419 void DoFlush(const base::Closure& done_cb); |
| 420 void DoPlay(const base::Closure& done_cb); |
| 421 void DoStop(const base::Closure& done_cb); |
416 | 422 |
417 // Called when |demuxer_| has stopped. This method calls Stop() | 423 // Initiates an asynchronous Seek() call sequence executing |done_cb| when |
418 // on |pipeline_filter_|. | 424 // completed. Seek() is separated from the other operations as we will |
419 void OnDemuxerStopDone(const base::Closure& callback); | 425 // prematurely terminate the call sequence if an error occurs. |
420 | 426 void DoSeek(const PipelineStatusCB& done_cb, base::TimeDelta seek_timestamp); |
421 // Initiates a Seek() on the |demuxer_| & |pipeline_filter_|. | 427 void OnDemuxerSeekDone(const PipelineStatusCB& done_cb, |
422 void DoSeek(base::TimeDelta seek_timestamp); | 428 base::TimeDelta seek_timestamp, |
423 | |
424 // Called when |demuxer_| finishes seeking. If seeking was successful, | |
425 // then Seek() is called on |pipeline_filter_|. | |
426 void OnDemuxerSeekDone(base::TimeDelta seek_timestamp, | |
427 PipelineStatus status); | 429 PipelineStatus status); |
| 430 void OnAudioRendererSeekDone(const PipelineStatusCB& done_cb, |
| 431 base::TimeDelta seek_timestamp, |
| 432 PipelineStatus status); |
| 433 void OnPipelineFilterSeekDone(const PipelineStatusCB& done_cb, |
| 434 PipelineStatus status); |
428 | 435 |
429 void OnAudioUnderflow(); | 436 void OnAudioUnderflow(); |
430 | 437 |
431 void StartClockIfWaitingForTimeUpdate_Locked(); | 438 void StartClockIfWaitingForTimeUpdate_Locked(); |
432 | 439 |
433 // Report pipeline |status| through |cb| avoiding duplicate error reporting. | 440 // Report pipeline |status| through |cb| avoiding duplicate error reporting. |
434 void ReportStatus(const PipelineStatusCB& cb, PipelineStatus status); | 441 void ReportStatus(const PipelineStatusCB& cb, PipelineStatus status); |
435 | 442 |
436 // Message loop used to execute pipeline tasks. | 443 // Message loop used to execute pipeline tasks. |
437 scoped_refptr<base::MessageLoopProxy> message_loop_; | 444 scoped_refptr<base::MessageLoopProxy> message_loop_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 // Filter collection as passed in by Start(). | 533 // Filter collection as passed in by Start(). |
527 scoped_ptr<FilterCollection> filter_collection_; | 534 scoped_ptr<FilterCollection> filter_collection_; |
528 | 535 |
529 // Callbacks for various pipeline operations. | 536 // Callbacks for various pipeline operations. |
530 PipelineStatusCB seek_cb_; | 537 PipelineStatusCB seek_cb_; |
531 base::Closure stop_cb_; | 538 base::Closure stop_cb_; |
532 PipelineStatusCB ended_cb_; | 539 PipelineStatusCB ended_cb_; |
533 PipelineStatusCB error_cb_; | 540 PipelineStatusCB error_cb_; |
534 | 541 |
535 // Reference to the filter(s) that constitute the pipeline. | 542 // Reference to the filter(s) that constitute the pipeline. |
| 543 // |
| 544 // TODO(scherkus): At this point in time this is a CompositeFilter that |
| 545 // contains |video_renderer_|. Remove when CompositeFilter is gone, see |
| 546 // http://crbug.com/126069 |
536 scoped_refptr<Filter> pipeline_filter_; | 547 scoped_refptr<Filter> pipeline_filter_; |
537 | 548 |
538 // Decoder reference used for signalling imminent shutdown. | 549 // Decoder reference used for signalling imminent shutdown. |
539 // This is a HACK necessary because WebMediaPlayerImpl::Destroy() holds the | 550 // This is a HACK necessary because WebMediaPlayerImpl::Destroy() holds the |
540 // renderer thread loop hostage for until PipelineImpl::Stop() calls its | 551 // renderer thread loop hostage for until PipelineImpl::Stop() calls its |
541 // callback. | 552 // callback. |
542 // This reference should only be used for this hack and no other purposes. | 553 // This reference should only be used for this hack and no other purposes. |
543 // http://crbug.com/110228 tracks removing this hack. | 554 // http://crbug.com/110228 tracks removing this hack. |
544 scoped_refptr<VideoDecoder> video_decoder_; | 555 scoped_refptr<VideoDecoder> video_decoder_; |
545 | 556 |
(...skipping 15 matching lines...) Expand all Loading... |
561 // Time of pipeline creation; is non-zero only until the pipeline first | 572 // Time of pipeline creation; is non-zero only until the pipeline first |
562 // reaches "kStarted", at which point it is used & zeroed out. | 573 // reaches "kStarted", at which point it is used & zeroed out. |
563 base::Time creation_time_; | 574 base::Time creation_time_; |
564 | 575 |
565 DISALLOW_COPY_AND_ASSIGN(Pipeline); | 576 DISALLOW_COPY_AND_ASSIGN(Pipeline); |
566 }; | 577 }; |
567 | 578 |
568 } // namespace media | 579 } // namespace media |
569 | 580 |
570 #endif // MEDIA_BASE_PIPELINE_H_ | 581 #endif // MEDIA_BASE_PIPELINE_H_ |
OLD | NEW |