102 lines
2.2 KiB
Bash
Executable File
102 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
BUILD_DIR="${BUILD_DIR:-$ROOT_DIR/build}"
|
|
SRS_ROOT="${SRS_ROOT:-$HOME/Code/srs}"
|
|
SRS_BIN="${SRS_BIN:-$SRS_ROOT/trunk/objs/srs}"
|
|
SRS_CONF="${SRS_CONF:-$SRS_ROOT/trunk/conf/srs.conf}"
|
|
FFPROBE_BIN="${FFPROBE_BIN:-ffprobe}"
|
|
ENCODER_DEVICE="${ENCODER_DEVICE:-software}"
|
|
|
|
wait_for_port() {
|
|
local host="$1"
|
|
local port="$2"
|
|
for _ in $(seq 1 80); do
|
|
if (echo >"/dev/tcp/${host}/${port}") >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
sleep 0.25
|
|
done
|
|
return 1
|
|
}
|
|
|
|
probe_stream() {
|
|
local stream_name="$1"
|
|
local expected_codec="$2"
|
|
"${FFPROBE_BIN}" \
|
|
-v error \
|
|
-select_streams v:0 \
|
|
-show_entries stream=codec_name,width,height \
|
|
-of default=noprint_wrappers=1 \
|
|
"http://127.0.0.1:8080/live/${stream_name}.flv" |
|
|
tee /dev/stderr |
|
|
grep -q "^codec_name=${expected_codec}$"
|
|
}
|
|
|
|
wait_for_stream() {
|
|
local stream_name="$1"
|
|
local expected_codec="$2"
|
|
for _ in $(seq 1 40); do
|
|
if probe_stream "$stream_name" "$expected_codec"; then
|
|
return 0
|
|
fi
|
|
sleep 0.25
|
|
done
|
|
return 1
|
|
}
|
|
|
|
run_case() {
|
|
local transport="$1"
|
|
local codec="$2"
|
|
local stream_name="cvmmap_${transport}_${codec}_${ENCODER_DEVICE}"
|
|
local expected_codec="$codec"
|
|
if [[ "$codec" == "h265" ]]; then
|
|
expected_codec="hevc"
|
|
fi
|
|
|
|
"${BUILD_DIR}/rtmp_output_tester" \
|
|
--transport "$transport" \
|
|
--codec "$codec" \
|
|
--encoder-device "$ENCODER_DEVICE" \
|
|
--rtmp-url "rtmp://127.0.0.1/live/${stream_name}" \
|
|
--frames 36 \
|
|
--frame-interval-ms 33 \
|
|
--linger-ms 4000 &
|
|
local tester_pid=$!
|
|
|
|
wait_for_stream "$stream_name" "$expected_codec"
|
|
wait "$tester_pid"
|
|
}
|
|
|
|
if [[ ! -x "$SRS_BIN" ]]; then
|
|
echo "SRS binary not found: $SRS_BIN" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$BUILD_DIR"
|
|
SRS_LOG="${BUILD_DIR}/srs-smoke.log"
|
|
|
|
pushd "${SRS_ROOT}/trunk" >/dev/null
|
|
"$SRS_BIN" -c "$SRS_CONF" >"$SRS_LOG" 2>&1 &
|
|
SRS_PID=$!
|
|
popd >/dev/null
|
|
|
|
cleanup() {
|
|
if kill -0 "$SRS_PID" >/dev/null 2>&1; then
|
|
kill "$SRS_PID" >/dev/null 2>&1 || true
|
|
wait "$SRS_PID" >/dev/null 2>&1 || true
|
|
fi
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
wait_for_port 127.0.0.1 1935
|
|
wait_for_port 127.0.0.1 8080
|
|
|
|
run_case libavformat h264
|
|
run_case ffmpeg_process h264
|
|
run_case libavformat h265
|
|
run_case ffmpeg_process h265
|
|
|
|
echo "RTMP SRS smoke tests completed successfully"
|