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 } },
45 const struct fcc_to_avcodecid* c;
47 for (c = lc; c->codec != CODEC_ID_NONE; c++)
50 while (c->list[i] != 0)
51 if (c->list[i++] == fcc)
52 return avcodec_find_decoder(c->codec);
58 static private_handle_t* create_handle(void)
60 private_handle_t* t = av_malloc(sizeof(private_handle_t));
63 memset(t, 0, sizeof(*t));
69 avcodec_register_all();
74 t->prev = handle_first->next;
75 handle_first->next = t;
76 t->next = handle_first;
82 static void destroy_handle(private_handle_t* handle)
88 avcodec_close(&handle->avcontext);
96 int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
98 AVCodecContext* ctx = handle;
101 case AVC_OPEN_BY_NAME:
103 // pin char* codec name
104 private_handle_t* h = create_handle();
105 (private_handle_t**)pout = h;
111 (private_handle_t**)pout = NULL;
112 return -1;// better error
116 case AVC_OPEN_BY_CODEC_ID:
118 // pin uint32_t codec fourcc
119 private_handle_t* h = create_handle();
120 (private_handle_t**)pout = h;
127 (private_handle_t**)pout = NULL;
128 return -1;// better error
132 case AVC_OPEN_BY_FOURCC:
134 // pin uint32_t codec fourcc
135 private_handle_t* h = create_handle();
136 (private_handle_t**)pout = h;
139 h->avcodec = avcodec_find_by_fcc((uint32_t) pin);
143 (private_handle_t**)pout = NULL;
144 return -1;// better error
150 // eventually close all allocated space if this was last
152 destroy_handle(handle);
164 case AVC_GET_VERSION: