| 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 <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "media/base/audio_decoder_config.h" | 13 #include "media/base/audio_decoder_config.h" |
| 14 #include "media/base/video_decoder_config.h" | 14 #include "media/base/video_decoder_config.h" |
| 15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 struct SubsampleEntry; | 19 struct SubsampleEntry; |
| 20 | 20 |
| 21 // These must be in sync with MediaCodecBridge.MEDIA_CODEC_XXX constants in |
| 22 // MediaCodecBridge.java. |
| 21 enum MediaCodecStatus { | 23 enum MediaCodecStatus { |
| 22 MEDIA_CODEC_OK, | 24 MEDIA_CODEC_OK, |
| 23 MEDIA_CODEC_ENQUEUE_INPUT_AGAIN_LATER, | 25 MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER, |
| 24 MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER, | 26 MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER, |
| 25 MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED, | 27 MEDIA_CODEC_OUTPUT_BUFFERS_CHANGED, |
| 26 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, | 28 MEDIA_CODEC_OUTPUT_FORMAT_CHANGED, |
| 27 MEDIA_CODEC_INPUT_END_OF_STREAM, | 29 MEDIA_CODEC_INPUT_END_OF_STREAM, |
| 28 MEDIA_CODEC_OUTPUT_END_OF_STREAM, | 30 MEDIA_CODEC_OUTPUT_END_OF_STREAM, |
| 31 MEDIA_CODEC_NO_KEY, |
| 29 MEDIA_CODEC_STOPPED, | 32 MEDIA_CODEC_STOPPED, |
| 30 MEDIA_CODEC_ERROR | 33 MEDIA_CODEC_ERROR |
| 31 }; | 34 }; |
| 32 | 35 |
| 33 // This class serves as a bridge for native code to call java functions inside | 36 // This class serves as a bridge for native code to call java functions inside |
| 34 // Android MediaCodec class. For more information on Android MediaCodec, check | 37 // Android MediaCodec class. For more information on Android MediaCodec, check |
| 35 // http://developer.android.com/reference/android/media/MediaCodec.html | 38 // http://developer.android.com/reference/android/media/MediaCodec.html |
| 36 // Note: MediaCodec is only available on JB and greater. | 39 // Note: MediaCodec is only available on JB and greater. |
| 37 // Use AudioCodecBridge or VideoCodecBridge to create an instance of this | 40 // Use AudioCodecBridge or VideoCodecBridge to create an instance of this |
| 38 // object. | 41 // object. |
| 39 class MEDIA_EXPORT MediaCodecBridge { | 42 class MEDIA_EXPORT MediaCodecBridge { |
| 40 public: | 43 public: |
| 41 enum DequeueBufferInfo { | |
| 42 INFO_OUTPUT_BUFFERS_CHANGED = -3, | |
| 43 INFO_OUTPUT_FORMAT_CHANGED = -2, | |
| 44 INFO_TRY_AGAIN_LATER = -1, | |
| 45 INFO_MEDIA_CODEC_ERROR = -1000, | |
| 46 }; | |
| 47 | |
| 48 // Returns true if MediaCodec is available on the device. | 44 // Returns true if MediaCodec is available on the device. |
| 49 static bool IsAvailable(); | 45 static bool IsAvailable(); |
| 50 | 46 |
| 51 // Returns whether MediaCodecBridge has a decoder that |is_secure| and can | 47 // Returns whether MediaCodecBridge has a decoder that |is_secure| and can |
| 52 // decode |codec| type. | 48 // decode |codec| type. |
| 53 static bool CanDecode(const std::string& codec, bool is_secure); | 49 static bool CanDecode(const std::string& codec, bool is_secure); |
| 54 | 50 |
| 55 virtual ~MediaCodecBridge(); | 51 virtual ~MediaCodecBridge(); |
| 56 | 52 |
| 57 // Resets both input and output, all indices previously returned in calls to | 53 // Resets both input and output, all indices previously returned in calls to |
| 58 // DequeueInputBuffer() and DequeueOutputBuffer() become invalid. | 54 // DequeueInputBuffer() and DequeueOutputBuffer() become invalid. |
| 59 // Please note that this clears all the inputs in the media codec. In other | 55 // Please note that this clears all the inputs in the media codec. In other |
| 60 // words, there will be no outputs until new input is provided. | 56 // words, there will be no outputs until new input is provided. |
| 61 void Reset(); | 57 void Reset(); |
| 62 | 58 |
| 63 // Finishes the decode/encode session. The instance remains active | 59 // Finishes the decode/encode session. The instance remains active |
| 64 // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy | 60 // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy |
| 65 // vendor's implementation , b/8125974, Stop() -> StartAudio/Video() may not | 61 // vendor's implementation , b/8125974, Stop() -> StartAudio/Video() may not |
| 66 // work on some devices. For reliability, Stop() -> delete and recreate new | 62 // work on some devices. For reliability, Stop() -> delete and recreate new |
| 67 // instance -> StartAudio/Video() is recommended. | 63 // instance -> StartAudio/Video() is recommended. |
| 68 void Stop(); | 64 void Stop(); |
| 69 | 65 |
| 70 // Used for getting output format. This is valid after DequeueInputBuffer() | 66 // Used for getting output format. This is valid after DequeueInputBuffer() |
| 71 // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED | 67 // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED |
| 72 void GetOutputFormat(int* width, int* height); | 68 void GetOutputFormat(int* width, int* height); |
| 73 | 69 |
| 74 // Submits a byte array to the given input buffer. Call this after getting an | 70 // Submits a byte array to the given input buffer. Call this after getting an |
| 75 // available buffer from DequeueInputBuffer(). Returns the number of bytes | 71 // available buffer from DequeueInputBuffer(). |
| 76 // put to the input buffer. | 72 MediaCodecStatus QueueInputBuffer(int index, |
| 77 size_t QueueInputBuffer(int index, const uint8* data, int size, | 73 const uint8* data, |
| 78 const base::TimeDelta& presentation_time); | 74 int size, |
| 75 const base::TimeDelta& presentation_time); |
| 79 | 76 |
| 80 // Similar to the above call, but submits a buffer that is encrypted. | 77 // Similar to the above call, but submits a buffer that is encrypted. |
| 81 size_t QueueSecureInputBuffer( | 78 MediaCodecStatus QueueSecureInputBuffer( |
| 82 int index, const uint8* data, int data_size, | 79 int index, |
| 80 const uint8* data, int data_size, |
| 83 const uint8* key_id, int key_id_size, | 81 const uint8* key_id, int key_id_size, |
| 84 const uint8* iv, int iv_size, | 82 const uint8* iv, int iv_size, |
| 85 const SubsampleEntry* subsamples, int subsamples_size, | 83 const SubsampleEntry* subsamples, int subsamples_size, |
| 86 const base::TimeDelta& presentation_time); | 84 const base::TimeDelta& presentation_time); |
| 87 | 85 |
| 88 // Submits an empty buffer with a EOS (END OF STREAM) flag. | 86 // Submits an empty buffer with a EOS (END OF STREAM) flag. |
| 89 void QueueEOS(int input_buffer_index); | 87 void QueueEOS(int input_buffer_index); |
| 90 | 88 |
| 91 // Returns: | 89 // Returns: |
| 92 // MEDIA_CODEC_OK if an input buffer is ready to be filled with valid data, | 90 // MEDIA_CODEC_OK if an input buffer is ready to be filled with valid data, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 jobject media_crypto); | 177 jobject media_crypto); |
| 180 | 178 |
| 181 private: | 179 private: |
| 182 explicit VideoCodecBridge(const std::string& mime); | 180 explicit VideoCodecBridge(const std::string& mime); |
| 183 }; | 181 }; |
| 184 | 182 |
| 185 } // namespace media | 183 } // namespace media |
| 186 | 184 |
| 187 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 185 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
| 188 | 186 |
| OLD | NEW |