Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_DECODER_JOB_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ |
| 6 #define MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "media/base/android/demuxer_stream_player_params.h" | 11 #include "media/base/android/demuxer_stream_player_params.h" |
| 12 #include "media/base/android/media_codec_bridge.h" | 12 #include "media/base/android/media_codec_bridge.h" |
| 13 #include "ui/gl/android/scoped_java_surface.h" | 13 #include "ui/gl/android/scoped_java_surface.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 | 20 |
| 21 class MediaDrmBridge; | 21 class MediaDrmBridge; |
| 22 | 22 |
| 23 // Class for managing all the decoding tasks. Each decoding task will be posted | 23 // Class for managing all the decoding tasks. Each decoding task will be posted |
| 24 // onto the same thread. The thread will be stopped once Stop() is called. | 24 // onto the same thread. The thread will be stopped once Stop() is called. |
| 25 // Data is stored in 2 chunks. When new data arrives, it is always stored in | 25 // Data is stored in 2 chunks. When new data arrives, it is always stored in |
| 26 // an inactive chunk. And when the current active chunk becomes empty, a new | 26 // an inactive chunk. And when the current active chunk becomes empty, a new |
| 27 // data request will be sent to the renderer. | 27 // data request will be sent to the renderer. |
| 28 class MediaDecoderJob { | 28 class MediaDecoderJob { |
| 29 public: | 29 public: |
| 30 // Return value when Decode() is called. | |
| 31 enum MediaDecoderJobStatus { | |
| 32 STATUS_SUCCESS, | |
| 33 STATUS_KEY_FRAME_REQUIRED, | |
| 34 STATUS_FAILURE, | |
| 35 }; | |
| 36 | |
| 30 struct Deleter { | 37 struct Deleter { |
| 31 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); } | 38 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); } |
| 32 }; | 39 }; |
| 33 | 40 |
| 34 // Callback when a decoder job finishes its work. Args: whether decode | 41 // Callback when a decoder job finishes its work. Args: whether decode |
| 35 // finished successfully, current presentation time, max presentation time. | 42 // finished successfully, current presentation time, max presentation time. |
| 36 // If the current presentation time is equal to kNoTimestamp(), the decoder | 43 // If the current presentation time is equal to kNoTimestamp(), the decoder |
| 37 // job skipped rendering of the decoded output and the callback target should | 44 // job skipped rendering of the decoded output and the callback target should |
| 38 // ignore the timestamps provided. | 45 // ignore the timestamps provided. |
| 39 typedef base::Callback<void(MediaCodecStatus, base::TimeDelta, | 46 typedef base::Callback<void(MediaCodecStatus, base::TimeDelta, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 50 // Called by MediaSourcePlayer when more data for this object has arrived. | 57 // Called by MediaSourcePlayer when more data for this object has arrived. |
| 51 void OnDataReceived(const DemuxerData& data); | 58 void OnDataReceived(const DemuxerData& data); |
| 52 | 59 |
| 53 // Prefetch so we know the decoder job has data when we call Decode(). | 60 // Prefetch so we know the decoder job has data when we call Decode(). |
| 54 // |prefetch_cb| - Run when prefetching has completed. | 61 // |prefetch_cb| - Run when prefetching has completed. |
| 55 void Prefetch(const base::Closure& prefetch_cb); | 62 void Prefetch(const base::Closure& prefetch_cb); |
| 56 | 63 |
| 57 // Called by MediaSourcePlayer to decode some data. | 64 // Called by MediaSourcePlayer to decode some data. |
| 58 // |callback| - Run when decode operation has completed. | 65 // |callback| - Run when decode operation has completed. |
| 59 // | 66 // |
| 60 // Returns true if the next decode was started and |callback| will be | 67 // Returns STATUS_SUCCESS on success, or STATUS_FAILURE on failure, or |
| 61 // called when the decode operation is complete. | 68 // STATUS_KEY_FRAME_REQUIRED if a browser seek is required. |
|
wolenetz
2015/02/04 21:07:23
nit: retain comment around |callback| usage
qinmin
2015/02/04 23:11:23
Done.
| |
| 62 // Returns false if |media_codec_bridge_| cannot be created; |callback| is | 69 MediaDecoderJobStatus Decode(base::TimeTicks start_time_ticks, |
| 63 // ignored and will not be called. | 70 base::TimeDelta start_presentation_timestamp, |
| 64 bool Decode(base::TimeTicks start_time_ticks, | 71 const DecoderCallback& callback); |
| 65 base::TimeDelta start_presentation_timestamp, | |
| 66 const DecoderCallback& callback); | |
| 67 | 72 |
| 68 // Called to stop the last Decode() early. | 73 // Called to stop the last Decode() early. |
| 69 // If the decoder is in the process of decoding the next frame, then | 74 // If the decoder is in the process of decoding the next frame, then |
| 70 // this method will just allow the decode to complete as normal. If | 75 // this method will just allow the decode to complete as normal. If |
| 71 // this object is waiting for a data request to complete, then this method | 76 // this object is waiting for a data request to complete, then this method |
| 72 // will wait for the data to arrive and then call the |callback| | 77 // will wait for the data to arrive and then call the |callback| |
| 73 // passed to Decode() with a status of MEDIA_CODEC_ABORT. This ensures that | 78 // passed to Decode() with a status of MEDIA_CODEC_ABORT. This ensures that |
| 74 // the |callback| passed to Decode() is always called and the status | 79 // the |callback| passed to Decode() is always called and the status |
| 75 // reflects whether data was actually decoded or the decode terminated early. | 80 // reflects whether data was actually decoded or the decode terminated early. |
| 76 void StopDecode(); | 81 void StopDecode(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 // Returns true if the "time to render" needs to be computed for frames in | 130 // Returns true if the "time to render" needs to be computed for frames in |
| 126 // this decoder job. | 131 // this decoder job. |
| 127 virtual bool ComputeTimeToRender() const = 0; | 132 virtual bool ComputeTimeToRender() const = 0; |
| 128 | 133 |
| 129 // Gets MediaCrypto object from |drm_bridge_|. | 134 // Gets MediaCrypto object from |drm_bridge_|. |
| 130 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); | 135 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); |
| 131 | 136 |
| 132 // Releases the |media_codec_bridge_|. | 137 // Releases the |media_codec_bridge_|. |
| 133 void ReleaseMediaCodecBridge(); | 138 void ReleaseMediaCodecBridge(); |
| 134 | 139 |
| 140 // Sets the current frame to a previously cached key frame. Returns true if | |
| 141 // a key frame is found, or false otherwise. | |
| 142 // TODO(qinmin): add UMA to study the cache hit ratio for key frames. | |
| 143 bool SetCurrentFrameToPreviouslyCachedKeyFrame(); | |
| 144 | |
| 135 MediaDrmBridge* drm_bridge() { return drm_bridge_; } | 145 MediaDrmBridge* drm_bridge() { return drm_bridge_; } |
| 136 | 146 |
| 137 void set_is_content_encrypted(bool is_content_encrypted) { | 147 void set_is_content_encrypted(bool is_content_encrypted) { |
| 138 is_content_encrypted_ = is_content_encrypted; | 148 is_content_encrypted_ = is_content_encrypted; |
| 139 } | 149 } |
| 140 | 150 |
| 151 virtual bool is_video() { return false; } | |
| 141 bool need_to_reconfig_decoder_job_; | 152 bool need_to_reconfig_decoder_job_; |
| 142 | 153 |
| 143 scoped_ptr<MediaCodecBridge> media_codec_bridge_; | 154 scoped_ptr<MediaCodecBridge> media_codec_bridge_; |
| 144 | 155 |
| 145 private: | 156 private: |
| 146 friend class MediaSourcePlayerTest; | 157 friend class MediaSourcePlayerTest; |
| 147 | 158 |
| 148 // Causes this instance to be deleted on the thread it is bound to. | 159 // Causes this instance to be deleted on the thread it is bound to. |
| 149 void Release(); | 160 void Release(); |
| 150 | 161 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 | 213 |
| 203 // Requests new data for the current chunk if it runs out of data. | 214 // Requests new data for the current chunk if it runs out of data. |
| 204 void RequestCurrentChunkIfEmpty(); | 215 void RequestCurrentChunkIfEmpty(); |
| 205 | 216 |
| 206 // Initializes |received_data_| and |access_unit_index_|. | 217 // Initializes |received_data_| and |access_unit_index_|. |
| 207 void InitializeReceivedData(); | 218 void InitializeReceivedData(); |
| 208 | 219 |
| 209 // Called when the decoder is completely drained and is ready to be released. | 220 // Called when the decoder is completely drained and is ready to be released. |
| 210 void OnDecoderDrained(); | 221 void OnDecoderDrained(); |
| 211 | 222 |
| 212 // Creates |media_codec_bridge_| for decoding purpose. Returns true if it is | 223 // Creates |media_codec_bridge_| for decoding purpose. |
| 213 // created, or false otherwise. | 224 // Returns STATUS_SUCCESS on success, or STATUS_FAILURE on failure, or |
| 214 bool CreateMediaCodecBridge(); | 225 // STATUS_KEY_FRAME_REQUIRED if a browser seek is required. |
| 215 | 226 MediaDecoderJobStatus CreateMediaCodecBridge(); |
| 216 // Called when an access unit is consumed by the decoder. |is_config_change| | |
| 217 // indicates whether the current access unit is a config change. If it is | |
| 218 // true, the next access unit is guarateed to be an I-frame. | |
| 219 virtual void CurrentDataConsumed(bool is_config_change) {} | |
| 220 | 227 |
| 221 // Implemented by the child class to create |media_codec_bridge_| for a | 228 // Implemented by the child class to create |media_codec_bridge_| for a |
| 222 // particular stream. Returns true if it is created, or false otherwise. | 229 // particular stream. |
| 223 virtual bool CreateMediaCodecBridgeInternal() = 0; | 230 // Returns STATUS_SUCCESS on success, or STATUS_FAILURE on failure, or |
| 231 // STATUS_KEY_FRAME_REQUIRED if a browser seek is required. | |
| 232 virtual MediaDecoderJobStatus CreateMediaCodecBridgeInternal() = 0; | |
| 224 | 233 |
| 225 // Returns true if the |configs| doesn't match the current demuxer configs | 234 // Returns true if the |configs| doesn't match the current demuxer configs |
| 226 // the decoder job has. | 235 // the decoder job has. |
| 227 virtual bool AreDemuxerConfigsChanged( | 236 virtual bool AreDemuxerConfigsChanged( |
| 228 const DemuxerConfigs& configs) const = 0; | 237 const DemuxerConfigs& configs) const = 0; |
| 229 | 238 |
| 230 // Returns true if |media_codec_bridge_| needs to be reconfigured for the | 239 // Returns true if |media_codec_bridge_| needs to be reconfigured for the |
| 231 // new DemuxerConfigs, or false otherwise. | 240 // new DemuxerConfigs, or false otherwise. |
| 232 virtual bool IsCodecReconfigureNeeded(const DemuxerConfigs& configs) const; | 241 virtual bool IsCodecReconfigureNeeded(const DemuxerConfigs& configs) const; |
| 233 | 242 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 // This access unit is passed to the decoder during config changes to drain | 352 // This access unit is passed to the decoder during config changes to drain |
| 344 // the decoder. | 353 // the decoder. |
| 345 AccessUnit eos_unit_; | 354 AccessUnit eos_unit_; |
| 346 | 355 |
| 347 DISALLOW_IMPLICIT_CONSTRUCTORS(MediaDecoderJob); | 356 DISALLOW_IMPLICIT_CONSTRUCTORS(MediaDecoderJob); |
| 348 }; | 357 }; |
| 349 | 358 |
| 350 } // namespace media | 359 } // namespace media |
| 351 | 360 |
| 352 #endif // MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ | 361 #endif // MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ |
| OLD | NEW |