annotate avcodec.c @ 1504:df7ab60d1ee0 libavcodec

This patch marks frames used in RPZA decoder as reference frames, from Roberto Togni (rtogni at freemail.it)
author tmmm
date Sun, 05 Oct 2003 21:48:16 +0000
parents cfc80b3a4ada
children ef54decf5624
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 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
41 { 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
42 { CODEC_ID_FLV1, { MKTAG('F', 'L', 'V', '1'), 0 } },
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
43
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
44 { CODEC_ID_NONE, {0}}
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
45 };
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
46 const struct fcc_to_avcodecid* c;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
47
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
48 for (c = lc; c->codec != CODEC_ID_NONE; c++)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
49 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
50 int i = 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
51 while (c->list[i] != 0)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
52 if (c->list[i++] == fcc)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
53 return avcodec_find_decoder(c->codec);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
54 }
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 return NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
57 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
58
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
59 static private_handle_t* create_handle(void)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
60 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
61 private_handle_t* t = av_malloc(sizeof(private_handle_t));
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
62 if (!t)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
63 return NULL;
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
64 memset(t, 0, sizeof(*t));
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
65
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
66 // register and fill
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
67 if (!handle_first)
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
68 {
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
69 avcodec_init();
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
70 avcodec_register_all();
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
71 handle_first = t;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
72 }
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
73 else
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
74 {
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
75 t->prev = handle_first->next;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
76 handle_first->next = t;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
77 t->next = handle_first;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
78 }
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
79
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
80 return t;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
81 }
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 static void destroy_handle(private_handle_t* handle)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
84 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
85 if (handle)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
86 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
87 if (handle->avcodec)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
88 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
89 avcodec_close(&handle->avcontext);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
90 }
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
91 av_free(handle);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
92
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
93 // count referencies
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
94 }
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 int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
98 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
99 AVCodecContext* ctx = handle;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
100 switch (cmd)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
101 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
102 case AVC_OPEN_BY_NAME:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
103 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
104 // pin char* codec name
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
105 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
106 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
107 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
108 return -ENOMEM;
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
109 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
110 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
111 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
112 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
113 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
114 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
115 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
116 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
117 case AVC_OPEN_BY_CODEC_ID:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
118 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
119 // pin uint32_t codec fourcc
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
120 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
121 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
122 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
123 return -ENOMEM;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
124
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
125 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
126 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
127 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
128 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
129 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
130 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
131 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
132 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
133 case AVC_OPEN_BY_FOURCC:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
134 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
135 // pin uint32_t codec fourcc
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
136 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
137 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
138 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
139 return -ENOMEM;
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
140 h->avcodec = avcodec_find_by_fcc((uint32_t) pin);
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
141 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
142 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
143 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
144 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
145 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
146 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
147 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
148 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
149 case AVC_CLOSE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
150 // uninit part
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
151 // eventually close all allocated space if this was last
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
152 // instance
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
153 destroy_handle(handle);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
154 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
155
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
156 case AVC_FLUSH:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
157 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
158
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
159 case AVC_DECODE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
160 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
161
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
162 case AVC_ENCODE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
163 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
164
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
165 case AVC_GET_VERSION:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
166 (int*) pout = 500;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
167 default:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
168 return -1;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
169
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 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
172 }