Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: media/base/android/media_source_player.h

Issue 16098014: Handle config changes for MSE on android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_ANDROID_MEDIA_SOURCE_PLAYER_H_ 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // Flush the decoder. 52 // Flush the decoder.
53 void Flush(); 53 void Flush();
54 54
55 struct Deleter { 55 struct Deleter {
56 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); } 56 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); }
57 }; 57 };
58 58
59 // Causes this instance to be deleted on the thread it is bound to. 59 // Causes this instance to be deleted on the thread it is bound to.
60 void Release(); 60 void Release();
61 61
62 // Called on the UI thread to indicate that one decode cycle has completed.
63 void OnDecodeCompleted();
64
62 protected: 65 protected:
63 MediaDecoderJob(base::Thread* thread, bool is_audio); 66 MediaDecoderJob(base::Thread* thread, bool is_audio);
64 67
65 // Release the output buffer and render it. 68 // Release the output buffer and render it.
66 void ReleaseOutputBuffer( 69 void ReleaseOutputBuffer(
67 int outputBufferIndex, size_t size, 70 int outputBufferIndex, size_t size,
68 const base::TimeDelta& presentation_timestamp, 71 const base::TimeDelta& presentation_timestamp,
69 bool end_of_stream, const MediaDecoderJob::DecoderCallback& callback); 72 bool end_of_stream, const MediaDecoderJob::DecoderCallback& callback);
70 73
71 // Helper function to decoder data on |thread_|. |unit| contains all the data 74 // Helper function to decoder data on |thread_|. |unit| contains all the data
(...skipping 17 matching lines...) Expand all
89 92
90 // Thread the decode task runs on. 93 // Thread the decode task runs on.
91 base::Thread* thread_; 94 base::Thread* thread_;
92 95
93 // Whether the decoder needs to be flushed. 96 // Whether the decoder needs to be flushed.
94 bool needs_flush_; 97 bool needs_flush_;
95 98
96 // Whether this is an audio decoder. 99 // Whether this is an audio decoder.
97 bool is_audio_; 100 bool is_audio_;
98 101
99 // Weak pointer passed to media decoder jobs for callbacks. 102 // Weak pointer passed to media decoder jobs for callbacks. It is bounded to
103 // the decoder thread.
100 base::WeakPtrFactory<MediaDecoderJob> weak_this_; 104 base::WeakPtrFactory<MediaDecoderJob> weak_this_;
105
106 // Whether the decoder is actively decoding data.
107 bool decoding_;
101 }; 108 };
102 109
103 typedef scoped_ptr<MediaDecoderJob, MediaDecoderJob::Deleter> 110 typedef scoped_ptr<MediaDecoderJob, MediaDecoderJob::Deleter>
104 ScopedMediaDecoderJob; 111 ScopedMediaDecoderJob;
105 112
106 // This class handles media source extensions on Android. It uses Android 113 // This class handles media source extensions on Android. It uses Android
107 // MediaCodec to decode audio and video streams in two separate threads. 114 // MediaCodec to decode audio and video streams in two separate threads.
108 // IPC is being used to send data from the render process to this object. 115 // IPC is being used to send data from the render process to this object.
109 // TODO(qinmin): use shared memory to send data between processes. 116 // TODO(qinmin): use shared memory to send data between processes.
110 class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid { 117 class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid {
(...skipping 13 matching lines...) Expand all
124 virtual void SetVolume(float leftVolume, float rightVolume) OVERRIDE; 131 virtual void SetVolume(float leftVolume, float rightVolume) OVERRIDE;
125 virtual int GetVideoWidth() OVERRIDE; 132 virtual int GetVideoWidth() OVERRIDE;
126 virtual int GetVideoHeight() OVERRIDE; 133 virtual int GetVideoHeight() OVERRIDE;
127 virtual base::TimeDelta GetCurrentTime() OVERRIDE; 134 virtual base::TimeDelta GetCurrentTime() OVERRIDE;
128 virtual base::TimeDelta GetDuration() OVERRIDE; 135 virtual base::TimeDelta GetDuration() OVERRIDE;
129 virtual bool IsPlaying() OVERRIDE; 136 virtual bool IsPlaying() OVERRIDE;
130 virtual bool CanPause() OVERRIDE; 137 virtual bool CanPause() OVERRIDE;
131 virtual bool CanSeekForward() OVERRIDE; 138 virtual bool CanSeekForward() OVERRIDE;
132 virtual bool CanSeekBackward() OVERRIDE; 139 virtual bool CanSeekBackward() OVERRIDE;
133 virtual bool IsPlayerReady() OVERRIDE; 140 virtual bool IsPlayerReady() OVERRIDE;
134 virtual void OnSeekRequestAck() OVERRIDE; 141 virtual void OnSeekRequestAck(unsigned request_id) OVERRIDE;
acolwell GONE FROM CHROMIUM 2013/06/04 15:19:14 nit:ditto
qinmin 2013/06/04 19:03:23 Done.
135 142
136 // Called when the demuxer is ready. 143 // Called when the demuxer is ready.
137 virtual void DemuxerReady( 144 virtual void DemuxerReady(
138 const MediaPlayerHostMsg_DemuxerReady_Params& params) OVERRIDE; 145 const MediaPlayerHostMsg_DemuxerReady_Params& params) OVERRIDE;
139 146
140 // Called when the requested data is received from the demuxer. 147 // Called when the requested data is received from the demuxer.
141 virtual void ReadFromDemuxerAck( 148 virtual void ReadFromDemuxerAck(
142 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params& params) OVERRIDE; 149 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params& params) OVERRIDE;
143 150
144 private: 151 private:
(...skipping 10 matching lines...) Expand all
155 162
156 // Called when the decoder finishes its task. 163 // Called when the decoder finishes its task.
157 void MediaDecoderCallback( 164 void MediaDecoderCallback(
158 bool is_audio, bool decode_succeeded, 165 bool is_audio, bool decode_succeeded,
159 const base::TimeDelta& presentation_timestamp, 166 const base::TimeDelta& presentation_timestamp,
160 const base::Time& wallclock_time, bool end_of_stream); 167 const base::Time& wallclock_time, bool end_of_stream);
161 168
162 // Handle pending events when all the decoder jobs finished. 169 // Handle pending events when all the decoder jobs finished.
163 void ProcessPendingEvents(); 170 void ProcessPendingEvents();
164 171
172 // Helper method to create the decoder jobs.
173 void CreateMediaDecoderJobs(bool config_change);
174
165 // Flush the decoders and clean up all the data needs to be decoded. 175 // Flush the decoders and clean up all the data needs to be decoded.
166 void ClearDecodingData(); 176 void ClearDecodingData();
167 177
168 // Called to decoder more data. 178 // Called to decoder more data.
169 void DecodeMoreAudio(); 179 void DecodeMoreAudio();
170 void DecodeMoreVideo(); 180 void DecodeMoreVideo();
171 181
172 // Functions check whether audio/video is present. 182 // Functions check whether audio/video is present.
173 bool HasVideo(); 183 bool HasVideo();
174 bool HasAudio(); 184 bool HasAudio();
175 185
176 enum PendingEventFlags { 186 enum PendingEventFlags {
177 NO_EVENT_PENDING = 0, 187 NO_EVENT_PENDING = 0,
178 SEEK_EVENT_PENDING = 1 << 0, 188 SEEK_EVENT_PENDING = 1 << 0,
179 SURFACE_CHANGE_EVENT_PENDING = 1 << 1, 189 SURFACE_CHANGE_EVENT_PENDING = 1 << 1,
190 CONFIG_CHANGE_EVENT_PENDING = 1 << 2,
180 }; 191 };
181 // Pending event that the player needs to do. 192 // Pending event that the player needs to do.
182 unsigned pending_event_; 193 unsigned pending_event_;
183 194
184 // Number of active decoding tasks. 195 // Number of active decoding tasks.
185 int active_decoding_tasks_; 196 int active_decoding_tasks_;
186 197
198 // ID to keep track of whether all the seek requests are acked.
199 unsigned seek_request_id_;
200
187 // Stats about the media. 201 // Stats about the media.
188 base::TimeDelta duration_; 202 base::TimeDelta duration_;
189 int width_; 203 int width_;
190 int height_; 204 int height_;
191 AudioCodec audio_codec_; 205 AudioCodec audio_codec_;
192 VideoCodec video_codec_; 206 VideoCodec video_codec_;
193 int num_channels_; 207 int num_channels_;
194 int sampling_rate_; 208 int sampling_rate_;
195 bool seekable_; 209 bool seekable_;
196 base::TimeDelta last_presentation_timestamp_; 210 base::TimeDelta last_presentation_timestamp_;
197 std::vector<uint8> audio_extra_data_; 211 std::vector<uint8> audio_extra_data_;
198 bool audio_finished_; 212 bool audio_finished_;
199 bool video_finished_; 213 bool video_finished_;
200 bool playing_; 214 bool playing_;
201 215
202 // Timestamps for providing simple A/V sync. When start decoding an audio 216 // Timestamps for providing simple A/V sync. When start decoding an audio
203 // chunk, we record its presentation timestamp and the current system time. 217 // chunk, we record its presentation timestamp and the current system time.
204 // Then we use this information to estimate when the next audio/video frame 218 // Then we use this information to estimate when the next audio/video frame
205 // should be rendered. 219 // should be rendered.
206 // TODO(qinmin): Need to fix the problem if audio/video lagged too far behind 220 // TODO(qinmin): Need to fix the problem if audio/video lagged too far behind
207 // due to network or decoding problem. 221 // due to network or decoding problem.
208 base::Time start_wallclock_time_; 222 base::Time start_wallclock_time_;
209 base::TimeDelta start_presentation_timestamp_; 223 base::TimeDelta start_presentation_timestamp_;
210 224
211 // Decoder jobs. 225 // The surface object currently owned by the player.
226 gfx::ScopedJavaSurface surface_;
227
228 // Decoder jobs
212 ScopedMediaDecoderJob audio_decoder_job_; 229 ScopedMediaDecoderJob audio_decoder_job_;
213 ScopedMediaDecoderJob video_decoder_job_; 230 ScopedMediaDecoderJob video_decoder_job_;
214 231
215 // These variables keep track of the current decoding data. 232 // These variables keep track of the current decoding data.
216 // TODO(qinmin): remove these variables when we no longer relies on IPC for 233 // TODO(qinmin): remove these variables when we no longer relies on IPC for
217 // data passing. 234 // data passing.
218 size_t audio_access_unit_index_; 235 size_t audio_access_unit_index_;
219 size_t video_access_unit_index_; 236 size_t video_access_unit_index_;
220 bool waiting_for_audio_data_; 237 bool waiting_for_audio_data_;
221 bool waiting_for_video_data_; 238 bool waiting_for_video_data_;
222 MediaPlayerHostMsg_ReadFromDemuxerAck_Params received_audio_; 239 MediaPlayerHostMsg_ReadFromDemuxerAck_Params received_audio_;
223 MediaPlayerHostMsg_ReadFromDemuxerAck_Params received_video_; 240 MediaPlayerHostMsg_ReadFromDemuxerAck_Params received_video_;
224 241
225 // Whether the video decoder need to use anempty surface.
226 bool use_empty_surface_;
227
228 // Weak pointer passed to media decoder jobs for callbacks. 242 // Weak pointer passed to media decoder jobs for callbacks.
229 base::WeakPtrFactory<MediaSourcePlayer> weak_this_; 243 base::WeakPtrFactory<MediaSourcePlayer> weak_this_;
230 244
231 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); 245 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer);
232 }; 246 };
233 247
234 } // namespace media 248 } // namespace media
235 249
236 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ 250 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698