179 lines
3.1 KiB
C
179 lines
3.1 KiB
C
#pragma once
|
|
|
|
//typedef uint8_t FOURCC[4];
|
|
|
|
union FOURCC {
|
|
|
|
uint32_t u32;
|
|
uint8_t bytes[4];
|
|
char chars[4];
|
|
|
|
FOURCC() {}
|
|
FOURCC(const char* str) : chars{str[0], str[1], str[2], str[3]} {}
|
|
|
|
bool operator == (const FOURCC other) const {return u32 == other.u32;}
|
|
bool operator != (const FOURCC other) const {return u32 != other.u32;}
|
|
|
|
};
|
|
|
|
|
|
//struct AVICommonHeader {
|
|
// FOURCC fourcc;
|
|
// uint32_t length;
|
|
//};
|
|
|
|
//struct AVITypeHeader {
|
|
// FOURCC fourcc;
|
|
// uint32_t length;
|
|
// FOURCC type;
|
|
//};
|
|
|
|
|
|
|
|
struct AVIChunk {
|
|
|
|
FOURCC type;
|
|
uint32_t size;
|
|
// uint8_t data[size] follows hereafter
|
|
|
|
bool isJUNK() const {return type == FOURCC("JUNK");}
|
|
|
|
/** is an audio data chunk? */
|
|
bool isAudioData() const {return type.chars[2] == 'w' && type.chars[3] == 'b';}
|
|
|
|
/** is a video data chunk? */
|
|
bool isVideoData() const {return type.chars[2] == 'd' && type.chars[3] == 'c';}
|
|
|
|
};
|
|
|
|
struct AVIList : AVIChunk {
|
|
|
|
// AVIList is an AVIChunk with type "RIFF" or "LIST"
|
|
|
|
FOURCC content;
|
|
// uint8_t data[size-4] follows hereafter, contains lists and chunks
|
|
|
|
uint32_t getPayloadSize() const {return size-4;}
|
|
|
|
};
|
|
|
|
struct RIFFHeader : AVIList {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AVIMainHeader : AVIChunk {
|
|
|
|
// <data from AVIChunk>
|
|
|
|
uint32_t ms_per_frame;
|
|
uint32_t max_bytes_per_sec;
|
|
uint32_t padding_granularity;
|
|
uint32_t flags;
|
|
uint32_t total_frames;
|
|
uint32_t initial_frames;
|
|
uint32_t streams;
|
|
uint32_t suggested_buffer_size;
|
|
uint32_t width;
|
|
uint32_t height;
|
|
uint32_t reserved[4];
|
|
|
|
} __attribute__((__packed__));
|
|
|
|
struct AVIRect {
|
|
uint16_t left;
|
|
uint16_t top;
|
|
uint16_t right;
|
|
uint16_t bottom;
|
|
} __attribute__((__packed__));
|
|
|
|
struct AVIStreamHeader : AVIChunk {
|
|
|
|
// <data from AVIChunk>
|
|
|
|
FOURCC fccType; // "vids" or "auds" or "txts"
|
|
FOURCC fccHandler; // video format, e.g. "MJPG"
|
|
uint32_t flags;
|
|
uint16_t priority;
|
|
uint16_t language;
|
|
uint32_t initial_frames;
|
|
uint32_t scale;
|
|
uint32_t rate;
|
|
uint32_t start;
|
|
uint32_t length;
|
|
uint32_t suggested_buffer_size;
|
|
uint32_t quality;
|
|
uint32_t sample_size;
|
|
AVIRect rcFrame;
|
|
|
|
bool isVideo() const {return fccType == FOURCC("vids");}
|
|
bool isAudio() const {return fccType == FOURCC("auds");}
|
|
|
|
} __attribute__((__packed__));
|
|
|
|
struct BitMapInfoHeader {
|
|
|
|
uint32_t biSize;
|
|
int32_t biWidth;
|
|
int32_t biHeight;
|
|
int16_t biPlanes;
|
|
uint16_t biBitCount;
|
|
uint32_t biCompression;
|
|
uint32_t biSizeImage;
|
|
int32_t biXPelsPerMeter;
|
|
int32_t biYPelsPerMeter;
|
|
uint32_t biClrUsed;
|
|
uint32_t biClrImportant;
|
|
|
|
} __attribute__((__packed__));
|
|
|
|
struct RGBQUAD {
|
|
|
|
uint8_t rgbBlue;
|
|
uint8_t rgbGreen;
|
|
uint8_t rgbRed;
|
|
uint8_t rgbReserved;
|
|
|
|
} __attribute__((__packed__));
|
|
|
|
struct BitMapInfo : AVIChunk {
|
|
|
|
// <data from AVIChunk>
|
|
BitMapInfoHeader bmi_header;
|
|
RGBQUAD bmi_colors[1];
|
|
|
|
};
|
|
|
|
struct WaveFormat : AVIChunk {
|
|
|
|
// <data from AVIChunk>
|
|
uint16_t format_tag;
|
|
uint16_t channels;
|
|
uint32_t samples_per_sec;
|
|
uint32_t avg_bytes_per_sec;
|
|
uint16_t block_align;
|
|
uint16_t size;
|
|
|
|
} __attribute__((__packed__));
|
|
|
|
struct AVIIndexEntry {
|
|
|
|
uint32_t ckid;
|
|
uint32_t flags;
|
|
uint32_t chunk_offset;
|
|
uint32_t chunk_length;
|
|
|
|
} __attribute__((__packed__));
|
|
|
|
|
|
|
|
|
|
struct ChunkInfo {
|
|
|
|
uint32_t offset;
|
|
uint32_t entry_offset;
|
|
uint32_t size;
|
|
|
|
} __attribute__((__packed__));
|