2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * Copyright (c) 2002-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include <libavcodec/avcodec.h>
30 #include <libavutil/channel_layout.h>
33 #include "gstavcodecmap.h"
35 #include <gst/video/video.h>
36 #include <gst/audio/audio.h>
37 #include <gst/pbutils/codec-utils.h>
39 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
43 GstAudioChannelPosition gst;
44 } _ff_to_gst_layout[] = {
46 AV_CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
47 AV_CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
48 AV_CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
49 AV_CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
50 AV_CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
51 AV_CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
52 AV_CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
53 AV_CH_FRONT_RIGHT_OF_CENTER,
54 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
55 AV_CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
56 AV_CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
57 AV_CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
58 AV_CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
59 AV_CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
60 AV_CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
61 AV_CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
62 AV_CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
63 AV_CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
64 AV_CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}, {
65 AV_CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
66 AV_CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
70 gst_ffmpeg_channel_positions_to_layout (GstAudioChannelPosition * pos,
75 gint channels_found = 0;
80 for (i = 0; i < channels; i++) {
81 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
82 if (_ff_to_gst_layout[j].gst == pos[i]) {
83 ret |= _ff_to_gst_layout[j].ff;
90 if (channels_found != channels)
96 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
97 GstAudioChannelPosition * pos)
100 gboolean none_layout = FALSE;
102 if (channel_layout == 0) {
103 nchannels = channels;
108 for (i = 0; i < 64; i++) {
109 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
114 if (nchannels != channels) {
115 GST_ERROR ("Number of channels is different (%u != %u)", channels,
117 nchannels = channels;
121 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
122 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
123 pos[j++] = _ff_to_gst_layout[i].gst;
125 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
130 if (j != nchannels) {
132 ("Unknown channels in channel layout - assuming NONE layout");
139 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
140 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
141 " - assuming NONE layout", channel_layout);
146 if (nchannels == 1) {
147 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
148 } else if (nchannels == 2) {
149 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
150 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
154 for (i = 0; i < nchannels; i++)
155 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
163 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
167 GstVideoFormat format;
169 if (!fmts || fmts[0] == -1) {
172 g_value_init (&va, GST_TYPE_LIST);
173 g_value_init (&v, G_TYPE_STRING);
174 for (i = 0; i <= PIX_FMT_NB; i++) {
175 format = gst_ffmpeg_pixfmt_to_videoformat (i);
176 if (format == GST_VIDEO_FORMAT_UNKNOWN)
178 g_value_set_string (&v, gst_video_format_to_string (format));
179 gst_value_list_append_value (&va, &v);
181 gst_caps_set_value (caps, "format", &va);
187 /* Only a single format */
188 g_value_init (&va, GST_TYPE_LIST);
189 g_value_init (&v, G_TYPE_STRING);
190 while (*fmts != -1) {
191 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
192 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
193 g_value_set_string (&v, gst_video_format_to_string (format));
194 gst_value_list_append_value (&va, &v);
198 if (gst_value_list_get_size (&va) == 1) {
199 /* The single value is still in v */
200 gst_caps_set_value (caps, "format", &v);
201 } else if (gst_value_list_get_size (&va) > 1) {
202 gst_caps_set_value (caps, "format", &va);
208 /* this macro makes a caps width fixed or unfixed width/height
209 * properties depending on whether we've got a context.
211 * See below for why we use this.
213 * We should actually do this stuff at the end, like in riff-media.c,
214 * but I'm too lazy today. Maybe later.
217 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
218 enum CodecID codec_id, gboolean encode, const char *mimetype,
219 const char *fieldname, ...)
221 GstCaps *caps = NULL;
225 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
227 /* fixed, non probing context */
228 if (context != NULL && context->width != -1) {
231 caps = gst_caps_new_simple (mimetype,
232 "width", G_TYPE_INT, context->width,
233 "height", G_TYPE_INT, context->height, NULL);
235 num = context->time_base.den / context->ticks_per_frame;
236 denom = context->time_base.num;
239 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
242 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
243 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
247 GST_LOG ("setting framerate: %d/%d", num, denom);
248 gst_caps_set_simple (caps,
249 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
251 /* so we are after restricted caps in this case */
255 caps = gst_caps_new_simple (mimetype,
256 "width", G_TYPE_INT, 352,
257 "height", G_TYPE_INT, 288,
258 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
259 gst_caps_append (caps, gst_caps_new_simple (mimetype,
260 "width", G_TYPE_INT, 176,
261 "height", G_TYPE_INT, 144,
262 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
267 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
268 * because we want automatic negotiation to go as close to 320x240 as
270 const static gint widths[] = { 352, 704, 176, 1408, 128 };
271 const static gint heights[] = { 288, 576, 144, 1152, 96 };
273 gint n_sizes = G_N_ELEMENTS (widths);
275 caps = gst_caps_new_empty ();
276 for (i = 0; i < n_sizes; i++) {
277 temp = gst_caps_new_simple (mimetype,
278 "width", G_TYPE_INT, widths[i],
279 "height", G_TYPE_INT, heights[i],
280 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
282 gst_caps_append (caps, temp);
286 case CODEC_ID_DVVIDEO:
293 gint framerate_n, framerate_d;
296 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
297 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
298 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
299 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
300 "I420", 720, 576, 16, 15, 25, 1}, {
301 "I420", 720, 576, 64, 45, 25, 1}, {
302 "Y41B", 720, 576, 16, 15, 25, 1}, {
303 "Y41B", 720, 576, 64, 45, 25, 1}, {
304 "Y42B", 720, 576, 16, 15, 25, 1}, {
305 "Y42B", 720, 576, 64, 45, 25, 1}, {
306 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
307 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
308 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
309 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
310 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
311 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
312 "Y42B", 960, 720, 1, 1, 50, 1}, {
313 "Y42B", 960, 720, 4, 3, 50, 1},};
315 gint n_sizes = G_N_ELEMENTS (profiles);
317 if (strcmp (mimetype, "video/x-raw") == 0) {
318 caps = gst_caps_new_empty ();
319 for (i = 0; i < n_sizes; i++) {
320 temp = gst_caps_new_simple (mimetype,
321 "format", G_TYPE_STRING, profiles[i].csp,
322 "width", G_TYPE_INT, profiles[i].width,
323 "height", G_TYPE_INT, profiles[i].height,
324 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
325 profiles[i].framerate_d, "pixel-aspect-ratio",
326 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
328 gst_caps_append (caps, temp);
331 caps = gst_caps_new_empty ();
332 for (i = 0; i < n_sizes; i++) {
333 temp = gst_caps_new_simple (mimetype,
334 "width", G_TYPE_INT, profiles[i].width,
335 "height", G_TYPE_INT, profiles[i].height,
336 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
337 profiles[i].framerate_d, "pixel-aspect-ratio",
338 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
340 gst_caps_append (caps, temp);
347 caps = gst_caps_new_simple (mimetype,
348 "width", G_TYPE_INT, 1920,
349 "height", G_TYPE_INT, 1080,
350 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
351 gst_caps_append (caps, gst_caps_new_simple (mimetype,
352 "width", G_TYPE_INT, 1280,
353 "height", G_TYPE_INT, 720,
354 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
359 if (codec && codec->supported_framerates
360 && codec->supported_framerates[0].num != 0
361 && codec->supported_framerates[0].den != 0) {
364 const AVRational *rates = codec->supported_framerates;
366 if (rates[1].num == 0 && rates[1].den == 0) {
368 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
369 rates[0].num, rates[0].den, NULL);
371 g_value_init (&va, GST_TYPE_LIST);
372 g_value_init (&v, GST_TYPE_FRACTION);
374 while (rates->num != 0 && rates->den != 0) {
375 gst_value_set_fraction (&v, rates->num, rates->den);
376 gst_value_list_append_value (&va, &v);
380 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
381 gst_caps_set_value (caps, "framerate", &va);
387 caps = gst_caps_new_empty_simple (mimetype);
395 /* no fixed caps or special restrictions applied;
396 * default unfixed setting */
398 GST_DEBUG ("Creating default caps");
399 caps = gst_caps_new_empty_simple (mimetype);
402 va_start (var_args, fieldname);
403 gst_caps_set_simple_valist (caps, fieldname, var_args);
410 get_nbits_set (guint64 n)
415 for (i = 0; i < 64; i++) {
416 if ((n & (G_GUINT64_CONSTANT (1) << i)))
424 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
425 const enum AVSampleFormat *fmts)
429 GstAudioFormat format;
431 if (!fmts || fmts[0] == -1) {
434 g_value_init (&va, GST_TYPE_LIST);
435 g_value_init (&v, G_TYPE_STRING);
436 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
437 format = gst_ffmpeg_smpfmt_to_audioformat (i);
438 if (format == GST_AUDIO_FORMAT_UNKNOWN)
440 g_value_set_string (&v, gst_audio_format_to_string (format));
441 gst_value_list_append_value (&va, &v);
443 gst_caps_set_value (caps, "format", &va);
449 g_value_init (&va, GST_TYPE_LIST);
450 g_value_init (&v, G_TYPE_STRING);
451 while (*fmts != -1) {
452 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
453 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
454 g_value_set_string (&v, gst_audio_format_to_string (format));
455 gst_value_list_append_value (&va, &v);
459 if (gst_value_list_get_size (&va) == 1) {
460 /* The single value is still in v */
461 gst_caps_set_value (caps, "format", &v);
462 } else if (gst_value_list_get_size (&va) > 1) {
463 gst_caps_set_value (caps, "format", &va);
469 /* same for audio - now with channels/sample rate
472 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
473 enum CodecID codec_id, gboolean encode, const char *mimetype,
474 const char *fieldname, ...)
476 GstCaps *caps = NULL;
480 /* fixed, non-probing context */
481 if (context != NULL && context->channels != -1) {
482 GstAudioChannelPosition pos[64];
484 caps = gst_caps_new_simple (mimetype,
485 "rate", G_TYPE_INT, context->sample_rate,
486 "channels", G_TYPE_INT, context->channels, NULL);
488 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
489 context->channels, pos)) {
492 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
494 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
499 gint maxchannels = 2;
500 const gint *rates = NULL;
503 /* so we must be after restricted caps in this case */
506 case CODEC_ID_AAC_LATM:
512 const static gint l_rates[] =
513 { 48000, 44100, 32000, 24000, 22050, 16000 };
514 n_rates = G_N_ELEMENTS (l_rates);
521 const static gint l_rates[] = { 48000, 44100, 32000 };
523 n_rates = G_N_ELEMENTS (l_rates);
527 case CODEC_ID_ADPCM_G722:
529 const static gint l_rates[] = { 16000 };
530 n_rates = G_N_ELEMENTS (l_rates);
535 case CODEC_ID_ADPCM_G726:
537 const static gint l_rates[] = { 8000 };
538 n_rates = G_N_ELEMENTS (l_rates);
543 case CODEC_ID_ADPCM_SWF:
545 const static gint l_rates[] = { 11025, 22050, 44100 };
546 n_rates = G_N_ELEMENTS (l_rates);
550 case CODEC_ID_ROQ_DPCM:
552 const static gint l_rates[] = { 22050 };
553 n_rates = G_N_ELEMENTS (l_rates);
557 case CODEC_ID_AMR_NB:
559 const static gint l_rates[] = { 8000 };
561 n_rates = G_N_ELEMENTS (l_rates);
565 case CODEC_ID_AMR_WB:
567 const static gint l_rates[] = { 16000 };
569 n_rates = G_N_ELEMENTS (l_rates);
577 /* regardless of encode/decode, open up channels if applicable */
578 /* Until decoders/encoders expose the maximum number of channels
579 * they support, we whitelist them here. */
581 case CODEC_ID_WMAPRO:
582 case CODEC_ID_TRUEHD:
589 if (codec && codec->channel_layouts) {
590 const uint64_t *layouts = codec->channel_layouts;
591 GstAudioChannelPosition pos[64];
593 caps = gst_caps_new_empty ();
595 gint nbits_set = get_nbits_set (*layouts);
597 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
600 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
603 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
605 "channels", G_TYPE_INT, nbits_set, NULL);
607 gst_caps_append (caps, tmp);
613 if (maxchannels == 1)
614 caps = gst_caps_new_simple (mimetype,
615 "channels", G_TYPE_INT, maxchannels, NULL);
617 caps = gst_caps_new_simple (mimetype,
618 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
622 GValue list = { 0, };
624 g_value_init (&list, GST_TYPE_LIST);
625 for (i = 0; i < n_rates; i++) {
628 g_value_init (&v, G_TYPE_INT);
629 g_value_set_int (&v, rates[i]);
630 gst_value_list_append_value (&list, &v);
633 gst_caps_set_value (caps, "rate", &list);
634 g_value_unset (&list);
635 } else if (codec && codec->supported_samplerates
636 && codec->supported_samplerates[0]) {
640 if (!codec->supported_samplerates[1]) {
641 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
642 codec->supported_samplerates[0], NULL);
644 const int *rates = codec->supported_samplerates;
646 g_value_init (&va, GST_TYPE_LIST);
647 g_value_init (&v, G_TYPE_INT);
650 g_value_set_int (&v, *rates);
651 gst_value_list_append_value (&va, &v);
654 gst_caps_set_value (caps, "rate", &va);
659 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
662 caps = gst_caps_new_empty_simple (mimetype);
665 va_start (var_args, fieldname);
666 gst_caps_set_simple_valist (caps, fieldname, var_args);
672 /* Convert a FFMPEG codec ID and optional AVCodecContext
673 * to a GstCaps. If the context is ommitted, no fixed values
674 * for video/audio size will be included in the GstCaps
676 * CodecID is primarily meant for compressed data GstCaps!
678 * encode is a special parameter. gstffmpegdec will say
679 * FALSE, gstffmpegenc will say TRUE. The output caps
680 * depends on this, in such a way that it will be very
681 * specific, defined, fixed and correct caps for encoders,
682 * yet very wide, "forgiving" caps for decoders. Example
683 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
684 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
689 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
690 AVCodecContext * context, gboolean encode)
692 GstCaps *caps = NULL;
693 gboolean buildcaps = FALSE;
695 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
698 case CODEC_ID_MPEG1VIDEO:
700 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
701 "mpegversion", G_TYPE_INT, 1,
702 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
705 case CODEC_ID_MPEG2VIDEO:
709 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
710 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
713 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
714 * the MPEG video stream headers, so may be omitted from caps. */
715 caps = gst_caps_new_simple ("video/mpeg",
716 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
717 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
721 case CODEC_ID_MPEG2VIDEO_XVMC:
722 /* this is a special ID - don't need it in GStreamer, I think */
728 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
729 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
730 G_TYPE_STRING, "h263", NULL);
732 /* don't pass codec_id, we can decode other variants with the H263
733 * decoder that don't have specific size requirements
736 gst_ff_vid_caps_new (context, NULL, CODEC_ID_NONE, encode,
737 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
743 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
744 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
746 if (encode && context) {
748 gst_caps_set_simple (caps,
749 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
750 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
751 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
752 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
759 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
760 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
765 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
791 /* FIXME: context->sub_id must be filled in during decoding */
793 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
794 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
795 "rmversion", G_TYPE_INT, version, NULL);
797 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
798 if (context->extradata_size >= 8) {
799 gst_caps_set_simple (caps,
800 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
809 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
810 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
815 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
816 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
823 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
824 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
826 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
827 * in the MPEG audio header, so may be omitted from caps. */
828 caps = gst_caps_new_simple ("audio/mpeg",
829 "mpegversion", G_TYPE_INT, 1,
830 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
834 case CODEC_ID_MUSEPACK7:
836 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
837 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
841 case CODEC_ID_MUSEPACK8:
843 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
844 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
851 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
858 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
862 case CODEC_ID_TRUEHD:
864 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
865 "audio/x-true-hd", NULL);
868 case CODEC_ID_ATRAC1:
870 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
871 "audio/x-vnd.sony.atrac1", NULL);
874 case CODEC_ID_ATRAC3:
876 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
877 "audio/x-vnd.sony.atrac3", NULL);
882 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
888 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
889 "audio/x-ffmpeg-parsed-ape", NULL);
891 gst_caps_set_simple (caps,
892 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
898 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
904 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
908 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
909 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
910 * sp5x is, but it's apparently something JPEG... We don't separate
911 * between those in GStreamer. Should we (at least between MJPEG,
912 * MJPEG-B and sp5x decoding...)? */
916 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
922 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
926 case CODEC_ID_MJPEGB:
928 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
929 "video/x-mjpeg-b", NULL);
933 if (encode && context != NULL) {
934 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
935 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
936 switch (context->codec_tag) {
937 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
939 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
940 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
942 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
946 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
947 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
948 "mpegversion", G_TYPE_INT, 4, NULL);
952 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
954 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
955 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
958 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
959 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
961 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
962 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
964 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
965 encode, "video/x-xvid", NULL));
966 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
967 encode, "video/x-3ivx", NULL));
972 case CODEC_ID_RAWVIDEO:
974 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
977 case CODEC_ID_MSMPEG4V1:
978 case CODEC_ID_MSMPEG4V2:
979 case CODEC_ID_MSMPEG4V3:
981 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
983 /* encode-FIXME: bitrate */
985 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
986 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
987 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
988 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
989 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
997 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
1000 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1001 "wmvversion", G_TYPE_INT, version, NULL);
1007 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1008 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1013 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1014 "svqversion", G_TYPE_INT, 1, NULL);
1019 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1020 "svqversion", G_TYPE_INT, 3, NULL);
1023 case CODEC_ID_DVAUDIO:
1025 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1029 case CODEC_ID_DVVIDEO:
1031 if (encode && context) {
1032 const gchar *format;
1034 switch (context->pix_fmt) {
1035 case PIX_FMT_YUYV422:
1038 case PIX_FMT_YUV420P:
1041 case PIX_FMT_YUVA420P:
1044 case PIX_FMT_YUV411P:
1047 case PIX_FMT_YUV422P:
1050 case PIX_FMT_YUV410P:
1055 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1061 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1062 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1066 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1067 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1072 case CODEC_ID_WMAV1:
1073 case CODEC_ID_WMAV2:
1075 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
1079 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1080 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1081 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1085 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1086 "wmaversion", G_TYPE_INT, version, "block_align",
1087 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1092 case CODEC_ID_WMAPRO:
1095 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1096 "wmaversion", G_TYPE_INT, 3, NULL);
1100 case CODEC_ID_WMAVOICE:
1103 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1108 case CODEC_ID_MACE3:
1109 case CODEC_ID_MACE6:
1111 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
1114 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1115 "maceversion", G_TYPE_INT, version, NULL);
1119 case CODEC_ID_HUFFYUV:
1121 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1122 "video/x-huffyuv", NULL);
1124 gst_caps_set_simple (caps,
1125 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1131 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1132 "video/x-compressed-yuv", NULL);
1137 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1138 "alignment", G_TYPE_STRING, "au", NULL);
1141 case CODEC_ID_INDEO5:
1143 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1144 "indeoversion", G_TYPE_INT, 5, NULL);
1147 case CODEC_ID_INDEO4:
1149 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1150 "indeoversion", G_TYPE_INT, 4, NULL);
1153 case CODEC_ID_INDEO3:
1155 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1156 "indeoversion", G_TYPE_INT, 3, NULL);
1159 case CODEC_ID_INDEO2:
1161 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1162 "indeoversion", G_TYPE_INT, 2, NULL);
1165 case CODEC_ID_FLASHSV:
1167 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1168 "video/x-flash-screen", NULL);
1173 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1179 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1185 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1191 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1192 "video/x-vp6-flash", NULL);
1197 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1198 "video/x-vp6-alpha", NULL);
1203 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1207 case CODEC_ID_THEORA:
1209 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1210 "video/x-theora", NULL);
1216 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1220 GValue arr = { 0, };
1221 GValue item = { 0, };
1223 g_value_init (&arr, GST_TYPE_LIST);
1224 g_value_init (&item, G_TYPE_INT);
1225 g_value_set_int (&item, 2);
1226 gst_value_list_append_value (&arr, &item);
1227 g_value_set_int (&item, 4);
1228 gst_value_list_append_value (&arr, &item);
1229 g_value_unset (&item);
1231 gst_caps_set_value (caps, "mpegversion", &arr);
1232 g_value_unset (&arr);
1234 g_value_init (&arr, GST_TYPE_LIST);
1235 g_value_init (&item, G_TYPE_STRING);
1236 g_value_set_string (&item, "raw");
1237 gst_value_list_append_value (&arr, &item);
1238 g_value_set_string (&item, "adts");
1239 gst_value_list_append_value (&arr, &item);
1240 g_value_set_string (&item, "adif");
1241 gst_value_list_append_value (&arr, &item);
1242 g_value_unset (&item);
1244 gst_caps_set_value (caps, "stream-format", &arr);
1245 g_value_unset (&arr);
1247 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1248 "stream-format", G_TYPE_STRING, "raw",
1249 "base-profile", G_TYPE_STRING, "lc", NULL);
1251 if (context && context->extradata_size > 0)
1252 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1253 context->extradata, context->extradata_size);
1258 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1259 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1260 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1266 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1267 "asusversion", G_TYPE_INT, 1, NULL);
1271 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1272 "asusversion", G_TYPE_INT, 2, NULL);
1277 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1278 "ffvversion", G_TYPE_INT, 1, NULL);
1283 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1287 case CODEC_ID_XAN_WC3:
1288 case CODEC_ID_XAN_WC4:
1290 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1291 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1296 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1297 "video/x-cirrus-logic-accupak", NULL);
1300 case CODEC_ID_FRAPS:
1302 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1308 case CODEC_ID_INTERPLAY_VIDEO:
1314 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1315 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1320 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1321 "video/x-apple-video", NULL);
1324 case CODEC_ID_CINEPAK:
1326 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1327 "video/x-cinepak", NULL);
1330 /* WS_VQA belogns here (order) */
1332 case CODEC_ID_MSRLE:
1334 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1335 "layout", G_TYPE_STRING, "microsoft", NULL);
1337 gst_caps_set_simple (caps,
1338 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1340 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1344 case CODEC_ID_QTRLE:
1346 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1347 "layout", G_TYPE_STRING, "quicktime", NULL);
1349 gst_caps_set_simple (caps,
1350 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1352 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1356 case CODEC_ID_MSVIDEO1:
1358 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1359 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1364 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1365 "wmvversion", G_TYPE_INT, 3, NULL);
1369 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1370 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1374 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1380 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1386 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1390 case CODEC_ID_TRUEMOTION1:
1392 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1393 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1395 case CODEC_ID_TRUEMOTION2:
1397 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1398 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1403 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1404 "video/x-ultimotion", NULL);
1409 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1410 "video/x-camtasia", NULL);
1412 gst_caps_set_simple (caps,
1413 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1415 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1421 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1427 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1433 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1439 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1445 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1451 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1457 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1458 "image/x-portable-anymap", NULL);
1463 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1464 "image/x-portable-graymap", NULL);
1469 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1475 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1479 case CODEC_ID_TARGA:
1481 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1487 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1491 case CODEC_ID_SUNRAST:
1493 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1494 "image/x-sun-raster", NULL);
1499 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1503 case CODEC_ID_QDRAW:
1505 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1509 case CODEC_ID_DNXHD:
1511 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1515 case CODEC_ID_PRORES:
1517 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1518 "video/x-prores", NULL);
1521 case CODEC_ID_MIMIC:
1523 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1529 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1533 case CODEC_ID_TRUESPEECH:
1535 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1536 "audio/x-truespeech", NULL);
1539 case CODEC_ID_QCELP:
1541 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1547 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1553 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1559 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1565 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1569 case CODEC_ID_LAGARITH:
1571 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1572 "video/x-lagarith", NULL);
1577 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1578 "video/x-camstudio", NULL);
1580 gst_caps_set_simple (caps,
1581 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1583 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1587 case CODEC_ID_WS_VQA:
1588 case CODEC_ID_IDCIN:
1591 case CODEC_ID_VMDVIDEO:
1592 case CODEC_ID_VMDAUDIO:
1596 case CODEC_ID_PGMYUV:
1597 case CODEC_ID_FFVHUFF:
1599 case CODEC_ID_MP3ADU:
1600 case CODEC_ID_MP3ON4:
1601 case CODEC_ID_WESTWOOD_SND1:
1602 case CODEC_ID_MMVIDEO:
1608 /* weird quasi-codecs for the demuxers only */
1609 case CODEC_ID_PCM_S16LE:
1610 case CODEC_ID_PCM_S16BE:
1611 case CODEC_ID_PCM_U16LE:
1612 case CODEC_ID_PCM_U16BE:
1613 case CODEC_ID_PCM_S8:
1614 case CODEC_ID_PCM_U8:
1616 GstAudioFormat format;
1619 case CODEC_ID_PCM_S16LE:
1620 format = GST_AUDIO_FORMAT_S16LE;
1622 case CODEC_ID_PCM_S16BE:
1623 format = GST_AUDIO_FORMAT_S16BE;
1625 case CODEC_ID_PCM_U16LE:
1626 format = GST_AUDIO_FORMAT_U16LE;
1628 case CODEC_ID_PCM_U16BE:
1629 format = GST_AUDIO_FORMAT_U16BE;
1631 case CODEC_ID_PCM_S8:
1632 format = GST_AUDIO_FORMAT_S8;
1634 case CODEC_ID_PCM_U8:
1635 format = GST_AUDIO_FORMAT_U8;
1638 g_assert (0); /* don't worry, we never get here */
1643 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1644 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1645 "layout", G_TYPE_STRING, "interleaved", NULL);
1649 case CODEC_ID_PCM_MULAW:
1651 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1655 case CODEC_ID_PCM_ALAW:
1657 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1661 case CODEC_ID_ADPCM_G722:
1663 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1666 gst_caps_set_simple (caps,
1667 "block_align", G_TYPE_INT, context->block_align,
1668 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1671 case CODEC_ID_ADPCM_G726:
1673 /* the G726 decoder can also handle G721 */
1675 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1676 "layout", G_TYPE_STRING, "g726", NULL);
1678 gst_caps_set_simple (caps,
1679 "block_align", G_TYPE_INT, context->block_align,
1680 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1683 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1684 "layout", G_TYPE_STRING, "g721",
1685 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1689 case CODEC_ID_ADPCM_IMA_QT:
1690 case CODEC_ID_ADPCM_IMA_WAV:
1691 case CODEC_ID_ADPCM_IMA_DK3:
1692 case CODEC_ID_ADPCM_IMA_DK4:
1693 case CODEC_ID_ADPCM_IMA_WS:
1694 case CODEC_ID_ADPCM_IMA_SMJPEG:
1695 case CODEC_ID_ADPCM_IMA_AMV:
1696 case CODEC_ID_ADPCM_IMA_ISS:
1697 case CODEC_ID_ADPCM_IMA_EA_EACS:
1698 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1699 case CODEC_ID_ADPCM_MS:
1700 case CODEC_ID_ADPCM_4XM:
1701 case CODEC_ID_ADPCM_XA:
1702 case CODEC_ID_ADPCM_ADX:
1703 case CODEC_ID_ADPCM_EA:
1704 case CODEC_ID_ADPCM_CT:
1705 case CODEC_ID_ADPCM_SWF:
1706 case CODEC_ID_ADPCM_YAMAHA:
1707 case CODEC_ID_ADPCM_SBPRO_2:
1708 case CODEC_ID_ADPCM_SBPRO_3:
1709 case CODEC_ID_ADPCM_SBPRO_4:
1710 case CODEC_ID_ADPCM_EA_R1:
1711 case CODEC_ID_ADPCM_EA_R2:
1712 case CODEC_ID_ADPCM_EA_R3:
1713 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1714 case CODEC_ID_ADPCM_EA_XAS:
1715 case CODEC_ID_ADPCM_THP:
1717 const gchar *layout = NULL;
1720 case CODEC_ID_ADPCM_IMA_QT:
1721 layout = "quicktime";
1723 case CODEC_ID_ADPCM_IMA_WAV:
1726 case CODEC_ID_ADPCM_IMA_DK3:
1729 case CODEC_ID_ADPCM_IMA_DK4:
1732 case CODEC_ID_ADPCM_IMA_WS:
1733 layout = "westwood";
1735 case CODEC_ID_ADPCM_IMA_SMJPEG:
1738 case CODEC_ID_ADPCM_IMA_AMV:
1741 case CODEC_ID_ADPCM_IMA_ISS:
1744 case CODEC_ID_ADPCM_IMA_EA_EACS:
1747 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1750 case CODEC_ID_ADPCM_MS:
1751 layout = "microsoft";
1753 case CODEC_ID_ADPCM_4XM:
1756 case CODEC_ID_ADPCM_XA:
1759 case CODEC_ID_ADPCM_ADX:
1762 case CODEC_ID_ADPCM_EA:
1765 case CODEC_ID_ADPCM_CT:
1768 case CODEC_ID_ADPCM_SWF:
1771 case CODEC_ID_ADPCM_YAMAHA:
1774 case CODEC_ID_ADPCM_SBPRO_2:
1777 case CODEC_ID_ADPCM_SBPRO_3:
1780 case CODEC_ID_ADPCM_SBPRO_4:
1783 case CODEC_ID_ADPCM_EA_R1:
1786 case CODEC_ID_ADPCM_EA_R2:
1789 case CODEC_ID_ADPCM_EA_R3:
1792 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1793 layout = "ea-maxis-xa";
1795 case CODEC_ID_ADPCM_EA_XAS:
1798 case CODEC_ID_ADPCM_THP:
1802 g_assert (0); /* don't worry, we never get here */
1806 /* FIXME: someone please check whether we need additional properties
1807 * in this caps definition. */
1809 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1810 "layout", G_TYPE_STRING, layout, NULL);
1812 gst_caps_set_simple (caps,
1813 "block_align", G_TYPE_INT, context->block_align,
1814 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1818 case CODEC_ID_AMR_NB:
1820 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1824 case CODEC_ID_AMR_WB:
1826 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1832 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1836 case CODEC_ID_GSM_MS:
1838 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1842 case CODEC_ID_NELLYMOSER:
1844 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1845 "audio/x-nellymoser", NULL);
1851 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1854 gst_caps_set_simple (caps,
1855 "leaf_size", G_TYPE_INT, context->block_align,
1856 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1861 case CODEC_ID_RA_144:
1862 case CODEC_ID_RA_288:
1868 case CODEC_ID_RA_144:
1871 case CODEC_ID_RA_288:
1881 /* FIXME: properties? */
1883 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1884 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1886 gst_caps_set_simple (caps,
1887 "leaf_size", G_TYPE_INT, context->block_align,
1888 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1893 case CODEC_ID_ROQ_DPCM:
1894 case CODEC_ID_INTERPLAY_DPCM:
1895 case CODEC_ID_XAN_DPCM:
1896 case CODEC_ID_SOL_DPCM:
1898 const gchar *layout = NULL;
1901 case CODEC_ID_ROQ_DPCM:
1904 case CODEC_ID_INTERPLAY_DPCM:
1905 layout = "interplay";
1907 case CODEC_ID_XAN_DPCM:
1910 case CODEC_ID_SOL_DPCM:
1914 g_assert (0); /* don't worry, we never get here */
1918 /* FIXME: someone please check whether we need additional properties
1919 * in this caps definition. */
1921 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1922 "layout", G_TYPE_STRING, layout, NULL);
1924 gst_caps_set_simple (caps,
1925 "block_align", G_TYPE_INT, context->block_align,
1926 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1930 case CODEC_ID_SHORTEN:
1931 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1936 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1939 gst_caps_set_simple (caps,
1940 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1945 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1946 * encoder case, we want to add things like samplerate, channels... */
1948 caps = gst_caps_new_empty_simple ("audio/x-flac");
1952 case CODEC_ID_DVD_SUBTITLE:
1953 case CODEC_ID_DVB_SUBTITLE:
1957 caps = gst_caps_new_empty_simple ("image/bmp");
1961 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1964 gst_caps_set_simple (caps,
1965 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1968 case CODEC_ID_TWINVQ:
1970 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1971 "audio/x-twin-vq", NULL);
1974 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1981 if ((codec = avcodec_find_decoder (codec_id)) ||
1982 (codec = avcodec_find_encoder (codec_id))) {
1985 GST_LOG ("Could not create stream format caps for %s", codec->name);
1987 switch (codec->type) {
1988 case AVMEDIA_TYPE_VIDEO:
1989 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1991 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
1994 case AVMEDIA_TYPE_AUDIO:
1995 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1997 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
1999 gst_caps_set_simple (caps,
2000 "block_align", G_TYPE_INT, context->block_align,
2001 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2012 /* set private data */
2013 if (context && context->extradata_size > 0) {
2014 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2016 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2017 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2018 gst_buffer_unref (data);
2021 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2024 GST_LOG ("No caps found for codec_id=%d", codec_id);
2030 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2031 * to a GstCaps. If the context is ommitted, no fixed values
2032 * for video/audio size will be included in the GstCaps
2034 * See below for usefullness
2038 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2039 enum CodecID codec_id)
2041 GstCaps *caps = NULL;
2042 GstVideoFormat format;
2044 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2046 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2047 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2048 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2052 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2054 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2061 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2063 switch (sample_fmt) {
2064 case AV_SAMPLE_FMT_U8:
2065 case AV_SAMPLE_FMT_U8P:
2066 return GST_AUDIO_FORMAT_U8;
2068 case AV_SAMPLE_FMT_S16:
2069 case AV_SAMPLE_FMT_S16P:
2070 return GST_AUDIO_FORMAT_S16;
2072 case AV_SAMPLE_FMT_S32:
2073 case AV_SAMPLE_FMT_S32P:
2074 return GST_AUDIO_FORMAT_S32;
2076 case AV_SAMPLE_FMT_FLT:
2077 case AV_SAMPLE_FMT_FLTP:
2078 return GST_AUDIO_FORMAT_F32;
2080 case AV_SAMPLE_FMT_DBL:
2081 case AV_SAMPLE_FMT_DBLP:
2082 return GST_AUDIO_FORMAT_F64;
2086 return GST_AUDIO_FORMAT_UNKNOWN;
2091 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2092 * to a GstCaps. If the context is ommitted, no fixed values
2093 * for video/audio size will be included in the GstCaps
2095 * See below for usefullness
2099 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2100 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2102 GstCaps *caps = NULL;
2103 GstAudioFormat format;
2105 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2107 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2108 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2109 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2110 "layout", G_TYPE_STRING, "interleaved", NULL);
2111 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2113 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2120 caps_has_field (GstCaps * caps, const gchar * field)
2124 n = gst_caps_get_size (caps);
2125 for (i = 0; i < n; i++) {
2126 GstStructure *s = gst_caps_get_structure (caps, i);
2128 if (gst_structure_has_field (s, field))
2136 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2137 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2139 GstCaps *caps = NULL;
2141 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2142 context, codec_id, encode, codec);
2144 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2145 codec->sample_fmts, codec->supported_samplerates);
2148 /* Specific codec context */
2150 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2153 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2154 "layout", G_TYPE_STRING, "interleaved", NULL);
2155 if (!caps_has_field (caps, "format"))
2156 gst_ffmpeg_audio_set_sample_fmts (caps,
2157 codec ? codec->sample_fmts : NULL);
2164 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2165 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2169 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2170 context, codec_id, encode, codec);
2173 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2176 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2178 if (!caps_has_field (caps, "format"))
2179 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2184 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2185 * and other audio properties in a AVCodecContext.
2187 * For usefullness, see below
2191 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2192 AVCodecContext * context, gboolean raw)
2194 GstStructure *structure;
2196 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2198 g_return_if_fail (gst_caps_get_size (caps) == 1);
2200 structure = gst_caps_get_structure (caps, 0);
2202 gst_structure_get_int (structure, "channels", &context->channels);
2203 gst_structure_get_int (structure, "rate", &context->sample_rate);
2204 gst_structure_get_int (structure, "block_align", &context->block_align);
2205 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2210 if (gst_structure_has_name (structure, "audio/x-raw")) {
2211 if ((fmt = gst_structure_get_string (structure, "format"))) {
2212 format = gst_audio_format_from_string (fmt);
2217 case GST_AUDIO_FORMAT_F32:
2218 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2220 case GST_AUDIO_FORMAT_F64:
2221 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2223 case GST_AUDIO_FORMAT_S32:
2224 context->sample_fmt = AV_SAMPLE_FMT_S32;
2226 case GST_AUDIO_FORMAT_S16:
2227 context->sample_fmt = AV_SAMPLE_FMT_S16;
2234 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2235 * and other video properties in a AVCodecContext.
2237 * For usefullness, see below
2241 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2242 AVCodecContext * context, gboolean raw)
2244 GstStructure *structure;
2246 const GValue *par = NULL;
2248 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2250 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2251 g_return_if_fail (gst_caps_get_size (caps) == 1);
2252 structure = gst_caps_get_structure (caps, 0);
2254 gst_structure_get_int (structure, "width", &context->width);
2255 gst_structure_get_int (structure, "height", &context->height);
2256 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2258 fps = gst_structure_get_value (structure, "framerate");
2259 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2261 /* somehow these seem mixed up.. */
2262 context->time_base.den = gst_value_get_fraction_numerator (fps);
2263 context->time_base.num = gst_value_get_fraction_denominator (fps);
2264 context->ticks_per_frame = 1;
2266 GST_DEBUG ("setting framerate %d/%d = %lf",
2267 context->time_base.den, context->time_base.num,
2268 1. * context->time_base.den / context->time_base.num);
2271 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2272 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2274 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2275 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2277 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2278 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2279 1. * context->sample_aspect_ratio.den /
2280 context->sample_aspect_ratio.num);
2286 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2288 if (gst_structure_has_name (structure, "video/x-raw")) {
2289 if ((fmt = gst_structure_get_string (structure, "format"))) {
2290 format = gst_video_format_from_string (fmt);
2295 case GST_VIDEO_FORMAT_YUY2:
2296 context->pix_fmt = PIX_FMT_YUYV422;
2298 case GST_VIDEO_FORMAT_I420:
2299 context->pix_fmt = PIX_FMT_YUV420P;
2301 case GST_VIDEO_FORMAT_A420:
2302 context->pix_fmt = PIX_FMT_YUVA420P;
2304 case GST_VIDEO_FORMAT_Y41B:
2305 context->pix_fmt = PIX_FMT_YUV411P;
2307 case GST_VIDEO_FORMAT_Y42B:
2308 context->pix_fmt = PIX_FMT_YUV422P;
2310 case GST_VIDEO_FORMAT_YUV9:
2311 context->pix_fmt = PIX_FMT_YUV410P;
2313 case GST_VIDEO_FORMAT_Y444:
2314 context->pix_fmt = PIX_FMT_YUV444P;
2316 case GST_VIDEO_FORMAT_GRAY8:
2317 context->pix_fmt = PIX_FMT_GRAY8;
2319 case GST_VIDEO_FORMAT_xRGB:
2320 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2321 context->pix_fmt = PIX_FMT_RGB32;
2324 case GST_VIDEO_FORMAT_BGRx:
2325 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2326 context->pix_fmt = PIX_FMT_RGB32;
2329 case GST_VIDEO_FORMAT_RGB:
2330 context->pix_fmt = PIX_FMT_RGB24;
2332 case GST_VIDEO_FORMAT_BGR:
2333 context->pix_fmt = PIX_FMT_BGR24;
2335 case GST_VIDEO_FORMAT_RGB16:
2336 context->pix_fmt = PIX_FMT_RGB565;
2338 case GST_VIDEO_FORMAT_RGB15:
2339 context->pix_fmt = PIX_FMT_RGB555;
2341 case GST_VIDEO_FORMAT_RGB8P:
2342 context->pix_fmt = PIX_FMT_PAL8;
2351 GstVideoFormat format;
2352 enum PixelFormat pixfmt;
2355 /* FIXME : FILLME */
2356 static const PixToFmt pixtofmttable[] = {
2357 /* GST_VIDEO_FORMAT_I420, */
2358 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2359 /* Note : this should use a different chroma placement */
2360 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2362 /* GST_VIDEO_FORMAT_YV12, */
2363 /* GST_VIDEO_FORMAT_YUY2, */
2364 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2365 /* GST_VIDEO_FORMAT_UYVY, */
2366 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2367 /* GST_VIDEO_FORMAT_AYUV, */
2368 /* GST_VIDEO_FORMAT_RGBx, */
2369 /* GST_VIDEO_FORMAT_BGRx, */
2370 /* GST_VIDEO_FORMAT_xRGB, */
2371 /* GST_VIDEO_FORMAT_xBGR, */
2372 /* GST_VIDEO_FORMAT_RGBA, */
2373 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2374 /* GST_VIDEO_FORMAT_BGRA, */
2375 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2376 /* GST_VIDEO_FORMAT_ARGB, */
2377 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2378 /* GST_VIDEO_FORMAT_ABGR, */
2379 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2380 /* GST_VIDEO_FORMAT_RGB, */
2381 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2382 /* GST_VIDEO_FORMAT_BGR, */
2383 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2384 /* GST_VIDEO_FORMAT_Y41B, */
2385 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2386 /* GST_VIDEO_FORMAT_Y42B, */
2387 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2388 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2389 /* GST_VIDEO_FORMAT_YVYU, */
2390 /* GST_VIDEO_FORMAT_Y444, */
2391 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2392 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2393 /* GST_VIDEO_FORMAT_v210, */
2394 /* GST_VIDEO_FORMAT_v216, */
2395 /* GST_VIDEO_FORMAT_NV12, */
2396 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2397 /* GST_VIDEO_FORMAT_NV21, */
2398 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2399 /* GST_VIDEO_FORMAT_GRAY8, */
2400 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2401 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2402 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2403 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2404 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2405 /* GST_VIDEO_FORMAT_v308, */
2406 /* GST_VIDEO_FORMAT_Y800, */
2407 /* GST_VIDEO_FORMAT_Y16, */
2408 /* GST_VIDEO_FORMAT_RGB16, */
2409 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2410 /* GST_VIDEO_FORMAT_BGR16, */
2411 /* GST_VIDEO_FORMAT_RGB15, */
2412 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2413 /* GST_VIDEO_FORMAT_BGR15, */
2414 /* GST_VIDEO_FORMAT_UYVP, */
2415 /* GST_VIDEO_FORMAT_A420, */
2416 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2417 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2418 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2419 /* GST_VIDEO_FORMAT_YUV9, */
2420 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2421 /* GST_VIDEO_FORMAT_YVU9, */
2422 /* GST_VIDEO_FORMAT_IYU1, */
2423 /* GST_VIDEO_FORMAT_ARGB64, */
2424 /* GST_VIDEO_FORMAT_AYUV64, */
2425 /* GST_VIDEO_FORMAT_r210, */
2426 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2427 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2428 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2429 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2430 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2431 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2432 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2433 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2434 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2438 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2442 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2443 if (pixtofmttable[i].pixfmt == pixfmt)
2444 return pixtofmttable[i].format;
2446 GST_WARNING ("Unknown pixel format %d", pixfmt);
2447 return GST_VIDEO_FORMAT_UNKNOWN;
2451 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2455 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2456 if (pixtofmttable[i].format == format)
2457 return pixtofmttable[i].pixfmt;
2458 return PIX_FMT_NONE;
2462 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2466 context->width = GST_VIDEO_INFO_WIDTH (info);
2467 context->height = GST_VIDEO_INFO_HEIGHT (info);
2468 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2469 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2470 context->bits_per_coded_sample = bpp;
2472 context->ticks_per_frame = 1;
2473 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2474 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2476 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2477 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2480 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2484 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2486 const AVCodec *codec;
2487 const enum AVSampleFormat *smpl_fmts;
2488 enum AVSampleFormat smpl_fmt = -1;
2490 context->channels = info->channels;
2491 context->sample_rate = info->rate;
2492 context->channel_layout =
2493 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2495 codec = context->codec;
2497 smpl_fmts = codec->sample_fmts;
2499 switch (info->finfo->format) {
2500 case GST_AUDIO_FORMAT_F32:
2502 while (*smpl_fmts != -1) {
2503 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2504 smpl_fmt = *smpl_fmts;
2506 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2507 smpl_fmt = *smpl_fmts;
2513 smpl_fmt = AV_SAMPLE_FMT_FLT;
2516 case GST_AUDIO_FORMAT_F64:
2518 while (*smpl_fmts != -1) {
2519 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2520 smpl_fmt = *smpl_fmts;
2522 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2523 smpl_fmt = *smpl_fmts;
2529 smpl_fmt = AV_SAMPLE_FMT_DBL;
2532 case GST_AUDIO_FORMAT_S32:
2534 while (*smpl_fmts != -1) {
2535 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2536 smpl_fmt = *smpl_fmts;
2538 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2539 smpl_fmt = *smpl_fmts;
2545 smpl_fmt = AV_SAMPLE_FMT_S32;
2548 case GST_AUDIO_FORMAT_S16:
2550 while (*smpl_fmts != -1) {
2551 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2552 smpl_fmt = *smpl_fmts;
2554 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2555 smpl_fmt = *smpl_fmts;
2561 smpl_fmt = AV_SAMPLE_FMT_S16;
2564 case GST_AUDIO_FORMAT_U8:
2566 while (*smpl_fmts != -1) {
2567 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2568 smpl_fmt = *smpl_fmts;
2570 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2571 smpl_fmt = *smpl_fmts;
2577 smpl_fmt = AV_SAMPLE_FMT_U8;
2584 g_assert (smpl_fmt != -1);
2586 context->sample_fmt = smpl_fmt;
2589 /* Convert a GstCaps and a FFMPEG codec Type to a
2590 * AVCodecContext. If the context is ommitted, no fixed values
2591 * for video/audio size will be included in the context
2593 * AVMediaType is primarily meant for uncompressed data GstCaps!
2597 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2598 const GstCaps * caps, AVCodecContext * context)
2600 if (context == NULL)
2604 case AVMEDIA_TYPE_VIDEO:
2605 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2608 case AVMEDIA_TYPE_AUDIO:
2609 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2620 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2624 guint8 *end = src + size;
2627 while (srcp < end) {
2628 if (count == 2 && *srcp <= 0x03) {
2629 GST_DEBUG ("added escape code");
2638 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2641 *destsize = dstp - dst;
2644 /* copy the config, escaping NAL units as we iterate them, if something fails we
2645 * copy everything and hope for the best. */
2647 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2652 guint nalsize, esize;
2662 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2664 GST_DEBUG ("num SPS %d", cnt);
2666 memcpy (dstp, srcp, 6);
2670 for (i = 0; i < cnt; i++) {
2671 GST_DEBUG ("copy SPS %d", i);
2672 nalsize = (srcp[0] << 8) | srcp[1];
2673 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2674 dstp[0] = esize >> 8;
2675 dstp[1] = esize & 0xff;
2677 srcp += nalsize + 2;
2680 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2682 GST_DEBUG ("num PPS %d", cnt);
2684 for (i = 0; i < cnt; i++) {
2685 GST_DEBUG ("copy PPS %d", i);
2686 nalsize = (srcp[0] << 8) | srcp[1];
2687 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2688 dstp[0] = esize >> 8;
2689 dstp[1] = esize & 0xff;
2691 srcp += nalsize + 2;
2693 *destsize = dstp - dst;
2699 GST_DEBUG ("something unexpected, doing full copy");
2700 memcpy (dst, src, size);
2708 * caps_with_codecid () transforms a GstCaps for a known codec
2709 * ID into a filled-in context.
2710 * codec_data from caps will override possible extradata already in the context
2714 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2715 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2718 const GValue *value;
2721 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2722 codec_id, codec_type, caps, context);
2724 if (!context || !gst_caps_get_size (caps))
2727 str = gst_caps_get_structure (caps, 0);
2729 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2730 if ((value = gst_structure_get_value (str, "codec_data"))) {
2733 buf = gst_value_get_buffer (value);
2734 gst_buffer_map (buf, &map, GST_MAP_READ);
2736 /* free the old one if it is there */
2737 if (context->extradata)
2738 av_free (context->extradata);
2741 if (codec_id == CODEC_ID_H264) {
2744 GST_DEBUG ("copy, escaping codec_data %d", size);
2745 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2746 * reason for this but let's just escape it for now. Start by allocating
2747 * enough space, x2 is more than enough.
2749 * FIXME, we disabled escaping because some file already contain escaped
2750 * codec_data and then we escape twice and fail. It's better to leave it
2751 * as is, as that is what most players do. */
2752 context->extradata =
2753 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2754 FF_INPUT_BUFFER_PADDING_SIZE));
2755 copy_config (context->extradata, data, size, &extrasize);
2756 GST_DEBUG ("escaped size: %d", extrasize);
2757 context->extradata_size = extrasize;
2761 /* allocate with enough padding */
2762 GST_DEBUG ("copy codec_data");
2763 context->extradata =
2764 av_mallocz (GST_ROUND_UP_16 (map.size +
2765 FF_INPUT_BUFFER_PADDING_SIZE));
2766 memcpy (context->extradata, map.data, map.size);
2767 context->extradata_size = map.size;
2770 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2771 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2772 context->extradata[0] = (guint8) map.size;
2775 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2777 gst_buffer_unmap (buf, &map);
2778 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2779 codec_id != CODEC_ID_FLAC) {
2780 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2781 * extradata anyway which makes then segfault. */
2782 context->extradata =
2783 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2784 context->extradata_size = 0;
2785 GST_DEBUG ("no codec data");
2789 case CODEC_ID_MPEG4:
2791 const gchar *mime = gst_structure_get_name (str);
2793 if (!strcmp (mime, "video/x-divx"))
2794 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2795 else if (!strcmp (mime, "video/x-xvid"))
2796 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2797 else if (!strcmp (mime, "video/x-3ivx"))
2798 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2799 else if (!strcmp (mime, "video/mpeg"))
2800 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2805 /* FIXME: this is a workaround for older gst-plugins releases
2806 * (<= 0.8.9). This should be removed at some point, because
2807 * it causes wrong decoded frame order. */
2808 if (!context->extradata) {
2809 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2812 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2813 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2814 gst_structure_get_int (str, "low_delay", &low_delay) ||
2815 gst_structure_get_int (str, "unknown_svq3_flag",
2816 &unknown_svq3_flag)) {
2817 context->extradata = (guint8 *) av_mallocz (0x64);
2818 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2822 flags |= unknown_svq3_flag;
2824 flags |= halfpel_flag;
2826 flags |= thirdpel_flag;
2829 flags = GUINT16_FROM_LE (flags);
2831 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2832 context->extradata_size = 0x64;
2837 case CODEC_ID_MSRLE:
2838 case CODEC_ID_QTRLE:
2845 if (gst_structure_get_int (str, "depth", &depth)) {
2846 context->bits_per_coded_sample = depth;
2848 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2861 if (gst_structure_get_int (str, "format", &format))
2862 context->sub_id = format;
2867 case CODEC_ID_RA_288:
2868 case CODEC_ID_RA_144:
2874 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2875 context->block_align = leaf_size;
2876 if (gst_structure_get_int (str, "bitrate", &bitrate))
2877 context->bit_rate = bitrate;
2880 gst_structure_get_int (str, "samplesize",
2881 &context->bits_per_coded_sample);
2884 case CODEC_ID_DVVIDEO:
2886 const gchar *format;
2888 if ((format = gst_structure_get_string (str, "format"))) {
2890 if (g_str_equal (format, "YUY2"))
2891 context->pix_fmt = PIX_FMT_YUYV422;
2892 else if (g_str_equal (format, "I420"))
2893 context->pix_fmt = PIX_FMT_YUV420P;
2894 else if (g_str_equal (format, "A420"))
2895 context->pix_fmt = PIX_FMT_YUVA420P;
2896 else if (g_str_equal (format, "Y41B"))
2897 context->pix_fmt = PIX_FMT_YUV411P;
2898 else if (g_str_equal (format, "Y42B"))
2899 context->pix_fmt = PIX_FMT_YUV422P;
2900 else if (g_str_equal (format, "YUV9"))
2901 context->pix_fmt = PIX_FMT_YUV410P;
2903 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2907 GST_WARNING ("No specified format");
2910 case CODEC_ID_H263P:
2914 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2915 context->flags |= CODEC_FLAG_4MV;
2917 context->flags &= ~CODEC_FLAG_4MV;
2918 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2919 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2920 context->flags |= CODEC_FLAG_AC_PRED;
2922 context->flags &= ~CODEC_FLAG_AC_PRED;
2923 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2924 context->flags |= CODEC_FLAG_LOOP_FILTER;
2926 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2929 case CODEC_ID_ADPCM_G726:
2931 const gchar *layout;
2933 if ((layout = gst_structure_get_string (str, "layout"))) {
2934 if (!strcmp (layout, "g721")) {
2935 context->sample_rate = 8000;
2936 context->channels = 1;
2937 context->bit_rate = 32000;
2946 if (!gst_caps_is_fixed (caps))
2949 /* common properties (width, height, fps) */
2950 switch (codec_type) {
2951 case AVMEDIA_TYPE_VIDEO:
2952 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2954 case AVMEDIA_TYPE_AUDIO:
2955 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2961 /* fixup of default settings */
2963 case CODEC_ID_QCELP:
2964 /* QCELP is always mono, no matter what the caps say */
2965 context->channels = 1;
2967 case CODEC_ID_ADPCM_G726:
2968 if (context->sample_rate && context->bit_rate)
2969 context->bits_per_coded_sample =
2970 context->bit_rate / context->sample_rate;
2977 /* _formatid_to_caps () is meant for muxers/demuxers, it
2978 * transforms a name (ffmpeg way of ID'ing these, why don't
2979 * they have unique numerical IDs?) to the corresponding
2980 * caps belonging to that mux-format
2982 * Note: we don't need any additional info because the caps
2983 * isn't supposed to contain any useful info besides the
2988 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2990 GstCaps *caps = NULL;
2992 if (!strcmp (format_name, "mpeg")) {
2993 caps = gst_caps_new_simple ("video/mpeg",
2994 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2995 } else if (!strcmp (format_name, "mpegts")) {
2996 caps = gst_caps_new_simple ("video/mpegts",
2997 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2998 } else if (!strcmp (format_name, "rm")) {
2999 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3000 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3001 } else if (!strcmp (format_name, "asf")) {
3002 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3003 } else if (!strcmp (format_name, "avi")) {
3004 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3005 } else if (!strcmp (format_name, "wav")) {
3006 caps = gst_caps_new_empty_simple ("audio/x-wav");
3007 } else if (!strcmp (format_name, "ape")) {
3008 caps = gst_caps_new_empty_simple ("application/x-ape");
3009 } else if (!strcmp (format_name, "swf")) {
3010 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3011 } else if (!strcmp (format_name, "au")) {
3012 caps = gst_caps_new_empty_simple ("audio/x-au");
3013 } else if (!strcmp (format_name, "dv")) {
3014 caps = gst_caps_new_simple ("video/x-dv",
3015 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3016 } else if (!strcmp (format_name, "4xm")) {
3017 caps = gst_caps_new_empty_simple ("video/x-4xm");
3018 } else if (!strcmp (format_name, "matroska")) {
3019 caps = gst_caps_new_empty_simple ("video/x-matroska");
3020 } else if (!strcmp (format_name, "mp3")) {
3021 caps = gst_caps_new_empty_simple ("application/x-id3");
3022 } else if (!strcmp (format_name, "flic")) {
3023 caps = gst_caps_new_empty_simple ("video/x-fli");
3024 } else if (!strcmp (format_name, "flv")) {
3025 caps = gst_caps_new_empty_simple ("video/x-flv");
3026 } else if (!strcmp (format_name, "tta")) {
3027 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3028 } else if (!strcmp (format_name, "aiff")) {
3029 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3030 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3032 gst_caps_from_string
3033 ("application/x-3gp; video/quicktime; audio/x-m4a");
3034 } else if (!strcmp (format_name, "mov")) {
3035 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3036 } else if (!strcmp (format_name, "mp4")) {
3037 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3038 } else if (!strcmp (format_name, "3gp")) {
3039 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3040 } else if (!strcmp (format_name, "3g2")) {
3041 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3042 } else if (!strcmp (format_name, "psp")) {
3043 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3044 } else if (!strcmp (format_name, "ipod")) {
3045 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3046 } else if (!strcmp (format_name, "aac")) {
3047 caps = gst_caps_new_simple ("audio/mpeg",
3048 "mpegversion", G_TYPE_INT, 4, NULL);
3049 } else if (!strcmp (format_name, "gif")) {
3050 caps = gst_caps_from_string ("image/gif");
3051 } else if (!strcmp (format_name, "ogg")) {
3052 caps = gst_caps_from_string ("application/ogg");
3053 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3054 caps = gst_caps_from_string ("application/mxf");
3055 } else if (!strcmp (format_name, "gxf")) {
3056 caps = gst_caps_from_string ("application/gxf");
3057 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3058 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3059 "y4mversion", G_TYPE_INT, 2, NULL);
3060 } else if (!strcmp (format_name, "mpc")) {
3061 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3062 } else if (!strcmp (format_name, "vqf")) {
3063 caps = gst_caps_from_string ("audio/x-vqf");
3064 } else if (!strcmp (format_name, "nsv")) {
3065 caps = gst_caps_from_string ("video/x-nsv");
3066 } else if (!strcmp (format_name, "amr")) {
3067 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3068 } else if (!strcmp (format_name, "webm")) {
3069 caps = gst_caps_from_string ("video/webm");
3070 } else if (!strcmp (format_name, "voc")) {
3071 caps = gst_caps_from_string ("audio/x-voc");
3075 GST_LOG ("Could not create stream format caps for %s", format_name);
3076 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3077 caps = gst_caps_new_empty_simple (name);
3085 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3086 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3087 AVOutputFormat * plugin)
3089 static enum CodecID tmp_vlist[] = {
3093 static enum CodecID tmp_alist[] = {
3098 GST_LOG ("format_name : %s", format_name);
3100 if (!strcmp (format_name, "mp4")) {
3101 static enum CodecID mp4_video_list[] = {
3102 CODEC_ID_MPEG4, CODEC_ID_H264,
3106 static enum CodecID mp4_audio_list[] = {
3107 CODEC_ID_AAC, CODEC_ID_MP3,
3111 *video_codec_list = mp4_video_list;
3112 *audio_codec_list = mp4_audio_list;
3113 } else if (!strcmp (format_name, "mpeg")) {
3114 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
3115 CODEC_ID_MPEG2VIDEO,
3119 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
3125 *video_codec_list = mpeg_video_list;
3126 *audio_codec_list = mpeg_audio_list;
3127 } else if (!strcmp (format_name, "dvd")) {
3128 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
3131 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
3138 *video_codec_list = mpeg_video_list;
3139 *audio_codec_list = mpeg_audio_list;
3140 } else if (!strcmp (format_name, "mpegts")) {
3141 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
3142 CODEC_ID_MPEG2VIDEO,
3146 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
3154 *video_codec_list = mpegts_video_list;
3155 *audio_codec_list = mpegts_audio_list;
3156 } else if (!strcmp (format_name, "vob")) {
3157 static enum CodecID vob_video_list[] =
3158 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
3159 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
3160 CODEC_ID_DTS, CODEC_ID_NONE
3163 *video_codec_list = vob_video_list;
3164 *audio_codec_list = vob_audio_list;
3165 } else if (!strcmp (format_name, "flv")) {
3166 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
3167 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
3169 *video_codec_list = flv_video_list;
3170 *audio_codec_list = flv_audio_list;
3171 } else if (!strcmp (format_name, "asf")) {
3172 static enum CodecID asf_video_list[] =
3173 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
3174 static enum CodecID asf_audio_list[] =
3175 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
3177 *video_codec_list = asf_video_list;
3178 *audio_codec_list = asf_audio_list;
3179 } else if (!strcmp (format_name, "dv")) {
3180 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
3181 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
3183 *video_codec_list = dv_video_list;
3184 *audio_codec_list = dv_audio_list;
3185 } else if (!strcmp (format_name, "mov")) {
3186 static enum CodecID mov_video_list[] = {
3187 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
3188 CODEC_ID_H263, CODEC_ID_H263P,
3189 CODEC_ID_H264, CODEC_ID_DVVIDEO,
3193 static enum CodecID mov_audio_list[] = {
3194 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
3195 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
3196 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3197 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
3198 CODEC_ID_MP3, CODEC_ID_NONE
3201 *video_codec_list = mov_video_list;
3202 *audio_codec_list = mov_audio_list;
3203 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3204 static enum CodecID tgp_video_list[] = {
3205 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
3208 static enum CodecID tgp_audio_list[] = {
3209 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3214 *video_codec_list = tgp_video_list;
3215 *audio_codec_list = tgp_audio_list;
3216 } else if (!strcmp (format_name, "mmf")) {
3217 static enum CodecID mmf_audio_list[] = {
3218 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
3220 *video_codec_list = NULL;
3221 *audio_codec_list = mmf_audio_list;
3222 } else if (!strcmp (format_name, "amr")) {
3223 static enum CodecID amr_audio_list[] = {
3224 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3227 *video_codec_list = NULL;
3228 *audio_codec_list = amr_audio_list;
3229 } else if (!strcmp (format_name, "gif")) {
3230 static enum CodecID gif_image_list[] = {
3231 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
3233 *video_codec_list = gif_image_list;
3234 *audio_codec_list = NULL;
3235 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
3236 (plugin->video_codec != CODEC_ID_NONE)) {
3237 tmp_vlist[0] = plugin->video_codec;
3238 tmp_alist[0] = plugin->audio_codec;
3240 *video_codec_list = tmp_vlist;
3241 *audio_codec_list = tmp_alist;
3243 GST_LOG ("Format %s not found", format_name);
3250 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3251 * are omitted, that can be queried by the user itself,
3252 * we're not eating the GstCaps or anything
3253 * A pointer to an allocated context is also needed for
3254 * optional extra info
3258 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3260 enum CodecID id = CODEC_ID_NONE;
3261 const gchar *mimetype;
3262 const GstStructure *structure;
3263 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3265 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3266 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3267 structure = gst_caps_get_structure (caps, 0);
3269 mimetype = gst_structure_get_name (structure);
3271 if (!strcmp (mimetype, "video/x-raw")) {
3272 id = CODEC_ID_RAWVIDEO;
3274 } else if (!strcmp (mimetype, "audio/x-raw")) {
3277 if (gst_audio_info_from_caps (&info, caps)) {
3278 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3279 case GST_AUDIO_FORMAT_S8:
3280 id = CODEC_ID_PCM_S8;
3282 case GST_AUDIO_FORMAT_U8:
3283 id = CODEC_ID_PCM_U8;
3285 case GST_AUDIO_FORMAT_S16LE:
3286 id = CODEC_ID_PCM_S16LE;
3288 case GST_AUDIO_FORMAT_S16BE:
3289 id = CODEC_ID_PCM_S16BE;
3291 case GST_AUDIO_FORMAT_U16LE:
3292 id = CODEC_ID_PCM_U16LE;
3294 case GST_AUDIO_FORMAT_U16BE:
3295 id = CODEC_ID_PCM_U16BE;
3300 if (id != CODEC_ID_NONE)
3303 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3304 id = CODEC_ID_PCM_MULAW;
3306 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3307 id = CODEC_ID_PCM_ALAW;
3309 } else if (!strcmp (mimetype, "video/x-dv")) {
3312 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3314 id = CODEC_ID_DVVIDEO;
3317 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3318 id = CODEC_ID_DVAUDIO;
3320 } else if (!strcmp (mimetype, "video/x-h263")) {
3321 const gchar *h263version =
3322 gst_structure_get_string (structure, "h263version");
3323 if (h263version && !strcmp (h263version, "h263p"))
3324 id = CODEC_ID_H263P;
3328 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3329 id = CODEC_ID_H263I;
3331 } else if (!strcmp (mimetype, "video/x-h261")) {
3334 } else if (!strcmp (mimetype, "video/mpeg")) {
3338 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3339 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3341 switch (mpegversion) {
3343 id = CODEC_ID_MPEG1VIDEO;
3346 id = CODEC_ID_MPEG2VIDEO;
3349 id = CODEC_ID_MPEG4;
3353 if (id != CODEC_ID_NONE)
3355 } else if (!strcmp (mimetype, "image/jpeg")) {
3356 id = CODEC_ID_MJPEG; /* A... B... */
3358 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3359 id = CODEC_ID_MJPEGB;
3361 } else if (!strcmp (mimetype, "video/x-wmv")) {
3362 gint wmvversion = 0;
3364 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3365 switch (wmvversion) {
3374 const gchar *format;
3376 /* WMV3 unless the fourcc exists and says otherwise */
3379 if ((format = gst_structure_get_string (structure, "format")) &&
3380 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3387 if (id != CODEC_ID_NONE)
3389 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3390 id = CODEC_ID_VORBIS;
3392 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3395 } else if (!strcmp (mimetype, "audio/mpeg")) {
3397 gint mpegversion = 0;
3399 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3400 switch (mpegversion) {
3401 case 2: /* ffmpeg uses faad for both... */
3406 if (gst_structure_get_int (structure, "layer", &layer)) {
3421 if (id != CODEC_ID_NONE)
3423 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3424 gint streamversion = -1;
3426 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3427 if (streamversion == 7)
3428 id = CODEC_ID_MUSEPACK7;
3430 id = CODEC_ID_MUSEPACK7;
3432 } else if (!strcmp (mimetype, "audio/x-wma")) {
3433 gint wmaversion = 0;
3435 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3436 switch (wmaversion) {
3438 id = CODEC_ID_WMAV1;
3441 id = CODEC_ID_WMAV2;
3444 id = CODEC_ID_WMAPRO;
3448 if (id != CODEC_ID_NONE)
3450 } else if (!strcmp (mimetype, "audio/x-wms")) {
3451 id = CODEC_ID_WMAVOICE;
3453 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3456 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3459 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3460 !strcmp (mimetype, "audio/atrac3")) {
3461 id = CODEC_ID_ATRAC3;
3463 } else if (!strcmp (mimetype, "audio/x-dts")) {
3466 } else if (!strcmp (mimetype, "application/x-ape")) {
3469 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3470 gint msmpegversion = 0;
3472 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3473 switch (msmpegversion) {
3475 id = CODEC_ID_MSMPEG4V1;
3478 id = CODEC_ID_MSMPEG4V2;
3481 id = CODEC_ID_MSMPEG4V3;
3485 if (id != CODEC_ID_NONE)
3487 } else if (!strcmp (mimetype, "video/x-svq")) {
3488 gint svqversion = 0;
3490 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3491 switch (svqversion) {
3500 if (id != CODEC_ID_NONE)
3502 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3503 id = CODEC_ID_HUFFYUV;
3505 } else if (!strcmp (mimetype, "audio/x-mace")) {
3506 gint maceversion = 0;
3508 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3509 switch (maceversion) {
3511 id = CODEC_ID_MACE3;
3514 id = CODEC_ID_MACE6;
3518 if (id != CODEC_ID_NONE)
3520 } else if (!strcmp (mimetype, "video/x-theora")) {
3521 id = CODEC_ID_THEORA;
3523 } else if (!strcmp (mimetype, "video/x-vp3")) {
3526 } else if (!strcmp (mimetype, "video/x-vp5")) {
3529 } else if (!strcmp (mimetype, "video/x-vp6")) {
3532 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3535 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3538 } else if (!strcmp (mimetype, "video/x-vp8")) {
3541 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3542 id = CODEC_ID_FLASHSV;
3544 } else if (!strcmp (mimetype, "video/x-indeo")) {
3545 gint indeoversion = 0;
3547 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3548 switch (indeoversion) {
3550 id = CODEC_ID_INDEO5;
3553 id = CODEC_ID_INDEO4;
3556 id = CODEC_ID_INDEO3;
3559 id = CODEC_ID_INDEO2;
3562 if (id != CODEC_ID_NONE)
3565 } else if (!strcmp (mimetype, "video/x-divx")) {
3566 gint divxversion = 0;
3568 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3569 switch (divxversion) {
3571 id = CODEC_ID_MSMPEG4V3;
3575 id = CODEC_ID_MPEG4;
3579 if (id != CODEC_ID_NONE)
3581 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3582 id = CODEC_ID_MPEG4;
3584 } else if (!strcmp (mimetype, "video/x-xvid")) {
3585 id = CODEC_ID_MPEG4;
3587 } else if (!strcmp (mimetype, "video/x-ffv")) {
3588 gint ffvversion = 0;
3590 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3595 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3596 const gchar *layout;
3598 layout = gst_structure_get_string (structure, "layout");
3599 if (layout == NULL) {
3601 } else if (!strcmp (layout, "quicktime")) {
3602 id = CODEC_ID_ADPCM_IMA_QT;
3603 } else if (!strcmp (layout, "microsoft")) {
3604 id = CODEC_ID_ADPCM_MS;
3605 } else if (!strcmp (layout, "dvi")) {
3606 id = CODEC_ID_ADPCM_IMA_WAV;
3607 } else if (!strcmp (layout, "4xm")) {
3608 id = CODEC_ID_ADPCM_4XM;
3609 } else if (!strcmp (layout, "smjpeg")) {
3610 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3611 } else if (!strcmp (layout, "dk3")) {
3612 id = CODEC_ID_ADPCM_IMA_DK3;
3613 } else if (!strcmp (layout, "dk4")) {
3614 id = CODEC_ID_ADPCM_IMA_DK4;
3615 } else if (!strcmp (layout, "westwood")) {
3616 id = CODEC_ID_ADPCM_IMA_WS;
3617 } else if (!strcmp (layout, "iss")) {
3618 id = CODEC_ID_ADPCM_IMA_ISS;
3619 } else if (!strcmp (layout, "xa")) {
3620 id = CODEC_ID_ADPCM_XA;
3621 } else if (!strcmp (layout, "adx")) {
3622 id = CODEC_ID_ADPCM_ADX;
3623 } else if (!strcmp (layout, "ea")) {
3624 id = CODEC_ID_ADPCM_EA;
3625 } else if (!strcmp (layout, "g726")) {
3626 id = CODEC_ID_ADPCM_G726;
3627 } else if (!strcmp (layout, "g721")) {
3628 id = CODEC_ID_ADPCM_G726;
3629 } else if (!strcmp (layout, "ct")) {
3630 id = CODEC_ID_ADPCM_CT;
3631 } else if (!strcmp (layout, "swf")) {
3632 id = CODEC_ID_ADPCM_SWF;
3633 } else if (!strcmp (layout, "yamaha")) {
3634 id = CODEC_ID_ADPCM_YAMAHA;
3635 } else if (!strcmp (layout, "sbpro2")) {
3636 id = CODEC_ID_ADPCM_SBPRO_2;
3637 } else if (!strcmp (layout, "sbpro3")) {
3638 id = CODEC_ID_ADPCM_SBPRO_3;
3639 } else if (!strcmp (layout, "sbpro4")) {
3640 id = CODEC_ID_ADPCM_SBPRO_4;
3642 if (id != CODEC_ID_NONE)
3644 } else if (!strcmp (mimetype, "video/x-4xm")) {
3647 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3648 const gchar *layout;
3650 layout = gst_structure_get_string (structure, "layout");
3653 } else if (!strcmp (layout, "roq")) {
3654 id = CODEC_ID_ROQ_DPCM;
3655 } else if (!strcmp (layout, "interplay")) {
3656 id = CODEC_ID_INTERPLAY_DPCM;
3657 } else if (!strcmp (layout, "xan")) {
3658 id = CODEC_ID_XAN_DPCM;
3659 } else if (!strcmp (layout, "sol")) {
3660 id = CODEC_ID_SOL_DPCM;
3662 if (id != CODEC_ID_NONE)
3664 } else if (!strcmp (mimetype, "audio/x-flac")) {
3667 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3668 id = CODEC_ID_SHORTEN;
3670 } else if (!strcmp (mimetype, "audio/x-alac")) {
3673 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3674 id = CODEC_ID_CINEPAK;
3676 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3679 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3680 switch (rmversion) {
3695 if (id != CODEC_ID_NONE)
3697 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3700 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3703 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3704 switch (raversion) {
3706 id = CODEC_ID_RA_144;
3709 id = CODEC_ID_RA_288;
3716 if (id != CODEC_ID_NONE)
3718 } else if (!strcmp (mimetype, "video/x-rle")) {
3719 const gchar *layout;
3721 if ((layout = gst_structure_get_string (structure, "layout"))) {
3722 if (!strcmp (layout, "microsoft")) {
3723 id = CODEC_ID_MSRLE;
3727 } else if (!strcmp (mimetype, "video/x-xan")) {
3730 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3731 switch (wcversion) {
3733 id = CODEC_ID_XAN_WC3;
3737 id = CODEC_ID_XAN_WC4;
3744 } else if (!strcmp (mimetype, "audio/AMR")) {
3746 id = CODEC_ID_AMR_NB;
3747 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3748 id = CODEC_ID_AMR_WB;
3750 } else if (!strcmp (mimetype, "audio/qcelp")) {
3751 id = CODEC_ID_QCELP;
3753 } else if (!strcmp (mimetype, "video/x-h264")) {
3756 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3757 gint flvversion = 0;
3759 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3760 switch (flvversion) {
3770 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3771 id = CODEC_ID_NELLYMOSER;
3773 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3777 if (strlen (mimetype) <= 30 &&
3778 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3779 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3780 (codec = avcodec_find_encoder_by_name (ext))) {
3785 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3789 if (strlen (mimetype) <= 30 &&
3790 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3791 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3792 (codec = avcodec_find_encoder_by_name (ext))) {
3799 if (context != NULL) {
3800 if (video == TRUE) {
3801 context->codec_type = AVMEDIA_TYPE_VIDEO;
3802 } else if (audio == TRUE) {
3803 context->codec_type = AVMEDIA_TYPE_AUDIO;
3805 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3807 context->codec_id = id;
3808 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3811 if (id != CODEC_ID_NONE) {
3812 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3814 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);