diff --git a/CMakeLists.txt b/CMakeLists.txt index 11c7003..08c17e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(OpenSSL_LIBRARY_DIRS ${OpenSSL_ROOT}/lib) set(OpenSSL_LIBRARIES libssl libcrypto) -set(FFMPEG_ROOT ${Libraries_ROOT}/ffmpeg-6.0-full_build-shared) +set(FFMPEG_ROOT ${Libraries_ROOT}/ffmpeg-6.1-full_build-shared) set(FFMPEG_INCLUDE_DIR ${FFMPEG_ROOT}/include) set(FFMPEG_LIBRARY_DIRS ${FFMPEG_ROOT}/lib) set(FFMPEG_LIBRARIES avcodec avformat avutil) @@ -37,12 +37,14 @@ find_package(LibDataChannel) add_subdirectory(E:/Projects/Kylin/Universal Universal) add_subdirectory(E:/Projects/Kylin/HttpProxy HttpProxy) +find_package(Boost REQUIRED COMPONENTS json) add_executable(FFmpegPlayer main.cpp Demuxer.h Demuxer.cpp AudioDecoder.h AudioDecoder.cpp VideoDecoder.h VideoDecoder.cpp WebRTCPublisher.h WebRTCPublisher.cpp + Helpers.h Helpers.cpp ) target_include_directories(FFmpegPlayer @@ -61,4 +63,5 @@ target_link_libraries(FFmpegPlayer PRIVATE ${FFMPEG_LIBRARIES} PRIVATE ${OpenSSL_LIBRARIES} PRIVATE LibDataChannel::LibDataChannel + PRIVATE Boost::json ) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index fc7ae3b..0000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,419 +0,0 @@ - - - - - - EnvironmentId - {11f4a1e9-12b5-4bf9-bf26-e33024189f36} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - 0 - false - true - false - 0 - true - true - 0 - 8 - true - false - 0 - true - true - true - *.md, *.MD, Makefile - false - true - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - true - Builtin.DefaultTidyAndClazy - 3 - true - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.6.1 MSVC2019 64bit - Desktop Qt 6.6.1 MSVC2019 64bit - qt.qt6.661.win64_msvc2019_64_kit - 0 - 0 - 0 - - Debug - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=Debug --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - 0 - E:\Projects\FFmpegPlayer-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug - - - - - all - - false - - true - 构建 - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - 构建 - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - Release - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=Release --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - E:\Projects\FFmpegPlayer-Desktop_Qt_6_6_1_MSVC2019_64bit-Release - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - CMakeProjectManager.CMakeBuildConfiguration - - - RelWithDebInfo - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - E:\Projects\FFmpegPlayer-Desktop_Qt_6_6_1_MSVC2019_64bit-RelWithDebInfo - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release with Debug Information - CMakeProjectManager.CMakeBuildConfiguration - - - RelWithDebInfo - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - 0 - E:\Projects\FFmpegPlayer-Desktop_Qt_6_6_1_MSVC2019_64bit-Profile - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - CMakeProjectManager.CMakeBuildConfiguration - - - MinSizeRel - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=MinSizeRel --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} - E:\Projects\FFmpegPlayer-Desktop_Qt_6_6_1_MSVC2019_64bit-MinSizeRel - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Minimum Size Release - CMakeProjectManager.CMakeBuildConfiguration - - 5 - - - 0 - 部署 - 部署 - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - 0 - true - - 2 - - false - FFmpegPlayer - CMakeProjectManager.CMakeRunConfiguration.FFmpegPlayer - FFmpegPlayer - false - true - true - true - E:/Projects/FFmpegPlayer-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/Helpers.cpp b/Helpers.cpp new file mode 100644 index 0000000..4b1bfc7 --- /dev/null +++ b/Helpers.cpp @@ -0,0 +1,6 @@ +#include "Helpers.h" + +ClientTrackData::ClientTrackData(std::shared_ptr track, std::shared_ptr sender) { + this->track = track; + this->sender = sender; +} diff --git a/Helpers.h b/Helpers.h new file mode 100644 index 0000000..84c77fa --- /dev/null +++ b/Helpers.h @@ -0,0 +1,13 @@ +#ifndef HELPERS_H +#define HELPERS_H + +#include "rtc/rtc.hpp" + +struct ClientTrackData { + std::shared_ptr track; + std::shared_ptr sender; + + ClientTrackData(std::shared_ptr track, std::shared_ptr sender); +}; + +#endif // HELPERS_H diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..d095d25 --- /dev/null +++ b/Readme.md @@ -0,0 +1,7 @@ + + +``` +CANDIDATE="192.168.2.26" +docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 -p 1990:1990 -p 8088:8088 --env CANDIDATE=192.168.2.26 -p 8000:8000/udp registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5 ./objs/srs -c conf/https.docker.conf +``` + diff --git a/WebRTCPublisher.cpp b/WebRTCPublisher.cpp index 461b9e2..742bf91 100644 --- a/WebRTCPublisher.cpp +++ b/WebRTCPublisher.cpp @@ -11,8 +11,8 @@ WebRTCPublisher::WebRTCPublisher(boost::asio::io_context &ioContext) : m_ioConte m_peer->onLocalDescription([&, this](rtc::Description sdp) { LOG(info) << "Send the SDP to the remote peer: " << std::string(sdp); - const auto serverIp = "172.16.7.16"; - const auto serverPort = "443"; + const auto serverIp = "192.168.2.26"; + const auto serverPort = "1990"; const auto streamUrl = "/live/livestream"; std::ostringstream oss; oss << "https://" << serverIp << ":" << serverPort << "/rtc/v1/publish/"; @@ -58,3 +58,31 @@ WebRTCPublisher::WebRTCPublisher(boost::asio::io_context &ioContext) : m_ioConte } }); } + +std::shared_ptr WebRTCPublisher::addVideo(const std::shared_ptr pc, + const uint8_t payloadType, const uint32_t ssrc, + const std::string cname, const std::string msid, + const std::function onOpen) { + auto video = rtc::Description::Video(cname); + video.addH264Codec(payloadType); + video.addSSRC(ssrc, cname, msid, cname); + auto track = pc->addTrack(video); + // create RTP configuration + auto rtpConfig = + make_shared(ssrc, cname, payloadType, rtc::H264RtpPacketizer::defaultClockRate); + // create packetizer + auto packetizer = make_shared(rtc::NalUnit::Separator::Length, rtpConfig); + // create H264 handler + auto h264Handler = make_shared(packetizer); + // add RTCP SR handler + auto srReporter = make_shared(rtpConfig); + h264Handler->addToChain(srReporter); + // add RTCP NACK handler + auto nackResponder = std::make_shared(); + h264Handler->addToChain(nackResponder); + // set handler + track->setMediaHandler(h264Handler); + track->onOpen(onOpen); + auto trackData = make_shared(track, srReporter); + return trackData; +} diff --git a/WebRTCPublisher.h b/WebRTCPublisher.h index 6c7515d..1ac22ef 100644 --- a/WebRTCPublisher.h +++ b/WebRTCPublisher.h @@ -1,13 +1,18 @@ #ifndef WEBRTCPUBLISHER_H #define WEBRTCPUBLISHER_H -#include "rtc/rtc.hpp" +#include "Helpers.h" #include class WebRTCPublisher { public: WebRTCPublisher(boost::asio::io_context &ioContext); +protected: + std::shared_ptr addVideo(const std::shared_ptr pc, const uint8_t payloadType, + const uint32_t ssrc, const std::string cname, const std::string msid, + const std::function onOpen); + private: boost::asio::io_context &m_ioContext; rtc::Configuration m_configuration; diff --git a/conf/https.docker.conf b/conf/https.docker.conf new file mode 100644 index 0000000..9aa21fe --- /dev/null +++ b/conf/https.docker.conf @@ -0,0 +1,20 @@ +http_api { + enabled on; + listen 1985; + https { + # Whether enable HTTPS API. + # default: off + enabled on; + # The listen endpoint for HTTPS API. + # default: 1990 + listen 1990; + # The SSL private key file, generated by: + # openssl genrsa -out server.key 2048 + # default: ./conf/server.key + key ./conf/server.key; + # The SSL public cert file, generated by: + # openssl req -new -x509 -key server.key -out server.crt -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net" + # default: ./conf/server.crt + cert ./conf/server.crt; + } +} \ No newline at end of file diff --git a/conf/server.crt b/conf/server.crt new file mode 100644 index 0000000..3264aa9 --- /dev/null +++ b/conf/server.crt @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDnzCCAoegAwIBAgIUAKUAHXhY3LCqqMJGdIiQS6yA5CMwDQYJKoZIhvcNAQEL +BQAwXzELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB0JlaWppbmcxEDAOBgNVBAcMB0Jl +aWppbmcxCzAJBgNVBAoMAk1lMQswCQYDVQQLDAJNZTESMBAGA1UEAwwJb3NzcnMu +bmV0MB4XDTI0MDExNTE0MjY0MVoXDTM0MDExMjE0MjY0MVowXzELMAkGA1UEBhMC +Q04xEDAOBgNVBAgMB0JlaWppbmcxEDAOBgNVBAcMB0JlaWppbmcxCzAJBgNVBAoM +Ak1lMQswCQYDVQQLDAJNZTESMBAGA1UEAwwJb3NzcnMubmV0MIIBIjANBgkqhkiG +9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvSbK4HYljfTR3jfmJDRXVhpAa8WV8U+BnMO6 +twWIyb58f166bFFquYCK7yqz1v+0e0vuLxUENJSPQFaEpeV77kutBMTCwrZxSiSA +/d4nK76GdddAnpdvkqkdOuIXeTaz+CPtueb2pmzIqdqOjtj+1Ufpx5D0bcJOfH5T +ctW315IZ2Ws+Uk+Lg8cuzjFgsSwznPioMN5KCkIY3dwt7sO3Et5X/m+Kq3xZ5j58 +psyXh8IUknSPNZ7NCEm+atuUoOro5jXl3gcJIVJ7nQPrzdZrs9tMr+pMu8mjQoKe +dlKkLFSrzSTiYvHwB7H2+woKizJXUxSQWIToXkVF0WoE0CQLoQIDAQABo1MwUTAd +BgNVHQ4EFgQUDRDC5HyZKmzfaIJoFAx9+6hqRfEwHwYDVR0jBBgwFoAUDRDC5HyZ +KmzfaIJoFAx9+6hqRfEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC +AQEAnudE/WvDte8uPv4kJ414yrg5w7r5vHZ7Iw9VVdwzf6RBRr8dDx2IUVVDzVY9 +ulv9v37Bx2s331Riait+CM543qCy/FLoZeHZt5UVw4PjEaFcQyhV3m9xrl0vYi0p +80xIE7yRgMXgxM9njZkvVblopFzJBfWi9/5NnjVwhLMaNLBqK2oHEEJO1NUpQ8Jd +2x2x8Tqhu9eiW6Xo7+D/SEJT9qSlrtvS/u2FItAgTEcij71Rtm9u6snKDXG3m5j2 +VFS48nZVDgCUP+uVbMmTG0ACkaYpwZHTK3CCeUHsjqoC8SD2aqwkuTBMt1P4or+z +vPI+vzNtkbz8O/V+JTU/FQiQag== +-----END CERTIFICATE----- diff --git a/conf/server.key b/conf/server.key new file mode 100644 index 0000000..004b6ac --- /dev/null +++ b/conf/server.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC9JsrgdiWN9NHe +N+YkNFdWGkBrxZXxT4Gcw7q3BYjJvnx/XrpsUWq5gIrvKrPW/7R7S+4vFQQ0lI9A +VoSl5XvuS60ExMLCtnFKJID93icrvoZ110Cel2+SqR064hd5NrP4I+255vambMip +2o6O2P7VR+nHkPRtwk58flNy1bfXkhnZaz5ST4uDxy7OMWCxLDOc+Kgw3koKQhjd +3C3uw7cS3lf+b4qrfFnmPnymzJeHwhSSdI81ns0ISb5q25Sg6ujmNeXeBwkhUnud +A+vN1muz20yv6ky7yaNCgp52UqQsVKvNJOJi8fAHsfb7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jlrDtiBceUA4WGUch5XxTwRtMOdbUTBAoGBAL5i9/kWDUmvHuG33ZKN +EW1ibd/A4WnEHHBsXicAF42DxRiEkiabN9/wPXO69i+MrZljZm+ndLrMIZ7UrNaJ +xSU6IjyGQiJYcI+MfdH7s2CUXIrt9M3+BQ/b19Bpz4Z16Z9rqCDGqsHiuDPKntcd +1421zg1QGiOTSZqqQNdKOhGx +-----END PRIVATE KEY----- diff --git a/main.cpp b/main.cpp index 69ff317..cd92f02 100644 --- a/main.cpp +++ b/main.cpp @@ -12,8 +12,8 @@ int main(int argc, char *argv[]) { auto ioContext = Amass::Singleton::instance(); std::cout << "hello world." << std::endl; constexpr auto path = "E:/Documents/juren-30s.mp4"; - Demuxer demuxer; - demuxer.open(path); + // Demuxer demuxer; + // demuxer.open(path); // auto [audioCodec, audioCodecParameter] = demuxer.codecInformation(Stream::Audio); // auto [videoCodec, videoCodecParameter] = demuxer.codecInformation(Stream::Video);