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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include <libavcodec/avcodec.h>
30 #include <libavutil/channel_layout.h>
33 #include "gstavcodecmap.h"
35 #include <gst/video/video.h>
36 #include <gst/audio/audio.h>
37 #include <gst/pbutils/codec-utils.h>
39 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
43 GstAudioChannelPosition gst;
44 } _ff_to_gst_layout[] = {
46 AV_CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
47 AV_CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
48 AV_CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
49 AV_CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
50 AV_CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
51 AV_CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
52 AV_CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
53 AV_CH_FRONT_RIGHT_OF_CENTER,
54 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
55 AV_CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
56 AV_CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
57 AV_CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
58 AV_CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
59 AV_CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
60 AV_CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
61 AV_CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
62 AV_CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
63 AV_CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
64 AV_CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}, {
65 AV_CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
66 AV_CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
70 gst_ffmpeg_channel_positions_to_layout (GstAudioChannelPosition * pos,
75 gint channels_found = 0;
80 for (i = 0; i < channels; i++) {
81 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
82 if (_ff_to_gst_layout[j].gst == pos[i]) {
83 ret |= _ff_to_gst_layout[i].ff;
90 if (channels_found != channels)
96 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
97 GstAudioChannelPosition * pos)
100 gboolean none_layout = FALSE;
102 if (channel_layout == 0) {
103 nchannels = channels;
108 for (i = 0; i < 64; i++) {
109 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
114 if (nchannels != channels) {
115 GST_ERROR ("Number of channels is different (%u != %u)", channels,
117 nchannels = channels;
121 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
122 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
123 pos[j++] = _ff_to_gst_layout[i].gst;
125 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
130 if (j != nchannels) {
132 ("Unknown channels in channel layout - assuming NONE layout");
139 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
140 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
141 " - assuming NONE layout", channel_layout);
146 if (nchannels == 1) {
147 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
148 } else if (nchannels == 2) {
149 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
150 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
154 for (i = 0; i < nchannels; i++)
155 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
162 /* this macro makes a caps width fixed or unfixed width/height
163 * properties depending on whether we've got a context.
165 * See below for why we use this.
167 * We should actually do this stuff at the end, like in riff-media.c,
168 * but I'm too lazy today. Maybe later.
171 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
172 enum CodecID codec_id, gboolean encode, const char *mimetype,
173 const char *fieldname, ...)
175 GstCaps *caps = NULL;
179 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
181 /* fixed, non probing context */
182 if (context != NULL && context->width != -1) {
185 caps = gst_caps_new_simple (mimetype,
186 "width", G_TYPE_INT, context->width,
187 "height", G_TYPE_INT, context->height, NULL);
189 num = context->time_base.den / context->ticks_per_frame;
190 denom = context->time_base.num;
193 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
196 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
197 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
201 GST_LOG ("setting framerate: %d/%d", num, denom);
202 gst_caps_set_simple (caps,
203 "framerate", GST_TYPE_FRACTION, num, denom, 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));
287 if (codec && codec->supported_framerates
288 && codec->supported_framerates[0].num != 0
289 && codec->supported_framerates[0].den != 0) {
292 const AVRational *rates = codec->supported_framerates;
294 if (rates[1].num == 0 && rates[1].den == 0) {
296 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
297 rates[0].num, rates[0].den, NULL);
299 g_value_init (&va, GST_TYPE_LIST);
300 g_value_init (&v, GST_TYPE_FRACTION);
302 while (rates->num != 0 && rates->den != 0) {
303 gst_value_set_fraction (&v, rates->num, rates->den);
304 gst_value_list_append_value (&va, &v);
308 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
309 gst_caps_set_value (caps, "framerate", &va);
320 /* no fixed caps or special restrictions applied;
321 * default unfixed setting */
323 GST_DEBUG ("Creating default caps");
324 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
327 va_start (var_args, fieldname);
328 gst_caps_set_simple_valist (caps, fieldname, var_args);
335 get_nbits_set (guint64 n)
340 for (i = 0; i < 64; i++) {
341 if ((n & (G_GUINT64_CONSTANT (1) << i)))
348 /* same for audio - now with channels/sample rate
351 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
352 enum CodecID codec_id, gboolean encode, const char *mimetype,
353 const char *fieldname, ...)
355 GstCaps *caps = NULL;
359 /* fixed, non-probing context */
360 if (context != NULL && context->channels != -1) {
361 GstAudioChannelPosition pos[64];
363 caps = gst_caps_new_simple (mimetype,
364 "rate", G_TYPE_INT, context->sample_rate,
365 "channels", G_TYPE_INT, context->channels, NULL);
367 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
368 context->channels, pos)) {
371 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
373 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
378 gint maxchannels = 2;
379 const gint *rates = NULL;
382 /* so we must be after restricted caps in this case */
385 case CODEC_ID_AAC_LATM:
391 const static gint l_rates[] =
392 { 48000, 44100, 32000, 24000, 22050, 16000 };
393 n_rates = G_N_ELEMENTS (l_rates);
400 const static gint l_rates[] = { 48000, 44100, 32000 };
402 n_rates = G_N_ELEMENTS (l_rates);
406 case CODEC_ID_ADPCM_G722:
408 const static gint l_rates[] = { 16000 };
409 n_rates = G_N_ELEMENTS (l_rates);
414 case CODEC_ID_ADPCM_G726:
416 const static gint l_rates[] = { 8000 };
417 n_rates = G_N_ELEMENTS (l_rates);
422 case CODEC_ID_ADPCM_SWF:
424 const static gint l_rates[] = { 11025, 22050, 44100 };
425 n_rates = G_N_ELEMENTS (l_rates);
429 case CODEC_ID_ROQ_DPCM:
431 const static gint l_rates[] = { 22050 };
432 n_rates = G_N_ELEMENTS (l_rates);
436 case CODEC_ID_AMR_NB:
438 const static gint l_rates[] = { 8000 };
440 n_rates = G_N_ELEMENTS (l_rates);
444 case CODEC_ID_AMR_WB:
446 const static gint l_rates[] = { 16000 };
448 n_rates = G_N_ELEMENTS (l_rates);
456 /* regardless of encode/decode, open up channels if applicable */
457 /* Until decoders/encoders expose the maximum number of channels
458 * they support, we whitelist them here. */
460 case CODEC_ID_WMAPRO:
461 case CODEC_ID_TRUEHD:
468 if (codec && codec->channel_layouts) {
469 const uint64_t *layouts = codec->channel_layouts;
470 GstAudioChannelPosition pos[64];
472 caps = gst_caps_new_empty ();
474 gint nbits_set = get_nbits_set (*layouts);
476 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
479 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
482 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
484 "channels", G_TYPE_INT, nbits_set, NULL);
486 gst_caps_append (caps, tmp);
492 if (maxchannels == 1)
493 caps = gst_caps_new_simple (mimetype,
494 "channels", G_TYPE_INT, maxchannels, NULL);
496 caps = gst_caps_new_simple (mimetype,
497 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
501 GValue list = { 0, };
503 g_value_init (&list, GST_TYPE_LIST);
504 for (i = 0; i < n_rates; i++) {
507 g_value_init (&v, G_TYPE_INT);
508 g_value_set_int (&v, rates[i]);
509 gst_value_list_append_value (&list, &v);
512 gst_caps_set_value (caps, "rate", &list);
513 g_value_unset (&list);
514 } else if (codec && codec->supported_samplerates
515 && codec->supported_samplerates[0]) {
519 if (!codec->supported_samplerates[1]) {
520 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
521 codec->supported_samplerates[0], NULL);
523 const int *rates = codec->supported_samplerates;
525 g_value_init (&va, GST_TYPE_LIST);
526 g_value_init (&v, G_TYPE_INT);
529 g_value_set_int (&v, *rates);
530 gst_value_list_append_value (&va, &v);
533 gst_caps_set_value (caps, "rate", &va);
538 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
541 caps = gst_caps_new_empty_simple (mimetype);
544 va_start (var_args, fieldname);
545 gst_caps_set_simple_valist (caps, fieldname, var_args);
551 /* Convert a FFMPEG codec ID and optional AVCodecContext
552 * to a GstCaps. If the context is ommitted, no fixed values
553 * for video/audio size will be included in the GstCaps
555 * CodecID is primarily meant for compressed data GstCaps!
557 * encode is a special parameter. gstffmpegdec will say
558 * FALSE, gstffmpegenc will say TRUE. The output caps
559 * depends on this, in such a way that it will be very
560 * specific, defined, fixed and correct caps for encoders,
561 * yet very wide, "forgiving" caps for decoders. Example
562 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
563 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
568 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
569 AVCodecContext * context, gboolean encode)
571 GstCaps *caps = NULL;
572 gboolean buildcaps = FALSE;
574 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
577 case CODEC_ID_MPEG1VIDEO:
579 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
580 "mpegversion", G_TYPE_INT, 1,
581 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
584 case CODEC_ID_MPEG2VIDEO:
588 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
589 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
592 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
593 * the MPEG video stream headers, so may be omitted from caps. */
594 caps = gst_caps_new_simple ("video/mpeg",
595 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
596 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
600 case CODEC_ID_MPEG2VIDEO_XVMC:
601 /* this is a special ID - don't need it in GStreamer, I think */
607 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
608 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
609 G_TYPE_STRING, "h263", NULL);
611 /* don't pass codec_id, we can decode other variants with the H263
612 * decoder that don't have specific size requirements
615 gst_ff_vid_caps_new (context, NULL, CODEC_ID_NONE, encode,
616 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
622 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
623 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
625 if (encode && context) {
627 gst_caps_set_simple (caps,
628 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
629 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
630 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
631 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
638 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
639 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
644 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
670 /* FIXME: context->sub_id must be filled in during decoding */
672 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
673 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
674 "rmversion", G_TYPE_INT, version, NULL);
676 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
677 if (context->extradata_size >= 8) {
678 gst_caps_set_simple (caps,
679 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
688 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
689 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
694 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
695 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
702 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
703 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
705 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
706 * in the MPEG audio header, so may be omitted from caps. */
707 caps = gst_caps_new_simple ("audio/mpeg",
708 "mpegversion", G_TYPE_INT, 1,
709 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
713 case CODEC_ID_MUSEPACK7:
715 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
716 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
720 case CODEC_ID_MUSEPACK8:
722 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
723 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
730 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
737 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
741 case CODEC_ID_TRUEHD:
743 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
744 "audio/x-true-hd", NULL);
747 case CODEC_ID_ATRAC1:
749 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
750 "audio/x-vnd.sony.atrac1", NULL);
753 case CODEC_ID_ATRAC3:
755 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
756 "audio/x-vnd.sony.atrac3", NULL);
761 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
767 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
768 "audio/x-ffmpeg-parsed-ape", NULL);
770 gst_caps_set_simple (caps,
771 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
777 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
783 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
787 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
788 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
789 * sp5x is, but it's apparently something JPEG... We don't separate
790 * between those in GStreamer. Should we (at least between MJPEG,
791 * MJPEG-B and sp5x decoding...)? */
795 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
801 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
805 case CODEC_ID_MJPEGB:
807 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
808 "video/x-mjpeg-b", NULL);
812 if (encode && context != NULL) {
813 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
814 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
815 switch (context->codec_tag) {
816 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
818 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
819 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
821 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
825 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
826 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
827 "mpegversion", G_TYPE_INT, 4, NULL);
831 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
833 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
834 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
837 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
838 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
840 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
841 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
843 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
844 encode, "video/x-xvid", NULL));
845 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
846 encode, "video/x-3ivx", NULL));
851 case CODEC_ID_RAWVIDEO:
853 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
856 case CODEC_ID_MSMPEG4V1:
857 case CODEC_ID_MSMPEG4V2:
858 case CODEC_ID_MSMPEG4V3:
860 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
862 /* encode-FIXME: bitrate */
864 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
865 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
866 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
867 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
868 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
876 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
879 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
880 "wmvversion", G_TYPE_INT, version, NULL);
886 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
887 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
892 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
893 "svqversion", G_TYPE_INT, 1, NULL);
898 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
899 "svqversion", G_TYPE_INT, 3, NULL);
902 case CODEC_ID_DVAUDIO:
904 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
908 case CODEC_ID_DVVIDEO:
910 if (encode && context) {
913 switch (context->pix_fmt) {
914 case PIX_FMT_YUYV422:
917 case PIX_FMT_YUV420P:
920 case PIX_FMT_YUVA420P:
923 case PIX_FMT_YUV411P:
926 case PIX_FMT_YUV422P:
929 case PIX_FMT_YUV410P:
934 ("Couldnt' find format for pixfmt %d, defaulting to I420",
940 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
941 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
945 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
946 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
954 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
958 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
959 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
960 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
964 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
965 "wmaversion", G_TYPE_INT, version, "block_align",
966 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
971 case CODEC_ID_WMAPRO:
974 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
975 "wmaversion", G_TYPE_INT, 3, NULL);
979 case CODEC_ID_WMAVOICE:
982 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
990 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
993 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
994 "maceversion", G_TYPE_INT, version, NULL);
998 case CODEC_ID_HUFFYUV:
1000 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1001 "video/x-huffyuv", NULL);
1003 gst_caps_set_simple (caps,
1004 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1010 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1011 "video/x-compressed-yuv", NULL);
1016 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1017 "alignment", G_TYPE_STRING, "au", NULL);
1020 case CODEC_ID_INDEO5:
1022 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1023 "indeoversion", G_TYPE_INT, 5, NULL);
1026 case CODEC_ID_INDEO4:
1028 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1029 "indeoversion", G_TYPE_INT, 4, NULL);
1032 case CODEC_ID_INDEO3:
1034 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1035 "indeoversion", G_TYPE_INT, 3, NULL);
1038 case CODEC_ID_INDEO2:
1040 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1041 "indeoversion", G_TYPE_INT, 2, NULL);
1044 case CODEC_ID_FLASHSV:
1046 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1047 "video/x-flash-screen", NULL);
1052 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1058 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1064 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1070 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1071 "video/x-vp6-flash", NULL);
1076 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1077 "video/x-vp6-alpha", NULL);
1082 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1086 case CODEC_ID_THEORA:
1088 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1089 "video/x-theora", NULL);
1095 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1099 GValue arr = { 0, };
1100 GValue item = { 0, };
1102 g_value_init (&arr, GST_TYPE_LIST);
1103 g_value_init (&item, G_TYPE_INT);
1104 g_value_set_int (&item, 2);
1105 gst_value_list_append_value (&arr, &item);
1106 g_value_set_int (&item, 4);
1107 gst_value_list_append_value (&arr, &item);
1108 g_value_unset (&item);
1110 gst_caps_set_value (caps, "mpegversion", &arr);
1111 g_value_unset (&arr);
1113 g_value_init (&arr, GST_TYPE_LIST);
1114 g_value_init (&item, G_TYPE_STRING);
1115 g_value_set_string (&item, "raw");
1116 gst_value_list_append_value (&arr, &item);
1117 g_value_set_string (&item, "adts");
1118 gst_value_list_append_value (&arr, &item);
1119 g_value_set_string (&item, "adif");
1120 gst_value_list_append_value (&arr, &item);
1121 g_value_unset (&item);
1123 gst_caps_set_value (caps, "stream-format", &arr);
1124 g_value_unset (&arr);
1126 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1127 "stream-format", G_TYPE_STRING, "raw",
1128 "base-profile", G_TYPE_STRING, "lc", NULL);
1130 if (context && context->extradata_size > 0)
1131 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1132 context->extradata, context->extradata_size);
1137 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1138 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1139 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1145 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1146 "asusversion", G_TYPE_INT, 1, NULL);
1150 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1151 "asusversion", G_TYPE_INT, 2, NULL);
1156 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1157 "ffvversion", G_TYPE_INT, 1, NULL);
1162 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1166 case CODEC_ID_XAN_WC3:
1167 case CODEC_ID_XAN_WC4:
1169 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1170 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1175 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1176 "video/x-cirrus-logic-accupak", NULL);
1179 case CODEC_ID_FRAPS:
1181 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1187 case CODEC_ID_INTERPLAY_VIDEO:
1193 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1194 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1199 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1200 "video/x-apple-video", NULL);
1203 case CODEC_ID_CINEPAK:
1205 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1206 "video/x-cinepak", NULL);
1209 /* WS_VQA belogns here (order) */
1211 case CODEC_ID_MSRLE:
1213 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1214 "layout", G_TYPE_STRING, "microsoft", NULL);
1216 gst_caps_set_simple (caps,
1217 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1219 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1223 case CODEC_ID_QTRLE:
1225 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1226 "layout", G_TYPE_STRING, "quicktime", NULL);
1228 gst_caps_set_simple (caps,
1229 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1231 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1235 case CODEC_ID_MSVIDEO1:
1237 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1238 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1243 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1244 "wmvversion", G_TYPE_INT, 3, NULL);
1248 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1249 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1253 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1259 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1265 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1269 case CODEC_ID_TRUEMOTION1:
1271 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1272 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1274 case CODEC_ID_TRUEMOTION2:
1276 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1277 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1282 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1283 "video/x-ultimotion", NULL);
1288 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1289 "video/x-camtasia", NULL);
1291 gst_caps_set_simple (caps,
1292 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1294 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1300 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1306 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1312 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1318 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1324 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1330 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1336 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1337 "image/x-portable-anymap", NULL);
1342 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1343 "image/x-portable-graymap", NULL);
1348 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1354 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1358 case CODEC_ID_TARGA:
1360 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1366 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1370 case CODEC_ID_SUNRAST:
1372 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1373 "image/x-sun-raster", NULL);
1378 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1382 case CODEC_ID_QDRAW:
1384 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1388 case CODEC_ID_DNXHD:
1390 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1394 case CODEC_ID_PRORES:
1396 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1397 "video/x-prores", NULL);
1400 case CODEC_ID_MIMIC:
1402 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1408 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1412 case CODEC_ID_TRUESPEECH:
1414 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1415 "audio/x-truespeech", NULL);
1418 case CODEC_ID_QCELP:
1420 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1426 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1432 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1438 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1444 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1448 case CODEC_ID_LAGARITH:
1450 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1451 "video/x-lagarith", NULL);
1456 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1457 "video/x-camstudio", NULL);
1459 gst_caps_set_simple (caps,
1460 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1462 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1466 case CODEC_ID_WS_VQA:
1467 case CODEC_ID_IDCIN:
1470 case CODEC_ID_VMDVIDEO:
1471 case CODEC_ID_VMDAUDIO:
1475 case CODEC_ID_PGMYUV:
1476 case CODEC_ID_FFVHUFF:
1478 case CODEC_ID_MP3ADU:
1479 case CODEC_ID_MP3ON4:
1480 case CODEC_ID_WESTWOOD_SND1:
1481 case CODEC_ID_MMVIDEO:
1487 /* weird quasi-codecs for the demuxers only */
1488 case CODEC_ID_PCM_S16LE:
1489 case CODEC_ID_PCM_S16BE:
1490 case CODEC_ID_PCM_U16LE:
1491 case CODEC_ID_PCM_U16BE:
1492 case CODEC_ID_PCM_S8:
1493 case CODEC_ID_PCM_U8:
1495 GstAudioFormat format;
1498 case CODEC_ID_PCM_S16LE:
1499 format = GST_AUDIO_FORMAT_S16LE;
1501 case CODEC_ID_PCM_S16BE:
1502 format = GST_AUDIO_FORMAT_S16BE;
1504 case CODEC_ID_PCM_U16LE:
1505 format = GST_AUDIO_FORMAT_U16LE;
1507 case CODEC_ID_PCM_U16BE:
1508 format = GST_AUDIO_FORMAT_U16BE;
1510 case CODEC_ID_PCM_S8:
1511 format = GST_AUDIO_FORMAT_S8;
1513 case CODEC_ID_PCM_U8:
1514 format = GST_AUDIO_FORMAT_U8;
1517 g_assert (0); /* don't worry, we never get here */
1522 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1523 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1524 "layout", G_TYPE_STRING, "interleaved", NULL);
1528 case CODEC_ID_PCM_MULAW:
1530 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1534 case CODEC_ID_PCM_ALAW:
1536 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1540 case CODEC_ID_ADPCM_G722:
1542 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1545 gst_caps_set_simple (caps,
1546 "block_align", G_TYPE_INT, context->block_align,
1547 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1550 case CODEC_ID_ADPCM_G726:
1552 /* the G726 decoder can also handle G721 */
1554 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1555 "layout", G_TYPE_STRING, "g726", NULL);
1557 gst_caps_set_simple (caps,
1558 "block_align", G_TYPE_INT, context->block_align,
1559 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1562 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1563 "layout", G_TYPE_STRING, "g721",
1564 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1568 case CODEC_ID_ADPCM_IMA_QT:
1569 case CODEC_ID_ADPCM_IMA_WAV:
1570 case CODEC_ID_ADPCM_IMA_DK3:
1571 case CODEC_ID_ADPCM_IMA_DK4:
1572 case CODEC_ID_ADPCM_IMA_WS:
1573 case CODEC_ID_ADPCM_IMA_SMJPEG:
1574 case CODEC_ID_ADPCM_IMA_AMV:
1575 case CODEC_ID_ADPCM_IMA_ISS:
1576 case CODEC_ID_ADPCM_IMA_EA_EACS:
1577 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1578 case CODEC_ID_ADPCM_MS:
1579 case CODEC_ID_ADPCM_4XM:
1580 case CODEC_ID_ADPCM_XA:
1581 case CODEC_ID_ADPCM_ADX:
1582 case CODEC_ID_ADPCM_EA:
1583 case CODEC_ID_ADPCM_CT:
1584 case CODEC_ID_ADPCM_SWF:
1585 case CODEC_ID_ADPCM_YAMAHA:
1586 case CODEC_ID_ADPCM_SBPRO_2:
1587 case CODEC_ID_ADPCM_SBPRO_3:
1588 case CODEC_ID_ADPCM_SBPRO_4:
1589 case CODEC_ID_ADPCM_EA_R1:
1590 case CODEC_ID_ADPCM_EA_R2:
1591 case CODEC_ID_ADPCM_EA_R3:
1592 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1593 case CODEC_ID_ADPCM_EA_XAS:
1594 case CODEC_ID_ADPCM_THP:
1596 const gchar *layout = NULL;
1599 case CODEC_ID_ADPCM_IMA_QT:
1600 layout = "quicktime";
1602 case CODEC_ID_ADPCM_IMA_WAV:
1605 case CODEC_ID_ADPCM_IMA_DK3:
1608 case CODEC_ID_ADPCM_IMA_DK4:
1611 case CODEC_ID_ADPCM_IMA_WS:
1612 layout = "westwood";
1614 case CODEC_ID_ADPCM_IMA_SMJPEG:
1617 case CODEC_ID_ADPCM_IMA_AMV:
1620 case CODEC_ID_ADPCM_IMA_ISS:
1623 case CODEC_ID_ADPCM_IMA_EA_EACS:
1626 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1629 case CODEC_ID_ADPCM_MS:
1630 layout = "microsoft";
1632 case CODEC_ID_ADPCM_4XM:
1635 case CODEC_ID_ADPCM_XA:
1638 case CODEC_ID_ADPCM_ADX:
1641 case CODEC_ID_ADPCM_EA:
1644 case CODEC_ID_ADPCM_CT:
1647 case CODEC_ID_ADPCM_SWF:
1650 case CODEC_ID_ADPCM_YAMAHA:
1653 case CODEC_ID_ADPCM_SBPRO_2:
1656 case CODEC_ID_ADPCM_SBPRO_3:
1659 case CODEC_ID_ADPCM_SBPRO_4:
1662 case CODEC_ID_ADPCM_EA_R1:
1665 case CODEC_ID_ADPCM_EA_R2:
1668 case CODEC_ID_ADPCM_EA_R3:
1671 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1672 layout = "ea-maxis-xa";
1674 case CODEC_ID_ADPCM_EA_XAS:
1677 case CODEC_ID_ADPCM_THP:
1681 g_assert (0); /* don't worry, we never get here */
1685 /* FIXME: someone please check whether we need additional properties
1686 * in this caps definition. */
1688 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1689 "layout", G_TYPE_STRING, layout, NULL);
1691 gst_caps_set_simple (caps,
1692 "block_align", G_TYPE_INT, context->block_align,
1693 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1697 case CODEC_ID_AMR_NB:
1699 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1703 case CODEC_ID_AMR_WB:
1705 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1711 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1715 case CODEC_ID_GSM_MS:
1717 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1721 case CODEC_ID_NELLYMOSER:
1723 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1724 "audio/x-nellymoser", NULL);
1730 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1733 gst_caps_set_simple (caps,
1734 "leaf_size", G_TYPE_INT, context->block_align,
1735 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1740 case CODEC_ID_RA_144:
1741 case CODEC_ID_RA_288:
1747 case CODEC_ID_RA_144:
1750 case CODEC_ID_RA_288:
1760 /* FIXME: properties? */
1762 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1763 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1765 gst_caps_set_simple (caps,
1766 "leaf_size", G_TYPE_INT, context->block_align,
1767 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1772 case CODEC_ID_ROQ_DPCM:
1773 case CODEC_ID_INTERPLAY_DPCM:
1774 case CODEC_ID_XAN_DPCM:
1775 case CODEC_ID_SOL_DPCM:
1777 const gchar *layout = NULL;
1780 case CODEC_ID_ROQ_DPCM:
1783 case CODEC_ID_INTERPLAY_DPCM:
1784 layout = "interplay";
1786 case CODEC_ID_XAN_DPCM:
1789 case CODEC_ID_SOL_DPCM:
1793 g_assert (0); /* don't worry, we never get here */
1797 /* FIXME: someone please check whether we need additional properties
1798 * in this caps definition. */
1800 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1801 "layout", G_TYPE_STRING, layout, NULL);
1803 gst_caps_set_simple (caps,
1804 "block_align", G_TYPE_INT, context->block_align,
1805 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1809 case CODEC_ID_SHORTEN:
1810 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1815 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1818 gst_caps_set_simple (caps,
1819 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1824 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1825 * encoder case, we want to add things like samplerate, channels... */
1827 caps = gst_caps_new_empty_simple ("audio/x-flac");
1831 case CODEC_ID_DVD_SUBTITLE:
1832 case CODEC_ID_DVB_SUBTITLE:
1836 caps = gst_caps_new_empty_simple ("image/bmp");
1840 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1843 gst_caps_set_simple (caps,
1844 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1847 case CODEC_ID_TWINVQ:
1849 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1850 "audio/x-twin-vq", NULL);
1853 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1860 if ((codec = avcodec_find_decoder (codec_id)) ||
1861 (codec = avcodec_find_encoder (codec_id))) {
1864 GST_LOG ("Could not create stream format caps for %s", codec->name);
1866 switch (codec->type) {
1867 case AVMEDIA_TYPE_VIDEO:
1868 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1870 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
1873 case AVMEDIA_TYPE_AUDIO:
1874 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1876 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
1878 gst_caps_set_simple (caps,
1879 "block_align", G_TYPE_INT, context->block_align,
1880 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1891 /* set private data */
1892 if (context && context->extradata_size > 0) {
1893 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1895 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1896 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1897 gst_buffer_unref (data);
1900 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1903 GST_LOG ("No caps found for codec_id=%d", codec_id);
1909 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1910 * to a GstCaps. If the context is ommitted, no fixed values
1911 * for video/audio size will be included in the GstCaps
1913 * See below for usefullness
1917 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1918 enum CodecID codec_id)
1920 GstCaps *caps = NULL;
1921 GstVideoFormat format;
1923 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
1925 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1926 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
1927 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1931 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1933 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1940 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
1942 switch (sample_fmt) {
1943 case AV_SAMPLE_FMT_U8:
1944 case AV_SAMPLE_FMT_U8P:
1945 return GST_AUDIO_FORMAT_U8;
1947 case AV_SAMPLE_FMT_S16:
1948 case AV_SAMPLE_FMT_S16P:
1949 return GST_AUDIO_FORMAT_S16;
1951 case AV_SAMPLE_FMT_S32:
1952 case AV_SAMPLE_FMT_S32P:
1953 return GST_AUDIO_FORMAT_S32;
1955 case AV_SAMPLE_FMT_FLT:
1956 case AV_SAMPLE_FMT_FLTP:
1957 return GST_AUDIO_FORMAT_F32;
1959 case AV_SAMPLE_FMT_DBL:
1960 case AV_SAMPLE_FMT_DBLP:
1961 return GST_AUDIO_FORMAT_F64;
1965 return GST_AUDIO_FORMAT_UNKNOWN;
1970 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1971 * to a GstCaps. If the context is ommitted, no fixed values
1972 * for video/audio size will be included in the GstCaps
1974 * See below for usefullness
1978 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
1979 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
1981 GstCaps *caps = NULL;
1982 GstAudioFormat format;
1984 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
1986 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1987 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
1988 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1989 "layout", G_TYPE_STRING, "interleaved", NULL);
1990 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1992 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1999 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
2000 const enum AVSampleFormat *fmts)
2004 GstAudioFormat format;
2006 if (!fmts || fmts[0] == -1) {
2009 g_value_init (&va, GST_TYPE_LIST);
2010 g_value_init (&v, G_TYPE_STRING);
2011 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
2012 format = gst_ffmpeg_smpfmt_to_audioformat (i);
2013 if (format == GST_AUDIO_FORMAT_UNKNOWN)
2015 g_value_set_string (&v, gst_audio_format_to_string (format));
2016 gst_value_list_append_value (&va, &v);
2018 gst_caps_set_value (caps, "format", &va);
2020 g_value_unset (&va);
2024 g_value_init (&va, GST_TYPE_LIST);
2025 g_value_init (&v, G_TYPE_STRING);
2026 while (*fmts != -1) {
2027 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
2028 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2029 g_value_set_string (&v, gst_audio_format_to_string (format));
2030 gst_value_list_append_value (&va, &v);
2034 if (gst_value_list_get_size (&va) == 1) {
2035 /* The single value is still in v */
2036 gst_caps_set_value (caps, "format", &v);
2037 } else if (gst_value_list_get_size (&va) > 1) {
2038 gst_caps_set_value (caps, "format", &va);
2041 g_value_unset (&va);
2045 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2046 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2048 GstCaps *caps = NULL;
2050 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2051 context, codec_id, encode, codec);
2053 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2054 codec->sample_fmts, codec->supported_samplerates);
2057 /* Specific codec context */
2059 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2062 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2063 "layout", G_TYPE_STRING, "interleaved", NULL);
2064 gst_ffmpeg_audio_set_sample_fmts (caps, codec ? codec->sample_fmts : NULL);
2071 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
2075 GstVideoFormat format;
2077 if (!fmts || fmts[0] == -1) {
2080 g_value_init (&va, GST_TYPE_LIST);
2081 g_value_init (&v, G_TYPE_STRING);
2082 for (i = 0; i <= PIX_FMT_NB; i++) {
2083 format = gst_ffmpeg_pixfmt_to_videoformat (i);
2084 if (format == GST_VIDEO_FORMAT_UNKNOWN)
2086 g_value_set_string (&v, gst_video_format_to_string (format));
2087 gst_value_list_append_value (&va, &v);
2089 gst_caps_set_value (caps, "format", &va);
2091 g_value_unset (&va);
2095 /* Only a single format */
2096 g_value_init (&va, GST_TYPE_LIST);
2097 g_value_init (&v, G_TYPE_STRING);
2098 while (*fmts != -1) {
2099 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
2100 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2101 g_value_set_string (&v, gst_video_format_to_string (format));
2102 gst_value_list_append_value (&va, &v);
2106 if (gst_value_list_get_size (&va) == 1) {
2107 /* The single value is still in v */
2108 gst_caps_set_value (caps, "format", &v);
2109 } else if (gst_value_list_get_size (&va) > 1) {
2110 gst_caps_set_value (caps, "format", &va);
2113 g_value_unset (&va);
2117 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2118 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2122 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2123 context, codec_id, encode, codec);
2126 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2129 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2131 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2136 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2137 * and other audio properties in a AVCodecContext.
2139 * For usefullness, see below
2143 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2144 AVCodecContext * context, gboolean raw)
2146 GstStructure *structure;
2148 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2150 g_return_if_fail (gst_caps_get_size (caps) == 1);
2152 structure = gst_caps_get_structure (caps, 0);
2154 gst_structure_get_int (structure, "channels", &context->channels);
2155 gst_structure_get_int (structure, "rate", &context->sample_rate);
2156 gst_structure_get_int (structure, "block_align", &context->block_align);
2157 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2162 if (gst_structure_has_name (structure, "audio/x-raw")) {
2163 if ((fmt = gst_structure_get_string (structure, "format"))) {
2164 format = gst_audio_format_from_string (fmt);
2169 case GST_AUDIO_FORMAT_F32:
2170 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2172 case GST_AUDIO_FORMAT_F64:
2173 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2175 case GST_AUDIO_FORMAT_S32:
2176 context->sample_fmt = AV_SAMPLE_FMT_S32;
2178 case GST_AUDIO_FORMAT_S16:
2179 context->sample_fmt = AV_SAMPLE_FMT_S16;
2186 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2187 * and other video properties in a AVCodecContext.
2189 * For usefullness, see below
2193 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2194 AVCodecContext * context, gboolean raw)
2196 GstStructure *structure;
2198 const GValue *par = NULL;
2200 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2202 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2203 g_return_if_fail (gst_caps_get_size (caps) == 1);
2204 structure = gst_caps_get_structure (caps, 0);
2206 gst_structure_get_int (structure, "width", &context->width);
2207 gst_structure_get_int (structure, "height", &context->height);
2208 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2210 fps = gst_structure_get_value (structure, "framerate");
2211 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2213 /* somehow these seem mixed up.. */
2214 context->time_base.den = gst_value_get_fraction_numerator (fps);
2215 context->time_base.num = gst_value_get_fraction_denominator (fps);
2216 context->ticks_per_frame = 1;
2218 GST_DEBUG ("setting framerate %d/%d = %lf",
2219 context->time_base.den, context->time_base.num,
2220 1. * context->time_base.den / context->time_base.num);
2223 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2224 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2226 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2227 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2229 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2230 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2231 1. * context->sample_aspect_ratio.den /
2232 context->sample_aspect_ratio.num);
2238 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2240 if (gst_structure_has_name (structure, "video/x-raw")) {
2241 if ((fmt = gst_structure_get_string (structure, "format"))) {
2242 format = gst_video_format_from_string (fmt);
2247 case GST_VIDEO_FORMAT_YUY2:
2248 context->pix_fmt = PIX_FMT_YUYV422;
2250 case GST_VIDEO_FORMAT_I420:
2251 context->pix_fmt = PIX_FMT_YUV420P;
2253 case GST_VIDEO_FORMAT_A420:
2254 context->pix_fmt = PIX_FMT_YUVA420P;
2256 case GST_VIDEO_FORMAT_Y41B:
2257 context->pix_fmt = PIX_FMT_YUV411P;
2259 case GST_VIDEO_FORMAT_Y42B:
2260 context->pix_fmt = PIX_FMT_YUV422P;
2262 case GST_VIDEO_FORMAT_YUV9:
2263 context->pix_fmt = PIX_FMT_YUV410P;
2265 case GST_VIDEO_FORMAT_Y444:
2266 context->pix_fmt = PIX_FMT_YUV444P;
2268 case GST_VIDEO_FORMAT_GRAY8:
2269 context->pix_fmt = PIX_FMT_GRAY8;
2271 case GST_VIDEO_FORMAT_xRGB:
2272 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2273 context->pix_fmt = PIX_FMT_RGB32;
2276 case GST_VIDEO_FORMAT_BGRx:
2277 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2278 context->pix_fmt = PIX_FMT_RGB32;
2281 case GST_VIDEO_FORMAT_RGB:
2282 context->pix_fmt = PIX_FMT_RGB24;
2284 case GST_VIDEO_FORMAT_BGR:
2285 context->pix_fmt = PIX_FMT_BGR24;
2287 case GST_VIDEO_FORMAT_RGB16:
2288 context->pix_fmt = PIX_FMT_RGB565;
2290 case GST_VIDEO_FORMAT_RGB15:
2291 context->pix_fmt = PIX_FMT_RGB555;
2293 case GST_VIDEO_FORMAT_RGB8P:
2294 context->pix_fmt = PIX_FMT_PAL8;
2303 GstVideoFormat format;
2304 enum PixelFormat pixfmt;
2307 /* FIXME : FILLME */
2308 static const PixToFmt pixtofmttable[] = {
2309 /* GST_VIDEO_FORMAT_I420, */
2310 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2311 /* Note : this should use a different chroma placement */
2312 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2314 /* GST_VIDEO_FORMAT_YV12, */
2315 /* GST_VIDEO_FORMAT_YUY2, */
2316 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2317 /* GST_VIDEO_FORMAT_UYVY, */
2318 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2319 /* GST_VIDEO_FORMAT_AYUV, */
2320 /* GST_VIDEO_FORMAT_RGBx, */
2321 /* GST_VIDEO_FORMAT_BGRx, */
2322 /* GST_VIDEO_FORMAT_xRGB, */
2323 /* GST_VIDEO_FORMAT_xBGR, */
2324 /* GST_VIDEO_FORMAT_RGBA, */
2325 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2326 /* GST_VIDEO_FORMAT_BGRA, */
2327 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2328 /* GST_VIDEO_FORMAT_ARGB, */
2329 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2330 /* GST_VIDEO_FORMAT_ABGR, */
2331 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2332 /* GST_VIDEO_FORMAT_RGB, */
2333 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2334 /* GST_VIDEO_FORMAT_BGR, */
2335 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2336 /* GST_VIDEO_FORMAT_Y41B, */
2337 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2338 /* GST_VIDEO_FORMAT_Y42B, */
2339 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2340 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2341 /* GST_VIDEO_FORMAT_YVYU, */
2342 /* GST_VIDEO_FORMAT_Y444, */
2343 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2344 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2345 /* GST_VIDEO_FORMAT_v210, */
2346 /* GST_VIDEO_FORMAT_v216, */
2347 /* GST_VIDEO_FORMAT_NV12, */
2348 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2349 /* GST_VIDEO_FORMAT_NV21, */
2350 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2351 /* GST_VIDEO_FORMAT_GRAY8, */
2352 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2353 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2354 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2355 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2356 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2357 /* GST_VIDEO_FORMAT_v308, */
2358 /* GST_VIDEO_FORMAT_Y800, */
2359 /* GST_VIDEO_FORMAT_Y16, */
2360 /* GST_VIDEO_FORMAT_RGB16, */
2361 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2362 /* GST_VIDEO_FORMAT_BGR16, */
2363 /* GST_VIDEO_FORMAT_RGB15, */
2364 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2365 /* GST_VIDEO_FORMAT_BGR15, */
2366 /* GST_VIDEO_FORMAT_UYVP, */
2367 /* GST_VIDEO_FORMAT_A420, */
2368 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2369 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2370 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2371 /* GST_VIDEO_FORMAT_YUV9, */
2372 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2373 /* GST_VIDEO_FORMAT_YVU9, */
2374 /* GST_VIDEO_FORMAT_IYU1, */
2375 /* GST_VIDEO_FORMAT_ARGB64, */
2376 /* GST_VIDEO_FORMAT_AYUV64, */
2377 /* GST_VIDEO_FORMAT_r210, */
2378 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2379 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2380 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2381 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2382 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2383 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2384 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2385 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2386 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2390 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2394 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2395 if (pixtofmttable[i].pixfmt == pixfmt)
2396 return pixtofmttable[i].format;
2398 GST_WARNING ("Unknown pixel format %d", pixfmt);
2399 return GST_VIDEO_FORMAT_UNKNOWN;
2403 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2407 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2408 if (pixtofmttable[i].format == format)
2409 return pixtofmttable[i].pixfmt;
2410 return PIX_FMT_NONE;
2414 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2418 context->width = GST_VIDEO_INFO_WIDTH (info);
2419 context->height = GST_VIDEO_INFO_HEIGHT (info);
2420 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2421 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2422 context->bits_per_coded_sample = bpp;
2424 context->ticks_per_frame = 1;
2425 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2426 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2428 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2429 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2432 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2436 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2438 const AVCodec *codec;
2439 const enum AVSampleFormat *smpl_fmts;
2440 enum AVSampleFormat smpl_fmt = -1;
2442 context->channels = info->channels;
2443 context->sample_rate = info->rate;
2444 context->channel_layout =
2445 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2447 codec = context->codec;
2449 smpl_fmts = codec->sample_fmts;
2451 switch (info->finfo->format) {
2452 case GST_AUDIO_FORMAT_F32:
2454 while (*smpl_fmts != -1) {
2455 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2456 smpl_fmt = *smpl_fmts;
2458 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2459 smpl_fmt = *smpl_fmts;
2465 smpl_fmt = AV_SAMPLE_FMT_FLT;
2468 case GST_AUDIO_FORMAT_F64:
2470 while (*smpl_fmts != -1) {
2471 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2472 smpl_fmt = *smpl_fmts;
2474 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2475 smpl_fmt = *smpl_fmts;
2481 smpl_fmt = AV_SAMPLE_FMT_DBL;
2484 case GST_AUDIO_FORMAT_S32:
2486 while (*smpl_fmts != -1) {
2487 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2488 smpl_fmt = *smpl_fmts;
2490 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2491 smpl_fmt = *smpl_fmts;
2497 smpl_fmt = AV_SAMPLE_FMT_S32;
2500 case GST_AUDIO_FORMAT_S16:
2502 while (*smpl_fmts != -1) {
2503 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2504 smpl_fmt = *smpl_fmts;
2506 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2507 smpl_fmt = *smpl_fmts;
2513 smpl_fmt = AV_SAMPLE_FMT_S16;
2516 case GST_AUDIO_FORMAT_U8:
2518 while (*smpl_fmts != -1) {
2519 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2520 smpl_fmt = *smpl_fmts;
2522 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2523 smpl_fmt = *smpl_fmts;
2529 smpl_fmt = AV_SAMPLE_FMT_U8;
2536 g_assert (smpl_fmt != -1);
2538 context->sample_fmt = smpl_fmt;
2541 /* Convert a GstCaps and a FFMPEG codec Type to a
2542 * AVCodecContext. If the context is ommitted, no fixed values
2543 * for video/audio size will be included in the context
2545 * AVMediaType is primarily meant for uncompressed data GstCaps!
2549 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2550 const GstCaps * caps, AVCodecContext * context)
2552 if (context == NULL)
2556 case AVMEDIA_TYPE_VIDEO:
2557 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2560 case AVMEDIA_TYPE_AUDIO:
2561 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2572 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2576 guint8 *end = src + size;
2579 while (srcp < end) {
2580 if (count == 2 && *srcp <= 0x03) {
2581 GST_DEBUG ("added escape code");
2590 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2593 *destsize = dstp - dst;
2596 /* copy the config, escaping NAL units as we iterate them, if something fails we
2597 * copy everything and hope for the best. */
2599 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2604 guint nalsize, esize;
2614 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2616 GST_DEBUG ("num SPS %d", cnt);
2618 memcpy (dstp, srcp, 6);
2622 for (i = 0; i < cnt; i++) {
2623 GST_DEBUG ("copy SPS %d", i);
2624 nalsize = (srcp[0] << 8) | srcp[1];
2625 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2626 dstp[0] = esize >> 8;
2627 dstp[1] = esize & 0xff;
2629 srcp += nalsize + 2;
2632 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2634 GST_DEBUG ("num PPS %d", cnt);
2636 for (i = 0; i < cnt; i++) {
2637 GST_DEBUG ("copy PPS %d", i);
2638 nalsize = (srcp[0] << 8) | srcp[1];
2639 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2640 dstp[0] = esize >> 8;
2641 dstp[1] = esize & 0xff;
2643 srcp += nalsize + 2;
2645 *destsize = dstp - dst;
2651 GST_DEBUG ("something unexpected, doing full copy");
2652 memcpy (dst, src, size);
2660 * caps_with_codecid () transforms a GstCaps for a known codec
2661 * ID into a filled-in context.
2662 * codec_data from caps will override possible extradata already in the context
2666 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2667 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2670 const GValue *value;
2673 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2674 codec_id, codec_type, caps, context);
2676 if (!context || !gst_caps_get_size (caps))
2679 str = gst_caps_get_structure (caps, 0);
2681 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2682 if ((value = gst_structure_get_value (str, "codec_data"))) {
2685 buf = gst_value_get_buffer (value);
2686 gst_buffer_map (buf, &map, GST_MAP_READ);
2688 /* free the old one if it is there */
2689 if (context->extradata)
2690 av_free (context->extradata);
2693 if (codec_id == CODEC_ID_H264) {
2696 GST_DEBUG ("copy, escaping codec_data %d", size);
2697 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2698 * reason for this but let's just escape it for now. Start by allocating
2699 * enough space, x2 is more than enough.
2701 * FIXME, we disabled escaping because some file already contain escaped
2702 * codec_data and then we escape twice and fail. It's better to leave it
2703 * as is, as that is what most players do. */
2704 context->extradata =
2705 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2706 FF_INPUT_BUFFER_PADDING_SIZE));
2707 copy_config (context->extradata, data, size, &extrasize);
2708 GST_DEBUG ("escaped size: %d", extrasize);
2709 context->extradata_size = extrasize;
2713 /* allocate with enough padding */
2714 GST_DEBUG ("copy codec_data");
2715 context->extradata =
2716 av_mallocz (GST_ROUND_UP_16 (map.size +
2717 FF_INPUT_BUFFER_PADDING_SIZE));
2718 memcpy (context->extradata, map.data, map.size);
2719 context->extradata_size = map.size;
2722 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2723 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2724 context->extradata[0] = (guint8) map.size;
2727 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2729 gst_buffer_unmap (buf, &map);
2730 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2731 codec_id != CODEC_ID_FLAC) {
2732 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2733 * extradata anyway which makes then segfault. */
2734 context->extradata =
2735 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2736 context->extradata_size = 0;
2737 GST_DEBUG ("no codec data");
2741 case CODEC_ID_MPEG4:
2743 const gchar *mime = gst_structure_get_name (str);
2745 if (!strcmp (mime, "video/x-divx"))
2746 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2747 else if (!strcmp (mime, "video/x-xvid"))
2748 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2749 else if (!strcmp (mime, "video/x-3ivx"))
2750 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2751 else if (!strcmp (mime, "video/mpeg"))
2752 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2757 /* FIXME: this is a workaround for older gst-plugins releases
2758 * (<= 0.8.9). This should be removed at some point, because
2759 * it causes wrong decoded frame order. */
2760 if (!context->extradata) {
2761 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2764 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2765 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2766 gst_structure_get_int (str, "low_delay", &low_delay) ||
2767 gst_structure_get_int (str, "unknown_svq3_flag",
2768 &unknown_svq3_flag)) {
2769 context->extradata = (guint8 *) av_mallocz (0x64);
2770 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2774 flags |= unknown_svq3_flag;
2776 flags |= halfpel_flag;
2778 flags |= thirdpel_flag;
2781 flags = GUINT16_FROM_LE (flags);
2783 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2784 context->extradata_size = 0x64;
2789 case CODEC_ID_MSRLE:
2790 case CODEC_ID_QTRLE:
2797 if (gst_structure_get_int (str, "depth", &depth)) {
2798 context->bits_per_coded_sample = depth;
2800 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2813 if (gst_structure_get_int (str, "format", &format))
2814 context->sub_id = format;
2819 case CODEC_ID_RA_288:
2820 case CODEC_ID_RA_144:
2826 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2827 context->block_align = leaf_size;
2828 if (gst_structure_get_int (str, "bitrate", &bitrate))
2829 context->bit_rate = bitrate;
2832 gst_structure_get_int (str, "samplesize",
2833 &context->bits_per_coded_sample);
2836 case CODEC_ID_DVVIDEO:
2838 const gchar *format;
2840 if ((format = gst_structure_get_string (str, "format"))) {
2842 if (g_str_equal (format, "YUY2"))
2843 context->pix_fmt = PIX_FMT_YUYV422;
2844 else if (g_str_equal (format, "I420"))
2845 context->pix_fmt = PIX_FMT_YUV420P;
2846 else if (g_str_equal (format, "A420"))
2847 context->pix_fmt = PIX_FMT_YUVA420P;
2848 else if (g_str_equal (format, "Y41B"))
2849 context->pix_fmt = PIX_FMT_YUV411P;
2850 else if (g_str_equal (format, "Y42B"))
2851 context->pix_fmt = PIX_FMT_YUV422P;
2852 else if (g_str_equal (format, "YUV9"))
2853 context->pix_fmt = PIX_FMT_YUV410P;
2855 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2859 GST_WARNING ("No specified format");
2862 case CODEC_ID_H263P:
2866 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2867 context->flags |= CODEC_FLAG_4MV;
2869 context->flags &= ~CODEC_FLAG_4MV;
2870 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2871 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2872 context->flags |= CODEC_FLAG_AC_PRED;
2874 context->flags &= ~CODEC_FLAG_AC_PRED;
2875 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2876 context->flags |= CODEC_FLAG_LOOP_FILTER;
2878 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2881 case CODEC_ID_ADPCM_G726:
2883 const gchar *layout;
2885 if ((layout = gst_structure_get_string (str, "layout"))) {
2886 if (!strcmp (layout, "g721")) {
2887 context->sample_rate = 8000;
2888 context->channels = 1;
2889 context->bit_rate = 32000;
2898 if (!gst_caps_is_fixed (caps))
2901 /* common properties (width, height, fps) */
2902 switch (codec_type) {
2903 case AVMEDIA_TYPE_VIDEO:
2904 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2906 case AVMEDIA_TYPE_AUDIO:
2907 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2913 /* fixup of default settings */
2915 case CODEC_ID_QCELP:
2916 /* QCELP is always mono, no matter what the caps say */
2917 context->channels = 1;
2919 case CODEC_ID_ADPCM_G726:
2920 if (context->sample_rate && context->bit_rate)
2921 context->bits_per_coded_sample =
2922 context->bit_rate / context->sample_rate;
2929 /* _formatid_to_caps () is meant for muxers/demuxers, it
2930 * transforms a name (ffmpeg way of ID'ing these, why don't
2931 * they have unique numerical IDs?) to the corresponding
2932 * caps belonging to that mux-format
2934 * Note: we don't need any additional info because the caps
2935 * isn't supposed to contain any useful info besides the
2940 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2942 GstCaps *caps = NULL;
2944 if (!strcmp (format_name, "mpeg")) {
2945 caps = gst_caps_new_simple ("video/mpeg",
2946 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2947 } else if (!strcmp (format_name, "mpegts")) {
2948 caps = gst_caps_new_simple ("video/mpegts",
2949 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2950 } else if (!strcmp (format_name, "rm")) {
2951 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2952 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2953 } else if (!strcmp (format_name, "asf")) {
2954 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2955 } else if (!strcmp (format_name, "avi")) {
2956 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2957 } else if (!strcmp (format_name, "wav")) {
2958 caps = gst_caps_new_empty_simple ("audio/x-wav");
2959 } else if (!strcmp (format_name, "ape")) {
2960 caps = gst_caps_new_empty_simple ("application/x-ape");
2961 } else if (!strcmp (format_name, "swf")) {
2962 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2963 } else if (!strcmp (format_name, "au")) {
2964 caps = gst_caps_new_empty_simple ("audio/x-au");
2965 } else if (!strcmp (format_name, "dv")) {
2966 caps = gst_caps_new_simple ("video/x-dv",
2967 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2968 } else if (!strcmp (format_name, "4xm")) {
2969 caps = gst_caps_new_empty_simple ("video/x-4xm");
2970 } else if (!strcmp (format_name, "matroska")) {
2971 caps = gst_caps_new_empty_simple ("video/x-matroska");
2972 } else if (!strcmp (format_name, "mp3")) {
2973 caps = gst_caps_new_empty_simple ("application/x-id3");
2974 } else if (!strcmp (format_name, "flic")) {
2975 caps = gst_caps_new_empty_simple ("video/x-fli");
2976 } else if (!strcmp (format_name, "flv")) {
2977 caps = gst_caps_new_empty_simple ("video/x-flv");
2978 } else if (!strcmp (format_name, "tta")) {
2979 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
2980 } else if (!strcmp (format_name, "aiff")) {
2981 caps = gst_caps_new_empty_simple ("audio/x-aiff");
2982 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2984 gst_caps_from_string
2985 ("application/x-3gp; video/quicktime; audio/x-m4a");
2986 } else if (!strcmp (format_name, "mov")) {
2987 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2988 } else if (!strcmp (format_name, "mp4")) {
2989 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2990 } else if (!strcmp (format_name, "3gp")) {
2991 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2992 } else if (!strcmp (format_name, "3g2")) {
2993 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2994 } else if (!strcmp (format_name, "psp")) {
2995 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2996 } else if (!strcmp (format_name, "ipod")) {
2997 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2998 } else if (!strcmp (format_name, "aac")) {
2999 caps = gst_caps_new_simple ("audio/mpeg",
3000 "mpegversion", G_TYPE_INT, 4, NULL);
3001 } else if (!strcmp (format_name, "gif")) {
3002 caps = gst_caps_from_string ("image/gif");
3003 } else if (!strcmp (format_name, "ogg")) {
3004 caps = gst_caps_from_string ("application/ogg");
3005 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3006 caps = gst_caps_from_string ("application/mxf");
3007 } else if (!strcmp (format_name, "gxf")) {
3008 caps = gst_caps_from_string ("application/gxf");
3009 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3010 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3011 "y4mversion", G_TYPE_INT, 2, NULL);
3012 } else if (!strcmp (format_name, "mpc")) {
3013 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3014 } else if (!strcmp (format_name, "vqf")) {
3015 caps = gst_caps_from_string ("audio/x-vqf");
3016 } else if (!strcmp (format_name, "nsv")) {
3017 caps = gst_caps_from_string ("video/x-nsv");
3018 } else if (!strcmp (format_name, "amr")) {
3019 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3020 } else if (!strcmp (format_name, "webm")) {
3021 caps = gst_caps_from_string ("video/webm");
3022 } else if (!strcmp (format_name, "voc")) {
3023 caps = gst_caps_from_string ("audio/x-voc");
3027 GST_LOG ("Could not create stream format caps for %s", format_name);
3028 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3029 caps = gst_caps_new_empty_simple (name);
3037 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3038 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3039 AVOutputFormat * plugin)
3041 static enum CodecID tmp_vlist[] = {
3045 static enum CodecID tmp_alist[] = {
3050 GST_LOG ("format_name : %s", format_name);
3052 if (!strcmp (format_name, "mp4")) {
3053 static enum CodecID mp4_video_list[] = {
3054 CODEC_ID_MPEG4, CODEC_ID_H264,
3058 static enum CodecID mp4_audio_list[] = {
3059 CODEC_ID_AAC, CODEC_ID_MP3,
3063 *video_codec_list = mp4_video_list;
3064 *audio_codec_list = mp4_audio_list;
3065 } else if (!strcmp (format_name, "mpeg")) {
3066 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
3067 CODEC_ID_MPEG2VIDEO,
3071 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
3077 *video_codec_list = mpeg_video_list;
3078 *audio_codec_list = mpeg_audio_list;
3079 } else if (!strcmp (format_name, "dvd")) {
3080 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
3083 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
3090 *video_codec_list = mpeg_video_list;
3091 *audio_codec_list = mpeg_audio_list;
3092 } else if (!strcmp (format_name, "mpegts")) {
3093 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
3094 CODEC_ID_MPEG2VIDEO,
3098 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
3106 *video_codec_list = mpegts_video_list;
3107 *audio_codec_list = mpegts_audio_list;
3108 } else if (!strcmp (format_name, "vob")) {
3109 static enum CodecID vob_video_list[] =
3110 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
3111 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
3112 CODEC_ID_DTS, CODEC_ID_NONE
3115 *video_codec_list = vob_video_list;
3116 *audio_codec_list = vob_audio_list;
3117 } else if (!strcmp (format_name, "flv")) {
3118 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
3119 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
3121 *video_codec_list = flv_video_list;
3122 *audio_codec_list = flv_audio_list;
3123 } else if (!strcmp (format_name, "asf")) {
3124 static enum CodecID asf_video_list[] =
3125 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
3126 static enum CodecID asf_audio_list[] =
3127 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
3129 *video_codec_list = asf_video_list;
3130 *audio_codec_list = asf_audio_list;
3131 } else if (!strcmp (format_name, "dv")) {
3132 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
3133 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
3135 *video_codec_list = dv_video_list;
3136 *audio_codec_list = dv_audio_list;
3137 } else if (!strcmp (format_name, "mov")) {
3138 static enum CodecID mov_video_list[] = {
3139 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
3140 CODEC_ID_H263, CODEC_ID_H263P,
3141 CODEC_ID_H264, CODEC_ID_DVVIDEO,
3145 static enum CodecID mov_audio_list[] = {
3146 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
3147 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
3148 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3149 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
3150 CODEC_ID_MP3, CODEC_ID_NONE
3153 *video_codec_list = mov_video_list;
3154 *audio_codec_list = mov_audio_list;
3155 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3156 static enum CodecID tgp_video_list[] = {
3157 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
3160 static enum CodecID tgp_audio_list[] = {
3161 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3166 *video_codec_list = tgp_video_list;
3167 *audio_codec_list = tgp_audio_list;
3168 } else if (!strcmp (format_name, "mmf")) {
3169 static enum CodecID mmf_audio_list[] = {
3170 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
3172 *video_codec_list = NULL;
3173 *audio_codec_list = mmf_audio_list;
3174 } else if (!strcmp (format_name, "amr")) {
3175 static enum CodecID amr_audio_list[] = {
3176 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3179 *video_codec_list = NULL;
3180 *audio_codec_list = amr_audio_list;
3181 } else if (!strcmp (format_name, "gif")) {
3182 static enum CodecID gif_image_list[] = {
3183 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
3185 *video_codec_list = gif_image_list;
3186 *audio_codec_list = NULL;
3187 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
3188 (plugin->video_codec != CODEC_ID_NONE)) {
3189 tmp_vlist[0] = plugin->video_codec;
3190 tmp_alist[0] = plugin->audio_codec;
3192 *video_codec_list = tmp_vlist;
3193 *audio_codec_list = tmp_alist;
3195 GST_LOG ("Format %s not found", format_name);
3202 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3203 * are omitted, that can be queried by the user itself,
3204 * we're not eating the GstCaps or anything
3205 * A pointer to an allocated context is also needed for
3206 * optional extra info
3210 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3212 enum CodecID id = CODEC_ID_NONE;
3213 const gchar *mimetype;
3214 const GstStructure *structure;
3215 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3217 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3218 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3219 structure = gst_caps_get_structure (caps, 0);
3221 mimetype = gst_structure_get_name (structure);
3223 if (!strcmp (mimetype, "video/x-raw")) {
3224 id = CODEC_ID_RAWVIDEO;
3226 } else if (!strcmp (mimetype, "audio/x-raw")) {
3229 if (gst_audio_info_from_caps (&info, caps)) {
3230 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3231 case GST_AUDIO_FORMAT_S8:
3232 id = CODEC_ID_PCM_S8;
3234 case GST_AUDIO_FORMAT_U8:
3235 id = CODEC_ID_PCM_U8;
3237 case GST_AUDIO_FORMAT_S16LE:
3238 id = CODEC_ID_PCM_S16LE;
3240 case GST_AUDIO_FORMAT_S16BE:
3241 id = CODEC_ID_PCM_S16BE;
3243 case GST_AUDIO_FORMAT_U16LE:
3244 id = CODEC_ID_PCM_U16LE;
3246 case GST_AUDIO_FORMAT_U16BE:
3247 id = CODEC_ID_PCM_U16BE;
3252 if (id != CODEC_ID_NONE)
3255 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3256 id = CODEC_ID_PCM_MULAW;
3258 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3259 id = CODEC_ID_PCM_ALAW;
3261 } else if (!strcmp (mimetype, "video/x-dv")) {
3264 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3266 id = CODEC_ID_DVVIDEO;
3269 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3270 id = CODEC_ID_DVAUDIO;
3272 } else if (!strcmp (mimetype, "video/x-h263")) {
3273 const gchar *h263version =
3274 gst_structure_get_string (structure, "h263version");
3275 if (h263version && !strcmp (h263version, "h263p"))
3276 id = CODEC_ID_H263P;
3280 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3281 id = CODEC_ID_H263I;
3283 } else if (!strcmp (mimetype, "video/x-h261")) {
3286 } else if (!strcmp (mimetype, "video/mpeg")) {
3290 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3291 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3293 switch (mpegversion) {
3295 id = CODEC_ID_MPEG1VIDEO;
3298 id = CODEC_ID_MPEG2VIDEO;
3301 id = CODEC_ID_MPEG4;
3305 if (id != CODEC_ID_NONE)
3307 } else if (!strcmp (mimetype, "image/jpeg")) {
3308 id = CODEC_ID_MJPEG; /* A... B... */
3310 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3311 id = CODEC_ID_MJPEGB;
3313 } else if (!strcmp (mimetype, "video/x-wmv")) {
3314 gint wmvversion = 0;
3316 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3317 switch (wmvversion) {
3326 const gchar *format;
3328 /* WMV3 unless the fourcc exists and says otherwise */
3331 if ((format = gst_structure_get_string (structure, "format")) &&
3332 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3339 if (id != CODEC_ID_NONE)
3341 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3342 id = CODEC_ID_VORBIS;
3344 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3347 } else if (!strcmp (mimetype, "audio/mpeg")) {
3349 gint mpegversion = 0;
3351 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3352 switch (mpegversion) {
3353 case 2: /* ffmpeg uses faad for both... */
3358 if (gst_structure_get_int (structure, "layer", &layer)) {
3373 if (id != CODEC_ID_NONE)
3375 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3376 gint streamversion = -1;
3378 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3379 if (streamversion == 7)
3380 id = CODEC_ID_MUSEPACK7;
3382 id = CODEC_ID_MUSEPACK7;
3384 } else if (!strcmp (mimetype, "audio/x-wma")) {
3385 gint wmaversion = 0;
3387 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3388 switch (wmaversion) {
3390 id = CODEC_ID_WMAV1;
3393 id = CODEC_ID_WMAV2;
3396 id = CODEC_ID_WMAPRO;
3400 if (id != CODEC_ID_NONE)
3402 } else if (!strcmp (mimetype, "audio/x-wms")) {
3403 id = CODEC_ID_WMAVOICE;
3405 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3408 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3411 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3412 !strcmp (mimetype, "audio/atrac3")) {
3413 id = CODEC_ID_ATRAC3;
3415 } else if (!strcmp (mimetype, "audio/x-dts")) {
3418 } else if (!strcmp (mimetype, "application/x-ape")) {
3421 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3422 gint msmpegversion = 0;
3424 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3425 switch (msmpegversion) {
3427 id = CODEC_ID_MSMPEG4V1;
3430 id = CODEC_ID_MSMPEG4V2;
3433 id = CODEC_ID_MSMPEG4V3;
3437 if (id != CODEC_ID_NONE)
3439 } else if (!strcmp (mimetype, "video/x-svq")) {
3440 gint svqversion = 0;
3442 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3443 switch (svqversion) {
3452 if (id != CODEC_ID_NONE)
3454 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3455 id = CODEC_ID_HUFFYUV;
3457 } else if (!strcmp (mimetype, "audio/x-mace")) {
3458 gint maceversion = 0;
3460 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3461 switch (maceversion) {
3463 id = CODEC_ID_MACE3;
3466 id = CODEC_ID_MACE6;
3470 if (id != CODEC_ID_NONE)
3472 } else if (!strcmp (mimetype, "video/x-theora")) {
3473 id = CODEC_ID_THEORA;
3475 } else if (!strcmp (mimetype, "video/x-vp3")) {
3478 } else if (!strcmp (mimetype, "video/x-vp5")) {
3481 } else if (!strcmp (mimetype, "video/x-vp6")) {
3484 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3487 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3490 } else if (!strcmp (mimetype, "video/x-vp8")) {
3493 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3494 id = CODEC_ID_FLASHSV;
3496 } else if (!strcmp (mimetype, "video/x-indeo")) {
3497 gint indeoversion = 0;
3499 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3500 switch (indeoversion) {
3502 id = CODEC_ID_INDEO5;
3505 id = CODEC_ID_INDEO4;
3508 id = CODEC_ID_INDEO3;
3511 id = CODEC_ID_INDEO2;
3514 if (id != CODEC_ID_NONE)
3517 } else if (!strcmp (mimetype, "video/x-divx")) {
3518 gint divxversion = 0;
3520 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3521 switch (divxversion) {
3523 id = CODEC_ID_MSMPEG4V3;
3527 id = CODEC_ID_MPEG4;
3531 if (id != CODEC_ID_NONE)
3533 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3534 id = CODEC_ID_MPEG4;
3536 } else if (!strcmp (mimetype, "video/x-xvid")) {
3537 id = CODEC_ID_MPEG4;
3539 } else if (!strcmp (mimetype, "video/x-ffv")) {
3540 gint ffvversion = 0;
3542 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3547 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3548 const gchar *layout;
3550 layout = gst_structure_get_string (structure, "layout");
3551 if (layout == NULL) {
3553 } else if (!strcmp (layout, "quicktime")) {
3554 id = CODEC_ID_ADPCM_IMA_QT;
3555 } else if (!strcmp (layout, "microsoft")) {
3556 id = CODEC_ID_ADPCM_MS;
3557 } else if (!strcmp (layout, "dvi")) {
3558 id = CODEC_ID_ADPCM_IMA_WAV;
3559 } else if (!strcmp (layout, "4xm")) {
3560 id = CODEC_ID_ADPCM_4XM;
3561 } else if (!strcmp (layout, "smjpeg")) {
3562 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3563 } else if (!strcmp (layout, "dk3")) {
3564 id = CODEC_ID_ADPCM_IMA_DK3;
3565 } else if (!strcmp (layout, "dk4")) {
3566 id = CODEC_ID_ADPCM_IMA_DK4;
3567 } else if (!strcmp (layout, "westwood")) {
3568 id = CODEC_ID_ADPCM_IMA_WS;
3569 } else if (!strcmp (layout, "iss")) {
3570 id = CODEC_ID_ADPCM_IMA_ISS;
3571 } else if (!strcmp (layout, "xa")) {
3572 id = CODEC_ID_ADPCM_XA;
3573 } else if (!strcmp (layout, "adx")) {
3574 id = CODEC_ID_ADPCM_ADX;
3575 } else if (!strcmp (layout, "ea")) {
3576 id = CODEC_ID_ADPCM_EA;
3577 } else if (!strcmp (layout, "g726")) {
3578 id = CODEC_ID_ADPCM_G726;
3579 } else if (!strcmp (layout, "g721")) {
3580 id = CODEC_ID_ADPCM_G726;
3581 } else if (!strcmp (layout, "ct")) {
3582 id = CODEC_ID_ADPCM_CT;
3583 } else if (!strcmp (layout, "swf")) {
3584 id = CODEC_ID_ADPCM_SWF;
3585 } else if (!strcmp (layout, "yamaha")) {
3586 id = CODEC_ID_ADPCM_YAMAHA;
3587 } else if (!strcmp (layout, "sbpro2")) {
3588 id = CODEC_ID_ADPCM_SBPRO_2;
3589 } else if (!strcmp (layout, "sbpro3")) {
3590 id = CODEC_ID_ADPCM_SBPRO_3;
3591 } else if (!strcmp (layout, "sbpro4")) {
3592 id = CODEC_ID_ADPCM_SBPRO_4;
3594 if (id != CODEC_ID_NONE)
3596 } else if (!strcmp (mimetype, "video/x-4xm")) {
3599 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3600 const gchar *layout;
3602 layout = gst_structure_get_string (structure, "layout");
3605 } else if (!strcmp (layout, "roq")) {
3606 id = CODEC_ID_ROQ_DPCM;
3607 } else if (!strcmp (layout, "interplay")) {
3608 id = CODEC_ID_INTERPLAY_DPCM;
3609 } else if (!strcmp (layout, "xan")) {
3610 id = CODEC_ID_XAN_DPCM;
3611 } else if (!strcmp (layout, "sol")) {
3612 id = CODEC_ID_SOL_DPCM;
3614 if (id != CODEC_ID_NONE)
3616 } else if (!strcmp (mimetype, "audio/x-flac")) {
3619 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3620 id = CODEC_ID_SHORTEN;
3622 } else if (!strcmp (mimetype, "audio/x-alac")) {
3625 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3626 id = CODEC_ID_CINEPAK;
3628 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3631 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3632 switch (rmversion) {
3647 if (id != CODEC_ID_NONE)
3649 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3652 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3655 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3656 switch (raversion) {
3658 id = CODEC_ID_RA_144;
3661 id = CODEC_ID_RA_288;
3668 if (id != CODEC_ID_NONE)
3670 } else if (!strcmp (mimetype, "video/x-rle")) {
3671 const gchar *layout;
3673 if ((layout = gst_structure_get_string (structure, "layout"))) {
3674 if (!strcmp (layout, "microsoft")) {
3675 id = CODEC_ID_MSRLE;
3679 } else if (!strcmp (mimetype, "video/x-xan")) {
3682 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3683 switch (wcversion) {
3685 id = CODEC_ID_XAN_WC3;
3689 id = CODEC_ID_XAN_WC4;
3696 } else if (!strcmp (mimetype, "audio/AMR")) {
3698 id = CODEC_ID_AMR_NB;
3699 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3700 id = CODEC_ID_AMR_WB;
3702 } else if (!strcmp (mimetype, "audio/qcelp")) {
3703 id = CODEC_ID_QCELP;
3705 } else if (!strcmp (mimetype, "video/x-h264")) {
3708 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3709 gint flvversion = 0;
3711 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3712 switch (flvversion) {
3722 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3723 id = CODEC_ID_NELLYMOSER;
3725 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3729 if (strlen (mimetype) <= 30 &&
3730 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3731 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3732 (codec = avcodec_find_encoder_by_name (ext))) {
3737 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3741 if (strlen (mimetype) <= 30 &&
3742 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3743 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3744 (codec = avcodec_find_encoder_by_name (ext))) {
3751 if (context != NULL) {
3752 if (video == TRUE) {
3753 context->codec_type = AVMEDIA_TYPE_VIDEO;
3754 } else if (audio == TRUE) {
3755 context->codec_type = AVMEDIA_TYPE_AUDIO;
3757 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3759 context->codec_id = id;
3760 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3763 if (id != CODEC_ID_NONE) {
3764 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3766 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);