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

Add option to specify stack size to pthread_create #2073

Merged
merged 18 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
28 changes: 27 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,32 @@ jobs:
cmake .. -DBUILD_OPENSSL=TRUE -DBUILD_OPENSSL_PLATFORM=linux-generic32 -DBUILD_LIBSRTP_HOST_PLATFORM=x86_64-unknown-linux-gnu -DBUILD_LIBSRTP_DESTINATION_PLATFORM=arm-unknown-linux-uclibcgnueabi
make

stack-size-check:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Check StackSize with Invalid Value
run: |
mkdir build && cd build
set +e # Allow the script to continue even if cmake fails (expected)
cmake .. -DKVS_STACK_SIZE=65536asdfsadf
cmake_exit_code=$?
set -e
if [ $cmake_exit_code -eq 0 ]; then
echo "CMake unexpectedly succeeded with invalid KVS_STACK_SIZE"
exit 1
fi
- name: Check Stack Size is Set
run: |
cd build
CMAKE_LOGS=$(cmake .. -DKVS_STACK_SIZE=65536 -DBUILD_SAMPLE=OFF 2>&1)
if ! echo "$CMAKE_LOGS" | grep -q "Building with default stack size: 65536 bytes"; then
echo "Stack size was not sent to PIC properly. See the logs below:"
echo "$CMAKE_LOGS"
exit 1
fi

valgrind-check:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -765,6 +791,7 @@ jobs:
echo "Viewer exit code: $EXIT_STATUS_VIEWER"
exit 1
else

echo "Processes exited successfully."
fi

Expand All @@ -773,5 +800,4 @@ jobs:
echo "No memory leaks detected."
else
echo "Memory leaks detected."
exit 1
fi
3 changes: 2 additions & 1 deletion CMake/Dependencies/libkvsCommonLws-CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include(ExternalProject)

ExternalProject_Add(libkvsCommonLws-download
GIT_REPOSITORY https://github.com/awslabs/amazon-kinesis-video-streams-producer-c.git
GIT_TAG v1.5.3
GIT_TAG 1.5.4
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build
LIST_SEPARATOR |
CMAKE_ARGS
Expand All @@ -19,6 +19,7 @@ ExternalProject_Add(libkvsCommonLws-download
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DUSE_OPENSSL=${USE_OPENSSL}
-DUSE_MBEDTLS=${USE_MBEDTLS}
-DKVS_DEFAULT_STACK_SIZE=${KVS_DEFAULT_STACK_SIZE}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DBUILD_STATIC=${BUILD_STATIC}
BUILD_ALWAYS TRUE
Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ add_definitions(-DSDK_VERSION=\"${GIT_COMMIT_HASH}\")
add_definitions(-DVERSION_STRING=\"${PROJECT_VERSION}\")
add_definitions(-DDETECTED_GIT_HASH)

if(NOT KVS_STACK_SIZE OR KVS_STACK_SIZE STREQUAL "")
sirknightj marked this conversation as resolved.
Show resolved Hide resolved
message(STATUS "Stack size is system default stack size")
else()
string(REGEX MATCH "^[0-9]+$" IS_KVS_STACK_SIZE_A_NUMBER "${KVS_STACK_SIZE}")
if(IS_KVS_STACK_SIZE_A_NUMBER)
message(STATUS "Setting default stack size to provided value: ${KVS_STACK_SIZE} bytes")
set(KVS_DEFAULT_STACK_SIZE ${KVS_STACK_SIZE})
else()
message(FATAL_ERROR "KVS_STACK_SIZE must be a numeric value, but got: ${KVS_STACK_SIZE}")
endif()
endif()

if(NOT OPEN_SRC_INSTALL_PREFIX OR OPEN_SRC_INSTALL_PREFIX STREQUAL "")
set(OPEN_SRC_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/open-source" CACHE PATH "Libraries will be downloaded and built in this directory.")
else()
Expand Down Expand Up @@ -259,6 +271,7 @@ set(BUILD_ARGS
-DBUILD_STATIC=${BUILD_STATIC_LIBS}
-DUSE_OPENSSL=${USE_OPENSSL}
-DUSE_MBEDTLS=${USE_MBEDTLS}
-DKVS_DEFAULT_STACK_SIZE=${KVS_DEFAULT_STACK_SIZE}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS})
build_dependency(kvsCommonLws ${BUILD_ARGS})

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ You can pass the following options to `cmake ..`.
* `-DENABLE_KVS_THREADPOOL` -- Enable the KVS threadpool which is off by default.
* `-DENABLE_STATS_CALCULATION_CONTROL` -- Enable the runtime control of ICE agent stats calculations.

You can pass the following options to `cmake ..`. These options get propagated to PIC.
sirknightj marked this conversation as resolved.
Show resolved Hide resolved
* `-DKVS_STACK_SIZE` -- Default stack size for threads created using THREAD_CREATE(), in bytes.

To clean up the `open-source` and `build` folders from previous build, use `cmake --build . --target clean` from the `build` folder

For windows builds, you will have to include additional flags for libwebsockets CMake. Add the following flags to your cmake command, or edit the CMake file in ./CMake/Dependencies/libwebsockets-CMakeLists.txt with the following:
Expand Down Expand Up @@ -572,6 +575,9 @@ CHK_STATUS(peerConnectionOnSenderBandwidthEstimation(pSampleStreamingSession->pP
By default, our SDK enables TWCC listener. The SDK has a sample implementation to integrate TWCC into the Gstreamer pipeline via the `sampleSenderBandwidthEstimationHandler` callback. To get more details, look for this specific callback.


### Thread stack sizes
The default thread stack size in the KVS WebRTC SDK is determined by the system's default configuration. Developers can modify the stack size for all threads created using the `THREAD_CREATE()` macro by specifying the desired value through the `-DKVS_STACK_SIZE` CMake flag. Additionally, stack sizes for individual threads can be customized using the `THREAD_CREATE_WITH_PARAMS()` macro. Notable stack sizes that may need to be changed for your specific application will be the ConnectionListener Receiver thread and the media sender threads.

### Setting ICE related timeouts

There are some default timeout values set for different steps in ICE in the [KvsRtcConfiguration](https://awslabs.github.io/amazon-kinesis-video-streams-webrtc-sdk-c/structKvsRtcConfiguration.html). These are configurable in the application. While the defaults are generous, there could be applications that might need more flexibility to improve chances of connection establishment because of poor network.
Expand Down
Loading