From ca66858da2de35a875cbe9b1e57004d1d95c4eb9 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 19 Jun 2022 14:40:51 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9EAndroid=20ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/android.yml | 25 +++++++++++++++++++ Android/app/build.gradle | 2 +- Android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +-- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/android.yml diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml new file mode 100644 index 00000000..04506829 --- /dev/null +++ b/.github/workflows/android.yml @@ -0,0 +1,25 @@ +name: Android CI +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-20.04 + steps: + + - name: 下载源码 + uses: actions/checkout@v1 + + - name: 配置JDK + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: gradle + + - name: 下载submodule源码 + run: git submodule update --init + + - name: 赋予gradlew文件可执行权限 + run: chmod +x ./Android/gradlew + + - name: 编译 + run: cd Android && ./gradlew build diff --git a/Android/app/build.gradle b/Android/app/build.gradle index 7e02236a..7b0bfe8e 100644 --- a/Android/app/build.gradle +++ b/Android/app/build.gradle @@ -17,7 +17,7 @@ android { } } ndk { - abiFilters "armeabi-v7a"//, "arm64-v8a" + abiFilters "arm64-v8a" //, "armeabi-v7a" } } } diff --git a/Android/build.gradle b/Android/build.gradle index 3c23accd..95a39961 100644 --- a/Android/build.gradle +++ b/Android/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/Android/gradle/wrapper/gradle-wrapper.properties b/Android/gradle/wrapper/gradle-wrapper.properties index 51f504ca..0a81a846 100644 --- a/Android/gradle/wrapper/gradle-wrapper.properties +++ b/Android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri May 10 12:15:32 CST 2019 +#Sun Jun 19 15:19:24 CST 2022 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip From 1c5380eeadb5b835c73e2ddd42b87d51bdc34d6b Mon Sep 17 00:00:00 2001 From: Dw9 Date: Sun, 19 Jun 2022 17:27:03 +0800 Subject: [PATCH 2/6] Update MP4Recorder.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #1679 _muxer->openMP4 创建非法的文件夹会失败抛出异常 所以_full_path_tmp等都是空字符串 delete_file的时候 就会从此盘符的""(full_path_tmp)目录挨个删除了。 复现建议新建个盘符... --- src/Record/MP4Recorder.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index ede0d32d..35dbeaa0 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -73,15 +73,18 @@ void MP4Recorder::asyncClose() { info.time_len = (float) (::time(NULL) - info.start_time); //关闭mp4非常耗时,所以要放在后台线程执行 muxer->closeMP4(); - //获取文件大小 - info.file_size = File::fileSize(full_path_tmp.data()); - if (info.file_size < 1024) { - //录像文件太小,删除之 - File::delete_file(full_path_tmp.data()); - return; + + if(!full_path_tmp.empty()) { + //获取文件大小 + info.file_size = File::fileSize(full_path_tmp.data()); + if (info.file_size < 1024) { + //录像文件太小,删除之 + File::delete_file(full_path_tmp.data()); + return; + } + //临时文件名改成正式文件名,防止mp4未完成时被访问 + rename(full_path_tmp.data(), full_path.data()); } - //临时文件名改成正式文件名,防止mp4未完成时被访问 - rename(full_path_tmp.data(), full_path.data()); /////record 业务逻辑////// NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4, info); @@ -138,4 +141,4 @@ void MP4Recorder::resetTracks() { } /* namespace mediakit */ -#endif //ENABLE_MP4 \ No newline at end of file +#endif //ENABLE_MP4 From 0eacda5327babb05d8a8b5906c809e8ac5fa0da7 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 19 Jun 2022 15:54:30 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=96=B0=E5=A2=9Edocker=20ci=E5=B9=B6?= =?UTF-8?q?=E5=85=A8=E9=9D=A2=E6=95=B4=E7=90=86ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/android.yml | 2 +- .github/workflows/ccpp.yml | 4 +- .github/workflows/docker.yml | 82 +++++++++++++++++++++++++++++++++++ .github/workflows/macos.yml | 4 +- .github/workflows/msvc-ci.yml | 6 +-- .gitmodules_github | 6 +++ CMakeLists.txt | 2 +- dockerfile | 14 +++--- 8 files changed, 103 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/docker.yml create mode 100644 .gitmodules_github diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 04506829..c71c3867 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -16,7 +16,7 @@ jobs: cache: gradle - name: 下载submodule源码 - run: git submodule update --init + run: mv -f .gitmodules_github .gitmodules && git submodule sync && git submodule update --init - name: 赋予gradlew文件可执行权限 run: chmod +x ./Android/gradlew diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index b9b3080d..0051a468 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v1 - name: 下载submodule源码 - run: git submodule update --init + run: mv -f .gitmodules_github .gitmodules && git submodule sync && git submodule update --init - name: apt-get安装依赖库(非必选) run: sudo apt-get update && sudo apt-get install -y cmake libssl-dev libsdl-dev libavcodec-dev libavutil-dev @@ -28,7 +28,7 @@ jobs: run: cd 3rdpart/libsrtp && ./configure --enable-openssl && make -j4 && sudo make install - name: 编译 - run: mkdir -p linux_build && cd linux_build && cmake .. -DENABLE_WEBRTC:BOOL=TRUE && make -j4 + run: mkdir -p linux_build && cd linux_build && cmake .. -DENABLE_WEBRTC:BOOL=TRUE && make -j ${nproc} - name: 运行MediaServer run: pwd && cd release/linux/Debug && sudo ./MediaServer -d & diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..7f6d8bf8 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,82 @@ +name: Docker + +on: [push, pull_request] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: docker.io + IMAGE_NAME: zlmediakit/zlmediakit + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: 下载submodule源码 + run: mv -f .gitmodules_github .gitmodules && git submodule sync && git submodule update --init + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@d6a3abf1bdea83574e28d40543793018b6035605 + with: + cosign-release: 'v1.7.1' + + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: zlmediakit + password: ${{ secrets.DOCKER_IO_SECRET }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: MODEL=Release + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign +# - name: Sign the published Docker image +# if: ${{ github.event_name != 'pull_request' }} +# env: +# COSIGN_EXPERIMENTAL: "true" +# # This step uses the identity token to provision an ephemeral certificate +# # against the sigstore community Fulcio instance. +# run: cosign sign ${{ steps.meta.outputs.tags }}@${{ steps.build-and-push.outputs.digest }} diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 51898d1a..d14001e6 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v1 - name: 下载submodule源码 - run: git submodule update --init + run: mv -f .gitmodules_github .gitmodules && git submodule sync && git submodule update --init # - name: 安装brew # run: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" @@ -31,7 +31,7 @@ jobs: # run: cd 3rdpart/libsrtp && ./configure --enable-openssl && make -j4 && sudo make install - name: 编译 - run: mkdir -p build && cd build && cmake .. && make -j4 + run: mkdir -p build && cd build && cmake .. && make -j ${nproc} - name: 运行MediaServer run: pwd && cd release/linux/Debug && sudo ./MediaServer -d & diff --git a/.github/workflows/msvc-ci.yml b/.github/workflows/msvc-ci.yml index fcbfe10a..2fb629da 100644 --- a/.github/workflows/msvc-ci.yml +++ b/.github/workflows/msvc-ci.yml @@ -8,9 +8,9 @@ jobs: steps: - uses: actions/checkout@v1 - with: - submodules: 'recursive' - fetch-depth: 1 + + - name: 下载submodule源码 + run: mv -Force .gitmodules_github .gitmodules && git submodule sync && git submodule update --init - name: 配置 vcpkg uses: lukka/run-vcpkg@v7 diff --git a/.gitmodules_github b/.gitmodules_github new file mode 100644 index 00000000..572aff62 --- /dev/null +++ b/.gitmodules_github @@ -0,0 +1,6 @@ +[submodule "ZLToolKit"] + path = 3rdpart/ZLToolKit + url = https://github.com/ZLMediaKit/ZLToolKit +[submodule "3rdpart/media-server"] + path = 3rdpart/media-server + url = https://github.com/ireader/media-server diff --git a/CMakeLists.txt b/CMakeLists.txt index eb193431..1dc1b7db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,7 @@ if (JEMALLOC_FOUND) endif () #查找openssl是否安装 -find_package(OPENSSL QUIET) +find_package(OpenSSL QUIET) if (OPENSSL_FOUND AND ENABLE_OPENSSL) message(STATUS "found library:${OPENSSL_LIBRARIES},ENABLE_OPENSSL defined") include_directories(${OPENSSL_INCLUDE_DIR}) diff --git a/dockerfile b/dockerfile index 0b3e1f0e..2be4d056 100644 --- a/dockerfile +++ b/dockerfile @@ -10,7 +10,7 @@ EXPOSE 10000/udp EXPOSE 10000/tcp EXPOSE 8000/udp -ADD sources.list /etc/apt/sources.list +# ADD sources.list /etc/apt/sources.list RUN apt-get update && \ DEBIAN_FRONTEND="noninteractive" \ @@ -29,12 +29,11 @@ RUN apt-get update && \ libfaac-dev \ gcc \ g++ \ - gdb \ - libmp4v2-dev && \ + gdb && \ apt-get autoremove -y && \ apt-get clean -y && \ wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz -O libsrtp-2.2.0.tar.gz && tar xfv libsrtp-2.2.0.tar.gz && \ - cd libsrtp-2.2.0 && ./configure --enable-openssl && make && make install && \ + cd libsrtp-2.2.0 && ./configure --enable-openssl && make -j ${nproc} && make install && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /opt/media @@ -45,12 +44,12 @@ RUN mkdir -p build release/linux/${MODEL}/ WORKDIR /opt/media/ZLMediaKit/build RUN cmake -DCMAKE_BUILD_TYPE=${MODEL} -DENABLE_WEBRTC=true -DENABLE_TESTS=false -DENABLE_API=false .. && \ - make -j8 + make -j ${nproc} FROM ubuntu:18.04 ARG MODEL -ADD sources.list /etc/apt/sources.list +# ADD sources.list /etc/apt/sources.list RUN apt-get update && \ DEBIAN_FRONTEND="noninteractive" \ @@ -66,8 +65,7 @@ RUN apt-get update && \ ffmpeg \ gcc \ g++ \ - gdb \ - libmp4v2-dev && \ + gdb && \ apt-get autoremove -y && \ apt-get clean -y && \ rm -rf /var/lib/apt/lists/* From aacd6416ba3a91c314cb49b0e0979633ec065f2e Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 19 Jun 2022 19:01:40 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E7=BC=96=E7=A8=8B=E7=BA=BF=E7=A8=8B=E6=95=B0=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ccpp.yml | 2 +- .github/workflows/macos.yml | 2 +- dockerfile | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 0051a468..b8812d02 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -28,7 +28,7 @@ jobs: run: cd 3rdpart/libsrtp && ./configure --enable-openssl && make -j4 && sudo make install - name: 编译 - run: mkdir -p linux_build && cd linux_build && cmake .. -DENABLE_WEBRTC:BOOL=TRUE && make -j ${nproc} + run: mkdir -p linux_build && cd linux_build && cmake .. -DENABLE_WEBRTC:BOOL=TRUE && make -j $(nproc) - name: 运行MediaServer run: pwd && cd release/linux/Debug && sudo ./MediaServer -d & diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index d14001e6..103e11d5 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -31,7 +31,7 @@ jobs: # run: cd 3rdpart/libsrtp && ./configure --enable-openssl && make -j4 && sudo make install - name: 编译 - run: mkdir -p build && cd build && cmake .. && make -j ${nproc} + run: mkdir -p build && cd build && cmake .. && make -j $(nproc) - name: 运行MediaServer run: pwd && cd release/linux/Debug && sudo ./MediaServer -d & diff --git a/dockerfile b/dockerfile index 2be4d056..84b00d3d 100644 --- a/dockerfile +++ b/dockerfile @@ -33,7 +33,7 @@ RUN apt-get update && \ apt-get autoremove -y && \ apt-get clean -y && \ wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz -O libsrtp-2.2.0.tar.gz && tar xfv libsrtp-2.2.0.tar.gz && \ - cd libsrtp-2.2.0 && ./configure --enable-openssl && make -j ${nproc} && make install && \ + cd libsrtp-2.2.0 && ./configure --enable-openssl && make -j $(nproc) && make install && \ rm -rf /var/lib/apt/lists/* RUN mkdir -p /opt/media @@ -44,7 +44,7 @@ RUN mkdir -p build release/linux/${MODEL}/ WORKDIR /opt/media/ZLMediaKit/build RUN cmake -DCMAKE_BUILD_TYPE=${MODEL} -DENABLE_WEBRTC=true -DENABLE_TESTS=false -DENABLE_API=false .. && \ - make -j ${nproc} + make -j $(nproc) FROM ubuntu:18.04 ARG MODEL From 160b3a67bd4d85f11de32323ba3de61c525b64bc Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 19 Jun 2022 19:12:43 +0800 Subject: [PATCH 5/6] =?UTF-8?q?Android=E7=BC=96=E8=AF=91=E5=B1=8F=E8=94=BD?= =?UTF-8?q?openssl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Android/app/src/main/cpp/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Android/app/src/main/cpp/CMakeLists.txt b/Android/app/src/main/cpp/CMakeLists.txt index dfbe9f58..aa3169cb 100644 --- a/Android/app/src/main/cpp/CMakeLists.txt +++ b/Android/app/src/main/cpp/CMakeLists.txt @@ -8,9 +8,11 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs_export/${AND set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/libs_export/${ANDROID_ABI}) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libs_export/${ANDROID_ABI}/binary) set(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${ANDROID_ABI}") -set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include") -set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/libcrypto.a") -set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/libssl.a") + +#由于openssl库编译时未指定-fPIC,到时github action ci编译失败,先屏蔽掉 +#set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include") +#set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/libcrypto.a") +#set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/libssl.a") #设置工程源码根目录 set(JNI_Root ${CMAKE_CURRENT_SOURCE_DIR}) From 67606050dc85a9ee736a3343f75f1e889406765c Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 19 Jun 2022 19:39:48 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0docker=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++----- README_en.md | 2 +- dockerfile | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f8ece25a..0ab9966f 100644 --- a/README.md +++ b/README.md @@ -140,11 +140,8 @@ 你可以从Docker Hub下载已经编译好的镜像并启动它: ```bash -#此镜像为zlmediakit开发团队提供,推荐 -docker run -id -p 1935:1935 -p 8080:80 -p 8554:554 -p 10000:10000 -p 10000:10000/udp -p 8000:8000/udp zlmediakit/zlmediakit:Release.last - -#此镜像委托第三方提供 -docker run -id -p 1935:1935 -p 8080:80 -p 8554:554 -p 10000:10000 -p 10000:10000/udp panjjo/zlmediakit +#此镜像为github持续集成自动编译推送,跟代码(master分支)保持最新状态 +docker run -id -p 1935:1935 -p 8080:80 -p 8443:443 -p 8554:554 -p 10000:10000 -p 10000:10000/udp -p 8000:8000/udp -p 9000:9000/udp zlmediakit/zlmediakit:master ``` 你也可以根据Dockerfile编译镜像: diff --git a/README_en.md b/README_en.md index a1d958d1..f9c56da9 100644 --- a/README_en.md +++ b/README_en.md @@ -257,7 +257,7 @@ git submodule update --init ## Docker Image You can pull a pre-built docker image from Docker Hub and run with ```bash -docker run -id -p 1935:1935 -p 8080:80 -p 8554:554 -p 10000:10000 -p 10000:10000/udp panjjo/zlmediakit +docker run -id -p 1935:1935 -p 8080:80 -p 8443:443 -p 8554:554 -p 10000:10000 -p 10000:10000/udp -p 8000:8000/udp -p 9000:9000/udp zlmediakit/zlmediakit:master ``` Dockerfile is also supplied to build images on Ubuntu 16.04 diff --git a/dockerfile b/dockerfile index 84b00d3d..4a9160c5 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,6 @@ FROM ubuntu:18.04 AS build ARG MODEL #shell,rtmp,rtsp,rtsps,http,https,rtp -EXPOSE 9000/tcp EXPOSE 1935/tcp EXPOSE 554/tcp EXPOSE 80/tcp @@ -9,6 +8,7 @@ EXPOSE 443/tcp EXPOSE 10000/udp EXPOSE 10000/tcp EXPOSE 8000/udp +EXPOSE 9000/udp # ADD sources.list /etc/apt/sources.list