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_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
857 case CODEC_ID_MSMPEG4V1:
858 case CODEC_ID_MSMPEG4V2:
859 case CODEC_ID_MSMPEG4V3:
861 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
863 /* encode-FIXME: bitrate */
865 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
866 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
867 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
868 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
869 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
877 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
880 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
881 "wmvversion", G_TYPE_INT, version, NULL);
887 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
888 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
893 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
894 "svqversion", G_TYPE_INT, 1, NULL);
899 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
900 "svqversion", G_TYPE_INT, 3, NULL);
903 case CODEC_ID_DVAUDIO:
905 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
909 case CODEC_ID_DVVIDEO:
911 if (encode && context) {
914 switch (context->pix_fmt) {
915 case PIX_FMT_YUYV422:
918 case PIX_FMT_YUV420P:
921 case PIX_FMT_YUVA420P:
924 case PIX_FMT_YUV411P:
927 case PIX_FMT_YUV422P:
930 case PIX_FMT_YUV410P:
935 ("Couldnt' find format for pixfmt %d, defaulting to I420",
941 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
942 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
946 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
947 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
955 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
959 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
960 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
961 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
965 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
966 "wmaversion", G_TYPE_INT, version, "block_align",
967 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
972 case CODEC_ID_WMAPRO:
975 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
976 "wmaversion", G_TYPE_INT, 3, NULL);
980 case CODEC_ID_WMAVOICE:
983 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
991 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
994 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
995 "maceversion", G_TYPE_INT, version, NULL);
999 case CODEC_ID_HUFFYUV:
1001 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1002 "video/x-huffyuv", NULL);
1004 gst_caps_set_simple (caps,
1005 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1011 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1012 "video/x-compressed-yuv", NULL);
1017 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1018 "alignment", G_TYPE_STRING, "au", NULL);
1021 case CODEC_ID_INDEO5:
1023 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1024 "indeoversion", G_TYPE_INT, 5, NULL);
1027 case CODEC_ID_INDEO4:
1029 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1030 "indeoversion", G_TYPE_INT, 4, NULL);
1033 case CODEC_ID_INDEO3:
1035 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1036 "indeoversion", G_TYPE_INT, 3, NULL);
1039 case CODEC_ID_INDEO2:
1041 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1042 "indeoversion", G_TYPE_INT, 2, NULL);
1045 case CODEC_ID_FLASHSV:
1047 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1048 "video/x-flash-screen", NULL);
1053 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1059 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1065 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1071 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1072 "video/x-vp6-flash", NULL);
1077 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1078 "video/x-vp6-alpha", NULL);
1083 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1087 case CODEC_ID_THEORA:
1089 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1090 "video/x-theora", NULL);
1096 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1100 GValue arr = { 0, };
1101 GValue item = { 0, };
1103 g_value_init (&arr, GST_TYPE_LIST);
1104 g_value_init (&item, G_TYPE_INT);
1105 g_value_set_int (&item, 2);
1106 gst_value_list_append_value (&arr, &item);
1107 g_value_set_int (&item, 4);
1108 gst_value_list_append_value (&arr, &item);
1109 g_value_unset (&item);
1111 gst_caps_set_value (caps, "mpegversion", &arr);
1112 g_value_unset (&arr);
1114 g_value_init (&arr, GST_TYPE_LIST);
1115 g_value_init (&item, G_TYPE_STRING);
1116 g_value_set_string (&item, "raw");
1117 gst_value_list_append_value (&arr, &item);
1118 g_value_set_string (&item, "adts");
1119 gst_value_list_append_value (&arr, &item);
1120 g_value_set_string (&item, "adif");
1121 gst_value_list_append_value (&arr, &item);
1122 g_value_unset (&item);
1124 gst_caps_set_value (caps, "stream-format", &arr);
1125 g_value_unset (&arr);
1127 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1128 "stream-format", G_TYPE_STRING, "raw",
1129 "base-profile", G_TYPE_STRING, "lc", NULL);
1131 if (context && context->extradata_size > 0)
1132 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1133 context->extradata, context->extradata_size);
1138 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1139 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1140 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1146 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1147 "asusversion", G_TYPE_INT, 1, NULL);
1151 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1152 "asusversion", G_TYPE_INT, 2, NULL);
1157 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1158 "ffvversion", G_TYPE_INT, 1, NULL);
1163 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1167 case CODEC_ID_XAN_WC3:
1168 case CODEC_ID_XAN_WC4:
1170 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1171 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1176 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1177 "video/x-cirrus-logic-accupak", NULL);
1180 case CODEC_ID_FRAPS:
1182 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1188 case CODEC_ID_INTERPLAY_VIDEO:
1194 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1195 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1200 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1201 "video/x-apple-video", NULL);
1204 case CODEC_ID_CINEPAK:
1206 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1207 "video/x-cinepak", NULL);
1210 /* WS_VQA belogns here (order) */
1212 case CODEC_ID_MSRLE:
1214 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1215 "layout", G_TYPE_STRING, "microsoft", NULL);
1217 gst_caps_set_simple (caps,
1218 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1220 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1224 case CODEC_ID_QTRLE:
1226 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1227 "layout", G_TYPE_STRING, "quicktime", NULL);
1229 gst_caps_set_simple (caps,
1230 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1232 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1236 case CODEC_ID_MSVIDEO1:
1238 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1239 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1244 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1245 "wmvversion", G_TYPE_INT, 3, NULL);
1249 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1250 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1254 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1260 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1266 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1270 case CODEC_ID_TRUEMOTION1:
1272 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1273 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1275 case CODEC_ID_TRUEMOTION2:
1277 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1278 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1283 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1284 "video/x-ultimotion", NULL);
1289 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1290 "video/x-camtasia", NULL);
1292 gst_caps_set_simple (caps,
1293 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1295 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1301 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1307 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1313 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1319 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1325 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1331 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1337 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1338 "image/x-portable-anymap", NULL);
1343 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1344 "image/x-portable-graymap", NULL);
1349 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1355 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1359 case CODEC_ID_TARGA:
1361 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1367 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1371 case CODEC_ID_SUNRAST:
1373 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1374 "image/x-sun-raster", NULL);
1379 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1383 case CODEC_ID_QDRAW:
1385 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1389 case CODEC_ID_DNXHD:
1391 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1395 case CODEC_ID_PRORES:
1397 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1398 "video/x-prores", NULL);
1401 case CODEC_ID_MIMIC:
1403 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1409 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1413 case CODEC_ID_TRUESPEECH:
1415 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1416 "audio/x-truespeech", NULL);
1419 case CODEC_ID_QCELP:
1421 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1427 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1433 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1439 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1445 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1449 case CODEC_ID_LAGARITH:
1451 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1452 "video/x-lagarith", NULL);
1457 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1458 "video/x-camstudio", NULL);
1460 gst_caps_set_simple (caps,
1461 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1463 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1467 case CODEC_ID_WS_VQA:
1468 case CODEC_ID_IDCIN:
1471 case CODEC_ID_VMDVIDEO:
1472 case CODEC_ID_VMDAUDIO:
1476 case CODEC_ID_PGMYUV:
1477 case CODEC_ID_FFVHUFF:
1479 case CODEC_ID_MP3ADU:
1480 case CODEC_ID_MP3ON4:
1481 case CODEC_ID_WESTWOOD_SND1:
1482 case CODEC_ID_MMVIDEO:
1488 /* weird quasi-codecs for the demuxers only */
1489 case CODEC_ID_PCM_S16LE:
1490 case CODEC_ID_PCM_S16BE:
1491 case CODEC_ID_PCM_U16LE:
1492 case CODEC_ID_PCM_U16BE:
1493 case CODEC_ID_PCM_S8:
1494 case CODEC_ID_PCM_U8:
1496 GstAudioFormat format;
1499 case CODEC_ID_PCM_S16LE:
1500 format = GST_AUDIO_FORMAT_S16LE;
1502 case CODEC_ID_PCM_S16BE:
1503 format = GST_AUDIO_FORMAT_S16BE;
1505 case CODEC_ID_PCM_U16LE:
1506 format = GST_AUDIO_FORMAT_U16LE;
1508 case CODEC_ID_PCM_U16BE:
1509 format = GST_AUDIO_FORMAT_U16BE;
1511 case CODEC_ID_PCM_S8:
1512 format = GST_AUDIO_FORMAT_S8;
1514 case CODEC_ID_PCM_U8:
1515 format = GST_AUDIO_FORMAT_U8;
1518 g_assert (0); /* don't worry, we never get here */
1523 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1524 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1525 "layout", G_TYPE_STRING, "interleaved", NULL);
1529 case CODEC_ID_PCM_MULAW:
1531 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1535 case CODEC_ID_PCM_ALAW:
1537 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1541 case CODEC_ID_ADPCM_G722:
1543 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1546 gst_caps_set_simple (caps,
1547 "block_align", G_TYPE_INT, context->block_align,
1548 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1551 case CODEC_ID_ADPCM_G726:
1553 /* the G726 decoder can also handle G721 */
1555 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1556 "layout", G_TYPE_STRING, "g726", NULL);
1558 gst_caps_set_simple (caps,
1559 "block_align", G_TYPE_INT, context->block_align,
1560 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1563 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1564 "layout", G_TYPE_STRING, "g721",
1565 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1569 case CODEC_ID_ADPCM_IMA_QT:
1570 case CODEC_ID_ADPCM_IMA_WAV:
1571 case CODEC_ID_ADPCM_IMA_DK3:
1572 case CODEC_ID_ADPCM_IMA_DK4:
1573 case CODEC_ID_ADPCM_IMA_WS:
1574 case CODEC_ID_ADPCM_IMA_SMJPEG:
1575 case CODEC_ID_ADPCM_IMA_AMV:
1576 case CODEC_ID_ADPCM_IMA_ISS:
1577 case CODEC_ID_ADPCM_IMA_EA_EACS:
1578 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1579 case CODEC_ID_ADPCM_MS:
1580 case CODEC_ID_ADPCM_4XM:
1581 case CODEC_ID_ADPCM_XA:
1582 case CODEC_ID_ADPCM_ADX:
1583 case CODEC_ID_ADPCM_EA:
1584 case CODEC_ID_ADPCM_CT:
1585 case CODEC_ID_ADPCM_SWF:
1586 case CODEC_ID_ADPCM_YAMAHA:
1587 case CODEC_ID_ADPCM_SBPRO_2:
1588 case CODEC_ID_ADPCM_SBPRO_3:
1589 case CODEC_ID_ADPCM_SBPRO_4:
1590 case CODEC_ID_ADPCM_EA_R1:
1591 case CODEC_ID_ADPCM_EA_R2:
1592 case CODEC_ID_ADPCM_EA_R3:
1593 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1594 case CODEC_ID_ADPCM_EA_XAS:
1595 case CODEC_ID_ADPCM_THP:
1597 const gchar *layout = NULL;
1600 case CODEC_ID_ADPCM_IMA_QT:
1601 layout = "quicktime";
1603 case CODEC_ID_ADPCM_IMA_WAV:
1606 case CODEC_ID_ADPCM_IMA_DK3:
1609 case CODEC_ID_ADPCM_IMA_DK4:
1612 case CODEC_ID_ADPCM_IMA_WS:
1613 layout = "westwood";
1615 case CODEC_ID_ADPCM_IMA_SMJPEG:
1618 case CODEC_ID_ADPCM_IMA_AMV:
1621 case CODEC_ID_ADPCM_IMA_ISS:
1624 case CODEC_ID_ADPCM_IMA_EA_EACS:
1627 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1630 case CODEC_ID_ADPCM_MS:
1631 layout = "microsoft";
1633 case CODEC_ID_ADPCM_4XM:
1636 case CODEC_ID_ADPCM_XA:
1639 case CODEC_ID_ADPCM_ADX:
1642 case CODEC_ID_ADPCM_EA:
1645 case CODEC_ID_ADPCM_CT:
1648 case CODEC_ID_ADPCM_SWF:
1651 case CODEC_ID_ADPCM_YAMAHA:
1654 case CODEC_ID_ADPCM_SBPRO_2:
1657 case CODEC_ID_ADPCM_SBPRO_3:
1660 case CODEC_ID_ADPCM_SBPRO_4:
1663 case CODEC_ID_ADPCM_EA_R1:
1666 case CODEC_ID_ADPCM_EA_R2:
1669 case CODEC_ID_ADPCM_EA_R3:
1672 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1673 layout = "ea-maxis-xa";
1675 case CODEC_ID_ADPCM_EA_XAS:
1678 case CODEC_ID_ADPCM_THP:
1682 g_assert (0); /* don't worry, we never get here */
1686 /* FIXME: someone please check whether we need additional properties
1687 * in this caps definition. */
1689 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1690 "layout", G_TYPE_STRING, layout, NULL);
1692 gst_caps_set_simple (caps,
1693 "block_align", G_TYPE_INT, context->block_align,
1694 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1698 case CODEC_ID_AMR_NB:
1700 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1704 case CODEC_ID_AMR_WB:
1706 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1712 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1716 case CODEC_ID_GSM_MS:
1718 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1722 case CODEC_ID_NELLYMOSER:
1724 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1725 "audio/x-nellymoser", NULL);
1731 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1734 gst_caps_set_simple (caps,
1735 "leaf_size", G_TYPE_INT, context->block_align,
1736 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1741 case CODEC_ID_RA_144:
1742 case CODEC_ID_RA_288:
1748 case CODEC_ID_RA_144:
1751 case CODEC_ID_RA_288:
1761 /* FIXME: properties? */
1763 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1764 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1766 gst_caps_set_simple (caps,
1767 "leaf_size", G_TYPE_INT, context->block_align,
1768 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1773 case CODEC_ID_ROQ_DPCM:
1774 case CODEC_ID_INTERPLAY_DPCM:
1775 case CODEC_ID_XAN_DPCM:
1776 case CODEC_ID_SOL_DPCM:
1778 const gchar *layout = NULL;
1781 case CODEC_ID_ROQ_DPCM:
1784 case CODEC_ID_INTERPLAY_DPCM:
1785 layout = "interplay";
1787 case CODEC_ID_XAN_DPCM:
1790 case CODEC_ID_SOL_DPCM:
1794 g_assert (0); /* don't worry, we never get here */
1798 /* FIXME: someone please check whether we need additional properties
1799 * in this caps definition. */
1801 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1802 "layout", G_TYPE_STRING, layout, NULL);
1804 gst_caps_set_simple (caps,
1805 "block_align", G_TYPE_INT, context->block_align,
1806 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1810 case CODEC_ID_SHORTEN:
1811 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1816 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1819 gst_caps_set_simple (caps,
1820 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1825 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1826 * encoder case, we want to add things like samplerate, channels... */
1828 caps = gst_caps_new_empty_simple ("audio/x-flac");
1832 case CODEC_ID_DVD_SUBTITLE:
1833 case CODEC_ID_DVB_SUBTITLE:
1837 caps = gst_caps_new_empty_simple ("image/bmp");
1841 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1844 gst_caps_set_simple (caps,
1845 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1848 case CODEC_ID_TWINVQ:
1850 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1851 "audio/x-twin-vq", NULL);
1854 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1861 if ((codec = avcodec_find_decoder (codec_id)) ||
1862 (codec = avcodec_find_encoder (codec_id))) {
1865 GST_LOG ("Could not create stream format caps for %s", codec->name);
1867 switch (codec->type) {
1868 case AVMEDIA_TYPE_VIDEO:
1869 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1871 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
1874 case AVMEDIA_TYPE_AUDIO:
1875 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1877 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
1879 gst_caps_set_simple (caps,
1880 "block_align", G_TYPE_INT, context->block_align,
1881 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1892 /* set private data */
1893 if (context && context->extradata_size > 0) {
1894 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1896 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1897 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1898 gst_buffer_unref (data);
1901 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1904 GST_LOG ("No caps found for codec_id=%d", codec_id);
1910 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1911 * to a GstCaps. If the context is ommitted, no fixed values
1912 * for video/audio size will be included in the GstCaps
1914 * See below for usefullness
1918 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1919 enum CodecID codec_id)
1921 GstCaps *caps = NULL;
1922 GstVideoFormat format;
1924 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
1926 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1927 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
1928 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1932 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1934 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1941 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
1943 switch (sample_fmt) {
1944 case AV_SAMPLE_FMT_U8:
1945 case AV_SAMPLE_FMT_U8P:
1946 return GST_AUDIO_FORMAT_U8;
1948 case AV_SAMPLE_FMT_S16:
1949 case AV_SAMPLE_FMT_S16P:
1950 return GST_AUDIO_FORMAT_S16;
1952 case AV_SAMPLE_FMT_S32:
1953 case AV_SAMPLE_FMT_S32P:
1954 return GST_AUDIO_FORMAT_S32;
1956 case AV_SAMPLE_FMT_FLT:
1957 case AV_SAMPLE_FMT_FLTP:
1958 return GST_AUDIO_FORMAT_F32;
1960 case AV_SAMPLE_FMT_DBL:
1961 case AV_SAMPLE_FMT_DBLP:
1962 return GST_AUDIO_FORMAT_F64;
1966 return GST_AUDIO_FORMAT_UNKNOWN;
1971 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1972 * to a GstCaps. If the context is ommitted, no fixed values
1973 * for video/audio size will be included in the GstCaps
1975 * See below for usefullness
1979 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
1980 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
1982 GstCaps *caps = NULL;
1983 GstAudioFormat format;
1985 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
1987 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1988 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
1989 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1990 "layout", G_TYPE_STRING, "interleaved", NULL);
1991 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1993 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2000 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
2001 const enum AVSampleFormat *fmts)
2005 GstAudioFormat format;
2007 if (!fmts || fmts[0] == -1) {
2010 g_value_init (&va, GST_TYPE_LIST);
2011 g_value_init (&v, G_TYPE_STRING);
2012 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
2013 format = gst_ffmpeg_smpfmt_to_audioformat (i);
2014 if (format == GST_AUDIO_FORMAT_UNKNOWN)
2016 g_value_set_string (&v, gst_audio_format_to_string (format));
2017 gst_value_list_append_value (&va, &v);
2019 gst_caps_set_value (caps, "format", &va);
2021 g_value_unset (&va);
2025 g_value_init (&va, GST_TYPE_LIST);
2026 g_value_init (&v, G_TYPE_STRING);
2027 while (*fmts != -1) {
2028 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
2029 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2030 g_value_set_string (&v, gst_audio_format_to_string (format));
2031 gst_value_list_append_value (&va, &v);
2035 if (gst_value_list_get_size (&va) == 1) {
2036 /* The single value is still in v */
2037 gst_caps_set_value (caps, "format", &v);
2038 } else if (gst_value_list_get_size (&va) > 1) {
2039 gst_caps_set_value (caps, "format", &va);
2042 g_value_unset (&va);
2046 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2047 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2049 GstCaps *caps = NULL;
2051 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2052 context, codec_id, encode, codec);
2054 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2055 codec->sample_fmts, codec->supported_samplerates);
2058 /* Specific codec context */
2060 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2063 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2064 "layout", G_TYPE_STRING, "interleaved", NULL);
2065 gst_ffmpeg_audio_set_sample_fmts (caps, codec ? codec->sample_fmts : NULL);
2072 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
2076 GstVideoFormat format;
2078 if (!fmts || fmts[0] == -1) {
2081 g_value_init (&va, GST_TYPE_LIST);
2082 g_value_init (&v, G_TYPE_STRING);
2083 for (i = 0; i <= PIX_FMT_NB; i++) {
2084 format = gst_ffmpeg_pixfmt_to_videoformat (i);
2085 if (format == GST_VIDEO_FORMAT_UNKNOWN)
2087 g_value_set_string (&v, gst_video_format_to_string (format));
2088 gst_value_list_append_value (&va, &v);
2090 gst_caps_set_value (caps, "format", &va);
2092 g_value_unset (&va);
2096 /* Only a single format */
2097 g_value_init (&va, GST_TYPE_LIST);
2098 g_value_init (&v, G_TYPE_STRING);
2099 while (*fmts != -1) {
2100 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
2101 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2102 g_value_set_string (&v, gst_video_format_to_string (format));
2103 gst_value_list_append_value (&va, &v);
2107 if (gst_value_list_get_size (&va) == 1) {
2108 /* The single value is still in v */
2109 gst_caps_set_value (caps, "format", &v);
2110 } else if (gst_value_list_get_size (&va) > 1) {
2111 gst_caps_set_value (caps, "format", &va);
2114 g_value_unset (&va);
2118 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2119 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2123 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2124 context, codec_id, encode, codec);
2127 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2130 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2132 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2137 /* Convert a FFMPEG codec Type and optional AVCodecContext
2138 * to a GstCaps. If the context is ommitted, no fixed values
2139 * for video/audio size will be included in the GstCaps
2141 * AVMediaType is primarily meant for uncompressed data GstCaps!
2145 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
2146 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
2150 switch (codec_type) {
2151 case AVMEDIA_TYPE_VIDEO:
2153 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
2155 case AVMEDIA_TYPE_AUDIO:
2157 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
2167 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2168 * and other audio properties in a AVCodecContext.
2170 * For usefullness, see below
2174 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2175 AVCodecContext * context, gboolean raw)
2177 GstStructure *structure;
2179 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2181 g_return_if_fail (gst_caps_get_size (caps) == 1);
2183 structure = gst_caps_get_structure (caps, 0);
2185 gst_structure_get_int (structure, "channels", &context->channels);
2186 gst_structure_get_int (structure, "rate", &context->sample_rate);
2187 gst_structure_get_int (structure, "block_align", &context->block_align);
2188 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2193 if (gst_structure_has_name (structure, "audio/x-raw")) {
2194 if ((fmt = gst_structure_get_string (structure, "format"))) {
2195 format = gst_audio_format_from_string (fmt);
2200 case GST_AUDIO_FORMAT_F32:
2201 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2203 case GST_AUDIO_FORMAT_F64:
2204 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2206 case GST_AUDIO_FORMAT_S32:
2207 context->sample_fmt = AV_SAMPLE_FMT_S32;
2209 case GST_AUDIO_FORMAT_S16:
2210 context->sample_fmt = AV_SAMPLE_FMT_S16;
2217 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2218 * and other video properties in a AVCodecContext.
2220 * For usefullness, see below
2224 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2225 AVCodecContext * context, gboolean raw)
2227 GstStructure *structure;
2229 const GValue *par = NULL;
2231 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2233 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2234 g_return_if_fail (gst_caps_get_size (caps) == 1);
2235 structure = gst_caps_get_structure (caps, 0);
2237 gst_structure_get_int (structure, "width", &context->width);
2238 gst_structure_get_int (structure, "height", &context->height);
2239 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2241 fps = gst_structure_get_value (structure, "framerate");
2242 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2244 /* somehow these seem mixed up.. */
2245 context->time_base.den = gst_value_get_fraction_numerator (fps);
2246 context->time_base.num = gst_value_get_fraction_denominator (fps);
2247 context->ticks_per_frame = 1;
2249 GST_DEBUG ("setting framerate %d/%d = %lf",
2250 context->time_base.den, context->time_base.num,
2251 1. * context->time_base.den / context->time_base.num);
2254 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2255 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2257 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2258 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2260 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2261 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2262 1. * context->sample_aspect_ratio.den /
2263 context->sample_aspect_ratio.num);
2269 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2271 if (gst_structure_has_name (structure, "video/x-raw")) {
2272 if ((fmt = gst_structure_get_string (structure, "format"))) {
2273 format = gst_video_format_from_string (fmt);
2278 case GST_VIDEO_FORMAT_YUY2:
2279 context->pix_fmt = PIX_FMT_YUYV422;
2281 case GST_VIDEO_FORMAT_I420:
2282 context->pix_fmt = PIX_FMT_YUV420P;
2284 case GST_VIDEO_FORMAT_A420:
2285 context->pix_fmt = PIX_FMT_YUVA420P;
2287 case GST_VIDEO_FORMAT_Y41B:
2288 context->pix_fmt = PIX_FMT_YUV411P;
2290 case GST_VIDEO_FORMAT_Y42B:
2291 context->pix_fmt = PIX_FMT_YUV422P;
2293 case GST_VIDEO_FORMAT_YUV9:
2294 context->pix_fmt = PIX_FMT_YUV410P;
2296 case GST_VIDEO_FORMAT_Y444:
2297 context->pix_fmt = PIX_FMT_YUV444P;
2299 case GST_VIDEO_FORMAT_GRAY8:
2300 context->pix_fmt = PIX_FMT_GRAY8;
2302 case GST_VIDEO_FORMAT_xRGB:
2303 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2304 context->pix_fmt = PIX_FMT_RGB32;
2307 case GST_VIDEO_FORMAT_BGRx:
2308 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2309 context->pix_fmt = PIX_FMT_RGB32;
2312 case GST_VIDEO_FORMAT_RGB:
2313 context->pix_fmt = PIX_FMT_RGB24;
2315 case GST_VIDEO_FORMAT_BGR:
2316 context->pix_fmt = PIX_FMT_BGR24;
2318 case GST_VIDEO_FORMAT_RGB16:
2319 context->pix_fmt = PIX_FMT_RGB565;
2321 case GST_VIDEO_FORMAT_RGB15:
2322 context->pix_fmt = PIX_FMT_RGB555;
2324 case GST_VIDEO_FORMAT_RGB8P:
2325 context->pix_fmt = PIX_FMT_PAL8;
2334 GstVideoFormat format;
2335 enum PixelFormat pixfmt;
2338 /* FIXME : FILLME */
2339 static const PixToFmt pixtofmttable[] = {
2340 /* GST_VIDEO_FORMAT_I420, */
2341 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2342 /* Note : this should use a different chroma placement */
2343 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2345 /* GST_VIDEO_FORMAT_YV12, */
2346 /* GST_VIDEO_FORMAT_YUY2, */
2347 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2348 /* GST_VIDEO_FORMAT_UYVY, */
2349 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2350 /* GST_VIDEO_FORMAT_AYUV, */
2351 /* GST_VIDEO_FORMAT_RGBx, */
2352 /* GST_VIDEO_FORMAT_BGRx, */
2353 /* GST_VIDEO_FORMAT_xRGB, */
2354 /* GST_VIDEO_FORMAT_xBGR, */
2355 /* GST_VIDEO_FORMAT_RGBA, */
2356 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2357 /* GST_VIDEO_FORMAT_BGRA, */
2358 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2359 /* GST_VIDEO_FORMAT_ARGB, */
2360 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2361 /* GST_VIDEO_FORMAT_ABGR, */
2362 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2363 /* GST_VIDEO_FORMAT_RGB, */
2364 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2365 /* GST_VIDEO_FORMAT_BGR, */
2366 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2367 /* GST_VIDEO_FORMAT_Y41B, */
2368 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2369 /* GST_VIDEO_FORMAT_Y42B, */
2370 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2371 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2372 /* GST_VIDEO_FORMAT_YVYU, */
2373 /* GST_VIDEO_FORMAT_Y444, */
2374 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2375 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2376 /* GST_VIDEO_FORMAT_v210, */
2377 /* GST_VIDEO_FORMAT_v216, */
2378 /* GST_VIDEO_FORMAT_NV12, */
2379 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2380 /* GST_VIDEO_FORMAT_NV21, */
2381 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2382 /* GST_VIDEO_FORMAT_GRAY8, */
2383 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2384 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2385 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2386 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2387 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2388 /* GST_VIDEO_FORMAT_v308, */
2389 /* GST_VIDEO_FORMAT_Y800, */
2390 /* GST_VIDEO_FORMAT_Y16, */
2391 /* GST_VIDEO_FORMAT_RGB16, */
2392 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2393 /* GST_VIDEO_FORMAT_BGR16, */
2394 /* GST_VIDEO_FORMAT_RGB15, */
2395 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2396 /* GST_VIDEO_FORMAT_BGR15, */
2397 /* GST_VIDEO_FORMAT_UYVP, */
2398 /* GST_VIDEO_FORMAT_A420, */
2399 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2400 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2401 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2402 /* GST_VIDEO_FORMAT_YUV9, */
2403 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2404 /* GST_VIDEO_FORMAT_YVU9, */
2405 /* GST_VIDEO_FORMAT_IYU1, */
2406 /* GST_VIDEO_FORMAT_ARGB64, */
2407 /* GST_VIDEO_FORMAT_AYUV64, */
2408 /* GST_VIDEO_FORMAT_r210, */
2409 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2410 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2411 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2412 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2413 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2414 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2415 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2416 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2417 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2421 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2425 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2426 if (pixtofmttable[i].pixfmt == pixfmt)
2427 return pixtofmttable[i].format;
2429 GST_WARNING ("Unknown pixel format %d", pixfmt);
2430 return GST_VIDEO_FORMAT_UNKNOWN;
2434 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2438 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2439 if (pixtofmttable[i].format == format)
2440 return pixtofmttable[i].pixfmt;
2441 return PIX_FMT_NONE;
2445 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2449 context->width = GST_VIDEO_INFO_WIDTH (info);
2450 context->height = GST_VIDEO_INFO_HEIGHT (info);
2451 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2452 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2453 context->bits_per_coded_sample = bpp;
2455 context->ticks_per_frame = 1;
2456 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2457 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2459 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2460 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2463 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2467 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2469 const AVCodec *codec;
2470 const enum AVSampleFormat *smpl_fmts;
2471 enum AVSampleFormat smpl_fmt = -1;
2473 context->channels = info->channels;
2474 context->sample_rate = info->rate;
2475 context->channel_layout =
2476 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2478 codec = context->codec;
2480 smpl_fmts = codec->sample_fmts;
2482 switch (info->finfo->format) {
2483 case GST_AUDIO_FORMAT_F32:
2485 while (*smpl_fmts != -1) {
2486 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2487 smpl_fmt = *smpl_fmts;
2489 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2490 smpl_fmt = *smpl_fmts;
2496 smpl_fmt = AV_SAMPLE_FMT_FLT;
2499 case GST_AUDIO_FORMAT_F64:
2501 while (*smpl_fmts != -1) {
2502 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2503 smpl_fmt = *smpl_fmts;
2505 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2506 smpl_fmt = *smpl_fmts;
2512 smpl_fmt = AV_SAMPLE_FMT_DBL;
2515 case GST_AUDIO_FORMAT_S32:
2517 while (*smpl_fmts != -1) {
2518 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2519 smpl_fmt = *smpl_fmts;
2521 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2522 smpl_fmt = *smpl_fmts;
2528 smpl_fmt = AV_SAMPLE_FMT_S32;
2531 case GST_AUDIO_FORMAT_S16:
2533 while (*smpl_fmts != -1) {
2534 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2535 smpl_fmt = *smpl_fmts;
2537 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2538 smpl_fmt = *smpl_fmts;
2544 smpl_fmt = AV_SAMPLE_FMT_S16;
2547 case GST_AUDIO_FORMAT_U8:
2549 while (*smpl_fmts != -1) {
2550 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2551 smpl_fmt = *smpl_fmts;
2553 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2554 smpl_fmt = *smpl_fmts;
2560 smpl_fmt = AV_SAMPLE_FMT_U8;
2567 g_assert (smpl_fmt != -1);
2569 context->sample_fmt = smpl_fmt;
2572 /* Convert a GstCaps and a FFMPEG codec Type to a
2573 * AVCodecContext. If the context is ommitted, no fixed values
2574 * for video/audio size will be included in the context
2576 * AVMediaType is primarily meant for uncompressed data GstCaps!
2580 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2581 const GstCaps * caps, AVCodecContext * context)
2583 if (context == NULL)
2587 case AVMEDIA_TYPE_VIDEO:
2588 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2591 case AVMEDIA_TYPE_AUDIO:
2592 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2603 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2607 guint8 *end = src + size;
2610 while (srcp < end) {
2611 if (count == 2 && *srcp <= 0x03) {
2612 GST_DEBUG ("added escape code");
2621 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2624 *destsize = dstp - dst;
2627 /* copy the config, escaping NAL units as we iterate them, if something fails we
2628 * copy everything and hope for the best. */
2630 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2635 guint nalsize, esize;
2645 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2647 GST_DEBUG ("num SPS %d", cnt);
2649 memcpy (dstp, srcp, 6);
2653 for (i = 0; i < cnt; i++) {
2654 GST_DEBUG ("copy SPS %d", i);
2655 nalsize = (srcp[0] << 8) | srcp[1];
2656 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2657 dstp[0] = esize >> 8;
2658 dstp[1] = esize & 0xff;
2660 srcp += nalsize + 2;
2663 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2665 GST_DEBUG ("num PPS %d", cnt);
2667 for (i = 0; i < cnt; i++) {
2668 GST_DEBUG ("copy PPS %d", i);
2669 nalsize = (srcp[0] << 8) | srcp[1];
2670 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2671 dstp[0] = esize >> 8;
2672 dstp[1] = esize & 0xff;
2674 srcp += nalsize + 2;
2676 *destsize = dstp - dst;
2682 GST_DEBUG ("something unexpected, doing full copy");
2683 memcpy (dst, src, size);
2691 * caps_with_codecid () transforms a GstCaps for a known codec
2692 * ID into a filled-in context.
2693 * codec_data from caps will override possible extradata already in the context
2697 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2698 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2701 const GValue *value;
2704 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2705 codec_id, codec_type, caps, context);
2707 if (!context || !gst_caps_get_size (caps))
2710 str = gst_caps_get_structure (caps, 0);
2712 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2713 if ((value = gst_structure_get_value (str, "codec_data"))) {
2716 buf = gst_value_get_buffer (value);
2717 gst_buffer_map (buf, &map, GST_MAP_READ);
2719 /* free the old one if it is there */
2720 if (context->extradata)
2721 av_free (context->extradata);
2724 if (codec_id == CODEC_ID_H264) {
2727 GST_DEBUG ("copy, escaping codec_data %d", size);
2728 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2729 * reason for this but let's just escape it for now. Start by allocating
2730 * enough space, x2 is more than enough.
2732 * FIXME, we disabled escaping because some file already contain escaped
2733 * codec_data and then we escape twice and fail. It's better to leave it
2734 * as is, as that is what most players do. */
2735 context->extradata =
2736 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2737 FF_INPUT_BUFFER_PADDING_SIZE));
2738 copy_config (context->extradata, data, size, &extrasize);
2739 GST_DEBUG ("escaped size: %d", extrasize);
2740 context->extradata_size = extrasize;
2744 /* allocate with enough padding */
2745 GST_DEBUG ("copy codec_data");
2746 context->extradata =
2747 av_mallocz (GST_ROUND_UP_16 (map.size +
2748 FF_INPUT_BUFFER_PADDING_SIZE));
2749 memcpy (context->extradata, map.data, map.size);
2750 context->extradata_size = map.size;
2753 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2754 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2755 context->extradata[0] = (guint8) map.size;
2758 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2760 gst_buffer_unmap (buf, &map);
2761 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2762 codec_id != CODEC_ID_FLAC) {
2763 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2764 * extradata anyway which makes then segfault. */
2765 context->extradata =
2766 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2767 context->extradata_size = 0;
2768 GST_DEBUG ("no codec data");
2772 case CODEC_ID_MPEG4:
2774 const gchar *mime = gst_structure_get_name (str);
2776 if (!strcmp (mime, "video/x-divx"))
2777 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2778 else if (!strcmp (mime, "video/x-xvid"))
2779 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2780 else if (!strcmp (mime, "video/x-3ivx"))
2781 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2782 else if (!strcmp (mime, "video/mpeg"))
2783 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2788 /* FIXME: this is a workaround for older gst-plugins releases
2789 * (<= 0.8.9). This should be removed at some point, because
2790 * it causes wrong decoded frame order. */
2791 if (!context->extradata) {
2792 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2795 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2796 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2797 gst_structure_get_int (str, "low_delay", &low_delay) ||
2798 gst_structure_get_int (str, "unknown_svq3_flag",
2799 &unknown_svq3_flag)) {
2800 context->extradata = (guint8 *) av_mallocz (0x64);
2801 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2805 flags |= unknown_svq3_flag;
2807 flags |= halfpel_flag;
2809 flags |= thirdpel_flag;
2812 flags = GUINT16_FROM_LE (flags);
2814 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2815 context->extradata_size = 0x64;
2820 case CODEC_ID_MSRLE:
2821 case CODEC_ID_QTRLE:
2828 if (gst_structure_get_int (str, "depth", &depth)) {
2829 context->bits_per_coded_sample = depth;
2831 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2844 if (gst_structure_get_int (str, "format", &format))
2845 context->sub_id = format;
2850 case CODEC_ID_RA_288:
2851 case CODEC_ID_RA_144:
2857 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2858 context->block_align = leaf_size;
2859 if (gst_structure_get_int (str, "bitrate", &bitrate))
2860 context->bit_rate = bitrate;
2863 gst_structure_get_int (str, "samplesize",
2864 &context->bits_per_coded_sample);
2867 case CODEC_ID_DVVIDEO:
2869 const gchar *format;
2871 if ((format = gst_structure_get_string (str, "format"))) {
2873 if (g_str_equal (format, "YUY2"))
2874 context->pix_fmt = PIX_FMT_YUYV422;
2875 else if (g_str_equal (format, "I420"))
2876 context->pix_fmt = PIX_FMT_YUV420P;
2877 else if (g_str_equal (format, "A420"))
2878 context->pix_fmt = PIX_FMT_YUVA420P;
2879 else if (g_str_equal (format, "Y41B"))
2880 context->pix_fmt = PIX_FMT_YUV411P;
2881 else if (g_str_equal (format, "Y42B"))
2882 context->pix_fmt = PIX_FMT_YUV422P;
2883 else if (g_str_equal (format, "YUV9"))
2884 context->pix_fmt = PIX_FMT_YUV410P;
2886 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2890 GST_WARNING ("No specified format");
2893 case CODEC_ID_H263P:
2897 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2898 context->flags |= CODEC_FLAG_4MV;
2900 context->flags &= ~CODEC_FLAG_4MV;
2901 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2902 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2903 context->flags |= CODEC_FLAG_AC_PRED;
2905 context->flags &= ~CODEC_FLAG_AC_PRED;
2906 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2907 context->flags |= CODEC_FLAG_LOOP_FILTER;
2909 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2912 case CODEC_ID_ADPCM_G726:
2914 const gchar *layout;
2916 if ((layout = gst_structure_get_string (str, "layout"))) {
2917 if (!strcmp (layout, "g721")) {
2918 context->sample_rate = 8000;
2919 context->channels = 1;
2920 context->bit_rate = 32000;
2929 if (!gst_caps_is_fixed (caps))
2932 /* common properties (width, height, fps) */
2933 switch (codec_type) {
2934 case AVMEDIA_TYPE_VIDEO:
2935 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2937 case AVMEDIA_TYPE_AUDIO:
2938 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2944 /* fixup of default settings */
2946 case CODEC_ID_QCELP:
2947 /* QCELP is always mono, no matter what the caps say */
2948 context->channels = 1;
2955 /* _formatid_to_caps () is meant for muxers/demuxers, it
2956 * transforms a name (ffmpeg way of ID'ing these, why don't
2957 * they have unique numerical IDs?) to the corresponding
2958 * caps belonging to that mux-format
2960 * Note: we don't need any additional info because the caps
2961 * isn't supposed to contain any useful info besides the
2966 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2968 GstCaps *caps = NULL;
2970 if (!strcmp (format_name, "mpeg")) {
2971 caps = gst_caps_new_simple ("video/mpeg",
2972 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2973 } else if (!strcmp (format_name, "mpegts")) {
2974 caps = gst_caps_new_simple ("video/mpegts",
2975 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2976 } else if (!strcmp (format_name, "rm")) {
2977 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2978 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2979 } else if (!strcmp (format_name, "asf")) {
2980 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2981 } else if (!strcmp (format_name, "avi")) {
2982 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2983 } else if (!strcmp (format_name, "wav")) {
2984 caps = gst_caps_new_empty_simple ("audio/x-wav");
2985 } else if (!strcmp (format_name, "ape")) {
2986 caps = gst_caps_new_empty_simple ("application/x-ape");
2987 } else if (!strcmp (format_name, "swf")) {
2988 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2989 } else if (!strcmp (format_name, "au")) {
2990 caps = gst_caps_new_empty_simple ("audio/x-au");
2991 } else if (!strcmp (format_name, "dv")) {
2992 caps = gst_caps_new_simple ("video/x-dv",
2993 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2994 } else if (!strcmp (format_name, "4xm")) {
2995 caps = gst_caps_new_empty_simple ("video/x-4xm");
2996 } else if (!strcmp (format_name, "matroska")) {
2997 caps = gst_caps_new_empty_simple ("video/x-matroska");
2998 } else if (!strcmp (format_name, "mp3")) {
2999 caps = gst_caps_new_empty_simple ("application/x-id3");
3000 } else if (!strcmp (format_name, "flic")) {
3001 caps = gst_caps_new_empty_simple ("video/x-fli");
3002 } else if (!strcmp (format_name, "flv")) {
3003 caps = gst_caps_new_empty_simple ("video/x-flv");
3004 } else if (!strcmp (format_name, "tta")) {
3005 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3006 } else if (!strcmp (format_name, "aiff")) {
3007 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3008 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3010 gst_caps_from_string
3011 ("application/x-3gp; video/quicktime; audio/x-m4a");
3012 } else if (!strcmp (format_name, "mov")) {
3013 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3014 } else if (!strcmp (format_name, "mp4")) {
3015 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3016 } else if (!strcmp (format_name, "3gp")) {
3017 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3018 } else if (!strcmp (format_name, "3g2")) {
3019 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3020 } else if (!strcmp (format_name, "psp")) {
3021 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3022 } else if (!strcmp (format_name, "ipod")) {
3023 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3024 } else if (!strcmp (format_name, "aac")) {
3025 caps = gst_caps_new_simple ("audio/mpeg",
3026 "mpegversion", G_TYPE_INT, 4, NULL);
3027 } else if (!strcmp (format_name, "gif")) {
3028 caps = gst_caps_from_string ("image/gif");
3029 } else if (!strcmp (format_name, "ogg")) {
3030 caps = gst_caps_from_string ("application/ogg");
3031 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3032 caps = gst_caps_from_string ("application/mxf");
3033 } else if (!strcmp (format_name, "gxf")) {
3034 caps = gst_caps_from_string ("application/gxf");
3035 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3036 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3037 "y4mversion", G_TYPE_INT, 2, NULL);
3038 } else if (!strcmp (format_name, "mpc")) {
3039 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3040 } else if (!strcmp (format_name, "vqf")) {
3041 caps = gst_caps_from_string ("audio/x-vqf");
3042 } else if (!strcmp (format_name, "nsv")) {
3043 caps = gst_caps_from_string ("video/x-nsv");
3044 } else if (!strcmp (format_name, "amr")) {
3045 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3046 } else if (!strcmp (format_name, "webm")) {
3047 caps = gst_caps_from_string ("video/webm");
3048 } else if (!strcmp (format_name, "voc")) {
3049 caps = gst_caps_from_string ("audio/x-voc");
3053 GST_LOG ("Could not create stream format caps for %s", format_name);
3054 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3055 caps = gst_caps_new_empty_simple (name);
3063 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3064 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3065 AVOutputFormat * plugin)
3067 static enum CodecID tmp_vlist[] = {
3071 static enum CodecID tmp_alist[] = {
3076 GST_LOG ("format_name : %s", format_name);
3078 if (!strcmp (format_name, "mp4")) {
3079 static enum CodecID mp4_video_list[] = {
3080 CODEC_ID_MPEG4, CODEC_ID_H264,
3084 static enum CodecID mp4_audio_list[] = {
3085 CODEC_ID_AAC, CODEC_ID_MP3,
3089 *video_codec_list = mp4_video_list;
3090 *audio_codec_list = mp4_audio_list;
3091 } else if (!strcmp (format_name, "mpeg")) {
3092 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
3093 CODEC_ID_MPEG2VIDEO,
3097 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
3103 *video_codec_list = mpeg_video_list;
3104 *audio_codec_list = mpeg_audio_list;
3105 } else if (!strcmp (format_name, "dvd")) {
3106 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
3109 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
3116 *video_codec_list = mpeg_video_list;
3117 *audio_codec_list = mpeg_audio_list;
3118 } else if (!strcmp (format_name, "mpegts")) {
3119 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
3120 CODEC_ID_MPEG2VIDEO,
3124 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
3132 *video_codec_list = mpegts_video_list;
3133 *audio_codec_list = mpegts_audio_list;
3134 } else if (!strcmp (format_name, "vob")) {
3135 static enum CodecID vob_video_list[] =
3136 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
3137 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
3138 CODEC_ID_DTS, CODEC_ID_NONE
3141 *video_codec_list = vob_video_list;
3142 *audio_codec_list = vob_audio_list;
3143 } else if (!strcmp (format_name, "flv")) {
3144 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
3145 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
3147 *video_codec_list = flv_video_list;
3148 *audio_codec_list = flv_audio_list;
3149 } else if (!strcmp (format_name, "asf")) {
3150 static enum CodecID asf_video_list[] =
3151 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
3152 static enum CodecID asf_audio_list[] =
3153 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
3155 *video_codec_list = asf_video_list;
3156 *audio_codec_list = asf_audio_list;
3157 } else if (!strcmp (format_name, "dv")) {
3158 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
3159 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
3161 *video_codec_list = dv_video_list;
3162 *audio_codec_list = dv_audio_list;
3163 } else if (!strcmp (format_name, "mov")) {
3164 static enum CodecID mov_video_list[] = {
3165 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
3166 CODEC_ID_H263, CODEC_ID_H263P,
3167 CODEC_ID_H264, CODEC_ID_DVVIDEO,
3171 static enum CodecID mov_audio_list[] = {
3172 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
3173 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
3174 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3175 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
3176 CODEC_ID_MP3, CODEC_ID_NONE
3179 *video_codec_list = mov_video_list;
3180 *audio_codec_list = mov_audio_list;
3181 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3182 static enum CodecID tgp_video_list[] = {
3183 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
3186 static enum CodecID tgp_audio_list[] = {
3187 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3192 *video_codec_list = tgp_video_list;
3193 *audio_codec_list = tgp_audio_list;
3194 } else if (!strcmp (format_name, "mmf")) {
3195 static enum CodecID mmf_audio_list[] = {
3196 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
3198 *video_codec_list = NULL;
3199 *audio_codec_list = mmf_audio_list;
3200 } else if (!strcmp (format_name, "amr")) {
3201 static enum CodecID amr_audio_list[] = {
3202 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3205 *video_codec_list = NULL;
3206 *audio_codec_list = amr_audio_list;
3207 } else if (!strcmp (format_name, "gif")) {
3208 static enum CodecID gif_image_list[] = {
3209 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
3211 *video_codec_list = gif_image_list;
3212 *audio_codec_list = NULL;
3213 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
3214 (plugin->video_codec != CODEC_ID_NONE)) {
3215 tmp_vlist[0] = plugin->video_codec;
3216 tmp_alist[0] = plugin->audio_codec;
3218 *video_codec_list = tmp_vlist;
3219 *audio_codec_list = tmp_alist;
3221 GST_LOG ("Format %s not found", format_name);
3228 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3229 * are omitted, that can be queried by the user itself,
3230 * we're not eating the GstCaps or anything
3231 * A pointer to an allocated context is also needed for
3232 * optional extra info
3236 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3238 enum CodecID id = CODEC_ID_NONE;
3239 const gchar *mimetype;
3240 const GstStructure *structure;
3241 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3243 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3244 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3245 structure = gst_caps_get_structure (caps, 0);
3247 mimetype = gst_structure_get_name (structure);
3249 if (!strcmp (mimetype, "video/x-raw")) {
3250 id = CODEC_ID_RAWVIDEO;
3252 } else if (!strcmp (mimetype, "audio/x-raw")) {
3255 if (gst_audio_info_from_caps (&info, caps)) {
3256 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3257 case GST_AUDIO_FORMAT_S8:
3258 id = CODEC_ID_PCM_S8;
3260 case GST_AUDIO_FORMAT_U8:
3261 id = CODEC_ID_PCM_U8;
3263 case GST_AUDIO_FORMAT_S16LE:
3264 id = CODEC_ID_PCM_S16LE;
3266 case GST_AUDIO_FORMAT_S16BE:
3267 id = CODEC_ID_PCM_S16BE;
3269 case GST_AUDIO_FORMAT_U16LE:
3270 id = CODEC_ID_PCM_U16LE;
3272 case GST_AUDIO_FORMAT_U16BE:
3273 id = CODEC_ID_PCM_U16BE;
3278 if (id != CODEC_ID_NONE)
3281 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3282 id = CODEC_ID_PCM_MULAW;
3284 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3285 id = CODEC_ID_PCM_ALAW;
3287 } else if (!strcmp (mimetype, "video/x-dv")) {
3290 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3292 id = CODEC_ID_DVVIDEO;
3295 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3296 id = CODEC_ID_DVAUDIO;
3298 } else if (!strcmp (mimetype, "video/x-h263")) {
3299 const gchar *h263version =
3300 gst_structure_get_string (structure, "h263version");
3301 if (h263version && !strcmp (h263version, "h263p"))
3302 id = CODEC_ID_H263P;
3306 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3307 id = CODEC_ID_H263I;
3309 } else if (!strcmp (mimetype, "video/x-h261")) {
3312 } else if (!strcmp (mimetype, "video/mpeg")) {
3316 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3317 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3319 switch (mpegversion) {
3321 id = CODEC_ID_MPEG1VIDEO;
3324 id = CODEC_ID_MPEG2VIDEO;
3327 id = CODEC_ID_MPEG4;
3331 if (id != CODEC_ID_NONE)
3333 } else if (!strcmp (mimetype, "image/jpeg")) {
3334 id = CODEC_ID_MJPEG; /* A... B... */
3336 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3337 id = CODEC_ID_MJPEGB;
3339 } else if (!strcmp (mimetype, "video/x-wmv")) {
3340 gint wmvversion = 0;
3342 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3343 switch (wmvversion) {
3352 const gchar *format;
3354 /* WMV3 unless the fourcc exists and says otherwise */
3357 if ((format = gst_structure_get_string (structure, "format")) &&
3358 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3365 if (id != CODEC_ID_NONE)
3367 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3368 id = CODEC_ID_VORBIS;
3370 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3373 } else if (!strcmp (mimetype, "audio/mpeg")) {
3375 gint mpegversion = 0;
3377 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3378 switch (mpegversion) {
3379 case 2: /* ffmpeg uses faad for both... */
3384 if (gst_structure_get_int (structure, "layer", &layer)) {
3399 if (id != CODEC_ID_NONE)
3401 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3402 gint streamversion = -1;
3404 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3405 if (streamversion == 7)
3406 id = CODEC_ID_MUSEPACK7;
3408 id = CODEC_ID_MUSEPACK7;
3410 } else if (!strcmp (mimetype, "audio/x-wma")) {
3411 gint wmaversion = 0;
3413 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3414 switch (wmaversion) {
3416 id = CODEC_ID_WMAV1;
3419 id = CODEC_ID_WMAV2;
3422 id = CODEC_ID_WMAPRO;
3426 if (id != CODEC_ID_NONE)
3428 } else if (!strcmp (mimetype, "audio/x-wms")) {
3429 id = CODEC_ID_WMAVOICE;
3431 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3434 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3437 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3438 !strcmp (mimetype, "audio/atrac3")) {
3439 id = CODEC_ID_ATRAC3;
3441 } else if (!strcmp (mimetype, "audio/x-dts")) {
3444 } else if (!strcmp (mimetype, "application/x-ape")) {
3447 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3448 gint msmpegversion = 0;
3450 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3451 switch (msmpegversion) {
3453 id = CODEC_ID_MSMPEG4V1;
3456 id = CODEC_ID_MSMPEG4V2;
3459 id = CODEC_ID_MSMPEG4V3;
3463 if (id != CODEC_ID_NONE)
3465 } else if (!strcmp (mimetype, "video/x-svq")) {
3466 gint svqversion = 0;
3468 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3469 switch (svqversion) {
3478 if (id != CODEC_ID_NONE)
3480 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3481 id = CODEC_ID_HUFFYUV;
3483 } else if (!strcmp (mimetype, "audio/x-mace")) {
3484 gint maceversion = 0;
3486 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3487 switch (maceversion) {
3489 id = CODEC_ID_MACE3;
3492 id = CODEC_ID_MACE6;
3496 if (id != CODEC_ID_NONE)
3498 } else if (!strcmp (mimetype, "video/x-theora")) {
3499 id = CODEC_ID_THEORA;
3501 } else if (!strcmp (mimetype, "video/x-vp3")) {
3504 } else if (!strcmp (mimetype, "video/x-vp5")) {
3507 } else if (!strcmp (mimetype, "video/x-vp6")) {
3510 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3513 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3516 } else if (!strcmp (mimetype, "video/x-vp8")) {
3519 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3520 id = CODEC_ID_FLASHSV;
3522 } else if (!strcmp (mimetype, "video/x-indeo")) {
3523 gint indeoversion = 0;
3525 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3526 switch (indeoversion) {
3528 id = CODEC_ID_INDEO5;
3531 id = CODEC_ID_INDEO4;
3534 id = CODEC_ID_INDEO3;
3537 id = CODEC_ID_INDEO2;
3540 if (id != CODEC_ID_NONE)
3543 } else if (!strcmp (mimetype, "video/x-divx")) {
3544 gint divxversion = 0;
3546 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3547 switch (divxversion) {
3549 id = CODEC_ID_MSMPEG4V3;
3553 id = CODEC_ID_MPEG4;
3557 if (id != CODEC_ID_NONE)
3559 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3560 id = CODEC_ID_MPEG4;
3562 } else if (!strcmp (mimetype, "video/x-xvid")) {
3563 id = CODEC_ID_MPEG4;
3565 } else if (!strcmp (mimetype, "video/x-ffv")) {
3566 gint ffvversion = 0;
3568 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3573 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3574 const gchar *layout;
3576 layout = gst_structure_get_string (structure, "layout");
3577 if (layout == NULL) {
3579 } else if (!strcmp (layout, "quicktime")) {
3580 id = CODEC_ID_ADPCM_IMA_QT;
3581 } else if (!strcmp (layout, "microsoft")) {
3582 id = CODEC_ID_ADPCM_MS;
3583 } else if (!strcmp (layout, "dvi")) {
3584 id = CODEC_ID_ADPCM_IMA_WAV;
3585 } else if (!strcmp (layout, "4xm")) {
3586 id = CODEC_ID_ADPCM_4XM;
3587 } else if (!strcmp (layout, "smjpeg")) {
3588 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3589 } else if (!strcmp (layout, "dk3")) {
3590 id = CODEC_ID_ADPCM_IMA_DK3;
3591 } else if (!strcmp (layout, "dk4")) {
3592 id = CODEC_ID_ADPCM_IMA_DK4;
3593 } else if (!strcmp (layout, "westwood")) {
3594 id = CODEC_ID_ADPCM_IMA_WS;
3595 } else if (!strcmp (layout, "iss")) {
3596 id = CODEC_ID_ADPCM_IMA_ISS;
3597 } else if (!strcmp (layout, "xa")) {
3598 id = CODEC_ID_ADPCM_XA;
3599 } else if (!strcmp (layout, "adx")) {
3600 id = CODEC_ID_ADPCM_ADX;
3601 } else if (!strcmp (layout, "ea")) {
3602 id = CODEC_ID_ADPCM_EA;
3603 } else if (!strcmp (layout, "g726")) {
3604 id = CODEC_ID_ADPCM_G726;
3605 } else if (!strcmp (layout, "g721")) {
3606 id = CODEC_ID_ADPCM_G726;
3607 } else if (!strcmp (layout, "ct")) {
3608 id = CODEC_ID_ADPCM_CT;
3609 } else if (!strcmp (layout, "swf")) {
3610 id = CODEC_ID_ADPCM_SWF;
3611 } else if (!strcmp (layout, "yamaha")) {
3612 id = CODEC_ID_ADPCM_YAMAHA;
3613 } else if (!strcmp (layout, "sbpro2")) {
3614 id = CODEC_ID_ADPCM_SBPRO_2;
3615 } else if (!strcmp (layout, "sbpro3")) {
3616 id = CODEC_ID_ADPCM_SBPRO_3;
3617 } else if (!strcmp (layout, "sbpro4")) {
3618 id = CODEC_ID_ADPCM_SBPRO_4;
3620 if (id != CODEC_ID_NONE)
3622 } else if (!strcmp (mimetype, "video/x-4xm")) {
3625 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3626 const gchar *layout;
3628 layout = gst_structure_get_string (structure, "layout");
3631 } else if (!strcmp (layout, "roq")) {
3632 id = CODEC_ID_ROQ_DPCM;
3633 } else if (!strcmp (layout, "interplay")) {
3634 id = CODEC_ID_INTERPLAY_DPCM;
3635 } else if (!strcmp (layout, "xan")) {
3636 id = CODEC_ID_XAN_DPCM;
3637 } else if (!strcmp (layout, "sol")) {
3638 id = CODEC_ID_SOL_DPCM;
3640 if (id != CODEC_ID_NONE)
3642 } else if (!strcmp (mimetype, "audio/x-flac")) {
3645 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3646 id = CODEC_ID_SHORTEN;
3648 } else if (!strcmp (mimetype, "audio/x-alac")) {
3651 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3652 id = CODEC_ID_CINEPAK;
3654 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3657 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3658 switch (rmversion) {
3673 if (id != CODEC_ID_NONE)
3675 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3678 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3681 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3682 switch (raversion) {
3684 id = CODEC_ID_RA_144;
3687 id = CODEC_ID_RA_288;
3694 if (id != CODEC_ID_NONE)
3696 } else if (!strcmp (mimetype, "video/x-rle")) {
3697 const gchar *layout;
3699 if ((layout = gst_structure_get_string (structure, "layout"))) {
3700 if (!strcmp (layout, "microsoft")) {
3701 id = CODEC_ID_MSRLE;
3705 } else if (!strcmp (mimetype, "video/x-xan")) {
3708 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3709 switch (wcversion) {
3711 id = CODEC_ID_XAN_WC3;
3715 id = CODEC_ID_XAN_WC4;
3722 } else if (!strcmp (mimetype, "audio/AMR")) {
3724 id = CODEC_ID_AMR_NB;
3725 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3726 id = CODEC_ID_AMR_WB;
3728 } else if (!strcmp (mimetype, "audio/qcelp")) {
3729 id = CODEC_ID_QCELP;
3731 } else if (!strcmp (mimetype, "video/x-h264")) {
3734 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3735 gint flvversion = 0;
3737 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3738 switch (flvversion) {
3748 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3749 id = CODEC_ID_NELLYMOSER;
3751 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3755 if (strlen (mimetype) <= 30 &&
3756 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3757 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3758 (codec = avcodec_find_encoder_by_name (ext))) {
3763 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3767 if (strlen (mimetype) <= 30 &&
3768 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3769 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3770 (codec = avcodec_find_encoder_by_name (ext))) {
3777 if (context != NULL) {
3778 if (video == TRUE) {
3779 context->codec_type = AVMEDIA_TYPE_VIDEO;
3780 } else if (audio == TRUE) {
3781 context->codec_type = AVMEDIA_TYPE_AUDIO;
3783 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3785 context->codec_id = id;
3786 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3789 if (id != CODEC_ID_NONE) {
3790 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3792 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);