This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
avi_player.h
135 lines (108 loc) · 2.37 KB
/
avi_player.h
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Bermuda Syndrome engine rewrite
* Copyright (C) 2007-2011 Gregory Montoir
*/
#ifndef AVI_PLAYER_H__
#define AVI_PLAYER_H__
#include "intern.h"
enum AVI_ChunkType {
kChunkAudioType,
kChunkVideoType
};
struct AVI_Chunk {
AVI_ChunkType type;
uint8_t *data;
int dataSize;
};
struct File;
struct AVI_Demuxer {
enum {
kSizeOfChunk_avih = 56,
kSizeOfChunk_strh = 56,
kSizeOfChunk_waveformat = 16,
kSizeOfChunk_bitmapinfo = 40
};
bool open(File *f);
void close();
bool readHeader();
bool readHeader_avih();
bool readHeader_strh();
bool readHeader_strf_auds();
bool readHeader_strf_vids();
bool readNextChunk(AVI_Chunk &chunk);
int _frames;
int _width, _height;
int _streams;
int _frameRate;
File *_f;
int _recordsListSize;
uint8_t *_chunkData;
int _chunkDataSize;
int _audioBufferSize;
int _videoBufferSize;
};
struct Mixer;
struct SystemStub;
struct Cinepak_YUV_Vector {
uint8_t y[4];
uint8_t u, v;
};
enum {
kCinepakV1 = 0,
kCinepakV4 = 1
};
struct Cinepak_Decoder {
enum {
MAX_STRIPS = 2,
MAX_VECTORS = 256
};
uint8_t readByte() {
return *_data++;
}
uint16_t readWord() {
uint16_t value = READ_BE_UINT16(_data); _data += 2;
return value;
}
uint32_t readLong() {
uint32_t value = READ_BE_UINT32(_data); _data += 4;
return value;
}
void decodeFrameV4(Cinepak_YUV_Vector *v0, Cinepak_YUV_Vector *v1, Cinepak_YUV_Vector *v2, Cinepak_YUV_Vector *v3);
void decodeFrameV1(Cinepak_YUV_Vector *v);
void decodeVector(Cinepak_YUV_Vector *v);
void decode(const uint8_t *data, int dataSize);
const uint8_t *_data;
Cinepak_YUV_Vector _vectors[2][MAX_STRIPS][MAX_VECTORS];
int _w, _h;
int _xPos, _yPos, _yMax;
uint8_t *_yuvFrame;
int _yuvPitch;
};
struct AVI_SoundBufferQueue {
uint8_t *buffer;
int size;
int offset;
AVI_SoundBufferQueue *next;
};
struct AVI_Player {
enum {
kDefaultFrameWidth = 320,
kDefaultFrameHeight = 200,
kSoundPreloadSize = 4,
};
AVI_Player(Mixer *mixer, SystemStub *stub);
~AVI_Player();
void play(File *f);
void readNextFrame();
void decodeAudioChunk(AVI_Chunk &c);
void decodeVideoChunk(AVI_Chunk &c);
void mix(int16_t *buf, int samples);
static void mixCallback(void *param, uint8_t *buf, int len);
AVI_Demuxer _demux;
AVI_SoundBufferQueue *_soundQueue, *_soundTailQueue;
int _soundQueuePreloadSize;
Cinepak_Decoder _cinepak;
Mixer *_mixer;
SystemStub *_stub;
};
#endif // AVI_PLAYER_H__