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
3 // found in the LICENSE file.
5 #ifndef CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_
6 #define CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_
8 #include "base/basictypes.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "chromecast/media/cma/pipeline/load_type.h"
15 #include "chromecast/media/cma/pipeline/media_pipeline.h"
16 #include "chromecast/media/cma/pipeline/media_pipeline_client.h"
17 #include "media/base/serial_runner.h"
19 namespace chromecast
{
21 class AudioPipelineImpl
;
23 class BufferingController
;
24 class MediaClockDevice
;
25 class MediaPipelineDevice
;
26 class VideoPipelineImpl
;
28 class MediaPipelineImpl
: public MediaPipeline
{
31 ~MediaPipelineImpl() override
;
33 // Initialize the media pipeline: the pipeline is configured based on
35 void Initialize(LoadType load_type
,
36 scoped_ptr
<MediaPipelineDevice
> media_pipeline_device
);
38 // MediaPipeline implementation.
39 void SetClient(const MediaPipelineClient
& client
) override
;
40 void SetCdm(int cdm_id
) override
;
41 AudioPipeline
* GetAudioPipeline() const override
;
42 VideoPipeline
* GetVideoPipeline() const override
;
44 const ::media::AudioDecoderConfig
& config
,
45 scoped_ptr
<CodedFrameProvider
> frame_provider
,
46 const ::media::PipelineStatusCB
& status_cb
) override
;
48 const std::vector
<::media::VideoDecoderConfig
>& configs
,
49 scoped_ptr
<CodedFrameProvider
> frame_provider
,
50 const ::media::PipelineStatusCB
& status_cb
) override
;
51 void StartPlayingFrom(base::TimeDelta time
) override
;
52 void Flush(const ::media::PipelineStatusCB
& status_cb
) override
;
54 void SetPlaybackRate(double playback_rate
) override
;
56 AudioPipelineImpl
* GetAudioPipelineImpl() const;
57 VideoPipelineImpl
* GetVideoPipelineImpl() const;
59 void SetCdm(BrowserCdmCast
* cdm
);
62 void StateTransition(const ::media::PipelineStatusCB
& status_cb
,
63 ::media::PipelineStatus status
);
65 // Invoked to notify about a change of buffering state.
66 void OnBufferingNotification(bool is_buffering
);
68 void UpdateMediaTime();
70 void OnError(::media::PipelineStatus error
);
72 base::ThreadChecker thread_checker_
;
74 MediaPipelineClient client_
;
76 scoped_ptr
<BufferingController
> buffering_controller_
;
78 // Interface with the underlying hardware media pipeline.
79 scoped_ptr
<MediaPipelineDevice
> media_pipeline_device_
;
80 MediaClockDevice
* clock_device_
;
84 scoped_ptr
<AudioPipelineImpl
> audio_pipeline_
;
85 scoped_ptr
<VideoPipelineImpl
> video_pipeline_
;
86 scoped_ptr
< ::media::SerialRunner
> pending_flush_callbacks_
;
88 // Playback rate set by the upper layer.
89 float target_playback_rate_
;
91 // Indicate a possible re-buffering phase.
94 // The media time is retrieved at regular intervals.
95 // Indicate whether time update is enabled.
96 bool enable_time_update_
;
97 bool pending_time_update_task_
;
98 base::TimeDelta last_media_time_
;
100 // Used to make the statistics update period a multiplier of the time update
102 int statistics_rolling_counter_
;
104 base::WeakPtr
<MediaPipelineImpl
> weak_this_
;
105 base::WeakPtrFactory
<MediaPipelineImpl
> weak_factory_
;
107 DISALLOW_COPY_AND_ASSIGN(MediaPipelineImpl
);
111 } // namespace chromecast
113 #endif // CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_