Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Sync mult srt #744

Open
wants to merge 5 commits into
base: 4.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
56 changes: 56 additions & 0 deletions doc/servermd/RESTAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ Resources:

- /v1.1/rooms/{roomId}/streaming-ins
- /v1.1/rooms/{roomId}/streaming-ins/{streamId}
- /v1.1/rooms/{roomId}/streaming-ins-srt
- /v1.1/rooms/{roomId}/streaming-ins-srt/{streamId}

### Start Streaming-in {#RESTAPIsection5_4_1}
**POST ${host}/v1.1/rooms/{roomId}/streaming-ins**
Expand Down Expand Up @@ -698,6 +700,60 @@ response body:
Description:<br>
Stop the specified external streaming-in in the specified room.<br>

request body:

**Empty**

response body:

**Empty**

### Start SRT Streaming-in {#RESTAPIsection5_4_3}
**POST ${host}/v1.1/rooms/{roomId}/streaming-ins-srt**

Description:<br>
Add an external SRT stream to the specified room.<br>

request body:

| type | content |
|:-------------|:-------|
| json | object(StreamingInSRTRequest) |

**Note**: Here is a definition of *StreamingInSRTRequest*.<br>

Object(StreamingInSRTRequest) {
connection: {
url: string(url), // string, e.g. "srt://...."
mode: "listener" | "caller" | "rendezvous", // "listener" by default.
latency: number(bytes) // The SRT latency with microseconds.
},
media: {
audio: "auto" | true | false,
video: "auto" | true | false
}
}

response body:

| type | content |
|:-------------|:-------|
| json | object(PeerInfo) |

**Note**: Here is a definition of *PeerInfo*.<br>

Object(StreamingInSRTResponse) {
ip: ip of peer device | undefined, //only available when mode is listener
port: srt listener port | undefined, //only available when mode is listener
streamID: srt stream id in OWT
}

### Stop SRT Streaming-in {#RESTAPIsection5_4_4}
**DELETE ${host}/v1.1/rooms/{roomId}/streaming-ins-srt/{streamId}**

Description:<br>
Stop the specified external SRT streaming-in in the specified room.<br>

request body:

**Empty**
Expand Down
19 changes: 17 additions & 2 deletions scripts/installCommonDeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ check_proxy(){
fi
}

install_srt(){
local VERSION="1.4.1"
local SRC="v${VERSION}.tar.gz"
local SRC_URL=" https://github.com/Haivision/srt/archive/${SRC}"
local SRC_DIR="srt-${VERSION}"
mkdir -p ${LIB_DIR}
pushd ${LIB_DIR}
wget ${SRC_URL}
rm -fr ${SRC_DIR}
tar xf ${SRC}
pushd ${SRC_DIR}
./configure --prefix=${PREFIX_DIR}
make && make install
}

install_fdkaac(){
local VERSION="0.1.6"
local SRC="fdk-aac-${VERSION}.tar.gz"
Expand Down Expand Up @@ -67,8 +82,8 @@ install_ffmpeg(){
tar xf ${SRC}
pushd ${DIR}
[[ "${DISABLE_NONFREE}" == "true" ]] && \
PKG_CONFIG_PATH=${PREFIX_DIR}/lib/pkgconfig CFLAGS=-fPIC ./configure --prefix=${PREFIX_DIR} --enable-shared --disable-static --disable-libvpx --disable-vaapi --enable-libfreetype || \
PKG_CONFIG_PATH=${PREFIX_DIR}/lib/pkgconfig CFLAGS=-fPIC ./configure --prefix=${PREFIX_DIR} --enable-shared --disable-static --disable-libvpx --disable-vaapi --enable-libfreetype --enable-libfdk-aac --enable-nonfree && \
PKG_CONFIG_PATH=${PREFIX_DIR}/lib/pkgconfig CFLAGS=-fPIC ./configure --prefix=${PREFIX_DIR} --enable-shared --disable-static --disable-libvpx --disable-vaapi --enable-libfreetype --enable-libsrt || \
PKG_CONFIG_PATH=${PREFIX_DIR}/lib/pkgconfig CFLAGS=-fPIC ./configure --prefix=${PREFIX_DIR} --enable-shared --disable-static --disable-libvpx --disable-vaapi --enable-libfreetype --enable-libfdk-aac --enable-nonfree --enable-libsrt && \
make -j4 -s V=0 && make install
popd
popd
Expand Down
2 changes: 2 additions & 0 deletions scripts/installUbuntuDeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ install_apt_deps(){
}

install_mediadeps_nonfree(){
install_srt
install_fdkaac
install_ffmpeg
}

install_mediadeps(){
install_srt
install_ffmpeg
}

Expand Down
1 change: 1 addition & 0 deletions scripts/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ function isLibAllowed(libSrc) {
'librawquic'
];
if (!options['archive'] || options['with-ffmpeg']) {
whiteList.push('libsrt');
whiteList.push('libav');
whiteList.push('libsw');
}
Expand Down
1 change: 1 addition & 0 deletions scripts/release/init-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ init_software()
${ROOT}/management_api/init.sh
${ROOT}/webrtc_agent/install_deps.sh
${ROOT}/video_agent/install_deps.sh
${ROOT}/streaming_agent/install_ffmpeg.sh --enable-srt
${ROOT}/video_agent/init.sh
copy_video_libs
else
Expand Down
60 changes: 58 additions & 2 deletions scripts/release/install_ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,31 @@
this=`dirname "$0"`
this=`cd "$this"; pwd`
SUDO=""
ENABLE_SRT=false
if [[ $EUID -ne 0 ]]; then
SUDO="sudo -E"
fi

echo "Streaming agent install ffmpeg"
echo $1

parse_arguments(){
while [ "$1" != "" ]; do
case $1 in
"--enable-srt")
echo "Enable SRT"
ENABLE_SRT=true
;;
"--cleanup")
CLEANUP=true
;;
esac
shift
done
}



detect_OS() {
lsb_release >/dev/null 2>/dev/null
if [ $? = 0 ]
Expand Down Expand Up @@ -57,16 +78,40 @@ install_build_deps() {
then
echo -e "\x1b[32mInstalling dependent components and libraries via yum...\x1b[0m"
${SUDO} yum install pkg-config make gcc gcc-c++ nasm yasm freetype-devel -y
if [ "$ENABLE_SRT" = "true" ]; then
${SUDO} yum install tcl openssl-devel cmake automake -y
fi
elif [[ "$OS" =~ .*ubuntu.* ]]
then
echo -e "\x1b[32mInstalling dependent components and libraries via apt-get...\x1b[0m"
${SUDO} apt-get update
${SUDO} apt-get install pkg-config make gcc g++ nasm yasm libfreetype6-dev -y
if [ "$ENABLE_SRT" = "true" ]; then
${SUDO} apt-get install tcl cmake libssl-dev build-essential -y
fi
else
echo -e "\x1b[32mUnsupported platform...\x1b[0m"
fi
}

install_srt(){
local VERSION="1.4.1"
local SRC="v${VERSION}.tar.gz"
local SRC_URL=" https://github.com/Haivision/srt/archive/${SRC}"
local SRC_DIR="srt-${VERSION}"
local PREFIX_DIR="${this}/ffmpeg-install"
mkdir -p ${LIB_DIR}
pushd ${LIB_DIR}
wget ${SRC_URL}
rm -fr ${SRC_DIR}
tar xf ${SRC}
pushd ${SRC_DIR}
./configure --prefix=${PREFIX_DIR}
make && make install
popd
popd
}

install_ffmpeg(){
local VERSION="4.1.3"
local DIR="ffmpeg-${VERSION}"
Expand All @@ -88,8 +133,13 @@ install_ffmpeg(){
rm -fr ${DIR}
tar xf ${SRC}
pushd ${DIR} >/dev/null
CFLAGS=-fPIC ./configure --prefix=${PREFIX_DIR} --enable-shared \
--disable-static --disable-libvpx --disable-vaapi --enable-libfreetype
if [ "$ENABLE_SRT" = "true" ]; then
PKG_CONFIG_PATH=${PREFIX_DIR}/lib/pkgconfig CFLAGS=-fPIC ./configure --prefix=${PREFIX_DIR} --enable-shared \
--disable-static --disable-libvpx --disable-vaapi --enable-libfreetype --enable-libsrt
else
CFLAGS=-fPIC ./configure --prefix=${PREFIX_DIR} --enable-shared \
--disable-static --disable-libvpx --disable-vaapi --enable-libfreetype
fi
make -j4 -s V=0 && make install
popd
popd
Expand All @@ -98,8 +148,14 @@ install_ffmpeg(){
cp -P ${PREFIX_DIR}/lib/*.so ${this}/lib/
}

parse_arguments $*

echo "Install building dependencies..."
install_build_deps

if [ "$ENABLE_SRT" = "true" ]; then
install_srt
fi

echo "Install ffmpeg..."
install_ffmpeg
4 changes: 2 additions & 2 deletions source/agent/conference/accessController.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ module.exports.create = function(spec, rpcReq, onSessionEstablished, onSessionAb
direction,
options);
})
.then(function() {
.then(function(result) {
log.debug('Initiate ok, participantId:', participantId, 'sessionId:', sessionId);
if (sessions[sessionId] === undefined) {
log.debug('Session has been aborted, sessionId:', sessionId);
Expand All @@ -243,7 +243,7 @@ module.exports.create = function(spec, rpcReq, onSessionEstablished, onSessionAb
return Promise.reject('Session has been aborted');
}
sessions[sessionId].state = 'connecting';
return 'ok';
return result;
}, (e) => {
delete sessions[sessionId];
return Promise.reject(e.message ? e.message : e);
Expand Down
56 changes: 56 additions & 0 deletions source/agent/conference/conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,61 @@ var Conference = function (rpcClient, selfRpcId) {
}
};

that.addStreamingInSRT = function(roomId, pubInfo, callback) {
pubInfo.connection.type = 'srt';
log.debug('addStreamingInSRT, roomId:', roomId, 'pubInfo:', JSON.stringify(pubInfo));

if (pubInfo.type === 'streaming') {
var stream_id = Math.round(Math.random() * 1000000000000000000) + '';
return initRoom(roomId)
.then(() => {
if (room_config.inputLimit >= 0 && (room_config.inputLimit <= currentInputCount())) {
return Promise.reject('Too many inputs');
}

if (pubInfo.media.audio && !room_config.mediaIn.audio.length) {
return Promise.reject('Audio is forbiden');
}

if (pubInfo.media.video && !room_config.mediaIn.video.length) {
return Promise.reject('Video is forbiden');
}

initiateStream(stream_id, {owner: 'admin', type: pubInfo.type});
return accessController.initiate('admin', stream_id, 'in', participants['admin'].getOrigin(), pubInfo);
}).then((result) => {
log.info("accessController initate success with result:", result);
callback('callback', result);
return 'ok';
}).then(() => {
return new Promise((resolve, reject) => {
var count = 0, wait = 1420;
var interval = setInterval(() => {
if (count > wait || !streams[stream_id]) {
clearInterval(interval);
accessController.terminate('admin', stream_id, 'Participant terminate');
removeStream(stream_id);
reject('Access timeout');
} else {
if (streams[stream_id] && !streams[stream_id].isInConnecting) {
clearInterval(interval);
resolve('ok');
} else {
count = count + 1;
}
}
}, 60);
});
}).catch((e) => {
callback('callback', 'error', e.message ? e.message : e);
removeStream(stream_id);
selfClean();
});
} else {
callback('callback', 'error', 'Invalid publication type');
}
};

const getRational = (str) => {
if (str === '0') {
return {numerator: 0, denominator: 1};
Expand Down Expand Up @@ -2526,6 +2581,7 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
getStreams: conference.getStreams,
getStreamInfo: conference.getStreamInfo,
addStreamingIn: conference.addStreamingIn,
addStreamingInSRT: conference.addStreamingInSRT,
controlStream: conference.controlStream,
deleteStream: conference.deleteStream,
getSubscriptions: conference.getSubscriptions,
Expand Down
11 changes: 11 additions & 0 deletions source/agent/streaming/agent.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,16 @@ ip_address = "" #default: ""
maxport = 0 #default: 0
minport = 0 #default: 0

[external]
#The IP address used for SRT listener address. Will use the IP got from the 'network_interface' item on the device if 'ip_address' is not specified or equal to "".
ip_address = "" #default: ""

#The network_interface whose SRT listener address to listen to SRT caller. The first 'IPv4' enumerated network interface in the system will be adopted if this item is not specified.
network_interface = "" # default: undefined

# The SRT listening UDP port range
maxport = 0 #default: 0
minport = 0 #default: 0

[avstream]
initialize_timeout = 3000 #default: 3000
2 changes: 1 addition & 1 deletion source/agent/streaming/dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "streaming-agent",
"dest": "streaming_agent",
"common": {
"package": "../package.json",
"package": "package.json",
"files": [
"agent.toml",
"log4js_configuration.json",
Expand Down
Loading