1 /* GStreamer RIFF I/O
2 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3 *
4 * riff-media.h: RIFF-id to/from caps routines
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "riff-ids.h"
27 #include "riff-media.h"
28
29 #include <gst/audio/audio.h>
30
31 #include <string.h>
32 #include <math.h>
33
34 GST_DEBUG_CATEGORY_EXTERN (riff_debug);
35 #define GST_CAT_DEFAULT riff_debug
36
37 /**
38 * gst_riff_create_video_caps:
39 * @codec_fcc: fourCC codec for this codec.
40 * @strh: pointer to the strh stream header structure.
41 * @strf: pointer to the strf stream header structure, including any
42 * data that is within the range of strf.size, but excluding any
43 * additional data withint this chunk but outside strf.size.
44 * @strf_data: a #GstBuffer containing the additional data in the strf
45 * chunk outside reach of strf.size. Usually a palette.
46 * @strd_data: a #GstBuffer containing the data in the strd stream header
47 * chunk. Usually codec initialization data.
48 * @codec_name: if given, will be filled with a human-readable codec name.
49 */
50
51 GstCaps *
gst_riff_create_video_caps(guint32 codec_fcc,gst_riff_strh * strh,gst_riff_strf_vids * strf,GstBuffer * strf_data,GstBuffer * strd_data,char ** codec_name)52 gst_riff_create_video_caps (guint32 codec_fcc,
53 gst_riff_strh * strh, gst_riff_strf_vids * strf,
54 GstBuffer * strf_data, GstBuffer * strd_data, char **codec_name)
55 {
56 GstCaps *caps = NULL;
57 GstBuffer *palette = NULL;
58
59 GST_DEBUG ("video fourcc %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (codec_fcc));
60
61 switch (codec_fcc) {
62 case GST_RIFF_DIB: /* uncompressed RGB */
63 case GST_RIFF_rgb:
64 case GST_RIFF_RGB:
65 case GST_RIFF_RAW:
66 {
67 gint bpp = (strf && strf->bit_cnt != 0) ? strf->bit_cnt : 8;
68
69 if (strf) {
70 if (bpp == 8) {
71 caps = gst_caps_new_simple ("video/x-raw",
72 "format", G_TYPE_STRING, "RGB8P", NULL);
73 } else if (bpp == 24) {
74 caps = gst_caps_new_simple ("video/x-raw",
75 "format", G_TYPE_STRING, "BGR", NULL);
76 } else if (bpp == 32) {
77 caps = gst_caps_new_simple ("video/x-raw",
78 "format", G_TYPE_STRING, "BGRx", NULL);
79 } else {
80 GST_WARNING ("Unhandled DIB RGB depth: %d", bpp);
81 return NULL;
82 }
83 } else {
84 /* for template */
85 caps =
86 gst_caps_from_string ("video/x-raw, format = (string) "
87 "{ RGB8P, BGR, BGRx }");
88 }
89
90 palette = strf_data;
91 strf_data = NULL;
92 if (codec_name) {
93 if (bpp == 8)
94 *codec_name = g_strdup_printf ("Palettized %d-bit RGB", bpp);
95 else
96 *codec_name = g_strdup_printf ("%d-bit RGB", bpp);
97 }
98 break;
99 }
100
101 case GST_MAKE_FOURCC ('G', 'R', 'E', 'Y'):
102 case GST_MAKE_FOURCC ('Y', '8', '0', '0'):
103 case GST_MAKE_FOURCC ('Y', '8', ' ', ' '):
104 caps = gst_caps_new_simple ("video/x-raw",
105 "format", G_TYPE_STRING, "GRAY8", NULL);
106 if (codec_name)
107 *codec_name = g_strdup ("Uncompressed 8-bit monochrome");
108 break;
109
110 case GST_MAKE_FOURCC ('r', '2', '1', '0'):
111 caps = gst_caps_new_simple ("video/x-raw",
112 "format", G_TYPE_STRING, "r210", NULL);
113 if (codec_name)
114 *codec_name = g_strdup ("Uncompressed packed RGB 10-bit 4:4:4");
115 break;
116
117 case GST_RIFF_I420:
118 case GST_RIFF_i420:
119 case GST_RIFF_IYUV:
120 caps = gst_caps_new_simple ("video/x-raw",
121 "format", G_TYPE_STRING, "I420", NULL);
122 if (codec_name)
123 *codec_name = g_strdup ("Uncompressed planar YUV 4:2:0");
124 break;
125
126 case GST_RIFF_YUY2:
127 case GST_RIFF_yuy2:
128 case GST_MAKE_FOURCC ('Y', 'U', 'N', 'V'):
129 case GST_MAKE_FOURCC ('Y', 'U', 'Y', 'V'):
130 caps = gst_caps_new_simple ("video/x-raw",
131 "format", G_TYPE_STRING, "YUY2", NULL);
132 if (codec_name)
133 *codec_name = g_strdup ("Uncompressed packed YUV 4:2:2");
134 break;
135
136 case GST_RIFF_YVU9:
137 caps = gst_caps_new_simple ("video/x-raw",
138 "format", G_TYPE_STRING, "YVU9", NULL);
139 if (codec_name)
140 *codec_name = g_strdup ("Uncompressed packed YVU 4:1:0");
141 break;
142
143 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
144 case GST_MAKE_FOURCC ('2', 'v', 'u', 'y'):
145 case GST_MAKE_FOURCC ('H', 'D', 'Y', 'C'):
146 caps = gst_caps_new_simple ("video/x-raw",
147 "format", G_TYPE_STRING, "UYVY", NULL);
148 if (codec_name)
149 *codec_name = g_strdup ("Uncompressed packed YUV 4:2:2");
150 break;
151
152 case GST_RIFF_YV12:
153 case GST_RIFF_yv12:
154 caps = gst_caps_new_simple ("video/x-raw",
155 "format", G_TYPE_STRING, "YV12", NULL);
156 if (codec_name)
157 *codec_name = g_strdup ("Uncompressed packed YVU 4:2:2");
158 break;
159 case GST_MAKE_FOURCC ('v', '2', '1', '0'):
160 caps = gst_caps_new_simple ("video/x-raw",
161 "format", G_TYPE_STRING, "v210", NULL);
162 if (codec_name)
163 *codec_name = g_strdup ("Uncompressed packed 10-bit YUV 4:2:2");
164 break;
165
166 case GST_RIFF_MJPG: /* YUY2 MJPEG */
167 case GST_RIFF_mJPG:
168 case GST_MAKE_FOURCC ('A', 'V', 'R', 'n'):
169 case GST_RIFF_IJPG:
170 case GST_MAKE_FOURCC ('i', 'j', 'p', 'g'):
171 case GST_RIFF_DMB1:
172 case GST_RIFF_dmb1:
173 case GST_MAKE_FOURCC ('A', 'C', 'D', 'V'):
174 case GST_MAKE_FOURCC ('Q', 'I', 'V', 'G'):
175 caps = gst_caps_new_empty_simple ("image/jpeg");
176 if (codec_name)
177 *codec_name = g_strdup ("Motion JPEG");
178 break;
179
180 case GST_RIFF_JPEG: /* generic (mostly RGB) MJPEG */
181 case GST_RIFF_jpeg:
182 case GST_MAKE_FOURCC ('j', 'p', 'e', 'g'): /* generic (mostly RGB) MJPEG */
183 caps = gst_caps_new_empty_simple ("image/jpeg");
184 if (codec_name)
185 *codec_name = g_strdup ("JPEG Still Image");
186 break;
187
188 case GST_MAKE_FOURCC ('P', 'I', 'X', 'L'): /* Miro/Pinnacle fourccs */
189 case GST_RIFF_VIXL: /* Miro/Pinnacle fourccs */
190 case GST_RIFF_vixl:
191 caps = gst_caps_new_empty_simple ("image/jpeg");
192 if (codec_name)
193 *codec_name = g_strdup ("Miro/Pinnacle Motion JPEG");
194 break;
195
196 case GST_MAKE_FOURCC ('C', 'J', 'P', 'G'):
197 caps = gst_caps_new_empty_simple ("image/jpeg");
198 if (codec_name)
199 *codec_name = g_strdup ("Creative Webcam JPEG");
200 break;
201
202 case GST_MAKE_FOURCC ('S', 'L', 'M', 'J'):
203 caps = gst_caps_new_empty_simple ("image/jpeg");
204 if (codec_name)
205 *codec_name = g_strdup ("SL Motion JPEG");
206 break;
207
208 case GST_MAKE_FOURCC ('J', 'P', 'G', 'L'):
209 caps = gst_caps_new_empty_simple ("image/jpeg");
210 if (codec_name)
211 *codec_name = g_strdup ("Pegasus Lossless JPEG");
212 break;
213
214 case GST_MAKE_FOURCC ('L', 'O', 'C', 'O'):
215 caps = gst_caps_new_empty_simple ("video/x-loco");
216 if (codec_name)
217 *codec_name = g_strdup ("LOCO Lossless");
218 break;
219
220 case GST_MAKE_FOURCC ('S', 'P', '5', '3'):
221 case GST_MAKE_FOURCC ('S', 'P', '5', '4'):
222 case GST_MAKE_FOURCC ('S', 'P', '5', '5'):
223 case GST_MAKE_FOURCC ('S', 'P', '5', '6'):
224 case GST_MAKE_FOURCC ('S', 'P', '5', '7'):
225 case GST_MAKE_FOURCC ('S', 'P', '5', '8'):
226 caps = gst_caps_new_empty_simple ("video/sp5x");
227 if (codec_name)
228 *codec_name = g_strdup ("Sp5x-like JPEG");
229 break;
230
231 case GST_MAKE_FOURCC ('Z', 'M', 'B', 'V'):
232 caps = gst_caps_new_empty_simple ("video/x-zmbv");
233 if (codec_name)
234 *codec_name = g_strdup ("Zip Motion Block video");
235 break;
236
237 case GST_MAKE_FOURCC ('H', 'F', 'Y', 'U'):
238 caps = gst_caps_new_empty_simple ("video/x-huffyuv");
239 if (strf) {
240 gst_caps_set_simple (caps, "bpp",
241 G_TYPE_INT, (int) strf->bit_cnt, NULL);
242 }
243 if (codec_name)
244 *codec_name = g_strdup ("Huffman Lossless Codec");
245 break;
246
247 case GST_MAKE_FOURCC ('M', 'P', 'E', 'G'):
248 case GST_MAKE_FOURCC ('M', 'P', 'G', 'I'):
249 case GST_MAKE_FOURCC ('m', 'p', 'g', '1'):
250 case GST_MAKE_FOURCC ('M', 'P', 'G', '1'):
251 case GST_MAKE_FOURCC ('P', 'I', 'M', '1'):
252 case GST_MAKE_FOURCC (0x01, 0x00, 0x00, 0x10):
253 caps = gst_caps_new_simple ("video/mpeg",
254 "systemstream", G_TYPE_BOOLEAN, FALSE,
255 "mpegversion", G_TYPE_INT, 1, NULL);
256 if (codec_name)
257 *codec_name = g_strdup ("MPEG-1 video");
258 break;
259
260 case GST_MAKE_FOURCC ('M', 'P', 'G', '2'):
261 case GST_MAKE_FOURCC ('m', 'p', 'g', '2'):
262 case GST_MAKE_FOURCC ('P', 'I', 'M', '2'):
263 case GST_MAKE_FOURCC ('D', 'V', 'R', ' '):
264 case GST_MAKE_FOURCC (0x02, 0x00, 0x00, 0x10):
265 caps = gst_caps_new_simple ("video/mpeg",
266 "systemstream", G_TYPE_BOOLEAN, FALSE,
267 "mpegversion", G_TYPE_INT, 2, NULL);
268 if (codec_name)
269 *codec_name = g_strdup ("MPEG-2 video");
270 break;
271
272 case GST_MAKE_FOURCC ('L', 'M', 'P', '2'):
273 caps = gst_caps_new_simple ("video/mpeg",
274 "systemstream", G_TYPE_BOOLEAN, FALSE,
275 "mpegversion", G_TYPE_INT, 2, NULL);
276 if (codec_name)
277 *codec_name = g_strdup ("Lead MPEG-2 video");
278 break;
279
280 case GST_RIFF_H263:
281 case GST_RIFF_h263:
282 case GST_RIFF_i263:
283 case GST_MAKE_FOURCC ('U', '2', '6', '3'):
284 case GST_MAKE_FOURCC ('v', 'i', 'v', '1'):
285 case GST_MAKE_FOURCC ('T', '2', '6', '3'):
286 caps = gst_caps_new_simple ("video/x-h263",
287 "variant", G_TYPE_STRING, "itu", NULL);
288 if (codec_name)
289 *codec_name = g_strdup ("ITU H.26n");
290 break;
291
292 case GST_RIFF_L263:
293 /* http://www.leadcodecs.com/Codecs/LEAD-H263.htm */
294 caps = gst_caps_new_simple ("video/x-h263",
295 "variant", G_TYPE_STRING, "lead", NULL);
296 if (codec_name)
297 *codec_name = g_strdup ("Lead H.263");
298 break;
299
300 case GST_RIFF_M263:
301 case GST_RIFF_m263:
302 caps = gst_caps_new_simple ("video/x-h263",
303 "variant", G_TYPE_STRING, "microsoft", NULL);
304 if (codec_name)
305 *codec_name = g_strdup ("Microsoft H.263");
306 break;
307
308 case GST_RIFF_VDOW:
309 caps = gst_caps_new_simple ("video/x-h263",
310 "variant", G_TYPE_STRING, "vdolive", NULL);
311 if (codec_name)
312 *codec_name = g_strdup ("VDOLive");
313 break;
314
315 case GST_MAKE_FOURCC ('V', 'I', 'V', 'O'):
316 caps = gst_caps_new_simple ("video/x-h263",
317 "variant", G_TYPE_STRING, "vivo", NULL);
318 if (codec_name)
319 *codec_name = g_strdup ("Vivo H.263");
320 break;
321
322 case GST_RIFF_x263:
323 caps = gst_caps_new_simple ("video/x-h263",
324 "variant", G_TYPE_STRING, "xirlink", NULL);
325 if (codec_name)
326 *codec_name = g_strdup ("Xirlink H.263");
327 break;
328
329 /* apparently not standard H.263...? */
330 case GST_MAKE_FOURCC ('I', '2', '6', '3'):
331 caps = gst_caps_new_simple ("video/x-intel-h263",
332 "variant", G_TYPE_STRING, "intel", NULL);
333 if (codec_name)
334 *codec_name = g_strdup ("Intel H.263");
335 break;
336
337 case GST_MAKE_FOURCC ('V', 'X', '1', 'K'):
338 caps = gst_caps_new_simple ("video/x-h263",
339 "variant", G_TYPE_STRING, "lucent", NULL);
340 if (codec_name)
341 *codec_name = g_strdup ("Lucent VX1000S H.263");
342 break;
343
344 case GST_MAKE_FOURCC ('X', '2', '6', '4'):
345 case GST_MAKE_FOURCC ('x', '2', '6', '4'):
346 case GST_MAKE_FOURCC ('H', '2', '6', '4'):
347 case GST_MAKE_FOURCC ('h', '2', '6', '4'):
348 case GST_MAKE_FOURCC ('a', 'v', 'c', '1'):
349 case GST_MAKE_FOURCC ('A', 'V', 'C', '1'):
350 caps = gst_caps_new_simple ("video/x-h264",
351 "variant", G_TYPE_STRING, "itu", NULL);
352 if (codec_name)
353 *codec_name = g_strdup ("ITU H.264");
354 break;
355
356 case GST_MAKE_FOURCC ('X', '2', '6', '5'):
357 case GST_MAKE_FOURCC ('x', '2', '6', '5'):
358 case GST_MAKE_FOURCC ('H', '2', '6', '5'):
359 case GST_MAKE_FOURCC ('h', '2', '6', '5'):
360 case GST_MAKE_FOURCC ('h', 'v', 'c', '1'):
361 case GST_MAKE_FOURCC ('H', 'V', 'C', '1'):
362 caps = gst_caps_new_empty_simple ("video/x-h265");
363 if (codec_name)
364 *codec_name = g_strdup ("H.265");
365 break;
366
367 case GST_RIFF_VSSH:
368 caps = gst_caps_new_simple ("video/x-h264",
369 "variant", G_TYPE_STRING, "videosoft", NULL);
370 if (codec_name)
371 *codec_name = g_strdup ("VideoSoft H.264");
372 break;
373
374 case GST_MAKE_FOURCC ('L', '2', '6', '4'):
375 /* http://www.leadcodecs.com/Codecs/LEAD-H264.htm */
376 caps = gst_caps_new_simple ("video/x-h264",
377 "variant", G_TYPE_STRING, "lead", NULL);
378 if (codec_name)
379 *codec_name = g_strdup ("Lead H.264");
380 break;
381
382 case GST_MAKE_FOURCC ('S', 'E', 'D', 'G'):
383 caps = gst_caps_new_simple ("video/mpeg",
384 "mpegversion", G_TYPE_INT, 4,
385 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
386 if (codec_name)
387 *codec_name = g_strdup ("Samsung MPEG-4");
388 break;
389
390 case GST_MAKE_FOURCC ('M', '4', 'C', 'C'):
391 caps = gst_caps_new_simple ("video/mpeg",
392 "mpegversion", G_TYPE_INT, 4,
393 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
394 if (codec_name)
395 *codec_name = g_strdup ("Divio MPEG-4");
396 break;
397
398 case GST_RIFF_DIV3:
399 case GST_MAKE_FOURCC ('d', 'i', 'v', '3'):
400 case GST_MAKE_FOURCC ('D', 'V', 'X', '3'):
401 case GST_MAKE_FOURCC ('d', 'v', 'x', '3'):
402 case GST_MAKE_FOURCC ('D', 'I', 'V', '4'):
403 case GST_MAKE_FOURCC ('d', 'i', 'v', '4'):
404 case GST_MAKE_FOURCC ('D', 'I', 'V', '5'):
405 case GST_MAKE_FOURCC ('d', 'i', 'v', '5'):
406 case GST_MAKE_FOURCC ('D', 'I', 'V', '6'):
407 case GST_MAKE_FOURCC ('d', 'i', 'v', '6'):
408 case GST_MAKE_FOURCC ('M', 'P', 'G', '3'):
409 case GST_MAKE_FOURCC ('m', 'p', 'g', '3'):
410 case GST_MAKE_FOURCC ('c', 'o', 'l', '0'):
411 case GST_MAKE_FOURCC ('C', 'O', 'L', '0'):
412 case GST_MAKE_FOURCC ('c', 'o', 'l', '1'):
413 case GST_MAKE_FOURCC ('C', 'O', 'L', '1'):
414 case GST_MAKE_FOURCC ('A', 'P', '4', '1'):
415 caps = gst_caps_new_simple ("video/x-divx",
416 "divxversion", G_TYPE_INT, 3, NULL);
417 if (codec_name)
418 *codec_name = g_strdup ("DivX MS-MPEG-4 Version 3");
419 break;
420
421 case GST_MAKE_FOURCC ('d', 'i', 'v', 'x'):
422 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
423 caps = gst_caps_new_simple ("video/x-divx",
424 "divxversion", G_TYPE_INT, 4, NULL);
425 if (codec_name)
426 *codec_name = g_strdup ("DivX MPEG-4 Version 4");
427 break;
428
429 case GST_MAKE_FOURCC ('B', 'L', 'Z', '0'):
430 caps = gst_caps_new_simple ("video/x-divx",
431 "divxversion", G_TYPE_INT, 4, NULL);
432 if (codec_name)
433 *codec_name = g_strdup ("Blizzard DivX");
434 break;
435
436 case GST_MAKE_FOURCC ('D', 'X', '5', '0'):
437 caps = gst_caps_new_simple ("video/x-divx",
438 "divxversion", G_TYPE_INT, 5, NULL);
439 if (codec_name)
440 *codec_name = g_strdup ("DivX MPEG-4 Version 5");
441 break;
442
443 case GST_MAKE_FOURCC ('M', 'P', 'G', '4'):
444 case GST_MAKE_FOURCC ('M', 'P', '4', '1'):
445 case GST_MAKE_FOURCC ('m', 'p', '4', '1'):
446 caps = gst_caps_new_simple ("video/x-msmpeg",
447 "msmpegversion", G_TYPE_INT, 41, NULL);
448 if (codec_name)
449 *codec_name = g_strdup ("Microsoft MPEG-4 4.1");
450 break;
451
452 case GST_MAKE_FOURCC ('m', 'p', '4', '2'):
453 case GST_MAKE_FOURCC ('M', 'P', '4', '2'):
454 caps = gst_caps_new_simple ("video/x-msmpeg",
455 "msmpegversion", G_TYPE_INT, 42, NULL);
456 if (codec_name)
457 *codec_name = g_strdup ("Microsoft MPEG-4 4.2");
458 break;
459
460 case GST_MAKE_FOURCC ('m', 'p', '4', '3'):
461 case GST_MAKE_FOURCC ('M', 'P', '4', '3'):
462 caps = gst_caps_new_simple ("video/x-msmpeg",
463 "msmpegversion", G_TYPE_INT, 43, NULL);
464 if (codec_name)
465 *codec_name = g_strdup ("Microsoft MPEG-4 4.3");
466 break;
467
468 case GST_MAKE_FOURCC ('M', 'P', '4', 'S'):
469 case GST_MAKE_FOURCC ('M', '4', 'S', '2'):
470 caps = gst_caps_new_simple ("video/mpeg",
471 "mpegversion", G_TYPE_INT, 4,
472 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
473 if (codec_name)
474 *codec_name = g_strdup ("Microsoft ISO MPEG-4 1.1");
475 break;
476
477 case GST_MAKE_FOURCC ('F', 'M', 'P', '4'):
478 case GST_MAKE_FOURCC ('U', 'M', 'P', '4'):
479 case GST_MAKE_FOURCC ('F', 'F', 'D', 'S'):
480 caps = gst_caps_new_simple ("video/mpeg",
481 "mpegversion", G_TYPE_INT, 4,
482 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
483 if (codec_name)
484 *codec_name = g_strdup ("FFmpeg MPEG-4");
485 break;
486
487 case GST_MAKE_FOURCC ('3', 'I', 'V', '1'):
488 case GST_MAKE_FOURCC ('3', 'I', 'V', '2'):
489 case GST_MAKE_FOURCC ('X', 'V', 'I', 'D'):
490 case GST_MAKE_FOURCC ('x', 'v', 'i', 'd'):
491 case GST_MAKE_FOURCC ('E', 'M', '4', 'A'):
492 case GST_MAKE_FOURCC ('E', 'P', 'V', 'H'):
493 case GST_MAKE_FOURCC ('F', 'V', 'F', 'W'):
494 case GST_MAKE_FOURCC ('I', 'N', 'M', 'C'):
495 case GST_MAKE_FOURCC ('D', 'I', 'G', 'I'):
496 case GST_MAKE_FOURCC ('D', 'M', '2', 'K'):
497 case GST_MAKE_FOURCC ('D', 'C', 'O', 'D'):
498 case GST_MAKE_FOURCC ('M', 'V', 'X', 'M'):
499 case GST_MAKE_FOURCC ('P', 'M', '4', 'V'):
500 case GST_MAKE_FOURCC ('S', 'M', 'P', '4'):
501 case GST_MAKE_FOURCC ('D', 'X', 'G', 'M'):
502 case GST_MAKE_FOURCC ('V', 'I', 'D', 'M'):
503 case GST_MAKE_FOURCC ('M', '4', 'T', '3'):
504 case GST_MAKE_FOURCC ('G', 'E', 'O', 'X'):
505 case GST_MAKE_FOURCC ('M', 'P', '4', 'V'):
506 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
507 case GST_MAKE_FOURCC ('R', 'M', 'P', '4'):
508 caps = gst_caps_new_simple ("video/mpeg",
509 "mpegversion", G_TYPE_INT, 4,
510 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
511 if (codec_name)
512 *codec_name = g_strdup ("MPEG-4");
513 break;
514
515 case GST_MAKE_FOURCC ('3', 'i', 'v', 'd'):
516 case GST_MAKE_FOURCC ('3', 'I', 'V', 'D'):
517 caps = gst_caps_new_simple ("video/x-msmpeg",
518 "msmpegversion", G_TYPE_INT, 43, NULL);
519 if (codec_name)
520 *codec_name = g_strdup ("Microsoft MPEG-4 4.3"); /* FIXME? */
521 break;
522
523 case GST_MAKE_FOURCC ('C', 'F', 'H', 'D'):
524 caps = gst_caps_new_empty_simple ("video/x-cineform");
525 if (codec_name)
526 *codec_name = g_strdup ("CineForm");
527 break;
528
529 case GST_MAKE_FOURCC ('D', 'V', 'S', 'D'):
530 case GST_MAKE_FOURCC ('d', 'v', 's', 'd'):
531 case GST_MAKE_FOURCC ('d', 'v', 'c', ' '):
532 case GST_MAKE_FOURCC ('d', 'v', '2', '5'):
533 caps = gst_caps_new_simple ("video/x-dv",
534 "systemstream", G_TYPE_BOOLEAN, FALSE,
535 "dvversion", G_TYPE_INT, 25, NULL);
536 if (codec_name)
537 *codec_name = g_strdup ("Generic DV");
538 break;
539
540 case GST_MAKE_FOURCC ('C', 'D', 'V', 'C'):
541 case GST_MAKE_FOURCC ('c', 'd', 'v', 'c'):
542 caps = gst_caps_new_simple ("video/x-dv",
543 "systemstream", G_TYPE_BOOLEAN, FALSE,
544 "dvversion", G_TYPE_INT, 25, NULL);
545 if (codec_name)
546 *codec_name = g_strdup ("Canopus DV");
547 break;
548
549 case GST_MAKE_FOURCC ('D', 'V', '5', '0'):
550 case GST_MAKE_FOURCC ('d', 'v', '5', '0'):
551 caps = gst_caps_new_simple ("video/x-dv",
552 "systemstream", G_TYPE_BOOLEAN, FALSE,
553 "dvversion", G_TYPE_INT, 50, NULL);
554 if (codec_name)
555 *codec_name = g_strdup ("DVCPro50 Video");
556 break;
557
558 case GST_MAKE_FOURCC ('M', 'S', 'S', '1'):
559 caps = gst_caps_new_simple ("video/x-wmv",
560 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
561 if (codec_name)
562 *codec_name = g_strdup ("Microsoft Windows Media 7 Screen");
563 break;
564
565 case GST_MAKE_FOURCC ('M', 'S', 'S', '2'):
566 caps = gst_caps_new_simple ("video/x-wmv",
567 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
568 if (codec_name)
569 *codec_name = g_strdup ("Microsoft Windows Media 9 Screen");
570 break;
571
572 case GST_MAKE_FOURCC ('W', 'M', 'V', '1'):
573 caps = gst_caps_new_simple ("video/x-wmv",
574 "wmvversion", G_TYPE_INT, 1, NULL);
575 if (codec_name)
576 *codec_name = g_strdup ("Microsoft Windows Media 7");
577 break;
578
579 case GST_MAKE_FOURCC ('W', 'M', 'V', '2'):
580 caps = gst_caps_new_simple ("video/x-wmv",
581 "wmvversion", G_TYPE_INT, 2, NULL);
582 if (codec_name)
583 *codec_name = g_strdup ("Microsoft Windows Media 8");
584 break;
585
586 case GST_MAKE_FOURCC ('W', 'M', 'V', '3'):
587 caps = gst_caps_new_simple ("video/x-wmv",
588 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
589 if (codec_name)
590 *codec_name = g_strdup ("Microsoft Windows Media 9");
591 break;
592
593 case GST_MAKE_FOURCC ('W', 'M', 'V', 'A'):
594 caps = gst_caps_new_simple ("video/x-wmv",
595 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMVA", NULL);
596 if (codec_name)
597 *codec_name = g_strdup ("Microsoft Windows Media Advanced Profile");
598 break;
599
600 case GST_MAKE_FOURCC ('W', 'V', 'C', '1'):
601 caps = gst_caps_new_simple ("video/x-wmv",
602 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
603 if (codec_name)
604 *codec_name = g_strdup ("Microsoft Windows Media VC-1");
605 break;
606
607 case GST_RIFF_cvid:
608 case GST_RIFF_CVID:
609 caps = gst_caps_new_empty_simple ("video/x-cinepak");
610 if (codec_name)
611 *codec_name = g_strdup ("Cinepak video");
612 break;
613
614 case GST_RIFF_FCCH_MSVC:
615 case GST_RIFF_FCCH_msvc:
616 case GST_RIFF_CRAM:
617 case GST_RIFF_cram:
618 case GST_RIFF_WHAM:
619 case GST_RIFF_wham:
620 caps = gst_caps_new_simple ("video/x-msvideocodec",
621 "msvideoversion", G_TYPE_INT, 1, NULL);
622 if (strf) {
623 gst_caps_set_simple (caps, "bpp",
624 G_TYPE_INT, (int) strf->bit_cnt, NULL);
625 }
626 if (codec_name)
627 *codec_name = g_strdup ("MS video v1");
628 palette = strf_data;
629 strf_data = NULL;
630 break;
631
632 case GST_RIFF_FCCH_RLE:
633 case GST_MAKE_FOURCC ('m', 'r', 'l', 'e'):
634 case GST_MAKE_FOURCC (0x1, 0x0, 0x0, 0x0): /* why, why, why? */
635 case GST_MAKE_FOURCC (0x2, 0x0, 0x0, 0x0): /* why, why, why? */
636 caps = gst_caps_new_simple ("video/x-rle",
637 "layout", G_TYPE_STRING, "microsoft", NULL);
638 palette = strf_data;
639 strf_data = NULL;
640 if (strf) {
641 gst_caps_set_simple (caps,
642 "depth", G_TYPE_INT, (gint) strf->bit_cnt, NULL);
643 } else {
644 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
645 }
646 if (codec_name)
647 *codec_name = g_strdup ("Microsoft RLE");
648 break;
649
650 case GST_MAKE_FOURCC ('A', 'A', 'S', 'C'):
651 caps = gst_caps_new_empty_simple ("video/x-aasc");
652 if (codec_name)
653 *codec_name = g_strdup ("Autodesk Animator");
654 break;
655
656 case GST_MAKE_FOURCC ('X', 'x', 'a', 'n'):
657 caps = gst_caps_new_simple ("video/x-xan",
658 "wcversion", G_TYPE_INT, 4, NULL);
659 if (codec_name)
660 *codec_name = g_strdup ("Xan Wing Commander 4");
661 break;
662
663 case GST_RIFF_RT21:
664 case GST_RIFF_rt21:
665 caps = gst_caps_new_simple ("video/x-indeo",
666 "indeoversion", G_TYPE_INT, 2, NULL);
667 if (codec_name)
668 *codec_name = g_strdup ("Intel Video 2");
669 break;
670
671 case GST_RIFF_IV31:
672 case GST_RIFF_IV32:
673 case GST_RIFF_iv31:
674 case GST_RIFF_iv32:
675 caps = gst_caps_new_simple ("video/x-indeo",
676 "indeoversion", G_TYPE_INT, 3, NULL);
677 if (codec_name)
678 *codec_name = g_strdup ("Intel Video 3");
679 break;
680
681 case GST_RIFF_IV41:
682 case GST_RIFF_iv41:
683 caps = gst_caps_new_simple ("video/x-indeo",
684 "indeoversion", G_TYPE_INT, 4, NULL);
685 if (codec_name)
686 *codec_name = g_strdup ("Intel Video 4");
687 break;
688
689 case GST_RIFF_IV50:
690 caps = gst_caps_new_simple ("video/x-indeo",
691 "indeoversion", G_TYPE_INT, 5, NULL);
692 if (codec_name)
693 *codec_name = g_strdup ("Intel Video 5");
694 break;
695
696 case GST_MAKE_FOURCC ('M', 'S', 'Z', 'H'):
697 caps = gst_caps_new_empty_simple ("video/x-mszh");
698 if (codec_name)
699 *codec_name = g_strdup ("Lossless MSZH Video");
700 break;
701
702 case GST_MAKE_FOURCC ('Z', 'L', 'I', 'B'):
703 caps = gst_caps_new_empty_simple ("video/x-zlib");
704 if (codec_name)
705 *codec_name = g_strdup ("Lossless zlib video");
706 break;
707
708 case GST_MAKE_FOURCC ('C', 'L', 'J', 'R'):
709 case GST_MAKE_FOURCC ('c', 'l', 'j', 'r'):
710 caps = gst_caps_new_empty_simple ("video/x-cirrus-logic-accupak");
711 if (codec_name)
712 *codec_name = g_strdup ("Cirrus Logipak AccuPak");
713 break;
714
715 case GST_RIFF_CYUV:
716 case GST_RIFF_cyuv:
717 caps = gst_caps_new_empty_simple ("video/x-compressed-yuv");
718 if (codec_name)
719 *codec_name = g_strdup ("CYUV Lossless");
720 break;
721
722 case GST_MAKE_FOURCC ('D', 'U', 'C', 'K'):
723 case GST_MAKE_FOURCC ('P', 'V', 'E', 'Z'):
724 caps = gst_caps_new_simple ("video/x-truemotion",
725 "trueversion", G_TYPE_INT, 1, NULL);
726 if (codec_name)
727 *codec_name = g_strdup ("Duck Truemotion1");
728 break;
729
730 case GST_MAKE_FOURCC ('T', 'M', '2', '0'):
731 caps = gst_caps_new_simple ("video/x-truemotion",
732 "trueversion", G_TYPE_INT, 2, NULL);
733 if (codec_name)
734 *codec_name = g_strdup ("TrueMotion 2.0");
735 break;
736
737 case GST_MAKE_FOURCC ('V', 'P', '3', '0'):
738 case GST_MAKE_FOURCC ('v', 'p', '3', '0'):
739 case GST_MAKE_FOURCC ('V', 'P', '3', '1'):
740 case GST_MAKE_FOURCC ('v', 'p', '3', '1'):
741 case GST_MAKE_FOURCC ('V', 'P', '3', ' '):
742 caps = gst_caps_new_empty_simple ("video/x-vp3");
743 if (codec_name)
744 *codec_name = g_strdup ("VP3");
745 break;
746
747 case GST_RIFF_ULTI:
748 case GST_RIFF_ulti:
749 caps = gst_caps_new_empty_simple ("video/x-ultimotion");
750 if (codec_name)
751 *codec_name = g_strdup ("IBM UltiMotion");
752 break;
753
754 /* FIXME 2.0: Rename video/x-camtasia to video/x-tscc,version=1 */
755 case GST_MAKE_FOURCC ('T', 'S', 'C', 'C'):
756 case GST_MAKE_FOURCC ('t', 's', 'c', 'c'):{
757 if (strf) {
758 gint depth = (strf->bit_cnt != 0) ? (gint) strf->bit_cnt : 24;
759
760 caps = gst_caps_new_simple ("video/x-camtasia", "depth", G_TYPE_INT,
761 depth, NULL);
762 } else {
763 /* template caps */
764 caps = gst_caps_new_empty_simple ("video/x-camtasia");
765 }
766 if (codec_name)
767 *codec_name = g_strdup ("TechSmith Camtasia");
768 break;
769 }
770
771 case GST_MAKE_FOURCC ('T', 'S', 'C', '2'):
772 case GST_MAKE_FOURCC ('t', 's', 'c', '2'):{
773 caps =
774 gst_caps_new_simple ("video/x-tscc", "tsccversion", G_TYPE_INT, 2,
775 NULL);
776 if (codec_name)
777 *codec_name = g_strdup ("TechSmith Screen Capture 2");
778 break;
779 }
780
781 case GST_MAKE_FOURCC ('C', 'S', 'C', 'D'):
782 {
783 if (strf) {
784 gint depth = (strf->bit_cnt != 0) ? (gint) strf->bit_cnt : 24;
785
786 caps = gst_caps_new_simple ("video/x-camstudio", "depth", G_TYPE_INT,
787 depth, NULL);
788 } else {
789 /* template caps */
790 caps = gst_caps_new_empty_simple ("video/x-camstudio");
791 }
792 if (codec_name)
793 *codec_name = g_strdup ("Camstudio");
794 break;
795 }
796
797 case GST_MAKE_FOURCC ('V', 'C', 'R', '1'):
798 caps = gst_caps_new_simple ("video/x-ati-vcr",
799 "vcrversion", G_TYPE_INT, 1, NULL);
800 if (codec_name)
801 *codec_name = g_strdup ("ATI VCR 1");
802 break;
803
804 case GST_MAKE_FOURCC ('V', 'C', 'R', '2'):
805 caps = gst_caps_new_simple ("video/x-ati-vcr",
806 "vcrversion", G_TYPE_INT, 2, NULL);
807 if (codec_name)
808 *codec_name = g_strdup ("ATI VCR 2");
809 break;
810
811 case GST_MAKE_FOURCC ('A', 'S', 'V', '1'):
812 caps = gst_caps_new_simple ("video/x-asus",
813 "asusversion", G_TYPE_INT, 1, NULL);
814 if (codec_name)
815 *codec_name = g_strdup ("Asus Video 1");
816 break;
817
818 case GST_MAKE_FOURCC ('A', 'S', 'V', '2'):
819 caps = gst_caps_new_simple ("video/x-asus",
820 "asusversion", G_TYPE_INT, 2, NULL);
821 if (codec_name)
822 *codec_name = g_strdup ("Asus Video 2");
823 break;
824
825 case GST_MAKE_FOURCC ('M', 'P', 'N', 'G'):
826 case GST_MAKE_FOURCC ('m', 'p', 'n', 'g'):
827 case GST_MAKE_FOURCC ('P', 'N', 'G', ' '):
828 case GST_MAKE_FOURCC ('p', 'n', 'g', ' '):
829 caps = gst_caps_new_empty_simple ("image/png");
830 if (codec_name)
831 *codec_name = g_strdup ("PNG image");
832 break;
833
834 case GST_MAKE_FOURCC ('F', 'L', 'V', '1'):
835 caps = gst_caps_new_simple ("video/x-flash-video",
836 "flvversion", G_TYPE_INT, 1, NULL);
837 if (codec_name)
838 *codec_name = g_strdup ("Flash Video 1");
839 break;
840
841 case GST_MAKE_FOURCC ('V', 'M', 'n', 'c'):
842 caps = gst_caps_new_simple ("video/x-vmnc",
843 "version", G_TYPE_INT, 1, NULL);
844 if (strf && strf->bit_cnt != 0)
845 gst_caps_set_simple (caps, "bpp", G_TYPE_INT, strf->bit_cnt, NULL);
846 if (codec_name)
847 *codec_name = g_strdup ("VMWare NC Video");
848 break;
849
850 case GST_MAKE_FOURCC ('d', 'r', 'a', 'c'):
851 caps = gst_caps_new_empty_simple ("video/x-dirac");
852 if (codec_name)
853 *codec_name = g_strdup ("Dirac");
854 break;
855
856 case GST_RIFF_rpza:
857 case GST_RIFF_azpr:
858 case GST_MAKE_FOURCC ('R', 'P', 'Z', 'A'):
859 caps = gst_caps_new_empty_simple ("video/x-apple-video");
860 if (codec_name)
861 *codec_name = g_strdup ("Apple Video (RPZA)");
862 break;
863
864
865 case GST_MAKE_FOURCC ('F', 'F', 'V', '1'):
866 caps = gst_caps_new_simple ("video/x-ffv",
867 "ffvversion", G_TYPE_INT, 1, NULL);
868 if (codec_name)
869 *codec_name = g_strdup ("FFmpeg lossless video codec");
870 break;
871
872 case GST_MAKE_FOURCC ('K', 'M', 'V', 'C'):
873 caps = gst_caps_new_empty_simple ("video/x-kmvc");
874 if (codec_name)
875 *codec_name = g_strdup ("Karl Morton's video codec");
876 break;
877
878 case GST_MAKE_FOURCC ('v', 'p', '5', '0'):
879 case GST_MAKE_FOURCC ('V', 'P', '5', '0'):
880 caps = gst_caps_new_empty_simple ("video/x-vp5");
881 if (codec_name)
882 *codec_name = g_strdup ("On2 VP5");
883 break;
884
885 case GST_MAKE_FOURCC ('v', 'p', '6', '0'):
886 case GST_MAKE_FOURCC ('V', 'P', '6', '0'):
887 case GST_MAKE_FOURCC ('v', 'p', '6', '1'):
888 case GST_MAKE_FOURCC ('V', 'P', '6', '1'):
889 case GST_MAKE_FOURCC ('V', 'p', '6', '2'):
890 case GST_MAKE_FOURCC ('V', 'P', '6', '2'):
891 caps = gst_caps_new_empty_simple ("video/x-vp6");
892 if (codec_name)
893 *codec_name = g_strdup ("On2 VP6");
894 break;
895
896 case GST_MAKE_FOURCC ('V', 'P', '6', 'F'):
897 case GST_MAKE_FOURCC ('v', 'p', '6', 'f'):
898 case GST_MAKE_FOURCC ('F', 'L', 'V', '4'):
899 caps = gst_caps_new_empty_simple ("video/x-vp6-flash");
900 if (codec_name)
901 *codec_name = g_strdup ("On2 VP6");
902 break;
903
904 case GST_MAKE_FOURCC ('v', 'p', '7', '0'):
905 case GST_MAKE_FOURCC ('V', 'P', '7', '0'):
906 caps = gst_caps_new_empty_simple ("video/x-vp7");
907 if (codec_name)
908 *codec_name = g_strdup ("On2 VP7");
909 break;
910
911 case GST_MAKE_FOURCC ('V', 'P', '8', '0'):
912 caps = gst_caps_new_empty_simple ("video/x-vp8");
913 if (codec_name)
914 *codec_name = g_strdup ("On2 VP8");
915 break;
916
917 case GST_MAKE_FOURCC ('L', 'M', '2', '0'):
918 caps = gst_caps_new_empty_simple ("video/x-mimic");
919 if (codec_name)
920 *codec_name = g_strdup ("Mimic webcam");
921 break;
922
923 case GST_MAKE_FOURCC ('T', 'H', 'E', 'O'):
924 case GST_MAKE_FOURCC ('t', 'h', 'e', 'o'):
925 caps = gst_caps_new_empty_simple ("video/x-theora");
926 if (codec_name)
927 *codec_name = g_strdup ("Theora video codec");
928
929 break;
930
931 case GST_MAKE_FOURCC ('F', 'P', 'S', '1'):
932 caps = gst_caps_new_empty_simple ("video/x-fraps");
933 if (codec_name)
934 *codec_name = g_strdup ("Fraps video");
935
936 break;
937
938 case GST_MAKE_FOURCC ('D', 'X', 'S', 'B'):
939 case GST_MAKE_FOURCC ('D', 'X', 'S', 'A'):
940 caps = gst_caps_new_empty_simple ("subpicture/x-xsub");
941 if (codec_name)
942 *codec_name = g_strdup ("XSUB subpicture stream");
943
944 break;
945
946 default:
947 GST_WARNING ("Unknown video fourcc %" GST_FOURCC_FORMAT,
948 GST_FOURCC_ARGS (codec_fcc));
949 return NULL;
950 }
951
952 if (strh != NULL) {
953 gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION,
954 strh->rate, strh->scale, NULL);
955 } else {
956 gst_caps_set_simple (caps,
957 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
958 }
959
960 if (strf != NULL) {
961 /* raw rgb data is stored topdown, but instead of inverting the buffer, */
962 /* some tools just negate the height field in the header (e.g. ffmpeg) */
963 gst_caps_set_simple (caps,
964 "width", G_TYPE_INT, strf->width,
965 "height", G_TYPE_INT, ABS ((gint) strf->height), NULL);
966 } else {
967 gst_caps_set_simple (caps,
968 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
969 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
970 }
971
972 /* extradata */
973 if (strf_data || strd_data) {
974 GstBuffer *codec_data;
975
976 codec_data = strf_data ? strf_data : strd_data;
977
978 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, codec_data, NULL);
979 }
980
981 /* palette */
982 if (palette) {
983 GstBuffer *copy;
984 guint num_colors;
985 gsize size;
986
987 if (strf != NULL)
988 num_colors = strf->num_colors;
989 else
990 num_colors = 256;
991
992 size = gst_buffer_get_size (palette);
993
994 if (size >= (num_colors * 4)) {
995 guint8 *pdata;
996
997 /* palette is always at least 256*4 bytes */
998 pdata = g_malloc0 (MAX (size, 256 * 4));
999 gst_buffer_extract (palette, 0, pdata, size);
1000
1001 if (G_BYTE_ORDER == G_BIG_ENDIAN) {
1002 guint8 *p = pdata;
1003 gint n;
1004
1005 /* own endianness */
1006 for (n = 0; n < num_colors; n++) {
1007 GST_WRITE_UINT32_BE (p, GST_READ_UINT32_LE (p));
1008 p += sizeof (guint32);
1009 }
1010 }
1011
1012 copy = gst_buffer_new_wrapped (pdata, size);
1013 gst_caps_set_simple (caps, "palette_data", GST_TYPE_BUFFER, copy, NULL);
1014 gst_buffer_unref (copy);
1015 } else {
1016 GST_WARNING ("Palette smaller than expected: broken file");
1017 }
1018 }
1019
1020 return caps;
1021 }
1022
1023 static const struct
1024 {
1025 const guint32 ms_mask;
1026 const GstAudioChannelPosition gst_pos;
1027 } layout_mapping[] = {
1028 {
1029 0x00001, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
1030 0x00002, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
1031 0x00004, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
1032 0x00008, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
1033 0x00010, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
1034 0x00020, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
1035 0x00040, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
1036 0x00080, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
1037 0x00100, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
1038 0x00200, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
1039 0x00400, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
1040 0x00800, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
1041 0x01000, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
1042 0x02000, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
1043 0x04000, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
1044 0x08000, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
1045 0x10000, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
1046 0x20000, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}
1047 };
1048
1049 #define MAX_CHANNEL_POSITIONS G_N_ELEMENTS (layout_mapping)
1050
1051 static gboolean
gst_riff_wavext_add_channel_mask(GstCaps * caps,gint num_channels,guint32 layout,gint channel_reorder_map[18])1052 gst_riff_wavext_add_channel_mask (GstCaps * caps, gint num_channels,
1053 guint32 layout, gint channel_reorder_map[18])
1054 {
1055 gint i, p;
1056 guint64 channel_mask = 0;
1057 GstAudioChannelPosition *from, *to;
1058 gboolean ret = FALSE;
1059
1060 if (num_channels < 1) {
1061 GST_DEBUG ("invalid number of channels: %d", num_channels);
1062 return FALSE;
1063 }
1064
1065 from = g_new (GstAudioChannelPosition, num_channels);
1066 to = g_new (GstAudioChannelPosition, num_channels);
1067 p = 0;
1068 for (i = 0; i < MAX_CHANNEL_POSITIONS; ++i) {
1069 if ((layout & layout_mapping[i].ms_mask) != 0) {
1070 if (p >= num_channels) {
1071 GST_WARNING ("More bits set in the channel layout map than there "
1072 "are channels! Setting channel-mask to 0.");
1073 channel_mask = 0;
1074 break;
1075 }
1076 channel_mask |= G_GUINT64_CONSTANT (1) << layout_mapping[i].gst_pos;
1077 from[p] = layout_mapping[i].gst_pos;
1078 ++p;
1079 }
1080 }
1081
1082 if (channel_mask > 0 && channel_reorder_map) {
1083 if (p != num_channels) {
1084 /* WAVEFORMATEXTENSIBLE allows to have more channels than bits in
1085 * the channel mask. We accept this, too, and hope that downstream
1086 * can handle this */
1087 GST_WARNING ("Partially unknown positions in channel mask");
1088 for (; p < num_channels; ++p)
1089 from[p] = GST_AUDIO_CHANNEL_POSITION_INVALID;
1090 }
1091 memcpy (to, from, sizeof (from[0]) * num_channels);
1092 if (!gst_audio_channel_positions_to_valid_order (to, num_channels))
1093 goto fail;
1094 if (!gst_audio_get_channel_reorder_map (num_channels, from, to,
1095 channel_reorder_map))
1096 goto fail;
1097 }
1098
1099 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, channel_mask,
1100 NULL);
1101
1102 ret = TRUE;
1103
1104 fail:
1105 g_free (from);
1106 g_free (to);
1107
1108 return ret;
1109 }
1110
1111 static gboolean
gst_riff_wave_add_default_channel_mask(GstCaps * caps,gint nchannels,gint channel_reorder_map[18])1112 gst_riff_wave_add_default_channel_mask (GstCaps * caps,
1113 gint nchannels, gint channel_reorder_map[18])
1114 {
1115 guint64 channel_mask = 0;
1116 static const gint reorder_maps[8][11] = {
1117 {0,},
1118 {0, 1},
1119 {-1, -1, -1},
1120 {0, 1, 2, 3},
1121 {0, 1, 3, 4, 2},
1122 {0, 1, 4, 5, 2, 3},
1123 {-1, -1, -1, -1, -1, -1, -1},
1124 {0, 1, 4, 5, 2, 3, 6, 7}
1125 };
1126
1127 if (nchannels > 8) {
1128 GST_DEBUG ("invalid number of channels: %d", nchannels);
1129 return FALSE;
1130 }
1131
1132 /* This uses the default channel mapping from ALSA which
1133 * is used in quite a few surround test files and seems to be
1134 * the defacto standard. The channel mapping from
1135 * WAVE_FORMAT_EXTENSIBLE doesn't seem to be used in normal
1136 * wav files like chan-id.wav.
1137 * http://bugzilla.gnome.org/show_bug.cgi?id=489010
1138 */
1139 switch (nchannels) {
1140 case 1:
1141 /* Mono => nothing */
1142 if (channel_reorder_map)
1143 channel_reorder_map[0] = 0;
1144 return TRUE;
1145 case 8:
1146 channel_mask |=
1147 G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT;
1148 channel_mask |=
1149 G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT;
1150 /* fall through */
1151 case 6:
1152 channel_mask |= G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_LFE1;
1153 /* fall through */
1154 case 5:
1155 channel_mask |=
1156 G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER;
1157 /* fall through */
1158 case 4:
1159 channel_mask |=
1160 G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT;
1161 channel_mask |=
1162 G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_REAR_LEFT;
1163 /* fall through */
1164 case 2:
1165 channel_mask |=
1166 G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
1167 channel_mask |=
1168 G_GUINT64_CONSTANT (1) << GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
1169 break;
1170 default:
1171 return FALSE;
1172 }
1173
1174 if (channel_reorder_map)
1175 memcpy (channel_reorder_map, reorder_maps[nchannels - 1],
1176 sizeof (gint) * nchannels);
1177
1178 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, channel_mask,
1179 NULL);
1180
1181 return TRUE;
1182 }
1183
1184 static guint32
gst_riff_wavext_get_default_channel_mask(guint nchannels)1185 gst_riff_wavext_get_default_channel_mask (guint nchannels)
1186 {
1187 guint32 channel_mask = 0;
1188
1189 /* Set the default channel mask for the given number of channels.
1190 * http://www.microsoft.com/whdc/device/audio/multichaud.mspx
1191 */
1192 switch (nchannels) {
1193 case 11:
1194 channel_mask |= 0x00400;
1195 channel_mask |= 0x00200;
1196 case 9:
1197 channel_mask |= 0x00100;
1198 case 8:
1199 channel_mask |= 0x00080;
1200 channel_mask |= 0x00040;
1201 case 6:
1202 channel_mask |= 0x00020;
1203 channel_mask |= 0x00010;
1204 case 4:
1205 channel_mask |= 0x00008;
1206 case 3:
1207 channel_mask |= 0x00004;
1208 case 2:
1209 channel_mask |= 0x00002;
1210 channel_mask |= 0x00001;
1211 break;
1212 }
1213
1214 return channel_mask;
1215 }
1216
1217 GstCaps *
gst_riff_create_audio_caps(guint16 codec_id,gst_riff_strh * strh,gst_riff_strf_auds * strf,GstBuffer * strf_data,GstBuffer * strd_data,char ** codec_name,gint channel_reorder_map[18])1218 gst_riff_create_audio_caps (guint16 codec_id,
1219 gst_riff_strh * strh, gst_riff_strf_auds * strf,
1220 GstBuffer * strf_data, GstBuffer * strd_data, char **codec_name,
1221 gint channel_reorder_map[18])
1222 {
1223 gboolean block_align = FALSE, rate_chan = TRUE;
1224 GstCaps *caps = NULL;
1225 gint i;
1226
1227 if (channel_reorder_map)
1228 for (i = 0; i < 18; i++)
1229 channel_reorder_map[i] = -1;
1230
1231 switch (codec_id) {
1232 case GST_RIFF_WAVE_FORMAT_PCM: /* PCM */
1233 if (strf != NULL) {
1234 gint ba = strf->blockalign;
1235 gint ch = strf->channels;
1236 gint wd, ws;
1237 GstAudioFormat format;
1238
1239 if (ba > (32 / 8) * ch) {
1240 GST_WARNING ("Invalid block align: %d > %d", ba, (32 / 8) * ch);
1241 wd = GST_ROUND_UP_8 (strf->bits_per_sample);
1242 } else if (ba != 0) {
1243 /* If we have an empty blockalign, we take the width contained in
1244 * strf->bits_per_sample */
1245 wd = ba * 8 / ch;
1246 } else {
1247 wd = GST_ROUND_UP_8 (strf->bits_per_sample);
1248 }
1249
1250 if (strf->bits_per_sample > 32) {
1251 GST_WARNING ("invalid depth (%d) of pcm audio, overwriting.",
1252 strf->bits_per_sample);
1253 strf->bits_per_sample = wd;
1254 }
1255
1256 /* in riff, the depth is stored in the size field but it just means that
1257 * the _least_ significant bits are cleared. We can therefore just play
1258 * the sample as if it had a depth == width */
1259 /* For reference, the actual depth is in strf->bits_per_sample */
1260 ws = wd;
1261
1262 format =
1263 gst_audio_format_build_integer (wd != 8, G_LITTLE_ENDIAN, wd, ws);
1264 if (format == GST_AUDIO_FORMAT_UNKNOWN) {
1265 GST_WARNING ("Unsupported raw audio format with width %d", wd);
1266 return NULL;
1267 }
1268
1269 caps = gst_caps_new_simple ("audio/x-raw",
1270 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1271 "layout", G_TYPE_STRING, "interleaved",
1272 "channels", G_TYPE_INT, ch, NULL);
1273
1274 /* Add default channel layout. We know no default layout for more than
1275 * 8 channels. */
1276 if (ch > 8)
1277 GST_WARNING ("don't know default layout for %d channels", ch);
1278 else if (gst_riff_wave_add_default_channel_mask (caps, ch,
1279 channel_reorder_map))
1280 GST_DEBUG ("using default channel layout for %d channels", ch);
1281 else
1282 GST_WARNING ("failed to add channel layout");
1283 } else {
1284 /* FIXME: this is pretty useless - we need fixed caps */
1285 caps = gst_caps_from_string ("audio/x-raw, "
1286 "format = (string) { S8, U8, S16LE, U16LE, S24LE, "
1287 "U24LE, S32LE, U32LE }, " "layout = (string) interleaved");
1288 }
1289 if (codec_name && strf)
1290 *codec_name = g_strdup_printf ("Uncompressed %d-bit PCM audio",
1291 strf->bits_per_sample);
1292 break;
1293
1294 case GST_RIFF_WAVE_FORMAT_ADPCM:
1295 if (strf != NULL) {
1296 /* Many encoding tools create a wrong bitrate information in the header,
1297 * so either we calculate the bitrate or mark it as invalid as this
1298 * would probably confuse timing */
1299 strf->av_bps = 0;
1300 if (strf->channels != 0 && strf->rate != 0 && strf->blockalign != 0) {
1301 int spb = ((strf->blockalign - strf->channels * 7) / 2) * 2;
1302 strf->av_bps =
1303 gst_util_uint64_scale_int (strf->rate, strf->blockalign, spb);
1304 GST_DEBUG ("fixing av_bps to calculated value %d of MS ADPCM",
1305 strf->av_bps);
1306 }
1307 }
1308 caps = gst_caps_new_simple ("audio/x-adpcm",
1309 "layout", G_TYPE_STRING, "microsoft", NULL);
1310 if (codec_name)
1311 *codec_name = g_strdup ("ADPCM audio");
1312 block_align = TRUE;
1313 break;
1314
1315 case GST_RIFF_WAVE_FORMAT_IEEE_FLOAT:
1316 if (strf != NULL) {
1317 gint ba = strf->blockalign;
1318 gint ch = strf->channels;
1319
1320 if (ba > 0 && ch > 0 && (ba == (64 / 8) * ch || ba == (32 / 8) * ch)) {
1321 gint wd = ba * 8 / ch;
1322
1323 caps = gst_caps_new_simple ("audio/x-raw",
1324 "format", G_TYPE_STRING, wd == 64 ? "F64LE" : "F32LE",
1325 "layout", G_TYPE_STRING, "interleaved",
1326 "channels", G_TYPE_INT, ch, NULL);
1327
1328 /* Add default channel layout. We know no default layout for more than
1329 * 8 channels. */
1330 if (ch > 8)
1331 GST_WARNING ("don't know default layout for %d channels", ch);
1332 else if (gst_riff_wave_add_default_channel_mask (caps, ch,
1333 channel_reorder_map))
1334 GST_DEBUG ("using default channel layout for %d channels", ch);
1335 else
1336 GST_WARNING ("failed to add channel layout");
1337 } else {
1338 GST_WARNING ("invalid block align %d or channel count %d", ba, ch);
1339 return NULL;
1340 }
1341 } else {
1342 /* FIXME: this is pretty useless - we need fixed caps */
1343 caps = gst_caps_from_string ("audio/x-raw, "
1344 "format = (string) { F32LE, F64LE }, "
1345 "layout = (string) interleaved");
1346 }
1347 if (codec_name && strf)
1348 *codec_name = g_strdup_printf ("Uncompressed %d-bit IEEE float audio",
1349 strf->bits_per_sample);
1350 break;
1351
1352 case GST_RIFF_WAVE_FORMAT_IBM_CVSD:
1353 goto unknown;
1354
1355 case GST_RIFF_WAVE_FORMAT_ALAW:
1356 if (strf != NULL) {
1357 if (strf->bits_per_sample != 8) {
1358 GST_WARNING ("invalid depth (%d) of alaw audio, overwriting.",
1359 strf->bits_per_sample);
1360 strf->bits_per_sample = 8;
1361 strf->blockalign = (strf->bits_per_sample * strf->channels) / 8;
1362 strf->av_bps = strf->blockalign * strf->rate;
1363 }
1364 if (strf->av_bps == 0 || strf->blockalign == 0) {
1365 GST_WARNING ("fixing av_bps (%d) and blockalign (%d) of alaw audio",
1366 strf->av_bps, strf->blockalign);
1367 strf->blockalign = (strf->bits_per_sample * strf->channels) / 8;
1368 strf->av_bps = strf->blockalign * strf->rate;
1369 }
1370 }
1371 caps = gst_caps_new_empty_simple ("audio/x-alaw");
1372 if (codec_name)
1373 *codec_name = g_strdup ("A-law audio");
1374 break;
1375
1376 case GST_RIFF_WAVE_FORMAT_WMS:
1377 caps = gst_caps_new_empty_simple ("audio/x-wms");
1378 if (strf != NULL) {
1379 gst_caps_set_simple (caps,
1380 "bitrate", G_TYPE_INT, strf->av_bps * 8,
1381 "width", G_TYPE_INT, strf->bits_per_sample,
1382 "depth", G_TYPE_INT, strf->bits_per_sample, NULL);
1383 } else {
1384 gst_caps_set_simple (caps,
1385 "bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
1386 }
1387 if (codec_name)
1388 *codec_name = g_strdup ("Windows Media Audio Speech");
1389 block_align = TRUE;
1390 break;
1391
1392 case GST_RIFF_WAVE_FORMAT_MULAW:
1393 if (strf != NULL) {
1394 if (strf->bits_per_sample != 8) {
1395 GST_WARNING ("invalid depth (%d) of mulaw audio, overwriting.",
1396 strf->bits_per_sample);
1397 strf->bits_per_sample = 8;
1398 strf->blockalign = (strf->bits_per_sample * strf->channels) / 8;
1399 strf->av_bps = strf->blockalign * strf->rate;
1400 }
1401 if (strf->av_bps == 0 || strf->blockalign == 0) {
1402 GST_WARNING ("fixing av_bps (%d) and blockalign (%d) of mulaw audio",
1403 strf->av_bps, strf->blockalign);
1404 strf->blockalign = (strf->bits_per_sample * strf->channels) / 8;
1405 strf->av_bps = strf->blockalign * strf->rate;
1406 }
1407 }
1408 caps = gst_caps_new_empty_simple ("audio/x-mulaw");
1409 if (codec_name)
1410 *codec_name = g_strdup ("Mu-law audio");
1411 break;
1412
1413 case GST_RIFF_WAVE_FORMAT_OKI_ADPCM:
1414 goto unknown;
1415
1416 case GST_RIFF_WAVE_FORMAT_DVI_ADPCM:
1417 if (strf != NULL) {
1418 /* Many encoding tools create a wrong bitrate information in the
1419 * header, so either we calculate the bitrate or mark it as invalid
1420 * as this would probably confuse timing */
1421 strf->av_bps = 0;
1422 if (strf->channels != 0 && strf->rate != 0 && strf->blockalign != 0) {
1423 int spb = ((strf->blockalign - strf->channels * 4) / 2) * 2;
1424 strf->av_bps =
1425 gst_util_uint64_scale_int (strf->rate, strf->blockalign, spb);
1426 GST_DEBUG ("fixing av_bps to calculated value %d of IMA DVI ADPCM",
1427 strf->av_bps);
1428 }
1429 }
1430 caps = gst_caps_new_simple ("audio/x-adpcm",
1431 "layout", G_TYPE_STRING, "dvi", NULL);
1432 if (codec_name)
1433 *codec_name = g_strdup ("DVI ADPCM audio");
1434 block_align = TRUE;
1435 break;
1436
1437 case GST_RIFF_WAVE_FORMAT_ADPCM_G722:
1438 caps = gst_caps_new_empty_simple ("audio/G722");
1439 if (codec_name)
1440 *codec_name = g_strdup ("G722 audio");
1441 break;
1442
1443 case GST_RIFF_WAVE_FORMAT_ITU_G726_ADPCM:
1444 if (strf != NULL) {
1445 gint bitrate;
1446 bitrate = 0;
1447 if (strf->av_bps == 2000 || strf->av_bps == 3000 || strf->av_bps == 4000
1448 || strf->av_bps == 5000) {
1449 strf->blockalign = strf->av_bps / 1000;
1450 bitrate = strf->av_bps * 8;
1451 } else if (strf->blockalign >= 2 && strf->blockalign <= 5) {
1452 bitrate = strf->blockalign * 8000;
1453 }
1454 if (bitrate > 0) {
1455 caps = gst_caps_new_simple ("audio/x-adpcm",
1456 "layout", G_TYPE_STRING, "g726", "bitrate", G_TYPE_INT, bitrate,
1457 NULL);
1458 } else {
1459 caps = gst_caps_new_simple ("audio/x-adpcm",
1460 "layout", G_TYPE_STRING, "g726", NULL);
1461 }
1462 } else {
1463 caps = gst_caps_new_simple ("audio/x-adpcm",
1464 "layout", G_TYPE_STRING, "g726", NULL);
1465 }
1466 if (codec_name)
1467 *codec_name = g_strdup ("G726 ADPCM audio");
1468 block_align = TRUE;
1469 break;
1470
1471 case GST_RIFF_WAVE_FORMAT_DSP_TRUESPEECH:
1472 caps = gst_caps_new_empty_simple ("audio/x-truespeech");
1473 if (codec_name)
1474 *codec_name = g_strdup ("DSP Group TrueSpeech");
1475 break;
1476
1477 case GST_RIFF_WAVE_FORMAT_GSM610:
1478 case GST_RIFF_WAVE_FORMAT_MSN:
1479 caps = gst_caps_new_empty_simple ("audio/ms-gsm");
1480 if (codec_name)
1481 *codec_name = g_strdup ("MS GSM audio");
1482 break;
1483
1484 case GST_RIFF_WAVE_FORMAT_MPEGL12: /* mp1 or mp2 */
1485 caps = gst_caps_new_simple ("audio/mpeg",
1486 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
1487 if (codec_name)
1488 *codec_name = g_strdup ("MPEG-1 layer 2");
1489 break;
1490
1491 case GST_RIFF_WAVE_FORMAT_MPEGL3: /* mp3 */
1492 caps = gst_caps_new_simple ("audio/mpeg",
1493 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
1494 if (codec_name)
1495 *codec_name = g_strdup ("MPEG-1 layer 3");
1496 break;
1497
1498 case GST_RIFF_WAVE_FORMAT_AMR_NB: /* amr-nb */
1499 caps = gst_caps_new_empty_simple ("audio/AMR");
1500 if (codec_name)
1501 *codec_name = g_strdup ("AMR Narrow Band (NB)");
1502 break;
1503
1504 case GST_RIFF_WAVE_FORMAT_AMR_WB: /* amr-wb */
1505 caps = gst_caps_new_empty_simple ("audio/AMR-WB");
1506 if (codec_name)
1507 *codec_name = g_strdup ("AMR Wide Band (WB)");
1508 break;
1509
1510 case GST_RIFF_WAVE_FORMAT_VORBIS1: /* ogg/vorbis mode 1 */
1511 case GST_RIFF_WAVE_FORMAT_VORBIS2: /* ogg/vorbis mode 2 */
1512 case GST_RIFF_WAVE_FORMAT_VORBIS3: /* ogg/vorbis mode 3 */
1513 case GST_RIFF_WAVE_FORMAT_VORBIS1PLUS: /* ogg/vorbis mode 1+ */
1514 case GST_RIFF_WAVE_FORMAT_VORBIS2PLUS: /* ogg/vorbis mode 2+ */
1515 case GST_RIFF_WAVE_FORMAT_VORBIS3PLUS: /* ogg/vorbis mode 3+ */
1516 caps = gst_caps_new_empty_simple ("audio/x-vorbis");
1517 if (codec_name)
1518 *codec_name = g_strdup ("Vorbis");
1519 break;
1520
1521 case GST_RIFF_WAVE_FORMAT_A52:
1522 caps = gst_caps_new_empty_simple ("audio/x-ac3");
1523 if (codec_name)
1524 *codec_name = g_strdup ("AC-3 audio");
1525 break;
1526 case GST_RIFF_WAVE_FORMAT_DTS:
1527 caps = gst_caps_new_empty_simple ("audio/x-dts");
1528 if (codec_name)
1529 *codec_name = g_strdup ("DTS audio");
1530 /* wavparse is not always able to specify rate/channels for DTS-in-wav */
1531 rate_chan = FALSE;
1532 break;
1533 case GST_RIFF_WAVE_FORMAT_AAC:
1534 case GST_RIFF_WAVE_FORMAT_AAC_AC:
1535 case GST_RIFF_WAVE_FORMAT_AAC_pm:
1536 {
1537 caps = gst_caps_new_simple ("audio/mpeg",
1538 "mpegversion", G_TYPE_INT, 4, NULL);
1539 if (codec_name)
1540 *codec_name = g_strdup ("MPEG-4 AAC audio");
1541 break;
1542 }
1543 case GST_RIFF_WAVE_FORMAT_WMAV1:
1544 case GST_RIFF_WAVE_FORMAT_WMAV2:
1545 case GST_RIFF_WAVE_FORMAT_WMAV3:
1546 case GST_RIFF_WAVE_FORMAT_WMAV3_L:
1547 {
1548 gint version = (codec_id - GST_RIFF_WAVE_FORMAT_WMAV1) + 1;
1549
1550 block_align = TRUE;
1551
1552 caps = gst_caps_new_simple ("audio/x-wma",
1553 "wmaversion", G_TYPE_INT, version, NULL);
1554
1555 if (codec_name) {
1556 if (codec_id == GST_RIFF_WAVE_FORMAT_WMAV3_L)
1557 *codec_name = g_strdup ("WMA Lossless");
1558 else
1559 *codec_name = g_strdup_printf ("WMA Version %d", version + 6);
1560 }
1561
1562 if (strf != NULL) {
1563 gst_caps_set_simple (caps,
1564 "bitrate", G_TYPE_INT, strf->av_bps * 8,
1565 "depth", G_TYPE_INT, strf->bits_per_sample, NULL);
1566 } else {
1567 gst_caps_set_simple (caps,
1568 "bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
1569 }
1570 break;
1571 }
1572 case GST_RIFF_WAVE_FORMAT_SONY_ATRAC3:
1573 caps = gst_caps_new_empty_simple ("audio/x-vnd.sony.atrac3");
1574 if (codec_name)
1575 *codec_name = g_strdup ("Sony ATRAC3");
1576 break;
1577
1578 case GST_RIFF_WAVE_FORMAT_SIREN:
1579 caps = gst_caps_new_empty_simple ("audio/x-siren");
1580 if (codec_name)
1581 *codec_name = g_strdup ("Siren7");
1582 rate_chan = FALSE;
1583 break;
1584
1585 case GST_RIFF_WAVE_FORMAT_ADPCM_IMA_DK4:
1586 caps =
1587 gst_caps_new_simple ("audio/x-adpcm", "layout", G_TYPE_STRING, "dk4",
1588 NULL);
1589 if (codec_name)
1590 *codec_name = g_strdup ("IMA/DK4 ADPCM");
1591 break;
1592 case GST_RIFF_WAVE_FORMAT_ADPCM_IMA_DK3:
1593 caps =
1594 gst_caps_new_simple ("audio/x-adpcm", "layout", G_TYPE_STRING, "dk3",
1595 NULL);
1596 if (codec_name)
1597 *codec_name = g_strdup ("IMA/DK3 ADPCM");
1598 break;
1599
1600 case GST_RIFF_WAVE_FORMAT_ADPCM_IMA_WAV:
1601 caps =
1602 gst_caps_new_simple ("audio/x-adpcm", "layout", G_TYPE_STRING, "dvi",
1603 NULL);
1604 if (codec_name)
1605 *codec_name = g_strdup ("IMA/WAV ADPCM");
1606 break;
1607 case GST_RIFF_WAVE_FORMAT_EXTENSIBLE:{
1608 guint16 valid_bits_per_sample;
1609 guint32 channel_mask;
1610 guint32 subformat_guid[4];
1611 GstMapInfo info;
1612 gsize size;
1613
1614 if (strf_data == NULL) {
1615 GST_WARNING ("WAVE_FORMAT_EXTENSIBLE but no strf_data buffer provided");
1616 return NULL;
1617 }
1618
1619 /* should be at least 22 bytes */
1620 size = gst_buffer_get_size (strf_data);
1621
1622 if (size < 22) {
1623 GST_WARNING ("WAVE_FORMAT_EXTENSIBLE data size is %" G_GSIZE_FORMAT
1624 " (expected: 22)", size);
1625 return NULL;
1626 }
1627
1628 gst_buffer_map (strf_data, &info, GST_MAP_READ);
1629 valid_bits_per_sample = GST_READ_UINT16_LE (info.data);
1630 channel_mask = GST_READ_UINT32_LE (info.data + 2);
1631 subformat_guid[0] = GST_READ_UINT32_LE (info.data + 6);
1632 subformat_guid[1] = GST_READ_UINT32_LE (info.data + 10);
1633 subformat_guid[2] = GST_READ_UINT32_LE (info.data + 14);
1634 subformat_guid[3] = GST_READ_UINT32_LE (info.data + 18);
1635 gst_buffer_unmap (strf_data, &info);
1636
1637 GST_DEBUG ("valid bps = %u", valid_bits_per_sample);
1638 GST_DEBUG ("channel mask = 0x%08x", channel_mask);
1639 GST_DEBUG ("GUID = %08x-%08x-%08x-%08x", subformat_guid[0],
1640 subformat_guid[1], subformat_guid[2], subformat_guid[3]);
1641
1642 if (subformat_guid[1] == 0x00100000 &&
1643 subformat_guid[2] == 0xaa000080 && subformat_guid[3] == 0x719b3800) {
1644 if (subformat_guid[0] == 0x00000001) {
1645 GST_DEBUG ("PCM");
1646 if (strf != NULL && strf->blockalign != 0 && strf->channels != 0
1647 && strf->rate != 0) {
1648 gint ba = strf->blockalign;
1649 gint wd = ba * 8 / strf->channels;
1650 gint ws;
1651 GstAudioFormat format;
1652
1653 /* in riff, the depth is stored in the size field but it just
1654 * means that the _least_ significant bits are cleared. We can
1655 * therefore just play the sample as if it had a depth == width */
1656 ws = wd;
1657
1658 /* For reference, use this to get the actual depth:
1659 * ws = strf->bits_per_sample;
1660 * if (valid_bits_per_sample != 0)
1661 * ws = valid_bits_per_sample; */
1662
1663 format =
1664 gst_audio_format_build_integer (wd != 8, G_LITTLE_ENDIAN, wd,
1665 ws);
1666
1667 caps = gst_caps_new_simple ("audio/x-raw",
1668 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1669 "layout", G_TYPE_STRING, "interleaved",
1670 "channels", G_TYPE_INT, strf->channels,
1671 "rate", G_TYPE_INT, strf->rate, NULL);
1672
1673 if (codec_name) {
1674 *codec_name = g_strdup_printf ("Uncompressed %d-bit PCM audio",
1675 strf->bits_per_sample);
1676 }
1677 }
1678 } else if (subformat_guid[0] == 0x00000003) {
1679 GST_DEBUG ("FLOAT");
1680 if (strf != NULL && strf->blockalign != 0 && strf->channels != 0
1681 && strf->rate != 0) {
1682 gint ba = strf->blockalign;
1683 gint wd = ba * 8 / strf->channels;
1684
1685 caps = gst_caps_new_simple ("audio/x-raw",
1686 "format", G_TYPE_STRING, wd == 32 ? "F32LE" : "F64LE",
1687 "layout", G_TYPE_STRING, "interleaved",
1688 "channels", G_TYPE_INT, strf->channels,
1689 "rate", G_TYPE_INT, strf->rate, NULL);
1690
1691 if (codec_name) {
1692 *codec_name =
1693 g_strdup_printf ("Uncompressed %d-bit IEEE float audio",
1694 strf->bits_per_sample);
1695 }
1696 }
1697 } else if (subformat_guid[0] == 0x0000006) {
1698 GST_DEBUG ("ALAW");
1699 if (strf != NULL) {
1700 if (strf->bits_per_sample != 8) {
1701 GST_WARNING ("invalid depth (%d) of alaw audio, overwriting.",
1702 strf->bits_per_sample);
1703 strf->bits_per_sample = 8;
1704 strf->av_bps = 8;
1705 strf->blockalign = strf->av_bps * strf->channels;
1706 }
1707 if (strf->av_bps == 0 || strf->blockalign == 0) {
1708 GST_WARNING
1709 ("fixing av_bps (%d) and blockalign (%d) of alaw audio",
1710 strf->av_bps, strf->blockalign);
1711 strf->av_bps = strf->bits_per_sample;
1712 strf->blockalign = strf->av_bps * strf->channels;
1713 }
1714 }
1715 caps = gst_caps_new_empty_simple ("audio/x-alaw");
1716
1717 if (codec_name)
1718 *codec_name = g_strdup ("A-law audio");
1719 } else if (subformat_guid[0] == 0x00000007) {
1720 GST_DEBUG ("MULAW");
1721 if (strf != NULL) {
1722 if (strf->bits_per_sample != 8) {
1723 GST_WARNING ("invalid depth (%d) of mulaw audio, overwriting.",
1724 strf->bits_per_sample);
1725 strf->bits_per_sample = 8;
1726 strf->av_bps = 8;
1727 strf->blockalign = strf->av_bps * strf->channels;
1728 }
1729 if (strf->av_bps == 0 || strf->blockalign == 0) {
1730 GST_WARNING
1731 ("fixing av_bps (%d) and blockalign (%d) of mulaw audio",
1732 strf->av_bps, strf->blockalign);
1733 strf->av_bps = strf->bits_per_sample;
1734 strf->blockalign = strf->av_bps * strf->channels;
1735 }
1736 }
1737 caps = gst_caps_new_empty_simple ("audio/x-mulaw");
1738 if (codec_name)
1739 *codec_name = g_strdup ("Mu-law audio");
1740 } else if (subformat_guid[0] == 0x00000092) {
1741 GST_DEBUG ("FIXME: handle DOLBY AC3 SPDIF format");
1742 GST_DEBUG ("WAVE_FORMAT_EXTENSIBLE AC-3 SPDIF audio");
1743 caps = gst_caps_new_empty_simple ("audio/x-ac3");
1744 if (codec_name)
1745 *codec_name = g_strdup ("wavext AC-3 SPDIF audio");
1746 } else if ((subformat_guid[0] & 0xffff) ==
1747 GST_RIFF_WAVE_FORMAT_EXTENSIBLE) {
1748 GST_DEBUG ("WAVE_FORMAT_EXTENSIBLE nested");
1749 } else {
1750 /* recurse where no special consideration has yet to be identified
1751 * for the subformat guid */
1752 caps = gst_riff_create_audio_caps (subformat_guid[0], strh, strf,
1753 strf_data, strd_data, codec_name, channel_reorder_map);
1754 if (!codec_name)
1755 GST_DEBUG ("WAVE_FORMAT_EXTENSIBLE audio");
1756 if (caps) {
1757 if (codec_name) {
1758 gchar *tmp = *codec_name;
1759 GST_DEBUG ("WAVE_FORMAT_EXTENSIBLE %s", *codec_name);
1760 *codec_name = g_strjoin ("wavext ", tmp, NULL);
1761 g_free (tmp);
1762 }
1763 return caps;
1764 }
1765 }
1766 } else if (subformat_guid[0] == 0x6ba47966 &&
1767 subformat_guid[1] == 0x41783f83 &&
1768 subformat_guid[2] == 0xf0006596 && subformat_guid[3] == 0xe59262bf) {
1769 caps = gst_caps_new_empty_simple ("application/x-ogg-avi");
1770 if (codec_name)
1771 *codec_name = g_strdup ("Ogg-AVI");
1772 }
1773
1774 if (caps == NULL) {
1775 GST_WARNING ("Unknown WAVE_FORMAT_EXTENSIBLE audio format");
1776 return NULL;
1777 }
1778
1779 if (strf != NULL) {
1780 /* If channel_mask == 0 and channels > 1 let's
1781 * assume default layout as some wav files don't have the
1782 * channel mask set. Don't set the layout for 1 channel. */
1783 if (channel_mask == 0 && strf->channels > 1)
1784 channel_mask =
1785 gst_riff_wavext_get_default_channel_mask (strf->channels);
1786
1787 if ((channel_mask != 0 || strf->channels > 1) &&
1788 !gst_riff_wavext_add_channel_mask (caps, strf->channels,
1789 channel_mask, channel_reorder_map)) {
1790 GST_WARNING ("failed to add channel layout");
1791 gst_caps_unref (caps);
1792 caps = NULL;
1793 }
1794 rate_chan = FALSE;
1795 }
1796
1797 break;
1798 }
1799 /* can anything decode these? pitfdll? */
1800 case GST_RIFF_WAVE_FORMAT_VOXWARE_AC8:
1801 case GST_RIFF_WAVE_FORMAT_VOXWARE_AC10:
1802 case GST_RIFF_WAVE_FORMAT_VOXWARE_AC16:
1803 case GST_RIFF_WAVE_FORMAT_VOXWARE_AC20:
1804 case GST_RIFF_WAVE_FORMAT_VOXWARE_METAVOICE:
1805 case GST_RIFF_WAVE_FORMAT_VOXWARE_METASOUND:
1806 case GST_RIFF_WAVE_FORMAT_VOXWARE_RT29HW:
1807 case GST_RIFF_WAVE_FORMAT_VOXWARE_VR12:
1808 case GST_RIFF_WAVE_FORMAT_VOXWARE_VR18:
1809 case GST_RIFF_WAVE_FORMAT_VOXWARE_TQ40:
1810 case GST_RIFF_WAVE_FORMAT_VOXWARE_TQ60:{
1811 caps = gst_caps_new_simple ("audio/x-voxware",
1812 "voxwaretype", G_TYPE_INT, (gint) codec_id, NULL);
1813 if (codec_name)
1814 *codec_name = g_strdup ("Voxware");
1815 break;
1816 }
1817 default:
1818 unknown:
1819 GST_WARNING ("Unknown audio tag 0x%04x", codec_id);
1820 return NULL;
1821 }
1822
1823 if (strf != NULL) {
1824 if (rate_chan) {
1825 gst_caps_set_simple (caps,
1826 "rate", G_TYPE_INT, strf->rate,
1827 "channels", G_TYPE_INT, strf->channels, NULL);
1828 }
1829 if (block_align) {
1830 gst_caps_set_simple (caps,
1831 "block_align", G_TYPE_INT, strf->blockalign, NULL);
1832 }
1833 } else {
1834 if (block_align) {
1835 gst_caps_set_simple (caps,
1836 "block_align", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
1837 }
1838 }
1839
1840 /* extradata */
1841 if (strf_data || strd_data) {
1842 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER,
1843 strf_data ? strf_data : strd_data, NULL);
1844 }
1845
1846 return caps;
1847 }
1848
1849 GstCaps *
gst_riff_create_iavs_caps(guint32 codec_fcc,gst_riff_strh * strh,gst_riff_strf_iavs * strf,GstBuffer * init_data,GstBuffer * extra_data,char ** codec_name)1850 gst_riff_create_iavs_caps (guint32 codec_fcc,
1851 gst_riff_strh * strh, gst_riff_strf_iavs * strf,
1852 GstBuffer * init_data, GstBuffer * extra_data, char **codec_name)
1853 {
1854 GstCaps *caps = NULL;
1855
1856 switch (codec_fcc) {
1857 /* is this correct? */
1858 case GST_MAKE_FOURCC ('D', 'V', 'S', 'D'):
1859 case GST_MAKE_FOURCC ('d', 'v', 's', 'd'):
1860 caps = gst_caps_new_simple ("video/x-dv",
1861 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
1862 if (codec_name)
1863 *codec_name = g_strdup ("Generic DV");
1864 break;
1865
1866 default:
1867 GST_WARNING ("Unknown IAVS fourcc %" GST_FOURCC_FORMAT,
1868 GST_FOURCC_ARGS (codec_fcc));
1869 return NULL;
1870 }
1871
1872 return caps;
1873 }
1874
1875 /*
1876 * Functions below are for template caps. All is variable.
1877 */
1878
1879 GstCaps *
gst_riff_create_video_template_caps(void)1880 gst_riff_create_video_template_caps (void)
1881 {
1882 static const guint32 tags[] = {
1883 GST_MAKE_FOURCC ('3', 'I', 'V', '1'),
1884 GST_MAKE_FOURCC ('A', 'S', 'V', '1'),
1885 GST_MAKE_FOURCC ('A', 'S', 'V', '2'),
1886 GST_MAKE_FOURCC ('C', 'F', 'H', 'D'),
1887 GST_MAKE_FOURCC ('C', 'L', 'J', 'R'),
1888 GST_MAKE_FOURCC ('C', 'S', 'C', 'D'),
1889 GST_MAKE_FOURCC ('C', 'Y', 'U', 'V'),
1890 GST_MAKE_FOURCC ('D', 'I', 'B', ' '),
1891 GST_MAKE_FOURCC ('D', 'I', 'V', '3'),
1892 GST_MAKE_FOURCC ('D', 'I', 'V', 'X'),
1893 GST_MAKE_FOURCC ('D', 'U', 'C', 'K'),
1894 GST_MAKE_FOURCC ('D', 'V', 'S', 'D'),
1895 GST_MAKE_FOURCC ('D', 'V', '5', '0'),
1896 GST_MAKE_FOURCC ('D', 'X', '5', '0'),
1897 GST_MAKE_FOURCC ('M', '4', 'C', 'C'),
1898 GST_MAKE_FOURCC ('F', 'L', 'V', '1'),
1899 GST_MAKE_FOURCC ('F', 'L', 'V', '4'),
1900 GST_MAKE_FOURCC ('H', '2', '6', '3'),
1901 GST_MAKE_FOURCC ('V', 'X', '1', 'K'),
1902 GST_MAKE_FOURCC ('H', '2', '6', '4'),
1903 GST_MAKE_FOURCC ('H', '2', '6', '5'),
1904 GST_MAKE_FOURCC ('H', 'F', 'Y', 'U'),
1905 GST_MAKE_FOURCC ('I', '2', '6', '3'),
1906 GST_MAKE_FOURCC ('I', '4', '2', '0'),
1907 GST_MAKE_FOURCC ('I', 'V', '3', '2'),
1908 GST_MAKE_FOURCC ('I', 'V', '4', '1'),
1909 GST_MAKE_FOURCC ('I', 'V', '5', '0'),
1910 GST_MAKE_FOURCC ('L', '2', '6', '3'),
1911 GST_MAKE_FOURCC ('L', '2', '6', '4'),
1912 GST_MAKE_FOURCC ('M', '2', '6', '3'),
1913 GST_MAKE_FOURCC ('M', '4', 'S', '2'),
1914 GST_MAKE_FOURCC ('M', 'J', 'P', 'G'),
1915 GST_MAKE_FOURCC ('M', 'P', '4', '2'),
1916 GST_MAKE_FOURCC ('M', 'P', '4', '3'),
1917 GST_MAKE_FOURCC ('M', 'P', 'E', 'G'),
1918 GST_MAKE_FOURCC ('M', 'P', 'G', '2'),
1919 GST_MAKE_FOURCC ('M', 'P', 'G', '4'),
1920 GST_MAKE_FOURCC ('M', 'S', 'Z', 'H'),
1921 GST_MAKE_FOURCC ('P', 'N', 'G', ' '),
1922 GST_MAKE_FOURCC ('R', 'L', 'E', ' '),
1923 GST_MAKE_FOURCC ('R', 'T', '2', '1'),
1924 GST_MAKE_FOURCC ('S', 'P', '5', '3'),
1925 GST_MAKE_FOURCC ('T', 'M', '2', '0'),
1926 GST_MAKE_FOURCC ('T', 'S', 'C', 'C'),
1927 GST_MAKE_FOURCC ('U', 'L', 'T', 'I'),
1928 GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'),
1929 GST_MAKE_FOURCC ('V', 'C', 'R', '1'),
1930 GST_MAKE_FOURCC ('V', 'C', 'R', '2'),
1931 GST_MAKE_FOURCC ('V', 'D', 'O', 'W'),
1932 GST_MAKE_FOURCC ('V', 'I', 'V', 'O'),
1933 GST_MAKE_FOURCC ('V', 'M', 'n', 'c'),
1934 GST_MAKE_FOURCC ('V', 'P', '3', ' '),
1935 GST_MAKE_FOURCC ('V', 'S', 'S', 'H'),
1936 GST_MAKE_FOURCC ('W', 'M', 'V', '1'),
1937 GST_MAKE_FOURCC ('W', 'M', 'V', '2'),
1938 GST_MAKE_FOURCC ('W', 'M', 'V', '3'),
1939 GST_MAKE_FOURCC ('X', 'V', 'I', 'D'),
1940 GST_MAKE_FOURCC ('X', 'x', 'a', 'n'),
1941 GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'),
1942 GST_MAKE_FOURCC ('Y', 'V', 'U', '9'),
1943 GST_MAKE_FOURCC ('Z', 'L', 'I', 'B'),
1944 GST_MAKE_FOURCC ('c', 'v', 'i', 'd'),
1945 GST_MAKE_FOURCC ('h', '2', '6', '4'),
1946 GST_MAKE_FOURCC ('m', 's', 'v', 'c'),
1947 GST_MAKE_FOURCC ('x', '2', '6', '3'),
1948 GST_MAKE_FOURCC ('d', 'r', 'a', 'c'),
1949 GST_MAKE_FOURCC ('F', 'F', 'V', '1'),
1950 GST_MAKE_FOURCC ('K', 'M', 'V', 'C'),
1951 GST_MAKE_FOURCC ('V', 'P', '5', '0'),
1952 GST_MAKE_FOURCC ('V', 'P', '6', '0'),
1953 GST_MAKE_FOURCC ('V', 'P', '6', 'F'),
1954 GST_MAKE_FOURCC ('V', 'P', '7', '0'),
1955 GST_MAKE_FOURCC ('V', 'P', '8', '0'),
1956 GST_MAKE_FOURCC ('L', 'M', '2', '0'),
1957 GST_MAKE_FOURCC ('R', 'P', 'Z', 'A'),
1958 GST_MAKE_FOURCC ('T', 'H', 'E', 'O'),
1959 GST_MAKE_FOURCC ('F', 'P', 'S', '1'),
1960 GST_MAKE_FOURCC ('A', 'A', 'S', 'C'),
1961 GST_MAKE_FOURCC ('Y', 'V', '1', '2'),
1962 GST_MAKE_FOURCC ('L', 'O', 'C', 'O'),
1963 GST_MAKE_FOURCC ('Z', 'M', 'B', 'V'),
1964 GST_MAKE_FOURCC ('v', '2', '1', '0'),
1965 GST_MAKE_FOURCC ('r', '2', '1', '0'),
1966 /* FILL ME */
1967 };
1968 guint i;
1969 GstCaps *caps, *one;
1970
1971 caps = gst_caps_new_empty ();
1972 for (i = 0; i < G_N_ELEMENTS (tags); i++) {
1973 one = gst_riff_create_video_caps (tags[i], NULL, NULL, NULL, NULL, NULL);
1974 if (one)
1975 gst_caps_append (caps, one);
1976 }
1977
1978 return caps;
1979 }
1980
1981 GstCaps *
gst_riff_create_audio_template_caps(void)1982 gst_riff_create_audio_template_caps (void)
1983 {
1984 static const guint16 tags[] = {
1985 GST_RIFF_WAVE_FORMAT_GSM610,
1986 GST_RIFF_WAVE_FORMAT_MPEGL3,
1987 GST_RIFF_WAVE_FORMAT_MPEGL12,
1988 GST_RIFF_WAVE_FORMAT_PCM,
1989 GST_RIFF_WAVE_FORMAT_VORBIS1,
1990 GST_RIFF_WAVE_FORMAT_A52,
1991 GST_RIFF_WAVE_FORMAT_DTS,
1992 GST_RIFF_WAVE_FORMAT_AAC,
1993 GST_RIFF_WAVE_FORMAT_ALAW,
1994 GST_RIFF_WAVE_FORMAT_MULAW,
1995 GST_RIFF_WAVE_FORMAT_WMS,
1996 GST_RIFF_WAVE_FORMAT_ADPCM,
1997 GST_RIFF_WAVE_FORMAT_DVI_ADPCM,
1998 GST_RIFF_WAVE_FORMAT_DSP_TRUESPEECH,
1999 GST_RIFF_WAVE_FORMAT_WMAV1,
2000 GST_RIFF_WAVE_FORMAT_WMAV2,
2001 GST_RIFF_WAVE_FORMAT_WMAV3,
2002 GST_RIFF_WAVE_FORMAT_SONY_ATRAC3,
2003 GST_RIFF_WAVE_FORMAT_IEEE_FLOAT,
2004 GST_RIFF_WAVE_FORMAT_VOXWARE_METASOUND,
2005 GST_RIFF_WAVE_FORMAT_ADPCM_IMA_DK4,
2006 GST_RIFF_WAVE_FORMAT_ADPCM_IMA_DK3,
2007 GST_RIFF_WAVE_FORMAT_ADPCM_IMA_WAV,
2008 GST_RIFF_WAVE_FORMAT_AMR_NB,
2009 GST_RIFF_WAVE_FORMAT_AMR_WB,
2010 GST_RIFF_WAVE_FORMAT_SIREN,
2011 /* FILL ME */
2012 };
2013 guint i;
2014 GstCaps *caps, *one;
2015
2016 caps = gst_caps_new_empty ();
2017 for (i = 0; i < G_N_ELEMENTS (tags); i++) {
2018 one =
2019 gst_riff_create_audio_caps (tags[i], NULL, NULL, NULL, NULL, NULL,
2020 NULL);
2021 if (one)
2022 gst_caps_append (caps, one);
2023 }
2024 one = gst_caps_new_empty_simple ("application/x-ogg-avi");
2025 gst_caps_append (caps, one);
2026
2027 return caps;
2028 }
2029
2030 GstCaps *
gst_riff_create_iavs_template_caps(void)2031 gst_riff_create_iavs_template_caps (void)
2032 {
2033 static const guint32 tags[] = {
2034 GST_MAKE_FOURCC ('D', 'V', 'S', 'D')
2035 /* FILL ME */
2036 };
2037 guint i;
2038 GstCaps *caps, *one;
2039
2040 caps = gst_caps_new_empty ();
2041 for (i = 0; i < G_N_ELEMENTS (tags); i++) {
2042 one = gst_riff_create_iavs_caps (tags[i], NULL, NULL, NULL, NULL, NULL);
2043 if (one)
2044 gst_caps_append (caps, one);
2045 }
2046
2047 return caps;
2048 }
2049