Skip to content

Commit

Permalink
Don't enable libloading by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfbiedert committed Jan 6, 2024
1 parent 9ef2f55 commit 155b035
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion openh264-sys2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "BSD-2-Clause"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = [ "source", "libloading" ] # TODO: Remove libloading from default
default = [ "source" ]
source = []
libloading = [ "dep:libloading" ]

Expand Down
6 changes: 5 additions & 1 deletion openh264-sys2/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::fmt::{Display, Formatter};
use std::fmt::{Debug, Display, Formatter};

#[derive(Debug)]
pub enum Error {
#[cfg(feature = "libloading")]
LibLoading(libloading::Error),
}

#[cfg(feature = "libloading")]
impl From<::libloading::Error> for Error {
fn from(value: libloading::Error) -> Self {
Self::LibLoading(value)
Expand All @@ -14,7 +16,9 @@ impl From<::libloading::Error> for Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
#[cfg(feature = "libloading")]
Error::LibLoading(x) => x.fmt(f),
_ => ().fmt(f),
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions openh264-sys2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ mod error;
/// Generated bindings for OpenH264.
mod generated {
pub mod consts;
#[cfg(feature = "libloading")]
pub mod fns_libloading;
#[cfg(feature = "source")]
pub mod fns_source;
pub mod types;
}
Expand Down Expand Up @@ -65,6 +67,7 @@ pub trait API {
/// - **Q: Is Cisco guaranteeing that it will pay other licensing fees for H.264, should additional patent holders assert claims in the future?**
///
/// A: Cisco is providing no such guarantee. We are only covering the royalties that would apply to the binary module under MPEG LA's AVC/H.264 patent pool.
#[cfg(feature = "libloading")]
pub mod libloading {
pub use crate::generated::fns_libloading::*;
use crate::{ISVCDecoder, ISVCEncoder, OpenH264Version, SDecoderCapability};
Expand All @@ -86,6 +89,7 @@ pub mod libloading {
///
/// This API surface should _just work_ once compiled. Depending on your commercial, legal and geographic situation, and the H.264 features you use,
/// this might or might not come with an elevated patent risk.
#[cfg(feature = "source")]
pub mod source {
use crate::{ISVCDecoder, ISVCEncoder, OpenH264Version, SDecoderCapability};
use std::os::raw::{c_int, c_long};
Expand Down Expand Up @@ -160,49 +164,63 @@ impl DynamicAPI {
impl API for DynamicAPI {
unsafe fn WelsCreateSVCEncoder(&self, ppEncoder: *mut *mut ISVCEncoder) -> c_int {
match self {
#[cfg(feature = "source")]
DynamicAPI::Source(api) => api.WelsCreateSVCEncoder(ppEncoder),
#[cfg(feature = "libloading")]
DynamicAPI::Libloading(api) => api.WelsCreateSVCEncoder(ppEncoder),
}
}

unsafe fn WelsDestroySVCEncoder(&self, pEncoder: *mut ISVCEncoder) {
match self {
#[cfg(feature = "source")]
DynamicAPI::Source(api) => api.WelsDestroySVCEncoder(pEncoder),
#[cfg(feature = "libloading")]
DynamicAPI::Libloading(api) => api.WelsDestroySVCEncoder(pEncoder),
}
}

unsafe fn WelsGetDecoderCapability(&self, pDecCapability: *mut SDecoderCapability) -> c_int {
match self {
#[cfg(feature = "source")]
DynamicAPI::Source(api) => api.WelsGetDecoderCapability(pDecCapability),
#[cfg(feature = "libloading")]
DynamicAPI::Libloading(api) => api.WelsGetDecoderCapability(pDecCapability),
}
}

unsafe fn WelsCreateDecoder(&self, ppDecoder: *mut *mut ISVCDecoder) -> c_long {
match self {
#[cfg(feature = "source")]
DynamicAPI::Source(api) => api.WelsCreateDecoder(ppDecoder),
#[cfg(feature = "libloading")]
DynamicAPI::Libloading(api) => api.WelsCreateDecoder(ppDecoder),
}
}

unsafe fn WelsDestroyDecoder(&self, pDecoder: *mut ISVCDecoder) {
match self {
#[cfg(feature = "source")]
DynamicAPI::Source(api) => api.WelsDestroyDecoder(pDecoder),
#[cfg(feature = "libloading")]
DynamicAPI::Libloading(api) => api.WelsDestroyDecoder(pDecoder),
}
}

unsafe fn WelsGetCodecVersion(&self) -> OpenH264Version {
match self {
#[cfg(feature = "source")]
DynamicAPI::Source(api) => api.WelsGetCodecVersion(),
#[cfg(feature = "libloading")]
DynamicAPI::Libloading(api) => api.WelsGetCodecVersion(),
}
}

unsafe fn WelsGetCodecVersionEx(&self, pVersion: *mut OpenH264Version) {
match self {
#[cfg(feature = "source")]
DynamicAPI::Source(api) => api.WelsGetCodecVersionEx(pVersion),
#[cfg(feature = "libloading")]
DynamicAPI::Libloading(api) => api.WelsGetCodecVersionEx(pVersion),
}
}
Expand Down
1 change: 1 addition & 0 deletions openh264-sys2/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn api_source() {

#[test]
#[ignore]
#[cfg(feature = "libloading")]
fn api_libloading() {
use openh264_sys2::libloading::APIEntry;
let api = unsafe { APIEntry::new(r"C:\Users\rb\Downloads\openh264-2.4.0-win64.dll\openh264-2.4.0-win64.dll").unwrap() };
Expand Down
2 changes: 1 addition & 1 deletion openh264/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository = "https://github.com/ralfbiedert/openh264-rust"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["source", "libloading"]
default = ["source"]
source = ["openh264-sys2/source"]
libloading = ["openh264-sys2/libloading"]
backtrace = [] # Remove once backtrace feature is stable.
Expand Down

0 comments on commit 155b035

Please sign in to comment.