• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 // Android APIs used to access Java functionality needed to enable low latency
12 // audio.
13 
14 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_JNI_H_
15 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_JNI_H_
16 
17 #include <jni.h>
18 
19 namespace webrtc {
20 
21 class AudioManagerJni {
22  public:
23   AudioManagerJni();
~AudioManagerJni()24   ~AudioManagerJni() {}
25 
26   // SetAndroidAudioDeviceObjects must only be called once unless there has
27   // been a successive call to ClearAndroidAudioDeviceObjects. For each
28   // call to ClearAndroidAudioDeviceObjects, SetAndroidAudioDeviceObjects may be
29   // called once.
30   // This function must be called by a Java thread as calling it from a thread
31   // created by the native application will prevent FindClass from working. See
32   // http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
33   // for more details.
34   // It has to be called for this class' APIs to be successful. Calling
35   // ClearAndroidAudioDeviceObjects will prevent this class' APIs to be called
36   // successfully if SetAndroidAudioDeviceObjects is not called after it.
37   static void SetAndroidAudioDeviceObjects(void* jvm, void* env,
38                                            void* context);
39   // This function must be called when the AudioManagerJni class is no
40   // longer needed. It frees up the global references acquired in
41   // SetAndroidAudioDeviceObjects.
42   static void ClearAndroidAudioDeviceObjects();
43 
low_latency_supported()44   bool low_latency_supported() const { return low_latency_supported_; }
native_output_sample_rate()45   int native_output_sample_rate() const { return native_output_sample_rate_; }
native_buffer_size()46   int native_buffer_size() const { return native_buffer_size_; }
47 
48  private:
49   bool HasDeviceObjects();
50 
51   // Following functions assume that the calling thread has been attached.
52   void SetLowLatencySupported(JNIEnv* env);
53   void SetNativeOutputSampleRate(JNIEnv* env);
54   void SetNativeFrameSize(JNIEnv* env);
55 
56   jmethodID LookUpMethodId(JNIEnv* env, const char* method_name,
57                            const char* method_signature);
58 
59   void CreateInstance(JNIEnv* env);
60 
61   // Whether or not low latency audio is supported, the native output sample
62   // rate and the audio buffer size do not change. I.e the values might as well
63   // just be cached when initializing.
64   bool low_latency_supported_;
65   int native_output_sample_rate_;
66   int native_buffer_size_;
67 };
68 
69 }  // namespace webrtc
70 
71 #endif  // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_MANAGER_JNI_H_
72