annotate avcodec.c @ 1097:7104c8561512 libavcodec

10l
author michaelni
date Wed, 05 Mar 2003 17:53:33 +0000
parents 890b9fb44e84
children 1e39f273ecd6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
1 #include "errno.h"
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
2 #include "avcodec.h"
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
3
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
4 #ifndef MKTAG
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
5 #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
6 #endif
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
7
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
8 // private structure used to hide all internal memory allocations
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
9 // and structures used for de/encoding - end user should
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
10 // never see any complicated structure
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
11 typedef struct private_handle
382
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 AVCodec* avcodec;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
14 AVCodecContext avcontext;
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
15 struct private_handle* next;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
16 struct private_handle* prev;
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
17 } private_handle_t;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
18
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
19 static private_handle_t* handle_first = 0;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
20
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
21 static AVCodec* avcodec_find_by_fcc(uint32_t fcc)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
22 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
23 // translation table
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
24 static const struct fcc_to_avcodecid {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
25 enum CodecID codec;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
26 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
27 } lc[] = {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
28 { CODEC_ID_H263, { MKTAG('U', '2', '6', '3'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
29 { CODEC_ID_H263I, { MKTAG('I', '2', '6', '3'), 0 } },
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
30 { CODEC_ID_MSMPEG4V3, { MKTAG('D', 'I', 'V', '3'), 0 } },
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
31 { 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
32 { CODEC_ID_MSMPEG4V2, { MKTAG('M', 'P', '4', '2'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
33 { CODEC_ID_MJPEG, { MKTAG('M', 'J', 'P', 'G'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
34 { CODEC_ID_MPEG1VIDEO, { MKTAG('P', 'I', 'M', '1'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
35 { CODEC_ID_AC3, { 0x2000, 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
36 { CODEC_ID_MP2, { 0x50, 0x55, 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
37
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
38 { CODEC_ID_NONE, {0}}
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
39 };
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
40 const struct fcc_to_avcodecid* c;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
41
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
42 for (c = lc; c->codec != CODEC_ID_NONE; c++)
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 int i = 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
45 while (c->list[i] != 0)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
46 if (c->list[i++] == fcc)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
47 return avcodec_find_decoder(c->codec);
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
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
50 return NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
51 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
52
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
53 static private_handle_t* create_handle(void)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
54 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
55 private_handle_t* t = av_malloc(sizeof(private_handle_t));
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
56 if (!t)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
57 return NULL;
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
58 memset(t, 0, sizeof(*t));
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
59
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
60 // register and fill
852
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
61 if (!handle_first)
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
62 {
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
63 avcodec_init();
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
64 avcodec_register_all();
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
65 handle_first = t;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
66 }
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
67 else
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
68 {
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
69 t->prev = handle_first->next;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
70 handle_first->next = t;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
71 t->next = handle_first;
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
72 }
c01c98206ee6 * useless commit - ignore
kabi
parents: 382
diff changeset
73
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
74 return t;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
75 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
76
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
77 static void destroy_handle(private_handle_t* handle)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
78 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
79 if (handle)
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 if (handle->avcodec)
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 avcodec_close(&handle->avcontext);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
84 }
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
85 av_free(handle);
382
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 // count referencies
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 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
90
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
91 int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
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 AVCodecContext* ctx = handle;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
94 switch (cmd)
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 case AVC_OPEN_BY_NAME:
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 // pin char* codec name
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
99 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
100 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
101 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
102 return -ENOMEM;
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
103 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
104 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
105 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
106 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
107 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
108 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
109 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
110 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
111 case AVC_OPEN_BY_CODEC_ID:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
112 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
113 // pin uint32_t codec fourcc
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
114 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
115 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
116 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
117 return -ENOMEM;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
118
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
119 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
120 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
121 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
122 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
123 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
124 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
125 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
126 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
127 case AVC_OPEN_BY_FOURCC:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
128 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
129 // pin uint32_t codec fourcc
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
130 private_handle_t* h = create_handle();
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
131 (private_handle_t**)pout = h;
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
132 if (!h)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
133 return -ENOMEM;
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
134 h->avcodec = avcodec_find_by_fcc((uint32_t) pin);
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
135 if (!h->avcodec)
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
136 {
1059
890b9fb44e84 * still unfinished code for Options
kabi
parents: 852
diff changeset
137 destroy_handle(h);
382
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
138 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
139 return -1;// better error
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
140 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
141 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
142 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
143 case AVC_CLOSE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
144 // uninit part
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
145 // eventually close all allocated space if this was last
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
146 // instance
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
147 destroy_handle(handle);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
148 break;
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_FLUSH:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
151 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
152
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
153 case AVC_DECODE:
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_ENCODE:
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_GET_VERSION:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
160 (int*) pout = 500;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
161 default:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
162 return -1;
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 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
165 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
166 }