2 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * riff-media.h: RIFF-id to/from caps routines
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.
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.
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
27 #include "riff-media.h"
30 * gst_riff_create_video_caps_with_data:
31 * @codec_fcc: fourCC codec for this codec.
32 * @strh: pointer to the strh stream header structure.
33 * @strf: pointer to the strf stream header structure, including any
34 * data that is within the range of strf.size, but excluding any
35 * additional data withint this chunk but outside strf.size.
36 * @strf_data: a #GstBuffer containing the additional data in the strf
37 * chunk outside reach of strf.size. Ususally a palette.
38 * @strd_data: a #GstBuffer containing the data in the strd stream header
39 * chunk. Usually codec initialization data.
40 * @codec_name: if given, will be filled with a human-readable codec name.
44 gst_riff_create_video_caps_with_data (guint32 codec_fcc,
45 gst_riff_strh * strh, gst_riff_strf_vids * strf,
46 GstBuffer * strf_data, GstBuffer * strd_data, char **codec_name)
51 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
52 caps = gst_caps_new_simple ("video/x-raw-yuv",
53 "format", GST_TYPE_FOURCC, codec_fcc, NULL);
55 *codec_name = g_strdup ("Uncompressed planar YUV 4:2:0");
58 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
59 caps = gst_caps_new_simple ("video/x-raw-yuv",
60 "format", GST_TYPE_FOURCC, codec_fcc, NULL);
62 *codec_name = g_strdup ("Uncompressed packed YUV 4:2:2");
65 case GST_MAKE_FOURCC ('M', 'J', 'P', 'G'): /* YUY2 MJPEG */
66 caps = gst_caps_new_simple ("image/jpeg", NULL);
68 *codec_name = g_strdup ("Motion JPEG");
71 case GST_MAKE_FOURCC ('J', 'P', 'E', 'G'): /* generic (mostly RGB) MJPEG */
72 caps = gst_caps_new_simple ("image/jpeg", NULL);
74 *codec_name = g_strdup ("JPEG Still Image");
77 case GST_MAKE_FOURCC ('P', 'I', 'X', 'L'): /* Miro/Pinnacle fourccs */
78 case GST_MAKE_FOURCC ('V', 'I', 'X', 'L'): /* Miro/Pinnacle fourccs */
79 caps = gst_caps_new_simple ("image/jpeg", NULL);
81 *codec_name = g_strdup ("Miro/Pinnacle Motion JPEG Video");
84 case GST_MAKE_FOURCC ('H', 'F', 'Y', 'U'):
85 caps = gst_caps_new_simple ("video/x-huffyuv", NULL);
87 *codec_name = g_strdup ("Huffman Lossless Codec");
90 case GST_MAKE_FOURCC ('M', 'P', 'E', 'G'):
91 case GST_MAKE_FOURCC ('M', 'P', 'G', 'I'):
92 caps = gst_caps_new_simple ("video/mpeg",
93 "systemstream", G_TYPE_BOOLEAN, FALSE,
94 "mpegversion", G_TYPE_INT, 1, NULL);
96 *codec_name = g_strdup ("MPEG video");
99 case GST_MAKE_FOURCC ('H', '2', '6', '3'):
100 caps = gst_caps_new_simple ("video/x-h263", NULL);
102 *codec_name = g_strdup ("ITU H.26n");
105 case GST_MAKE_FOURCC ('i', '2', '6', '3'):
106 caps = gst_caps_new_simple ("video/x-h263", NULL);
108 *codec_name = g_strdup ("ITU H.263");
111 case GST_MAKE_FOURCC ('L', '2', '6', '3'):
112 caps = gst_caps_new_simple ("video/x-h263", NULL);
114 *codec_name = g_strdup ("Lead H.263");
117 case GST_MAKE_FOURCC ('M', '2', '6', '3'):
118 caps = gst_caps_new_simple ("video/x-h263", NULL);
120 *codec_name = g_strdup ("Microsoft H.263");
123 case GST_MAKE_FOURCC ('V', 'D', 'O', 'W'):
124 caps = gst_caps_new_simple ("video/x-h263", NULL);
126 *codec_name = g_strdup ("VDOLive");
129 case GST_MAKE_FOURCC ('V', 'I', 'V', 'O'):
130 caps = gst_caps_new_simple ("video/x-h263", NULL);
132 *codec_name = g_strdup ("Vivo H.263");
135 case GST_MAKE_FOURCC ('x', '2', '6', '3'):
136 caps = gst_caps_new_simple ("video/x-h263", NULL);
138 *codec_name = g_strdup ("Xirlink H.263");
141 case GST_MAKE_FOURCC ('D', 'I', 'V', '3'):
142 case GST_MAKE_FOURCC ('d', 'i', 'v', '3'):
143 case GST_MAKE_FOURCC ('D', 'I', 'V', '4'):
144 case GST_MAKE_FOURCC ('d', 'i', 'v', '4'):
145 case GST_MAKE_FOURCC ('D', 'I', 'V', '5'):
146 case GST_MAKE_FOURCC ('d', 'i', 'v', '5'):
147 case GST_MAKE_FOURCC ('D', 'I', 'V', '6'):
148 case GST_MAKE_FOURCC ('d', 'i', 'v', '6'):
149 caps = gst_caps_new_simple ("video/x-divx",
150 "divxversion", G_TYPE_INT, 3, NULL);
152 *codec_name = g_strdup ("DivX MS-MPEG-4 Version 3");
155 case GST_MAKE_FOURCC ('d', 'i', 'v', 'x'):
156 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
157 caps = gst_caps_new_simple ("video/x-divx",
158 "divxversion", G_TYPE_INT, 4, NULL);
160 *codec_name = g_strdup ("DivX MPEG-4 Version 4");
163 case GST_MAKE_FOURCC ('D', 'X', '5', '0'):
164 caps = gst_caps_new_simple ("video/x-divx",
165 "divxversion", G_TYPE_INT, 5, NULL);
167 *codec_name = g_strdup ("DivX MPEG-4 Version 5");
170 case GST_MAKE_FOURCC ('X', 'V', 'I', 'D'):
171 case GST_MAKE_FOURCC ('x', 'v', 'i', 'd'):
172 caps = gst_caps_new_simple ("video/x-xvid", NULL);
174 *codec_name = g_strdup ("XVID MPEG-4");
177 case GST_MAKE_FOURCC ('M', 'P', 'G', '4'):
178 caps = gst_caps_new_simple ("video/x-msmpeg",
179 "msmpegversion", G_TYPE_INT, 41, NULL);
181 *codec_name = g_strdup ("Microsoft MPEG-4 4.1");
184 case GST_MAKE_FOURCC ('M', 'P', '4', '2'):
185 caps = gst_caps_new_simple ("video/x-msmpeg",
186 "msmpegversion", G_TYPE_INT, 42, NULL);
188 *codec_name = g_strdup ("Microsoft MPEG-4 4.2");
191 case GST_MAKE_FOURCC ('M', 'P', '4', '3'):
192 caps = gst_caps_new_simple ("video/x-msmpeg",
193 "msmpegversion", G_TYPE_INT, 43, NULL);
195 *codec_name = g_strdup ("Microsoft MPEG-4 4.3");
198 case GST_MAKE_FOURCC ('3', 'I', 'V', '1'):
199 case GST_MAKE_FOURCC ('3', 'I', 'V', '2'):
200 caps = gst_caps_new_simple ("video/x-3ivx", NULL);
202 *codec_name = g_strdup ("3ivx");
205 case GST_MAKE_FOURCC ('D', 'V', 'S', 'D'):
206 case GST_MAKE_FOURCC ('d', 'v', 's', 'd'):
207 caps = gst_caps_new_simple ("video/x-dv",
208 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
210 *codec_name = g_strdup ("Generic DV");
213 case GST_MAKE_FOURCC ('W', 'M', 'V', '1'):
214 caps = gst_caps_new_simple ("video/x-wmv",
215 "wmvversion", G_TYPE_INT, 1, NULL);
217 *codec_name = g_strdup ("Windows Media Video 7");
220 case GST_MAKE_FOURCC ('W', 'M', 'V', '2'):
221 caps = gst_caps_new_simple ("video/x-wmv",
222 "wmvversion", G_TYPE_INT, 2, NULL);
224 *codec_name = g_strdup ("Windows Media Video 8");
227 case GST_MAKE_FOURCC ('W', 'M', 'V', '3'):
228 caps = gst_caps_new_simple ("video/x-wmv",
229 "wmvversion", G_TYPE_INT, 3, NULL);
231 *codec_name = g_strdup ("Windows Media Video 9");
234 case GST_MAKE_FOURCC ('c', 'v', 'i', 'd'):
235 caps = gst_caps_new_simple ("video/x-cinepak", NULL);
237 *codec_name = g_strdup ("Cinepak video");
240 case GST_MAKE_FOURCC ('M', 'S', 'V', 'C'):
241 case GST_MAKE_FOURCC ('m', 's', 'v', 'c'):
242 case GST_MAKE_FOURCC ('C', 'R', 'A', 'M'):
243 case GST_MAKE_FOURCC ('c', 'r', 'a', 'm'):
244 case GST_MAKE_FOURCC ('W', 'H', 'A', 'M'):
245 case GST_MAKE_FOURCC ('w', 'h', 'a', 'm'):
246 caps = gst_caps_new_simple ("video/x-msvideocodec",
247 "msvideoversion", G_TYPE_INT, 1, NULL);
249 *codec_name = g_strdup ("MS video v1");
252 case GST_MAKE_FOURCC ('R', 'L', 'E', ' '):
253 case GST_MAKE_FOURCC ('m', 'r', 'l', 'e'):
254 case GST_MAKE_FOURCC (0x1, 0x0, 0x0, 0x0): /* why, why, why? */
255 caps = gst_caps_new_simple ("video/x-rle",
256 "layout", G_TYPE_STRING, "microsoft", NULL);
257 if (strf_data && GST_BUFFER_SIZE (strf_data) >= 256 * 4) {
258 GstBuffer *copy = gst_buffer_copy (strf_data);
259 GValue value = { 0 };
261 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
263 guint32 *data = (guint32 *) GST_BUFFER_DATA (copy);
266 for (n = 0; n < 256; n++)
267 data[n] = GUINT32_FROM_LE (data[n]);
269 g_value_init (&value, GST_TYPE_BUFFER);
270 g_value_set_boxed (&value, copy);
271 gst_structure_set_value (gst_caps_get_structure (caps, 0),
272 "palette_data", &value);
273 g_value_unset (&value);
274 gst_buffer_unref (copy);
277 gst_caps_set_simple (caps,
278 "depth", G_TYPE_INT, (gint) strf->bit_cnt, NULL);
280 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
283 *codec_name = g_strdup ("Mcrosoft RLE");
287 GST_WARNING ("Unknown video fourcc " GST_FOURCC_FORMAT,
288 GST_FOURCC_ARGS (codec_fcc));
293 gdouble fps = 1. * strh->rate / strh->scale;
295 gst_caps_set_simple (caps, "framerate", G_TYPE_DOUBLE, fps, NULL);
297 gst_caps_set_simple (caps,
298 "framerate", GST_TYPE_DOUBLE_RANGE, 0., G_MAXDOUBLE, NULL);
302 gst_caps_set_simple (caps,
303 "width", G_TYPE_INT, strf->width,
304 "height", G_TYPE_INT, strf->height, NULL);
306 gst_caps_set_simple (caps,
307 "width", GST_TYPE_INT_RANGE, 16, 4096,
308 "height", GST_TYPE_INT_RANGE, 16, 4096, NULL);
315 gst_riff_create_video_caps (guint32 codec_fcc,
316 gst_riff_strh * strh, gst_riff_strf_vids * strf, char **codec_name)
318 return gst_riff_create_video_caps_with_data (codec_fcc,
319 strh, strf, NULL, NULL, codec_name);
323 gst_riff_create_audio_caps (guint16 codec_id,
324 gst_riff_strh * strh, gst_riff_strf_auds * strf, char **codec_name)
326 gboolean block_align = FALSE;
327 GstCaps *caps = NULL;
330 case GST_RIFF_WAVE_FORMAT_MPEGL3: /* mp3 */
331 caps = gst_caps_new_simple ("audio/mpeg",
332 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
334 *codec_name = g_strdup ("MPEG 1 layer 3");
337 case GST_RIFF_WAVE_FORMAT_MPEGL12: /* mp1 or mp2 */
338 caps = gst_caps_new_simple ("audio/mpeg",
339 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
341 *codec_name = g_strdup ("MPEG 1 layer 2");
344 case GST_RIFF_WAVE_FORMAT_PCM: /* PCM */
346 gint ba = GUINT16_FROM_LE (strf->blockalign);
347 gint ch = GUINT16_FROM_LE (strf->channels);
348 gint ws = GUINT16_FROM_LE (strf->size);
350 caps = gst_caps_new_simple ("audio/x-raw-int",
351 "endianness", G_TYPE_INT, G_LITTLE_ENDIAN,
352 "width", G_TYPE_INT, (int) (ba * 8 / ch),
353 "depth", G_TYPE_INT, ws, "signed", G_TYPE_BOOLEAN, ws != 8, NULL);
355 caps = gst_caps_from_string ("audio/x-raw-int, "
356 "endianness = (int) LITTLE_ENDIAN, "
357 "signed = (boolean) { true, false }, "
358 "width = (int) { 8, 16 }, " "depth = (int) { 8, 16 }");
361 *codec_name = g_strdup ("Uncompressed PCM audio");
364 case GST_RIFF_WAVE_FORMAT_ADPCM:
365 caps = gst_caps_new_simple ("audio/x-adpcm",
366 "layout", G_TYPE_STRING, "microsoft", NULL);
368 *codec_name = g_strdup ("ADPCM audio");
372 case GST_RIFF_WAVE_FORMAT_DVI_ADPCM:
373 caps = gst_caps_new_simple ("audio/x-adpcm",
374 "layout", G_TYPE_STRING, "dvi", NULL);
376 *codec_name = g_strdup ("DVI ADPCM audio");
380 case GST_RIFF_WAVE_FORMAT_MULAW:
381 if (strf != NULL && strf->size != 8) {
382 GST_WARNING ("invalid depth (%d) of mulaw audio, overwriting.",
385 caps = gst_caps_new_simple ("audio/x-mulaw", NULL);
387 *codec_name = g_strdup ("Mulaw");
390 case GST_RIFF_WAVE_FORMAT_ALAW:
391 if (strf != NULL && strf->size != 8) {
392 GST_WARNING ("invalid depth (%d) of alaw audio, overwriting.",
395 caps = gst_caps_new_simple ("audio/x-alaw", NULL);
397 *codec_name = g_strdup ("Alaw");
400 case GST_RIFF_WAVE_FORMAT_VORBIS1: /* ogg/vorbis mode 1 */
401 case GST_RIFF_WAVE_FORMAT_VORBIS2: /* ogg/vorbis mode 2 */
402 case GST_RIFF_WAVE_FORMAT_VORBIS3: /* ogg/vorbis mode 3 */
403 case GST_RIFF_WAVE_FORMAT_VORBIS1PLUS: /* ogg/vorbis mode 1+ */
404 case GST_RIFF_WAVE_FORMAT_VORBIS2PLUS: /* ogg/vorbis mode 2+ */
405 case GST_RIFF_WAVE_FORMAT_VORBIS3PLUS: /* ogg/vorbis mode 3+ */
406 caps = gst_caps_new_simple ("audio/x-vorbis", NULL);
408 *codec_name = g_strdup ("Vorbis");
411 case GST_RIFF_WAVE_FORMAT_A52:
412 caps = gst_caps_new_simple ("audio/x-ac3", NULL);
414 *codec_name = g_strdup ("AC3");
418 GST_WARNING ("Unknown audio tag 0x%04x", codec_id);
423 gst_caps_set_simple (caps,
424 "rate", G_TYPE_INT, strf->rate,
425 "channels", G_TYPE_INT, strf->channels, NULL);
427 gst_caps_set_simple (caps,
428 "block_align", G_TYPE_INT, strf->blockalign, NULL);
430 gst_caps_set_simple (caps,
431 "rate", GST_TYPE_INT_RANGE, 8000, 96000,
432 "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
434 gst_caps_set_simple (caps,
435 "block_align", GST_TYPE_INT_RANGE, 1, 8192, NULL);
442 gst_riff_create_iavs_caps (guint32 codec_fcc,
443 gst_riff_strh * strh, gst_riff_strf_iavs * strf, char **codec_name)
445 GstCaps *caps = NULL;
448 /* is this correct? */
449 case GST_MAKE_FOURCC ('D', 'V', 'S', 'D'):
450 case GST_MAKE_FOURCC ('d', 'v', 's', 'd'):
451 caps = gst_caps_new_simple ("video/x-dv",
452 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
454 *codec_name = g_strdup ("Generic DV");
458 GST_WARNING ("Unknown IAVS fourcc " GST_FOURCC_FORMAT,
459 GST_FOURCC_ARGS (codec_fcc));
467 * Functions below are for template caps. All is variable.
471 gst_riff_create_video_template_caps (void)
474 GST_MAKE_FOURCC ('I', '4', '2', '0'),
475 GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'),
476 GST_MAKE_FOURCC ('M', 'J', 'P', 'G'),
477 GST_MAKE_FOURCC ('D', 'V', 'S', 'D'),
478 GST_MAKE_FOURCC ('W', 'M', 'V', '1'),
479 GST_MAKE_FOURCC ('W', 'M', 'V', '2'),
480 GST_MAKE_FOURCC ('M', 'P', 'G', '4'),
481 GST_MAKE_FOURCC ('M', 'P', '4', '2'),
482 GST_MAKE_FOURCC ('M', 'P', '4', '3'),
483 GST_MAKE_FOURCC ('H', 'F', 'Y', 'U'),
484 GST_MAKE_FOURCC ('D', 'I', 'V', '3'),
485 GST_MAKE_FOURCC ('M', 'P', 'E', 'G'),
486 GST_MAKE_FOURCC ('H', '2', '6', '3'),
487 GST_MAKE_FOURCC ('D', 'I', 'V', 'X'),
488 GST_MAKE_FOURCC ('X', 'V', 'I', 'D'),
489 GST_MAKE_FOURCC ('3', 'I', 'V', '1'),
490 GST_MAKE_FOURCC ('c', 'v', 'i', 'd'),
491 GST_MAKE_FOURCC ('m', 's', 'v', 'c'),
492 GST_MAKE_FOURCC ('R', 'L', 'E', ' '),
499 caps = gst_caps_new_empty ();
500 for (i = 0; tags[i] != 0; i++) {
501 one = gst_riff_create_video_caps (tags[i], NULL, NULL, NULL);
503 gst_caps_append (caps, one);
510 gst_riff_create_audio_template_caps (void)
513 GST_RIFF_WAVE_FORMAT_MPEGL3,
514 GST_RIFF_WAVE_FORMAT_MPEGL12,
515 GST_RIFF_WAVE_FORMAT_PCM,
516 GST_RIFF_WAVE_FORMAT_VORBIS1,
517 GST_RIFF_WAVE_FORMAT_A52,
518 GST_RIFF_WAVE_FORMAT_ALAW,
519 GST_RIFF_WAVE_FORMAT_MULAW,
520 GST_RIFF_WAVE_FORMAT_ADPCM,
521 GST_RIFF_WAVE_FORMAT_DVI_ADPCM,
528 caps = gst_caps_new_empty ();
529 for (i = 0; tags[i] != 0; i++) {
530 one = gst_riff_create_audio_caps (tags[i], NULL, NULL, NULL);
532 gst_caps_append (caps, one);
539 gst_riff_create_iavs_template_caps (void)
542 GST_MAKE_FOURCC ('D', 'V', 'S', 'D'),
549 caps = gst_caps_new_empty ();
550 for (i = 0; tags[i] != 0; i++) {
551 one = gst_riff_create_iavs_caps (tags[i], NULL, NULL, NULL);
553 gst_caps_append (caps, one);