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.
5 #ifndef MEDIA_BASE_ANDROID_WEBAUDIO_MEDIA_CODEC_BRIDGE_H_
6 #define MEDIA_BASE_ANDROID_WEBAUDIO_MEDIA_CODEC_BRIDGE_H_
10 #include "base/file_descriptor_posix.h"
11 #include "base/memory/shared_memory.h"
12 #include "media/base/media_export.h"
16 // This class serves as a bridge for native code to call Java
17 // functions in the Android MediaCodec class. See
18 // http://developer.android.com/reference/android/media/MediaCodec.html.
19 class MEDIA_EXPORT WebAudioMediaCodecBridge
{
21 // Create the bridge with the given file descriptors. We read from
22 // |encoded_audio_handle| to get the encoded audio data. Audio file
23 // information and decoded PCM samples are written to |pcm_output|.
24 // We also take ownership of |pcm_output|.
25 WebAudioMediaCodecBridge(base::SharedMemoryHandle encoded_audio_handle
,
26 base::FileDescriptor pcm_output
,
28 ~WebAudioMediaCodecBridge();
30 // Inform JNI about this bridge. Returns true if registration
32 static bool RegisterWebAudioMediaCodecBridge(JNIEnv
* env
);
34 // Start MediaCodec to process the encoded data in
35 // |encoded_audio_handle|. The PCM samples are sent to |pcm_output|.
36 static void RunWebAudioMediaCodec(
37 base::SharedMemoryHandle encoded_audio_handle
,
38 base::FileDescriptor pcm_output
,
41 void OnChunkDecoded(JNIEnv
* env
,
42 jobject
/*java object*/,
45 jint input_channel_count
,
46 jint output_channel_count
);
48 void InitializeDestination(JNIEnv
* env
,
49 jobject
/*java object*/,
55 // Handles MediaCodec processing of the encoded data in
56 // |encoded_audio_handle_| and sends the pcm data to |pcm_output_|.
57 // Returns true if decoding was successful.
58 bool DecodeInMemoryAudioFile();
60 // Save encoded audio data to a temporary file and return the file
61 // descriptor to that file. -1 is returned if the audio data could
62 // not be saved for any reason.
63 int SaveEncodedAudioToFile(JNIEnv
*, jobject
);
65 // The encoded audio data is read from this file descriptor for the
66 // shared memory that holds the encoded data.
67 base::SharedMemoryHandle encoded_audio_handle_
;
69 // The audio file information and decoded pcm data are written to
70 // this file descriptor. We take ownership of this descriptor.
73 // The length of the encoded data.
76 DISALLOW_COPY_AND_ASSIGN(WebAudioMediaCodecBridge
);
80 #endif // MEDIA_BASE_ANDROID_WEBAUDIO_MEDIA_CODEC_BRIDGE_H_