Chromium Code Reviews| 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 | 9 |
| 10 #include "base/file_descriptor_posix.h" | 10 #include "base/file_descriptor_posix.h" |
| 11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
| 12 #include "media/base/media_export.h" | 12 #include "media/base/media_export.h" |
| 13 | 13 |
| 14 namespace media { | 14 namespace media { |
| 15 | 15 |
| 16 // This class serves as a bridge for native code to call Java | 16 // This class serves as a bridge for native code to call Java |
| 17 // functions in the Android MediaCodec class. See | 17 // functions in the Android MediaCodec class. See |
| 18 // http://developer.android.com/reference/android/media/MediaCodec.html. | 18 // http://developer.android.com/reference/android/media/MediaCodec.html. |
| 19 class MEDIA_EXPORT WebAudioMediaCodecBridge { | 19 class MEDIA_EXPORT WebAudioMediaCodecBridge { |
| 20 public: | 20 public: |
| 21 // Create the bridge with the given file descriptors. We read from | 21 // Create the bridge with the given file descriptors. We read from |
| 22 // |encoded_audio_handle| to get the encoded audio data. Audio file | 22 // |encoded_audio_handle| to get the encoded audio data. Audio file |
| 23 // information and decoded PCM samples are written to |pcm_output|. | 23 // information and decoded PCM samples are written to |pcm_output|. |
| 24 // We also take ownership of |pcm_output|. | 24 // We also take ownership of |pcm_output|. |
| 25 WebAudioMediaCodecBridge(base::SharedMemoryHandle encoded_audio_handle, | 25 WebAudioMediaCodecBridge(base::SharedMemoryHandle encoded_audio_handle, |
| 26 base::FileDescriptor pcm_output); | 26 base::FileDescriptor pcm_output, |
| 27 size_t data_size); | |
| 27 ~WebAudioMediaCodecBridge(); | 28 ~WebAudioMediaCodecBridge(); |
| 28 | 29 |
| 29 // Inform JNI about this bridge. Returns true if registration | 30 // Inform JNI about this bridge. Returns true if registration |
| 30 // succeeded. | 31 // succeeded. |
| 31 static bool RegisterWebAudioMediaCodecBridge(JNIEnv* env); | 32 static bool RegisterWebAudioMediaCodecBridge(JNIEnv* env); |
| 32 | 33 |
| 33 // Start MediaCodec to process the encoded data in | 34 // Start MediaCodec to process the encoded data in |
| 34 // |encoded_audio_handle|. The PCM samples are sent to |pcm_output|. | 35 // |encoded_audio_handle|. The PCM samples are sent to |pcm_output|. |
| 35 static void RunWebAudioMediaCodec( | 36 static void RunWebAudioMediaCodec( |
| 36 base::SharedMemoryHandle encoded_audio_handle, | 37 base::SharedMemoryHandle encoded_audio_handle, |
| 37 base::FileDescriptor pcm_output); | 38 base::FileDescriptor pcm_output, |
| 39 size_t data_size); | |
| 38 | 40 |
| 39 void OnChunkDecoded(JNIEnv* env, | 41 void OnChunkDecoded(JNIEnv* env, |
| 40 jobject /*java object*/, | 42 jobject /*java object*/, |
| 41 jobject buf, | 43 jobject buf, |
| 42 jint buf_size); | 44 jint buf_size); |
| 43 | 45 |
| 44 void InitializeDestination(JNIEnv* env, | 46 void InitializeDestination(JNIEnv* env, |
| 45 jobject /*java object*/, | 47 jobject /*java object*/, |
| 46 jint channel_count, | 48 jint channel_count, |
| 47 jint sample_rate, | 49 jint sample_rate, |
| 48 jlong duration_us, | 50 jlong duration_us); |
| 49 jboolean is_vorbis); | |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 // Handles MediaCodec processing of the encoded data in | 53 // Handles MediaCodec processing of the encoded data in |
| 53 // |encoded_audio_handle_| and sends the pcm data to |pcm_output_|. | 54 // |encoded_audio_handle_| and sends the pcm data to |pcm_output_|. |
| 54 // Returns true if decoding was successful. | 55 // Returns true if decoding was successful. |
| 55 bool DecodeInMemoryAudioFile(); | 56 bool DecodeInMemoryAudioFile(); |
| 56 | 57 |
| 57 // The encoded audio data is read from this file descriptor for the | 58 // The encoded audio data is read from this file descriptor for the |
| 58 // shared memory that holds the encoded data. | 59 // shared memory that holds the encoded data. |
| 59 int encoded_audio_handle_; | 60 int encoded_audio_handle_; |
| 60 | 61 |
| 61 // The audio file information and decoded pcm data are written to | 62 // The audio file information and decoded pcm data are written to |
| 62 // this file descriptor. We take ownership of this descriptor. | 63 // this file descriptor. We take ownership of this descriptor. |
| 63 int pcm_output_; | 64 int pcm_output_; |
| 64 | 65 |
| 66 // The length of the encoded data | |
|
bulach
2013/04/29 13:16:25
nit: end with a .
| |
| 67 size_t data_size_; | |
| 68 | |
| 65 DISALLOW_COPY_AND_ASSIGN(WebAudioMediaCodecBridge); | 69 DISALLOW_COPY_AND_ASSIGN(WebAudioMediaCodecBridge); |
| 66 }; | 70 }; |
| 67 | 71 |
| 68 } // namespace media | 72 } // namespace media |
| 69 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ | 73 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_ |
| OLD | NEW |