mirror of
				https://github.com/kunkundi/crossdesk.git
				synced 2025-10-26 20:25:34 +08:00 
			
		
		
		
	1.Implementation for rtp session module; 2.Separate signal server from main project
This commit is contained in:
		| @@ -100,6 +100,7 @@ inline int ProcessMouseKeyEven(SDL_Event &ev) { | ||||
|  | ||||
| void GuestReceiveBuffer(const char *data, size_t size, const char *user_id, | ||||
|                         size_t user_id_size) { | ||||
|   std::cout << "Receive: [" << user_id << "] " << std::endl; | ||||
|   memcpy(dst_buffer, data, size); | ||||
|  | ||||
|   SDL_Event event; | ||||
|   | ||||
							
								
								
									
										43
									
								
								application/signal_server/xmake.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								application/signal_server/xmake.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| set_project("projectx") | ||||
| set_version("0.0.1") | ||||
|  | ||||
| add_rules("mode.release", "mode.debug") | ||||
| set_languages("c++17") | ||||
|  | ||||
| add_rules("mode.release", "mode.debug") | ||||
|  | ||||
| add_requires("asio 1.24.0", "nlohmann_json", "spdlog 1.11.0") | ||||
|  | ||||
| add_defines("ASIO_STANDALONE", "ASIO_HAS_STD_TYPE_TRAITS", "ASIO_HAS_STD_SHARED_PTR",  | ||||
|     "ASIO_HAS_STD_ADDRESSOF", "ASIO_HAS_STD_ATOMIC", "ASIO_HAS_STD_CHRONO", "ASIO_HAS_CSTDINT", "ASIO_HAS_STD_ARRAY", | ||||
|     "ASIO_HAS_STD_SYSTEM_ERROR") | ||||
|  | ||||
| if is_os("windows") then | ||||
|     add_defines("_WEBSOCKETPP_CPP11_INTERNAL_") | ||||
|     add_links("ws2_32", "Bcrypt") | ||||
|     add_requires("cuda") | ||||
| elseif is_os("linux") then  | ||||
|     add_links("pthread") | ||||
|     set_config("cxxflags", "-fPIC") | ||||
| end | ||||
|  | ||||
| add_packages("spdlog") | ||||
|  | ||||
| includes("../../thirdparty") | ||||
|  | ||||
| target("log") | ||||
|     set_kind("headeronly") | ||||
|     add_packages("spdlog") | ||||
|     add_headerfiles("../../src/log/log.h") | ||||
|     add_includedirs("../../src/log", {public = true}) | ||||
|  | ||||
| target("common") | ||||
|     set_kind("headeronly") | ||||
|     add_includedirs("../../src/common", {public = true}) | ||||
|  | ||||
| target("signal_server") | ||||
|     set_kind("binary") | ||||
|     add_deps("log", "common") | ||||
|     add_files("*.cpp") | ||||
|     add_packages("asio", "nlohmann_json", "spdlog") | ||||
|     add_includedirs("../../thirdparty/websocketpp/include") | ||||
| @@ -79,7 +79,7 @@ int VideoEncoder::Encode(const uint8_t *pData, int nSize) { | ||||
|     return -1; | ||||
|   } | ||||
|  | ||||
|   if (0 == seq_++ % (30 * 5)) { | ||||
|   if (0 == seq_++ % (30)) { | ||||
|     ForceIdr(); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| #ifndef _RTP_PACKET_H_ | ||||
| #define _RTP_PACKET_H_ | ||||
|  | ||||
| #include <cstring> | ||||
| #include <stdint.h> | ||||
|  | ||||
| #include <vector> | ||||
|  | ||||
| //  0                   1                   2                   3 | ||||
| @@ -39,16 +40,18 @@ class RtpPacket { | ||||
|  | ||||
|  public: | ||||
|   // Set Header | ||||
|   void SetMarker(bool has_marker) { marker_ = has_marker; } | ||||
|   void SetPayloadType(uint8_t payload_type) { payload_type_ = payload_type; } | ||||
|   void SetVerion(uint32_t version) { version_ = version; } | ||||
|   void SetHasPadding(bool has_padding) { has_padding_ = has_padding; } | ||||
|   void SetHasExtension(bool has_extension) { has_extension_ = has_extension; } | ||||
|   void SetMarker(bool marker) { marker_ = marker; } | ||||
|   void SetPayloadType(uint32_t payload_type) { payload_type_ = payload_type; } | ||||
|   void SetSequenceNumber(uint16_t sequence_number) { | ||||
|     sequence_number_ = sequence_number; | ||||
|   } | ||||
|   void SetTimestamp(uint32_t timestamp) { timestamp_ = timestamp; } | ||||
|   void SetSsrc(uint32_t ssrc) { ssrc_ = ssrc; } | ||||
|   void SetCsrcs(){}; | ||||
|   void SetCsrcs(std::vector<uint32_t> &csrcs) { csrcs_ = csrcs; } | ||||
|  | ||||
|   void SetHasExtension(bool has_extension) { has_extension_ = has_extension; }; | ||||
|   void SetExtensionProfile(uint16_t extension_profile) { | ||||
|     extension_profile_ = extension_profile; | ||||
|   } | ||||
| @@ -64,19 +67,21 @@ class RtpPacket { | ||||
|  | ||||
|  public: | ||||
|   // Get Header | ||||
|   bool Marker() const { return marker_; } | ||||
|   uint8_t PayloadType() const { return payload_type_; } | ||||
|   uint16_t SequenceNumber() const { return sequence_number_; } | ||||
|   uint32_t Timestamp() const { return timestamp_; } | ||||
|   uint32_t Ssrc() const { return ssrc_; } | ||||
|   std::vector<uint32_t> Csrcs() const; | ||||
|   bool HasExtension() const { return has_extension_; }; | ||||
|   uint16_t ExtensionProfile() const { return extension_profile_; } | ||||
|   uint8_t *ExtensionData() const { return extension_data_; } | ||||
|   const uint32_t Verion() { return version_; } | ||||
|   const bool HasPadding() { return has_padding_; } | ||||
|   const bool HasExtension() { return has_extension_; } | ||||
|   const bool Marker() { return marker_; } | ||||
|   const uint32_t PayloadType() { return payload_type_; } | ||||
|   const uint16_t SequenceNumber() { return sequence_number_; } | ||||
|   const uint32_t Timestamp() { return timestamp_; } | ||||
|   const uint32_t Ssrc() { return ssrc_; } | ||||
|   const std::vector<uint32_t> Csrcs() { return csrcs_; }; | ||||
|   const uint16_t ExtensionProfile() { return extension_profile_; } | ||||
|   const uint8_t *ExtensionData() { return extension_data_; } | ||||
|  | ||||
|   // Payload | ||||
|   uint8_t *Payload() const { return payload_; }; | ||||
|   size_t PayloadSize() const { return payload_size_; } | ||||
|   const uint8_t *Payload() { return payload_; }; | ||||
|   const size_t PayloadSize() { return payload_size_; } | ||||
|  | ||||
|  public: | ||||
|   const uint8_t *Buffer() { return buffer_; } | ||||
| @@ -89,7 +94,7 @@ class RtpPacket { | ||||
|   bool has_extension_ = false; | ||||
|   uint32_t total_csrc_number_ = 0; | ||||
|   bool marker_ = false; | ||||
|   uint8_t payload_type_ = 0; | ||||
|   uint32_t payload_type_ = 0; | ||||
|   uint16_t sequence_number_ = 0; | ||||
|   uint32_t timestamp_ = 0; | ||||
|   uint32_t ssrc_ = 0; | ||||
|   | ||||
							
								
								
									
										55
									
								
								src/rtp/rtp_session.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/rtp/rtp_session.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| #include "rtp_session.h" | ||||
|  | ||||
| #include <chrono> | ||||
|  | ||||
| #define RTP_VERSION 1 | ||||
|  | ||||
| RtpSession ::RtpSession(uint32_t payload_type) | ||||
|     : version_(RTP_VERSION), | ||||
|       has_padding_(false), | ||||
|       has_extension_(false), | ||||
|       payload_type_(payload_type), | ||||
|       sequence_number_(0) {} | ||||
|  | ||||
| RtpSession ::~RtpSession() { | ||||
|   if (extension_data_) { | ||||
|     delete extension_data_; | ||||
|     extension_data_ = nullptr; | ||||
|   } | ||||
|  | ||||
|   if (rtp_packet_) { | ||||
|     delete rtp_packet_; | ||||
|     rtp_packet_ = nullptr; | ||||
|   } | ||||
| } | ||||
|  | ||||
| RtpPacket RtpSession::Encode(uint8_t* buffer, size_t size) { | ||||
|   if (!rtp_packet_) { | ||||
|     rtp_packet_ = new RtpPacket(); | ||||
|   } | ||||
|  | ||||
|   rtp_packet_->SetVerion(version_); | ||||
|   rtp_packet_->SetHasPadding(has_padding_); | ||||
|   rtp_packet_->SetHasExtension(has_extension_); | ||||
|   rtp_packet_->SetMarker(marker_); | ||||
|   rtp_packet_->SetPayloadType(payload_type_); | ||||
|   rtp_packet_->SetSequenceNumber(sequence_number_++); | ||||
|  | ||||
|   timestamp_ = | ||||
|       std::chrono::high_resolution_clock::now().time_since_epoch().count(); | ||||
|   rtp_packet_->SetTimestamp(timestamp_); | ||||
|   rtp_packet_->SetSsrc(ssrc_); | ||||
|  | ||||
|   if (!csrcs_.empty()) { | ||||
|     rtp_packet_->SetCsrcs(csrcs_); | ||||
|   } | ||||
|  | ||||
|   if (has_extension_) { | ||||
|     rtp_packet_->SetExtensionProfile(extension_profile_); | ||||
|     rtp_packet_->SetExtensionData(extension_data_, extension_len_); | ||||
|   } | ||||
|  | ||||
|   rtp_packet_->Encode(buffer, size); | ||||
|  | ||||
|   return *rtp_packet_; | ||||
| } | ||||
							
								
								
									
										40
									
								
								src/rtp/rtp_session.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								src/rtp/rtp_session.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| #ifndef _RTP_SESSION_H_ | ||||
| #define _RTP_SESSION_H_ | ||||
|  | ||||
| #include <stdint.h> | ||||
|  | ||||
| #include <vector> | ||||
|  | ||||
| #include "rtp_packet.h" | ||||
|  | ||||
| class RtpSession | ||||
|  | ||||
| { | ||||
|  public: | ||||
|   RtpSession(uint32_t payload_type); | ||||
|   ~RtpSession(); | ||||
|  | ||||
|  public: | ||||
|   RtpPacket Encode(uint8_t* buffer, size_t size); | ||||
|  | ||||
|  private: | ||||
|   uint32_t version_ = 0; | ||||
|   bool has_padding_ = false; | ||||
|   bool has_extension_ = false; | ||||
|   uint32_t total_csrc_number_ = 0; | ||||
|   bool marker_ = false; | ||||
|   uint8_t payload_type_ = 0; | ||||
|   uint16_t sequence_number_ = 0; | ||||
|   uint32_t timestamp_ = 0; | ||||
|   uint32_t ssrc_ = 0; | ||||
|   std::vector<uint32_t> csrcs_; | ||||
|   uint16_t profile_ = 0; | ||||
|   uint16_t extension_profile_ = 0; | ||||
|   uint16_t extension_len_ = 0; | ||||
|   uint8_t* extension_data_ = nullptr; | ||||
|  | ||||
|  private: | ||||
|   RtpPacket* rtp_packet_ = nullptr; | ||||
| }; | ||||
|  | ||||
| #endif | ||||
| @@ -29,6 +29,11 @@ IceTransmission::IceTransmission( | ||||
|       on_receive_ice_msg_cb_(on_receive_ice_msg) {} | ||||
|  | ||||
| IceTransmission::~IceTransmission() { | ||||
|   if (rtp_session_) { | ||||
|     delete rtp_session_; | ||||
|     rtp_session_ = nullptr; | ||||
|   } | ||||
|  | ||||
|   if (ice_agent_) { | ||||
|     delete ice_agent_; | ||||
|     ice_agent_ = nullptr; | ||||
| @@ -107,6 +112,7 @@ int IceTransmission::InitIceTransmission(std::string &ip, int port) { | ||||
|     ikcp_release(kcp); | ||||
|   }); | ||||
|  | ||||
|   rtp_session_ = new RtpSession(1); | ||||
|   ice_agent_ = new IceAgent(ip, port); | ||||
|  | ||||
|   ice_agent_->CreateIceAgent( | ||||
| @@ -269,12 +275,14 @@ int IceTransmission::SendData(const char *data, size_t size) { | ||||
|  | ||||
|     int num = 0; | ||||
|     for (num = 0; num * 1400 < size; num++) { | ||||
|       RtpPacket packet((uint8_t *)(data + num * 1400), 1400); | ||||
|       RtpPacket packet = | ||||
|           rtp_session_->Encode((uint8_t *)(data + num * 1400), 1400); | ||||
|       send_ringbuffer_.push(packet); | ||||
|     } | ||||
|  | ||||
|     if (size - num * 1400 > 0) { | ||||
|       RtpPacket packet((uint8_t *)(data + num * 1400), size - num * 1400); | ||||
|     if (size > num * 1400 && size - num * 1400 > 0) { | ||||
|       RtpPacket packet = rtp_session_->Encode((uint8_t *)(data + num * 1400), | ||||
|                                               size - num * 1400); | ||||
|       send_ringbuffer_.push(packet); | ||||
|     } | ||||
|   } | ||||
|   | ||||
| @@ -7,6 +7,7 @@ | ||||
| #include "ice_agent.h" | ||||
| #include "ringbuffer.h" | ||||
| #include "rtp_packet.h" | ||||
| #include "rtp_session.h" | ||||
| #include "ws_transmission.h" | ||||
| class IceTransmission { | ||||
|  public: | ||||
| @@ -72,6 +73,9 @@ class IceTransmission { | ||||
|   RingBuffer<RtpPacket> recv_ringbuffer_; | ||||
|   bool kcp_stop_ = false; | ||||
|   std::thread *kcp_update_thread_ = nullptr; | ||||
|  | ||||
|  private: | ||||
|   RtpSession *rtp_session_ = nullptr; | ||||
| }; | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										2
									
								
								thirdparty/nvcodec/Interface/nvEncodeAPI.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								thirdparty/nvcodec/Interface/nvEncodeAPI.h
									
									
									
									
										vendored
									
									
								
							| @@ -1522,7 +1522,7 @@ typedef struct _NV_ENC_RC_PARAMS { | ||||
|                                only used if enableLookahead=1.*/ | ||||
|   uint8_t lowDelayKeyFrameScale; /**< [in]: Specifies the ratio of I frame bits | ||||
|                                     to P frame bits in case of single frame VBV | ||||
|                                     and CBR rate control mode, is set to 2 by | ||||
|                                     and CBR rate control mode, is set 2 by | ||||
|                                     default for low latency tuning info and 1 by | ||||
|                                     default for ultra low latency tuning info */ | ||||
|   uint8_t reserved1[3]; | ||||
|   | ||||
| @@ -27,6 +27,7 @@ add_packages("spdlog") | ||||
|  | ||||
| includes("thirdparty") | ||||
| includes("application/remote_desk") | ||||
| includes("application/signal_server") | ||||
|  | ||||
| target("log") | ||||
|     set_kind("headeronly") | ||||
| @@ -113,13 +114,6 @@ target("projectx") | ||||
|     -- set_policy("build.merge_archive", true) | ||||
|     -- set_targetdir("$(projectdir)/libdrtc/lib") | ||||
|  | ||||
| target("signal_server") | ||||
|     set_kind("binary") | ||||
|     add_deps("log", "common") | ||||
|     add_files("tests/signal_server/*.cpp") | ||||
|     add_packages("asio", "nlohmann_json", "spdlog") | ||||
|     add_includedirs("thirdparty/websocketpp/include") | ||||
|  | ||||
| target("host") | ||||
|     set_kind("binary") | ||||
|     add_deps("projectx") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user