r1053: Add Russian translation.
[cinelerra_cv.git] / quicktime / plugin.c
blob333b040b09fe28b8ab119f7495aaefebfd509c35
1 #include <stdio.h>
2 #include <dirent.h>
3 #include <dlfcn.h>
4 #include "funcprotos.h"
5 #include "quicktime.h"
8 static int total_vcodecs = 0;
9 static int total_acodecs = 0;
10 static quicktime_codectable_t *vcodecs = NULL;
11 static quicktime_codectable_t *acodecs = NULL;
16 static int register_vcodec(void (*init_vcodec)(quicktime_video_map_t *))
18 total_vcodecs++;
19 vcodecs = (quicktime_codectable_t *)realloc(vcodecs,
20 total_vcodecs * sizeof(quicktime_codectable_t));
22 vcodecs[total_vcodecs - 1].init_vcodec = init_vcodec;
23 return total_vcodecs - 1;
26 static int register_acodec(void (*init_acodec)(quicktime_audio_map_t *))
28 total_acodecs++;
29 acodecs = (quicktime_codectable_t *)realloc(acodecs,
30 total_acodecs * sizeof(quicktime_codectable_t));
31 acodecs[total_acodecs - 1].init_acodec = init_acodec;
32 return total_acodecs - 1;
38 #include "ima4.h"
39 #include "mp4a.h"
40 #include "qtvorbis.h"
41 #include "qtmp3.h"
42 #include "rawaudio.h"
43 #include "twos.h"
44 #include "ulaw.h"
45 #include "wma.h"
46 #include "wmx2.h"
48 static void register_acodecs()
50 register_acodec(quicktime_init_codec_twos);
51 register_acodec(quicktime_init_codec_rawaudio);
52 register_acodec(quicktime_init_codec_ima4);
53 register_acodec(quicktime_init_codec_mp4a);
54 register_acodec(quicktime_init_codec_ulaw);
56 register_acodec(quicktime_init_codec_vorbis);
57 register_acodec(quicktime_init_codec_mp3);
58 register_acodec(quicktime_init_codec_wmx2);
59 register_acodec(quicktime_init_codec_wmav1);
60 register_acodec(quicktime_init_codec_wmav2);
67 #include "qth264.h"
68 #include "raw.h"
69 #include "qtdv.h"
70 #include "jpeg.h"
71 #include "mpeg4.h"
72 #include "qtpng.h"
73 #include "rle.h"
74 #include "v308.h"
75 #include "v408.h"
76 #include "v410.h"
77 #include "yuv2.h"
78 #include "yuv4.h"
79 #include "yv12.h"
81 static void register_vcodecs()
84 register_vcodec(quicktime_init_codec_raw);
86 register_vcodec(quicktime_init_codec_h264);
87 register_vcodec(quicktime_init_codec_hv64);
88 register_vcodec(quicktime_init_codec_divx);
89 register_vcodec(quicktime_init_codec_hv60);
90 register_vcodec(quicktime_init_codec_div5);
91 register_vcodec(quicktime_init_codec_div3);
92 register_vcodec(quicktime_init_codec_div3v2);
93 register_vcodec(quicktime_init_codec_div3lower);
94 register_vcodec(quicktime_init_codec_mp4v);
95 register_vcodec(quicktime_init_codec_xvid);
96 register_vcodec(quicktime_init_codec_svq1);
97 register_vcodec(quicktime_init_codec_svq3);
98 register_vcodec(quicktime_init_codec_h263);
99 register_vcodec(quicktime_init_codec_dv);
100 register_vcodec(quicktime_init_codec_dvsd);
101 register_vcodec(quicktime_init_codec_dvcp);
103 register_vcodec(quicktime_init_codec_jpeg);
104 register_vcodec(quicktime_init_codec_mjpa);
105 register_vcodec(quicktime_init_codec_mjpg);
106 register_vcodec(quicktime_init_codec_png);
107 register_vcodec(quicktime_init_codec_rle);
109 register_vcodec(quicktime_init_codec_yuv2);
110 register_vcodec(quicktime_init_codec_2vuy);
111 register_vcodec(quicktime_init_codec_yuv4);
112 register_vcodec(quicktime_init_codec_yv12);
113 register_vcodec(quicktime_init_codec_v410);
114 register_vcodec(quicktime_init_codec_v308);
115 register_vcodec(quicktime_init_codec_v408);
121 int quicktime_find_vcodec(quicktime_video_map_t *vtrack)
123 int i;
124 char *compressor = vtrack->track->mdia.minf.stbl.stsd.table[0].format;
125 quicktime_codec_t *codec_base = (quicktime_codec_t*)vtrack->codec;
126 if(!total_vcodecs) register_vcodecs();
128 for(i = 0; i < total_vcodecs; i++)
130 quicktime_codectable_t *table = &vcodecs[i];
131 table->init_vcodec(vtrack);
132 if(quicktime_match_32(compressor, codec_base->fourcc))
134 return 0;
136 else
138 codec_base->delete_vcodec(vtrack);
139 codec_base->priv = 0;
143 return -1;
147 int quicktime_find_acodec(quicktime_audio_map_t *atrack)
149 int i;
150 char *compressor = atrack->track->mdia.minf.stbl.stsd.table[0].format;
151 int compression_id = atrack->track->mdia.minf.stbl.stsd.table[0].compression_id;
152 quicktime_codec_t *codec_base = (quicktime_codec_t*)atrack->codec;
153 int32_t compressor_int = *(int32_t*)compressor;
154 if(!total_acodecs) register_acodecs();
156 for(i = 0; i < total_acodecs; i++)
158 quicktime_codectable_t *table = &acodecs[i];
159 table->init_acodec(atrack);
161 // For writing and reading Quicktime
162 if(quicktime_match_32(compressor, codec_base->fourcc))
163 return 0;
164 else
165 // For reading AVI, sometimes the fourcc is 0 and the compression_id is used instead.
166 // Sometimes the compression_id is the fourcc.
167 if((compressor[0] == 0 || compressor_int == codec_base->wav_id) &&
168 codec_base->wav_id == compression_id)
169 return 0;
170 else
172 codec_base->delete_acodec(atrack);
173 codec_base->priv = 0;
177 return -1;
181 char* quicktime_acodec_title(char *fourcc)
183 int i;
184 char *result = 0;
185 quicktime_audio_map_t *atrack =
186 (quicktime_audio_map_t*)calloc(1, sizeof(quicktime_audio_map_t));
187 quicktime_codec_t *codec_base =
188 atrack->codec =
189 (quicktime_codec_t*)calloc(1, sizeof(quicktime_codec_t));
190 int done = 0;
191 if(!total_acodecs) register_acodecs();
192 for(i = 0; i < total_acodecs && !done; i++)
194 //printf("quicktime_acodec_title 1\n");
195 quicktime_codectable_t *table = &acodecs[i];
196 //printf("quicktime_acodec_title 2\n");
197 table->init_acodec(atrack);
198 //printf("quicktime_acodec_title 3\n");
199 if(quicktime_match_32(fourcc, codec_base->fourcc))
201 result = codec_base->title;
202 done = 1;
204 //printf("quicktime_acodec_title 4\n");
205 codec_base->delete_acodec(atrack);
206 //printf("quicktime_acodec_title 5\n");
208 free(codec_base);
209 free(atrack);
211 if(!result)
212 return fourcc;
213 else
214 return result;
217 char* quicktime_vcodec_title(char *fourcc)
219 int i;
220 char *result = 0;
222 quicktime_video_map_t *vtrack =
223 (quicktime_video_map_t*)calloc(1, sizeof(quicktime_video_map_t));
224 quicktime_codec_t *codec_base =
225 vtrack->codec =
226 (quicktime_codec_t*)calloc(1, sizeof(quicktime_codec_t));
227 int done = 0;
230 if(!total_vcodecs) register_vcodecs();
231 for(i = 0; i < total_vcodecs && !done; i++)
233 quicktime_codectable_t *table = &vcodecs[i];
234 table->init_vcodec(vtrack);
235 if(quicktime_match_32(fourcc, codec_base->fourcc))
237 result = codec_base->title;
238 done = 1;
240 codec_base->delete_vcodec(vtrack);
245 free(codec_base);
246 free(vtrack);
248 if(!result)
249 return fourcc;
250 else
251 return result;