[go: up one dir, main page]

Menu

[d49389]: / mov_mp4.h  Maximize  Restore  History

Download this file

91 lines (77 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef mov_mp4_header
#define mov_mp4_header
#include "windows.h"
#include "inttypes.h"
struct MovAtom{
__int64 sz;
unsigned long t;
__int64 pos;
int hsize;
};
struct MovParser{
const void* buf;
int buf_size;
const char* p;
__int64 offset;
__int64 fileSize;
HANDLE hfile;
MovParser(const void* buf, int buf_size, int64_t fileSize){
this->buf = buf;
this->buf_size = buf_size;
this->fileSize = fileSize;
p = (const char*)buf;
offset = 0;
hfile = 0;
}
MovParser(const wchar_t* name){
buf = 0;
buf_size = 0;
p = 0;
offset = 0;
hfile = CreateFileW(name,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
LARGE_INTEGER s;
GetFileSizeEx(hfile,&s);
fileSize = s.QuadPart;
}
~MovParser(){
if(hfile) CloseHandle(hfile);
}
bool can_read(int64_t s){
if(hfile){
if(fileSize-offset<8) return false;
} else {
if(buf_size-offset<8) return false;
}
return true;
}
bool can_read(MovAtom& a){
return offset<a.pos+a.sz;
}
void read(MovAtom& a, char*& buf, int& size, int extra=0){
size = int(a.sz-a.hsize);
buf = (char*)malloc(size+extra);
memset(buf+size,0,extra);
if(hfile){
unsigned long w;
ReadFile(hfile,buf,size,&w,0);
} else {
memcpy(buf,p,size); p+=size;
}
offset+=size;
}
void skip(MovAtom& a){
__int64 d = a.pos+a.sz-offset;
offset+=d;
if(hfile){
LARGE_INTEGER p;
p.QuadPart = offset;
SetFilePointerEx(hfile,p,0,FILE_BEGIN);
} else {
p+=d;
}
}
unsigned long read4();
__int64 read8();
bool read(MovAtom& a);
};
#endif