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_layout_to_gst (guint64 channel_layout, gint channels,
71 GstAudioChannelPosition * pos)
74 gboolean none_layout = FALSE;
76 if (channel_layout == 0) {
82 for (i = 0; i < 64; i++) {
83 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
88 if (nchannels != channels) {
89 GST_ERROR ("Number of channels is different (%u != %u)", channels,
95 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
96 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
97 pos[j++] = _ff_to_gst_layout[i].gst;
99 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
104 if (j != nchannels) {
106 ("Unknown channels in channel layout - assuming NONE layout");
113 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
114 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
115 " - assuming NONE layout", channel_layout);
120 if (nchannels == 1) {
121 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
122 } else if (nchannels == 2) {
123 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
124 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
128 for (i = 0; i < nchannels; i++)
129 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
136 /* this macro makes a caps width fixed or unfixed width/height
137 * properties depending on whether we've got a context.
139 * See below for why we use this.
141 * We should actually do this stuff at the end, like in riff-media.c,
142 * but I'm too lazy today. Maybe later.
145 gst_ff_vid_caps_new (AVCodecContext * context, enum CodecID codec_id,
146 gboolean encode, const char *mimetype, const char *fieldname, ...)
148 GstStructure *structure = NULL;
149 GstCaps *caps = NULL;
153 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
155 /* fixed, non probing context */
156 if (context != NULL && context->width != -1) {
159 caps = gst_caps_new_simple (mimetype,
160 "width", G_TYPE_INT, context->width,
161 "height", G_TYPE_INT, context->height, NULL);
163 num = context->time_base.den / context->ticks_per_frame;
164 denom = context->time_base.num;
167 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
170 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
171 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
175 GST_LOG ("setting framerate: %d/%d", num, denom);
176 gst_caps_set_simple (caps,
177 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
179 /* so we are after restricted caps in this case */
183 caps = gst_caps_new_simple (mimetype,
184 "width", G_TYPE_INT, 352,
185 "height", G_TYPE_INT, 288,
186 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
187 gst_caps_append (caps, gst_caps_new_simple (mimetype,
188 "width", G_TYPE_INT, 176,
189 "height", G_TYPE_INT, 144,
190 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
195 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
196 * because we want automatic negotiation to go as close to 320x240 as
198 const static gint widths[] = { 352, 704, 176, 1408, 128 };
199 const static gint heights[] = { 288, 576, 144, 1152, 96 };
201 gint n_sizes = G_N_ELEMENTS (widths);
203 caps = gst_caps_new_empty ();
204 for (i = 0; i < n_sizes; i++) {
205 temp = gst_caps_new_simple (mimetype,
206 "width", G_TYPE_INT, widths[i],
207 "height", G_TYPE_INT, heights[i],
208 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
210 gst_caps_append (caps, temp);
214 case CODEC_ID_DVVIDEO:
221 gint framerate_n, framerate_d;
224 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 10, 11, 30000, 1001}, {
225 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 40, 33, 30000, 1001}, {
226 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 59, 54, 25, 1}, {
227 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 118, 81, 25, 1}, {
228 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 59, 54, 25, 1}, {
229 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 118, 81, 25, 1}
232 gint n_sizes = G_N_ELEMENTS (profiles);
234 caps = gst_caps_new_empty ();
235 for (i = 0; i < n_sizes; i++) {
236 temp = gst_caps_new_simple (mimetype,
237 "width", G_TYPE_INT, profiles[i].width,
238 "height", G_TYPE_INT, profiles[i].height,
239 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
240 profiles[i].framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION,
241 profiles[i].par_n, profiles[i].par_d, NULL);
243 gst_caps_append (caps, temp);
249 caps = gst_caps_new_simple (mimetype,
250 "width", G_TYPE_INT, 1920,
251 "height", G_TYPE_INT, 1080,
252 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
253 gst_caps_append (caps, gst_caps_new_simple (mimetype,
254 "width", G_TYPE_INT, 1280,
255 "height", G_TYPE_INT, 720,
256 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
264 /* no fixed caps or special restrictions applied;
265 * default unfixed setting */
267 GST_DEBUG ("Creating default caps");
268 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
271 for (i = 0; i < gst_caps_get_size (caps); i++) {
272 va_start (var_args, fieldname);
273 structure = gst_caps_get_structure (caps, i);
274 gst_structure_set_valist (structure, fieldname, var_args);
282 get_nbits_set (guint64 n)
287 for (i = 0; i < 64; i++) {
288 if ((n & (G_GUINT64_CONSTANT (1) << i)))
295 /* same for audio - now with channels/sample rate
298 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
299 enum CodecID codec_id, gboolean encode, const char *mimetype,
300 const char *fieldname, ...)
302 GstCaps *caps = NULL;
306 /* fixed, non-probing context */
307 if (context != NULL && context->channels != -1) {
308 GstAudioChannelPosition pos[64];
310 caps = gst_caps_new_simple (mimetype,
311 "rate", G_TYPE_INT, context->sample_rate,
312 "channels", G_TYPE_INT, context->channels, NULL);
314 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
315 context->channels, pos)) {
318 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
320 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
325 gint maxchannels = 2;
326 const gint *rates = NULL;
329 /* so we must be after restricted caps in this case */
332 case CODEC_ID_AAC_LATM:
338 const static gint l_rates[] =
339 { 48000, 44100, 32000, 24000, 22050, 16000 };
340 n_rates = G_N_ELEMENTS (l_rates);
347 const static gint l_rates[] = { 48000, 44100, 32000 };
349 n_rates = G_N_ELEMENTS (l_rates);
353 case CODEC_ID_ADPCM_G722:
355 const static gint l_rates[] = { 16000 };
356 n_rates = G_N_ELEMENTS (l_rates);
361 case CODEC_ID_ADPCM_G726:
363 const static gint l_rates[] = { 8000 };
364 n_rates = G_N_ELEMENTS (l_rates);
369 case CODEC_ID_ADPCM_SWF:
371 const static gint l_rates[] = { 11025, 22050, 44100 };
372 n_rates = G_N_ELEMENTS (l_rates);
376 case CODEC_ID_ROQ_DPCM:
378 const static gint l_rates[] = { 22050 };
379 n_rates = G_N_ELEMENTS (l_rates);
383 case CODEC_ID_AMR_NB:
385 const static gint l_rates[] = { 8000 };
387 n_rates = G_N_ELEMENTS (l_rates);
391 case CODEC_ID_AMR_WB:
393 const static gint l_rates[] = { 16000 };
395 n_rates = G_N_ELEMENTS (l_rates);
403 /* regardless of encode/decode, open up channels if applicable */
404 /* Until decoders/encoders expose the maximum number of channels
405 * they support, we whitelist them here. */
407 case CODEC_ID_WMAPRO:
408 case CODEC_ID_TRUEHD:
415 if (codec && codec->channel_layouts) {
416 const uint64_t *layouts = codec->channel_layouts;
417 GstAudioChannelPosition pos[64];
419 caps = gst_caps_new_empty ();
421 gint nbits_set = get_nbits_set (*layouts);
423 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
426 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
429 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
431 "channels", G_TYPE_INT, nbits_set, NULL);
433 gst_caps_append (caps, tmp);
439 if (maxchannels == 1)
440 caps = gst_caps_new_simple (mimetype,
441 "channels", G_TYPE_INT, maxchannels, NULL);
443 caps = gst_caps_new_simple (mimetype,
444 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
448 GValue list = { 0, };
450 g_value_init (&list, GST_TYPE_LIST);
451 for (i = 0; i < n_rates; i++) {
454 g_value_init (&v, G_TYPE_INT);
455 g_value_set_int (&v, rates[i]);
456 gst_value_list_append_value (&list, &v);
459 gst_caps_set_value (caps, "rate", &list);
460 g_value_unset (&list);
461 } else if (codec && codec->supported_samplerates
462 && codec->supported_samplerates[0]) {
466 if (!codec->supported_samplerates[1]) {
467 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
468 codec->supported_samplerates[0], NULL);
470 const int *rates = codec->supported_samplerates;
472 g_value_init (&va, GST_TYPE_LIST);
473 g_value_init (&v, G_TYPE_INT);
476 g_value_set_int (&v, *rates);
477 gst_value_list_append_value (&va, &v);
480 gst_caps_set_value (caps, "rate", &va);
485 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
488 caps = gst_caps_new_empty_simple (mimetype);
491 va_start (var_args, fieldname);
492 gst_caps_set_simple_valist (caps, fieldname, var_args);
498 /* Convert a FFMPEG codec ID and optional AVCodecContext
499 * to a GstCaps. If the context is ommitted, no fixed values
500 * for video/audio size will be included in the GstCaps
502 * CodecID is primarily meant for compressed data GstCaps!
504 * encode is a special parameter. gstffmpegdec will say
505 * FALSE, gstffmpegenc will say TRUE. The output caps
506 * depends on this, in such a way that it will be very
507 * specific, defined, fixed and correct caps for encoders,
508 * yet very wide, "forgiving" caps for decoders. Example
509 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
510 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
515 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
516 AVCodecContext * context, gboolean encode)
518 GstCaps *caps = NULL;
519 gboolean buildcaps = FALSE;
521 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
524 case CODEC_ID_MPEG1VIDEO:
526 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
527 "mpegversion", G_TYPE_INT, 1,
528 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
531 case CODEC_ID_MPEG2VIDEO:
534 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
535 "mpegversion", G_TYPE_INT, 2,
536 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
538 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
539 * the MPEG video stream headers, so may be omitted from caps. */
540 caps = gst_caps_new_simple ("video/mpeg",
541 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
542 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
546 case CODEC_ID_MPEG2VIDEO_XVMC:
547 /* this is a special ID - don't need it in GStreamer, I think */
552 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
553 "variant", G_TYPE_STRING, "itu",
554 "h263version", G_TYPE_STRING, "h263", NULL);
556 /* don't pass codec_id, we can decode other variants with the H263
557 * decoder that don't have specific size requirements
560 gst_ff_vid_caps_new (context, CODEC_ID_NONE, encode, "video/x-h263",
561 "variant", G_TYPE_STRING, "itu", NULL);
566 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
567 "variant", G_TYPE_STRING, "itu",
568 "h263version", G_TYPE_STRING, "h263p", NULL);
569 if (encode && context) {
571 gst_caps_set_simple (caps,
572 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
573 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
574 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
575 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
582 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-intel-h263",
583 "variant", G_TYPE_STRING, "intel", NULL);
588 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h261", NULL);
613 /* FIXME: context->sub_id must be filled in during decoding */
615 gst_ff_vid_caps_new (context, codec_id, encode,
616 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
617 "rmversion", G_TYPE_INT, version, NULL);
619 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
620 if (context->extradata_size >= 8) {
621 gst_caps_set_simple (caps,
622 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
631 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
632 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
637 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
638 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
645 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
646 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
648 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
649 * in the MPEG audio header, so may be omitted from caps. */
650 caps = gst_caps_new_simple ("audio/mpeg",
651 "mpegversion", G_TYPE_INT, 1,
652 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
656 case CODEC_ID_MUSEPACK7:
658 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
659 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
663 case CODEC_ID_MUSEPACK8:
665 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
666 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
673 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
680 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
684 case CODEC_ID_TRUEHD:
686 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
687 "audio/x-true-hd", NULL);
690 case CODEC_ID_ATRAC1:
692 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
693 "audio/x-vnd.sony.atrac1", NULL);
696 case CODEC_ID_ATRAC3:
698 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
699 "audio/x-vnd.sony.atrac3", NULL);
704 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
710 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
711 "audio/x-ffmpeg-parsed-ape", NULL);
713 gst_caps_set_simple (caps,
714 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
720 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
726 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
730 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
731 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
732 * sp5x is, but it's apparently something JPEG... We don't separate
733 * between those in GStreamer. Should we (at least between MJPEG,
734 * MJPEG-B and sp5x decoding...)? */
738 gst_ff_vid_caps_new (context, codec_id, encode, "image/jpeg", NULL);
743 gst_ff_vid_caps_new (context, codec_id, encode, "video/sp5x", NULL);
746 case CODEC_ID_MJPEGB:
748 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mjpeg-b",
753 if (encode && context != NULL) {
754 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
755 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
756 switch (context->codec_tag) {
757 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
759 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-divx",
760 "divxversion", G_TYPE_INT, 5, NULL);
762 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
765 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
766 "systemstream", G_TYPE_BOOLEAN, FALSE,
767 "mpegversion", G_TYPE_INT, 4, NULL);
771 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
772 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
773 "mpegversion", G_TYPE_INT, 4,
774 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
776 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
777 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
779 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
780 "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4, 5,
782 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
783 "video/x-xvid", NULL));
784 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
785 "video/x-3ivx", NULL));
790 case CODEC_ID_RAWVIDEO:
792 gst_ffmpeg_codectype_to_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
796 case CODEC_ID_MSMPEG4V1:
797 case CODEC_ID_MSMPEG4V2:
798 case CODEC_ID_MSMPEG4V3:
800 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
802 /* encode-FIXME: bitrate */
803 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-msmpeg",
804 "msmpegversion", G_TYPE_INT, version, NULL);
805 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
806 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
807 "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
815 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
817 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
818 "wmvversion", G_TYPE_INT, version, NULL);
824 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-flash-video",
825 "flvversion", G_TYPE_INT, 1, NULL);
829 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
830 "svqversion", G_TYPE_INT, 1, NULL);
834 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
835 "svqversion", G_TYPE_INT, 3, NULL);
838 case CODEC_ID_DVAUDIO:
840 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
844 case CODEC_ID_DVVIDEO:
846 if (encode && context) {
849 switch (context->pix_fmt) {
850 case PIX_FMT_YUYV422:
853 case PIX_FMT_YUV420P:
856 case PIX_FMT_YUVA420P:
859 case PIX_FMT_YUV411P:
862 case PIX_FMT_YUV422P:
865 case PIX_FMT_YUV410P:
870 ("Couldnt' find format for pixfmt %d, defaulting to I420",
875 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
876 "systemstream", G_TYPE_BOOLEAN, FALSE,
877 "format", G_TYPE_STRING, format, NULL);
879 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
880 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
888 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
892 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
893 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
894 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
898 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
899 "wmaversion", G_TYPE_INT, version, "block_align",
900 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
905 case CODEC_ID_WMAPRO:
908 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
909 "wmaversion", G_TYPE_INT, 3, NULL);
913 case CODEC_ID_WMAVOICE:
916 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
924 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
927 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
928 "maceversion", G_TYPE_INT, version, NULL);
932 case CODEC_ID_HUFFYUV:
934 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-huffyuv",
937 gst_caps_set_simple (caps,
938 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
944 gst_ff_vid_caps_new (context, codec_id, encode,
945 "video/x-compressed-yuv", NULL);
950 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h264",
951 "alignment", G_TYPE_STRING, "au", NULL);
954 case CODEC_ID_INDEO5:
955 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
956 "indeoversion", G_TYPE_INT, 5, NULL);
959 case CODEC_ID_INDEO4:
960 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
961 "indeoversion", G_TYPE_INT, 4, NULL);
964 case CODEC_ID_INDEO3:
965 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
966 "indeoversion", G_TYPE_INT, 3, NULL);
969 case CODEC_ID_INDEO2:
970 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
971 "indeoversion", G_TYPE_INT, 2, NULL);
974 case CODEC_ID_FLASHSV:
976 gst_ff_vid_caps_new (context, codec_id, encode,
977 "video/x-flash-screen", NULL);
982 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp3", NULL);
987 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp5", NULL);
992 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6", NULL);
997 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-flash",
1003 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-alpha",
1009 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp8", NULL);
1012 case CODEC_ID_THEORA:
1014 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-theora",
1021 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1025 GValue arr = { 0, };
1026 GValue item = { 0, };
1028 g_value_init (&arr, GST_TYPE_LIST);
1029 g_value_init (&item, G_TYPE_INT);
1030 g_value_set_int (&item, 2);
1031 gst_value_list_append_value (&arr, &item);
1032 g_value_set_int (&item, 4);
1033 gst_value_list_append_value (&arr, &item);
1034 g_value_unset (&item);
1036 gst_caps_set_value (caps, "mpegversion", &arr);
1037 g_value_unset (&arr);
1039 g_value_init (&arr, GST_TYPE_LIST);
1040 g_value_init (&item, G_TYPE_STRING);
1041 g_value_set_string (&item, "raw");
1042 gst_value_list_append_value (&arr, &item);
1043 g_value_set_string (&item, "adts");
1044 gst_value_list_append_value (&arr, &item);
1045 g_value_set_string (&item, "adif");
1046 gst_value_list_append_value (&arr, &item);
1047 g_value_unset (&item);
1049 gst_caps_set_value (caps, "stream-format", &arr);
1050 g_value_unset (&arr);
1052 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1053 "stream-format", G_TYPE_STRING, "raw",
1054 "base-profile", G_TYPE_STRING, "lc", NULL);
1056 if (context && context->extradata_size > 0)
1057 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1058 context->extradata, context->extradata_size);
1063 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1064 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1065 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1070 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1071 "asusversion", G_TYPE_INT, 1, NULL);
1074 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1075 "asusversion", G_TYPE_INT, 2, NULL);
1079 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ffv",
1080 "ffvversion", G_TYPE_INT, 1, NULL);
1085 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-4xm", NULL);
1088 case CODEC_ID_XAN_WC3:
1089 case CODEC_ID_XAN_WC4:
1090 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-xan",
1091 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1096 gst_ff_vid_caps_new (context, codec_id, encode,
1097 "video/x-cirrus-logic-accupak", NULL);
1100 case CODEC_ID_FRAPS:
1102 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-fraps",
1108 case CODEC_ID_INTERPLAY_VIDEO:
1113 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ati-vcr",
1114 "vcrversion", G_TYPE_INT, 1, NULL);
1119 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-apple-video",
1123 case CODEC_ID_CINEPAK:
1125 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-cinepak",
1129 /* WS_VQA belogns here (order) */
1131 case CODEC_ID_MSRLE:
1132 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1133 "layout", G_TYPE_STRING, "microsoft", NULL);
1135 gst_caps_set_simple (caps,
1136 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1138 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1142 case CODEC_ID_QTRLE:
1143 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1144 "layout", G_TYPE_STRING, "quicktime", NULL);
1146 gst_caps_set_simple (caps,
1147 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1149 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1153 case CODEC_ID_MSVIDEO1:
1155 gst_ff_vid_caps_new (context, codec_id, encode,
1156 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1160 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1161 "wmvversion", G_TYPE_INT, 3, NULL);
1164 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1165 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1169 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1175 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mszh", NULL);
1180 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zlib", NULL);
1183 case CODEC_ID_TRUEMOTION1:
1185 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1186 "trueversion", G_TYPE_INT, 1, NULL);
1188 case CODEC_ID_TRUEMOTION2:
1190 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1191 "trueversion", G_TYPE_INT, 2, NULL);
1196 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ultimotion",
1202 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camtasia",
1205 gst_caps_set_simple (caps,
1206 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1208 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1214 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-kmvc", NULL);
1219 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-nuv", NULL);
1223 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/gif", NULL);
1227 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/png", NULL);
1231 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/ppm", NULL);
1235 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/pbm", NULL);
1240 gst_ff_vid_caps_new (context, codec_id, encode,
1241 "image/x-portable-anymap", NULL);
1246 gst_ff_vid_caps_new (context, codec_id, encode,
1247 "image/x-portable-graymap", NULL);
1252 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-pcx", NULL);
1257 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sgi", NULL);
1260 case CODEC_ID_TARGA:
1262 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-tga", NULL);
1267 gst_ff_vid_caps_new (context, codec_id, encode, "image/tiff", NULL);
1270 case CODEC_ID_SUNRAST:
1272 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sun-raster",
1278 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-smc", NULL);
1281 case CODEC_ID_QDRAW:
1283 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-qdrw", NULL);
1286 case CODEC_ID_DNXHD:
1288 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dnxhd",
1292 case CODEC_ID_PRORES:
1294 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-prores",
1298 case CODEC_ID_MIMIC:
1300 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mimic",
1306 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vmnc", NULL);
1309 case CODEC_ID_TRUESPEECH:
1311 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1312 "audio/x-truespeech", NULL);
1315 case CODEC_ID_QCELP:
1317 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1323 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-amv", NULL);
1328 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-aasc", NULL);
1333 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-loco", NULL);
1338 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zmbv", NULL);
1341 case CODEC_ID_LAGARITH:
1343 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-lagarith",
1349 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camstudio",
1352 gst_caps_set_simple (caps,
1353 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1355 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1359 case CODEC_ID_WS_VQA:
1360 case CODEC_ID_IDCIN:
1363 case CODEC_ID_VMDVIDEO:
1364 case CODEC_ID_VMDAUDIO:
1368 case CODEC_ID_PGMYUV:
1369 case CODEC_ID_FFVHUFF:
1371 case CODEC_ID_MP3ADU:
1372 case CODEC_ID_MP3ON4:
1373 case CODEC_ID_WESTWOOD_SND1:
1374 case CODEC_ID_MMVIDEO:
1380 /* weird quasi-codecs for the demuxers only */
1381 case CODEC_ID_PCM_S16LE:
1382 case CODEC_ID_PCM_S16BE:
1383 case CODEC_ID_PCM_U16LE:
1384 case CODEC_ID_PCM_U16BE:
1385 case CODEC_ID_PCM_S8:
1386 case CODEC_ID_PCM_U8:
1388 GstAudioFormat format;
1391 case CODEC_ID_PCM_S16LE:
1392 format = GST_AUDIO_FORMAT_S16LE;
1394 case CODEC_ID_PCM_S16BE:
1395 format = GST_AUDIO_FORMAT_S16BE;
1397 case CODEC_ID_PCM_U16LE:
1398 format = GST_AUDIO_FORMAT_U16LE;
1400 case CODEC_ID_PCM_U16BE:
1401 format = GST_AUDIO_FORMAT_U16BE;
1403 case CODEC_ID_PCM_S8:
1404 format = GST_AUDIO_FORMAT_S8;
1406 case CODEC_ID_PCM_U8:
1407 format = GST_AUDIO_FORMAT_U8;
1410 g_assert (0); /* don't worry, we never get here */
1415 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1416 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1417 "layout", G_TYPE_STRING, "interleaved", NULL);
1421 case CODEC_ID_PCM_MULAW:
1423 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1427 case CODEC_ID_PCM_ALAW:
1429 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1433 case CODEC_ID_ADPCM_G722:
1435 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1438 gst_caps_set_simple (caps,
1439 "block_align", G_TYPE_INT, context->block_align,
1440 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1443 case CODEC_ID_ADPCM_G726:
1445 /* the G726 decoder can also handle G721 */
1447 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1448 "layout", G_TYPE_STRING, "g726", NULL);
1450 gst_caps_set_simple (caps,
1451 "block_align", G_TYPE_INT, context->block_align,
1452 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1455 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1456 "layout", G_TYPE_STRING, "g721",
1457 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1461 case CODEC_ID_ADPCM_IMA_QT:
1462 case CODEC_ID_ADPCM_IMA_WAV:
1463 case CODEC_ID_ADPCM_IMA_DK3:
1464 case CODEC_ID_ADPCM_IMA_DK4:
1465 case CODEC_ID_ADPCM_IMA_WS:
1466 case CODEC_ID_ADPCM_IMA_SMJPEG:
1467 case CODEC_ID_ADPCM_IMA_AMV:
1468 case CODEC_ID_ADPCM_IMA_ISS:
1469 case CODEC_ID_ADPCM_IMA_EA_EACS:
1470 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1471 case CODEC_ID_ADPCM_MS:
1472 case CODEC_ID_ADPCM_4XM:
1473 case CODEC_ID_ADPCM_XA:
1474 case CODEC_ID_ADPCM_ADX:
1475 case CODEC_ID_ADPCM_EA:
1476 case CODEC_ID_ADPCM_CT:
1477 case CODEC_ID_ADPCM_SWF:
1478 case CODEC_ID_ADPCM_YAMAHA:
1479 case CODEC_ID_ADPCM_SBPRO_2:
1480 case CODEC_ID_ADPCM_SBPRO_3:
1481 case CODEC_ID_ADPCM_SBPRO_4:
1482 case CODEC_ID_ADPCM_EA_R1:
1483 case CODEC_ID_ADPCM_EA_R2:
1484 case CODEC_ID_ADPCM_EA_R3:
1485 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1486 case CODEC_ID_ADPCM_EA_XAS:
1487 case CODEC_ID_ADPCM_THP:
1489 const gchar *layout = NULL;
1492 case CODEC_ID_ADPCM_IMA_QT:
1493 layout = "quicktime";
1495 case CODEC_ID_ADPCM_IMA_WAV:
1498 case CODEC_ID_ADPCM_IMA_DK3:
1501 case CODEC_ID_ADPCM_IMA_DK4:
1504 case CODEC_ID_ADPCM_IMA_WS:
1505 layout = "westwood";
1507 case CODEC_ID_ADPCM_IMA_SMJPEG:
1510 case CODEC_ID_ADPCM_IMA_AMV:
1513 case CODEC_ID_ADPCM_IMA_ISS:
1516 case CODEC_ID_ADPCM_IMA_EA_EACS:
1519 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1522 case CODEC_ID_ADPCM_MS:
1523 layout = "microsoft";
1525 case CODEC_ID_ADPCM_4XM:
1528 case CODEC_ID_ADPCM_XA:
1531 case CODEC_ID_ADPCM_ADX:
1534 case CODEC_ID_ADPCM_EA:
1537 case CODEC_ID_ADPCM_CT:
1540 case CODEC_ID_ADPCM_SWF:
1543 case CODEC_ID_ADPCM_YAMAHA:
1546 case CODEC_ID_ADPCM_SBPRO_2:
1549 case CODEC_ID_ADPCM_SBPRO_3:
1552 case CODEC_ID_ADPCM_SBPRO_4:
1555 case CODEC_ID_ADPCM_EA_R1:
1558 case CODEC_ID_ADPCM_EA_R2:
1561 case CODEC_ID_ADPCM_EA_R3:
1564 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1565 layout = "ea-maxis-xa";
1567 case CODEC_ID_ADPCM_EA_XAS:
1570 case CODEC_ID_ADPCM_THP:
1574 g_assert (0); /* don't worry, we never get here */
1578 /* FIXME: someone please check whether we need additional properties
1579 * in this caps definition. */
1581 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1582 "layout", G_TYPE_STRING, layout, NULL);
1584 gst_caps_set_simple (caps,
1585 "block_align", G_TYPE_INT, context->block_align,
1586 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1590 case CODEC_ID_AMR_NB:
1592 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1596 case CODEC_ID_AMR_WB:
1598 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1604 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1608 case CODEC_ID_GSM_MS:
1610 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1614 case CODEC_ID_NELLYMOSER:
1616 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1617 "audio/x-nellymoser", NULL);
1623 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1626 gst_caps_set_simple (caps,
1627 "leaf_size", G_TYPE_INT, context->block_align,
1628 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1633 case CODEC_ID_RA_144:
1634 case CODEC_ID_RA_288:
1640 case CODEC_ID_RA_144:
1643 case CODEC_ID_RA_288:
1653 /* FIXME: properties? */
1655 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1656 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1658 gst_caps_set_simple (caps,
1659 "leaf_size", G_TYPE_INT, context->block_align,
1660 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1665 case CODEC_ID_ROQ_DPCM:
1666 case CODEC_ID_INTERPLAY_DPCM:
1667 case CODEC_ID_XAN_DPCM:
1668 case CODEC_ID_SOL_DPCM:
1670 const gchar *layout = NULL;
1673 case CODEC_ID_ROQ_DPCM:
1676 case CODEC_ID_INTERPLAY_DPCM:
1677 layout = "interplay";
1679 case CODEC_ID_XAN_DPCM:
1682 case CODEC_ID_SOL_DPCM:
1686 g_assert (0); /* don't worry, we never get here */
1690 /* FIXME: someone please check whether we need additional properties
1691 * in this caps definition. */
1693 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1694 "layout", G_TYPE_STRING, layout, NULL);
1696 gst_caps_set_simple (caps,
1697 "block_align", G_TYPE_INT, context->block_align,
1698 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1702 case CODEC_ID_SHORTEN:
1703 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1708 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1711 gst_caps_set_simple (caps,
1712 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1717 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1718 * encoder case, we want to add things like samplerate, channels... */
1720 caps = gst_caps_new_empty_simple ("audio/x-flac");
1724 case CODEC_ID_DVD_SUBTITLE:
1725 case CODEC_ID_DVB_SUBTITLE:
1729 caps = gst_caps_new_empty_simple ("image/bmp");
1733 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1736 gst_caps_set_simple (caps,
1737 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1740 case CODEC_ID_TWINVQ:
1742 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1743 "audio/x-twin-vq", NULL);
1746 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1753 if ((codec = avcodec_find_decoder (codec_id)) ||
1754 (codec = avcodec_find_encoder (codec_id))) {
1757 GST_LOG ("Could not create stream format caps for %s", codec->name);
1759 switch (codec->type) {
1760 case AVMEDIA_TYPE_VIDEO:
1761 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1762 caps = gst_ff_vid_caps_new (context, codec_id, encode, mime, NULL);
1765 case AVMEDIA_TYPE_AUDIO:
1766 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1768 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
1770 gst_caps_set_simple (caps,
1771 "block_align", G_TYPE_INT, context->block_align,
1772 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1783 /* set private data */
1784 if (context && context->extradata_size > 0) {
1785 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1787 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1788 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1789 gst_buffer_unref (data);
1792 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1795 GST_LOG ("No caps found for codec_id=%d", codec_id);
1801 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1802 * to a GstCaps. If the context is ommitted, no fixed values
1803 * for video/audio size will be included in the GstCaps
1805 * See below for usefullness
1809 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1810 enum CodecID codec_id)
1812 GstCaps *caps = NULL;
1813 GstVideoFormat format;
1815 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
1817 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1818 caps = gst_ff_vid_caps_new (context, codec_id, TRUE, "video/x-raw",
1819 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1823 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1825 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1832 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
1834 switch (sample_fmt) {
1835 case AV_SAMPLE_FMT_U8:
1836 case AV_SAMPLE_FMT_U8P:
1837 return GST_AUDIO_FORMAT_U8;
1839 case AV_SAMPLE_FMT_S16:
1840 case AV_SAMPLE_FMT_S16P:
1841 return GST_AUDIO_FORMAT_S16;
1843 case AV_SAMPLE_FMT_S32:
1844 case AV_SAMPLE_FMT_S32P:
1845 return GST_AUDIO_FORMAT_S32;
1847 case AV_SAMPLE_FMT_FLT:
1848 case AV_SAMPLE_FMT_FLTP:
1849 return GST_AUDIO_FORMAT_F32;
1851 case AV_SAMPLE_FMT_DBL:
1852 case AV_SAMPLE_FMT_DBLP:
1853 return GST_AUDIO_FORMAT_F64;
1857 return GST_AUDIO_FORMAT_UNKNOWN;
1862 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1863 * to a GstCaps. If the context is ommitted, no fixed values
1864 * for video/audio size will be included in the GstCaps
1866 * See below for usefullness
1870 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
1871 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
1873 GstCaps *caps = NULL;
1874 GstAudioFormat format;
1876 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
1878 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1879 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
1880 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1881 "layout", G_TYPE_STRING, "interleaved", NULL);
1882 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1884 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1891 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
1892 const enum AVSampleFormat *fmts)
1896 GstAudioFormat format;
1898 if (!fmts || fmts[0] == -1) {
1901 g_value_init (&va, GST_TYPE_LIST);
1902 g_value_init (&v, G_TYPE_STRING);
1903 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
1904 format = gst_ffmpeg_smpfmt_to_audioformat (i);
1905 g_value_set_string (&v, gst_audio_format_to_string (format));
1906 gst_value_list_append_value (&va, &v);
1908 gst_caps_set_value (caps, "format", &va);
1910 g_value_unset (&va);
1914 /* Only a single rate */
1915 if (fmts[1] == -1) {
1916 format = gst_ffmpeg_smpfmt_to_audioformat (fmts[0]);
1917 gst_caps_set_simple (caps, "format", G_TYPE_STRING,
1918 gst_audio_format_to_string (format), NULL);
1922 g_value_init (&va, GST_TYPE_LIST);
1923 g_value_init (&v, G_TYPE_STRING);
1924 while (*fmts != -1) {
1925 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
1926 g_value_set_string (&v, gst_audio_format_to_string (format));
1927 gst_value_list_append_value (&va, &v);
1930 gst_caps_set_value (caps, "format", &va);
1932 g_value_unset (&va);
1936 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
1937 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1939 GstCaps *caps = NULL;
1941 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1942 context, codec_id, encode, codec);
1944 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
1945 codec->sample_fmts, codec->supported_samplerates);
1948 /* Specific codec context */
1950 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
1953 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
1954 "layout", G_TYPE_STRING, "interleaved", NULL);
1955 gst_ffmpeg_audio_set_sample_fmts (caps, codec ? codec->sample_fmts : NULL);
1962 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
1963 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1967 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1968 context, codec_id, encode, codec);
1971 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
1975 AVCodecContext ctx = { 0, };
1977 caps = gst_caps_new_empty ();
1978 for (i = 0; i < PIX_FMT_NB; i++) {
1981 temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1983 gst_caps_append (caps, temp);
1990 /* Convert a FFMPEG codec Type and optional AVCodecContext
1991 * to a GstCaps. If the context is ommitted, no fixed values
1992 * for video/audio size will be included in the GstCaps
1994 * AVMediaType is primarily meant for uncompressed data GstCaps!
1998 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
1999 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
2003 switch (codec_type) {
2004 case AVMEDIA_TYPE_VIDEO:
2006 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
2008 case AVMEDIA_TYPE_AUDIO:
2010 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
2020 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2021 * and other audio properties in a AVCodecContext.
2023 * For usefullness, see below
2027 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2028 AVCodecContext * context, gboolean raw)
2030 GstStructure *structure;
2032 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2034 g_return_if_fail (gst_caps_get_size (caps) == 1);
2036 structure = gst_caps_get_structure (caps, 0);
2038 gst_structure_get_int (structure, "channels", &context->channels);
2039 gst_structure_get_int (structure, "rate", &context->sample_rate);
2040 gst_structure_get_int (structure, "block_align", &context->block_align);
2041 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2046 if (gst_structure_has_name (structure, "audio/x-raw")) {
2047 if ((fmt = gst_structure_get_string (structure, "format"))) {
2048 format = gst_audio_format_from_string (fmt);
2053 case GST_AUDIO_FORMAT_F32:
2054 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2056 case GST_AUDIO_FORMAT_F64:
2057 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2059 case GST_AUDIO_FORMAT_S32:
2060 context->sample_fmt = AV_SAMPLE_FMT_S32;
2062 case GST_AUDIO_FORMAT_S16:
2063 context->sample_fmt = AV_SAMPLE_FMT_S16;
2070 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2071 * and other video properties in a AVCodecContext.
2073 * For usefullness, see below
2077 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2078 AVCodecContext * context, gboolean raw)
2080 GstStructure *structure;
2082 const GValue *par = NULL;
2084 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2086 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2087 g_return_if_fail (gst_caps_get_size (caps) == 1);
2088 structure = gst_caps_get_structure (caps, 0);
2090 gst_structure_get_int (structure, "width", &context->width);
2091 gst_structure_get_int (structure, "height", &context->height);
2092 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2094 fps = gst_structure_get_value (structure, "framerate");
2095 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2097 /* somehow these seem mixed up.. */
2098 context->time_base.den = gst_value_get_fraction_numerator (fps);
2099 context->time_base.num = gst_value_get_fraction_denominator (fps);
2100 context->ticks_per_frame = 1;
2102 GST_DEBUG ("setting framerate %d/%d = %lf",
2103 context->time_base.den, context->time_base.num,
2104 1. * context->time_base.den / context->time_base.num);
2107 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2108 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2110 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2111 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2113 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2114 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2115 1. * context->sample_aspect_ratio.den /
2116 context->sample_aspect_ratio.num);
2122 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2124 if (gst_structure_has_name (structure, "video/x-raw")) {
2125 if ((fmt = gst_structure_get_string (structure, "format"))) {
2126 format = gst_video_format_from_string (fmt);
2131 case GST_VIDEO_FORMAT_YUY2:
2132 context->pix_fmt = PIX_FMT_YUYV422;
2134 case GST_VIDEO_FORMAT_I420:
2135 context->pix_fmt = PIX_FMT_YUV420P;
2137 case GST_VIDEO_FORMAT_A420:
2138 context->pix_fmt = PIX_FMT_YUVA420P;
2140 case GST_VIDEO_FORMAT_Y41B:
2141 context->pix_fmt = PIX_FMT_YUV411P;
2143 case GST_VIDEO_FORMAT_Y42B:
2144 context->pix_fmt = PIX_FMT_YUV422P;
2146 case GST_VIDEO_FORMAT_YUV9:
2147 context->pix_fmt = PIX_FMT_YUV410P;
2149 case GST_VIDEO_FORMAT_Y444:
2150 context->pix_fmt = PIX_FMT_YUV444P;
2152 case GST_VIDEO_FORMAT_GRAY8:
2153 context->pix_fmt = PIX_FMT_GRAY8;
2155 case GST_VIDEO_FORMAT_xRGB:
2156 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2157 context->pix_fmt = PIX_FMT_RGB32;
2160 case GST_VIDEO_FORMAT_BGRx:
2161 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2162 context->pix_fmt = PIX_FMT_RGB32;
2165 case GST_VIDEO_FORMAT_RGB:
2166 context->pix_fmt = PIX_FMT_RGB24;
2168 case GST_VIDEO_FORMAT_BGR:
2169 context->pix_fmt = PIX_FMT_BGR24;
2171 case GST_VIDEO_FORMAT_RGB16:
2172 context->pix_fmt = PIX_FMT_RGB565;
2174 case GST_VIDEO_FORMAT_RGB15:
2175 context->pix_fmt = PIX_FMT_RGB555;
2177 case GST_VIDEO_FORMAT_RGB8P:
2178 context->pix_fmt = PIX_FMT_PAL8;
2187 GstVideoFormat format;
2188 enum PixelFormat pixfmt;
2191 /* FIXME : FILLME */
2192 static const PixToFmt pixtofmttable[] = {
2193 /* GST_VIDEO_FORMAT_I420, */
2194 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2195 /* Note : this should use a different chroma placement */
2196 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2198 /* GST_VIDEO_FORMAT_YV12, */
2199 /* GST_VIDEO_FORMAT_YUY2, */
2200 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2201 /* GST_VIDEO_FORMAT_UYVY, */
2202 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2203 /* GST_VIDEO_FORMAT_AYUV, */
2204 /* GST_VIDEO_FORMAT_RGBx, */
2205 /* GST_VIDEO_FORMAT_BGRx, */
2206 /* GST_VIDEO_FORMAT_xRGB, */
2207 /* GST_VIDEO_FORMAT_xBGR, */
2208 /* GST_VIDEO_FORMAT_RGBA, */
2209 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2210 /* GST_VIDEO_FORMAT_BGRA, */
2211 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2212 /* GST_VIDEO_FORMAT_ARGB, */
2213 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2214 /* GST_VIDEO_FORMAT_ABGR, */
2215 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2216 /* GST_VIDEO_FORMAT_RGB, */
2217 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2218 /* GST_VIDEO_FORMAT_BGR, */
2219 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2220 /* GST_VIDEO_FORMAT_Y41B, */
2221 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2222 /* GST_VIDEO_FORMAT_Y42B, */
2223 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2224 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2225 /* GST_VIDEO_FORMAT_YVYU, */
2226 /* GST_VIDEO_FORMAT_Y444, */
2227 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2228 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2229 /* GST_VIDEO_FORMAT_v210, */
2230 /* GST_VIDEO_FORMAT_v216, */
2231 /* GST_VIDEO_FORMAT_NV12, */
2232 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2233 /* GST_VIDEO_FORMAT_NV21, */
2234 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2235 /* GST_VIDEO_FORMAT_GRAY8, */
2236 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2237 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2238 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2239 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2240 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2241 /* GST_VIDEO_FORMAT_v308, */
2242 /* GST_VIDEO_FORMAT_Y800, */
2243 /* GST_VIDEO_FORMAT_Y16, */
2244 /* GST_VIDEO_FORMAT_RGB16, */
2245 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2246 /* GST_VIDEO_FORMAT_BGR16, */
2247 /* GST_VIDEO_FORMAT_RGB15, */
2248 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2249 /* GST_VIDEO_FORMAT_BGR15, */
2250 /* GST_VIDEO_FORMAT_UYVP, */
2251 /* GST_VIDEO_FORMAT_A420, */
2252 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2253 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2254 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2255 /* GST_VIDEO_FORMAT_YUV9, */
2256 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2257 /* GST_VIDEO_FORMAT_YVU9, */
2258 /* GST_VIDEO_FORMAT_IYU1, */
2259 /* GST_VIDEO_FORMAT_ARGB64, */
2260 /* GST_VIDEO_FORMAT_AYUV64, */
2261 /* GST_VIDEO_FORMAT_r210, */
2262 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2263 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2264 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2265 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2266 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2267 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2268 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2269 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2270 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2274 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2278 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2279 if (pixtofmttable[i].pixfmt == pixfmt)
2280 return pixtofmttable[i].format;
2282 GST_WARNING ("Unknown pixel format %d", pixfmt);
2283 return GST_VIDEO_FORMAT_UNKNOWN;
2287 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2291 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2292 if (pixtofmttable[i].format == format)
2293 return pixtofmttable[i].pixfmt;
2294 return PIX_FMT_NONE;
2298 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2302 context->width = GST_VIDEO_INFO_WIDTH (info);
2303 context->height = GST_VIDEO_INFO_HEIGHT (info);
2304 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2305 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2306 context->bits_per_coded_sample = bpp;
2308 context->ticks_per_frame = 1;
2309 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2310 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2312 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2313 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2316 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2320 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2322 const AVCodec *codec;
2323 const enum AVSampleFormat *smpl_fmts;
2324 enum AVSampleFormat smpl_fmt = -1;
2326 context->channels = info->channels;
2327 context->sample_rate = info->rate;
2329 codec = context->codec;
2331 smpl_fmts = codec->sample_fmts;
2333 switch (info->finfo->format) {
2334 case GST_AUDIO_FORMAT_F32:
2336 while (*smpl_fmts != -1) {
2337 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2338 smpl_fmt = *smpl_fmts;
2340 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2341 smpl_fmt = *smpl_fmts;
2347 smpl_fmt = AV_SAMPLE_FMT_FLT;
2350 case GST_AUDIO_FORMAT_F64:
2352 while (*smpl_fmts != -1) {
2353 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2354 smpl_fmt = *smpl_fmts;
2356 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2357 smpl_fmt = *smpl_fmts;
2363 smpl_fmt = AV_SAMPLE_FMT_DBL;
2366 case GST_AUDIO_FORMAT_S32:
2368 while (*smpl_fmts != -1) {
2369 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2370 smpl_fmt = *smpl_fmts;
2372 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2373 smpl_fmt = *smpl_fmts;
2379 smpl_fmt = AV_SAMPLE_FMT_S32;
2382 case GST_AUDIO_FORMAT_S16:
2384 while (*smpl_fmts != -1) {
2385 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2386 smpl_fmt = *smpl_fmts;
2388 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2389 smpl_fmt = *smpl_fmts;
2395 smpl_fmt = AV_SAMPLE_FMT_S16;
2398 case GST_AUDIO_FORMAT_U8:
2400 while (*smpl_fmts != -1) {
2401 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2402 smpl_fmt = *smpl_fmts;
2404 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2405 smpl_fmt = *smpl_fmts;
2411 smpl_fmt = AV_SAMPLE_FMT_U8;
2418 g_assert (smpl_fmt != -1);
2420 context->sample_fmt = smpl_fmt;
2423 /* Convert a GstCaps and a FFMPEG codec Type to a
2424 * AVCodecContext. If the context is ommitted, no fixed values
2425 * for video/audio size will be included in the context
2427 * AVMediaType is primarily meant for uncompressed data GstCaps!
2431 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2432 const GstCaps * caps, AVCodecContext * context)
2434 if (context == NULL)
2438 case AVMEDIA_TYPE_VIDEO:
2439 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2442 case AVMEDIA_TYPE_AUDIO:
2443 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2454 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2458 guint8 *end = src + size;
2461 while (srcp < end) {
2462 if (count == 2 && *srcp <= 0x03) {
2463 GST_DEBUG ("added escape code");
2472 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2475 *destsize = dstp - dst;
2478 /* copy the config, escaping NAL units as we iterate them, if something fails we
2479 * copy everything and hope for the best. */
2481 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2486 guint nalsize, esize;
2496 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2498 GST_DEBUG ("num SPS %d", cnt);
2500 memcpy (dstp, srcp, 6);
2504 for (i = 0; i < cnt; i++) {
2505 GST_DEBUG ("copy SPS %d", i);
2506 nalsize = (srcp[0] << 8) | srcp[1];
2507 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2508 dstp[0] = esize >> 8;
2509 dstp[1] = esize & 0xff;
2511 srcp += nalsize + 2;
2514 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2516 GST_DEBUG ("num PPS %d", cnt);
2518 for (i = 0; i < cnt; i++) {
2519 GST_DEBUG ("copy PPS %d", i);
2520 nalsize = (srcp[0] << 8) | srcp[1];
2521 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2522 dstp[0] = esize >> 8;
2523 dstp[1] = esize & 0xff;
2525 srcp += nalsize + 2;
2527 *destsize = dstp - dst;
2533 GST_DEBUG ("something unexpected, doing full copy");
2534 memcpy (dst, src, size);
2542 * caps_with_codecid () transforms a GstCaps for a known codec
2543 * ID into a filled-in context.
2544 * codec_data from caps will override possible extradata already in the context
2548 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2549 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2552 const GValue *value;
2555 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2556 codec_id, codec_type, caps, context);
2558 if (!context || !gst_caps_get_size (caps))
2561 str = gst_caps_get_structure (caps, 0);
2563 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2564 if ((value = gst_structure_get_value (str, "codec_data"))) {
2567 buf = gst_value_get_buffer (value);
2568 gst_buffer_map (buf, &map, GST_MAP_READ);
2570 /* free the old one if it is there */
2571 if (context->extradata)
2572 av_free (context->extradata);
2575 if (codec_id == CODEC_ID_H264) {
2578 GST_DEBUG ("copy, escaping codec_data %d", size);
2579 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2580 * reason for this but let's just escape it for now. Start by allocating
2581 * enough space, x2 is more than enough.
2583 * FIXME, we disabled escaping because some file already contain escaped
2584 * codec_data and then we escape twice and fail. It's better to leave it
2585 * as is, as that is what most players do. */
2586 context->extradata =
2587 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2588 FF_INPUT_BUFFER_PADDING_SIZE));
2589 copy_config (context->extradata, data, size, &extrasize);
2590 GST_DEBUG ("escaped size: %d", extrasize);
2591 context->extradata_size = extrasize;
2595 /* allocate with enough padding */
2596 GST_DEBUG ("copy codec_data");
2597 context->extradata =
2598 av_mallocz (GST_ROUND_UP_16 (map.size +
2599 FF_INPUT_BUFFER_PADDING_SIZE));
2600 memcpy (context->extradata, map.data, map.size);
2601 context->extradata_size = map.size;
2604 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2605 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2606 context->extradata[0] = (guint8) map.size;
2609 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2611 gst_buffer_unmap (buf, &map);
2612 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2613 codec_id != CODEC_ID_FLAC) {
2614 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2615 * extradata anyway which makes then segfault. */
2616 context->extradata =
2617 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2618 context->extradata_size = 0;
2619 GST_DEBUG ("no codec data");
2623 case CODEC_ID_MPEG4:
2625 const gchar *mime = gst_structure_get_name (str);
2627 if (!strcmp (mime, "video/x-divx"))
2628 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2629 else if (!strcmp (mime, "video/x-xvid"))
2630 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2631 else if (!strcmp (mime, "video/x-3ivx"))
2632 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2633 else if (!strcmp (mime, "video/mpeg"))
2634 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2639 /* FIXME: this is a workaround for older gst-plugins releases
2640 * (<= 0.8.9). This should be removed at some point, because
2641 * it causes wrong decoded frame order. */
2642 if (!context->extradata) {
2643 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2646 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2647 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2648 gst_structure_get_int (str, "low_delay", &low_delay) ||
2649 gst_structure_get_int (str, "unknown_svq3_flag",
2650 &unknown_svq3_flag)) {
2651 context->extradata = (guint8 *) av_mallocz (0x64);
2652 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2656 flags |= unknown_svq3_flag;
2658 flags |= halfpel_flag;
2660 flags |= thirdpel_flag;
2663 flags = GUINT16_FROM_LE (flags);
2665 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2666 context->extradata_size = 0x64;
2671 case CODEC_ID_MSRLE:
2672 case CODEC_ID_QTRLE:
2679 if (gst_structure_get_int (str, "depth", &depth)) {
2680 context->bits_per_coded_sample = depth;
2682 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2695 if (gst_structure_get_int (str, "format", &format))
2696 context->sub_id = format;
2701 case CODEC_ID_RA_288:
2702 case CODEC_ID_RA_144:
2708 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2709 context->block_align = leaf_size;
2710 if (gst_structure_get_int (str, "bitrate", &bitrate))
2711 context->bit_rate = bitrate;
2714 gst_structure_get_int (str, "samplesize",
2715 &context->bits_per_coded_sample);
2718 case CODEC_ID_DVVIDEO:
2720 const gchar *format;
2722 if ((format = gst_structure_get_string (str, "format"))) {
2724 if (g_str_equal (format, "YUY2"))
2725 context->pix_fmt = PIX_FMT_YUYV422;
2726 else if (g_str_equal (format, "I420"))
2727 context->pix_fmt = PIX_FMT_YUV420P;
2728 else if (g_str_equal (format, "A420"))
2729 context->pix_fmt = PIX_FMT_YUVA420P;
2730 else if (g_str_equal (format, "Y41B"))
2731 context->pix_fmt = PIX_FMT_YUV411P;
2732 else if (g_str_equal (format, "Y42B"))
2733 context->pix_fmt = PIX_FMT_YUV422P;
2734 else if (g_str_equal (format, "YUV9"))
2735 context->pix_fmt = PIX_FMT_YUV410P;
2737 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2741 GST_WARNING ("No specified format");
2744 case CODEC_ID_H263P:
2748 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2749 context->flags |= CODEC_FLAG_4MV;
2751 context->flags &= ~CODEC_FLAG_4MV;
2752 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2753 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2754 context->flags |= CODEC_FLAG_AC_PRED;
2756 context->flags &= ~CODEC_FLAG_AC_PRED;
2757 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2758 context->flags |= CODEC_FLAG_LOOP_FILTER;
2760 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2763 case CODEC_ID_ADPCM_G726:
2765 const gchar *layout;
2767 if ((layout = gst_structure_get_string (str, "layout"))) {
2768 if (!strcmp (layout, "g721")) {
2769 context->sample_rate = 8000;
2770 context->channels = 1;
2771 context->bit_rate = 32000;
2780 if (!gst_caps_is_fixed (caps))
2783 /* common properties (width, height, fps) */
2784 switch (codec_type) {
2785 case AVMEDIA_TYPE_VIDEO:
2786 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2788 case AVMEDIA_TYPE_AUDIO:
2789 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2795 /* fixup of default settings */
2797 case CODEC_ID_QCELP:
2798 /* QCELP is always mono, no matter what the caps say */
2799 context->channels = 1;
2806 /* _formatid_to_caps () is meant for muxers/demuxers, it
2807 * transforms a name (ffmpeg way of ID'ing these, why don't
2808 * they have unique numerical IDs?) to the corresponding
2809 * caps belonging to that mux-format
2811 * Note: we don't need any additional info because the caps
2812 * isn't supposed to contain any useful info besides the
2817 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2819 GstCaps *caps = NULL;
2821 if (!strcmp (format_name, "mpeg")) {
2822 caps = gst_caps_new_simple ("video/mpeg",
2823 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2824 } else if (!strcmp (format_name, "mpegts")) {
2825 caps = gst_caps_new_simple ("video/mpegts",
2826 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2827 } else if (!strcmp (format_name, "rm")) {
2828 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2829 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2830 } else if (!strcmp (format_name, "asf")) {
2831 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2832 } else if (!strcmp (format_name, "avi")) {
2833 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2834 } else if (!strcmp (format_name, "wav")) {
2835 caps = gst_caps_new_empty_simple ("audio/x-wav");
2836 } else if (!strcmp (format_name, "ape")) {
2837 caps = gst_caps_new_empty_simple ("application/x-ape");
2838 } else if (!strcmp (format_name, "swf")) {
2839 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2840 } else if (!strcmp (format_name, "au")) {
2841 caps = gst_caps_new_empty_simple ("audio/x-au");
2842 } else if (!strcmp (format_name, "dv")) {
2843 caps = gst_caps_new_simple ("video/x-dv",
2844 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2845 } else if (!strcmp (format_name, "4xm")) {
2846 caps = gst_caps_new_empty_simple ("video/x-4xm");
2847 } else if (!strcmp (format_name, "matroska")) {
2848 caps = gst_caps_new_empty_simple ("video/x-matroska");
2849 } else if (!strcmp (format_name, "mp3")) {
2850 caps = gst_caps_new_empty_simple ("application/x-id3");
2851 } else if (!strcmp (format_name, "flic")) {
2852 caps = gst_caps_new_empty_simple ("video/x-fli");
2853 } else if (!strcmp (format_name, "flv")) {
2854 caps = gst_caps_new_empty_simple ("video/x-flv");
2855 } else if (!strcmp (format_name, "tta")) {
2856 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
2857 } else if (!strcmp (format_name, "aiff")) {
2858 caps = gst_caps_new_empty_simple ("audio/x-aiff");
2859 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2861 gst_caps_from_string
2862 ("application/x-3gp; video/quicktime; audio/x-m4a");
2863 } else if (!strcmp (format_name, "mov")) {
2864 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2865 } else if (!strcmp (format_name, "mp4")) {
2866 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2867 } else if (!strcmp (format_name, "3gp")) {
2868 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2869 } else if (!strcmp (format_name, "3g2")) {
2870 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2871 } else if (!strcmp (format_name, "psp")) {
2872 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2873 } else if (!strcmp (format_name, "ipod")) {
2874 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2875 } else if (!strcmp (format_name, "aac")) {
2876 caps = gst_caps_new_simple ("audio/mpeg",
2877 "mpegversion", G_TYPE_INT, 4, NULL);
2878 } else if (!strcmp (format_name, "gif")) {
2879 caps = gst_caps_from_string ("image/gif");
2880 } else if (!strcmp (format_name, "ogg")) {
2881 caps = gst_caps_from_string ("application/ogg");
2882 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
2883 caps = gst_caps_from_string ("application/mxf");
2884 } else if (!strcmp (format_name, "gxf")) {
2885 caps = gst_caps_from_string ("application/gxf");
2886 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
2887 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
2888 "y4mversion", G_TYPE_INT, 2, NULL);
2889 } else if (!strcmp (format_name, "mpc")) {
2890 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
2891 } else if (!strcmp (format_name, "vqf")) {
2892 caps = gst_caps_from_string ("audio/x-vqf");
2893 } else if (!strcmp (format_name, "nsv")) {
2894 caps = gst_caps_from_string ("video/x-nsv");
2895 } else if (!strcmp (format_name, "amr")) {
2896 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
2897 } else if (!strcmp (format_name, "webm")) {
2898 caps = gst_caps_from_string ("video/webm");
2899 } else if (!strcmp (format_name, "voc")) {
2900 caps = gst_caps_from_string ("audio/x-voc");
2904 GST_LOG ("Could not create stream format caps for %s", format_name);
2905 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
2906 caps = gst_caps_new_empty_simple (name);
2914 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
2915 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
2916 AVOutputFormat * plugin)
2918 static enum CodecID tmp_vlist[] = {
2922 static enum CodecID tmp_alist[] = {
2927 GST_LOG ("format_name : %s", format_name);
2929 if (!strcmp (format_name, "mp4")) {
2930 static enum CodecID mp4_video_list[] = {
2931 CODEC_ID_MPEG4, CODEC_ID_H264,
2935 static enum CodecID mp4_audio_list[] = {
2936 CODEC_ID_AAC, CODEC_ID_MP3,
2940 *video_codec_list = mp4_video_list;
2941 *audio_codec_list = mp4_audio_list;
2942 } else if (!strcmp (format_name, "mpeg")) {
2943 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
2944 CODEC_ID_MPEG2VIDEO,
2948 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
2954 *video_codec_list = mpeg_video_list;
2955 *audio_codec_list = mpeg_audio_list;
2956 } else if (!strcmp (format_name, "dvd")) {
2957 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
2960 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
2967 *video_codec_list = mpeg_video_list;
2968 *audio_codec_list = mpeg_audio_list;
2969 } else if (!strcmp (format_name, "mpegts")) {
2970 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
2971 CODEC_ID_MPEG2VIDEO,
2975 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
2983 *video_codec_list = mpegts_video_list;
2984 *audio_codec_list = mpegts_audio_list;
2985 } else if (!strcmp (format_name, "vob")) {
2986 static enum CodecID vob_video_list[] =
2987 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
2988 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
2989 CODEC_ID_DTS, CODEC_ID_NONE
2992 *video_codec_list = vob_video_list;
2993 *audio_codec_list = vob_audio_list;
2994 } else if (!strcmp (format_name, "flv")) {
2995 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
2996 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
2998 *video_codec_list = flv_video_list;
2999 *audio_codec_list = flv_audio_list;
3000 } else if (!strcmp (format_name, "asf")) {
3001 static enum CodecID asf_video_list[] =
3002 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
3003 static enum CodecID asf_audio_list[] =
3004 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
3006 *video_codec_list = asf_video_list;
3007 *audio_codec_list = asf_audio_list;
3008 } else if (!strcmp (format_name, "dv")) {
3009 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
3010 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
3012 *video_codec_list = dv_video_list;
3013 *audio_codec_list = dv_audio_list;
3014 } else if (!strcmp (format_name, "mov")) {
3015 static enum CodecID mov_video_list[] = {
3016 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
3017 CODEC_ID_H263, CODEC_ID_H263P,
3018 CODEC_ID_H264, CODEC_ID_DVVIDEO,
3022 static enum CodecID mov_audio_list[] = {
3023 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
3024 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
3025 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3026 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
3027 CODEC_ID_MP3, CODEC_ID_NONE
3030 *video_codec_list = mov_video_list;
3031 *audio_codec_list = mov_audio_list;
3032 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3033 static enum CodecID tgp_video_list[] = {
3034 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
3037 static enum CodecID tgp_audio_list[] = {
3038 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3043 *video_codec_list = tgp_video_list;
3044 *audio_codec_list = tgp_audio_list;
3045 } else if (!strcmp (format_name, "mmf")) {
3046 static enum CodecID mmf_audio_list[] = {
3047 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
3049 *video_codec_list = NULL;
3050 *audio_codec_list = mmf_audio_list;
3051 } else if (!strcmp (format_name, "amr")) {
3052 static enum CodecID amr_audio_list[] = {
3053 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3056 *video_codec_list = NULL;
3057 *audio_codec_list = amr_audio_list;
3058 } else if (!strcmp (format_name, "gif")) {
3059 static enum CodecID gif_image_list[] = {
3060 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
3062 *video_codec_list = gif_image_list;
3063 *audio_codec_list = NULL;
3064 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
3065 (plugin->video_codec != CODEC_ID_NONE)) {
3066 tmp_vlist[0] = plugin->video_codec;
3067 tmp_alist[0] = plugin->audio_codec;
3069 *video_codec_list = tmp_vlist;
3070 *audio_codec_list = tmp_alist;
3072 GST_LOG ("Format %s not found", format_name);
3079 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3080 * are omitted, that can be queried by the user itself,
3081 * we're not eating the GstCaps or anything
3082 * A pointer to an allocated context is also needed for
3083 * optional extra info
3087 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3089 enum CodecID id = CODEC_ID_NONE;
3090 const gchar *mimetype;
3091 const GstStructure *structure;
3092 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3094 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3095 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3096 structure = gst_caps_get_structure (caps, 0);
3098 mimetype = gst_structure_get_name (structure);
3100 if (!strcmp (mimetype, "video/x-raw")) {
3101 id = CODEC_ID_RAWVIDEO;
3103 } else if (!strcmp (mimetype, "audio/x-raw")) {
3106 if (gst_audio_info_from_caps (&info, caps)) {
3107 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3108 case GST_AUDIO_FORMAT_S8:
3109 id = CODEC_ID_PCM_S8;
3111 case GST_AUDIO_FORMAT_U8:
3112 id = CODEC_ID_PCM_U8;
3114 case GST_AUDIO_FORMAT_S16LE:
3115 id = CODEC_ID_PCM_S16LE;
3117 case GST_AUDIO_FORMAT_S16BE:
3118 id = CODEC_ID_PCM_S16BE;
3120 case GST_AUDIO_FORMAT_U16LE:
3121 id = CODEC_ID_PCM_U16LE;
3123 case GST_AUDIO_FORMAT_U16BE:
3124 id = CODEC_ID_PCM_U16BE;
3129 if (id != CODEC_ID_NONE)
3132 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3133 id = CODEC_ID_PCM_MULAW;
3135 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3136 id = CODEC_ID_PCM_ALAW;
3138 } else if (!strcmp (mimetype, "video/x-dv")) {
3141 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3143 id = CODEC_ID_DVVIDEO;
3146 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3147 id = CODEC_ID_DVAUDIO;
3149 } else if (!strcmp (mimetype, "video/x-h263")) {
3150 const gchar *h263version =
3151 gst_structure_get_string (structure, "h263version");
3152 if (h263version && !strcmp (h263version, "h263p"))
3153 id = CODEC_ID_H263P;
3157 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3158 id = CODEC_ID_H263I;
3160 } else if (!strcmp (mimetype, "video/x-h261")) {
3163 } else if (!strcmp (mimetype, "video/mpeg")) {
3167 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3168 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3170 switch (mpegversion) {
3172 id = CODEC_ID_MPEG1VIDEO;
3175 id = CODEC_ID_MPEG2VIDEO;
3178 id = CODEC_ID_MPEG4;
3182 if (id != CODEC_ID_NONE)
3184 } else if (!strcmp (mimetype, "image/jpeg")) {
3185 id = CODEC_ID_MJPEG; /* A... B... */
3187 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3188 id = CODEC_ID_MJPEGB;
3190 } else if (!strcmp (mimetype, "video/x-wmv")) {
3191 gint wmvversion = 0;
3193 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3194 switch (wmvversion) {
3203 const gchar *format;
3205 /* WMV3 unless the fourcc exists and says otherwise */
3208 if ((format = gst_structure_get_string (structure, "format")) &&
3209 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3216 if (id != CODEC_ID_NONE)
3218 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3219 id = CODEC_ID_VORBIS;
3221 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3224 } else if (!strcmp (mimetype, "audio/mpeg")) {
3226 gint mpegversion = 0;
3228 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3229 switch (mpegversion) {
3230 case 2: /* ffmpeg uses faad for both... */
3235 if (gst_structure_get_int (structure, "layer", &layer)) {
3250 if (id != CODEC_ID_NONE)
3252 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3253 gint streamversion = -1;
3255 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3256 if (streamversion == 7)
3257 id = CODEC_ID_MUSEPACK7;
3259 id = CODEC_ID_MUSEPACK7;
3261 } else if (!strcmp (mimetype, "audio/x-wma")) {
3262 gint wmaversion = 0;
3264 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3265 switch (wmaversion) {
3267 id = CODEC_ID_WMAV1;
3270 id = CODEC_ID_WMAV2;
3273 id = CODEC_ID_WMAPRO;
3277 if (id != CODEC_ID_NONE)
3279 } else if (!strcmp (mimetype, "audio/x-wms")) {
3280 id = CODEC_ID_WMAVOICE;
3282 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3285 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3288 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3289 !strcmp (mimetype, "audio/atrac3")) {
3290 id = CODEC_ID_ATRAC3;
3292 } else if (!strcmp (mimetype, "audio/x-dts")) {
3295 } else if (!strcmp (mimetype, "application/x-ape")) {
3298 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3299 gint msmpegversion = 0;
3301 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3302 switch (msmpegversion) {
3304 id = CODEC_ID_MSMPEG4V1;
3307 id = CODEC_ID_MSMPEG4V2;
3310 id = CODEC_ID_MSMPEG4V3;
3314 if (id != CODEC_ID_NONE)
3316 } else if (!strcmp (mimetype, "video/x-svq")) {
3317 gint svqversion = 0;
3319 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3320 switch (svqversion) {
3329 if (id != CODEC_ID_NONE)
3331 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3332 id = CODEC_ID_HUFFYUV;
3334 } else if (!strcmp (mimetype, "audio/x-mace")) {
3335 gint maceversion = 0;
3337 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3338 switch (maceversion) {
3340 id = CODEC_ID_MACE3;
3343 id = CODEC_ID_MACE6;
3347 if (id != CODEC_ID_NONE)
3349 } else if (!strcmp (mimetype, "video/x-theora")) {
3350 id = CODEC_ID_THEORA;
3352 } else if (!strcmp (mimetype, "video/x-vp3")) {
3355 } else if (!strcmp (mimetype, "video/x-vp5")) {
3358 } else if (!strcmp (mimetype, "video/x-vp6")) {
3361 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3364 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3367 } else if (!strcmp (mimetype, "video/x-vp8")) {
3370 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3371 id = CODEC_ID_FLASHSV;
3373 } else if (!strcmp (mimetype, "video/x-indeo")) {
3374 gint indeoversion = 0;
3376 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3377 switch (indeoversion) {
3379 id = CODEC_ID_INDEO5;
3382 id = CODEC_ID_INDEO4;
3385 id = CODEC_ID_INDEO3;
3388 id = CODEC_ID_INDEO2;
3391 if (id != CODEC_ID_NONE)
3394 } else if (!strcmp (mimetype, "video/x-divx")) {
3395 gint divxversion = 0;
3397 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3398 switch (divxversion) {
3400 id = CODEC_ID_MSMPEG4V3;
3404 id = CODEC_ID_MPEG4;
3408 if (id != CODEC_ID_NONE)
3410 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3411 id = CODEC_ID_MPEG4;
3413 } else if (!strcmp (mimetype, "video/x-xvid")) {
3414 id = CODEC_ID_MPEG4;
3416 } else if (!strcmp (mimetype, "video/x-ffv")) {
3417 gint ffvversion = 0;
3419 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3424 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3425 const gchar *layout;
3427 layout = gst_structure_get_string (structure, "layout");
3428 if (layout == NULL) {
3430 } else if (!strcmp (layout, "quicktime")) {
3431 id = CODEC_ID_ADPCM_IMA_QT;
3432 } else if (!strcmp (layout, "microsoft")) {
3433 id = CODEC_ID_ADPCM_MS;
3434 } else if (!strcmp (layout, "dvi")) {
3435 id = CODEC_ID_ADPCM_IMA_WAV;
3436 } else if (!strcmp (layout, "4xm")) {
3437 id = CODEC_ID_ADPCM_4XM;
3438 } else if (!strcmp (layout, "smjpeg")) {
3439 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3440 } else if (!strcmp (layout, "dk3")) {
3441 id = CODEC_ID_ADPCM_IMA_DK3;
3442 } else if (!strcmp (layout, "dk4")) {
3443 id = CODEC_ID_ADPCM_IMA_DK4;
3444 } else if (!strcmp (layout, "westwood")) {
3445 id = CODEC_ID_ADPCM_IMA_WS;
3446 } else if (!strcmp (layout, "iss")) {
3447 id = CODEC_ID_ADPCM_IMA_ISS;
3448 } else if (!strcmp (layout, "xa")) {
3449 id = CODEC_ID_ADPCM_XA;
3450 } else if (!strcmp (layout, "adx")) {
3451 id = CODEC_ID_ADPCM_ADX;
3452 } else if (!strcmp (layout, "ea")) {
3453 id = CODEC_ID_ADPCM_EA;
3454 } else if (!strcmp (layout, "g726")) {
3455 id = CODEC_ID_ADPCM_G726;
3456 } else if (!strcmp (layout, "g721")) {
3457 id = CODEC_ID_ADPCM_G726;
3458 } else if (!strcmp (layout, "ct")) {
3459 id = CODEC_ID_ADPCM_CT;
3460 } else if (!strcmp (layout, "swf")) {
3461 id = CODEC_ID_ADPCM_SWF;
3462 } else if (!strcmp (layout, "yamaha")) {
3463 id = CODEC_ID_ADPCM_YAMAHA;
3464 } else if (!strcmp (layout, "sbpro2")) {
3465 id = CODEC_ID_ADPCM_SBPRO_2;
3466 } else if (!strcmp (layout, "sbpro3")) {
3467 id = CODEC_ID_ADPCM_SBPRO_3;
3468 } else if (!strcmp (layout, "sbpro4")) {
3469 id = CODEC_ID_ADPCM_SBPRO_4;
3471 if (id != CODEC_ID_NONE)
3473 } else if (!strcmp (mimetype, "video/x-4xm")) {
3476 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3477 const gchar *layout;
3479 layout = gst_structure_get_string (structure, "layout");
3482 } else if (!strcmp (layout, "roq")) {
3483 id = CODEC_ID_ROQ_DPCM;
3484 } else if (!strcmp (layout, "interplay")) {
3485 id = CODEC_ID_INTERPLAY_DPCM;
3486 } else if (!strcmp (layout, "xan")) {
3487 id = CODEC_ID_XAN_DPCM;
3488 } else if (!strcmp (layout, "sol")) {
3489 id = CODEC_ID_SOL_DPCM;
3491 if (id != CODEC_ID_NONE)
3493 } else if (!strcmp (mimetype, "audio/x-flac")) {
3496 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3497 id = CODEC_ID_SHORTEN;
3499 } else if (!strcmp (mimetype, "audio/x-alac")) {
3502 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3503 id = CODEC_ID_CINEPAK;
3505 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3508 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3509 switch (rmversion) {
3524 if (id != CODEC_ID_NONE)
3526 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3529 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3532 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3533 switch (raversion) {
3535 id = CODEC_ID_RA_144;
3538 id = CODEC_ID_RA_288;
3545 if (id != CODEC_ID_NONE)
3547 } else if (!strcmp (mimetype, "video/x-rle")) {
3548 const gchar *layout;
3550 if ((layout = gst_structure_get_string (structure, "layout"))) {
3551 if (!strcmp (layout, "microsoft")) {
3552 id = CODEC_ID_MSRLE;
3556 } else if (!strcmp (mimetype, "video/x-xan")) {
3559 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3560 switch (wcversion) {
3562 id = CODEC_ID_XAN_WC3;
3566 id = CODEC_ID_XAN_WC4;
3573 } else if (!strcmp (mimetype, "audio/AMR")) {
3575 id = CODEC_ID_AMR_NB;
3576 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3577 id = CODEC_ID_AMR_WB;
3579 } else if (!strcmp (mimetype, "audio/qcelp")) {
3580 id = CODEC_ID_QCELP;
3582 } else if (!strcmp (mimetype, "video/x-h264")) {
3585 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3586 gint flvversion = 0;
3588 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3589 switch (flvversion) {
3599 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3600 id = CODEC_ID_NELLYMOSER;
3602 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3606 if (strlen (mimetype) <= 30 &&
3607 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3608 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3609 (codec = avcodec_find_encoder_by_name (ext))) {
3614 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3618 if (strlen (mimetype) <= 30 &&
3619 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3620 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3621 (codec = avcodec_find_encoder_by_name (ext))) {
3628 if (context != NULL) {
3629 if (video == TRUE) {
3630 context->codec_type = AVMEDIA_TYPE_VIDEO;
3631 } else if (audio == TRUE) {
3632 context->codec_type = AVMEDIA_TYPE_AUDIO;
3634 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3636 context->codec_id = id;
3637 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3640 if (id != CODEC_ID_NONE) {
3641 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3643 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);