From 73c8a5faf445eb12fd1a3e91fa8dde17536cda7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 29 Jul 2023 13:07:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=AE=BE=E7=BD=AE=E5=8D=95?= =?UTF-8?q?=E5=AD=97=E8=8A=82=E5=AF=B9=E9=BD=90=E6=96=B9=E5=BC=8F=20(#2716?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit __attribute__((packed)) 替换为 #pragma pack(push, 1) --- src/Common/macros.h | 8 -------- src/Extension/H264Rtp.cpp | 6 +----- src/Rtcp/Rtcp.h | 26 +++++++++++--------------- src/Rtcp/RtcpFCI.cpp | 4 ++-- src/Rtcp/RtcpFCI.h | 22 +++++++++++----------- src/Rtmp/Rtmp.h | 19 ++++--------------- src/Rtsp/Rtsp.h | 6 +----- webrtc/RtpExt.cpp | 8 ++------ 8 files changed, 32 insertions(+), 67 deletions(-) diff --git a/src/Common/macros.h b/src/Common/macros.h index 4c61d11c..8c86fc10 100644 --- a/src/Common/macros.h +++ b/src/Common/macros.h @@ -32,14 +32,6 @@ #define __LITTLE_ENDIAN LITTLE_ENDIAN #endif -#ifndef PACKED -#if !defined(_WIN32) -#define PACKED __attribute__((packed)) -#else -#define PACKED -#endif //! defined(_WIN32) -#endif - #ifndef CHECK #define CHECK(exp, ...) ::mediakit::Assert_ThrowCpp(!(exp), #exp, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__) #endif // CHECK diff --git a/src/Extension/H264Rtp.cpp b/src/Extension/H264Rtp.cpp index eae8edd1..28c775c6 100644 --- a/src/Extension/H264Rtp.cpp +++ b/src/Extension/H264Rtp.cpp @@ -13,9 +13,7 @@ namespace mediakit{ -#if defined(_WIN32) #pragma pack(push, 1) -#endif // defined(_WIN32) class FuFlags { public: @@ -30,11 +28,9 @@ public: unsigned end_bit: 1; unsigned start_bit: 1; #endif -} PACKED; +}; -#if defined(_WIN32) #pragma pack(pop) -#endif // defined(_WIN32) H264RtpDecoder::H264RtpDecoder() { _frame = obtainFrame(); diff --git a/src/Rtcp/Rtcp.h b/src/Rtcp/Rtcp.h index 9275506c..3511f4a6 100644 --- a/src/Rtcp/Rtcp.h +++ b/src/Rtcp/Rtcp.h @@ -19,9 +19,7 @@ namespace mediakit { -#if defined(_WIN32) #pragma pack(push, 1) -#endif // defined(_WIN32) // http://www.networksorcery.com/enp/protocol/rtcp.htm #define RTCP_PT_MAP(XX) \ @@ -235,7 +233,7 @@ private: */ void net2Host(size_t size); -} PACKED; +}; ///////////////////////////////////////////////////////////////////////////// @@ -272,7 +270,7 @@ private: * 网络字节序转换为主机字节序 */ void net2Host(); -} PACKED; +}; /* * 6.4.1 SR: Sender Report RTCP Packet @@ -371,7 +369,7 @@ private: * @param size 字节长度,防止内存越界 */ void net2Host(size_t size); -} PACKED; +}; ///////////////////////////////////////////////////////////////////////////// @@ -441,7 +439,7 @@ private: */ std::string dumpString() const; -} PACKED; +}; ///////////////////////////////////////////////////////////////////////////// @@ -512,7 +510,7 @@ private: * 网络字节序转换为主机字节序 */ void net2Host(); -} PACKED; +}; // Source description class RtcpSdes : public RtcpHeader { @@ -548,7 +546,7 @@ private: * @param size 字节长度,防止内存越界 */ void net2Host(size_t size); -} PACKED; +}; // https://tools.ietf.org/html/rfc4585#section-6.1 // 6.1. Common Packet Format for Feedback Messages @@ -624,7 +622,7 @@ private: private: static std::shared_ptr create_l(RtcpType type, int fmt, const void *fci, size_t fci_len); -} PACKED; +}; // BYE /* @@ -684,7 +682,7 @@ private: * @param size 字节长度,防止内存越界 */ void net2Host(size_t size); -} PACKED; +}; /* 0 1 2 3 @@ -738,7 +736,7 @@ private: */ void net2Host(size_t size); -} PACKED; +}; /* @@ -777,7 +775,7 @@ private: * @param size 字节长度,防止内存越界 */ void net2Host(); -} PACKED; +}; class RtcpXRDLRR : public RtcpHeader { public: @@ -814,11 +812,9 @@ private: */ void net2Host(size_t size); -} PACKED; +}; -#if defined(_WIN32) #pragma pack(pop) -#endif // defined(_WIN32) } // namespace mediakit #endif // ZLMEDIAKIT_RTCP_H diff --git a/src/Rtcp/RtcpFCI.cpp b/src/Rtcp/RtcpFCI.cpp index c6508217..8ed27670 100644 --- a/src/Rtcp/RtcpFCI.cpp +++ b/src/Rtcp/RtcpFCI.cpp @@ -240,7 +240,7 @@ public: RunLengthChunk(SymbolStatus status, uint16_t run_length); // 打印本对象 string dumpString() const; -} PACKED; +}; RunLengthChunk::RunLengthChunk(SymbolStatus status, uint16_t run_length) { type = 0; @@ -291,7 +291,7 @@ public: StatusVecChunk(bool symbol_bit, const vector &status); // 打印本对象 string dumpString() const; -} PACKED; +}; StatusVecChunk::StatusVecChunk(bool symbol_bit, const vector &status) { CHECK(status.size() << symbol_bit <= 14); diff --git a/src/Rtcp/RtcpFCI.h b/src/Rtcp/RtcpFCI.h index 745dc16a..5ce36aa2 100644 --- a/src/Rtcp/RtcpFCI.h +++ b/src/Rtcp/RtcpFCI.h @@ -55,7 +55,7 @@ public: private: uint32_t data; -} PACKED; +}; #if 0 //PSFB fmt = 3 @@ -97,7 +97,7 @@ public: uint8_t padding; static size_t constexpr kSize = 8; -} PACKED; +}; #endif // PSFB fmt = 4 @@ -125,7 +125,7 @@ private: uint32_t ssrc; uint8_t seq_number; uint8_t reserved[3]; -} PACKED; +}; #if 0 //PSFB fmt = 5 @@ -147,7 +147,7 @@ public: private: uint8_t data[kSize]; -} PACKED; +}; //PSFB fmt = 6 //https://tools.ietf.org/html/rfc5104#section-4.3.2.1 @@ -160,7 +160,7 @@ private: // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ class FCI_TSTN : public FCI_TSTR{ -} PACKED; +}; //PSFB fmt = 7 //https://tools.ietf.org/html/rfc5104#section-4.3.4.1 @@ -183,7 +183,7 @@ public: private: uint8_t data[kSize]; -} PACKED; +}; #endif @@ -233,7 +233,7 @@ private: // SSRC feedback (32 bits) Consists of one or more SSRC entries which // this feedback message applies to. uint32_t ssrc_feedback[1]; -} PACKED; +}; /////////////////////////////////////////// RTPFB //////////////////////////////////////////////////// @@ -265,7 +265,7 @@ private: uint16_t pid; // bitmask of following lost packets (BLP): 16 bits uint16_t blp; -} PACKED; +}; #if 0 //RTPFB fmt = 3 @@ -300,7 +300,7 @@ private: // to the description in section 4.2.1.2. The value is an // unsigned integer [0..511]. uint32_t max_tbr; -} PACKED; +}; //RTPFB fmt = 4 // https://tools.ietf.org/html/rfc5104#section-4.2.2.1 @@ -314,7 +314,7 @@ private: class FCI_TMMBN : public FCI_TMMBR{ public: -} PACKED; +}; #endif enum class SymbolStatus : uint8_t { @@ -374,7 +374,7 @@ private: uint8_t ref_time[3]; // feedback packet count,反馈包号,本包是第几个transport-cc包,每次加1 | uint8_t fb_pkt_count; -} PACKED; +}; } // namespace mediakit #endif // ZLMEDIAKIT_RTCPFCI_H diff --git a/src/Rtmp/Rtmp.h b/src/Rtmp/Rtmp.h index c7fd5262..0e947f72 100644 --- a/src/Rtmp/Rtmp.h +++ b/src/Rtmp/Rtmp.h @@ -18,13 +18,6 @@ #include "Network/Buffer.h" #include "Extension/Track.h" -#if !defined(_WIN32) -#define PACKED __attribute__((packed)) -#else -#define PACKED -#endif //!defined(_WIN32) - - #define DEFAULT_CHUNK_LEN 128 #define HANDSHAKE_PLAINTEXT 0x03 #define RANDOM_LEN (1536 - 8) @@ -65,9 +58,7 @@ namespace mediakit { -#if defined(_WIN32) #pragma pack(push, 1) -#endif // defined(_WIN32) class RtmpHandshake { public: @@ -81,7 +72,7 @@ public: void create_complex_c0c1(); -}PACKED; +}; class RtmpHeader { public: @@ -97,7 +88,7 @@ public: uint8_t body_size[3]; uint8_t type_id; uint8_t stream_index[4]; /* Note, this is little-endian while others are BE */ -}PACKED; +}; class FLVHeader { public: @@ -130,7 +121,7 @@ public: uint32_t length; //固定为0 uint32_t previous_tag_size0; -} PACKED; +}; class RtmpTagHeader { public: @@ -139,11 +130,9 @@ public: uint8_t timestamp[3] = {0}; uint8_t timestamp_ex = 0; uint8_t streamid[3] = {0}; /* Always 0. */ -} PACKED; +}; -#if defined(_WIN32) #pragma pack(pop) -#endif // defined(_WIN32) class RtmpPacket : public toolkit::Buffer{ public: diff --git a/src/Rtsp/Rtsp.h b/src/Rtsp/Rtsp.h index 55e8ee5a..01817315 100644 --- a/src/Rtsp/Rtsp.h +++ b/src/Rtsp/Rtsp.h @@ -65,9 +65,7 @@ typedef enum { }; // namespace Rtsp -#if defined(_WIN32) #pragma pack(push, 1) -#endif // defined(_WIN32) class RtpHeader { public: @@ -132,11 +130,9 @@ private: size_t getPayloadOffset() const; // 返回padding长度 size_t getPaddingSize(size_t rtp_size) const; -} PACKED; +}; -#if defined(_WIN32) #pragma pack(pop) -#endif // defined(_WIN32) // 此rtp为rtp over tcp形式,需要忽略前4个字节 class RtpPacket : public toolkit::BufferRaw { diff --git a/webrtc/RtpExt.cpp b/webrtc/RtpExt.cpp index dda65077..b7d97b5c 100644 --- a/webrtc/RtpExt.cpp +++ b/webrtc/RtpExt.cpp @@ -11,9 +11,7 @@ #include "RtpExt.h" #include "Sdp.h" -#if defined(_WIN32) #pragma pack(push, 1) -#endif // defined(_WIN32) using namespace std; using namespace toolkit; @@ -51,7 +49,7 @@ private: uint8_t id: 4; #endif uint8_t data[1]; -} PACKED; +}; //0 1 2 3 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 @@ -77,11 +75,9 @@ private: uint8_t id; uint8_t len; uint8_t data[1]; -} PACKED; +}; -#if defined(_WIN32) #pragma pack(pop) -#endif // defined(_WIN32) //////////////////////////////////////////////////////////////////