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 GstStructure *structure = NULL;
176 GstCaps *caps = NULL;
180 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
182 /* fixed, non probing context */
183 if (context != NULL && context->width != -1) {
186 caps = gst_caps_new_simple (mimetype,
187 "width", G_TYPE_INT, context->width,
188 "height", G_TYPE_INT, context->height, NULL);
190 num = context->time_base.den / context->ticks_per_frame;
191 denom = context->time_base.num;
194 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
197 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
198 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
202 GST_LOG ("setting framerate: %d/%d", num, denom);
203 gst_caps_set_simple (caps,
204 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
206 /* so we are after restricted caps in this case */
210 caps = gst_caps_new_simple (mimetype,
211 "width", G_TYPE_INT, 352,
212 "height", G_TYPE_INT, 288,
213 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
214 gst_caps_append (caps, gst_caps_new_simple (mimetype,
215 "width", G_TYPE_INT, 176,
216 "height", G_TYPE_INT, 144,
217 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
222 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
223 * because we want automatic negotiation to go as close to 320x240 as
225 const static gint widths[] = { 352, 704, 176, 1408, 128 };
226 const static gint heights[] = { 288, 576, 144, 1152, 96 };
228 gint n_sizes = G_N_ELEMENTS (widths);
230 caps = gst_caps_new_empty ();
231 for (i = 0; i < n_sizes; i++) {
232 temp = gst_caps_new_simple (mimetype,
233 "width", G_TYPE_INT, widths[i],
234 "height", G_TYPE_INT, heights[i],
235 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
237 gst_caps_append (caps, temp);
241 case CODEC_ID_DVVIDEO:
248 gint framerate_n, framerate_d;
251 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 10, 11, 30000, 1001}, {
252 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 40, 33, 30000, 1001}, {
253 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 59, 54, 25, 1}, {
254 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 118, 81, 25, 1}, {
255 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 59, 54, 25, 1}, {
256 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 118, 81, 25, 1}
259 gint n_sizes = G_N_ELEMENTS (profiles);
261 caps = gst_caps_new_empty ();
262 for (i = 0; i < n_sizes; i++) {
263 temp = gst_caps_new_simple (mimetype,
264 "width", G_TYPE_INT, profiles[i].width,
265 "height", G_TYPE_INT, profiles[i].height,
266 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
267 profiles[i].framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION,
268 profiles[i].par_n, profiles[i].par_d, NULL);
270 gst_caps_append (caps, temp);
276 caps = gst_caps_new_simple (mimetype,
277 "width", G_TYPE_INT, 1920,
278 "height", G_TYPE_INT, 1080,
279 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
280 gst_caps_append (caps, gst_caps_new_simple (mimetype,
281 "width", G_TYPE_INT, 1280,
282 "height", G_TYPE_INT, 720,
283 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
291 /* no fixed caps or special restrictions applied;
292 * default unfixed setting */
294 GST_DEBUG ("Creating default caps");
295 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
298 for (i = 0; i < gst_caps_get_size (caps); i++) {
299 va_start (var_args, fieldname);
300 structure = gst_caps_get_structure (caps, i);
301 gst_structure_set_valist (structure, fieldname, var_args);
309 get_nbits_set (guint64 n)
314 for (i = 0; i < 64; i++) {
315 if ((n & (G_GUINT64_CONSTANT (1) << i)))
322 /* same for audio - now with channels/sample rate
325 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
326 enum CodecID codec_id, gboolean encode, const char *mimetype,
327 const char *fieldname, ...)
329 GstCaps *caps = NULL;
333 /* fixed, non-probing context */
334 if (context != NULL && context->channels != -1) {
335 GstAudioChannelPosition pos[64];
337 caps = gst_caps_new_simple (mimetype,
338 "rate", G_TYPE_INT, context->sample_rate,
339 "channels", G_TYPE_INT, context->channels, NULL);
341 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
342 context->channels, pos)) {
345 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
347 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
352 gint maxchannels = 2;
353 const gint *rates = NULL;
356 /* so we must be after restricted caps in this case */
359 case CODEC_ID_AAC_LATM:
365 const static gint l_rates[] =
366 { 48000, 44100, 32000, 24000, 22050, 16000 };
367 n_rates = G_N_ELEMENTS (l_rates);
374 const static gint l_rates[] = { 48000, 44100, 32000 };
376 n_rates = G_N_ELEMENTS (l_rates);
380 case CODEC_ID_ADPCM_G722:
382 const static gint l_rates[] = { 16000 };
383 n_rates = G_N_ELEMENTS (l_rates);
388 case CODEC_ID_ADPCM_G726:
390 const static gint l_rates[] = { 8000 };
391 n_rates = G_N_ELEMENTS (l_rates);
396 case CODEC_ID_ADPCM_SWF:
398 const static gint l_rates[] = { 11025, 22050, 44100 };
399 n_rates = G_N_ELEMENTS (l_rates);
403 case CODEC_ID_ROQ_DPCM:
405 const static gint l_rates[] = { 22050 };
406 n_rates = G_N_ELEMENTS (l_rates);
410 case CODEC_ID_AMR_NB:
412 const static gint l_rates[] = { 8000 };
414 n_rates = G_N_ELEMENTS (l_rates);
418 case CODEC_ID_AMR_WB:
420 const static gint l_rates[] = { 16000 };
422 n_rates = G_N_ELEMENTS (l_rates);
430 /* regardless of encode/decode, open up channels if applicable */
431 /* Until decoders/encoders expose the maximum number of channels
432 * they support, we whitelist them here. */
434 case CODEC_ID_WMAPRO:
435 case CODEC_ID_TRUEHD:
442 if (codec && codec->channel_layouts) {
443 const uint64_t *layouts = codec->channel_layouts;
444 GstAudioChannelPosition pos[64];
446 caps = gst_caps_new_empty ();
448 gint nbits_set = get_nbits_set (*layouts);
450 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
453 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
456 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
458 "channels", G_TYPE_INT, nbits_set, NULL);
460 gst_caps_append (caps, tmp);
466 if (maxchannels == 1)
467 caps = gst_caps_new_simple (mimetype,
468 "channels", G_TYPE_INT, maxchannels, NULL);
470 caps = gst_caps_new_simple (mimetype,
471 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
475 GValue list = { 0, };
477 g_value_init (&list, GST_TYPE_LIST);
478 for (i = 0; i < n_rates; i++) {
481 g_value_init (&v, G_TYPE_INT);
482 g_value_set_int (&v, rates[i]);
483 gst_value_list_append_value (&list, &v);
486 gst_caps_set_value (caps, "rate", &list);
487 g_value_unset (&list);
488 } else if (codec && codec->supported_samplerates
489 && codec->supported_samplerates[0]) {
493 if (!codec->supported_samplerates[1]) {
494 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
495 codec->supported_samplerates[0], NULL);
497 const int *rates = codec->supported_samplerates;
499 g_value_init (&va, GST_TYPE_LIST);
500 g_value_init (&v, G_TYPE_INT);
503 g_value_set_int (&v, *rates);
504 gst_value_list_append_value (&va, &v);
507 gst_caps_set_value (caps, "rate", &va);
512 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
515 caps = gst_caps_new_empty_simple (mimetype);
518 va_start (var_args, fieldname);
519 gst_caps_set_simple_valist (caps, fieldname, var_args);
525 /* Convert a FFMPEG codec ID and optional AVCodecContext
526 * to a GstCaps. If the context is ommitted, no fixed values
527 * for video/audio size will be included in the GstCaps
529 * CodecID is primarily meant for compressed data GstCaps!
531 * encode is a special parameter. gstffmpegdec will say
532 * FALSE, gstffmpegenc will say TRUE. The output caps
533 * depends on this, in such a way that it will be very
534 * specific, defined, fixed and correct caps for encoders,
535 * yet very wide, "forgiving" caps for decoders. Example
536 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
537 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
542 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
543 AVCodecContext * context, gboolean encode)
545 GstCaps *caps = NULL;
546 gboolean buildcaps = FALSE;
548 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
551 case CODEC_ID_MPEG1VIDEO:
553 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
554 "mpegversion", G_TYPE_INT, 1,
555 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
558 case CODEC_ID_MPEG2VIDEO:
562 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
563 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
566 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
567 * the MPEG video stream headers, so may be omitted from caps. */
568 caps = gst_caps_new_simple ("video/mpeg",
569 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
570 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
574 case CODEC_ID_MPEG2VIDEO_XVMC:
575 /* this is a special ID - don't need it in GStreamer, I think */
581 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
582 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
583 G_TYPE_STRING, "h263", NULL);
585 /* don't pass codec_id, we can decode other variants with the H263
586 * decoder that don't have specific size requirements
589 gst_ff_vid_caps_new (context, NULL, CODEC_ID_NONE, encode,
590 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
596 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
597 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
599 if (encode && context) {
601 gst_caps_set_simple (caps,
602 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
603 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
604 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
605 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
612 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
613 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
618 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
644 /* FIXME: context->sub_id must be filled in during decoding */
646 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
647 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
648 "rmversion", G_TYPE_INT, version, NULL);
650 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
651 if (context->extradata_size >= 8) {
652 gst_caps_set_simple (caps,
653 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
662 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
663 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
668 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
669 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
676 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
677 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
679 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
680 * in the MPEG audio header, so may be omitted from caps. */
681 caps = gst_caps_new_simple ("audio/mpeg",
682 "mpegversion", G_TYPE_INT, 1,
683 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
687 case CODEC_ID_MUSEPACK7:
689 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
690 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
694 case CODEC_ID_MUSEPACK8:
696 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
697 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
704 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
711 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
715 case CODEC_ID_TRUEHD:
717 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
718 "audio/x-true-hd", NULL);
721 case CODEC_ID_ATRAC1:
723 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
724 "audio/x-vnd.sony.atrac1", NULL);
727 case CODEC_ID_ATRAC3:
729 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
730 "audio/x-vnd.sony.atrac3", NULL);
735 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
741 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
742 "audio/x-ffmpeg-parsed-ape", NULL);
744 gst_caps_set_simple (caps,
745 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
751 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
757 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
761 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
762 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
763 * sp5x is, but it's apparently something JPEG... We don't separate
764 * between those in GStreamer. Should we (at least between MJPEG,
765 * MJPEG-B and sp5x decoding...)? */
769 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
775 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
779 case CODEC_ID_MJPEGB:
781 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
782 "video/x-mjpeg-b", NULL);
786 if (encode && context != NULL) {
787 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
788 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
789 switch (context->codec_tag) {
790 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
792 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
793 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
795 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
799 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
800 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
801 "mpegversion", G_TYPE_INT, 4, NULL);
805 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
807 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
808 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
811 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
812 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
814 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
815 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
817 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
818 encode, "video/x-xvid", NULL));
819 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
820 encode, "video/x-3ivx", NULL));
825 case CODEC_ID_RAWVIDEO:
827 gst_ffmpeg_codectype_to_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
831 case CODEC_ID_MSMPEG4V1:
832 case CODEC_ID_MSMPEG4V2:
833 case CODEC_ID_MSMPEG4V3:
835 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
837 /* encode-FIXME: bitrate */
839 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
840 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
841 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
842 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
843 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
851 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
854 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
855 "wmvversion", G_TYPE_INT, version, NULL);
861 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
862 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
867 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
868 "svqversion", G_TYPE_INT, 1, NULL);
873 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
874 "svqversion", G_TYPE_INT, 3, NULL);
877 case CODEC_ID_DVAUDIO:
879 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
883 case CODEC_ID_DVVIDEO:
885 if (encode && context) {
888 switch (context->pix_fmt) {
889 case PIX_FMT_YUYV422:
892 case PIX_FMT_YUV420P:
895 case PIX_FMT_YUVA420P:
898 case PIX_FMT_YUV411P:
901 case PIX_FMT_YUV422P:
904 case PIX_FMT_YUV410P:
909 ("Couldnt' find format for pixfmt %d, defaulting to I420",
915 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
916 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
920 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
921 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
929 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
933 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
934 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
935 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
939 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
940 "wmaversion", G_TYPE_INT, version, "block_align",
941 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
946 case CODEC_ID_WMAPRO:
949 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
950 "wmaversion", G_TYPE_INT, 3, NULL);
954 case CODEC_ID_WMAVOICE:
957 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
965 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
968 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
969 "maceversion", G_TYPE_INT, version, NULL);
973 case CODEC_ID_HUFFYUV:
975 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
976 "video/x-huffyuv", NULL);
978 gst_caps_set_simple (caps,
979 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
985 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
986 "video/x-compressed-yuv", NULL);
991 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
992 "alignment", G_TYPE_STRING, "au", NULL);
995 case CODEC_ID_INDEO5:
997 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
998 "indeoversion", G_TYPE_INT, 5, NULL);
1001 case CODEC_ID_INDEO4:
1003 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1004 "indeoversion", G_TYPE_INT, 4, NULL);
1007 case CODEC_ID_INDEO3:
1009 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1010 "indeoversion", G_TYPE_INT, 3, NULL);
1013 case CODEC_ID_INDEO2:
1015 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1016 "indeoversion", G_TYPE_INT, 2, NULL);
1019 case CODEC_ID_FLASHSV:
1021 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1022 "video/x-flash-screen", NULL);
1027 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1033 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1039 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1045 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1046 "video/x-vp6-flash", NULL);
1051 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1052 "video/x-vp6-alpha", NULL);
1057 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1061 case CODEC_ID_THEORA:
1063 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1064 "video/x-theora", NULL);
1070 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1074 GValue arr = { 0, };
1075 GValue item = { 0, };
1077 g_value_init (&arr, GST_TYPE_LIST);
1078 g_value_init (&item, G_TYPE_INT);
1079 g_value_set_int (&item, 2);
1080 gst_value_list_append_value (&arr, &item);
1081 g_value_set_int (&item, 4);
1082 gst_value_list_append_value (&arr, &item);
1083 g_value_unset (&item);
1085 gst_caps_set_value (caps, "mpegversion", &arr);
1086 g_value_unset (&arr);
1088 g_value_init (&arr, GST_TYPE_LIST);
1089 g_value_init (&item, G_TYPE_STRING);
1090 g_value_set_string (&item, "raw");
1091 gst_value_list_append_value (&arr, &item);
1092 g_value_set_string (&item, "adts");
1093 gst_value_list_append_value (&arr, &item);
1094 g_value_set_string (&item, "adif");
1095 gst_value_list_append_value (&arr, &item);
1096 g_value_unset (&item);
1098 gst_caps_set_value (caps, "stream-format", &arr);
1099 g_value_unset (&arr);
1101 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1102 "stream-format", G_TYPE_STRING, "raw",
1103 "base-profile", G_TYPE_STRING, "lc", NULL);
1105 if (context && context->extradata_size > 0)
1106 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1107 context->extradata, context->extradata_size);
1112 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1113 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1114 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1120 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1121 "asusversion", G_TYPE_INT, 1, NULL);
1125 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1126 "asusversion", G_TYPE_INT, 2, NULL);
1131 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1132 "ffvversion", G_TYPE_INT, 1, NULL);
1137 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1141 case CODEC_ID_XAN_WC3:
1142 case CODEC_ID_XAN_WC4:
1144 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1145 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1150 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1151 "video/x-cirrus-logic-accupak", NULL);
1154 case CODEC_ID_FRAPS:
1156 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1162 case CODEC_ID_INTERPLAY_VIDEO:
1168 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1169 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1174 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1175 "video/x-apple-video", NULL);
1178 case CODEC_ID_CINEPAK:
1180 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1181 "video/x-cinepak", NULL);
1184 /* WS_VQA belogns here (order) */
1186 case CODEC_ID_MSRLE:
1188 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1189 "layout", G_TYPE_STRING, "microsoft", NULL);
1191 gst_caps_set_simple (caps,
1192 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1194 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1198 case CODEC_ID_QTRLE:
1200 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1201 "layout", G_TYPE_STRING, "quicktime", NULL);
1203 gst_caps_set_simple (caps,
1204 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1206 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1210 case CODEC_ID_MSVIDEO1:
1212 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1213 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1218 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1219 "wmvversion", G_TYPE_INT, 3, NULL);
1223 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1224 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1228 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1234 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1240 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1244 case CODEC_ID_TRUEMOTION1:
1246 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1247 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1249 case CODEC_ID_TRUEMOTION2:
1251 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1252 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1257 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1258 "video/x-ultimotion", NULL);
1263 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1264 "video/x-camtasia", NULL);
1266 gst_caps_set_simple (caps,
1267 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1269 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1275 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1281 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1287 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1293 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1299 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1305 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1311 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1312 "image/x-portable-anymap", NULL);
1317 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1318 "image/x-portable-graymap", NULL);
1323 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1329 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1333 case CODEC_ID_TARGA:
1335 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1341 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1345 case CODEC_ID_SUNRAST:
1347 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1348 "image/x-sun-raster", NULL);
1353 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1357 case CODEC_ID_QDRAW:
1359 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1363 case CODEC_ID_DNXHD:
1365 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1369 case CODEC_ID_PRORES:
1371 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1372 "video/x-prores", NULL);
1375 case CODEC_ID_MIMIC:
1377 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1383 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1387 case CODEC_ID_TRUESPEECH:
1389 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1390 "audio/x-truespeech", NULL);
1393 case CODEC_ID_QCELP:
1395 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1401 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1407 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1413 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1419 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1423 case CODEC_ID_LAGARITH:
1425 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1426 "video/x-lagarith", NULL);
1431 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1432 "video/x-camstudio", NULL);
1434 gst_caps_set_simple (caps,
1435 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1437 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1441 case CODEC_ID_WS_VQA:
1442 case CODEC_ID_IDCIN:
1445 case CODEC_ID_VMDVIDEO:
1446 case CODEC_ID_VMDAUDIO:
1450 case CODEC_ID_PGMYUV:
1451 case CODEC_ID_FFVHUFF:
1453 case CODEC_ID_MP3ADU:
1454 case CODEC_ID_MP3ON4:
1455 case CODEC_ID_WESTWOOD_SND1:
1456 case CODEC_ID_MMVIDEO:
1462 /* weird quasi-codecs for the demuxers only */
1463 case CODEC_ID_PCM_S16LE:
1464 case CODEC_ID_PCM_S16BE:
1465 case CODEC_ID_PCM_U16LE:
1466 case CODEC_ID_PCM_U16BE:
1467 case CODEC_ID_PCM_S8:
1468 case CODEC_ID_PCM_U8:
1470 GstAudioFormat format;
1473 case CODEC_ID_PCM_S16LE:
1474 format = GST_AUDIO_FORMAT_S16LE;
1476 case CODEC_ID_PCM_S16BE:
1477 format = GST_AUDIO_FORMAT_S16BE;
1479 case CODEC_ID_PCM_U16LE:
1480 format = GST_AUDIO_FORMAT_U16LE;
1482 case CODEC_ID_PCM_U16BE:
1483 format = GST_AUDIO_FORMAT_U16BE;
1485 case CODEC_ID_PCM_S8:
1486 format = GST_AUDIO_FORMAT_S8;
1488 case CODEC_ID_PCM_U8:
1489 format = GST_AUDIO_FORMAT_U8;
1492 g_assert (0); /* don't worry, we never get here */
1497 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1498 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1499 "layout", G_TYPE_STRING, "interleaved", NULL);
1503 case CODEC_ID_PCM_MULAW:
1505 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1509 case CODEC_ID_PCM_ALAW:
1511 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1515 case CODEC_ID_ADPCM_G722:
1517 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1520 gst_caps_set_simple (caps,
1521 "block_align", G_TYPE_INT, context->block_align,
1522 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1525 case CODEC_ID_ADPCM_G726:
1527 /* the G726 decoder can also handle G721 */
1529 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1530 "layout", G_TYPE_STRING, "g726", NULL);
1532 gst_caps_set_simple (caps,
1533 "block_align", G_TYPE_INT, context->block_align,
1534 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1537 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1538 "layout", G_TYPE_STRING, "g721",
1539 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1543 case CODEC_ID_ADPCM_IMA_QT:
1544 case CODEC_ID_ADPCM_IMA_WAV:
1545 case CODEC_ID_ADPCM_IMA_DK3:
1546 case CODEC_ID_ADPCM_IMA_DK4:
1547 case CODEC_ID_ADPCM_IMA_WS:
1548 case CODEC_ID_ADPCM_IMA_SMJPEG:
1549 case CODEC_ID_ADPCM_IMA_AMV:
1550 case CODEC_ID_ADPCM_IMA_ISS:
1551 case CODEC_ID_ADPCM_IMA_EA_EACS:
1552 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1553 case CODEC_ID_ADPCM_MS:
1554 case CODEC_ID_ADPCM_4XM:
1555 case CODEC_ID_ADPCM_XA:
1556 case CODEC_ID_ADPCM_ADX:
1557 case CODEC_ID_ADPCM_EA:
1558 case CODEC_ID_ADPCM_CT:
1559 case CODEC_ID_ADPCM_SWF:
1560 case CODEC_ID_ADPCM_YAMAHA:
1561 case CODEC_ID_ADPCM_SBPRO_2:
1562 case CODEC_ID_ADPCM_SBPRO_3:
1563 case CODEC_ID_ADPCM_SBPRO_4:
1564 case CODEC_ID_ADPCM_EA_R1:
1565 case CODEC_ID_ADPCM_EA_R2:
1566 case CODEC_ID_ADPCM_EA_R3:
1567 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1568 case CODEC_ID_ADPCM_EA_XAS:
1569 case CODEC_ID_ADPCM_THP:
1571 const gchar *layout = NULL;
1574 case CODEC_ID_ADPCM_IMA_QT:
1575 layout = "quicktime";
1577 case CODEC_ID_ADPCM_IMA_WAV:
1580 case CODEC_ID_ADPCM_IMA_DK3:
1583 case CODEC_ID_ADPCM_IMA_DK4:
1586 case CODEC_ID_ADPCM_IMA_WS:
1587 layout = "westwood";
1589 case CODEC_ID_ADPCM_IMA_SMJPEG:
1592 case CODEC_ID_ADPCM_IMA_AMV:
1595 case CODEC_ID_ADPCM_IMA_ISS:
1598 case CODEC_ID_ADPCM_IMA_EA_EACS:
1601 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1604 case CODEC_ID_ADPCM_MS:
1605 layout = "microsoft";
1607 case CODEC_ID_ADPCM_4XM:
1610 case CODEC_ID_ADPCM_XA:
1613 case CODEC_ID_ADPCM_ADX:
1616 case CODEC_ID_ADPCM_EA:
1619 case CODEC_ID_ADPCM_CT:
1622 case CODEC_ID_ADPCM_SWF:
1625 case CODEC_ID_ADPCM_YAMAHA:
1628 case CODEC_ID_ADPCM_SBPRO_2:
1631 case CODEC_ID_ADPCM_SBPRO_3:
1634 case CODEC_ID_ADPCM_SBPRO_4:
1637 case CODEC_ID_ADPCM_EA_R1:
1640 case CODEC_ID_ADPCM_EA_R2:
1643 case CODEC_ID_ADPCM_EA_R3:
1646 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1647 layout = "ea-maxis-xa";
1649 case CODEC_ID_ADPCM_EA_XAS:
1652 case CODEC_ID_ADPCM_THP:
1656 g_assert (0); /* don't worry, we never get here */
1660 /* FIXME: someone please check whether we need additional properties
1661 * in this caps definition. */
1663 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1664 "layout", G_TYPE_STRING, layout, NULL);
1666 gst_caps_set_simple (caps,
1667 "block_align", G_TYPE_INT, context->block_align,
1668 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1672 case CODEC_ID_AMR_NB:
1674 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1678 case CODEC_ID_AMR_WB:
1680 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1686 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1690 case CODEC_ID_GSM_MS:
1692 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1696 case CODEC_ID_NELLYMOSER:
1698 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1699 "audio/x-nellymoser", NULL);
1705 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1708 gst_caps_set_simple (caps,
1709 "leaf_size", G_TYPE_INT, context->block_align,
1710 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1715 case CODEC_ID_RA_144:
1716 case CODEC_ID_RA_288:
1722 case CODEC_ID_RA_144:
1725 case CODEC_ID_RA_288:
1735 /* FIXME: properties? */
1737 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1738 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1740 gst_caps_set_simple (caps,
1741 "leaf_size", G_TYPE_INT, context->block_align,
1742 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1747 case CODEC_ID_ROQ_DPCM:
1748 case CODEC_ID_INTERPLAY_DPCM:
1749 case CODEC_ID_XAN_DPCM:
1750 case CODEC_ID_SOL_DPCM:
1752 const gchar *layout = NULL;
1755 case CODEC_ID_ROQ_DPCM:
1758 case CODEC_ID_INTERPLAY_DPCM:
1759 layout = "interplay";
1761 case CODEC_ID_XAN_DPCM:
1764 case CODEC_ID_SOL_DPCM:
1768 g_assert (0); /* don't worry, we never get here */
1772 /* FIXME: someone please check whether we need additional properties
1773 * in this caps definition. */
1775 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1776 "layout", G_TYPE_STRING, layout, NULL);
1778 gst_caps_set_simple (caps,
1779 "block_align", G_TYPE_INT, context->block_align,
1780 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1784 case CODEC_ID_SHORTEN:
1785 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1790 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1793 gst_caps_set_simple (caps,
1794 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1799 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1800 * encoder case, we want to add things like samplerate, channels... */
1802 caps = gst_caps_new_empty_simple ("audio/x-flac");
1806 case CODEC_ID_DVD_SUBTITLE:
1807 case CODEC_ID_DVB_SUBTITLE:
1811 caps = gst_caps_new_empty_simple ("image/bmp");
1815 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1818 gst_caps_set_simple (caps,
1819 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1822 case CODEC_ID_TWINVQ:
1824 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1825 "audio/x-twin-vq", NULL);
1828 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1835 if ((codec = avcodec_find_decoder (codec_id)) ||
1836 (codec = avcodec_find_encoder (codec_id))) {
1839 GST_LOG ("Could not create stream format caps for %s", codec->name);
1841 switch (codec->type) {
1842 case AVMEDIA_TYPE_VIDEO:
1843 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1845 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
1848 case AVMEDIA_TYPE_AUDIO:
1849 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1851 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
1853 gst_caps_set_simple (caps,
1854 "block_align", G_TYPE_INT, context->block_align,
1855 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1866 /* set private data */
1867 if (context && context->extradata_size > 0) {
1868 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1870 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1871 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1872 gst_buffer_unref (data);
1875 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1878 GST_LOG ("No caps found for codec_id=%d", codec_id);
1884 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1885 * to a GstCaps. If the context is ommitted, no fixed values
1886 * for video/audio size will be included in the GstCaps
1888 * See below for usefullness
1892 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1893 enum CodecID codec_id)
1895 GstCaps *caps = NULL;
1896 GstVideoFormat format;
1898 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
1900 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1901 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
1902 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1906 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1908 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1915 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
1917 switch (sample_fmt) {
1918 case AV_SAMPLE_FMT_U8:
1919 case AV_SAMPLE_FMT_U8P:
1920 return GST_AUDIO_FORMAT_U8;
1922 case AV_SAMPLE_FMT_S16:
1923 case AV_SAMPLE_FMT_S16P:
1924 return GST_AUDIO_FORMAT_S16;
1926 case AV_SAMPLE_FMT_S32:
1927 case AV_SAMPLE_FMT_S32P:
1928 return GST_AUDIO_FORMAT_S32;
1930 case AV_SAMPLE_FMT_FLT:
1931 case AV_SAMPLE_FMT_FLTP:
1932 return GST_AUDIO_FORMAT_F32;
1934 case AV_SAMPLE_FMT_DBL:
1935 case AV_SAMPLE_FMT_DBLP:
1936 return GST_AUDIO_FORMAT_F64;
1940 return GST_AUDIO_FORMAT_UNKNOWN;
1945 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1946 * to a GstCaps. If the context is ommitted, no fixed values
1947 * for video/audio size will be included in the GstCaps
1949 * See below for usefullness
1953 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
1954 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
1956 GstCaps *caps = NULL;
1957 GstAudioFormat format;
1959 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
1961 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1962 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
1963 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1964 "layout", G_TYPE_STRING, "interleaved", NULL);
1965 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1967 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1974 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
1975 const enum AVSampleFormat *fmts)
1979 GstAudioFormat format;
1981 if (!fmts || fmts[0] == -1) {
1984 g_value_init (&va, GST_TYPE_LIST);
1985 g_value_init (&v, G_TYPE_STRING);
1986 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
1987 format = gst_ffmpeg_smpfmt_to_audioformat (i);
1988 if (format == GST_AUDIO_FORMAT_UNKNOWN)
1990 g_value_set_string (&v, gst_audio_format_to_string (format));
1991 gst_value_list_append_value (&va, &v);
1993 gst_caps_set_value (caps, "format", &va);
1995 g_value_unset (&va);
1999 /* Only a single format */
2000 if (fmts[1] == -1) {
2001 format = gst_ffmpeg_smpfmt_to_audioformat (fmts[0]);
2002 if (format != GST_AUDIO_FORMAT_UNKNOWN)
2003 gst_caps_set_simple (caps, "format", G_TYPE_STRING,
2004 gst_audio_format_to_string (format), NULL);
2008 g_value_init (&va, GST_TYPE_LIST);
2009 g_value_init (&v, G_TYPE_STRING);
2010 while (*fmts != -1) {
2011 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
2012 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2013 g_value_set_string (&v, gst_audio_format_to_string (format));
2014 gst_value_list_append_value (&va, &v);
2018 if (gst_value_list_get_size (&va) > 0)
2019 gst_caps_set_value (caps, "format", &va);
2021 g_value_unset (&va);
2025 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2026 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2028 GstCaps *caps = NULL;
2030 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2031 context, codec_id, encode, codec);
2033 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2034 codec->sample_fmts, codec->supported_samplerates);
2037 /* Specific codec context */
2039 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2042 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2043 "layout", G_TYPE_STRING, "interleaved", NULL);
2044 gst_ffmpeg_audio_set_sample_fmts (caps, codec ? codec->sample_fmts : NULL);
2051 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
2055 GstVideoFormat format;
2057 if (!fmts || fmts[0] == -1) {
2060 g_value_init (&va, GST_TYPE_LIST);
2061 g_value_init (&v, G_TYPE_STRING);
2062 for (i = 0; i <= PIX_FMT_NB; i++) {
2063 format = gst_ffmpeg_pixfmt_to_videoformat (i);
2064 if (format == GST_VIDEO_FORMAT_UNKNOWN)
2066 g_value_set_string (&v, gst_video_format_to_string (format));
2067 gst_value_list_append_value (&va, &v);
2069 gst_caps_set_value (caps, "format", &va);
2071 g_value_unset (&va);
2075 /* Only a single format */
2076 if (fmts[1] == -1) {
2077 format = gst_ffmpeg_pixfmt_to_videoformat (fmts[0]);
2078 if (format != GST_VIDEO_FORMAT_UNKNOWN)
2079 gst_caps_set_simple (caps, "format", G_TYPE_STRING,
2080 gst_video_format_to_string (format), NULL);
2084 g_value_init (&va, GST_TYPE_LIST);
2085 g_value_init (&v, G_TYPE_STRING);
2086 while (*fmts != -1) {
2087 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
2088 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2089 g_value_set_string (&v, gst_video_format_to_string (format));
2090 gst_value_list_append_value (&va, &v);
2094 if (gst_value_list_get_size (&va) > 0)
2095 gst_caps_set_value (caps, "format", &va);
2097 g_value_unset (&va);
2101 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2102 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2106 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2107 context, codec_id, encode, codec);
2110 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2113 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2115 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2120 /* Convert a FFMPEG codec Type and optional AVCodecContext
2121 * to a GstCaps. If the context is ommitted, no fixed values
2122 * for video/audio size will be included in the GstCaps
2124 * AVMediaType is primarily meant for uncompressed data GstCaps!
2128 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
2129 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
2133 switch (codec_type) {
2134 case AVMEDIA_TYPE_VIDEO:
2136 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
2138 case AVMEDIA_TYPE_AUDIO:
2140 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
2150 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2151 * and other audio properties in a AVCodecContext.
2153 * For usefullness, see below
2157 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2158 AVCodecContext * context, gboolean raw)
2160 GstStructure *structure;
2162 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2164 g_return_if_fail (gst_caps_get_size (caps) == 1);
2166 structure = gst_caps_get_structure (caps, 0);
2168 gst_structure_get_int (structure, "channels", &context->channels);
2169 gst_structure_get_int (structure, "rate", &context->sample_rate);
2170 gst_structure_get_int (structure, "block_align", &context->block_align);
2171 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2176 if (gst_structure_has_name (structure, "audio/x-raw")) {
2177 if ((fmt = gst_structure_get_string (structure, "format"))) {
2178 format = gst_audio_format_from_string (fmt);
2183 case GST_AUDIO_FORMAT_F32:
2184 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2186 case GST_AUDIO_FORMAT_F64:
2187 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2189 case GST_AUDIO_FORMAT_S32:
2190 context->sample_fmt = AV_SAMPLE_FMT_S32;
2192 case GST_AUDIO_FORMAT_S16:
2193 context->sample_fmt = AV_SAMPLE_FMT_S16;
2200 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2201 * and other video properties in a AVCodecContext.
2203 * For usefullness, see below
2207 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2208 AVCodecContext * context, gboolean raw)
2210 GstStructure *structure;
2212 const GValue *par = NULL;
2214 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2216 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2217 g_return_if_fail (gst_caps_get_size (caps) == 1);
2218 structure = gst_caps_get_structure (caps, 0);
2220 gst_structure_get_int (structure, "width", &context->width);
2221 gst_structure_get_int (structure, "height", &context->height);
2222 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2224 fps = gst_structure_get_value (structure, "framerate");
2225 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2227 /* somehow these seem mixed up.. */
2228 context->time_base.den = gst_value_get_fraction_numerator (fps);
2229 context->time_base.num = gst_value_get_fraction_denominator (fps);
2230 context->ticks_per_frame = 1;
2232 GST_DEBUG ("setting framerate %d/%d = %lf",
2233 context->time_base.den, context->time_base.num,
2234 1. * context->time_base.den / context->time_base.num);
2237 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2238 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2240 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2241 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2243 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2244 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2245 1. * context->sample_aspect_ratio.den /
2246 context->sample_aspect_ratio.num);
2252 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2254 if (gst_structure_has_name (structure, "video/x-raw")) {
2255 if ((fmt = gst_structure_get_string (structure, "format"))) {
2256 format = gst_video_format_from_string (fmt);
2261 case GST_VIDEO_FORMAT_YUY2:
2262 context->pix_fmt = PIX_FMT_YUYV422;
2264 case GST_VIDEO_FORMAT_I420:
2265 context->pix_fmt = PIX_FMT_YUV420P;
2267 case GST_VIDEO_FORMAT_A420:
2268 context->pix_fmt = PIX_FMT_YUVA420P;
2270 case GST_VIDEO_FORMAT_Y41B:
2271 context->pix_fmt = PIX_FMT_YUV411P;
2273 case GST_VIDEO_FORMAT_Y42B:
2274 context->pix_fmt = PIX_FMT_YUV422P;
2276 case GST_VIDEO_FORMAT_YUV9:
2277 context->pix_fmt = PIX_FMT_YUV410P;
2279 case GST_VIDEO_FORMAT_Y444:
2280 context->pix_fmt = PIX_FMT_YUV444P;
2282 case GST_VIDEO_FORMAT_GRAY8:
2283 context->pix_fmt = PIX_FMT_GRAY8;
2285 case GST_VIDEO_FORMAT_xRGB:
2286 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2287 context->pix_fmt = PIX_FMT_RGB32;
2290 case GST_VIDEO_FORMAT_BGRx:
2291 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2292 context->pix_fmt = PIX_FMT_RGB32;
2295 case GST_VIDEO_FORMAT_RGB:
2296 context->pix_fmt = PIX_FMT_RGB24;
2298 case GST_VIDEO_FORMAT_BGR:
2299 context->pix_fmt = PIX_FMT_BGR24;
2301 case GST_VIDEO_FORMAT_RGB16:
2302 context->pix_fmt = PIX_FMT_RGB565;
2304 case GST_VIDEO_FORMAT_RGB15:
2305 context->pix_fmt = PIX_FMT_RGB555;
2307 case GST_VIDEO_FORMAT_RGB8P:
2308 context->pix_fmt = PIX_FMT_PAL8;
2317 GstVideoFormat format;
2318 enum PixelFormat pixfmt;
2321 /* FIXME : FILLME */
2322 static const PixToFmt pixtofmttable[] = {
2323 /* GST_VIDEO_FORMAT_I420, */
2324 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2325 /* Note : this should use a different chroma placement */
2326 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2328 /* GST_VIDEO_FORMAT_YV12, */
2329 /* GST_VIDEO_FORMAT_YUY2, */
2330 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2331 /* GST_VIDEO_FORMAT_UYVY, */
2332 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2333 /* GST_VIDEO_FORMAT_AYUV, */
2334 /* GST_VIDEO_FORMAT_RGBx, */
2335 /* GST_VIDEO_FORMAT_BGRx, */
2336 /* GST_VIDEO_FORMAT_xRGB, */
2337 /* GST_VIDEO_FORMAT_xBGR, */
2338 /* GST_VIDEO_FORMAT_RGBA, */
2339 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2340 /* GST_VIDEO_FORMAT_BGRA, */
2341 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2342 /* GST_VIDEO_FORMAT_ARGB, */
2343 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2344 /* GST_VIDEO_FORMAT_ABGR, */
2345 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2346 /* GST_VIDEO_FORMAT_RGB, */
2347 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2348 /* GST_VIDEO_FORMAT_BGR, */
2349 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2350 /* GST_VIDEO_FORMAT_Y41B, */
2351 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2352 /* GST_VIDEO_FORMAT_Y42B, */
2353 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2354 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2355 /* GST_VIDEO_FORMAT_YVYU, */
2356 /* GST_VIDEO_FORMAT_Y444, */
2357 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2358 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2359 /* GST_VIDEO_FORMAT_v210, */
2360 /* GST_VIDEO_FORMAT_v216, */
2361 /* GST_VIDEO_FORMAT_NV12, */
2362 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2363 /* GST_VIDEO_FORMAT_NV21, */
2364 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2365 /* GST_VIDEO_FORMAT_GRAY8, */
2366 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2367 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2368 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2369 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2370 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2371 /* GST_VIDEO_FORMAT_v308, */
2372 /* GST_VIDEO_FORMAT_Y800, */
2373 /* GST_VIDEO_FORMAT_Y16, */
2374 /* GST_VIDEO_FORMAT_RGB16, */
2375 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2376 /* GST_VIDEO_FORMAT_BGR16, */
2377 /* GST_VIDEO_FORMAT_RGB15, */
2378 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2379 /* GST_VIDEO_FORMAT_BGR15, */
2380 /* GST_VIDEO_FORMAT_UYVP, */
2381 /* GST_VIDEO_FORMAT_A420, */
2382 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2383 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2384 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2385 /* GST_VIDEO_FORMAT_YUV9, */
2386 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2387 /* GST_VIDEO_FORMAT_YVU9, */
2388 /* GST_VIDEO_FORMAT_IYU1, */
2389 /* GST_VIDEO_FORMAT_ARGB64, */
2390 /* GST_VIDEO_FORMAT_AYUV64, */
2391 /* GST_VIDEO_FORMAT_r210, */
2392 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2393 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2394 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2395 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2396 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2397 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2398 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2399 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2400 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2404 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2408 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2409 if (pixtofmttable[i].pixfmt == pixfmt)
2410 return pixtofmttable[i].format;
2412 GST_WARNING ("Unknown pixel format %d", pixfmt);
2413 return GST_VIDEO_FORMAT_UNKNOWN;
2417 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2421 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2422 if (pixtofmttable[i].format == format)
2423 return pixtofmttable[i].pixfmt;
2424 return PIX_FMT_NONE;
2428 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2432 context->width = GST_VIDEO_INFO_WIDTH (info);
2433 context->height = GST_VIDEO_INFO_HEIGHT (info);
2434 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2435 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2436 context->bits_per_coded_sample = bpp;
2438 context->ticks_per_frame = 1;
2439 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2440 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2442 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2443 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2446 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2450 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2452 const AVCodec *codec;
2453 const enum AVSampleFormat *smpl_fmts;
2454 enum AVSampleFormat smpl_fmt = -1;
2456 context->channels = info->channels;
2457 context->sample_rate = info->rate;
2458 context->channel_layout =
2459 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2461 codec = context->codec;
2463 smpl_fmts = codec->sample_fmts;
2465 switch (info->finfo->format) {
2466 case GST_AUDIO_FORMAT_F32:
2468 while (*smpl_fmts != -1) {
2469 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2470 smpl_fmt = *smpl_fmts;
2472 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2473 smpl_fmt = *smpl_fmts;
2479 smpl_fmt = AV_SAMPLE_FMT_FLT;
2482 case GST_AUDIO_FORMAT_F64:
2484 while (*smpl_fmts != -1) {
2485 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2486 smpl_fmt = *smpl_fmts;
2488 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2489 smpl_fmt = *smpl_fmts;
2495 smpl_fmt = AV_SAMPLE_FMT_DBL;
2498 case GST_AUDIO_FORMAT_S32:
2500 while (*smpl_fmts != -1) {
2501 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2502 smpl_fmt = *smpl_fmts;
2504 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2505 smpl_fmt = *smpl_fmts;
2511 smpl_fmt = AV_SAMPLE_FMT_S32;
2514 case GST_AUDIO_FORMAT_S16:
2516 while (*smpl_fmts != -1) {
2517 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2518 smpl_fmt = *smpl_fmts;
2520 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2521 smpl_fmt = *smpl_fmts;
2527 smpl_fmt = AV_SAMPLE_FMT_S16;
2530 case GST_AUDIO_FORMAT_U8:
2532 while (*smpl_fmts != -1) {
2533 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2534 smpl_fmt = *smpl_fmts;
2536 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2537 smpl_fmt = *smpl_fmts;
2543 smpl_fmt = AV_SAMPLE_FMT_U8;
2550 g_assert (smpl_fmt != -1);
2552 context->sample_fmt = smpl_fmt;
2555 /* Convert a GstCaps and a FFMPEG codec Type to a
2556 * AVCodecContext. If the context is ommitted, no fixed values
2557 * for video/audio size will be included in the context
2559 * AVMediaType is primarily meant for uncompressed data GstCaps!
2563 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2564 const GstCaps * caps, AVCodecContext * context)
2566 if (context == NULL)
2570 case AVMEDIA_TYPE_VIDEO:
2571 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2574 case AVMEDIA_TYPE_AUDIO:
2575 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2586 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2590 guint8 *end = src + size;
2593 while (srcp < end) {
2594 if (count == 2 && *srcp <= 0x03) {
2595 GST_DEBUG ("added escape code");
2604 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2607 *destsize = dstp - dst;
2610 /* copy the config, escaping NAL units as we iterate them, if something fails we
2611 * copy everything and hope for the best. */
2613 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2618 guint nalsize, esize;
2628 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2630 GST_DEBUG ("num SPS %d", cnt);
2632 memcpy (dstp, srcp, 6);
2636 for (i = 0; i < cnt; i++) {
2637 GST_DEBUG ("copy SPS %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;
2646 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2648 GST_DEBUG ("num PPS %d", cnt);
2650 for (i = 0; i < cnt; i++) {
2651 GST_DEBUG ("copy PPS %d", i);
2652 nalsize = (srcp[0] << 8) | srcp[1];
2653 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2654 dstp[0] = esize >> 8;
2655 dstp[1] = esize & 0xff;
2657 srcp += nalsize + 2;
2659 *destsize = dstp - dst;
2665 GST_DEBUG ("something unexpected, doing full copy");
2666 memcpy (dst, src, size);
2674 * caps_with_codecid () transforms a GstCaps for a known codec
2675 * ID into a filled-in context.
2676 * codec_data from caps will override possible extradata already in the context
2680 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2681 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2684 const GValue *value;
2687 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2688 codec_id, codec_type, caps, context);
2690 if (!context || !gst_caps_get_size (caps))
2693 str = gst_caps_get_structure (caps, 0);
2695 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2696 if ((value = gst_structure_get_value (str, "codec_data"))) {
2699 buf = gst_value_get_buffer (value);
2700 gst_buffer_map (buf, &map, GST_MAP_READ);
2702 /* free the old one if it is there */
2703 if (context->extradata)
2704 av_free (context->extradata);
2707 if (codec_id == CODEC_ID_H264) {
2710 GST_DEBUG ("copy, escaping codec_data %d", size);
2711 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2712 * reason for this but let's just escape it for now. Start by allocating
2713 * enough space, x2 is more than enough.
2715 * FIXME, we disabled escaping because some file already contain escaped
2716 * codec_data and then we escape twice and fail. It's better to leave it
2717 * as is, as that is what most players do. */
2718 context->extradata =
2719 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2720 FF_INPUT_BUFFER_PADDING_SIZE));
2721 copy_config (context->extradata, data, size, &extrasize);
2722 GST_DEBUG ("escaped size: %d", extrasize);
2723 context->extradata_size = extrasize;
2727 /* allocate with enough padding */
2728 GST_DEBUG ("copy codec_data");
2729 context->extradata =
2730 av_mallocz (GST_ROUND_UP_16 (map.size +
2731 FF_INPUT_BUFFER_PADDING_SIZE));
2732 memcpy (context->extradata, map.data, map.size);
2733 context->extradata_size = map.size;
2736 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2737 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2738 context->extradata[0] = (guint8) map.size;
2741 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2743 gst_buffer_unmap (buf, &map);
2744 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2745 codec_id != CODEC_ID_FLAC) {
2746 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2747 * extradata anyway which makes then segfault. */
2748 context->extradata =
2749 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2750 context->extradata_size = 0;
2751 GST_DEBUG ("no codec data");
2755 case CODEC_ID_MPEG4:
2757 const gchar *mime = gst_structure_get_name (str);
2759 if (!strcmp (mime, "video/x-divx"))
2760 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2761 else if (!strcmp (mime, "video/x-xvid"))
2762 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2763 else if (!strcmp (mime, "video/x-3ivx"))
2764 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2765 else if (!strcmp (mime, "video/mpeg"))
2766 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2771 /* FIXME: this is a workaround for older gst-plugins releases
2772 * (<= 0.8.9). This should be removed at some point, because
2773 * it causes wrong decoded frame order. */
2774 if (!context->extradata) {
2775 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2778 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2779 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2780 gst_structure_get_int (str, "low_delay", &low_delay) ||
2781 gst_structure_get_int (str, "unknown_svq3_flag",
2782 &unknown_svq3_flag)) {
2783 context->extradata = (guint8 *) av_mallocz (0x64);
2784 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2788 flags |= unknown_svq3_flag;
2790 flags |= halfpel_flag;
2792 flags |= thirdpel_flag;
2795 flags = GUINT16_FROM_LE (flags);
2797 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2798 context->extradata_size = 0x64;
2803 case CODEC_ID_MSRLE:
2804 case CODEC_ID_QTRLE:
2811 if (gst_structure_get_int (str, "depth", &depth)) {
2812 context->bits_per_coded_sample = depth;
2814 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2827 if (gst_structure_get_int (str, "format", &format))
2828 context->sub_id = format;
2833 case CODEC_ID_RA_288:
2834 case CODEC_ID_RA_144:
2840 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2841 context->block_align = leaf_size;
2842 if (gst_structure_get_int (str, "bitrate", &bitrate))
2843 context->bit_rate = bitrate;
2846 gst_structure_get_int (str, "samplesize",
2847 &context->bits_per_coded_sample);
2850 case CODEC_ID_DVVIDEO:
2852 const gchar *format;
2854 if ((format = gst_structure_get_string (str, "format"))) {
2856 if (g_str_equal (format, "YUY2"))
2857 context->pix_fmt = PIX_FMT_YUYV422;
2858 else if (g_str_equal (format, "I420"))
2859 context->pix_fmt = PIX_FMT_YUV420P;
2860 else if (g_str_equal (format, "A420"))
2861 context->pix_fmt = PIX_FMT_YUVA420P;
2862 else if (g_str_equal (format, "Y41B"))
2863 context->pix_fmt = PIX_FMT_YUV411P;
2864 else if (g_str_equal (format, "Y42B"))
2865 context->pix_fmt = PIX_FMT_YUV422P;
2866 else if (g_str_equal (format, "YUV9"))
2867 context->pix_fmt = PIX_FMT_YUV410P;
2869 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2873 GST_WARNING ("No specified format");
2876 case CODEC_ID_H263P:
2880 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2881 context->flags |= CODEC_FLAG_4MV;
2883 context->flags &= ~CODEC_FLAG_4MV;
2884 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2885 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2886 context->flags |= CODEC_FLAG_AC_PRED;
2888 context->flags &= ~CODEC_FLAG_AC_PRED;
2889 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2890 context->flags |= CODEC_FLAG_LOOP_FILTER;
2892 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2895 case CODEC_ID_ADPCM_G726:
2897 const gchar *layout;
2899 if ((layout = gst_structure_get_string (str, "layout"))) {
2900 if (!strcmp (layout, "g721")) {
2901 context->sample_rate = 8000;
2902 context->channels = 1;
2903 context->bit_rate = 32000;
2912 if (!gst_caps_is_fixed (caps))
2915 /* common properties (width, height, fps) */
2916 switch (codec_type) {
2917 case AVMEDIA_TYPE_VIDEO:
2918 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2920 case AVMEDIA_TYPE_AUDIO:
2921 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2927 /* fixup of default settings */
2929 case CODEC_ID_QCELP:
2930 /* QCELP is always mono, no matter what the caps say */
2931 context->channels = 1;
2938 /* _formatid_to_caps () is meant for muxers/demuxers, it
2939 * transforms a name (ffmpeg way of ID'ing these, why don't
2940 * they have unique numerical IDs?) to the corresponding
2941 * caps belonging to that mux-format
2943 * Note: we don't need any additional info because the caps
2944 * isn't supposed to contain any useful info besides the
2949 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2951 GstCaps *caps = NULL;
2953 if (!strcmp (format_name, "mpeg")) {
2954 caps = gst_caps_new_simple ("video/mpeg",
2955 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2956 } else if (!strcmp (format_name, "mpegts")) {
2957 caps = gst_caps_new_simple ("video/mpegts",
2958 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2959 } else if (!strcmp (format_name, "rm")) {
2960 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2961 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2962 } else if (!strcmp (format_name, "asf")) {
2963 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2964 } else if (!strcmp (format_name, "avi")) {
2965 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2966 } else if (!strcmp (format_name, "wav")) {
2967 caps = gst_caps_new_empty_simple ("audio/x-wav");
2968 } else if (!strcmp (format_name, "ape")) {
2969 caps = gst_caps_new_empty_simple ("application/x-ape");
2970 } else if (!strcmp (format_name, "swf")) {
2971 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2972 } else if (!strcmp (format_name, "au")) {
2973 caps = gst_caps_new_empty_simple ("audio/x-au");
2974 } else if (!strcmp (format_name, "dv")) {
2975 caps = gst_caps_new_simple ("video/x-dv",
2976 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2977 } else if (!strcmp (format_name, "4xm")) {
2978 caps = gst_caps_new_empty_simple ("video/x-4xm");
2979 } else if (!strcmp (format_name, "matroska")) {
2980 caps = gst_caps_new_empty_simple ("video/x-matroska");
2981 } else if (!strcmp (format_name, "mp3")) {
2982 caps = gst_caps_new_empty_simple ("application/x-id3");
2983 } else if (!strcmp (format_name, "flic")) {
2984 caps = gst_caps_new_empty_simple ("video/x-fli");
2985 } else if (!strcmp (format_name, "flv")) {
2986 caps = gst_caps_new_empty_simple ("video/x-flv");
2987 } else if (!strcmp (format_name, "tta")) {
2988 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
2989 } else if (!strcmp (format_name, "aiff")) {
2990 caps = gst_caps_new_empty_simple ("audio/x-aiff");
2991 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2993 gst_caps_from_string
2994 ("application/x-3gp; video/quicktime; audio/x-m4a");
2995 } else if (!strcmp (format_name, "mov")) {
2996 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2997 } else if (!strcmp (format_name, "mp4")) {
2998 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2999 } else if (!strcmp (format_name, "3gp")) {
3000 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3001 } else if (!strcmp (format_name, "3g2")) {
3002 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3003 } else if (!strcmp (format_name, "psp")) {
3004 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3005 } else if (!strcmp (format_name, "ipod")) {
3006 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3007 } else if (!strcmp (format_name, "aac")) {
3008 caps = gst_caps_new_simple ("audio/mpeg",
3009 "mpegversion", G_TYPE_INT, 4, NULL);
3010 } else if (!strcmp (format_name, "gif")) {
3011 caps = gst_caps_from_string ("image/gif");
3012 } else if (!strcmp (format_name, "ogg")) {
3013 caps = gst_caps_from_string ("application/ogg");
3014 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3015 caps = gst_caps_from_string ("application/mxf");
3016 } else if (!strcmp (format_name, "gxf")) {
3017 caps = gst_caps_from_string ("application/gxf");
3018 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3019 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3020 "y4mversion", G_TYPE_INT, 2, NULL);
3021 } else if (!strcmp (format_name, "mpc")) {
3022 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3023 } else if (!strcmp (format_name, "vqf")) {
3024 caps = gst_caps_from_string ("audio/x-vqf");
3025 } else if (!strcmp (format_name, "nsv")) {
3026 caps = gst_caps_from_string ("video/x-nsv");
3027 } else if (!strcmp (format_name, "amr")) {
3028 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3029 } else if (!strcmp (format_name, "webm")) {
3030 caps = gst_caps_from_string ("video/webm");
3031 } else if (!strcmp (format_name, "voc")) {
3032 caps = gst_caps_from_string ("audio/x-voc");
3036 GST_LOG ("Could not create stream format caps for %s", format_name);
3037 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3038 caps = gst_caps_new_empty_simple (name);
3046 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3047 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3048 AVOutputFormat * plugin)
3050 static enum CodecID tmp_vlist[] = {
3054 static enum CodecID tmp_alist[] = {
3059 GST_LOG ("format_name : %s", format_name);
3061 if (!strcmp (format_name, "mp4")) {
3062 static enum CodecID mp4_video_list[] = {
3063 CODEC_ID_MPEG4, CODEC_ID_H264,
3067 static enum CodecID mp4_audio_list[] = {
3068 CODEC_ID_AAC, CODEC_ID_MP3,
3072 *video_codec_list = mp4_video_list;
3073 *audio_codec_list = mp4_audio_list;
3074 } else if (!strcmp (format_name, "mpeg")) {
3075 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
3076 CODEC_ID_MPEG2VIDEO,
3080 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
3086 *video_codec_list = mpeg_video_list;
3087 *audio_codec_list = mpeg_audio_list;
3088 } else if (!strcmp (format_name, "dvd")) {
3089 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
3092 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
3099 *video_codec_list = mpeg_video_list;
3100 *audio_codec_list = mpeg_audio_list;
3101 } else if (!strcmp (format_name, "mpegts")) {
3102 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
3103 CODEC_ID_MPEG2VIDEO,
3107 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
3115 *video_codec_list = mpegts_video_list;
3116 *audio_codec_list = mpegts_audio_list;
3117 } else if (!strcmp (format_name, "vob")) {
3118 static enum CodecID vob_video_list[] =
3119 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
3120 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
3121 CODEC_ID_DTS, CODEC_ID_NONE
3124 *video_codec_list = vob_video_list;
3125 *audio_codec_list = vob_audio_list;
3126 } else if (!strcmp (format_name, "flv")) {
3127 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
3128 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
3130 *video_codec_list = flv_video_list;
3131 *audio_codec_list = flv_audio_list;
3132 } else if (!strcmp (format_name, "asf")) {
3133 static enum CodecID asf_video_list[] =
3134 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
3135 static enum CodecID asf_audio_list[] =
3136 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
3138 *video_codec_list = asf_video_list;
3139 *audio_codec_list = asf_audio_list;
3140 } else if (!strcmp (format_name, "dv")) {
3141 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
3142 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
3144 *video_codec_list = dv_video_list;
3145 *audio_codec_list = dv_audio_list;
3146 } else if (!strcmp (format_name, "mov")) {
3147 static enum CodecID mov_video_list[] = {
3148 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
3149 CODEC_ID_H263, CODEC_ID_H263P,
3150 CODEC_ID_H264, CODEC_ID_DVVIDEO,
3154 static enum CodecID mov_audio_list[] = {
3155 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
3156 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
3157 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3158 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
3159 CODEC_ID_MP3, CODEC_ID_NONE
3162 *video_codec_list = mov_video_list;
3163 *audio_codec_list = mov_audio_list;
3164 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3165 static enum CodecID tgp_video_list[] = {
3166 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
3169 static enum CodecID tgp_audio_list[] = {
3170 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3175 *video_codec_list = tgp_video_list;
3176 *audio_codec_list = tgp_audio_list;
3177 } else if (!strcmp (format_name, "mmf")) {
3178 static enum CodecID mmf_audio_list[] = {
3179 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
3181 *video_codec_list = NULL;
3182 *audio_codec_list = mmf_audio_list;
3183 } else if (!strcmp (format_name, "amr")) {
3184 static enum CodecID amr_audio_list[] = {
3185 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3188 *video_codec_list = NULL;
3189 *audio_codec_list = amr_audio_list;
3190 } else if (!strcmp (format_name, "gif")) {
3191 static enum CodecID gif_image_list[] = {
3192 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
3194 *video_codec_list = gif_image_list;
3195 *audio_codec_list = NULL;
3196 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
3197 (plugin->video_codec != CODEC_ID_NONE)) {
3198 tmp_vlist[0] = plugin->video_codec;
3199 tmp_alist[0] = plugin->audio_codec;
3201 *video_codec_list = tmp_vlist;
3202 *audio_codec_list = tmp_alist;
3204 GST_LOG ("Format %s not found", format_name);
3211 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3212 * are omitted, that can be queried by the user itself,
3213 * we're not eating the GstCaps or anything
3214 * A pointer to an allocated context is also needed for
3215 * optional extra info
3219 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3221 enum CodecID id = CODEC_ID_NONE;
3222 const gchar *mimetype;
3223 const GstStructure *structure;
3224 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3226 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3227 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3228 structure = gst_caps_get_structure (caps, 0);
3230 mimetype = gst_structure_get_name (structure);
3232 if (!strcmp (mimetype, "video/x-raw")) {
3233 id = CODEC_ID_RAWVIDEO;
3235 } else if (!strcmp (mimetype, "audio/x-raw")) {
3238 if (gst_audio_info_from_caps (&info, caps)) {
3239 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3240 case GST_AUDIO_FORMAT_S8:
3241 id = CODEC_ID_PCM_S8;
3243 case GST_AUDIO_FORMAT_U8:
3244 id = CODEC_ID_PCM_U8;
3246 case GST_AUDIO_FORMAT_S16LE:
3247 id = CODEC_ID_PCM_S16LE;
3249 case GST_AUDIO_FORMAT_S16BE:
3250 id = CODEC_ID_PCM_S16BE;
3252 case GST_AUDIO_FORMAT_U16LE:
3253 id = CODEC_ID_PCM_U16LE;
3255 case GST_AUDIO_FORMAT_U16BE:
3256 id = CODEC_ID_PCM_U16BE;
3261 if (id != CODEC_ID_NONE)
3264 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3265 id = CODEC_ID_PCM_MULAW;
3267 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3268 id = CODEC_ID_PCM_ALAW;
3270 } else if (!strcmp (mimetype, "video/x-dv")) {
3273 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3275 id = CODEC_ID_DVVIDEO;
3278 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3279 id = CODEC_ID_DVAUDIO;
3281 } else if (!strcmp (mimetype, "video/x-h263")) {
3282 const gchar *h263version =
3283 gst_structure_get_string (structure, "h263version");
3284 if (h263version && !strcmp (h263version, "h263p"))
3285 id = CODEC_ID_H263P;
3289 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3290 id = CODEC_ID_H263I;
3292 } else if (!strcmp (mimetype, "video/x-h261")) {
3295 } else if (!strcmp (mimetype, "video/mpeg")) {
3299 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3300 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3302 switch (mpegversion) {
3304 id = CODEC_ID_MPEG1VIDEO;
3307 id = CODEC_ID_MPEG2VIDEO;
3310 id = CODEC_ID_MPEG4;
3314 if (id != CODEC_ID_NONE)
3316 } else if (!strcmp (mimetype, "image/jpeg")) {
3317 id = CODEC_ID_MJPEG; /* A... B... */
3319 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3320 id = CODEC_ID_MJPEGB;
3322 } else if (!strcmp (mimetype, "video/x-wmv")) {
3323 gint wmvversion = 0;
3325 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3326 switch (wmvversion) {
3335 const gchar *format;
3337 /* WMV3 unless the fourcc exists and says otherwise */
3340 if ((format = gst_structure_get_string (structure, "format")) &&
3341 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3348 if (id != CODEC_ID_NONE)
3350 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3351 id = CODEC_ID_VORBIS;
3353 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3356 } else if (!strcmp (mimetype, "audio/mpeg")) {
3358 gint mpegversion = 0;
3360 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3361 switch (mpegversion) {
3362 case 2: /* ffmpeg uses faad for both... */
3367 if (gst_structure_get_int (structure, "layer", &layer)) {
3382 if (id != CODEC_ID_NONE)
3384 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3385 gint streamversion = -1;
3387 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3388 if (streamversion == 7)
3389 id = CODEC_ID_MUSEPACK7;
3391 id = CODEC_ID_MUSEPACK7;
3393 } else if (!strcmp (mimetype, "audio/x-wma")) {
3394 gint wmaversion = 0;
3396 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3397 switch (wmaversion) {
3399 id = CODEC_ID_WMAV1;
3402 id = CODEC_ID_WMAV2;
3405 id = CODEC_ID_WMAPRO;
3409 if (id != CODEC_ID_NONE)
3411 } else if (!strcmp (mimetype, "audio/x-wms")) {
3412 id = CODEC_ID_WMAVOICE;
3414 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3417 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3420 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3421 !strcmp (mimetype, "audio/atrac3")) {
3422 id = CODEC_ID_ATRAC3;
3424 } else if (!strcmp (mimetype, "audio/x-dts")) {
3427 } else if (!strcmp (mimetype, "application/x-ape")) {
3430 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3431 gint msmpegversion = 0;
3433 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3434 switch (msmpegversion) {
3436 id = CODEC_ID_MSMPEG4V1;
3439 id = CODEC_ID_MSMPEG4V2;
3442 id = CODEC_ID_MSMPEG4V3;
3446 if (id != CODEC_ID_NONE)
3448 } else if (!strcmp (mimetype, "video/x-svq")) {
3449 gint svqversion = 0;
3451 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3452 switch (svqversion) {
3461 if (id != CODEC_ID_NONE)
3463 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3464 id = CODEC_ID_HUFFYUV;
3466 } else if (!strcmp (mimetype, "audio/x-mace")) {
3467 gint maceversion = 0;
3469 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3470 switch (maceversion) {
3472 id = CODEC_ID_MACE3;
3475 id = CODEC_ID_MACE6;
3479 if (id != CODEC_ID_NONE)
3481 } else if (!strcmp (mimetype, "video/x-theora")) {
3482 id = CODEC_ID_THEORA;
3484 } else if (!strcmp (mimetype, "video/x-vp3")) {
3487 } else if (!strcmp (mimetype, "video/x-vp5")) {
3490 } else if (!strcmp (mimetype, "video/x-vp6")) {
3493 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3496 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3499 } else if (!strcmp (mimetype, "video/x-vp8")) {
3502 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3503 id = CODEC_ID_FLASHSV;
3505 } else if (!strcmp (mimetype, "video/x-indeo")) {
3506 gint indeoversion = 0;
3508 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3509 switch (indeoversion) {
3511 id = CODEC_ID_INDEO5;
3514 id = CODEC_ID_INDEO4;
3517 id = CODEC_ID_INDEO3;
3520 id = CODEC_ID_INDEO2;
3523 if (id != CODEC_ID_NONE)
3526 } else if (!strcmp (mimetype, "video/x-divx")) {
3527 gint divxversion = 0;
3529 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3530 switch (divxversion) {
3532 id = CODEC_ID_MSMPEG4V3;
3536 id = CODEC_ID_MPEG4;
3540 if (id != CODEC_ID_NONE)
3542 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3543 id = CODEC_ID_MPEG4;
3545 } else if (!strcmp (mimetype, "video/x-xvid")) {
3546 id = CODEC_ID_MPEG4;
3548 } else if (!strcmp (mimetype, "video/x-ffv")) {
3549 gint ffvversion = 0;
3551 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3556 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3557 const gchar *layout;
3559 layout = gst_structure_get_string (structure, "layout");
3560 if (layout == NULL) {
3562 } else if (!strcmp (layout, "quicktime")) {
3563 id = CODEC_ID_ADPCM_IMA_QT;
3564 } else if (!strcmp (layout, "microsoft")) {
3565 id = CODEC_ID_ADPCM_MS;
3566 } else if (!strcmp (layout, "dvi")) {
3567 id = CODEC_ID_ADPCM_IMA_WAV;
3568 } else if (!strcmp (layout, "4xm")) {
3569 id = CODEC_ID_ADPCM_4XM;
3570 } else if (!strcmp (layout, "smjpeg")) {
3571 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3572 } else if (!strcmp (layout, "dk3")) {
3573 id = CODEC_ID_ADPCM_IMA_DK3;
3574 } else if (!strcmp (layout, "dk4")) {
3575 id = CODEC_ID_ADPCM_IMA_DK4;
3576 } else if (!strcmp (layout, "westwood")) {
3577 id = CODEC_ID_ADPCM_IMA_WS;
3578 } else if (!strcmp (layout, "iss")) {
3579 id = CODEC_ID_ADPCM_IMA_ISS;
3580 } else if (!strcmp (layout, "xa")) {
3581 id = CODEC_ID_ADPCM_XA;
3582 } else if (!strcmp (layout, "adx")) {
3583 id = CODEC_ID_ADPCM_ADX;
3584 } else if (!strcmp (layout, "ea")) {
3585 id = CODEC_ID_ADPCM_EA;
3586 } else if (!strcmp (layout, "g726")) {
3587 id = CODEC_ID_ADPCM_G726;
3588 } else if (!strcmp (layout, "g721")) {
3589 id = CODEC_ID_ADPCM_G726;
3590 } else if (!strcmp (layout, "ct")) {
3591 id = CODEC_ID_ADPCM_CT;
3592 } else if (!strcmp (layout, "swf")) {
3593 id = CODEC_ID_ADPCM_SWF;
3594 } else if (!strcmp (layout, "yamaha")) {
3595 id = CODEC_ID_ADPCM_YAMAHA;
3596 } else if (!strcmp (layout, "sbpro2")) {
3597 id = CODEC_ID_ADPCM_SBPRO_2;
3598 } else if (!strcmp (layout, "sbpro3")) {
3599 id = CODEC_ID_ADPCM_SBPRO_3;
3600 } else if (!strcmp (layout, "sbpro4")) {
3601 id = CODEC_ID_ADPCM_SBPRO_4;
3603 if (id != CODEC_ID_NONE)
3605 } else if (!strcmp (mimetype, "video/x-4xm")) {
3608 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3609 const gchar *layout;
3611 layout = gst_structure_get_string (structure, "layout");
3614 } else if (!strcmp (layout, "roq")) {
3615 id = CODEC_ID_ROQ_DPCM;
3616 } else if (!strcmp (layout, "interplay")) {
3617 id = CODEC_ID_INTERPLAY_DPCM;
3618 } else if (!strcmp (layout, "xan")) {
3619 id = CODEC_ID_XAN_DPCM;
3620 } else if (!strcmp (layout, "sol")) {
3621 id = CODEC_ID_SOL_DPCM;
3623 if (id != CODEC_ID_NONE)
3625 } else if (!strcmp (mimetype, "audio/x-flac")) {
3628 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3629 id = CODEC_ID_SHORTEN;
3631 } else if (!strcmp (mimetype, "audio/x-alac")) {
3634 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3635 id = CODEC_ID_CINEPAK;
3637 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3640 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3641 switch (rmversion) {
3656 if (id != CODEC_ID_NONE)
3658 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3661 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3664 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3665 switch (raversion) {
3667 id = CODEC_ID_RA_144;
3670 id = CODEC_ID_RA_288;
3677 if (id != CODEC_ID_NONE)
3679 } else if (!strcmp (mimetype, "video/x-rle")) {
3680 const gchar *layout;
3682 if ((layout = gst_structure_get_string (structure, "layout"))) {
3683 if (!strcmp (layout, "microsoft")) {
3684 id = CODEC_ID_MSRLE;
3688 } else if (!strcmp (mimetype, "video/x-xan")) {
3691 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3692 switch (wcversion) {
3694 id = CODEC_ID_XAN_WC3;
3698 id = CODEC_ID_XAN_WC4;
3705 } else if (!strcmp (mimetype, "audio/AMR")) {
3707 id = CODEC_ID_AMR_NB;
3708 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3709 id = CODEC_ID_AMR_WB;
3711 } else if (!strcmp (mimetype, "audio/qcelp")) {
3712 id = CODEC_ID_QCELP;
3714 } else if (!strcmp (mimetype, "video/x-h264")) {
3717 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3718 gint flvversion = 0;
3720 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3721 switch (flvversion) {
3731 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3732 id = CODEC_ID_NELLYMOSER;
3734 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3738 if (strlen (mimetype) <= 30 &&
3739 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3740 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3741 (codec = avcodec_find_encoder_by_name (ext))) {
3746 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3750 if (strlen (mimetype) <= 30 &&
3751 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3752 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3753 (codec = avcodec_find_encoder_by_name (ext))) {
3760 if (context != NULL) {
3761 if (video == TRUE) {
3762 context->codec_type = AVMEDIA_TYPE_VIDEO;
3763 } else if (audio == TRUE) {
3764 context->codec_type = AVMEDIA_TYPE_AUDIO;
3766 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3768 context->codec_id = id;
3769 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3772 if (id != CODEC_ID_NONE) {
3773 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3775 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);