gstffmpegcodecmap.c 34.4 KB
Newer Older
1 2
/* GStreamer
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 4
 * This file:
 * Copyright (c) 2002-2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

22
#include "config.h"
23
#include <gst/gst.h>
24 25 26 27 28
#ifdef HAVE_FFMPEG_UNINSTALLED
#include <avcodec.h>
#else
#include <ffmpeg/avcodec.h>
#endif
29
#include <string.h>
30

31 32 33 34 35 36 37 38
#include "gstffmpegcodecmap.h"

/* this macro makes a caps width fixed or unfixed width/height
 * properties depending on whether we've got a context.
 *
 * See below for why we use this.
 */

David Schleef's avatar
David Schleef committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52
#define GST_FF_VID_CAPS_NEW(mimetype, props...)			\
    (context != NULL) ?						\
    gst_caps_new_simple (mimetype,			      	\
	"width",     G_TYPE_INT,   context->width,	      	\
	"height",    G_TYPE_INT,   context->height,	  	\
	"framerate", G_TYPE_DOUBLE, 1. * context->frame_rate /  \
				   context->frame_rate_base,    \
	##props, NULL)	  					\
    :	  							\
    gst_caps_new_simple (mimetype,			      	\
	"width",     GST_TYPE_INT_RANGE, 16, 4096,      	\
	"height",    GST_TYPE_INT_RANGE, 16, 4096,	      	\
	"framerate", GST_TYPE_DOUBLE_RANGE, 0., G_MAXDOUBLE,	\
	##props, NULL)
53 54 55 56

/* same for audio - now with channels/sample rate
 */

David Schleef's avatar
David Schleef committed
57 58 59 60 61 62 63 64 65
#define GST_FF_AUD_CAPS_NEW(mimetype, props...)			\
    (context != NULL) ?					      	\
    gst_caps_new_simple (mimetype,	      			\
	"rate", G_TYPE_INT, context->sample_rate,		\
	"channels", G_TYPE_INT, context->channels,		\
	##props, NULL)						\
    :								\
    gst_caps_new_simple (mimetype,	      			\
	##props, NULL)
66 67 68 69 70 71 72 73

/* Convert a FFMPEG codec ID and optional AVCodecContext
 * to a GstCaps. If the context is ommitted, no fixed values
 * for video/audio size will be included in the GstCaps
 *
 * CodecID is primarily meant for compressed data GstCaps!
 */

74
GstCaps *
75 76
gst_ffmpeg_codecid_to_caps (enum CodecID    codec_id,
                            AVCodecContext *context)
77
{
78 79
  GstCaps *caps = NULL;

80
  switch (codec_id) {
81
    case CODEC_ID_MPEG1VIDEO:
82
      /* this caps doesn't need width/height/framerate */
David Schleef's avatar
David Schleef committed
83 84 85 86
      caps = gst_caps_new_simple ("video/mpeg",
	  "mpegversion",  G_TYPE_INT,	  1,
          "systemstream", G_TYPE_BOOLEAN, FALSE,
          NULL);
87
      break;
David Schleef's avatar
David Schleef committed
88
      
89 90
    case CODEC_ID_H263P:
    case CODEC_ID_H263I:
91
    case CODEC_ID_H263:
David Schleef's avatar
David Schleef committed
92
      caps = GST_FF_VID_CAPS_NEW ("video/x-h263");
93
      break;
94

95
    case CODEC_ID_RV10:
David Schleef's avatar
David Schleef committed
96 97 98
      caps = GST_FF_VID_CAPS_NEW ("video/x-pn-realvideo",
	  "systemstream", G_TYPE_BOOLEAN, FALSE,
	  NULL);
99
      break;
100

101
    case CODEC_ID_MP2:
David Schleef's avatar
David Schleef committed
102 103 104 105
      caps = GST_FF_AUD_CAPS_NEW ("audio/mpeg",
	  "mpegversion", G_TYPE_INT, 1,
	  "layer", G_TYPE_INT, 2,
          NULL);
106
      break;
107

108
    case CODEC_ID_MP3LAME:
David Schleef's avatar
David Schleef committed
109 110 111 112
      caps = GST_FF_AUD_CAPS_NEW ("audio/mpeg",
	  "mpegversion", G_TYPE_INT, 1,
	  "layer", G_TYPE_INT, 3,
	  NULL);
113
      break;
114

David Schleef's avatar
David Schleef committed
115 116 117 118 119
    /* FIXME: This could become problematic when we fully switched to seperation
       of ogg and vorbis, because ffmpeg does ass ume ogg == ogg/vorbis 
       Maybe we want to disable this? */
    case CODEC_ID_VORBIS:
      caps = GST_FF_AUD_CAPS_NEW ("application/ogg");
120
      break;
121
      
122
    case CODEC_ID_AC3:
David Schleef's avatar
David Schleef committed
123
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-ac3");
124
      break;
125

126
    case CODEC_ID_MJPEG:
Wim Taymans's avatar
Wim Taymans committed
127
    case CODEC_ID_MJPEGB:
128
    /*case CODEC_ID_LJPEG:*/
David Schleef's avatar
David Schleef committed
129
      caps = GST_FF_VID_CAPS_NEW ("video/x-jpeg");
Wim Taymans's avatar
Wim Taymans committed
130
      break;
131

132
    case CODEC_ID_MPEG4:
David Schleef's avatar
David Schleef committed
133 134 135 136 137 138 139 140 141 142 143 144
      caps = GST_FF_VID_CAPS_NEW ("video/mpeg",
	  "mpegversion",  G_TYPE_INT, 4,
          "systemstream", G_TYPE_BOOLEAN, FALSE,
	  NULL);
      gst_caps_append(caps,
	  GST_FF_VID_CAPS_NEW ("video/x-divx",
	      "divxversion", GST_TYPE_INT_RANGE, 4, 5,
	      NULL));
      gst_caps_append(caps,
             GST_FF_VID_CAPS_NEW ("video/x-xvid"));
      gst_caps_append(caps,
             GST_FF_VID_CAPS_NEW ("video/x-3ivx"));
145
      break;
146

147 148 149 150 151
    /* weird quasi-codecs for the demuxers only */
    case CODEC_ID_RAWVIDEO:
      /* we use a shortcut to the raw-video pad function */
      return gst_ffmpeg_codectype_to_caps (CODEC_TYPE_VIDEO, context);

152
    case CODEC_ID_MSMPEG4V1:
David Schleef's avatar
David Schleef committed
153 154 155
      caps = GST_FF_VID_CAPS_NEW ("video/x-msmpeg",
	  "msmpegversion", G_TYPE_INT, 41,
	  NULL);
156
      break;
157

158
    case CODEC_ID_MSMPEG4V2:
David Schleef's avatar
David Schleef committed
159 160 161
      caps = GST_FF_VID_CAPS_NEW ("video/x-msmpeg",
          "msmpegversion", G_TYPE_INT, 42,
          NULL);
162
      break;
163

164
    case CODEC_ID_MSMPEG4V3:
David Schleef's avatar
David Schleef committed
165 166 167 168 169 170 171
      caps = GST_FF_VID_CAPS_NEW ("video/x-msmpeg",
	  "msmpegversion", G_TYPE_INT, 43,
	  NULL);
      gst_caps_append(caps,
          GST_FF_VID_CAPS_NEW ("video/x-divx",
	      "divxversion", G_TYPE_INT, 3,
              NULL));
172
      break;
173

174
    case CODEC_ID_WMV1:
David Schleef's avatar
David Schleef committed
175 176 177
      caps = GST_FF_VID_CAPS_NEW ("video/x-wmv",
	  "wmvversion", G_TYPE_INT, 1,
          NULL);
178
      break;
179

180
    case CODEC_ID_WMV2:
David Schleef's avatar
David Schleef committed
181 182 183
      caps = GST_FF_VID_CAPS_NEW ("video/x-wmv",
	  "wmvversion", G_TYPE_INT, 2,
          NULL);
184
      break;
185

186
    case CODEC_ID_SVQ1:
David Schleef's avatar
David Schleef committed
187 188 189
      caps = GST_FF_VID_CAPS_NEW ("video/x-svq",
	  "svqversion", G_TYPE_INT, 1,
          NULL);
190
      break;
191 192

    case CODEC_ID_SVQ3:
David Schleef's avatar
David Schleef committed
193 194 195
      caps = GST_FF_VID_CAPS_NEW ("video/x-svq",
	  "svqversion", G_TYPE_INT, 1,
          NULL);
196
      break;
197

198
    case CODEC_ID_DVAUDIO:
David Schleef's avatar
David Schleef committed
199
        caps = GST_FF_AUD_CAPS_NEW ("audio/x-dv");
200
        break;
201

202
    case CODEC_ID_DVVIDEO:
David Schleef's avatar
David Schleef committed
203
      caps = GST_FF_VID_CAPS_NEW ("video/dv");
204
      break;
205

206
    case CODEC_ID_WMAV1:
David Schleef's avatar
David Schleef committed
207 208 209 210 211 212 213
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-wma",
	  "wmaversion",  G_TYPE_INT,	      1,
          "flags1",      GST_TYPE_INT_RANGE,  G_MININT, G_MAXINT,
          "flags2",      GST_TYPE_INT_RANGE,  G_MININT, G_MAXINT,
          "block_align", GST_TYPE_INT_RANGE,  0, G_MAXINT,
          "bitrate",     GST_TYPE_INT_RANGE,  0, G_MAXINT,
	  NULL);
214
      break;
215

216
    case CODEC_ID_WMAV2:
David Schleef's avatar
David Schleef committed
217 218 219 220 221 222 223
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-wma",
	  "wmaversion",  G_TYPE_INT,	      2,
          "flags1",      GST_TYPE_INT_RANGE,  G_MININT, G_MAXINT,
          "flags2",      GST_TYPE_INT_RANGE,  G_MININT, G_MAXINT,
          "block_align", GST_TYPE_INT_RANGE,  0, G_MAXINT,
          "bitrate",     GST_TYPE_INT_RANGE,  0, G_MAXINT,
	  NULL);
224
      break;
225

226
    case CODEC_ID_MACE3:
David Schleef's avatar
David Schleef committed
227 228 229
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-mace",
	  "maceversion", G_TYPE_INT, 3,
          NULL);
230
      break;
231

232
    case CODEC_ID_MACE6:
David Schleef's avatar
David Schleef committed
233 234 235
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-mace",
	  "maceversion", G_TYPE_INT, 6,
          NULL);
236
      break;
237

Wim Taymans's avatar
Wim Taymans committed
238
    case CODEC_ID_HUFFYUV:
David Schleef's avatar
David Schleef committed
239
      caps = GST_FF_VID_CAPS_NEW ("video/x-huffyuv");
240 241 242 243 244 245 246
      break;

    case CODEC_ID_CYUV:
      /* .. */
      break;

    case CODEC_ID_H264:
David Schleef's avatar
David Schleef committed
247
      caps = GST_FF_VID_CAPS_NEW ("video/x-h264");
248 249 250
      break;

    case CODEC_ID_INDEO3:
David Schleef's avatar
David Schleef committed
251 252 253
      caps = GST_FF_VID_CAPS_NEW ("video/x-indeo",
	  "indeoversion", G_TYPE_INT, 3,
	  NULL);
254 255 256
      break;

    case CODEC_ID_VP3:
David Schleef's avatar
David Schleef committed
257 258 259
      caps = GST_FF_VID_CAPS_NEW ("video/x-vp3");
      gst_caps_append(caps,
             GST_FF_VID_CAPS_NEW ("video/x-theora"));
260 261 262
      break;

    case CODEC_ID_AAC:
David Schleef's avatar
David Schleef committed
263 264 265 266
      caps = GST_FF_AUD_CAPS_NEW ("audio/mpeg",
	  "systemstream", G_TYPE_BOOLEAN, FALSE,
	  "mpegversion",  G_TYPE_INT,	  2,
	  NULL);
267 268 269
      break;

    case CODEC_ID_MPEG4AAC:
David Schleef's avatar
David Schleef committed
270 271 272 273
      caps = GST_FF_AUD_CAPS_NEW ("audio/mpeg",
	  "systemstream", G_TYPE_BOOLEAN, FALSE,
	  "mpegversion",  G_TYPE_INT,	  4,
	  NULL);
274 275 276 277 278 279
      break;

    case CODEC_ID_ASV1:
      /* .. */
      break;

280
    case CODEC_ID_FFV1:
David Schleef's avatar
David Schleef committed
281 282 283
      caps = GST_FF_VID_CAPS_NEW ("video/x-ffv",
	  "ffvversion", G_TYPE_INT, 1,
	  NULL);
284 285 286
      break;

    case CODEC_ID_4XM:
David Schleef's avatar
David Schleef committed
287
      caps = GST_FF_VID_CAPS_NEW ("video/x-4xm");
288 289 290 291 292 293 294 295 296 297
      break;

    /* weird quasi-codecs for the demuxers only */
    case CODEC_ID_PCM_S16LE:
    case CODEC_ID_PCM_S16BE:
    case CODEC_ID_PCM_U16LE:
    case CODEC_ID_PCM_U16BE:
    case CODEC_ID_PCM_S8:
    case CODEC_ID_PCM_U8:
      do {
298
        gint width = 0, depth = 0, endianness = 0;
299 300 301 302
	gboolean signedness = FALSE; /* blabla */

        switch (codec_id) {
          case CODEC_ID_PCM_S16LE:
303
            width = 16; depth = 16;
304 305 306 307
            endianness = G_LITTLE_ENDIAN;
            signedness = TRUE;
            break;
          case CODEC_ID_PCM_S16BE:
308
            width = 16; depth = 16;
309 310 311 312
            endianness = G_BIG_ENDIAN;
            signedness = TRUE;
            break;
          case CODEC_ID_PCM_U16LE:
313
            width = 16; depth = 16;
314 315 316 317
            endianness = G_LITTLE_ENDIAN;
            signedness = FALSE;
            break;
          case CODEC_ID_PCM_U16BE:
318
            width = 16; depth = 16;
319 320 321 322
            endianness = G_BIG_ENDIAN;
            signedness = FALSE;
            break;
          case CODEC_ID_PCM_S8:
323
            width = 8;  depth = 8;
324 325 326 327
            endianness = G_BYTE_ORDER;
            signedness = TRUE;
            break;
          case CODEC_ID_PCM_U8:
328
            width = 8;  depth = 8;
329 330 331 332 333 334 335 336
            endianness = G_BYTE_ORDER;
            signedness = FALSE;
            break;
          default:
            g_assert(0); /* don't worry, we never get here */
            break;
        }

David Schleef's avatar
David Schleef committed
337 338 339 340 341 342
        caps = GST_FF_AUD_CAPS_NEW ("audio/x-raw-int",
	    "width",      G_TYPE_INT,	  width,
	    "depth",      G_TYPE_INT,	  depth,
	    "endianness", G_TYPE_INT,	  endianness,
	    "signed",     G_TYPE_BOOLEAN, signedness,
	    NULL);
343 344 345
      } while (0);
      break;

346
    case CODEC_ID_PCM_MULAW:
David Schleef's avatar
David Schleef committed
347
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-mulaw");
348 349 350
      break;

    case CODEC_ID_PCM_ALAW:
David Schleef's avatar
David Schleef committed
351
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-alaw");
352 353
      break;

354
    case CODEC_ID_ADPCM_IMA_QT:
David Schleef's avatar
David Schleef committed
355 356 357
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-adpcm",
	  "layout", G_TYPE_STRING, "quicktime",
          NULL);
358
      break;
359

360
    case CODEC_ID_ADPCM_IMA_WAV:
David Schleef's avatar
David Schleef committed
361 362 363
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-adpcm",
	  "layout", G_TYPE_STRING, "wav",
          NULL);
364
      break;
365

366
    case CODEC_ID_ADPCM_MS:
David Schleef's avatar
David Schleef committed
367 368 369
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-adpcm",
	  "layout", G_TYPE_STRING, "microsoft",
          NULL);
370 371 372
      break;

    case CODEC_ID_ADPCM_4XM:
David Schleef's avatar
David Schleef committed
373 374 375
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-adpcm",
	  "layout", G_TYPE_STRING, "4xm",
          NULL);
376 377 378 379 380 381
      break;

    case CODEC_ID_AMR_NB:
      /* .. */
      break;

382
    case CODEC_ID_RA_144:
David Schleef's avatar
David Schleef committed
383 384 385
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-pn-realaudio",
	  "bitrate", G_TYPE_INT, 14400,
          NULL);
386 387 388
      break;

    case CODEC_ID_RA_288:
David Schleef's avatar
David Schleef committed
389 390 391
      caps = GST_FF_AUD_CAPS_NEW ("audio/x-pn-realaudio",
	  "bitrate", G_TYPE_INT, 28800,
          NULL);
392
      break;
393

394 395 396 397 398 399
    default:
      /* .. */
      break;
  }

  if (caps != NULL) {
David Schleef's avatar
David Schleef committed
400 401
    char *str = gst_caps_to_string (caps);
    GST_DEBUG ("caps for codec_id=%d: %s", codec_id, str);
402
    g_free(str);
403
  } else {
David Schleef's avatar
David Schleef committed
404
    GST_WARNING ("No caps found for codec_id=%d", codec_id);
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
  }

  return caps;
}

/* Convert a FFMPEG Pixel Format and optional AVCodecContext
 * to a GstCaps. If the context is ommitted, no fixed values
 * for video/audio size will be included in the GstCaps
 *
 * See below for usefullness
 */

static GstCaps *
gst_ffmpeg_pixfmt_to_caps (enum PixelFormat  pix_fmt,
                           AVCodecContext   *context)
{
  GstCaps *caps = NULL;

  int bpp = 0, depth = 0, endianness = 0;
  gulong g_mask = 0, r_mask = 0, b_mask = 0;
  guint32 fmt = 0;

  switch (pix_fmt) {
    case PIX_FMT_YUV420P:
      fmt = GST_MAKE_FOURCC ('I','4','2','0');
      break;
    case PIX_FMT_YUV422:
      fmt = GST_MAKE_FOURCC ('Y','U','Y','2');
      break;
    case PIX_FMT_RGB24:
      bpp = depth = 24;
      endianness = G_BIG_ENDIAN;
      r_mask = 0xff0000; g_mask = 0x00ff00; b_mask = 0x0000ff;
      break;
    case PIX_FMT_BGR24:
      bpp = depth = 24;
441 442
      endianness = G_BIG_ENDIAN;
      r_mask = 0x0000ff; g_mask = 0x00ff00; b_mask = 0xff0000;
443 444
      break;
    case PIX_FMT_YUV422P:
445
      fmt = GST_MAKE_FOURCC ('Y','4','2','B');
446 447 448 449 450
      break;
    case PIX_FMT_YUV444P:
      /* .. */
      break;
    case PIX_FMT_RGBA32:
451
      bpp = 32; depth = 24;
452 453
      endianness = G_BIG_ENDIAN;
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
Benjamin Otte's avatar
Benjamin Otte committed
454
      r_mask = 0x00ff0000; g_mask = 0x0000ff00; b_mask = 0x000000ff;
455 456
#else 
      r_mask = 0x0000ff00; g_mask = 0x00ff0000; b_mask = 0xff000000;
457
#endif
458 459
      break;
    case PIX_FMT_YUV410P:
460
      fmt = GST_MAKE_FOURCC ('Y','U','V','9');
461 462
      break;
    case PIX_FMT_YUV411P:
463
      fmt = GST_MAKE_FOURCC ('Y','4','1','B');
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
      break;
    case PIX_FMT_RGB565:
      bpp = depth = 16;
      endianness = G_BYTE_ORDER;
      r_mask = 0xf800; g_mask = 0x07e0; b_mask = 0x001f;
      break;
    case PIX_FMT_RGB555:
      bpp = 16; depth = 15;
      endianness = G_BYTE_ORDER;
      r_mask = 0x7c00; g_mask = 0x03e0; b_mask = 0x001f;
      break;
    default:
      /* give up ... */
      break;
  }

  if (bpp != 0) {
David Schleef's avatar
David Schleef committed
481 482 483 484 485 486 487 488
    caps = GST_FF_VID_CAPS_NEW ("video/x-raw-rgb",
	"bpp",	      G_TYPE_INT, bpp,
        "depth",      G_TYPE_INT, depth,
        "red_mask",   G_TYPE_INT, r_mask,
        "green_mask", G_TYPE_INT, g_mask,
        "blue_mask",  G_TYPE_INT, b_mask,
	"endianness", G_TYPE_INT, endianness,
        NULL);
489
  } else if (fmt) {
David Schleef's avatar
David Schleef committed
490 491 492
    caps = GST_FF_VID_CAPS_NEW ("video/x-raw-yuv",
	"format",     GST_TYPE_FOURCC, fmt,
        NULL);
493 494 495
  }

  if (caps != NULL) {
David Schleef's avatar
David Schleef committed
496 497
    char *str = gst_caps_to_string (caps);
    GST_DEBUG ("caps for pix_fmt=%d: %s", pix_fmt, str);
498
    g_free(str);
499
  } else {
David Schleef's avatar
David Schleef committed
500
    GST_WARNING ("No caps found for pix_fmt=%d", pix_fmt);
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
  }

  return caps;
}

/* Convert a FFMPEG Sample Format and optional AVCodecContext
 * to a GstCaps. If the context is ommitted, no fixed values
 * for video/audio size will be included in the GstCaps
 *
 * See below for usefullness
 */

static GstCaps *
gst_ffmpeg_smpfmt_to_caps (enum SampleFormat  sample_fmt,
                           AVCodecContext    *context)
{
  GstCaps *caps = NULL;

  int bpp = 0;
  gboolean signedness = FALSE;

  switch (sample_fmt) {
    case SAMPLE_FMT_S16:
      signedness = TRUE;
      bpp = 16;
526
      break;
527

528
    default:
529
      /* .. */
530 531 532
      break;
  }

533
  if (bpp) {
David Schleef's avatar
David Schleef committed
534 535 536 537 538 539
    caps = GST_FF_AUD_CAPS_NEW ("audio/x-raw-int",
	"signed",     G_TYPE_BOOLEAN, signedness,
        "endianness", G_TYPE_INT,     G_BYTE_ORDER,
        "width",      G_TYPE_INT,     bpp,
        "depth",      G_TYPE_INT,     bpp,
        NULL);
540 541 542
  }

  if (caps != NULL) {
David Schleef's avatar
David Schleef committed
543 544
    char *str = gst_caps_to_string (caps);
    GST_DEBUG ("caps for sample_fmt=%d: %s", sample_fmt, str);
545
    g_free(str);
546
  } else {
David Schleef's avatar
David Schleef committed
547
    GST_WARNING ("No caps found for sample_fmt=%d", sample_fmt);
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
  }

  return caps;
}

/* Convert a FFMPEG codec Type and optional AVCodecContext
 * to a GstCaps. If the context is ommitted, no fixed values
 * for video/audio size will be included in the GstCaps
 *
 * CodecType is primarily meant for uncompressed data GstCaps!
 */

GstCaps *
gst_ffmpeg_codectype_to_caps (enum CodecType  codec_type,
                              AVCodecContext *context)
{
David Schleef's avatar
David Schleef committed
564
  GstCaps *caps;
565 566 567 568 569 570 571 572 573

  switch (codec_type) {
    case CODEC_TYPE_VIDEO:
      if (context) {
        caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context);
      } else {
        GstCaps *temp;
        enum PixelFormat i;

David Schleef's avatar
David Schleef committed
574
        caps = gst_caps_new_empty ();
575 576 577
        for (i = 0; i < PIX_FMT_NB; i++) {
          temp = gst_ffmpeg_pixfmt_to_caps (i, NULL);
          if (temp != NULL) {
David Schleef's avatar
David Schleef committed
578
            gst_caps_append (caps, temp);
579 580 581 582 583 584 585 586 587 588 589 590
          }
        }
      }
      break;

    case CODEC_TYPE_AUDIO:
      if (context) {
        caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context);
      } else {
        GstCaps *temp;
        enum SampleFormat i;

David Schleef's avatar
David Schleef committed
591
        caps = gst_caps_new_empty ();
592 593 594
        for (i = 0; i <= SAMPLE_FMT_S16; i++) {
          temp = gst_ffmpeg_smpfmt_to_caps (i, NULL);
          if (temp != NULL) {
David Schleef's avatar
David Schleef committed
595
            gst_caps_append (caps, temp);
596 597 598 599 600 601 602
          }
        }
      }
      break;

    default:
      /* .. */
David Schleef's avatar
David Schleef committed
603
      caps = NULL;
604 605 606 607
      break;
  }

  return caps;
608
}
609

610 611 612 613 614

/* Construct the context extradata from caps
 * when needed.
 */
static void
David Schleef's avatar
David Schleef committed
615
gst_ffmpeg_caps_to_extradata (const GstCaps *caps,
616 617
                              AVCodecContext *context)
{
David Schleef's avatar
David Schleef committed
618
  GstStructure *structure;
619 620
  const gchar *mimetype;

David Schleef's avatar
David Schleef committed
621 622 623 624
  g_return_if_fail (gst_caps_get_size (caps) == 1);
  structure = gst_caps_get_structure (caps, 0);
  
  mimetype = gst_structure_get_name (structure);
625 626

  if (!strcmp(mimetype, "audio/x-wma")) {
David Schleef's avatar
David Schleef committed
627
    gint flags1, flags2, wmaversion = 0;
628

David Schleef's avatar
David Schleef committed
629 630 631 632
    if (!gst_structure_get_int (structure, "flags1", &flags1) &&
	!gst_structure_get_int (structure, "flags2", &flags2) &&
	!gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
      g_warning ("invalid caps for audio/x-wma");
633 634 635
      return;
    }

David Schleef's avatar
David Schleef committed
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
    /* 
     * Rebuild context data from flags1 & flags2 
     * see wmadec in ffmpeg/libavcodec/wmadec.c 
     */
    gst_structure_get_int (structure, "wmaversion", &wmaversion);
    switch (wmaversion) {
      case 1:
	/* FIXME: is this freed with g_free? If not, don't use g_malloc */
	context->extradata = (guint8 *) g_malloc0 (4); 
	((guint8 *)context->extradata)[0] = flags1;
	((guint8 *)context->extradata)[2] = flags2;
	context->extradata_size = 4;
	break;
      case 2:
	/* FIXME: is this freed with g_free? If not, don't use g_malloc */
	context->extradata = (guint8 *) g_malloc0 (6);        
	((guint8 *) context->extradata)[0] = flags1;
	((guint8 *) context->extradata)[1] = flags1 >> 8;
	((guint8 *) context->extradata)[2] = flags1 >> 16;
	((guint8 *) context->extradata)[3] = flags1 >> 24;
	((guint8 *) context->extradata)[4] = flags2; 
	((guint8 *) context->extradata)[5] = flags2 >> 8;
	context->extradata_size = 6;
	break;
      default:
	g_warning ("Unknown wma version %d\n", wmaversion);
	break;
663 664 665 666 667
    }
  }
}


668 669 670 671 672 673 674
/* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
 * and other audio properties in a AVCodecContext.
 *
 * For usefullness, see below
 */

static void
David Schleef's avatar
David Schleef committed
675
gst_ffmpeg_caps_to_smpfmt (const GstCaps *caps,
676 677
                           AVCodecContext *context)
{
David Schleef's avatar
David Schleef committed
678 679 680 681 682 683 684 685 686 687 688
  GstStructure *structure;
  gint depth = 0, width = 0, endianness = 0;
  gboolean signedness = FALSE;

  g_return_if_fail (gst_caps_get_size (caps) == 1);
  structure = gst_caps_get_structure (caps, 0);
  
  if (gst_structure_get_int (structure, "width", &width) &&
      gst_structure_get_int (structure, "depth", &depth) &&
      gst_structure_get_int (structure, "signed", &signedness) &&
      gst_structure_get_int (structure, "endianness", &endianness)) {
689 690 691 692 693 694
    if (width == 16 && depth == 16 &&
        endianness == G_BYTE_ORDER && signedness == TRUE) {
      context->sample_fmt = SAMPLE_FMT_S16;
    }
  }

David Schleef's avatar
David Schleef committed
695 696 697 698
  gst_structure_get_int (structure, "channels", &context->channels);
  gst_structure_get_int (structure, "rate", &context->sample_rate);
  gst_structure_get_int (structure, "block_align", &context->block_align);
  gst_structure_get_int (structure, "bitrate", &context->bit_rate);
699

700
  gst_ffmpeg_caps_to_extradata (caps, context);
701 702
}

703

704 705 706 707 708 709 710
/* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
 * and other video properties in a AVCodecContext.
 *
 * For usefullness, see below
 */

static void
David Schleef's avatar
David Schleef committed
711
gst_ffmpeg_caps_to_pixfmt (const GstCaps *caps,
712 713
                           AVCodecContext *context)
{
David Schleef's avatar
David Schleef committed
714 715 716 717 718 719 720 721
  GstStructure *structure;
  gdouble fps;
  
  g_return_if_fail (gst_caps_get_size (caps) == 1);
  structure = gst_caps_get_structure (caps, 0);
  
  gst_structure_get_int (structure, "width", &context->width);
  gst_structure_get_int (structure, "height", &context->height);
722

David Schleef's avatar
David Schleef committed
723
  if (gst_structure_get_double (structure, "framerate", &fps)) {
724 725
    context->frame_rate = fps * DEFAULT_FRAME_RATE_BASE;
    context->frame_rate_base = DEFAULT_FRAME_RATE_BASE;
726 727
  }

David Schleef's avatar
David Schleef committed
728 729 730 731
  if (strcmp (gst_structure_get_name (structure), "video/x-raw-yuv") == 0) {
    guint32 fourcc;
    
    if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
Benjamin Otte's avatar
Benjamin Otte committed
732 733 734 735 736 737 738 739 740 741
      switch (fourcc) {
	case GST_MAKE_FOURCC ('Y','U','Y','2'):
	  context->pix_fmt = PIX_FMT_YUV422;
	  break;
	case GST_MAKE_FOURCC ('I','4','2','0'):
	  context->pix_fmt = PIX_FMT_YUV420P;
	  break;
	case GST_MAKE_FOURCC ('Y','4','1','B'):
	  context->pix_fmt = PIX_FMT_YUV411P;
	  break;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
742 743 744
	case GST_MAKE_FOURCC ('Y','4','2','B'):
	  context->pix_fmt = PIX_FMT_YUV422P;
	  break;
Benjamin Otte's avatar
Benjamin Otte committed
745 746 747
	case GST_MAKE_FOURCC ('Y','U','V','9'):
	  context->pix_fmt = PIX_FMT_YUV410P;
	  break;
748
#if 0
Benjamin Otte's avatar
Benjamin Otte committed
749 750 751
	case FIXME:
	  context->pix_fmt = PIX_FMT_YUV444P;
	  break;
752
#endif
Benjamin Otte's avatar
Benjamin Otte committed
753 754
      }
    }
David Schleef's avatar
David Schleef committed
755 756 757 758 759 760
  } else if (strcmp (gst_structure_get_name (structure), "video/x-raw-rgb") == 0) {
    gint bpp = 0, rmask = 0, endianness = 0;
    
    if (gst_structure_get_int (structure, "bpp", &bpp) &&
	gst_structure_get_int (structure, "endianness", &endianness) &&
	gst_structure_get_int (structure, "red_mask", &rmask)) {
Benjamin Otte's avatar
Benjamin Otte committed
761 762
      switch (bpp) {
        case 32:
Ronald S. Bultje's avatar
Ronald S. Bultje committed
763
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
764
          if (rmask == 0x00ff0000)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
765
#else
766
          if (rmask == 0x0000ff00)
Ronald S. Bultje's avatar
Ronald S. Bultje committed
767 768
#endif
            context->pix_fmt = PIX_FMT_RGBA32;
Benjamin Otte's avatar
Benjamin Otte committed
769 770
          break;
        case 24:
Ronald S. Bultje's avatar
Ronald S. Bultje committed
771 772 773 774
          if (rmask == 0x0000FF)
            context->pix_fmt = PIX_FMT_BGR24;
          else
            context->pix_fmt = PIX_FMT_RGB24;
Benjamin Otte's avatar
Benjamin Otte committed
775 776
	  break;
        case 16:
Ronald S. Bultje's avatar
Ronald S. Bultje committed
777 778
          if (endianness == G_BYTE_ORDER)
            context->pix_fmt = PIX_FMT_RGB565;
Benjamin Otte's avatar
Benjamin Otte committed
779 780
	  break;
        case 15:
Ronald S. Bultje's avatar
Ronald S. Bultje committed
781 782
          if (endianness == G_BYTE_ORDER)
            context->pix_fmt = PIX_FMT_RGB555;
Benjamin Otte's avatar
Benjamin Otte committed
783 784 785 786 787
	  break;
        default:
          /* nothing */
	  break;
      }
788 789 790 791 792 793 794 795 796 797 798 799 800
    }
  }
}

/* Convert a GstCaps and a FFMPEG codec Type to a
 * AVCodecContext. If the context is ommitted, no fixed values
 * for video/audio size will be included in the context
 *
 * CodecType is primarily meant for uncompressed data GstCaps!
 */

void
gst_ffmpeg_caps_to_codectype (enum CodecType  type,
David Schleef's avatar
David Schleef committed
801
                              const GstCaps *caps,
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
                              AVCodecContext *context)
{
  if (context == NULL)
    return;

  switch (type) {
    case CODEC_TYPE_VIDEO:
      gst_ffmpeg_caps_to_pixfmt (caps, context);
      break;

    case CODEC_TYPE_AUDIO:
      gst_ffmpeg_caps_to_smpfmt (caps, context);
      break;

    default:
      /* unknown */
      break;
  }
}
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837

/* _formatid_to_caps () is meant for muxers/demuxers, it
 * transforms a name (ffmpeg way of ID'ing these, why don't
 * they have unique numerical IDs?) to the corresponding
 * caps belonging to that mux-format
 *
 * Note: we don't need any additional info because the caps
 * isn't supposed to contain any useful info besides the
 * media type anyway
 */

GstCaps *
gst_ffmpeg_formatid_to_caps (const gchar *format_name)
{
  GstCaps *caps = NULL;

  if (!strcmp (format_name, "mpeg")) {
David Schleef's avatar
David Schleef committed
838 839 840
    caps = gst_caps_new_simple ("video/mpeg",
	"systemstream", G_TYPE_BOOLEAN, TRUE,
        NULL);
841
  } else if (!strcmp (format_name, "mpegts")) {
David Schleef's avatar
David Schleef committed
842 843 844
    caps = gst_caps_new_simple ("video/mpegts",
	"systemstream", G_TYPE_BOOLEAN, TRUE,
        NULL);
845
  } else if (!strcmp (format_name, "rm")) {
David Schleef's avatar
David Schleef committed
846 847 848
    caps = gst_caps_new_simple ("ffmpeg_rm", "audio/x-pn-realvideo",
	"systemstream", G_TYPE_BOOLEAN, TRUE,
        NULL);
849
  } else if (!strcmp (format_name, "asf")) {
David Schleef's avatar
David Schleef committed
850 851
    caps = gst_caps_new_simple ("video/x-ms-asf",
	NULL);
852
  } else if (!strcmp (format_name, "avi")) {
David Schleef's avatar
David Schleef committed
853 854
    caps = gst_caps_new_simple ("video/x-msvideo",
	NULL);
855
  } else if (!strcmp (format_name, "wav")) {
David Schleef's avatar
David Schleef committed
856 857
    caps = gst_caps_new_simple ("video/x-wav",
	NULL);
858
  } else if (!strcmp (format_name, "swf")) {
David Schleef's avatar
David Schleef committed
859 860
    caps = gst_caps_new_simple ("application/x-shockwave-flash",
	NULL);
861
  } else if (!strcmp (format_name, "au")) {
David Schleef's avatar
David Schleef committed
862 863
    caps = gst_caps_new_simple ("audio/x-au",
	NULL);
864
  } else if (!strcmp (format_name, "mov")) {
David Schleef's avatar
David Schleef committed
865 866
    caps = gst_caps_new_simple ("video/quicktime",
	NULL);
867
  } else if (!strcmp (format_name, "dv")) {
David Schleef's avatar
David Schleef committed
868 869 870
    caps = gst_caps_new_simple ("video/x-dv",
	"systemstream", G_TYPE_BOOLEAN, TRUE,
	NULL);
871
  } else if (!strcmp (format_name, "4xm")) {
David Schleef's avatar
David Schleef committed
872 873
    caps = gst_caps_new_simple ("video/x-4xm",
	NULL);
874 875 876 877 878 879
  } else {
    /* unknown! */
  }

  return caps;
}
880 881 882 883 884 885 886 887 888

/* Convert a GstCaps to a FFMPEG codec ID. Size et all
 * are omitted, that can be queried by the user itself,
 * we're not eating the GstCaps or anything
 * A pointer to an allocated context is also needed for
 * optional extra info (not used yet, though)
 */

enum CodecID
David Schleef's avatar
David Schleef committed
889
gst_ffmpeg_caps_to_codecid (const GstCaps *caps,
890 891 892 893
                            AVCodecContext *context)
{
  enum CodecID id = CODEC_ID_NONE;
  const gchar *mimetype;
David Schleef's avatar
David Schleef committed
894
  const GstStructure *structure;
895 896 897
  gboolean video = FALSE, audio = FALSE; /* we want to be sure! */

  g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
David Schleef's avatar
David Schleef committed
898 899 900 901
  g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
  structure = gst_caps_get_structure (caps, 0);
  
  mimetype = gst_structure_get_name (structure);
902

Ronald S. Bultje's avatar
Ronald S. Bultje committed
903 904 905 906 907 908 909 910
  if (!strcmp (mimetype, "video/x-raw-rgb")) {

    id = CODEC_ID_RAWVIDEO;

    if (context != NULL) {
      gint bpp = 0, endianness = 0, rmask = 0;
      enum PixelFormat pix_fmt = -1;

David Schleef's avatar
David Schleef committed
911 912 913
      gst_structure_get_int (structure, "bpp",        &bpp);
      gst_structure_get_int (structure, "endianness", &endianness);
      gst_structure_get_int (structure, "rmask",      &rmask);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
  
      switch (bpp) {
        case 15:
          if (endianness == G_BYTE_ORDER) {
            pix_fmt = PIX_FMT_RGB555;
          }
          break;
        case 16:
          if (endianness == G_BYTE_ORDER) {
            pix_fmt = PIX_FMT_RGB565;
          }
          break;
        case 24:
          if (rmask == 0xff0000) {
            pix_fmt = PIX_FMT_RGB24;
          } else {
            pix_fmt = PIX_FMT_BGR24;
          }
          break;
        case 32:
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
          if (rmask == 0xff0000) {
#else
          if (rmask == 0x0000ff) {
#endif
            pix_fmt = PIX_FMT_RGBA32;
          }
          break;
        default:
          /* ... */
          break;
      }

      /* only set if actually recognized! */
      if (pix_fmt != -1) {
        video = TRUE;
        context->pix_fmt = pix_fmt;
      } else {
        id = CODEC_ID_NONE;
      }
    }

  } else if (!strcmp (mimetype, "video/x-raw-yuv")) {
957 958 959 960 961 962 963

    id = CODEC_ID_RAWVIDEO;

    if (context != NULL) {
      guint32 fmt_fcc = 0;
      enum PixelFormat pix_fmt = -1;

David Schleef's avatar
David Schleef committed
964
      gst_structure_get_fourcc (structure, "format", &fmt_fcc);
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000

      switch (fmt_fcc) {
        case GST_MAKE_FOURCC ('Y','U','Y','2'):
          pix_fmt = PIX_FMT_YUV422;
          break;
        case GST_MAKE_FOURCC ('I','4','2','0'):
          pix_fmt = PIX_FMT_YUV420P;
          break;
        case GST_MAKE_FOURCC ('Y','4','1','B'):
          pix_fmt = PIX_FMT_YUV411P;
          break;
        case GST_MAKE_FOURCC ('Y','4','2','B'):
          pix_fmt = PIX_FMT_YUV422P;
          break;
        case GST_MAKE_FOURCC ('Y','U','V','9'):
          pix_fmt = PIX_FMT_YUV410P;
          break;
        default:
          /* ... */
          break;
      }

      /* only set if actually recognized! */
      if (pix_fmt != -1) {
        video = TRUE;
        context->pix_fmt = pix_fmt;
      } else {
        id = CODEC_ID_NONE;
      }
    }

  } else if (!strcmp (mimetype, "audio/x-raw-int")) {

    gint depth = 0, width = 0, endianness = 0;
    gboolean signedness = FALSE; /* bla default value */

David Schleef's avatar
David Schleef committed
1001 1002 1003 1004
    gst_structure_get_int (structure, "endianness", &endianness);
    gst_structure_get_boolean (structure, "signed", &signedness);
    gst_structure_get_int (structure, "width", &width);
    gst_structure_get_int (structure, "depth", &depth);
1005

David Schleef's avatar
David Schleef committed
1006 1007 1008 1009 1010 1011
    if (context) {
      context->sample_rate = 0;
      context->channels = 0;
      gst_structure_get_int (structure, "channels", &context->channels);
      gst_structure_get_int (structure, "rate", &context->sample_rate);
    }
1012

David Schleef's avatar
David Schleef committed
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
    if (depth == width) {
      switch (depth) {
	case 8:
	  if (signedness) {
	    id = CODEC_ID_PCM_S8;
	  } else {
	    id = CODEC_ID_PCM_U8;
	  }
	  break;
	case 16:
	  switch (endianness) {
	    case G_BIG_ENDIAN:
	      if (signedness) {
		id = CODEC_ID_PCM_S16BE;
	      } else {
		id = CODEC_ID_PCM_U16BE;
	      }
	      break;
	    case G_LITTLE_ENDIAN:
	      if (signedness) {
		id = CODEC_ID_PCM_S16LE;
	      } else {
		id = CODEC_ID_PCM_U16LE;
	      }
	      break;
	  }
	  break;
      }
1041

David Schleef's avatar
David Schleef committed
1042 1043
      if (id != CODEC_ID_NONE) {
	audio = TRUE;
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
      }
    }

  } else if (!strcmp(mimetype, "audio/x-mulaw")) {

    id = CODEC_ID_PCM_MULAW;
    audio = TRUE;

  } else if (!strcmp(mimetype, "audio/x-alaw")) {

    id = CODEC_ID_PCM_ALAW;
    audio = TRUE;

  } else if (!strcmp(mimetype, "video/x-dv")) {

    id = CODEC_ID_DVVIDEO;
    video = TRUE;

  } else if (!strcmp(mimetype, "audio/x-dv")) { /* ??? */

    id = CODEC_ID_DVAUDIO;
    audio = TRUE;

  } else if (!strcmp(mimetype, "video/x-h263")) {

    id = CODEC_ID_H263; /* or H263[IP] */
    video = TRUE;

  } else if (!strcmp(mimetype, "video/mpeg")) {

    gboolean sys_strm = TRUE;
    gint mpegversion = 0;
David Schleef's avatar
David Schleef committed
1076 1077 1078
    gst_structure_get_boolean (structure, "systemstream", &sys_strm);
    gst_structure_get_int (structure, "mpegversion", &mpegversion);
    if (!sys_strm) {
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
      switch (mpegversion) {
        case 1:
          id = CODEC_ID_MPEG1VIDEO;
          break;
        case 4:
          id = CODEC_ID_MPEG4;
          break;
        default:
          /* ... */
          break;
      }
    }

    if (id != CODEC_ID_NONE) {
      video = TRUE;
    }

  } else if (!strcmp(mimetype, "video/x-jpeg")) {

    id = CODEC_ID_MJPEG; /* A... B... */
    video = TRUE;

  } else if (!strcmp(mimetype, "video/x-wmv")) {
David Schleef's avatar
David Schleef committed
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
    gint wmvversion = 0;

    gst_structure_get_int (structure, "wmvversion", &wmvversion);

    switch (wmvversion) {
      case 1:
	id = CODEC_ID_WMV1;
	break;
      case 2:
	id = CODEC_ID_WMV2;
	break;
      default:
	/* ... */
	break;
    }
1117

David Schleef's avatar
David Schleef committed
1118 1119
    if (id != CODEC_ID_NONE) {
      video = TRUE;
1120 1121 1122 1123 1124 1125 1126
    }

  } else if (!strcmp(mimetype, "application/ogg")) {

    id = CODEC_ID_VORBIS;

  } else if (!strcmp(mimetype, "audio/mpeg")) {
David Schleef's avatar
David Schleef committed
1127 1128
    gint layer = 0;
    gint mpegversion = 0;
1129

David Schleef's avatar
David Schleef committed
1130
    if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
1131 1132 1133 1134
      switch (mpegversion) {
        case 2: /* ffmpeg uses faad for both... */
        case 4:
          id = CODEC_ID_MPEG4AAC;
1135
          break;
1136
        case 1:
David Schleef's avatar
David Schleef committed
1137
          if (gst_structure_get_int (structure, "layer", &layer)) {
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
            switch (layer) {
              case 1:
              case 2:
                id = CODEC_ID_MP2;
                break;
              case 3:
                id = CODEC_ID_MP3;
                break;
              default:
                /* ... */
                break;
            }
          }
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
        default:
          /* ... */
          break;
      }
    }

    if (id != CODEC_ID_NONE) {
      audio = TRUE;
    }

  } else if (!strcmp(mimetype, "audio/x-wma")) {
David Schleef's avatar
David Schleef committed
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
    gint wmaversion = 0;

    gst_structure_get_int (structure, "wmaversion", &wmaversion);

    switch (wmaversion) {
      case 1:
	id = CODEC_ID_WMAV1;
	break;
      case 2:
	id = CODEC_ID_WMAV2;
	break;
      default:
	/* ... */
	break;
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
    }

    if (id != CODEC_ID_NONE) {
      audio = TRUE;
    }

  } else if (!strcmp(mimetype, "audio/x-ac3")) {

    id = CODEC_ID_AC3;

  } else if (!strcmp(mimetype, "video/x-msmpeg")) {
David Schleef's avatar
David Schleef committed
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
    gint msmpegversion = 0;

    gst_structure_get_int (structure, "msmpegversion", &msmpegversion);

    switch (msmpegversion) {
      case 41:
	id = CODEC_ID_MSMPEG4V1;
	break;
      case 42:
	id = CODEC_ID_MSMPEG4V2;
	break;
      case 43:
	id = CODEC_ID_MSMPEG4V3;
	break;
      default:
	/* ... */
	break;
1204 1205 1206 1207 1208 1209 1210
    }

    if (id != CODEC_ID_NONE) {
      video = TRUE;
    }

  } else if (!strcmp(mimetype, "video/x-svq")) {
David Schleef's avatar
David Schleef committed
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
    gint svqversion = 0;

    gst_structure_get_int (structure, "svqversion", &svqversion);

    switch (svqversion) {
      case 1:
	id = CODEC_ID_SVQ1;
	break;
      case 3:
	id = CODEC_ID_SVQ3;
	break;
      default:
	/* ... */
	break;
1225 1226