diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index d39ca2b..9e5cf3c 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -41,3 +41,6 @@ TARGET_LINK_LIBRARIES ( scream_bw_test_rx ${screamLibs} pthread ) + +add_subdirectory(wrapper_lib) + diff --git a/code/ScreamRx.h b/code/ScreamRx.h index 7146fd1..92b3583 100644 --- a/code/ScreamRx.h +++ b/code/ScreamRx.h @@ -152,7 +152,7 @@ class ScreamRx { * It is up to the wrapper application to prepend this RTCP * with SR or RR when needed */ - bool ScreamRx::createStandardizedFeedbackOoo(uint32_t time_ntp, bool isMark, unsigned char* buf, int& size); + bool createStandardizedFeedbackOoo(uint32_t time_ntp, bool isMark, unsigned char* buf, int& size); /* * Get last feedback transmission time in NTP domain (Q16) diff --git a/code/wrapper_lib/CMakeLists.txt b/code/wrapper_lib/CMakeLists.txt index 9fe94f3..a7dcf93 100644 --- a/code/wrapper_lib/CMakeLists.txt +++ b/code/wrapper_lib/CMakeLists.txt @@ -2,20 +2,20 @@ #set(CMAKE_VERBOSE_MAKEFILE ON) -set(BUILD_SHARED_LIBS on) +# set(BUILD_SHARED_LIBS on) SET(HEADERS -../ScreamTx.h -../RtpQueue.h + ../ScreamTx.h + ../RtpQueue.h ) SET(SRCS -../RtpQueue.cpp -../ScreamTx.cpp -../ScreamV2Tx.cpp -../ScreamV2TxStream.cpp -screamtxbw_plugin_wrapper.cpp -screamtx_plugin_wrapper.cpp + ../RtpQueue.cpp + ../ScreamTx.cpp + ../ScreamV2Tx.cpp + ../ScreamV2TxStream.cpp + screamtxbw_plugin_wrapper.cpp + screamtx_plugin_wrapper.cpp ) set(CMAKE_BUILD_TYPE Debug) @@ -25,12 +25,17 @@ if(BUILD_SHARED_LIBS) add_library(scream SHARED ${SRCS}) else() - set(CMAKE_CXX_FLAGS " -DV2 -g -I .. ${CMAKE_CXX_FLAGS_INIT} -fPIC") add_library(scream STATIC ${SRCS}) endif() INCLUDE_DIRECTORIES( -${screamIncludes} + ${screamIncludes} +) + +# Add install instructions for the library for automated buildscripts +install(TARGETS scream + ARCHIVE DESTINATION lib ) + diff --git a/code/wrapper_lib/screamtx_plugin_wrapper.cpp b/code/wrapper_lib/screamtx_plugin_wrapper.cpp index 569c989..425dfb3 100644 --- a/code/wrapper_lib/screamtx_plugin_wrapper.cpp +++ b/code/wrapper_lib/screamtx_plugin_wrapper.cpp @@ -1,6 +1,6 @@ // Scream sender side wrapper -#include "ScreamTx.h" -#include "RtpQueue.h" +#include "../ScreamTx.h" +#include "../RtpQueue.h" #include "sys/types.h" #include #include diff --git a/code/wrapper_lib/screamtxbw_plugin_wrapper.cpp b/code/wrapper_lib/screamtxbw_plugin_wrapper.cpp index c828b58..20f3b7b 100644 --- a/code/wrapper_lib/screamtxbw_plugin_wrapper.cpp +++ b/code/wrapper_lib/screamtxbw_plugin_wrapper.cpp @@ -1,5 +1,5 @@ -#include "ScreamTx.h" -#include "RtpQueue.h" +#include "../ScreamTx.h" +#include "../RtpQueue.h" #include "sys/types.h" #include #include diff --git a/gstscream/Cargo.toml b/gstscream/Cargo.toml index 514b01c..e1b0cd8 100644 --- a/gstscream/Cargo.toml +++ b/gstscream/Cargo.toml @@ -38,6 +38,7 @@ name="scream_receiver" path="src/receiver.rs" [build-dependencies] +cmake = "0.1.35" gst-plugin-version-helper = { git = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git" } [features] diff --git a/gstscream/README.md b/gstscream/README.md index 4f741bf..f876726 100644 --- a/gstscream/README.md +++ b/gstscream/README.md @@ -7,9 +7,14 @@ # Building gstscream and sample applications Should be possible to build and run on Windows (not tested) However SCReAM BW can't be built for Windows. -Therefore modify build.sh to remove --features screamtxbw-enabled +Therefore you cannot build with --features screamtxbw-enabled + ```bash -./scripts/build.sh +# To build with L4S and with SCReAM BW +cargo build --features=ecn-enabled,screamtxbw-enabled + +# To build without SCReAM BW +cargo build --features=ecn-enabled ``` # Environment Variables are set in script/env.sh diff --git a/gstscream/build.rs b/gstscream/build.rs index cda12e5..38cee10 100644 --- a/gstscream/build.rs +++ b/gstscream/build.rs @@ -1,3 +1,57 @@ +//! Builds the rust abstraction for the `SCREAMV2` protocol. +//! +//! This build script builds the c++ scream library and +//! provides the needed linker arguments needed to statically +//! link the library to this rust code. + +#![deny(warnings)] +#![deny(clippy::all)] + +use std::path::PathBuf; + fn main() { - gst_plugin_version_helper::info() + gst_plugin_version_helper::info(); + + let source_dir = PathBuf::from( + std::env::var("CARGO_MANIFEST_DIR") + .expect("Cannot find \"CARGO_MANIFEST_DIR\", please build the project using cargo"), + ); + + let parent_dir = source_dir.parent().unwrap_or_else(|| { + panic!( + "Cannot find parent of {} (project root)", + source_dir.display() + ) + }); + + build_and_link_scream(parent_dir); + + // re-run if any code in the gstscream directory changes. + println!("cargo:rerun-if-changed={}", source_dir.display()); + + // re-run if any of the c++ code changes. + println!( + "cargo:rerun-if-changed={}", + parent_dir.join("code").display() + ); + println!( + "cargo:rerun-if-changed={}", + parent_dir.join("CMakeList.txt").display() + ); +} + +/// Builds the c++ scream library and provides the needed linker arguments. +fn build_and_link_scream(parent_dir: &std::path::Path) { + let code_dir = parent_dir.join("code"); + let built = cmake::Config::new(code_dir).build(); + + println!( + "cargo:rustc-link-search=all={}", + built.join("lib").display() + ); + + // Statically link scream. + println!("cargo:rustc-link-lib=static=scream"); + // Dynamically link stdc++ as this is generally available. + println!("cargo:rustc-link-lib=dylib=stdc++"); } diff --git a/gstscream/scripts/build.sh b/gstscream/scripts/build.sh deleted file mode 100755 index 0bc1dfe..0000000 --- a/gstscream/scripts/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -ECN_ENABLED=1 -SCRIPT_PATH=$(realpath $0) -SCRIPT_DIR=$(dirname $SCRIPT_PATH) -source $SCRIPT_DIR/env.sh -SCREAMLIB_DIR=$SCRIPT_DIR/../../code/wrapper_lib -cd $SCREAMLIB_DIR; cmake .; make -cd $SCRIPT_DIR -export RUSTFLAGS="$RUSTFLAGS -L$SCREAMLIB_DIR" -if (($ECN_ENABLED == 1)); then - cargo build --features ecn-enabled,screamtxbw-enabled - cargo clippy --features ecn-enabled,screamtxbw-enabled -else - cargo build --features screamtxbw-enabled - cargo clippy --features screamtxbw-enabled -fi - diff --git a/gstscream/src/screamrx/ecn.rs b/gstscream/src/screamrx/ecn.rs index 3bc3784..1e8797a 100644 --- a/gstscream/src/screamrx/ecn.rs +++ b/gstscream/src/screamrx/ecn.rs @@ -13,7 +13,6 @@ pub struct GstNetEcnMeta { pub cp: GstNetEcnCp, } -#[link(name = "gstnet-1.0")] extern "C" { //========================================================================= diff --git a/gstscream/src/screamtx/imp.rs b/gstscream/src/screamtx/imp.rs index 9fb88c4..14158b3 100644 --- a/gstscream/src/screamtx/imp.rs +++ b/gstscream/src/screamtx/imp.rs @@ -357,7 +357,7 @@ extern "C" fn callback(stx: *const Screamtx, buf: gst::Buffer, is_push: u8) { drop(buf); } } -#[link(name = "scream")] + extern "C" { fn ScreamSenderPush( buf: *mut gst_sys::GstBuffer, diff --git a/gstscream/src/screamtxbw/imp.rs b/gstscream/src/screamtxbw/imp.rs index 25ee30e..ef5fc8e 100644 --- a/gstscream/src/screamtxbw/imp.rs +++ b/gstscream/src/screamtxbw/imp.rs @@ -189,7 +189,7 @@ extern "C" fn callback( .expect("Screamtxbw callback srcpad.push failed"); } } -#[link(name = "scream")] + extern "C" { #[allow(improper_ctypes)] fn ScreamTxBwPluginInit(