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