DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
src/aviwriter/avi.h
00001 #ifndef __VIDEOMGR_UTIL_AVI_H
00002 #define __VIDEOMGR_UTIL_AVI_H
00003 
00004 #include <stdint.h>
00005 
00006 #include "informational.h"
00007 #include "wave_mmreg.h"
00008 #include "waveformatex.h"
00009 #include "bitmapinfoheader.h"
00010 #include "riff.h"
00011 
00012 #if defined(_MSC_VER)
00013 # pragma pack(push,1)
00014 #endif
00015 
00016 /* typedef for an AVI FOURCC */
00017 typedef uint32_t avi_fourcc_t;
00018 
00019 /* take chars and form them into an AVI FOURCC (little endian byte order) */
00020 #define avi_fourcc_const(a,b,c,d)       ( (((uint32_t)(a)) << 0U) | (((uint32_t)(b)) << 8U) | (((uint32_t)(c)) << 16U) | (((uint32_t)(d)) << 24U) )
00021 
00022 /* common AVI FOURCCs */
00023 #define avi_riff_AVI                    avi_fourcc_const('A','V','I',' ')
00024 #define avi_riff_movi                   avi_fourcc_const('m','o','v','i')
00025 #define avi_riff_hdrl                   avi_fourcc_const('h','d','r','l')
00026 #define avi_riff_idx1                   avi_fourcc_const('i','d','x','1')
00027 #define avi_riff_indx                   avi_fourcc_const('i','n','d','x')
00028 #define avi_riff_avih                   avi_fourcc_const('a','v','i','h')
00029 #define avi_riff_strl                   avi_fourcc_const('s','t','r','l')
00030 #define avi_riff_strh                   avi_fourcc_const('s','t','r','h')
00031 #define avi_riff_strf                   avi_fourcc_const('s','t','r','f')
00032 #define avi_riff_vprp                   avi_fourcc_const('v','p','r','p')
00033 #define avi_riff_dmlh                   avi_fourcc_const('d','m','l','h')
00034 #define avi_riff_odml                   avi_fourcc_const('o','d','m','l')
00035 
00036 #define avi_fccType_audio               avi_fourcc_const('a','u','d','s')
00037 #define avi_fccType_video               avi_fourcc_const('v','i','d','s')
00038 #define avi_fccType_iavs                avi_fourcc_const('i','a','v','s')
00039 
00040 /* AVI file struct: AVIMAINHEADER */
00041 /* AVI placement in file:
00042  * 
00043  * RIFF:AVI
00044  *   LIST:hdrl
00045  *     avih            <------- *HERE* usually first chunk in hdrl list
00046  *   LIST:strl
00047  *     strh
00048  *     strf
00049  * ...
00050  */
00051 typedef struct {                                                /* (sizeof) (offset hex) (offset dec) */
00052         /* NTS: The first two fields defined in Microsoft's SDK headers are not repeated here, because
00053          *      they are effectively the AVI RIFF chunk header, which most of our code does not include
00054          *      as part of the read (why did you do that, Microsoft?) */
00055         /* FOURCC       fcc */
00056         /* uint32_t     cb */
00057         uint32_t _Little_Endian_        dwMicroSecPerFrame;     /* (4)  +0x00 +0 */
00058         uint32_t _Little_Endian_        dwMaxBytesPerSec;       /* (4)  +0x04 +4 */
00059         uint32_t _Little_Endian_        dwPaddingGranularity;   /* (4)  +0x08 +8 */
00060         uint32_t _Little_Endian_        dwFlags;                /* (4)  +0x0C +12 */
00061         uint32_t _Little_Endian_        dwTotalFrames;          /* (4)  +0x10 +16 */
00062         uint32_t _Little_Endian_        dwInitialFrames;        /* (4)  +0x14 +20 */
00063         uint32_t _Little_Endian_        dwStreams;              /* (4)  +0x18 +24 */
00064         uint32_t _Little_Endian_        dwSuggestedBufferSize;  /* (4)  +0x1C +28 */
00065         uint32_t _Little_Endian_        dwWidth;                /* (4)  +0x20 +32 */
00066         uint32_t _Little_Endian_        dwHeight;               /* (4)  +0x24 +36 */
00067         uint32_t _Little_Endian_        dwReserved[4];          /* (16) +0x28 +40 */
00068 } GCC_ATTRIBUTE(packed) riff_avih_AVIMAINHEADER;                /* (56) =0x38 =56 */
00069 
00070 #define riff_avih_AVIMAINHEADER_flags_HASINDEX                          0x00000010UL
00071 #define riff_avih_AVIMAINHEADER_flags_MUSTUSEINDEX                      0x00000020UL
00072 #define riff_avih_AVIMAINHEADER_flags_ISINTERLEAVED                     0x00000100UL
00073 #define riff_avih_AVIMAINHEADER_flags_TRUSTCKTYPE                       0x00000800UL
00074 #define riff_avih_AVIMAINHEADER_flags_WASCAPTUREFILE                    0x00010000UL
00075 #define riff_avih_AVIMAINHEADER_flags_COPYRIGHTED                       0x00020000UL
00076 
00077 /* AVI file struct: AVISTREAMHEADER */
00078 /* AVI placement in file:
00079  * 
00080  * RIFF:AVI
00081  *   LIST:hdrl
00082  *     avih
00083  *   LIST:strl         <------- one LIST per AVI stream
00084  *     strh            <------- *HERE* usually first chunk in strl list
00085  *     strf
00086  * ...
00087  */
00088 typedef struct {                                                /* (sizeof) (offset hex) (offset dec) */
00089         /* NTS: The first two fields defined in Microsoft's SDK headers are not repeated here, because
00090          *      they are effectively the AVI RIFF chunk header, which most of our code does not include
00091          *      as part of the read (why did you do that, Microsoft?) */
00092         /* FOURCC       fcc */
00093         /* uint32_t     cb */
00094         avi_fourcc_t _Little_Endian_    fccType;                /* (4)  +0x00 +0 */
00095         avi_fourcc_t _Little_Endian_    fccHandler;             /* (4)  +0x04 +4 */
00096         uint32_t _Little_Endian_        dwFlags;                /* (4)  +0x08 +8 */
00097         uint16_t _Little_Endian_        wPriority;              /* (2)  +0x0C +12 */
00098         uint16_t _Little_Endian_        wLanguage;              /* (2)  +0x0E +14 */
00099         uint32_t _Little_Endian_        dwInitialFrames;        /* (4)  +0x10 +16 */
00100         uint32_t _Little_Endian_        dwScale;                /* (4)  +0x14 +20 */
00101         uint32_t _Little_Endian_        dwRate;                 /* (4)  +0x18 +24 */
00102         uint32_t _Little_Endian_        dwStart;                /* (4)  +0x1C +28 */
00103         uint32_t _Little_Endian_        dwLength;               /* (4)  +0x20 +32 */
00104         uint32_t _Little_Endian_        dwSuggestedBufferSize;  /* (4)  +0x24 +36 */
00105         uint32_t _Little_Endian_        dwQuality;              /* (4)  +0x28 +40 */
00106         uint32_t _Little_Endian_        dwSampleSize;           /* (4)  +0x2C +44 */
00107         struct {
00108                 int16_t _Little_Endian_ left;                   /* (2)  +0x30 +48 */
00109                 int16_t _Little_Endian_ top;                    /* (2)  +0x32 +50 */
00110                 int16_t _Little_Endian_ right;                  /* (2)  +0x34 +52 */
00111                 int16_t _Little_Endian_ bottom;                 /* (2)  +0x36 +54 */
00112         } GCC_ATTRIBUTE(packed) rcFrame;
00113 } GCC_ATTRIBUTE(packed) riff_strh_AVISTREAMHEADER;              /* (56) +0x38 +56 */
00114 
00115 static const riff_strh_AVISTREAMHEADER riff_strh_AVISTREAMHEADER_INIT = {
00116         0,
00117         0,
00118         0,
00119         0,
00120         0,
00121         0,//uint32_t        dwInitialFrames;
00122         0,//uint32_t        dwScale;
00123         0,//uint32_t        dwRate;
00124         0,//uint32_t        dwStart;
00125         0,//uint32_t        dwLength;
00126         0,//uint32_t        dwSuggestedBufferSize;
00127         0,//uint32_t        dwQuality;
00128         0,//uint32_t        dwSampleSize;
00129         { 0,0,0,0 }
00130 };
00131 
00132 #define riff_strh_AVISTREAMHEADER_flags_DISABLED                        0x00000001UL
00133 #define riff_strh_AVISTREAMHEADER_flags_VIDEO_PALCHANGES                0x00010000UL
00134 
00135 /* AVIPALCHANGE */
00136 typedef struct {
00137         uint8_t         bFirstEntry;
00138         uint8_t         bNumEntries;
00139         uint16_t        wFlags;
00140         /* PALETTEENTRY[] */
00141 } GCC_ATTRIBUTE(packed) riff_AVIPALCHANGE_header;
00142 
00143 /* AVI palette entry */
00144 typedef struct {
00145         uint8_t         peRed,peGreen,peBlue,peFlags;
00146 } GCC_ATTRIBUTE(packed) riff_AVIPALCHANGE_PALETTEENTRY;
00147 
00148 #define riff_AVIPALCHANGE_PALETTEENTRY_flags_PC_RESERVED                0x01U
00149 #define riff_AVIPALCHANGE_PALETTEENTRY_flags_PC_EXPLICIT                0x02U
00150 #define riff_AVIPALCHANGE_PALETTEENTRY_flags_PC_NOCOLLAPSE              0x04U
00151 
00152 /* AVIOLDINDEX (one element of the structure) */
00153 typedef struct {
00154         uint32_t        dwChunkId;
00155         uint32_t        dwFlags;
00156         uint32_t        dwOffset;
00157         uint32_t        dwSize;
00158 } GCC_ATTRIBUTE(packed) riff_idx1_AVIOLDINDEX;
00159 
00160 /* AVIOLDINDEX chunk IDs. NOTE that this chunk ID makes the last two bytes of dwChunkId (the upper 16 bits) */
00161 /* NOTICE due to little Endian byte order the string is typed in reverse here */
00162 #define riff_idx1_AVIOLDINDEX_chunkid_type_mask                         0xFFFF0000UL
00163 #define riff_idx1_AVIOLDINDEX_chunkid_stream_index_mask                 0x0000FFFFUL
00164 #define riff_idx1_AVIOLDINDEX_chunkid_uncompressed_videoframe           avi_fourcc_const(0,0,'d','b')
00165 #define riff_idx1_AVIOLDINDEX_chunkid_compressed_videoframe             avi_fourcc_const(0,0,'d','c')
00166 #define riff_idx1_AVIOLDINDEX_chunkid_palette_change                    avi_fourcc_const(0,0,'p','c')
00167 #define riff_idx1_AVIOLDINDEX_chunkid_audio_data                        avi_fourcc_const(0,0,'w','b')
00168 
00169 #define riff_idx1_AVIOLDINDEX_flags_LIST                                0x00000001UL
00170 #define riff_idx1_AVIOLDINDEX_flags_KEYFRAME                            0x00000010UL
00171 #define riff_idx1_AVIOLDINDEX_flags_FIRSTPART                           0x00000020UL
00172 #define riff_idx1_AVIOLDINDEX_flags_LASTPART                            0x00000040UL
00173 #define riff_idx1_AVIOLDINDEX_flags_NO_TIME                             0x00000100UL
00174 
00175 /* AVIMETAINDEX (a meta-structure for all the variations in indx and nnix chunks) */
00176 typedef struct {
00177 /*      FOURCC          fcc;
00178         UINT            cb; */
00179         uint16_t        wLongsPerEntry;
00180         uint8_t         bIndexSubType;
00181         uint8_t         bIndexType;
00182         uint32_t        nEntriesInUse;
00183         uint32_t        dwChunkId;
00184         uint32_t        dwReserved[3];
00185 /*      uint32_t           adwIndex[]; */
00186 } GCC_ATTRIBUTE(packed) riff_indx_AVIMETAINDEX;
00187 
00188 #define riff_indx_type_AVI_INDEX_OF_INDEXES                             0x00
00189 #define riff_indx_type_AVI_INDEX_OF_CHUNKS                              0x01
00190 #define riff_indx_type_AVI_INDEX_OF_TIMED_CHUNKS                        0x02
00191 #define riff_indx_type_AVI_INDEX_OF_SUB_2FIELD                          0x03
00192 #define riff_indx_type_AVI_INDEX_IS_DATA                                0x80
00193 
00194 #define riff_indx_subtype_AVI_INDEX_SUB_DEFAULT                         0x00
00195 #define riff_indx_subtype_AVI_INDEX_SUB_2FIELD                          0x01
00196 
00197 /* AVISUPERINDEX */
00198 typedef struct {
00199 /*      FOURCC          fcc;
00200         UINT            cb; */
00201         uint16_t        wLongsPerEntry;
00202         uint8_t         bIndexSubType;
00203         uint8_t         bIndexType;
00204         uint32_t        nEntriesInUse;
00205         uint32_t        dwChunkId;
00206         uint32_t        dwReserved[3];
00207 /*      AVISUPERINDEXentry[] */
00208 } GCC_ATTRIBUTE(packed) riff_indx_AVISUPERINDEX;
00209 
00210 typedef struct {
00211         uint64_t        qwOffset;
00212         uint32_t        dwSize;
00213         uint32_t        dwDuration;
00214 } GCC_ATTRIBUTE(packed) riff_indx_AVISUPERINDEX_entry;
00215 
00216 /* AVISTDINDEX */
00217 typedef struct {
00218 /*      FOURCC          fcc;
00219         UINT            cb; */
00220         uint16_t        wLongsPerEntry;
00221         uint8_t         bIndexSubType;
00222         uint8_t         bIndexType;
00223         uint32_t        nEntriesInUse;
00224         uint32_t        dwChunkId;
00225         uint64_t        qwBaseOffset;
00226         uint32_t        dwReserved_3;
00227 /*      AVISTDINDEXentry[] */
00228 } GCC_ATTRIBUTE(packed) riff_indx_AVISTDINDEX;
00229 
00230 typedef struct {
00231         uint32_t        dwOffset;               /* relative to qwBaseOffset */
00232         uint32_t        dwSize;                 /* bit 31 is set if delta frame */
00233 } GCC_ATTRIBUTE(packed) riff_indx_AVISTDINDEX_entry;
00234 
00235 typedef struct {
00236         uint32_t        CompressedBMHeight;
00237         uint32_t        CompressedBMWidth;
00238         uint32_t        ValidBMHeight;
00239         uint32_t        ValidBMWidth;
00240         uint32_t        ValidBMXOffset;
00241         uint32_t        ValidBMYOffset;
00242         uint32_t        VideoXOffsetInT;
00243         uint32_t        VideoYValidStartLine;
00244 } GCC_ATTRIBUTE(packed) riff_vprp_VIDEO_FIELD_DESC;
00245 
00246 /* vprp chunk */
00247 typedef struct {
00248         uint32_t        VideoFormatToken;
00249         uint32_t        VideoStandard;
00250         uint32_t        dwVerticalRefreshRate;
00251         uint32_t        dwHTotalInT;
00252         uint32_t        dwVTotalInLines;
00253         uint32_t        dwFrameAspectRatio;
00254         uint32_t        dwFrameWidthInPixels;
00255         uint32_t        dwFrameHeightInLines;
00256         uint32_t        nbFieldPerFrame;
00257 /*      riff_vprp_VIDEO_FIELD_DESC FieldInfo[nbFieldPerFrame]; */
00258 } GCC_ATTRIBUTE(packed) riff_vprp_VideoPropHeader;
00259 
00260 /* LIST:odml dmlh chunk */
00261 typedef struct {
00262         uint32_t        dwTotalFrames;
00263 } GCC_ATTRIBUTE(packed) riff_odml_dmlh_ODMLExtendedAVIHeader;
00264 
00265 /* AVI stream format contents if stream type is 'iavs' (Interleaved audio/video stream) */
00266 typedef struct windows_DVINFO {
00267         uint32_t        dwDVAAuxSrc;
00268         uint32_t        dwDVAAuxCtl;
00269         uint32_t        dwDVAAuxSrc1;
00270         uint32_t        dwDVAAuxCtl1;
00271         uint32_t        dwDVVAuxSrc;
00272         uint32_t        dwDVVAuxCtl;
00273         uint32_t        dwDVReserved[2];
00274 } GCC_ATTRIBUTE(packed) windows_DVINFO; /* =32 bytes */
00275 
00276 static const windows_DVINFO WINDOWS_DVINFO_INIT = {
00277         0,
00278         0,
00279         0,
00280         0,
00281         0,
00282         0,
00283         {0,0}
00284 };
00285 
00286 #if defined(_MSC_VER)
00287 # pragma pack(pop)
00288 #endif
00289 
00290 #endif
00291