[MediaRouter] Update MR-2-Extension's PostMessage to return boolean.
[chromium-blink-merge.git] / chromecast / media / cma / pipeline / media_pipeline_impl.h
blob71a5384ee66e95e0007042137733f9e5e910c601
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 {
20 namespace media {
21 class AudioPipelineImpl;
22 class BrowserCdmCast;
23 class BufferingController;
24 class MediaClockDevice;
25 class MediaPipelineDevice;
26 class VideoPipelineImpl;
28 class MediaPipelineImpl : public MediaPipeline {
29 public:
30 MediaPipelineImpl();
31 ~MediaPipelineImpl() override;
33 // Initialize the media pipeline: the pipeline is configured based on
34 // |load_type|.
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;
43 void InitializeAudio(
44 const ::media::AudioDecoderConfig& config,
45 scoped_ptr<CodedFrameProvider> frame_provider,
46 const ::media::PipelineStatusCB& status_cb) override;
47 void InitializeVideo(
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;
53 void Stop() override;
54 void SetPlaybackRate(double playback_rate) override;
56 AudioPipelineImpl* GetAudioPipelineImpl() const;
57 VideoPipelineImpl* GetVideoPipelineImpl() const;
59 void SetCdm(BrowserCdmCast* cdm);
61 private:
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_;
82 bool has_audio_;
83 bool has_video_;
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.
92 bool is_buffering_;
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
101 // period.
102 int statistics_rolling_counter_;
104 base::WeakPtr<MediaPipelineImpl> weak_this_;
105 base::WeakPtrFactory<MediaPipelineImpl> weak_factory_;
107 DISALLOW_COPY_AND_ASSIGN(MediaPipelineImpl);
110 } // namespace media
111 } // namespace chromecast
113 #endif // CHROMECAST_MEDIA_CMA_PIPELINE_MEDIA_PIPELINE_IMPL_H_