统一设置单字节对齐方式 (#2716)

__attribute__((packed)) 替换为 #pragma pack(push, 1)
This commit is contained in:
夏楚 2023-07-29 13:07:22 +08:00 committed by GitHub
parent 54194fe501
commit 73c8a5faf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 67 deletions

View File

@ -32,14 +32,6 @@
#define __LITTLE_ENDIAN LITTLE_ENDIAN #define __LITTLE_ENDIAN LITTLE_ENDIAN
#endif #endif
#ifndef PACKED
#if !defined(_WIN32)
#define PACKED __attribute__((packed))
#else
#define PACKED
#endif //! defined(_WIN32)
#endif
#ifndef CHECK #ifndef CHECK
#define CHECK(exp, ...) ::mediakit::Assert_ThrowCpp(!(exp), #exp, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__) #define CHECK(exp, ...) ::mediakit::Assert_ThrowCpp(!(exp), #exp, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
#endif // CHECK #endif // CHECK

View File

@ -13,9 +13,7 @@
namespace mediakit{ namespace mediakit{
#if defined(_WIN32)
#pragma pack(push, 1) #pragma pack(push, 1)
#endif // defined(_WIN32)
class FuFlags { class FuFlags {
public: public:
@ -30,11 +28,9 @@ public:
unsigned end_bit: 1; unsigned end_bit: 1;
unsigned start_bit: 1; unsigned start_bit: 1;
#endif #endif
} PACKED; };
#if defined(_WIN32)
#pragma pack(pop) #pragma pack(pop)
#endif // defined(_WIN32)
H264RtpDecoder::H264RtpDecoder() { H264RtpDecoder::H264RtpDecoder() {
_frame = obtainFrame(); _frame = obtainFrame();

View File

@ -19,9 +19,7 @@
namespace mediakit { namespace mediakit {
#if defined(_WIN32)
#pragma pack(push, 1) #pragma pack(push, 1)
#endif // defined(_WIN32)
// http://www.networksorcery.com/enp/protocol/rtcp.htm // http://www.networksorcery.com/enp/protocol/rtcp.htm
#define RTCP_PT_MAP(XX) \ #define RTCP_PT_MAP(XX) \
@ -235,7 +233,7 @@ private:
*/ */
void net2Host(size_t size); void net2Host(size_t size);
} PACKED; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -272,7 +270,7 @@ private:
* *
*/ */
void net2Host(); void net2Host();
} PACKED; };
/* /*
* 6.4.1 SR: Sender Report RTCP Packet * 6.4.1 SR: Sender Report RTCP Packet
@ -371,7 +369,7 @@ private:
* @param size * @param size
*/ */
void net2Host(size_t size); void net2Host(size_t size);
} PACKED; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -441,7 +439,7 @@ private:
*/ */
std::string dumpString() const; std::string dumpString() const;
} PACKED; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -512,7 +510,7 @@ private:
* *
*/ */
void net2Host(); void net2Host();
} PACKED; };
// Source description // Source description
class RtcpSdes : public RtcpHeader { class RtcpSdes : public RtcpHeader {
@ -548,7 +546,7 @@ private:
* @param size * @param size
*/ */
void net2Host(size_t size); void net2Host(size_t size);
} PACKED; };
// https://tools.ietf.org/html/rfc4585#section-6.1 // https://tools.ietf.org/html/rfc4585#section-6.1
// 6.1. Common Packet Format for Feedback Messages // 6.1. Common Packet Format for Feedback Messages
@ -624,7 +622,7 @@ private:
private: private:
static std::shared_ptr<RtcpFB> create_l(RtcpType type, int fmt, const void *fci, size_t fci_len); static std::shared_ptr<RtcpFB> create_l(RtcpType type, int fmt, const void *fci, size_t fci_len);
} PACKED; };
// BYE // BYE
/* /*
@ -684,7 +682,7 @@ private:
* @param size * @param size
*/ */
void net2Host(size_t size); void net2Host(size_t size);
} PACKED; };
/* /*
0 1 2 3 0 1 2 3
@ -738,7 +736,7 @@ private:
*/ */
void net2Host(size_t size); void net2Host(size_t size);
} PACKED; };
/* /*
@ -777,7 +775,7 @@ private:
* @param size * @param size
*/ */
void net2Host(); void net2Host();
} PACKED; };
class RtcpXRDLRR : public RtcpHeader { class RtcpXRDLRR : public RtcpHeader {
public: public:
@ -814,11 +812,9 @@ private:
*/ */
void net2Host(size_t size); void net2Host(size_t size);
} PACKED; };
#if defined(_WIN32)
#pragma pack(pop) #pragma pack(pop)
#endif // defined(_WIN32)
} // namespace mediakit } // namespace mediakit
#endif // ZLMEDIAKIT_RTCP_H #endif // ZLMEDIAKIT_RTCP_H

View File

@ -240,7 +240,7 @@ public:
RunLengthChunk(SymbolStatus status, uint16_t run_length); RunLengthChunk(SymbolStatus status, uint16_t run_length);
// 打印本对象 // 打印本对象
string dumpString() const; string dumpString() const;
} PACKED; };
RunLengthChunk::RunLengthChunk(SymbolStatus status, uint16_t run_length) { RunLengthChunk::RunLengthChunk(SymbolStatus status, uint16_t run_length) {
type = 0; type = 0;
@ -291,7 +291,7 @@ public:
StatusVecChunk(bool symbol_bit, const vector<SymbolStatus> &status); StatusVecChunk(bool symbol_bit, const vector<SymbolStatus> &status);
// 打印本对象 // 打印本对象
string dumpString() const; string dumpString() const;
} PACKED; };
StatusVecChunk::StatusVecChunk(bool symbol_bit, const vector<SymbolStatus> &status) { StatusVecChunk::StatusVecChunk(bool symbol_bit, const vector<SymbolStatus> &status) {
CHECK(status.size() << symbol_bit <= 14); CHECK(status.size() << symbol_bit <= 14);

View File

@ -55,7 +55,7 @@ public:
private: private:
uint32_t data; uint32_t data;
} PACKED; };
#if 0 #if 0
//PSFB fmt = 3 //PSFB fmt = 3
@ -97,7 +97,7 @@ public:
uint8_t padding; uint8_t padding;
static size_t constexpr kSize = 8; static size_t constexpr kSize = 8;
} PACKED; };
#endif #endif
// PSFB fmt = 4 // PSFB fmt = 4
@ -125,7 +125,7 @@ private:
uint32_t ssrc; uint32_t ssrc;
uint8_t seq_number; uint8_t seq_number;
uint8_t reserved[3]; uint8_t reserved[3];
} PACKED; };
#if 0 #if 0
//PSFB fmt = 5 //PSFB fmt = 5
@ -147,7 +147,7 @@ public:
private: private:
uint8_t data[kSize]; uint8_t data[kSize];
} PACKED; };
//PSFB fmt = 6 //PSFB fmt = 6
//https://tools.ietf.org/html/rfc5104#section-4.3.2.1 //https://tools.ietf.org/html/rfc5104#section-4.3.2.1
@ -160,7 +160,7 @@ private:
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
class FCI_TSTN : public FCI_TSTR{ class FCI_TSTN : public FCI_TSTR{
} PACKED; };
//PSFB fmt = 7 //PSFB fmt = 7
//https://tools.ietf.org/html/rfc5104#section-4.3.4.1 //https://tools.ietf.org/html/rfc5104#section-4.3.4.1
@ -183,7 +183,7 @@ public:
private: private:
uint8_t data[kSize]; uint8_t data[kSize];
} PACKED; };
#endif #endif
@ -233,7 +233,7 @@ private:
// SSRC feedback (32 bits) Consists of one or more SSRC entries which // SSRC feedback (32 bits) Consists of one or more SSRC entries which
// this feedback message applies to. // this feedback message applies to.
uint32_t ssrc_feedback[1]; uint32_t ssrc_feedback[1];
} PACKED; };
/////////////////////////////////////////// RTPFB //////////////////////////////////////////////////// /////////////////////////////////////////// RTPFB ////////////////////////////////////////////////////
@ -265,7 +265,7 @@ private:
uint16_t pid; uint16_t pid;
// bitmask of following lost packets (BLP): 16 bits // bitmask of following lost packets (BLP): 16 bits
uint16_t blp; uint16_t blp;
} PACKED; };
#if 0 #if 0
//RTPFB fmt = 3 //RTPFB fmt = 3
@ -300,7 +300,7 @@ private:
// to the description in section 4.2.1.2. The value is an // to the description in section 4.2.1.2. The value is an
// unsigned integer [0..511]. // unsigned integer [0..511].
uint32_t max_tbr; uint32_t max_tbr;
} PACKED; };
//RTPFB fmt = 4 //RTPFB fmt = 4
// https://tools.ietf.org/html/rfc5104#section-4.2.2.1 // https://tools.ietf.org/html/rfc5104#section-4.2.2.1
@ -314,7 +314,7 @@ private:
class FCI_TMMBN : public FCI_TMMBR{ class FCI_TMMBN : public FCI_TMMBR{
public: public:
} PACKED; };
#endif #endif
enum class SymbolStatus : uint8_t { enum class SymbolStatus : uint8_t {
@ -374,7 +374,7 @@ private:
uint8_t ref_time[3]; uint8_t ref_time[3];
// feedback packet count,反馈包号,本包是第几个transport-cc包每次加1 | // feedback packet count,反馈包号,本包是第几个transport-cc包每次加1 |
uint8_t fb_pkt_count; uint8_t fb_pkt_count;
} PACKED; };
} // namespace mediakit } // namespace mediakit
#endif // ZLMEDIAKIT_RTCPFCI_H #endif // ZLMEDIAKIT_RTCPFCI_H

View File

@ -18,13 +18,6 @@
#include "Network/Buffer.h" #include "Network/Buffer.h"
#include "Extension/Track.h" #include "Extension/Track.h"
#if !defined(_WIN32)
#define PACKED __attribute__((packed))
#else
#define PACKED
#endif //!defined(_WIN32)
#define DEFAULT_CHUNK_LEN 128 #define DEFAULT_CHUNK_LEN 128
#define HANDSHAKE_PLAINTEXT 0x03 #define HANDSHAKE_PLAINTEXT 0x03
#define RANDOM_LEN (1536 - 8) #define RANDOM_LEN (1536 - 8)
@ -65,9 +58,7 @@
namespace mediakit { namespace mediakit {
#if defined(_WIN32)
#pragma pack(push, 1) #pragma pack(push, 1)
#endif // defined(_WIN32)
class RtmpHandshake { class RtmpHandshake {
public: public:
@ -81,7 +72,7 @@ public:
void create_complex_c0c1(); void create_complex_c0c1();
}PACKED; };
class RtmpHeader { class RtmpHeader {
public: public:
@ -97,7 +88,7 @@ public:
uint8_t body_size[3]; uint8_t body_size[3];
uint8_t type_id; uint8_t type_id;
uint8_t stream_index[4]; /* Note, this is little-endian while others are BE */ uint8_t stream_index[4]; /* Note, this is little-endian while others are BE */
}PACKED; };
class FLVHeader { class FLVHeader {
public: public:
@ -130,7 +121,7 @@ public:
uint32_t length; uint32_t length;
//固定为0 //固定为0
uint32_t previous_tag_size0; uint32_t previous_tag_size0;
} PACKED; };
class RtmpTagHeader { class RtmpTagHeader {
public: public:
@ -139,11 +130,9 @@ public:
uint8_t timestamp[3] = {0}; uint8_t timestamp[3] = {0};
uint8_t timestamp_ex = 0; uint8_t timestamp_ex = 0;
uint8_t streamid[3] = {0}; /* Always 0. */ uint8_t streamid[3] = {0}; /* Always 0. */
} PACKED; };
#if defined(_WIN32)
#pragma pack(pop) #pragma pack(pop)
#endif // defined(_WIN32)
class RtmpPacket : public toolkit::Buffer{ class RtmpPacket : public toolkit::Buffer{
public: public:

View File

@ -65,9 +65,7 @@ typedef enum {
}; // namespace Rtsp }; // namespace Rtsp
#if defined(_WIN32)
#pragma pack(push, 1) #pragma pack(push, 1)
#endif // defined(_WIN32)
class RtpHeader { class RtpHeader {
public: public:
@ -132,11 +130,9 @@ private:
size_t getPayloadOffset() const; size_t getPayloadOffset() const;
// 返回padding长度 // 返回padding长度
size_t getPaddingSize(size_t rtp_size) const; size_t getPaddingSize(size_t rtp_size) const;
} PACKED; };
#if defined(_WIN32)
#pragma pack(pop) #pragma pack(pop)
#endif // defined(_WIN32)
// 此rtp为rtp over tcp形式需要忽略前4个字节 // 此rtp为rtp over tcp形式需要忽略前4个字节
class RtpPacket : public toolkit::BufferRaw { class RtpPacket : public toolkit::BufferRaw {

View File

@ -11,9 +11,7 @@
#include "RtpExt.h" #include "RtpExt.h"
#include "Sdp.h" #include "Sdp.h"
#if defined(_WIN32)
#pragma pack(push, 1) #pragma pack(push, 1)
#endif // defined(_WIN32)
using namespace std; using namespace std;
using namespace toolkit; using namespace toolkit;
@ -51,7 +49,7 @@ private:
uint8_t id: 4; uint8_t id: 4;
#endif #endif
uint8_t data[1]; uint8_t data[1];
} PACKED; };
//0 1 2 3 //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 // 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 id;
uint8_t len; uint8_t len;
uint8_t data[1]; uint8_t data[1];
} PACKED; };
#if defined(_WIN32)
#pragma pack(pop) #pragma pack(pop)
#endif // defined(_WIN32)
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////