[MPlayer-dev-eng] [PATCH] Remove direct uses of __attribute__((packed)).
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Mon Jan 25 20:55:02 EET 2021
It is not portable and ideally it should not be used
at all.
However as a quick-fix wrap it in a macro so it is not
necessary to edit each occurrence individually to support
other compilers.
Code that is completely platform-dependent anyway is not changed
at this point.
---
libmpcodecs/ad_realaud.c | 5 +-
libmpdemux/asf.h | 29 ++++++++---
libmpdemux/aviheader.h | 5 +-
libmpdemux/demux_ogg.c | 5 +-
libmpdemux/ms_hdr.h | 23 ++++++---
loader/dshow/guids.h | 15 ++++--
loader/dshow/mediatype.h | 5 +-
loader/qtx/qtxsdk/components.h | 90 +++++++++++++++++++++++++---------
mppacked.h | 33 +++++++++++++
stream/stream_netstream.h | 9 +++-
stream/tvi_dshow.c | 5 +-
11 files changed, 179 insertions(+), 45 deletions(-)
create mode 100644 mppacked.h
diff --git a/libmpcodecs/ad_realaud.c b/libmpcodecs/ad_realaud.c
index 76186dba1..34f9b4063 100644
--- a/libmpcodecs/ad_realaud.c
+++ b/libmpcodecs/ad_realaud.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "mp_msg.h"
+#include "mppacked.h"
//#include <stddef.h>
#ifdef HAVE_LIBDL
@@ -147,7 +148,8 @@ typedef struct /*__attribute__((__packed__))*/ {
} ra_init_t;
/* windows dlls need packed structs (no padding) */
-typedef struct __attribute__((__packed__)) {
+MP_PACKED(
+typedef struct, {
int samplerate;
short bits;
short channels;
@@ -157,6 +159,7 @@ typedef struct __attribute__((__packed__)) {
int extradata_len;
void* extradata;
} wra_init_t;
+)
#endif
#ifdef HAVE_LIBDL
diff --git a/libmpdemux/asf.h b/libmpdemux/asf.h
index a2bf546fd..98b457c00 100644
--- a/libmpdemux/asf.h
+++ b/libmpdemux/asf.h
@@ -23,29 +23,35 @@
#include <inttypes.h>
#include "libavutil/common.h"
#include "mpbswap.h"
+#include "mppacked.h"
///////////////////////
// ASF Object Header
///////////////////////
-typedef struct __attribute__((packed)) {
+MP_PACKED(
+typedef struct, {
uint8_t guid[16];
uint64_t size;
} ASF_obj_header_t;
+)
////////////////
// ASF Header
////////////////
-typedef struct __attribute__((packed)) {
+MP_PACKED(
+typedef struct, {
ASF_obj_header_t objh;
uint32_t cno; // number of subchunks
uint8_t v1; // unknown (0x01)
uint8_t v2; // unknown (0x02)
} ASF_header_t;
+)
/////////////////////
// ASF File Header
/////////////////////
-typedef struct __attribute__((packed)) {
+MP_PACKED(
+typedef struct, {
uint8_t stream_id[16]; // stream GUID
uint64_t file_size;
uint64_t creation_time; //File creation time FILETIME 8
@@ -58,11 +64,13 @@ typedef struct __attribute__((packed)) {
uint32_t max_packet_size; //Max size of the packet UINT32 4
uint32_t max_bitrate; //Maximum bitrate of the media (sum of all the stream)
} ASF_file_header_t;
+)
///////////////////////
// ASF Stream Header
///////////////////////
-typedef struct __attribute__((packed)) {
+MP_PACKED(
+typedef struct, {
uint8_t type[16]; // Stream type (audio/video) GUID 16
uint8_t concealment[16]; // Audio error concealment type GUID 16
uint64_t unk1; // Unknown, maybe reserved ( usually contains 0 ) UINT64 8
@@ -71,38 +79,45 @@ typedef struct __attribute__((packed)) {
uint16_t stream_no; //Stream number UINT16 2
uint32_t unk2; //Unknown UINT32 4
} ASF_stream_header_t;
+)
///////////////////////////
// ASF Content Description
///////////////////////////
-typedef struct __attribute__((packed)) {
+MP_PACKED(
+typedef struct, {
uint16_t title_size;
uint16_t author_size;
uint16_t copyright_size;
uint16_t comment_size;
uint16_t rating_size;
} ASF_content_description_t;
+)
////////////////////////
// ASF Segment Header
////////////////////////
-typedef struct __attribute__((packed)) {
+MP_PACKED(
+typedef struct, {
uint8_t streamno;
uint8_t seq;
uint32_t x;
uint8_t flag;
} ASF_segmhdr_t;
+)
//////////////////////
// ASF Stream Chunck
//////////////////////
-typedef struct __attribute__((packed)) {
+MP_PACKED(
+typedef struct, {
uint16_t type;
uint16_t size;
uint32_t sequence_number;
uint16_t unknown;
uint16_t size_confirm;
} ASF_stream_chunck_t;
+)
// Definition of the stream type
#if HAVE_BIGENDIAN
diff --git a/libmpdemux/aviheader.h b/libmpdemux/aviheader.h
index 0d5a19db6..0a2f594b5 100644
--- a/libmpdemux/aviheader.h
+++ b/libmpdemux/aviheader.h
@@ -24,6 +24,7 @@
#include "config.h" /* get correct definition of HAVE_BIGENDIAN */
#include "libavutil/common.h"
#include "mpbswap.h"
+#include "mppacked.h"
#include "demuxer.h"
#ifndef mmioFOURCC
@@ -150,7 +151,8 @@ typedef struct avistdindex_entry {
} avistdindex_entry;
// Standard index
-typedef struct __attribute__((packed)) avistdindex_chunk {
+MP_PACKED(
+typedef struct, avistdindex_chunk {
char fcc[4]; // ix##
uint32_t dwSize; // size of this chunk
uint16_t wLongsPerEntry; // must be sizeof(aIndex[0])/sizeof(DWORD)
@@ -162,6 +164,7 @@ typedef struct __attribute__((packed)) avistdindex_chunk {
uint32_t dwReserved3; // must be 0
avistdindex_entry *aIndex; // the actual frames
} avistdindex_chunk;
+)
// Base Index Form 'indx'
diff --git a/libmpdemux/demux_ogg.c b/libmpdemux/demux_ogg.c
index e15794c91..59066b037 100644
--- a/libmpdemux/demux_ogg.c
+++ b/libmpdemux/demux_ogg.c
@@ -28,6 +28,7 @@
#include "mp_msg.h"
#include "help_mp.h"
#include "mpcommon.h"
+#include "mppacked.h"
#include "stream/stream.h"
#include "demuxer.h"
#include "stheader.h"
@@ -81,7 +82,8 @@ typedef struct stream_header_audio {
ogg_int32_t avgbytespersec;
} stream_header_audio;
-typedef struct __attribute__((__packed__)) stream_header {
+MP_PACKED(
+typedef struct, stream_header {
char streamtype[8];
char subtype[4];
@@ -103,6 +105,7 @@ typedef struct __attribute__((__packed__)) stream_header {
stream_header_audio audio;
} sh;
} stream_header;
+)
/// Our private datas
diff --git a/libmpdemux/ms_hdr.h b/libmpdemux/ms_hdr.h
index 3d6bc0754..56085db5a 100644
--- a/libmpdemux/ms_hdr.h
+++ b/libmpdemux/ms_hdr.h
@@ -20,10 +20,12 @@
#define MPLAYER_MS_HDR_H
#include "config.h"
+#include "mppacked.h"
#ifndef _WAVEFORMATEX_
#define _WAVEFORMATEX_
-typedef struct __attribute__((__packed__)) _WAVEFORMATEX {
+MP_PACKED(
+typedef struct, _WAVEFORMATEX {
unsigned short wFormatTag;
unsigned short nChannels;
unsigned int nSamplesPerSec;
@@ -31,23 +33,28 @@ typedef struct __attribute__((__packed__)) _WAVEFORMATEX {
unsigned short nBlockAlign;
unsigned short wBitsPerSample;
unsigned short cbSize;
-} WAVEFORMATEX, *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
+} WAVEFORMATEX;
+)
+typedef WAVEFORMATEX *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
#endif /* _WAVEFORMATEX_ */
#ifndef _WAVEFORMATEXTENSIBLE_
#define _WAVEFORMATEXTENSIBLE_
-typedef struct __attribute__((__packed__)) _WAVEFORMATEXTENSIBLE {
+MP_PACKED(
+typedef struct, _WAVEFORMATEXTENSIBLE {
WAVEFORMATEX wf;
unsigned short wValidBitsPerSample;
unsigned int dwChannelMask;
unsigned int SubFormat; // Only interested in first 32 bits of guid
unsigned int _guid_remainder[3];
} WAVEFORMATEXTENSIBLE;
+)
#endif /* _WAVEFORMATEXTENSIBLE_ */
#ifndef _MPEGLAYER3WAVEFORMAT_
#define _MPEGLAYER3WAVEFORMAT_
-typedef struct __attribute__((__packed__)) mpeglayer3waveformat_tag {
+MP_PACKED(
+typedef struct, mpeglayer3waveformat_tag {
WAVEFORMATEX wf;
unsigned short wID;
unsigned int fdwFlags;
@@ -55,12 +62,14 @@ typedef struct __attribute__((__packed__)) mpeglayer3waveformat_tag {
unsigned short nFramesPerBlock;
unsigned short nCodecDelay;
} MPEGLAYER3WAVEFORMAT;
+)
#endif /* _MPEGLAYER3WAVEFORMAT_ */
/* windows.h #includes wingdi.h on MinGW. */
#if !defined(_BITMAPINFOHEADER_) && !defined(_WINGDI_)
#define _BITMAPINFOHEADER_
-typedef struct __attribute__((__packed__))
+MP_PACKED(
+typedef struct,
{
int biSize;
int biWidth;
@@ -73,7 +82,9 @@ typedef struct __attribute__((__packed__))
int biYPelsPerMeter;
int biClrUsed;
int biClrImportant;
-} BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
+} BITMAPINFOHEADER;
+)
+typedef BITMAPINFOHEADER *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
typedef struct {
BITMAPINFOHEADER bmiHeader;
int bmiColors[1];
diff --git a/loader/dshow/guids.h b/loader/dshow/guids.h
index 76a4970d2..cd708f7c7 100644
--- a/loader/dshow/guids.h
+++ b/loader/dshow/guids.h
@@ -18,18 +18,26 @@ under MinGW
#include "mediatype.h"
+#include "mppacked.h"
+
//#define Debug if(1)
#define Debug if(0)
typedef long long REFERENCE_TIME;
-typedef struct __attribute__((__packed__)) RECT32
+MP_PACKED(
+typedef struct, RECT32
{
- int left, top, right, bottom;
+ int left
+ int top
+ int right
+ int bottom;
} RECT32;
+)
-typedef struct __attribute__((__packed__)) tagVIDEOINFOHEADER
+MP_PACKED(
+typedef struct, tagVIDEOINFOHEADER
{
RECT32 rcSource; // The bit we really want to use
RECT32 rcTarget; // Where the video should go
@@ -39,6 +47,7 @@ typedef struct __attribute__((__packed__)) tagVIDEOINFOHEADER
BITMAPINFOHEADER bmiHeader;
//int reserved[3];
} VIDEOINFOHEADER;
+)
typedef GUID CLSID;
typedef GUID IID;
diff --git a/loader/dshow/mediatype.h b/loader/dshow/mediatype.h
index ecb696ca3..dc6d10e43 100644
--- a/loader/dshow/mediatype.h
+++ b/loader/dshow/mediatype.h
@@ -8,8 +8,10 @@
#define MPLAYER_MEDIATYPE_H
#include "guids.h"
+#include "mppacked.h"
-typedef struct __attribute__((__packed__)) MediaType
+MP_PACKED(
+typedef struct, MediaType
{
GUID majortype; //0x0
GUID subtype; //0x10
@@ -21,6 +23,7 @@ typedef struct __attribute__((__packed__)) MediaType
unsigned long cbFormat; //0x40
char* pbFormat; //0x44
} AM_MEDIA_TYPE;
+)
/**
* \brief print info from AM_MEDIA_TYPE structure
diff --git a/loader/qtx/qtxsdk/components.h b/loader/qtx/qtxsdk/components.h
index e621a6250..5ad7572d8 100644
--- a/loader/qtx/qtxsdk/components.h
+++ b/loader/qtx/qtxsdk/components.h
@@ -3,6 +3,8 @@
#include <inttypes.h>
+#include "mppacked.h"
+
// Basic types:
typedef char * Ptr;
@@ -39,99 +41,121 @@ enum {
//==================== COMPONENTS ===========================
-struct __attribute__((__packed__)) ComponentParameters {
+MP_PACKED(
+struct, ComponentParameters {
UInt8 flags; /* call modifiers: sync/async, deferred, immed, etc */
UInt8 paramSize; /* size in bytes of actual parameters passed to this call */
short what; /* routine selector, negative for Component management calls */
int32_t params[1]; /* actual parameters for the indicated routine */
};
+)
typedef struct ComponentParameters ComponentParameters;
-struct __attribute__((__packed__)) ComponentDescription {
+MP_PACKED(
+struct, ComponentDescription {
OSType componentType; /* A unique 4-byte code indentifying the command set */
OSType componentSubType; /* Particular flavor of this instance */
OSType componentManufacturer; /* Vendor indentification */
uint32_t componentFlags; /* 8 each for Component,Type,SubType,Manuf/revision */
uint32_t componentFlagsMask; /* Mask for specifying which flags to consider in search, zero during registration */
};
+)
typedef struct ComponentDescription ComponentDescription;
-struct __attribute__((__packed__)) ResourceSpec {
+MP_PACKED(
+struct, ResourceSpec {
OSType resType; /* 4-byte code */
short resID; /* */
};
+)
typedef struct ResourceSpec ResourceSpec;
-struct __attribute__((__packed__)) ComponentResource {
+MP_PACKED(
+struct, ComponentResource {
ComponentDescription cd; /* Registration parameters */
ResourceSpec component; /* resource where Component code is found */
ResourceSpec componentName; /* name string resource */
ResourceSpec componentInfo; /* info string resource */
ResourceSpec componentIcon; /* icon resource */
};
+)
typedef struct ComponentResource ComponentResource;
typedef ComponentResource * ComponentResourcePtr;
typedef ComponentResourcePtr * ComponentResourceHandle;
-struct __attribute__((__packed__)) ComponentRecord {
+MP_PACKED(
+struct, ComponentRecord {
int32_t data[1];
};
+)
typedef struct ComponentRecord ComponentRecord;
typedef ComponentRecord * Component;
-struct __attribute__((__packed__)) ComponentInstanceRecord {
+MP_PACKED(
+struct, ComponentInstanceRecord {
int32_t data[1];
};
+)
typedef struct ComponentInstanceRecord ComponentInstanceRecord;
typedef ComponentInstanceRecord * ComponentInstance;
// ========================= QUICKDRAW =========================
-struct __attribute__((__packed__)) Rect {
+MP_PACKED(
+struct, Rect {
short top;
short left;
short bottom;
short right;
};
+)
typedef struct Rect Rect;
typedef Rect * RectPtr;
-struct __attribute__((__packed__)) RGBColor {
+MP_PACKED(
+struct, RGBColor {
unsigned short red; /*magnitude of red component*/
unsigned short green; /*magnitude of green component*/
unsigned short blue; /*magnitude of blue component*/
};
+)
typedef struct RGBColor RGBColor;
typedef RGBColor * RGBColorPtr;
typedef RGBColorPtr * RGBColorHdl;
-struct __attribute__((__packed__)) ColorSpec {
+MP_PACKED(
+struct, ColorSpec {
short value; /*index or other value*/
RGBColor rgb; /*true color*/
};
+)
typedef struct ColorSpec ColorSpec;
typedef ColorSpec * ColorSpecPtr;
typedef ColorSpec CSpecArray[1];
-struct __attribute__((__packed__)) ColorTable {
+MP_PACKED(
+struct, ColorTable {
int32_t ctSeed; /*unique identifier for table*/
short ctFlags; /*high bit: 0 = PixMap; 1 = device*/
short ctSize; /*number of entries in CTTable*/
CSpecArray ctTable; /*array [0..0] of ColorSpec*/
};
+)
typedef struct ColorTable ColorTable;
typedef ColorTable * CTabPtr;
typedef CTabPtr * CTabHandle;
-struct __attribute__((__packed__)) MatrixRecord {
+MP_PACKED(
+struct, MatrixRecord {
Fixed matrix[3][3];
};
+)
typedef struct MatrixRecord MatrixRecord;
typedef MatrixRecord * MatrixRecordPtr;
@@ -140,7 +164,8 @@ typedef OSType CodecType;
typedef unsigned short CodecFlags;
typedef uint32_t CodecQ;
-struct __attribute__((__packed__)) ImageDescription {
+MP_PACKED(
+struct, ImageDescription {
int32_t idSize; /* total size of ImageDescription including extra data ( CLUTs and other per sequence data ) */
CodecType cType; /* what kind of codec compressed this data */
int32_t resvd1; /* reserved for Apple use */
@@ -161,6 +186,7 @@ struct __attribute__((__packed__)) ImageDescription {
short depth; /* what depth is this data (1-32) or ( 33-40 grayscale ) */
short clutID; /* clut id or if 0 clut follows or -1 if no clut */
};
+)
typedef struct ImageDescription ImageDescription;
typedef ImageDescription * ImageDescriptionPtr;
typedef ImageDescriptionPtr * ImageDescriptionHandle;
@@ -185,7 +211,8 @@ enum {
k2vuyPixelFormat = FOUR_CHAR_CODE('2','v','u','y') /* UYVY 4:2:2 byte ordering 16*/
};
-struct __attribute__((__packed__)) PixMapExtension {
+MP_PACKED(
+struct, PixMapExtension {
int32_t extSize; /*size of struct, duh!*/
uint32_t pmBits; /*pixmap attributes bitfield*/
void * pmGD; /*this is a GDHandle*/
@@ -197,13 +224,15 @@ struct __attribute__((__packed__)) PixMapExtension {
uint32_t signature;
Handle baseAddrHandle;
};
+)
typedef struct PixMapExtension PixMapExtension;
typedef PixMapExtension * PixMapExtPtr;
typedef PixMapExtPtr * PixMapExtHandle;
-struct __attribute__((__packed__)) PixMap {
+MP_PACKED(
+struct, PixMap {
Ptr baseAddr; /*pointer to pixels*/
short rowBytes; /*offset to next line*/
Rect bounds; /*encloses bitmap*/
@@ -220,16 +249,19 @@ struct __attribute__((__packed__)) PixMap {
CTabHandle pmTable; /*color map for this pixMap*/
PixMapExtHandle pmExt; /*Handle to pixMap extension*/
};
+)
typedef struct PixMap PixMap;
typedef PixMap * PixMapPtr;
typedef PixMapPtr * PixMapHandle;
-struct __attribute__((__packed__)) BitMap {
+MP_PACKED(
+struct, BitMap {
Ptr baseAddr;
short rowBytes;
Rect bounds;
};
+)
typedef struct BitMap BitMap;
typedef BitMap * BitMapPtr;
typedef BitMapPtr * BitMapHandle;
@@ -241,12 +273,15 @@ struct Pattern {
typedef struct Pattern Pattern;
typedef unsigned char Style;
typedef Style StyleField;
-struct __attribute__((__packed__)) Point {
+MP_PACKED(
+struct, Point {
short v;
short h;
};
+)
typedef struct Point Point;
-struct __attribute__((__packed__)) GrafPort {
+MP_PACKED(
+struct, GrafPort {
short device;
BitMap portBits;
Rect portRect;
@@ -274,6 +309,7 @@ struct __attribute__((__packed__)) GrafPort {
Handle polySave;
/*QDProcsPtr*/void* grafProcs;
};
+)
typedef struct GrafPort GrafPort;
typedef GrafPort *GWorldPtr;
typedef GWorldPtr *GWorldHandle;
@@ -417,7 +453,8 @@ enum {
-struct __attribute__((__packed__)) CodecCapabilities {
+MP_PACKED(
+struct, CodecCapabilities {
int32_t flags;
short wantedPixelSize;
short extendWidth;
@@ -428,9 +465,11 @@ struct __attribute__((__packed__)) CodecCapabilities {
uint32_t time;
int32_t flags2; /* field new in QuickTime 4.0 */
};
+)
typedef struct CodecCapabilities CodecCapabilities;
-struct __attribute__((__packed__)) CodecDecompressParams {
+MP_PACKED(
+struct, CodecDecompressParams {
ImageSequence sequenceID; /* predecompress,banddecompress */
ImageDescriptionHandle imageDescription; /* predecompress,banddecompress */
Ptr data;
@@ -502,11 +541,13 @@ struct __attribute__((__packed__)) CodecDecompressParams {
UInt32 taskWeight; /* preferred weight for MP tasks implementing this operation*/
OSType taskName; /* preferred name (type) for MP tasks implementing this operation*/
};
+)
typedef struct CodecDecompressParams CodecDecompressParams;
-struct __attribute__((__packed__)) ImageSubCodecDecompressCapabilities {
+MP_PACKED(
+struct, ImageSubCodecDecompressCapabilities {
int32_t recordSize; /* sizeof(ImageSubCodecDecompressCapabilities)*/
int32_t decompressRecordSize; /* size of your codec's decompress record*/
Boolean canAsync; /* default true*/
@@ -525,10 +566,12 @@ struct __attribute__((__packed__)) ImageSubCodecDecompressCapabilities {
Boolean isChildCodec; /* set by base codec before calling Initialize*/
UInt8 pad3[3];
};
+)
typedef struct ImageSubCodecDecompressCapabilities ImageSubCodecDecompressCapabilities;
-struct __attribute__((__packed__)) ImageSubCodecDecompressRecord {
+MP_PACKED(
+struct, ImageSubCodecDecompressRecord {
Ptr baseAddr;
int32_t rowBytes;
Ptr codecData;
@@ -544,6 +587,7 @@ struct __attribute__((__packed__)) ImageSubCodecDecompressRecord {
ImageCodecDrawBandCompleteUPP drawBandCompleteUPP; /* only used if subcodec set subCodecCallsDrawBandComplete; if drawBandCompleteUPP is non-nil, codec must call it when a frame is finished, but may return from DrawBand before the frame is finished. */
void * drawBandCompleteRefCon; /* Note: do not call drawBandCompleteUPP directly from a hardware interrupt; instead, use DTInstall to run a function at deferred task time, and call drawBandCompleteUPP from that. */
};
+)
typedef struct ImageSubCodecDecompressRecord ImageSubCodecDecompressRecord;
@@ -593,7 +637,8 @@ enum {
codecInfoSequenceSensitive = (1L << 13) /* compressed data is sensitive to out of sequence decoding */
};
-struct __attribute__((__packed__)) CodecInfo {
+MP_PACKED(
+struct, CodecInfo {
Str31 typeName; /* name of the codec type i.e.: 'Apple Image Compression' */
short version; /* version of the codec data that this codec knows about */
short revisionLevel; /* revision level of this codec i.e: 0x00010001 (1.0.1) */
@@ -613,6 +658,7 @@ struct __attribute__((__packed__)) CodecInfo {
short compressPipelineLatency; /* in milliseconds ( for asynchronous codecs ) */
int32_t privateData;
};
+)
typedef struct CodecInfo CodecInfo;
enum {
diff --git a/mppacked.h b/mppacked.h
new file mode 100644
index 000000000..f17c61d7c
--- /dev/null
+++ b/mppacked.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_MPPACKED_H
+#define MPLAYER_MPPACKED_H
+
+#ifdef _MSC_VER
+// actually also works for newer gcc
+#define MP_PACKED(type, name_and_def) \
+_Pragma("pack(push, 1)") \
+type name_and_def \
+_Pragma("pack(pop)")
+#else
+#define MP_PACKED(type, name_and_def) \
+type __attribute__((packed)) name_and_def
+#endif
+
+#endif /* MPLAYER_MPPACKED_H */
diff --git a/stream/stream_netstream.h b/stream/stream_netstream.h
index 456094fa9..1f4d0a8fb 100644
--- a/stream/stream_netstream.h
+++ b/stream/stream_netstream.h
@@ -36,13 +36,16 @@
#include "mp_msg.h"
#include "mpbswap.h"
+#include "mppacked.h"
#include "network.h"
+MP_PACKED(
typedef struct mp_net_stream_packet_st {
uint16_t len;
uint8_t cmd;
char data[0];
-} __attribute__ ((packed)) mp_net_stream_packet_t;
+}, mp_net_stream_packet_t;
+)
#define PACKET_MAX_SIZE 4096
@@ -61,13 +64,15 @@ typedef struct mp_net_stream_packet_st {
// Server response
#define NET_STREAM_OK 128
// Data returned if open is successful
+MP_PACKED(
typedef struct mp_net_stream_opened_st {
uint32_t file_format;
uint32_t flags;
uint32_t sector_size;
uint64_t start_pos;
uint64_t end_pos;
-} __attribute__ ((packed)) mp_net_stream_opened_t;
+}, mp_net_stream_opened_t;
+)
// FILL_BUFFER return the data
// CLOSE return nothing
#define NET_STREAM_ERROR 129
diff --git a/stream/tvi_dshow.c b/stream/tvi_dshow.c
index aafd278f4..00c3975bd 100644
--- a/stream/tvi_dshow.c
+++ b/stream/tvi_dshow.c
@@ -86,6 +86,7 @@
#include "tv.h"
#include "mp_msg.h"
+#include "mppacked.h"
#include "frequencies.h"
@@ -221,12 +222,14 @@ typedef struct priv {
\note
structure have to be 2-byte aligned and have 10-byte length!!
*/
-typedef struct __attribute__((__packed__)) {
+MP_PACKED(
+typedef struct, {
WORD CountryCode; ///< Country code
WORD CableFreqTable; ///< index of resource with frequencies for cable channels
WORD BroadcastFreqTable; ///< index of resource with frequencies for broadcast channels
DWORD VideoStandard; ///< used video standard
} TRCCountryList;
+)
/**
information about image formats
*/
--
2.30.0
More information about the MPlayer-dev-eng
mailing list