Skip to content

Commit

Permalink
feat #23: add desktop capturer files
Browse files Browse the repository at this point in the history
  • Loading branch information
peilinok committed Dec 25, 2024
1 parent c2b9561 commit 167f708
Show file tree
Hide file tree
Showing 206 changed files with 17,745 additions and 570 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci-pr-on-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ jobs:
- name: Build
shell: bash
run: >
bash scripts/build.sh -p linux
bash scripts/build.sh -p linux -a x86_64
-t ${{env.BUILD_TYPE}}
-f ${{ steps.strings.outputs.build-dir }}
-b ${{ steps.strings.outputs.build-output-dir }}
-U ON
-S ON
- name: Unit Test
working-directory: ${{ steps.strings.outputs.build-dir }}/linux/tests/unit_test
working-directory: ${{ steps.strings.outputs.build-dir }}/linux/x86_64/tests/unit_test
run: ASAN_OPTIONS=detect_leaks=1 ctest --build-config ${{env.BUILD_TYPE}} --output-on-failure --timeout ${{env.TEST_TIMEOUT}}

- name: Smoke Test
working-directory: ${{ steps.strings.outputs.build-dir }}/linux/tests/smoke_test
working-directory: ${{ steps.strings.outputs.build-dir }}/linux/x86_64/tests/smoke_test
run: ctest --build-config ${{env.BUILD_TYPE}} --output-on-failure --timeout ${{env.TEST_TIMEOUT}}

# Build on Windows for windows
Expand Down Expand Up @@ -209,5 +209,4 @@ jobs:
bash scripts/build.sh -p android
-t ${{ env.BUILD_TYPE }}
-f ${{ steps.strings.outputs.build-dir }}
-b ${{ steps.strings.outputs.build-output-dir }}
-A "arm64-v8a,x86_64"
-b ${{ steps.strings.outputs.build-output-dir }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ CMakeCache.txt
*.jpg
*.ppm
*.yuv

*.spec
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
[submodule "thirdparty/spdlog"]
path = thirdparty/spdlog
url = git@github.com:opentraa/spdlog.git
[submodule "thirdparty/cpu_features"]
path = thirdparty/cpu_features
url = git@github.com:google/cpu_features.git
285 changes: 261 additions & 24 deletions CMakeLists.txt

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions cmake/linux/toolchain-aarch64-clang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# toolchain for aarch64-linux-gnu from obs

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm64)

set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET aarch64-linux-gnu)

set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET aarch64-linux-gnu)

set(CMAKE_ASM_COMPILER clang)
set(CMAKE_ASM_COMPILER_TARGET aarch64-linux-gnu)
20 changes: 20 additions & 0 deletions cmake/linux/toolchain-aarch64-gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# toolchain for aarch64-linux-gnu from obs

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm64)

if(CROSS STREQUAL "")
set(CROSS aarch64-linux-gnu-)
endif()

if(NOT CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER ${CROSS}gcc)
endif()

if(NOT CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER ${CROSS}g++)
endif()

if(NOT CMAKE_ASM_COMPILER)
set(CMAKE_ASM_COMPILER ${CROSS}as)
endif()
20 changes: 20 additions & 0 deletions cmake/linux/toolchain-x86_64-gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# toolchain for x86_64-linux-gnu from obs

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

if(CROSS STREQUAL "")
set(CROSS x86_64-linux-gnu-)
endif()

if(NOT CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER ${CROSS}gcc)
endif()

if(NOT CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER ${CROSS}g++)
endif()

if(NOT CMAKE_ASM_COMPILER)
set(CMAKE_ASM_COMPILER ${CROSS}as)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
# command.
#

cmake_minimum_required(VERSION 3.8.0)
cmake_minimum_required(VERSION 3.10.0)

# CMake invokes the toolchain file twice during the first build, but only once during subsequent rebuilds.
if(DEFINED ENV{_IOS_TOOLCHAIN_HAS_RUN})
Expand Down
2 changes: 1 addition & 1 deletion include/traa/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ typedef enum traa_screen_source_flags {
*
* This flag indicates that the current process source should be ignored.
*/
TRAA_SCREEN_SOURCE_FLAG_IGNORE_CURRENT_PROCESS = 1 << 5,
TRAA_SCREEN_SOURCE_FLAG_IGNORE_CURRENT_PROCESS_WINDOWS = 1 << 5,

/**
* @brief Do not ignore the tool window source.
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if "%ENABLE_ANSI%"=="1" (
:: Default values
set "BUILD_ARCH=x64"
set "BUILD_TYPE=Release"
set "BUILD_FOLDER=%cd%\build"
set "BUILD_FOLDER=%cd%\build\win"
set "BIN_FOLDER=%cd%\bin"
set "SOURCE_DIR=%cd%"
set "VERSION=0.0.1"
Expand Down Expand Up @@ -62,7 +62,7 @@ goto:eof
:show_usage
echo Usage: build.bat [options]
echo Options:
echo -a, --arch Architecture (Win32/x64) [default: x64]
echo -a, --arch Architecture (Win32/x64/ARM64) [default: x64]
echo -t, --build-type Build type (Debug/Release) [default: Release]
echo -f, --build-folder Build folder path [default: build]
echo -b, --bin-folder Binary output folder [default: bin]
Expand Down
53 changes: 49 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ VERBOSE=0
BUILD_UNITTEST=OFF
BUILD_SMOKETEST=OFF
ANDROID_ABI="arm64-v8a,armeabi-v7a,x86,x86_64"
TARGET_ARCH="x86_64"

# cpu_features library on Android implements getauxval() for API level < 18, see cpu_features/src/hwcaps_linux_or_android.c
# The implementation call dlopen() to load libc.so and then call dlsym() to get the address of getauxval().
# Which is not allowed in most Android apps, so we need to set the minimum API level to 18.
ANDROID_API_LEVEL="18"

# function for logging
log() {
Expand Down Expand Up @@ -44,6 +50,8 @@ show_usage() {
echo " -A, --android-abi Android ABI [default: arm64-v8a,armeabi-v7a,x86,x86_64]"
echo " -V, --verbose Verbose output"
echo " -h, --help Show this help message"
echo " -L, --api-level Android API level [default: 18]"
echo " -a, --arch Target architecture for Linux (x86_64/aarch64_clang/aarch64_gnu) [default: x86_64]"
}

# parse command line arguments
Expand Down Expand Up @@ -93,6 +101,14 @@ while [[ $# -gt 0 ]]; do
show_usage
exit 0
;;
-L|--api-level)
ANDROID_API_LEVEL="$2"
shift 2
;;
-a|--arch)
TARGET_ARCH="$2"
shift 2
;;
*)
log "ERROR" "Unknown option: $1"
show_usage
Expand Down Expand Up @@ -120,6 +136,14 @@ if [[ ! "$TARGET_PLATFORM" =~ ^(macos|ios|xros|linux|android)$ ]]; then
exit 1
fi

# Add architecture validation for Linux platform
if [ "$TARGET_PLATFORM" == "linux" ]; then
if [[ ! "$TARGET_ARCH" =~ ^(x86_64|aarch64_clang|aarch64_gnu)$ ]]; then
log "ERROR" "Invalid Linux architecture: $TARGET_ARCH"
exit 1
fi
fi

# main build function
build() {
log "INFO" "Starting build for platform: $TARGET_PLATFORM"
Expand All @@ -128,7 +152,6 @@ build() {
log "INFO" "Binary folder: $BIN_FOLDER"
log "INFO" "Source directory: $SOURCE_DIR"
log "INFO" "Version: $VERSION"
log "INFO" "Android ABI: $ANDROID_ABI"

BUILD_FOLDER="$BUILD_FOLDER/$TARGET_PLATFORM"
log "INFO" "Redirect build folder: $BUILD_FOLDER"
Expand All @@ -144,6 +167,7 @@ build() {

# if target platform is android, we should run cmake for each ABI separately
if [ "$TARGET_PLATFORM" == "android" ]; then
log "INFO" "Android ABI: $ANDROID_ABI"
for abi in $(echo $ANDROID_ABI | tr "," "\n");do
log "INFO" "Building for ABI: $abi"
local build_folder_abi="$BUILD_FOLDER/$abi"
Expand All @@ -156,6 +180,7 @@ build() {
-DANDROID_ABI="$abi" \
-DANDROID_NDK="$ANDROID_NDK_HOME" \
-DCMAKE_SYSTEM_NAME=Android \
-DANDROID_PLATFORM=android-$ANDROID_API_LEVEL \
-DANDROID_STL=c++_static \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
Expand Down Expand Up @@ -207,14 +232,16 @@ build() {
case $TARGET_PLATFORM in
"macos"|"ios"|"xros")
local cmake_platform

# TODO @sylar: need to build OS64COMBINED and SIMULATOR64 for ios and then create xcframework
case $TARGET_PLATFORM in
"macos") cmake_platform="MAC_UNIVERSAL" ;;
"ios") cmake_platform="OS64COMBINED" ;;
"xros") cmake_platform="VISIONOSCOMBINED" ;;
esac

cmake -G Xcode \
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.toolchain.cmake \
-DCMAKE_TOOLCHAIN_FILE=cmake/macos/ios.toolchain.cmake \
-B "$BUILD_FOLDER" \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DPLATFORM="$cmake_platform" \
Expand All @@ -225,9 +252,27 @@ build() {
-S "$SOURCE_DIR"
;;
"linux")
local toolchain_file
case $TARGET_ARCH in
"x86_64")
toolchain_file="cmake/linux/toolchain-x86_64-gcc.cmake"
;;
"aarch64_clang")
toolchain_file="cmake/linux/toolchain-aarch64-clang.cmake"
;;
"aarch64_gnu")
toolchain_file="cmake/linux/toolchain-aarch64-gcc.cmake"
;;
esac

log "INFO" "Using toolchain file: $toolchain_file"
log "INFO" "Building for architecture: $TARGET_ARCH"

# set sub folder for BUILD_FOLDER
BUILD_FOLDER="$BUILD_FOLDER/$TARGET_ARCH"

cmake -B "$BUILD_FOLDER" \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_TOOLCHAIN_FILE="$toolchain_file" \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DTRAA_OPTION_BIN_FOLDER="$BIN_FOLDER" \
-DTRAA_OPTION_ENABLE_UNIT_TEST="$BUILD_UNITTEST" \
Expand Down
31 changes: 31 additions & 0 deletions src/base/arraysize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/

#ifndef TRAA_BASE_ARRAYSIZE_H_
#define TRAA_BASE_ARRAYSIZE_H_

#include <stddef.h>

// This file defines the arraysize() macro and is derived from Chromium's
// base/macros.h.

// The arraysize(arr) macro returns the # of elements in an array arr.
// The expression is a compile-time constant, and therefore can be
// used in defining new arrays, for example. If you use arraysize on
// a pointer by mistake, you will get a compile-time error.

// This template function declaration is used in defining arraysize.
// Note that the function doesn't need an implementation, as we only
// use its type.
template <typename T, size_t N> char (&array_size_helper(T (&array)[N]))[N];

#define arraysize(array) (sizeof(array_size_helper(array)))

#endif // TRAA_BASE_ARRAYSIZE_H_
Loading

0 comments on commit 167f708

Please sign in to comment.