gstffmpegcodecmap.c 22.1 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 23 24 25 26 27
#include "config.h"
#ifdef HAVE_FFMPEG_UNINSTALLED
#include <avcodec.h>
#else
#include <ffmpeg/avcodec.h>
#endif
28
#include <string.h>
29 30
#include <gst/gst.h>

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#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.
 */

#define GST_FF_VID_CAPS_NEW(name, mimetype, props...)		\
	(context != NULL) ?					\
	GST_CAPS_NEW (name,					\
		      mimetype,					\
		      "width",  GST_PROPS_INT (context->width),	\
		      "height", GST_PROPS_INT (context->height),\
		      ##props)					\
	:							\
	GST_CAPS_NEW (name,					\
		      mimetype,					\
		      "width",  GST_PROPS_INT_RANGE (16, 4096),	\
		      "height", GST_PROPS_INT_RANGE (16, 4096),	\
		      ##props)

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

#define GST_FF_AUD_CAPS_NEW(name, mimetype, props...)			\
	(context != NULL) ?						\
	GST_CAPS_NEW (name,						\
		      mimetype,						\
		      "rate",     GST_PROPS_INT (context->sample_rate),	\
		      "channels", GST_PROPS_INT (context->channels),	\
		      ##props)						\
	:								\
	GST_CAPS_NEW (name,						\
		      mimetype,						\
		      "rate",     GST_PROPS_INT_RANGE (8000, 96000),	\
		      "channels", GST_PROPS_INT_RANGE (1, 2),		\
		      ##props)

/* 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!
 */

77
GstCaps *
78 79
gst_ffmpeg_codecid_to_caps (enum CodecID    codec_id,
                            AVCodecContext *context)
80
{
81 82
  GstCaps *caps = NULL;

83
  switch (codec_id) {
84
    case CODEC_ID_MPEG1VIDEO:
85 86 87 88 89
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_mpeg1video",
                                  "video/mpeg",
                                    "mpegversion",  GST_PROPS_INT (1),
                                    "systemstream", GST_PROPS_BOOLEAN (FALSE)
                                 );
90
      break;
91 92 93

    case CODEC_ID_H263P:
    case CODEC_ID_H263I:
94
    case CODEC_ID_H263:
95 96 97
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_h263",
                                  "video/h263"
                                 );
98
      break;
99

100
    case CODEC_ID_RV10:
101 102 103
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_rv10",
                                  "video/realvideo"
                                 );
104
      break;
105

106
    case CODEC_ID_MP2:
107 108 109 110
      caps = GST_CAPS_NEW ("ffmpeg_mp2",
                           "audio/x-mp3",
                             "layer", GST_PROPS_INT (2)
                          );
111
      break;
112

113
    case CODEC_ID_MP3LAME:
114 115 116 117
      caps = GST_CAPS_NEW ("ffmpeg_mp3",
                           "audio/x-mp3",
                             "layer", GST_PROPS_INT (3)
                          );
118
      break;
119

120
    case CODEC_ID_VORBIS:
121
      caps = GST_CAPS_NEW ("ffmpeg_vorbis",
122
		           "application/x-ogg",
123 124
			   NULL
			  );
125
      break;
126
      
127
    case CODEC_ID_AC3:
128
      caps = GST_CAPS_NEW ("ffmpeg_ac3",
129
		           "audio/ac3",
130 131
			   NULL
			  );
132
      break;
133

134
    case CODEC_ID_MJPEG:
Wim Taymans's avatar
Wim Taymans committed
135
    case CODEC_ID_MJPEGB:
136 137 138
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_mjpeg",
                                  "video/jpeg"
                                 );
Wim Taymans's avatar
Wim Taymans committed
139
      break;
140

141
    case CODEC_ID_MPEG4:
142 143 144 145 146 147 148 149
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_mpeg4",
                                  "video/mpeg",
                                    "mpegversion",  GST_PROPS_INT (4),
                                    "systemstream", GST_PROPS_BOOLEAN (FALSE)
                                 );
      caps = gst_caps_append(caps,
             GST_FF_VID_CAPS_NEW ("ffmpeg_divx",
                                  "video/divx",
150
				    "divxversion",  GST_PROPS_INT (5)
151 152 153 154 155
                                 ));
      caps = gst_caps_append(caps,
             GST_FF_VID_CAPS_NEW ("ffmpeg_xvid",
                                  "video/xvid"
                                 ));
156
      break;
157

158
    case CODEC_ID_MSMPEG4V1:
159 160 161 162
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_msmpeg4v1",
                                  "video/x-msmpeg",
                                    "mpegversion", GST_PROPS_INT (41)
                                 );
163
      break;
164

165
    case CODEC_ID_MSMPEG4V2:
166 167 168 169
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_msmpeg4v2",
                                  "video/x-msmpeg",
                                    "mpegversion", GST_PROPS_INT (42)
                                 );
170
      break;
171

172
    case CODEC_ID_MSMPEG4V3:
173 174 175 176
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_msmpeg4v3",
                                  "video/x-msmpeg",
                                    "mpegversion", GST_PROPS_INT (43)
                                 );
177
      break;
178

179
    case CODEC_ID_WMV1:
180 181 182 183
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_wmv1",
                                  "video/wmv",
                                    "wmvversion", GST_PROPS_INT (1)
                                 );
184
      break;
185

186
    case CODEC_ID_WMV2:
187 188 189 190
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_wmv2",
                                  "video/wmv",
                                    "wmvversion", GST_PROPS_INT (2)
                                 );
191
      break;
192

193
    case CODEC_ID_SVQ1:
194 195 196 197
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_svq1",
                                  "video/x-svq",
                                    "svqversion", GST_PROPS_INT (1)
                                 );
198
      break;
199 200 201 202 203 204

    case CODEC_ID_SVQ3:
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_svq3",
                                  "video/x-svq",
                                    "svqversion", GST_PROPS_INT (3)
                                 );
205
      break;
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226

    case CODEC_ID_DVAUDIO: /* ??? */
    case CODEC_ID_DVVIDEO:
      if (!context) {
        caps = GST_FF_VID_CAPS_NEW ("ffmpeg_dvvideo",
                                    "video/dv",
                                      "format",  GST_PROPS_LIST (
                                                   GST_PROPS_STRING ("NTSC"),
                                                   GST_PROPS_STRING ("PAL")
                                                 )
                                   );
      } else {
        GstPropsEntry *normentry;

	if (context->height == 576) {
	  normentry = gst_props_entry_new("format", GST_PROPS_STRING ("PAL"));
	} else {
	  normentry = gst_props_entry_new("format", GST_PROPS_STRING ("NTSC"));
	}

        caps = GST_FF_VID_CAPS_NEW ("ffmpeg_dvvideo",
227
                                    "video/dv"
228 229 230
                                   );
	gst_props_add_entry(caps->properties, normentry);
      }
231
      break;
232

233
    case CODEC_ID_WMAV1:
234 235 236 237
      caps = GST_CAPS_NEW ("ffmpeg_wma1",
                           "audio/wma",
                             "wmaversion", GST_PROPS_INT (1)
                          );
238
      break;
239

240
    case CODEC_ID_WMAV2:
241 242 243 244
      caps = GST_CAPS_NEW ("ffmpeg_wma2",
                           "audio/wma",
                             "wmaversion", GST_PROPS_INT (2)
                          );
245
      break;
246

247
    case CODEC_ID_MACE3:
248
      /* .. */
249
      break;
250

251
    case CODEC_ID_MACE6:
252
      /* .. */
253
      break;
254

Wim Taymans's avatar
Wim Taymans committed
255
    case CODEC_ID_HUFFYUV:
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_huffyuv",
                                  "video/huffyuv"
                                 );
      break;

    case CODEC_ID_CYUV:
      /* .. */
      break;

    case CODEC_ID_H264:
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_h264",
                                  "video/h264"
                                 );
      break;

    case CODEC_ID_INDEO3:
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_indeo3",
                                  "video/indeo3"
                                 );
      break;

    case CODEC_ID_VP3:
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_vp3",
                                  "video/vp3"
                                 );
      caps = gst_caps_append(caps,
             GST_FF_VID_CAPS_NEW ("ffmpeg_theora",
                                  "video/x-theora"
                                 ));
      break;

    case CODEC_ID_AAC:
      /* .. */
      break;

    case CODEC_ID_MPEG4AAC:
      caps = GST_FF_VID_CAPS_NEW ("ffmpeg_mpeg4aac",
293
                                  "audio/mpeg",
294 295 296 297 298 299 300 301 302
                                    "systemstream", GST_PROPS_BOOLEAN (FALSE),
                                    "mpegversion",  GST_PROPS_INT (4)
                                 );
      break;

    case CODEC_ID_ASV1:
      /* .. */
      break;

303
    case CODEC_ID_ADPCM_IMA_QT:
304
      /* .. */
305
      break;
306

307
    case CODEC_ID_ADPCM_IMA_WAV:
308
      /* .. */
309
      break;
310

311
    case CODEC_ID_ADPCM_MS:
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 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 441 442 443 444 445 446 447 448
      /* .. */
      break;

    case CODEC_ID_AMR_NB:
      /* .. */
      break;

    default:
      /* .. */
      break;
  }

  if (caps != NULL) {
    char *str = g_strdup_printf("The caps that belongs to codec_id=%d",
				codec_id);
    gst_caps_debug(caps, str);
    g_free(str);
  }

  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;
      endianness = G_LITTLE_ENDIAN;
      r_mask = 0xff0000; g_mask = 0x00ff00; b_mask = 0x0000ff;
      break;
    case PIX_FMT_YUV422P:
      /* .. */
      break;
    case PIX_FMT_YUV444P:
      /* .. */
      break;
    case PIX_FMT_RGBA32:
      bpp = depth = 32;
      endianness = G_BYTE_ORDER;
      r_mask = 0x00ff0000; g_mask = 0x0000ff00; b_mask = 0x000000ff;
      break;
    case PIX_FMT_YUV410P:
      /* .. */
      break;
    case PIX_FMT_YUV411P:
      fmt = GST_MAKE_FOURCC ('Y','4','1','P');
      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) {
    fmt = GST_MAKE_FOURCC ('R','G','B',' ');
    caps = GST_FF_VID_CAPS_NEW ("ffmpeg_rawvideo",
                                "video/raw",
                                  "format",     GST_PROPS_FOURCC (fmt),
                                  "bpp",        GST_PROPS_INT (bpp),
                                  "depth",      GST_PROPS_INT (depth),
                                  "red_mask",   GST_PROPS_INT (r_mask),
                                  "green_mask", GST_PROPS_INT (g_mask),
                                  "blue_mask",  GST_PROPS_INT (b_mask),
                                  "endianness", GST_PROPS_INT (endianness)
                                );
  } else if (fmt) {
    caps = GST_FF_VID_CAPS_NEW ("ffmpeg_rawvideo",
                                "video/raw",
                                  "format",     GST_PROPS_FOURCC (fmt)
                               );
  }

  if (caps != NULL) {
    char *str = g_strdup_printf("The caps that belongs to pix_fmt=%d",
				pix_fmt);
    gst_caps_debug(caps, str);
    g_free(str);
  }

  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;
449
      break;
450

451
    default:
452
      /* .. */
453 454 455
      break;
  }

456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 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 526 527 528 529 530 531 532 533 534 535 536
  if (bpp) {
    caps = GST_FF_AUD_CAPS_NEW ("ffmpeg_rawaudio",
                                "audio/raw",
                                  "signed",     GST_PROPS_BOOLEAN (signedness),
                                  "endianness", GST_PROPS_INT (G_BYTE_ORDER),
                                  "width",      GST_PROPS_INT (bpp),
                                  "depth",      GST_PROPS_INT (bpp),
                                  "law",        GST_PROPS_INT (0),
                                  "format",     GST_PROPS_STRING ("int")
                                );
  }

  if (caps != NULL) {
    char *str = g_strdup_printf("The caps that belongs to sample_fmt=%d",
				sample_fmt);
    gst_caps_debug(caps, str);
    g_free(str);
  }

  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)
{
  GstCaps *caps = NULL;

  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;

        for (i = 0; i < PIX_FMT_NB; i++) {
          temp = gst_ffmpeg_pixfmt_to_caps (i, NULL);
          if (temp != NULL) {
            caps = gst_caps_append (caps, temp);
          }
        }
      }
      break;

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

        for (i = 0; i <= SAMPLE_FMT_S16; i++) {
          temp = gst_ffmpeg_smpfmt_to_caps (i, NULL);
          if (temp != NULL) {
            caps = gst_caps_append (caps, temp);
          }
        }
      }
      break;

    default:
      /* .. */
      break;
  }

  if (caps != NULL) {
    char *str = g_strdup_printf("The caps that belongs to codec_type=%d",
				codec_type);
    gst_caps_debug(caps, str);
    g_free(str);
  }

  return caps;
537
}
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 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 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693

/* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
 * and other audio properties in a AVCodecContext.
 *
 * For usefullness, see below
 */

static void
gst_ffmpeg_caps_to_smpfmt (GstCaps        *caps,
                           AVCodecContext *context)
{
  if (gst_caps_has_property_typed (caps, "width",
				   GST_PROPS_INT_TYPE) &&
      gst_caps_has_property_typed (caps, "depth",
				   GST_PROPS_INT_TYPE) &&
      gst_caps_has_property_typed (caps, "signed",
				   GST_PROPS_BOOLEAN_TYPE) &&
      gst_caps_has_property_typed (caps, "endianness",
				   GST_PROPS_INT_TYPE)) {
    gint depth = 0, width = 0, endianness = 0;
    gboolean signedness = FALSE;
    gst_caps_get (caps,
                  "width",      &width,
                  "depth",      &depth,
                  "endianness", &endianness,
                  "signed",     &signedness,
                  NULL);
    if (width == 16 && depth == 16 &&
        endianness == G_BYTE_ORDER && signedness == TRUE) {
      context->sample_fmt = SAMPLE_FMT_S16;
    }
  }

  if (gst_caps_has_property_typed (caps, "channels",
				   GST_PROPS_INT_TYPE)) {
    gst_caps_get_int (caps, "rate", &context->channels);
  }

  if (gst_caps_has_property_typed (caps, "rate",
				   GST_PROPS_INT_TYPE)) {
    gst_caps_get_int (caps, "rate", &context->sample_rate);
  }
}

/* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
 * and other video properties in a AVCodecContext.
 *
 * For usefullness, see below
 */

static void
gst_ffmpeg_caps_to_pixfmt (GstCaps        *caps,
                           AVCodecContext *context)
{
  if (gst_caps_has_property_typed (caps, "width",
				   GST_PROPS_INT_TYPE) &&
      gst_caps_has_property_typed (caps, "height",
				   GST_PROPS_INT_TYPE)) {
    gst_caps_get (caps,
                  "width",  &context->width,
                  "height", &context->height,
                  NULL);
  }

  if (gst_caps_has_property_typed (caps, "format",
				   GST_PROPS_FOURCC_TYPE)) {
    guint32 fourcc;
    gst_caps_get_fourcc_int (caps, "format", &fourcc);

    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','P'):
        context->pix_fmt = PIX_FMT_YUV411P;
        break;
      case GST_MAKE_FOURCC ('R','G','B',' '):
        if (gst_caps_has_property_typed (caps, "depth",
					 GST_PROPS_INT_TYPE) &&
	    gst_caps_has_property_typed (caps, "endianness",
					 GST_PROPS_INT_TYPE)) {
          gint depth = 0, endianness = 0;
          gst_caps_get_int (caps, "depth", &depth);
          gst_caps_get_int (caps, "endianness", &endianness);

          switch (depth) {
            case 32:
              if (endianness == G_BYTE_ORDER)
                context->pix_fmt = PIX_FMT_RGBA32;
              break;
            case 24:
              switch (endianness) {
                case G_LITTLE_ENDIAN:
                  context->pix_fmt = PIX_FMT_BGR24;
                  break;
                case G_BIG_ENDIAN:
                  context->pix_fmt = PIX_FMT_RGB24;
                  break;
                default:
                  /* nothing */
                  break;
              }
              break;
            case 16:
              if (endianness == G_BYTE_ORDER)
                context->pix_fmt = PIX_FMT_RGB565;
              break;
            case 15:
              if (endianness == G_BYTE_ORDER)
                context->pix_fmt = PIX_FMT_RGB555;
              break;
            default:
              /* nothing */
              break;
          }
        }
        break;
      default:
        /* nothing */
        break;
    }
  }
}

/* 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,
                              GstCaps        *caps,
                              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;
  }
}
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770

/* _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")) {
    caps = GST_CAPS_NEW ("ffmpeg_mpeg",
			 "video/mpeg",
                           "systemstream", GST_PROPS_BOOLEAN (TRUE)
                        );
  } else if (!strcmp (format_name, "mpegts")) {
    caps = GST_CAPS_NEW ("ffmpeg_mpegts",
			 "video/mpegts",
                           "systemstream", GST_PROPS_BOOLEAN (TRUE)
                        );
  } else if (!strcmp (format_name, "rm")) {
    caps = GST_CAPS_NEW ("ffmpeg_rm",
			 "audio/x-pn-realaudio",
                           NULL
                        );
  } else if (!strcmp (format_name, "asf")) {
    caps = GST_CAPS_NEW ("ffmpeg_asf",
			 "video/x-ms-asf",
                           NULL
                        );
  } else if (!strcmp (format_name, "avi")) {
    caps = GST_CAPS_NEW ("ffmpeg_avi",
			 "video/avi",
                           NULL
                        );
  } else if (!strcmp (format_name, "wav")) {
    caps = GST_CAPS_NEW ("ffmpeg_wav",
			 "video/x-wav",
                           NULL
                        );
  } else if (!strcmp (format_name, "swf")) {
    caps = GST_CAPS_NEW ("ffmpeg_swf",
			 "application/x-shockwave-flash",
                           NULL
                        );
  } else if (!strcmp (format_name, "au")) {
    caps = GST_CAPS_NEW ("ffmpeg_au",
			 "audio/basic",
                           NULL
                        );
  } else if (!strcmp (format_name, "mov")) {
    caps = GST_CAPS_NEW ("ffmpeg_quicktime",
			 "video/quicktime",
                           NULL
                        );
  } else if (!strcmp (format_name, "dv")) {
    caps = GST_CAPS_NEW ("ffmpeg_dv",
			 "video/dv",
                           "systemstream", GST_PROPS_BOOLEAN (TRUE)
                        );
  } else if (!strcmp (format_name, "4xm")) {
    caps = GST_CAPS_NEW ("ffmpeg_4xm",
			 "video/x-4xm",
                           NULL
                        );
  } else {
    /* unknown! */
  }

  return caps;
}
771 772 773 774 775 776 777 778

enum CodecID
gst_ffmpeg_caps_to_codecid (GstCaps *caps, enum CodecID *id)
{
  /* FIXME */
  return 0;
}