Skip to content

Commit

Permalink
Support Android build
Browse files Browse the repository at this point in the history
  • Loading branch information
rosetta-jpn authored Oct 30, 2024
1 parent fda656e commit d9de934
Show file tree
Hide file tree
Showing 31 changed files with 234 additions and 80 deletions.
10 changes: 10 additions & 0 deletions Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

license {
name: "external_rust_crates_cros-libva_license",
visibility: [":__subpackages__"],
license_kinds: ["SPDX-license-identifier-BSD-3-Clause"],
license_text: ["LICENSE"],
}
24 changes: 5 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
[package]
name = "cros-libva"
version = "0.0.8"
license = "BSD-3-Clause"
description = "Safe bindings over libva"
repository = "https://github.com/chromeos/cros-libva"
authors = ["The Chromium OS Authors"]
edition = "2021"
[workspace]
resolver = "2"
members = ["lib"]

[dependencies]
thiserror = "1"
bitflags = "2.5"
log = { version = "0", features = ["release_max_level_debug"] }

[build-dependencies]
bindgen = "0.70.1"
pkg-config = "0.3.26"

[dev-dependencies]
crc32fast = "1.2.1"
[workspace.package]
readme = "README.md"
40 changes: 40 additions & 0 deletions android/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package {
default_applicable_licenses: ["external_rust_crates_cros-libva_license"],
}

rust_binary_host {
name: "cros_libva_bindgen_build",
srcs: ["build.rs"],
rustlibs: [
"libbindgen",
"libbindgen_cmd",
],
lints: "android",
clippy_lints: "android",

vendor: true,
}

rust_bindgen {
name: "libcros_libva_bindgen",
crate_name: "cros_libva_bindgen",
custom_bindgen: "cros_libva_bindgen_build",
wrapper_src: "android_wrapper.h",
source_stem: "bindings",
cflags: ["-I external/rust/crates/cros-libva/lib"],
visibility: ["//external/rust/crates/cros-libva/lib"],

vendor: true,
enabled: false,
arch: {
x86_64: {
enabled: true,
// Libva headers that bindings source is generated from.
header_libs: ["libva_headers"],
},
},
}
6 changes: 6 additions & 0 deletions android/android_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is lib/vaapi-wrapper.h.
#include "libva-wrapper.h"
12 changes: 12 additions & 0 deletions android/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! cros-libva bindings generator in Android.
#[path = "../lib/bindgen_gen.rs"]
mod bindgen_gen;

fn main() {
bindgen_cmd::build(bindgen_gen::vaapi_gen_builder);
}
6 changes: 6 additions & 0 deletions android/srcs.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Bindgen-generated bindings of our local libva headers.
srcs: [":libcros_libva_bindgen"]
10 changes: 10 additions & 0 deletions cargo_embargo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"package": {
"cros_libva": {
"host_supported": false,
"add_module_block": "android/srcs.bp"
}
},
"run_cargo": false,
"tests": true
}
69 changes: 69 additions & 0 deletions lib/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file is generated by cargo_embargo.
// Do not modify this file because the changes will be overridden on upgrade.

package {
default_applicable_licenses: ["external_rust_crates_cros-libva_license"],
}

rust_test {
name: "cros-libva_test_src_lib",
crate_name: "cros_libva",
cargo_env_compat: true,
cargo_pkg_version: "0.0.8",
crate_root: "src/lib.rs",
test_suites: ["general-tests"],
auto_gen_config: true,
test_options: {
unit_test: true,
},
edition: "2021",
rustlibs: [
"libbitflags",
"libcrc32fast",
"liblog_rust",
"libthiserror",
],

vendor: true,
enabled: false,
arch: {
x86_64: {
enabled: true,
// Bindgen-generated bindings of our local libva headers.
srcs: [":libcros_libva_bindgen"],
},
},
}

rust_library {
name: "libcros_libva",
crate_name: "cros_libva",
cargo_env_compat: true,
cargo_pkg_version: "0.0.8",
crate_root: "src/lib.rs",
edition: "2021",
rustlibs: [
"libbitflags",
"liblog_rust",
"libthiserror",
],
apex_available: [
"//apex_available:platform",
"//apex_available:anyapex",
],

vendor: true,
enabled: false,
arch: {
x86_64: {
enabled: true,
// Bindgen-generated bindings of our local libva headers.
srcs: [":libcros_libva_bindgen"],
shared_libs: [ "libva" ],
},
},
}
20 changes: 20 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "cros-libva"
version = "0.0.8"
license = "BSD-3-Clause"
description = "Safe bindings over libva"
repository = "https://github.com/chromeos/cros-libva"
authors = ["The Chromium OS Authors"]
edition = "2021"

[dependencies]
thiserror = "1"
bitflags = "2.5"
log = { version = "0", features = ["release_max_level_debug"] }

[build-dependencies]
bindgen = "0.70.1"
pkg-config = "0.3.26"

[dev-dependencies]
crc32fast = "1.2.1"
18 changes: 18 additions & 0 deletions lib/bindgen_gen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// The allow list of VA functions, structures and enum values.
const ALLOW_LIST_TYPE : &str = ".*ExternalBuffers.*|.*PRIME.*|.*MPEG2.*|.*VP8.*|.*VP9.*|.*H264.*|.*HEVC.*|VACodedBufferSegment|.*AV1.*|VAEncMisc.*|VASurfaceDecodeMBErrors|VADecodeErrorType";

// The common bindgen builder for VA-API.
pub fn vaapi_gen_builder(builder: bindgen::Builder) -> bindgen::Builder {
builder
.derive_default(true)
.derive_eq(true)
.layout_tests(false)
.constified_enum_module("VA.*")
.allowlist_var("VA.*")
.allowlist_function("va.*")
.allowlist_type(ALLOW_LIST_TYPE)
}
29 changes: 4 additions & 25 deletions build.rs → lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use std::env::{self};
use std::path::{Path, PathBuf};

mod bindgen_gen;
use bindgen_gen::vaapi_gen_builder;

/// Environment variable that can be set to point to the directory containing the `va.h`, `va_drm.h` and `va_drmcommon.h`
/// files to use to generate the bindings.
const CROS_LIBVA_H_PATH_ENV: &str = "CROS_LIBVA_H_PATH";
Expand All @@ -13,9 +16,6 @@ const CROS_LIBVA_LIB_PATH_ENV: &str = "CROS_LIBVA_LIB_PATH";
/// Wrapper file to use as input of bindgen.
const WRAPPER_PATH: &str = "libva-wrapper.h";

/// Allow list
const ALLOW_LIST_TYPE : &str = ".*ExternalBuffers.*|.*PRIME.*|.*MPEG2.*|.*VP8.*|.*VP9.*|.*H264.*|.*HEVC.*|VACodedBufferSegment|.*AV1.*|VAEncMisc.*|VASurfaceDecodeMBErrors|VADecodeErrorType";

fn main() {
// Do not require dependencies when generating docs.
if std::env::var("CARGO_DOC").is_ok() || std::env::var("DOCS_RS").is_ok() {
Expand Down Expand Up @@ -46,15 +46,7 @@ fn main() {
println!("cargo:rustc-link-lib=dylib=va");
println!("cargo:rustc-link-lib=dylib=va-drm"); // for the vaGetDisplayDRM entrypoint

let mut bindings_builder = bindgen::builder()
.header(WRAPPER_PATH)
.raw_line("pub mod constants;")
.derive_default(true)
.derive_eq(true)
.layout_tests(false)
.constified_enum_module("VA.*")
.allowlist_function("va.*")
.allowlist_type(ALLOW_LIST_TYPE);
let mut bindings_builder = vaapi_gen_builder(bindgen::builder()).header(WRAPPER_PATH);
if !va_h_path.is_empty() {
bindings_builder = bindings_builder.clang_arg(format!("-I{}", va_h_path));
}
Expand All @@ -67,17 +59,4 @@ fn main() {
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");

let mut bindings_builder = bindgen::builder()
.header(WRAPPER_PATH)
.allowlist_var("VA.*");
if !va_h_path.is_empty() {
bindings_builder = bindings_builder.clang_arg(format!("-I{}", va_h_path));
}
let bindings = bindings_builder
.generate()
.expect("unable to generate bindings");
bindings
.write_to_file(out_path.join("constants.rs"))
.expect("Couldn't write bindings!");
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/buffer/vp8.rs → lib/src/buffer/vp8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl PictureParameterBufferVP8 {
last_ref_frame,
golden_ref_frame,
alt_ref_frame,
out_of_loop_frame: bindings::constants::VA_INVALID_SURFACE,
out_of_loop_frame: bindings::VA_INVALID_SURFACE,
pic_fields,
mb_segment_tree_probs,
loop_filter_level,
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/context.rs → lib/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Context {
) -> Result<Rc<Self>, VaError> {
let mut context_id = 0;
let flags = if progressive {
bindings::constants::VA_PROGRESSIVE as i32
bindings::VA_PROGRESSIVE as i32
} else {
0
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d9de934

Please sign in to comment.