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_audio_set_sample_fmts (GstCaps * caps,
1808 const enum AVSampleFormat *fmts)
1812 GstAudioFormat format;
1814 if (!fmts || fmts[0] == -1) {
1817 g_value_init (&va, GST_TYPE_LIST);
1818 g_value_init (&v, G_TYPE_STRING);
1819 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
1820 format = gst_ffmpeg_smpfmt_to_audioformat (i);
1821 g_value_set_string (&v, gst_audio_format_to_string (format));
1822 gst_value_list_append_value (&va, &v);
1824 gst_caps_set_value (caps, "format", &va);
1826 g_value_unset (&va);
1830 /* Only a single rate */
1831 if (fmts[1] == -1) {
1832 format = gst_ffmpeg_smpfmt_to_audioformat (fmts[0]);
1833 gst_caps_set_simple (caps, "format", G_TYPE_STRING,
1834 gst_audio_format_to_string (format), NULL);
1838 g_value_init (&va, GST_TYPE_LIST);
1839 g_value_init (&v, G_TYPE_STRING);
1840 while (*fmts != -1) {
1841 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
1842 g_value_set_string (&v, gst_audio_format_to_string (format));
1843 gst_value_list_append_value (&va, &v);
1846 gst_caps_set_value (caps, "format", &va);
1848 g_value_unset (&va);
1852 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
1853 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1855 GstCaps *caps = NULL;
1857 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1858 context, codec_id, encode, codec);
1860 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
1861 codec->sample_fmts, codec->supported_samplerates);
1864 /* Specific codec context */
1865 caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec_id);
1867 caps = gst_ff_aud_caps_new (context, codec_id, TRUE, "audio/x-raw",
1868 "layout", G_TYPE_STRING, "interleaved", NULL);
1870 gst_ffmpeg_audio_set_sample_fmts (caps, codec ? codec->sample_fmts : NULL);
1877 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
1878 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1882 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1883 context, codec_id, encode, codec);
1886 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
1890 AVCodecContext ctx = { 0, };
1892 caps = gst_caps_new_empty ();
1893 for (i = 0; i < PIX_FMT_NB; i++) {
1896 temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1898 gst_caps_append (caps, temp);
1905 /* Convert a FFMPEG codec Type and optional AVCodecContext
1906 * to a GstCaps. If the context is ommitted, no fixed values
1907 * for video/audio size will be included in the GstCaps
1909 * AVMediaType is primarily meant for uncompressed data GstCaps!
1913 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
1914 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
1918 switch (codec_type) {
1919 case AVMEDIA_TYPE_VIDEO:
1921 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1923 case AVMEDIA_TYPE_AUDIO:
1925 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
1935 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
1936 * and other audio properties in a AVCodecContext.
1938 * For usefullness, see below
1942 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
1943 AVCodecContext * context, gboolean raw)
1945 GstStructure *structure;
1947 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
1949 g_return_if_fail (gst_caps_get_size (caps) == 1);
1951 structure = gst_caps_get_structure (caps, 0);
1953 gst_structure_get_int (structure, "channels", &context->channels);
1954 gst_structure_get_int (structure, "rate", &context->sample_rate);
1955 gst_structure_get_int (structure, "block_align", &context->block_align);
1956 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
1961 if (gst_structure_has_name (structure, "audio/x-raw")) {
1962 if ((fmt = gst_structure_get_string (structure, "format"))) {
1963 format = gst_audio_format_from_string (fmt);
1968 case GST_AUDIO_FORMAT_F32:
1969 context->sample_fmt = AV_SAMPLE_FMT_FLT;
1971 case GST_AUDIO_FORMAT_F64:
1972 context->sample_fmt = AV_SAMPLE_FMT_DBL;
1974 case GST_AUDIO_FORMAT_S32:
1975 context->sample_fmt = AV_SAMPLE_FMT_S32;
1977 case GST_AUDIO_FORMAT_S16:
1978 context->sample_fmt = AV_SAMPLE_FMT_S16;
1985 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
1986 * and other video properties in a AVCodecContext.
1988 * For usefullness, see below
1992 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
1993 AVCodecContext * context, gboolean raw)
1995 GstStructure *structure;
1997 const GValue *par = NULL;
1999 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2001 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2002 g_return_if_fail (gst_caps_get_size (caps) == 1);
2003 structure = gst_caps_get_structure (caps, 0);
2005 gst_structure_get_int (structure, "width", &context->width);
2006 gst_structure_get_int (structure, "height", &context->height);
2007 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2009 fps = gst_structure_get_value (structure, "framerate");
2010 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2012 /* somehow these seem mixed up.. */
2013 context->time_base.den = gst_value_get_fraction_numerator (fps);
2014 context->time_base.num = gst_value_get_fraction_denominator (fps);
2015 context->ticks_per_frame = 1;
2017 GST_DEBUG ("setting framerate %d/%d = %lf",
2018 context->time_base.den, context->time_base.num,
2019 1. * context->time_base.den / context->time_base.num);
2022 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2023 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2025 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2026 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2028 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2029 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2030 1. * context->sample_aspect_ratio.den /
2031 context->sample_aspect_ratio.num);
2037 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2039 if (gst_structure_has_name (structure, "video/x-raw")) {
2040 if ((fmt = gst_structure_get_string (structure, "format"))) {
2041 format = gst_video_format_from_string (fmt);
2046 case GST_VIDEO_FORMAT_YUY2:
2047 context->pix_fmt = PIX_FMT_YUYV422;
2049 case GST_VIDEO_FORMAT_I420:
2050 context->pix_fmt = PIX_FMT_YUV420P;
2052 case GST_VIDEO_FORMAT_A420:
2053 context->pix_fmt = PIX_FMT_YUVA420P;
2055 case GST_VIDEO_FORMAT_Y41B:
2056 context->pix_fmt = PIX_FMT_YUV411P;
2058 case GST_VIDEO_FORMAT_Y42B:
2059 context->pix_fmt = PIX_FMT_YUV422P;
2061 case GST_VIDEO_FORMAT_YUV9:
2062 context->pix_fmt = PIX_FMT_YUV410P;
2064 case GST_VIDEO_FORMAT_Y444:
2065 context->pix_fmt = PIX_FMT_YUV444P;
2067 case GST_VIDEO_FORMAT_GRAY8:
2068 context->pix_fmt = PIX_FMT_GRAY8;
2070 case GST_VIDEO_FORMAT_xRGB:
2071 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2072 context->pix_fmt = PIX_FMT_RGB32;
2075 case GST_VIDEO_FORMAT_BGRx:
2076 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2077 context->pix_fmt = PIX_FMT_RGB32;
2080 case GST_VIDEO_FORMAT_RGB:
2081 context->pix_fmt = PIX_FMT_RGB24;
2083 case GST_VIDEO_FORMAT_BGR:
2084 context->pix_fmt = PIX_FMT_BGR24;
2086 case GST_VIDEO_FORMAT_RGB16:
2087 context->pix_fmt = PIX_FMT_RGB565;
2089 case GST_VIDEO_FORMAT_RGB15:
2090 context->pix_fmt = PIX_FMT_RGB555;
2092 case GST_VIDEO_FORMAT_RGB8P:
2093 context->pix_fmt = PIX_FMT_PAL8;
2102 GstVideoFormat format;
2103 enum PixelFormat pixfmt;
2106 /* FIXME : FILLME */
2107 static const PixToFmt pixtofmttable[] = {
2108 /* GST_VIDEO_FORMAT_I420, */
2109 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2110 /* Note : this should use a different chroma placement */
2111 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2113 /* GST_VIDEO_FORMAT_YV12, */
2114 /* GST_VIDEO_FORMAT_YUY2, */
2115 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2116 /* GST_VIDEO_FORMAT_UYVY, */
2117 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2118 /* GST_VIDEO_FORMAT_AYUV, */
2119 /* GST_VIDEO_FORMAT_RGBx, */
2120 /* GST_VIDEO_FORMAT_BGRx, */
2121 /* GST_VIDEO_FORMAT_xRGB, */
2122 /* GST_VIDEO_FORMAT_xBGR, */
2123 /* GST_VIDEO_FORMAT_RGBA, */
2124 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2125 /* GST_VIDEO_FORMAT_BGRA, */
2126 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2127 /* GST_VIDEO_FORMAT_ARGB, */
2128 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2129 /* GST_VIDEO_FORMAT_ABGR, */
2130 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2131 /* GST_VIDEO_FORMAT_RGB, */
2132 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2133 /* GST_VIDEO_FORMAT_BGR, */
2134 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2135 /* GST_VIDEO_FORMAT_Y41B, */
2136 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2137 /* GST_VIDEO_FORMAT_Y42B, */
2138 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2139 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2140 /* GST_VIDEO_FORMAT_YVYU, */
2141 /* GST_VIDEO_FORMAT_Y444, */
2142 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2143 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2144 /* GST_VIDEO_FORMAT_v210, */
2145 /* GST_VIDEO_FORMAT_v216, */
2146 /* GST_VIDEO_FORMAT_NV12, */
2147 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2148 /* GST_VIDEO_FORMAT_NV21, */
2149 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2150 /* GST_VIDEO_FORMAT_GRAY8, */
2151 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2152 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2153 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2154 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2155 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2156 /* GST_VIDEO_FORMAT_v308, */
2157 /* GST_VIDEO_FORMAT_Y800, */
2158 /* GST_VIDEO_FORMAT_Y16, */
2159 /* GST_VIDEO_FORMAT_RGB16, */
2160 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2161 /* GST_VIDEO_FORMAT_BGR16, */
2162 /* GST_VIDEO_FORMAT_RGB15, */
2163 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2164 /* GST_VIDEO_FORMAT_BGR15, */
2165 /* GST_VIDEO_FORMAT_UYVP, */
2166 /* GST_VIDEO_FORMAT_A420, */
2167 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2168 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2169 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2170 /* GST_VIDEO_FORMAT_YUV9, */
2171 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2172 /* GST_VIDEO_FORMAT_YVU9, */
2173 /* GST_VIDEO_FORMAT_IYU1, */
2174 /* GST_VIDEO_FORMAT_ARGB64, */
2175 /* GST_VIDEO_FORMAT_AYUV64, */
2176 /* GST_VIDEO_FORMAT_r210, */
2177 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2178 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2179 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2180 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2181 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2182 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2183 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2184 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2185 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2189 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2193 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2194 if (pixtofmttable[i].pixfmt == pixfmt)
2195 return pixtofmttable[i].format;
2197 GST_WARNING ("Unknown pixel format %d", pixfmt);
2198 return GST_VIDEO_FORMAT_UNKNOWN;
2202 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2206 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2207 if (pixtofmttable[i].format == format)
2208 return pixtofmttable[i].pixfmt;
2209 return PIX_FMT_NONE;
2213 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2217 context->width = GST_VIDEO_INFO_WIDTH (info);
2218 context->height = GST_VIDEO_INFO_HEIGHT (info);
2219 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2220 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2221 context->bits_per_coded_sample = bpp;
2223 context->ticks_per_frame = 1;
2224 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2225 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2227 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2228 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2231 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2235 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2237 const AVCodec *codec;
2238 const enum AVSampleFormat *smpl_fmts;
2239 enum AVSampleFormat smpl_fmt = -1;
2241 context->channels = info->channels;
2242 context->sample_rate = info->rate;
2244 codec = context->codec;
2246 smpl_fmts = codec->sample_fmts;
2248 switch (info->finfo->format) {
2249 case GST_AUDIO_FORMAT_F32:
2251 while (*smpl_fmts != -1) {
2252 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2253 smpl_fmt = *smpl_fmts;
2255 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2256 smpl_fmt = *smpl_fmts;
2262 smpl_fmt = AV_SAMPLE_FMT_FLT;
2265 case GST_AUDIO_FORMAT_F64:
2267 while (*smpl_fmts != -1) {
2268 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2269 smpl_fmt = *smpl_fmts;
2271 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2272 smpl_fmt = *smpl_fmts;
2278 smpl_fmt = AV_SAMPLE_FMT_DBL;
2281 case GST_AUDIO_FORMAT_S32:
2283 while (*smpl_fmts != -1) {
2284 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2285 smpl_fmt = *smpl_fmts;
2287 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2288 smpl_fmt = *smpl_fmts;
2294 smpl_fmt = AV_SAMPLE_FMT_S32;
2297 case GST_AUDIO_FORMAT_S16:
2299 while (*smpl_fmts != -1) {
2300 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2301 smpl_fmt = *smpl_fmts;
2303 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2304 smpl_fmt = *smpl_fmts;
2310 smpl_fmt = AV_SAMPLE_FMT_S16;
2313 case GST_AUDIO_FORMAT_U8:
2315 while (*smpl_fmts != -1) {
2316 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2317 smpl_fmt = *smpl_fmts;
2319 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2320 smpl_fmt = *smpl_fmts;
2326 smpl_fmt = AV_SAMPLE_FMT_U8;
2333 g_assert (smpl_fmt != -1);
2335 context->sample_fmt = smpl_fmt;
2338 /* Convert a GstCaps and a FFMPEG codec Type to a
2339 * AVCodecContext. If the context is ommitted, no fixed values
2340 * for video/audio size will be included in the context
2342 * AVMediaType is primarily meant for uncompressed data GstCaps!
2346 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2347 const GstCaps * caps, AVCodecContext * context)
2349 if (context == NULL)
2353 case AVMEDIA_TYPE_VIDEO:
2354 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2357 case AVMEDIA_TYPE_AUDIO:
2358 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2369 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2373 guint8 *end = src + size;
2376 while (srcp < end) {
2377 if (count == 2 && *srcp <= 0x03) {
2378 GST_DEBUG ("added escape code");
2387 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2390 *destsize = dstp - dst;
2393 /* copy the config, escaping NAL units as we iterate them, if something fails we
2394 * copy everything and hope for the best. */
2396 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2401 guint nalsize, esize;
2411 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2413 GST_DEBUG ("num SPS %d", cnt);
2415 memcpy (dstp, srcp, 6);
2419 for (i = 0; i < cnt; i++) {
2420 GST_DEBUG ("copy SPS %d", i);
2421 nalsize = (srcp[0] << 8) | srcp[1];
2422 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2423 dstp[0] = esize >> 8;
2424 dstp[1] = esize & 0xff;
2426 srcp += nalsize + 2;
2429 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2431 GST_DEBUG ("num PPS %d", cnt);
2433 for (i = 0; i < cnt; i++) {
2434 GST_DEBUG ("copy PPS %d", i);
2435 nalsize = (srcp[0] << 8) | srcp[1];
2436 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2437 dstp[0] = esize >> 8;
2438 dstp[1] = esize & 0xff;
2440 srcp += nalsize + 2;
2442 *destsize = dstp - dst;
2448 GST_DEBUG ("something unexpected, doing full copy");
2449 memcpy (dst, src, size);
2457 * caps_with_codecid () transforms a GstCaps for a known codec
2458 * ID into a filled-in context.
2459 * codec_data from caps will override possible extradata already in the context
2463 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2464 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2467 const GValue *value;
2470 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2471 codec_id, codec_type, caps, context);
2473 if (!context || !gst_caps_get_size (caps))
2476 str = gst_caps_get_structure (caps, 0);
2478 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2479 if ((value = gst_structure_get_value (str, "codec_data"))) {
2482 buf = gst_value_get_buffer (value);
2483 gst_buffer_map (buf, &map, GST_MAP_READ);
2485 /* free the old one if it is there */
2486 if (context->extradata)
2487 av_free (context->extradata);
2490 if (codec_id == CODEC_ID_H264) {
2493 GST_DEBUG ("copy, escaping codec_data %d", size);
2494 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2495 * reason for this but let's just escape it for now. Start by allocating
2496 * enough space, x2 is more than enough.
2498 * FIXME, we disabled escaping because some file already contain escaped
2499 * codec_data and then we escape twice and fail. It's better to leave it
2500 * as is, as that is what most players do. */
2501 context->extradata =
2502 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2503 FF_INPUT_BUFFER_PADDING_SIZE));
2504 copy_config (context->extradata, data, size, &extrasize);
2505 GST_DEBUG ("escaped size: %d", extrasize);
2506 context->extradata_size = extrasize;
2510 /* allocate with enough padding */
2511 GST_DEBUG ("copy codec_data");
2512 context->extradata =
2513 av_mallocz (GST_ROUND_UP_16 (map.size +
2514 FF_INPUT_BUFFER_PADDING_SIZE));
2515 memcpy (context->extradata, map.data, map.size);
2516 context->extradata_size = map.size;
2519 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2520 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2521 context->extradata[0] = (guint8) map.size;
2524 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2526 gst_buffer_unmap (buf, &map);
2527 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2528 codec_id != CODEC_ID_FLAC) {
2529 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2530 * extradata anyway which makes then segfault. */
2531 context->extradata =
2532 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2533 context->extradata_size = 0;
2534 GST_DEBUG ("no codec data");
2538 case CODEC_ID_MPEG4:
2540 const gchar *mime = gst_structure_get_name (str);
2542 if (!strcmp (mime, "video/x-divx"))
2543 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2544 else if (!strcmp (mime, "video/x-xvid"))
2545 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2546 else if (!strcmp (mime, "video/x-3ivx"))
2547 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2548 else if (!strcmp (mime, "video/mpeg"))
2549 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2554 /* FIXME: this is a workaround for older gst-plugins releases
2555 * (<= 0.8.9). This should be removed at some point, because
2556 * it causes wrong decoded frame order. */
2557 if (!context->extradata) {
2558 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2561 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2562 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2563 gst_structure_get_int (str, "low_delay", &low_delay) ||
2564 gst_structure_get_int (str, "unknown_svq3_flag",
2565 &unknown_svq3_flag)) {
2566 context->extradata = (guint8 *) av_mallocz (0x64);
2567 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2571 flags |= unknown_svq3_flag;
2573 flags |= halfpel_flag;
2575 flags |= thirdpel_flag;
2578 flags = GUINT16_FROM_LE (flags);
2580 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2581 context->extradata_size = 0x64;
2586 case CODEC_ID_MSRLE:
2587 case CODEC_ID_QTRLE:
2594 if (gst_structure_get_int (str, "depth", &depth)) {
2595 context->bits_per_coded_sample = depth;
2597 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2610 if (gst_structure_get_int (str, "format", &format))
2611 context->sub_id = format;
2616 case CODEC_ID_RA_288:
2617 case CODEC_ID_RA_144:
2623 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2624 context->block_align = leaf_size;
2625 if (gst_structure_get_int (str, "bitrate", &bitrate))
2626 context->bit_rate = bitrate;
2629 gst_structure_get_int (str, "samplesize",
2630 &context->bits_per_coded_sample);
2633 case CODEC_ID_DVVIDEO:
2635 const gchar *format;
2637 if ((format = gst_structure_get_string (str, "format"))) {
2639 if (g_str_equal (format, "YUY2"))
2640 context->pix_fmt = PIX_FMT_YUYV422;
2641 else if (g_str_equal (format, "I420"))
2642 context->pix_fmt = PIX_FMT_YUV420P;
2643 else if (g_str_equal (format, "A420"))
2644 context->pix_fmt = PIX_FMT_YUVA420P;
2645 else if (g_str_equal (format, "Y41B"))
2646 context->pix_fmt = PIX_FMT_YUV411P;
2647 else if (g_str_equal (format, "Y42B"))
2648 context->pix_fmt = PIX_FMT_YUV422P;
2649 else if (g_str_equal (format, "YUV9"))
2650 context->pix_fmt = PIX_FMT_YUV410P;
2652 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2656 GST_WARNING ("No specified format");
2659 case CODEC_ID_H263P:
2663 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2664 context->flags |= CODEC_FLAG_4MV;
2666 context->flags &= ~CODEC_FLAG_4MV;
2667 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2668 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2669 context->flags |= CODEC_FLAG_AC_PRED;
2671 context->flags &= ~CODEC_FLAG_AC_PRED;
2672 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2673 context->flags |= CODEC_FLAG_LOOP_FILTER;
2675 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2678 case CODEC_ID_ADPCM_G726:
2680 const gchar *layout;
2682 if ((layout = gst_structure_get_string (str, "layout"))) {
2683 if (!strcmp (layout, "g721")) {
2684 context->sample_rate = 8000;
2685 context->channels = 1;
2686 context->bit_rate = 32000;
2695 if (!gst_caps_is_fixed (caps))
2698 /* common properties (width, height, fps) */
2699 switch (codec_type) {
2700 case AVMEDIA_TYPE_VIDEO:
2701 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2703 case AVMEDIA_TYPE_AUDIO:
2704 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2710 /* fixup of default settings */
2712 case CODEC_ID_QCELP:
2713 /* QCELP is always mono, no matter what the caps say */
2714 context->channels = 1;
2721 /* _formatid_to_caps () is meant for muxers/demuxers, it
2722 * transforms a name (ffmpeg way of ID'ing these, why don't
2723 * they have unique numerical IDs?) to the corresponding
2724 * caps belonging to that mux-format
2726 * Note: we don't need any additional info because the caps
2727 * isn't supposed to contain any useful info besides the
2732 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2734 GstCaps *caps = NULL;
2736 if (!strcmp (format_name, "mpeg")) {
2737 caps = gst_caps_new_simple ("video/mpeg",
2738 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2739 } else if (!strcmp (format_name, "mpegts")) {
2740 caps = gst_caps_new_simple ("video/mpegts",
2741 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2742 } else if (!strcmp (format_name, "rm")) {
2743 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2744 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2745 } else if (!strcmp (format_name, "asf")) {
2746 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2747 } else if (!strcmp (format_name, "avi")) {
2748 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2749 } else if (!strcmp (format_name, "wav")) {
2750 caps = gst_caps_new_empty_simple ("audio/x-wav");
2751 } else if (!strcmp (format_name, "ape")) {
2752 caps = gst_caps_new_empty_simple ("application/x-ape");
2753 } else if (!strcmp (format_name, "swf")) {
2754 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2755 } else if (!strcmp (format_name, "au")) {
2756 caps = gst_caps_new_empty_simple ("audio/x-au");
2757 } else if (!strcmp (format_name, "dv")) {
2758 caps = gst_caps_new_simple ("video/x-dv",
2759 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2760 } else if (!strcmp (format_name, "4xm")) {
2761 caps = gst_caps_new_empty_simple ("video/x-4xm");
2762 } else if (!strcmp (format_name, "matroska")) {
2763 caps = gst_caps_new_empty_simple ("video/x-matroska");
2764 } else if (!strcmp (format_name, "mp3")) {
2765 caps = gst_caps_new_empty_simple ("application/x-id3");
2766 } else if (!strcmp (format_name, "flic")) {
2767 caps = gst_caps_new_empty_simple ("video/x-fli");
2768 } else if (!strcmp (format_name, "flv")) {
2769 caps = gst_caps_new_empty_simple ("video/x-flv");
2770 } else if (!strcmp (format_name, "tta")) {
2771 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
2772 } else if (!strcmp (format_name, "aiff")) {
2773 caps = gst_caps_new_empty_simple ("audio/x-aiff");
2774 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2776 gst_caps_from_string
2777 ("application/x-3gp; video/quicktime; audio/x-m4a");
2778 } else if (!strcmp (format_name, "mov")) {
2779 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2780 } else if (!strcmp (format_name, "mp4")) {
2781 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2782 } else if (!strcmp (format_name, "3gp")) {
2783 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2784 } else if (!strcmp (format_name, "3g2")) {
2785 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2786 } else if (!strcmp (format_name, "psp")) {
2787 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2788 } else if (!strcmp (format_name, "ipod")) {
2789 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2790 } else if (!strcmp (format_name, "aac")) {
2791 caps = gst_caps_new_simple ("audio/mpeg",
2792 "mpegversion", G_TYPE_INT, 4, NULL);
2793 } else if (!strcmp (format_name, "gif")) {
2794 caps = gst_caps_from_string ("image/gif");
2795 } else if (!strcmp (format_name, "ogg")) {
2796 caps = gst_caps_from_string ("application/ogg");
2797 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
2798 caps = gst_caps_from_string ("application/mxf");
2799 } else if (!strcmp (format_name, "gxf")) {
2800 caps = gst_caps_from_string ("application/gxf");
2801 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
2802 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
2803 "y4mversion", G_TYPE_INT, 2, NULL);
2804 } else if (!strcmp (format_name, "mpc")) {
2805 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
2806 } else if (!strcmp (format_name, "vqf")) {
2807 caps = gst_caps_from_string ("audio/x-vqf");
2808 } else if (!strcmp (format_name, "nsv")) {
2809 caps = gst_caps_from_string ("video/x-nsv");
2810 } else if (!strcmp (format_name, "amr")) {
2811 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
2812 } else if (!strcmp (format_name, "webm")) {
2813 caps = gst_caps_from_string ("video/webm");
2814 } else if (!strcmp (format_name, "voc")) {
2815 caps = gst_caps_from_string ("audio/x-voc");
2819 GST_LOG ("Could not create stream format caps for %s", format_name);
2820 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
2821 caps = gst_caps_new_empty_simple (name);
2829 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
2830 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
2831 AVOutputFormat * plugin)
2833 static enum CodecID tmp_vlist[] = {
2837 static enum CodecID tmp_alist[] = {
2842 GST_LOG ("format_name : %s", format_name);
2844 if (!strcmp (format_name, "mp4")) {
2845 static enum CodecID mp4_video_list[] = {
2846 CODEC_ID_MPEG4, CODEC_ID_H264,
2850 static enum CodecID mp4_audio_list[] = {
2851 CODEC_ID_AAC, CODEC_ID_MP3,
2855 *video_codec_list = mp4_video_list;
2856 *audio_codec_list = mp4_audio_list;
2857 } else if (!strcmp (format_name, "mpeg")) {
2858 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
2859 CODEC_ID_MPEG2VIDEO,
2863 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
2869 *video_codec_list = mpeg_video_list;
2870 *audio_codec_list = mpeg_audio_list;
2871 } else if (!strcmp (format_name, "dvd")) {
2872 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
2875 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
2882 *video_codec_list = mpeg_video_list;
2883 *audio_codec_list = mpeg_audio_list;
2884 } else if (!strcmp (format_name, "mpegts")) {
2885 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
2886 CODEC_ID_MPEG2VIDEO,
2890 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
2898 *video_codec_list = mpegts_video_list;
2899 *audio_codec_list = mpegts_audio_list;
2900 } else if (!strcmp (format_name, "vob")) {
2901 static enum CodecID vob_video_list[] =
2902 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
2903 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
2904 CODEC_ID_DTS, CODEC_ID_NONE
2907 *video_codec_list = vob_video_list;
2908 *audio_codec_list = vob_audio_list;
2909 } else if (!strcmp (format_name, "flv")) {
2910 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
2911 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
2913 *video_codec_list = flv_video_list;
2914 *audio_codec_list = flv_audio_list;
2915 } else if (!strcmp (format_name, "asf")) {
2916 static enum CodecID asf_video_list[] =
2917 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
2918 static enum CodecID asf_audio_list[] =
2919 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
2921 *video_codec_list = asf_video_list;
2922 *audio_codec_list = asf_audio_list;
2923 } else if (!strcmp (format_name, "dv")) {
2924 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
2925 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
2927 *video_codec_list = dv_video_list;
2928 *audio_codec_list = dv_audio_list;
2929 } else if (!strcmp (format_name, "mov")) {
2930 static enum CodecID mov_video_list[] = {
2931 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
2932 CODEC_ID_H263, CODEC_ID_H263P,
2933 CODEC_ID_H264, CODEC_ID_DVVIDEO,
2937 static enum CodecID mov_audio_list[] = {
2938 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
2939 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
2940 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2941 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
2942 CODEC_ID_MP3, CODEC_ID_NONE
2945 *video_codec_list = mov_video_list;
2946 *audio_codec_list = mov_audio_list;
2947 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
2948 static enum CodecID tgp_video_list[] = {
2949 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
2952 static enum CodecID tgp_audio_list[] = {
2953 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2958 *video_codec_list = tgp_video_list;
2959 *audio_codec_list = tgp_audio_list;
2960 } else if (!strcmp (format_name, "mmf")) {
2961 static enum CodecID mmf_audio_list[] = {
2962 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
2964 *video_codec_list = NULL;
2965 *audio_codec_list = mmf_audio_list;
2966 } else if (!strcmp (format_name, "amr")) {
2967 static enum CodecID amr_audio_list[] = {
2968 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2971 *video_codec_list = NULL;
2972 *audio_codec_list = amr_audio_list;
2973 } else if (!strcmp (format_name, "gif")) {
2974 static enum CodecID gif_image_list[] = {
2975 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
2977 *video_codec_list = gif_image_list;
2978 *audio_codec_list = NULL;
2979 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
2980 (plugin->video_codec != CODEC_ID_NONE)) {
2981 tmp_vlist[0] = plugin->video_codec;
2982 tmp_alist[0] = plugin->audio_codec;
2984 *video_codec_list = tmp_vlist;
2985 *audio_codec_list = tmp_alist;
2987 GST_LOG ("Format %s not found", format_name);
2994 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
2995 * are omitted, that can be queried by the user itself,
2996 * we're not eating the GstCaps or anything
2997 * A pointer to an allocated context is also needed for
2998 * optional extra info
3002 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3004 enum CodecID id = CODEC_ID_NONE;
3005 const gchar *mimetype;
3006 const GstStructure *structure;
3007 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3009 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3010 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3011 structure = gst_caps_get_structure (caps, 0);
3013 mimetype = gst_structure_get_name (structure);
3015 if (!strcmp (mimetype, "video/x-raw")) {
3016 id = CODEC_ID_RAWVIDEO;
3018 } else if (!strcmp (mimetype, "audio/x-raw")) {
3021 if (gst_audio_info_from_caps (&info, caps)) {
3022 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3023 case GST_AUDIO_FORMAT_S8:
3024 id = CODEC_ID_PCM_S8;
3026 case GST_AUDIO_FORMAT_U8:
3027 id = CODEC_ID_PCM_U8;
3029 case GST_AUDIO_FORMAT_S16LE:
3030 id = CODEC_ID_PCM_S16LE;
3032 case GST_AUDIO_FORMAT_S16BE:
3033 id = CODEC_ID_PCM_S16BE;
3035 case GST_AUDIO_FORMAT_U16LE:
3036 id = CODEC_ID_PCM_U16LE;
3038 case GST_AUDIO_FORMAT_U16BE:
3039 id = CODEC_ID_PCM_U16BE;
3044 if (id != CODEC_ID_NONE)
3047 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3048 id = CODEC_ID_PCM_MULAW;
3050 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3051 id = CODEC_ID_PCM_ALAW;
3053 } else if (!strcmp (mimetype, "video/x-dv")) {
3056 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3058 id = CODEC_ID_DVVIDEO;
3061 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3062 id = CODEC_ID_DVAUDIO;
3064 } else if (!strcmp (mimetype, "video/x-h263")) {
3065 const gchar *h263version =
3066 gst_structure_get_string (structure, "h263version");
3067 if (h263version && !strcmp (h263version, "h263p"))
3068 id = CODEC_ID_H263P;
3072 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3073 id = CODEC_ID_H263I;
3075 } else if (!strcmp (mimetype, "video/x-h261")) {
3078 } else if (!strcmp (mimetype, "video/mpeg")) {
3082 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3083 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3085 switch (mpegversion) {
3087 id = CODEC_ID_MPEG1VIDEO;
3090 id = CODEC_ID_MPEG2VIDEO;
3093 id = CODEC_ID_MPEG4;
3097 if (id != CODEC_ID_NONE)
3099 } else if (!strcmp (mimetype, "image/jpeg")) {
3100 id = CODEC_ID_MJPEG; /* A... B... */
3102 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3103 id = CODEC_ID_MJPEGB;
3105 } else if (!strcmp (mimetype, "video/x-wmv")) {
3106 gint wmvversion = 0;
3108 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3109 switch (wmvversion) {
3118 const gchar *format;
3120 /* WMV3 unless the fourcc exists and says otherwise */
3123 if ((format = gst_structure_get_string (structure, "format")) &&
3124 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3131 if (id != CODEC_ID_NONE)
3133 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3134 id = CODEC_ID_VORBIS;
3136 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3139 } else if (!strcmp (mimetype, "audio/mpeg")) {
3141 gint mpegversion = 0;
3143 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3144 switch (mpegversion) {
3145 case 2: /* ffmpeg uses faad for both... */
3150 if (gst_structure_get_int (structure, "layer", &layer)) {
3165 if (id != CODEC_ID_NONE)
3167 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3168 gint streamversion = -1;
3170 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3171 if (streamversion == 7)
3172 id = CODEC_ID_MUSEPACK7;
3174 id = CODEC_ID_MUSEPACK7;
3176 } else if (!strcmp (mimetype, "audio/x-wma")) {
3177 gint wmaversion = 0;
3179 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3180 switch (wmaversion) {
3182 id = CODEC_ID_WMAV1;
3185 id = CODEC_ID_WMAV2;
3188 id = CODEC_ID_WMAPRO;
3192 if (id != CODEC_ID_NONE)
3194 } else if (!strcmp (mimetype, "audio/x-wms")) {
3195 id = CODEC_ID_WMAVOICE;
3197 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3200 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3203 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3204 !strcmp (mimetype, "audio/atrac3")) {
3205 id = CODEC_ID_ATRAC3;
3207 } else if (!strcmp (mimetype, "audio/x-dts")) {
3210 } else if (!strcmp (mimetype, "application/x-ape")) {
3213 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3214 gint msmpegversion = 0;
3216 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3217 switch (msmpegversion) {
3219 id = CODEC_ID_MSMPEG4V1;
3222 id = CODEC_ID_MSMPEG4V2;
3225 id = CODEC_ID_MSMPEG4V3;
3229 if (id != CODEC_ID_NONE)
3231 } else if (!strcmp (mimetype, "video/x-svq")) {
3232 gint svqversion = 0;
3234 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3235 switch (svqversion) {
3244 if (id != CODEC_ID_NONE)
3246 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3247 id = CODEC_ID_HUFFYUV;
3249 } else if (!strcmp (mimetype, "audio/x-mace")) {
3250 gint maceversion = 0;
3252 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3253 switch (maceversion) {
3255 id = CODEC_ID_MACE3;
3258 id = CODEC_ID_MACE6;
3262 if (id != CODEC_ID_NONE)
3264 } else if (!strcmp (mimetype, "video/x-theora")) {
3265 id = CODEC_ID_THEORA;
3267 } else if (!strcmp (mimetype, "video/x-vp3")) {
3270 } else if (!strcmp (mimetype, "video/x-vp5")) {
3273 } else if (!strcmp (mimetype, "video/x-vp6")) {
3276 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3279 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3282 } else if (!strcmp (mimetype, "video/x-vp8")) {
3285 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3286 id = CODEC_ID_FLASHSV;
3288 } else if (!strcmp (mimetype, "video/x-indeo")) {
3289 gint indeoversion = 0;
3291 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3292 switch (indeoversion) {
3294 id = CODEC_ID_INDEO5;
3297 id = CODEC_ID_INDEO4;
3300 id = CODEC_ID_INDEO3;
3303 id = CODEC_ID_INDEO2;
3306 if (id != CODEC_ID_NONE)
3309 } else if (!strcmp (mimetype, "video/x-divx")) {
3310 gint divxversion = 0;
3312 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3313 switch (divxversion) {
3315 id = CODEC_ID_MSMPEG4V3;
3319 id = CODEC_ID_MPEG4;
3323 if (id != CODEC_ID_NONE)
3325 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3326 id = CODEC_ID_MPEG4;
3328 } else if (!strcmp (mimetype, "video/x-xvid")) {
3329 id = CODEC_ID_MPEG4;
3331 } else if (!strcmp (mimetype, "video/x-ffv")) {
3332 gint ffvversion = 0;
3334 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3339 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3340 const gchar *layout;
3342 layout = gst_structure_get_string (structure, "layout");
3343 if (layout == NULL) {
3345 } else if (!strcmp (layout, "quicktime")) {
3346 id = CODEC_ID_ADPCM_IMA_QT;
3347 } else if (!strcmp (layout, "microsoft")) {
3348 id = CODEC_ID_ADPCM_MS;
3349 } else if (!strcmp (layout, "dvi")) {
3350 id = CODEC_ID_ADPCM_IMA_WAV;
3351 } else if (!strcmp (layout, "4xm")) {
3352 id = CODEC_ID_ADPCM_4XM;
3353 } else if (!strcmp (layout, "smjpeg")) {
3354 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3355 } else if (!strcmp (layout, "dk3")) {
3356 id = CODEC_ID_ADPCM_IMA_DK3;
3357 } else if (!strcmp (layout, "dk4")) {
3358 id = CODEC_ID_ADPCM_IMA_DK4;
3359 } else if (!strcmp (layout, "westwood")) {
3360 id = CODEC_ID_ADPCM_IMA_WS;
3361 } else if (!strcmp (layout, "iss")) {
3362 id = CODEC_ID_ADPCM_IMA_ISS;
3363 } else if (!strcmp (layout, "xa")) {
3364 id = CODEC_ID_ADPCM_XA;
3365 } else if (!strcmp (layout, "adx")) {
3366 id = CODEC_ID_ADPCM_ADX;
3367 } else if (!strcmp (layout, "ea")) {
3368 id = CODEC_ID_ADPCM_EA;
3369 } else if (!strcmp (layout, "g726")) {
3370 id = CODEC_ID_ADPCM_G726;
3371 } else if (!strcmp (layout, "g721")) {
3372 id = CODEC_ID_ADPCM_G726;
3373 } else if (!strcmp (layout, "ct")) {
3374 id = CODEC_ID_ADPCM_CT;
3375 } else if (!strcmp (layout, "swf")) {
3376 id = CODEC_ID_ADPCM_SWF;
3377 } else if (!strcmp (layout, "yamaha")) {
3378 id = CODEC_ID_ADPCM_YAMAHA;
3379 } else if (!strcmp (layout, "sbpro2")) {
3380 id = CODEC_ID_ADPCM_SBPRO_2;
3381 } else if (!strcmp (layout, "sbpro3")) {
3382 id = CODEC_ID_ADPCM_SBPRO_3;
3383 } else if (!strcmp (layout, "sbpro4")) {
3384 id = CODEC_ID_ADPCM_SBPRO_4;
3386 if (id != CODEC_ID_NONE)
3388 } else if (!strcmp (mimetype, "video/x-4xm")) {
3391 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3392 const gchar *layout;
3394 layout = gst_structure_get_string (structure, "layout");
3397 } else if (!strcmp (layout, "roq")) {
3398 id = CODEC_ID_ROQ_DPCM;
3399 } else if (!strcmp (layout, "interplay")) {
3400 id = CODEC_ID_INTERPLAY_DPCM;
3401 } else if (!strcmp (layout, "xan")) {
3402 id = CODEC_ID_XAN_DPCM;
3403 } else if (!strcmp (layout, "sol")) {
3404 id = CODEC_ID_SOL_DPCM;
3406 if (id != CODEC_ID_NONE)
3408 } else if (!strcmp (mimetype, "audio/x-flac")) {
3411 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3412 id = CODEC_ID_SHORTEN;
3414 } else if (!strcmp (mimetype, "audio/x-alac")) {
3417 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3418 id = CODEC_ID_CINEPAK;
3420 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3423 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3424 switch (rmversion) {
3439 if (id != CODEC_ID_NONE)
3441 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3444 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3447 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3448 switch (raversion) {
3450 id = CODEC_ID_RA_144;
3453 id = CODEC_ID_RA_288;
3460 if (id != CODEC_ID_NONE)
3462 } else if (!strcmp (mimetype, "video/x-rle")) {
3463 const gchar *layout;
3465 if ((layout = gst_structure_get_string (structure, "layout"))) {
3466 if (!strcmp (layout, "microsoft")) {
3467 id = CODEC_ID_MSRLE;
3471 } else if (!strcmp (mimetype, "video/x-xan")) {
3474 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3475 switch (wcversion) {
3477 id = CODEC_ID_XAN_WC3;
3481 id = CODEC_ID_XAN_WC4;
3488 } else if (!strcmp (mimetype, "audio/AMR")) {
3490 id = CODEC_ID_AMR_NB;
3491 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3492 id = CODEC_ID_AMR_WB;
3494 } else if (!strcmp (mimetype, "audio/qcelp")) {
3495 id = CODEC_ID_QCELP;
3497 } else if (!strcmp (mimetype, "video/x-h264")) {
3500 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3501 gint flvversion = 0;
3503 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3504 switch (flvversion) {
3514 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3515 id = CODEC_ID_NELLYMOSER;
3517 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3521 if (strlen (mimetype) <= 30 &&
3522 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3523 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3524 (codec = avcodec_find_encoder_by_name (ext))) {
3529 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3533 if (strlen (mimetype) <= 30 &&
3534 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3535 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3536 (codec = avcodec_find_encoder_by_name (ext))) {
3543 if (context != NULL) {
3544 if (video == TRUE) {
3545 context->codec_type = AVMEDIA_TYPE_VIDEO;
3546 } else if (audio == TRUE) {
3547 context->codec_type = AVMEDIA_TYPE_AUDIO;
3549 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3551 context->codec_id = id;
3552 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3555 if (id != CODEC_ID_NONE) {
3556 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3558 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);