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"
37 * Read a palette from a caps.
41 gst_ffmpeg_get_palette (const GstCaps * caps, AVCodecContext * context)
43 GstStructure *str = gst_caps_get_structure (caps, 0);
44 const GValue *palette_v;
45 const GstBuffer *palette;
47 /* do we have a palette? */
48 if ((palette_v = gst_structure_get_value (str, "palette_data")) && context) {
49 palette = gst_value_get_buffer (palette_v);
50 if (GST_BUFFER_SIZE (palette) >= AVPALETTE_SIZE) {
52 av_free (context->palctrl);
53 context->palctrl = av_malloc (sizeof (AVPaletteControl));
54 context->palctrl->palette_changed = 1;
55 memcpy (context->palctrl->palette, GST_BUFFER_DATA (palette),
62 gst_ffmpeg_set_palette (GstCaps * caps, AVCodecContext * context)
64 if (context->palctrl) {
65 GstBuffer *palette = gst_buffer_new_and_alloc (AVPALETTE_SIZE);
67 memcpy (GST_BUFFER_DATA (palette), context->palctrl->palette,
69 gst_caps_set_simple (caps, "palette_data", GST_TYPE_BUFFER, palette, NULL);
73 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
77 GstAudioChannelPosition gst;
78 } _ff_to_gst_layout[] = {
80 CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
81 CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
82 CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
83 CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE}, {
84 CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
85 CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
86 CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
87 CH_FRONT_RIGHT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
88 CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
89 CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
90 CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
91 CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
92 CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
93 CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
94 CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
95 CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
96 CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_NONE}, {
97 CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_NONE}, {
98 CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
99 CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
102 static GstAudioChannelPosition *
103 gst_ff_channel_layout_to_gst (guint64 channel_layout, guint channels)
105 guint nchannels = 0, i, j;
106 GstAudioChannelPosition *pos = NULL;
107 gboolean none_layout = FALSE;
109 for (i = 0; i < 64; i++) {
110 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
115 if (channel_layout == 0) {
116 nchannels = channels;
120 if (nchannels != channels) {
121 GST_ERROR ("Number of channels is different (%u != %u)", channels,
126 pos = g_new (GstAudioChannelPosition, nchannels);
128 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
129 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
130 pos[j++] = _ff_to_gst_layout[i].gst;
132 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
137 if (j != nchannels) {
138 GST_WARNING ("Unknown channels in channel layout - assuming NONE layout");
142 if (!none_layout && !gst_audio_check_channel_positions (pos, nchannels)) {
143 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
144 " - assuming NONE layout", channel_layout);
149 if (nchannels == 1) {
150 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
151 } else if (nchannels == 2) {
152 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
153 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
154 } else if (channel_layout == 0) {
158 for (i = 0; i < nchannels; i++)
159 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
163 if (nchannels == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER) {
164 GST_DEBUG ("mono common case; won't set channel positions");
167 } else if (nchannels == 2 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
168 && pos[1] == GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT) {
169 GST_DEBUG ("stereo common case; won't set channel positions");
177 /* this macro makes a caps width fixed or unfixed width/height
178 * properties depending on whether we've got a context.
180 * See below for why we use this.
182 * We should actually do this stuff at the end, like in riff-media.c,
183 * but I'm too lazy today. Maybe later.
186 gst_ff_vid_caps_new (AVCodecContext * context, enum CodecID codec_id,
187 const char *mimetype, const char *fieldname, ...)
189 GstStructure *structure = NULL;
190 GstCaps *caps = NULL;
194 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
196 /* fixed, non probing context */
197 if (context != NULL && context->width != -1) {
198 caps = gst_caps_new_simple (mimetype,
199 "width", G_TYPE_INT, context->width,
200 "height", G_TYPE_INT, context->height,
201 "framerate", GST_TYPE_FRACTION,
202 context->time_base.den / context->ticks_per_frame,
203 context->time_base.num, NULL);
205 /* so we are after restricted caps in this case */
209 caps = gst_caps_new_simple (mimetype,
210 "width", G_TYPE_INT, 352,
211 "height", G_TYPE_INT, 288,
212 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
213 gst_caps_append (caps, gst_caps_new_simple (mimetype,
214 "width", G_TYPE_INT, 176,
215 "height", G_TYPE_INT, 144,
216 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
221 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
222 * because we want automatic negotiation to go as close to 320x240 as
224 const static gint widths[] = { 352, 704, 176, 1408, 128 };
225 const static gint heights[] = { 288, 576, 144, 1152, 96 };
227 gint n_sizes = G_N_ELEMENTS (widths);
229 caps = gst_caps_new_empty ();
230 for (i = 0; i < n_sizes; i++) {
231 temp = gst_caps_new_simple (mimetype,
232 "width", G_TYPE_INT, widths[i],
233 "height", G_TYPE_INT, heights[i],
234 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
236 gst_caps_append (caps, temp);
240 case CODEC_ID_DVVIDEO:
247 gint framerate_n, framerate_d;
250 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 10, 11, 30000, 1001}, {
251 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 40, 33, 30000, 1001}, {
252 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 59, 54, 25, 1}, {
253 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 118, 81, 25, 1}, {
254 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 59, 54, 25, 1}, {
255 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 118, 81, 25, 1}
258 gint n_sizes = G_N_ELEMENTS (profiles);
260 caps = gst_caps_new_empty ();
261 for (i = 0; i < n_sizes; i++) {
262 temp = gst_caps_new_simple (mimetype,
263 "width", G_TYPE_INT, profiles[i].width,
264 "height", G_TYPE_INT, profiles[i].height,
265 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
266 profiles[i].framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION,
267 profiles[i].par_n, profiles[i].par_d, NULL);
269 gst_caps_append (caps, temp);
275 caps = gst_caps_new_simple (mimetype,
276 "width", G_TYPE_INT, 1920,
277 "height", G_TYPE_INT, 1080,
278 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
279 gst_caps_append (caps, gst_caps_new_simple (mimetype,
280 "width", G_TYPE_INT, 1280,
281 "height", G_TYPE_INT, 720,
282 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
290 /* no fixed caps or special restrictions applied;
291 * default unfixed setting */
293 GST_DEBUG ("Creating default caps");
294 caps = gst_caps_new_simple (mimetype,
295 "width", GST_TYPE_INT_RANGE, 16, 4096,
296 "height", GST_TYPE_INT_RANGE, 16, 4096,
297 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
300 for (i = 0; i < gst_caps_get_size (caps); i++) {
301 va_start (var_args, fieldname);
302 structure = gst_caps_get_structure (caps, i);
303 gst_structure_set_valist (structure, fieldname, var_args);
310 /* same for audio - now with channels/sample rate
313 gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
314 const char *mimetype, const char *fieldname, ...)
316 GstCaps *caps = NULL;
317 GstStructure *structure = NULL;
321 /* fixed, non-probing context */
322 if (context != NULL && context->channels != -1) {
323 GstAudioChannelPosition *pos;
324 guint64 channel_layout = context->channel_layout;
326 if (channel_layout == 0) {
327 const guint64 default_channel_set[] = {
328 0, 0, CH_LAYOUT_SURROUND, CH_LAYOUT_QUAD, CH_LAYOUT_5POINT0,
329 CH_LAYOUT_5POINT1, 0, CH_LAYOUT_7POINT1
336 if (context->channels > 0
337 && context->channels < G_N_ELEMENTS (default_channel_set))
338 channel_layout = default_channel_set[context->channels - 1];
345 caps = gst_caps_new_simple (mimetype,
346 "rate", G_TYPE_INT, context->sample_rate,
347 "channels", G_TYPE_INT, context->channels, NULL);
349 pos = gst_ff_channel_layout_to_gst (channel_layout, context->channels);
351 gst_audio_set_channel_positions (gst_caps_get_structure (caps, 0), pos);
355 gint maxchannels = 2;
356 const gint *rates = NULL;
360 /* so we must be after restricted caps in this particular case */
364 const static gint l_rates[] =
365 { 48000, 44100, 32000, 24000, 22050, 16000 };
366 n_rates = G_N_ELEMENTS (l_rates);
373 const static gint l_rates[] = { 48000, 44100, 32000 };
374 n_rates = G_N_ELEMENTS (l_rates);
378 case CODEC_ID_ADPCM_SWF:
380 const static gint l_rates[] = { 11025, 22050, 44100 };
381 n_rates = G_N_ELEMENTS (l_rates);
385 case CODEC_ID_ROQ_DPCM:
387 const static gint l_rates[] = { 22050 };
388 n_rates = G_N_ELEMENTS (l_rates);
392 case CODEC_ID_ADPCM_G726:
395 case CODEC_ID_AMR_NB:
397 const static gint l_rates[] = { 8000 };
399 n_rates = G_N_ELEMENTS (l_rates);
403 case CODEC_ID_AMR_WB:
405 const static gint l_rates[] = { 16000 };
407 n_rates = G_N_ELEMENTS (l_rates);
415 /* TODO: handle context->channel_layouts here to set
416 * the list of channel layouts supported by the encoder.
417 * Unfortunately no encoder uses this yet....
421 /* regardless of encode/decode, open up channels if applicable */
422 /* Until decoders/encoders expose the maximum number of channels
423 * they support, we whitelist them here. */
431 case CODEC_ID_WMAPRO:
432 case CODEC_ID_TRUEHD:
439 if (maxchannels == 1)
440 caps = gst_caps_new_simple (mimetype,
441 "channels", G_TYPE_INT, maxchannels, NULL);
443 caps = gst_caps_new_simple (mimetype,
444 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
446 GValue list = { 0, };
447 GstStructure *structure;
449 g_value_init (&list, GST_TYPE_LIST);
450 for (i = 0; i < n_rates; i++) {
453 g_value_init (&v, G_TYPE_INT);
454 g_value_set_int (&v, rates[i]);
455 gst_value_list_append_value (&list, &v);
458 structure = gst_caps_get_structure (caps, 0);
459 gst_structure_set_value (structure, "rate", &list);
460 g_value_unset (&list);
462 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
465 for (i = 0; i < gst_caps_get_size (caps); i++) {
466 va_start (var_args, fieldname);
467 structure = gst_caps_get_structure (caps, i);
468 gst_structure_set_valist (structure, fieldname, var_args);
475 /* Convert a FFMPEG codec ID and optional AVCodecContext
476 * to a GstCaps. If the context is ommitted, no fixed values
477 * for video/audio size will be included in the GstCaps
479 * CodecID is primarily meant for compressed data GstCaps!
481 * encode is a special parameter. gstffmpegdec will say
482 * FALSE, gstffmpegenc will say TRUE. The output caps
483 * depends on this, in such a way that it will be very
484 * specific, defined, fixed and correct caps for encoders,
485 * yet very wide, "forgiving" caps for decoders. Example
486 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
487 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
492 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
493 AVCodecContext * context, gboolean encode)
495 GstCaps *caps = NULL;
496 gboolean buildcaps = FALSE;
498 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
501 case CODEC_ID_MPEG1VIDEO:
503 caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
504 "mpegversion", G_TYPE_INT, 1,
505 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
508 case CODEC_ID_MPEG2VIDEO:
511 caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
512 "mpegversion", G_TYPE_INT, 2,
513 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
515 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
516 * the MPEG video stream headers, so may be omitted from caps. */
517 caps = gst_caps_new_simple ("video/mpeg",
518 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
519 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
523 case CODEC_ID_MPEG2VIDEO_XVMC:
524 /* this is a special ID - don't need it in GStreamer, I think */
529 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h263",
530 "variant", G_TYPE_STRING, "itu",
531 "h263version", G_TYPE_STRING, "h263", NULL);
533 /* don't pass codec_id, we can decode other variants with the H263
534 * decoder that don't have specific size requirements
536 caps = gst_ff_vid_caps_new (context, CODEC_ID_NONE, "video/x-h263",
537 "variant", G_TYPE_STRING, "itu", NULL);
542 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h263",
543 "variant", G_TYPE_STRING, "itu",
544 "h263version", G_TYPE_STRING, "h263p", NULL);
545 if (encode && context) {
547 gst_caps_set_simple (caps,
548 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
549 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
550 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
551 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
557 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-intel-h263",
558 "variant", G_TYPE_STRING, "intel", NULL);
562 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h261", NULL);
587 /* FIXME: context->sub_id must be filled in during decoding */
588 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-pn-realvideo",
589 "systemstream", G_TYPE_BOOLEAN, FALSE,
590 "rmversion", G_TYPE_INT, version, NULL);
592 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
593 if (context->extradata_size >= 8) {
594 gst_caps_set_simple (caps,
595 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
604 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
605 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
610 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
611 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
617 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
618 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
620 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
621 * in the MPEG audio header, so may be omitted from caps. */
622 caps = gst_caps_new_simple ("audio/mpeg",
623 "mpegversion", G_TYPE_INT, 1,
624 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
628 case CODEC_ID_MUSEPACK7:
630 gst_ff_aud_caps_new (context, codec_id,
631 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
635 case CODEC_ID_MUSEPACK8:
637 gst_ff_aud_caps_new (context, codec_id,
638 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
644 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-ac3", NULL);
649 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-eac3", NULL);
652 case CODEC_ID_TRUEHD:
653 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-true-hd", NULL);
656 case CODEC_ID_ATRAC1:
658 gst_ff_aud_caps_new (context, codec_id, "audio/x-vnd.sony.atrac1",
662 case CODEC_ID_ATRAC3:
664 gst_ff_aud_caps_new (context, codec_id, "audio/x-vnd.sony.atrac3",
669 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dts", NULL);
674 gst_ff_aud_caps_new (context, codec_id, "audio/x-ffmpeg-parsed-ape",
677 gst_caps_set_simple (caps,
678 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
683 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mlp", NULL);
687 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-imc", NULL);
690 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
691 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
692 * sp5x is, but it's apparently something JPEG... We don't separate
693 * between those in GStreamer. Should we (at least between MJPEG,
694 * MJPEG-B and sp5x decoding...)? */
697 caps = gst_ff_vid_caps_new (context, codec_id, "image/jpeg", NULL);
701 caps = gst_ff_vid_caps_new (context, codec_id, "video/sp5x", NULL);
704 case CODEC_ID_MJPEGB:
705 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mjpeg-b", NULL);
709 if (encode && context != NULL) {
710 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
711 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
712 switch (context->codec_tag) {
713 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
714 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-divx",
715 "divxversion", G_TYPE_INT, 5, NULL);
717 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
720 caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
721 "systemstream", G_TYPE_BOOLEAN, FALSE,
722 "mpegversion", G_TYPE_INT, 4, NULL);
726 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
727 caps = gst_ff_vid_caps_new (context, codec_id, "video/mpeg",
728 "mpegversion", G_TYPE_INT, 4,
729 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
731 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
732 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
734 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
735 "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4, 5,
737 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
738 "video/x-xvid", NULL));
739 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
740 "video/x-3ivx", NULL));
745 case CODEC_ID_RAWVIDEO:
746 caps = gst_ffmpeg_codectype_to_caps (CODEC_TYPE_VIDEO, context, codec_id,
750 case CODEC_ID_MSMPEG4V1:
751 case CODEC_ID_MSMPEG4V2:
752 case CODEC_ID_MSMPEG4V3:
754 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
756 /* encode-FIXME: bitrate */
757 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-msmpeg",
758 "msmpegversion", G_TYPE_INT, version, NULL);
759 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
760 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id,
761 "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
769 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
771 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
772 "wmvversion", G_TYPE_INT, version, NULL);
777 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-flash-video",
778 "flvversion", G_TYPE_INT, 1, NULL);
782 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-svq",
783 "svqversion", G_TYPE_INT, 1, NULL);
787 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-svq",
788 "svqversion", G_TYPE_INT, 3, NULL);
791 case CODEC_ID_DVAUDIO:
792 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dv", NULL);
795 case CODEC_ID_DVVIDEO:
797 if (encode && context) {
800 switch (context->pix_fmt) {
801 case PIX_FMT_YUYV422:
802 fourcc = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
804 case PIX_FMT_YUV420P:
805 fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
807 case PIX_FMT_YUV411P:
808 fourcc = GST_MAKE_FOURCC ('Y', '4', '1', 'B');
810 case PIX_FMT_YUV422P:
811 fourcc = GST_MAKE_FOURCC ('Y', '4', '2', 'B');
813 case PIX_FMT_YUV410P:
814 fourcc = GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
818 ("Couldnt' find fourcc for pixfmt %d, defaulting to I420",
820 fourcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
823 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dv",
824 "systemstream", G_TYPE_BOOLEAN, FALSE,
825 "format", GST_TYPE_FOURCC, fourcc, NULL);
827 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dv",
828 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
836 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
839 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
840 "wmaversion", G_TYPE_INT, version,
841 "block_align", G_TYPE_INT, context->block_align,
842 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
844 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
845 "wmaversion", G_TYPE_INT, version,
846 "block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT,
847 "bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
851 case CODEC_ID_WMAPRO:
853 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wma",
854 "wmaversion", G_TYPE_INT, 3, NULL);
858 case CODEC_ID_WMAVOICE:
860 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-wms", NULL);
867 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
869 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mace",
870 "maceversion", G_TYPE_INT, version, NULL);
874 case CODEC_ID_HUFFYUV:
875 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-huffyuv", NULL);
877 gst_caps_set_simple (caps,
878 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
884 gst_ff_vid_caps_new (context, codec_id, "video/x-compressed-yuv",
889 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-h264", NULL);
892 case CODEC_ID_INDEO5:
893 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
894 "indeoversion", G_TYPE_INT, 5, NULL);
897 case CODEC_ID_INDEO3:
898 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
899 "indeoversion", G_TYPE_INT, 3, NULL);
902 case CODEC_ID_INDEO2:
903 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-indeo",
904 "indeoversion", G_TYPE_INT, 2, NULL);
907 case CODEC_ID_FLASHSV:
909 gst_ff_vid_caps_new (context, codec_id, "video/x-flash-screen", NULL);
913 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp3", NULL);
917 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp5", NULL);
921 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6", NULL);
925 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6-flash", NULL);
929 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vp6-alpha", NULL);
932 case CODEC_ID_THEORA:
933 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-theora", NULL);
937 caps = gst_ff_aud_caps_new (context, codec_id, "audio/mpeg",
938 "mpegversion", G_TYPE_INT, 4, NULL);
942 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-asus",
943 "asusversion", G_TYPE_INT, 1, NULL);
946 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-asus",
947 "asusversion", G_TYPE_INT, 2, NULL);
951 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ffv",
952 "ffvversion", G_TYPE_INT, 1, NULL);
956 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-4xm", NULL);
959 case CODEC_ID_XAN_WC3:
960 case CODEC_ID_XAN_WC4:
961 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-xan",
962 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
967 gst_ff_vid_caps_new (context, codec_id,
968 "video/x-cirrus-logic-accupak", NULL);
972 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-fraps", NULL);
977 case CODEC_ID_INTERPLAY_VIDEO:
982 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ati-vcr",
983 "vcrversion", G_TYPE_INT, 1, NULL);
988 gst_ff_vid_caps_new (context, codec_id, "video/x-apple-video", NULL);
991 case CODEC_ID_CINEPAK:
992 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-cinepak", NULL);
995 /* WS_VQA belogns here (order) */
998 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-rle",
999 "layout", G_TYPE_STRING, "microsoft", NULL);
1001 gst_caps_set_simple (caps,
1002 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1004 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1008 case CODEC_ID_QTRLE:
1009 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-rle",
1010 "layout", G_TYPE_STRING, "quicktime", NULL);
1012 gst_caps_set_simple (caps,
1013 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1015 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1019 case CODEC_ID_MSVIDEO1:
1020 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-msvideocodec",
1021 "msvideoversion", G_TYPE_INT, 1, NULL);
1025 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
1026 "wmvversion", G_TYPE_INT, 3, NULL);
1029 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-wmv",
1030 "wmvversion", G_TYPE_INT, 3, "format", GST_TYPE_FOURCC,
1031 GST_MAKE_FOURCC ('W', 'V', 'C', '1'), NULL);
1034 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-qdm2", NULL);
1038 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mszh", NULL);
1042 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-zlib", NULL);
1045 case CODEC_ID_TRUEMOTION1:
1046 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-truemotion",
1047 "trueversion", G_TYPE_INT, 1, NULL);
1049 case CODEC_ID_TRUEMOTION2:
1050 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-truemotion",
1051 "trueversion", G_TYPE_INT, 2, NULL);
1055 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-ultimotion",
1060 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-camtasia", NULL);
1062 gst_caps_set_simple (caps,
1063 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1065 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1070 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-kmvc", NULL);
1074 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-nuv", NULL);
1078 caps = gst_ff_vid_caps_new (context, codec_id, "image/gif", NULL);
1082 caps = gst_ff_vid_caps_new (context, codec_id, "image/png", NULL);
1086 caps = gst_ff_vid_caps_new (context, codec_id, "image/ppm", NULL);
1090 caps = gst_ff_vid_caps_new (context, codec_id, "image/pbm", NULL);
1095 gst_ff_vid_caps_new (context, codec_id, "image/x-portable-anymap",
1101 gst_ff_vid_caps_new (context, codec_id, "image/x-portable-graymap",
1106 caps = gst_ff_vid_caps_new (context, codec_id, "image/x-pcx", NULL);
1110 caps = gst_ff_vid_caps_new (context, codec_id, "image/x-sgi", NULL);
1113 case CODEC_ID_TARGA:
1114 caps = gst_ff_vid_caps_new (context, codec_id, "image/x-tga", NULL);
1118 caps = gst_ff_vid_caps_new (context, codec_id, "image/tiff", NULL);
1121 case CODEC_ID_SUNRAST:
1123 gst_ff_vid_caps_new (context, codec_id, "image/x-sun-raster", NULL);
1127 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-smc", NULL);
1130 case CODEC_ID_QDRAW:
1131 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-qdrw", NULL);
1134 case CODEC_ID_DNXHD:
1135 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-dnxhd", NULL);
1138 case CODEC_ID_MIMIC:
1139 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-mimic", NULL);
1143 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-vmnc", NULL);
1146 case CODEC_ID_TRUESPEECH:
1148 gst_ff_aud_caps_new (context, codec_id, "audio/x-truespeech", NULL);
1151 case CODEC_ID_QCELP:
1152 caps = gst_ff_aud_caps_new (context, codec_id, "audio/qcelp", NULL);
1156 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-amv", NULL);
1160 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-aasc", NULL);
1164 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-loco", NULL);
1168 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-zmbv", NULL);
1172 case CODEC_ID_WS_VQA:
1173 case CODEC_ID_IDCIN:
1176 case CODEC_ID_VMDVIDEO:
1177 case CODEC_ID_VMDAUDIO:
1178 case CODEC_ID_SONIC:
1179 case CODEC_ID_SONIC_LS:
1184 case CODEC_ID_PGMYUV:
1185 case CODEC_ID_FFVHUFF:
1187 case CODEC_ID_MP3ADU:
1188 case CODEC_ID_MP3ON4:
1189 case CODEC_ID_WESTWOOD_SND1:
1191 case CODEC_ID_MMVIDEO:
1197 /* weird quasi-codecs for the demuxers only */
1198 case CODEC_ID_PCM_S16LE:
1199 case CODEC_ID_PCM_S16BE:
1200 case CODEC_ID_PCM_U16LE:
1201 case CODEC_ID_PCM_U16BE:
1202 case CODEC_ID_PCM_S8:
1203 case CODEC_ID_PCM_U8:
1205 gint width = 0, depth = 0, endianness = 0;
1206 gboolean signedness = FALSE; /* blabla */
1209 case CODEC_ID_PCM_S16LE:
1212 endianness = G_LITTLE_ENDIAN;
1215 case CODEC_ID_PCM_S16BE:
1218 endianness = G_BIG_ENDIAN;
1221 case CODEC_ID_PCM_U16LE:
1224 endianness = G_LITTLE_ENDIAN;
1227 case CODEC_ID_PCM_U16BE:
1230 endianness = G_BIG_ENDIAN;
1233 case CODEC_ID_PCM_S8:
1236 endianness = G_BYTE_ORDER;
1239 case CODEC_ID_PCM_U8:
1242 endianness = G_BYTE_ORDER;
1246 g_assert (0); /* don't worry, we never get here */
1250 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-int",
1251 "width", G_TYPE_INT, width,
1252 "depth", G_TYPE_INT, depth,
1253 "endianness", G_TYPE_INT, endianness,
1254 "signed", G_TYPE_BOOLEAN, signedness, NULL);
1258 case CODEC_ID_PCM_MULAW:
1259 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-mulaw", NULL);
1262 case CODEC_ID_PCM_ALAW:
1263 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-alaw", NULL);
1266 case CODEC_ID_ADPCM_G726:
1268 /* the G726 decoder can also handle G721 */
1269 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-adpcm",
1270 "layout", G_TYPE_STRING, "g726", NULL);
1272 gst_caps_set_simple (caps,
1273 "block_align", G_TYPE_INT, context->block_align,
1274 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1277 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1278 "layout", G_TYPE_STRING, "g721",
1279 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1283 case CODEC_ID_ADPCM_IMA_QT:
1284 case CODEC_ID_ADPCM_IMA_WAV:
1285 case CODEC_ID_ADPCM_IMA_DK3:
1286 case CODEC_ID_ADPCM_IMA_DK4:
1287 case CODEC_ID_ADPCM_IMA_WS:
1288 case CODEC_ID_ADPCM_IMA_SMJPEG:
1289 case CODEC_ID_ADPCM_IMA_AMV:
1290 case CODEC_ID_ADPCM_IMA_ISS:
1291 case CODEC_ID_ADPCM_IMA_EA_EACS:
1292 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1293 case CODEC_ID_ADPCM_MS:
1294 case CODEC_ID_ADPCM_4XM:
1295 case CODEC_ID_ADPCM_XA:
1296 case CODEC_ID_ADPCM_ADX:
1297 case CODEC_ID_ADPCM_EA:
1298 case CODEC_ID_ADPCM_CT:
1299 case CODEC_ID_ADPCM_SWF:
1300 case CODEC_ID_ADPCM_YAMAHA:
1301 case CODEC_ID_ADPCM_SBPRO_2:
1302 case CODEC_ID_ADPCM_SBPRO_3:
1303 case CODEC_ID_ADPCM_SBPRO_4:
1304 case CODEC_ID_ADPCM_EA_R1:
1305 case CODEC_ID_ADPCM_EA_R2:
1306 case CODEC_ID_ADPCM_EA_R3:
1307 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1308 case CODEC_ID_ADPCM_EA_XAS:
1309 case CODEC_ID_ADPCM_THP:
1311 const gchar *layout = NULL;
1314 case CODEC_ID_ADPCM_IMA_QT:
1315 layout = "quicktime";
1317 case CODEC_ID_ADPCM_IMA_WAV:
1320 case CODEC_ID_ADPCM_IMA_DK3:
1323 case CODEC_ID_ADPCM_IMA_DK4:
1326 case CODEC_ID_ADPCM_IMA_WS:
1327 layout = "westwood";
1329 case CODEC_ID_ADPCM_IMA_SMJPEG:
1332 case CODEC_ID_ADPCM_IMA_AMV:
1335 case CODEC_ID_ADPCM_IMA_ISS:
1338 case CODEC_ID_ADPCM_IMA_EA_EACS:
1341 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1344 case CODEC_ID_ADPCM_MS:
1345 layout = "microsoft";
1347 case CODEC_ID_ADPCM_4XM:
1350 case CODEC_ID_ADPCM_XA:
1353 case CODEC_ID_ADPCM_ADX:
1356 case CODEC_ID_ADPCM_EA:
1359 case CODEC_ID_ADPCM_CT:
1362 case CODEC_ID_ADPCM_SWF:
1365 case CODEC_ID_ADPCM_YAMAHA:
1368 case CODEC_ID_ADPCM_SBPRO_2:
1371 case CODEC_ID_ADPCM_SBPRO_3:
1374 case CODEC_ID_ADPCM_SBPRO_4:
1377 case CODEC_ID_ADPCM_EA_R1:
1380 case CODEC_ID_ADPCM_EA_R2:
1383 case CODEC_ID_ADPCM_EA_R3:
1386 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1387 layout = "ea-maxis-xa";
1389 case CODEC_ID_ADPCM_EA_XAS:
1392 case CODEC_ID_ADPCM_THP:
1396 g_assert (0); /* don't worry, we never get here */
1400 /* FIXME: someone please check whether we need additional properties
1401 * in this caps definition. */
1402 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-adpcm",
1403 "layout", G_TYPE_STRING, layout, NULL);
1405 gst_caps_set_simple (caps,
1406 "block_align", G_TYPE_INT, context->block_align,
1407 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1411 case CODEC_ID_AMR_NB:
1412 caps = gst_ff_aud_caps_new (context, codec_id, "audio/AMR", NULL);
1415 case CODEC_ID_AMR_WB:
1416 caps = gst_ff_aud_caps_new (context, codec_id, "audio/AMR-WB", NULL);
1419 case CODEC_ID_NELLYMOSER:
1421 gst_ff_aud_caps_new (context, codec_id, "audio/x-nellymoser", NULL);
1426 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-sipro", NULL);
1428 gst_caps_set_simple (caps,
1429 "leaf_size", G_TYPE_INT, context->block_align,
1430 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1435 case CODEC_ID_RA_144:
1436 case CODEC_ID_RA_288:
1442 case CODEC_ID_RA_144:
1445 case CODEC_ID_RA_288:
1455 /* FIXME: properties? */
1456 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-pn-realaudio",
1457 "raversion", G_TYPE_INT, version, NULL);
1459 gst_caps_set_simple (caps,
1460 "leaf_size", G_TYPE_INT, context->block_align,
1461 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1466 case CODEC_ID_ROQ_DPCM:
1467 case CODEC_ID_INTERPLAY_DPCM:
1468 case CODEC_ID_XAN_DPCM:
1469 case CODEC_ID_SOL_DPCM:
1471 const gchar *layout = NULL;
1474 case CODEC_ID_ROQ_DPCM:
1477 case CODEC_ID_INTERPLAY_DPCM:
1478 layout = "interplay";
1480 case CODEC_ID_XAN_DPCM:
1483 case CODEC_ID_SOL_DPCM:
1487 g_assert (0); /* don't worry, we never get here */
1491 /* FIXME: someone please check whether we need additional properties
1492 * in this caps definition. */
1493 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-dpcm",
1494 "layout", G_TYPE_STRING, layout, NULL);
1496 gst_caps_set_simple (caps,
1497 "block_align", G_TYPE_INT, context->block_align,
1498 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1502 case CODEC_ID_SHORTEN:
1503 caps = gst_caps_new_simple ("audio/x-shorten", NULL);
1507 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-alac", NULL);
1509 gst_caps_set_simple (caps,
1510 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1515 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1516 * encoder case, we want to add things like samplerate, channels... */
1518 caps = gst_caps_new_simple ("audio/x-flac", NULL);
1522 case CODEC_ID_DVD_SUBTITLE:
1523 case CODEC_ID_DVB_SUBTITLE:
1527 caps = gst_caps_new_simple ("image/bmp", NULL);
1530 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-tta", NULL);
1532 gst_caps_set_simple (caps,
1533 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1536 case CODEC_ID_TWINVQ:
1537 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-twin-vq", NULL);
1540 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1547 if ((codec = avcodec_find_decoder (codec_id)) ||
1548 (codec = avcodec_find_encoder (codec_id))) {
1551 GST_LOG ("Could not create stream format caps for %s", codec->name);
1553 switch (codec->type) {
1554 case CODEC_TYPE_VIDEO:
1555 mime = g_strdup_printf ("video/x-gst_ff-%s", codec->name);
1556 caps = gst_ff_vid_caps_new (context, codec_id, mime, NULL);
1559 case CODEC_TYPE_AUDIO:
1560 mime = g_strdup_printf ("audio/x-gst_ff-%s", codec->name);
1561 caps = gst_ff_aud_caps_new (context, codec_id, mime, NULL);
1563 gst_caps_set_simple (caps,
1564 "block_align", G_TYPE_INT, context->block_align,
1565 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1576 /* set private data */
1577 if (context && context->extradata_size > 0) {
1578 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1580 memcpy (GST_BUFFER_DATA (data), context->extradata,
1581 context->extradata_size);
1582 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1583 gst_buffer_unref (data);
1588 gst_ffmpeg_set_palette (caps, context);
1591 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1594 GST_LOG ("No caps found for codec_id=%d", codec_id);
1600 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1601 * to a GstCaps. If the context is ommitted, no fixed values
1602 * for video/audio size will be included in the GstCaps
1604 * See below for usefullness
1608 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1609 enum CodecID codec_id)
1611 GstCaps *caps = NULL;
1613 int bpp = 0, depth = 0, endianness = 0;
1614 gulong g_mask = 0, r_mask = 0, b_mask = 0, a_mask = 0;
1618 case PIX_FMT_YUVJ420P:
1619 case PIX_FMT_YUV420P:
1620 fmt = GST_MAKE_FOURCC ('I', '4', '2', '0');
1622 case PIX_FMT_YUYV422:
1623 fmt = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
1627 endianness = G_BIG_ENDIAN;
1634 endianness = G_BIG_ENDIAN;
1639 case PIX_FMT_YUVJ422P:
1640 case PIX_FMT_YUV422P:
1641 fmt = GST_MAKE_FOURCC ('Y', '4', '2', 'B');
1643 case PIX_FMT_YUVJ444P:
1644 case PIX_FMT_YUV444P:
1645 fmt = GST_MAKE_FOURCC ('Y', '4', '4', '4');
1650 endianness = G_BIG_ENDIAN;
1651 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
1652 r_mask = 0x00ff0000;
1653 g_mask = 0x0000ff00;
1654 b_mask = 0x000000ff;
1655 a_mask = 0xff000000;
1657 r_mask = 0x0000ff00;
1658 g_mask = 0x00ff0000;
1659 b_mask = 0xff000000;
1660 a_mask = 0x000000ff;
1663 case PIX_FMT_YUV410P:
1664 fmt = GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
1666 case PIX_FMT_YUV411P:
1667 fmt = GST_MAKE_FOURCC ('Y', '4', '1', 'B');
1669 case PIX_FMT_RGB565:
1671 endianness = G_BYTE_ORDER;
1676 case PIX_FMT_RGB555:
1679 endianness = G_BYTE_ORDER;
1686 endianness = G_BYTE_ORDER;
1690 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-gray",
1691 "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth, NULL);
1702 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-rgb",
1703 "bpp", G_TYPE_INT, bpp,
1704 "depth", G_TYPE_INT, depth,
1705 "red_mask", G_TYPE_INT, r_mask,
1706 "green_mask", G_TYPE_INT, g_mask,
1707 "blue_mask", G_TYPE_INT, b_mask,
1708 "alpha_mask", G_TYPE_INT, a_mask,
1709 "endianness", G_TYPE_INT, endianness, NULL);
1711 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-rgb",
1712 "bpp", G_TYPE_INT, bpp,
1713 "depth", G_TYPE_INT, depth,
1714 "red_mask", G_TYPE_INT, r_mask,
1715 "green_mask", G_TYPE_INT, g_mask,
1716 "blue_mask", G_TYPE_INT, b_mask,
1717 "endianness", G_TYPE_INT, endianness, NULL);
1720 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-rgb",
1721 "bpp", G_TYPE_INT, bpp,
1722 "depth", G_TYPE_INT, depth,
1723 "endianness", G_TYPE_INT, endianness, NULL);
1724 if (caps && context) {
1725 gst_ffmpeg_set_palette (caps, context);
1729 caps = gst_ff_vid_caps_new (context, codec_id, "video/x-raw-yuv",
1730 "format", GST_TYPE_FOURCC, fmt, NULL);
1735 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1737 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1743 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1744 * to a GstCaps. If the context is ommitted, no fixed values
1745 * for video/audio size will be included in the GstCaps
1747 * See below for usefullness
1751 gst_ffmpeg_smpfmt_to_caps (enum SampleFormat sample_fmt,
1752 AVCodecContext * context, enum CodecID codec_id)
1754 GstCaps *caps = NULL;
1757 gboolean integer = TRUE;
1758 gboolean signedness = FALSE;
1760 switch (sample_fmt) {
1761 case SAMPLE_FMT_S16:
1766 case SAMPLE_FMT_S32:
1771 case SAMPLE_FMT_FLT:
1776 case SAMPLE_FMT_DBL:
1787 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-int",
1788 "signed", G_TYPE_BOOLEAN, signedness,
1789 "endianness", G_TYPE_INT, G_BYTE_ORDER,
1790 "width", G_TYPE_INT, bpp, "depth", G_TYPE_INT, bpp, NULL);
1792 caps = gst_ff_aud_caps_new (context, codec_id, "audio/x-raw-float",
1793 "endianness", G_TYPE_INT, G_BYTE_ORDER,
1794 "width", G_TYPE_INT, bpp, NULL);
1799 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1801 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1808 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
1809 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1811 GstCaps *caps = NULL;
1813 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1814 context, codec_id, encode, codec);
1816 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
1817 codec->sample_fmts, codec->supported_samplerates);
1820 /* Specific codec context */
1821 caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec_id);
1822 } else if (codec && codec->sample_fmts) {
1826 caps = gst_caps_new_empty ();
1827 for (i = 0; codec->sample_fmts[i] != -1; i++) {
1829 gst_ffmpeg_smpfmt_to_caps (codec->sample_fmts[i], context, codec_id);
1831 gst_caps_append (caps, temp);
1835 enum SampleFormat i;
1836 AVCodecContext ctx = { 0, };
1839 caps = gst_caps_new_empty ();
1840 for (i = 0; i <= SAMPLE_FMT_DBL; i++) {
1841 temp = gst_ffmpeg_smpfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1843 gst_caps_append (caps, temp);
1851 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
1852 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1856 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1857 context, codec_id, encode, codec);
1860 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
1864 AVCodecContext ctx = { 0, };
1866 caps = gst_caps_new_empty ();
1867 for (i = 0; i < PIX_FMT_NB; i++) {
1870 temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1872 gst_caps_append (caps, temp);
1879 /* Convert a FFMPEG codec Type and optional AVCodecContext
1880 * to a GstCaps. If the context is ommitted, no fixed values
1881 * for video/audio size will be included in the GstCaps
1883 * CodecType is primarily meant for uncompressed data GstCaps!
1887 gst_ffmpeg_codectype_to_caps (enum CodecType codec_type,
1888 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
1892 switch (codec_type) {
1893 case CODEC_TYPE_VIDEO:
1895 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1897 case CODEC_TYPE_AUDIO:
1899 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
1909 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
1910 * and other audio properties in a AVCodecContext.
1912 * For usefullness, see below
1916 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
1917 AVCodecContext * context, gboolean raw)
1919 GstStructure *structure;
1920 gint depth = 0, width = 0, endianness = 0;
1921 gboolean signedness = FALSE;
1924 g_return_if_fail (gst_caps_get_size (caps) == 1);
1925 structure = gst_caps_get_structure (caps, 0);
1927 gst_structure_get_int (structure, "channels", &context->channels);
1928 gst_structure_get_int (structure, "rate", &context->sample_rate);
1929 gst_structure_get_int (structure, "block_align", &context->block_align);
1930 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
1935 name = gst_structure_get_name (structure);
1937 if (!strcmp (name, "audio/x-raw-float")) {
1939 if (gst_structure_get_int (structure, "width", &width) &&
1940 gst_structure_get_int (structure, "endianness", &endianness)) {
1941 if (endianness == G_BYTE_ORDER) {
1943 context->sample_fmt = SAMPLE_FMT_FLT;
1944 else if (width == 64)
1945 context->sample_fmt = SAMPLE_FMT_DBL;
1950 if (gst_structure_get_int (structure, "width", &width) &&
1951 gst_structure_get_int (structure, "depth", &depth) &&
1952 gst_structure_get_boolean (structure, "signed", &signedness) &&
1953 gst_structure_get_int (structure, "endianness", &endianness)) {
1954 if ((endianness == G_BYTE_ORDER) && (signedness == TRUE)) {
1955 if ((width == 16) && (depth == 16))
1956 context->sample_fmt = SAMPLE_FMT_S16;
1957 else if ((width == 32) && (depth == 32))
1958 context->sample_fmt = SAMPLE_FMT_S32;
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 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
1980 g_return_if_fail (gst_caps_get_size (caps) == 1);
1981 structure = gst_caps_get_structure (caps, 0);
1983 gst_structure_get_int (structure, "width", &context->width);
1984 gst_structure_get_int (structure, "height", &context->height);
1985 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
1987 fps = gst_structure_get_value (structure, "framerate");
1988 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
1990 /* somehow these seem mixed up.. */
1991 context->time_base.den = gst_value_get_fraction_numerator (fps);
1992 context->time_base.num = gst_value_get_fraction_denominator (fps);
1993 context->ticks_per_frame = 1;
1995 GST_DEBUG ("setting framerate %d/%d = %lf",
1996 context->time_base.den, context->time_base.num,
1997 1. * context->time_base.den / context->time_base.num);
2000 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2001 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2003 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2004 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2006 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2007 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2008 1. * context->sample_aspect_ratio.den /
2009 context->sample_aspect_ratio.num);
2015 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2017 if (strcmp (gst_structure_get_name (structure), "video/x-raw-yuv") == 0) {
2020 if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
2022 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
2023 context->pix_fmt = PIX_FMT_YUYV422;
2025 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
2026 context->pix_fmt = PIX_FMT_YUV420P;
2028 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
2029 context->pix_fmt = PIX_FMT_YUV411P;
2031 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
2032 context->pix_fmt = PIX_FMT_YUV422P;
2034 case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
2035 context->pix_fmt = PIX_FMT_YUV410P;
2039 context->pix_fmt = PIX_FMT_YUV444P;
2044 } else if (strcmp (gst_structure_get_name (structure),
2045 "video/x-raw-rgb") == 0) {
2046 gint bpp = 0, rmask = 0, endianness = 0;
2048 if (gst_structure_get_int (structure, "bpp", &bpp) &&
2049 gst_structure_get_int (structure, "endianness", &endianness)) {
2050 if (gst_structure_get_int (structure, "red_mask", &rmask)) {
2053 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2054 if (rmask == 0x00ff0000)
2056 if (rmask == 0x0000ff00)
2058 context->pix_fmt = PIX_FMT_RGB32;
2061 if (rmask == 0x0000FF)
2062 context->pix_fmt = PIX_FMT_BGR24;
2064 context->pix_fmt = PIX_FMT_RGB24;
2067 if (endianness == G_BYTE_ORDER)
2068 context->pix_fmt = PIX_FMT_RGB565;
2071 if (endianness == G_BYTE_ORDER)
2072 context->pix_fmt = PIX_FMT_RGB555;
2080 context->pix_fmt = PIX_FMT_PAL8;
2081 gst_ffmpeg_get_palette (caps, context);
2085 } else if (strcmp (gst_structure_get_name (structure),
2086 "video/x-raw-gray") == 0) {
2089 if (gst_structure_get_int (structure, "bpp", &bpp)) {
2092 context->pix_fmt = PIX_FMT_GRAY8;
2099 /* Convert a GstCaps and a FFMPEG codec Type to a
2100 * AVCodecContext. If the context is ommitted, no fixed values
2101 * for video/audio size will be included in the context
2103 * CodecType is primarily meant for uncompressed data GstCaps!
2107 gst_ffmpeg_caps_with_codectype (enum CodecType type,
2108 const GstCaps * caps, AVCodecContext * context)
2110 if (context == NULL)
2114 case CODEC_TYPE_VIDEO:
2115 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2118 case CODEC_TYPE_AUDIO:
2119 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2130 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2134 guint8 *end = src + size;
2137 while (srcp < end) {
2138 if (count == 2 && *srcp <= 0x03) {
2139 GST_DEBUG ("added escape code");
2148 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2151 *destsize = dstp - dst;
2154 /* copy the config, escaping NAL units as we iterate them, if something fails we
2155 * copy everything and hope for the best. */
2157 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2162 guint nalsize, esize;
2172 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2174 GST_DEBUG ("num SPS %d", cnt);
2176 memcpy (dstp, srcp, 6);
2180 for (i = 0; i < cnt; i++) {
2181 GST_DEBUG ("copy SPS %d", i);
2182 nalsize = (srcp[0] << 8) | srcp[1];
2183 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2184 dstp[0] = esize >> 8;
2185 dstp[1] = esize & 0xff;
2187 srcp += nalsize + 2;
2190 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2192 GST_DEBUG ("num PPS %d", cnt);
2194 for (i = 0; i < cnt; i++) {
2195 GST_DEBUG ("copy PPS %d", i);
2196 nalsize = (srcp[0] << 8) | srcp[1];
2197 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2198 dstp[0] = esize >> 8;
2199 dstp[1] = esize & 0xff;
2201 srcp += nalsize + 2;
2203 *destsize = dstp - dst;
2209 GST_DEBUG ("something unexpected, doing full copy");
2210 memcpy (dst, src, size);
2218 * caps_with_codecid () transforms a GstCaps for a known codec
2219 * ID into a filled-in context.
2220 * codec_data from caps will override possible extradata already in the context
2224 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2225 enum CodecType codec_type, const GstCaps * caps, AVCodecContext * context)
2228 const GValue *value;
2229 const GstBuffer *buf;
2231 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2232 codec_id, codec_type, caps, context);
2234 if (!context || !gst_caps_get_size (caps))
2237 str = gst_caps_get_structure (caps, 0);
2239 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2240 if ((value = gst_structure_get_value (str, "codec_data"))) {
2244 buf = GST_BUFFER_CAST (gst_value_get_mini_object (value));
2245 size = GST_BUFFER_SIZE (buf);
2246 data = GST_BUFFER_DATA (buf);
2248 /* free the old one if it is there */
2249 if (context->extradata)
2250 av_free (context->extradata);
2253 if (codec_id == CODEC_ID_H264) {
2256 GST_DEBUG ("copy, escaping codec_data %d", size);
2257 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2258 * reason for this but let's just escape it for now. Start by allocating
2259 * enough space, x2 is more than enough.
2261 * FIXME, we disabled escaping because some file already contain escaped
2262 * codec_data and then we escape twice and fail. It's better to leave it
2263 * as is, as that is what most players do. */
2264 context->extradata =
2265 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2266 FF_INPUT_BUFFER_PADDING_SIZE));
2267 copy_config (context->extradata, data, size, &extrasize);
2268 GST_DEBUG ("escaped size: %d", extrasize);
2269 context->extradata_size = extrasize;
2273 /* allocate with enough padding */
2274 GST_DEBUG ("copy codec_data");
2275 context->extradata =
2276 av_mallocz (GST_ROUND_UP_16 (size + FF_INPUT_BUFFER_PADDING_SIZE));
2277 memcpy (context->extradata, data, size);
2278 context->extradata_size = size;
2281 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2282 if (codec_id == CODEC_ID_VC1 && size > 0 && data[0] == 0) {
2283 context->extradata[0] = (guint8) size;
2286 GST_DEBUG ("have codec data of size %d", size);
2287 } else if (context->extradata == NULL) {
2288 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2289 * extradata anyway which makes then segfault. */
2290 context->extradata =
2291 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2292 context->extradata_size = 0;
2293 GST_DEBUG ("no codec data");
2297 case CODEC_ID_MPEG4:
2299 const gchar *mime = gst_structure_get_name (str);
2301 if (!strcmp (mime, "video/x-divx"))
2302 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2303 else if (!strcmp (mime, "video/x-xvid"))
2304 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2305 else if (!strcmp (mime, "video/x-3ivx"))
2306 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2307 else if (!strcmp (mime, "video/mpeg"))
2308 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2313 /* FIXME: this is a workaround for older gst-plugins releases
2314 * (<= 0.8.9). This should be removed at some point, because
2315 * it causes wrong decoded frame order. */
2316 if (!context->extradata) {
2317 /* fix prevent defect */
2318 gint halfpel_flag = 0, thirdpel_flag = 0, low_delay = 0, unknown_svq3_flag = 0;
2321 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2322 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2323 gst_structure_get_int (str, "low_delay", &low_delay) ||
2324 gst_structure_get_int (str, "unknown_svq3_flag",
2325 &unknown_svq3_flag)) {
2326 context->extradata = (guint8 *) av_mallocz (0x64);
2327 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2331 flags |= unknown_svq3_flag;
2333 flags |= halfpel_flag;
2335 flags |= thirdpel_flag;
2338 flags = GUINT16_FROM_LE (flags);
2340 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2341 context->extradata_size = 0x64;
2346 case CODEC_ID_MSRLE:
2347 case CODEC_ID_QTRLE:
2353 if (gst_structure_get_int (str, "depth", &depth)) {
2354 context->bits_per_coded_sample = depth;
2356 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2369 if (gst_structure_get_int (str, "format", &format))
2370 context->sub_id = format;
2375 case CODEC_ID_RA_288:
2376 case CODEC_ID_RA_144:
2382 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2383 context->block_align = leaf_size;
2384 if (gst_structure_get_int (str, "bitrate", &bitrate))
2385 context->bit_rate = bitrate;
2388 gst_structure_get_int (str, "samplesize",
2389 &context->bits_per_coded_sample);
2392 case CODEC_ID_DVVIDEO:
2396 if (gst_structure_get_fourcc (str, "format", &fourcc))
2398 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
2399 context->pix_fmt = PIX_FMT_YUYV422;
2401 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
2402 context->pix_fmt = PIX_FMT_YUV420P;
2404 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
2405 context->pix_fmt = PIX_FMT_YUV411P;
2407 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
2408 context->pix_fmt = PIX_FMT_YUV422P;
2410 case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
2411 context->pix_fmt = PIX_FMT_YUV410P;
2414 GST_WARNING ("couldn't convert fourcc %" GST_FOURCC_FORMAT
2415 " to a pixel format", GST_FOURCC_ARGS (fourcc));
2420 case CODEC_ID_H263P:
2424 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2425 context->flags |= CODEC_FLAG_4MV;
2427 context->flags &= ~CODEC_FLAG_4MV;
2428 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2429 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2430 context->flags |= CODEC_FLAG_AC_PRED;
2432 context->flags &= ~CODEC_FLAG_AC_PRED;
2433 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2434 context->flags |= CODEC_FLAG_LOOP_FILTER;
2436 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2439 case CODEC_ID_ADPCM_G726:
2441 const gchar *layout;
2443 if ((layout = gst_structure_get_string (str, "layout"))) {
2444 if (!strcmp (layout, "g721")) {
2445 context->sample_rate = 8000;
2446 context->channels = 1;
2447 context->bit_rate = 32000;
2456 if (!gst_caps_is_fixed (caps))
2459 /* common properties (width, height, fps) */
2460 switch (codec_type) {
2461 case CODEC_TYPE_VIDEO:
2462 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2463 gst_ffmpeg_get_palette (caps, context);
2465 case CODEC_TYPE_AUDIO:
2466 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2472 /* fixup of default settings */
2474 case CODEC_ID_QCELP:
2475 /* QCELP is always mono, no matter what the caps say */
2476 context->channels = 1;
2483 /* _formatid_to_caps () is meant for muxers/demuxers, it
2484 * transforms a name (ffmpeg way of ID'ing these, why don't
2485 * they have unique numerical IDs?) to the corresponding
2486 * caps belonging to that mux-format
2488 * Note: we don't need any additional info because the caps
2489 * isn't supposed to contain any useful info besides the
2494 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2496 GstCaps *caps = NULL;
2498 if (!strcmp (format_name, "mpeg")) {
2499 caps = gst_caps_new_simple ("video/mpeg",
2500 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2501 } else if (!strcmp (format_name, "mpegts")) {
2502 caps = gst_caps_new_simple ("video/mpegts",
2503 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2504 } else if (!strcmp (format_name, "rm")) {
2505 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2506 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2507 } else if (!strcmp (format_name, "asf")) {
2508 caps = gst_caps_new_simple ("video/x-ms-asf", NULL);
2509 } else if (!strcmp (format_name, "avi")) {
2510 caps = gst_caps_new_simple ("video/x-msvideo", NULL);
2511 } else if (!strcmp (format_name, "wav")) {
2512 caps = gst_caps_new_simple ("audio/x-wav", NULL);
2513 } else if (!strcmp (format_name, "ape")) {
2514 caps = gst_caps_new_simple ("application/x-ape", NULL);
2515 } else if (!strcmp (format_name, "swf")) {
2516 caps = gst_caps_new_simple ("application/x-shockwave-flash", NULL);
2517 } else if (!strcmp (format_name, "au")) {
2518 caps = gst_caps_new_simple ("audio/x-au", NULL);
2519 } else if (!strcmp (format_name, "dv")) {
2520 caps = gst_caps_new_simple ("video/x-dv",
2521 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2522 } else if (!strcmp (format_name, "4xm")) {
2523 caps = gst_caps_new_simple ("video/x-4xm", NULL);
2524 } else if (!strcmp (format_name, "matroska")) {
2525 caps = gst_caps_new_simple ("video/x-matroska", NULL);
2526 } else if (!strcmp (format_name, "mp3")) {
2527 caps = gst_caps_new_simple ("application/x-id3", NULL);
2528 } else if (!strcmp (format_name, "flic")) {
2529 caps = gst_caps_new_simple ("video/x-fli", NULL);
2530 } else if (!strcmp (format_name, "flv")) {
2531 caps = gst_caps_new_simple ("video/x-flv", NULL);
2532 } else if (!strcmp (format_name, "tta")) {
2533 caps = gst_caps_new_simple ("audio/x-ttafile", NULL);
2534 } else if (!strcmp (format_name, "aiff")) {
2535 caps = gst_caps_new_simple ("audio/x-aiff", NULL);
2536 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2538 gst_caps_from_string
2539 ("application/x-3gp; video/quicktime; audio/x-m4a");
2540 } else if (!strcmp (format_name, "mov")) {
2541 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2542 } else if (!strcmp (format_name, "mp4")) {
2543 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2544 } else if (!strcmp (format_name, "3gp")) {
2545 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2546 } else if (!strcmp (format_name, "3g2")) {
2547 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2548 } else if (!strcmp (format_name, "psp")) {
2549 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2550 } else if (!strcmp (format_name, "ipod")) {
2551 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2552 } else if (!strcmp (format_name, "aac")) {
2553 caps = gst_caps_new_simple ("audio/mpeg",
2554 "mpegversion", G_TYPE_INT, 4, NULL);
2555 } else if (!strcmp (format_name, "gif")) {
2556 caps = gst_caps_from_string ("image/gif");
2557 } else if (!strcmp (format_name, "ogg")) {
2558 caps = gst_caps_from_string ("application/ogg");
2559 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
2560 caps = gst_caps_from_string ("application/mxf");
2561 } else if (!strcmp (format_name, "gxf")) {
2562 caps = gst_caps_from_string ("application/gxf");
2563 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
2564 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
2565 "y4mversion", G_TYPE_INT, 2, NULL);
2566 } else if (!strcmp (format_name, "mpc")) {
2567 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
2568 } else if (!strcmp (format_name, "vqf")) {
2569 caps = gst_caps_from_string ("audio/x-vqf");
2570 } else if (!strcmp (format_name, "nsv")) {
2571 caps = gst_caps_from_string ("video/x-nsv");
2572 } else if (!strcmp (format_name, "amr")) {
2573 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
2574 } else if (!strcmp (format_name, "webm")) {
2575 caps = gst_caps_from_string ("video/webm");
2579 GST_LOG ("Could not create stream format caps for %s", format_name);
2580 name = g_strdup_printf ("application/x-gst_ff-%s", format_name);
2581 caps = gst_caps_new_simple (name, NULL);
2589 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
2590 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
2591 AVOutputFormat * plugin)
2593 static enum CodecID tmp_vlist[] = {
2597 static enum CodecID tmp_alist[] = {
2602 GST_LOG ("format_name : %s", format_name);
2604 if (!strcmp (format_name, "mp4")) {
2605 static enum CodecID mp4_video_list[] = {
2606 CODEC_ID_MPEG4, CODEC_ID_H264,
2610 static enum CodecID mp4_audio_list[] = {
2611 CODEC_ID_AAC, CODEC_ID_MP3,
2615 *video_codec_list = mp4_video_list;
2616 *audio_codec_list = mp4_audio_list;
2617 } else if (!strcmp (format_name, "mpeg")) {
2618 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
2619 CODEC_ID_MPEG2VIDEO,
2623 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
2629 *video_codec_list = mpeg_video_list;
2630 *audio_codec_list = mpeg_audio_list;
2631 } else if (!strcmp (format_name, "dvd")) {
2632 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
2635 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
2642 *video_codec_list = mpeg_video_list;
2643 *audio_codec_list = mpeg_audio_list;
2644 } else if (!strcmp (format_name, "mpegts")) {
2645 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
2646 CODEC_ID_MPEG2VIDEO,
2650 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
2658 *video_codec_list = mpegts_video_list;
2659 *audio_codec_list = mpegts_audio_list;
2660 } else if (!strcmp (format_name, "vob")) {
2661 static enum CodecID vob_video_list[] =
2662 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
2663 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
2664 CODEC_ID_DTS, CODEC_ID_NONE
2667 *video_codec_list = vob_video_list;
2668 *audio_codec_list = vob_audio_list;
2669 } else if (!strcmp (format_name, "flv")) {
2670 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
2671 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
2673 *video_codec_list = flv_video_list;
2674 *audio_codec_list = flv_audio_list;
2675 } else if (!strcmp (format_name, "asf")) {
2676 static enum CodecID asf_video_list[] =
2677 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
2678 static enum CodecID asf_audio_list[] =
2679 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
2681 *video_codec_list = asf_video_list;
2682 *audio_codec_list = asf_audio_list;
2683 } else if (!strcmp (format_name, "dv")) {
2684 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
2685 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
2687 *video_codec_list = dv_video_list;
2688 *audio_codec_list = dv_audio_list;
2689 } else if (!strcmp (format_name, "mov")) {
2690 static enum CodecID mov_video_list[] = {
2691 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
2692 CODEC_ID_H263, CODEC_ID_H263P,
2693 CODEC_ID_H264, CODEC_ID_DVVIDEO,
2697 static enum CodecID mov_audio_list[] = {
2698 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
2699 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
2700 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2701 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
2702 CODEC_ID_MP3, CODEC_ID_NONE
2705 *video_codec_list = mov_video_list;
2706 *audio_codec_list = mov_audio_list;
2707 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
2708 static enum CodecID tgp_video_list[] = {
2709 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
2712 static enum CodecID tgp_audio_list[] = {
2713 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2718 *video_codec_list = tgp_video_list;
2719 *audio_codec_list = tgp_audio_list;
2720 } else if (!strcmp (format_name, "mmf")) {
2721 static enum CodecID mmf_audio_list[] = {
2722 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
2724 *video_codec_list = NULL;
2725 *audio_codec_list = mmf_audio_list;
2726 } else if (!strcmp (format_name, "amr")) {
2727 static enum CodecID amr_audio_list[] = {
2728 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2731 *video_codec_list = NULL;
2732 *audio_codec_list = amr_audio_list;
2733 } else if (!strcmp (format_name, "gif")) {
2734 static enum CodecID gif_image_list[] = {
2735 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
2737 *video_codec_list = gif_image_list;
2738 *audio_codec_list = NULL;
2739 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
2740 (plugin->video_codec != CODEC_ID_NONE)) {
2741 tmp_vlist[0] = plugin->video_codec;
2742 tmp_alist[0] = plugin->audio_codec;
2744 *video_codec_list = tmp_vlist;
2745 *audio_codec_list = tmp_alist;
2747 GST_LOG ("Format %s not found", format_name);
2754 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
2755 * are omitted, that can be queried by the user itself,
2756 * we're not eating the GstCaps or anything
2757 * A pointer to an allocated context is also needed for
2758 * optional extra info
2762 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
2764 enum CodecID id = CODEC_ID_NONE;
2765 const gchar *mimetype;
2766 const GstStructure *structure;
2767 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
2769 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
2770 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
2771 structure = gst_caps_get_structure (caps, 0);
2773 mimetype = gst_structure_get_name (structure);
2775 if (!strcmp (mimetype, "video/x-raw-rgb") ||
2776 !strcmp (mimetype, "video/x-raw-yuv")) {
2777 id = CODEC_ID_RAWVIDEO;
2779 } else if (!strcmp (mimetype, "audio/x-raw-int")) {
2780 gint depth, width, endianness;
2781 gboolean signedness;
2783 if (gst_structure_get_int (structure, "endianness", &endianness) &&
2784 gst_structure_get_boolean (structure, "signed", &signedness) &&
2785 gst_structure_get_int (structure, "width", &width) &&
2786 gst_structure_get_int (structure, "depth", &depth) && depth == width) {
2790 id = CODEC_ID_PCM_S8;
2792 id = CODEC_ID_PCM_U8;
2796 switch (endianness) {
2799 id = CODEC_ID_PCM_S16BE;
2801 id = CODEC_ID_PCM_U16BE;
2804 case G_LITTLE_ENDIAN:
2806 id = CODEC_ID_PCM_S16LE;
2808 id = CODEC_ID_PCM_U16LE;
2814 if (id != CODEC_ID_NONE)
2817 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
2818 id = CODEC_ID_PCM_MULAW;
2820 } else if (!strcmp (mimetype, "audio/x-alaw")) {
2821 id = CODEC_ID_PCM_ALAW;
2823 } else if (!strcmp (mimetype, "video/x-dv")) {
2826 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
2828 id = CODEC_ID_DVVIDEO;
2831 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
2832 id = CODEC_ID_DVAUDIO;
2834 } else if (!strcmp (mimetype, "video/x-h263")) {
2835 const gchar *h263version =
2836 gst_structure_get_string (structure, "h263version");
2837 if (h263version && !strcmp (h263version, "h263p"))
2838 id = CODEC_ID_H263P;
2842 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
2843 id = CODEC_ID_H263I;
2845 } else if (!strcmp (mimetype, "video/x-h261")) {
2848 } else if (!strcmp (mimetype, "video/mpeg")) {
2852 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
2853 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
2855 switch (mpegversion) {
2857 id = CODEC_ID_MPEG1VIDEO;
2860 id = CODEC_ID_MPEG2VIDEO;
2863 id = CODEC_ID_MPEG4;
2867 if (id != CODEC_ID_NONE)
2869 } else if (!strcmp (mimetype, "image/jpeg")) {
2870 id = CODEC_ID_MJPEG; /* A... B... */
2872 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
2873 id = CODEC_ID_MJPEGB;
2875 } else if (!strcmp (mimetype, "video/x-wmv")) {
2876 gint wmvversion = 0;
2878 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
2879 switch (wmvversion) {
2890 /* WMV3 unless the fourcc exists and says otherwise */
2893 if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
2894 if ((fourcc == GST_MAKE_FOURCC ('W', 'V', 'C', '1')) ||
2895 (fourcc == GST_MAKE_FOURCC ('W', 'M', 'V', 'A'))) {
2903 if (id != CODEC_ID_NONE)
2905 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
2906 id = CODEC_ID_VORBIS;
2908 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
2911 } else if (!strcmp (mimetype, "audio/mpeg")) {
2913 gint mpegversion = 0;
2915 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
2916 switch (mpegversion) {
2917 case 2: /* ffmpeg uses faad for both... */
2922 if (gst_structure_get_int (structure, "layer", &layer)) {
2937 if (id != CODEC_ID_NONE)
2939 } else if (!strcmp (mimetype, "audio/x-musepack")) {
2940 gint streamversion = -1;
2942 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
2943 if (streamversion == 7)
2944 id = CODEC_ID_MUSEPACK7;
2946 id = CODEC_ID_MUSEPACK7;
2948 } else if (!strcmp (mimetype, "audio/x-wma")) {
2949 gint wmaversion = 0;
2951 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
2952 switch (wmaversion) {
2954 id = CODEC_ID_WMAV1;
2957 id = CODEC_ID_WMAV2;
2960 id = CODEC_ID_WMAPRO;
2964 if (id != CODEC_ID_NONE)
2966 } else if (!strcmp (mimetype, "audio/x-wms")) {
2967 id = CODEC_ID_WMAVOICE;
2969 } else if (!strcmp (mimetype, "audio/x-ac3")) {
2972 } else if (!strcmp (mimetype, "audio/x-eac3")) {
2975 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
2976 !strcmp (mimetype, "audio/atrac3")) {
2977 id = CODEC_ID_ATRAC3;
2979 } else if (!strcmp (mimetype, "audio/x-dts")) {
2982 } else if (!strcmp (mimetype, "application/x-ape")) {
2985 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
2986 gint msmpegversion = 0;
2988 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
2989 switch (msmpegversion) {
2991 id = CODEC_ID_MSMPEG4V1;
2994 id = CODEC_ID_MSMPEG4V2;
2997 id = CODEC_ID_MSMPEG4V3;
3001 if (id != CODEC_ID_NONE)
3003 } else if (!strcmp (mimetype, "video/x-svq")) {
3004 gint svqversion = 0;
3006 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3007 switch (svqversion) {
3016 if (id != CODEC_ID_NONE)
3018 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3019 id = CODEC_ID_HUFFYUV;
3021 } else if (!strcmp (mimetype, "audio/x-mace")) {
3022 gint maceversion = 0;
3024 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3025 switch (maceversion) {
3027 id = CODEC_ID_MACE3;
3030 id = CODEC_ID_MACE6;
3034 if (id != CODEC_ID_NONE)
3036 } else if (!strcmp (mimetype, "video/x-theora")) {
3037 id = CODEC_ID_THEORA;
3039 } else if (!strcmp (mimetype, "video/x-vp3")) {
3042 } else if (!strcmp (mimetype, "video/x-vp5")) {
3045 } else if (!strcmp (mimetype, "video/x-vp6")) {
3048 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3051 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3054 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3055 id = CODEC_ID_FLASHSV;
3057 } else if (!strcmp (mimetype, "video/x-indeo")) {
3058 gint indeoversion = 0;
3060 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3061 switch (indeoversion) {
3063 id = CODEC_ID_INDEO5;
3066 id = CODEC_ID_INDEO3;
3069 id = CODEC_ID_INDEO2;
3072 if (id != CODEC_ID_NONE)
3075 } else if (!strcmp (mimetype, "video/x-divx")) {
3076 gint divxversion = 0;
3078 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3079 switch (divxversion) {
3081 id = CODEC_ID_MSMPEG4V3;
3085 id = CODEC_ID_MPEG4;
3089 if (id != CODEC_ID_NONE)
3091 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3092 id = CODEC_ID_MPEG4;
3094 } else if (!strcmp (mimetype, "video/x-xvid")) {
3095 id = CODEC_ID_MPEG4;
3097 } else if (!strcmp (mimetype, "video/x-ffv")) {
3098 gint ffvversion = 0;
3100 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3105 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3106 const gchar *layout;
3108 layout = gst_structure_get_string (structure, "layout");
3109 if (layout == NULL) {
3111 } else if (!strcmp (layout, "quicktime")) {
3112 id = CODEC_ID_ADPCM_IMA_QT;
3113 } else if (!strcmp (layout, "microsoft")) {
3114 id = CODEC_ID_ADPCM_MS;
3115 } else if (!strcmp (layout, "dvi")) {
3116 id = CODEC_ID_ADPCM_IMA_WAV;
3117 } else if (!strcmp (layout, "4xm")) {
3118 id = CODEC_ID_ADPCM_4XM;
3119 } else if (!strcmp (layout, "smjpeg")) {
3120 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3121 } else if (!strcmp (layout, "dk3")) {
3122 id = CODEC_ID_ADPCM_IMA_DK3;
3123 } else if (!strcmp (layout, "dk4")) {
3124 id = CODEC_ID_ADPCM_IMA_DK4;
3125 } else if (!strcmp (layout, "westwood")) {
3126 id = CODEC_ID_ADPCM_IMA_WS;
3127 } else if (!strcmp (layout, "iss")) {
3128 id = CODEC_ID_ADPCM_IMA_ISS;
3129 } else if (!strcmp (layout, "xa")) {
3130 id = CODEC_ID_ADPCM_XA;
3131 } else if (!strcmp (layout, "adx")) {
3132 id = CODEC_ID_ADPCM_ADX;
3133 } else if (!strcmp (layout, "ea")) {
3134 id = CODEC_ID_ADPCM_EA;
3135 } else if (!strcmp (layout, "g726")) {
3136 id = CODEC_ID_ADPCM_G726;
3137 } else if (!strcmp (layout, "g721")) {
3138 id = CODEC_ID_ADPCM_G726;
3139 } else if (!strcmp (layout, "ct")) {
3140 id = CODEC_ID_ADPCM_CT;
3141 } else if (!strcmp (layout, "swf")) {
3142 id = CODEC_ID_ADPCM_SWF;
3143 } else if (!strcmp (layout, "yamaha")) {
3144 id = CODEC_ID_ADPCM_YAMAHA;
3145 } else if (!strcmp (layout, "sbpro2")) {
3146 id = CODEC_ID_ADPCM_SBPRO_2;
3147 } else if (!strcmp (layout, "sbpro3")) {
3148 id = CODEC_ID_ADPCM_SBPRO_3;
3149 } else if (!strcmp (layout, "sbpro4")) {
3150 id = CODEC_ID_ADPCM_SBPRO_4;
3152 if (id != CODEC_ID_NONE)
3154 } else if (!strcmp (mimetype, "video/x-4xm")) {
3157 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3158 const gchar *layout;
3160 layout = gst_structure_get_string (structure, "layout");
3163 } else if (!strcmp (layout, "roq")) {
3164 id = CODEC_ID_ROQ_DPCM;
3165 } else if (!strcmp (layout, "interplay")) {
3166 id = CODEC_ID_INTERPLAY_DPCM;
3167 } else if (!strcmp (layout, "xan")) {
3168 id = CODEC_ID_XAN_DPCM;
3169 } else if (!strcmp (layout, "sol")) {
3170 id = CODEC_ID_SOL_DPCM;
3172 if (id != CODEC_ID_NONE)
3174 } else if (!strcmp (mimetype, "audio/x-flac")) {
3177 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3178 id = CODEC_ID_SHORTEN;
3180 } else if (!strcmp (mimetype, "audio/x-alac")) {
3183 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3184 id = CODEC_ID_CINEPAK;
3186 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3189 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3190 switch (rmversion) {
3205 if (id != CODEC_ID_NONE)
3207 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3210 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3213 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3214 switch (raversion) {
3216 id = CODEC_ID_RA_144;
3219 id = CODEC_ID_RA_288;
3226 if (id != CODEC_ID_NONE)
3228 } else if (!strcmp (mimetype, "video/x-rle")) {
3229 const gchar *layout;
3231 if ((layout = gst_structure_get_string (structure, "layout"))) {
3232 if (!strcmp (layout, "microsoft")) {
3233 id = CODEC_ID_MSRLE;
3237 } else if (!strcmp (mimetype, "video/x-xan")) {
3240 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3241 switch (wcversion) {
3243 id = CODEC_ID_XAN_WC3;
3247 id = CODEC_ID_XAN_WC4;
3254 } else if (!strcmp (mimetype, "audio/AMR")) {
3256 id = CODEC_ID_AMR_NB;
3257 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3258 id = CODEC_ID_AMR_WB;
3260 } else if (!strcmp (mimetype, "audio/qcelp")) {
3261 id = CODEC_ID_QCELP;
3263 } else if (!strcmp (mimetype, "video/x-h264")) {
3266 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3267 gint flvversion = 0;
3269 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3270 switch (flvversion) {
3280 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3281 id = CODEC_ID_NELLYMOSER;
3283 } else if (!strncmp (mimetype, "audio/x-gst_ff-", 15)) {
3287 if (strlen (mimetype) <= 30 &&
3288 sscanf (mimetype, "audio/x-gst_ff-%s", ext) == 1) {
3289 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3290 (codec = avcodec_find_encoder_by_name (ext))) {
3295 } else if (!strncmp (mimetype, "video/x-gst_ff-", 15)) {
3299 if (strlen (mimetype) <= 30 &&
3300 sscanf (mimetype, "video/x-gst_ff-%s", ext) == 1) {
3301 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3302 (codec = avcodec_find_encoder_by_name (ext))) {
3309 if (context != NULL) {
3310 if (video == TRUE) {
3311 context->codec_type = CODEC_TYPE_VIDEO;
3312 } else if (audio == TRUE) {
3313 context->codec_type = CODEC_TYPE_AUDIO;
3315 context->codec_type = CODEC_TYPE_UNKNOWN;
3317 context->codec_id = id;
3318 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3321 if (id != CODEC_ID_NONE) {
3322 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3324 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);