2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * Copyright (c) 2002-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
26 #ifdef HAVE_FFMPEG_UNINSTALLED
29 #include <libavcodec/avcodec.h>
33 #include "gstffmpeg.h"
34 #include "gstffmpegcodecmap.h"
36 #include <gst/video/video.h>
37 #include <gst/audio/audio.h>
38 #include <gst/pbutils/codec-utils.h>
41 * Read a palette from a caps.
45 gst_ffmpeg_get_palette (const GstCaps * caps, AVCodecContext * context)
47 GstStructure *str = gst_caps_get_structure (caps, 0);
48 const GValue *palette_v;
51 /* do we have a palette? */
52 if ((palette_v = gst_structure_get_value (str, "palette_data")) && context) {
53 palette = gst_value_get_buffer (palette_v);
54 if (gst_buffer_get_size (palette) >= AVPALETTE_SIZE) {
56 av_free (context->palctrl);
57 context->palctrl = av_malloc (sizeof (AVPaletteControl));
58 context->palctrl->palette_changed = 1;
59 gst_buffer_extract (palette, 0, context->palctrl->palette,
66 gst_ffmpeg_set_palette (GstCaps * caps, AVCodecContext * context)
68 if (context->palctrl) {
69 GstBuffer *palette = gst_buffer_new_and_alloc (AVPALETTE_SIZE);
71 gst_buffer_fill (palette, 0, context->palctrl->palette, AVPALETTE_SIZE);
72 gst_caps_set_simple (caps, "palette_data", GST_TYPE_BUFFER, palette, NULL);
76 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
80 GstAudioChannelPosition gst;
81 } _ff_to_gst_layout[] = {
83 CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
84 CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
85 CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
86 CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE}, {
87 CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
88 CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
89 CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
90 CH_FRONT_RIGHT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
91 CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
92 CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
93 CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
94 CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
95 CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
96 CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
97 CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
98 CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
99 CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
100 CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
101 CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
102 CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
105 static GstAudioChannelPosition *
106 gst_ff_channel_layout_to_gst (guint64 channel_layout, guint channels)
108 guint nchannels = 0, i, j;
109 GstAudioChannelPosition *pos = NULL;
110 gboolean none_layout = FALSE;
112 for (i = 0; i < 64; i++) {
113 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
118 if (channel_layout == 0) {
119 nchannels = channels;
123 if (nchannels != channels) {
124 GST_ERROR ("Number of channels is different (%u != %u)", channels,
129 pos = g_new (GstAudioChannelPosition, nchannels);
131 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
132 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
133 pos[j++] = _ff_to_gst_layout[i].gst;
135 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
140 if (j != nchannels) {
141 GST_WARNING ("Unknown channels in channel layout - assuming NONE layout");
145 if (!none_layout && !gst_audio_check_channel_positions (pos, nchannels)) {
146 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
147 " - assuming NONE layout", channel_layout);
152 if (nchannels == 1) {
153 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
154 } else if (nchannels == 2) {
155 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
156 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
157 } else if (channel_layout == 0) {
161 for (i = 0; i < nchannels; i++)
162 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
166 if (nchannels == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER) {
167 GST_DEBUG ("mono common case; won't set channel positions");
170 } else if (nchannels == 2 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
171 && pos[1] == GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT) {
172 GST_DEBUG ("stereo common case; won't set channel positions");
180 /* this macro makes a caps width fixed or unfixed width/height
181 * properties depending on whether we've got a context.
183 * See below for why we use this.
185 * We should actually do this stuff at the end, like in riff-media.c,
186 * but I'm too lazy today. Maybe later.
189 gst_ff_vid_caps_new (AVCodecContext * context, enum CodecID codec_id,
190 const char *mimetype, const char *fieldname, ...)
192 GstStructure *structure = NULL;
193 GstCaps *caps = NULL;
197 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
199 /* fixed, non probing context */
200 if (context != NULL && context->width != -1) {
203 caps = gst_caps_new_simple (mimetype,
204 "width", G_TYPE_INT, context->width,
205 "height", G_TYPE_INT, context->height, NULL);
207 num = context->time_base.den / context->ticks_per_frame;
208 denom = context->time_base.num;
211 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
214 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
215 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
219 GST_LOG ("setting framerate: %d/%d", num, denom);
220 gst_caps_set_simple (caps,
221 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
223 /* so we are after restricted caps in this case */
227 caps = gst_caps_new_simple (mimetype,
228 "width", G_TYPE_INT, 352,
229 "height", G_TYPE_INT, 288,
230 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
231 gst_caps_append (caps, gst_caps_new_simple (mimetype,
232 "width", G_TYPE_INT, 176,
233 "height", G_TYPE_INT, 144,
234 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
239 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
240 * because we want automatic negotiation to go as close to 320x240 as
242 const static gint widths[] = { 352, 704, 176, 1408, 128 };
243 const static gint heights[] = { 288, 576, 144, 1152, 96 };
245 gint n_sizes = G_N_ELEMENTS (widths);
247 caps = gst_caps_new_empty ();
248 for (i = 0; i < n_sizes; i++) {
249 temp = gst_caps_new_simple (mimetype,
250 "width", G_TYPE_INT, widths[i],
251 "height", G_TYPE_INT, heights[i],
252 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
254 gst_caps_append (caps, temp);
258 case CODEC_ID_DVVIDEO:
265 gint framerate_n, framerate_d;
268 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 10, 11, 30000, 1001}, {
269 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 40, 33, 30000, 1001}, {
270 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 59, 54, 25, 1}, {
271 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 118, 81, 25, 1}, {
272 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 59, 54, 25, 1}, {
273 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 118, 81, 25, 1}
276 gint n_sizes = G_N_ELEMENTS (profiles);
278 caps = gst_caps_new_empty ();
279 for (i = 0; i < n_sizes; i++) {
280 temp = gst_caps_new_simple (mimetype,
281 "width", G_TYPE_INT, profiles[i].width,
282 "height", G_TYPE_INT, profiles[i].height,
283 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
284 profiles[i].framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION,
285 profiles[i].par_n, profiles[i].par_d, NULL);
287 gst_caps_append (caps, temp);
293 caps = gst_caps_new_simple (mimetype,
294 "width", G_TYPE_INT, 1920,
295 "height", G_TYPE_INT, 1080,
296 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
297 gst_caps_append (caps, gst_caps_new_simple (mimetype,
298 "width", G_TYPE_INT, 1280,
299 "height", G_TYPE_INT, 720,
300 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
308 /* no fixed caps or special restrictions applied;
309 * default unfixed setting */
311 GST_DEBUG ("Creating default caps");
312 caps = gst_caps_new_simple (mimetype,
313 "width", GST_TYPE_INT_RANGE, 16, 4096,
314 "height", GST_TYPE_INT_RANGE, 16, 4096,
315 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
318 for (i = 0; i < gst_caps_get_size (caps); i++) {
319 va_start (var_args, fieldname);
320 structure = gst_caps_get_structure (caps, i);
321 gst_structure_set_valist (structure, fieldname, var_args);
328 /* same for audio - now with channels/sample rate
331 gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
332 const char *mimetype, const char *fieldname, ...)
334 GstCaps *caps = NULL;
335 GstStructure *structure = NULL;
339 /* fixed, non-probing context */
340 if (context != NULL && context->channels != -1) {
341 GstAudioChannelPosition *pos;
342 guint64 channel_layout = context->channel_layout;
344 if (channel_layout == 0) {
345 const guint64 default_channel_set[] = {
346 0, 0, CH_LAYOUT_SURROUND, CH_LAYOUT_QUAD, CH_LAYOUT_5POINT0,
347 CH_LAYOUT_5POINT1, 0, CH_LAYOUT_7POINT1
354 if (context->channels > 0
355 && context->channels < G_N_ELEMENTS (default_channel_set))
356 channel_layout = default_channel_set[context->channels - 1];
363 caps = gst_caps_new_simple (mimetype,
364 "rate", G_TYPE_INT, context->sample_rate,
365 "channels", G_TYPE_INT, context->channels, NULL);
367 pos = gst_ff_channel_layout_to_gst (channel_layout, context->channels);
369 gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
373 gint maxchannels = 2;
374 const gint *rates = NULL;
378 /* so we must be after restricted caps in this particular case */
382 const static gint l_rates[] =
383 { 48000, 44100, 32000, 24000, 22050, 16000 };
384 n_rates = G_N_ELEMENTS (l_rates);
391 const static gint l_rates[] = { 48000, 44100, 32000 };
392 n_rates = G_N_ELEMENTS (l_rates);
396 case CODEC_ID_ADPCM_SWF:
398 const static gint l_rates[] = { 11025, 22050, 44100 };
399 n_rates = G_N_ELEMENTS (l_rates);
403 case CODEC_ID_ROQ_DPCM:
405 const static gint l_rates[] = { 22050 };
406 n_rates = G_N_ELEMENTS (l_rates);
410 case CODEC_ID_ADPCM_G726:
413 case CODEC_ID_AMR_NB:
415 const static gint l_rates[] = { 8000 };
417 n_rates = G_N_ELEMENTS (l_rates);
421 case CODEC_ID_AMR_WB:
423 const static gint l_rates[] = { 16000 };
425 n_rates = G_N_ELEMENTS (l_rates);
433 /* TODO: handle context->channel_layouts here to set
434 * the list of channel layouts supported by the encoder.
435 * Unfortunately no encoder uses this yet....
439 /* regardless of encode/decode, open up channels if applicable */
440 /* Until decoders/encoders expose the maximum number of channels
441 * they support, we whitelist them here. */
446 case CODEC_ID_AAC_LATM:
450 case CODEC_ID_WMAPRO:
451 case CODEC_ID_TRUEHD:
459 if (maxchannels == 1)
460 caps = gst_caps_new_simple (mimetype,
461 "channels", G_TYPE_INT, maxchannels, NULL);
463 caps = gst_caps_new_simple (mimetype,
464 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
466 GValue list = { 0, };
467 GstStructure *structure;
469 g_value_init (&list, GST_TYPE_LIST);
470 for (i = 0; i < n_rates; i++) {
473 g_value_init (&v, G_TYPE_INT);
474 g_value_set_int (&v, rates[i]);
475 gst_value_list_append_value (&list, &v);
478 structure = gst_caps_get_structure (caps, 0);
479 gst_structure_set_value (structure, "rate", &list);
480 g_value_unset (&list);
482 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
485 for (i = 0; i < gst_caps_get_size (caps); i++) {
486 va_start (var_args, fieldname);
487 structure = gst_caps_get_structure (caps, i);
488 gst_structure_set_valist (structure, fieldname, var_args);
495 /* Convert a FFMPEG codec ID and optional AVCodecContext
496 * to a GstCaps. If the context is ommitted, no fixed values
497 * for video/audio size will be included in the GstCaps
499 * CodecID is primarily meant for compressed data GstCaps!
501 * encode is a special parameter. gstffmpegdec will say
502 * FALSE, gstffmpegenc will say TRUE. The output caps
503 * depends on this, in such a way that it will be very
504 * specific, defined, fixed and correct caps for encoders,
505 * yet very wide, "forgiving" caps for decoders. Example
506 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
507 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
512 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
513 AVCodecContext * context, gboolean encode)
515 GstCaps *caps = NULL;
516 gboolean buildcaps = FALSE;
518 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
521 case CODEC_ID_MPEG1VIDEO:
523 caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
524 "mpegversion", G_TYPE_INT, 1,
525 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
528 case CODEC_ID_MPEG2VIDEO:
531 caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
532 "mpegversion", G_TYPE_INT, 2,
533 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
535 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
536 * the MPEG video stream headers, so may be omitted from caps. */
537 caps = gst_caps_new_simple ("video/mpeg",
538 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
539 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
543 case CODEC_ID_MPEG2VIDEO_XVMC:
544 /* this is a special ID - don't need it in GStreamer, I think */
549 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h263",
550 "variant", G_TYPE_STRING, "itu",
551 "h263version", G_TYPE_STRING, "h263", NULL);
553 /* don't pass codec_id, we can decode other variants with the H263
554 * decoder that don't have specific size requirements
556 caps = gst_ff_vid_caps_new (context, CODEC_ID_NONE, "video/x-h263",
557 "variant", G_TYPE_STRING, "itu", NULL);
562 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h263",
563 "variant", G_TYPE_STRING, "itu",
564 "h263version", G_TYPE_STRING, "h263p", NULL);
565 if (encode && context) {
567 gst_caps_set_simple (caps,
568 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
569 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
570 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
571 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
577 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-intel-h263",
578 "variant", G_TYPE_STRING, "intel", NULL);
582 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h261", NULL);
607 /* FIXME: context->sub_id must be filled in during decoding */
608 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-pn-realvideo",
609 "systemstream", G_TYPE_BOOLEAN, FALSE,
610 "rmversion", G_TYPE_INT, version, NULL);
612 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
613 if (context->extradata_size >= 8) {
614 gst_caps_set_simple (caps,
615 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
624 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
625 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
630 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
631 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
637 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
638 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
640 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
641 * in the MPEG audio header, so may be omitted from caps. */
642 caps = gst_caps_new_simple ("audio/mpeg",
643 "mpegversion", G_TYPE_INT, 1,
644 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
648 case CODEC_ID_MUSEPACK7:
650 gst_ff_aud_caps_new (context, codec_id,
651 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
655 case CODEC_ID_MUSEPACK8:
657 gst_ff_aud_caps_new (context, codec_id,
658 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
664 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-ac3", NULL);
669 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-eac3", NULL);
672 case CODEC_ID_TRUEHD:
673 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-true-hd", NULL);
676 case CODEC_ID_ATRAC1:
678 gst_ff_aud_caps_new (context, codec_id, "audio/x-vnd.sony.atrac1",
682 case CODEC_ID_ATRAC3:
684 gst_ff_aud_caps_new (context, codec_id, "audio/x-vnd.sony.atrac3",
689 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dts", NULL);
694 gst_ff_aud_caps_new (context, codec_id, "audio/x-ffmpeg-parsed-ape",
697 gst_caps_set_simple (caps,
698 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
703 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mlp", NULL);
707 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-imc", NULL);
710 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
711 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
712 * sp5x is, but it's apparently something JPEG... We don't separate
713 * between those in GStreamer. Should we (at least between MJPEG,
714 * MJPEG-B and sp5x decoding...)? */
717 caps = gst_ff_vid_caps_new (context, codec_id, "image/jpeg", NULL);
721 caps = gst_ff_vid_caps_new (context, codec_id, "video/sp5x", NULL);
724 case CODEC_ID_MJPEGB:
725 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mjpeg-b", NULL);
729 if (encode && context != NULL) {
730 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
731 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
732 switch (context->codec_tag) {
733 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
734 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-divx",
735 "divxversion", G_TYPE_INT, 5, NULL);
737 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
740 caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
741 "systemstream", G_TYPE_BOOLEAN, FALSE,
742 "mpegversion", G_TYPE_INT, 4, NULL);
746 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
747 caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
748 "mpegversion", G_TYPE_INT, 4,
749 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
751 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
752 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
754 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
755 "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4, 5,
757 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
758 "video/x-xvid", NULL));
759 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
760 "video/x-3ivx", NULL));
765 case CODEC_ID_RAWVIDEO:
767 gst_ffmpeg_codectype_to_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
771 case CODEC_ID_MSMPEG4V1:
772 case CODEC_ID_MSMPEG4V2:
773 case CODEC_ID_MSMPEG4V3:
775 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
777 /* encode-FIXME: bitrate */
778 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-msmpeg",
779 "msmpegversion", G_TYPE_INT, version, NULL);
780 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
781 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
782 "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
790 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
792 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
793 "wmvversion", G_TYPE_INT, version, NULL);
798 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-flash-video",
799 "flvversion", G_TYPE_INT, 1, NULL);
803 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-svq",
804 "svqversion", G_TYPE_INT, 1, NULL);
808 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-svq",
809 "svqversion", G_TYPE_INT, 3, NULL);
812 case CODEC_ID_DVAUDIO:
813 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dv", NULL);
816 case CODEC_ID_DVVIDEO:
818 if (encode && context) {
821 switch (context->pix_fmt) {
822 case PIX_FMT_YUYV422:
825 case PIX_FMT_YUV420P:
828 case PIX_FMT_YUVA420P:
831 case PIX_FMT_YUV411P:
834 case PIX_FMT_YUV422P:
837 case PIX_FMT_YUV410P:
842 ("Couldnt' find format for pixfmt %d, defaulting to I420",
847 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dv",
848 "systemstream", G_TYPE_BOOLEAN, FALSE,
849 "format", G_TYPE_STRING, format, NULL);
851 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dv",
852 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
860 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
863 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
864 "wmaversion", G_TYPE_INT, version,
865 "block_align", G_TYPE_INT, context->block_align,
866 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
868 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
869 "wmaversion", G_TYPE_INT, version,
870 "block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT,
871 "bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
875 case CODEC_ID_WMAPRO:
877 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
878 "wmaversion", G_TYPE_INT, 3, NULL);
882 case CODEC_ID_WMAVOICE:
884 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wms", NULL);
891 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
893 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mace",
894 "maceversion", G_TYPE_INT, version, NULL);
898 case CODEC_ID_HUFFYUV:
899 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-huffyuv", NULL);
901 gst_caps_set_simple (caps,
902 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
908 gst_ff_vid_caps_new (context, codec_id, "video/x-compressed-yuv",
913 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h264", NULL);
916 case CODEC_ID_INDEO5:
917 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
918 "indeoversion", G_TYPE_INT, 5, NULL);
921 case CODEC_ID_INDEO3:
922 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
923 "indeoversion", G_TYPE_INT, 3, NULL);
926 case CODEC_ID_INDEO2:
927 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
928 "indeoversion", G_TYPE_INT, 2, NULL);
931 case CODEC_ID_FLASHSV:
933 gst_ff_vid_caps_new (context, codec_id, "video/x-flash-screen", NULL);
937 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp3", NULL);
941 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp5", NULL);
945 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6", NULL);
949 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6-flash", NULL);
953 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6-alpha", NULL);
957 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp8", NULL);
960 case CODEC_ID_THEORA:
961 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-theora", NULL);
966 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg", NULL);
970 GValue item = { 0, };
972 g_value_init (&arr, GST_TYPE_LIST);
973 g_value_init (&item, G_TYPE_INT);
974 g_value_set_int (&item, 2);
975 gst_value_list_append_value (&arr, &item);
976 g_value_set_int (&item, 4);
977 gst_value_list_append_value (&arr, &item);
978 g_value_unset (&item);
980 gst_caps_set_value (caps, "mpegversion", &arr);
981 g_value_unset (&arr);
983 g_value_init (&arr, GST_TYPE_LIST);
984 g_value_init (&item, G_TYPE_STRING);
985 g_value_set_string (&item, "raw");
986 gst_value_list_append_value (&arr, &item);
987 g_value_set_string (&item, "adts");
988 gst_value_list_append_value (&arr, &item);
989 g_value_set_string (&item, "adif");
990 gst_value_list_append_value (&arr, &item);
991 g_value_unset (&item);
993 gst_caps_set_value (caps, "stream-format", &arr);
994 g_value_unset (&arr);
996 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
997 "stream-format", G_TYPE_STRING, "raw",
998 "base-profile", G_TYPE_STRING, "lc", NULL);
1000 if (context && context->extradata_size > 0)
1001 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1002 context->extradata, context->extradata_size);
1007 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1008 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
1009 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1014 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-asus",
1015 "asusversion", G_TYPE_INT, 1, NULL);
1018 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-asus",
1019 "asusversion", G_TYPE_INT, 2, NULL);
1023 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ffv",
1024 "ffvversion", G_TYPE_INT, 1, NULL);
1028 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-4xm", NULL);
1031 case CODEC_ID_XAN_WC3:
1032 case CODEC_ID_XAN_WC4:
1033 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-xan",
1034 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1039 gst_ff_vid_caps_new (context, codec_id,
1040 "video/x-cirrus-logic-accupak", NULL);
1043 case CODEC_ID_FRAPS:
1044 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-fraps", NULL);
1049 case CODEC_ID_INTERPLAY_VIDEO:
1054 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ati-vcr",
1055 "vcrversion", G_TYPE_INT, 1, NULL);
1060 gst_ff_vid_caps_new (context, codec_id, "video/x-apple-video", NULL);
1063 case CODEC_ID_CINEPAK:
1064 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-cinepak", NULL);
1067 /* WS_VQA belogns here (order) */
1069 case CODEC_ID_MSRLE:
1070 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-rle",
1071 "layout", G_TYPE_STRING, "microsoft", NULL);
1073 gst_caps_set_simple (caps,
1074 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1076 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1080 case CODEC_ID_QTRLE:
1081 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-rle",
1082 "layout", G_TYPE_STRING, "quicktime", NULL);
1084 gst_caps_set_simple (caps,
1085 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1087 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1091 case CODEC_ID_MSVIDEO1:
1092 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-msvideocodec",
1093 "msvideoversion", G_TYPE_INT, 1, NULL);
1097 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
1098 "wmvversion", G_TYPE_INT, 3, NULL);
1101 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
1102 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1105 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-qdm2", NULL);
1109 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mszh", NULL);
1113 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-zlib", NULL);
1116 case CODEC_ID_TRUEMOTION1:
1117 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-truemotion",
1118 "trueversion", G_TYPE_INT, 1, NULL);
1120 case CODEC_ID_TRUEMOTION2:
1121 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-truemotion",
1122 "trueversion", G_TYPE_INT, 2, NULL);
1126 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ultimotion",
1131 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-camtasia", NULL);
1133 gst_caps_set_simple (caps,
1134 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1136 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1141 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-kmvc", NULL);
1145 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-nuv", NULL);
1149 caps = gst_ff_vid_caps_new (context, codec_id, "image/gif", NULL);
1153 caps = gst_ff_vid_caps_new (context, codec_id, "image/png", NULL);
1157 caps = gst_ff_vid_caps_new (context, codec_id, "image/ppm", NULL);
1161 caps = gst_ff_vid_caps_new (context, codec_id, "image/pbm", NULL);
1166 gst_ff_vid_caps_new (context, codec_id, "image/x-portable-anymap",
1172 gst_ff_vid_caps_new (context, codec_id, "image/x-portable-graymap",
1177 caps = gst_ff_vid_caps_new (context, codec_id, "image/x-pcx", NULL);
1181 caps = gst_ff_vid_caps_new (context, codec_id, "image/x-sgi", NULL);
1184 case CODEC_ID_TARGA:
1185 caps = gst_ff_vid_caps_new (context, codec_id, "image/x-tga", NULL);
1189 caps = gst_ff_vid_caps_new (context, codec_id, "image/tiff", NULL);
1192 case CODEC_ID_SUNRAST:
1194 gst_ff_vid_caps_new (context, codec_id, "image/x-sun-raster", NULL);
1198 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-smc", NULL);
1201 case CODEC_ID_QDRAW:
1202 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-qdrw", NULL);
1205 case CODEC_ID_DNXHD:
1206 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dnxhd", NULL);
1209 case CODEC_ID_MIMIC:
1210 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mimic", NULL);
1214 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vmnc", NULL);
1217 case CODEC_ID_TRUESPEECH:
1219 gst_ff_aud_caps_new (context, codec_id, "audio/x-truespeech", NULL);
1222 case CODEC_ID_QCELP:
1223 caps = gst_ff_aud_caps_new (context, codec_id, "audio/qcelp", NULL);
1227 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-amv", NULL);
1231 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-aasc", NULL);
1235 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-loco", NULL);
1239 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-zmbv", NULL);
1242 case CODEC_ID_LAGARITH:
1243 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-lagarith", NULL);
1247 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-camstudio", NULL);
1249 gst_caps_set_simple (caps,
1250 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1252 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1256 case CODEC_ID_WS_VQA:
1257 case CODEC_ID_IDCIN:
1260 case CODEC_ID_VMDVIDEO:
1261 case CODEC_ID_VMDAUDIO:
1262 case CODEC_ID_SONIC:
1263 case CODEC_ID_SONIC_LS:
1267 case CODEC_ID_PGMYUV:
1268 case CODEC_ID_FFVHUFF:
1270 case CODEC_ID_MP3ADU:
1271 case CODEC_ID_MP3ON4:
1272 case CODEC_ID_WESTWOOD_SND1:
1273 case CODEC_ID_MMVIDEO:
1279 /* weird quasi-codecs for the demuxers only */
1280 case CODEC_ID_PCM_S16LE:
1281 case CODEC_ID_PCM_S16BE:
1282 case CODEC_ID_PCM_U16LE:
1283 case CODEC_ID_PCM_U16BE:
1284 case CODEC_ID_PCM_S8:
1285 case CODEC_ID_PCM_U8:
1287 GstAudioFormat format;
1290 case CODEC_ID_PCM_S16LE:
1291 format = GST_AUDIO_FORMAT_S16LE;
1293 case CODEC_ID_PCM_S16BE:
1294 format = GST_AUDIO_FORMAT_S16BE;
1296 case CODEC_ID_PCM_U16LE:
1297 format = GST_AUDIO_FORMAT_U16LE;
1299 case CODEC_ID_PCM_U16BE:
1300 format = GST_AUDIO_FORMAT_U16BE;
1302 case CODEC_ID_PCM_S8:
1303 format = GST_AUDIO_FORMAT_S8;
1305 case CODEC_ID_PCM_U8:
1306 format = GST_AUDIO_FORMAT_U8;
1309 g_assert (0); /* don't worry, we never get here */
1313 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw",
1314 "format", G_TYPE_STRING, gst_audio_format_to_string (format), NULL);
1318 case CODEC_ID_PCM_MULAW:
1319 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mulaw", NULL);
1322 case CODEC_ID_PCM_ALAW:
1323 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-alaw", NULL);
1326 case CODEC_ID_ADPCM_G722:
1327 caps = gst_ff_aud_caps_new (context, codec_id, "audio/G722", NULL);
1329 gst_caps_set_simple (caps,
1330 "block_align", G_TYPE_INT, context->block_align,
1331 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1334 case CODEC_ID_ADPCM_G726:
1336 /* the G726 decoder can also handle G721 */
1337 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-adpcm",
1338 "layout", G_TYPE_STRING, "g726", NULL);
1340 gst_caps_set_simple (caps,
1341 "block_align", G_TYPE_INT, context->block_align,
1342 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1345 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1346 "layout", G_TYPE_STRING, "g721",
1347 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1351 case CODEC_ID_ADPCM_IMA_QT:
1352 case CODEC_ID_ADPCM_IMA_WAV:
1353 case CODEC_ID_ADPCM_IMA_DK3:
1354 case CODEC_ID_ADPCM_IMA_DK4:
1355 case CODEC_ID_ADPCM_IMA_WS:
1356 case CODEC_ID_ADPCM_IMA_SMJPEG:
1357 case CODEC_ID_ADPCM_IMA_AMV:
1358 case CODEC_ID_ADPCM_IMA_ISS:
1359 case CODEC_ID_ADPCM_IMA_EA_EACS:
1360 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1361 case CODEC_ID_ADPCM_MS:
1362 case CODEC_ID_ADPCM_4XM:
1363 case CODEC_ID_ADPCM_XA:
1364 case CODEC_ID_ADPCM_ADX:
1365 case CODEC_ID_ADPCM_EA:
1366 case CODEC_ID_ADPCM_CT:
1367 case CODEC_ID_ADPCM_SWF:
1368 case CODEC_ID_ADPCM_YAMAHA:
1369 case CODEC_ID_ADPCM_SBPRO_2:
1370 case CODEC_ID_ADPCM_SBPRO_3:
1371 case CODEC_ID_ADPCM_SBPRO_4:
1372 case CODEC_ID_ADPCM_EA_R1:
1373 case CODEC_ID_ADPCM_EA_R2:
1374 case CODEC_ID_ADPCM_EA_R3:
1375 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1376 case CODEC_ID_ADPCM_EA_XAS:
1377 case CODEC_ID_ADPCM_THP:
1379 const gchar *layout = NULL;
1382 case CODEC_ID_ADPCM_IMA_QT:
1383 layout = "quicktime";
1385 case CODEC_ID_ADPCM_IMA_WAV:
1388 case CODEC_ID_ADPCM_IMA_DK3:
1391 case CODEC_ID_ADPCM_IMA_DK4:
1394 case CODEC_ID_ADPCM_IMA_WS:
1395 layout = "westwood";
1397 case CODEC_ID_ADPCM_IMA_SMJPEG:
1400 case CODEC_ID_ADPCM_IMA_AMV:
1403 case CODEC_ID_ADPCM_IMA_ISS:
1406 case CODEC_ID_ADPCM_IMA_EA_EACS:
1409 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1412 case CODEC_ID_ADPCM_MS:
1413 layout = "microsoft";
1415 case CODEC_ID_ADPCM_4XM:
1418 case CODEC_ID_ADPCM_XA:
1421 case CODEC_ID_ADPCM_ADX:
1424 case CODEC_ID_ADPCM_EA:
1427 case CODEC_ID_ADPCM_CT:
1430 case CODEC_ID_ADPCM_SWF:
1433 case CODEC_ID_ADPCM_YAMAHA:
1436 case CODEC_ID_ADPCM_SBPRO_2:
1439 case CODEC_ID_ADPCM_SBPRO_3:
1442 case CODEC_ID_ADPCM_SBPRO_4:
1445 case CODEC_ID_ADPCM_EA_R1:
1448 case CODEC_ID_ADPCM_EA_R2:
1451 case CODEC_ID_ADPCM_EA_R3:
1454 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1455 layout = "ea-maxis-xa";
1457 case CODEC_ID_ADPCM_EA_XAS:
1460 case CODEC_ID_ADPCM_THP:
1464 g_assert (0); /* don't worry, we never get here */
1468 /* FIXME: someone please check whether we need additional properties
1469 * in this caps definition. */
1470 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-adpcm",
1471 "layout", G_TYPE_STRING, layout, NULL);
1473 gst_caps_set_simple (caps,
1474 "block_align", G_TYPE_INT, context->block_align,
1475 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1479 case CODEC_ID_AMR_NB:
1480 caps = gst_ff_aud_caps_new (context, codec_id, "audio/AMR", NULL);
1483 case CODEC_ID_AMR_WB:
1484 caps = gst_ff_aud_caps_new (context, codec_id, "audio/AMR-WB", NULL);
1488 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-gsm", NULL);
1491 case CODEC_ID_GSM_MS:
1492 caps = gst_ff_aud_caps_new (context, codec_id, "audio/ms-gsm", NULL);
1495 case CODEC_ID_NELLYMOSER:
1497 gst_ff_aud_caps_new (context, codec_id, "audio/x-nellymoser", NULL);
1502 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-sipro", NULL);
1504 gst_caps_set_simple (caps,
1505 "leaf_size", G_TYPE_INT, context->block_align,
1506 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1511 case CODEC_ID_RA_144:
1512 case CODEC_ID_RA_288:
1518 case CODEC_ID_RA_144:
1521 case CODEC_ID_RA_288:
1531 /* FIXME: properties? */
1532 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-pn-realaudio",
1533 "raversion", G_TYPE_INT, version, NULL);
1535 gst_caps_set_simple (caps,
1536 "leaf_size", G_TYPE_INT, context->block_align,
1537 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1542 case CODEC_ID_ROQ_DPCM:
1543 case CODEC_ID_INTERPLAY_DPCM:
1544 case CODEC_ID_XAN_DPCM:
1545 case CODEC_ID_SOL_DPCM:
1547 const gchar *layout = NULL;
1550 case CODEC_ID_ROQ_DPCM:
1553 case CODEC_ID_INTERPLAY_DPCM:
1554 layout = "interplay";
1556 case CODEC_ID_XAN_DPCM:
1559 case CODEC_ID_SOL_DPCM:
1563 g_assert (0); /* don't worry, we never get here */
1567 /* FIXME: someone please check whether we need additional properties
1568 * in this caps definition. */
1569 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dpcm",
1570 "layout", G_TYPE_STRING, layout, NULL);
1572 gst_caps_set_simple (caps,
1573 "block_align", G_TYPE_INT, context->block_align,
1574 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1578 case CODEC_ID_SHORTEN:
1579 caps = gst_caps_new_simple ("audio/x-shorten", NULL);
1583 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-alac", NULL);
1585 gst_caps_set_simple (caps,
1586 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1591 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1592 * encoder case, we want to add things like samplerate, channels... */
1594 caps = gst_caps_new_simple ("audio/x-flac", NULL);
1598 case CODEC_ID_DVD_SUBTITLE:
1599 case CODEC_ID_DVB_SUBTITLE:
1603 caps = gst_caps_new_simple ("image/bmp", NULL);
1606 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-tta", NULL);
1608 gst_caps_set_simple (caps,
1609 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1612 case CODEC_ID_TWINVQ:
1613 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-twin-vq", NULL);
1616 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1623 if ((codec = avcodec_find_decoder (codec_id)) ||
1624 (codec = avcodec_find_encoder (codec_id))) {
1627 GST_LOG ("Could not create stream format caps for %s", codec->name);
1629 switch (codec->type) {
1630 case AVMEDIA_TYPE_VIDEO:
1631 mime = g_strdup_printf ("video/x-gst_ff-%s", codec->name);
1632 caps = gst_ff_vid_caps_new (context, codec_id, mime, NULL);
1635 case AVMEDIA_TYPE_AUDIO:
1636 mime = g_strdup_printf ("audio/x-gst_ff-%s", codec->name);
1637 caps = gst_ff_aud_caps_new (context, codec_id, mime, NULL);
1639 gst_caps_set_simple (caps,
1640 "block_align", G_TYPE_INT, context->block_align,
1641 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1652 /* set private data */
1653 if (context && context->extradata_size > 0) {
1654 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1656 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1657 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1658 gst_buffer_unref (data);
1663 gst_ffmpeg_set_palette (caps, context);
1666 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1669 GST_LOG ("No caps found for codec_id=%d", codec_id);
1675 /* Convert a FFMPEG Pixel Format to a GStreamer VideoFormat */
1677 gst_ffmpeg_pixfmt_to_video_format (enum PixelFormat pix_fmt)
1682 case PIX_FMT_YUVJ420P:
1683 case PIX_FMT_YUV420P:
1684 fmt = GST_VIDEO_FORMAT_I420;
1686 case PIX_FMT_YUVA420P:
1687 fmt = GST_VIDEO_FORMAT_A420;
1689 case PIX_FMT_YUYV422:
1690 fmt = GST_VIDEO_FORMAT_YUY2;
1693 fmt = GST_VIDEO_FORMAT_RGB;
1696 fmt = GST_VIDEO_FORMAT_BGR;
1698 case PIX_FMT_YUVJ422P:
1699 case PIX_FMT_YUV422P:
1700 fmt = GST_VIDEO_FORMAT_Y42B;
1702 case PIX_FMT_YUVJ444P:
1703 case PIX_FMT_YUV444P:
1704 fmt = GST_VIDEO_FORMAT_Y444;
1707 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
1708 fmt = GST_VIDEO_FORMAT_xRGB;
1710 fmt = GST_VIDEO_FORMAT_BGRx;
1713 case PIX_FMT_YUV410P:
1714 fmt = GST_VIDEO_FORMAT_YUV9;
1716 case PIX_FMT_YUV411P:
1717 fmt = GST_VIDEO_FORMAT_Y41B;
1719 case PIX_FMT_RGB565:
1720 fmt = GST_VIDEO_FORMAT_RGB16;
1722 case PIX_FMT_RGB555:
1723 fmt = GST_VIDEO_FORMAT_RGB15;
1726 fmt = GST_VIDEO_FORMAT_RGB8_PALETTED;
1729 fmt = GST_VIDEO_FORMAT_GRAY8;
1733 fmt = GST_VIDEO_FORMAT_UNKNOWN;
1739 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1740 * to a GstCaps. If the context is ommitted, no fixed values
1741 * for video/audio size will be included in the GstCaps
1743 * See below for usefullness
1747 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1748 enum CodecID codec_id)
1750 GstCaps *caps = NULL;
1751 GstVideoFormat format;
1753 format = gst_ffmpeg_pixfmt_to_video_format (pix_fmt);
1755 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1756 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw",
1757 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1761 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1763 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1769 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1770 * to a GstCaps. If the context is ommitted, no fixed values
1771 * for video/audio size will be included in the GstCaps
1773 * See below for usefullness
1777 gst_ffmpeg_smpfmt_to_caps (enum SampleFormat sample_fmt,
1778 AVCodecContext * context, enum CodecID codec_id)
1780 GstCaps *caps = NULL;
1781 GstAudioFormat format;
1783 switch (sample_fmt) {
1784 case SAMPLE_FMT_S16:
1785 format = GST_AUDIO_FORMAT_S16;
1787 case SAMPLE_FMT_S32:
1788 format = GST_AUDIO_FORMAT_S32;
1790 case SAMPLE_FMT_FLT:
1791 format = GST_AUDIO_FORMAT_F32;
1793 case SAMPLE_FMT_DBL:
1794 format = GST_AUDIO_FORMAT_F64;
1798 format = GST_AUDIO_FORMAT_UNKNOWN;
1802 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1803 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw",
1804 "format", G_TYPE_STRING, gst_audio_format_to_string (format), NULL);
1805 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1807 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1814 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
1815 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1817 GstCaps *caps = NULL;
1819 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1820 context, codec_id, encode, codec);
1822 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
1823 codec->sample_fmts, codec->supported_samplerates);
1826 /* Specific codec context */
1827 caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec_id);
1828 } else if (codec && codec->sample_fmts) {
1832 caps = gst_caps_new_empty ();
1833 for (i = 0; codec->sample_fmts[i] != -1; i++) {
1835 gst_ffmpeg_smpfmt_to_caps (codec->sample_fmts[i], context, codec_id);
1837 gst_caps_append (caps, temp);
1841 enum SampleFormat i;
1842 AVCodecContext ctx = { 0, };
1845 caps = gst_caps_new_empty ();
1846 for (i = 0; i <= SAMPLE_FMT_DBL; i++) {
1847 temp = gst_ffmpeg_smpfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1849 gst_caps_append (caps, temp);
1857 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
1858 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1862 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1863 context, codec_id, encode, codec);
1866 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
1870 AVCodecContext ctx = { 0, };
1872 caps = gst_caps_new_empty ();
1873 for (i = 0; i < PIX_FMT_NB; i++) {
1876 temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1878 gst_caps_append (caps, temp);
1885 /* Convert a FFMPEG codec Type and optional AVCodecContext
1886 * to a GstCaps. If the context is ommitted, no fixed values
1887 * for video/audio size will be included in the GstCaps
1889 * AVMediaType is primarily meant for uncompressed data GstCaps!
1893 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
1894 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
1898 switch (codec_type) {
1899 case AVMEDIA_TYPE_VIDEO:
1901 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1903 case AVMEDIA_TYPE_AUDIO:
1905 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
1915 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
1916 * and other audio properties in a AVCodecContext.
1918 * For usefullness, see below
1922 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
1923 AVCodecContext * context, gboolean raw)
1925 GstStructure *structure;
1927 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
1929 g_return_if_fail (gst_caps_get_size (caps) == 1);
1931 structure = gst_caps_get_structure (caps, 0);
1933 gst_structure_get_int (structure, "channels", &context->channels);
1934 gst_structure_get_int (structure, "rate", &context->sample_rate);
1935 gst_structure_get_int (structure, "block_align", &context->block_align);
1936 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
1941 if (gst_structure_has_name (structure, "audio/x-raw")) {
1942 if ((fmt = gst_structure_get_string (structure, "format"))) {
1943 format = gst_audio_format_from_string (fmt);
1948 case GST_AUDIO_FORMAT_F32:
1949 context->sample_fmt = SAMPLE_FMT_FLT;
1951 case GST_AUDIO_FORMAT_F64:
1952 context->sample_fmt = SAMPLE_FMT_DBL;
1954 case GST_AUDIO_FORMAT_S32:
1955 context->sample_fmt = SAMPLE_FMT_S32;
1957 case GST_AUDIO_FORMAT_S16:
1958 context->sample_fmt = SAMPLE_FMT_S16;
1965 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
1966 * and other video properties in a AVCodecContext.
1968 * For usefullness, see below
1972 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
1973 AVCodecContext * context, gboolean raw)
1975 GstStructure *structure;
1977 const GValue *par = NULL;
1979 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
1981 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
1982 g_return_if_fail (gst_caps_get_size (caps) == 1);
1983 structure = gst_caps_get_structure (caps, 0);
1985 gst_structure_get_int (structure, "width", &context->width);
1986 gst_structure_get_int (structure, "height", &context->height);
1987 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
1989 fps = gst_structure_get_value (structure, "framerate");
1990 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
1992 /* somehow these seem mixed up.. */
1993 context->time_base.den = gst_value_get_fraction_numerator (fps);
1994 context->time_base.num = gst_value_get_fraction_denominator (fps);
1995 context->ticks_per_frame = 1;
1997 GST_DEBUG ("setting framerate %d/%d = %lf",
1998 context->time_base.den, context->time_base.num,
1999 1. * context->time_base.den / context->time_base.num);
2002 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2003 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2005 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2006 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2008 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2009 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2010 1. * context->sample_aspect_ratio.den /
2011 context->sample_aspect_ratio.num);
2017 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2019 if (gst_structure_has_name (structure, "video/x-raw")) {
2020 if ((fmt = gst_structure_get_string (structure, "format"))) {
2021 format = gst_video_format_from_string (fmt);
2026 case GST_VIDEO_FORMAT_YUY2:
2027 context->pix_fmt = PIX_FMT_YUYV422;
2029 case GST_VIDEO_FORMAT_I420:
2030 context->pix_fmt = PIX_FMT_YUV420P;
2032 case GST_VIDEO_FORMAT_A420:
2033 context->pix_fmt = PIX_FMT_YUVA420P;
2035 case GST_VIDEO_FORMAT_Y41B:
2036 context->pix_fmt = PIX_FMT_YUV411P;
2038 case GST_VIDEO_FORMAT_Y42B:
2039 context->pix_fmt = PIX_FMT_YUV422P;
2041 case GST_VIDEO_FORMAT_YUV9:
2042 context->pix_fmt = PIX_FMT_YUV410P;
2044 case GST_VIDEO_FORMAT_Y444:
2045 context->pix_fmt = PIX_FMT_YUV444P;
2047 case GST_VIDEO_FORMAT_GRAY8:
2048 context->pix_fmt = PIX_FMT_GRAY8;
2050 case GST_VIDEO_FORMAT_xRGB:
2051 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2052 context->pix_fmt = PIX_FMT_RGB32;
2055 case GST_VIDEO_FORMAT_BGRx:
2056 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2057 context->pix_fmt = PIX_FMT_RGB32;
2060 case GST_VIDEO_FORMAT_RGB:
2061 context->pix_fmt = PIX_FMT_RGB24;
2063 case GST_VIDEO_FORMAT_BGR:
2064 context->pix_fmt = PIX_FMT_BGR24;
2066 case GST_VIDEO_FORMAT_RGB16:
2067 context->pix_fmt = PIX_FMT_RGB565;
2069 case GST_VIDEO_FORMAT_RGB15:
2070 context->pix_fmt = PIX_FMT_RGB555;
2072 case GST_VIDEO_FORMAT_RGB8_PALETTED:
2073 context->pix_fmt = PIX_FMT_PAL8;
2074 gst_ffmpeg_get_palette (caps, context);
2081 /* Convert a GstCaps and a FFMPEG codec Type to a
2082 * AVCodecContext. If the context is ommitted, no fixed values
2083 * for video/audio size will be included in the context
2085 * AVMediaType is primarily meant for uncompressed data GstCaps!
2089 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2090 const GstCaps * caps, AVCodecContext * context)
2092 if (context == NULL)
2096 case AVMEDIA_TYPE_VIDEO:
2097 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2100 case AVMEDIA_TYPE_AUDIO:
2101 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2112 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2116 guint8 *end = src + size;
2119 while (srcp < end) {
2120 if (count == 2 && *srcp <= 0x03) {
2121 GST_DEBUG ("added escape code");
2130 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2133 *destsize = dstp - dst;
2136 /* copy the config, escaping NAL units as we iterate them, if something fails we
2137 * copy everything and hope for the best. */
2139 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2144 guint nalsize, esize;
2154 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2156 GST_DEBUG ("num SPS %d", cnt);
2158 memcpy (dstp, srcp, 6);
2162 for (i = 0; i < cnt; i++) {
2163 GST_DEBUG ("copy SPS %d", i);
2164 nalsize = (srcp[0] << 8) | srcp[1];
2165 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2166 dstp[0] = esize >> 8;
2167 dstp[1] = esize & 0xff;
2169 srcp += nalsize + 2;
2172 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2174 GST_DEBUG ("num PPS %d", cnt);
2176 for (i = 0; i < cnt; i++) {
2177 GST_DEBUG ("copy PPS %d", i);
2178 nalsize = (srcp[0] << 8) | srcp[1];
2179 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2180 dstp[0] = esize >> 8;
2181 dstp[1] = esize & 0xff;
2183 srcp += nalsize + 2;
2185 *destsize = dstp - dst;
2191 GST_DEBUG ("something unexpected, doing full copy");
2192 memcpy (dst, src, size);
2200 * caps_with_codecid () transforms a GstCaps for a known codec
2201 * ID into a filled-in context.
2202 * codec_data from caps will override possible extradata already in the context
2206 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2207 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2210 const GValue *value;
2213 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2214 codec_id, codec_type, caps, context);
2216 if (!context || !gst_caps_get_size (caps))
2219 str = gst_caps_get_structure (caps, 0);
2221 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2222 if ((value = gst_structure_get_value (str, "codec_data"))) {
2226 buf = gst_value_get_buffer (value);
2227 data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
2229 /* free the old one if it is there */
2230 if (context->extradata)
2231 av_free (context->extradata);
2234 if (codec_id == CODEC_ID_H264) {
2237 GST_DEBUG ("copy, escaping codec_data %d", size);
2238 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2239 * reason for this but let's just escape it for now. Start by allocating
2240 * enough space, x2 is more than enough.
2242 * FIXME, we disabled escaping because some file already contain escaped
2243 * codec_data and then we escape twice and fail. It's better to leave it
2244 * as is, as that is what most players do. */
2245 context->extradata =
2246 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2247 FF_INPUT_BUFFER_PADDING_SIZE));
2248 copy_config (context->extradata, data, size, &extrasize);
2249 GST_DEBUG ("escaped size: %d", extrasize);
2250 context->extradata_size = extrasize;
2254 /* allocate with enough padding */
2255 GST_DEBUG ("copy codec_data");
2256 context->extradata =
2257 av_mallocz (GST_ROUND_UP_16 (size + FF_INPUT_BUFFER_PADDING_SIZE));
2258 memcpy (context->extradata, data, size);
2259 context->extradata_size = size;
2262 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2263 if (codec_id == CODEC_ID_VC1 && size > 0 && data[0] == 0) {
2264 context->extradata[0] = (guint8) size;
2267 GST_DEBUG ("have codec data of size %d", size);
2269 gst_buffer_unmap (buf, data, size);
2270 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2271 codec_id != CODEC_ID_FLAC) {
2272 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2273 * extradata anyway which makes then segfault. */
2274 context->extradata =
2275 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2276 context->extradata_size = 0;
2277 GST_DEBUG ("no codec data");
2281 case CODEC_ID_MPEG4:
2283 const gchar *mime = gst_structure_get_name (str);
2285 if (!strcmp (mime, "video/x-divx"))
2286 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2287 else if (!strcmp (mime, "video/x-xvid"))
2288 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2289 else if (!strcmp (mime, "video/x-3ivx"))
2290 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2291 else if (!strcmp (mime, "video/mpeg"))
2292 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2297 /* FIXME: this is a workaround for older gst-plugins releases
2298 * (<= 0.8.9). This should be removed at some point, because
2299 * it causes wrong decoded frame order. */
2300 if (!context->extradata) {
2301 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2304 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2305 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2306 gst_structure_get_int (str, "low_delay", &low_delay) ||
2307 gst_structure_get_int (str, "unknown_svq3_flag",
2308 &unknown_svq3_flag)) {
2309 context->extradata = (guint8 *) av_mallocz (0x64);
2310 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2314 flags |= unknown_svq3_flag;
2316 flags |= halfpel_flag;
2318 flags |= thirdpel_flag;
2321 flags = GUINT16_FROM_LE (flags);
2323 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2324 context->extradata_size = 0x64;
2329 case CODEC_ID_MSRLE:
2330 case CODEC_ID_QTRLE:
2337 if (gst_structure_get_int (str, "depth", &depth)) {
2338 context->bits_per_coded_sample = depth;
2340 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2353 if (gst_structure_get_int (str, "format", &format))
2354 context->sub_id = format;
2359 case CODEC_ID_RA_288:
2360 case CODEC_ID_RA_144:
2366 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2367 context->block_align = leaf_size;
2368 if (gst_structure_get_int (str, "bitrate", &bitrate))
2369 context->bit_rate = bitrate;
2372 gst_structure_get_int (str, "samplesize",
2373 &context->bits_per_coded_sample);
2376 case CODEC_ID_DVVIDEO:
2378 const gchar *format;
2380 format = gst_structure_get_string (str, "format");
2382 if (g_str_equal (format, "YUY2"))
2383 context->pix_fmt = PIX_FMT_YUYV422;
2384 else if (g_str_equal (format, "I420"))
2385 context->pix_fmt = PIX_FMT_YUV420P;
2386 else if (g_str_equal (format, "A420"))
2387 context->pix_fmt = PIX_FMT_YUVA420P;
2388 else if (g_str_equal (format, "Y41B"))
2389 context->pix_fmt = PIX_FMT_YUV411P;
2390 else if (g_str_equal (format, "Y42B"))
2391 context->pix_fmt = PIX_FMT_YUV422P;
2392 else if (g_str_equal (format, "YUV9"))
2393 context->pix_fmt = PIX_FMT_YUV410P;
2395 GST_WARNING ("couldn't convert format %s" " to a pixel format", format);
2399 case CODEC_ID_H263P:
2403 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2404 context->flags |= CODEC_FLAG_4MV;
2406 context->flags &= ~CODEC_FLAG_4MV;
2407 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2408 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2409 context->flags |= CODEC_FLAG_AC_PRED;
2411 context->flags &= ~CODEC_FLAG_AC_PRED;
2412 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2413 context->flags |= CODEC_FLAG_LOOP_FILTER;
2415 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2418 case CODEC_ID_ADPCM_G726:
2420 const gchar *layout;
2422 if ((layout = gst_structure_get_string (str, "layout"))) {
2423 if (!strcmp (layout, "g721")) {
2424 context->sample_rate = 8000;
2425 context->channels = 1;
2426 context->bit_rate = 32000;
2435 if (!gst_caps_is_fixed (caps))
2438 /* common properties (width, height, fps) */
2439 switch (codec_type) {
2440 case AVMEDIA_TYPE_VIDEO:
2441 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2442 gst_ffmpeg_get_palette (caps, context);
2444 case AVMEDIA_TYPE_AUDIO:
2445 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2451 /* fixup of default settings */
2453 case CODEC_ID_QCELP:
2454 /* QCELP is always mono, no matter what the caps say */
2455 context->channels = 1;
2462 /* _formatid_to_caps () is meant for muxers/demuxers, it
2463 * transforms a name (ffmpeg way of ID'ing these, why don't
2464 * they have unique numerical IDs?) to the corresponding
2465 * caps belonging to that mux-format
2467 * Note: we don't need any additional info because the caps
2468 * isn't supposed to contain any useful info besides the
2473 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2475 GstCaps *caps = NULL;
2477 if (!strcmp (format_name, "mpeg")) {
2478 caps = gst_caps_new_simple ("video/mpeg",
2479 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2480 } else if (!strcmp (format_name, "mpegts")) {
2481 caps = gst_caps_new_simple ("video/mpegts",
2482 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2483 } else if (!strcmp (format_name, "rm")) {
2484 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2485 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2486 } else if (!strcmp (format_name, "asf")) {
2487 caps = gst_caps_new_simple ("video/x-ms-asf", NULL);
2488 } else if (!strcmp (format_name, "avi")) {
2489 caps = gst_caps_new_simple ("video/x-msvideo", NULL);
2490 } else if (!strcmp (format_name, "wav")) {
2491 caps = gst_caps_new_simple ("audio/x-wav", NULL);
2492 } else if (!strcmp (format_name, "ape")) {
2493 caps = gst_caps_new_simple ("application/x-ape", NULL);
2494 } else if (!strcmp (format_name, "swf")) {
2495 caps = gst_caps_new_simple ("application/x-shockwave-flash", NULL);
2496 } else if (!strcmp (format_name, "au")) {
2497 caps = gst_caps_new_simple ("audio/x-au", NULL);
2498 } else if (!strcmp (format_name, "dv")) {
2499 caps = gst_caps_new_simple ("video/x-dv",
2500 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2501 } else if (!strcmp (format_name, "4xm")) {
2502 caps = gst_caps_new_simple ("video/x-4xm", NULL);
2503 } else if (!strcmp (format_name, "matroska")) {
2504 caps = gst_caps_new_simple ("video/x-matroska", NULL);
2505 } else if (!strcmp (format_name, "mp3")) {
2506 caps = gst_caps_new_simple ("application/x-id3", NULL);
2507 } else if (!strcmp (format_name, "flic")) {
2508 caps = gst_caps_new_simple ("video/x-fli", NULL);
2509 } else if (!strcmp (format_name, "flv")) {
2510 caps = gst_caps_new_simple ("video/x-flv", NULL);
2511 } else if (!strcmp (format_name, "tta")) {
2512 caps = gst_caps_new_simple ("audio/x-ttafile", NULL);
2513 } else if (!strcmp (format_name, "aiff")) {
2514 caps = gst_caps_new_simple ("audio/x-aiff", NULL);
2515 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2517 gst_caps_from_string
2518 ("application/x-3gp; video/quicktime; audio/x-m4a");
2519 } else if (!strcmp (format_name, "mov")) {
2520 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2521 } else if (!strcmp (format_name, "mp4")) {
2522 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2523 } else if (!strcmp (format_name, "3gp")) {
2524 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2525 } else if (!strcmp (format_name, "3g2")) {
2526 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2527 } else if (!strcmp (format_name, "psp")) {
2528 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2529 } else if (!strcmp (format_name, "ipod")) {
2530 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2531 } else if (!strcmp (format_name, "aac")) {
2532 caps = gst_caps_new_simple ("audio/mpeg",
2533 "mpegversion", G_TYPE_INT, 4, NULL);
2534 } else if (!strcmp (format_name, "gif")) {
2535 caps = gst_caps_from_string ("image/gif");
2536 } else if (!strcmp (format_name, "ogg")) {
2537 caps = gst_caps_from_string ("application/ogg");
2538 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
2539 caps = gst_caps_from_string ("application/mxf");
2540 } else if (!strcmp (format_name, "gxf")) {
2541 caps = gst_caps_from_string ("application/gxf");
2542 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
2543 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
2544 "y4mversion", G_TYPE_INT, 2, NULL);
2545 } else if (!strcmp (format_name, "mpc")) {
2546 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
2547 } else if (!strcmp (format_name, "vqf")) {
2548 caps = gst_caps_from_string ("audio/x-vqf");
2549 } else if (!strcmp (format_name, "nsv")) {
2550 caps = gst_caps_from_string ("video/x-nsv");
2551 } else if (!strcmp (format_name, "amr")) {
2552 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
2553 } else if (!strcmp (format_name, "webm")) {
2554 caps = gst_caps_from_string ("video/webm");
2558 GST_LOG ("Could not create stream format caps for %s", format_name);
2559 name = g_strdup_printf ("application/x-gst_ff-%s", format_name);
2560 caps = gst_caps_new_simple (name, NULL);
2568 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
2569 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
2570 AVOutputFormat * plugin)
2572 static enum CodecID tmp_vlist[] = {
2576 static enum CodecID tmp_alist[] = {
2581 GST_LOG ("format_name : %s", format_name);
2583 if (!strcmp (format_name, "mp4")) {
2584 static enum CodecID mp4_video_list[] = {
2585 CODEC_ID_MPEG4, CODEC_ID_H264,
2589 static enum CodecID mp4_audio_list[] = {
2590 CODEC_ID_AAC, CODEC_ID_MP3,
2594 *video_codec_list = mp4_video_list;
2595 *audio_codec_list = mp4_audio_list;
2596 } else if (!strcmp (format_name, "mpeg")) {
2597 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
2598 CODEC_ID_MPEG2VIDEO,
2602 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
2608 *video_codec_list = mpeg_video_list;
2609 *audio_codec_list = mpeg_audio_list;
2610 } else if (!strcmp (format_name, "dvd")) {
2611 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
2614 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
2621 *video_codec_list = mpeg_video_list;
2622 *audio_codec_list = mpeg_audio_list;
2623 } else if (!strcmp (format_name, "mpegts")) {
2624 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
2625 CODEC_ID_MPEG2VIDEO,
2629 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
2637 *video_codec_list = mpegts_video_list;
2638 *audio_codec_list = mpegts_audio_list;
2639 } else if (!strcmp (format_name, "vob")) {
2640 static enum CodecID vob_video_list[] =
2641 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
2642 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
2643 CODEC_ID_DTS, CODEC_ID_NONE
2646 *video_codec_list = vob_video_list;
2647 *audio_codec_list = vob_audio_list;
2648 } else if (!strcmp (format_name, "flv")) {
2649 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
2650 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
2652 *video_codec_list = flv_video_list;
2653 *audio_codec_list = flv_audio_list;
2654 } else if (!strcmp (format_name, "asf")) {
2655 static enum CodecID asf_video_list[] =
2656 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
2657 static enum CodecID asf_audio_list[] =
2658 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
2660 *video_codec_list = asf_video_list;
2661 *audio_codec_list = asf_audio_list;
2662 } else if (!strcmp (format_name, "dv")) {
2663 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
2664 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
2666 *video_codec_list = dv_video_list;
2667 *audio_codec_list = dv_audio_list;
2668 } else if (!strcmp (format_name, "mov")) {
2669 static enum CodecID mov_video_list[] = {
2670 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
2671 CODEC_ID_H263, CODEC_ID_H263P,
2672 CODEC_ID_H264, CODEC_ID_DVVIDEO,
2676 static enum CodecID mov_audio_list[] = {
2677 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
2678 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
2679 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2680 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
2681 CODEC_ID_MP3, CODEC_ID_NONE
2684 *video_codec_list = mov_video_list;
2685 *audio_codec_list = mov_audio_list;
2686 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
2687 static enum CodecID tgp_video_list[] = {
2688 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
2691 static enum CodecID tgp_audio_list[] = {
2692 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2697 *video_codec_list = tgp_video_list;
2698 *audio_codec_list = tgp_audio_list;
2699 } else if (!strcmp (format_name, "mmf")) {
2700 static enum CodecID mmf_audio_list[] = {
2701 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
2703 *video_codec_list = NULL;
2704 *audio_codec_list = mmf_audio_list;
2705 } else if (!strcmp (format_name, "amr")) {
2706 static enum CodecID amr_audio_list[] = {
2707 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2710 *video_codec_list = NULL;
2711 *audio_codec_list = amr_audio_list;
2712 } else if (!strcmp (format_name, "gif")) {
2713 static enum CodecID gif_image_list[] = {
2714 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
2716 *video_codec_list = gif_image_list;
2717 *audio_codec_list = NULL;
2718 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
2719 (plugin->video_codec != CODEC_ID_NONE)) {
2720 tmp_vlist[0] = plugin->video_codec;
2721 tmp_alist[0] = plugin->audio_codec;
2723 *video_codec_list = tmp_vlist;
2724 *audio_codec_list = tmp_alist;
2726 GST_LOG ("Format %s not found", format_name);
2733 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
2734 * are omitted, that can be queried by the user itself,
2735 * we're not eating the GstCaps or anything
2736 * A pointer to an allocated context is also needed for
2737 * optional extra info
2741 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
2743 enum CodecID id = CODEC_ID_NONE;
2744 const gchar *mimetype;
2745 const GstStructure *structure;
2746 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
2748 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
2749 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
2750 structure = gst_caps_get_structure (caps, 0);
2752 mimetype = gst_structure_get_name (structure);
2754 if (!strcmp (mimetype, "video/x-raw")) {
2755 id = CODEC_ID_RAWVIDEO;
2757 } else if (!strcmp (mimetype, "audio/x-raw")) {
2760 if (gst_audio_info_from_caps (&info, caps)) {
2761 switch (GST_AUDIO_INFO_FORMAT (&info)) {
2762 case GST_AUDIO_FORMAT_S8:
2763 id = CODEC_ID_PCM_S8;
2765 case GST_AUDIO_FORMAT_U8:
2766 id = CODEC_ID_PCM_U8;
2768 case GST_AUDIO_FORMAT_S16LE:
2769 id = CODEC_ID_PCM_S16LE;
2771 case GST_AUDIO_FORMAT_S16BE:
2772 id = CODEC_ID_PCM_S16BE;
2774 case GST_AUDIO_FORMAT_U16LE:
2775 id = CODEC_ID_PCM_U16LE;
2777 case GST_AUDIO_FORMAT_U16BE:
2778 id = CODEC_ID_PCM_U16BE;
2783 if (id != CODEC_ID_NONE)
2786 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
2787 id = CODEC_ID_PCM_MULAW;
2789 } else if (!strcmp (mimetype, "audio/x-alaw")) {
2790 id = CODEC_ID_PCM_ALAW;
2792 } else if (!strcmp (mimetype, "video/x-dv")) {
2795 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
2797 id = CODEC_ID_DVVIDEO;
2800 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
2801 id = CODEC_ID_DVAUDIO;
2803 } else if (!strcmp (mimetype, "video/x-h263")) {
2804 const gchar *h263version =
2805 gst_structure_get_string (structure, "h263version");
2806 if (h263version && !strcmp (h263version, "h263p"))
2807 id = CODEC_ID_H263P;
2811 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
2812 id = CODEC_ID_H263I;
2814 } else if (!strcmp (mimetype, "video/x-h261")) {
2817 } else if (!strcmp (mimetype, "video/mpeg")) {
2821 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
2822 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
2824 switch (mpegversion) {
2826 id = CODEC_ID_MPEG1VIDEO;
2829 id = CODEC_ID_MPEG2VIDEO;
2832 id = CODEC_ID_MPEG4;
2836 if (id != CODEC_ID_NONE)
2838 } else if (!strcmp (mimetype, "image/jpeg")) {
2839 id = CODEC_ID_MJPEG; /* A... B... */
2841 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
2842 id = CODEC_ID_MJPEGB;
2844 } else if (!strcmp (mimetype, "video/x-wmv")) {
2845 gint wmvversion = 0;
2847 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
2848 switch (wmvversion) {
2857 const gchar *format;
2859 /* WMV3 unless the fourcc exists and says otherwise */
2861 format = gst_structure_get_string (structure, "format");
2863 if (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")) {
2870 if (id != CODEC_ID_NONE)
2872 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
2873 id = CODEC_ID_VORBIS;
2875 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
2878 } else if (!strcmp (mimetype, "audio/mpeg")) {
2880 gint mpegversion = 0;
2882 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
2883 switch (mpegversion) {
2884 case 2: /* ffmpeg uses faad for both... */
2889 if (gst_structure_get_int (structure, "layer", &layer)) {
2904 if (id != CODEC_ID_NONE)
2906 } else if (!strcmp (mimetype, "audio/x-musepack")) {
2907 gint streamversion = -1;
2909 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
2910 if (streamversion == 7)
2911 id = CODEC_ID_MUSEPACK7;
2913 id = CODEC_ID_MUSEPACK7;
2915 } else if (!strcmp (mimetype, "audio/x-wma")) {
2916 gint wmaversion = 0;
2918 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
2919 switch (wmaversion) {
2921 id = CODEC_ID_WMAV1;
2924 id = CODEC_ID_WMAV2;
2927 id = CODEC_ID_WMAPRO;
2931 if (id != CODEC_ID_NONE)
2933 } else if (!strcmp (mimetype, "audio/x-wms")) {
2934 id = CODEC_ID_WMAVOICE;
2936 } else if (!strcmp (mimetype, "audio/x-ac3")) {
2939 } else if (!strcmp (mimetype, "audio/x-eac3")) {
2942 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
2943 !strcmp (mimetype, "audio/atrac3")) {
2944 id = CODEC_ID_ATRAC3;
2946 } else if (!strcmp (mimetype, "audio/x-dts")) {
2949 } else if (!strcmp (mimetype, "application/x-ape")) {
2952 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
2953 gint msmpegversion = 0;
2955 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
2956 switch (msmpegversion) {
2958 id = CODEC_ID_MSMPEG4V1;
2961 id = CODEC_ID_MSMPEG4V2;
2964 id = CODEC_ID_MSMPEG4V3;
2968 if (id != CODEC_ID_NONE)
2970 } else if (!strcmp (mimetype, "video/x-svq")) {
2971 gint svqversion = 0;
2973 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
2974 switch (svqversion) {
2983 if (id != CODEC_ID_NONE)
2985 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
2986 id = CODEC_ID_HUFFYUV;
2988 } else if (!strcmp (mimetype, "audio/x-mace")) {
2989 gint maceversion = 0;
2991 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
2992 switch (maceversion) {
2994 id = CODEC_ID_MACE3;
2997 id = CODEC_ID_MACE6;
3001 if (id != CODEC_ID_NONE)
3003 } else if (!strcmp (mimetype, "video/x-theora")) {
3004 id = CODEC_ID_THEORA;
3006 } else if (!strcmp (mimetype, "video/x-vp3")) {
3009 } else if (!strcmp (mimetype, "video/x-vp5")) {
3012 } else if (!strcmp (mimetype, "video/x-vp6")) {
3015 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3018 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3021 } else if (!strcmp (mimetype, "video/x-vp8")) {
3024 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3025 id = CODEC_ID_FLASHSV;
3027 } else if (!strcmp (mimetype, "video/x-indeo")) {
3028 gint indeoversion = 0;
3030 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3031 switch (indeoversion) {
3033 id = CODEC_ID_INDEO5;
3036 id = CODEC_ID_INDEO3;
3039 id = CODEC_ID_INDEO2;
3042 if (id != CODEC_ID_NONE)
3045 } else if (!strcmp (mimetype, "video/x-divx")) {
3046 gint divxversion = 0;
3048 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3049 switch (divxversion) {
3051 id = CODEC_ID_MSMPEG4V3;
3055 id = CODEC_ID_MPEG4;
3059 if (id != CODEC_ID_NONE)
3061 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3062 id = CODEC_ID_MPEG4;
3064 } else if (!strcmp (mimetype, "video/x-xvid")) {
3065 id = CODEC_ID_MPEG4;
3067 } else if (!strcmp (mimetype, "video/x-ffv")) {
3068 gint ffvversion = 0;
3070 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3075 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3076 const gchar *layout;
3078 layout = gst_structure_get_string (structure, "layout");
3079 if (layout == NULL) {
3081 } else if (!strcmp (layout, "quicktime")) {
3082 id = CODEC_ID_ADPCM_IMA_QT;
3083 } else if (!strcmp (layout, "microsoft")) {
3084 id = CODEC_ID_ADPCM_MS;
3085 } else if (!strcmp (layout, "dvi")) {
3086 id = CODEC_ID_ADPCM_IMA_WAV;
3087 } else if (!strcmp (layout, "4xm")) {
3088 id = CODEC_ID_ADPCM_4XM;
3089 } else if (!strcmp (layout, "smjpeg")) {
3090 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3091 } else if (!strcmp (layout, "dk3")) {
3092 id = CODEC_ID_ADPCM_IMA_DK3;
3093 } else if (!strcmp (layout, "dk4")) {
3094 id = CODEC_ID_ADPCM_IMA_DK4;
3095 } else if (!strcmp (layout, "westwood")) {
3096 id = CODEC_ID_ADPCM_IMA_WS;
3097 } else if (!strcmp (layout, "iss")) {
3098 id = CODEC_ID_ADPCM_IMA_ISS;
3099 } else if (!strcmp (layout, "xa")) {
3100 id = CODEC_ID_ADPCM_XA;
3101 } else if (!strcmp (layout, "adx")) {
3102 id = CODEC_ID_ADPCM_ADX;
3103 } else if (!strcmp (layout, "ea")) {
3104 id = CODEC_ID_ADPCM_EA;
3105 } else if (!strcmp (layout, "g726")) {
3106 id = CODEC_ID_ADPCM_G726;
3107 } else if (!strcmp (layout, "g721")) {
3108 id = CODEC_ID_ADPCM_G726;
3109 } else if (!strcmp (layout, "ct")) {
3110 id = CODEC_ID_ADPCM_CT;
3111 } else if (!strcmp (layout, "swf")) {
3112 id = CODEC_ID_ADPCM_SWF;
3113 } else if (!strcmp (layout, "yamaha")) {
3114 id = CODEC_ID_ADPCM_YAMAHA;
3115 } else if (!strcmp (layout, "sbpro2")) {
3116 id = CODEC_ID_ADPCM_SBPRO_2;
3117 } else if (!strcmp (layout, "sbpro3")) {
3118 id = CODEC_ID_ADPCM_SBPRO_3;
3119 } else if (!strcmp (layout, "sbpro4")) {
3120 id = CODEC_ID_ADPCM_SBPRO_4;
3122 if (id != CODEC_ID_NONE)
3124 } else if (!strcmp (mimetype, "video/x-4xm")) {
3127 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3128 const gchar *layout;
3130 layout = gst_structure_get_string (structure, "layout");
3133 } else if (!strcmp (layout, "roq")) {
3134 id = CODEC_ID_ROQ_DPCM;
3135 } else if (!strcmp (layout, "interplay")) {
3136 id = CODEC_ID_INTERPLAY_DPCM;
3137 } else if (!strcmp (layout, "xan")) {
3138 id = CODEC_ID_XAN_DPCM;
3139 } else if (!strcmp (layout, "sol")) {
3140 id = CODEC_ID_SOL_DPCM;
3142 if (id != CODEC_ID_NONE)
3144 } else if (!strcmp (mimetype, "audio/x-flac")) {
3147 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3148 id = CODEC_ID_SHORTEN;
3150 } else if (!strcmp (mimetype, "audio/x-alac")) {
3153 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3154 id = CODEC_ID_CINEPAK;
3156 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3159 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3160 switch (rmversion) {
3175 if (id != CODEC_ID_NONE)
3177 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3180 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3183 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3184 switch (raversion) {
3186 id = CODEC_ID_RA_144;
3189 id = CODEC_ID_RA_288;
3196 if (id != CODEC_ID_NONE)
3198 } else if (!strcmp (mimetype, "video/x-rle")) {
3199 const gchar *layout;
3201 if ((layout = gst_structure_get_string (structure, "layout"))) {
3202 if (!strcmp (layout, "microsoft")) {
3203 id = CODEC_ID_MSRLE;
3207 } else if (!strcmp (mimetype, "video/x-xan")) {
3210 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3211 switch (wcversion) {
3213 id = CODEC_ID_XAN_WC3;
3217 id = CODEC_ID_XAN_WC4;
3224 } else if (!strcmp (mimetype, "audio/AMR")) {
3226 id = CODEC_ID_AMR_NB;
3227 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3228 id = CODEC_ID_AMR_WB;
3230 } else if (!strcmp (mimetype, "audio/qcelp")) {
3231 id = CODEC_ID_QCELP;
3233 } else if (!strcmp (mimetype, "video/x-h264")) {
3236 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3237 gint flvversion = 0;
3239 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3240 switch (flvversion) {
3250 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3251 id = CODEC_ID_NELLYMOSER;
3253 } else if (!strncmp (mimetype, "audio/x-gst_ff-", 15)) {
3257 if (strlen (mimetype) <= 30 &&
3258 sscanf (mimetype, "audio/x-gst_ff-%s", ext) == 1) {
3259 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3260 (codec = avcodec_find_encoder_by_name (ext))) {
3265 } else if (!strncmp (mimetype, "video/x-gst_ff-", 15)) {
3269 if (strlen (mimetype) <= 30 &&
3270 sscanf (mimetype, "video/x-gst_ff-%s", ext) == 1) {
3271 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3272 (codec = avcodec_find_encoder_by_name (ext))) {
3279 if (context != NULL) {
3280 if (video == TRUE) {
3281 context->codec_type = AVMEDIA_TYPE_VIDEO;
3282 } else if (audio == TRUE) {
3283 context->codec_type = AVMEDIA_TYPE_AUDIO;
3285 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3287 context->codec_id = id;
3288 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3291 if (id != CODEC_ID_NONE) {
3292 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3294 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);