annotate avcodec.c @ 2269:535b7dfee202 libavcodec

lowres fixes for the parser
author michael
date Mon, 27 Sep 2004 10:06:10 +0000
parents ef54decf5624
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1059
diff changeset
1 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1059
diff changeset
2 * @file avcodec.c
1e39f273ecd6 per file doxy
michaelni
parents: 1059
diff changeset
3 * avcodec.
1e39f273ecd6 per file doxy
michaelni
parents: 1059
diff changeset
4 */
1e39f273ecd6 per file doxy
michaelni
parents: 1059
diff changeset
5
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
6 #include "errno.h"
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
7 #include "avcodec.h"
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
8
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
9 #ifndef MKTAG
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
10 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
11 #endif
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
12
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
13 // private structure used to hide all internal memory allocations
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
14 // and structures used for de/encoding - end user should
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
15 // never see any complicated structure
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
16 typedef struct private_handle
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
17 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
18 AVCodec* avcodec;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
19 AVCodecContext avcontext;
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
20 struct private_handle* next;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
21 struct private_handle* prev;
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
22 } private_handle_t;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
23
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
24 static private_handle_t* handle_first = 0;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
25
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
26 static AVCodec* avcodec_find_by_fcc(uint32_t fcc)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
27 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
28 // translation table
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
29 static const struct fcc_to_avcodecid {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
30 enum CodecID codec;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
31 uint32_t list[4]; // maybe we could map more fcc to same codec
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
32 } lc[] = {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
33 { CODEC_ID_H263, { MKTAG('U', '2', '6', '3'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
34 { CODEC_ID_H263I, { MKTAG('I', '2', '6', '3'), 0 } },
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
35 { CODEC_ID_MSMPEG4V3, { MKTAG('D', 'I', 'V', '3'), 0 } },
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
36 { CODEC_ID_MPEG4, { MKTAG('D', 'I', 'V', 'X'), MKTAG('D', 'X', '5', '0'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
37 { CODEC_ID_MSMPEG4V2, { MKTAG('M', 'P', '4', '2'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
38 { CODEC_ID_MJPEG, { MKTAG('M', 'J', 'P', 'G'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
39 { CODEC_ID_MPEG1VIDEO, { MKTAG('P', 'I', 'M', '1'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
40 { CODEC_ID_AC3, { 0x2000, 0 } },
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 1353
diff changeset
41 { CODEC_ID_DTS, { 0x10, 0 } },
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
42 { CODEC_ID_MP2, { 0x50, 0x55, 0 } },
1353
cfc80b3a4ada flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents: 1106
diff changeset
43 { CODEC_ID_FLV1, { MKTAG('F', 'L', 'V', '1'), 0 } },
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
44
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
45 { CODEC_ID_NONE, {0}}
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
46 };
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
47 const struct fcc_to_avcodecid* c;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
48
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
49 for (c = lc; c->codec != CODEC_ID_NONE; c++)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
50 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
51 int i = 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
52 while (c->list[i] != 0)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
53 if (c->list[i++] == fcc)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
54 return avcodec_find_decoder(c->codec);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
55 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
56
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
57 return NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
58 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
59
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
60 static private_handle_t* create_handle(void)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
61 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
62 private_handle_t* t = av_malloc(sizeof(private_handle_t));
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
63 if (!t)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
64 return NULL;
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
65 memset(t, 0, sizeof(*t));
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
66
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
67 // register and fill
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
68 if (!handle_first)
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
69 {
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
70 avcodec_init();
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
71 avcodec_register_all();
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
72 handle_first = t;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
73 }
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
74 else
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
75 {
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
76 t->prev = handle_first->next;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
77 handle_first->next = t;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
78 t->next = handle_first;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
79 }
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
80
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
81 return t;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
82 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
83
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
84 static void destroy_handle(private_handle_t* handle)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
85 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
86 if (handle)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
87 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
88 if (handle->avcodec)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
89 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
90 avcodec_close(&handle->avcontext);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
91 }
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
92 av_free(handle);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
93
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
94 // count referencies
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
95 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
96 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
97
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
98 int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
99 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
100 AVCodecContext* ctx = handle;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
101 switch (cmd)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
102 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
103 case AVC_OPEN_BY_NAME:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
104 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
105 // pin char* codec name
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
106 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
107 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
108 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
109 return -ENOMEM;
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
110 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
111 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
112 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
113 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
114 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
115 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
116 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
117 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
118 case AVC_OPEN_BY_CODEC_ID:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
119 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
120 // pin uint32_t codec fourcc
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
121 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
122 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
123 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
124 return -ENOMEM;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
125
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
126 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
127 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
128 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
129 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
130 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
131 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
132 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
133 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
134 case AVC_OPEN_BY_FOURCC:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
135 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
136 // pin uint32_t codec fourcc
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
137 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
138 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
139 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
140 return -ENOMEM;
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
141 h->avcodec = avcodec_find_by_fcc((uint32_t) pin);
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
142 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
143 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
144 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
145 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
146 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
147 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
148 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
149 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
150 case AVC_CLOSE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
151 // uninit part
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
152 // eventually close all allocated space if this was last
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
153 // instance
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
154 destroy_handle(handle);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
155 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
156
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
157 case AVC_FLUSH:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
158 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
159
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
160 case AVC_DECODE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
161 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
162
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
163 case AVC_ENCODE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
164 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
165
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
166 case AVC_GET_VERSION:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
167 (int*) pout = 500;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
168 default:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
169 return -1;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
170
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
171 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
172 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
173 }