| 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_SDK_MEDIA_CODEC_BRIDGE_H_ | 5 #ifndef MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_ |
| 6 #define MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_ | 6 #define MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // This class implements MediaCodecBridge using android MediaCodec SDK APIs. | 26 // This class implements MediaCodecBridge using android MediaCodec SDK APIs. |
| 27 class MEDIA_EXPORT SdkMediaCodecBridge : public MediaCodecBridge { | 27 class MEDIA_EXPORT SdkMediaCodecBridge : public MediaCodecBridge { |
| 28 public: | 28 public: |
| 29 ~SdkMediaCodecBridge() override; | 29 ~SdkMediaCodecBridge() override; |
| 30 | 30 |
| 31 // MediaCodecBridge implementations. | 31 // MediaCodecBridge implementations. |
| 32 MediaCodecStatus Reset() override; | 32 MediaCodecStatus Reset() override; |
| 33 bool Start() override; | 33 bool Start() override; |
| 34 void Stop() override; | 34 void Stop() override; |
| 35 void GetOutputFormat(int* width, int* height) override; | 35 MediaCodecStatus GetOutputSize(gfx::Size* size) override; |
| 36 int GetOutputSamplingRate() override; | 36 MediaCodecStatus GetOutputSamplingRate(int* sampling_rate) override; |
| 37 MediaCodecStatus QueueInputBuffer( | 37 MediaCodecStatus QueueInputBuffer( |
| 38 int index, | 38 int index, |
| 39 const uint8_t* data, | 39 const uint8_t* data, |
| 40 size_t data_size, | 40 size_t data_size, |
| 41 const base::TimeDelta& presentation_time) override; | 41 const base::TimeDelta& presentation_time) override; |
| 42 using MediaCodecBridge::QueueSecureInputBuffer; | 42 using MediaCodecBridge::QueueSecureInputBuffer; |
| 43 MediaCodecStatus QueueSecureInputBuffer( | 43 MediaCodecStatus QueueSecureInputBuffer( |
| 44 int index, | 44 int index, |
| 45 const uint8_t* data, | 45 const uint8_t* data, |
| 46 size_t data_size, | 46 size_t data_size, |
| 47 const std::vector<char>& key_id, | 47 const std::vector<char>& key_id, |
| 48 const std::vector<char>& iv, | 48 const std::vector<char>& iv, |
| 49 const SubsampleEntry* subsamples, | 49 const SubsampleEntry* subsamples, |
| 50 int subsamples_size, | 50 int subsamples_size, |
| 51 const base::TimeDelta& presentation_time) override; | 51 const base::TimeDelta& presentation_time) override; |
| 52 void QueueEOS(int input_buffer_index) override; | 52 void QueueEOS(int input_buffer_index) override; |
| 53 MediaCodecStatus DequeueInputBuffer(const base::TimeDelta& timeout, | 53 MediaCodecStatus DequeueInputBuffer(const base::TimeDelta& timeout, |
| 54 int* index) override; | 54 int* index) override; |
| 55 MediaCodecStatus DequeueOutputBuffer(const base::TimeDelta& timeout, | 55 MediaCodecStatus DequeueOutputBuffer(const base::TimeDelta& timeout, |
| 56 int* index, | 56 int* index, |
| 57 size_t* offset, | 57 size_t* offset, |
| 58 size_t* size, | 58 size_t* size, |
| 59 base::TimeDelta* presentation_time, | 59 base::TimeDelta* presentation_time, |
| 60 bool* end_of_stream, | 60 bool* end_of_stream, |
| 61 bool* key_frame) override; | 61 bool* key_frame) override; |
| 62 void ReleaseOutputBuffer(int index, bool render) override; | 62 void ReleaseOutputBuffer(int index, bool render) override; |
| 63 void GetInputBuffer(int input_buffer_index, | 63 MediaCodecStatus GetInputBuffer(int input_buffer_index, |
| 64 uint8_t** data, | 64 uint8_t** data, |
| 65 size_t* capacity) override; | 65 size_t* capacity) override; |
| 66 void CopyFromOutputBuffer(int index, | 66 MediaCodecStatus CopyFromOutputBuffer(int index, |
| 67 size_t offset, | 67 size_t offset, |
| 68 void* dst, | 68 void* dst, |
| 69 size_t num) override; | 69 size_t num) override; |
| 70 | 70 |
| 71 static bool RegisterSdkMediaCodecBridge(JNIEnv* env); | 71 static bool RegisterSdkMediaCodecBridge(JNIEnv* env); |
| 72 | 72 |
| 73 protected: | 73 protected: |
| 74 SdkMediaCodecBridge(const std::string& mime, | 74 SdkMediaCodecBridge(const std::string& mime, |
| 75 bool is_secure, | 75 bool is_secure, |
| 76 MediaCodecDirection direction); | 76 MediaCodecDirection direction); |
| 77 | 77 |
| 78 // Called to get the buffer address given the output buffer index and offset. | 78 // Called to get the buffer address given the output buffer index and offset. |
| 79 // This function returns the size of available data to read and |addr| is the | 79 // The size of available data to read is written to |*capacity| and the |
| 80 // pointer to the address to read. | 80 // address to read from is written to |*addr|. |
| 81 size_t GetOutputBufferAddress(int index, size_t offset, void** addr); | 81 // Returns MEDIA_CODEC_ERROR if a error occurs, or MEDIA_CODEC_OK otherwise. |
| 82 MediaCodecStatus GetOutputBufferAddress(int index, |
| 83 size_t offset, |
| 84 void** addr, |
| 85 size_t* capacity); |
| 82 | 86 |
| 83 jobject media_codec() { return j_media_codec_.obj(); } | 87 jobject media_codec() { return j_media_codec_.obj(); } |
| 84 MediaCodecDirection direction_; | 88 MediaCodecDirection direction_; |
| 85 | 89 |
| 86 private: | 90 private: |
| 87 // Java MediaCodec instance. | 91 // Java MediaCodec instance. |
| 88 base::android::ScopedJavaGlobalRef<jobject> j_media_codec_; | 92 base::android::ScopedJavaGlobalRef<jobject> j_media_codec_; |
| 89 | 93 |
| 90 DISALLOW_COPY_AND_ASSIGN(SdkMediaCodecBridge); | 94 DISALLOW_COPY_AND_ASSIGN(SdkMediaCodecBridge); |
| 91 }; | 95 }; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 118 const uint8_t* extra_data, | 122 const uint8_t* extra_data, |
| 119 size_t extra_data_size, | 123 size_t extra_data_size, |
| 120 int64_t codec_delay_ns, | 124 int64_t codec_delay_ns, |
| 121 int64_t seek_preroll_ns, | 125 int64_t seek_preroll_ns, |
| 122 bool play_audio, | 126 bool play_audio, |
| 123 jobject media_crypto) WARN_UNUSED_RESULT; | 127 jobject media_crypto) WARN_UNUSED_RESULT; |
| 124 | 128 |
| 125 // Plays the output buffer right away or save for later playback if |postpone| | 129 // Plays the output buffer right away or save for later playback if |postpone| |
| 126 // is set to true. This call must be called after DequeueOutputBuffer() and | 130 // is set to true. This call must be called after DequeueOutputBuffer() and |
| 127 // before ReleaseOutputBuffer. The data is extracted from the output buffers | 131 // before ReleaseOutputBuffer. The data is extracted from the output buffers |
| 128 // using |index|, |size| and |offset|. Returns the playback head position | 132 // using |index|, |size| and |offset|. The playback head position in frames is |
| 129 // expressed in frames. | 133 // output in |*playback_pos|. |
| 130 // When |postpone| is set to true, the next PlayOutputBuffer() should have | 134 // When |postpone| is set to true, the next PlayOutputBuffer() should have |
| 131 // postpone == false, and it will play two buffers: the postponed one and | 135 // postpone == false, and it will play two buffers: the postponed one and |
| 132 // the one identified by |index|. | 136 // the one identified by |index|. |
| 133 int64_t PlayOutputBuffer(int index, | 137 // Returns MEDIA_CODEC_ERROR if an error occurs, or MEDIA_CODEC_OK otherwise. |
| 134 size_t size, | 138 MediaCodecStatus PlayOutputBuffer(int index, |
| 135 size_t offset, | 139 size_t size, |
| 136 bool postpone = false); | 140 size_t offset, |
| 141 bool postpone, |
| 142 int64_t* playback_pos); |
| 137 | 143 |
| 138 // Set the volume of the audio output. | 144 // Set the volume of the audio output. |
| 139 void SetVolume(double volume); | 145 void SetVolume(double volume); |
| 140 | 146 |
| 141 private: | 147 private: |
| 142 explicit AudioCodecBridge(const std::string& mime); | 148 explicit AudioCodecBridge(const std::string& mime); |
| 143 | 149 |
| 144 // Configure the java MediaFormat object with the extra codec data passed in. | 150 // Configure the java MediaFormat object with the extra codec data passed in. |
| 145 bool ConfigureMediaFormat(jobject j_format, | 151 bool ConfigureMediaFormat(jobject j_format, |
| 146 const AudioCodec& codec, | 152 const AudioCodec& codec, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 VideoCodecBridge(const std::string& mime, | 205 VideoCodecBridge(const std::string& mime, |
| 200 bool is_secure, | 206 bool is_secure, |
| 201 MediaCodecDirection direction); | 207 MediaCodecDirection direction); |
| 202 | 208 |
| 203 int adaptive_playback_supported_for_testing_; | 209 int adaptive_playback_supported_for_testing_; |
| 204 }; | 210 }; |
| 205 | 211 |
| 206 } // namespace media | 212 } // namespace media |
| 207 | 213 |
| 208 #endif // MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_ | 214 #endif // MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_ |
| OLD | NEW |