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: 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 // |buffering_controller| can be NULL if no buffering strategy is needed.
damienv1 2014/11/20 17:08:26 Comment could be removed (the controller is not gi
gunsch 2014/11/20 19:50:27 Done.
49 AvPipelineImpl(
50 MediaComponentDevice* media_component_device,
51 const UpdateConfigCB& update_config_cb);
52 ~AvPipelineImpl();
53
54 // Setting the frame provider or the client must be done in the
55 // |kUninitialized| state.
56 void SetCodedFrameProvider(scoped_ptr<CodedFrameProvider> frame_provider,
57 size_t max_buffer_size,
58 size_t max_frame_size);
59 void SetClient(const AvPipelineClient& client);
60
61 // Initialize the pipeline.
62 bool Initialize();
63
64 // Setup the pipeline and ensure samples are available for the given media
65 // time, then start rendering samples.
66 bool StartPlayingFrom(base::TimeDelta time,
67 const scoped_refptr<BufferingState>& buffering_state);
68
69 // Stop rendering samples.
70 // Return true when successful.
71 bool Pause();
72
73 // Flush any remaining samples in the pipeline.
74 // Invoke |done_cb| when flush is completed.
75 void Flush(const base::Closure& done_cb);
76
77 // Tear down the pipeline and release the hardware resources.
78 void Stop();
79
80 State GetState() const { return state_; }
81 void TransitionToState(State state);
82
83 void SetCdm(BrowserCdmCast* media_keys);
84
85 private:
86 // Callback invoked when the CDM state has changed in a way that might
87 // impact media playback.
88 void OnCdmStateChange();
89
90 // Callback invoked when playback has reached the end of stream.
91 void OnEos();
92
93 // Feed the pipeline, getting the frames from |frame_provider_|.
94 void FetchBufferIfNeeded();
95
96 // Callback invoked when receiving a new frame from |frame_provider_|.
97 void OnNewFrame(const scoped_refptr<DecoderBufferBase>& buffer,
98 const ::media::AudioDecoderConfig& audio_config,
99 const ::media::VideoDecoderConfig& video_config);
100
101 // Process a pending buffer.
102 void ProcessPendingBuffer();
103
104 void OnFramePushed(MediaComponentDevice::FrameStatus status);
105
106 // Callbacks:
107 // - when BrowserCdm updated its state.
108 // - when BrowserCdm has been destroyed.
109 void OnCdmStateChanged();
110 void OnCdmDestroyed();
111
112 // Callback invoked when a frame has been buffered by |frame_provider_|
113 // which is a BufferingFrameProvider.
114 void OnFrameBuffered(const scoped_refptr<DecoderBufferBase>& buffer,
115 bool is_at_max_capacity);
116 void UpdatePlayableFrames();
117
118 base::ThreadChecker thread_checker_;
119
120 UpdateConfigCB update_config_cb_;
121
122 AvPipelineClient client_;
123
124 // Backends.
125 MediaComponentDevice* media_component_device_;
126
127 // AV pipeline state.
128 State state_;
129
130 // Buffering state.
131 // Can be NULL if there is no buffering strategy.
132 scoped_refptr<BufferingState> buffering_state_;
133
134 // |buffered_time_| is the maximum timestamp of buffered frames.
135 // |playable_buffered_time_| is the maximum timestamp of buffered and
136 // playable frames (i.e. the key id is available for those frames).
137 base::TimeDelta buffered_time_;
138 base::TimeDelta playable_buffered_time_;
139
140 // List of frames buffered but not playable right away due to a missing
141 // key id.
142 std::list<scoped_refptr<DecoderBufferBase> > non_playable_frames_;
143
144 // Buffer provider.
145 scoped_ptr<BufferingFrameProvider> frame_provider_;
146
147 // Indicate whether the frame fetching process is active.
148 bool enable_feeding_;
149
150 // Indicate whether there is a pending buffer read.
151 bool pending_read_;
152
153 // Pending buffer.
154 scoped_refptr<DecoderBufferBase> pending_buffer_;
155
156 // Indicate if there is a frame being pushed to the audio device.
157 bool pending_push_;
158
159 // The media time is retrieved at regular intervals.
160 // Indicate whether time update is enabled.
161 bool enable_time_update_;
162 bool pending_time_update_task_;
163
164 // Decryption keys, if available.
165 BrowserCdmCast* media_keys_;
166 int media_keys_callback_id_;
167
168 base::WeakPtrFactory<AvPipelineImpl> weak_factory_;
169 base::WeakPtr<AvPipelineImpl> weak_this_;
170
171 DISALLOW_COPY_AND_ASSIGN(AvPipelineImpl);
172 };
173
174 } // namespace media
175 } // namespace chromecast
176
177 #endif // CHROMECAST_MEDIA_CMA_BASE_AV_PIPELINE_IMPL_H_
OLDNEW

Powered by Google App Engine