Skip to content

Commit e1e1f04

Browse files
wysaidCopilot
andcommitted
ci: add video writer test execution to macOS and Windows CI
- Add --writer flag to run_tests.sh for running ccap_video_writer_test - Add writer test step to macOS CI workflow (Release builds) - Add writer test step to Windows CI workflow (VS2022/VS2026/MinGW Release) - On Linux the writer test binary is not built (unsupported platform), so the script gracefully skips without error - Apply code formatting fixes from format_all.sh Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 98b7ab2 commit e1e1f04

5 files changed

Lines changed: 100 additions & 14 deletions

File tree

.github/workflows/macos-build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ jobs:
132132
133133
# Run video file playback tests (Release only)
134134
./run_tests.sh --video --skip-build
135+
136+
# Run video writer tests (Release only, macOS/Windows)
137+
./run_tests.sh --writer --skip-build
135138
fi
136139
137140
- name: Upload artifacts

.github/workflows/windows-build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ jobs:
207207
208208
# Run video file playback tests (Release only)
209209
./run_tests.sh --video --skip-build
210+
211+
# Run video writer tests (Release only, macOS/Windows)
212+
./run_tests.sh --writer --skip-build
210213
fi
211214
212215
- name: Upload artifacts
@@ -468,6 +471,9 @@ jobs:
468471
469472
# Run video file playback tests (Release only)
470473
./run_tests.sh --video --skip-build
474+
475+
# Run video writer tests (Release only, macOS/Windows)
476+
./run_tests.sh --writer --skip-build
471477
fi
472478
473479
- name: Upload artifacts
@@ -631,6 +637,9 @@ jobs:
631637
632638
# Run video file playback tests (Release only)
633639
./run_tests.sh --video --skip-build
640+
641+
# Run video writer tests (Release only, macOS/Windows)
642+
./run_tests.sh --writer --skip-build
634643
fi
635644
636645
- name: Upload artifacts

examples/desktop/6-record_video_c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int main(int argc, char** argv) {
131131
writerConfig.width = (uint32_t)realWidth;
132132
writerConfig.height = (uint32_t)realHeight;
133133
writerConfig.frameRate = realFps > 0.0 ? realFps : 30.0;
134-
writerConfig.bitRate = 0; // auto bit rate based on resolution and codec (YouTube recommended)
134+
writerConfig.bitRate = 0; // auto bit rate based on resolution and codec (YouTube recommended)
135135

136136
CcapVideoWriter* writer = ccap_video_writer_create();
137137
if (!writer) {

scripts/run_tests.sh

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# ./run_tests.sh --functional # Run only functional tests (with ASAN)
1919
# ./run_tests.sh --performance # Run only performance tests (without ASAN)
2020
# ./run_tests.sh --video # Run only video file playback tests (Release mode)
21+
# ./run_tests.sh --writer # Run only video writer tests (Release mode, macOS/Windows)
2122
# ./run_tests.sh --avx2 # Run only AVX2 performance tests
2223
# ./run_tests.sh --shuffle # Run only tests with names containing 'shuffle' (case-insensitive) in functional tests
2324
# ./run_tests.sh --no-sanitize # Disable ASAN for all tests
@@ -75,6 +76,7 @@ RUN_ALL=false
7576
RUN_FUNCTIONAL=true
7677
RUN_PERFORMANCE=true
7778
RUN_VIDEO=false
79+
RUN_WRITER=false
7880
SKIP_BUILD=false
7981
EXIT_WHEN_FAILED=false
8082
GTEST_FAIL_FAST_PARAM=""
@@ -91,6 +93,7 @@ while [[ $# -gt 0 ]]; do
9193
RUN_FUNCTIONAL=true
9294
RUN_PERFORMANCE=true
9395
RUN_VIDEO=true
96+
RUN_WRITER=true
9497
shift
9598
;;
9699
-f | --functional)
@@ -116,6 +119,13 @@ while [[ $# -gt 0 ]]; do
116119
RUN_VIDEO=true
117120
shift
118121
;;
122+
--writer)
123+
# Video writer tests only (Release mode, macOS/Windows only)
124+
RUN_FUNCTIONAL=false
125+
RUN_PERFORMANCE=false
126+
RUN_WRITER=true
127+
shift
128+
;;
119129
--shuffle)
120130
# Functional only, and later restrict to tests containing 'shuffle' (case-insensitive)
121131
RUN_FUNCTIONAL=true
@@ -151,6 +161,7 @@ while [[ $# -gt 0 ]]; do
151161
echo " $0 --functional # Run only functional tests (Debug mode, with ASAN)"
152162
echo " $0 --performance # Run only performance tests (Release mode, without ASAN)"
153163
echo " $0 --video # Run only video file playback tests (Release mode)"
164+
echo " $0 --writer # Run only video writer tests (Release mode, macOS/Windows)"
154165
echo " $0 --avx2 # Run only AVX2 performance tests (Release mode)"
155166
echo " $0 --shuffle # Run only tests whose names contain '*shuffle*' or '*Shuffle*' in functional tests"
156167
echo " $0 --skip-build # Skip build step, run tests only"
@@ -215,6 +226,7 @@ fi
215226
TEST_RESULT=0
216227
PERF_RESULT=0
217228
VIDEO_RESULT=0
229+
WRITER_RESULT=0
218230

219231
# Determine ASAN usage
220232
# Functional tests: default enabled, Performance tests: default disabled
@@ -317,13 +329,15 @@ if [ "$RUN_FUNCTIONAL" = true ]; then
317329
fi
318330

319331
# Build Release version for performance tests or video tests
320-
if [ "$RUN_PERFORMANCE" = true ] || [ "$RUN_VIDEO" = true ]; then
332+
if [ "$RUN_PERFORMANCE" = true ] || [ "$RUN_VIDEO" = true ] || [ "$RUN_WRITER" = true ]; then
321333
echo ""
322334
echo -e "${PURPLE}===============================================${NC}"
323335
if [ "$SKIP_BUILD" = true ]; then
324336
echo -e "${BLUE}Skipping build, using existing Release binaries${NC}"
325337
else
326-
if [ "$RUN_VIDEO" = true ]; then
338+
if [ "$RUN_WRITER" = true ] && [ "$RUN_VIDEO" != true ] && [ "$RUN_PERFORMANCE" != true ]; then
339+
echo -e "${BLUE}Building Release version (for video writer tests)${NC}"
340+
elif [ "$RUN_VIDEO" = true ]; then
327341
echo -e "${BLUE}Building Release version (for video file playback tests)${NC}"
328342
else
329343
echo -e "${BLUE}Building Release version (for performance tests)${NC}"
@@ -365,6 +379,9 @@ if [ "$RUN_PERFORMANCE" = true ] || [ "$RUN_VIDEO" = true ]; then
365379
if [ "$RUN_VIDEO" = true ]; then
366380
cmake --build . --config Release --target ccap_file_playback_test --parallel $(detectCores)
367381
fi
382+
if [ "$RUN_WRITER" = true ]; then
383+
cmake --build . --config Release --target ccap_video_writer_test --parallel $(detectCores)
384+
fi
368385
cd ..
369386
else
370387
# Linux/Mac: use separate Release directory
@@ -386,6 +403,9 @@ if [ "$RUN_PERFORMANCE" = true ] || [ "$RUN_VIDEO" = true ]; then
386403
if [ "$RUN_VIDEO" = true ]; then
387404
cmake --build . --config Release --target ccap_file_playback_test --parallel $(detectCores)
388405
fi
406+
if [ "$RUN_WRITER" = true ]; then
407+
cmake --build . --config Release --target ccap_video_writer_test --parallel $(detectCores)
408+
fi
389409
cd ../..
390410
fi
391411
fi
@@ -564,6 +584,45 @@ if [ "$RUN_VIDEO" = true ]; then
564584
fi
565585
fi
566586

587+
# Run video writer tests in Release mode (macOS/Windows only)
588+
WRITER_RESULT=0
589+
if [ "$RUN_WRITER" = true ]; then
590+
echo ""
591+
echo "==============================================="
592+
echo -e "${GREEN}Running Video Writer Tests (Release)${NC}"
593+
echo "==============================================="
594+
595+
# Determine test executable path based on platform
596+
if isWindows; then
597+
WRITER_EXECUTABLE="./build/tests/Release/ccap_video_writer_test.exe"
598+
else
599+
WRITER_EXECUTABLE="./build/Release/tests/ccap_video_writer_test"
600+
fi
601+
602+
if [ -f "$WRITER_EXECUTABLE" ]; then
603+
echo -e "${YELLOW}Running video writer tests in Release mode...${NC}"
604+
605+
"$WRITER_EXECUTABLE" $GTEST_FAIL_FAST_PARAM --gtest_output=xml:build/writer_test_results_release.xml
606+
607+
WRITER_RESULT=$?
608+
609+
if [ $WRITER_RESULT -eq 0 ]; then
610+
echo -e "${GREEN}✓ Video writer tests PASSED${NC}"
611+
else
612+
echo -e "${RED}✗ Video writer tests FAILED${NC}"
613+
if [ "$EXIT_WHEN_FAILED" = true ]; then
614+
echo -e "${RED}❌ Exiting due to --exit-when-failed flag${NC}"
615+
exit 1
616+
fi
617+
fi
618+
else
619+
echo -e "${YELLOW}⚠ ccap_video_writer_test executable not found at $WRITER_EXECUTABLE${NC}"
620+
echo -e "${YELLOW} Video writer is only available on Windows and macOS with CCAP_ENABLE_VIDEO_WRITER=ON${NC}"
621+
# Not a failure on Linux - writer is not supported there
622+
WRITER_RESULT=0
623+
fi
624+
fi
625+
567626
echo ""
568627
echo "==============================================="
569628
echo -e "${GREEN}Test Summary${NC}"
@@ -584,6 +643,10 @@ if [ "$RUN_VIDEO" = true ] && [ $VIDEO_RESULT -ne 0 ]; then
584643
OVERALL_RESULT=1
585644
fi
586645

646+
if [ "$RUN_WRITER" = true ] && [ $WRITER_RESULT -ne 0 ]; then
647+
OVERALL_RESULT=1
648+
fi
649+
587650
if [ $OVERALL_RESULT -eq 0 ]; then
588651
echo -e "${GREEN}🎉 All tests PASSED!${NC}"
589652

@@ -601,6 +664,9 @@ if [ $OVERALL_RESULT -eq 0 ]; then
601664
if [ "$RUN_VIDEO" = true ]; then
602665
echo -e "${GREEN} ✓ Video file playback tests (Release mode)${NC}"
603666
fi
667+
if [ "$RUN_WRITER" = true ]; then
668+
echo -e "${GREEN} ✓ Video writer tests (Release mode)${NC}"
669+
fi
604670

605671
exit 0
606672
else
@@ -614,5 +680,8 @@ else
614680
if [ "$RUN_VIDEO" = true ] && [ $VIDEO_RESULT -ne 0 ]; then
615681
echo -e "${RED} - Video file playback tests failed${NC}"
616682
fi
683+
if [ "$RUN_WRITER" = true ] && [ $WRITER_RESULT -ne 0 ]; then
684+
echo -e "${RED} - Video writer tests failed${NC}"
685+
fi
617686
exit 1
618687
fi

src/ccap_writer_imp.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,21 @@ inline uint64_t computeAutoBitRate(uint32_t width, uint32_t height, double frame
5858
const bool is60fps = fps > 45.0;
5959

6060
// YouTube H.264 reference data points: (pixelCount, bitrateInMbps)
61-
struct RefPoint { double pixels; double bitrateMbps; };
61+
struct RefPoint {
62+
double pixels;
63+
double bitrateMbps;
64+
};
6265
static const RefPoint refs30[] = {
63-
{1280 * 720, 7.5},
64-
{1920 * 1080, 10.0},
65-
{2560 * 1440, 15.0},
66-
{3840 * 2160, 30.0},
66+
{ 1280 * 720, 7.5 },
67+
{ 1920 * 1080, 10.0 },
68+
{ 2560 * 1440, 15.0 },
69+
{ 3840 * 2160, 30.0 },
6770
};
6871
static const RefPoint refs60[] = {
69-
{1280 * 720, 9.0},
70-
{1920 * 1080, 12.0},
71-
{2560 * 1440, 24.0},
72-
{3840 * 2160, 35.0},
72+
{ 1280 * 720, 9.0 },
73+
{ 1920 * 1080, 12.0 },
74+
{ 2560 * 1440, 24.0 },
75+
{ 3840 * 2160, 35.0 },
7376
};
7477

7578
const RefPoint* refs = is60fps ? refs60 : refs30;
@@ -89,7 +92,8 @@ inline uint64_t computeAutoBitRate(uint32_t width, uint32_t height, double frame
8992
} else {
9093
// Between reference points: linear interpolation by pixel count
9194
int i = 0;
92-
while (i < refCount - 1 && pixels > refs[i + 1].pixels) i++;
95+
while (i < refCount - 1 && pixels > refs[i + 1].pixels)
96+
i++;
9397
const auto& lo = refs[i];
9498
const auto& hi = refs[i + 1];
9599
double t = (pixels - lo.pixels) / (hi.pixels - lo.pixels);
@@ -102,7 +106,8 @@ inline uint64_t computeAutoBitRate(uint32_t width, uint32_t height, double frame
102106
const auto& r60 = refs60;
103107
// Average ratio across reference points
104108
double ratio = 0;
105-
for (int i = 0; i < refCount; i++) ratio += r60[i].bitrateMbps / r30[i].bitrateMbps;
109+
for (int i = 0; i < refCount; i++)
110+
ratio += r60[i].bitrateMbps / r30[i].bitrateMbps;
106111
ratio /= refCount; // ~1.27
107112
double t = (fps - 30.0) / 30.0;
108113
bitrateMbps *= (1.0 + t * (ratio - 1.0));

0 commit comments

Comments
 (0)