#ifndef ka_block_h
#define ka_block_h

#include "inttypes.h"

#define ka_block_id uint32_t

#define KA_BLOCK_TYPEMASK      0xFF000000
#define KA_BLOCK_IDMASK        0x00FF0000
#define KA_BLOCK_STREAMMASK    0x0000FFFF

#define KA_BLOCK_TYPE_DUMMY    0x00000000
#define KA_BLOCK_TYPE_AUDIO    0x01000000
#define KA_BLOCK_TYPE_VIDEO    0x02000000
#define KA_BLOCK_TYPE_SUBTITLE 0x03000000
#define KA_BLOCK_TYPE_NAV      0x04000000
#define KA_BLOCK_TYPE_INVALID  0xFF000000

#define KA_ABLOCK_UNKNOWN      0x01FF0000
#define KA_ABLOCK_AAC          0x01000000
#define KA_ABLOCK_AC3          0x01010000
#define KA_ABLOCK_ACELPNET     0x01020000
#define KA_ABLOCK_AGSM         0x01030000
#define KA_ABLOCK_ALAC         0x01040000
#define KA_ABLOCK_ALAW         0x01050000
#define KA_ABLOCK_ATRAC        0x01060000
#define KA_ABLOCK_COOK         0x01070000
#define KA_ABLOCK_DK3ADPCM     0x01080000
#define KA_ABLOCK_DK4ADPCM     0x01090000
#define KA_ABLOCK_DNET         0x010A0000
#define KA_ABLOCK_DTS          0x010B0000
#define KA_ABLOCK_FLAC         0x010C0000
#define KA_ABLOCK_IMC          0x010D0000
#define KA_ABLOCK_LH           0x010E0000
#define KA_ABLOCK_LPCM_BE      0x010F0000
#define KA_ABLOCK_LPCM_LE      0x01100000
#define KA_ABLOCK_LPCM_BE_U    0x01110000
#define KA_ABLOCK_LPCM_LE_U    0x01120000
#define KA_ABLOCK_MACE3        0x01130000
#define KA_ABLOCK_MACE6        0x01140000
#define KA_ABLOCK_MPEG         0x01150000
#define KA_ABLOCK_MSADPCM      0x01160000
#define KA_ABLOCK_MSGSM        0x01170000
#define KA_ABLOCK_MSIMAADPCM   0x01180000
#define KA_ABLOCK_QCLP         0x01190000
#define KA_ABLOCK_QDESIGN_V1   0x011A0000
#define KA_ABLOCK_QDESIGN_V2   0x011B0000
#define KA_ABLOCK_QTIMAADPCM   0x011C0000
#define KA_ABLOCK_REAL_14_4    0x011D0000
#define KA_ABLOCK_REAL_28_8    0x011E0000
#define KA_ABLOCK_SIPRO        0x011F0000
#define KA_ABLOCK_ULAW         0x01200000
#define KA_ABLOCK_VIVOG723     0x01210000
#define KA_ABLOCK_VORBIS       0x01220000
#define KA_ABLOCK_VOXWARE      0x01230000
#define KA_ABLOCK_WMA_LOSSLESS 0x01240000
#define KA_ABLOCK_WMA_V1       0x01250000
#define KA_ABLOCK_WMA_V2       0x01260000
#define KA_ABLOCK_WMA_V3       0x01270000
#define KA_ABLOCK_WMA_VOICE    0x01280000
#define KA_ABLOCK_TRUEHD       0x01290000
#define KA_ABLOCK_LPCM_DVD     0x012A0000
#define KA_ABLOCK_LPCM_BR      0x012B0000

#define KA_VBLOCK_UNKNOWN      0x02FF0000
#define KA_VBLOCK_3IVX         0x02000000
#define KA_VBLOCK_8BPS         0x02010000
#define KA_VBLOCK_ASV_V1       0x02020000
#define KA_VBLOCK_ASV_V2       0x02030000
#define KA_VBLOCK_ATIVCR_V1    0x02040000
#define KA_VBLOCK_ATIVCR_V2    0x02050000
#define KA_VBLOCK_CINEPAK      0x02060000
#define KA_VBLOCK_CRAM         0x02070000
#define KA_VBLOCK_CYUV         0x02080000
#define KA_VBLOCK_DIVX         0x02090000
#define KA_VBLOCK_DIVX_V5      0x020A0000
#define KA_VBLOCK_DUCK         0x020B0000
#define KA_VBLOCK_DV           0x020C0000
#define KA_VBLOCK_FLI          0x020D0000
#define KA_VBLOCK_GREY         0x020E0000
#define KA_VBLOCK_H263         0x020F0000
#define KA_VBLOCK_H264         0x02100000
#define KA_VBLOCK_HFYU         0x02110000
#define KA_VBLOCK_I420         0x02120000
#define KA_VBLOCK_IMAGE        0x02130000
#define KA_VBLOCK_IV31         0x02140000
#define KA_VBLOCK_IV32         0x02150000
#define KA_VBLOCK_IV41         0x02160000
#define KA_VBLOCK_IV50         0x02170000
#define KA_VBLOCK_JPEG         0x02180000
#define KA_VBLOCK_MJPEG_A      0x02190000
#define KA_VBLOCK_MJPEG_B      0x021A0000
#define KA_VBLOCK_MPEG         0x021B0000
#define KA_VBLOCK_MSMPEG4_V1   0x021C0000
#define KA_VBLOCK_MSMPEG4_V2   0x021D0000
#define KA_VBLOCK_MSMPEG4_V3   0x021E0000
#define KA_VBLOCK_MSRLE        0x021F0000
#define KA_VBLOCK_MSS1         0x02200000
#define KA_VBLOCK_MSZH         0x02210000
#define KA_VBLOCK_MVI2         0x02220000
#define KA_VBLOCK_PGVV         0x02230000
#define KA_VBLOCK_QTRLE        0x02240000
#define KA_VBLOCK_RGB          0x02250000
#define KA_VBLOCK_RPZA         0x02260000
#define KA_VBLOCK_RV10         0x02270000
#define KA_VBLOCK_RV20         0x02280000
#define KA_VBLOCK_RV30         0x02290000
#define KA_VBLOCK_RV40         0x022A0000
#define KA_VBLOCK_SEGA         0x022B0000
#define KA_VBLOCK_SMC          0x022C0000
#define KA_VBLOCK_SORENSON_V1  0x022D0000
#define KA_VBLOCK_SORENSON_V3  0x022E0000
#define KA_VBLOCK_TSCC         0x022F0000
#define KA_VBLOCK_UCOD         0x02300000
#define KA_VBLOCK_VIVO         0x02310000
#define KA_VBLOCK_VP3          0x02320000
#define KA_VBLOCK_VP4          0x02330000
#define KA_VBLOCK_VP5          0x02340000
#define KA_VBLOCK_VP6          0x02350000
#define KA_VBLOCK_WMV_V7       0x02360000
#define KA_VBLOCK_WMV_V8       0x02370000
#define KA_VBLOCK_WMV_V9       0x02380000
#define KA_VBLOCK_XVID         0x02390000
#define KA_VBLOCK_XXAN         0x023A0000
#define KA_VBLOCK_YUV2         0x023B0000
#define KA_VBLOCK_YUV9         0x023C0000
#define KA_VBLOCK_YV12         0x023D0000
#define KA_VBLOCK_ZLIB         0x023E0000
#define KA_VBLOCK_ZYGO         0x023F0000
#define KA_VBLOCK_H265         0x02400000
#define KA_VBLOCK_VC1          0x02410000

#define KA_SBLOCK_UNKNOWN      0x03FF0000
#define KA_SBLOCK_DVD_SUBTITLE 0x03000000
#define KA_SBLOCK_DVB_SUBTITLE 0x03010000
#define KA_SBLOCK_TELETEXT     0x03020000
#define KA_SBLOCK_PGS          0x03030000

#define KA_NBLOCK_UNKNOWN      0x04FF0000
#define KA_NBLOCK_DVD_PCI      0x04000000
#define KA_NBLOCK_DVD_DSI      0x04010000

typedef struct
{
  uint32_t typ;       // block type
  uint32_t section;   // id of vobu / part of stream without discontinuities
  uint32_t scr;       // time stamp, source
  uint32_t dts;       // time stamp, decode
  uint32_t pts;       // time stamp, presentation
  const uint8_t* sod; // start of packet data
  const uint8_t* eod; // end of packet data
} ka_block_t;

#endif
