pbutils: Avoid assertion describing raw audio caps without format
[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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /**
21  * SECTION:gstpbutilsdescriptions
22  * @title: Descriptions
23  * @short_description: Provides human-readable descriptions for caps/codecs
24  * and encoder, decoder, URI source and URI sink elements
25  *
26  * The above functions provide human-readable strings for media formats
27  * and decoder/demuxer/depayloader/encoder/muxer/payloader elements for use
28  * in error dialogs or other messages shown to users.
29  *
30  * gst_pb_utils_add_codec_description_to_tag_list() is a utility function
31  * for demuxer and decoder elements to add audio/video codec tags from a
32  * given (fixed) #GstCaps.
33  *
34  */
35
36 #ifdef HAVE_CONFIG_H
37 # include "config.h"
38 #endif
39
40 #include "gst/gst-i18n-plugin.h"
41
42 #include <gst/audio/audio.h>
43 #include <gst/video/video.h>
44
45 #include "pbutils.h"
46 #include "pbutils-private.h"
47
48 #include <string.h>
49
50 typedef enum
51 {
52   FLAG_SYSTEMSTREAM = (1 << 0), /* match record only if caps have systemstream=true   */
53   FLAG_CONTAINER = (1 << 1),    /* format is a container format (muxed)               */
54   FLAG_AUDIO = (1 << 2),        /* format is an audio format, or audio container/tag  */
55   FLAG_VIDEO = (1 << 3),        /* format is a video format, or video container/tag   */
56   FLAG_IMAGE = (1 << 4),        /* format is an image format, or image container/tag  */
57   FLAG_SUB = (1 << 5),          /* format is a subtitle format, or subtitle container */
58   FLAG_TAG = (1 << 6),          /* format is a tag/container                          */
59   FLAG_GENERIC = (1 << 7)       /* format is a generic container (e.g. multipart)     */
60 } FormatFlags;
61
62 typedef struct
63 {
64   const gchar *type;
65   const gchar *desc;
66   FormatFlags flags:24;
67   gchar ext[5];                 /* file extension */
68 } FormatInfo;
69
70 #define AV_CONTAINER    (FLAG_CONTAINER | FLAG_AUDIO | FLAG_VIDEO)
71 #define AVS_CONTAINER   (AV_CONTAINER | FLAG_SUB)
72 #define AVI_CONTAINER   (AV_CONTAINER | FLAG_IMAGE)
73 #define AVIS_CONTAINER  (AV_CONTAINER | FLAG_IMAGE | FLAG_SUB)
74 #define AUDIO_CONTAINER (FLAG_CONTAINER | FLAG_AUDIO)
75 #define VIDEO_CONTAINER (FLAG_CONTAINER | FLAG_VIDEO)
76 #define AUDIO_TAG       (AUDIO_CONTAINER | FLAG_TAG)
77
78 static const FormatInfo formats[] = {
79   /* container/tag formats with static descriptions */
80   /* FIXME: does anyone use oga in practice? */
81   {"audio/ogg", "Ogg", AUDIO_CONTAINER, "ogg"},
82   {"audio/webm", "WebM", AUDIO_CONTAINER, "webm"},
83   {"audio/x-matroska", "Matroska", AUDIO_CONTAINER, "mka"},
84   {"application/gxf", "General Exchange Format (GXF)", AVI_CONTAINER, "gxf"},
85   {"application/ogg", "Ogg", AVIS_CONTAINER, "ogg"},
86   {"application/kate", "Ogg", FLAG_CONTAINER | FLAG_SUB, "ogg"},
87   {"application/mxf", "Material eXchange Format (MXF)", AVIS_CONTAINER, "mxf"},
88   {"application/vnd.rn-realmedia", "Realmedia", AV_CONTAINER, "rm"},
89   {"application/x-id3", N_("ID3 tag"), AUDIO_TAG, ""},
90   {"application/x-ape", N_("APE tag"), AUDIO_TAG, ""},
91   {"application/x-apetag", N_("APE tag"), AUDIO_TAG, ""},
92   {"application/x-icy", N_("ICY internet radio"), AUDIO_TAG, ""},
93   {"application/x-3gp", "3GP", AV_CONTAINER, "3gp"},
94   {"application/x-pn-realaudio", "RealAudio", AUDIO_CONTAINER, "ra"},
95   {"application/x-yuv4mpeg", "Y4M", VIDEO_CONTAINER, "y4m"},
96   {"multipart/x-mixed-replace", "Multipart", FLAG_CONTAINER | FLAG_GENERIC, ""},
97   {"video/ogg", "Ogg", AVIS_CONTAINER, "ogv"},
98   {"video/x-fli", "FLI/FLC/FLX Animation", VIDEO_CONTAINER, "fli"},
99   {"video/x-flv", "Flash", AV_CONTAINER, "flv"},
100   {"video/x-matroska", "Matroska", AVIS_CONTAINER, "mkv"},
101   /* FIXME: does anyone use .mk3d in practice, rather than .mkv? */
102   {"video/x-matroska-3d", "Matroska", AVIS_CONTAINER, "mk3d"},
103   {"video/webm", "WebM", AVS_CONTAINER, "webm"},
104   {"video/x-ms-asf", "Advanced Streaming Format (ASF)", AVIS_CONTAINER, "asf"},
105   {"video/x-msvideo", "Audio Video Interleave (AVI)", AVIS_CONTAINER, "avi"},
106   {"video/x-quicktime", "Quicktime", AVIS_CONTAINER, "mov"},
107   {"video/quicktime", "Quicktime", AVIS_CONTAINER, "mov"},
108   {"video/mj2", "Motion JPEG 2000", AVIS_CONTAINER, "mj2"},
109
110   /* audio formats with static descriptions */
111   {"audio/x-ac3", "AC-3 (ATSC A/52)", FLAG_AUDIO, "ac3"},
112   {"audio/ac3", "AC-3 (ATSC A/52)", FLAG_AUDIO, "ac3"},
113   {"audio/x-private-ac3", "DVD AC-3 (ATSC A/52)", FLAG_AUDIO, "ac3"},
114   {"audio/x-private1-ac3", "DVD AC-3 (ATSC A/52)", FLAG_AUDIO, "ac3"},
115   {"audio/x-alaw", "A-Law", FLAG_AUDIO, ""},
116   {"audio/amr", "Adaptive Multi Rate (AMR)", FLAG_AUDIO, "amr"},
117   {"audio/AMR", "Adaptive Multi Rate (AMR)", FLAG_AUDIO, "amr"},
118   {"audio/AMR-WB", "Adaptive Multi Rate WideBand (AMR-WB)", FLAG_AUDIO, "amr"},
119   {"audio/iLBC-sh", "Internet Low Bitrate Codec (iLBC)", AUDIO_CONTAINER,
120       "ilbc"},
121   {"audio/ms-gsm", "MS GSM", FLAG_AUDIO, "gsm"},
122   {"audio/qcelp", "QCELP", FLAG_AUDIO, ""},
123   {"audio/aiff", "Audio Interchange File Format (AIFF)", AUDIO_CONTAINER,
124       "aiff"},
125   {"audio/x-aiff", "Audio Interchange File Format (AIFF)", AUDIO_CONTAINER,
126       "aiff"},
127   {"audio/x-alac", N_("Apple Lossless Audio (ALAC)"), FLAG_AUDIO, ""},
128   {"audio/x-amr-nb-sh", "Adaptive Multi Rate NarrowBand (AMR-NB)",
129       AUDIO_CONTAINER, "amr"},
130   {"audio/x-amr-wb-sh", "Adaptive Multi Rate WideBand (AMR-WB)",
131       AUDIO_CONTAINER, "amr"},
132   {"audio/x-au", "Sun .au", AUDIO_CONTAINER, "au"},
133   {"audio/x-audible", "Audible Audio", AUDIO_CONTAINER, "aa"},
134   {"audio/x-caf", "Apple Core Audio Format", AUDIO_CONTAINER, "caf"},
135   {"audio/x-celt", "Constrained Energy Lapped Transform (CELT)", FLAG_AUDIO,
136       ""},
137   {"audio/x-cinepak", "Cinepak Audio", FLAG_AUDIO, ""},
138   {"audio/x-dpcm", "DPCM", FLAG_AUDIO, ""},
139   {"audio/x-dts", "DTS", FLAG_AUDIO, "dts"},
140   {"audio/x-private1-dts", "DTS", FLAG_AUDIO, "dts"},
141   {"audio/x-dv", "DV Audio", FLAG_AUDIO, ""},
142   {"audio/x-eac3", "E-AC-3 (ATSC A/52B)", FLAG_AUDIO, "eac3"},
143   {"audio/x-flac", N_("Free Lossless Audio Codec (FLAC)"), FLAG_AUDIO, "flac"},
144   {"audio/x-gsm", "GSM", FLAG_AUDIO, "gsm"},
145   {"audio/x-iec958", "S/PDIF IEC958", 0, ""},   /* TODO: check description */
146   {"audio/x-iLBC", "Internet Low Bitrate Codec (iLBC)", FLAG_AUDIO, "ilbc"},
147   {"audio/x-ircam", "Berkeley/IRCAM/CARL", FLAG_AUDIO, ""},
148   {"audio/x-lpcm", "LPCM", FLAG_AUDIO, ""},
149   {"audio/x-private1-lpcm", "DVD LPCM", FLAG_AUDIO, ""},
150   {"audio/x-m4a", "MPEG-4 AAC", FLAG_CONTAINER, "m4a"},
151   {"audio/x-mod", "Module Music Format (MOD)", FLAG_AUDIO, "mod"},
152   {"audio/x-mulaw", "Mu-Law", FLAG_AUDIO, ""},
153   {"audio/x-musepack", "Musepack (MPC)", FLAG_AUDIO, "mpc"},
154   {"audio/x-nellymoser", "Nellymoser Asao", FLAG_AUDIO, ""},
155   {"audio/x-nist", "Sphere NIST", FLAG_AUDIO, ""},
156   {"audio/x-nsf", "Nintendo NSF", FLAG_AUDIO, ""},
157   {"audio/x-opus", "Opus", FLAG_AUDIO, ""},
158   {"audio/x-paris", "Ensoniq PARIS", FLAG_AUDIO, ""},
159   {"audio/x-qdm", "QDesign Music (QDM)", FLAG_AUDIO, ""},
160   {"audio/x-qdm2", "QDesign Music (QDM) 2", FLAG_AUDIO, ""},
161   {"audio/x-ralf-mpeg4-generic", "Real Audio Lossless (RALF)", FLAG_AUDIO, ""},
162   {"audio/x-rf64", "Broadcast Wave Format", AUDIO_CONTAINER, "rf64"},
163   {"audio/x-sbc", "Low Complexity Subband Coding", FLAG_AUDIO, "sbc"},
164   {"audio/x-sds", "Midi Sample Dump Standard", FLAG_AUDIO, ""},
165   {"audio/x-shorten", "Shorten Lossless", FLAG_AUDIO, "shn"},
166   {"audio/x-sid", "Sid", FLAG_AUDIO, "sid"},
167   {"audio/x-sipro", "Sipro/ACELP.NET Voice", FLAG_AUDIO, ""},
168   {"audio/x-siren", "Siren", FLAG_AUDIO, ""},
169   {"audio/x-spc", "SNES-SPC700 Sound File Data", FLAG_AUDIO, "spc"},
170   {"audio/x-speex", "Speex", FLAG_AUDIO, ""},
171   {"audio/x-svx", "Amiga IFF / SVX8 / SV16", FLAG_AUDIO, ""},
172   {"audio/x-true-hd", "Dolby TrueHD", FLAG_AUDIO, ""},
173   {"audio/x-tta", N_("Lossless True Audio (TTA)"), FLAG_AUDIO, "tta"},
174   {"audio/x-ttafile", N_("Lossless True Audio (TTA)"), FLAG_AUDIO, "tta"},
175   {"audio/x-vnd.sony.atrac3", "Sony ATRAC3", FLAG_AUDIO, ""},
176   {"audio/x-vorbis", "Vorbis", FLAG_AUDIO, ""},
177   {"audio/x-voc", "SoundBlaster VOC", FLAG_AUDIO, ""},
178   {"audio/x-w64", "Sonic Foundry Wave64", AUDIO_CONTAINER, "w64"},
179   {"audio/x-wav", "WAV", AUDIO_CONTAINER, "wav"},
180   {"audio/x-wavpack", "Wavpack", FLAG_AUDIO, "wp"},
181   {"audio/x-wavpack-correction", "Wavpack", 0, "wpc"},
182   {"audio/x-wms", N_("Windows Media Speech"), FLAG_AUDIO, ""},
183   {"audio/x-voxware", "Voxware", FLAG_AUDIO, ""},
184   {"audio/x-xi", "Fasttracker 2 Extended Instrument", FLAG_AUDIO, "xi"},
185
186
187   /* video formats with static descriptions */
188   {"video/sp5x", "Sunplus JPEG 5.x", FLAG_VIDEO, ""},
189   {"video/vivo", "Vivo", FLAG_VIDEO, ""},
190   {"video/x-4xm", "4X Technologies Video", FLAG_VIDEO, ""},
191   {"video/x-apple-video", "Apple video", FLAG_VIDEO, ""},
192   {"video/x-aasc", "Autodesk Animator", FLAG_VIDEO, ""},
193   {"video/x-camtasia", "TechSmith Camtasia", FLAG_VIDEO, ""},
194   {"video/x-cavs", "Chinese AVS (CAVS)", FLAG_VIDEO, ""},
195   {"video/x-cdxa", "RIFF/CDXA (VCD)", AV_CONTAINER, ""},
196   {"video/x-cinepak", "Cinepak Video", FLAG_VIDEO, ""},
197   {"video/x-cirrus-logic-accupak", "Cirrus Logipak AccuPak", FLAG_VIDEO, ""},
198   {"video/x-compressed-yuv", N_("CYUV Lossless"), FLAG_VIDEO, ""},
199   {"video/x-dnxhd", "Digital Nonlinear Extensible High Definition (DNxHD)",
200       FLAG_VIDEO, ""},
201   {"subpicture/x-dvd", "DVD subpicture", FLAG_VIDEO, ""},
202   {"video/x-ffv", N_("FFMpeg v1"), FLAG_VIDEO, ""},
203   {"video/x-flash-screen", "Flash Screen Video", FLAG_VIDEO, ""},
204   {"video/x-flash-video", "Sorenson Spark Video", FLAG_VIDEO, ""},
205   {"video/x-h261", "H.261", FLAG_VIDEO, ""},
206   {"video/x-huffyuv", "Huffyuv", FLAG_VIDEO, ""},
207   {"video/x-intel-h263", "Intel H.263", FLAG_VIDEO, ""},
208   {"video/x-jpeg", "Motion JPEG", FLAG_VIDEO, ""},
209   /* { "video/x-jpeg-b", "", 0 }, does this actually exist? */
210   {"video/x-loco", "LOCO Lossless", FLAG_VIDEO, ""},
211   {"video/x-mimic", "MIMIC", FLAG_VIDEO, ""},
212   {"video/x-mjpeg", "Motion-JPEG", FLAG_VIDEO, ""},
213   {"video/x-mjpeg-b", "Motion-JPEG format B", FLAG_VIDEO, ""},
214   {"video/mpegts", "MPEG-2 Transport Stream", AVS_CONTAINER, "ts"},
215   {"video/x-mng", "Multiple Image Network Graphics (MNG)", FLAG_VIDEO, ""},
216   {"video/x-mszh", N_("Lossless MSZH"), FLAG_VIDEO, ""},
217   {"video/x-msvideocodec", "Microsoft Video 1", FLAG_VIDEO, ""},
218   {"video/x-mve", "Interplay MVE", AV_CONTAINER, "mve"},
219   {"video/x-nut", "NUT", AV_CONTAINER, "nut"},
220   {"video/x-nuv", "MythTV NuppelVideo (NUV)", AV_CONTAINER, "nuv"},
221   {"video/x-prores", "Apple ProRes", FLAG_VIDEO, ""},
222   {"video/x-qdrw", "Apple QuickDraw", FLAG_VIDEO, ""},
223   {"video/x-smc", "Apple SMC", FLAG_VIDEO, ""},
224   {"video/x-smoke", "Smoke", FLAG_VIDEO, ""},
225   {"video/x-tarkin", "Tarkin", FLAG_VIDEO, ""},
226   {"video/x-theora", "Theora", FLAG_VIDEO, ""},
227   {"video/x-rle", N_("Run-length encoding"), FLAG_VIDEO, ""},
228   {"video/x-ultimotion", "IBM UltiMotion", FLAG_VIDEO, ""},
229   {"video/x-vcd", "VideoCD (VCD)", 0},
230   {"video/x-vmnc", "VMWare NC", FLAG_VIDEO, ""},
231   {"video/x-vp3", "On2 VP3", FLAG_VIDEO, ""},
232   {"video/x-vp5", "On2 VP5", FLAG_VIDEO, ""},
233   {"video/x-vp6", "On2 VP6", FLAG_VIDEO, ""},
234   {"video/x-vp6-flash", "On2 VP6/Flash", FLAG_VIDEO, ""},
235   {"video/x-vp6-alpha", "On2 VP6 with alpha", FLAG_VIDEO, ""},
236   {"video/x-vp7", "On2 VP7", FLAG_VIDEO, ""},
237   {"video/x-vp8", "VP8", FLAG_VIDEO, ""},
238   {"video/x-vp9", "VP9", FLAG_VIDEO, ""},
239   {"video/x-zlib", "Lossless zlib video", FLAG_VIDEO, ""},
240   {"video/x-zmbv", "Zip Motion Block video", FLAG_VIDEO, ""},
241
242   /* image formats with static descriptions */
243   {"image/bmp", "BMP", FLAG_IMAGE, "bmp"},
244   {"image/x-bmp", "BMP", FLAG_IMAGE, "bmp"},
245   {"image/x-MS-bmp", "BMP", FLAG_IMAGE, "bmp"},
246   {"image/gif", "GIF", FLAG_IMAGE, "gif"},
247   {"image/jpeg", "JPEG", FLAG_IMAGE | FLAG_VIDEO, "jpg"},
248   {"image/jng", "JPEG Network Graphics (JNG)", FLAG_IMAGE, ""},
249   {"image/png", "PNG", FLAG_VIDEO | FLAG_IMAGE, "png"},
250   {"image/pbm", "Portable BitMap (PBM)", FLAG_IMAGE, "pbm"},
251   {"image/ppm", "Portable PixMap (PPM)", FLAG_IMAGE, "ppm"},
252   {"image/svg+xml", "Scalable Vector Graphics (SVG)", FLAG_IMAGE, "svg"},
253   {"image/tiff", "TIFF", FLAG_IMAGE, "tiff"},
254   {"image/x-cmu-raster", "CMU Raster Format", FLAG_IMAGE, ""},
255   {"image/x-degas", "DEGAS", FLAG_IMAGE, ""},
256   {"image/x-icon", "ICO", FLAG_IMAGE, "ico"},
257   {"image/x-j2c", "JPEG 2000", FLAG_VIDEO | FLAG_IMAGE, ""},
258   {"image/x-jpc", "JPEG 2000", FLAG_VIDEO | FLAG_IMAGE, ""},
259   {"image/jp2", "JPEG 2000", FLAG_VIDEO | FLAG_IMAGE, ""},
260   {"image/x-pcx", "PCX", FLAG_IMAGE, ""},
261   {"image/x-xcf", "XFC", FLAG_IMAGE, ""},
262   {"image/x-pixmap", "XPM", FLAG_IMAGE, "xpm"},
263   {"image/x-portable-anymap", "Portable AnyMap (PNM)", FLAG_IMAGE, "pnm"},
264   {"image/x-portable-graymap", "Portable GrayMap (PGM)", FLAG_IMAGE, "pgm"},
265   {"image/x-xpixmap", "XPM", FLAG_IMAGE, "xpm"},
266   {"image/x-quicktime", "QuickTime Image Format (QTIF)",
267       FLAG_IMAGE | FLAG_CONTAINER, ".mov"},
268   {"image/x-sun-raster", "Sun Raster Format (RAS)", FLAG_IMAGE, ""},
269   {"image/x-tga", "TGA", FLAG_IMAGE, "tga"},
270   {"image/vnd.wap.wbmp", "Wireless Bitmap", FLAG_IMAGE, "wbmp"},
271
272   /* subtitle formats with static descriptions */
273   {"text/x-raw", N_("Timed Text"), FLAG_SUB, ""},
274   {"application/x-ssa", "SubStation Alpha", FLAG_SUB, ""},
275   {"application/x-ass", "Advanced SubStation Alpha", FLAG_SUB, ""},
276   /* FIXME: add variant field to typefinder? */
277   {"application/x-subtitle", N_("Subtitle"), FLAG_SUB, ""},
278   {"application/x-subtitle-mpl2", N_("MPL2 subtitle format"), FLAG_SUB, ""},
279   {"application/x-subtitle-dks", N_("DKS subtitle format"), FLAG_SUB, ""},
280   {"application/x-subtitle-qttext", N_("QTtext subtitle format"), FLAG_SUB, ""},
281   {"application/x-subtitle-sami", N_("Sami subtitle format"), FLAG_SUB, ""},
282   {"application/x-subtitle-tmplayer", N_("TMPlayer subtitle format"), FLAG_SUB,
283       ""},
284   {"application/x-teletext", "Teletext", 0, ""},
285   {"application/x-kate", "Kate", 0, ""},
286   {"closedcaption/x-cea-608", N_("CEA 608 Closed Caption"), FLAG_SUB, ""},
287   {"closedcaption/x-cea-708", N_("CEA 708 Closed Caption"), FLAG_SUB, ""},
288   {"subtitle/x-kate", N_("Kate subtitle format"), FLAG_SUB, ""},
289   {"application/x-subtitle-vtt", N_("WebVTT subtitle format"), FLAG_SUB, ""},
290   {"subpicture/x-dvb", "DVB subtitles", FLAG_SUB, ""},
291   {"subpicture/x-pgs", "PGS subtitles", FLAG_SUB, ""},
292   {"subpicture/x-xsub", "XSUB subtitles", FLAG_SUB, ""},
293
294   /* non-audio/video/container formats */
295   {"hdv/aux-v", "HDV AUX-V", 0, ""},
296   {"hdv/aux-a", "HDV AUX-A", 0, ""},
297
298   /* formats with dynamic descriptions */
299   {"audio/mpeg", NULL, FLAG_AUDIO, ""},
300   {"audio/x-adpcm", NULL, FLAG_AUDIO, ""},
301   {"audio/x-mace", NULL, FLAG_AUDIO, ""},
302   {"audio/x-pn-realaudio", NULL, FLAG_AUDIO, ""},
303   {"audio/x-raw", NULL, FLAG_AUDIO, ""},
304   {"audio/x-wma", NULL, FLAG_AUDIO, ""},
305   {"video/mpeg", NULL, AVS_CONTAINER | FLAG_SYSTEMSTREAM, "mpg"},
306   {"video/mpeg", NULL, FLAG_VIDEO, ""},
307   {"video/x-asus", NULL, FLAG_VIDEO, ""},
308   {"video/x-ati-vcr", NULL, FLAG_VIDEO, ""},
309   {"video/x-dirac", NULL, FLAG_VIDEO, ""},
310   {"video/x-divx", NULL, FLAG_VIDEO, ""},
311   {"video/x-dv", "Digital Video (DV) System Stream",
312       FLAG_CONTAINER | FLAG_SYSTEMSTREAM, "dv"},
313   {"video/x-dv", "Digital Video (DV)", FLAG_VIDEO, ""},
314   {"video/x-h263", NULL, FLAG_VIDEO, "h263"},
315   {"video/x-h264", NULL, FLAG_VIDEO, "h264"},
316   {"video/x-h265", NULL, FLAG_VIDEO, "h265"},
317   {"video/x-indeo", NULL, FLAG_VIDEO, ""},
318   {"video/x-msmpeg", NULL, FLAG_VIDEO, ""},
319   {"video/x-pn-realvideo", NULL, FLAG_VIDEO, ""},
320 #if 0
321   /* do these exist? are they used anywhere? */
322   {"video/x-pn-multirate-realvideo", NULL, 0},
323   {"audio/x-pn-multirate-realaudio", NULL, 0},
324   {"audio/x-pn-multirate-realaudio-live", NULL, 0},
325 #endif
326   {"video/x-truemotion", NULL, FLAG_VIDEO, ""},
327   {"video/x-raw", NULL, FLAG_VIDEO, ""},
328   {"video/x-svq", NULL, FLAG_VIDEO, ""},
329   {"video/x-wmv", NULL, FLAG_VIDEO, ""},
330   {"video/x-xan", NULL, FLAG_VIDEO, ""},
331   {"video/x-tscc", NULL, FLAG_VIDEO, ""}
332 };
333
334 static const gchar *
335 pbutils_desc_get_profile_name_from_nick (const gchar * map, gsize map_len,
336     const gchar * nick)
337 {
338   const gchar *end = map + map_len;
339   const gchar *p;
340
341   p = map;
342   while (*p != '\0' && p < end) {
343     guint len = strlen (p);
344
345     if (strcmp (p, nick) == 0)
346       return p + len + 1;
347     p += len + 1;
348     p += strlen (p) + 1;
349   }
350   return NULL;
351 }
352
353 static const gchar *
354 pbutils_desc_get_mpeg2v_profile_name_from_nick (const gchar * nick)
355 {
356   static const gchar map[] =
357       "simple\000Simple\000main\000Main\000high\000High\000";
358
359   return pbutils_desc_get_profile_name_from_nick (map, sizeof (map), nick);
360 }
361
362 static const gchar *
363 pbutils_desc_get_mpeg4v_profile_name_from_nick (const gchar * nick)
364 {
365   static const gchar map[] = "simple\000Simple\000"
366       "simple-scalable\000Simple Scalable\000"
367       "core\000Core\000"
368       "main\000Main\000"
369       "n-bit\000N-bit\000"
370       "scalable\000Scalable\000"
371       "hybrid\000Hybrid\000"
372       "advanced-real-time-simple\000Advanced Real-Time Simple\000"
373       "core-scalable\000Core-Scalable\000"
374       "advanced-coding-efficiency\000Advanced Coding Efficiency\000"
375       "advanced-core\000Advanced Core\000"
376       "advanced-scalable-texture\000Advanced Scalable Texture\000"
377       "simple-face\000Simple Face Animation\000"
378       "simple-fba\000Simple FBA\000"
379       "simple-studio\000Simple Studio\000"
380       "core-studio\000Core Studio\000"
381       "advanced-simple\000Advanced Simple\000"
382       "fine-granularity-scalable\000Fine Granularity Scalable\000"
383       "basic-animated-texture\000Basic Animated Texture\000"
384       "baseline\000Baseline Profile\000";
385
386   return pbutils_desc_get_profile_name_from_nick (map, sizeof (map), nick);
387 }
388
389 static const gchar *
390 pbutils_desc_get_h264_profile_name_from_nick (const gchar * nick)
391 {
392   static const gchar map[] = "baseline\000Baseline\000"
393       "constrained-baseline\000Constrained Baseline\000"
394       "main\000Main\000"
395       "extended\000Extended\000"
396       "high\000High\000"
397       "high-10-intra\000High 10 Intra\000"
398       "high-10\000High 10\000"
399       "high-4:2:2-intra\000High 4:2:2 Intra\000"
400       "high-4:2:2\000High 4:2:2\000"
401       "high-4:4:4-intra\000High 4:4:4 Intra\000"
402       "high-4:4:4\000High 4:4:4\000"
403       "cavlc-4:4:4-intra\000CAVLC 4:4:4 Intra\000"
404       "multiview-high\000Multiview High\000"
405       "stereo-high\000Stereo High\000"
406       "scalable-constrained-baseline\000Scalable Constrained Baseline\000"
407       "scalable-baseline\000Scalable Baseline\000"
408       "scalable-high\000Scalable High\000";
409
410   return pbutils_desc_get_profile_name_from_nick (map, sizeof (map), nick);
411 }
412
413 static const gchar *
414 pbutils_desc_get_h265_profile_name_from_nick (const gchar * nick)
415 {
416   static const gchar map[] = "main\000Main\000"
417       "main-10\000Main 10\000"
418       "main-12\000Main 12\000"
419       "main-4:2:2-10\000Main 4:2:2 10\000"
420       "main-4:2:2-12\000Main 4:2:2 12\000"
421       "main-4:4:4\000Main 4:4:4\000"
422       "main-4:4:4-10\000Main 4:4:4 10\000"
423       "main-4:4:4-12\000Main 4:4:4 12\000"
424       "main-4:4:4-16-intra\000Main 4:4:4 16 Intra\000"
425       "main-still-picture\000Main Still Picture\000";
426
427   return pbutils_desc_get_profile_name_from_nick (map, sizeof (map), nick);
428 }
429
430 /* returns static descriptions and dynamic ones (such as video/x-raw),
431  * or NULL if caps aren't known at all */
432 static gchar *
433 format_info_get_desc (const FormatInfo * info, const GstCaps * caps)
434 {
435   const GstStructure *s;
436
437   g_assert (info != NULL);
438
439   gst_pb_utils_init_locale_text_domain ();
440
441   if (info->desc != NULL)
442     return g_strdup (_(info->desc));
443
444   s = gst_caps_get_structure (caps, 0);
445
446   if (strcmp (info->type, "video/x-raw") == 0) {
447     gchar *ret = NULL;
448     const gchar *str = 0;
449     GstVideoFormat format;
450     const GstVideoFormatInfo *finfo;
451
452     str = gst_structure_get_string (s, "format");
453     if (str == NULL)
454       return g_strdup (_("Uncompressed video"));
455     format = gst_video_format_from_string (str);
456     if (format == GST_VIDEO_FORMAT_UNKNOWN)
457       return g_strdup (_("Uncompressed video"));
458
459     finfo = gst_video_format_get_info (format);
460
461     if (GST_VIDEO_FORMAT_INFO_IS_GRAY (finfo)) {
462       ret = g_strdup (_("Uncompressed gray"));
463     } else if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo)) {
464       const gchar *subs;
465       gint w_sub, h_sub, n_semi;
466
467       w_sub = GST_VIDEO_FORMAT_INFO_W_SUB (finfo, 1);
468       h_sub = GST_VIDEO_FORMAT_INFO_H_SUB (finfo, 1);
469
470       if (w_sub == 1 && h_sub == 1) {
471         subs = "4:4:4";
472       } else if (w_sub == 2 && h_sub == 1) {
473         subs = "4:2:2";
474       } else if (w_sub == 2 && h_sub == 2) {
475         subs = "4:2:0";
476       } else if (w_sub == 4 && h_sub == 1) {
477         subs = "4:1:1";
478       } else {
479         subs = "";
480       }
481
482       n_semi = GST_VIDEO_FORMAT_INFO_HAS_ALPHA (finfo) ? 3 : 2;
483
484       if (GST_VIDEO_FORMAT_INFO_N_PLANES (finfo) == 1) {
485         ret = g_strdup_printf (_("Uncompressed packed YUV %s"), subs);
486       } else if (GST_VIDEO_FORMAT_INFO_N_PLANES (finfo) == n_semi) {
487         ret = g_strdup_printf (_("Uncompressed semi-planar YUV %s"), subs);
488       } else {
489         ret = g_strdup_printf (_("Uncompressed planar YUV %s"), subs);
490       }
491     } else if (GST_VIDEO_FORMAT_INFO_IS_RGB (finfo)) {
492       gboolean alpha, palette;
493       gint bits;
494
495       alpha = GST_VIDEO_FORMAT_INFO_HAS_ALPHA (finfo);
496       palette = GST_VIDEO_FORMAT_INFO_HAS_PALETTE (finfo);
497       bits = GST_VIDEO_FORMAT_INFO_BITS (finfo);
498
499       if (palette) {
500         ret = g_strdup_printf (_("Uncompressed palettized %d-bit %s"),
501             bits, alpha ? "RGBA" : "RGB");
502       } else {
503         ret = g_strdup_printf (_("Uncompressed %d-bit %s"),
504             bits, alpha ? "RGBA" : "RGB");
505       }
506     } else {
507       ret = g_strdup (_("Uncompressed video"));
508     }
509     return ret;
510   } else if (strcmp (info->type, "video/x-h263") == 0) {
511     const gchar *variant, *ret;
512
513     variant = gst_structure_get_string (s, "variant");
514     if (variant == NULL)
515       ret = "H.263";
516     else if (strcmp (variant, "itu") == 0)
517       ret = "ITU H.26n";        /* why not ITU H.263? (tpm) */
518     else if (strcmp (variant, "lead") == 0)
519       ret = "Lead H.263";
520     else if (strcmp (variant, "microsoft") == 0)
521       ret = "Microsoft H.263";
522     else if (strcmp (variant, "vdolive") == 0)
523       ret = "VDOLive";
524     else if (strcmp (variant, "vivo") == 0)
525       ret = "Vivo H.263";
526     else if (strcmp (variant, "xirlink") == 0)
527       ret = "Xirlink H.263";
528     else {
529       GST_WARNING ("Unknown H263 variant '%s'", variant);
530       ret = "H.263";
531     }
532     return g_strdup (ret);
533   } else if (strcmp (info->type, "video/x-h264") == 0) {
534     const gchar *variant, *ret;
535     const gchar *profile;
536
537     variant = gst_structure_get_string (s, "variant");
538     if (variant == NULL)
539       ret = "H.264";
540     else if (strcmp (variant, "itu") == 0)
541       ret = "ITU H.264";
542     else if (strcmp (variant, "videosoft") == 0)
543       ret = "Videosoft H.264";
544     else if (strcmp (variant, "lead") == 0)
545       ret = "Lead H.264";
546     else {
547       GST_WARNING ("Unknown H264 variant '%s'", variant);
548       ret = "H.264";
549     }
550     /* profile */
551     profile = gst_structure_get_string (s, "profile");
552     if (profile != NULL)
553       profile = pbutils_desc_get_h264_profile_name_from_nick (profile);
554     if (profile == NULL)
555       return g_strdup (ret);
556     return g_strdup_printf ("%s (%s Profile)", ret, profile);
557   } else if (strcmp (info->type, "video/x-h265") == 0) {
558     const gchar *profile = gst_structure_get_string (s, "profile");
559
560     if (profile != NULL)
561       profile = pbutils_desc_get_h265_profile_name_from_nick (profile);
562     if (profile != NULL)
563       return g_strdup_printf ("H.265 (%s Profile)", profile);
564
565     return g_strdup ("H.265");
566   } else if (strcmp (info->type, "video/x-dirac") == 0) {
567     const gchar *profile = gst_structure_get_string (s, "profile");
568     if (profile == NULL)
569       return g_strdup ("Dirac");
570     if (strcmp (profile, "vc2-low-delay") == 0)
571       return g_strdup_printf ("Dirac (%s)", "VC-2 Low Delay Profile");
572     else if (strcmp (profile, "vc2-simple") == 0)
573       return g_strdup_printf ("Dirac (%s)", "VC-2 Simple Profile");
574     else if (strcmp (profile, "vc2-main") == 0)
575       return g_strdup_printf ("Dirac (%s)", "VC-2 Main Profile");
576     else
577       return g_strdup ("Dirac");
578   } else if (strcmp (info->type, "video/x-divx") == 0) {
579     gint ver = 0;
580
581     if (!gst_structure_get_int (s, "divxversion", &ver) || ver <= 2) {
582       GST_WARNING ("Unexpected DivX version in %" GST_PTR_FORMAT, caps);
583       return g_strdup ("DivX MPEG-4");
584     }
585     return g_strdup_printf (_("DivX MPEG-4 Version %d"), ver);
586   } else if (strcmp (info->type, "video/x-msmpeg") == 0) {
587     gint ver = 0;
588
589     if (!gst_structure_get_int (s, "msmpegversion", &ver) ||
590         ver < 40 || ver > 49) {
591       GST_WARNING ("Unexpected msmpegversion in %" GST_PTR_FORMAT, caps);
592       return g_strdup ("Microsoft MPEG-4 4.x");
593     }
594     return g_strdup_printf ("Microsoft MPEG-4 4.%d", ver % 10);
595   } else if (strcmp (info->type, "video/x-truemotion") == 0) {
596     gint ver = 0;
597
598     gst_structure_get_int (s, "trueversion", &ver);
599     switch (ver) {
600       case 1:
601         return g_strdup_printf ("Duck TrueMotion 1");
602       case 2:
603         return g_strdup_printf ("TrueMotion 2.0");
604       default:
605         GST_WARNING ("Unexpected trueversion in %" GST_PTR_FORMAT, caps);
606         break;
607     }
608     return g_strdup_printf ("TrueMotion");
609   } else if (strcmp (info->type, "video/x-xan") == 0) {
610     gint ver = 0;
611
612     if (!gst_structure_get_int (s, "wcversion", &ver) || ver < 1) {
613       GST_WARNING ("Unexpected wcversion in %" GST_PTR_FORMAT, caps);
614       return g_strdup ("Xan Wing Commander");
615     }
616     return g_strdup_printf ("Xan Wing Commander %u", ver);
617   } else if (strcmp (info->type, "video/x-indeo") == 0) {
618     gint ver = 0;
619
620     if (!gst_structure_get_int (s, "indeoversion", &ver) || ver < 2) {
621       GST_WARNING ("Unexpected indeoversion in %" GST_PTR_FORMAT, caps);
622       return g_strdup ("Intel Indeo");
623     }
624     return g_strdup_printf ("Intel Indeo %u", ver);
625   } else if (strcmp (info->type, "audio/x-wma") == 0) {
626     gint ver = 0;
627
628     gst_structure_get_int (s, "wmaversion", &ver);
629     switch (ver) {
630       case 1:
631       case 2:
632       case 3:
633         return g_strdup_printf ("Windows Media Audio %d", ver + 6);
634       default:
635         break;
636     }
637     GST_WARNING ("Unexpected wmaversion in %" GST_PTR_FORMAT, caps);
638     return g_strdup ("Windows Media Audio");
639   } else if (strcmp (info->type, "video/x-wmv") == 0) {
640     gint ver = 0;
641     const gchar *str;
642
643     gst_structure_get_int (s, "wmvversion", &ver);
644     str = gst_structure_get_string (s, "format");
645
646     switch (ver) {
647       case 1:
648       case 2:
649       case 3:
650         if (str && strncmp (str, "MSS", 3)) {
651           return g_strdup_printf ("Windows Media Video %d Screen", ver + 6);
652         } else {
653           return g_strdup_printf ("Windows Media Video %d", ver + 6);
654         }
655       default:
656         break;
657     }
658     GST_WARNING ("Unexpected wmvversion in %" GST_PTR_FORMAT, caps);
659     return g_strdup ("Windows Media Video");
660   } else if (strcmp (info->type, "audio/x-mace") == 0) {
661     gint ver = 0;
662
663     gst_structure_get_int (s, "maceversion", &ver);
664     if (ver == 3 || ver == 6) {
665       return g_strdup_printf ("MACE-%d", ver);
666     } else {
667       GST_WARNING ("Unexpected maceversion in %" GST_PTR_FORMAT, caps);
668       return g_strdup ("MACE");
669     }
670   } else if (strcmp (info->type, "video/x-svq") == 0) {
671     gint ver = 0;
672
673     gst_structure_get_int (s, "svqversion", &ver);
674     if (ver == 1 || ver == 3) {
675       return g_strdup_printf ("Sorensen Video %d", ver);
676     } else {
677       GST_WARNING ("Unexpected svqversion in %" GST_PTR_FORMAT, caps);
678       return g_strdup ("Sorensen Video");
679     }
680   } else if (strcmp (info->type, "video/x-asus") == 0) {
681     gint ver = 0;
682
683     gst_structure_get_int (s, "asusversion", &ver);
684     if (ver == 1 || ver == 2) {
685       return g_strdup_printf ("Asus Video %d", ver);
686     } else {
687       GST_WARNING ("Unexpected asusversion in %" GST_PTR_FORMAT, caps);
688       return g_strdup ("Asus Video");
689     }
690   } else if (strcmp (info->type, "video/x-ati-vcr") == 0) {
691     gint ver = 0;
692
693     gst_structure_get_int (s, "vcrversion", &ver);
694     if (ver == 1 || ver == 2) {
695       return g_strdup_printf ("ATI VCR %d", ver);
696     } else {
697       GST_WARNING ("Unexpected acrversion in %" GST_PTR_FORMAT, caps);
698       return g_strdup ("ATI VCR");
699     }
700   } else if (strcmp (info->type, "audio/x-adpcm") == 0) {
701     const GValue *layout_val;
702
703     layout_val = gst_structure_get_value (s, "layout");
704     if (layout_val != NULL && G_VALUE_HOLDS_STRING (layout_val)) {
705       const gchar *layout;
706
707       if ((layout = g_value_get_string (layout_val))) {
708         gchar *layout_upper, *ret;
709
710         if (strcmp (layout, "swf") == 0)
711           return g_strdup ("Shockwave ADPCM");
712         if (strcmp (layout, "microsoft") == 0)
713           return g_strdup ("Microsoft ADPCM");
714         if (strcmp (layout, "quicktime") == 0)
715           return g_strdup ("Quicktime ADPCM");
716         if (strcmp (layout, "westwood") == 0)
717           return g_strdup ("Westwood ADPCM");
718         if (strcmp (layout, "yamaha") == 0)
719           return g_strdup ("Yamaha ADPCM");
720         /* FIXME: other layouts: sbpro2, sbpro3, sbpro4, ct, g726, ea,
721          * adx, xa, 4xm, smjpeg, dk4, dk3, dvi */
722         layout_upper = g_ascii_strup (layout, -1);
723         ret = g_strdup_printf ("%s ADPCM", layout_upper);
724         g_free (layout_upper);
725         return ret;
726       }
727     }
728     return g_strdup ("ADPCM");
729   } else if (strcmp (info->type, "audio/mpeg") == 0) {
730     gint ver = 0, layer = 0;
731
732     gst_structure_get_int (s, "mpegversion", &ver);
733
734     switch (ver) {
735       case 1:
736         gst_structure_get_int (s, "layer", &layer);
737         switch (layer) {
738           case 1:
739           case 2:
740           case 3:
741             return g_strdup_printf ("MPEG-1 Layer %d (MP%d)", layer, layer);
742           default:
743             break;
744         }
745         GST_WARNING ("Unexpected MPEG-1 layer in %" GST_PTR_FORMAT, caps);
746         return g_strdup ("MPEG-1 Audio");
747       case 2:
748         return g_strdup ("MPEG-2 AAC");
749       case 4:
750         return g_strdup ("MPEG-4 AAC");
751       default:
752         break;
753     }
754     GST_WARNING ("Unexpected audio mpegversion in %" GST_PTR_FORMAT, caps);
755     return g_strdup ("MPEG Audio");
756   } else if (strcmp (info->type, "audio/x-pn-realaudio") == 0) {
757     gint ver = 0;
758
759     gst_structure_get_int (s, "raversion", &ver);
760     switch (ver) {
761       case 1:
762         return g_strdup ("RealAudio 14k4bps");
763       case 2:
764         return g_strdup ("RealAudio 28k8bps");
765       case 8:
766         return g_strdup ("RealAudio G2 (Cook)");
767       default:
768         break;
769     }
770     GST_WARNING ("Unexpected raversion in %" GST_PTR_FORMAT, caps);
771     return g_strdup ("RealAudio");
772   } else if (strcmp (info->type, "video/x-pn-realvideo") == 0) {
773     gint ver = 0;
774
775     gst_structure_get_int (s, "rmversion", &ver);
776     switch (ver) {
777       case 1:
778         return g_strdup ("RealVideo 1.0");
779       case 2:
780         return g_strdup ("RealVideo 2.0");
781       case 3:
782         return g_strdup ("RealVideo 3.0");
783       case 4:
784         return g_strdup ("RealVideo 4.0");
785       default:
786         break;
787     }
788     GST_WARNING ("Unexpected rmversion in %" GST_PTR_FORMAT, caps);
789     return g_strdup ("RealVideo");
790   } else if (strcmp (info->type, "video/mpeg") == 0) {
791     gboolean sysstream;
792     gint ver = 0;
793
794     if (!gst_structure_get_boolean (s, "systemstream", &sysstream)) {
795       GST_WARNING ("Missing systemstream field in mpeg video caps "
796           "%" GST_PTR_FORMAT, caps);
797       sysstream = FALSE;
798     }
799
800     if (gst_structure_get_int (s, "mpegversion", &ver) && ver > 0 && ver <= 4) {
801       if (sysstream) {
802         return g_strdup_printf ("MPEG-%d System Stream", ver);
803       } else {
804         const gchar *profile = gst_structure_get_string (s, "profile");
805         if (profile != NULL) {
806           if (ver == 4)
807             profile = pbutils_desc_get_mpeg4v_profile_name_from_nick (profile);
808           else if (ver == 2)
809             profile = pbutils_desc_get_mpeg2v_profile_name_from_nick (profile);
810           else
811             profile = NULL;
812         }
813         if (profile != NULL)
814           return g_strdup_printf ("MPEG-%d Video (%s Profile)", ver, profile);
815         else
816           return g_strdup_printf ("MPEG-%d Video", ver);
817       }
818     }
819     GST_WARNING ("Missing mpegversion field in mpeg video caps "
820         "%" GST_PTR_FORMAT, caps);
821     return g_strdup ("MPEG Video");
822   } else if (strcmp (info->type, "audio/x-raw") == 0) {
823     gint depth = 0;
824     gboolean is_float;
825     const gchar *str;
826     GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
827     const GstAudioFormatInfo *finfo;
828
829     str = gst_structure_get_string (s, "format");
830     if (str)
831       format = gst_audio_format_from_string (str);
832     if (format == GST_AUDIO_FORMAT_UNKNOWN)
833       return g_strdup (_("Uncompressed audio"));
834
835     finfo = gst_audio_format_get_info (format);
836     depth = GST_AUDIO_FORMAT_INFO_DEPTH (finfo);
837     is_float = GST_AUDIO_FORMAT_INFO_IS_FLOAT (finfo);
838
839     return g_strdup_printf (_("Raw %d-bit %s audio"), depth,
840         is_float ? "floating-point" : "PCM");
841   } else if (strcmp (info->type, "video/x-tscc") == 0) {
842     gint version;
843     gst_structure_get_int (s, "tsccversion", &version);
844     switch (version) {
845       case 1:
846         return g_strdup ("TechSmith Screen Capture 1");
847       case 2:
848         return g_strdup ("TechSmith Screen Capture 2");
849       default:
850         break;
851     }
852     GST_WARNING ("Unexpected version in %" GST_PTR_FORMAT, caps);
853     return g_strdup ("TechSmith Screen Capture");
854   }
855   return NULL;
856 }
857
858 /* returns format info structure, will return NULL for dynamic media types! */
859 static const FormatInfo *
860 find_format_info (const GstCaps * caps)
861 {
862   const GstStructure *s;
863   const gchar *media_type;
864   guint i;
865
866   s = gst_caps_get_structure (caps, 0);
867   media_type = gst_structure_get_name (s);
868
869   for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
870     if (strcmp (media_type, formats[i].type) == 0) {
871       gboolean is_sys = FALSE;
872
873       if ((formats[i].flags & FLAG_SYSTEMSTREAM) == 0)
874         return &formats[i];
875
876       /* this record should only be matched if the systemstream field is set */
877       if (gst_structure_get_boolean (s, "systemstream", &is_sys) && is_sys)
878         return &formats[i];
879     }
880   }
881
882   return NULL;
883 }
884
885 static gboolean
886 caps_are_rtp_caps (const GstCaps * caps, const gchar * media, gchar ** format)
887 {
888   const GstStructure *s;
889   const gchar *str;
890
891   g_assert (media != NULL && format != NULL);
892
893   s = gst_caps_get_structure (caps, 0);
894   if (!gst_structure_has_name (s, "application/x-rtp"))
895     return FALSE;
896   if (!gst_structure_has_field_typed (s, "media", G_TYPE_STRING))
897     return FALSE;
898   str = gst_structure_get_string (s, "media");
899   if (str == NULL || !g_str_equal (str, media))
900     return FALSE;
901   str = gst_structure_get_string (s, "encoding-name");
902   if (str == NULL || *str == '\0')
903     return FALSE;
904
905   if (strcmp (str, "X-ASF-PF") == 0) {
906     *format = g_strdup ("Windows Media");
907   } else if (g_str_has_prefix (str, "X-")) {
908     *format = g_strdup (str + 2);
909   } else {
910     *format = g_strdup (str);
911   }
912
913   return TRUE;
914 }
915
916 /**
917  * gst_pb_utils_get_source_description:
918  * @protocol: the protocol the source element needs to handle, e.g. "http"
919  *
920  * Returns a localised string describing a source element handling the protocol
921  * specified in @protocol, for use in error dialogs or other messages to be
922  * seen by the user. Should never return NULL unless @protocol is invalid.
923  *
924  * This function is mainly for internal use, applications would typically
925  * use gst_missing_plugin_message_get_description() to get a description of
926  * a missing feature from a missing-plugin message.
927  *
928  * Returns: a newly-allocated description string, or NULL on error. Free
929  *          string with g_free() when not needed any longer.
930  */
931 gchar *
932 gst_pb_utils_get_source_description (const gchar * protocol)
933 {
934   gchar *proto_uc, *ret;
935
936   g_return_val_if_fail (protocol != NULL, NULL);
937
938   gst_pb_utils_init_locale_text_domain ();
939
940   if (strcmp (protocol, "cdda") == 0)
941     return g_strdup (_("Audio CD source"));
942
943   if (strcmp (protocol, "dvd") == 0)
944     return g_strdup (_("DVD source"));
945
946   if (strcmp (protocol, "rtsp") == 0)
947     return g_strdup (_("Real Time Streaming Protocol (RTSP) source"));
948
949   /* TODO: what about mmst, mmsu, mmsh? */
950   if (strcmp (protocol, "mms") == 0)
951     return g_strdup (_("Microsoft Media Server (MMS) protocol source"));
952
953   /* make protocol uppercase */
954   proto_uc = g_ascii_strup (protocol, -1);
955
956   /* TODO: find out how to add a comment for translators to the source code
957    * (and tell them to make the first letter uppercase below if they move
958    * the protocol to the middle or end of the string) */
959   ret = g_strdup_printf (_("%s protocol source"), proto_uc);
960
961   g_free (proto_uc);
962
963   return ret;
964 }
965
966 /**
967  * gst_pb_utils_get_sink_description:
968  * @protocol: the protocol the sink element needs to handle, e.g. "http"
969  *
970  * Returns a localised string describing a sink element handling the protocol
971  * specified in @protocol, for use in error dialogs or other messages to be
972  * seen by the user. Should never return NULL unless @protocol is invalid.
973  *
974  * This function is mainly for internal use, applications would typically
975  * use gst_missing_plugin_message_get_description() to get a description of
976  * a missing feature from a missing-plugin message.
977  *
978  * Returns: a newly-allocated description string, or NULL on error. Free
979  *          string with g_free() when not needed any longer.
980  */
981 gchar *
982 gst_pb_utils_get_sink_description (const gchar * protocol)
983 {
984   gchar *proto_uc, *ret;
985
986   g_return_val_if_fail (protocol != NULL, NULL);
987
988   /* make protocol uppercase */
989   proto_uc = g_ascii_strup (protocol, -1);
990
991   /* TODO: find out how to add a comment for translators to the source code
992    * (and tell them to make the first letter uppercase below if they move
993    * the protocol to the middle or end of the string) */
994   ret = g_strdup_printf ("%s protocol sink", proto_uc);
995
996   g_free (proto_uc);
997
998   return ret;
999 }
1000
1001 /**
1002  * gst_pb_utils_get_decoder_description:
1003  * @caps: the (fixed) #GstCaps for which an decoder description is needed
1004  *
1005  * Returns a localised string describing an decoder for the format specified
1006  * in @caps, for use in error dialogs or other messages to be seen by the user.
1007  * Should never return NULL unless @factory_name or @caps are invalid.
1008  *
1009  * This function is mainly for internal use, applications would typically
1010  * use gst_missing_plugin_message_get_description() to get a description of
1011  * a missing feature from a missing-plugin message.
1012  *
1013  * Returns: a newly-allocated description string, or NULL on error. Free
1014  *          string with g_free() when not needed any longer.
1015  */
1016 gchar *
1017 gst_pb_utils_get_decoder_description (const GstCaps * caps)
1018 {
1019   gchar *str, *ret;
1020   GstCaps *tmp;
1021
1022   g_return_val_if_fail (caps != NULL, NULL);
1023   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
1024
1025   tmp = copy_and_clean_caps (caps);
1026
1027   g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
1028
1029   gst_pb_utils_init_locale_text_domain ();
1030
1031   /* special-case RTP caps */
1032   if (caps_are_rtp_caps (tmp, "video", &str)) {
1033     ret = g_strdup_printf (_("%s video RTP depayloader"), str);
1034   } else if (caps_are_rtp_caps (tmp, "audio", &str)) {
1035     ret = g_strdup_printf (_("%s audio RTP depayloader"), str);
1036   } else if (caps_are_rtp_caps (tmp, "application", &str)) {
1037     ret = g_strdup_printf (_("%s RTP depayloader"), str);
1038   } else {
1039     const FormatInfo *info;
1040
1041     str = gst_pb_utils_get_codec_description (tmp);
1042     info = find_format_info (tmp);
1043     if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) {
1044       ret = g_strdup_printf (_("%s demuxer"), str);
1045     } else {
1046       ret = g_strdup_printf (_("%s decoder"), str);
1047     }
1048   }
1049
1050   g_free (str);
1051   gst_caps_unref (tmp);
1052
1053   return ret;
1054 }
1055
1056 /**
1057  * gst_pb_utils_get_encoder_description:
1058  * @caps: the (fixed) #GstCaps for which an encoder description is needed
1059  *
1060  * Returns a localised string describing an encoder for the format specified
1061  * in @caps, for use in error dialogs or other messages to be seen by the user.
1062  * Should never return NULL unless @factory_name or @caps are invalid.
1063  *
1064  * This function is mainly for internal use, applications would typically
1065  * use gst_missing_plugin_message_get_description() to get a description of
1066  * a missing feature from a missing-plugin message.
1067  *
1068  * Returns: a newly-allocated description string, or NULL on error. Free
1069  *          string with g_free() when not needed any longer.
1070  */
1071 gchar *
1072 gst_pb_utils_get_encoder_description (const GstCaps * caps)
1073 {
1074   gchar *str, *ret;
1075   GstCaps *tmp;
1076
1077   g_return_val_if_fail (caps != NULL, NULL);
1078   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
1079   tmp = copy_and_clean_caps (caps);
1080   g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
1081   gst_pb_utils_init_locale_text_domain ();
1082
1083   /* special-case RTP caps */
1084   if (caps_are_rtp_caps (tmp, "video", &str)) {
1085     ret = g_strdup_printf (_("%s video RTP payloader"), str);
1086   } else if (caps_are_rtp_caps (tmp, "audio", &str)) {
1087     ret = g_strdup_printf (_("%s audio RTP payloader"), str);
1088   } else if (caps_are_rtp_caps (tmp, "application", &str)) {
1089     ret = g_strdup_printf (_("%s RTP payloader"), str);
1090   } else {
1091     const FormatInfo *info;
1092
1093     str = gst_pb_utils_get_codec_description (tmp);
1094     info = find_format_info (tmp);
1095     if (info != NULL && (info->flags & FLAG_CONTAINER) != 0) {
1096       ret = g_strdup_printf (_("%s muxer"), str);
1097     } else {
1098       ret = g_strdup_printf (_("%s encoder"), str);
1099     }
1100   }
1101
1102   g_free (str);
1103   gst_caps_unref (tmp);
1104
1105   return ret;
1106 }
1107
1108 /**
1109  * gst_pb_utils_get_element_description:
1110  * @factory_name: the name of the element, e.g. "giosrc"
1111  *
1112  * Returns a localised string describing the given element, for use in
1113  * error dialogs or other messages to be seen by the user. Should never
1114  * return NULL unless @factory_name is invalid.
1115  *
1116  * This function is mainly for internal use, applications would typically
1117  * use gst_missing_plugin_message_get_description() to get a description of
1118  * a missing feature from a missing-plugin message.
1119  *
1120  * Returns: a newly-allocated description string, or NULL on error. Free
1121  *          string with g_free() when not needed any longer.
1122  */
1123 gchar *
1124 gst_pb_utils_get_element_description (const gchar * factory_name)
1125 {
1126   gchar *ret;
1127
1128   g_return_val_if_fail (factory_name != NULL, NULL);
1129
1130   gst_pb_utils_init_locale_text_domain ();
1131
1132   ret = g_strdup_printf (_("GStreamer element %s"), factory_name);
1133   if (ret && g_str_has_prefix (ret, factory_name))
1134     *ret = g_ascii_toupper (*ret);
1135
1136   return ret;
1137 }
1138
1139 /**
1140  * gst_pb_utils_add_codec_description_to_tag_list:
1141  * @taglist: a #GstTagList
1142  * @codec_tag: (allow-none): a GStreamer codec tag such as #GST_TAG_AUDIO_CODEC,
1143  *             #GST_TAG_VIDEO_CODEC or #GST_TAG_CODEC. If none is specified,
1144  *             the function will attempt to detect the appropriate category.
1145  * @caps: the (fixed) #GstCaps for which a codec tag should be added.
1146  *
1147  * Adds a codec tag describing the format specified by @caps to @taglist.
1148  *
1149  * Returns: TRUE if a codec tag was added, FALSE otherwise.
1150  */
1151 gboolean
1152 gst_pb_utils_add_codec_description_to_tag_list (GstTagList * taglist,
1153     const gchar * codec_tag, const GstCaps * caps)
1154 {
1155   const FormatInfo *info;
1156   gchar *desc;
1157
1158   g_return_val_if_fail (taglist != NULL, FALSE);
1159   g_return_val_if_fail (GST_IS_TAG_LIST (taglist), FALSE);
1160   g_return_val_if_fail (codec_tag == NULL || (gst_tag_exists (codec_tag)
1161           && gst_tag_get_type (codec_tag) == G_TYPE_STRING), FALSE);
1162   g_return_val_if_fail (caps != NULL, FALSE);
1163   g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
1164
1165   info = find_format_info (caps);
1166   if (info == NULL)
1167     return FALSE;
1168
1169   /* Attempt to find tag classification */
1170   if (codec_tag == NULL) {
1171     if (info->flags & FLAG_CONTAINER)
1172       codec_tag = GST_TAG_CONTAINER_FORMAT;
1173     else if (info->flags & FLAG_AUDIO)
1174       codec_tag = GST_TAG_AUDIO_CODEC;
1175     else if (info->flags & FLAG_VIDEO)
1176       codec_tag = GST_TAG_VIDEO_CODEC;
1177     else if (info->flags & FLAG_SUB)
1178       codec_tag = GST_TAG_SUBTITLE_CODEC;
1179     else
1180       codec_tag = GST_TAG_CODEC;
1181   }
1182
1183   desc = format_info_get_desc (info, caps);
1184   gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, codec_tag, desc, NULL);
1185   g_free (desc);
1186
1187   return TRUE;
1188 }
1189
1190 /**
1191  * gst_pb_utils_get_codec_description:
1192  * @caps: the (fixed) #GstCaps for which an format description is needed
1193  *
1194  * Returns a localised (as far as this is possible) string describing the
1195  * media format specified in @caps, for use in error dialogs or other messages
1196  * to be seen by the user. Should never return NULL unless @caps is invalid.
1197  *
1198  * Also see the convenience function
1199  * gst_pb_utils_add_codec_description_to_tag_list().
1200  *
1201  * Returns: a newly-allocated description string, or NULL on error. Free
1202  *          string with g_free() when not needed any longer.
1203  */
1204 gchar *
1205 gst_pb_utils_get_codec_description (const GstCaps * caps)
1206 {
1207   const FormatInfo *info;
1208   gchar *str, *comma;
1209   GstCaps *tmp;
1210
1211   g_return_val_if_fail (caps != NULL, NULL);
1212   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
1213   tmp = copy_and_clean_caps (caps);
1214   g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
1215
1216   info = find_format_info (tmp);
1217
1218   if (info) {
1219     str = format_info_get_desc (info, tmp);
1220   } else {
1221     str = gst_caps_to_string (tmp);
1222
1223     /* cut off everything after the media type, if there is anything */
1224     if ((comma = strchr (str, ','))) {
1225       *comma = '\0';
1226       g_strchomp (str);
1227       /* we could do something more elaborate here, like taking into account
1228        * audio/, video/, image/ and application/ prefixes etc. */
1229     }
1230
1231     GST_WARNING ("No description available for media type: %s", str);
1232   }
1233   gst_caps_unref (tmp);
1234
1235   return str;
1236 }
1237
1238 /* internal helper functions for gst_encoding_profile_get_file_extension() */
1239 const gchar *pb_utils_get_file_extension_from_caps (const GstCaps * caps);
1240 gboolean pb_utils_is_tag (const GstCaps * caps);
1241
1242 const gchar *
1243 pb_utils_get_file_extension_from_caps (const GstCaps * caps)
1244 {
1245   const FormatInfo *info;
1246   const gchar *ext = NULL;
1247   GstCaps *stripped_caps;
1248
1249   g_assert (GST_IS_CAPS (caps));
1250
1251   stripped_caps = copy_and_clean_caps (caps);
1252
1253   g_assert (gst_caps_is_fixed (stripped_caps));
1254
1255   info = find_format_info (stripped_caps);
1256
1257   if (info && info->ext[0] != '\0') {
1258     ext = info->ext;
1259   } else if (info && info->desc == NULL) {
1260     const GstStructure *s;
1261
1262     s = gst_caps_get_structure (stripped_caps, 0);
1263
1264     /* cases where we have to evaluate the caps more closely */
1265     if (strcmp (info->type, "audio/mpeg") == 0) {
1266       int version = 0, layer = 3;
1267
1268       if (gst_structure_get_int (s, "mpegversion", &version)) {
1269         if (version == 2 || version == 4) {
1270           ext = "aac";
1271         } else if (version == 1) {
1272           gst_structure_get_int (s, "layer", &layer);
1273           if (layer == 1)
1274             ext = "mp1";
1275           else if (layer == 2)
1276             ext = "mp2";
1277           else
1278             ext = "mp3";
1279         }
1280       }
1281     }
1282   }
1283
1284   gst_caps_unref (stripped_caps);
1285   return ext;
1286 }
1287
1288 gboolean
1289 pb_utils_is_tag (const GstCaps * caps)
1290 {
1291   const FormatInfo *info;
1292   GstCaps *stripped_caps;
1293   gboolean is_tag = FALSE;
1294
1295   g_assert (GST_IS_CAPS (caps));
1296
1297   stripped_caps = copy_and_clean_caps (caps);
1298
1299   g_assert (gst_caps_is_fixed (stripped_caps));
1300
1301   info = find_format_info (stripped_caps);
1302
1303   if (info) {
1304     is_tag = (info->flags & FLAG_TAG) != 0;
1305   }
1306   gst_caps_unref (stripped_caps);
1307
1308   return is_tag;
1309 }
1310
1311 #if 0
1312 void
1313 gst_pb_utils_list_all (void)
1314 {
1315   gint i;
1316
1317   g_print ("static const gchar *caps_strings[] = { ");
1318
1319   for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
1320     if (formats[i].desc != NULL)
1321       g_print ("  \"%s\", ", formats[i].type);
1322   }
1323   g_print ("\n#if 0\n");
1324   for (i = 0; i < G_N_ELEMENTS (formats); ++i) {
1325     if (formats[i].desc == NULL)
1326       g_print ("  \"%s\", \n", formats[i].type);
1327   }
1328   g_print ("\n#endif\n");
1329 }
1330 #endif