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, enum CodecID codec_id,
286 gboolean encode, const char *mimetype, const char *fieldname, ...)
288 GstCaps *caps = NULL;
289 GstStructure *structure = NULL;
293 /* fixed, non-probing context */
294 if (context != NULL && context->channels != -1) {
295 GstAudioChannelPosition pos[64];
297 caps = gst_caps_new_simple (mimetype,
298 "rate", G_TYPE_INT, context->sample_rate,
299 "channels", G_TYPE_INT, context->channels, NULL);
301 if (gst_ffmpeg_channel_layout_to_gst (context, pos)) {
304 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
306 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
311 gint maxchannels = 2;
312 const gint *rates = NULL;
315 /* so we must be after restricted caps in this case */
318 case CODEC_ID_AAC_LATM:
324 const static gint l_rates[] =
325 { 48000, 44100, 32000, 24000, 22050, 16000 };
326 n_rates = G_N_ELEMENTS (l_rates);
333 const static gint l_rates[] = { 48000, 44100, 32000 };
335 n_rates = G_N_ELEMENTS (l_rates);
339 case CODEC_ID_ADPCM_G722:
341 const static gint l_rates[] = { 16000 };
342 n_rates = G_N_ELEMENTS (l_rates);
347 case CODEC_ID_ADPCM_G726:
349 const static gint l_rates[] = { 8000 };
350 n_rates = G_N_ELEMENTS (l_rates);
355 case CODEC_ID_ADPCM_SWF:
357 const static gint l_rates[] = { 11025, 22050, 44100 };
358 n_rates = G_N_ELEMENTS (l_rates);
362 case CODEC_ID_ROQ_DPCM:
364 const static gint l_rates[] = { 22050 };
365 n_rates = G_N_ELEMENTS (l_rates);
369 case CODEC_ID_AMR_NB:
371 const static gint l_rates[] = { 8000 };
373 n_rates = G_N_ELEMENTS (l_rates);
377 case CODEC_ID_AMR_WB:
379 const static gint l_rates[] = { 16000 };
381 n_rates = G_N_ELEMENTS (l_rates);
389 /* TODO: handle context->channel_layouts here to set
390 * the list of channel layouts supported by the encoder.
391 * Unfortunately no encoder uses this yet....
393 /* regardless of encode/decode, open up channels if applicable */
394 /* Until decoders/encoders expose the maximum number of channels
395 * they support, we whitelist them here. */
397 case CODEC_ID_WMAPRO:
398 case CODEC_ID_TRUEHD:
405 if (maxchannels == 1)
406 caps = gst_caps_new_simple (mimetype,
407 "channels", G_TYPE_INT, maxchannels, NULL);
409 caps = gst_caps_new_simple (mimetype,
410 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
412 GValue list = { 0, };
413 GstStructure *structure;
415 g_value_init (&list, GST_TYPE_LIST);
416 for (i = 0; i < n_rates; i++) {
419 g_value_init (&v, G_TYPE_INT);
420 g_value_set_int (&v, rates[i]);
421 gst_value_list_append_value (&list, &v);
424 structure = gst_caps_get_structure (caps, 0);
425 gst_structure_set_value (structure, "rate", &list);
426 g_value_unset (&list);
428 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
430 caps = gst_caps_new_empty_simple (mimetype);
433 for (i = 0; i < gst_caps_get_size (caps); i++) {
434 va_start (var_args, fieldname);
435 structure = gst_caps_get_structure (caps, i);
436 gst_structure_set_valist (structure, fieldname, var_args);
443 /* Convert a FFMPEG codec ID and optional AVCodecContext
444 * to a GstCaps. If the context is ommitted, no fixed values
445 * for video/audio size will be included in the GstCaps
447 * CodecID is primarily meant for compressed data GstCaps!
449 * encode is a special parameter. gstffmpegdec will say
450 * FALSE, gstffmpegenc will say TRUE. The output caps
451 * depends on this, in such a way that it will be very
452 * specific, defined, fixed and correct caps for encoders,
453 * yet very wide, "forgiving" caps for decoders. Example
454 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
455 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
460 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
461 AVCodecContext * context, gboolean encode)
463 GstCaps *caps = NULL;
464 gboolean buildcaps = FALSE;
466 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
469 case CODEC_ID_MPEG1VIDEO:
471 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
472 "mpegversion", G_TYPE_INT, 1,
473 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
476 case CODEC_ID_MPEG2VIDEO:
479 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
480 "mpegversion", G_TYPE_INT, 2,
481 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
483 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
484 * the MPEG video stream headers, so may be omitted from caps. */
485 caps = gst_caps_new_simple ("video/mpeg",
486 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
487 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
491 case CODEC_ID_MPEG2VIDEO_XVMC:
492 /* this is a special ID - don't need it in GStreamer, I think */
497 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
498 "variant", G_TYPE_STRING, "itu",
499 "h263version", G_TYPE_STRING, "h263", NULL);
501 /* don't pass codec_id, we can decode other variants with the H263
502 * decoder that don't have specific size requirements
505 gst_ff_vid_caps_new (context, CODEC_ID_NONE, encode, "video/x-h263",
506 "variant", G_TYPE_STRING, "itu", NULL);
511 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
512 "variant", G_TYPE_STRING, "itu",
513 "h263version", G_TYPE_STRING, "h263p", NULL);
514 if (encode && context) {
516 gst_caps_set_simple (caps,
517 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
518 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
519 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
520 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
527 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-intel-h263",
528 "variant", G_TYPE_STRING, "intel", NULL);
533 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h261", NULL);
558 /* FIXME: context->sub_id must be filled in during decoding */
560 gst_ff_vid_caps_new (context, codec_id, encode,
561 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
562 "rmversion", G_TYPE_INT, version, NULL);
564 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
565 if (context->extradata_size >= 8) {
566 gst_caps_set_simple (caps,
567 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
576 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
577 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
582 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
583 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
589 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
590 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
592 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
593 * in the MPEG audio header, so may be omitted from caps. */
594 caps = gst_caps_new_simple ("audio/mpeg",
595 "mpegversion", G_TYPE_INT, 1,
596 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
600 case CODEC_ID_MUSEPACK7:
602 gst_ff_aud_caps_new (context, codec_id, encode,
603 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
607 case CODEC_ID_MUSEPACK8:
609 gst_ff_aud_caps_new (context, codec_id, encode,
610 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
617 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-ac3", NULL);
623 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-eac3", NULL);
626 case CODEC_ID_TRUEHD:
628 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-true-hd",
632 case CODEC_ID_ATRAC1:
634 gst_ff_aud_caps_new (context, codec_id, encode,
635 "audio/x-vnd.sony.atrac1", NULL);
638 case CODEC_ID_ATRAC3:
640 gst_ff_aud_caps_new (context, codec_id, encode,
641 "audio/x-vnd.sony.atrac3", NULL);
646 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dts", NULL);
651 gst_ff_aud_caps_new (context, codec_id, encode,
652 "audio/x-ffmpeg-parsed-ape", NULL);
654 gst_caps_set_simple (caps,
655 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
661 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mlp", NULL);
666 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-imc", NULL);
669 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
670 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
671 * sp5x is, but it's apparently something JPEG... We don't separate
672 * between those in GStreamer. Should we (at least between MJPEG,
673 * MJPEG-B and sp5x decoding...)? */
677 gst_ff_vid_caps_new (context, codec_id, encode, "image/jpeg", NULL);
682 gst_ff_vid_caps_new (context, codec_id, encode, "video/sp5x", NULL);
685 case CODEC_ID_MJPEGB:
687 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mjpeg-b",
692 if (encode && context != NULL) {
693 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
694 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
695 switch (context->codec_tag) {
696 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
698 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-divx",
699 "divxversion", G_TYPE_INT, 5, NULL);
701 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
704 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
705 "systemstream", G_TYPE_BOOLEAN, FALSE,
706 "mpegversion", G_TYPE_INT, 4, NULL);
710 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
711 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
712 "mpegversion", G_TYPE_INT, 4,
713 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
715 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
716 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
718 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
719 "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4, 5,
721 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
722 "video/x-xvid", NULL));
723 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
724 "video/x-3ivx", NULL));
729 case CODEC_ID_RAWVIDEO:
731 gst_ffmpeg_codectype_to_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
735 case CODEC_ID_MSMPEG4V1:
736 case CODEC_ID_MSMPEG4V2:
737 case CODEC_ID_MSMPEG4V3:
739 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
741 /* encode-FIXME: bitrate */
742 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-msmpeg",
743 "msmpegversion", G_TYPE_INT, version, NULL);
744 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
745 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
746 "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
754 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
756 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
757 "wmvversion", G_TYPE_INT, version, NULL);
763 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-flash-video",
764 "flvversion", G_TYPE_INT, 1, NULL);
768 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
769 "svqversion", G_TYPE_INT, 1, NULL);
773 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
774 "svqversion", G_TYPE_INT, 3, NULL);
777 case CODEC_ID_DVAUDIO:
779 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dv", NULL);
782 case CODEC_ID_DVVIDEO:
784 if (encode && context) {
787 switch (context->pix_fmt) {
788 case PIX_FMT_YUYV422:
791 case PIX_FMT_YUV420P:
794 case PIX_FMT_YUVA420P:
797 case PIX_FMT_YUV411P:
800 case PIX_FMT_YUV422P:
803 case PIX_FMT_YUV410P:
808 ("Couldnt' find format for pixfmt %d, defaulting to I420",
813 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
814 "systemstream", G_TYPE_BOOLEAN, FALSE,
815 "format", G_TYPE_STRING, format, NULL);
817 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
818 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
826 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
829 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
830 "wmaversion", G_TYPE_INT, version,
831 "block_align", G_TYPE_INT, context->block_align,
832 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
834 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
835 "wmaversion", G_TYPE_INT, version,
836 "block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT,
837 "bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
841 case CODEC_ID_WMAPRO:
843 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
844 "wmaversion", G_TYPE_INT, 3, NULL);
848 case CODEC_ID_WMAVOICE:
851 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wms", NULL);
858 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
860 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mace",
861 "maceversion", G_TYPE_INT, version, NULL);
865 case CODEC_ID_HUFFYUV:
867 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-huffyuv",
870 gst_caps_set_simple (caps,
871 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
877 gst_ff_vid_caps_new (context, codec_id, encode,
878 "video/x-compressed-yuv", NULL);
883 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h264",
884 "alignment", G_TYPE_STRING, "au", NULL);
887 case CODEC_ID_INDEO5:
888 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
889 "indeoversion", G_TYPE_INT, 5, NULL);
892 case CODEC_ID_INDEO4:
893 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
894 "indeoversion", G_TYPE_INT, 4, NULL);
897 case CODEC_ID_INDEO3:
898 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
899 "indeoversion", G_TYPE_INT, 3, NULL);
902 case CODEC_ID_INDEO2:
903 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
904 "indeoversion", G_TYPE_INT, 2, NULL);
907 case CODEC_ID_FLASHSV:
909 gst_ff_vid_caps_new (context, codec_id, encode,
910 "video/x-flash-screen", NULL);
915 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp3", NULL);
920 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp5", NULL);
925 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6", NULL);
930 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-flash",
936 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-alpha",
942 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp8", NULL);
945 case CODEC_ID_THEORA:
947 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-theora",
954 gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg", NULL);
958 GValue item = { 0, };
960 g_value_init (&arr, GST_TYPE_LIST);
961 g_value_init (&item, G_TYPE_INT);
962 g_value_set_int (&item, 2);
963 gst_value_list_append_value (&arr, &item);
964 g_value_set_int (&item, 4);
965 gst_value_list_append_value (&arr, &item);
966 g_value_unset (&item);
968 gst_caps_set_value (caps, "mpegversion", &arr);
969 g_value_unset (&arr);
971 g_value_init (&arr, GST_TYPE_LIST);
972 g_value_init (&item, G_TYPE_STRING);
973 g_value_set_string (&item, "raw");
974 gst_value_list_append_value (&arr, &item);
975 g_value_set_string (&item, "adts");
976 gst_value_list_append_value (&arr, &item);
977 g_value_set_string (&item, "adif");
978 gst_value_list_append_value (&arr, &item);
979 g_value_unset (&item);
981 gst_caps_set_value (caps, "stream-format", &arr);
982 g_value_unset (&arr);
984 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
985 "stream-format", G_TYPE_STRING, "raw",
986 "base-profile", G_TYPE_STRING, "lc", NULL);
988 if (context && context->extradata_size > 0)
989 gst_codec_utils_aac_caps_set_level_and_profile (caps,
990 context->extradata, context->extradata_size);
995 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
996 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
997 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1002 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1003 "asusversion", G_TYPE_INT, 1, NULL);
1006 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1007 "asusversion", G_TYPE_INT, 2, NULL);
1011 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ffv",
1012 "ffvversion", G_TYPE_INT, 1, NULL);
1017 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-4xm", NULL);
1020 case CODEC_ID_XAN_WC3:
1021 case CODEC_ID_XAN_WC4:
1022 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-xan",
1023 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1028 gst_ff_vid_caps_new (context, codec_id, encode,
1029 "video/x-cirrus-logic-accupak", NULL);
1032 case CODEC_ID_FRAPS:
1034 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-fraps",
1040 case CODEC_ID_INTERPLAY_VIDEO:
1045 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ati-vcr",
1046 "vcrversion", G_TYPE_INT, 1, NULL);
1051 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-apple-video",
1055 case CODEC_ID_CINEPAK:
1057 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-cinepak",
1061 /* WS_VQA belogns here (order) */
1063 case CODEC_ID_MSRLE:
1064 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1065 "layout", G_TYPE_STRING, "microsoft", NULL);
1067 gst_caps_set_simple (caps,
1068 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1070 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1074 case CODEC_ID_QTRLE:
1075 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1076 "layout", G_TYPE_STRING, "quicktime", NULL);
1078 gst_caps_set_simple (caps,
1079 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1081 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1085 case CODEC_ID_MSVIDEO1:
1087 gst_ff_vid_caps_new (context, codec_id, encode,
1088 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1092 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1093 "wmvversion", G_TYPE_INT, 3, NULL);
1096 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1097 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1101 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-qdm2", NULL);
1106 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mszh", NULL);
1111 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zlib", NULL);
1114 case CODEC_ID_TRUEMOTION1:
1116 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1117 "trueversion", G_TYPE_INT, 1, NULL);
1119 case CODEC_ID_TRUEMOTION2:
1121 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1122 "trueversion", G_TYPE_INT, 2, NULL);
1127 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ultimotion",
1133 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camtasia",
1136 gst_caps_set_simple (caps,
1137 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1139 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1145 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-kmvc", NULL);
1150 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-nuv", NULL);
1154 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/gif", NULL);
1158 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/png", NULL);
1162 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/ppm", NULL);
1166 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/pbm", NULL);
1171 gst_ff_vid_caps_new (context, codec_id, encode,
1172 "image/x-portable-anymap", NULL);
1177 gst_ff_vid_caps_new (context, codec_id, encode,
1178 "image/x-portable-graymap", NULL);
1183 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-pcx", NULL);
1188 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sgi", NULL);
1191 case CODEC_ID_TARGA:
1193 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-tga", NULL);
1198 gst_ff_vid_caps_new (context, codec_id, encode, "image/tiff", NULL);
1201 case CODEC_ID_SUNRAST:
1203 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sun-raster",
1209 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-smc", NULL);
1212 case CODEC_ID_QDRAW:
1214 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-qdrw", NULL);
1217 case CODEC_ID_DNXHD:
1219 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dnxhd",
1223 case CODEC_ID_PRORES:
1225 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-prores",
1229 case CODEC_ID_MIMIC:
1231 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mimic",
1237 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vmnc", NULL);
1240 case CODEC_ID_TRUESPEECH:
1242 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-truespeech",
1246 case CODEC_ID_QCELP:
1248 gst_ff_aud_caps_new (context, codec_id, encode, "audio/qcelp", NULL);
1253 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-amv", NULL);
1258 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-aasc", NULL);
1263 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-loco", NULL);
1268 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zmbv", NULL);
1271 case CODEC_ID_LAGARITH:
1273 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-lagarith",
1279 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camstudio",
1282 gst_caps_set_simple (caps,
1283 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1285 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1289 case CODEC_ID_WS_VQA:
1290 case CODEC_ID_IDCIN:
1293 case CODEC_ID_VMDVIDEO:
1294 case CODEC_ID_VMDAUDIO:
1298 case CODEC_ID_PGMYUV:
1299 case CODEC_ID_FFVHUFF:
1301 case CODEC_ID_MP3ADU:
1302 case CODEC_ID_MP3ON4:
1303 case CODEC_ID_WESTWOOD_SND1:
1304 case CODEC_ID_MMVIDEO:
1310 /* weird quasi-codecs for the demuxers only */
1311 case CODEC_ID_PCM_S16LE:
1312 case CODEC_ID_PCM_S16BE:
1313 case CODEC_ID_PCM_U16LE:
1314 case CODEC_ID_PCM_U16BE:
1315 case CODEC_ID_PCM_S8:
1316 case CODEC_ID_PCM_U8:
1318 GstAudioFormat format;
1321 case CODEC_ID_PCM_S16LE:
1322 format = GST_AUDIO_FORMAT_S16LE;
1324 case CODEC_ID_PCM_S16BE:
1325 format = GST_AUDIO_FORMAT_S16BE;
1327 case CODEC_ID_PCM_U16LE:
1328 format = GST_AUDIO_FORMAT_U16LE;
1330 case CODEC_ID_PCM_U16BE:
1331 format = GST_AUDIO_FORMAT_U16BE;
1333 case CODEC_ID_PCM_S8:
1334 format = GST_AUDIO_FORMAT_S8;
1336 case CODEC_ID_PCM_U8:
1337 format = GST_AUDIO_FORMAT_U8;
1340 g_assert (0); /* don't worry, we never get here */
1344 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-raw",
1345 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1346 "layout", G_TYPE_STRING, "interleaved", NULL);
1350 case CODEC_ID_PCM_MULAW:
1352 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mulaw",
1356 case CODEC_ID_PCM_ALAW:
1358 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-alaw", NULL);
1361 case CODEC_ID_ADPCM_G722:
1363 gst_ff_aud_caps_new (context, codec_id, encode, "audio/G722", NULL);
1365 gst_caps_set_simple (caps,
1366 "block_align", G_TYPE_INT, context->block_align,
1367 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1370 case CODEC_ID_ADPCM_G726:
1372 /* the G726 decoder can also handle G721 */
1373 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-adpcm",
1374 "layout", G_TYPE_STRING, "g726", NULL);
1376 gst_caps_set_simple (caps,
1377 "block_align", G_TYPE_INT, context->block_align,
1378 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1381 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1382 "layout", G_TYPE_STRING, "g721",
1383 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1387 case CODEC_ID_ADPCM_IMA_QT:
1388 case CODEC_ID_ADPCM_IMA_WAV:
1389 case CODEC_ID_ADPCM_IMA_DK3:
1390 case CODEC_ID_ADPCM_IMA_DK4:
1391 case CODEC_ID_ADPCM_IMA_WS:
1392 case CODEC_ID_ADPCM_IMA_SMJPEG:
1393 case CODEC_ID_ADPCM_IMA_AMV:
1394 case CODEC_ID_ADPCM_IMA_ISS:
1395 case CODEC_ID_ADPCM_IMA_EA_EACS:
1396 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1397 case CODEC_ID_ADPCM_MS:
1398 case CODEC_ID_ADPCM_4XM:
1399 case CODEC_ID_ADPCM_XA:
1400 case CODEC_ID_ADPCM_ADX:
1401 case CODEC_ID_ADPCM_EA:
1402 case CODEC_ID_ADPCM_CT:
1403 case CODEC_ID_ADPCM_SWF:
1404 case CODEC_ID_ADPCM_YAMAHA:
1405 case CODEC_ID_ADPCM_SBPRO_2:
1406 case CODEC_ID_ADPCM_SBPRO_3:
1407 case CODEC_ID_ADPCM_SBPRO_4:
1408 case CODEC_ID_ADPCM_EA_R1:
1409 case CODEC_ID_ADPCM_EA_R2:
1410 case CODEC_ID_ADPCM_EA_R3:
1411 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1412 case CODEC_ID_ADPCM_EA_XAS:
1413 case CODEC_ID_ADPCM_THP:
1415 const gchar *layout = NULL;
1418 case CODEC_ID_ADPCM_IMA_QT:
1419 layout = "quicktime";
1421 case CODEC_ID_ADPCM_IMA_WAV:
1424 case CODEC_ID_ADPCM_IMA_DK3:
1427 case CODEC_ID_ADPCM_IMA_DK4:
1430 case CODEC_ID_ADPCM_IMA_WS:
1431 layout = "westwood";
1433 case CODEC_ID_ADPCM_IMA_SMJPEG:
1436 case CODEC_ID_ADPCM_IMA_AMV:
1439 case CODEC_ID_ADPCM_IMA_ISS:
1442 case CODEC_ID_ADPCM_IMA_EA_EACS:
1445 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1448 case CODEC_ID_ADPCM_MS:
1449 layout = "microsoft";
1451 case CODEC_ID_ADPCM_4XM:
1454 case CODEC_ID_ADPCM_XA:
1457 case CODEC_ID_ADPCM_ADX:
1460 case CODEC_ID_ADPCM_EA:
1463 case CODEC_ID_ADPCM_CT:
1466 case CODEC_ID_ADPCM_SWF:
1469 case CODEC_ID_ADPCM_YAMAHA:
1472 case CODEC_ID_ADPCM_SBPRO_2:
1475 case CODEC_ID_ADPCM_SBPRO_3:
1478 case CODEC_ID_ADPCM_SBPRO_4:
1481 case CODEC_ID_ADPCM_EA_R1:
1484 case CODEC_ID_ADPCM_EA_R2:
1487 case CODEC_ID_ADPCM_EA_R3:
1490 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1491 layout = "ea-maxis-xa";
1493 case CODEC_ID_ADPCM_EA_XAS:
1496 case CODEC_ID_ADPCM_THP:
1500 g_assert (0); /* don't worry, we never get here */
1504 /* FIXME: someone please check whether we need additional properties
1505 * in this caps definition. */
1506 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-adpcm",
1507 "layout", G_TYPE_STRING, layout, NULL);
1509 gst_caps_set_simple (caps,
1510 "block_align", G_TYPE_INT, context->block_align,
1511 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1515 case CODEC_ID_AMR_NB:
1516 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/AMR", NULL);
1519 case CODEC_ID_AMR_WB:
1521 gst_ff_aud_caps_new (context, codec_id, encode, "audio/AMR-WB", NULL);
1526 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-gsm", NULL);
1529 case CODEC_ID_GSM_MS:
1531 gst_ff_aud_caps_new (context, codec_id, encode, "audio/ms-gsm", NULL);
1534 case CODEC_ID_NELLYMOSER:
1536 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-nellymoser",
1543 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-sipro",
1546 gst_caps_set_simple (caps,
1547 "leaf_size", G_TYPE_INT, context->block_align,
1548 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1553 case CODEC_ID_RA_144:
1554 case CODEC_ID_RA_288:
1560 case CODEC_ID_RA_144:
1563 case CODEC_ID_RA_288:
1573 /* FIXME: properties? */
1575 gst_ff_aud_caps_new (context, codec_id, encode,
1576 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1578 gst_caps_set_simple (caps,
1579 "leaf_size", G_TYPE_INT, context->block_align,
1580 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1585 case CODEC_ID_ROQ_DPCM:
1586 case CODEC_ID_INTERPLAY_DPCM:
1587 case CODEC_ID_XAN_DPCM:
1588 case CODEC_ID_SOL_DPCM:
1590 const gchar *layout = NULL;
1593 case CODEC_ID_ROQ_DPCM:
1596 case CODEC_ID_INTERPLAY_DPCM:
1597 layout = "interplay";
1599 case CODEC_ID_XAN_DPCM:
1602 case CODEC_ID_SOL_DPCM:
1606 g_assert (0); /* don't worry, we never get here */
1610 /* FIXME: someone please check whether we need additional properties
1611 * in this caps definition. */
1612 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dpcm",
1613 "layout", G_TYPE_STRING, layout, NULL);
1615 gst_caps_set_simple (caps,
1616 "block_align", G_TYPE_INT, context->block_align,
1617 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1621 case CODEC_ID_SHORTEN:
1622 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1627 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-alac", NULL);
1629 gst_caps_set_simple (caps,
1630 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1635 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1636 * encoder case, we want to add things like samplerate, channels... */
1638 caps = gst_caps_new_empty_simple ("audio/x-flac");
1642 case CODEC_ID_DVD_SUBTITLE:
1643 case CODEC_ID_DVB_SUBTITLE:
1647 caps = gst_caps_new_empty_simple ("image/bmp");
1651 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-tta", NULL);
1653 gst_caps_set_simple (caps,
1654 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1657 case CODEC_ID_TWINVQ:
1659 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-twin-vq",
1663 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1670 if ((codec = avcodec_find_decoder (codec_id)) ||
1671 (codec = avcodec_find_encoder (codec_id))) {
1674 GST_LOG ("Could not create stream format caps for %s", codec->name);
1676 switch (codec->type) {
1677 case AVMEDIA_TYPE_VIDEO:
1678 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1679 caps = gst_ff_vid_caps_new (context, codec_id, encode, mime, NULL);
1682 case AVMEDIA_TYPE_AUDIO:
1683 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1684 caps = gst_ff_aud_caps_new (context, codec_id, encode, mime, NULL);
1686 gst_caps_set_simple (caps,
1687 "block_align", G_TYPE_INT, context->block_align,
1688 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1699 /* set private data */
1700 if (context && context->extradata_size > 0) {
1701 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1703 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1704 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1705 gst_buffer_unref (data);
1708 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1711 GST_LOG ("No caps found for codec_id=%d", codec_id);
1717 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1718 * to a GstCaps. If the context is ommitted, no fixed values
1719 * for video/audio size will be included in the GstCaps
1721 * See below for usefullness
1725 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1726 enum CodecID codec_id)
1728 GstCaps *caps = NULL;
1729 GstVideoFormat format;
1731 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
1733 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1734 caps = gst_ff_vid_caps_new (context, codec_id, TRUE, "video/x-raw",
1735 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1739 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1741 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1748 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
1750 switch (sample_fmt) {
1751 case AV_SAMPLE_FMT_U8:
1752 case AV_SAMPLE_FMT_U8P:
1753 return GST_AUDIO_FORMAT_U8;
1755 case AV_SAMPLE_FMT_S16:
1756 case AV_SAMPLE_FMT_S16P:
1757 return GST_AUDIO_FORMAT_S16;
1759 case AV_SAMPLE_FMT_S32:
1760 case AV_SAMPLE_FMT_S32P:
1761 return GST_AUDIO_FORMAT_S32;
1763 case AV_SAMPLE_FMT_FLT:
1764 case AV_SAMPLE_FMT_FLTP:
1765 return GST_AUDIO_FORMAT_F32;
1767 case AV_SAMPLE_FMT_DBL:
1768 case AV_SAMPLE_FMT_DBLP:
1769 return GST_AUDIO_FORMAT_F64;
1773 return GST_AUDIO_FORMAT_UNKNOWN;
1778 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1779 * to a GstCaps. If the context is ommitted, no fixed values
1780 * for video/audio size will be included in the GstCaps
1782 * See below for usefullness
1786 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
1787 AVCodecContext * context, enum CodecID codec_id)
1789 GstCaps *caps = NULL;
1790 GstAudioFormat format;
1792 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
1794 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1795 caps = gst_ff_aud_caps_new (context, codec_id, TRUE, "audio/x-raw",
1796 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1797 "layout", G_TYPE_STRING, "interleaved", NULL);
1798 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1800 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1807 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
1808 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1810 GstCaps *caps = NULL;
1812 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1813 context, codec_id, encode, codec);
1815 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
1816 codec->sample_fmts, codec->supported_samplerates);
1819 /* Specific codec context */
1820 caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec_id);
1821 } else if (codec && codec->sample_fmts) {
1825 caps = gst_caps_new_empty ();
1826 for (i = 0; codec->sample_fmts[i] != -1; i++) {
1828 gst_ffmpeg_smpfmt_to_caps (codec->sample_fmts[i], context, codec_id);
1830 gst_caps_append (caps, temp);
1834 enum AVSampleFormat i;
1835 AVCodecContext ctx = { 0, };
1838 caps = gst_caps_new_empty ();
1839 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
1840 temp = gst_ffmpeg_smpfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1842 gst_caps_append (caps, temp);
1850 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
1851 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1855 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1856 context, codec_id, encode, codec);
1859 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
1863 AVCodecContext ctx = { 0, };
1865 caps = gst_caps_new_empty ();
1866 for (i = 0; i < PIX_FMT_NB; i++) {
1869 temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1871 gst_caps_append (caps, temp);
1878 /* Convert a FFMPEG codec Type and optional AVCodecContext
1879 * to a GstCaps. If the context is ommitted, no fixed values
1880 * for video/audio size will be included in the GstCaps
1882 * AVMediaType is primarily meant for uncompressed data GstCaps!
1886 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
1887 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
1891 switch (codec_type) {
1892 case AVMEDIA_TYPE_VIDEO:
1894 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1896 case AVMEDIA_TYPE_AUDIO:
1898 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
1908 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
1909 * and other audio properties in a AVCodecContext.
1911 * For usefullness, see below
1915 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
1916 AVCodecContext * context, gboolean raw)
1918 GstStructure *structure;
1920 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
1922 g_return_if_fail (gst_caps_get_size (caps) == 1);
1924 structure = gst_caps_get_structure (caps, 0);
1926 gst_structure_get_int (structure, "channels", &context->channels);
1927 gst_structure_get_int (structure, "rate", &context->sample_rate);
1928 gst_structure_get_int (structure, "block_align", &context->block_align);
1929 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
1934 if (gst_structure_has_name (structure, "audio/x-raw")) {
1935 if ((fmt = gst_structure_get_string (structure, "format"))) {
1936 format = gst_audio_format_from_string (fmt);
1941 case GST_AUDIO_FORMAT_F32:
1942 context->sample_fmt = AV_SAMPLE_FMT_FLT;
1944 case GST_AUDIO_FORMAT_F64:
1945 context->sample_fmt = AV_SAMPLE_FMT_DBL;
1947 case GST_AUDIO_FORMAT_S32:
1948 context->sample_fmt = AV_SAMPLE_FMT_S32;
1950 case GST_AUDIO_FORMAT_S16:
1951 context->sample_fmt = AV_SAMPLE_FMT_S16;
1958 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
1959 * and other video properties in a AVCodecContext.
1961 * For usefullness, see below
1965 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
1966 AVCodecContext * context, gboolean raw)
1968 GstStructure *structure;
1970 const GValue *par = NULL;
1972 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
1974 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
1975 g_return_if_fail (gst_caps_get_size (caps) == 1);
1976 structure = gst_caps_get_structure (caps, 0);
1978 gst_structure_get_int (structure, "width", &context->width);
1979 gst_structure_get_int (structure, "height", &context->height);
1980 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
1982 fps = gst_structure_get_value (structure, "framerate");
1983 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
1985 /* somehow these seem mixed up.. */
1986 context->time_base.den = gst_value_get_fraction_numerator (fps);
1987 context->time_base.num = gst_value_get_fraction_denominator (fps);
1988 context->ticks_per_frame = 1;
1990 GST_DEBUG ("setting framerate %d/%d = %lf",
1991 context->time_base.den, context->time_base.num,
1992 1. * context->time_base.den / context->time_base.num);
1995 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1996 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
1998 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
1999 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2001 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2002 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2003 1. * context->sample_aspect_ratio.den /
2004 context->sample_aspect_ratio.num);
2010 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2012 if (gst_structure_has_name (structure, "video/x-raw")) {
2013 if ((fmt = gst_structure_get_string (structure, "format"))) {
2014 format = gst_video_format_from_string (fmt);
2019 case GST_VIDEO_FORMAT_YUY2:
2020 context->pix_fmt = PIX_FMT_YUYV422;
2022 case GST_VIDEO_FORMAT_I420:
2023 context->pix_fmt = PIX_FMT_YUV420P;
2025 case GST_VIDEO_FORMAT_A420:
2026 context->pix_fmt = PIX_FMT_YUVA420P;
2028 case GST_VIDEO_FORMAT_Y41B:
2029 context->pix_fmt = PIX_FMT_YUV411P;
2031 case GST_VIDEO_FORMAT_Y42B:
2032 context->pix_fmt = PIX_FMT_YUV422P;
2034 case GST_VIDEO_FORMAT_YUV9:
2035 context->pix_fmt = PIX_FMT_YUV410P;
2037 case GST_VIDEO_FORMAT_Y444:
2038 context->pix_fmt = PIX_FMT_YUV444P;
2040 case GST_VIDEO_FORMAT_GRAY8:
2041 context->pix_fmt = PIX_FMT_GRAY8;
2043 case GST_VIDEO_FORMAT_xRGB:
2044 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2045 context->pix_fmt = PIX_FMT_RGB32;
2048 case GST_VIDEO_FORMAT_BGRx:
2049 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2050 context->pix_fmt = PIX_FMT_RGB32;
2053 case GST_VIDEO_FORMAT_RGB:
2054 context->pix_fmt = PIX_FMT_RGB24;
2056 case GST_VIDEO_FORMAT_BGR:
2057 context->pix_fmt = PIX_FMT_BGR24;
2059 case GST_VIDEO_FORMAT_RGB16:
2060 context->pix_fmt = PIX_FMT_RGB565;
2062 case GST_VIDEO_FORMAT_RGB15:
2063 context->pix_fmt = PIX_FMT_RGB555;
2065 case GST_VIDEO_FORMAT_RGB8P:
2066 context->pix_fmt = PIX_FMT_PAL8;
2075 GstVideoFormat format;
2076 enum PixelFormat pixfmt;
2079 /* FIXME : FILLME */
2080 static const PixToFmt pixtofmttable[] = {
2081 /* GST_VIDEO_FORMAT_I420, */
2082 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2083 /* Note : this should use a different chroma placement */
2084 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2086 /* GST_VIDEO_FORMAT_YV12, */
2087 /* GST_VIDEO_FORMAT_YUY2, */
2088 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2089 /* GST_VIDEO_FORMAT_UYVY, */
2090 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2091 /* GST_VIDEO_FORMAT_AYUV, */
2092 /* GST_VIDEO_FORMAT_RGBx, */
2093 /* GST_VIDEO_FORMAT_BGRx, */
2094 /* GST_VIDEO_FORMAT_xRGB, */
2095 /* GST_VIDEO_FORMAT_xBGR, */
2096 /* GST_VIDEO_FORMAT_RGBA, */
2097 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2098 /* GST_VIDEO_FORMAT_BGRA, */
2099 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2100 /* GST_VIDEO_FORMAT_ARGB, */
2101 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2102 /* GST_VIDEO_FORMAT_ABGR, */
2103 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2104 /* GST_VIDEO_FORMAT_RGB, */
2105 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2106 /* GST_VIDEO_FORMAT_BGR, */
2107 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2108 /* GST_VIDEO_FORMAT_Y41B, */
2109 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2110 /* GST_VIDEO_FORMAT_Y42B, */
2111 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2112 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2113 /* GST_VIDEO_FORMAT_YVYU, */
2114 /* GST_VIDEO_FORMAT_Y444, */
2115 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2116 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2117 /* GST_VIDEO_FORMAT_v210, */
2118 /* GST_VIDEO_FORMAT_v216, */
2119 /* GST_VIDEO_FORMAT_NV12, */
2120 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2121 /* GST_VIDEO_FORMAT_NV21, */
2122 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2123 /* GST_VIDEO_FORMAT_GRAY8, */
2124 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2125 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2126 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2127 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2128 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2129 /* GST_VIDEO_FORMAT_v308, */
2130 /* GST_VIDEO_FORMAT_Y800, */
2131 /* GST_VIDEO_FORMAT_Y16, */
2132 /* GST_VIDEO_FORMAT_RGB16, */
2133 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2134 /* GST_VIDEO_FORMAT_BGR16, */
2135 /* GST_VIDEO_FORMAT_RGB15, */
2136 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2137 /* GST_VIDEO_FORMAT_BGR15, */
2138 /* GST_VIDEO_FORMAT_UYVP, */
2139 /* GST_VIDEO_FORMAT_A420, */
2140 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2141 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2142 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2143 /* GST_VIDEO_FORMAT_YUV9, */
2144 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2145 /* GST_VIDEO_FORMAT_YVU9, */
2146 /* GST_VIDEO_FORMAT_IYU1, */
2147 /* GST_VIDEO_FORMAT_ARGB64, */
2148 /* GST_VIDEO_FORMAT_AYUV64, */
2149 /* GST_VIDEO_FORMAT_r210, */
2150 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2151 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2152 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2153 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2154 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2155 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2156 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2157 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2158 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2162 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2166 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2167 if (pixtofmttable[i].pixfmt == pixfmt)
2168 return pixtofmttable[i].format;
2170 GST_WARNING ("Unknown pixel format %d", pixfmt);
2171 return GST_VIDEO_FORMAT_UNKNOWN;
2175 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2179 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2180 if (pixtofmttable[i].format == format)
2181 return pixtofmttable[i].pixfmt;
2182 return PIX_FMT_NONE;
2186 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2190 context->width = GST_VIDEO_INFO_WIDTH (info);
2191 context->height = GST_VIDEO_INFO_HEIGHT (info);
2192 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2193 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2194 context->bits_per_coded_sample = bpp;
2196 context->ticks_per_frame = 1;
2197 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2198 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2200 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2201 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2204 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2208 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2210 const AVCodec *codec;
2211 const enum AVSampleFormat *smpl_fmts;
2212 enum AVSampleFormat smpl_fmt = -1;
2214 context->channels = info->channels;
2215 context->sample_rate = info->rate;
2217 codec = context->codec;
2219 smpl_fmts = codec->sample_fmts;
2221 switch (info->finfo->format) {
2222 case GST_AUDIO_FORMAT_F32:
2224 while (*smpl_fmts != -1) {
2225 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2226 smpl_fmt = *smpl_fmts;
2228 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2229 smpl_fmt = *smpl_fmts;
2235 smpl_fmt = AV_SAMPLE_FMT_FLT;
2238 case GST_AUDIO_FORMAT_F64:
2240 while (*smpl_fmts != -1) {
2241 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2242 smpl_fmt = *smpl_fmts;
2244 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2245 smpl_fmt = *smpl_fmts;
2251 smpl_fmt = AV_SAMPLE_FMT_DBL;
2254 case GST_AUDIO_FORMAT_S32:
2256 while (*smpl_fmts != -1) {
2257 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2258 smpl_fmt = *smpl_fmts;
2260 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2261 smpl_fmt = *smpl_fmts;
2267 smpl_fmt = AV_SAMPLE_FMT_S32;
2270 case GST_AUDIO_FORMAT_S16:
2272 while (*smpl_fmts != -1) {
2273 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2274 smpl_fmt = *smpl_fmts;
2276 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2277 smpl_fmt = *smpl_fmts;
2283 smpl_fmt = AV_SAMPLE_FMT_S16;
2286 case GST_AUDIO_FORMAT_U8:
2288 while (*smpl_fmts != -1) {
2289 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2290 smpl_fmt = *smpl_fmts;
2292 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2293 smpl_fmt = *smpl_fmts;
2299 smpl_fmt = AV_SAMPLE_FMT_U8;
2306 g_assert (smpl_fmt != -1);
2308 context->sample_fmt = smpl_fmt;
2311 /* Convert a GstCaps and a FFMPEG codec Type to a
2312 * AVCodecContext. If the context is ommitted, no fixed values
2313 * for video/audio size will be included in the context
2315 * AVMediaType is primarily meant for uncompressed data GstCaps!
2319 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2320 const GstCaps * caps, AVCodecContext * context)
2322 if (context == NULL)
2326 case AVMEDIA_TYPE_VIDEO:
2327 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2330 case AVMEDIA_TYPE_AUDIO:
2331 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2342 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2346 guint8 *end = src + size;
2349 while (srcp < end) {
2350 if (count == 2 && *srcp <= 0x03) {
2351 GST_DEBUG ("added escape code");
2360 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2363 *destsize = dstp - dst;
2366 /* copy the config, escaping NAL units as we iterate them, if something fails we
2367 * copy everything and hope for the best. */
2369 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2374 guint nalsize, esize;
2384 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2386 GST_DEBUG ("num SPS %d", cnt);
2388 memcpy (dstp, srcp, 6);
2392 for (i = 0; i < cnt; i++) {
2393 GST_DEBUG ("copy SPS %d", i);
2394 nalsize = (srcp[0] << 8) | srcp[1];
2395 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2396 dstp[0] = esize >> 8;
2397 dstp[1] = esize & 0xff;
2399 srcp += nalsize + 2;
2402 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2404 GST_DEBUG ("num PPS %d", cnt);
2406 for (i = 0; i < cnt; i++) {
2407 GST_DEBUG ("copy PPS %d", i);
2408 nalsize = (srcp[0] << 8) | srcp[1];
2409 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2410 dstp[0] = esize >> 8;
2411 dstp[1] = esize & 0xff;
2413 srcp += nalsize + 2;
2415 *destsize = dstp - dst;
2421 GST_DEBUG ("something unexpected, doing full copy");
2422 memcpy (dst, src, size);
2430 * caps_with_codecid () transforms a GstCaps for a known codec
2431 * ID into a filled-in context.
2432 * codec_data from caps will override possible extradata already in the context
2436 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2437 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2440 const GValue *value;
2443 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2444 codec_id, codec_type, caps, context);
2446 if (!context || !gst_caps_get_size (caps))
2449 str = gst_caps_get_structure (caps, 0);
2451 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2452 if ((value = gst_structure_get_value (str, "codec_data"))) {
2455 buf = gst_value_get_buffer (value);
2456 gst_buffer_map (buf, &map, GST_MAP_READ);
2458 /* free the old one if it is there */
2459 if (context->extradata)
2460 av_free (context->extradata);
2463 if (codec_id == CODEC_ID_H264) {
2466 GST_DEBUG ("copy, escaping codec_data %d", size);
2467 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2468 * reason for this but let's just escape it for now. Start by allocating
2469 * enough space, x2 is more than enough.
2471 * FIXME, we disabled escaping because some file already contain escaped
2472 * codec_data and then we escape twice and fail. It's better to leave it
2473 * as is, as that is what most players do. */
2474 context->extradata =
2475 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2476 FF_INPUT_BUFFER_PADDING_SIZE));
2477 copy_config (context->extradata, data, size, &extrasize);
2478 GST_DEBUG ("escaped size: %d", extrasize);
2479 context->extradata_size = extrasize;
2483 /* allocate with enough padding */
2484 GST_DEBUG ("copy codec_data");
2485 context->extradata =
2486 av_mallocz (GST_ROUND_UP_16 (map.size +
2487 FF_INPUT_BUFFER_PADDING_SIZE));
2488 memcpy (context->extradata, map.data, map.size);
2489 context->extradata_size = map.size;
2492 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2493 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2494 context->extradata[0] = (guint8) map.size;
2497 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2499 gst_buffer_unmap (buf, &map);
2500 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2501 codec_id != CODEC_ID_FLAC) {
2502 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2503 * extradata anyway which makes then segfault. */
2504 context->extradata =
2505 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2506 context->extradata_size = 0;
2507 GST_DEBUG ("no codec data");
2511 case CODEC_ID_MPEG4:
2513 const gchar *mime = gst_structure_get_name (str);
2515 if (!strcmp (mime, "video/x-divx"))
2516 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2517 else if (!strcmp (mime, "video/x-xvid"))
2518 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2519 else if (!strcmp (mime, "video/x-3ivx"))
2520 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2521 else if (!strcmp (mime, "video/mpeg"))
2522 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2527 /* FIXME: this is a workaround for older gst-plugins releases
2528 * (<= 0.8.9). This should be removed at some point, because
2529 * it causes wrong decoded frame order. */
2530 if (!context->extradata) {
2531 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2534 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2535 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2536 gst_structure_get_int (str, "low_delay", &low_delay) ||
2537 gst_structure_get_int (str, "unknown_svq3_flag",
2538 &unknown_svq3_flag)) {
2539 context->extradata = (guint8 *) av_mallocz (0x64);
2540 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2544 flags |= unknown_svq3_flag;
2546 flags |= halfpel_flag;
2548 flags |= thirdpel_flag;
2551 flags = GUINT16_FROM_LE (flags);
2553 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2554 context->extradata_size = 0x64;
2559 case CODEC_ID_MSRLE:
2560 case CODEC_ID_QTRLE:
2567 if (gst_structure_get_int (str, "depth", &depth)) {
2568 context->bits_per_coded_sample = depth;
2570 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2583 if (gst_structure_get_int (str, "format", &format))
2584 context->sub_id = format;
2589 case CODEC_ID_RA_288:
2590 case CODEC_ID_RA_144:
2596 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2597 context->block_align = leaf_size;
2598 if (gst_structure_get_int (str, "bitrate", &bitrate))
2599 context->bit_rate = bitrate;
2602 gst_structure_get_int (str, "samplesize",
2603 &context->bits_per_coded_sample);
2606 case CODEC_ID_DVVIDEO:
2608 const gchar *format;
2610 if ((format = gst_structure_get_string (str, "format"))) {
2612 if (g_str_equal (format, "YUY2"))
2613 context->pix_fmt = PIX_FMT_YUYV422;
2614 else if (g_str_equal (format, "I420"))
2615 context->pix_fmt = PIX_FMT_YUV420P;
2616 else if (g_str_equal (format, "A420"))
2617 context->pix_fmt = PIX_FMT_YUVA420P;
2618 else if (g_str_equal (format, "Y41B"))
2619 context->pix_fmt = PIX_FMT_YUV411P;
2620 else if (g_str_equal (format, "Y42B"))
2621 context->pix_fmt = PIX_FMT_YUV422P;
2622 else if (g_str_equal (format, "YUV9"))
2623 context->pix_fmt = PIX_FMT_YUV410P;
2625 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2629 GST_WARNING ("No specified format");
2632 case CODEC_ID_H263P:
2636 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2637 context->flags |= CODEC_FLAG_4MV;
2639 context->flags &= ~CODEC_FLAG_4MV;
2640 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2641 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2642 context->flags |= CODEC_FLAG_AC_PRED;
2644 context->flags &= ~CODEC_FLAG_AC_PRED;
2645 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2646 context->flags |= CODEC_FLAG_LOOP_FILTER;
2648 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2651 case CODEC_ID_ADPCM_G726:
2653 const gchar *layout;
2655 if ((layout = gst_structure_get_string (str, "layout"))) {
2656 if (!strcmp (layout, "g721")) {
2657 context->sample_rate = 8000;
2658 context->channels = 1;
2659 context->bit_rate = 32000;
2668 if (!gst_caps_is_fixed (caps))
2671 /* common properties (width, height, fps) */
2672 switch (codec_type) {
2673 case AVMEDIA_TYPE_VIDEO:
2674 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2676 case AVMEDIA_TYPE_AUDIO:
2677 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2683 /* fixup of default settings */
2685 case CODEC_ID_QCELP:
2686 /* QCELP is always mono, no matter what the caps say */
2687 context->channels = 1;
2694 /* _formatid_to_caps () is meant for muxers/demuxers, it
2695 * transforms a name (ffmpeg way of ID'ing these, why don't
2696 * they have unique numerical IDs?) to the corresponding
2697 * caps belonging to that mux-format
2699 * Note: we don't need any additional info because the caps
2700 * isn't supposed to contain any useful info besides the
2705 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2707 GstCaps *caps = NULL;
2709 if (!strcmp (format_name, "mpeg")) {
2710 caps = gst_caps_new_simple ("video/mpeg",
2711 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2712 } else if (!strcmp (format_name, "mpegts")) {
2713 caps = gst_caps_new_simple ("video/mpegts",
2714 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2715 } else if (!strcmp (format_name, "rm")) {
2716 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2717 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2718 } else if (!strcmp (format_name, "asf")) {
2719 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2720 } else if (!strcmp (format_name, "avi")) {
2721 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2722 } else if (!strcmp (format_name, "wav")) {
2723 caps = gst_caps_new_empty_simple ("audio/x-wav");
2724 } else if (!strcmp (format_name, "ape")) {
2725 caps = gst_caps_new_empty_simple ("application/x-ape");
2726 } else if (!strcmp (format_name, "swf")) {
2727 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2728 } else if (!strcmp (format_name, "au")) {
2729 caps = gst_caps_new_empty_simple ("audio/x-au");
2730 } else if (!strcmp (format_name, "dv")) {
2731 caps = gst_caps_new_simple ("video/x-dv",
2732 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2733 } else if (!strcmp (format_name, "4xm")) {
2734 caps = gst_caps_new_empty_simple ("video/x-4xm");
2735 } else if (!strcmp (format_name, "matroska")) {
2736 caps = gst_caps_new_empty_simple ("video/x-matroska");
2737 } else if (!strcmp (format_name, "mp3")) {
2738 caps = gst_caps_new_empty_simple ("application/x-id3");
2739 } else if (!strcmp (format_name, "flic")) {
2740 caps = gst_caps_new_empty_simple ("video/x-fli");
2741 } else if (!strcmp (format_name, "flv")) {
2742 caps = gst_caps_new_empty_simple ("video/x-flv");
2743 } else if (!strcmp (format_name, "tta")) {
2744 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
2745 } else if (!strcmp (format_name, "aiff")) {
2746 caps = gst_caps_new_empty_simple ("audio/x-aiff");
2747 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2749 gst_caps_from_string
2750 ("application/x-3gp; video/quicktime; audio/x-m4a");
2751 } else if (!strcmp (format_name, "mov")) {
2752 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2753 } else if (!strcmp (format_name, "mp4")) {
2754 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2755 } else if (!strcmp (format_name, "3gp")) {
2756 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2757 } else if (!strcmp (format_name, "3g2")) {
2758 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2759 } else if (!strcmp (format_name, "psp")) {
2760 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2761 } else if (!strcmp (format_name, "ipod")) {
2762 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2763 } else if (!strcmp (format_name, "aac")) {
2764 caps = gst_caps_new_simple ("audio/mpeg",
2765 "mpegversion", G_TYPE_INT, 4, NULL);
2766 } else if (!strcmp (format_name, "gif")) {
2767 caps = gst_caps_from_string ("image/gif");
2768 } else if (!strcmp (format_name, "ogg")) {
2769 caps = gst_caps_from_string ("application/ogg");
2770 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
2771 caps = gst_caps_from_string ("application/mxf");
2772 } else if (!strcmp (format_name, "gxf")) {
2773 caps = gst_caps_from_string ("application/gxf");
2774 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
2775 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
2776 "y4mversion", G_TYPE_INT, 2, NULL);
2777 } else if (!strcmp (format_name, "mpc")) {
2778 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
2779 } else if (!strcmp (format_name, "vqf")) {
2780 caps = gst_caps_from_string ("audio/x-vqf");
2781 } else if (!strcmp (format_name, "nsv")) {
2782 caps = gst_caps_from_string ("video/x-nsv");
2783 } else if (!strcmp (format_name, "amr")) {
2784 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
2785 } else if (!strcmp (format_name, "webm")) {
2786 caps = gst_caps_from_string ("video/webm");
2787 } else if (!strcmp (format_name, "voc")) {
2788 caps = gst_caps_from_string ("audio/x-voc");
2792 GST_LOG ("Could not create stream format caps for %s", format_name);
2793 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
2794 caps = gst_caps_new_empty_simple (name);
2802 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
2803 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
2804 AVOutputFormat * plugin)
2806 static enum CodecID tmp_vlist[] = {
2810 static enum CodecID tmp_alist[] = {
2815 GST_LOG ("format_name : %s", format_name);
2817 if (!strcmp (format_name, "mp4")) {
2818 static enum CodecID mp4_video_list[] = {
2819 CODEC_ID_MPEG4, CODEC_ID_H264,
2823 static enum CodecID mp4_audio_list[] = {
2824 CODEC_ID_AAC, CODEC_ID_MP3,
2828 *video_codec_list = mp4_video_list;
2829 *audio_codec_list = mp4_audio_list;
2830 } else if (!strcmp (format_name, "mpeg")) {
2831 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
2832 CODEC_ID_MPEG2VIDEO,
2836 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
2842 *video_codec_list = mpeg_video_list;
2843 *audio_codec_list = mpeg_audio_list;
2844 } else if (!strcmp (format_name, "dvd")) {
2845 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
2848 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
2855 *video_codec_list = mpeg_video_list;
2856 *audio_codec_list = mpeg_audio_list;
2857 } else if (!strcmp (format_name, "mpegts")) {
2858 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
2859 CODEC_ID_MPEG2VIDEO,
2863 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
2871 *video_codec_list = mpegts_video_list;
2872 *audio_codec_list = mpegts_audio_list;
2873 } else if (!strcmp (format_name, "vob")) {
2874 static enum CodecID vob_video_list[] =
2875 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
2876 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
2877 CODEC_ID_DTS, CODEC_ID_NONE
2880 *video_codec_list = vob_video_list;
2881 *audio_codec_list = vob_audio_list;
2882 } else if (!strcmp (format_name, "flv")) {
2883 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
2884 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
2886 *video_codec_list = flv_video_list;
2887 *audio_codec_list = flv_audio_list;
2888 } else if (!strcmp (format_name, "asf")) {
2889 static enum CodecID asf_video_list[] =
2890 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
2891 static enum CodecID asf_audio_list[] =
2892 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
2894 *video_codec_list = asf_video_list;
2895 *audio_codec_list = asf_audio_list;
2896 } else if (!strcmp (format_name, "dv")) {
2897 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
2898 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
2900 *video_codec_list = dv_video_list;
2901 *audio_codec_list = dv_audio_list;
2902 } else if (!strcmp (format_name, "mov")) {
2903 static enum CodecID mov_video_list[] = {
2904 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
2905 CODEC_ID_H263, CODEC_ID_H263P,
2906 CODEC_ID_H264, CODEC_ID_DVVIDEO,
2910 static enum CodecID mov_audio_list[] = {
2911 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
2912 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
2913 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2914 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
2915 CODEC_ID_MP3, CODEC_ID_NONE
2918 *video_codec_list = mov_video_list;
2919 *audio_codec_list = mov_audio_list;
2920 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
2921 static enum CodecID tgp_video_list[] = {
2922 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
2925 static enum CodecID tgp_audio_list[] = {
2926 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2931 *video_codec_list = tgp_video_list;
2932 *audio_codec_list = tgp_audio_list;
2933 } else if (!strcmp (format_name, "mmf")) {
2934 static enum CodecID mmf_audio_list[] = {
2935 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
2937 *video_codec_list = NULL;
2938 *audio_codec_list = mmf_audio_list;
2939 } else if (!strcmp (format_name, "amr")) {
2940 static enum CodecID amr_audio_list[] = {
2941 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2944 *video_codec_list = NULL;
2945 *audio_codec_list = amr_audio_list;
2946 } else if (!strcmp (format_name, "gif")) {
2947 static enum CodecID gif_image_list[] = {
2948 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
2950 *video_codec_list = gif_image_list;
2951 *audio_codec_list = NULL;
2952 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
2953 (plugin->video_codec != CODEC_ID_NONE)) {
2954 tmp_vlist[0] = plugin->video_codec;
2955 tmp_alist[0] = plugin->audio_codec;
2957 *video_codec_list = tmp_vlist;
2958 *audio_codec_list = tmp_alist;
2960 GST_LOG ("Format %s not found", format_name);
2967 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
2968 * are omitted, that can be queried by the user itself,
2969 * we're not eating the GstCaps or anything
2970 * A pointer to an allocated context is also needed for
2971 * optional extra info
2975 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
2977 enum CodecID id = CODEC_ID_NONE;
2978 const gchar *mimetype;
2979 const GstStructure *structure;
2980 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
2982 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
2983 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
2984 structure = gst_caps_get_structure (caps, 0);
2986 mimetype = gst_structure_get_name (structure);
2988 if (!strcmp (mimetype, "video/x-raw")) {
2989 id = CODEC_ID_RAWVIDEO;
2991 } else if (!strcmp (mimetype, "audio/x-raw")) {
2994 if (gst_audio_info_from_caps (&info, caps)) {
2995 switch (GST_AUDIO_INFO_FORMAT (&info)) {
2996 case GST_AUDIO_FORMAT_S8:
2997 id = CODEC_ID_PCM_S8;
2999 case GST_AUDIO_FORMAT_U8:
3000 id = CODEC_ID_PCM_U8;
3002 case GST_AUDIO_FORMAT_S16LE:
3003 id = CODEC_ID_PCM_S16LE;
3005 case GST_AUDIO_FORMAT_S16BE:
3006 id = CODEC_ID_PCM_S16BE;
3008 case GST_AUDIO_FORMAT_U16LE:
3009 id = CODEC_ID_PCM_U16LE;
3011 case GST_AUDIO_FORMAT_U16BE:
3012 id = CODEC_ID_PCM_U16BE;
3017 if (id != CODEC_ID_NONE)
3020 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3021 id = CODEC_ID_PCM_MULAW;
3023 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3024 id = CODEC_ID_PCM_ALAW;
3026 } else if (!strcmp (mimetype, "video/x-dv")) {
3029 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3031 id = CODEC_ID_DVVIDEO;
3034 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3035 id = CODEC_ID_DVAUDIO;
3037 } else if (!strcmp (mimetype, "video/x-h263")) {
3038 const gchar *h263version =
3039 gst_structure_get_string (structure, "h263version");
3040 if (h263version && !strcmp (h263version, "h263p"))
3041 id = CODEC_ID_H263P;
3045 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3046 id = CODEC_ID_H263I;
3048 } else if (!strcmp (mimetype, "video/x-h261")) {
3051 } else if (!strcmp (mimetype, "video/mpeg")) {
3055 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3056 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3058 switch (mpegversion) {
3060 id = CODEC_ID_MPEG1VIDEO;
3063 id = CODEC_ID_MPEG2VIDEO;
3066 id = CODEC_ID_MPEG4;
3070 if (id != CODEC_ID_NONE)
3072 } else if (!strcmp (mimetype, "image/jpeg")) {
3073 id = CODEC_ID_MJPEG; /* A... B... */
3075 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3076 id = CODEC_ID_MJPEGB;
3078 } else if (!strcmp (mimetype, "video/x-wmv")) {
3079 gint wmvversion = 0;
3081 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3082 switch (wmvversion) {
3091 const gchar *format;
3093 /* WMV3 unless the fourcc exists and says otherwise */
3096 if ((format = gst_structure_get_string (structure, "format")) &&
3097 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3104 if (id != CODEC_ID_NONE)
3106 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3107 id = CODEC_ID_VORBIS;
3109 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3112 } else if (!strcmp (mimetype, "audio/mpeg")) {
3114 gint mpegversion = 0;
3116 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3117 switch (mpegversion) {
3118 case 2: /* ffmpeg uses faad for both... */
3123 if (gst_structure_get_int (structure, "layer", &layer)) {
3138 if (id != CODEC_ID_NONE)
3140 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3141 gint streamversion = -1;
3143 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3144 if (streamversion == 7)
3145 id = CODEC_ID_MUSEPACK7;
3147 id = CODEC_ID_MUSEPACK7;
3149 } else if (!strcmp (mimetype, "audio/x-wma")) {
3150 gint wmaversion = 0;
3152 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3153 switch (wmaversion) {
3155 id = CODEC_ID_WMAV1;
3158 id = CODEC_ID_WMAV2;
3161 id = CODEC_ID_WMAPRO;
3165 if (id != CODEC_ID_NONE)
3167 } else if (!strcmp (mimetype, "audio/x-wms")) {
3168 id = CODEC_ID_WMAVOICE;
3170 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3173 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3176 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3177 !strcmp (mimetype, "audio/atrac3")) {
3178 id = CODEC_ID_ATRAC3;
3180 } else if (!strcmp (mimetype, "audio/x-dts")) {
3183 } else if (!strcmp (mimetype, "application/x-ape")) {
3186 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3187 gint msmpegversion = 0;
3189 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3190 switch (msmpegversion) {
3192 id = CODEC_ID_MSMPEG4V1;
3195 id = CODEC_ID_MSMPEG4V2;
3198 id = CODEC_ID_MSMPEG4V3;
3202 if (id != CODEC_ID_NONE)
3204 } else if (!strcmp (mimetype, "video/x-svq")) {
3205 gint svqversion = 0;
3207 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3208 switch (svqversion) {
3217 if (id != CODEC_ID_NONE)
3219 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3220 id = CODEC_ID_HUFFYUV;
3222 } else if (!strcmp (mimetype, "audio/x-mace")) {
3223 gint maceversion = 0;
3225 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3226 switch (maceversion) {
3228 id = CODEC_ID_MACE3;
3231 id = CODEC_ID_MACE6;
3235 if (id != CODEC_ID_NONE)
3237 } else if (!strcmp (mimetype, "video/x-theora")) {
3238 id = CODEC_ID_THEORA;
3240 } else if (!strcmp (mimetype, "video/x-vp3")) {
3243 } else if (!strcmp (mimetype, "video/x-vp5")) {
3246 } else if (!strcmp (mimetype, "video/x-vp6")) {
3249 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3252 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3255 } else if (!strcmp (mimetype, "video/x-vp8")) {
3258 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3259 id = CODEC_ID_FLASHSV;
3261 } else if (!strcmp (mimetype, "video/x-indeo")) {
3262 gint indeoversion = 0;
3264 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3265 switch (indeoversion) {
3267 id = CODEC_ID_INDEO5;
3270 id = CODEC_ID_INDEO4;
3273 id = CODEC_ID_INDEO3;
3276 id = CODEC_ID_INDEO2;
3279 if (id != CODEC_ID_NONE)
3282 } else if (!strcmp (mimetype, "video/x-divx")) {
3283 gint divxversion = 0;
3285 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3286 switch (divxversion) {
3288 id = CODEC_ID_MSMPEG4V3;
3292 id = CODEC_ID_MPEG4;
3296 if (id != CODEC_ID_NONE)
3298 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3299 id = CODEC_ID_MPEG4;
3301 } else if (!strcmp (mimetype, "video/x-xvid")) {
3302 id = CODEC_ID_MPEG4;
3304 } else if (!strcmp (mimetype, "video/x-ffv")) {
3305 gint ffvversion = 0;
3307 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3312 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3313 const gchar *layout;
3315 layout = gst_structure_get_string (structure, "layout");
3316 if (layout == NULL) {
3318 } else if (!strcmp (layout, "quicktime")) {
3319 id = CODEC_ID_ADPCM_IMA_QT;
3320 } else if (!strcmp (layout, "microsoft")) {
3321 id = CODEC_ID_ADPCM_MS;
3322 } else if (!strcmp (layout, "dvi")) {
3323 id = CODEC_ID_ADPCM_IMA_WAV;
3324 } else if (!strcmp (layout, "4xm")) {
3325 id = CODEC_ID_ADPCM_4XM;
3326 } else if (!strcmp (layout, "smjpeg")) {
3327 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3328 } else if (!strcmp (layout, "dk3")) {
3329 id = CODEC_ID_ADPCM_IMA_DK3;
3330 } else if (!strcmp (layout, "dk4")) {
3331 id = CODEC_ID_ADPCM_IMA_DK4;
3332 } else if (!strcmp (layout, "westwood")) {
3333 id = CODEC_ID_ADPCM_IMA_WS;
3334 } else if (!strcmp (layout, "iss")) {
3335 id = CODEC_ID_ADPCM_IMA_ISS;
3336 } else if (!strcmp (layout, "xa")) {
3337 id = CODEC_ID_ADPCM_XA;
3338 } else if (!strcmp (layout, "adx")) {
3339 id = CODEC_ID_ADPCM_ADX;
3340 } else if (!strcmp (layout, "ea")) {
3341 id = CODEC_ID_ADPCM_EA;
3342 } else if (!strcmp (layout, "g726")) {
3343 id = CODEC_ID_ADPCM_G726;
3344 } else if (!strcmp (layout, "g721")) {
3345 id = CODEC_ID_ADPCM_G726;
3346 } else if (!strcmp (layout, "ct")) {
3347 id = CODEC_ID_ADPCM_CT;
3348 } else if (!strcmp (layout, "swf")) {
3349 id = CODEC_ID_ADPCM_SWF;
3350 } else if (!strcmp (layout, "yamaha")) {
3351 id = CODEC_ID_ADPCM_YAMAHA;
3352 } else if (!strcmp (layout, "sbpro2")) {
3353 id = CODEC_ID_ADPCM_SBPRO_2;
3354 } else if (!strcmp (layout, "sbpro3")) {
3355 id = CODEC_ID_ADPCM_SBPRO_3;
3356 } else if (!strcmp (layout, "sbpro4")) {
3357 id = CODEC_ID_ADPCM_SBPRO_4;
3359 if (id != CODEC_ID_NONE)
3361 } else if (!strcmp (mimetype, "video/x-4xm")) {
3364 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3365 const gchar *layout;
3367 layout = gst_structure_get_string (structure, "layout");
3370 } else if (!strcmp (layout, "roq")) {
3371 id = CODEC_ID_ROQ_DPCM;
3372 } else if (!strcmp (layout, "interplay")) {
3373 id = CODEC_ID_INTERPLAY_DPCM;
3374 } else if (!strcmp (layout, "xan")) {
3375 id = CODEC_ID_XAN_DPCM;
3376 } else if (!strcmp (layout, "sol")) {
3377 id = CODEC_ID_SOL_DPCM;
3379 if (id != CODEC_ID_NONE)
3381 } else if (!strcmp (mimetype, "audio/x-flac")) {
3384 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3385 id = CODEC_ID_SHORTEN;
3387 } else if (!strcmp (mimetype, "audio/x-alac")) {
3390 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3391 id = CODEC_ID_CINEPAK;
3393 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3396 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3397 switch (rmversion) {
3412 if (id != CODEC_ID_NONE)
3414 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3417 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3420 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3421 switch (raversion) {
3423 id = CODEC_ID_RA_144;
3426 id = CODEC_ID_RA_288;
3433 if (id != CODEC_ID_NONE)
3435 } else if (!strcmp (mimetype, "video/x-rle")) {
3436 const gchar *layout;
3438 if ((layout = gst_structure_get_string (structure, "layout"))) {
3439 if (!strcmp (layout, "microsoft")) {
3440 id = CODEC_ID_MSRLE;
3444 } else if (!strcmp (mimetype, "video/x-xan")) {
3447 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3448 switch (wcversion) {
3450 id = CODEC_ID_XAN_WC3;
3454 id = CODEC_ID_XAN_WC4;
3461 } else if (!strcmp (mimetype, "audio/AMR")) {
3463 id = CODEC_ID_AMR_NB;
3464 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3465 id = CODEC_ID_AMR_WB;
3467 } else if (!strcmp (mimetype, "audio/qcelp")) {
3468 id = CODEC_ID_QCELP;
3470 } else if (!strcmp (mimetype, "video/x-h264")) {
3473 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3474 gint flvversion = 0;
3476 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3477 switch (flvversion) {
3487 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3488 id = CODEC_ID_NELLYMOSER;
3490 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3494 if (strlen (mimetype) <= 30 &&
3495 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3496 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3497 (codec = avcodec_find_encoder_by_name (ext))) {
3502 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3506 if (strlen (mimetype) <= 30 &&
3507 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3508 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3509 (codec = avcodec_find_encoder_by_name (ext))) {
3516 if (context != NULL) {
3517 if (video == TRUE) {
3518 context->codec_type = AVMEDIA_TYPE_VIDEO;
3519 } else if (audio == TRUE) {
3520 context->codec_type = AVMEDIA_TYPE_AUDIO;
3522 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3524 context->codec_id = id;
3525 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3528 if (id != CODEC_ID_NONE) {
3529 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3531 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);