Chromium Code Reviews

Side by Side Diff: chromecast/media/cma/pipeline/av_pipeline_impl.h

Issue 741863002: Chromecast: adds a media pipeline feeding data to CMA device backends. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cma-cdm
Patch Set: address nits, merge Pause/Flush Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
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.
4
5 #ifndef CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_
6 #define CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_
7
8 #include <list>
9
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "chromecast/media/cma/backend/media_component_device.h"
16 #include "chromecast/media/cma/pipeline/av_pipeline_client.h"
17
18 namespace media {
19 class AudioDecoderConfig;
20 class VideoDecoderConfig;
21 }
22
23 namespace chromecast {
24 namespace media {
25 class BrowserCdmCast;
26 class BufferingFrameProvider;
27 class BufferingState;
28 class CodedFrameProvider;
29 class DecoderBufferBase;
30 class MediaComponentDevice;
31
32 class AvPipelineImpl {
33 public:
34 // Pipeline states.
35 enum State {
36 kUninitialized,
37 kPlaying,
38 kFlushing,
39 kFlushed,
40 kStopped,
41 kError,
42 };
43
44 typedef base::Callback<
45 void(const ::media::AudioDecoderConfig&,
46 const ::media::VideoDecoderConfig&)> UpdateConfigCB;
47
48 AvPipelineImpl(
49 MediaComponentDevice* media_component_device,
50 const UpdateConfigCB& update_config_cb);
51 ~AvPipelineImpl();
52
53 // Setting the frame provider or the client must be done in the
54 // |kUninitialized| state.
55 void SetCodedFrameProvider(scoped_ptr<CodedFrameProvider> frame_provider,
56 size_t max_buffer_size,
57 size_t max_frame_size);
58 void SetClient(const AvPipelineClient& client);
59
60 // Initialize the pipeline.
61 bool Initialize();
62
63 // Setup the pipeline and ensure samples are available for the given media
64 // time, then start rendering samples.
65 bool StartPlayingFrom(base::TimeDelta time,
66 const scoped_refptr<BufferingState>& buffering_state);
67
68 // Flush any remaining samples in the pipeline.
69 // Invoke |done_cb| when flush is completed.
70 void Flush(const base::Closure& done_cb);
71
72 // Tear down the pipeline and release the hardware resources.
73 void Stop();
74
75 State GetState() const { return state_; }
76 void TransitionToState(State state);
77
78 void SetCdm(BrowserCdmCast* media_keys);
79
80 private:
81 // Callback invoked when the CDM state has changed in a way that might
82 // impact media playback.
83 void OnCdmStateChange();
84
85 // Callback invoked when playback has reached the end of stream.
86 void OnEos();
87
88 // Feed the pipeline, getting the frames from |frame_provider_|.
89 void FetchBufferIfNeeded();
90
91 // Callback invoked when receiving a new frame from |frame_provider_|.
92 void OnNewFrame(const scoped_refptr<DecoderBufferBase>& buffer,
93 const ::media::AudioDecoderConfig& audio_config,
94 const ::media::VideoDecoderConfig& video_config);
95
96 // Process a pending buffer.
97 void ProcessPendingBuffer();
98
99 void OnFramePushed(MediaComponentDevice::FrameStatus status);
100
101 // Callbacks:
102 // - when BrowserCdm updated its state.
103 // - when BrowserCdm has been destroyed.
104 void OnCdmStateChanged();
105 void OnCdmDestroyed();
106
107 // Callback invoked when a frame has been buffered by |frame_provider_|
108 // which is a BufferingFrameProvider.
109 void OnFrameBuffered(const scoped_refptr<DecoderBufferBase>& buffer,
110 bool is_at_max_capacity);
111 void UpdatePlayableFrames();
112
113 base::ThreadChecker thread_checker_;
114
115 UpdateConfigCB update_config_cb_;
116
117 AvPipelineClient client_;
118
119 // Backends.
120 MediaComponentDevice* media_component_device_;
121
122 // AV pipeline state.
123 State state_;
124
125 // Buffering state.
126 // Can be NULL if there is no buffering strategy.
127 scoped_refptr<BufferingState> buffering_state_;
128
129 // |buffered_time_| is the maximum timestamp of buffered frames.
130 // |playable_buffered_time_| is the maximum timestamp of buffered and
131 // playable frames (i.e. the key id is available for those frames).
132 base::TimeDelta buffered_time_;
133 base::TimeDelta playable_buffered_time_;
134
135 // List of frames buffered but not playable right away due to a missing
136 // key id.
137 std::list<scoped_refptr<DecoderBufferBase> > non_playable_frames_;
138
139 // Buffer provider.
140 scoped_ptr<BufferingFrameProvider> frame_provider_;
141
142 // Indicate whether the frame fetching process is active.
143 bool enable_feeding_;
144
145 // Indicate whether there is a pending buffer read.
146 bool pending_read_;
147
148 // Pending buffer.
149 scoped_refptr<DecoderBufferBase> pending_buffer_;
150
151 // Indicate if there is a frame being pushed to the audio device.
152 bool pending_push_;
153
154 // The media time is retrieved at regular intervals.
155 // Indicate whether time update is enabled.
156 bool enable_time_update_;
157 bool pending_time_update_task_;
158
159 // Decryption keys, if available.
160 BrowserCdmCast* media_keys_;
161 int media_keys_callback_id_;
162
163 base::WeakPtrFactory<AvPipelineImpl> weak_factory_;
164 base::WeakPtr<AvPipelineImpl> weak_this_;
165
166 DISALLOW_COPY_AND_ASSIGN(AvPipelineImpl);
167 };
168
169 } // namespace media
170 } // namespace chromecast
171
172 #endif // CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_
OLDNEW
« no previous file with comments | « chromecast/media/cma/pipeline/av_pipeline_client.cc ('k') | chromecast/media/cma/pipeline/av_pipeline_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine