annotate avcodec.c @ 596:01da62a51ce8 libavcodec

hopefully fixing unreprodceable segfault when overreading the end if error_resilience==-1 (it didnt overread here though)
author michaelni
date Sun, 04 Aug 2002 19:28:27 +0000
parents b1663b0ffbbc
children c01c98206ee6
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
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
11 typedef struct
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;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
15 } private_handle_t;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
16
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
17 static AVCodec* avcodec_find_by_fcc(uint32_t fcc)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
18 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
19 // translation table
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
20 static const struct fcc_to_avcodecid {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
21 enum CodecID codec;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
22 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
23 } lc[] = {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
24 { CODEC_ID_H263, { MKTAG('U', '2', '6', '3'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
25 { CODEC_ID_H263I, { MKTAG('I', '2', '6', '3'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
26 { CODEC_ID_MSMPEG4, { MKTAG('D', 'I', 'V', '3'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
27 { 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
28 { CODEC_ID_MSMPEG4V2, { MKTAG('M', 'P', '4', '2'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
29 { CODEC_ID_MJPEG, { MKTAG('M', 'J', 'P', 'G'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
30 { CODEC_ID_MPEG1VIDEO, { MKTAG('P', 'I', 'M', '1'), 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
31 { CODEC_ID_AC3, { 0x2000, 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
32 { CODEC_ID_MP2, { 0x50, 0x55, 0 } },
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
33
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
34 { CODEC_ID_NONE, {0}}
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
35 };
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
36 const struct fcc_to_avcodecid* c;
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 for (c = lc; c->codec != CODEC_ID_NONE; c++)
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 int i = 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
41 while (c->list[i] != 0)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
42 if (c->list[i++] == fcc)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
43 return avcodec_find_decoder(c->codec);
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
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
46 return NULL;
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
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
49 static private_handle_t* create_handle()
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 private_handle_t* t = malloc(sizeof(private_handle_t));
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
52 if (!t)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
53 return NULL;
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 // register and fill
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
56 avcodec_init();
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
57 avcodec_register_all();
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
58 return t;
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
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
61 static void destroy_handle(private_handle_t* handle)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
62 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
63 if (handle)
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 if (handle->avcodec)
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 avcodec_close(&handle->avcontext);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
68 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
69 free(handle);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
70
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
71 // count referencies
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
72 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
73 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
74
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
75 int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
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 AVCodecContext* ctx = handle;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
78 switch (cmd)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
79 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
80 case AVC_OPEN_BY_NAME:
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 // pin char* codec name
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
83 private_handle_t* handle = create_handle();
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
84 (private_handle_t**)pout = handle;
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 return -ENOMEM;
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 destroy_handle(handle);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
90 (private_handle_t**)pout = NULL;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
91 return -1;// better error
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 return 0;
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 case AVC_OPEN_BY_CODEC_ID:
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 // pin uint32_t codec fourcc
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
98 private_handle_t* handle = create_handle();
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
99 (private_handle_t**)pout = handle;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
100 if (!handle)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
101 return -ENOMEM;
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 if (!handle->avcodec)
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 destroy_handle(handle);
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_FOURCC:
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
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
114 private_handle_t* handle = create_handle();
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
115 (private_handle_t**)pout = handle;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
116 if (!handle)
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 handle->avcodec = avcodec_find_by_fcc((uint32_t) pin);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
119 if (!handle->avcodec)
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
120 {
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
121 destroy_handle(handle);
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_CLOSE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
128 // uninit part
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
129 // eventually close all allocated space if this was last
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
130 // instance
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
131 destroy_handle(handle);
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
132 break;
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_FLUSH:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
135 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
136
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
137 case AVC_DECODE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
138 break;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
139
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
140 case AVC_ENCODE:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
141 break;
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_GET_VERSION:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
144 (int*) pout = 500;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
145 default:
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
146 return -1;
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 }
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
149 return 0;
b1663b0ffbbc * first shot for the new avcodec API
kabi
parents:
diff changeset
150 }