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_CODEC_BRIDGE_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <stdint.h> |
| 10 |
9 #include <set> | 11 #include <set> |
10 #include <string> | 12 #include <string> |
11 | 13 |
12 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
14 #include "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
15 #include "media/base/video_decoder_config.h" | 17 #include "media/base/video_decoder_config.h" |
16 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
17 | 19 |
18 namespace media { | 20 namespace media { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 112 |
111 // Used for checking for new sampling rate after DequeueInputBuffer() returns | 113 // Used for checking for new sampling rate after DequeueInputBuffer() returns |
112 // INFO_OUTPUT_FORMAT_CHANGED | 114 // INFO_OUTPUT_FORMAT_CHANGED |
113 int GetOutputSamplingRate(); | 115 int GetOutputSamplingRate(); |
114 | 116 |
115 // Submits a byte array to the given input buffer. Call this after getting an | 117 // Submits a byte array to the given input buffer. Call this after getting an |
116 // available buffer from DequeueInputBuffer(). If |data| is NULL, assume the | 118 // available buffer from DequeueInputBuffer(). If |data| is NULL, assume the |
117 // input buffer has already been populated (but still obey |size|). | 119 // input buffer has already been populated (but still obey |size|). |
118 // |data_size| must be less than kint32max (because Java). | 120 // |data_size| must be less than kint32max (because Java). |
119 MediaCodecStatus QueueInputBuffer(int index, | 121 MediaCodecStatus QueueInputBuffer(int index, |
120 const uint8* data, | 122 const uint8_t* data, |
121 size_t data_size, | 123 size_t data_size, |
122 const base::TimeDelta& presentation_time); | 124 const base::TimeDelta& presentation_time); |
123 | 125 |
124 // Similar to the above call, but submits a buffer that is encrypted. Note: | 126 // Similar to the above call, but submits a buffer that is encrypted. Note: |
125 // NULL |subsamples| indicates the whole buffer is encrypted. If |data| is | 127 // NULL |subsamples| indicates the whole buffer is encrypted. If |data| is |
126 // NULL, assume the input buffer has already been populated (but still obey | 128 // NULL, assume the input buffer has already been populated (but still obey |
127 // |data_size|). |data_size| must be less than kint32max (because Java). | 129 // |data_size|). |data_size| must be less than kint32max (because Java). |
128 MediaCodecStatus QueueSecureInputBuffer( | 130 MediaCodecStatus QueueSecureInputBuffer( |
129 int index, | 131 int index, |
130 const uint8* data, | 132 const uint8_t* data, |
131 size_t data_size, | 133 size_t data_size, |
132 const std::string& key_id, | 134 const std::string& key_id, |
133 const std::string& iv, | 135 const std::string& iv, |
134 const std::vector<SubsampleEntry>& subsamples, | 136 const std::vector<SubsampleEntry>& subsamples, |
135 const base::TimeDelta& presentation_time); | 137 const base::TimeDelta& presentation_time); |
136 | 138 |
137 // Same QueueSecureInputBuffer overriden for the use with MediaSourcePlayer | 139 // Same QueueSecureInputBuffer overriden for the use with MediaSourcePlayer |
138 // and MediaCodecPlayer. | 140 // and MediaCodecPlayer. |
139 // TODO(timav): remove this method and keep only the one above after we | 141 // TODO(timav): remove this method and keep only the one above after we |
140 // switch to the Spitzer pipeline. | 142 // switch to the Spitzer pipeline. |
141 MediaCodecStatus QueueSecureInputBuffer( | 143 MediaCodecStatus QueueSecureInputBuffer( |
142 int index, | 144 int index, |
143 const uint8* data, | 145 const uint8_t* data, |
144 size_t data_size, | 146 size_t data_size, |
145 const uint8* key_id, | 147 const uint8_t* key_id, |
146 int key_id_size, | 148 int key_id_size, |
147 const uint8* iv, | 149 const uint8_t* iv, |
148 int iv_size, | 150 int iv_size, |
149 const SubsampleEntry* subsamples, | 151 const SubsampleEntry* subsamples, |
150 int subsamples_size, | 152 int subsamples_size, |
151 const base::TimeDelta& presentation_time); | 153 const base::TimeDelta& presentation_time); |
152 | 154 |
153 // Submits an empty buffer with a EOS (END OF STREAM) flag. | 155 // Submits an empty buffer with a EOS (END OF STREAM) flag. |
154 void QueueEOS(int input_buffer_index); | 156 void QueueEOS(int input_buffer_index); |
155 | 157 |
156 // Returns: | 158 // Returns: |
157 // MEDIA_CODEC_OK if an input buffer is ready to be filled with valid data, | 159 // MEDIA_CODEC_OK if an input buffer is ready to be filled with valid data, |
(...skipping 27 matching lines...) Expand all Loading... |
185 | 187 |
186 // Returns the number of output buffers used by the codec. | 188 // Returns the number of output buffers used by the codec. |
187 // TODO(qinmin): this call is deprecated in Lollipop. | 189 // TODO(qinmin): this call is deprecated in Lollipop. |
188 int GetOutputBuffersCount(); | 190 int GetOutputBuffersCount(); |
189 | 191 |
190 // Returns the capacity of each output buffer used by the codec. | 192 // Returns the capacity of each output buffer used by the codec. |
191 // TODO(qinmin): this call is deprecated in Lollipop. | 193 // TODO(qinmin): this call is deprecated in Lollipop. |
192 size_t GetOutputBuffersCapacity(); | 194 size_t GetOutputBuffersCapacity(); |
193 | 195 |
194 // Returns an input buffer's base pointer and capacity. | 196 // Returns an input buffer's base pointer and capacity. |
195 void GetInputBuffer(int input_buffer_index, uint8** data, size_t* capacity); | 197 void GetInputBuffer(int input_buffer_index, uint8_t** data, size_t* capacity); |
196 | 198 |
197 // Copy |dst_size| bytes from output buffer |index|'s |offset| onwards into | 199 // Copy |dst_size| bytes from output buffer |index|'s |offset| onwards into |
198 // |*dst|. | 200 // |*dst|. |
199 bool CopyFromOutputBuffer(int index, size_t offset, void* dst, int dst_size); | 201 bool CopyFromOutputBuffer(int index, size_t offset, void* dst, int dst_size); |
200 | 202 |
201 static bool RegisterMediaCodecBridge(JNIEnv* env); | 203 static bool RegisterMediaCodecBridge(JNIEnv* env); |
202 | 204 |
203 protected: | 205 protected: |
204 // Returns true if |mime_type| is known to be unaccelerated (i.e. backed by a | 206 // Returns true if |mime_type| is known to be unaccelerated (i.e. backed by a |
205 // software codec instead of a hardware one). | 207 // software codec instead of a hardware one). |
(...skipping 14 matching lines...) Expand all Loading... |
220 // the address to read. | 222 // the address to read. |
221 int GetOutputBufferAddress(int index, size_t offset, void** addr); | 223 int GetOutputBufferAddress(int index, size_t offset, void** addr); |
222 | 224 |
223 jobject media_codec() { return j_media_codec_.obj(); } | 225 jobject media_codec() { return j_media_codec_.obj(); } |
224 MediaCodecDirection direction_; | 226 MediaCodecDirection direction_; |
225 | 227 |
226 private: | 228 private: |
227 // Fills a particular input buffer; returns false if |data_size| exceeds the | 229 // Fills a particular input buffer; returns false if |data_size| exceeds the |
228 // input buffer's capacity (and doesn't touch the input buffer in that case). | 230 // input buffer's capacity (and doesn't touch the input buffer in that case). |
229 bool FillInputBuffer(int index, | 231 bool FillInputBuffer(int index, |
230 const uint8* data, | 232 const uint8_t* data, |
231 size_t data_size) WARN_UNUSED_RESULT; | 233 size_t data_size) WARN_UNUSED_RESULT; |
232 | 234 |
233 // Java MediaCodec instance. | 235 // Java MediaCodec instance. |
234 base::android::ScopedJavaGlobalRef<jobject> j_media_codec_; | 236 base::android::ScopedJavaGlobalRef<jobject> j_media_codec_; |
235 | 237 |
236 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge); | 238 DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge); |
237 }; | 239 }; |
238 | 240 |
239 class AudioCodecBridge : public MediaCodecBridge { | 241 class AudioCodecBridge : public MediaCodecBridge { |
240 public: | 242 public: |
241 // Returns an AudioCodecBridge instance if |codec| is supported, or a NULL | 243 // Returns an AudioCodecBridge instance if |codec| is supported, or a NULL |
242 // pointer otherwise. | 244 // pointer otherwise. |
243 static AudioCodecBridge* Create(const AudioCodec& codec); | 245 static AudioCodecBridge* Create(const AudioCodec& codec); |
244 | 246 |
245 // See MediaCodecBridge::IsKnownUnaccelerated(). | 247 // See MediaCodecBridge::IsKnownUnaccelerated(). |
246 static bool IsKnownUnaccelerated(const AudioCodec& codec); | 248 static bool IsKnownUnaccelerated(const AudioCodec& codec); |
247 | 249 |
248 // Start the audio codec bridge. | 250 // Start the audio codec bridge. |
249 bool Start(const AudioCodec& codec, int sample_rate, int channel_count, | 251 bool Start(const AudioCodec& codec, |
250 const uint8* extra_data, size_t extra_data_size, | 252 int sample_rate, |
251 int64 codec_delay_ns, int64 seek_preroll_ns, | 253 int channel_count, |
252 bool play_audio, jobject media_crypto) WARN_UNUSED_RESULT; | 254 const uint8_t* extra_data, |
| 255 size_t extra_data_size, |
| 256 int64_t codec_delay_ns, |
| 257 int64_t seek_preroll_ns, |
| 258 bool play_audio, |
| 259 jobject media_crypto) WARN_UNUSED_RESULT; |
253 | 260 |
254 // Plays the output buffer right away or save for later playback if |postpone| | 261 // Plays the output buffer right away or save for later playback if |postpone| |
255 // is set to true. This call must be called after DequeueOutputBuffer() and | 262 // is set to true. This call must be called after DequeueOutputBuffer() and |
256 // before ReleaseOutputBuffer. The data is extracted from the output buffers | 263 // before ReleaseOutputBuffer. The data is extracted from the output buffers |
257 // using |index|, |size| and |offset|. Returns the playback head position | 264 // using |index|, |size| and |offset|. Returns the playback head position |
258 // expressed in frames. | 265 // expressed in frames. |
259 // When |postpone| is set to true, the next PlayOutputBuffer() should have | 266 // When |postpone| is set to true, the next PlayOutputBuffer() should have |
260 // postpone == false, and it will play two buffers: the postponed one and | 267 // postpone == false, and it will play two buffers: the postponed one and |
261 // the one identified by |index|. | 268 // the one identified by |index|. |
262 int64 PlayOutputBuffer(int index, | 269 int64_t PlayOutputBuffer(int index, |
263 size_t size, | 270 size_t size, |
264 size_t offset, | 271 size_t offset, |
265 bool postpone = false); | 272 bool postpone = false); |
266 | 273 |
267 // Set the volume of the audio output. | 274 // Set the volume of the audio output. |
268 void SetVolume(double volume); | 275 void SetVolume(double volume); |
269 | 276 |
270 private: | 277 private: |
271 explicit AudioCodecBridge(const std::string& mime); | 278 explicit AudioCodecBridge(const std::string& mime); |
272 | 279 |
273 // Configure the java MediaFormat object with the extra codec data passed in. | 280 // Configure the java MediaFormat object with the extra codec data passed in. |
274 bool ConfigureMediaFormat(jobject j_format, const AudioCodec& codec, | 281 bool ConfigureMediaFormat(jobject j_format, |
275 const uint8* extra_data, size_t extra_data_size, | 282 const AudioCodec& codec, |
276 int64 codec_delay_ns, int64 seek_preroll_ns); | 283 const uint8_t* extra_data, |
| 284 size_t extra_data_size, |
| 285 int64_t codec_delay_ns, |
| 286 int64_t seek_preroll_ns); |
277 }; | 287 }; |
278 | 288 |
279 class MEDIA_EXPORT VideoCodecBridge : public MediaCodecBridge { | 289 class MEDIA_EXPORT VideoCodecBridge : public MediaCodecBridge { |
280 public: | 290 public: |
281 // See MediaCodecBridge::IsKnownUnaccelerated(). | 291 // See MediaCodecBridge::IsKnownUnaccelerated(). |
282 static bool IsKnownUnaccelerated(const VideoCodec& codec, | 292 static bool IsKnownUnaccelerated(const VideoCodec& codec, |
283 MediaCodecDirection direction); | 293 MediaCodecDirection direction); |
284 | 294 |
285 // Create, start, and return a VideoCodecBridge decoder or NULL on failure. | 295 // Create, start, and return a VideoCodecBridge decoder or NULL on failure. |
286 static VideoCodecBridge* CreateDecoder( | 296 static VideoCodecBridge* CreateDecoder( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 VideoCodecBridge(const std::string& mime, | 330 VideoCodecBridge(const std::string& mime, |
321 bool is_secure, | 331 bool is_secure, |
322 MediaCodecDirection direction); | 332 MediaCodecDirection direction); |
323 | 333 |
324 int adaptive_playback_supported_for_testing_; | 334 int adaptive_playback_supported_for_testing_; |
325 }; | 335 }; |
326 | 336 |
327 } // namespace media | 337 } // namespace media |
328 | 338 |
329 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 339 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
OLD | NEW |