Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebRTC m120 & libmediasoupclient 3.4.3 #33

Merged
merged 8 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ else()
target_compile_options(webrtc-testlibs PRIVATE "-Wno-unused-parameter")
endif()


target_link_libraries(webrtc-testlibs
${WEBRTC_LIB_PATH})

set_property(TARGET webrtc-testlibs PROPERTY CXX_STANDARD 14)
set_property(TARGET webrtc-testlibs PROPERTY CXX_STANDARD 20)
set_property(TARGET webrtc-testlibs PROPERTY CXX_STANDARD_REQUIRED ON)

target_compile_definitions(webrtc-testlibs PUBLIC ${webrtc_COMMON_COMPILE_DEFS})

Expand Down Expand Up @@ -163,8 +163,14 @@ target_link_libraries(mediasoup-connector
${MEDIASOUP_SDP_LIB_PATH}
${mediasoup-connector_PLATFORM_DEPS})

if(MSVC)
target_link_libraries(mediasoup-connector Iphlpapi.lib)
endif()

set_target_properties(mediasoup-connector PROPERTIES FOLDER "plugins")
set_property(TARGET mediasoup-connector PROPERTY CXX_STANDARD 14)

set_property(TARGET mediasoup-connector PROPERTY CXX_STANDARD 20)
set_property(TARGET mediasoup-connector PROPERTY CXX_STANDARD_REQUIRED ON)

target_compile_definitions(mediasoup-connector PUBLIC ${webrtc_COMMON_COMPILE_DEFS})

Expand Down
14 changes: 7 additions & 7 deletions MediaSoupTransceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool MediaSoupTransceiver::CreateVideoProducerTrack(const std::string &id, const
encodings.emplace_back(webrtc::RtpEncodingParameters{});
}

if (auto ptr = m_sendTransport->Produce(this, videoTrack, &encodings, codecOptions, codec)) {
if (auto ptr = m_sendTransport->Produce(this, videoTrack.get(), &encodings, codecOptions, codec)) {
AssignProducer(id, ptr, mailbox);
} else {
m_lastErorMsg = "MediaSoupTransceiver::CreateVideoProducerTrack - Transport failed to produce video";
Expand Down Expand Up @@ -318,7 +318,7 @@ bool MediaSoupTransceiver::CreateAudioProducerTrack(const std::string &id)

json codecOptions = {{"opusStereo", true}, {"opusDtx", true}};

if (auto ptr = m_sendTransport->Produce(this, audioTrack, nullptr, &codecOptions, nullptr)) {
if (auto ptr = m_sendTransport->Produce(this, audioTrack.get(), nullptr, &codecOptions, nullptr)) {
auto mailbox = std::make_shared<MediaSoupMailbox>();
AssignProducer(id, ptr, mailbox);

Expand All @@ -345,13 +345,13 @@ MediaSoupTransceiver::CreateProducerAudioTrack(rtc::scoped_refptr<webrtc::PeerCo
options.auto_gain_control = false;
options.noise_suppression = true;
options.echo_cancellation = false;
options.residual_echo_detector = false;
options.experimental_agc = false;
options.experimental_ns = false;
options.typing_detection = false;
//options.residual_echo_detector = false;
//options.experimental_agc = false;
//options.experimental_ns = false;
//options.typing_detection = false;

rtc::scoped_refptr<webrtc::AudioSourceInterface> source = factory->CreateAudioSource(options);
return factory->CreateAudioTrack(label, source);
return factory->CreateAudioTrack(label, source.get());
}

bool MediaSoupTransceiver::CreateAudioConsumer(const std::string &id, const std::string &producerId, json *rtpParameters, obs_source_t *source)
Expand Down
11 changes: 10 additions & 1 deletion MyFrameGeneratorInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ MyFrameGeneratorInterface::MyFrameGeneratorInterface(int width, int height, Outp
: m_mailbox(mailbox), m_width(width), m_height(height)
{
m_lastFrame = webrtc::I420Buffer::Create(width, height);
webrtc::I420Buffer::SetBlack(m_lastFrame);
webrtc::I420Buffer::SetBlack(m_lastFrame.get());
}

void MyFrameGeneratorInterface::ChangeResolution(size_t width, size_t height) {}
webrtc::test::FrameGeneratorInterface::Resolution MyFrameGeneratorInterface::GetResolution() const
{
return {static_cast<size_t>(m_width), static_cast<size_t>(m_height)};
}

webrtc::test::FrameGeneratorInterface::VideoFrameData MyFrameGeneratorInterface::NextFrame()
{
Expand All @@ -24,6 +28,11 @@ webrtc::test::FrameGeneratorInterface::VideoFrameData MyFrameGeneratorInterface:
return VideoFrameData(m_lastFrame, absl::nullopt);
}

absl::optional<int> MyFrameGeneratorInterface::fps() const
{
return absl::nullopt;
}

FrameGeneratorCapturerVideoTrackSource::FrameGeneratorCapturerVideoTrackSource(Config config, webrtc::Clock *clock, bool is_screencast,
std::shared_ptr<MediaSoupMailbox> mailbox)
: VideoTrackSource(false), task_queue_factory_(webrtc::CreateDefaultTaskQueueFactory()), is_screencast_(is_screencast)
Expand Down
3 changes: 3 additions & 0 deletions MyFrameGeneratorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class MyFrameGeneratorInterface : public webrtc::test::FrameGeneratorInterface {
MyFrameGeneratorInterface(int width, int height, OutputType type, std::shared_ptr<MediaSoupMailbox> mailbox);

void ChangeResolution(size_t width, size_t height) override;
Resolution GetResolution() const override;

VideoFrameData NextFrame() override;

absl::optional<int> fps() const override;

private:
const int m_width;
const int m_height;
Expand Down
2 changes: 1 addition & 1 deletion MyLogSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// This is a singleton
MyLogSink::MyLogSink()
{
rtc::LogMessage::AddLogToStream(this, rtc::WARNING);
rtc::LogMessage::AddLogToStream(this, rtc::LoggingSeverity::LS_WARNING);
}

MyLogSink::~MyLogSink()
Expand Down
11 changes: 9 additions & 2 deletions cmake/legacy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ endif()
target_link_libraries(webrtc-testlibs
${WEBRTC_LIB_PATH})

set_property(TARGET webrtc-testlibs PROPERTY CXX_STANDARD 14)
set_property(TARGET webrtc-testlibs PROPERTY CXX_STANDARD 20)
set_property(TARGET webrtc-testlibs PROPERTY CXX_STANDARD_REQUIRED ON)

target_compile_definitions(webrtc-testlibs PUBLIC ${webrtc_COMMON_COMPILE_DEFS})

Expand Down Expand Up @@ -147,8 +148,14 @@ target_link_libraries(mediasoup-connector
${MEDIASOUP_SDP_LIB_PATH}
${mediasoup-connector_PLATFORM_DEPS})

if(MSVC)
target_link_libraries(mediasoup-connector Iphlpapi.lib)
endif()

set_target_properties(mediasoup-connector PROPERTIES FOLDER "plugins")
set_property(TARGET mediasoup-connector PROPERTY CXX_STANDARD 14)

set_property(TARGET mediasoup-connector PROPERTY CXX_STANDARD 20)
set_property(TARGET mediasoup-connector PROPERTY CXX_STANDARD_REQUIRED ON)

target_compile_definitions(mediasoup-connector PUBLIC ${webrtc_COMMON_COMPILE_DEFS})

Expand Down
166 changes: 166 additions & 0 deletions scripts/build-libmediasoupclient-macos.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/bin/zsh

# 1. Precompile the webrtc library for arm64 or/and x84_64
# 2. Place the script to an empty folder
# 3. ./build-libmediasoupclient-macos.zsh --architecture=arm64 --webrtc-folder=THE_COMBINED_WEBRTC_INCLUDE_AND_LIB_FOLDER
# 4. ./build-libmediasoupclient-macos.zsh --architecture=x86_64 --webrtc-folder=THE_COMBINED_WEBRTC_INCLUDE_AND_LIB_FOLDER

download_libmediasoupclient() {
# Check if the webrtc folder exists
if [ -d "${GIT_FOLDER}" ]
then
echo "### The '${GIT_FOLDER}' folder exists. It will be reused. Remove it if you want to clone the git repositoty again."
return
fi

# Clone
git clone --recurse-submodules https://github.com/versatica/libmediasoupclient.git ${GIT_FOLDER}
if [ $? -ne 0 ]
then
echo "### ould not clone libmediasoupclient."
exit 1
fi

# Check if the source folder name is correct and the folder exists
if [ ! -d "${GIT_FOLDER}" ]
then
echo "### The source folder '${GIT_FOLDER}' could not be found. Probably the 'git clone' command failed. Please check manually"
exit 1
fi

# Checkout the necessary version
cd "${GIT_FOLDER}"
git checkout -b ${GIT_TAG}-build ${GIT_TAG}
if [ $? -ne 0 ]
then
echo "### git checkout ${GIT_TAG} failed"
cd "${INITIAL_WORKING_FOLDER}"
exit 1
fi
}

build_libmediasoupclient() {
cd "${GIT_FOLDER}"

# Prepare build parameters
case "${ARCHITECTURE}" in
arm64)
MIN_MACOS_VERSION=11.0
;;
x86_64)
MIN_MACOS_VERSION=11.0
;;
*)
echo "### Unknown architecture! Only 'arm64' or 'x86_64' is supported."
exit 1
;;
esac

# Check if the build folder exists
if [ -d "${BUILD_FOLDER}" ]
then
echo "### The '${BUILD_FOLDER}' folder exists. Configuring will be skiped. Remove the folder if you want to configure from scratch."
else
cmake . -B"${BUILD_FOLDER}" -DLIBWEBRTC_INCLUDE_PATH="${WEBRTC_FOLDER}" -DLIBWEBRTC_BINARY_PATH="${WEBRTC_FOLDER}" -DCMAKE_OSX_ARCHITECTURES="${ARCHITECTURE}" -DCMAKE_OSX_DEPLOYMENT_TARGET=${MIN_MACOS_VERSION}
if [ $? -ne 0 ]
then
echo "### Could not configure to build for ${ARCHITECTURE}"
cd "${INITIAL_WORKING_FOLDER}"
exit 1
fi
fi

cmake --build ${BUILD_FOLDER} --config RelWithDebInfo
if [ $? -ne 0 ]
then
echo "### Build failed for ${ARCHITECTURE}"
cd "${INITIAL_WORKING_FOLDER}"
exit 1
fi
}

package_libmediasoupclient() {
PACKAGE_FOLDER_NAME=libmediasoupclient-${GIT_TAG}-osx-${ARCHITECTURE}
PACKAGE_FOLDER=${INITIAL_WORKING_FOLDER}/${PACKAGE_FOLDER_NAME}

if [ -d "${PACKAGE_FOLDER}" ]; then
echo "### Package folder ${PACKAGE_FOLDER} exists. Plrease remove it manually and start the script again."
exit 1
fi

# Create the folder
echo "### Creating the package folder: ${PACKAGE_FOLDER}"
mkdir -p "${PACKAGE_FOLDER}/include/mediasoupclient"
mkdir -p "${PACKAGE_FOLDER}/include/sdptransform"
mkdir -p "${PACKAGE_FOLDER}/lib"

# Copy libs
echo "### Copying libraries ..."
cp "${BUILD_FOLDER}/libmediasoupclient.a" "${PACKAGE_FOLDER}/lib"
cp "${BUILD_FOLDER}/_deps/libsdptransform-build/libsdptransform.a" "${PACKAGE_FOLDER}/lib"

# Copy includes
echo "### Copying includes ..."
cp -R "${GIT_FOLDER}/include/." "${PACKAGE_FOLDER}/include/mediasoupclient"
cp -R "${BUILD_FOLDER}/_deps/libsdptransform-src/include/." "${PACKAGE_FOLDER}/include/sdptransform"

# Copy the script
cp "${SCRIPT_PATH}" "${PACKAGE_FOLDER}"

cd ${INITIAL_WORKING_FOLDER}

# Zip everything
echo "### Compressing ..."
zip --quiet --recurse-paths ${PACKAGE_FOLDER_NAME}.zip ${PACKAGE_FOLDER_NAME}

# SHA256
shasum -a 256 ${PACKAGE_FOLDER_NAME}.zip | tr '/a-z/' '/A-Z/'
}

# SCRIPT START

ARCHITECTURE=$(uname -m)

while [ $# -gt 0 ]; do
case "$1" in
--architecture=*)
ARCHITECTURE="${1#*=}"
;;
--webrtc-folder=*)
WEBRTC_FOLDER="${1#*=}"
;;
*)
echo "### Error: Invalid command line parameter. Please use --architecture=arm64|x86_64 --webrtc-folder=..."
exit 1
esac
shift
done

if [ -z "${WEBRTC_FOLDER}" ]; then
echo "### The webrtc include folder is not set. Please specify --webrtc-include-folder=..."
exit 1
fi

INITIAL_WORKING_FOLDER=${PWD}
SCRIPT_PATH=$(realpath $0)
GIT_FOLDER_NAME=libmediasoupclient
GIT_FOLDER=${PWD}/${GIT_FOLDER_NAME}
BUILD_FOLDER_NAME=build-${ARCHITECTURE}
BUILD_FOLDER=${GIT_FOLDER}/${BUILD_FOLDER_NAME}
GIT_TAG=3.4.3

# Check if git is available
if ! command -v git &> /dev/null
then
echo "'git' could not be found. Please install 'git' and start the script again."
exit 1
fi

# Download the sources
download_libmediasoupclient

# Build
build_libmediasoupclient

# Package
package_libmediasoupclient
83 changes: 83 additions & 0 deletions scripts/build-libmediasoupclient-windows.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
@echo off

set Z7_PATH="C:\Program Files\7-Zip"
set ORIGINAL_WORK_DIR=%CD%
set SCRIPT_FULL_FILENAME=%ORIGINAL_WORK_DIR%\%~n0%~x0
set WEBRTC_FOLDER=%1
set GIT_TAG=3.4.3
set GIT_FOLDER_NAME=libmediasoupclient
set GIT_FOLDER_PATH=%ORIGINAL_WORK_DIR%\%GIT_FOLDER_NAME%
set BUILD_FOLDER_NAME=build
set BUILD_FOLDER_PATH=%GIT_FOLDER_PATH%\build
set PACKAGE_FOLDER_NAME=libmediasoupclient_dist
set PACKAGE_FOLDER_PATH=%ORIGINAL_WORK_DIR%\%PACKAGE_FOLDER_NAME%

if [%WEBRTC_FOLDER%] == [] (
echo The combined include and lib webrtc folder path is missed. Use: build-libmediasoupclient-windows.cmd COMBINED_WEBRTC_FOLDER_PATH
goto end
)

if exist %GIT_FOLDER_PATH%\ goto skip_checkout

echo ### Cloning ...

call git clone --recurse-submodules https://github.com/versatica/libmediasoupclient.git

echo f | xcopy libmediasoupclient.patch "%GIT_FOLDER_NAME%\libmediasoupclient.patch" /yf

cd %GIT_FOLDER_NAME%

echo ### Checkout %GIT_TAG% ...
call git checkout -b %GIT_TAG%-build %GIT_TAG%

echo ### Patching ...
call git apply --ignore-whitespace libmediasoupclient.patch

if %errorlevel% neq 0 goto end

:skip_checkout

cd %GIT_FOLDER_PATH%

if exist %BUILD_FOLDER_NAME%\ goto skip_build

echo ### Configuring for build ...
cmake . -B%BUILD_FOLDER_NAME% -DLIBWEBRTC_INCLUDE_PATH=%WEBRTC_FOLDER% -DLIBWEBRTC_BINARY_PATH=%WEBRTC_FOLDER%

echo ### Building ...
cmake --build %BUILD_FOLDER_NAME% --config RelWithDebInfo

if %errorlevel% neq 0 goto end

:skip_build

cd %ORIGINAL_WORK_DIR%

if exist %PACKAGE_FOLDER_PATH%\ goto skip_copy

echo ### Copying files for the package ...

mkdir %PACKAGE_FOLDER_PATH%\include\mediasoupclient %PACKAGE_FOLDER_PATH%\include\sdptransform %PACKAGE_FOLDER_PATH%\lib

xcopy "%GIT_FOLDER_PATH%\include\*.hpp" "%PACKAGE_FOLDER_PATH%\include\mediasoupclient" /sy
xcopy "%BUILD_FOLDER_PATH%\_deps\libsdptransform-src\include\*.hpp" "%PACKAGE_FOLDER_PATH%\include\sdptransform" /sy

echo f | xcopy "%BUILD_FOLDER_PATH%\RelWithDebInfo\mediasoupclient.lib" "%PACKAGE_FOLDER_PATH%\lib\mediasoupclient.lib" /yf
echo f | xcopy "%BUILD_FOLDER_PATH%\RelWithDebInfo\mediasoupclient.pdb" "%PACKAGE_FOLDER_PATH%\lib\mediasoupclient.pdb" /yf
echo f | xcopy "%BUILD_FOLDER_PATH%\_deps\libsdptransform-build\RelWithDebInfo\sdptransform.lib" "%PACKAGE_FOLDER_PATH%\lib\sdptransform.lib" /yf
echo f | xcopy "%BUILD_FOLDER_PATH%\_deps\libsdptransform-build\RelWithDebInfo\sdptransform.pdb" "%PACKAGE_FOLDER_PATH%\lib\sdptransform.pdb" /yf

echo f | xcopy "%BUILD_FOLDER_PATH%\_deps\libsdptransform-build\RelWithDebInfo\sdptransform.pdb" "%PACKAGE_FOLDER_PATH%\lib\sdptransform.pdb" /yf

echo f | xcopy "%SCRIPT_FULL_FILENAME%" "%PACKAGE_FOLDER_PATH%" /yf

:skip_copy

echo "### 7z-ing..."

set PACKAGE_FILE=libmediasoupclient-%GIT_TAG%-win-x64.7z
%Z7_PATH%\7z.exe a %PACKAGE_FILE% %PACKAGE_FOLDER_NAME%

:end

cd %ORIGINAL_WORK_DIR%
Loading
Loading