diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f1c423121..bbfbd27d2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,14 +18,17 @@ jobs: uses: actions/checkout@v2 # The github.ref is, for example, refs/tags/v4.0.145 or refs/tags/v4.0-r8 # Generate variables like: - # SRS_TAG=v4.0.145 # SRS_TAG=v4.0-r8 + # SRS_TAG=v4.0.145 + # SRS_VERSION=4.0.145 # SRS_MAJOR=4 # @see https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable - name: Generate varaiables run: | SRS_TAG=$(echo ${{ github.ref }}| awk -F '/' '{print $3}') echo "SRS_TAG=$SRS_TAG" >> $GITHUB_ENV + SRS_VERSION=$(echo ${SRS_TAG}| sed 's/^v//g') + echo "SRS_VERSION=$SRS_VERSION" >> $GITHUB_ENV SRS_MAJOR=$(echo $SRS_TAG| cut -c 2) echo "SRS_MAJOR=$SRS_MAJOR" >> $GITHUB_ENV # Create source tar for release. Note that it's for OpenWRT package srs-server, so the filename MUST be @@ -35,12 +38,24 @@ jobs: # SRS_SOURCE_MD5=83e38700a80a26e30b2df054e69956e5 - name: Create source tar.gz run: | - DEST_DIR=srs-server-$(echo ${SRS_TAG}| sed 's/^v//g') && mkdir -p $DEST_DIR && + DEST_DIR=srs-server-$SRS_VERSION && mkdir -p $DEST_DIR && cp README.md $DEST_DIR && cp LICENSE $DEST_DIR && cp -R trunk $DEST_DIR/trunk && (cd $DEST_DIR/trunk/3rdparty && rm -rf *.zip openssl-*.gz srs-bench) && tar zcf ${DEST_DIR}.tar.gz ${DEST_DIR} && du -sh ${DEST_DIR}* && rm -rf ${DEST_DIR} && echo "SRS_SOURCE_TAR=${DEST_DIR}.tar.gz" >> $GITHUB_ENV && echo "SRS_SOURCE_MD5=$(md5sum ${DEST_DIR}.tar.gz| awk '{print $1}')" >> $GITHUB_ENV + # Create package tar for release + # Generate variables like: + # SRS_PACKAGE_ZIP=SRS-CentOS7-x86_64-4.0.145.zip + # SRS_PACKAGE_MD5=3880a26e30b283edf05700a4e69956e5 + - name: Create package zip + run: | + docker build --tag srs:pkg --build-arg version=$SRS_VERSION -f trunk/Dockerfile.pkg . && + SRS_PACKAGE_ZIP=SRS-CentOS7-x86_64-$SRS_VERSION.zip && + docker run --rm -v $(pwd):/output srs:pkg cp objs/$SRS_PACKAGE_ZIP /output/ && + du -sh $SRS_PACKAGE_ZIP && + echo "SRS_PACKAGE_ZIP=$SRS_PACKAGE_ZIP" >> $GITHUB_ENV && + echo "SRS_PACKAGE_MD5=$(md5sum $SRS_PACKAGE_ZIP| awk '{print $1}')" >> $GITHUB_ENV ################################################################ # Tests @@ -116,15 +131,25 @@ jobs: body: | ${{ github.event.head_commit.message }} ${{ env.SRS_SOURCE_MD5 }} [${{ env.SRS_SOURCE_TAR }}](https://github.com/ossrs/srs/releases/download/${{ env.SRS_TAG }}/${{ env.SRS_SOURCE_TAR }}) + ${{ env.SRS_PACKAGE_MD5 }} [${{ env.SRS_PACKAGE_ZIP }}](https://github.com/ossrs/srs/releases/download/${{ env.SRS_TAG }}/${{ env.SRS_PACKAGE_ZIP }}) draft: false prerelease: true - # Upload release files - - name: Upload Release Assets - id: upload-release-assets + # Upload release source files + - name: Upload Release Assets Source + id: upload-release-assets-source uses: dwenegar/upload-release-assets@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_id: ${{ steps.create_release.outputs.id }} assets_path: ${{ env.SRS_SOURCE_TAR }} + # Upload release package files + - name: Upload Release Assets Package + id: upload-release-assets-package + uses: dwenegar/upload-release-assets@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ steps.create_release.outputs.id }} + assets_path: ${{ env.SRS_PACKAGE_ZIP }} diff --git a/README.md b/README.md index 4162c34d6..b8852d5c1 100755 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ A big `THANK YOU` also goes to: ## Releases -* 2021-10-28, Release [v4.0.187](https://github.com/ossrs/srs/releases/tag/v4.0.187), 4.0 dev7, v4.0.187, 143831 lines. +* 2021-11-02, Release [v4.0.191](https://github.com/ossrs/srs/releases/tag/v4.0.191), 4.0 dev7, v4.0.191, 143890 lines. * 2021-10-12, Release [v4.0.177](https://github.com/ossrs/srs/releases/tag/v4.0.177), 4.0 dev6, v4.0.177, 143686 lines. * 2021-09-05, Release [v4.0.161](https://github.com/ossrs/srs/releases/tag/v4.0.161), 4.0 dev5, v4.0.161, 145865 lines. * 2021-08-15, Release [v4.0.156](https://github.com/ossrs/srs/releases/tag/v4.0.156), 4.0 dev4, v4.0.156, 145490 lines. diff --git a/trunk/Dockerfile.pkg b/trunk/Dockerfile.pkg new file mode 100644 index 000000000..e6b74172d --- /dev/null +++ b/trunk/Dockerfile.pkg @@ -0,0 +1,16 @@ +FROM ossrs/srs:dev + +# version=4.0.145 +ARG version + +# Install depends tools. +RUN yum install -y zip + +# Setup the packager env. +ENV SRS_AUTO_PACKAGER ossrs + +# Build and install SRS. +ADD srs-server-${version}.tar.gz /srs +WORKDIR /srs/srs-server-${version}/trunk +RUN ./scripts/package.sh --x86-x64 --jobs=2 + diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index d5f5aff3f..dea714815 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -30,6 +30,8 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2021-11-04, Merge [#2707](https://github.com/ossrs/srs/pull/2707): Refuse edge request when state is stopping. v4.0.192 +* v4.0, 2021-11-02, Auto create package by github actions. v4.0.191 * v4.0, 2021-10-30, Merge [#2552](https://github.com/ossrs/srs/pull/2552): Script: Refine CentOS7 service script to restart SRS. v4.0.190 * v4.0, 2021-10-30, Merge [#2397](https://github.com/ossrs/srs/pull/2397): SRTP: Patch libsrtp2 to fix GCC10 build fail. v4.0.189 * v4.0, 2021-10-30, Merge [#2284](https://github.com/ossrs/srs/pull/2284): Forward: Fast quit when cycle fail. v4.0.188 diff --git a/trunk/packaging/redhat/srs.conf b/trunk/packaging/redhat/srs.conf new file mode 100644 index 000000000..221c352a4 --- /dev/null +++ b/trunk/packaging/redhat/srs.conf @@ -0,0 +1,50 @@ +# main config for srs. +# @see full.conf for detail config. + +daemon off; +pid /var/lib/srs/srs.pid; +work_dir /var/lib/srs; +listen 1935; +max_connections 1000; +srs_log_tank file; +srs_log_file /var/log/srs/srs.log; + +http_api { + enabled on; + listen 1985; +} + +http_server { + enabled on; + listen 8080; + dir /usr/share/srs/html; +} + +rtc_server { + enabled on; + listen 8000; + # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#config-candidate + candidate $CANDIDATE; +} + +stats { + network 0; + disk sda sdb xvda xvdb; +} + +vhost __defaultVhost__ { + hls { + enabled on; + } + http_remux { + enabled on; + mount [vhost]/[app]/[stream].flv; + } + rtc { + enabled on; + # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtmp-to-rtc + rtmp_to_rtc off; + # @see https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#rtc-to-rtmp + rtc_to_rtmp off; + } +} diff --git a/trunk/packaging/redhat/srs.init b/trunk/packaging/redhat/srs.init new file mode 100644 index 000000000..c0a6ec2f9 --- /dev/null +++ b/trunk/packaging/redhat/srs.init @@ -0,0 +1,76 @@ +#!/bin/sh +# +# srs - a simple, high efficiency and realtime video server +# +# chkconfig: + +### BEGIN INIT INFO +# Provides: srs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: a simple, high efficiency and realtime video server +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +exec="/usr/bin/srs" +prog=${exec##*/} +configfile=/etc/srs/srs.conf + +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog + +lockfile=/var/lock/subsys/$prog + +start() { + echo -n $"Starting $prog: " + daemon --user nobody $exec -c $configfile + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping $prog: " + killproc $exec -TERM + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +reload() { + echo -n $"reloading $prog: " + killproc $exec -HUP + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +rotate() { + echo -n $"logrotate $prog: " + killproc $exec -USR1 + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +case "$1" in + start|stop|restart|reload|rotate) + $1 + ;; + status) + status $prog + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|reload|rotate}" + exit 2 +esac diff --git a/trunk/packaging/redhat/srs.logrotate b/trunk/packaging/redhat/srs.logrotate new file mode 100644 index 000000000..5823687df --- /dev/null +++ b/trunk/packaging/redhat/srs.logrotate @@ -0,0 +1,15 @@ +/var/log/srs/*.log { + daily + missingok + rotate 30 + compress + delaycompress + notifempty + create 640 root nobody + sharedscripts + postrotate + if [ -f /var/lib/srs/srs.pid ]; then + kill -USR1 `cat /var/lib/srs/srs.pid` + fi + endscript +} diff --git a/trunk/packaging/redhat/srs.service b/trunk/packaging/redhat/srs.service new file mode 100644 index 000000000..97b3a9283 --- /dev/null +++ b/trunk/packaging/redhat/srs.service @@ -0,0 +1,23 @@ +[Unit] +Description=srs - a simple, high efficiency and realtime video server +Documentation=https://github.com/ossrs/srs/wiki +After=network-online.target remote-fs.target nss-lookup.target +Wants=network-online.target + +[Service] +Type=simple +User=nobody +Group=nobody +WorkingDirectory=/var/lib/srs +EnvironmentFile=-/etc/sysconfig/srs +PIDFile=/var/lib/srs/srs.pid +ExecStartPre=/usr/bin/srs -c /etc/srs/srs.conf -t +ExecStart=/usr/bin/srs -c /etc/srs/srs.conf +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s TERM $MAINPID +Restart=on-failure +PrivateTmp=true + +[Install] +WantedBy=multi-user.target + diff --git a/trunk/packaging/redhat/srs.spec b/trunk/packaging/redhat/srs.spec new file mode 100644 index 000000000..654854fde --- /dev/null +++ b/trunk/packaging/redhat/srs.spec @@ -0,0 +1,103 @@ +%define use_systemd (0%{?fedora} && 0%{?fedora} >= 18) || (0%{?rhel} && 0%{?rhel} >= 7) || (0%{?suse_version} == 1315) + +Name: srs +Version: 3.0.168 +Release: 1%{?dist} +Summary: a simple, high efficiency and realtime video server + +License: MIT +URL: https://github.com/ossrs/srs +Source0: %{name}-3.0-r8.tar.gz +Source1: srs.conf +Source2: srs.service +Source3: srs.init +Source4: srs.logrotate + +BuildRequires: python +BuildRequires: rsync + +%if %{use_systemd} +BuildRequires: systemd +Requires: systemd +%else +BuildRequires: initscripts +Requires: initscripts +%endif + +%description +SRS is a simple, high efficiency and realtime video server, supports RTMP/WebRTC/HLS/HTTP-FLV/SRT. + +%prep +%setup -q -n srs-3.0-r8 + +%build +cd trunk +./configure --prefix=/usr +make %{?_smp_mflags} + +%install +rm -rf $RPM_BUILD_ROOT + +%{__mkdir_p} $RPM_BUILD_ROOT%{_bindir} +%{__mkdir_p} $RPM_BUILD_ROOT%{_initrddir} +%{__mkdir_p} $RPM_BUILD_ROOT%{_datadir}/%{name} +%{__mkdir_p} $RPM_BUILD_ROOT%{_sharedstatedir}/%{name} +%{__mkdir_p} $RPM_BUILD_ROOT%{_localstatedir}/log/%{name} + +%{__install} -m 755 trunk/objs/srs $RPM_BUILD_ROOT%{_bindir} + +#http_server file +rsync -aqL --delete trunk/objs/nginx/ $RPM_BUILD_ROOT%{_datadir}/%{name}/ + +#%{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/%{name} +%{__install} -D -m 644 trunk/packaging/redhat/srs.conf $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/srs.conf + +#init files +%if %{use_systemd} +%{__mkdir} -p $RPM_BUILD_ROOT%{_unitdir} +%{__install} -p -m 644 trunk/packaging/redhat/srs.service $RPM_BUILD_ROOT%{_unitdir}/srs.service +%else +%{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir} +%{__install} -p -m 755 trunk/packaging/redhat/srs.init $RPM_BUILD_ROOT%{_initrddir}/srs +sed -i 's/daemon/{s/off/on/g}' %{_sysconfdir}/%{name}/srs.conf +%endif + +#logrotate +%{__install} -D -p -m 644 trunk/packaging/redhat/srs.logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/srs + + +%pre +# Add the "srs" user +# getent group srs >/dev/null || groupadd -r srs +# getent passwd srs >/dev/null || useradd -r -g srs -s /sbin/nologin -d /var/lib/srs srs + +%post +%if %{use_systemd} +%systemd_post %{name}.service +%endif + +%preun +%if %{use_systemd} +%systemd_preun %{name}.service +%endif + +%files +%defattr(-,root,root,-) +%{_bindir}/* +%config(noreplace) %{_sysconfdir}/srs/srs.conf +%{_sysconfdir}/logrotate.d/srs +%{_datadir}/%{name} +%dir %attr(0755, nobody, nobody) %{_localstatedir}/log/%{name} +%dir %attr(0755, nobody, nobody) %{_sharedstatedir}/%{name} +%doc trunk/conf +%license LICENSE + +%if %{use_systemd} +%{_unitdir}/srs.service +%else +%{_initrddir}/%{name} +%endif + +%changelog +* Mon Nov 1 2021 Purple Grape +- rpm init diff --git a/trunk/src/app/srs_app_rtc_api.cpp b/trunk/src/app/srs_app_rtc_api.cpp index d9b0c97c5..df0ae4b52 100644 --- a/trunk/src/app/srs_app_rtc_api.cpp +++ b/trunk/src/app/srs_app_rtc_api.cpp @@ -237,10 +237,8 @@ srs_error_t SrsGoApiRtcPlay::check_remote_sdp(const SrsSdp& remote_sdp) return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "now only suppor rtcp-mux"); } - for (std::vector::const_iterator iter_media = iter->payload_types_.begin(); iter_media != iter->payload_types_.end(); ++iter_media) { - if (iter->sendonly_) { - return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "play API only support sendrecv/recvonly"); - } + if (iter->sendonly_) { + return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "play API only support sendrecv/recvonly"); } } @@ -489,10 +487,8 @@ srs_error_t SrsGoApiRtcPublish::check_remote_sdp(const SrsSdp& remote_sdp) return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "now only suppor rtcp-mux"); } - for (std::vector::const_iterator iter_media = iter->payload_types_.begin(); iter_media != iter->payload_types_.end(); ++iter_media) { - if (iter->recvonly_) { - return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "publish API only support sendrecv/sendonly"); - } + if (iter->recvonly_) { + return srs_error_new(ERROR_RTC_SDP_EXCHANGE, "publish API only support sendrecv/sendonly"); } } diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index 2e769e020..3d8223c48 100755 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -202,7 +202,16 @@ void SrsFastCoroutine::stop() if (trd) { void* res = NULL; int r0 = st_thread_join((st_thread_t)trd, &res); - srs_assert(!r0); + if (r0) { + // By st_thread_join + if (errno == EINVAL) srs_assert(!r0); + if (errno == EDEADLK) srs_assert(!r0); + // By st_cond_timedwait + if (errno == EINTR) srs_assert(!r0); + if (errno == ETIME) srs_assert(!r0); + // Others + srs_assert(!r0); + } srs_error_t err_res = (srs_error_t)res; if (err_res != srs_success) { diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 5e3377299..0613583c2 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -54,7 +54,9 @@ #endif #include +#ifndef srs_assert #define srs_assert(expression) assert(expression) +#endif #include #include diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index a6fd66fbb..eef3bfb57 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 190 +#define VERSION_REVISION 192 #endif diff --git a/trunk/src/protocol/srs_service_st.cpp b/trunk/src/protocol/srs_service_st.cpp index dcc8eeb12..65fa523f4 100644 --- a/trunk/src/protocol/srs_service_st.cpp +++ b/trunk/src/protocol/srs_service_st.cpp @@ -74,8 +74,17 @@ void srs_close_stfd(srs_netfd_t& stfd) { if (stfd) { // we must ensure the close is ok. - int err = st_netfd_close((st_netfd_t)stfd); - srs_assert(err != -1); + int r0 = st_netfd_close((st_netfd_t)stfd); + if (r0) { + // By _st_epoll_fd_close or _st_kq_fd_close + if (errno == EBUSY) srs_assert(!r0); + // By close + if (errno == EBADF) srs_assert(!r0); + if (errno == EINTR) srs_assert(!r0); + if (errno == EIO) srs_assert(!r0); + // Others + srs_assert(!r0); + } stfd = NULL; } } diff --git a/trunk/src/utest/srs_utest_reload.hpp b/trunk/src/utest/srs_utest_reload.hpp index 2af4e64b0..01688b7b5 100644 --- a/trunk/src/utest/srs_utest_reload.hpp +++ b/trunk/src/utest/srs_utest_reload.hpp @@ -10,7 +10,7 @@ /* #include */ -#include +#include #include #include diff --git a/trunk/src/utest/srs_utest_service.cpp b/trunk/src/utest/srs_utest_service.cpp index 20f744bfc..197383555 100644 --- a/trunk/src/utest/srs_utest_service.cpp +++ b/trunk/src/utest/srs_utest_service.cpp @@ -24,6 +24,7 @@ using namespace std; #include #include #include +#include MockSrsConnection::MockSrsConnection() { @@ -1452,3 +1453,35 @@ VOID TEST(TCPServerTest, ContextUtility) } } +class MockStopSelfThread : public ISrsCoroutineHandler +{ +public: + int r0; + int r1; + SrsFastCoroutine trd; + MockStopSelfThread() : trd("mock", this), r0(0), r1(0) { + } + virtual ~MockStopSelfThread() { + } + srs_error_t start() { + return trd.start(); + } + void stop() { + trd.stop(); + } + virtual srs_error_t cycle() { + r0 = st_thread_join((st_thread_t)trd.trd, NULL); + r1 = errno; + return srs_success; + } +}; + +VOID TEST(StopSelfThreadTest, ShouldFailWhenStopSelf) +{ + MockStopSelfThread trd; + trd.start(); + srs_usleep(0); + EXPECT_EQ(-1, trd.r0); + EXPECT_EQ(EDEADLK, trd.r1); +} +