Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android: Migrate from ndk-glue to ndk-context #641

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ hound = "3.4"
ringbuf = "0.2"
clap = { version = "3", default-features = false, features = ["std"] }

[target.'cfg(target_os = "android")'.dev-dependencies]
ndk-glue = "0.6"
est31 marked this conversation as resolved.
Show resolved Hide resolved

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "profileapi", "std", "synchapi", "winbase", "winuser"] }
asio-sys = { version = "0.2", path = "asio-sys", optional = true }
Expand Down Expand Up @@ -55,7 +58,7 @@ web-sys = { version = "0.3.35", features = [ "AudioContext", "AudioContextOption
[target.'cfg(target_os = "android")'.dependencies]
oboe = { version = "0.4", features = [ "java-interface" ] }
ndk = "0.6"
ndk-glue = "0.6"
ndk-context = "0.1"
jni = "0.19"

[[example]]
Expand Down
14 changes: 6 additions & 8 deletions src/host/oboe/android_media.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::sync::Arc;

extern crate jni;
extern crate ndk_glue;

use self::jni::Executor;
use self::jni::{errors::Result as JResult, objects::JObject, JNIEnv, JavaVM};
use self::jni::{errors::Result as JResult, JNIEnv, JavaVM};

// constants from android.media.AudioFormat
pub const ENCODING_PCM_16BIT: i32 = 2;
Expand All @@ -14,12 +13,11 @@ pub const CHANNEL_OUT_STEREO: i32 = 12;

fn with_attached<F, R>(closure: F) -> JResult<R>
where
F: FnOnce(&JNIEnv, JObject) -> JResult<R>,
F: FnOnce(&JNIEnv) -> JResult<R>,
{
let activity = ndk_glue::native_activity();
let vm = Arc::new(unsafe { JavaVM::from_raw(activity.vm())? });
let activity = activity.activity();
Executor::new(vm).with_attached(|env| closure(env, activity.into()))
let android_context = ndk_context::android_context();
let vm = Arc::new(unsafe { JavaVM::from_raw(android_context.vm().cast())? });
Executor::new(vm).with_attached(|env| closure(env))
}

fn get_min_buffer_size(
Expand All @@ -31,7 +29,7 @@ fn get_min_buffer_size(
// Unwrapping everything because these operations are not expected to fail
// or throw exceptions. Android returns negative values for invalid parameters,
// which is what we expect.
with_attached(|env, _activity| {
with_attached(|env| {
let class = env.find_class(class).unwrap();
env.call_static_method(
class,
Expand Down