pbutils: add description for x-annodex
[platform/upstream/gstreamer.git] / gst-libs / gst / pbutils / descriptions.c
1 /* GStreamer Plugins Base utils library source/sink/codec description support
2  * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /**
21  * SECTION:gstpbutilsdescriptions
22  * @short_description: Provides human-readable descriptions for caps/codecs
23  * and encoder, decoder, URI source and URI sink elements
24  *
25  * <refsect2>
26  * <para>
27  * The above functions provide human-readable strings for media formats
28  * and decoder/demuxer/depayloader/encoder/muxer/payloader elements for use
29  * in error dialogs or other messages shown to users.
30  * </para>
31  * <para>
32  * gst_pb_utils_add_codec_description_to_tag_list() is a utility function
33  * for demuxer and decoder elements to add audio/video codec tags from a
34  * given (fixed) #GstCaps.
35  * </para>
36  * </refsect2>
37  */
38
39 #ifdef HAVE_CONFIG_H
40 # include "config.h"
41 #endif
42
43 #include "gst/gst-i18n-plugin.h"
44
45 #include "pbutils.h"
46 #include "pbutils-private.h"
47
48 #include <string.h>
49
50 typedef enum
51 {
52   FLAG_CONTAINER = (1 << 0),    /* format is a container format (muxed)             */
53   FLAG_SYSTEMSTREAM = (1 << 1)  /* match record only if caps have systemstream=true */
54 } FormatFlags;
55
56 typedef struct
57 {
58   const gchar *type;
59   const gchar *desc;
60   FormatFlags flags;
61 } FormatInfo;
62
63 static const FormatInfo formats[] = {
64   /* container/tag formats with static descriptions */
65   {"application/gxf", "General Exchange Format (GXF)", FLAG_CONTAINER},
66   {"application/ogg", "Ogg", FLAG_CONTAINER},
67   {"application/mxf", "Material eXchange Format (MXF)", FLAG_CONTAINER},
68   {"application/vnd.rn-realmedia", "Realmedia", FLAG_CONTAINER},
69   {"application/x-annodex", "Ogg", FLAG_CONTAINER},
70   {"application/x-id3", N_("ID3 tag"), FLAG_CONTAINER},
71   {"application/x-ape", N_("APE tag"), FLAG_CONTAINER},
72   {"application/x-apetag", N_("APE tag"), FLAG_CONTAINER},
73   {"application/x-icy", N_("ICY internet radio"), FLAG_CONTAINER},
74   {"application/x-3gp", "3GP", FLAG_CONTAINER},
75   {"application/x-pn-realaudio", "RealAudio", FLAG_CONTAINER},
76   {"application/x-yuv4mpeg", "Y4M", FLAG_CONTAINER},
77   {"multipart/x-mixed-replace", "Multipart", FLAG_CONTAINER},
78   {"video/x-fli", "FLI/FLC/FLX Animation", FLAG_CONTAINER},
79   {"video/x-flv", "Flash", FLAG_CONTAINER},
80   {"video/x-matroska", "Matroska", FLAG_CONTAINER},
81   {"video/webm", "WebM", FLAG_CONTAINER},
82   {"video/x-ms-asf", "Advanced Streaming Format (ASF)", FLAG_CONTAINER},
83   {"video/x-msvideo", "Audio Video Interleave (AVI)", FLAG_CONTAINER},
84   {"video/x-quicktime", "Quicktime", FLAG_CONTAINER},
85   {"video/quicktime", "Quicktime", FLAG_CONTAINER},
86   {"video/mj2", "Motion JPEG 2000", FLAG_CONTAINER},
87
88   /* audio formats with static descriptions */
89   {"audio/x-ac3", "AC-3 (ATSC A/52)", 0},
90   {"audio/ac3", "AC-3 (ATSC A/52)", 0},
91   {"audio/x-private-ac3", "DVD AC-3 (ATSC A/52)", 0},
92   {"audio/x-private1-ac3", "DVD AC-3 (ATSC A/52)", 0},
93   {"audio/x-alaw", "A-Law", 0},
94   {"audio/amr", "Adaptive Multi Rate (AMR)", 0},
95   {"audio/AMR", "Adaptive Multi Rate (AMR)", 0},
96   {"audio/AMR-WB", "Adaptive Multi Rate WideBand (AMR-WB)", 0},
97   {"audio/iLBC-sh", "Internet Low Bitrate Codec (iLBC)", 0},
98   {"audio/ms-gsm", "MS GSM", 0},
99   {"audio/qcelp", "QCELP", 0},
100   {"audio/aiff", "Audio Interchange File Format (AIFF)", 0},
101   {"audio/x-aiff", "Audio Interchange File Format (AIFF)", 0},
102   {"audio/x-alac", N_("Apple Lossless Audio (ALAC)"), 0},
103   {"audio/x-amr-nb-sh", "Adaptive Multi Rate NarrowBand (AMR-NB)", 0},
104   {"audio/x-amr-wb-sh", "Adaptive Multi Rate WideBand (AMR-WB)", 0},
105   {"audio/x-au", "Sun .au", 0},
106   {"audio/x-celt", "Constrained Energy Lapped Transform (CELT)", 0},
107   {"audio/x-cinepak", "Cinepak Audio", 0},
108   {"audio/x-dpcm", "DPCM", 0},
109   {"audio/x-dts", "DTS", 0},
110   {"audio/x-private1-dts", "DTS", 0},
111   {"audio/x-dv", "DV Audio", 0},
112   {"audio/x-flac", N_("Free Lossless Audio Codec (FLAC)"), 0},
113   {"audio/x-gsm", "GSM", 0},
114   {"audio/x-iec958", "S/PDIF IEC958", 0},       /* TODO: check description */
115   {"audio/x-iLBC", "Internet Low Bitrate Codec (iLBC)", 0},
116   {"audio/x-ircam", "Berkeley/IRCAM/CARL", 0},
117   {"audio/x-lpcm", "LPCM", 0},
118   {"audio/x-private1-lpcm", "DVD LPCM", 0},
119   {"audio/x-m4a", "MPEG-4 AAC", FLAG_CONTAINER},
120   {"audio/x-mod", "Module Music Format (MOD)", 0},
121   {"audio/x-mulaw", "Mu-Law", 0},
122   {"audio/x-musepack", "Musepack (MPC)", 0},
123   {"audio/x-nellymoser", "Nellymoser Asao", 0},
124   {"audio/x-nist", "Sphere NIST", 0},
125   {"audio/x-nsf", "Nintendo NSF", 0},
126   {"audio/x-paris", "Ensoniq PARIS", 0},
127   {"audio/x-qdm", "QDesign Music (QDM)", 0},
128   {"audio/x-qdm2", "QDesign Music (QDM) 2", 0},
129   {"audio/x-ralf-mpeg4-generic", "Real Audio Lossless (RALF)", 0},
130   {"audio/x-sds", "SDS", 0},
131   {"audio/x-shorten", "Shorten Lossless", 0},
132   {"audio/x-sid", "Sid", 0},
133   {"audio/x-sipro", "Sipro/ACELP.NET Voice", 0},
134   {"audio/x-siren", "Siren", 0},
135   {"audio/x-spc", "SNES-SPC700 Sound File Data", 0},
136   {"audio/x-speex", "Speex", 0},
137   {"audio/x-svx", "Amiga IFF / SVX8 / SV16", 0},
138   {"audio/x-tta", N_("Lossless True Audio (TTA)"), 0},
139   {"audio/x-ttafile", N_("Lossless True Audio (TTA)"), 0},
140   {"audio/x-vnd.sony.atrac3", "Sony ATRAC3", 0},
141   {"audio/x-vorbis", "Vorbis", 0},
142   {"audio/x-voc", "SoundBlaster VOC", 0},
143   {"audio/x-w64", "Sonic Foundry Wave64", 0},
144   {"audio/x-wav", "WAV", 0},
145   {"audio/x-wavpack", "Wavpack", 0},
146   {"audio/x-wavpack-correction", "Wavpack", 0},
147   {"audio/x-wms", N_("Windows Media Speech"), 0},
148   {"audio/x-voxware", "Voxware", 0},
149
150
151   /* video formats with static descriptions */
152   {"video/sp5x", "Sunplus JPEG 5.x", 0},
153   {"video/vivo", "Vivo", 0},
154   {"video/x-3ivx", "3ivx", 0},
155   {"video/x-4xm", "4X Techologies Video", 0},
156   {"video/x-apple-video", "Apple video", 0},
157   {"video/x-aasc", "Autodesk Animator", 0},
158   {"video/x-camtasia", "TechSmith Camtasia", 0},
159   {"video/x-cdxa", "RIFF/CDXA (VCD)", 0},
160   {"video/x-cinepak", "Cinepak Video", 0},
161   {"video/x-cirrus-logic-accupak", "Cirrus Logipak AccuPak", 0},
162   {"video/x-compressed-yuv", N_("CYUV Lossless"), 0},
163   {"video/x-dirac", "Dirac", 0},
164   {"video/x-dnxhd", "Digital Nonlinear Extensible High Definition (DNxHD)", 0},
165   /* FIXME 0.11: rename to subpicture/x-dvd or so */
166   {"video/x-dvd-subpicture", "DVD subpicture", 0},
167   {"video/x-ffv", N_("FFMpeg v1"), 0},
168   {"video/x-flash-screen", "Flash Screen Video", 0},
169   {"video/x-flash-video", "Sorenson Spark Video", 0},
170   {"video/x-h261", "H.261", 0},
171   {"video/x-huffyuv", "Huffyuv", 0},
172   {"video/x-intel-h263", "Intel H.263", 0},
173   {"video/x-jpeg", "Motion JPEG", 0},
174   /* { "video/x-jpeg-b", "", 0 }, does this actually exist? */
175   {"video/x-loco", "LOCO Lossless", 0},
176   {"video/x-mimic", "MIMIC", 0},
177   {"video/x-mjpeg", "Motion-JPEG", 0},
178   {"video/x-mjpeg-b", "Motion-JPEG format B", 0},
179   {"video/mpegts", "MPEG-2 Transport Stream", FLAG_CONTAINER},
180   {"video/x-mng", "Multiple Image Network Graphics (MNG)", 0},
181   {"video/x-mszh", N_("Lossless MSZH"), 0},
182   {"video/x-msvideocodec", "Microsoft Video 1", 0},
183   {"video/x-mve", "Interplay MVE", FLAG_CONTAINER},
184   {"video/x-nut", "NUT", FLAG_CONTAINER},
185   {"video/x-nuv", "MythTV NuppelVideo (NUV)", FLAG_CONTAINER},
186   {"video/x-qdrw", "Apple QuickDraw", 0},
187   {"video/x-raw-gray", N_("Uncompressed Gray Image"), 0},
188   {"video/x-smc", "Apple SMC", 0},
189   {"video/x-smoke", "Smoke", 0},
190   {"video/x-tarkin", "Tarkin", 0},
191   {"video/x-theora", "Theora", 0},
192   {"video/x-rle", N_("Run-length encoding"), 0},
193   {"video/x-ultimotion", "IBM UltiMotion", 0},
194   {"video/x-vcd", "VideoCD (VCD)", 0},
195   {"video/x-vmnc", "VMWare NC", 0},
196   {"video/x-vp3", "On2 VP3", 0},
197   {"video/x-vp5", "On2 VP5", 0},
198   {"video/x-vp6", "On2 VP6", 0},
199   {"video/x-vp6-flash", "On2 VP6/Flash", 0},
200   {"video/x-vp6-alpha", "On2 VP6 with alpha", 0},
201   {"video/x-vp7", "On2 VP7", 0},
202   {"video/x-vp8", "VP8", 0},
203   {"video/x-xvid", "XVID MPEG-4", 0},
204   {"video/x-zlib", "Lossless zlib video", 0},
205   {"video/x-zmbv", "Zip Motion Block video", 0},
206
207   /* image formats with static descriptions */
208   {"image/bmp", "BMP", 0},
209   {"image/x-bmp", "BMP", 0},
210   {"image/x-MS-bmp", "BMP", 0},
211   {"image/gif", "GIF", 0},
212   {"image/jpeg", "JPEG", 0},
213   {"image/jng", "JPEG Network Graphics (JNG)", 0},
214   {"image/png", "PNG", 0},
215   {"image/pbm", "Portable BitMap (PBM)", 0},
216   {"image/ppm", "Portable PixMap (PPM)", 0},
217   {"image/svg+xml", "Scalable Vector Graphics (SVG)", 0},
218   {"image/tiff", "TIFF", 0},
219   {"image/x-cmu-raster", "CMU Raster Format", 0},
220   {"image/x-icon", "ICO", 0},
221   {"image/x-j2c", "JPEG 2000", 0},
222   {"image/x-jpc", "JPEG 2000", 0},
223   {"image/jp2", "JPEG 2000", 0},
224   {"image/x-pcx", "PCX", 0},
225   {"image/x-xcf", "XFC", 0},
226   {"image/x-pixmap", "XPM", 0},
227   {"image/x-portable-anymap", "Portable AnyMap (PAM)", 0},
228   {"image/x-portable-graymap", "Portable GrayMap (PGM)", 0},
229   {"image/x-xpixmap", "XPM", 0},
230   {"image/x-quicktime", "QuickTime Image Format (QTIF)", 0},
231   {"image/x-sun-raster", "Sun Raster Format (RAS)", 0},
232   {"image/x-tga", "TGA", 0},
233
234   /* subtitle formats with static descriptions */
235   {"application/x-ass", "ASS", 0},
236   {"application/x-subtitle-sami", N_("Sami subtitle format"), 0},
237   {"application/x-subtitle-tmplayer", N_("TMPlayer subtitle format"), 0},
238   {"application/x-kate", "Kate", 0},
239   {"subtitle/x-kate", N_("Kate subtitle format"), 0},
240   {"subpicture/x-dvb", "DVB subtitles", 0},
241   /* add variant field to typefinder? { "application/x-subtitle", N_("subtitle"), 0}, */
242
243   /* non-audio/video/container formats */
244   {"hdv/aux-v", "HDV AUX-V", 0},
245   {"hdv/aux-a", "HDV AUX-A", 0},
246
247   /* formats with dynamic descriptions */
248   {"audio/mpeg", NULL, 0},
249   {"audio/x-adpcm", NULL, 0},
250   {"audio/x-mace", NULL, 0},
251   {"audio/x-pn-realaudio", NULL, 0},
252   {"audio/x-raw-int", NULL, 0},
253   {"audio/x-raw-float", NULL, 0},
254   {"audio/x-wma", NULL, 0},
255   {"video/mpeg", NULL, FLAG_CONTAINER | FLAG_SYSTEMSTREAM},
256   {"video/mpeg", NULL, 0},
257   {"video/x-asus", NULL, 0},
258   {"video/x-ati-vcr", NULL, 0},
259   {"video/x-divx", NULL, 0},
260   {"video/x-dv", "Digital Video (DV) System Stream",
261       FLAG_CONTAINER | FLAG_SYSTEMSTREAM},
262   {"video/x-dv", "Digital Video (DV)", 0},
263   {"video/x-h263", NULL, 0},
264   {"video/x-h264", NULL, 0},
265   {"video/x-indeo", NULL, 0},
266   {"video/x-msmpeg", NULL, 0},
267   {"video/x-pn-realvideo", NULL, 0},
268 #if 0
269   /* do these exist? are they used anywhere? */
270   {"video/x-pn-multirate-realvideo", NULL, 0},
271   {"audio/x-pn-multirate-realaudio", NULL, 0},
272   {"audio/x-pn-multirate-realaudio-live", NULL, 0},
273 #endif
274   {"video/x-truemotion", NULL, 0},
275   {"video/x-raw-rgb", NULL, 0},
276   {"video/x-raw-yuv", NULL, 0},
277   {"video/x-svq", NULL, 0},
278   {"video/x-wmv", NULL, 0},
279   {"video/x-xan", NULL, 0}
280 };
281
282 /* returns static descriptions and dynamic ones (such as video/x-raw-yuv),
283  * or NULL if caps aren't known at all */
284 static gchar *
285 format_info_get_desc (const FormatInfo * info, const GstCaps * caps)
286 {
287   const GstStructure *s;
288
289   g_assert (info != NULL);
290
291   if (info->desc != NULL)
292     return g_strdup (_(info->desc));
293
294   s = gst_caps_get_structure (caps, 0);
295
296   if (strcmp (info->type, "video/x-raw-yuv") == 0) {
297     const gchar *ret = NULL;
298     guint32 fourcc = 0;
299
300     gst_structure_get_fourcc (s, "format", &fourcc);
301     switch (fourcc) {
302       case GST_MAKE_FOURCC ('I', '4', '2', '0'):
303         ret = _("Uncompressed planar YUV 4:2:0");
304         break;
305       case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
306         ret = _("Uncompressed planar YVU 4:2:0");
307         break;
308       case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
309         ret = _("Uncompressed packed YUV 4:2:2");
310         break;
311       case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
312         ret = _("Uncompressed packed YUV 4:1:0");
313         break;
314       case GST_MAKE_FOURCC ('Y', 'V', 'U', '9'):
315         ret = _("Uncompressed packed YVU 4:1:0");
316         break;
317       case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
318       case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
319         ret = _("Uncompressed packed YUV 4:2:2");
320         break;
321       case GST_MAKE_FOURCC ('Y', '4', '1', 'P'):
322         ret = _("Uncompressed packed YUV 4:1:1");
323         break;
324       case GST_MAKE_FOURCC ('I', 'Y', 'U', '2'):
325         ret = _("Uncompressed packed YUV 4:4:4");
326         break;
327       case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
328         ret = _("Uncompressed planar YUV 4:2:2");
329         break;
330       case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
331         ret = _("Uncompressed planar YUV 4:1:1");
332         break;
333       case GST_MAKE_FOURCC ('Y', '8', '0', '0'):
334         ret = _("Uncompressed black and white Y-plane");
335         break;
336       default:
337         ret = _("Uncompressed YUV");
338         break;
339     }
340     return g_strdup (ret);
341   } else if (strcmp (info->type, "video/x-raw-rgb") == 0) {
342     const gchar *rgb_str;
343     gint depth = 0;
344
345     gst_structure_get_int (s, "depth", &depth);
346     rgb_str = gst_structure_has_field (s, "alpha_mask") ? "RGBA" : "RGB";
347     if (gst_structure_has_field (s, "paletted_data")) {
348       return g_strdup_printf (_("Uncompressed palettized %d-bit %s"), depth,
349           rgb_str);
350     } else {
351       return g_strdup_printf ("Uncompressed %d-bit %s", depth, rgb_str);
352     }
353   } else if (strcmp (info->type, "video/x-h263") == 0) {
354     const gchar *variant, *ret;
355
356     variant = gst_structure_get_string (s, "variant");
357     if (variant == NULL)
358       ret = "H.263";
359     else if (strcmp (variant, "itu") == 0)
360       ret = "ITU H.26n";        /* why not ITU H.263? (tpm) */
361     else if (strcmp (variant, "lead") == 0)
362       ret = "Lead H.263";
363     else if (strcmp (variant, "microsoft") == 0)
364       ret = "Microsoft H.263";
365     else if (strcmp (variant, "vdolive") == 0)
366       ret = "VDOLive";
367     else if (strcmp (variant, "vivo") == 0)
368       ret = "Vivo H.263";
369     else if (strcmp (variant, "xirlink") == 0)
370       ret = "Xirlink H.263";
371     else {
372       GST_WARNING ("Unknown H263 variant '%s'", variant);
373       ret = "H.263";
374     }
375     return g_strdup (ret);
376   } else if (strcmp (info->type, "video/x-h264") == 0) {
377     const gchar *variant, *ret;
378
379     variant = gst_structure_get_string (s, "variant");
380     if (variant == NULL)
381       ret = "H.264";
382     else if (strcmp (variant, "itu") == 0)
383       ret = "ITU H.264";
384     else if (strcmp (variant, "videosoft") == 0)
385       ret = "Videosoft H.264";
386     else if (strcmp (variant, "lead") == 0)
387       ret = "Lead H.264";
388     else {
389       GST_WARNING ("Unknown H264 variant '%s'", variant);
390       ret = "H.264";
391     }
392     return g_strdup (ret);
393   } else if (strcmp (info->type, "video/x-divx") == 0) {
394     gint ver = 0;
395
396     if (!gst_structure_get_int (s, "divxversion", &ver) || ver <= 2) {
397       GST_WARNING ("Unexpected DivX version in %" GST_PTR_FORMAT, caps);
398       return g_strdup ("DivX MPEG-4");
399     }
400     return g_strdup_printf (_("DivX MPEG-4 Version %d"), ver);
401   } else if (strcmp (info->type, "video/x-msmpeg") == 0) {
402     gint ver = 0;
403
404     if (!gst_structure_get_int (s, "msmpegversion", &ver) ||
405         ver < 40 || ver > 49) {
406       GST_WARNING ("Unexpected msmpegversion in %" GST_PTR_FORMAT, caps);
407       return g_strdup ("Microsoft MPEG-4 4.x");
408     }
409     return g_strdup_printf ("Microsoft MPEG-4 4.%d", ver % 10);
410   } else if (strcmp (info->type, "video/x-truemotion") == 0) {
411     gint ver = 0;
412
413     gst_structure_get_int (s, "trueversion", &ver);
414     switch (ver) {
415       case 1:
416         return g_strdup_printf ("Duck TrueMotion 1");
417       case 2:
418         return g_strdup_printf ("TrueMotion 2.0");
419       default:
420         GST_WARNING ("Unexpected trueversion in %" GST_PTR_FORMAT, caps);
421         break;
422     }
423     return g_strdup_printf ("TrueMotion");
424   } else if (strcmp (info->type, "video/x-xan") == 0) {
425     gint ver = 0;
426
427     if (!gst_structure_get_int (s, "wcversion", &ver) || ver < 1) {
428       GST_WARNING ("Unexpected wcversion in %" GST_PTR_FORMAT, caps);
429       return g_strdup ("Xan Wing Commander");
430     }
431     return g_strdup_printf ("Xan Wing Commander %u", ver);
432   } else if (strcmp (info->type, "video/x-indeo") == 0) {
433     gint ver = 0;
434
435     if (!gst_structure_get_int (s, "indeoversion", &ver) || ver < 2) {
436       GST_WARNING ("Unexpected indeoversion in %" GST_PTR_FORMAT, caps);
437       return g_strdup ("Intel Indeo");
438     }
439     return g_strdup_printf ("Intel Indeo %u", ver);
440   } else if (strcmp (info->type, "audio/x-wma") == 0) {
441     gint ver = 0;
442
443     gst_structure_get_int (s, "wmaversion", &ver);
444     switch (ver) {
445       case 1:
446       case 2:
447       case 3:
448         return g_strdup_printf ("Windows Media Audio %d", ver + 6);
449       default:
450         break;
451     }
452     GST_WARNING ("Unexpected wmaversion in %" GST_PTR_FORMAT, caps);
453     return g_strdup ("Windows Media Audio");
454   } else if (strcmp (info->type, "video/x-wmv") == 0) {
455     gint ver = 0;
456
457     gst_structure_get_int (s, "wmvversion", &ver);
458     switch (ver) {
459       case 1:
460       case 2:
461       case 3:
462         return g_strdup_printf ("Windows Media Video %d", ver + 6);
463       default:
464         break;
465     }
466     GST_WARNING ("Unexpected wmvversion in %" GST_PTR_FORMAT, caps);
467     return g_strdup ("Windows Media Video");
468   } else if (strcmp (info->type, "audio/x-mace") == 0) {
469     gint ver = 0;
470
471     gst_structure_get_int (s, "maceversion", &ver);
472     if (ver == 3 || ver == 6) {
473       return g_strdup_printf ("MACE-%d", ver);
474     } else {
475       GST_WARNING ("Unexpected maceversion in %" GST_PTR_FORMAT, caps);
476       return g_strdup ("MACE");
477     }
478   } else if (strcmp (info->type, "video/x-svq") == 0) {
479     gint ver = 0;
480
481     gst_structure_get_int (s, "svqversion", &ver);
482     if (ver == 1 || ver == 3) {
483       return g_strdup_printf ("Sorensen Video %d", ver);
484     } else {
485       GST_WARNING ("Unexpected svqversion in %" GST_PTR_FORMAT, caps);
486       return g_strdup ("Sorensen Video");
487     }
488   } else if (strcmp (info->type, "video/x-asus") == 0) {
489     gint ver = 0;
490
491     gst_structure_get_int (s, "asusversion", &ver);
492     if (ver == 1 || ver == 2) {
493       return g_strdup_printf ("Asus Video %d", ver);
494     } else {
495       GST_WARNING ("Unexpected asusversion in %" GST_PTR_FORMAT, caps);
496       return g_strdup ("Asus Video");
497     }
498   } else if (strcmp (info->type, "video/x-ati-vcr") == 0) {
499     gint ver = 0;
500
501     gst_structure_get_int (s, "vcrversion", &ver);
502     if (ver == 1 || ver == 2) {
503       return g_strdup_printf ("ATI VCR %d", ver);
504     } else {
505       GST_WARNING ("Unexpected acrversion in %" GST_PTR_FORMAT, caps);
506       return g_strdup ("ATI VCR");
507     }
508   } else if (strcmp (info->type, "audio/x-adpcm") == 0) {
509     const GValue *layout_val;
510
511     layout_val = gst_structure_get_value (s, "layout");
512     if (layout_val != NULL && G_VALUE_HOLDS_STRING (layout_val)) {
513       const gchar *layout;
514
515       if ((layout = g_value_get_string (layout_val))) {
516         gchar *layout_upper, *ret;
517
518         if (strcmp (layout, "swf") == 0)
519           return g_strdup ("Shockwave ADPCM");
520         if (strcmp (layout, "microsoft") == 0)
521           return g_strdup ("Microsoft ADPCM");
522         if (strcmp (layout, "quicktime") == 0)
523           return g_strdup ("Quicktime ADPCM");
524         if (strcmp (layout, "westwood") == 0)
525           return g_strdup ("Westwood ADPCM");
526         if (strcmp (layout, "yamaha") == 0)
527           return g_strdup ("Yamaha ADPCM");
528         /* FIXME: other layouts: sbpro2, sbpro3, sbpro4, ct, g726, ea,
529          * adx, xa, 4xm, smjpeg, dk4, dk3, dvi */
530         layout_upper = g_ascii_strup (layout, -1);
531         ret = g_strdup_printf ("%s ADPCM", layout_upper);
532         g_free (layout_upper);
533         return ret;
534       }
535     }
536     return g_strdup ("ADPCM");
537   } else if (strcmp (info->type, "audio/mpeg") == 0) {
538     gint ver = 0, layer = 0;
539
540     gst_structure_get_int (s, "mpegversion", &ver);
541
542     switch (ver) {
543       case 1:
544         gst_structure_get_int (s, "layer", &layer);
545         switch (layer) {
546           case 1:
547           case 2:
548           case 3:
549             return g_strdup_printf ("MPEG-1 Layer %d (MP%d)", layer, layer);
550           default:
551             break;
552         }
553         GST_WARNING ("Unexpected MPEG-1 layer in %" GST_PTR_FORMAT, caps);
554         return g_strdup ("MPEG-1 Audio");
555       case 4:
556         return g_strdup ("MPEG-4 AAC");
557       default:
558         break;
559     }
560     GST_WARNING ("Unexpected audio mpegversion in %" GST_PTR_FORMAT, caps);
561     return g_strdup ("MPEG Audio");
562   } else if (strcmp (info->type, "audio/x-pn-realaudio") == 0) {
563     gint ver = 0;
564
565     gst_structure_get_int (s, "raversion", &ver);
566     switch (ver) {
567       case 1:
568         return g_strdup ("RealAudio 14k4bps");
569       case 2:
570         return g_strdup ("RealAudio 28k8bps");
571       case 8:
572         return g_strdup ("RealAudio G2 (Cook)");
573       default:
574         break;
575     }
576     GST_WARNING ("Unexpected raversion in %" GST_PTR_FORMAT, caps);
577     return g_strdup ("RealAudio");
578   } else if (strcmp (info->type, "video/x-pn-realvideo") == 0) {
579     gint ver = 0;
580
581     gst_structure_get_int (s, "rmversion", &ver);
582     switch (ver) {
583       case 1:
584         return g_strdup ("RealVideo 1.0");
585       case 2:
586         return g_strdup ("RealVideo 2.0");
587       case 3:
588         return g_strdup ("RealVideo 3.0");
589       case 4:
590         return g_strdup ("RealVideo 4.0");
591       default:
592         break;
593     }
594     GST_WARNING ("Unexpected rmversion in %" GST_PTR_FORMAT, caps);
595     return g_strdup ("RealVideo");
596   } else if (strcmp (info->type, "video/mpeg") == 0) {
597     gboolean sysstream;
598     gint ver = 0;
599
600     if (!gst_structure_get_boolean (s, "systemstream", &sysstream) ||
601         !gst_structure_get_int (s, "mpegversion", &ver) || ver < 1 || ver > 4) {
602       GST_WARNING ("Missing fields in mpeg video caps %" GST_PTR_FORMAT, caps);
603     } else {
604       if (sysstream) {
605         return g_strdup_printf ("MPEG-%d System Stream", ver);
606       } else {
607         return g_strdup_printf ("MPEG-%d Video", ver);
608       }
609     }
610     return g_strdup ("MPEG Video");
611   } else if (strcmp (info->type, "audio/x-raw-int") == 0) {
612     gint bitdepth = 0;
613
614     /* 8-bit pcm might not have depth field (?) */
615     if (!gst_structure_get_int (s, "depth", &bitdepth))
616       gst_structure_get_int (s, "width", &bitdepth);
617     if (bitdepth != 0)
618       return g_strdup_printf (_("Raw %d-bit PCM audio"), bitdepth);
619     else
620       return g_strdup (_("Raw PCM audio"));
621   } else if (strcmp (info->type, "audio/x-raw-float") == 0) {
622     gint bitdepth = 0;
623
624     gst_structure_get_int (s, "width", &bitdepth);
625     if (bitdepth != 0)
626       return g_strdup_printf (_("Raw %d-bit floating-point audio"), bitdepth);
627     else
628       return g_strdup (_("Raw floating-point audio"));
629   }
630
631   return NULL;
632 }
633
634 /* returns format info structure, will return NULL for dynamic media types! */
635 static const FormatInfo *
636 find_format_info (const GstCaps * caps)
637 {
638   const GstStructure *s;
639   const gchar *media_type;
640   guint i;
641
642   s = gst_caps_get_structure (caps, 0);
643   media_type = gst_structure_get_name (s);
644
645   for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
646     if (strcmp (media_type, formats[i].type) == 0) {
647       gboolean is_sys = FALSE;
648
649       if ((formats[i].flags & FLAG_SYSTEMSTREAM) == 0)
650         return &formats[i];
651
652       /* this record should only be matched if the systemstream field is set */
653       if (gst_structure_get_boolean (s, "systemstream", &is_sys) && is_sys)
654         return &formats[i];
655     }
656   }
657
658   return NULL;
659 }
660
661 static gboolean
662 caps_are_rtp_caps (const GstCaps * caps, const gchar * media, gchar ** format)
663 {
664   const GstStructure *s;
665   const gchar *str;
666
667   g_assert (media != NULL && format != NULL);
668
669   s = gst_caps_get_structure (caps, 0);
670   if (!gst_structure_has_name (s, "application/x-rtp"))
671     return FALSE;
672   if (!gst_structure_has_field_typed (s, "media", G_TYPE_STRING))
673     return FALSE;
674   str = gst_structure_get_string (s, "media");
675   if (str == NULL || !g_str_equal (str, media))
676     return FALSE;
677   str = gst_structure_get_string (s, "encoding-name");
678   if (str == NULL || *str == '\0')
679     return FALSE;
680
681   if (strcmp (str, "X-ASF-PF") == 0) {
682     *format = g_strdup ("Windows Media");
683   } else if (g_str_has_prefix (str, "X-")) {
684     *format = g_strdup (str + 2);
685   } else {
686     *format = g_strdup (str);
687   }
688
689   return TRUE;
690 }
691
692 /**
693  * gst_pb_utils_get_source_description:
694  * @protocol: the protocol the source element needs to handle, e.g. "http"
695  *
696  * Returns a localised string describing a source element handling the protocol
697  * specified in @protocol, for use in error dialogs or other messages to be
698  * seen by the user. Should never return NULL unless @protocol is invalid.
699  *
700  * This function is mainly for internal use, applications would typically
701  * use gst_missing_plugin_message_get_description() to get a description of
702  * a missing feature from a missing-plugin message.
703  *
704  * Returns: a newly-allocated description string, or NULL on error. Free
705  *          string with g_free() when not needed any longer.
706  */
707 gchar *
708 gst_pb_utils_get_source_description (const gchar * protocol)
709 {
710   gchar *proto_uc, *ret;
711
712   g_return_val_if_fail (protocol != NULL, NULL);
713
714   if (strcmp (protocol, "cdda") == 0)
715     return g_strdup (_("Audio CD source"));
716
717   if (strcmp (protocol, "dvd") == 0)
718     return g_strdup (_("DVD source"));
719
720   if (strcmp (protocol, "rtsp") == 0)
721     return g_strdup (_("Real Time Streaming Protocol (RTSP) source"));
722
723   /* TODO: what about mmst, mmsu, mmsh? */
724   if (strcmp (protocol, "mms") == 0)
725     return g_strdup (_("Microsoft Media Server (MMS) protocol source"));
726
727   /* make protocol uppercase */
728   proto_uc = g_ascii_strup (protocol, -1);
729
730   /* TODO: find out how to add a comment for translators to the source code
731    * (and tell them to make the first letter uppercase below if they move
732    * the protocol to the middle or end of the string) */
733   ret = g_strdup_printf (_("%s protocol source"), proto_uc);
734
735   g_free (proto_uc);
736
737   return ret;
738 }
739
740 /**
741  * gst_pb_utils_get_sink_description:
742  * @protocol: the protocol the sink element needs to handle, e.g. "http"
743  *
744  * Returns a localised string describing a sink element handling the protocol
745  * specified in @protocol, for use in error dialogs or other messages to be
746  * seen by the user. Should never return NULL unless @protocol is invalid.
747  *
748  * This function is mainly for internal use, applications would typically
749  * use gst_missing_plugin_message_get_description() to get a description of
750  * a missing feature from a missing-plugin message.
751  *
752  * Returns: a newly-allocated description string, or NULL on error. Free
753  *          string with g_free() when not needed any longer.
754  */
755 gchar *
756 gst_pb_utils_get_sink_description (const gchar * protocol)
757 {
758   gchar *proto_uc, *ret;
759
760   g_return_val_if_fail (protocol != NULL, NULL);
761
762   /* make protocol uppercase */
763   proto_uc = g_ascii_strup (protocol, -1);
764
765   /* TODO: find out how to add a comment for translators to the source code
766    * (and tell them to make the first letter uppercase below if they move
767    * the protocol to the middle or end of the string) */
768   ret = g_strdup_printf ("%s protocol sink", proto_uc);
769
770   g_free (proto_uc);
771
772   return ret;
773 }
774
775 /**
776  * gst_pb_utils_get_decoder_description:
777  * @caps: the (fixed) #GstCaps for which an decoder description is needed
778  *
779  * Returns a localised string describing an decoder for the format specified
780  * in @caps, for use in error dialogs or other messages to be seen by the user.
781  * Should never return NULL unless @factory_name or @caps are invalid.
782  *
783  * This function is mainly for internal use, applications would typically
784  * use gst_missing_plugin_message_get_description() to get a description of
785  * a missing feature from a missing-plugin message.
786  *
787  * Returns: a newly-allocated description string, or NULL on error. Free
788  *          string with g_free() when not needed any longer.
789  */
790 gchar *
791 gst_pb_utils_get_decoder_description (const GstCaps * caps)
792 {
793   gchar *str, *ret;
794   GstCaps *tmp;
795
796   g_return_val_if_fail (caps != NULL, NULL);
797   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
798
799   tmp = copy_and_clean_caps (caps);
800
801   g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
802
803   /* special-case RTP caps */
804   if (caps_are_rtp_caps (tmp, "video", &str)) {
805     ret = g_strdup_printf (_("%s video RTP depayloader"), str);
806   } else if (caps_are_rtp_caps (tmp, "audio", &str)) {
807     ret = g_strdup_printf (_("%s audio RTP depayloader"), str);
808   } else if (caps_are_rtp_caps (tmp, "application", &str)) {
809     ret = g_strdup_printf (_("%s RTP depayloader"), str);
810   } else {
811     const FormatInfo *info;
812
813     str = gst_pb_utils_get_codec_description (tmp);
814     info = find_format_info (tmp);
815     if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) {
816       ret = g_strdup_printf (_("%s demuxer"), str);
817     } else {
818       ret = g_strdup_printf (_("%s decoder"), str);
819     }
820   }
821
822   g_free (str);
823   gst_caps_unref (tmp);
824
825   return ret;
826 }
827
828 /**
829  * gst_pb_utils_get_encoder_description:
830  * @caps: the (fixed) #GstCaps for which an encoder description is needed
831  *
832  * Returns a localised string describing an encoder for the format specified
833  * in @caps, for use in error dialogs or other messages to be seen by the user.
834  * Should never return NULL unless @factory_name or @caps are invalid.
835  *
836  * This function is mainly for internal use, applications would typically
837  * use gst_missing_plugin_message_get_description() to get a description of
838  * a missing feature from a missing-plugin message.
839  *
840  * Returns: a newly-allocated description string, or NULL on error. Free
841  *          string with g_free() when not needed any longer.
842  */
843 gchar *
844 gst_pb_utils_get_encoder_description (const GstCaps * caps)
845 {
846   gchar *str, *ret;
847   GstCaps *tmp;
848
849   g_return_val_if_fail (caps != NULL, NULL);
850   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
851   tmp = copy_and_clean_caps (caps);
852   g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
853
854   /* special-case RTP caps */
855   if (caps_are_rtp_caps (tmp, "video", &str)) {
856     ret = g_strdup_printf (_("%s video RTP payloader"), str);
857   } else if (caps_are_rtp_caps (tmp, "audio", &str)) {
858     ret = g_strdup_printf (_("%s audio RTP payloader"), str);
859   } else if (caps_are_rtp_caps (tmp, "application", &str)) {
860     ret = g_strdup_printf (_("%s RTP payloader"), str);
861   } else {
862     const FormatInfo *info;
863
864     str = gst_pb_utils_get_codec_description (tmp);
865     info = find_format_info (tmp);
866     if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) {
867       ret = g_strdup_printf (_("%s muxer"), str);
868     } else {
869       ret = g_strdup_printf (_("%s encoder"), str);
870     }
871   }
872
873   g_free (str);
874   gst_caps_unref (tmp);
875
876   return ret;
877 }
878
879 /**
880  * gst_pb_utils_get_element_description:
881  * @factory_name: the name of the element, e.g. "gnomevfssrc"
882  *
883  * Returns a localised string describing the given element, for use in
884  * error dialogs or other messages to be seen by the user. Should never
885  * return NULL unless @factory_name is invalid.
886  *
887  * This function is mainly for internal use, applications would typically
888  * use gst_missing_plugin_message_get_description() to get a description of
889  * a missing feature from a missing-plugin message.
890  *
891  * Returns: a newly-allocated description string, or NULL on error. Free
892  *          string with g_free() when not needed any longer.
893  */
894 gchar *
895 gst_pb_utils_get_element_description (const gchar * factory_name)
896 {
897   gchar *ret;
898
899   g_return_val_if_fail (factory_name != NULL, NULL);
900
901   ret = g_strdup_printf (_("GStreamer element %s"), factory_name);
902   if (ret && g_str_has_prefix (ret, factory_name))
903     *ret = g_ascii_toupper (*ret);
904
905   return ret;
906 }
907
908 /**
909  * gst_pb_utils_add_codec_description_to_tag_list:
910  * @taglist: a #GstTagList
911  * @codec_tag: a GStreamer codec tag such as #GST_TAG_AUDIO_CODEC,
912  *             #GST_TAG_VIDEO_CODEC or #GST_TAG_CODEC
913  * @caps: the (fixed) #GstCaps for which a codec tag should be added.
914  *
915  * Adds a codec tag describing the format specified by @caps to @taglist.
916  *
917  * Returns: TRUE if a codec tag was added, FALSE otherwise.
918  */
919 gboolean
920 gst_pb_utils_add_codec_description_to_tag_list (GstTagList * taglist,
921     const gchar * codec_tag, const GstCaps * caps)
922 {
923   const FormatInfo *info;
924   gchar *desc;
925
926   g_return_val_if_fail (taglist != NULL, FALSE);
927   g_return_val_if_fail (GST_IS_TAG_LIST (taglist), FALSE);
928   g_return_val_if_fail (codec_tag != NULL, FALSE);
929   g_return_val_if_fail (gst_tag_exists (codec_tag), FALSE);
930   g_return_val_if_fail (gst_tag_get_type (codec_tag) == G_TYPE_STRING, FALSE);
931   g_return_val_if_fail (caps != NULL, FALSE);
932   g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
933
934   info = find_format_info (caps);
935   if (info == NULL)
936     return FALSE;
937
938   desc = format_info_get_desc (info, caps);
939   gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, codec_tag, desc, NULL);
940   g_free (desc);
941
942   return TRUE;
943 }
944
945 /**
946  * gst_pb_utils_get_codec_description:
947  * @caps: the (fixed) #GstCaps for which an format description is needed
948  *
949  * Returns a localised (as far as this is possible) string describing the
950  * media format specified in @caps, for use in error dialogs or other messages
951  * to be seen by the user. Should never return NULL unless @caps is invalid.
952  *
953  * Also see the convenience function
954  * gst_pb_utils_add_codec_description_to_tag_list().
955  *
956  * Returns: a newly-allocated description string, or NULL on error. Free
957  *          string with g_free() when not needed any longer.
958  */
959 gchar *
960 gst_pb_utils_get_codec_description (const GstCaps * caps)
961 {
962   const FormatInfo *info;
963   gchar *str, *comma;
964   GstCaps *tmp;
965
966   g_return_val_if_fail (caps != NULL, NULL);
967   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
968   tmp = copy_and_clean_caps (caps);
969   g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
970
971   info = find_format_info (tmp);
972
973   if (info) {
974     str = format_info_get_desc (info, tmp);
975   } else {
976     str = gst_caps_to_string (tmp);
977
978     /* cut off everything after the media type, if there is anything */
979     if ((comma = strchr (str, ','))) {
980       *comma = '\0';
981       g_strchomp (str);
982       /* we could do something more elaborate here, like taking into account
983        * audio/, video/, image/ and application/ prefixes etc. */
984     }
985
986     GST_WARNING ("No description available for media type: %s", str);
987   }
988   gst_caps_unref (tmp);
989
990   return str;
991 }
992
993 #if 0
994 void
995 gst_pb_utils_list_all (void)
996 {
997   gint i;
998
999   g_print ("static const gchar *caps_strings[] = { ");
1000
1001   for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
1002     if (formats[i].desc != NULL)
1003       g_print ("  \"%s\", ", formats[i].type);
1004   }
1005   g_print ("\n#if 0\n");
1006   for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
1007     if (formats[i].desc == NULL)
1008       g_print ("  \"%s\", \n", formats[i].type);
1009   }
1010   g_print ("\n#endif\n");
1011 }
1012 #endif