OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MEDIA_BASE_ANDROID_WEBAUDIO_MEDIA_CODEC_BRIDGE_H_ | |
6 #define MEDIA_BASE_ANDROID_WEBAUDIO_MEDIA_CODEC_BRIDGE_H_ | |
7 | |
8 #include <jni.h> | |
9 #include <stdint.h> | |
10 | |
11 #include "base/android/scoped_java_ref.h" | |
12 #include "base/callback.h" | |
13 #include "base/file_descriptor_posix.h" | |
14 #include "base/macros.h" | |
15 #include "base/memory/shared_memory.h" | |
16 #include "media/base/media_export.h" | |
17 | |
18 namespace media { | |
19 | |
20 // This class serves as a bridge for native code to call Java | |
21 // functions in the Android MediaCodec class. See | |
22 // http://developer.android.com/reference/android/media/MediaCodec.html. | |
23 class MEDIA_EXPORT WebAudioMediaCodecBridge { | |
24 public: | |
25 // Create the bridge with the given file descriptors. We read from | |
26 // |encoded_audio_handle| to get the encoded audio data. Audio file | |
27 // information and decoded PCM samples are written to |pcm_output|. | |
28 // We also take ownership of |pcm_output|. | |
29 WebAudioMediaCodecBridge(base::SharedMemoryHandle encoded_audio_handle, | |
30 base::FileDescriptor pcm_output, | |
31 uint32_t data_size); | |
32 ~WebAudioMediaCodecBridge(); | |
33 | |
34 // Inform JNI about this bridge. Returns true if registration | |
35 // succeeded. | |
36 static bool RegisterWebAudioMediaCodecBridge(JNIEnv* env); | |
37 | |
38 // Start MediaCodec to process the encoded data in | |
39 // |encoded_audio_handle|. The PCM samples are sent to |pcm_output|. | |
40 static void RunWebAudioMediaCodec( | |
41 base::SharedMemoryHandle encoded_audio_handle, | |
42 base::FileDescriptor pcm_output, | |
43 uint32_t data_size, | |
44 base::Closure on_decode_finished_cb); | |
45 | |
46 void OnChunkDecoded( | |
47 JNIEnv* env, | |
48 const base::android::JavaParamRef<jobject>& /*java object*/, | |
49 const base::android::JavaParamRef<jobject>& buf, | |
50 jint buf_size, | |
51 jint input_channel_count, | |
52 jint output_channel_count); | |
53 | |
54 void InitializeDestination( | |
55 JNIEnv* env, | |
56 const base::android::JavaParamRef<jobject>& /*java object*/, | |
57 jint channel_count, | |
58 jint sample_rate, | |
59 jlong duration_us); | |
60 | |
61 private: | |
62 // Handles MediaCodec processing of the encoded data in | |
63 // |encoded_audio_handle_| and sends the pcm data to |pcm_output_|. | |
64 // Returns true if decoding was successful. | |
65 bool DecodeInMemoryAudioFile(); | |
66 | |
67 // Save encoded audio data to a temporary file and return the file | |
68 // descriptor to that file. -1 is returned if the audio data could | |
69 // not be saved for any reason. | |
70 int SaveEncodedAudioToFile(JNIEnv*, jobject); | |
71 | |
72 // The encoded audio data is read from this file descriptor for the | |
73 // shared memory that holds the encoded data. | |
74 base::SharedMemoryHandle encoded_audio_handle_; | |
75 | |
76 // The audio file information and decoded pcm data are written to | |
77 // this file descriptor. We take ownership of this descriptor. | |
78 int pcm_output_; | |
79 | |
80 // The length of the encoded data. | |
81 uint32_t data_size_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(WebAudioMediaCodecBridge); | |
84 }; | |
85 | |
86 } // namespace media | |
87 #endif // MEDIA_BASE_ANDROID_WEBAUDIO_MEDIA_CODEC_BRIDGE_H_ | |
OLD | NEW |