10
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
13
// private structure used to hide all internal memory allocations
14
// and structures used for de/encoding - end user should
15
// never see any complicated structure
16
typedef struct private_handle
19
AVCodecContext avcontext;
20
struct private_handle* next;
21
struct private_handle* prev;
24
static private_handle_t* handle_first = 0;
26
static AVCodec* avcodec_find_by_fcc(uint32_t fcc)
29
static const struct fcc_to_avcodecid {
31
uint32_t list[4]; // maybe we could map more fcc to same codec
33
{ CODEC_ID_H263, { MKTAG('U', '2', '6', '3'), 0 } },
34
{ CODEC_ID_H263I, { MKTAG('I', '2', '6', '3'), 0 } },
35
{ CODEC_ID_MSMPEG4V3, { MKTAG('D', 'I', 'V', '3'), 0 } },
36
{ CODEC_ID_MPEG4, { MKTAG('D', 'I', 'V', 'X'), MKTAG('D', 'X', '5', '0'), 0 } },
37
{ CODEC_ID_MSMPEG4V2, { MKTAG('M', 'P', '4', '2'), 0 } },
38
{ CODEC_ID_MJPEG, { MKTAG('M', 'J', 'P', 'G'), 0 } },
39
{ CODEC_ID_MPEG1VIDEO, { MKTAG('P', 'I', 'M', '1'), 0 } },
40
{ CODEC_ID_AC3, { 0x2000, 0 } },
41
{ CODEC_ID_MP2, { 0x50, 0x55, 0 } },
42
{ CODEC_ID_FLV1, { MKTAG('F', 'L', 'V', '1'), 0 } },
46
const struct fcc_to_avcodecid* c;
48
for (c = lc; c->codec != CODEC_ID_NONE; c++)
51
while (c->list[i] != 0)
52
if (c->list[i++] == fcc)
53
return avcodec_find_decoder(c->codec);
59
static private_handle_t* create_handle(void)
61
private_handle_t* t = av_malloc(sizeof(private_handle_t));
64
memset(t, 0, sizeof(*t));
70
avcodec_register_all();
75
t->prev = handle_first->next;
76
handle_first->next = t;
77
t->next = handle_first;
83
static void destroy_handle(private_handle_t* handle)
89
avcodec_close(&handle->avcontext);
97
int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
99
AVCodecContext* ctx = handle;
102
case AVC_OPEN_BY_NAME:
104
// pin char* codec name
105
private_handle_t* h = create_handle();
106
(private_handle_t**)pout = h;
112
(private_handle_t**)pout = NULL;
113
return -1;// better error
117
case AVC_OPEN_BY_CODEC_ID:
119
// pin uint32_t codec fourcc
120
private_handle_t* h = create_handle();
121
(private_handle_t**)pout = h;
128
(private_handle_t**)pout = NULL;
129
return -1;// better error
133
case AVC_OPEN_BY_FOURCC:
135
// pin uint32_t codec fourcc
136
private_handle_t* h = create_handle();
137
(private_handle_t**)pout = h;
140
h->avcodec = avcodec_find_by_fcc((uint32_t) pin);
144
(private_handle_t**)pout = NULL;
145
return -1;// better error
151
// eventually close all allocated space if this was last
153
destroy_handle(handle);
165
case AVC_GET_VERSION: