From 9a05c2be4d580732b8c880bebe7091d346b8b903 Mon Sep 17 00:00:00 2001 From: wxf Date: Thu, 17 Dec 2020 19:43:17 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E8=B0=83=E6=95=B4=20linux=20=E4=B8=8B?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 3 ++- server/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5332e02d..aec266ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,8 +180,9 @@ if (WIN32) set(INSTALL_PATH_LIB $ENV{HOME}/${CMAKE_PROJECT_NAME}/lib) set(INSTALL_PATH_INCLUDE $ENV{HOME}/${CMAKE_PROJECT_NAME}/include) else () - set(INSTALL_PATH_LIB lib) + set(INSTALL_PATH_LIB lib${LIB_SUFFIX}) set(INSTALL_PATH_INCLUDE include) + set(INSTALL_PATH_EXECUTABLE bin) endif () if(ENABLE_CXX_API) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 092a4221..9b9692b3 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -10,8 +10,8 @@ add_executable(MediaServer ${MediaServer_src_list}) if(WIN32) set_target_properties(MediaServer PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) +else() + install(TARGETS MediaServer DESTINATION ${INSTALL_PATH_EXECUTABLE}) endif() target_link_libraries(MediaServer jsoncpp ${LINK_LIB_LIST}) - - From acc5ecb937159cf87a5fd164a0d7bb1f887db0f6 Mon Sep 17 00:00:00 2001 From: wxf Date: Thu, 17 Dec 2020 19:45:43 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20rpm=20spec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/rpm/ZLMediaKit.spec | 123 ++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 package/rpm/ZLMediaKit.spec diff --git a/package/rpm/ZLMediaKit.spec b/package/rpm/ZLMediaKit.spec new file mode 100644 index 00000000..e3af386d --- /dev/null +++ b/package/rpm/ZLMediaKit.spec @@ -0,0 +1,123 @@ +%if 0%{?fedora} >= 15 || 0%{?rhel} >= 7 +%global use_devtoolset 0 +%else +%global use_devtoolset 1 +%endif + +Name: ZLMediaKit +Version: 5.0.0 +Release: 1%{?dist} +Summary: A lightweight, high performance and stable stream server and client framework based on C++11. + +Group: development +License: MIT +URL: https://github.com/xia-chu/ZLMediaKit +Source0: %{name}-%{version}.tar.xz + +BuildRequires: openssl-devel +BuildRequires: mysql-devel +BuildRequires: faac-devel +BuildRequires: x264-devel + +%if 0%{?use_devtoolset} +BuildRequires: devtoolset-8-gcc-c++ +%endif + +%description +A lightweight RTSP/RTMP/HTTP/HLS/HTTP-FLV/WebSocket-FLV/HTTP-TS/HTTP-fMP4/WebSocket-TS/WebSocket-fMP4/GB28181 server and client framework based on C++11. + +%package media-server +Requires: %{name}-%{version} +Summary: A lightweight, high performance and stable stream server + +%description media-server +A lightweight RTSP/RTMP/HTTP/HLS/HTTP-FLV/WebSocket-FLV/HTTP-TS/HTTP-fMP4/WebSocket-TS/WebSocket-fMP4/GB28181 server. + +%package c-libs +Requires: %{name}-%{version} +Summary: The %{name} C libraries. +%description c-libs +The %{name} C libraries. + +%package c-devel +Requires: %{name}-c-libs-%{version} +Summary: The %{name} C API headers. +%description c-devel +The %{name} C API headers. + +%package cxx-devel +Requires: %{name}-%{version} +Summary: The %{name} C++ API headers and development libraries. +%description cxx-devel +The %{name} C++ API headers and development libraries. + +%prep +%setup -q + +%build +mkdir -p %{_target_platform} + +pushd %{_target_platform} + +%if 0%{?use_devtoolset} +. /opt/rh/devtoolset-8/enable +%endif + +%cmake \ + -DENABLE_HLS:BOOL=ON \ + -DENABLE_OPENSSL:BOOL=ON \ + -DENABLE_MYSQL:BOOL=ON \ + -DENABLE_FAAC:BOOL=ON \ + -DENABLE_X264:BOOL=ON \ + -DENABLE_MP4:BOOL=ON \ + -DENABLE_RTPPROXY:BOOL=ON \ + -DENABLE_API:BOOL=ON \ + -DENABLE_CXX_API:BOOL=ON \ + -DENABLE_TESTS:BOOL=OFF \ + -DENABLE_SERVERL:BOOL=ON \ + .. + +make %{?_smp_mflags} + +popd + +%install +rm -rf $RPM_BUILD_ROOT + +pushd %{_target_platform} +%make_install +popd + +install -m 0755 -d %{buildroot}%{_docdir}/%{name} +install -m 0644 LICENSE %{buildroot}%{_docdir}/%{name} +install -m 0644 README.md %{buildroot}%{_docdir}/%{name} +install -m 0644 README_en.md %{buildroot}%{_docdir}/%{name} + +# TODO: service files + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%doc %{_docdir}/* + +%files media-server +%{_bindir}/* + +%files c-libs +%{_libdir}/libmk_api.so + +%files c-devel +%{_includedir}/mk_* + +%files cxx-devel +%{_includedir}/ZLMediaKit/* +%{_includedir}/ZLToolKit/* +%{_libdir}/libzlmediakit.a +%{_libdir}/libzltoolkit.a +%{_libdir}/libmpeg.a +%{_libdir}/libmov.a +%{_libdir}/libflv.a + +%changelog + From af6446507eef80766f44eed3e778051c7d662a1f Mon Sep 17 00:00:00 2001 From: wxf Date: Thu, 17 Dec 2020 20:14:49 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/rpm/ZLMediaKit.spec | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/package/rpm/ZLMediaKit.spec b/package/rpm/ZLMediaKit.spec index e3af386d..09d0838c 100644 --- a/package/rpm/ZLMediaKit.spec +++ b/package/rpm/ZLMediaKit.spec @@ -1,9 +1,16 @@ %if 0%{?fedora} >= 15 || 0%{?rhel} >= 7 %global use_devtoolset 0 +%bcond_without faac +%bcond_without x264 %else %global use_devtoolset 1 +%bcond_with faac +%bcond_with x264 %endif +%bcond_without openssl +%bcond_without mysql + Name: ZLMediaKit Version: 5.0.0 Release: 1%{?dist} @@ -14,10 +21,21 @@ License: MIT URL: https://github.com/xia-chu/ZLMediaKit Source0: %{name}-%{version}.tar.xz +%if %{with openssl} BuildRequires: openssl-devel +%endif + +%if %{with mysql} BuildRequires: mysql-devel +%endif + +%if %{with faac} BuildRequires: faac-devel +%endif + +%if %{with x264} BuildRequires: x264-devel +%endif %if 0%{?use_devtoolset} BuildRequires: devtoolset-8-gcc-c++ @@ -64,11 +82,12 @@ pushd %{_target_platform} %endif %cmake \ + -DCMAKE_BUILD_TYPE:STRING=Release \ -DENABLE_HLS:BOOL=ON \ - -DENABLE_OPENSSL:BOOL=ON \ - -DENABLE_MYSQL:BOOL=ON \ - -DENABLE_FAAC:BOOL=ON \ - -DENABLE_X264:BOOL=ON \ + -DENABLE_OPENSSL:BOOL=%{with openssl} \ + -DENABLE_MYSQL:BOOL=%{with mysql} \ + -DENABLE_FAAC:BOOL=%{with faac} \ + -DENABLE_X264:BOOL=%{with x264} \ -DENABLE_MP4:BOOL=ON \ -DENABLE_RTPPROXY:BOOL=ON \ -DENABLE_API:BOOL=ON \ From 2242f7ecc5afb7744c6e21bccdb4c34784ed2126 Mon Sep 17 00:00:00 2001 From: wxf Date: Thu, 17 Dec 2020 20:43:38 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20CentOS=206=20?= =?UTF-8?q?=E4=B8=8B=E4=BD=BF=E7=94=A8=20devtoolset=208=20=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 inttypes.h 提供的 PRIu64 需要定义 __STDC_FORMAT_MACROS, 而 cinttypes 会定义该宏. https://stackoverflow.com/a/8132440/5218590 --- src/Http/HlsParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/HlsParser.cpp b/src/Http/HlsParser.cpp index b6b35f01..60e578d7 100644 --- a/src/Http/HlsParser.cpp +++ b/src/Http/HlsParser.cpp @@ -9,7 +9,7 @@ */ #include -#include +#include #include "HlsParser.h" #include "Util/util.h" #include "Common/Parser.h" From 6a2709bec2c44fa4aac0cf49ffd2597b2f650978 Mon Sep 17 00:00:00 2001 From: wxf Date: Thu, 17 Dec 2020 21:40:58 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E9=9C=80=E8=A6=81=20cmake3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/rpm/ZLMediaKit.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/rpm/ZLMediaKit.spec b/package/rpm/ZLMediaKit.spec index 09d0838c..c4e5c855 100644 --- a/package/rpm/ZLMediaKit.spec +++ b/package/rpm/ZLMediaKit.spec @@ -81,7 +81,7 @@ pushd %{_target_platform} . /opt/rh/devtoolset-8/enable %endif -%cmake \ +%cmake3 \ -DCMAKE_BUILD_TYPE:STRING=Release \ -DENABLE_HLS:BOOL=ON \ -DENABLE_OPENSSL:BOOL=%{with openssl} \ From e467cf10c341e420ea53cbb7efe1b59bd7dba760 Mon Sep 17 00:00:00 2001 From: wxf Date: Fri, 18 Dec 2020 09:12:52 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20rpm=20=E5=8C=85?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/rpm/ZLMediaKit.spec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package/rpm/ZLMediaKit.spec b/package/rpm/ZLMediaKit.spec index c4e5c855..58b2b633 100644 --- a/package/rpm/ZLMediaKit.spec +++ b/package/rpm/ZLMediaKit.spec @@ -45,26 +45,26 @@ BuildRequires: devtoolset-8-gcc-c++ A lightweight RTSP/RTMP/HTTP/HLS/HTTP-FLV/WebSocket-FLV/HTTP-TS/HTTP-fMP4/WebSocket-TS/WebSocket-fMP4/GB28181 server and client framework based on C++11. %package media-server -Requires: %{name}-%{version} +Requires: %{name} = %{version} Summary: A lightweight, high performance and stable stream server %description media-server A lightweight RTSP/RTMP/HTTP/HLS/HTTP-FLV/WebSocket-FLV/HTTP-TS/HTTP-fMP4/WebSocket-TS/WebSocket-fMP4/GB28181 server. %package c-libs -Requires: %{name}-%{version} +Requires: %{name} = %{version} Summary: The %{name} C libraries. %description c-libs The %{name} C libraries. %package c-devel -Requires: %{name}-c-libs-%{version} +Requires: %{name}-c-libs = %{version} Summary: The %{name} C API headers. %description c-devel The %{name} C API headers. %package cxx-devel -Requires: %{name}-%{version} +Requires: %{name} = %{version} Summary: The %{name} C++ API headers and development libraries. %description cxx-devel The %{name} C++ API headers and development libraries. From 6c853008fce46f2ad61b43df7d3026c69e7637ef Mon Sep 17 00:00:00 2001 From: mirs Date: Fri, 18 Dec 2020 18:32:12 +0800 Subject: [PATCH 07/15] fix disable hls and rtpproxy compile error --- src/Rtp/Decoder.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Rtp/Decoder.cpp b/src/Rtp/Decoder.cpp index c0aadd7d..35a6663d 100644 --- a/src/Rtp/Decoder.cpp +++ b/src/Rtp/Decoder.cpp @@ -223,6 +223,7 @@ void DecoderImp::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d } #else void DecoderImp::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t dts,const void *data,int bytes) {} +void DecoderImp::onStream(int stream,int codecid,const void *extra,int bytes,int finish) {} #endif void DecoderImp::onTrack(const Track::Ptr &track) { From 8efb2da572cd6d963db27605995f746ca805e768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 19 Dec 2020 09:16:04 +0800 Subject: [PATCH 08/15] Update config.ini --- conf/config.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/config.ini b/conf/config.ini index aca73bf2..3cf01429 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -55,7 +55,7 @@ modifyStamp=0 #服务器唯一id,用于触发hook时区别是哪台服务器 mediaServerId=your_server_id -###### 以下是按需转协议的开关,在测试ZLMediaKit的接收推流性能时,请关闭以下全部开关 +###### 以下是按需转协议的开关,在测试ZLMediaKit的接收推流性能时,请把下面开关置1 ###### 如果某种协议你用不到,你可以把以下开关置1以便节省资源(但是还是可以播放,只是第一个播放者体验稍微差点), ###### 如果某种协议你想获取最好的用户体验,请置0(第一个播放者可以秒开,且不花屏) From 544797e501d0c0c4b43e02a0faf8bf26376a05b6 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 19 Dec 2020 09:20:24 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E8=A7=A3=E5=86=B3rtsp=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E5=99=A8TEARDOWN=E4=B8=8D=E4=BC=A0url=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9A#631?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtspPlayer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index de3aa0d8..8c3b0538 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -37,8 +37,10 @@ RtspPlayer::~RtspPlayer(void) { } void RtspPlayer::teardown(){ if (alive()) { - sendRtspRequest("TEARDOWN" ,_content_base); - shutdown(SockException(Err_shutdown,"teardown")); + if (!_content_base.empty()) { + sendRtspRequest("TEARDOWN", _content_base); + } + shutdown(SockException(Err_shutdown, "teardown")); } _md5_nonce.clear(); From 76a55c6c08c0c7bc5cbb36be4892a5df912af0c4 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 19 Dec 2020 18:59:22 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AC=94=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtspPlayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 8c3b0538..3ebde80f 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -234,7 +234,7 @@ void RtspPlayer::sendSetup(unsigned int track_idx) { } break; case Rtsp::RTP_MULTICAST: { - sendRtspRequest("SETUP",baseUrl,{"Transport","Transport: RTP/AVP;multicast"}); + sendRtspRequest("SETUP",baseUrl,{"Transport","RTP/AVP;multicast"}); } break; case Rtsp::RTP_UDP: { From 250d9f8e54d259e339ca10c09a251b9a2a02aa59 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 19 Dec 2020 19:46:18 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E4=BC=98=E5=8C=96GB28181=20tcp=E6=8E=A8?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpSession.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Rtp/RtpSession.cpp b/src/Rtp/RtpSession.cpp index 21fb5e2d..cfea27f6 100644 --- a/src/Rtp/RtpSession.cpp +++ b/src/Rtp/RtpSession.cpp @@ -57,8 +57,8 @@ void RtpSession::onManager() { } void RtpSession::onRtpPacket(const char *data, uint64_t len) { - if (len > 1024 * 2) { - throw SockException(Err_shutdown, "rtp包长度异常,发送端可能缓存溢出并覆盖"); + if (len > 1024 * 10) { + throw SockException(Err_shutdown, StrPrinter << "rtp包长度异常(" << len << "),发送端可能缓存溢出并覆盖"); } if (!_process) { uint32_t ssrc; From 584ea17dc54a13fc6bf7b2f46a2812db1195c9f5 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 19 Dec 2020 19:47:43 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtpReceiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rtsp/RtpReceiver.cpp b/src/Rtsp/RtpReceiver.cpp index 75d5b45e..6e3826f9 100644 --- a/src/Rtsp/RtpReceiver.cpp +++ b/src/Rtsp/RtpReceiver.cpp @@ -113,7 +113,7 @@ bool RtpReceiver::handleOneRtp(int track_index, TrackType type, int samplerate, } if (rtp_raw_len <= rtp.offset) { - WarnL << "无有效负载的rtp包:" << rtp_raw_len << " <= " << (int) rtp.offset; + //无有效负载的rtp包 return false; } From 29c905078730163c0f1b0d6be963cdc02488cc74 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 19 Dec 2020 20:31:35 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d12175d..40a676a9 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ bash build_docker_images.sh - 流媒体管理平台 - [功能强大的流媒体控制管理接口平台,支持GB28181](https://github.com/chatop2020/StreamNode) - - [GB28181-2016网络视频平台](https://github.com/648540858/wvp-GB28181) + - [GB28181-2016网络视频平台](https://github.com/648540858/wvp-GB28181-pro) - [node-js版本的GB28181平台](https://gitee.com/hfwudao/GB28181_Node_Http) - [Go实现的海康ehome服务器](https://github.com/tsingeye/FreeEhome) From 3cdc89385641fcbbc594f456a566bbecf43d60c1 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 19 Dec 2020 20:38:39 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 40a676a9..ee1f12e6 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ ## 功能清单 ### 功能一览 -图片 +图片 - RTSP[S] - RTSP[S] 服务器,支持RTMP/MP4/HLS转RTSP[S],支持亚马逊echo show这样的设备 From bc125e65bef2cd6e9a9bb8b8b2526d7fe36ef8ac Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 20 Dec 2020 20:25:44 +0800 Subject: [PATCH 15/15] =?UTF-8?q?addFFmpegSource=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=94=AF=E6=8C=81enable=5Fhls=E3=80=81enable=5Fmp4=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- postman/ZLMediaKit.postman_collection.json | 16 ++++++++++--- server/FFmpegSource.cpp | 11 +++++++++ server/FFmpegSource.h | 24 ++++++++++++++++--- server/WebApi.cpp | 28 ++++++++++++++-------- 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/postman/ZLMediaKit.postman_collection.json b/postman/ZLMediaKit.postman_collection.json index 3b1d5a43..48d93811 100644 --- a/postman/ZLMediaKit.postman_collection.json +++ b/postman/ZLMediaKit.postman_collection.json @@ -428,7 +428,7 @@ "method": "GET", "header": [], "url": { - "raw": "{{ZLMediaKit_URL}}/index/api/addStreamProxy?secret={{ZLMediaKit_secret}}&vhost={{defaultVhost}}&app=live&stream=test&url=rtmp://live.hkstv.hk.lxdns.com/live/hks2&enable_rtsp=1&enable_rtmp=1", + "raw": "{{ZLMediaKit_URL}}/index/api/addStreamProxy?secret={{ZLMediaKit_secret}}&vhost={{defaultVhost}}&app=live&stream=test&url=rtmp://live.hkstv.hk.lxdns.com/live/hks2", "host": [ "{{ZLMediaKit_URL}}" ], @@ -523,7 +523,7 @@ "method": "GET", "header": [], "url": { - "raw": "{{ZLMediaKit_URL}}/index/api/addFFmpegSource?secret={{ZLMediaKit_secret}}&src_url=http://live.hkstv.hk.lxdns.com/live/hks2/playlist.m3u8&dst_url=rtmp://10.8.9.115:8554/live/hks2&timeout_ms=10000", + "raw": "{{ZLMediaKit_URL}}/index/api/addFFmpegSource?secret={{ZLMediaKit_secret}}&src_url=http://hefeng.live.tempsource.cjyun.org/videotmp/s10100-hftv.m3u8&dst_url=rtmp://127.0.0.1/live/hks2&timeout_ms=10000&enable_hls=0&enable_mp4=0", "host": [ "{{ZLMediaKit_URL}}" ], @@ -540,7 +540,7 @@ }, { "key": "src_url", - "value": "http://live.hkstv.hk.lxdns.com/live/hks2/playlist.m3u8", + "value": "http://hefeng.live.tempsource.cjyun.org/videotmp/s10100-hftv.m3u8", "description": "FFmpeg拉流地址,支持任意协议或格式(只要FFmpeg支持即可)" }, { @@ -552,6 +552,16 @@ "key": "timeout_ms", "value": "10000", "description": "FFmpeg推流成功超时时间,单位毫秒" + }, + { + "key": "enable_hls", + "value": "0", + "description": "是否开启hls录制" + }, + { + "key": "enable_mp4", + "value": "0", + "description": "是否开启mp4录制" } ] } diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 6ae12e85..62e0e404 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -59,6 +59,11 @@ static bool is_local_ip(const string &ip){ return false; } +void FFmpegSource::setupRecord(bool enable_hls, bool enable_mp4){ + _enable_hls = enable_hls; + _enable_mp4 = enable_mp4; +} + void FFmpegSource::play(const string &src_url,const string &dst_url,int timeout_ms,const onPlay &cb) { GET_CONFIG(string,ffmpeg_bin,FFmpeg::kBin); GET_CONFIG(string,ffmpeg_cmd,FFmpeg::kCmd); @@ -263,6 +268,12 @@ void FFmpegSource::onGetMediaSource(const MediaSource::Ptr &src) { //防止多次进入onGetMediaSource函数导致无限递归调用的bug setDelegate(listener); src->setListener(shared_from_this()); + if (_enable_hls) { + src->setupRecord(Recorder::type_hls, true, ""); + } + if (_enable_mp4) { + src->setupRecord(Recorder::type_mp4, true, ""); + } } } diff --git a/server/FFmpegSource.h b/server/FFmpegSource.h index 1b9c1e9f..48c21ae7 100644 --- a/server/FFmpegSource.h +++ b/server/FFmpegSource.h @@ -46,13 +46,29 @@ public: typedef function onPlay; FFmpegSource(); - virtual ~FFmpegSource(); + ~FFmpegSource(); + /** * 设置主动关闭回调 - * @param cb */ void setOnClose(const function &cb); - void play(const string &src_url,const string &dst_url,int timeout_ms,const onPlay &cb); + + /** + * 开始播放url + * @param src_url FFmpeg拉流地址 + * @param dst_url FFmpeg推流地址 + * @param timeout_ms 等待结果超时时间,单位毫秒 + * @param cb 成功与否回调 + */ + void play(const string &src_url, const string &dst_url, int timeout_ms, const onPlay &cb); + + /** + * 设置录制 + * @param enable_hls 是否开启hls直播或录制 + * @param enable_mp4 是否录制mp4 + */ + void setupRecord(bool enable_hls, bool enable_mp4); + private: void findAsync(int maxWaitMS ,const function &cb); void startTimer(int timeout_ms); @@ -69,6 +85,8 @@ private: std::shared_ptr getOriginSock(MediaSource &sender) const override; private: + bool _enable_hls = false; + bool _enable_mp4 = false; Process _process; Timer::Ptr _timer; EventPoller::Ptr _poller; diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 61ee2221..768b2e64 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -694,28 +694,31 @@ void installWebApi() { static auto addFFmpegSource = [](const string &src_url, const string &dst_url, int timeout_ms, - const function &cb){ + bool enable_hls, + bool enable_mp4, + const function &cb) { auto key = MD5(dst_url).hexdigest(); lock_guard lck(s_ffmpegMapMtx); - if(s_ffmpegMap.find(key) != s_ffmpegMap.end()){ + if (s_ffmpegMap.find(key) != s_ffmpegMap.end()) { //已经在拉流了 - cb(SockException(Err_success),key); + cb(SockException(Err_success), key); return; } FFmpegSource::Ptr ffmpeg = std::make_shared(); s_ffmpegMap[key] = ffmpeg; - ffmpeg->setOnClose([key](){ + ffmpeg->setOnClose([key]() { lock_guard lck(s_ffmpegMapMtx); s_ffmpegMap.erase(key); }); - ffmpeg->play(src_url, dst_url,timeout_ms,[cb , key](const SockException &ex){ - if(ex){ + ffmpeg->setupRecord(enable_hls, enable_mp4); + ffmpeg->play(src_url, dst_url, timeout_ms, [cb, key](const SockException &ex) { + if (ex) { lock_guard lck(s_ffmpegMapMtx); s_ffmpegMap.erase(key); } - cb(ex,key); + cb(ex, key); }); }; @@ -727,12 +730,15 @@ void installWebApi() { auto src_url = allArgs["src_url"]; auto dst_url = allArgs["dst_url"]; int timeout_ms = allArgs["timeout_ms"]; + auto enable_hls = allArgs["enable_hls"].as(); + auto enable_mp4 = allArgs["enable_mp4"].as(); - addFFmpegSource(src_url,dst_url,timeout_ms,[invoker,val,headerOut](const SockException &ex,const string &key){ - if(ex){ + addFFmpegSource(src_url, dst_url, timeout_ms, enable_hls, enable_mp4, + [invoker, val, headerOut](const SockException &ex, const string &key) { + if (ex) { const_cast(val)["code"] = API::OtherFailed; const_cast(val)["msg"] = ex.what(); - }else{ + } else { const_cast(val)["data"]["key"] = key; } invoker("200 OK", headerOut, val.toStyledString()); @@ -1084,6 +1090,8 @@ void installWebApi() { addFFmpegSource("http://hls-ott-zhibo.wasu.tv/live/272/index.m3u8",/** ffmpeg拉流支持任意编码格式任意协议 **/ dst_url, (1000 * timeout_sec) - 500, + false, + false, [invoker,val,headerOut](const SockException &ex,const string &key){ if(ex){ const_cast(val)["code"] = API::OtherFailed;