| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // Data is stored in 2 chunks. When new data arrives, it is always stored in | 22 // Data is stored in 2 chunks. When new data arrives, it is always stored in |
| 23 // an inactive chunk. And when the current active chunk becomes empty, a new | 23 // an inactive chunk. And when the current active chunk becomes empty, a new |
| 24 // data request will be sent to the renderer. | 24 // data request will be sent to the renderer. |
| 25 class MediaDecoderJob { | 25 class MediaDecoderJob { |
| 26 public: | 26 public: |
| 27 struct Deleter { | 27 struct Deleter { |
| 28 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); } | 28 inline void operator()(MediaDecoderJob* ptr) const { ptr->Release(); } |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 // Callback when a decoder job finishes its work. Args: whether decode | 31 // Callback when a decoder job finishes its work. Args: whether decode |
| 32 // finished successfully, presentation time, audio output bytes. | 32 // finished successfully, current presentation time, max presentation time. |
| 33 // If the presentation time is equal to kNoTimestamp(), the decoder job | 33 // If the current presentation time is equal to kNoTimestamp(), the decoder |
| 34 // skipped rendering of the decoded output and the callback target should | 34 // job skipped rendering of the decoded output and the callback target should |
| 35 // update its clock to avoid introducing extra delays to the next frame. | 35 // update its clock to avoid introducing extra delays to the next frame. |
| 36 typedef base::Callback<void(MediaCodecStatus, base::TimeDelta, | 36 typedef base::Callback<void(MediaCodecStatus, base::TimeDelta, |
| 37 size_t)> DecoderCallback; | 37 base::TimeDelta)> DecoderCallback; |
| 38 // Callback when a decoder job finishes releasing the output buffer. | 38 // Callback when a decoder job finishes releasing the output buffer. |
| 39 // Args: audio output bytes, must be 0 for video. | 39 // Args: current presentation time, max presentation time. |
| 40 typedef base::Callback<void(size_t)> ReleaseOutputCompletionCallback; | 40 typedef base::Callback<void(base::TimeDelta, base::TimeDelta)> |
| 41 ReleaseOutputCompletionCallback; |
| 41 | 42 |
| 42 virtual ~MediaDecoderJob(); | 43 virtual ~MediaDecoderJob(); |
| 43 | 44 |
| 44 // Called by MediaSourcePlayer when more data for this object has arrived. | 45 // Called by MediaSourcePlayer when more data for this object has arrived. |
| 45 void OnDataReceived(const DemuxerData& data); | 46 void OnDataReceived(const DemuxerData& data); |
| 46 | 47 |
| 47 // Prefetch so we know the decoder job has data when we call Decode(). | 48 // Prefetch so we know the decoder job has data when we call Decode(). |
| 48 // |prefetch_cb| - Run when prefetching has completed. | 49 // |prefetch_cb| - Run when prefetching has completed. |
| 49 void Prefetch(const base::Closure& prefetch_cb); | 50 void Prefetch(const base::Closure& prefetch_cb); |
| 50 | 51 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner, | 89 const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner, |
| 89 MediaCodecBridge* media_codec_bridge, | 90 MediaCodecBridge* media_codec_bridge, |
| 90 const base::Closure& request_data_cb); | 91 const base::Closure& request_data_cb); |
| 91 | 92 |
| 92 // Release the output buffer at index |output_buffer_index| and render it if | 93 // Release the output buffer at index |output_buffer_index| and render it if |
| 93 // |render_output| is true. Upon completion, |callback| will be called. | 94 // |render_output| is true. Upon completion, |callback| will be called. |
| 94 virtual void ReleaseOutputBuffer( | 95 virtual void ReleaseOutputBuffer( |
| 95 int output_buffer_index, | 96 int output_buffer_index, |
| 96 size_t size, | 97 size_t size, |
| 97 bool render_output, | 98 bool render_output, |
| 99 base::TimeDelta current_presentation_timestamp, |
| 98 const ReleaseOutputCompletionCallback& callback) = 0; | 100 const ReleaseOutputCompletionCallback& callback) = 0; |
| 99 | 101 |
| 100 // Returns true if the "time to render" needs to be computed for frames in | 102 // Returns true if the "time to render" needs to be computed for frames in |
| 101 // this decoder job. | 103 // this decoder job. |
| 102 virtual bool ComputeTimeToRender() const = 0; | 104 virtual bool ComputeTimeToRender() const = 0; |
| 103 | 105 |
| 104 private: | 106 private: |
| 105 friend class MediaSourcePlayerTest; | 107 friend class MediaSourcePlayerTest; |
| 106 | 108 |
| 107 // Causes this instance to be deleted on the thread it is bound to. | 109 // Causes this instance to be deleted on the thread it is bound to. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 130 void DecodeInternal(const AccessUnit& unit, | 132 void DecodeInternal(const AccessUnit& unit, |
| 131 base::TimeTicks start_time_ticks, | 133 base::TimeTicks start_time_ticks, |
| 132 base::TimeDelta start_presentation_timestamp, | 134 base::TimeDelta start_presentation_timestamp, |
| 133 bool needs_flush, | 135 bool needs_flush, |
| 134 const DecoderCallback& callback); | 136 const DecoderCallback& callback); |
| 135 | 137 |
| 136 // Called on the UI thread to indicate that one decode cycle has completed. | 138 // Called on the UI thread to indicate that one decode cycle has completed. |
| 137 // Completes any pending job destruction or any pending decode stop. If | 139 // Completes any pending job destruction or any pending decode stop. If |
| 138 // destruction was not pending, passes its arguments to |decode_cb_|. | 140 // destruction was not pending, passes its arguments to |decode_cb_|. |
| 139 void OnDecodeCompleted(MediaCodecStatus status, | 141 void OnDecodeCompleted(MediaCodecStatus status, |
| 140 base::TimeDelta presentation_timestamp, | 142 base::TimeDelta current_presentation_timestamp, |
| 141 size_t audio_output_bytes); | 143 base::TimeDelta max_presentation_timestamp); |
| 142 | 144 |
| 143 // Helper function to get the current access unit that is being decoded. | 145 // Helper function to get the current access unit that is being decoded. |
| 144 const AccessUnit& CurrentAccessUnit() const; | 146 const AccessUnit& CurrentAccessUnit() const; |
| 145 | 147 |
| 146 // Check whether a chunk has no remaining access units to decode. If | 148 // Check whether a chunk has no remaining access units to decode. If |
| 147 // |is_active_chunk| is true, this function returns whether decoder has | 149 // |is_active_chunk| is true, this function returns whether decoder has |
| 148 // consumed all data in |received_data_[current_demuxer_data_index_]|. | 150 // consumed all data in |received_data_[current_demuxer_data_index_]|. |
| 149 // Otherwise, it returns whether decoder has consumed all data in the inactive | 151 // Otherwise, it returns whether decoder has consumed all data in the inactive |
| 150 // chunk. | 152 // chunk. |
| 151 bool NoAccessUnitsRemainingInChunk(bool is_active_chunk) const; | 153 bool NoAccessUnitsRemainingInChunk(bool is_active_chunk) const; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // the decoder thread. | 249 // the decoder thread. |
| 248 // NOTE: Weak pointers must be invalidated before all other member variables. | 250 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 249 base::WeakPtrFactory<MediaDecoderJob> weak_factory_; | 251 base::WeakPtrFactory<MediaDecoderJob> weak_factory_; |
| 250 | 252 |
| 251 DISALLOW_IMPLICIT_CONSTRUCTORS(MediaDecoderJob); | 253 DISALLOW_IMPLICIT_CONSTRUCTORS(MediaDecoderJob); |
| 252 }; | 254 }; |
| 253 | 255 |
| 254 } // namespace media | 256 } // namespace media |
| 255 | 257 |
| 256 #endif // MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ | 258 #endif // MEDIA_BASE_ANDROID_MEDIA_DECODER_JOB_H_ |
| OLD | NEW |