From cdf3491e0f7432e153330bb933f9d43f15c06779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Tue, 31 Jul 2018 11:20:35 +0200 Subject: [PATCH] Fix android example --- .gitignore | 3 +- Cargo.lock | 79 +++++++++++++++++++++++++++++++++ Cargo.toml | 1 + examples/android/lib/Cargo.toml | 2 +- examples/android/lib/src/lib.rs | 31 +++++++------ examples/android/run.sh | 12 +++-- 6 files changed, 109 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 53eaa219..6aac4b29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -/target +**/target **/*.rs.bk +**/wget-log diff --git a/Cargo.lock b/Cargo.lock index b05d1012..63b17e13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,11 @@ dependencies = [ "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ascii" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.0.3" @@ -34,6 +39,11 @@ name = "byte-slice-cast" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "byteorder" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bzip2" version = "0.3.3" @@ -57,6 +67,11 @@ name = "cc" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cfg-if" version = "0.1.4" @@ -70,6 +85,15 @@ dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "combine" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ascii 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crc" version = "1.8.1" @@ -78,6 +102,11 @@ dependencies = [ "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "error-chain" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "examples" version = "0.1.0" @@ -321,6 +350,23 @@ dependencies = [ "pkg-config 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "jni" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "combine 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jni-sys 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "jni-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "1.0.2" @@ -331,6 +377,22 @@ name = "libc" version = "0.2.42" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "log" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "log" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "memchr" version = "2.0.1" @@ -531,6 +593,14 @@ dependencies = [ name = "servo-media-player" version = "0.1.0" +[[package]] +name = "servo_media_android" +version = "0.1.0" +dependencies = [ + "jni 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "servo-media 0.1.0", +] + [[package]] name = "servo_media_derive" version = "0.1.0" @@ -639,15 +709,20 @@ dependencies = [ "checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum aho-corasick 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c6d463cbe7ed28720b5b489e7c083eeb8f90d08be2a0d6bb9e1ffea9ce1afa" "checksum array-init 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c3cc8456d0ae81a8c76f59e384683a601548c38949a4bfcb65dd31ded5c75ff3" +"checksum ascii 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae7d751998c189c1d4468cf0a39bb2eae052a9c58d50ebb3b9591ee3813ad50" "checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" "checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" "checksum byte-slice-cast 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5a865e7bfa6c3b79216ccba767d4dc66e4f9f65f1ed4639e73faff3c4a2485d7" +"checksum byteorder 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8389c509ec62b9fe8eca58c502a0acaf017737355615243496cde4994f8fa4f9" "checksum bzip2 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b" "checksum bzip2-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2c5162604199bbb17690ede847eaa6120a3f33d5ab4dcc8e7c25b16d849ae79b" "checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275" +"checksum cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" "checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum combine 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1645a65a99c7c8d345761f4b75a6ffe5be3b3b27a93ee731fccc5050ba6be97c" "checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" "checksum flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fac2277e84e5e858483756647a9d0aa8d9a2b7cba517fd84325a0aaa69a0909" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" @@ -667,8 +742,12 @@ dependencies = [ "checksum gstreamer-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b2f51e25a6f97dd4bfd640cba96f192f8759b8766afd66d6d9ea0f82ca14a37" "checksum gstreamer-video 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75300cf1ed8d8d65811349fc755fac22be05ea55df551ab29e43664d4a575c92" "checksum gstreamer-video-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ed798787e78a0f1c8be06bd3adcab03f962f049a820743aae9f690f56a0d538" +"checksum jni 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cffc930ce6a38a4013e30567b559bdc79f601013ba4a81e65dbda9207263efd4" +"checksum jni-sys 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "de0aaaba8809ab8d83a53fe2b313b996b79e8632b855eae9f70ad4323dca91b8" "checksum lazy_static 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fb497c35d362b6a331cfd94956a07fc2c78a4604cdbee844a81170386b996dd3" "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" +"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum miniz_oxide 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9ba430291c9d6cedae28bcd2d49d1c32fc57d60cd49086646c5dd5673a870eb5" "checksum miniz_oxide_c_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5a5b8234d6103ebfba71e29786da4608540f862de5ce980a1c94f86a40ca0d51" diff --git a/Cargo.toml b/Cargo.toml index 7069f21d..ad4c9b37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "audio", "backends/gstreamer", "examples", + "examples/android/lib", "player", "servo-media", "servo-media-derive" diff --git a/examples/android/lib/Cargo.toml b/examples/android/lib/Cargo.toml index fe4591cc..034ac019 100644 --- a/examples/android/lib/Cargo.toml +++ b/examples/android/lib/Cargo.toml @@ -8,7 +8,7 @@ authors = ["Fernando Jiménez Moreno "] crate-type = ["cdylib"] [dependencies] -servo_media = { path = "../../.." } +servo-media = { path = "../../../servo-media" } [target.'cfg(target_os="android")'.dependencies] jni = { version = "0.5", default-features = false } diff --git a/examples/android/lib/src/lib.rs b/examples/android/lib/src/lib.rs index 7dd17de3..cbfac2b6 100644 --- a/examples/android/lib/src/lib.rs +++ b/examples/android/lib/src/lib.rs @@ -1,35 +1,38 @@ extern crate servo_media; use servo_media::audio::gain_node::GainNodeOptions; -use servo_media::audio::graph::AudioGraph; +use servo_media::audio::context::AudioContext; use servo_media::audio::node::{AudioNodeInit, AudioNodeMessage}; -use servo_media::audio::oscillator_node::OscillatorNodeMessage; -use servo_media::ServoMedia; +use servo_media::audio::node::AudioScheduledSourceNodeMessage; +use servo_media::{Backend, ServoMedia}; struct AudioStream { - graph: AudioGraph, + context: AudioContext, } impl AudioStream { pub fn new() -> Self { - let graph = ServoMedia::get().unwrap().create_audio_graph(); - graph.create_node(AudioNodeInit::OscillatorNode(Default::default())); - graph.message_node( - 0, - AudioNodeMessage::OscillatorNode(OscillatorNodeMessage::Start(0.)), - ); + let context = ServoMedia::get().unwrap().create_audio_context(Default::default()); + let osc = context.create_node(AudioNodeInit::OscillatorNode(Default::default())); let mut options = GainNodeOptions::default(); options.gain = 0.5; - graph.create_node(AudioNodeInit::GainNode(options)); - Self { graph } + let gain = context.create_node(AudioNodeInit::GainNode(options)); + let dest = context.dest_node(); + context.connect_ports(osc.output(0), gain.input(0)); + context.connect_ports(gain.output(0), dest.input(0)); + context.message_node( + osc, + AudioNodeMessage::AudioScheduledSourceNode(AudioScheduledSourceNodeMessage::Start(0.)), + ); + Self { context } } pub fn play(&mut self) { - self.graph.resume() + let _ = self.context.resume(); } pub fn stop(&mut self) { - self.graph.suspend() + let _ = self.context.suspend(); } } diff --git a/examples/android/run.sh b/examples/android/run.sh index e4aaa6ae..965ef72f 100755 --- a/examples/android/run.sh +++ b/examples/android/run.sh @@ -1,17 +1,23 @@ ROOT=${PWD} PKG_CONFIG_PATH_OLD=$PKG_CONFIG_PATH cd ../../ -export PKG_CONFIG_PATH=${PWD}/target/gst-build-armeabi/pkgconfig +export PKG_CONFIG_PATH=${PWD}/backends/gstreamer/target/gst-build-armeabi/pkgconfig +echo "Set PKG_CONFIG_PATH to ${PKG_CONFIG_PATH}" +cd servo-media +echo "Building servo-media ${PWD}" +PKG_CONFIG_ALLOW_CROSS=1 cargo build --target=arm-linux-androideabi || return 1 cd ${ROOT}/lib +echo "Building servo-media-android ${PWD}" PKG_CONFIG_ALLOW_CROSS=1 cargo build || return 1 +echo "Set PKG_CONFIG_PATH to previous state ${PKG_CONFIG_PATH_OLD}" export PKG_CONFIG_PATH=$PKG_CONFIG_PATH_OLD cd ../src/app/src/main/ rm -rf jniLibs mkdir -p jniLibs/armeabi -ln -s ${ROOT}/lib/target/arm-linux-androideabi/debug/libservo_media_android.so jniLibs/armeabi/libservo_media_android.so -ln -s ${ROOT}/../../target/gst-build-armeabi/libgstreamer_android.so jniLibs/armeabi/libgstreamer_android.so +ln -s ${ROOT}/../../target/arm-linux-androideabi/debug/libservo_media_android.so jniLibs/armeabi/libservo_media_android.so +ln -s ${ROOT}/../../backends/gstreamer/target/gst-build-armeabi/libgstreamer_android.so jniLibs/armeabi/libgstreamer_android.so cd ${ROOT}/src ./gradlew installDebug || return 1