From cf30fe52f6bf1f155803e927c4afd60519f566e7 Mon Sep 17 00:00:00 2001 From: ivajon Date: Thu, 8 Aug 2024 13:27:19 +0200 Subject: [PATCH 1/7] Initial c++ changes needed for build.rs refactor --- code/CMakeLists.txt | 3 +++ code/wrapper_lib/CMakeLists.txt | 27 +++++++++++-------- code/wrapper_lib/screamtx_plugin_wrapper.cpp | 4 +-- .../wrapper_lib/screamtxbw_plugin_wrapper.cpp | 4 +-- 4 files changed, 23 insertions(+), 15 deletions(-) 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/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 From 9fafe9fe33fe118221f3c1e2c9b9db3319ceb466 Mon Sep 17 00:00:00 2001 From: ivajon Date: Thu, 8 Aug 2024 13:34:29 +0200 Subject: [PATCH 2/7] remove faulty ScreamRx::* --- code/ScreamRx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 84ecaf4e1f837eada885208ad9704694e82e687e Mon Sep 17 00:00:00 2001 From: ivajon Date: Thu, 8 Aug 2024 13:46:38 +0200 Subject: [PATCH 3/7] initial build.rs changes --- gstscream/build.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) 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++"); } From 63a80dda44d7a308c8bd5b99f507412c082d04b4 Mon Sep 17 00:00:00 2001 From: ivajon Date: Thu, 8 Aug 2024 13:47:30 +0200 Subject: [PATCH 4/7] Add needed build dependencies --- gstscream/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gstscream/Cargo.toml b/gstscream/Cargo.toml index 514b01c..6feaf60 100644 --- a/gstscream/Cargo.toml +++ b/gstscream/Cargo.toml @@ -38,6 +38,8 @@ name="scream_receiver" path="src/receiver.rs" [build-dependencies] +pkg-config = "0.3.30" +cmake = "0.1.35" gst-plugin-version-helper = { git = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git" } [features] From ef5f8ba4bb3f83200f41145090c99eadd6fafdba Mon Sep 17 00:00:00 2001 From: ivajon Date: Thu, 8 Aug 2024 13:56:05 +0200 Subject: [PATCH 5/7] remove inline linker args as this is now done in build.rs --- gstscream/src/screamrx/ecn.rs | 1 - gstscream/src/screamtx/imp.rs | 2 +- gstscream/src/screamtxbw/imp.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) 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( From d26b9583ebe4ae128b3f4445e9b59ebce8f90432 Mon Sep 17 00:00:00 2001 From: ivajon Date: Thu, 8 Aug 2024 14:08:25 +0200 Subject: [PATCH 6/7] remove build.sh as this is now done in build.rs --- gstscream/README.md | 9 +++++++-- gstscream/scripts/build.sh | 17 ----------------- 2 files changed, 7 insertions(+), 19 deletions(-) delete mode 100755 gstscream/scripts/build.sh 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/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 - From 6e609a23452856f5e96762851446df5826939b75 Mon Sep 17 00:00:00 2001 From: eivajon Date: Thu, 8 Aug 2024 15:50:31 +0200 Subject: [PATCH 7/7] Remove pkg-config dependency --- gstscream/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/gstscream/Cargo.toml b/gstscream/Cargo.toml index 6feaf60..e1b0cd8 100644 --- a/gstscream/Cargo.toml +++ b/gstscream/Cargo.toml @@ -38,7 +38,6 @@ name="scream_receiver" path="src/receiver.rs" [build-dependencies] -pkg-config = "0.3.30" cmake = "0.1.35" gst-plugin-version-helper = { git = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git" }