Use stdint types in MatroskaParser
This commit is contained in:
parent
b1f132ec6f
commit
3d76d583e1
3 changed files with 162 additions and 169 deletions
|
@ -111,9 +111,9 @@ static void mystrlcpy(char *dst,const char *src,unsigned size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cue {
|
struct Cue {
|
||||||
ulonglong Time;
|
uint64_t Time;
|
||||||
ulonglong Position;
|
uint64_t Position;
|
||||||
ulonglong Block;
|
uint64_t Block;
|
||||||
unsigned char Track;
|
unsigned char Track;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -121,9 +121,9 @@ struct QueueEntry {
|
||||||
struct QueueEntry *next;
|
struct QueueEntry *next;
|
||||||
unsigned int Length;
|
unsigned int Length;
|
||||||
|
|
||||||
ulonglong Start;
|
uint64_t Start;
|
||||||
ulonglong End;
|
uint64_t End;
|
||||||
ulonglong Position;
|
uint64_t Position;
|
||||||
|
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
};
|
};
|
||||||
|
@ -147,7 +147,7 @@ struct MatroskaFile {
|
||||||
|
|
||||||
// internal buffering
|
// internal buffering
|
||||||
char inbuf[IBSZ];
|
char inbuf[IBSZ];
|
||||||
ulonglong bufbase; // file offset of the first byte in buffer
|
uint64_t bufbase; // file offset of the first byte in buffer
|
||||||
int bufpos; // current read position in buffer
|
int bufpos; // current read position in buffer
|
||||||
int buflen; // valid bytes in buffer
|
int buflen; // valid bytes in buffer
|
||||||
|
|
||||||
|
@ -156,15 +156,15 @@ struct MatroskaFile {
|
||||||
jmp_buf jb;
|
jmp_buf jb;
|
||||||
|
|
||||||
// pointers to key elements
|
// pointers to key elements
|
||||||
ulonglong pSegment;
|
uint64_t pSegment;
|
||||||
ulonglong pSeekHead;
|
uint64_t pSeekHead;
|
||||||
ulonglong pSegmentInfo;
|
uint64_t pSegmentInfo;
|
||||||
ulonglong pCluster;
|
uint64_t pCluster;
|
||||||
ulonglong pTracks;
|
uint64_t pTracks;
|
||||||
ulonglong pCues;
|
uint64_t pCues;
|
||||||
ulonglong pAttachments;
|
uint64_t pAttachments;
|
||||||
ulonglong pChapters;
|
uint64_t pChapters;
|
||||||
ulonglong pTags;
|
uint64_t pTags;
|
||||||
|
|
||||||
// flags for key elements
|
// flags for key elements
|
||||||
struct {
|
struct {
|
||||||
|
@ -178,7 +178,7 @@ struct MatroskaFile {
|
||||||
} seen;
|
} seen;
|
||||||
|
|
||||||
// file info
|
// file info
|
||||||
ulonglong firstTimecode;
|
uint64_t firstTimecode;
|
||||||
|
|
||||||
// SegmentInfo
|
// SegmentInfo
|
||||||
struct SegmentInfo Seg;
|
struct SegmentInfo Seg;
|
||||||
|
@ -192,10 +192,10 @@ struct MatroskaFile {
|
||||||
unsigned int nQBlocks,nQBlocksSize;
|
unsigned int nQBlocks,nQBlocksSize;
|
||||||
struct QueueEntry **QBlocks;
|
struct QueueEntry **QBlocks;
|
||||||
struct Queue *Queues;
|
struct Queue *Queues;
|
||||||
ulonglong readPosition;
|
uint64_t readPosition;
|
||||||
unsigned int trackMask;
|
unsigned int trackMask;
|
||||||
ulonglong pSegmentTop; // offset of next byte after the segment
|
uint64_t pSegmentTop; // offset of next byte after the segment
|
||||||
ulonglong tcCluster; // current cluster timecode
|
uint64_t tcCluster; // current cluster timecode
|
||||||
|
|
||||||
// Cues
|
// Cues
|
||||||
unsigned int nCues,nCuesSize;
|
unsigned int nCues,nCuesSize;
|
||||||
|
@ -227,7 +227,7 @@ static void myvsnprintf_string(char **pdest,char *de,const char *str) {
|
||||||
|
|
||||||
static void myvsnprintf_uint_impl(char **pdest,char *de,int width,int zero,
|
static void myvsnprintf_uint_impl(char **pdest,char *de,int width,int zero,
|
||||||
int neg,unsigned base,int letter,
|
int neg,unsigned base,int letter,
|
||||||
int ms,ulonglong val)
|
int ms,uint64_t val)
|
||||||
{
|
{
|
||||||
char *dest = *pdest;
|
char *dest = *pdest;
|
||||||
char tmp[21]; /* enough for 64 bit ints */
|
char tmp[21]; /* enough for 64 bit ints */
|
||||||
|
@ -275,14 +275,14 @@ static void myvsnprintf_uint_impl(char **pdest,char *de,int width,int zero,
|
||||||
|
|
||||||
static void myvsnprintf_uint(char **pdest,char *de,int width,int zero,
|
static void myvsnprintf_uint(char **pdest,char *de,int width,int zero,
|
||||||
int neg,unsigned base,int letter,
|
int neg,unsigned base,int letter,
|
||||||
ulonglong val)
|
uint64_t val)
|
||||||
{
|
{
|
||||||
myvsnprintf_uint_impl(pdest,de,width,zero,neg,base,letter,0,val);
|
myvsnprintf_uint_impl(pdest,de,width,zero,neg,base,letter,0,val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void myvsnprintf_int(char **pdest,char *de,int width,int zero,
|
static void myvsnprintf_int(char **pdest,char *de,int width,int zero,
|
||||||
int neg,unsigned base,int letter,
|
int neg,unsigned base,int letter,
|
||||||
longlong val)
|
int64_t val)
|
||||||
{
|
{
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
myvsnprintf_uint_impl(pdest,de,width,zero,neg,base,letter,1,-val);
|
myvsnprintf_uint_impl(pdest,de,width,zero,neg,base,letter,1,-val);
|
||||||
|
@ -348,7 +348,7 @@ static void myvsnprintf(char *dest,unsigned dsize,const char *fmt,va_list ap)
|
||||||
myvsnprintf_int(&dest,de,width,zero,neg,10,'a',va_arg(ap,long));
|
myvsnprintf_int(&dest,de,width,zero,neg,10,'a',va_arg(ap,long));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
myvsnprintf_int(&dest,de,width,zero,neg,10,'a',va_arg(ap,longlong));
|
myvsnprintf_int(&dest,de,width,zero,neg,10,'a',va_arg(ap,int64_t));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -361,7 +361,7 @@ static void myvsnprintf(char *dest,unsigned dsize,const char *fmt,va_list ap)
|
||||||
myvsnprintf_uint(&dest,de,width,zero,neg,10,'a',va_arg(ap,unsigned long));
|
myvsnprintf_uint(&dest,de,width,zero,neg,10,'a',va_arg(ap,unsigned long));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
myvsnprintf_uint(&dest,de,width,zero,neg,10,'a',va_arg(ap,ulonglong));
|
myvsnprintf_uint(&dest,de,width,zero,neg,10,'a',va_arg(ap,uint64_t));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -374,7 +374,7 @@ static void myvsnprintf(char *dest,unsigned dsize,const char *fmt,va_list ap)
|
||||||
myvsnprintf_uint(&dest,de,width,zero,neg,16,'a',va_arg(ap,unsigned long));
|
myvsnprintf_uint(&dest,de,width,zero,neg,16,'a',va_arg(ap,unsigned long));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
myvsnprintf_uint(&dest,de,width,zero,neg,16,'a',va_arg(ap,ulonglong));
|
myvsnprintf_uint(&dest,de,width,zero,neg,16,'a',va_arg(ap,uint64_t));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -387,7 +387,7 @@ static void myvsnprintf(char *dest,unsigned dsize,const char *fmt,va_list ap)
|
||||||
myvsnprintf_uint(&dest,de,width,zero,neg,16,'A',va_arg(ap,unsigned long));
|
myvsnprintf_uint(&dest,de,width,zero,neg,16,'A',va_arg(ap,unsigned long));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
myvsnprintf_uint(&dest,de,width,zero,neg,16,'A',va_arg(ap,ulonglong));
|
myvsnprintf_uint(&dest,de,width,zero,neg,16,'A',va_arg(ap,uint64_t));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -537,7 +537,7 @@ static inline int readch(MatroskaFile *mf) {
|
||||||
return mf->bufpos < mf->buflen ? (unsigned char)(mf->inbuf[mf->bufpos++]) : nextbuf(mf);
|
return mf->bufpos < mf->buflen ? (unsigned char)(mf->inbuf[mf->bufpos++]) : nextbuf(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline ulonglong filepos(MatroskaFile *mf) {
|
static inline uint64_t filepos(MatroskaFile *mf) {
|
||||||
return mf->bufbase + mf->bufpos;
|
return mf->bufbase + mf->bufpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,7 +566,7 @@ static void readbytes(MatroskaFile *mf,void *buffer,int len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void skipbytes(MatroskaFile *mf,ulonglong len) {
|
static void skipbytes(MatroskaFile *mf,uint64_t len) {
|
||||||
unsigned int nb = mf->buflen - mf->bufpos;
|
unsigned int nb = mf->buflen - mf->bufpos;
|
||||||
|
|
||||||
if (nb > len)
|
if (nb > len)
|
||||||
|
@ -583,7 +583,7 @@ static void skipbytes(MatroskaFile *mf,ulonglong len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void seek(MatroskaFile *mf,ulonglong pos) {
|
static void seek(MatroskaFile *mf,uint64_t pos) {
|
||||||
// see if pos is inside buffer
|
// see if pos is inside buffer
|
||||||
if (pos>=mf->bufbase && pos<mf->bufbase+mf->buflen)
|
if (pos>=mf->bufbase && pos<mf->bufbase+mf->buflen)
|
||||||
mf->bufpos = (unsigned)(pos - mf->bufbase);
|
mf->bufpos = (unsigned)(pos - mf->bufbase);
|
||||||
|
@ -599,14 +599,14 @@ static void seek(MatroskaFile *mf,ulonglong pos) {
|
||||||
static inline MKFLOAT mkfi(int i) {
|
static inline MKFLOAT mkfi(int i) {
|
||||||
#ifdef MATROSKA_INTEGER_ONLY
|
#ifdef MATROSKA_INTEGER_ONLY
|
||||||
MKFLOAT f;
|
MKFLOAT f;
|
||||||
f.v = (longlong)i << 32;
|
f.v = (int64_t)i << 32;
|
||||||
return f;
|
return f;
|
||||||
#else
|
#else
|
||||||
return i;
|
return i;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline longlong mul3(MKFLOAT scale,longlong tc) {
|
static inline int64_t mul3(MKFLOAT scale,int64_t tc) {
|
||||||
#ifdef MATROSKA_INTEGER_ONLY
|
#ifdef MATROSKA_INTEGER_ONLY
|
||||||
// x1 x0
|
// x1 x0
|
||||||
// y1 y0
|
// y1 y0
|
||||||
|
@ -620,7 +620,7 @@ static inline longlong mul3(MKFLOAT scale,longlong tc) {
|
||||||
//
|
//
|
||||||
// r = ((x0*y0) >> 32) + (x1*y0) + (x0*y1) + ((x1*y1) << 32)
|
// r = ((x0*y0) >> 32) + (x1*y0) + (x0*y1) + ((x1*y1) << 32)
|
||||||
unsigned x0,x1,y0,y1;
|
unsigned x0,x1,y0,y1;
|
||||||
ulonglong p;
|
uint64_t p;
|
||||||
char sign = 0;
|
char sign = 0;
|
||||||
|
|
||||||
if (scale.v < 0)
|
if (scale.v < 0)
|
||||||
|
@ -629,18 +629,18 @@ static inline longlong mul3(MKFLOAT scale,longlong tc) {
|
||||||
sign = !sign, tc = -tc;
|
sign = !sign, tc = -tc;
|
||||||
|
|
||||||
x0 = (unsigned)scale.v;
|
x0 = (unsigned)scale.v;
|
||||||
x1 = (unsigned)((ulonglong)scale.v >> 32);
|
x1 = (unsigned)((uint64_t)scale.v >> 32);
|
||||||
y0 = (unsigned)tc;
|
y0 = (unsigned)tc;
|
||||||
y1 = (unsigned)((ulonglong)tc >> 32);
|
y1 = (unsigned)((uint64_t)tc >> 32);
|
||||||
|
|
||||||
p = (ulonglong)x0*y0 >> 32;
|
p = (uint64_t)x0*y0 >> 32;
|
||||||
p += (ulonglong)x0*y1;
|
p += (uint64_t)x0*y1;
|
||||||
p += (ulonglong)x1*y0;
|
p += (uint64_t)x1*y0;
|
||||||
p += (ulonglong)(x1*y1) << 32;
|
p += (uint64_t)(x1*y1) << 32;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
#else
|
#else
|
||||||
return (longlong)(scale * tc);
|
return (int64_t)(scale * tc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,9 +684,9 @@ fail:
|
||||||
return 0; // NOT REACHED
|
return 0; // NOT REACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
static ulonglong readVLUIntImp(MatroskaFile *mf,int *mask) {
|
static uint64_t readVLUIntImp(MatroskaFile *mf,int *mask) {
|
||||||
int c,d,m;
|
int c,d,m;
|
||||||
ulonglong v = 0;
|
uint64_t v = 0;
|
||||||
|
|
||||||
c = readch(mf);
|
c = readch(mf);
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
|
@ -700,7 +700,7 @@ static ulonglong readVLUIntImp(MatroskaFile *mf,int *mask) {
|
||||||
c &= 0x7f >> m;
|
c &= 0x7f >> m;
|
||||||
if (mask)
|
if (mask)
|
||||||
*mask = m;
|
*mask = m;
|
||||||
return v | ((ulonglong)c << m*8);
|
return v | ((uint64_t)c << m*8);
|
||||||
}
|
}
|
||||||
d = readch(mf);
|
d = readch(mf);
|
||||||
if (d == EOF)
|
if (d == EOF)
|
||||||
|
@ -710,13 +710,13 @@ static ulonglong readVLUIntImp(MatroskaFile *mf,int *mask) {
|
||||||
// NOT REACHED
|
// NOT REACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline ulonglong readVLUInt(MatroskaFile *mf) {
|
static inline uint64_t readVLUInt(MatroskaFile *mf) {
|
||||||
return readVLUIntImp(mf,NULL);
|
return readVLUIntImp(mf,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ulonglong readSize(MatroskaFile *mf) {
|
static uint64_t readSize(MatroskaFile *mf) {
|
||||||
int m;
|
int m;
|
||||||
ulonglong v = readVLUIntImp(mf,&m);
|
uint64_t v = readVLUIntImp(mf,&m);
|
||||||
|
|
||||||
// see if it's unspecified
|
// see if it's unspecified
|
||||||
if (v == (MAXU64 >> (57-m*7)))
|
if (v == (MAXU64 >> (57-m*7)))
|
||||||
|
@ -725,20 +725,20 @@ static ulonglong readSize(MatroskaFile *mf) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline longlong readVLSInt(MatroskaFile *mf) {
|
static inline int64_t readVLSInt(MatroskaFile *mf) {
|
||||||
static longlong bias[8] = { (ONE<<6)-1, (ONE<<13)-1, (ONE<<20)-1, (ONE<<27)-1,
|
static int64_t bias[8] = { (ONE<<6)-1, (ONE<<13)-1, (ONE<<20)-1, (ONE<<27)-1,
|
||||||
(ONE<<34)-1, (ONE<<41)-1, (ONE<<48)-1, (ONE<<55)-1 };
|
(ONE<<34)-1, (ONE<<41)-1, (ONE<<48)-1, (ONE<<55)-1 };
|
||||||
|
|
||||||
int m;
|
int m;
|
||||||
longlong v = readVLUIntImp(mf,&m);
|
int64_t v = readVLUIntImp(mf,&m);
|
||||||
|
|
||||||
return v - bias[m];
|
return v - bias[m];
|
||||||
}
|
}
|
||||||
|
|
||||||
static ulonglong readUInt(MatroskaFile *mf,unsigned int len) {
|
static uint64_t readUInt(MatroskaFile *mf,unsigned int len) {
|
||||||
int c;
|
int c;
|
||||||
unsigned int m = len;
|
unsigned int m = len;
|
||||||
ulonglong v = 0;
|
uint64_t v = 0;
|
||||||
|
|
||||||
if (len==0)
|
if (len==0)
|
||||||
return v;
|
return v;
|
||||||
|
@ -755,8 +755,8 @@ static ulonglong readUInt(MatroskaFile *mf,unsigned int len) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline longlong readSInt(MatroskaFile *mf,unsigned int len) {
|
static inline int64_t readSInt(MatroskaFile *mf,unsigned int len) {
|
||||||
longlong v = readUInt(mf,(unsigned)len);
|
int64_t v = readUInt(mf,(unsigned)len);
|
||||||
int s = 64 - (len<<3);
|
int s = 64 - (len<<3);
|
||||||
return (v << s) >> s;
|
return (v << s) >> s;
|
||||||
}
|
}
|
||||||
|
@ -768,7 +768,7 @@ static MKFLOAT readFloat(MatroskaFile *mf,unsigned int len) {
|
||||||
#else
|
#else
|
||||||
union {
|
union {
|
||||||
unsigned int ui;
|
unsigned int ui;
|
||||||
ulonglong ull;
|
uint64_t ull;
|
||||||
float f;
|
float f;
|
||||||
double d;
|
double d;
|
||||||
} u;
|
} u;
|
||||||
|
@ -804,7 +804,7 @@ shift:
|
||||||
f.v = f.v << shift;
|
f.v = f.v << shift;
|
||||||
}
|
}
|
||||||
} else if (len == 8) {
|
} else if (len == 8) {
|
||||||
ulonglong ui = readUInt(mf,(unsigned)len);
|
uint64_t ui = readUInt(mf,(unsigned)len);
|
||||||
f.v = (ui & LL(0xfffffffffffff)) | LL(0x10000000000000);
|
f.v = (ui & LL(0xfffffffffffff)) | LL(0x10000000000000);
|
||||||
if (ui & 0x80000000)
|
if (ui & 0x80000000)
|
||||||
f.v = -f.v;
|
f.v = -f.v;
|
||||||
|
@ -837,7 +837,7 @@ shift:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readString(MatroskaFile *mf,ulonglong len,char *buffer,int buflen) {
|
static void readString(MatroskaFile *mf,uint64_t len,char *buffer,int buflen) {
|
||||||
unsigned int nread;
|
unsigned int nread;
|
||||||
|
|
||||||
if (buflen<1)
|
if (buflen<1)
|
||||||
|
@ -857,7 +857,7 @@ static void readString(MatroskaFile *mf,ulonglong len,char *buffer,int buflen) {
|
||||||
buffer[nread] = '\0';
|
buffer[nread] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readLangCC(MatroskaFile *mf, ulonglong len, char lcc[4]) {
|
static void readLangCC(MatroskaFile *mf, uint64_t len, char lcc[4]) {
|
||||||
unsigned todo = len > 3 ? 3 : (int)len;
|
unsigned todo = len > 3 ? 3 : (int)len;
|
||||||
|
|
||||||
lcc[0] = lcc[1] = lcc[2] = lcc[3] = 0;
|
lcc[0] = lcc[1] = lcc[2] = lcc[3] = 0;
|
||||||
|
@ -869,10 +869,10 @@ static void readLangCC(MatroskaFile *mf, ulonglong len, char lcc[4]) {
|
||||||
// file parser
|
// file parser
|
||||||
#define FOREACH(f,tl) \
|
#define FOREACH(f,tl) \
|
||||||
{ \
|
{ \
|
||||||
ulonglong tmplen = (tl); \
|
uint64_t tmplen = (tl); \
|
||||||
{ \
|
{ \
|
||||||
ulonglong start = filepos(f); \
|
uint64_t start = filepos(f); \
|
||||||
ulonglong cur,len; \
|
uint64_t cur,len; \
|
||||||
int id; \
|
int id; \
|
||||||
for (;;) { \
|
for (;;) { \
|
||||||
cur = filepos(mf); \
|
cur = filepos(mf); \
|
||||||
|
@ -922,8 +922,8 @@ static int IsWritingApp(MatroskaFile *mf,const char *str) {
|
||||||
return !*str;
|
return !*str;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
static void parseEBML(MatroskaFile *mf,ulonglong toplen) {
|
static void parseEBML(MatroskaFile *mf,uint64_t toplen) {
|
||||||
ulonglong v;
|
uint64_t v;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
|
||||||
FOREACH(mf,toplen)
|
FOREACH(mf,toplen)
|
||||||
|
@ -961,9 +961,9 @@ static void parseEBML(MatroskaFile *mf,ulonglong toplen) {
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSeekEntry(MatroskaFile *mf,ulonglong toplen) {
|
static void parseSeekEntry(MatroskaFile *mf,uint64_t toplen) {
|
||||||
int seekid = 0;
|
int seekid = 0;
|
||||||
ulonglong pos = (ulonglong)-1;
|
uint64_t pos = (uint64_t)-1;
|
||||||
|
|
||||||
FOREACH(mf,toplen)
|
FOREACH(mf,toplen)
|
||||||
case 0x53ab: // SeekID
|
case 0x53ab: // SeekID
|
||||||
|
@ -976,7 +976,7 @@ static void parseSeekEntry(MatroskaFile *mf,ulonglong toplen) {
|
||||||
break;
|
break;
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
|
|
||||||
if (pos == (ulonglong)-1)
|
if (pos == (uint64_t)-1)
|
||||||
errorjmp(mf,"Invalid element position in parseSeekEntry");
|
errorjmp(mf,"Invalid element position in parseSeekEntry");
|
||||||
|
|
||||||
pos += mf->pSegment;
|
pos += mf->pSegment;
|
||||||
|
@ -1011,7 +1011,7 @@ static void parseSeekEntry(MatroskaFile *mf,ulonglong toplen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSeekHead(MatroskaFile *mf,ulonglong toplen) {
|
static void parseSeekHead(MatroskaFile *mf,uint64_t toplen) {
|
||||||
FOREACH(mf,toplen)
|
FOREACH(mf,toplen)
|
||||||
case 0x4dbb:
|
case 0x4dbb:
|
||||||
parseSeekEntry(mf,len);
|
parseSeekEntry(mf,len);
|
||||||
|
@ -1019,7 +1019,7 @@ static void parseSeekHead(MatroskaFile *mf,ulonglong toplen) {
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSegmentInfo(MatroskaFile *mf,ulonglong toplen) {
|
static void parseSegmentInfo(MatroskaFile *mf,uint64_t toplen) {
|
||||||
MKFLOAT duration = mkfi(0);
|
MKFLOAT duration = mkfi(0);
|
||||||
|
|
||||||
if (mf->seen.SegmentInfo) {
|
if (mf->seen.SegmentInfo) {
|
||||||
|
@ -1081,8 +1081,8 @@ static void parseSegmentInfo(MatroskaFile *mf,ulonglong toplen) {
|
||||||
mf->Seg.Duration = mul3(duration,mf->Seg.TimecodeScale);
|
mf->Seg.Duration = mul3(duration,mf->Seg.TimecodeScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseFirstCluster(MatroskaFile *mf,ulonglong toplen) {
|
static void parseFirstCluster(MatroskaFile *mf,uint64_t toplen) {
|
||||||
ulonglong end = filepos(mf) + toplen;
|
uint64_t end = filepos(mf) + toplen;
|
||||||
|
|
||||||
mf->seen.Cluster = 1;
|
mf->seen.Cluster = 1;
|
||||||
mf->firstTimecode = 0;
|
mf->firstTimecode = 0;
|
||||||
|
@ -1110,8 +1110,8 @@ static void parseFirstCluster(MatroskaFile *mf,ulonglong toplen) {
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseVideoInfo(MatroskaFile *mf,ulonglong toplen,struct TrackInfo *ti) {
|
static void parseVideoInfo(MatroskaFile *mf,uint64_t toplen,struct TrackInfo *ti) {
|
||||||
ulonglong v;
|
uint64_t v;
|
||||||
char dW = 0, dH = 0;
|
char dW = 0, dH = 0;
|
||||||
|
|
||||||
FOREACH(mf,toplen)
|
FOREACH(mf,toplen)
|
||||||
|
@ -1199,8 +1199,8 @@ static void parseVideoInfo(MatroskaFile *mf,ulonglong toplen,struct TrackInfo *t
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseAudioInfo(MatroskaFile *mf,ulonglong toplen,struct TrackInfo *ti) {
|
static void parseAudioInfo(MatroskaFile *mf,uint64_t toplen,struct TrackInfo *ti) {
|
||||||
ulonglong v;
|
uint64_t v;
|
||||||
|
|
||||||
FOREACH(mf,toplen)
|
FOREACH(mf,toplen)
|
||||||
case 0xb5: // SamplingFrequency
|
case 0xb5: // SamplingFrequency
|
||||||
|
@ -1248,9 +1248,9 @@ static void CopyStr(char **src,char **dst) {
|
||||||
*dst += l;
|
*dst += l;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseTrackEntry(MatroskaFile *mf,ulonglong toplen) {
|
static void parseTrackEntry(MatroskaFile *mf,uint64_t toplen) {
|
||||||
struct TrackInfo t,*tp,**tpp;
|
struct TrackInfo t,*tp,**tpp;
|
||||||
ulonglong v;
|
uint64_t v;
|
||||||
char *cp = NULL, *cs = NULL;
|
char *cp = NULL, *cs = NULL;
|
||||||
size_t cplen = 0, cslen = 0, cpadd = 0;
|
size_t cplen = 0, cslen = 0, cpadd = 0;
|
||||||
unsigned CompScope, num_comp = 0;
|
unsigned CompScope, num_comp = 0;
|
||||||
|
@ -1512,7 +1512,7 @@ static void parseTrackEntry(MatroskaFile *mf,ulonglong toplen) {
|
||||||
*tpp = tp;
|
*tpp = tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseTracks(MatroskaFile *mf,ulonglong toplen) {
|
static void parseTracks(MatroskaFile *mf,uint64_t toplen) {
|
||||||
mf->seen.Tracks = 1;
|
mf->seen.Tracks = 1;
|
||||||
FOREACH(mf,toplen)
|
FOREACH(mf,toplen)
|
||||||
case 0xae: // TrackEntry
|
case 0xae: // TrackEntry
|
||||||
|
@ -1521,7 +1521,7 @@ static void parseTracks(MatroskaFile *mf,ulonglong toplen) {
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addCue(MatroskaFile *mf,ulonglong pos,ulonglong timecode) {
|
static void addCue(MatroskaFile *mf,uint64_t pos,uint64_t timecode) {
|
||||||
struct Cue *cc = AGET(mf,Cues);
|
struct Cue *cc = AGET(mf,Cues);
|
||||||
cc->Time = timecode;
|
cc->Time = timecode;
|
||||||
cc->Position = pos;
|
cc->Position = pos;
|
||||||
|
@ -1532,7 +1532,7 @@ static void addCue(MatroskaFile *mf,ulonglong pos,ulonglong timecode) {
|
||||||
static void fixupCues(MatroskaFile *mf) {
|
static void fixupCues(MatroskaFile *mf) {
|
||||||
// adjust cues, shift cues if file does not start at 0
|
// adjust cues, shift cues if file does not start at 0
|
||||||
unsigned i;
|
unsigned i;
|
||||||
longlong adjust = mf->firstTimecode * mf->Seg.TimecodeScale;
|
int64_t adjust = mf->firstTimecode * mf->Seg.TimecodeScale;
|
||||||
|
|
||||||
for (i=0;i<mf->nCues;++i) {
|
for (i=0;i<mf->nCues;++i) {
|
||||||
mf->Cues[i].Time *= mf->Seg.TimecodeScale;
|
mf->Cues[i].Time *= mf->Seg.TimecodeScale;
|
||||||
|
@ -1540,9 +1540,9 @@ static void fixupCues(MatroskaFile *mf) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseCues(MatroskaFile *mf,ulonglong toplen) {
|
static void parseCues(MatroskaFile *mf,uint64_t toplen) {
|
||||||
jmp_buf jb;
|
jmp_buf jb;
|
||||||
ulonglong v;
|
uint64_t v;
|
||||||
struct Cue cc;
|
struct Cue cc;
|
||||||
unsigned i,j,k;
|
unsigned i,j,k;
|
||||||
|
|
||||||
|
@ -1625,7 +1625,7 @@ static void parseCues(MatroskaFile *mf,ulonglong toplen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseAttachment(MatroskaFile *mf,ulonglong toplen) {
|
static void parseAttachment(MatroskaFile *mf,uint64_t toplen) {
|
||||||
struct Attachment a,*pa;
|
struct Attachment a,*pa;
|
||||||
|
|
||||||
memset(&a,0,sizeof(a));
|
memset(&a,0,sizeof(a));
|
||||||
|
@ -1663,7 +1663,7 @@ static void parseAttachment(MatroskaFile *mf,ulonglong toplen) {
|
||||||
pa->MimeType = mystrdup(mf->cache,a.MimeType);
|
pa->MimeType = mystrdup(mf->cache,a.MimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseAttachments(MatroskaFile *mf,ulonglong toplen) {
|
static void parseAttachments(MatroskaFile *mf,uint64_t toplen) {
|
||||||
mf->seen.Attachments = 1;
|
mf->seen.Attachments = 1;
|
||||||
|
|
||||||
FOREACH(mf,toplen)
|
FOREACH(mf,toplen)
|
||||||
|
@ -1673,7 +1673,7 @@ static void parseAttachments(MatroskaFile *mf,ulonglong toplen) {
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseChapter(MatroskaFile *mf,ulonglong toplen,struct Chapter *parent) {
|
static void parseChapter(MatroskaFile *mf,uint64_t toplen,struct Chapter *parent) {
|
||||||
struct ChapterDisplay *disp;
|
struct ChapterDisplay *disp;
|
||||||
struct ChapterProcess *proc;
|
struct ChapterProcess *proc;
|
||||||
struct ChapterCommand *cmd;
|
struct ChapterCommand *cmd;
|
||||||
|
@ -1708,7 +1708,7 @@ static void parseChapter(MatroskaFile *mf,ulonglong toplen,struct Chapter *paren
|
||||||
case 0x8f: // ChapterTrack
|
case 0x8f: // ChapterTrack
|
||||||
FOREACH(mf,len)
|
FOREACH(mf,len)
|
||||||
case 0x89: // ChapterTrackNumber
|
case 0x89: // ChapterTrackNumber
|
||||||
*(ulonglong*)(ASGET(mf,ch,Tracks)) = readUInt(mf,(unsigned)len);
|
*(uint64_t*)(ASGET(mf,ch,Tracks)) = readUInt(mf,(unsigned)len);
|
||||||
break;
|
break;
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
break;
|
break;
|
||||||
|
@ -1816,7 +1816,7 @@ static void parseChapter(MatroskaFile *mf,ulonglong toplen,struct Chapter *paren
|
||||||
ARELEASE(mf,ch,Children);
|
ARELEASE(mf,ch,Children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseChapters(MatroskaFile *mf,ulonglong toplen) {
|
static void parseChapters(MatroskaFile *mf,uint64_t toplen) {
|
||||||
struct Chapter *ch;
|
struct Chapter *ch;
|
||||||
|
|
||||||
mf->seen.Chapters = 1;
|
mf->seen.Chapters = 1;
|
||||||
|
@ -1846,7 +1846,7 @@ static void parseChapters(MatroskaFile *mf,ulonglong toplen) {
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseTags(MatroskaFile *mf,ulonglong toplen) {
|
static void parseTags(MatroskaFile *mf,uint64_t toplen) {
|
||||||
struct Tag *tag;
|
struct Tag *tag;
|
||||||
struct Target *target;
|
struct Target *target;
|
||||||
struct SimpleTag *st;
|
struct SimpleTag *st;
|
||||||
|
@ -1920,7 +1920,7 @@ static void parseTags(MatroskaFile *mf,ulonglong toplen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseContainer(MatroskaFile *mf) {
|
static void parseContainer(MatroskaFile *mf) {
|
||||||
ulonglong len;
|
uint64_t len;
|
||||||
int id = readID(mf);
|
int id = readID(mf);
|
||||||
if (id==EOF)
|
if (id==EOF)
|
||||||
errorjmp(mf,"Unexpected EOF in parseContainer");
|
errorjmp(mf,"Unexpected EOF in parseContainer");
|
||||||
|
@ -1952,7 +1952,7 @@ static void parseContainer(MatroskaFile *mf) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseContainerPos(MatroskaFile *mf,ulonglong pos) {
|
static void parseContainerPos(MatroskaFile *mf,uint64_t pos) {
|
||||||
seek(mf,pos);
|
seek(mf,pos);
|
||||||
parseContainer(mf);
|
parseContainer(mf);
|
||||||
}
|
}
|
||||||
|
@ -1985,8 +1985,8 @@ static void parsePointers(MatroskaFile *mf) {
|
||||||
memcpy(&mf->jb,&jb,sizeof(jb));
|
memcpy(&mf->jb,&jb,sizeof(jb));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSegment(MatroskaFile *mf,ulonglong toplen) {
|
static void parseSegment(MatroskaFile *mf,uint64_t toplen) {
|
||||||
ulonglong nextpos;
|
uint64_t nextpos;
|
||||||
unsigned nSeekHeads = 0, dontstop = 0;
|
unsigned nSeekHeads = 0, dontstop = 0;
|
||||||
jmp_buf jb;
|
jmp_buf jb;
|
||||||
|
|
||||||
|
@ -2064,8 +2064,8 @@ static void parseSegment(MatroskaFile *mf,ulonglong toplen) {
|
||||||
parsePointers(mf);
|
parsePointers(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseBlockAdditions(MatroskaFile *mf, ulonglong toplen, ulonglong timecode, unsigned track) {
|
static void parseBlockAdditions(MatroskaFile *mf, uint64_t toplen, uint64_t timecode, unsigned track) {
|
||||||
ulonglong add_id = 1, add_pos, add_len;
|
uint64_t add_id = 1, add_pos, add_len;
|
||||||
unsigned char have_add;
|
unsigned char have_add;
|
||||||
|
|
||||||
FOREACH(mf, toplen)
|
FOREACH(mf, toplen)
|
||||||
|
@ -2096,10 +2096,10 @@ static void parseBlockAdditions(MatroskaFile *mf, ulonglong toplen, ulonglong ti
|
||||||
ENDFOR(mf);
|
ENDFOR(mf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseBlockGroup(MatroskaFile *mf,ulonglong toplen,ulonglong timecode, int blockex) {
|
static void parseBlockGroup(MatroskaFile *mf,uint64_t toplen,uint64_t timecode, int blockex) {
|
||||||
ulonglong v;
|
uint64_t v;
|
||||||
ulonglong duration = 0;
|
uint64_t duration = 0;
|
||||||
ulonglong dpos;
|
uint64_t dpos;
|
||||||
struct QueueEntry *qe,*qf = NULL;
|
struct QueueEntry *qe,*qf = NULL;
|
||||||
unsigned char have_duration = 0, have_block = 0;
|
unsigned char have_duration = 0, have_block = 0;
|
||||||
unsigned char gap = 0;
|
unsigned char gap = 0;
|
||||||
|
@ -2253,7 +2253,7 @@ out:
|
||||||
errorjmp(mf,"Found a BlockGroup without Block");
|
errorjmp(mf,"Found a BlockGroup without Block");
|
||||||
|
|
||||||
if (nframes > 1) {
|
if (nframes > 1) {
|
||||||
ulonglong defd = mf->Tracks[tracknum]->DefaultDuration;
|
uint64_t defd = mf->Tracks[tracknum]->DefaultDuration;
|
||||||
v = qf->Start;
|
v = qf->Start;
|
||||||
|
|
||||||
if (have_duration) {
|
if (have_duration) {
|
||||||
|
@ -2319,8 +2319,8 @@ static void EmptyQueues(MatroskaFile *mf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int readMoreBlocks(MatroskaFile *mf) {
|
static int readMoreBlocks(MatroskaFile *mf) {
|
||||||
ulonglong toplen, cstop;
|
uint64_t toplen, cstop;
|
||||||
longlong cp;
|
int64_t cp;
|
||||||
int cid, ret = 0;
|
int cid, ret = 0;
|
||||||
jmp_buf jb;
|
jmp_buf jb;
|
||||||
volatile unsigned retries = 0;
|
volatile unsigned retries = 0;
|
||||||
|
@ -2346,7 +2346,7 @@ static int readMoreBlocks(MatroskaFile *mf) {
|
||||||
|
|
||||||
cp = mf->cache->scan(mf->cache,filepos(mf),0x1f43b675); // cluster
|
cp = mf->cache->scan(mf->cache,filepos(mf),0x1f43b675); // cluster
|
||||||
|
|
||||||
if (cp < 0 || (ulonglong)cp >= mf->pSegmentTop)
|
if (cp < 0 || (uint64_t)cp >= mf->pSegmentTop)
|
||||||
goto ex;
|
goto ex;
|
||||||
|
|
||||||
seek(mf,cp);
|
seek(mf,cp);
|
||||||
|
@ -2476,10 +2476,10 @@ static int fillQueues(MatroskaFile *mf,unsigned int mask) {
|
||||||
|
|
||||||
static void reindex(MatroskaFile *mf) {
|
static void reindex(MatroskaFile *mf) {
|
||||||
jmp_buf jb;
|
jmp_buf jb;
|
||||||
ulonglong pos = mf->pCluster;
|
uint64_t pos = mf->pCluster;
|
||||||
ulonglong step = 10*1024*1024;
|
uint64_t step = 10*1024*1024;
|
||||||
ulonglong size, tc, isize;
|
uint64_t size, tc, isize;
|
||||||
longlong next_cluster;
|
int64_t next_cluster;
|
||||||
int id, have_tc, bad;
|
int id, have_tc, bad;
|
||||||
struct Cue *cue;
|
struct Cue *cue;
|
||||||
|
|
||||||
|
@ -2510,7 +2510,7 @@ static void reindex(MatroskaFile *mf) {
|
||||||
|
|
||||||
// find next cluster header
|
// find next cluster header
|
||||||
next_cluster = mf->cache->scan(mf->cache,pos,0x1f43b675); // cluster
|
next_cluster = mf->cache->scan(mf->cache,pos,0x1f43b675); // cluster
|
||||||
if (next_cluster < 0 || (ulonglong)next_cluster >= mf->pSegmentTop)
|
if (next_cluster < 0 || (uint64_t)next_cluster >= mf->pSegmentTop)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pos = next_cluster + 4; // prevent endless loops
|
pos = next_cluster + 4; // prevent endless loops
|
||||||
|
@ -2533,7 +2533,7 @@ static void reindex(MatroskaFile *mf) {
|
||||||
have_tc = 0;
|
have_tc = 0;
|
||||||
size += filepos(mf);
|
size += filepos(mf);
|
||||||
|
|
||||||
while (filepos(mf) < (ulonglong)next_cluster + 1024) {
|
while (filepos(mf) < (uint64_t)next_cluster + 1024) {
|
||||||
id = readID(mf);
|
id = readID(mf);
|
||||||
if (id == EOF)
|
if (id == EOF)
|
||||||
break;
|
break;
|
||||||
|
@ -2591,7 +2591,7 @@ static void reindex(MatroskaFile *mf) {
|
||||||
memcpy(&mf->jb,&jb,sizeof(jb));
|
memcpy(&mf->jb,&jb,sizeof(jb));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fixupChapter(ulonglong adj, struct Chapter *ch) {
|
static void fixupChapter(uint64_t adj, struct Chapter *ch) {
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
if (ch->Start != 0)
|
if (ch->Start != 0)
|
||||||
|
@ -2603,8 +2603,8 @@ static void fixupChapter(ulonglong adj, struct Chapter *ch) {
|
||||||
fixupChapter(adj,&ch->Children[i]);
|
fixupChapter(adj,&ch->Children[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static longlong findLastTimecode(MatroskaFile *mf) {
|
static int64_t findLastTimecode(MatroskaFile *mf) {
|
||||||
ulonglong nd = 0;
|
uint64_t nd = 0;
|
||||||
unsigned n,vtrack;
|
unsigned n,vtrack;
|
||||||
|
|
||||||
if (mf->nTracks == 0)
|
if (mf->nTracks == 0)
|
||||||
|
@ -2633,7 +2633,7 @@ ok:
|
||||||
do
|
do
|
||||||
while (mf->Queues[vtrack].head)
|
while (mf->Queues[vtrack].head)
|
||||||
{
|
{
|
||||||
ulonglong tc = mf->Queues[vtrack].head->flags & FRAME_UNKNOWN_END ?
|
uint64_t tc = mf->Queues[vtrack].head->flags & FRAME_UNKNOWN_END ?
|
||||||
mf->Queues[vtrack].head->Start : mf->Queues[vtrack].head->End;
|
mf->Queues[vtrack].head->Start : mf->Queues[vtrack].head->End;
|
||||||
if (nd < tc)
|
if (nd < tc)
|
||||||
nd = tc;
|
nd = tc;
|
||||||
|
@ -2656,7 +2656,7 @@ ok:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseFile(MatroskaFile *mf) {
|
static void parseFile(MatroskaFile *mf) {
|
||||||
ulonglong len = filepos(mf), adjust;
|
uint64_t len = filepos(mf), adjust;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
int id = readID(mf);
|
int id = readID(mf);
|
||||||
int m;
|
int m;
|
||||||
|
@ -2694,7 +2694,7 @@ segment:
|
||||||
if (len == MAXU64) {
|
if (len == MAXU64) {
|
||||||
mf->pSegmentTop = MAXU64;
|
mf->pSegmentTop = MAXU64;
|
||||||
if (mf->cache->getfilesize) {
|
if (mf->cache->getfilesize) {
|
||||||
longlong seglen = mf->cache->getfilesize(mf->cache);
|
int64_t seglen = mf->cache->getfilesize(mf->cache);
|
||||||
if (seglen > 0)
|
if (seglen > 0)
|
||||||
mf->pSegmentTop = seglen;
|
mf->pSegmentTop = seglen;
|
||||||
}
|
}
|
||||||
|
@ -2726,7 +2726,7 @@ segment:
|
||||||
|
|
||||||
// try to detect real duration
|
// try to detect real duration
|
||||||
if (!(mf->flags & MKVF_AVOID_SEEKS)) {
|
if (!(mf->flags & MKVF_AVOID_SEEKS)) {
|
||||||
longlong nd = findLastTimecode(mf);
|
int64_t nd = findLastTimecode(mf);
|
||||||
if (nd > 0)
|
if (nd > 0)
|
||||||
mf->Seg.Duration = nd;
|
mf->Seg.Duration = nd;
|
||||||
}
|
}
|
||||||
|
@ -2760,7 +2760,7 @@ static void DeleteChapter(MatroskaFile *mf,struct Chapter *ch) {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// public interface
|
// public interface
|
||||||
MatroskaFile *mkv_OpenEx(InputStream *io,
|
MatroskaFile *mkv_OpenEx(InputStream *io,
|
||||||
ulonglong base,
|
uint64_t base,
|
||||||
unsigned flags,
|
unsigned flags,
|
||||||
char *err_msg,unsigned msgsize)
|
char *err_msg,unsigned msgsize)
|
||||||
{
|
{
|
||||||
|
@ -2877,16 +2877,16 @@ void mkv_GetTags(MatroskaFile *mf,Tag **tag,unsigned *count) {
|
||||||
*count = mf->nTags;
|
*count = mf->nTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulonglong mkv_GetSegmentTop(MatroskaFile *mf) {
|
uint64_t mkv_GetSegmentTop(MatroskaFile *mf) {
|
||||||
return mf->pSegmentTop;
|
return mf->pSegmentTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IS_DELTA(f) (!((f)->flags & FRAME_KF) || ((f)->flags & FRAME_UNKNOWN_START))
|
#define IS_DELTA(f) (!((f)->flags & FRAME_KF) || ((f)->flags & FRAME_UNKNOWN_START))
|
||||||
|
|
||||||
void mkv_Seek(MatroskaFile *mf,ulonglong timecode,unsigned flags) {
|
void mkv_Seek(MatroskaFile *mf,uint64_t timecode,unsigned flags) {
|
||||||
int i,j,m,ret;
|
int i,j,m,ret;
|
||||||
unsigned n,z,mask;
|
unsigned n,z,mask;
|
||||||
ulonglong m_kftime[MAX_TRACKS];
|
uint64_t m_kftime[MAX_TRACKS];
|
||||||
unsigned char m_seendf[MAX_TRACKS];
|
unsigned char m_seendf[MAX_TRACKS];
|
||||||
|
|
||||||
if (mf->flags & MKVF_AVOID_SEEKS)
|
if (mf->flags & MKVF_AVOID_SEEKS)
|
||||||
|
@ -3031,7 +3031,7 @@ again:;
|
||||||
|
|
||||||
void mkv_SkipToKeyframe(MatroskaFile *mf) {
|
void mkv_SkipToKeyframe(MatroskaFile *mf) {
|
||||||
unsigned n,wait;
|
unsigned n,wait;
|
||||||
ulonglong ht;
|
uint64_t ht;
|
||||||
|
|
||||||
if (setjmp(mf->jb)!=0)
|
if (setjmp(mf->jb)!=0)
|
||||||
return;
|
return;
|
||||||
|
@ -3074,16 +3074,16 @@ void mkv_SkipToKeyframe(MatroskaFile *mf) {
|
||||||
} while (wait);
|
} while (wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
ulonglong mkv_GetLowestQTimecode(MatroskaFile *mf) {
|
uint64_t mkv_GetLowestQTimecode(MatroskaFile *mf) {
|
||||||
unsigned n,seen;
|
unsigned n,seen;
|
||||||
ulonglong t;
|
uint64_t t;
|
||||||
|
|
||||||
// find the lowest queued timecode
|
// find the lowest queued timecode
|
||||||
for (n=seen=0,t=0;n<mf->nTracks;++n)
|
for (n=seen=0,t=0;n<mf->nTracks;++n)
|
||||||
if (mf->Queues[n].head && (!seen || t > mf->Queues[n].head->Start))
|
if (mf->Queues[n].head && (!seen || t > mf->Queues[n].head->Start))
|
||||||
t = mf->Queues[n].head->Start, seen=1;
|
t = mf->Queues[n].head->Start, seen=1;
|
||||||
|
|
||||||
return seen ? t : (ulonglong)LL(-1);
|
return seen ? t : (uint64_t)LL(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mkv_TruncFloat(MKFLOAT f) {
|
int mkv_TruncFloat(MKFLOAT f) {
|
||||||
|
@ -3111,8 +3111,8 @@ void mkv_SetTrackMask(MatroskaFile *mf,unsigned int mask) {
|
||||||
|
|
||||||
int mkv_ReadFrame(MatroskaFile *mf,
|
int mkv_ReadFrame(MatroskaFile *mf,
|
||||||
unsigned int mask,unsigned int *track,
|
unsigned int mask,unsigned int *track,
|
||||||
ulonglong *StartTime,ulonglong *EndTime,
|
uint64_t *StartTime,uint64_t *EndTime,
|
||||||
ulonglong *FilePos,unsigned int *FrameSize,
|
uint64_t *FilePos,unsigned int *FrameSize,
|
||||||
unsigned int *FrameFlags)
|
unsigned int *FrameFlags)
|
||||||
{
|
{
|
||||||
unsigned int i,j;
|
unsigned int i,j;
|
||||||
|
@ -3167,7 +3167,7 @@ struct CompressedStream {
|
||||||
z_stream zs;
|
z_stream zs;
|
||||||
|
|
||||||
/* current compressed frame */
|
/* current compressed frame */
|
||||||
ulonglong frame_pos;
|
uint64_t frame_pos;
|
||||||
unsigned frame_size;
|
unsigned frame_size;
|
||||||
char frame_buffer[2048];
|
char frame_buffer[2048];
|
||||||
|
|
||||||
|
@ -3237,7 +3237,7 @@ void cs_Destroy(/* in */ CompressedStream *cs) {
|
||||||
/* advance to the next frame in matroska stream, you need to pass values returned
|
/* advance to the next frame in matroska stream, you need to pass values returned
|
||||||
* by mkv_ReadFrame */
|
* by mkv_ReadFrame */
|
||||||
void cs_NextFrame(/* in */ CompressedStream *cs,
|
void cs_NextFrame(/* in */ CompressedStream *cs,
|
||||||
/* in */ ulonglong pos,
|
/* in */ uint64_t pos,
|
||||||
/* in */ unsigned size)
|
/* in */ unsigned size)
|
||||||
{
|
{
|
||||||
cs->zs.avail_in = 0;
|
cs->zs.avail_in = 0;
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef MATROSKA_PARSER_H
|
#ifndef MATROSKA_PARSER_H
|
||||||
#define MATROSKA_PARSER_H
|
#define MATROSKA_PARSER_H
|
||||||
|
|
||||||
|
@ -57,19 +59,10 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* 64-bit integers */
|
|
||||||
#ifdef _WIN32_WCE
|
|
||||||
typedef signed __int64 longlong;
|
|
||||||
typedef unsigned __int64 ulonglong;
|
|
||||||
#else
|
|
||||||
typedef signed long long longlong;
|
|
||||||
typedef unsigned long long ulonglong;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* MKFLOATing point */
|
/* MKFLOATing point */
|
||||||
#ifdef MATROSKA_INTEGER_ONLY
|
#ifdef MATROSKA_INTEGER_ONLY
|
||||||
typedef struct {
|
typedef struct {
|
||||||
longlong v;
|
int64_t v;
|
||||||
} MKFLOAT;
|
} MKFLOAT;
|
||||||
#else
|
#else
|
||||||
typedef double MKFLOAT;
|
typedef double MKFLOAT;
|
||||||
|
@ -78,9 +71,9 @@ typedef double MKFLOAT;
|
||||||
/* generic I/O */
|
/* generic I/O */
|
||||||
struct InputStream {
|
struct InputStream {
|
||||||
/* read bytes from stream */
|
/* read bytes from stream */
|
||||||
int (*read)(struct InputStream *cc,ulonglong pos,void *buffer,int count);
|
int (*read)(struct InputStream *cc,uint64_t pos,void *buffer,int count);
|
||||||
/* scan for a four byte signature, bytes must be nonzero */
|
/* scan for a four byte signature, bytes must be nonzero */
|
||||||
longlong (*scan)(struct InputStream *cc,ulonglong start,unsigned signature);
|
int64_t (*scan)(struct InputStream *cc,uint64_t start,unsigned signature);
|
||||||
/* get cache size, this is used to cap readahead */
|
/* get cache size, this is used to cap readahead */
|
||||||
unsigned (*getcachesize)(struct InputStream *cc);
|
unsigned (*getcachesize)(struct InputStream *cc);
|
||||||
/* fetch last error message */
|
/* fetch last error message */
|
||||||
|
@ -90,9 +83,9 @@ struct InputStream {
|
||||||
void *(*memrealloc)(struct InputStream *cc,void *mem,size_t newsize);
|
void *(*memrealloc)(struct InputStream *cc,void *mem,size_t newsize);
|
||||||
void (*memfree)(struct InputStream *cc,void *mem);
|
void (*memfree)(struct InputStream *cc,void *mem);
|
||||||
/* zero return causes parser to abort open */
|
/* zero return causes parser to abort open */
|
||||||
int (*progress)(struct InputStream *cc,ulonglong cur,ulonglong max);
|
int (*progress)(struct InputStream *cc,uint64_t cur,uint64_t max);
|
||||||
/* get file size, optional, can be NULL or return -1 if filesize is unknown */
|
/* get file size, optional, can be NULL or return -1 if filesize is unknown */
|
||||||
longlong (*getfilesize)(struct InputStream *cc);
|
int64_t (*getfilesize)(struct InputStream *cc);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct InputStream InputStream;
|
typedef struct InputStream InputStream;
|
||||||
|
@ -115,10 +108,10 @@ struct TrackInfo {
|
||||||
unsigned char Number;
|
unsigned char Number;
|
||||||
unsigned char Type;
|
unsigned char Type;
|
||||||
unsigned char TrackOverlay;
|
unsigned char TrackOverlay;
|
||||||
ulonglong UID;
|
uint64_t UID;
|
||||||
ulonglong MinCache;
|
uint64_t MinCache;
|
||||||
ulonglong MaxCache;
|
uint64_t MaxCache;
|
||||||
ulonglong DefaultDuration;
|
uint64_t DefaultDuration;
|
||||||
MKFLOAT TimecodeScale;
|
MKFLOAT TimecodeScale;
|
||||||
void *CodecPrivate;
|
void *CodecPrivate;
|
||||||
unsigned CodecPrivateSize;
|
unsigned CodecPrivateSize;
|
||||||
|
@ -174,18 +167,18 @@ struct SegmentInfo {
|
||||||
char *Title;
|
char *Title;
|
||||||
char *MuxingApp;
|
char *MuxingApp;
|
||||||
char *WritingApp;
|
char *WritingApp;
|
||||||
ulonglong TimecodeScale;
|
uint64_t TimecodeScale;
|
||||||
ulonglong Duration;
|
uint64_t Duration;
|
||||||
longlong DateUTC;
|
int64_t DateUTC;
|
||||||
char DateUTCValid;
|
char DateUTCValid;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SegmentInfo SegmentInfo;
|
typedef struct SegmentInfo SegmentInfo;
|
||||||
|
|
||||||
struct Attachment {
|
struct Attachment {
|
||||||
ulonglong Position;
|
uint64_t Position;
|
||||||
ulonglong Length;
|
uint64_t Length;
|
||||||
ulonglong UID;
|
uint64_t UID;
|
||||||
char *Name;
|
char *Name;
|
||||||
char *Description;
|
char *Description;
|
||||||
char *MimeType;
|
char *MimeType;
|
||||||
|
@ -214,12 +207,12 @@ struct ChapterProcess {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Chapter {
|
struct Chapter {
|
||||||
ulonglong UID;
|
uint64_t UID;
|
||||||
ulonglong Start;
|
uint64_t Start;
|
||||||
ulonglong End;
|
uint64_t End;
|
||||||
|
|
||||||
unsigned nTracks,nTracksSize;
|
unsigned nTracks,nTracksSize;
|
||||||
ulonglong *Tracks;
|
uint64_t *Tracks;
|
||||||
unsigned nDisplay,nDisplaySize;
|
unsigned nDisplay,nDisplaySize;
|
||||||
struct ChapterDisplay *Display;
|
struct ChapterDisplay *Display;
|
||||||
unsigned nChildren,nChildrenSize;
|
unsigned nChildren,nChildrenSize;
|
||||||
|
@ -244,7 +237,7 @@ typedef struct Chapter Chapter;
|
||||||
#define TARGET_ATTACHMENT 2
|
#define TARGET_ATTACHMENT 2
|
||||||
#define TARGET_EDITION 3
|
#define TARGET_EDITION 3
|
||||||
struct Target {
|
struct Target {
|
||||||
ulonglong UID;
|
uint64_t UID;
|
||||||
unsigned Type;
|
unsigned Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -275,7 +268,7 @@ X MatroskaFile *mkv_Open(/* in */ InputStream *io,
|
||||||
#define MKVF_AVOID_SEEKS 1 /* use sequential reading only */
|
#define MKVF_AVOID_SEEKS 1 /* use sequential reading only */
|
||||||
|
|
||||||
X MatroskaFile *mkv_OpenEx(/* in */ InputStream *io,
|
X MatroskaFile *mkv_OpenEx(/* in */ InputStream *io,
|
||||||
/* in */ ulonglong base,
|
/* in */ uint64_t base,
|
||||||
/* in */ unsigned flags,
|
/* in */ unsigned flags,
|
||||||
/* out */ char *err_msg,
|
/* out */ char *err_msg,
|
||||||
/* in */ unsigned msgsize);
|
/* in */ unsigned msgsize);
|
||||||
|
@ -306,7 +299,7 @@ X void mkv_GetTags(/* in */ MatroskaFile *mf,
|
||||||
/* out */ Tag **tag,
|
/* out */ Tag **tag,
|
||||||
/* out */ unsigned *count);
|
/* out */ unsigned *count);
|
||||||
|
|
||||||
X ulonglong mkv_GetSegmentTop(MatroskaFile *mf);
|
X uint64_t mkv_GetSegmentTop(MatroskaFile *mf);
|
||||||
|
|
||||||
/* Seek to specified timecode,
|
/* Seek to specified timecode,
|
||||||
* if timecode is past end of file,
|
* if timecode is past end of file,
|
||||||
|
@ -317,12 +310,12 @@ X ulonglong mkv_GetSegmentTop(MatroskaFile *mf);
|
||||||
#define MKVF_SEEK_TO_PREV_KEYFRAME_STRICT 2
|
#define MKVF_SEEK_TO_PREV_KEYFRAME_STRICT 2
|
||||||
|
|
||||||
X void mkv_Seek(/* in */ MatroskaFile *mf,
|
X void mkv_Seek(/* in */ MatroskaFile *mf,
|
||||||
/* in */ ulonglong timecode /* in ns */,
|
/* in */ uint64_t timecode /* in ns */,
|
||||||
/* in */ unsigned flags);
|
/* in */ unsigned flags);
|
||||||
|
|
||||||
X void mkv_SkipToKeyframe(MatroskaFile *mf);
|
X void mkv_SkipToKeyframe(MatroskaFile *mf);
|
||||||
|
|
||||||
X ulonglong mkv_GetLowestQTimecode(MatroskaFile *mf);
|
X uint64_t mkv_GetLowestQTimecode(MatroskaFile *mf);
|
||||||
|
|
||||||
X int mkv_TruncFloat(MKFLOAT f);
|
X int mkv_TruncFloat(MKFLOAT f);
|
||||||
|
|
||||||
|
@ -353,9 +346,9 @@ X void mkv_SetTrackMask(/* in */ MatroskaFile *mf,/* in */ unsigned int ma
|
||||||
X int mkv_ReadFrame(/* in */ MatroskaFile *mf,
|
X int mkv_ReadFrame(/* in */ MatroskaFile *mf,
|
||||||
/* in */ unsigned int mask,
|
/* in */ unsigned int mask,
|
||||||
/* out */ unsigned int *track,
|
/* out */ unsigned int *track,
|
||||||
/* out */ ulonglong *StartTime /* in ns */,
|
/* out */ uint64_t *StartTime /* in ns */,
|
||||||
/* out */ ulonglong *EndTime /* in ns */,
|
/* out */ uint64_t *EndTime /* in ns */,
|
||||||
/* out */ ulonglong *FilePos /* in bytes from start of file */,
|
/* out */ uint64_t *FilePos /* in bytes from start of file */,
|
||||||
/* out */ unsigned int *FrameSize /* in bytes */,
|
/* out */ unsigned int *FrameSize /* in bytes */,
|
||||||
/* out */ unsigned int *FrameFlags);
|
/* out */ unsigned int *FrameFlags);
|
||||||
|
|
||||||
|
@ -374,7 +367,7 @@ X void cs_Destroy(/* in */ CompressedStream *cs);
|
||||||
/* advance to the next frame in matroska stream, you need to pass values returned
|
/* advance to the next frame in matroska stream, you need to pass values returned
|
||||||
* by mkv_ReadFrame */
|
* by mkv_ReadFrame */
|
||||||
X void cs_NextFrame(/* in */ CompressedStream *cs,
|
X void cs_NextFrame(/* in */ CompressedStream *cs,
|
||||||
/* in */ ulonglong pos,
|
/* in */ uint64_t pos,
|
||||||
/* in */ unsigned size);
|
/* in */ unsigned size);
|
||||||
|
|
||||||
/* read and decode more data from current frame, return number of bytes decoded,
|
/* read and decode more data from current frame, return number of bytes decoded,
|
||||||
|
|
|
@ -62,7 +62,7 @@ struct MkvStdIO final : InputStream {
|
||||||
agi::read_file_mapping file;
|
agi::read_file_mapping file;
|
||||||
std::string error;
|
std::string error;
|
||||||
|
|
||||||
static int Read(InputStream *st, ulonglong pos, void *buffer, int count) {
|
static int Read(InputStream *st, uint64_t pos, void *buffer, int count) {
|
||||||
auto *self = static_cast<MkvStdIO*>(st);
|
auto *self = static_cast<MkvStdIO*>(st);
|
||||||
if (pos == self->file.size())
|
if (pos == self->file.size())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -78,7 +78,7 @@ struct MkvStdIO final : InputStream {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static longlong Scan(InputStream *st, ulonglong start, unsigned signature) {
|
static int64_t Scan(InputStream *st, uint64_t start, unsigned signature) {
|
||||||
auto *self = static_cast<MkvStdIO*>(st);
|
auto *self = static_cast<MkvStdIO*>(st);
|
||||||
try {
|
try {
|
||||||
unsigned cmp = 0;
|
unsigned cmp = 0;
|
||||||
|
@ -96,7 +96,7 @@ struct MkvStdIO final : InputStream {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static longlong Size(InputStream *st) {
|
static int64_t Size(InputStream *st) {
|
||||||
return static_cast<MkvStdIO*>(st)->file.size();
|
return static_cast<MkvStdIO*>(st)->file.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ struct MkvStdIO final : InputStream {
|
||||||
memalloc = [](InputStream *, size_t size) { return malloc(size); };
|
memalloc = [](InputStream *, size_t size) { return malloc(size); };
|
||||||
memrealloc = [](InputStream *, void *mem, size_t size) { return realloc(mem, size); };
|
memrealloc = [](InputStream *, void *mem, size_t size) { return realloc(mem, size); };
|
||||||
memfree = [](InputStream *, void *mem) { free(mem); };
|
memfree = [](InputStream *, void *mem) { free(mem); };
|
||||||
progress = [](InputStream *, ulonglong, ulonglong) { return 1; };
|
progress = [](InputStream *, uint64_t, uint64_t) { return 1; };
|
||||||
getfilesize = &MkvStdIO::Size;
|
getfilesize = &MkvStdIO::Size;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -117,7 +117,7 @@ static void read_subtitles(agi::ProgressSink *ps, MatroskaFile *file, MkvStdIO *
|
||||||
std::vector<std::pair<int, std::string>> subList;
|
std::vector<std::pair<int, std::string>> subList;
|
||||||
|
|
||||||
// Load blocks
|
// Load blocks
|
||||||
ulonglong startTime, endTime, filePos;
|
uint64_t startTime, endTime, filePos;
|
||||||
unsigned int rt, frameSize, frameFlags;
|
unsigned int rt, frameSize, frameFlags;
|
||||||
|
|
||||||
while (mkv_ReadFrame(file, 0, &rt, &startTime, &endTime, &filePos, &frameSize, &frameFlags) == 0) {
|
while (mkv_ReadFrame(file, 0, &rt, &startTime, &endTime, &filePos, &frameSize, &frameFlags) == 0) {
|
||||||
|
@ -128,7 +128,7 @@ static void read_subtitles(agi::ProgressSink *ps, MatroskaFile *file, MkvStdIO *
|
||||||
const auto readBufEnd = readBuf + frameSize;
|
const auto readBufEnd = readBuf + frameSize;
|
||||||
|
|
||||||
// Get start and end times
|
// Get start and end times
|
||||||
longlong timecodeScaleLow = 1000000;
|
int64_t timecodeScaleLow = 1000000;
|
||||||
AssTime subStart = startTime / timecodeScaleLow;
|
AssTime subStart = startTime / timecodeScaleLow;
|
||||||
AssTime subEnd = endTime / timecodeScaleLow;
|
AssTime subEnd = endTime / timecodeScaleLow;
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ void MatroskaWrapper::GetSubtitles(agi::fs::path const& filename, AssFile *targe
|
||||||
|
|
||||||
// Read timecode scale
|
// Read timecode scale
|
||||||
auto segInfo = mkv_GetFileInfo(file);
|
auto segInfo = mkv_GetFileInfo(file);
|
||||||
longlong timecodeScale = mkv_TruncFloat(trackInfo->TimecodeScale) * segInfo->TimecodeScale;
|
int64_t timecodeScale = mkv_TruncFloat(trackInfo->TimecodeScale) * segInfo->TimecodeScale;
|
||||||
|
|
||||||
// Progress bar
|
// Progress bar
|
||||||
auto totalTime = double(segInfo->Duration) / timecodeScale;
|
auto totalTime = double(segInfo->Duration) / timecodeScale;
|
||||||
|
|
Loading…
Reference in a new issue