aom-sys-0.3.3/.cargo_vcs_info.json0000644000000001450000000000100124270ustar { "git": { "sha1": "4e7ae645bdf49bfb52a544b081a846f918abd1d2" }, "path_in_vcs": "aom-sys" }aom-sys-0.3.3/.gitignore000064400000000000000000000000321046102023000132020ustar 00000000000000src/aom.rs data/aom_build aom-sys-0.3.3/Cargo.toml0000644000000016160000000000100104310ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "aom-sys" version = "0.3.3" authors = ["Luca Barbato "] build = "build.rs" description = "FFI bindings to aom" readme = "README.md" license = "MIT" repository = "https://github.com/rust-av/aom-rs" [package.metadata.system-deps] aom = "3.0.0" [dependencies] [build-dependencies.bindgen] version = "0.69.1" [build-dependencies.system-deps] version = "6.0" [features] build_sources = [] aom-sys-0.3.3/Cargo.toml.orig000064400000000000000000000006301046102023000141050ustar 00000000000000[package] name = "aom-sys" version = "0.3.3" authors = ["Luca Barbato "] license = "MIT" description = "FFI bindings to aom" repository = "https://github.com/rust-av/aom-rs" edition = "2021" build = "build.rs" readme = "../README.md" [package.metadata.system-deps] aom = "3.0.0" [features] build_sources = [] [build-dependencies] bindgen = "0.69.1" system-deps = "6.0" [dependencies] aom-sys-0.3.3/LICENSE000064400000000000000000000020551046102023000122260ustar 00000000000000MIT License Copyright (c) 2018 Luca Barbato Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. aom-sys-0.3.3/README.md000064400000000000000000000025661046102023000125070ustar 00000000000000# libaom bindings [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Actions Status](https://github.com/rust-av/aom-rs/workflows/aom/badge.svg)](https://github.com/rust-av/aom-rs/actions) It is a simple [binding][1] and safe abstraction over [libaom][2]. ## Building To build the code, always have a look at [CI](https://github.com/rust-av/aom-rs/blob/master/.github/workflows/aom.yml) to install the necessary dependencies on all supported operating systems. ## Building with vcpkg for Windows x64 To build with [vcpkg](https://vcpkg.io/en/index.html), you need to follow these steps: 1. Install `pkg-config` through [chocolatey](https://chocolatey.org/) choco install pkgconfiglite 2. Install `aom` vcpkg install aom:x64-windows 3. Add to the `PKG_CONFIG_PATH` environment variable the path `$VCPKG_INSTALLATION_ROOT\installed\x64-windows\lib\pkgconfig` 4. Build code cargo build --workspace To speed up the computation, you can build your packages only in `Release` mode adding the `set(VCPKG_BUILD_TYPE release)` line to the `$VCPKG_INSTALLATION_ROOT\triplets\x64-windows.cmake` file. Building for Windows x86 is the same, just replace `x64` with `x86` in the steps above. ## TODO - [x] Simple bindings - [ ] Safe abstraction - [ ] Examples [1]: https://github.com/rust-lang/rust-bindgen [2]: https://aomedia.googlesource.com/aom aom-sys-0.3.3/build.rs000064400000000000000000000017261046102023000126720ustar 00000000000000use std::env; use std::fs::File; use std::io::Write; use std::path::PathBuf; fn format_write(builder: bindgen::Builder) -> String { builder .generate() .unwrap() .to_string() .replace("/**", "/*") .replace("/*!", "/*") } fn main() { let libs = system_deps::Config::new().probe().unwrap(); let headers = libs.all_include_paths(); let mut builder = bindgen::builder() .header("data/aom.h") .blocklist_type("max_align_t") .size_t_is_usize(true) .default_enum_style(bindgen::EnumVariation::ModuleConsts); for header in headers { builder = builder.clang_arg("-I").clang_arg(header.to_str().unwrap()); } // Manually fix the comment so rustdoc won't try to pick them let s = format_write(builder); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let mut file = File::create(out_path.join("aom.rs")).unwrap(); let _ = file.write(s.as_bytes()); } aom-sys-0.3.3/data/aom.h000064400000000000000000000001501046102023000130510ustar 00000000000000#include #include #include #include aom-sys-0.3.3/src/lib.rs000064400000000000000000000056501046102023000131300ustar 00000000000000#![allow(dead_code)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] pub mod aom { include!(concat!(env!("OUT_DIR"), "/aom.rs")); } pub use aom::*; #[cfg(test)] mod tests { use super::aom::*; use std::ffi::CStr; use std::mem; #[test] fn version() { println!("{}", unsafe { CStr::from_ptr(aom_codec_version_str()).to_string_lossy() }); println!("{}", unsafe { CStr::from_ptr(aom_codec_build_config()).to_string_lossy() }); } #[test] fn encode() { let w = 360; let h = 360; let align = 32; let kf_interval = 10; let mut raw = mem::MaybeUninit::uninit(); let mut ctx = mem::MaybeUninit::uninit(); let ret = unsafe { aom_img_alloc(raw.as_mut_ptr(), aom_img_fmt::AOM_IMG_FMT_I420, w, h, align) }; if ret.is_null() { panic!("Image allocation failed"); } #[allow(clippy::forget_copy)] mem::forget(ret); // raw and ret are the same (ret does not implement Drop trait) let raw = unsafe { raw.assume_init() }; print!("{:#?}", raw); let mut cfg = mem::MaybeUninit::uninit(); let mut ret = unsafe { aom_codec_enc_config_default(aom_codec_av1_cx(), cfg.as_mut_ptr(), 0) }; if ret != aom_codec_err_t::AOM_CODEC_OK { panic!("Default Configuration failed"); } let mut cfg = unsafe { cfg.assume_init() }; cfg.g_w = w; cfg.g_h = h; cfg.g_timebase.num = 1; cfg.g_timebase.den = 30; cfg.rc_target_bitrate = 100 * 1014; ret = unsafe { aom_codec_enc_init_ver( ctx.as_mut_ptr(), aom_codec_av1_cx(), &cfg, 0, AOM_ENCODER_ABI_VERSION as i32, ) }; if ret != aom_codec_err_t::AOM_CODEC_OK { panic!("Codec Init failed"); } let mut ctx = unsafe { ctx.assume_init() }; let mut out = 0; for i in 0..100 { let mut flags = 0; if i % kf_interval == 0 { flags |= AOM_EFLAG_FORCE_KF; } unsafe { let ret = aom_codec_encode(&mut ctx, &raw, i, 1, flags as aom_enc_frame_flags_t); if ret != aom_codec_err_t::AOM_CODEC_OK { panic!("Encode failed {:?}", ret); } let mut iter = mem::zeroed(); loop { let pkt = aom_codec_get_cx_data(&mut ctx, &mut iter); if pkt.is_null() { break; } else { println!("{:#?}", (*pkt).kind); out = 1; } } } } if out != 1 { panic!("No packet produced"); } } }