annotate avcodec.c @ 1106:1e39f273ecd6 libavcodec

per file doxy
author michaelni
date Thu, 06 Mar 2003 11:32:04 +0000
parents 890b9fb44e84
children cfc80b3a4ada
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 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
42
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
43 { CODEC_ID_NONE, {0}}
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 const struct fcc_to_avcodecid* c;
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 for (c = lc; c->codec != CODEC_ID_NONE; 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 int i = 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
50 while (c->list[i] != 0)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
51 if (c->list[i++] == fcc)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
52 return avcodec_find_decoder(c->codec);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
53 }
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 return NULL;
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
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
58 static private_handle_t* create_handle(void)
382
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 private_handle_t* t = av_malloc(sizeof(private_handle_t));
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
61 if (!t)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
62 return NULL;
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
63 memset(t, 0, sizeof(*t));
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
64
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
65 // register and fill
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
66 if (!handle_first)
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
67 {
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
68 avcodec_init();
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
69 avcodec_register_all();
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
70 handle_first = t;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
71 }
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
72 else
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
73 {
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
74 t->prev = handle_first->next;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
75 handle_first->next = t;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
76 t->next = handle_first;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
77 }
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
78
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
79 return t;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
80 }
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 static void destroy_handle(private_handle_t* handle)
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 if (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->avcodec)
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 avcodec_close(&handle->avcontext);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
89 }
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
90 av_free(handle);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
91
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
92 // count referencies
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 }
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 int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
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 AVCodecContext* ctx = handle;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
99 switch (cmd)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
100 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
101 case AVC_OPEN_BY_NAME:
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 // pin char* codec name
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
104 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
105 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
106 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
107 return -ENOMEM;
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
108 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
109 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
110 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
111 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
112 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
113 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
114 return 0;
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 case AVC_OPEN_BY_CODEC_ID:
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 // pin uint32_t codec fourcc
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
119 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
120 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
121 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
122 return -ENOMEM;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
123
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
124 if (!h->avcodec)
382
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 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
127 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
128 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
129 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
130 return 0;
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 case AVC_OPEN_BY_FOURCC:
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 // pin uint32_t codec fourcc
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
135 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
136 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
137 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
138 return -ENOMEM;
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
139 h->avcodec = avcodec_find_by_fcc((uint32_t) pin);
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
140 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
141 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
142 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
143 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
144 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
145 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
146 return 0;
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 case AVC_CLOSE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
149 // uninit part
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
150 // eventually close all allocated space if this was last
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
151 // instance
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
152 destroy_handle(handle);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
153 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
154
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
155 case AVC_FLUSH:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
156 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
157
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
158 case AVC_DECODE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
159 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
160
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
161 case AVC_ENCODE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
162 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
163
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
164 case AVC_GET_VERSION:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
165 (int*) pout = 500;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
166 default:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
167 return -1;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
168
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 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
171 }