-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathaudio_manager.rs
More file actions
53 lines (42 loc) · 1.88 KB
/
audio_manager.rs
File metadata and controls
53 lines (42 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use super::{
utils::{
get_context, get_property, get_system_property, get_system_service, with_attached, JNIEnv,
JObject, JResult,
},
AudioManager, Context,
};
impl AudioManager {
/// Get the frames per buffer using Android Java API
pub fn get_frames_per_buffer() -> Result<i32, String> {
let context = get_context();
with_attached(context, |env, context| get_frames_per_buffer(env, &context))
.map_err(|error| error.to_string())
}
/// Get the AAudio mixer burst count from system property
pub fn get_mixer_bursts() -> Result<i32, String> {
let context = get_context();
with_attached(context, |env, _context| get_mixer_bursts(env))
.map_err(|error| error.to_string())
}
}
fn get_frames_per_buffer<'j>(env: &mut JNIEnv<'j>, context: &JObject<'j>) -> JResult<i32> {
let audio_manager = get_system_service(env, context, Context::AUDIO_SERVICE)?;
let frames_per_buffer = get_property(
env,
&audio_manager,
AudioManager::PROPERTY_OUTPUT_FRAMES_PER_BUFFER,
)?;
let frames_per_buffer_string = String::from(env.get_string(&frames_per_buffer)?);
// TODO: Use jni::errors::Error::ParseFailed instead of jni::errors::Error::JniCall once jni > v0.21.1 is released
frames_per_buffer_string
.parse::<i32>()
.map_err(|_| jni::errors::Error::JniCall(jni::errors::JniError::Unknown))
}
fn get_mixer_bursts<'j>(env: &mut JNIEnv<'j>) -> JResult<i32> {
let mixer_bursts = get_system_property(env, "aaudio.mixer_bursts", "2")?;
let mixer_bursts_string = String::from(env.get_string(&mixer_bursts)?);
// TODO: Use jni::errors::Error::ParseFailed instead of jni::errors::Error::JniCall once jni > v0.21.1 is released
mixer_bursts_string
.parse::<i32>()
.map_err(|_| jni::errors::Error::JniCall(jni::errors::JniError::Unknown))
}