Skip to content

Commit 4b9977f

Browse files
authored
Merge branch 'qualabs:master' into master
2 parents 3c0cdb1 + b902853 commit 4b9977f

File tree

11 files changed

+157
-99
lines changed

11 files changed

+157
-99
lines changed

.gitignore

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
# Exclude everything
2-
/*
1+
# Build directories
2+
build_*
3+
build/
4+
.deps/
35

4-
# Except for default project files
5-
!/.github
6-
!/build-aux
7-
!/cmake
8-
!/data
9-
!/src
10-
!.clang-format
11-
!.gersemirc
12-
!.gitignore
13-
!buildspec.json
14-
!CMakeLists.txt
15-
!CMakePresets.json
16-
!LICENSE
17-
!README.md
6+
# Nix
7+
.direnv/
8+
result
189

19-
# Exclude lock files
10+
# CMake
11+
cmake/.CMakeBuildNumber
2012
*.lock.json
2113

22-
# Exclude macOS legacy resource forks
14+
# macOS
2315
.DS_Store
2416

25-
# Exclude CMake build number cache
26-
/cmake/.CMakeBuildNumber
17+
# IDEs
18+
.vscode/
19+
.idea/

CMakeLists.txt

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,27 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::libobs)
1919
option(MOQ_LOCAL "Path to moq repo for local development" "")
2020

2121
if(MOQ_LOCAL)
22-
add_subdirectory(${MOQ_LOCAL}/rs/libmoq moq)
22+
add_subdirectory(${MOQ_LOCAL}/rs/libmoq moq)
2323
else()
24-
include(FetchContent)
25-
FetchContent_Declare(moq
26-
URL https://github.com/kixelated/moq/releases/download/v${MOQ_VERSION}/moq-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}.tar.gz
27-
)
28-
FetchContent_MakeAvailable(moq)
24+
include(FetchContent)
25+
FetchContent_Declare(
26+
moq
27+
URL
28+
https://github.com/kixelated/moq/releases/download/v${MOQ_VERSION}/moq-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}.tar.gz
29+
)
30+
FetchContent_MakeAvailable(moq)
2931

30-
add_library(moq SHARED IMPORTED GLOBAL)
31-
set_target_properties(moq PROPERTIES
32-
IMPORTED_LOCATION "${moq_SOURCE_DIR}/lib/libmoq.dylib"
33-
INTERFACE_INCLUDE_DIRECTORIES "${moq_SOURCE_DIR}/include"
34-
)
32+
add_library(moq SHARED IMPORTED GLOBAL)
33+
set_target_properties(
34+
moq
35+
PROPERTIES
36+
IMPORTED_LOCATION "${moq_SOURCE_DIR}/lib/libmoq.dylib"
37+
INTERFACE_INCLUDE_DIRECTORIES "${moq_SOURCE_DIR}/include"
38+
)
3539
endif()
3640

3741
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE moq)
3842

39-
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
40-
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:moq>
41-
$<TARGET_BUNDLE_CONTENT_DIR:${CMAKE_PROJECT_NAME}>/MacOS/
42-
)
43-
4443
if(ENABLE_FRONTEND_API)
4544
find_package(obs-frontend-api REQUIRED)
4645
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::obs-frontend-api)
@@ -59,6 +58,9 @@ if(ENABLE_QT)
5958
)
6059
endif()
6160

62-
target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/obs-moq.cpp src/moq-output.h src/moq-service.h src/moq-output.cpp src/moq-service.cpp)
61+
target_sources(
62+
${CMAKE_PROJECT_NAME}
63+
PRIVATE src/obs-moq.cpp src/moq-output.h src/moq-service.h src/moq-output.cpp src/moq-service.cpp
64+
)
6365

6466
set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name})

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ Prerequisites:
3333
3434
3. Configure the project with CMake:
3535
```bash
36+
just setup ../moq
37+
38+
# Alternatively:
3639
cmake --preset macos -DMOQ_LOCAL=../moq
3740
```
3841
3942
4. Build the plugin:
4043
```bash
44+
just build
45+
46+
# Alternatively:
4147
cmake --build --preset macos
4248
```
4349

cmake/common/buildspec_common.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ function(_check_dependencies)
148148

149149
if(EXISTS "${dependencies_dir}/.dependency_${dependency}_${arch}.sha256")
150150
file(
151-
READ
152-
"${dependencies_dir}/.dependency_${dependency}_${arch}.sha256"
151+
READ "${dependencies_dir}/.dependency_${dependency}_${arch}.sha256"
153152
OBS_DEPENDENCY_${dependency}_${arch}_HASH
154153
)
155154
endif()

cmake/linux/helpers.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ function(target_install_resources target)
5858
file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
5959
foreach(data_file IN LISTS data_files)
6060
cmake_path(
61-
RELATIVE_PATH
62-
data_file
61+
RELATIVE_PATH data_file
6362
BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
6463
OUTPUT_VARIABLE relative_path
6564
)

cmake/macos/helpers.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ function(target_install_resources target)
7979
file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
8080
foreach(data_file IN LISTS data_files)
8181
cmake_path(
82-
RELATIVE_PATH
83-
data_file
82+
RELATIVE_PATH data_file
8483
BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
8584
OUTPUT_VARIABLE relative_path
8685
)

cmake/windows/helpers.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ function(target_install_resources target)
6565
file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
6666
foreach(data_file IN LISTS data_files)
6767
cmake_path(
68-
RELATIVE_PATH
69-
data_file
68+
RELATIVE_PATH data_file
7069
BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
7170
OUTPUT_VARIABLE relative_path
7271
)

justfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env just --justfile
2+
3+
# Using Just: https://github.com/casey/just?tab=readme-ov-file#installation
4+
5+
set quiet
6+
7+
# List all of the available commands.
8+
default:
9+
just --list
10+
11+
# Configure the project using CMake presets (optionally specify MOQ_LOCAL path and preset)
12+
setup path="" preset="":
13+
#!/usr/bin/env bash
14+
set -euo pipefail
15+
16+
PRESET=$(just preset "{{preset}}")
17+
18+
# Add MOQ_LOCAL if path is provided
19+
if [[ -n "{{path}}" ]]; then
20+
echo "Configuring with preset: $PRESET and MOQ_LOCAL={{path}}"
21+
cmake --preset "$PRESET" -DMOQ_LOCAL="{{path}}"
22+
else
23+
echo "Configuring with preset: $PRESET"
24+
cmake --preset "$PRESET"
25+
fi
26+
27+
# Build the project using CMake presets (optionally specify preset name)
28+
build preset="":
29+
#!/usr/bin/env bash
30+
set -euo pipefail
31+
32+
PRESET=$(just preset "{{preset}}")
33+
cmake --build --preset "$PRESET"
34+
35+
# Run the CI checks
36+
check:
37+
./build-aux/run-clang-format --check
38+
./build-aux/run-gersemi --check
39+
40+
# Automatically fix formatting issues.
41+
fix:
42+
./build-aux/run-clang-format --fix
43+
./build-aux/run-gersemi --fix
44+
45+
# Detect the appropriate CMake preset for the current platform (or use override)
46+
preset override="":
47+
#!/usr/bin/env bash
48+
set -euo pipefail
49+
50+
# Use provided override or auto-detect
51+
if [[ -n "{{override}}" ]]; then
52+
echo "{{override}}"
53+
elif [[ "$OSTYPE" == "darwin"* ]]; then
54+
echo "macos"
55+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
56+
echo "ubuntu-x86_64"
57+
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
58+
echo "windows-x64"
59+
else
60+
echo "Unknown platform: $OSTYPE" >&2
61+
exit 1
62+
fi

src/moq-output.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ bool MoQOutput::Start()
6868

6969
// Create a callback to log when the session is connected or closed
7070
auto session_connect_callback = [](void *user_data, int error_code) {
71-
auto self = static_cast<MoQOutput*>(user_data);
71+
auto self = static_cast<MoQOutput *>(user_data);
7272

7373
if (error_code == 0) {
7474
auto elapsed = std::chrono::steady_clock::now() - self->connect_start;
7575
self->connect_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
76-
LOG_INFO("MoQ session established (%d ms): %s", self->connect_time_ms, self->server_url.c_str());
76+
LOG_INFO("MoQ session established (%d ms): %s", self->connect_time_ms,
77+
self->server_url.c_str());
7778
} else {
7879
LOG_INFO("MoQ session closed (%d): %s", error_code, self->server_url.c_str());
7980
}
@@ -151,11 +152,7 @@ void MoQOutput::AudioData(struct encoder_packet *packet)
151152
return;
152153
}
153154

154-
auto pts = util_mul_div64(
155-
packet->pts,
156-
1000000ULL * packet->timebase_num,
157-
packet->timebase_den
158-
);
155+
auto pts = util_mul_div64(packet->pts, 1000000ULL * packet->timebase_num, packet->timebase_den);
159156

160157
auto result = moq_track_write(audio, packet->data, packet->size, pts);
161158
if (result < 0) {
@@ -176,11 +173,7 @@ void MoQOutput::VideoData(struct encoder_packet *packet)
176173
return;
177174
}
178175

179-
auto pts = util_mul_div64(
180-
packet->pts,
181-
1000000ULL * packet->timebase_num,
182-
packet->timebase_den
183-
);
176+
auto pts = util_mul_div64(packet->pts, 1000000ULL * packet->timebase_num, packet->timebase_den);
184177

185178
auto result = moq_track_write(video, packet->data, packet->size, pts);
186179
if (result < 0) {
@@ -212,7 +205,6 @@ void MoQOutput::VideoInit()
212205
auto video_height = obs_encoder_get_height(encoder);
213206
*/
214207

215-
216208
uint8_t *extra_data = nullptr;
217209
size_t extra_size = 0;
218210

src/moq-output.h

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,45 @@
55
#include <string>
66
#include "logger.h"
77

8-
class MoQOutput {
9-
public:
10-
MoQOutput(obs_data_t *settings, obs_output_t *output);
11-
~MoQOutput();
12-
13-
bool Start();
14-
void Stop(bool signal = true);
15-
void Data(struct encoder_packet *packet);
16-
17-
inline size_t GetTotalBytes() { return total_bytes_sent; }
18-
19-
inline int GetConnectTime() { return connect_time_ms; }
20-
21-
private:
22-
void VideoInit();
23-
void VideoData(struct encoder_packet *packet);
24-
void AudioInit();
25-
void AudioData(struct encoder_packet *packet);
26-
27-
obs_output_t *output;
28-
29-
std::string server_url;
30-
std::string path;
31-
32-
size_t total_bytes_sent;
33-
int connect_time_ms;
34-
std::chrono::steady_clock::time_point connect_start;
35-
36-
int session;
37-
int broadcast;
38-
int video;
39-
int audio;
8+
class MoQOutput
9+
{
10+
public:
11+
MoQOutput(obs_data_t *settings, obs_output_t *output);
12+
~MoQOutput();
13+
14+
bool Start();
15+
void Stop(bool signal = true);
16+
void Data(struct encoder_packet *packet);
17+
18+
inline size_t GetTotalBytes()
19+
{
20+
return total_bytes_sent;
21+
}
22+
23+
inline int GetConnectTime()
24+
{
25+
return connect_time_ms;
26+
}
27+
28+
private:
29+
void VideoInit();
30+
void VideoData(struct encoder_packet *packet);
31+
void AudioInit();
32+
void AudioData(struct encoder_packet *packet);
33+
34+
obs_output_t *output;
35+
36+
std::string server_url;
37+
std::string path;
38+
39+
size_t total_bytes_sent;
40+
int connect_time_ms;
41+
std::chrono::steady_clock::time_point connect_start;
42+
43+
int session;
44+
int broadcast;
45+
int video;
46+
int audio;
4047
};
4148

4249
void register_moq_output();

0 commit comments

Comments
 (0)