OLD | NEW |
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 28 matching lines...) Expand all Loading... |
39 DECODE_TRY_AGAIN_LATER = 1, | 39 DECODE_TRY_AGAIN_LATER = 1, |
40 DECODE_FAILED = 2, | 40 DECODE_FAILED = 2, |
41 }; | 41 }; |
42 | 42 |
43 virtual ~MediaDecoderJob(); | 43 virtual ~MediaDecoderJob(); |
44 | 44 |
45 // Callback when a decoder job finishes its work. Args: whether decode | 45 // Callback when a decoder job finishes its work. Args: whether decode |
46 // finished successfully, presentation time, timestamp when the data is | 46 // finished successfully, presentation time, timestamp when the data is |
47 // rendered, whether decoder is reaching EOS. | 47 // rendered, whether decoder is reaching EOS. |
48 typedef base::Callback<void(DecodeStatus, const base::TimeDelta&, | 48 typedef base::Callback<void(DecodeStatus, const base::TimeDelta&, |
49 const base::Time&, bool)> DecoderCallback; | 49 const base::TimeTicks&, bool)> DecoderCallback; |
50 | 50 |
51 // Called by MediaSourcePlayer to decode some data. | 51 // Called by MediaSourcePlayer to decode some data. |
52 void Decode( | 52 void Decode( |
53 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params::AccessUnit& unit, | 53 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params::AccessUnit& unit, |
54 const base::Time& start_wallclock_time, | 54 const base::TimeTicks& start_wallclock_time, |
55 const base::TimeDelta& start_presentation_timestamp, | 55 const base::TimeDelta& start_presentation_timestamp, |
56 const MediaDecoderJob::DecoderCallback& callback); | 56 const MediaDecoderJob::DecoderCallback& callback); |
57 | 57 |
58 // Flush the decoder. | 58 // Flush the decoder. |
59 void Flush(); | 59 void Flush(); |
60 | 60 |
61 struct Deleter { | 61 struct Deleter { |
62 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); } | 62 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); } |
63 }; | 63 }; |
64 | 64 |
(...skipping 13 matching lines...) Expand all Loading... |
78 bool end_of_stream, const MediaDecoderJob::DecoderCallback& callback); | 78 bool end_of_stream, const MediaDecoderJob::DecoderCallback& callback); |
79 | 79 |
80 // Helper function to decoder data on |thread_|. |unit| contains all the data | 80 // Helper function to decoder data on |thread_|. |unit| contains all the data |
81 // to be decoded. |start_wallclock_time| and |start_presentation_timestamp| | 81 // to be decoded. |start_wallclock_time| and |start_presentation_timestamp| |
82 // represent the system time and the presentation timestamp when the first | 82 // represent the system time and the presentation timestamp when the first |
83 // frame is rendered. We use these information to estimate when the current | 83 // frame is rendered. We use these information to estimate when the current |
84 // frame should be rendered. If |needs_flush| is true, codec needs to be | 84 // frame should be rendered. If |needs_flush| is true, codec needs to be |
85 // flushed at the beginning of this call. | 85 // flushed at the beginning of this call. |
86 void DecodeInternal( | 86 void DecodeInternal( |
87 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params::AccessUnit& unit, | 87 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params::AccessUnit& unit, |
88 const base::Time& start_wallclock_time, | 88 const base::TimeTicks& start_wallclock_time, |
89 const base::TimeDelta& start_presentation_timestamp, | 89 const base::TimeDelta& start_presentation_timestamp, |
90 bool needs_flush, | 90 bool needs_flush, |
91 const MediaDecoderJob::DecoderCallback& callback); | 91 const MediaDecoderJob::DecoderCallback& callback); |
92 | 92 |
93 // The media codec bridge used for decoding. | 93 // The media codec bridge used for decoding. |
94 scoped_ptr<MediaCodecBridge> media_codec_bridge_; | 94 scoped_ptr<MediaCodecBridge> media_codec_bridge_; |
95 | 95 |
96 // The message loop where callbacks should be dispatched. | 96 // The message loop where callbacks should be dispatched. |
97 scoped_refptr<base::MessageLoopProxy> message_loop_; | 97 scoped_refptr<base::MessageLoopProxy> message_loop_; |
98 | 98 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 virtual void ReadFromDemuxerAck( | 154 virtual void ReadFromDemuxerAck( |
155 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params& params) OVERRIDE; | 155 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params& params) OVERRIDE; |
156 | 156 |
157 // Called when the demuxer has changed the duration. | 157 // Called when the demuxer has changed the duration. |
158 virtual void DurationChanged(const base::TimeDelta& duration) OVERRIDE; | 158 virtual void DurationChanged(const base::TimeDelta& duration) OVERRIDE; |
159 | 159 |
160 private: | 160 private: |
161 // Update the timestamps for A/V sync scheduling. | 161 // Update the timestamps for A/V sync scheduling. |
162 void UpdateTimestamps( | 162 void UpdateTimestamps( |
163 const base::TimeDelta& presentation_timestamp, | 163 const base::TimeDelta& presentation_timestamp, |
164 const base::Time& wallclock_time); | 164 const base::TimeTicks& wallclock_time); |
165 | 165 |
166 // Helper function for starting media playback. | 166 // Helper function for starting media playback. |
167 void StartInternal(); | 167 void StartInternal(); |
168 | 168 |
169 // Playback is completed for one channel. | 169 // Playback is completed for one channel. |
170 void PlaybackCompleted(bool is_audio); | 170 void PlaybackCompleted(bool is_audio); |
171 | 171 |
172 // Called when the decoder finishes its task. | 172 // Called when the decoder finishes its task. |
173 void MediaDecoderCallback( | 173 void MediaDecoderCallback( |
174 bool is_audio, MediaDecoderJob::DecodeStatus decode_status, | 174 bool is_audio, MediaDecoderJob::DecodeStatus decode_status, |
175 const base::TimeDelta& presentation_timestamp, | 175 const base::TimeDelta& presentation_timestamp, |
176 const base::Time& wallclock_time, bool end_of_stream); | 176 const base::TimeTicks& wallclock_time, bool end_of_stream); |
177 | 177 |
178 // Handle pending events when all the decoder jobs finished. | 178 // Handle pending events when all the decoder jobs finished. |
179 void ProcessPendingEvents(); | 179 void ProcessPendingEvents(); |
180 | 180 |
181 // Helper method to create the decoder jobs. | 181 // Helper method to create the decoder jobs. |
182 void CreateVideoDecoderJob(); | 182 void CreateVideoDecoderJob(); |
183 void CreateAudioDecoderJob(); | 183 void CreateAudioDecoderJob(); |
184 | 184 |
185 // Flush the decoders and clean up all the data needs to be decoded. | 185 // Flush the decoders and clean up all the data needs to be decoded. |
186 void ClearDecodingData(); | 186 void ClearDecodingData(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 bool audio_finished_; | 224 bool audio_finished_; |
225 bool video_finished_; | 225 bool video_finished_; |
226 bool playing_; | 226 bool playing_; |
227 | 227 |
228 // Timestamps for providing simple A/V sync. When start decoding an audio | 228 // Timestamps for providing simple A/V sync. When start decoding an audio |
229 // chunk, we record its presentation timestamp and the current system time. | 229 // chunk, we record its presentation timestamp and the current system time. |
230 // Then we use this information to estimate when the next audio/video frame | 230 // Then we use this information to estimate when the next audio/video frame |
231 // should be rendered. | 231 // should be rendered. |
232 // TODO(qinmin): Need to fix the problem if audio/video lagged too far behind | 232 // TODO(qinmin): Need to fix the problem if audio/video lagged too far behind |
233 // due to network or decoding problem. | 233 // due to network or decoding problem. |
234 base::Time start_wallclock_time_; | 234 base::TimeTicks start_wallclock_time_; |
235 base::TimeDelta start_presentation_timestamp_; | 235 base::TimeDelta start_presentation_timestamp_; |
236 | 236 |
237 // The surface object currently owned by the player. | 237 // The surface object currently owned by the player. |
238 gfx::ScopedJavaSurface surface_; | 238 gfx::ScopedJavaSurface surface_; |
239 | 239 |
240 // Decoder jobs | 240 // Decoder jobs |
241 ScopedMediaDecoderJob audio_decoder_job_; | 241 ScopedMediaDecoderJob audio_decoder_job_; |
242 ScopedMediaDecoderJob video_decoder_job_; | 242 ScopedMediaDecoderJob video_decoder_job_; |
243 | 243 |
244 bool reconfig_audio_decoder_; | 244 bool reconfig_audio_decoder_; |
(...skipping 11 matching lines...) Expand all Loading... |
256 | 256 |
257 // Weak pointer passed to media decoder jobs for callbacks. | 257 // Weak pointer passed to media decoder jobs for callbacks. |
258 base::WeakPtrFactory<MediaSourcePlayer> weak_this_; | 258 base::WeakPtrFactory<MediaSourcePlayer> weak_this_; |
259 | 259 |
260 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); | 260 DISALLOW_COPY_AND_ASSIGN(MediaSourcePlayer); |
261 }; | 261 }; |
262 | 262 |
263 } // namespace media | 263 } // namespace media |
264 | 264 |
265 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ | 265 #endif // MEDIA_BASE_ANDROID_MEDIA_SOURCE_PLAYER_H_ |
OLD | NEW |