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 (AVCodecContext * context,
71 GstAudioChannelPosition * pos)
73 guint nchannels = 0, channels = context->channels;
74 guint64 channel_layout = context->channel_layout;
75 gboolean none_layout = FALSE;
77 if (channel_layout == 0) {
83 for (i = 0; i < 64; i++) {
84 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
89 if (nchannels != channels) {
90 GST_ERROR ("Number of channels is different (%u != %u)", channels,
96 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
97 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
98 pos[j++] = _ff_to_gst_layout[i].gst;
100 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
105 if (j != nchannels) {
107 ("Unknown channels in channel layout - assuming NONE layout");
114 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
115 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
116 " - assuming NONE layout", channel_layout);
121 if (nchannels == 1) {
122 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
123 } else if (nchannels == 2) {
124 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
125 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
129 for (i = 0; i < nchannels; i++)
130 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
137 /* this macro makes a caps width fixed or unfixed width/height
138 * properties depending on whether we've got a context.
140 * See below for why we use this.
142 * We should actually do this stuff at the end, like in riff-media.c,
143 * but I'm too lazy today. Maybe later.
146 gst_ff_vid_caps_new (AVCodecContext * context, enum CodecID codec_id,
147 gboolean encode, const char *mimetype, const char *fieldname, ...)
149 GstStructure *structure = NULL;
150 GstCaps *caps = NULL;
154 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
156 /* fixed, non probing context */
157 if (context != NULL && context->width != -1) {
160 caps = gst_caps_new_simple (mimetype,
161 "width", G_TYPE_INT, context->width,
162 "height", G_TYPE_INT, context->height, NULL);
164 num = context->time_base.den / context->ticks_per_frame;
165 denom = context->time_base.num;
168 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
171 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
172 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
176 GST_LOG ("setting framerate: %d/%d", num, denom);
177 gst_caps_set_simple (caps,
178 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
180 /* so we are after restricted caps in this case */
184 caps = gst_caps_new_simple (mimetype,
185 "width", G_TYPE_INT, 352,
186 "height", G_TYPE_INT, 288,
187 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
188 gst_caps_append (caps, gst_caps_new_simple (mimetype,
189 "width", G_TYPE_INT, 176,
190 "height", G_TYPE_INT, 144,
191 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
196 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
197 * because we want automatic negotiation to go as close to 320x240 as
199 const static gint widths[] = { 352, 704, 176, 1408, 128 };
200 const static gint heights[] = { 288, 576, 144, 1152, 96 };
202 gint n_sizes = G_N_ELEMENTS (widths);
204 caps = gst_caps_new_empty ();
205 for (i = 0; i < n_sizes; i++) {
206 temp = gst_caps_new_simple (mimetype,
207 "width", G_TYPE_INT, widths[i],
208 "height", G_TYPE_INT, heights[i],
209 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
211 gst_caps_append (caps, temp);
215 case CODEC_ID_DVVIDEO:
222 gint framerate_n, framerate_d;
225 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 10, 11, 30000, 1001}, {
226 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 40, 33, 30000, 1001}, {
227 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 59, 54, 25, 1}, {
228 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 118, 81, 25, 1}, {
229 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 59, 54, 25, 1}, {
230 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 118, 81, 25, 1}
233 gint n_sizes = G_N_ELEMENTS (profiles);
235 caps = gst_caps_new_empty ();
236 for (i = 0; i < n_sizes; i++) {
237 temp = gst_caps_new_simple (mimetype,
238 "width", G_TYPE_INT, profiles[i].width,
239 "height", G_TYPE_INT, profiles[i].height,
240 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
241 profiles[i].framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION,
242 profiles[i].par_n, profiles[i].par_d, NULL);
244 gst_caps_append (caps, temp);
250 caps = gst_caps_new_simple (mimetype,
251 "width", G_TYPE_INT, 1920,
252 "height", G_TYPE_INT, 1080,
253 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
254 gst_caps_append (caps, gst_caps_new_simple (mimetype,
255 "width", G_TYPE_INT, 1280,
256 "height", G_TYPE_INT, 720,
257 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
265 /* no fixed caps or special restrictions applied;
266 * default unfixed setting */
268 GST_DEBUG ("Creating default caps");
269 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
272 for (i = 0; i < gst_caps_get_size (caps); i++) {
273 va_start (var_args, fieldname);
274 structure = gst_caps_get_structure (caps, i);
275 gst_structure_set_valist (structure, fieldname, var_args);
282 /* same for audio - now with channels/sample rate
285 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
286 enum CodecID codec_id, gboolean encode, const char *mimetype,
287 const char *fieldname, ...)
289 GstCaps *caps = NULL;
290 GstStructure *structure = NULL;
294 /* fixed, non-probing context */
295 if (context != NULL && context->channels != -1) {
296 GstAudioChannelPosition pos[64];
298 caps = gst_caps_new_simple (mimetype,
299 "rate", G_TYPE_INT, context->sample_rate,
300 "channels", G_TYPE_INT, context->channels, NULL);
302 if (gst_ffmpeg_channel_layout_to_gst (context, pos)) {
305 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
307 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
312 gint maxchannels = 2;
313 const gint *rates = NULL;
316 /* so we must be after restricted caps in this case */
319 case CODEC_ID_AAC_LATM:
325 const static gint l_rates[] =
326 { 48000, 44100, 32000, 24000, 22050, 16000 };
327 n_rates = G_N_ELEMENTS (l_rates);
334 const static gint l_rates[] = { 48000, 44100, 32000 };
336 n_rates = G_N_ELEMENTS (l_rates);
340 case CODEC_ID_ADPCM_G722:
342 const static gint l_rates[] = { 16000 };
343 n_rates = G_N_ELEMENTS (l_rates);
348 case CODEC_ID_ADPCM_G726:
350 const static gint l_rates[] = { 8000 };
351 n_rates = G_N_ELEMENTS (l_rates);
356 case CODEC_ID_ADPCM_SWF:
358 const static gint l_rates[] = { 11025, 22050, 44100 };
359 n_rates = G_N_ELEMENTS (l_rates);
363 case CODEC_ID_ROQ_DPCM:
365 const static gint l_rates[] = { 22050 };
366 n_rates = G_N_ELEMENTS (l_rates);
370 case CODEC_ID_AMR_NB:
372 const static gint l_rates[] = { 8000 };
374 n_rates = G_N_ELEMENTS (l_rates);
378 case CODEC_ID_AMR_WB:
380 const static gint l_rates[] = { 16000 };
382 n_rates = G_N_ELEMENTS (l_rates);
390 /* TODO: handle context->channel_layouts here to set
391 * the list of channel layouts supported by the encoder.
392 * Unfortunately no encoder uses this yet....
394 /* regardless of encode/decode, open up channels if applicable */
395 /* Until decoders/encoders expose the maximum number of channels
396 * they support, we whitelist them here. */
398 case CODEC_ID_WMAPRO:
399 case CODEC_ID_TRUEHD:
406 if (maxchannels == 1)
407 caps = gst_caps_new_simple (mimetype,
408 "channels", G_TYPE_INT, maxchannels, NULL);
410 caps = gst_caps_new_simple (mimetype,
411 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
413 GValue list = { 0, };
414 GstStructure *structure;
416 g_value_init (&list, GST_TYPE_LIST);
417 for (i = 0; i < n_rates; i++) {
420 g_value_init (&v, G_TYPE_INT);
421 g_value_set_int (&v, rates[i]);
422 gst_value_list_append_value (&list, &v);
425 structure = gst_caps_get_structure (caps, 0);
426 gst_structure_set_value (structure, "rate", &list);
427 g_value_unset (&list);
428 } else if (codec && codec->supported_samplerates
429 && codec->supported_samplerates[0]) {
433 if (!codec->supported_samplerates[1]) {
434 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
435 codec->supported_samplerates[0], NULL);
437 const int *rates = codec->supported_samplerates;
439 g_value_init (&va, GST_TYPE_LIST);
440 g_value_init (&v, G_TYPE_INT);
443 g_value_set_int (&v, *rates);
444 gst_value_list_append_value (&va, &v);
447 gst_caps_set_value (caps, "rate", &va);
452 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
455 caps = gst_caps_new_empty_simple (mimetype);
458 for (i = 0; i < gst_caps_get_size (caps); i++) {
459 va_start (var_args, fieldname);
460 structure = gst_caps_get_structure (caps, i);
461 gst_structure_set_valist (structure, fieldname, var_args);
468 /* Convert a FFMPEG codec ID and optional AVCodecContext
469 * to a GstCaps. If the context is ommitted, no fixed values
470 * for video/audio size will be included in the GstCaps
472 * CodecID is primarily meant for compressed data GstCaps!
474 * encode is a special parameter. gstffmpegdec will say
475 * FALSE, gstffmpegenc will say TRUE. The output caps
476 * depends on this, in such a way that it will be very
477 * specific, defined, fixed and correct caps for encoders,
478 * yet very wide, "forgiving" caps for decoders. Example
479 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
480 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
485 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
486 AVCodecContext * context, gboolean encode)
488 GstCaps *caps = NULL;
489 gboolean buildcaps = FALSE;
491 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
494 case CODEC_ID_MPEG1VIDEO:
496 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
497 "mpegversion", G_TYPE_INT, 1,
498 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
501 case CODEC_ID_MPEG2VIDEO:
504 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
505 "mpegversion", G_TYPE_INT, 2,
506 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
508 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
509 * the MPEG video stream headers, so may be omitted from caps. */
510 caps = gst_caps_new_simple ("video/mpeg",
511 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
512 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
516 case CODEC_ID_MPEG2VIDEO_XVMC:
517 /* this is a special ID - don't need it in GStreamer, I think */
522 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
523 "variant", G_TYPE_STRING, "itu",
524 "h263version", G_TYPE_STRING, "h263", NULL);
526 /* don't pass codec_id, we can decode other variants with the H263
527 * decoder that don't have specific size requirements
530 gst_ff_vid_caps_new (context, CODEC_ID_NONE, encode, "video/x-h263",
531 "variant", G_TYPE_STRING, "itu", NULL);
536 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
537 "variant", G_TYPE_STRING, "itu",
538 "h263version", G_TYPE_STRING, "h263p", NULL);
539 if (encode && context) {
541 gst_caps_set_simple (caps,
542 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
543 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
544 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
545 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
552 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-intel-h263",
553 "variant", G_TYPE_STRING, "intel", NULL);
558 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h261", NULL);
583 /* FIXME: context->sub_id must be filled in during decoding */
585 gst_ff_vid_caps_new (context, codec_id, encode,
586 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
587 "rmversion", G_TYPE_INT, version, NULL);
589 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
590 if (context->extradata_size >= 8) {
591 gst_caps_set_simple (caps,
592 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
601 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
602 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
607 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
608 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
615 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
616 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
618 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
619 * in the MPEG audio header, so may be omitted from caps. */
620 caps = gst_caps_new_simple ("audio/mpeg",
621 "mpegversion", G_TYPE_INT, 1,
622 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
626 case CODEC_ID_MUSEPACK7:
628 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
629 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
633 case CODEC_ID_MUSEPACK8:
635 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
636 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
643 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
650 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
654 case CODEC_ID_TRUEHD:
656 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
657 "audio/x-true-hd", NULL);
660 case CODEC_ID_ATRAC1:
662 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
663 "audio/x-vnd.sony.atrac1", NULL);
666 case CODEC_ID_ATRAC3:
668 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
669 "audio/x-vnd.sony.atrac3", NULL);
674 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
680 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
681 "audio/x-ffmpeg-parsed-ape", NULL);
683 gst_caps_set_simple (caps,
684 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
690 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
696 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
700 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
701 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
702 * sp5x is, but it's apparently something JPEG... We don't separate
703 * between those in GStreamer. Should we (at least between MJPEG,
704 * MJPEG-B and sp5x decoding...)? */
708 gst_ff_vid_caps_new (context, codec_id, encode, "image/jpeg", NULL);
713 gst_ff_vid_caps_new (context, codec_id, encode, "video/sp5x", NULL);
716 case CODEC_ID_MJPEGB:
718 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mjpeg-b",
723 if (encode && context != NULL) {
724 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
725 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
726 switch (context->codec_tag) {
727 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
729 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-divx",
730 "divxversion", G_TYPE_INT, 5, NULL);
732 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
735 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
736 "systemstream", G_TYPE_BOOLEAN, FALSE,
737 "mpegversion", G_TYPE_INT, 4, NULL);
741 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
742 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
743 "mpegversion", G_TYPE_INT, 4,
744 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
746 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
747 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
749 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
750 "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4, 5,
752 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
753 "video/x-xvid", NULL));
754 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
755 "video/x-3ivx", NULL));
760 case CODEC_ID_RAWVIDEO:
762 gst_ffmpeg_codectype_to_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
766 case CODEC_ID_MSMPEG4V1:
767 case CODEC_ID_MSMPEG4V2:
768 case CODEC_ID_MSMPEG4V3:
770 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
772 /* encode-FIXME: bitrate */
773 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-msmpeg",
774 "msmpegversion", G_TYPE_INT, version, NULL);
775 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
776 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
777 "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
785 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
787 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
788 "wmvversion", G_TYPE_INT, version, NULL);
794 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-flash-video",
795 "flvversion", G_TYPE_INT, 1, NULL);
799 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
800 "svqversion", G_TYPE_INT, 1, NULL);
804 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
805 "svqversion", G_TYPE_INT, 3, NULL);
808 case CODEC_ID_DVAUDIO:
810 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
814 case CODEC_ID_DVVIDEO:
816 if (encode && context) {
819 switch (context->pix_fmt) {
820 case PIX_FMT_YUYV422:
823 case PIX_FMT_YUV420P:
826 case PIX_FMT_YUVA420P:
829 case PIX_FMT_YUV411P:
832 case PIX_FMT_YUV422P:
835 case PIX_FMT_YUV410P:
840 ("Couldnt' find format for pixfmt %d, defaulting to I420",
845 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
846 "systemstream", G_TYPE_BOOLEAN, FALSE,
847 "format", G_TYPE_STRING, format, NULL);
849 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
850 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
858 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
862 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
863 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
864 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
868 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
869 "wmaversion", G_TYPE_INT, version, "block_align",
870 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
875 case CODEC_ID_WMAPRO:
878 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
879 "wmaversion", G_TYPE_INT, 3, NULL);
883 case CODEC_ID_WMAVOICE:
886 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
894 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
897 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
898 "maceversion", G_TYPE_INT, version, NULL);
902 case CODEC_ID_HUFFYUV:
904 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-huffyuv",
907 gst_caps_set_simple (caps,
908 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
914 gst_ff_vid_caps_new (context, codec_id, encode,
915 "video/x-compressed-yuv", NULL);
920 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h264",
921 "alignment", G_TYPE_STRING, "au", NULL);
924 case CODEC_ID_INDEO5:
925 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
926 "indeoversion", G_TYPE_INT, 5, NULL);
929 case CODEC_ID_INDEO4:
930 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
931 "indeoversion", G_TYPE_INT, 4, NULL);
934 case CODEC_ID_INDEO3:
935 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
936 "indeoversion", G_TYPE_INT, 3, NULL);
939 case CODEC_ID_INDEO2:
940 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
941 "indeoversion", G_TYPE_INT, 2, NULL);
944 case CODEC_ID_FLASHSV:
946 gst_ff_vid_caps_new (context, codec_id, encode,
947 "video/x-flash-screen", NULL);
952 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp3", NULL);
957 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp5", NULL);
962 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6", NULL);
967 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-flash",
973 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-alpha",
979 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp8", NULL);
982 case CODEC_ID_THEORA:
984 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-theora",
991 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
996 GValue item = { 0, };
998 g_value_init (&arr, GST_TYPE_LIST);
999 g_value_init (&item, G_TYPE_INT);
1000 g_value_set_int (&item, 2);
1001 gst_value_list_append_value (&arr, &item);
1002 g_value_set_int (&item, 4);
1003 gst_value_list_append_value (&arr, &item);
1004 g_value_unset (&item);
1006 gst_caps_set_value (caps, "mpegversion", &arr);
1007 g_value_unset (&arr);
1009 g_value_init (&arr, GST_TYPE_LIST);
1010 g_value_init (&item, G_TYPE_STRING);
1011 g_value_set_string (&item, "raw");
1012 gst_value_list_append_value (&arr, &item);
1013 g_value_set_string (&item, "adts");
1014 gst_value_list_append_value (&arr, &item);
1015 g_value_set_string (&item, "adif");
1016 gst_value_list_append_value (&arr, &item);
1017 g_value_unset (&item);
1019 gst_caps_set_value (caps, "stream-format", &arr);
1020 g_value_unset (&arr);
1022 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1023 "stream-format", G_TYPE_STRING, "raw",
1024 "base-profile", G_TYPE_STRING, "lc", NULL);
1026 if (context && context->extradata_size > 0)
1027 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1028 context->extradata, context->extradata_size);
1033 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1034 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1035 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1040 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1041 "asusversion", G_TYPE_INT, 1, NULL);
1044 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1045 "asusversion", G_TYPE_INT, 2, NULL);
1049 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ffv",
1050 "ffvversion", G_TYPE_INT, 1, NULL);
1055 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-4xm", NULL);
1058 case CODEC_ID_XAN_WC3:
1059 case CODEC_ID_XAN_WC4:
1060 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-xan",
1061 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1066 gst_ff_vid_caps_new (context, codec_id, encode,
1067 "video/x-cirrus-logic-accupak", NULL);
1070 case CODEC_ID_FRAPS:
1072 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-fraps",
1078 case CODEC_ID_INTERPLAY_VIDEO:
1083 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ati-vcr",
1084 "vcrversion", G_TYPE_INT, 1, NULL);
1089 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-apple-video",
1093 case CODEC_ID_CINEPAK:
1095 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-cinepak",
1099 /* WS_VQA belogns here (order) */
1101 case CODEC_ID_MSRLE:
1102 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1103 "layout", G_TYPE_STRING, "microsoft", NULL);
1105 gst_caps_set_simple (caps,
1106 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1108 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1112 case CODEC_ID_QTRLE:
1113 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1114 "layout", G_TYPE_STRING, "quicktime", NULL);
1116 gst_caps_set_simple (caps,
1117 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1119 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1123 case CODEC_ID_MSVIDEO1:
1125 gst_ff_vid_caps_new (context, codec_id, encode,
1126 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1130 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1131 "wmvversion", G_TYPE_INT, 3, NULL);
1134 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1135 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1139 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1145 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mszh", NULL);
1150 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zlib", NULL);
1153 case CODEC_ID_TRUEMOTION1:
1155 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1156 "trueversion", G_TYPE_INT, 1, NULL);
1158 case CODEC_ID_TRUEMOTION2:
1160 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1161 "trueversion", G_TYPE_INT, 2, NULL);
1166 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ultimotion",
1172 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camtasia",
1175 gst_caps_set_simple (caps,
1176 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1178 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1184 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-kmvc", NULL);
1189 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-nuv", NULL);
1193 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/gif", NULL);
1197 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/png", NULL);
1201 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/ppm", NULL);
1205 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/pbm", NULL);
1210 gst_ff_vid_caps_new (context, codec_id, encode,
1211 "image/x-portable-anymap", NULL);
1216 gst_ff_vid_caps_new (context, codec_id, encode,
1217 "image/x-portable-graymap", NULL);
1222 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-pcx", NULL);
1227 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sgi", NULL);
1230 case CODEC_ID_TARGA:
1232 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-tga", NULL);
1237 gst_ff_vid_caps_new (context, codec_id, encode, "image/tiff", NULL);
1240 case CODEC_ID_SUNRAST:
1242 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sun-raster",
1248 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-smc", NULL);
1251 case CODEC_ID_QDRAW:
1253 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-qdrw", NULL);
1256 case CODEC_ID_DNXHD:
1258 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dnxhd",
1262 case CODEC_ID_PRORES:
1264 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-prores",
1268 case CODEC_ID_MIMIC:
1270 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mimic",
1276 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vmnc", NULL);
1279 case CODEC_ID_TRUESPEECH:
1281 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1282 "audio/x-truespeech", NULL);
1285 case CODEC_ID_QCELP:
1287 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1293 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-amv", NULL);
1298 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-aasc", NULL);
1303 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-loco", NULL);
1308 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zmbv", NULL);
1311 case CODEC_ID_LAGARITH:
1313 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-lagarith",
1319 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camstudio",
1322 gst_caps_set_simple (caps,
1323 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1325 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1329 case CODEC_ID_WS_VQA:
1330 case CODEC_ID_IDCIN:
1333 case CODEC_ID_VMDVIDEO:
1334 case CODEC_ID_VMDAUDIO:
1338 case CODEC_ID_PGMYUV:
1339 case CODEC_ID_FFVHUFF:
1341 case CODEC_ID_MP3ADU:
1342 case CODEC_ID_MP3ON4:
1343 case CODEC_ID_WESTWOOD_SND1:
1344 case CODEC_ID_MMVIDEO:
1350 /* weird quasi-codecs for the demuxers only */
1351 case CODEC_ID_PCM_S16LE:
1352 case CODEC_ID_PCM_S16BE:
1353 case CODEC_ID_PCM_U16LE:
1354 case CODEC_ID_PCM_U16BE:
1355 case CODEC_ID_PCM_S8:
1356 case CODEC_ID_PCM_U8:
1358 GstAudioFormat format;
1361 case CODEC_ID_PCM_S16LE:
1362 format = GST_AUDIO_FORMAT_S16LE;
1364 case CODEC_ID_PCM_S16BE:
1365 format = GST_AUDIO_FORMAT_S16BE;
1367 case CODEC_ID_PCM_U16LE:
1368 format = GST_AUDIO_FORMAT_U16LE;
1370 case CODEC_ID_PCM_U16BE:
1371 format = GST_AUDIO_FORMAT_U16BE;
1373 case CODEC_ID_PCM_S8:
1374 format = GST_AUDIO_FORMAT_S8;
1376 case CODEC_ID_PCM_U8:
1377 format = GST_AUDIO_FORMAT_U8;
1380 g_assert (0); /* don't worry, we never get here */
1385 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1386 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1387 "layout", G_TYPE_STRING, "interleaved", NULL);
1391 case CODEC_ID_PCM_MULAW:
1393 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1397 case CODEC_ID_PCM_ALAW:
1399 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1403 case CODEC_ID_ADPCM_G722:
1405 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1408 gst_caps_set_simple (caps,
1409 "block_align", G_TYPE_INT, context->block_align,
1410 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1413 case CODEC_ID_ADPCM_G726:
1415 /* the G726 decoder can also handle G721 */
1417 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1418 "layout", G_TYPE_STRING, "g726", NULL);
1420 gst_caps_set_simple (caps,
1421 "block_align", G_TYPE_INT, context->block_align,
1422 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1425 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1426 "layout", G_TYPE_STRING, "g721",
1427 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1431 case CODEC_ID_ADPCM_IMA_QT:
1432 case CODEC_ID_ADPCM_IMA_WAV:
1433 case CODEC_ID_ADPCM_IMA_DK3:
1434 case CODEC_ID_ADPCM_IMA_DK4:
1435 case CODEC_ID_ADPCM_IMA_WS:
1436 case CODEC_ID_ADPCM_IMA_SMJPEG:
1437 case CODEC_ID_ADPCM_IMA_AMV:
1438 case CODEC_ID_ADPCM_IMA_ISS:
1439 case CODEC_ID_ADPCM_IMA_EA_EACS:
1440 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1441 case CODEC_ID_ADPCM_MS:
1442 case CODEC_ID_ADPCM_4XM:
1443 case CODEC_ID_ADPCM_XA:
1444 case CODEC_ID_ADPCM_ADX:
1445 case CODEC_ID_ADPCM_EA:
1446 case CODEC_ID_ADPCM_CT:
1447 case CODEC_ID_ADPCM_SWF:
1448 case CODEC_ID_ADPCM_YAMAHA:
1449 case CODEC_ID_ADPCM_SBPRO_2:
1450 case CODEC_ID_ADPCM_SBPRO_3:
1451 case CODEC_ID_ADPCM_SBPRO_4:
1452 case CODEC_ID_ADPCM_EA_R1:
1453 case CODEC_ID_ADPCM_EA_R2:
1454 case CODEC_ID_ADPCM_EA_R3:
1455 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1456 case CODEC_ID_ADPCM_EA_XAS:
1457 case CODEC_ID_ADPCM_THP:
1459 const gchar *layout = NULL;
1462 case CODEC_ID_ADPCM_IMA_QT:
1463 layout = "quicktime";
1465 case CODEC_ID_ADPCM_IMA_WAV:
1468 case CODEC_ID_ADPCM_IMA_DK3:
1471 case CODEC_ID_ADPCM_IMA_DK4:
1474 case CODEC_ID_ADPCM_IMA_WS:
1475 layout = "westwood";
1477 case CODEC_ID_ADPCM_IMA_SMJPEG:
1480 case CODEC_ID_ADPCM_IMA_AMV:
1483 case CODEC_ID_ADPCM_IMA_ISS:
1486 case CODEC_ID_ADPCM_IMA_EA_EACS:
1489 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1492 case CODEC_ID_ADPCM_MS:
1493 layout = "microsoft";
1495 case CODEC_ID_ADPCM_4XM:
1498 case CODEC_ID_ADPCM_XA:
1501 case CODEC_ID_ADPCM_ADX:
1504 case CODEC_ID_ADPCM_EA:
1507 case CODEC_ID_ADPCM_CT:
1510 case CODEC_ID_ADPCM_SWF:
1513 case CODEC_ID_ADPCM_YAMAHA:
1516 case CODEC_ID_ADPCM_SBPRO_2:
1519 case CODEC_ID_ADPCM_SBPRO_3:
1522 case CODEC_ID_ADPCM_SBPRO_4:
1525 case CODEC_ID_ADPCM_EA_R1:
1528 case CODEC_ID_ADPCM_EA_R2:
1531 case CODEC_ID_ADPCM_EA_R3:
1534 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1535 layout = "ea-maxis-xa";
1537 case CODEC_ID_ADPCM_EA_XAS:
1540 case CODEC_ID_ADPCM_THP:
1544 g_assert (0); /* don't worry, we never get here */
1548 /* FIXME: someone please check whether we need additional properties
1549 * in this caps definition. */
1551 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1552 "layout", G_TYPE_STRING, layout, NULL);
1554 gst_caps_set_simple (caps,
1555 "block_align", G_TYPE_INT, context->block_align,
1556 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1560 case CODEC_ID_AMR_NB:
1562 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1566 case CODEC_ID_AMR_WB:
1568 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1574 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1578 case CODEC_ID_GSM_MS:
1580 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1584 case CODEC_ID_NELLYMOSER:
1586 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1587 "audio/x-nellymoser", NULL);
1593 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1596 gst_caps_set_simple (caps,
1597 "leaf_size", G_TYPE_INT, context->block_align,
1598 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1603 case CODEC_ID_RA_144:
1604 case CODEC_ID_RA_288:
1610 case CODEC_ID_RA_144:
1613 case CODEC_ID_RA_288:
1623 /* FIXME: properties? */
1625 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1626 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1628 gst_caps_set_simple (caps,
1629 "leaf_size", G_TYPE_INT, context->block_align,
1630 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1635 case CODEC_ID_ROQ_DPCM:
1636 case CODEC_ID_INTERPLAY_DPCM:
1637 case CODEC_ID_XAN_DPCM:
1638 case CODEC_ID_SOL_DPCM:
1640 const gchar *layout = NULL;
1643 case CODEC_ID_ROQ_DPCM:
1646 case CODEC_ID_INTERPLAY_DPCM:
1647 layout = "interplay";
1649 case CODEC_ID_XAN_DPCM:
1652 case CODEC_ID_SOL_DPCM:
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-dpcm",
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_SHORTEN:
1673 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1678 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1681 gst_caps_set_simple (caps,
1682 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1687 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1688 * encoder case, we want to add things like samplerate, channels... */
1690 caps = gst_caps_new_empty_simple ("audio/x-flac");
1694 case CODEC_ID_DVD_SUBTITLE:
1695 case CODEC_ID_DVB_SUBTITLE:
1699 caps = gst_caps_new_empty_simple ("image/bmp");
1703 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1706 gst_caps_set_simple (caps,
1707 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1710 case CODEC_ID_TWINVQ:
1712 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1713 "audio/x-twin-vq", NULL);
1716 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1723 if ((codec = avcodec_find_decoder (codec_id)) ||
1724 (codec = avcodec_find_encoder (codec_id))) {
1727 GST_LOG ("Could not create stream format caps for %s", codec->name);
1729 switch (codec->type) {
1730 case AVMEDIA_TYPE_VIDEO:
1731 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1732 caps = gst_ff_vid_caps_new (context, codec_id, encode, mime, NULL);
1735 case AVMEDIA_TYPE_AUDIO:
1736 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1738 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
1740 gst_caps_set_simple (caps,
1741 "block_align", G_TYPE_INT, context->block_align,
1742 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1753 /* set private data */
1754 if (context && context->extradata_size > 0) {
1755 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1757 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1758 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1759 gst_buffer_unref (data);
1762 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1765 GST_LOG ("No caps found for codec_id=%d", codec_id);
1771 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1772 * to a GstCaps. If the context is ommitted, no fixed values
1773 * for video/audio size will be included in the GstCaps
1775 * See below for usefullness
1779 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1780 enum CodecID codec_id)
1782 GstCaps *caps = NULL;
1783 GstVideoFormat format;
1785 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
1787 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1788 caps = gst_ff_vid_caps_new (context, codec_id, TRUE, "video/x-raw",
1789 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1793 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1795 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1802 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
1804 switch (sample_fmt) {
1805 case AV_SAMPLE_FMT_U8:
1806 case AV_SAMPLE_FMT_U8P:
1807 return GST_AUDIO_FORMAT_U8;
1809 case AV_SAMPLE_FMT_S16:
1810 case AV_SAMPLE_FMT_S16P:
1811 return GST_AUDIO_FORMAT_S16;
1813 case AV_SAMPLE_FMT_S32:
1814 case AV_SAMPLE_FMT_S32P:
1815 return GST_AUDIO_FORMAT_S32;
1817 case AV_SAMPLE_FMT_FLT:
1818 case AV_SAMPLE_FMT_FLTP:
1819 return GST_AUDIO_FORMAT_F32;
1821 case AV_SAMPLE_FMT_DBL:
1822 case AV_SAMPLE_FMT_DBLP:
1823 return GST_AUDIO_FORMAT_F64;
1827 return GST_AUDIO_FORMAT_UNKNOWN;
1832 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1833 * to a GstCaps. If the context is ommitted, no fixed values
1834 * for video/audio size will be included in the GstCaps
1836 * See below for usefullness
1840 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
1841 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
1843 GstCaps *caps = NULL;
1844 GstAudioFormat format;
1846 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
1848 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1849 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
1850 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1851 "layout", G_TYPE_STRING, "interleaved", NULL);
1852 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1854 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1861 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
1862 const enum AVSampleFormat *fmts)
1866 GstAudioFormat format;
1868 if (!fmts || fmts[0] == -1) {
1871 g_value_init (&va, GST_TYPE_LIST);
1872 g_value_init (&v, G_TYPE_STRING);
1873 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
1874 format = gst_ffmpeg_smpfmt_to_audioformat (i);
1875 g_value_set_string (&v, gst_audio_format_to_string (format));
1876 gst_value_list_append_value (&va, &v);
1878 gst_caps_set_value (caps, "format", &va);
1880 g_value_unset (&va);
1884 /* Only a single rate */
1885 if (fmts[1] == -1) {
1886 format = gst_ffmpeg_smpfmt_to_audioformat (fmts[0]);
1887 gst_caps_set_simple (caps, "format", G_TYPE_STRING,
1888 gst_audio_format_to_string (format), NULL);
1892 g_value_init (&va, GST_TYPE_LIST);
1893 g_value_init (&v, G_TYPE_STRING);
1894 while (*fmts != -1) {
1895 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
1896 g_value_set_string (&v, gst_audio_format_to_string (format));
1897 gst_value_list_append_value (&va, &v);
1900 gst_caps_set_value (caps, "format", &va);
1902 g_value_unset (&va);
1906 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
1907 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1909 GstCaps *caps = NULL;
1911 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1912 context, codec_id, encode, codec);
1914 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
1915 codec->sample_fmts, codec->supported_samplerates);
1918 /* Specific codec context */
1920 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
1923 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
1924 "layout", G_TYPE_STRING, "interleaved", NULL);
1926 gst_ffmpeg_audio_set_sample_fmts (caps, codec ? codec->sample_fmts : NULL);
1933 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
1934 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1938 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1939 context, codec_id, encode, codec);
1942 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
1946 AVCodecContext ctx = { 0, };
1948 caps = gst_caps_new_empty ();
1949 for (i = 0; i < PIX_FMT_NB; i++) {
1952 temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1954 gst_caps_append (caps, temp);
1961 /* Convert a FFMPEG codec Type and optional AVCodecContext
1962 * to a GstCaps. If the context is ommitted, no fixed values
1963 * for video/audio size will be included in the GstCaps
1965 * AVMediaType is primarily meant for uncompressed data GstCaps!
1969 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
1970 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
1974 switch (codec_type) {
1975 case AVMEDIA_TYPE_VIDEO:
1977 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1979 case AVMEDIA_TYPE_AUDIO:
1981 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
1991 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
1992 * and other audio properties in a AVCodecContext.
1994 * For usefullness, see below
1998 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
1999 AVCodecContext * context, gboolean raw)
2001 GstStructure *structure;
2003 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2005 g_return_if_fail (gst_caps_get_size (caps) == 1);
2007 structure = gst_caps_get_structure (caps, 0);
2009 gst_structure_get_int (structure, "channels", &context->channels);
2010 gst_structure_get_int (structure, "rate", &context->sample_rate);
2011 gst_structure_get_int (structure, "block_align", &context->block_align);
2012 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2017 if (gst_structure_has_name (structure, "audio/x-raw")) {
2018 if ((fmt = gst_structure_get_string (structure, "format"))) {
2019 format = gst_audio_format_from_string (fmt);
2024 case GST_AUDIO_FORMAT_F32:
2025 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2027 case GST_AUDIO_FORMAT_F64:
2028 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2030 case GST_AUDIO_FORMAT_S32:
2031 context->sample_fmt = AV_SAMPLE_FMT_S32;
2033 case GST_AUDIO_FORMAT_S16:
2034 context->sample_fmt = AV_SAMPLE_FMT_S16;
2041 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2042 * and other video properties in a AVCodecContext.
2044 * For usefullness, see below
2048 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2049 AVCodecContext * context, gboolean raw)
2051 GstStructure *structure;
2053 const GValue *par = NULL;
2055 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2057 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2058 g_return_if_fail (gst_caps_get_size (caps) == 1);
2059 structure = gst_caps_get_structure (caps, 0);
2061 gst_structure_get_int (structure, "width", &context->width);
2062 gst_structure_get_int (structure, "height", &context->height);
2063 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2065 fps = gst_structure_get_value (structure, "framerate");
2066 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2068 /* somehow these seem mixed up.. */
2069 context->time_base.den = gst_value_get_fraction_numerator (fps);
2070 context->time_base.num = gst_value_get_fraction_denominator (fps);
2071 context->ticks_per_frame = 1;
2073 GST_DEBUG ("setting framerate %d/%d = %lf",
2074 context->time_base.den, context->time_base.num,
2075 1. * context->time_base.den / context->time_base.num);
2078 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2079 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2081 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2082 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2084 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2085 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2086 1. * context->sample_aspect_ratio.den /
2087 context->sample_aspect_ratio.num);
2093 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2095 if (gst_structure_has_name (structure, "video/x-raw")) {
2096 if ((fmt = gst_structure_get_string (structure, "format"))) {
2097 format = gst_video_format_from_string (fmt);
2102 case GST_VIDEO_FORMAT_YUY2:
2103 context->pix_fmt = PIX_FMT_YUYV422;
2105 case GST_VIDEO_FORMAT_I420:
2106 context->pix_fmt = PIX_FMT_YUV420P;
2108 case GST_VIDEO_FORMAT_A420:
2109 context->pix_fmt = PIX_FMT_YUVA420P;
2111 case GST_VIDEO_FORMAT_Y41B:
2112 context->pix_fmt = PIX_FMT_YUV411P;
2114 case GST_VIDEO_FORMAT_Y42B:
2115 context->pix_fmt = PIX_FMT_YUV422P;
2117 case GST_VIDEO_FORMAT_YUV9:
2118 context->pix_fmt = PIX_FMT_YUV410P;
2120 case GST_VIDEO_FORMAT_Y444:
2121 context->pix_fmt = PIX_FMT_YUV444P;
2123 case GST_VIDEO_FORMAT_GRAY8:
2124 context->pix_fmt = PIX_FMT_GRAY8;
2126 case GST_VIDEO_FORMAT_xRGB:
2127 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2128 context->pix_fmt = PIX_FMT_RGB32;
2131 case GST_VIDEO_FORMAT_BGRx:
2132 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2133 context->pix_fmt = PIX_FMT_RGB32;
2136 case GST_VIDEO_FORMAT_RGB:
2137 context->pix_fmt = PIX_FMT_RGB24;
2139 case GST_VIDEO_FORMAT_BGR:
2140 context->pix_fmt = PIX_FMT_BGR24;
2142 case GST_VIDEO_FORMAT_RGB16:
2143 context->pix_fmt = PIX_FMT_RGB565;
2145 case GST_VIDEO_FORMAT_RGB15:
2146 context->pix_fmt = PIX_FMT_RGB555;
2148 case GST_VIDEO_FORMAT_RGB8P:
2149 context->pix_fmt = PIX_FMT_PAL8;
2158 GstVideoFormat format;
2159 enum PixelFormat pixfmt;
2162 /* FIXME : FILLME */
2163 static const PixToFmt pixtofmttable[] = {
2164 /* GST_VIDEO_FORMAT_I420, */
2165 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2166 /* Note : this should use a different chroma placement */
2167 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2169 /* GST_VIDEO_FORMAT_YV12, */
2170 /* GST_VIDEO_FORMAT_YUY2, */
2171 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2172 /* GST_VIDEO_FORMAT_UYVY, */
2173 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2174 /* GST_VIDEO_FORMAT_AYUV, */
2175 /* GST_VIDEO_FORMAT_RGBx, */
2176 /* GST_VIDEO_FORMAT_BGRx, */
2177 /* GST_VIDEO_FORMAT_xRGB, */
2178 /* GST_VIDEO_FORMAT_xBGR, */
2179 /* GST_VIDEO_FORMAT_RGBA, */
2180 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2181 /* GST_VIDEO_FORMAT_BGRA, */
2182 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2183 /* GST_VIDEO_FORMAT_ARGB, */
2184 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2185 /* GST_VIDEO_FORMAT_ABGR, */
2186 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2187 /* GST_VIDEO_FORMAT_RGB, */
2188 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2189 /* GST_VIDEO_FORMAT_BGR, */
2190 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2191 /* GST_VIDEO_FORMAT_Y41B, */
2192 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2193 /* GST_VIDEO_FORMAT_Y42B, */
2194 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2195 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2196 /* GST_VIDEO_FORMAT_YVYU, */
2197 /* GST_VIDEO_FORMAT_Y444, */
2198 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2199 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2200 /* GST_VIDEO_FORMAT_v210, */
2201 /* GST_VIDEO_FORMAT_v216, */
2202 /* GST_VIDEO_FORMAT_NV12, */
2203 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2204 /* GST_VIDEO_FORMAT_NV21, */
2205 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2206 /* GST_VIDEO_FORMAT_GRAY8, */
2207 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2208 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2209 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2210 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2211 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2212 /* GST_VIDEO_FORMAT_v308, */
2213 /* GST_VIDEO_FORMAT_Y800, */
2214 /* GST_VIDEO_FORMAT_Y16, */
2215 /* GST_VIDEO_FORMAT_RGB16, */
2216 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2217 /* GST_VIDEO_FORMAT_BGR16, */
2218 /* GST_VIDEO_FORMAT_RGB15, */
2219 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2220 /* GST_VIDEO_FORMAT_BGR15, */
2221 /* GST_VIDEO_FORMAT_UYVP, */
2222 /* GST_VIDEO_FORMAT_A420, */
2223 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2224 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2225 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2226 /* GST_VIDEO_FORMAT_YUV9, */
2227 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2228 /* GST_VIDEO_FORMAT_YVU9, */
2229 /* GST_VIDEO_FORMAT_IYU1, */
2230 /* GST_VIDEO_FORMAT_ARGB64, */
2231 /* GST_VIDEO_FORMAT_AYUV64, */
2232 /* GST_VIDEO_FORMAT_r210, */
2233 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2234 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2235 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2236 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2237 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2238 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2239 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2240 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2241 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2245 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2249 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2250 if (pixtofmttable[i].pixfmt == pixfmt)
2251 return pixtofmttable[i].format;
2253 GST_WARNING ("Unknown pixel format %d", pixfmt);
2254 return GST_VIDEO_FORMAT_UNKNOWN;
2258 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2262 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2263 if (pixtofmttable[i].format == format)
2264 return pixtofmttable[i].pixfmt;
2265 return PIX_FMT_NONE;
2269 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2273 context->width = GST_VIDEO_INFO_WIDTH (info);
2274 context->height = GST_VIDEO_INFO_HEIGHT (info);
2275 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2276 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2277 context->bits_per_coded_sample = bpp;
2279 context->ticks_per_frame = 1;
2280 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2281 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2283 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2284 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2287 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2291 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2293 const AVCodec *codec;
2294 const enum AVSampleFormat *smpl_fmts;
2295 enum AVSampleFormat smpl_fmt = -1;
2297 context->channels = info->channels;
2298 context->sample_rate = info->rate;
2300 codec = context->codec;
2302 smpl_fmts = codec->sample_fmts;
2304 switch (info->finfo->format) {
2305 case GST_AUDIO_FORMAT_F32:
2307 while (*smpl_fmts != -1) {
2308 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2309 smpl_fmt = *smpl_fmts;
2311 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2312 smpl_fmt = *smpl_fmts;
2318 smpl_fmt = AV_SAMPLE_FMT_FLT;
2321 case GST_AUDIO_FORMAT_F64:
2323 while (*smpl_fmts != -1) {
2324 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2325 smpl_fmt = *smpl_fmts;
2327 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2328 smpl_fmt = *smpl_fmts;
2334 smpl_fmt = AV_SAMPLE_FMT_DBL;
2337 case GST_AUDIO_FORMAT_S32:
2339 while (*smpl_fmts != -1) {
2340 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2341 smpl_fmt = *smpl_fmts;
2343 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2344 smpl_fmt = *smpl_fmts;
2350 smpl_fmt = AV_SAMPLE_FMT_S32;
2353 case GST_AUDIO_FORMAT_S16:
2355 while (*smpl_fmts != -1) {
2356 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2357 smpl_fmt = *smpl_fmts;
2359 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2360 smpl_fmt = *smpl_fmts;
2366 smpl_fmt = AV_SAMPLE_FMT_S16;
2369 case GST_AUDIO_FORMAT_U8:
2371 while (*smpl_fmts != -1) {
2372 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2373 smpl_fmt = *smpl_fmts;
2375 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2376 smpl_fmt = *smpl_fmts;
2382 smpl_fmt = AV_SAMPLE_FMT_U8;
2389 g_assert (smpl_fmt != -1);
2391 context->sample_fmt = smpl_fmt;
2394 /* Convert a GstCaps and a FFMPEG codec Type to a
2395 * AVCodecContext. If the context is ommitted, no fixed values
2396 * for video/audio size will be included in the context
2398 * AVMediaType is primarily meant for uncompressed data GstCaps!
2402 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2403 const GstCaps * caps, AVCodecContext * context)
2405 if (context == NULL)
2409 case AVMEDIA_TYPE_VIDEO:
2410 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2413 case AVMEDIA_TYPE_AUDIO:
2414 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2425 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2429 guint8 *end = src + size;
2432 while (srcp < end) {
2433 if (count == 2 && *srcp <= 0x03) {
2434 GST_DEBUG ("added escape code");
2443 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2446 *destsize = dstp - dst;
2449 /* copy the config, escaping NAL units as we iterate them, if something fails we
2450 * copy everything and hope for the best. */
2452 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2457 guint nalsize, esize;
2467 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2469 GST_DEBUG ("num SPS %d", cnt);
2471 memcpy (dstp, srcp, 6);
2475 for (i = 0; i < cnt; i++) {
2476 GST_DEBUG ("copy SPS %d", i);
2477 nalsize = (srcp[0] << 8) | srcp[1];
2478 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2479 dstp[0] = esize >> 8;
2480 dstp[1] = esize & 0xff;
2482 srcp += nalsize + 2;
2485 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2487 GST_DEBUG ("num PPS %d", cnt);
2489 for (i = 0; i < cnt; i++) {
2490 GST_DEBUG ("copy PPS %d", i);
2491 nalsize = (srcp[0] << 8) | srcp[1];
2492 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2493 dstp[0] = esize >> 8;
2494 dstp[1] = esize & 0xff;
2496 srcp += nalsize + 2;
2498 *destsize = dstp - dst;
2504 GST_DEBUG ("something unexpected, doing full copy");
2505 memcpy (dst, src, size);
2513 * caps_with_codecid () transforms a GstCaps for a known codec
2514 * ID into a filled-in context.
2515 * codec_data from caps will override possible extradata already in the context
2519 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2520 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2523 const GValue *value;
2526 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2527 codec_id, codec_type, caps, context);
2529 if (!context || !gst_caps_get_size (caps))
2532 str = gst_caps_get_structure (caps, 0);
2534 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2535 if ((value = gst_structure_get_value (str, "codec_data"))) {
2538 buf = gst_value_get_buffer (value);
2539 gst_buffer_map (buf, &map, GST_MAP_READ);
2541 /* free the old one if it is there */
2542 if (context->extradata)
2543 av_free (context->extradata);
2546 if (codec_id == CODEC_ID_H264) {
2549 GST_DEBUG ("copy, escaping codec_data %d", size);
2550 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2551 * reason for this but let's just escape it for now. Start by allocating
2552 * enough space, x2 is more than enough.
2554 * FIXME, we disabled escaping because some file already contain escaped
2555 * codec_data and then we escape twice and fail. It's better to leave it
2556 * as is, as that is what most players do. */
2557 context->extradata =
2558 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2559 FF_INPUT_BUFFER_PADDING_SIZE));
2560 copy_config (context->extradata, data, size, &extrasize);
2561 GST_DEBUG ("escaped size: %d", extrasize);
2562 context->extradata_size = extrasize;
2566 /* allocate with enough padding */
2567 GST_DEBUG ("copy codec_data");
2568 context->extradata =
2569 av_mallocz (GST_ROUND_UP_16 (map.size +
2570 FF_INPUT_BUFFER_PADDING_SIZE));
2571 memcpy (context->extradata, map.data, map.size);
2572 context->extradata_size = map.size;
2575 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2576 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2577 context->extradata[0] = (guint8) map.size;
2580 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2582 gst_buffer_unmap (buf, &map);
2583 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2584 codec_id != CODEC_ID_FLAC) {
2585 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2586 * extradata anyway which makes then segfault. */
2587 context->extradata =
2588 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2589 context->extradata_size = 0;
2590 GST_DEBUG ("no codec data");
2594 case CODEC_ID_MPEG4:
2596 const gchar *mime = gst_structure_get_name (str);
2598 if (!strcmp (mime, "video/x-divx"))
2599 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2600 else if (!strcmp (mime, "video/x-xvid"))
2601 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2602 else if (!strcmp (mime, "video/x-3ivx"))
2603 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2604 else if (!strcmp (mime, "video/mpeg"))
2605 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2610 /* FIXME: this is a workaround for older gst-plugins releases
2611 * (<= 0.8.9). This should be removed at some point, because
2612 * it causes wrong decoded frame order. */
2613 if (!context->extradata) {
2614 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2617 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2618 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2619 gst_structure_get_int (str, "low_delay", &low_delay) ||
2620 gst_structure_get_int (str, "unknown_svq3_flag",
2621 &unknown_svq3_flag)) {
2622 context->extradata = (guint8 *) av_mallocz (0x64);
2623 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2627 flags |= unknown_svq3_flag;
2629 flags |= halfpel_flag;
2631 flags |= thirdpel_flag;
2634 flags = GUINT16_FROM_LE (flags);
2636 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2637 context->extradata_size = 0x64;
2642 case CODEC_ID_MSRLE:
2643 case CODEC_ID_QTRLE:
2650 if (gst_structure_get_int (str, "depth", &depth)) {
2651 context->bits_per_coded_sample = depth;
2653 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2666 if (gst_structure_get_int (str, "format", &format))
2667 context->sub_id = format;
2672 case CODEC_ID_RA_288:
2673 case CODEC_ID_RA_144:
2679 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2680 context->block_align = leaf_size;
2681 if (gst_structure_get_int (str, "bitrate", &bitrate))
2682 context->bit_rate = bitrate;
2685 gst_structure_get_int (str, "samplesize",
2686 &context->bits_per_coded_sample);
2689 case CODEC_ID_DVVIDEO:
2691 const gchar *format;
2693 if ((format = gst_structure_get_string (str, "format"))) {
2695 if (g_str_equal (format, "YUY2"))
2696 context->pix_fmt = PIX_FMT_YUYV422;
2697 else if (g_str_equal (format, "I420"))
2698 context->pix_fmt = PIX_FMT_YUV420P;
2699 else if (g_str_equal (format, "A420"))
2700 context->pix_fmt = PIX_FMT_YUVA420P;
2701 else if (g_str_equal (format, "Y41B"))
2702 context->pix_fmt = PIX_FMT_YUV411P;
2703 else if (g_str_equal (format, "Y42B"))
2704 context->pix_fmt = PIX_FMT_YUV422P;
2705 else if (g_str_equal (format, "YUV9"))
2706 context->pix_fmt = PIX_FMT_YUV410P;
2708 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2712 GST_WARNING ("No specified format");
2715 case CODEC_ID_H263P:
2719 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2720 context->flags |= CODEC_FLAG_4MV;
2722 context->flags &= ~CODEC_FLAG_4MV;
2723 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2724 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2725 context->flags |= CODEC_FLAG_AC_PRED;
2727 context->flags &= ~CODEC_FLAG_AC_PRED;
2728 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2729 context->flags |= CODEC_FLAG_LOOP_FILTER;
2731 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2734 case CODEC_ID_ADPCM_G726:
2736 const gchar *layout;
2738 if ((layout = gst_structure_get_string (str, "layout"))) {
2739 if (!strcmp (layout, "g721")) {
2740 context->sample_rate = 8000;
2741 context->channels = 1;
2742 context->bit_rate = 32000;
2751 if (!gst_caps_is_fixed (caps))
2754 /* common properties (width, height, fps) */
2755 switch (codec_type) {
2756 case AVMEDIA_TYPE_VIDEO:
2757 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2759 case AVMEDIA_TYPE_AUDIO:
2760 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2766 /* fixup of default settings */
2768 case CODEC_ID_QCELP:
2769 /* QCELP is always mono, no matter what the caps say */
2770 context->channels = 1;
2777 /* _formatid_to_caps () is meant for muxers/demuxers, it
2778 * transforms a name (ffmpeg way of ID'ing these, why don't
2779 * they have unique numerical IDs?) to the corresponding
2780 * caps belonging to that mux-format
2782 * Note: we don't need any additional info because the caps
2783 * isn't supposed to contain any useful info besides the
2788 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2790 GstCaps *caps = NULL;
2792 if (!strcmp (format_name, "mpeg")) {
2793 caps = gst_caps_new_simple ("video/mpeg",
2794 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2795 } else if (!strcmp (format_name, "mpegts")) {
2796 caps = gst_caps_new_simple ("video/mpegts",
2797 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2798 } else if (!strcmp (format_name, "rm")) {
2799 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2800 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2801 } else if (!strcmp (format_name, "asf")) {
2802 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2803 } else if (!strcmp (format_name, "avi")) {
2804 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2805 } else if (!strcmp (format_name, "wav")) {
2806 caps = gst_caps_new_empty_simple ("audio/x-wav");
2807 } else if (!strcmp (format_name, "ape")) {
2808 caps = gst_caps_new_empty_simple ("application/x-ape");
2809 } else if (!strcmp (format_name, "swf")) {
2810 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2811 } else if (!strcmp (format_name, "au")) {
2812 caps = gst_caps_new_empty_simple ("audio/x-au");
2813 } else if (!strcmp (format_name, "dv")) {
2814 caps = gst_caps_new_simple ("video/x-dv",
2815 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2816 } else if (!strcmp (format_name, "4xm")) {
2817 caps = gst_caps_new_empty_simple ("video/x-4xm");
2818 } else if (!strcmp (format_name, "matroska")) {
2819 caps = gst_caps_new_empty_simple ("video/x-matroska");
2820 } else if (!strcmp (format_name, "mp3")) {
2821 caps = gst_caps_new_empty_simple ("application/x-id3");
2822 } else if (!strcmp (format_name, "flic")) {
2823 caps = gst_caps_new_empty_simple ("video/x-fli");
2824 } else if (!strcmp (format_name, "flv")) {
2825 caps = gst_caps_new_empty_simple ("video/x-flv");
2826 } else if (!strcmp (format_name, "tta")) {
2827 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
2828 } else if (!strcmp (format_name, "aiff")) {
2829 caps = gst_caps_new_empty_simple ("audio/x-aiff");
2830 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2832 gst_caps_from_string
2833 ("application/x-3gp; video/quicktime; audio/x-m4a");
2834 } else if (!strcmp (format_name, "mov")) {
2835 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2836 } else if (!strcmp (format_name, "mp4")) {
2837 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2838 } else if (!strcmp (format_name, "3gp")) {
2839 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2840 } else if (!strcmp (format_name, "3g2")) {
2841 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2842 } else if (!strcmp (format_name, "psp")) {
2843 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2844 } else if (!strcmp (format_name, "ipod")) {
2845 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2846 } else if (!strcmp (format_name, "aac")) {
2847 caps = gst_caps_new_simple ("audio/mpeg",
2848 "mpegversion", G_TYPE_INT, 4, NULL);
2849 } else if (!strcmp (format_name, "gif")) {
2850 caps = gst_caps_from_string ("image/gif");
2851 } else if (!strcmp (format_name, "ogg")) {
2852 caps = gst_caps_from_string ("application/ogg");
2853 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
2854 caps = gst_caps_from_string ("application/mxf");
2855 } else if (!strcmp (format_name, "gxf")) {
2856 caps = gst_caps_from_string ("application/gxf");
2857 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
2858 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
2859 "y4mversion", G_TYPE_INT, 2, NULL);
2860 } else if (!strcmp (format_name, "mpc")) {
2861 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
2862 } else if (!strcmp (format_name, "vqf")) {
2863 caps = gst_caps_from_string ("audio/x-vqf");
2864 } else if (!strcmp (format_name, "nsv")) {
2865 caps = gst_caps_from_string ("video/x-nsv");
2866 } else if (!strcmp (format_name, "amr")) {
2867 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
2868 } else if (!strcmp (format_name, "webm")) {
2869 caps = gst_caps_from_string ("video/webm");
2870 } else if (!strcmp (format_name, "voc")) {
2871 caps = gst_caps_from_string ("audio/x-voc");
2875 GST_LOG ("Could not create stream format caps for %s", format_name);
2876 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
2877 caps = gst_caps_new_empty_simple (name);
2885 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
2886 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
2887 AVOutputFormat * plugin)
2889 static enum CodecID tmp_vlist[] = {
2893 static enum CodecID tmp_alist[] = {
2898 GST_LOG ("format_name : %s", format_name);
2900 if (!strcmp (format_name, "mp4")) {
2901 static enum CodecID mp4_video_list[] = {
2902 CODEC_ID_MPEG4, CODEC_ID_H264,
2906 static enum CodecID mp4_audio_list[] = {
2907 CODEC_ID_AAC, CODEC_ID_MP3,
2911 *video_codec_list = mp4_video_list;
2912 *audio_codec_list = mp4_audio_list;
2913 } else if (!strcmp (format_name, "mpeg")) {
2914 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
2915 CODEC_ID_MPEG2VIDEO,
2919 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
2925 *video_codec_list = mpeg_video_list;
2926 *audio_codec_list = mpeg_audio_list;
2927 } else if (!strcmp (format_name, "dvd")) {
2928 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
2931 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
2938 *video_codec_list = mpeg_video_list;
2939 *audio_codec_list = mpeg_audio_list;
2940 } else if (!strcmp (format_name, "mpegts")) {
2941 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
2942 CODEC_ID_MPEG2VIDEO,
2946 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
2954 *video_codec_list = mpegts_video_list;
2955 *audio_codec_list = mpegts_audio_list;
2956 } else if (!strcmp (format_name, "vob")) {
2957 static enum CodecID vob_video_list[] =
2958 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
2959 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
2960 CODEC_ID_DTS, CODEC_ID_NONE
2963 *video_codec_list = vob_video_list;
2964 *audio_codec_list = vob_audio_list;
2965 } else if (!strcmp (format_name, "flv")) {
2966 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
2967 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
2969 *video_codec_list = flv_video_list;
2970 *audio_codec_list = flv_audio_list;
2971 } else if (!strcmp (format_name, "asf")) {
2972 static enum CodecID asf_video_list[] =
2973 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
2974 static enum CodecID asf_audio_list[] =
2975 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
2977 *video_codec_list = asf_video_list;
2978 *audio_codec_list = asf_audio_list;
2979 } else if (!strcmp (format_name, "dv")) {
2980 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
2981 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
2983 *video_codec_list = dv_video_list;
2984 *audio_codec_list = dv_audio_list;
2985 } else if (!strcmp (format_name, "mov")) {
2986 static enum CodecID mov_video_list[] = {
2987 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
2988 CODEC_ID_H263, CODEC_ID_H263P,
2989 CODEC_ID_H264, CODEC_ID_DVVIDEO,
2993 static enum CodecID mov_audio_list[] = {
2994 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
2995 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
2996 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2997 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
2998 CODEC_ID_MP3, CODEC_ID_NONE
3001 *video_codec_list = mov_video_list;
3002 *audio_codec_list = mov_audio_list;
3003 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3004 static enum CodecID tgp_video_list[] = {
3005 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
3008 static enum CodecID tgp_audio_list[] = {
3009 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3014 *video_codec_list = tgp_video_list;
3015 *audio_codec_list = tgp_audio_list;
3016 } else if (!strcmp (format_name, "mmf")) {
3017 static enum CodecID mmf_audio_list[] = {
3018 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
3020 *video_codec_list = NULL;
3021 *audio_codec_list = mmf_audio_list;
3022 } else if (!strcmp (format_name, "amr")) {
3023 static enum CodecID amr_audio_list[] = {
3024 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3027 *video_codec_list = NULL;
3028 *audio_codec_list = amr_audio_list;
3029 } else if (!strcmp (format_name, "gif")) {
3030 static enum CodecID gif_image_list[] = {
3031 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
3033 *video_codec_list = gif_image_list;
3034 *audio_codec_list = NULL;
3035 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
3036 (plugin->video_codec != CODEC_ID_NONE)) {
3037 tmp_vlist[0] = plugin->video_codec;
3038 tmp_alist[0] = plugin->audio_codec;
3040 *video_codec_list = tmp_vlist;
3041 *audio_codec_list = tmp_alist;
3043 GST_LOG ("Format %s not found", format_name);
3050 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3051 * are omitted, that can be queried by the user itself,
3052 * we're not eating the GstCaps or anything
3053 * A pointer to an allocated context is also needed for
3054 * optional extra info
3058 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3060 enum CodecID id = CODEC_ID_NONE;
3061 const gchar *mimetype;
3062 const GstStructure *structure;
3063 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3065 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3066 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3067 structure = gst_caps_get_structure (caps, 0);
3069 mimetype = gst_structure_get_name (structure);
3071 if (!strcmp (mimetype, "video/x-raw")) {
3072 id = CODEC_ID_RAWVIDEO;
3074 } else if (!strcmp (mimetype, "audio/x-raw")) {
3077 if (gst_audio_info_from_caps (&info, caps)) {
3078 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3079 case GST_AUDIO_FORMAT_S8:
3080 id = CODEC_ID_PCM_S8;
3082 case GST_AUDIO_FORMAT_U8:
3083 id = CODEC_ID_PCM_U8;
3085 case GST_AUDIO_FORMAT_S16LE:
3086 id = CODEC_ID_PCM_S16LE;
3088 case GST_AUDIO_FORMAT_S16BE:
3089 id = CODEC_ID_PCM_S16BE;
3091 case GST_AUDIO_FORMAT_U16LE:
3092 id = CODEC_ID_PCM_U16LE;
3094 case GST_AUDIO_FORMAT_U16BE:
3095 id = CODEC_ID_PCM_U16BE;
3100 if (id != CODEC_ID_NONE)
3103 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3104 id = CODEC_ID_PCM_MULAW;
3106 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3107 id = CODEC_ID_PCM_ALAW;
3109 } else if (!strcmp (mimetype, "video/x-dv")) {
3112 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3114 id = CODEC_ID_DVVIDEO;
3117 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3118 id = CODEC_ID_DVAUDIO;
3120 } else if (!strcmp (mimetype, "video/x-h263")) {
3121 const gchar *h263version =
3122 gst_structure_get_string (structure, "h263version");
3123 if (h263version && !strcmp (h263version, "h263p"))
3124 id = CODEC_ID_H263P;
3128 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3129 id = CODEC_ID_H263I;
3131 } else if (!strcmp (mimetype, "video/x-h261")) {
3134 } else if (!strcmp (mimetype, "video/mpeg")) {
3138 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3139 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3141 switch (mpegversion) {
3143 id = CODEC_ID_MPEG1VIDEO;
3146 id = CODEC_ID_MPEG2VIDEO;
3149 id = CODEC_ID_MPEG4;
3153 if (id != CODEC_ID_NONE)
3155 } else if (!strcmp (mimetype, "image/jpeg")) {
3156 id = CODEC_ID_MJPEG; /* A... B... */
3158 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3159 id = CODEC_ID_MJPEGB;
3161 } else if (!strcmp (mimetype, "video/x-wmv")) {
3162 gint wmvversion = 0;
3164 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3165 switch (wmvversion) {
3174 const gchar *format;
3176 /* WMV3 unless the fourcc exists and says otherwise */
3179 if ((format = gst_structure_get_string (structure, "format")) &&
3180 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3187 if (id != CODEC_ID_NONE)
3189 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3190 id = CODEC_ID_VORBIS;
3192 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3195 } else if (!strcmp (mimetype, "audio/mpeg")) {
3197 gint mpegversion = 0;
3199 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3200 switch (mpegversion) {
3201 case 2: /* ffmpeg uses faad for both... */
3206 if (gst_structure_get_int (structure, "layer", &layer)) {
3221 if (id != CODEC_ID_NONE)
3223 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3224 gint streamversion = -1;
3226 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3227 if (streamversion == 7)
3228 id = CODEC_ID_MUSEPACK7;
3230 id = CODEC_ID_MUSEPACK7;
3232 } else if (!strcmp (mimetype, "audio/x-wma")) {
3233 gint wmaversion = 0;
3235 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3236 switch (wmaversion) {
3238 id = CODEC_ID_WMAV1;
3241 id = CODEC_ID_WMAV2;
3244 id = CODEC_ID_WMAPRO;
3248 if (id != CODEC_ID_NONE)
3250 } else if (!strcmp (mimetype, "audio/x-wms")) {
3251 id = CODEC_ID_WMAVOICE;
3253 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3256 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3259 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3260 !strcmp (mimetype, "audio/atrac3")) {
3261 id = CODEC_ID_ATRAC3;
3263 } else if (!strcmp (mimetype, "audio/x-dts")) {
3266 } else if (!strcmp (mimetype, "application/x-ape")) {
3269 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3270 gint msmpegversion = 0;
3272 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3273 switch (msmpegversion) {
3275 id = CODEC_ID_MSMPEG4V1;
3278 id = CODEC_ID_MSMPEG4V2;
3281 id = CODEC_ID_MSMPEG4V3;
3285 if (id != CODEC_ID_NONE)
3287 } else if (!strcmp (mimetype, "video/x-svq")) {
3288 gint svqversion = 0;
3290 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3291 switch (svqversion) {
3300 if (id != CODEC_ID_NONE)
3302 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3303 id = CODEC_ID_HUFFYUV;
3305 } else if (!strcmp (mimetype, "audio/x-mace")) {
3306 gint maceversion = 0;
3308 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3309 switch (maceversion) {
3311 id = CODEC_ID_MACE3;
3314 id = CODEC_ID_MACE6;
3318 if (id != CODEC_ID_NONE)
3320 } else if (!strcmp (mimetype, "video/x-theora")) {
3321 id = CODEC_ID_THEORA;
3323 } else if (!strcmp (mimetype, "video/x-vp3")) {
3326 } else if (!strcmp (mimetype, "video/x-vp5")) {
3329 } else if (!strcmp (mimetype, "video/x-vp6")) {
3332 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3335 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3338 } else if (!strcmp (mimetype, "video/x-vp8")) {
3341 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3342 id = CODEC_ID_FLASHSV;
3344 } else if (!strcmp (mimetype, "video/x-indeo")) {
3345 gint indeoversion = 0;
3347 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3348 switch (indeoversion) {
3350 id = CODEC_ID_INDEO5;
3353 id = CODEC_ID_INDEO4;
3356 id = CODEC_ID_INDEO3;
3359 id = CODEC_ID_INDEO2;
3362 if (id != CODEC_ID_NONE)
3365 } else if (!strcmp (mimetype, "video/x-divx")) {
3366 gint divxversion = 0;
3368 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3369 switch (divxversion) {
3371 id = CODEC_ID_MSMPEG4V3;
3375 id = CODEC_ID_MPEG4;
3379 if (id != CODEC_ID_NONE)
3381 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3382 id = CODEC_ID_MPEG4;
3384 } else if (!strcmp (mimetype, "video/x-xvid")) {
3385 id = CODEC_ID_MPEG4;
3387 } else if (!strcmp (mimetype, "video/x-ffv")) {
3388 gint ffvversion = 0;
3390 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3395 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3396 const gchar *layout;
3398 layout = gst_structure_get_string (structure, "layout");
3399 if (layout == NULL) {
3401 } else if (!strcmp (layout, "quicktime")) {
3402 id = CODEC_ID_ADPCM_IMA_QT;
3403 } else if (!strcmp (layout, "microsoft")) {
3404 id = CODEC_ID_ADPCM_MS;
3405 } else if (!strcmp (layout, "dvi")) {
3406 id = CODEC_ID_ADPCM_IMA_WAV;
3407 } else if (!strcmp (layout, "4xm")) {
3408 id = CODEC_ID_ADPCM_4XM;
3409 } else if (!strcmp (layout, "smjpeg")) {
3410 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3411 } else if (!strcmp (layout, "dk3")) {
3412 id = CODEC_ID_ADPCM_IMA_DK3;
3413 } else if (!strcmp (layout, "dk4")) {
3414 id = CODEC_ID_ADPCM_IMA_DK4;
3415 } else if (!strcmp (layout, "westwood")) {
3416 id = CODEC_ID_ADPCM_IMA_WS;
3417 } else if (!strcmp (layout, "iss")) {
3418 id = CODEC_ID_ADPCM_IMA_ISS;
3419 } else if (!strcmp (layout, "xa")) {
3420 id = CODEC_ID_ADPCM_XA;
3421 } else if (!strcmp (layout, "adx")) {
3422 id = CODEC_ID_ADPCM_ADX;
3423 } else if (!strcmp (layout, "ea")) {
3424 id = CODEC_ID_ADPCM_EA;
3425 } else if (!strcmp (layout, "g726")) {
3426 id = CODEC_ID_ADPCM_G726;
3427 } else if (!strcmp (layout, "g721")) {
3428 id = CODEC_ID_ADPCM_G726;
3429 } else if (!strcmp (layout, "ct")) {
3430 id = CODEC_ID_ADPCM_CT;
3431 } else if (!strcmp (layout, "swf")) {
3432 id = CODEC_ID_ADPCM_SWF;
3433 } else if (!strcmp (layout, "yamaha")) {
3434 id = CODEC_ID_ADPCM_YAMAHA;
3435 } else if (!strcmp (layout, "sbpro2")) {
3436 id = CODEC_ID_ADPCM_SBPRO_2;
3437 } else if (!strcmp (layout, "sbpro3")) {
3438 id = CODEC_ID_ADPCM_SBPRO_3;
3439 } else if (!strcmp (layout, "sbpro4")) {
3440 id = CODEC_ID_ADPCM_SBPRO_4;
3442 if (id != CODEC_ID_NONE)
3444 } else if (!strcmp (mimetype, "video/x-4xm")) {
3447 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3448 const gchar *layout;
3450 layout = gst_structure_get_string (structure, "layout");
3453 } else if (!strcmp (layout, "roq")) {
3454 id = CODEC_ID_ROQ_DPCM;
3455 } else if (!strcmp (layout, "interplay")) {
3456 id = CODEC_ID_INTERPLAY_DPCM;
3457 } else if (!strcmp (layout, "xan")) {
3458 id = CODEC_ID_XAN_DPCM;
3459 } else if (!strcmp (layout, "sol")) {
3460 id = CODEC_ID_SOL_DPCM;
3462 if (id != CODEC_ID_NONE)
3464 } else if (!strcmp (mimetype, "audio/x-flac")) {
3467 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3468 id = CODEC_ID_SHORTEN;
3470 } else if (!strcmp (mimetype, "audio/x-alac")) {
3473 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3474 id = CODEC_ID_CINEPAK;
3476 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3479 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3480 switch (rmversion) {
3495 if (id != CODEC_ID_NONE)
3497 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3500 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3503 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3504 switch (raversion) {
3506 id = CODEC_ID_RA_144;
3509 id = CODEC_ID_RA_288;
3516 if (id != CODEC_ID_NONE)
3518 } else if (!strcmp (mimetype, "video/x-rle")) {
3519 const gchar *layout;
3521 if ((layout = gst_structure_get_string (structure, "layout"))) {
3522 if (!strcmp (layout, "microsoft")) {
3523 id = CODEC_ID_MSRLE;
3527 } else if (!strcmp (mimetype, "video/x-xan")) {
3530 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3531 switch (wcversion) {
3533 id = CODEC_ID_XAN_WC3;
3537 id = CODEC_ID_XAN_WC4;
3544 } else if (!strcmp (mimetype, "audio/AMR")) {
3546 id = CODEC_ID_AMR_NB;
3547 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3548 id = CODEC_ID_AMR_WB;
3550 } else if (!strcmp (mimetype, "audio/qcelp")) {
3551 id = CODEC_ID_QCELP;
3553 } else if (!strcmp (mimetype, "video/x-h264")) {
3556 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3557 gint flvversion = 0;
3559 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3560 switch (flvversion) {
3570 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3571 id = CODEC_ID_NELLYMOSER;
3573 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3577 if (strlen (mimetype) <= 30 &&
3578 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3579 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3580 (codec = avcodec_find_encoder_by_name (ext))) {
3585 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3589 if (strlen (mimetype) <= 30 &&
3590 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3591 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3592 (codec = avcodec_find_encoder_by_name (ext))) {
3599 if (context != NULL) {
3600 if (video == TRUE) {
3601 context->codec_type = AVMEDIA_TYPE_VIDEO;
3602 } else if (audio == TRUE) {
3603 context->codec_type = AVMEDIA_TYPE_AUDIO;
3605 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3607 context->codec_id = id;
3608 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3611 if (id != CODEC_ID_NONE) {
3612 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3614 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);