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, "format", G_TYPE_STRING, "WMV3", 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_S302M:
1953 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
1956 case CODEC_ID_DVD_SUBTITLE:
1957 case CODEC_ID_DVB_SUBTITLE:
1961 caps = gst_caps_new_empty_simple ("image/bmp");
1965 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1968 gst_caps_set_simple (caps,
1969 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1972 case CODEC_ID_TWINVQ:
1974 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1975 "audio/x-twin-vq", NULL);
1978 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1985 if ((codec = avcodec_find_decoder (codec_id)) ||
1986 (codec = avcodec_find_encoder (codec_id))) {
1989 GST_LOG ("Could not create stream format caps for %s", codec->name);
1991 switch (codec->type) {
1992 case AVMEDIA_TYPE_VIDEO:
1993 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1995 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
1998 case AVMEDIA_TYPE_AUDIO:
1999 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2001 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2003 gst_caps_set_simple (caps,
2004 "block_align", G_TYPE_INT, context->block_align,
2005 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2016 /* set private data */
2017 if (context && context->extradata_size > 0) {
2018 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2020 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2021 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2022 gst_buffer_unref (data);
2025 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2028 GST_LOG ("No caps found for codec_id=%d", codec_id);
2034 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2035 * to a GstCaps. If the context is ommitted, no fixed values
2036 * for video/audio size will be included in the GstCaps
2038 * See below for usefullness
2042 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2043 enum CodecID codec_id)
2045 GstCaps *caps = NULL;
2046 GstVideoFormat format;
2048 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2050 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2051 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2052 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2056 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2058 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2065 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2067 switch (sample_fmt) {
2068 case AV_SAMPLE_FMT_U8:
2069 case AV_SAMPLE_FMT_U8P:
2070 return GST_AUDIO_FORMAT_U8;
2072 case AV_SAMPLE_FMT_S16:
2073 case AV_SAMPLE_FMT_S16P:
2074 return GST_AUDIO_FORMAT_S16;
2076 case AV_SAMPLE_FMT_S32:
2077 case AV_SAMPLE_FMT_S32P:
2078 return GST_AUDIO_FORMAT_S32;
2080 case AV_SAMPLE_FMT_FLT:
2081 case AV_SAMPLE_FMT_FLTP:
2082 return GST_AUDIO_FORMAT_F32;
2084 case AV_SAMPLE_FMT_DBL:
2085 case AV_SAMPLE_FMT_DBLP:
2086 return GST_AUDIO_FORMAT_F64;
2090 return GST_AUDIO_FORMAT_UNKNOWN;
2095 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2096 * to a GstCaps. If the context is ommitted, no fixed values
2097 * for video/audio size will be included in the GstCaps
2099 * See below for usefullness
2103 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2104 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2106 GstCaps *caps = NULL;
2107 GstAudioFormat format;
2109 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2111 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2112 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2113 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2114 "layout", G_TYPE_STRING, "interleaved", NULL);
2115 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2117 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2124 caps_has_field (GstCaps * caps, const gchar * field)
2128 n = gst_caps_get_size (caps);
2129 for (i = 0; i < n; i++) {
2130 GstStructure *s = gst_caps_get_structure (caps, i);
2132 if (gst_structure_has_field (s, field))
2140 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2141 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2143 GstCaps *caps = NULL;
2145 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2146 context, codec_id, encode, codec);
2148 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2149 codec->sample_fmts, codec->supported_samplerates);
2152 /* Specific codec context */
2154 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2157 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2158 "layout", G_TYPE_STRING, "interleaved", NULL);
2159 if (!caps_has_field (caps, "format"))
2160 gst_ffmpeg_audio_set_sample_fmts (caps,
2161 codec ? codec->sample_fmts : NULL);
2168 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2169 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2173 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2174 context, codec_id, encode, codec);
2177 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2180 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2182 if (!caps_has_field (caps, "format"))
2183 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2188 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2189 * and other audio properties in a AVCodecContext.
2191 * For usefullness, see below
2195 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2196 AVCodecContext * context, gboolean raw)
2198 GstStructure *structure;
2200 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2202 g_return_if_fail (gst_caps_get_size (caps) == 1);
2204 structure = gst_caps_get_structure (caps, 0);
2206 gst_structure_get_int (structure, "channels", &context->channels);
2207 gst_structure_get_int (structure, "rate", &context->sample_rate);
2208 gst_structure_get_int (structure, "block_align", &context->block_align);
2209 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2214 if (gst_structure_has_name (structure, "audio/x-raw")) {
2215 if ((fmt = gst_structure_get_string (structure, "format"))) {
2216 format = gst_audio_format_from_string (fmt);
2221 case GST_AUDIO_FORMAT_F32:
2222 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2224 case GST_AUDIO_FORMAT_F64:
2225 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2227 case GST_AUDIO_FORMAT_S32:
2228 context->sample_fmt = AV_SAMPLE_FMT_S32;
2230 case GST_AUDIO_FORMAT_S16:
2231 context->sample_fmt = AV_SAMPLE_FMT_S16;
2238 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2239 * and other video properties in a AVCodecContext.
2241 * For usefullness, see below
2245 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2246 AVCodecContext * context, gboolean raw)
2248 GstStructure *structure;
2250 const GValue *par = NULL;
2252 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2254 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2255 g_return_if_fail (gst_caps_get_size (caps) == 1);
2256 structure = gst_caps_get_structure (caps, 0);
2258 gst_structure_get_int (structure, "width", &context->width);
2259 gst_structure_get_int (structure, "height", &context->height);
2260 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2262 fps = gst_structure_get_value (structure, "framerate");
2263 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2265 /* somehow these seem mixed up.. */
2266 context->time_base.den = gst_value_get_fraction_numerator (fps);
2267 context->time_base.num = gst_value_get_fraction_denominator (fps);
2268 context->ticks_per_frame = 1;
2270 GST_DEBUG ("setting framerate %d/%d = %lf",
2271 context->time_base.den, context->time_base.num,
2272 1. * context->time_base.den / context->time_base.num);
2275 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2276 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2278 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2279 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2281 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2282 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2283 1. * context->sample_aspect_ratio.den /
2284 context->sample_aspect_ratio.num);
2290 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2292 if (gst_structure_has_name (structure, "video/x-raw")) {
2293 if ((fmt = gst_structure_get_string (structure, "format"))) {
2294 format = gst_video_format_from_string (fmt);
2299 case GST_VIDEO_FORMAT_YUY2:
2300 context->pix_fmt = PIX_FMT_YUYV422;
2302 case GST_VIDEO_FORMAT_I420:
2303 context->pix_fmt = PIX_FMT_YUV420P;
2305 case GST_VIDEO_FORMAT_A420:
2306 context->pix_fmt = PIX_FMT_YUVA420P;
2308 case GST_VIDEO_FORMAT_Y41B:
2309 context->pix_fmt = PIX_FMT_YUV411P;
2311 case GST_VIDEO_FORMAT_Y42B:
2312 context->pix_fmt = PIX_FMT_YUV422P;
2314 case GST_VIDEO_FORMAT_YUV9:
2315 context->pix_fmt = PIX_FMT_YUV410P;
2317 case GST_VIDEO_FORMAT_Y444:
2318 context->pix_fmt = PIX_FMT_YUV444P;
2320 case GST_VIDEO_FORMAT_GRAY8:
2321 context->pix_fmt = PIX_FMT_GRAY8;
2323 case GST_VIDEO_FORMAT_xRGB:
2324 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2325 context->pix_fmt = PIX_FMT_RGB32;
2328 case GST_VIDEO_FORMAT_BGRx:
2329 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2330 context->pix_fmt = PIX_FMT_RGB32;
2333 case GST_VIDEO_FORMAT_RGB:
2334 context->pix_fmt = PIX_FMT_RGB24;
2336 case GST_VIDEO_FORMAT_BGR:
2337 context->pix_fmt = PIX_FMT_BGR24;
2339 case GST_VIDEO_FORMAT_RGB16:
2340 context->pix_fmt = PIX_FMT_RGB565;
2342 case GST_VIDEO_FORMAT_RGB15:
2343 context->pix_fmt = PIX_FMT_RGB555;
2345 case GST_VIDEO_FORMAT_RGB8P:
2346 context->pix_fmt = PIX_FMT_PAL8;
2355 GstVideoFormat format;
2356 enum PixelFormat pixfmt;
2359 /* FIXME : FILLME */
2360 static const PixToFmt pixtofmttable[] = {
2361 /* GST_VIDEO_FORMAT_I420, */
2362 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2363 /* Note : this should use a different chroma placement */
2364 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2366 /* GST_VIDEO_FORMAT_YV12, */
2367 /* GST_VIDEO_FORMAT_YUY2, */
2368 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2369 /* GST_VIDEO_FORMAT_UYVY, */
2370 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2371 /* GST_VIDEO_FORMAT_AYUV, */
2372 /* GST_VIDEO_FORMAT_RGBx, */
2373 /* GST_VIDEO_FORMAT_BGRx, */
2374 /* GST_VIDEO_FORMAT_xRGB, */
2375 /* GST_VIDEO_FORMAT_xBGR, */
2376 /* GST_VIDEO_FORMAT_RGBA, */
2377 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2378 /* GST_VIDEO_FORMAT_BGRA, */
2379 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2380 /* GST_VIDEO_FORMAT_ARGB, */
2381 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2382 /* GST_VIDEO_FORMAT_ABGR, */
2383 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2384 /* GST_VIDEO_FORMAT_RGB, */
2385 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2386 /* GST_VIDEO_FORMAT_BGR, */
2387 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2388 /* GST_VIDEO_FORMAT_Y41B, */
2389 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2390 /* GST_VIDEO_FORMAT_Y42B, */
2391 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2392 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2393 /* GST_VIDEO_FORMAT_YVYU, */
2394 /* GST_VIDEO_FORMAT_Y444, */
2395 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2396 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2397 /* GST_VIDEO_FORMAT_v210, */
2398 /* GST_VIDEO_FORMAT_v216, */
2399 /* GST_VIDEO_FORMAT_NV12, */
2400 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2401 /* GST_VIDEO_FORMAT_NV21, */
2402 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2403 /* GST_VIDEO_FORMAT_GRAY8, */
2404 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2405 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2406 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2407 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2408 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2409 /* GST_VIDEO_FORMAT_v308, */
2410 /* GST_VIDEO_FORMAT_Y800, */
2411 /* GST_VIDEO_FORMAT_Y16, */
2412 /* GST_VIDEO_FORMAT_RGB16, */
2413 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2414 /* GST_VIDEO_FORMAT_BGR16, */
2415 /* GST_VIDEO_FORMAT_RGB15, */
2416 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2417 /* GST_VIDEO_FORMAT_BGR15, */
2418 /* GST_VIDEO_FORMAT_UYVP, */
2419 /* GST_VIDEO_FORMAT_A420, */
2420 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2421 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2422 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2423 /* GST_VIDEO_FORMAT_YUV9, */
2424 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2425 /* GST_VIDEO_FORMAT_YVU9, */
2426 /* GST_VIDEO_FORMAT_IYU1, */
2427 /* GST_VIDEO_FORMAT_ARGB64, */
2428 /* GST_VIDEO_FORMAT_AYUV64, */
2429 /* GST_VIDEO_FORMAT_r210, */
2430 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2431 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2432 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2433 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2434 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2435 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2436 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2437 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2438 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2442 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2446 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2447 if (pixtofmttable[i].pixfmt == pixfmt)
2448 return pixtofmttable[i].format;
2450 GST_WARNING ("Unknown pixel format %d", pixfmt);
2451 return GST_VIDEO_FORMAT_UNKNOWN;
2455 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2459 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2460 if (pixtofmttable[i].format == format)
2461 return pixtofmttable[i].pixfmt;
2462 return PIX_FMT_NONE;
2466 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2470 context->width = GST_VIDEO_INFO_WIDTH (info);
2471 context->height = GST_VIDEO_INFO_HEIGHT (info);
2472 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2473 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2474 context->bits_per_coded_sample = bpp;
2476 context->ticks_per_frame = 1;
2477 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2478 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2480 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2481 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2484 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2488 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2490 const AVCodec *codec;
2491 const enum AVSampleFormat *smpl_fmts;
2492 enum AVSampleFormat smpl_fmt = -1;
2494 context->channels = info->channels;
2495 context->sample_rate = info->rate;
2496 context->channel_layout =
2497 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2499 codec = context->codec;
2501 smpl_fmts = codec->sample_fmts;
2503 switch (info->finfo->format) {
2504 case GST_AUDIO_FORMAT_F32:
2506 while (*smpl_fmts != -1) {
2507 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2508 smpl_fmt = *smpl_fmts;
2510 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2511 smpl_fmt = *smpl_fmts;
2517 smpl_fmt = AV_SAMPLE_FMT_FLT;
2520 case GST_AUDIO_FORMAT_F64:
2522 while (*smpl_fmts != -1) {
2523 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2524 smpl_fmt = *smpl_fmts;
2526 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2527 smpl_fmt = *smpl_fmts;
2533 smpl_fmt = AV_SAMPLE_FMT_DBL;
2536 case GST_AUDIO_FORMAT_S32:
2538 while (*smpl_fmts != -1) {
2539 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2540 smpl_fmt = *smpl_fmts;
2542 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2543 smpl_fmt = *smpl_fmts;
2549 smpl_fmt = AV_SAMPLE_FMT_S32;
2552 case GST_AUDIO_FORMAT_S16:
2554 while (*smpl_fmts != -1) {
2555 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2556 smpl_fmt = *smpl_fmts;
2558 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2559 smpl_fmt = *smpl_fmts;
2565 smpl_fmt = AV_SAMPLE_FMT_S16;
2568 case GST_AUDIO_FORMAT_U8:
2570 while (*smpl_fmts != -1) {
2571 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2572 smpl_fmt = *smpl_fmts;
2574 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2575 smpl_fmt = *smpl_fmts;
2581 smpl_fmt = AV_SAMPLE_FMT_U8;
2588 g_assert (smpl_fmt != -1);
2590 context->sample_fmt = smpl_fmt;
2593 /* Convert a GstCaps and a FFMPEG codec Type to a
2594 * AVCodecContext. If the context is ommitted, no fixed values
2595 * for video/audio size will be included in the context
2597 * AVMediaType is primarily meant for uncompressed data GstCaps!
2601 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2602 const GstCaps * caps, AVCodecContext * context)
2604 if (context == NULL)
2608 case AVMEDIA_TYPE_VIDEO:
2609 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2612 case AVMEDIA_TYPE_AUDIO:
2613 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2624 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2628 guint8 *end = src + size;
2631 while (srcp < end) {
2632 if (count == 2 && *srcp <= 0x03) {
2633 GST_DEBUG ("added escape code");
2642 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2645 *destsize = dstp - dst;
2648 /* copy the config, escaping NAL units as we iterate them, if something fails we
2649 * copy everything and hope for the best. */
2651 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2656 guint nalsize, esize;
2666 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2668 GST_DEBUG ("num SPS %d", cnt);
2670 memcpy (dstp, srcp, 6);
2674 for (i = 0; i < cnt; i++) {
2675 GST_DEBUG ("copy SPS %d", i);
2676 nalsize = (srcp[0] << 8) | srcp[1];
2677 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2678 dstp[0] = esize >> 8;
2679 dstp[1] = esize & 0xff;
2681 srcp += nalsize + 2;
2684 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2686 GST_DEBUG ("num PPS %d", cnt);
2688 for (i = 0; i < cnt; i++) {
2689 GST_DEBUG ("copy PPS %d", i);
2690 nalsize = (srcp[0] << 8) | srcp[1];
2691 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2692 dstp[0] = esize >> 8;
2693 dstp[1] = esize & 0xff;
2695 srcp += nalsize + 2;
2697 *destsize = dstp - dst;
2703 GST_DEBUG ("something unexpected, doing full copy");
2704 memcpy (dst, src, size);
2712 * caps_with_codecid () transforms a GstCaps for a known codec
2713 * ID into a filled-in context.
2714 * codec_data from caps will override possible extradata already in the context
2718 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2719 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2722 const GValue *value;
2725 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2726 codec_id, codec_type, caps, context);
2728 if (!context || !gst_caps_get_size (caps))
2731 str = gst_caps_get_structure (caps, 0);
2733 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2734 if ((value = gst_structure_get_value (str, "codec_data"))) {
2737 buf = gst_value_get_buffer (value);
2738 gst_buffer_map (buf, &map, GST_MAP_READ);
2740 /* free the old one if it is there */
2741 if (context->extradata)
2742 av_free (context->extradata);
2745 if (codec_id == CODEC_ID_H264) {
2748 GST_DEBUG ("copy, escaping codec_data %d", size);
2749 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2750 * reason for this but let's just escape it for now. Start by allocating
2751 * enough space, x2 is more than enough.
2753 * FIXME, we disabled escaping because some file already contain escaped
2754 * codec_data and then we escape twice and fail. It's better to leave it
2755 * as is, as that is what most players do. */
2756 context->extradata =
2757 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2758 FF_INPUT_BUFFER_PADDING_SIZE));
2759 copy_config (context->extradata, data, size, &extrasize);
2760 GST_DEBUG ("escaped size: %d", extrasize);
2761 context->extradata_size = extrasize;
2765 /* allocate with enough padding */
2766 GST_DEBUG ("copy codec_data");
2767 context->extradata =
2768 av_mallocz (GST_ROUND_UP_16 (map.size +
2769 FF_INPUT_BUFFER_PADDING_SIZE));
2770 memcpy (context->extradata, map.data, map.size);
2771 context->extradata_size = map.size;
2774 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2775 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2776 context->extradata[0] = (guint8) map.size;
2779 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2781 gst_buffer_unmap (buf, &map);
2782 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2783 codec_id != CODEC_ID_FLAC) {
2784 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2785 * extradata anyway which makes then segfault. */
2786 context->extradata =
2787 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2788 context->extradata_size = 0;
2789 GST_DEBUG ("no codec data");
2793 case CODEC_ID_MPEG4:
2795 const gchar *mime = gst_structure_get_name (str);
2797 if (!strcmp (mime, "video/x-divx"))
2798 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2799 else if (!strcmp (mime, "video/x-xvid"))
2800 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2801 else if (!strcmp (mime, "video/x-3ivx"))
2802 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2803 else if (!strcmp (mime, "video/mpeg"))
2804 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2809 /* FIXME: this is a workaround for older gst-plugins releases
2810 * (<= 0.8.9). This should be removed at some point, because
2811 * it causes wrong decoded frame order. */
2812 if (!context->extradata) {
2813 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2816 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2817 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2818 gst_structure_get_int (str, "low_delay", &low_delay) ||
2819 gst_structure_get_int (str, "unknown_svq3_flag",
2820 &unknown_svq3_flag)) {
2821 context->extradata = (guint8 *) av_mallocz (0x64);
2822 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2826 flags |= unknown_svq3_flag;
2828 flags |= halfpel_flag;
2830 flags |= thirdpel_flag;
2833 flags = GUINT16_FROM_LE (flags);
2835 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2836 context->extradata_size = 0x64;
2841 case CODEC_ID_MSRLE:
2842 case CODEC_ID_QTRLE:
2849 if (gst_structure_get_int (str, "depth", &depth)) {
2850 context->bits_per_coded_sample = depth;
2852 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2865 if (gst_structure_get_int (str, "format", &format))
2866 context->sub_id = format;
2871 case CODEC_ID_RA_288:
2872 case CODEC_ID_RA_144:
2878 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2879 context->block_align = leaf_size;
2880 if (gst_structure_get_int (str, "bitrate", &bitrate))
2881 context->bit_rate = bitrate;
2884 gst_structure_get_int (str, "samplesize",
2885 &context->bits_per_coded_sample);
2888 case CODEC_ID_DVVIDEO:
2890 const gchar *format;
2892 if ((format = gst_structure_get_string (str, "format"))) {
2894 if (g_str_equal (format, "YUY2"))
2895 context->pix_fmt = PIX_FMT_YUYV422;
2896 else if (g_str_equal (format, "I420"))
2897 context->pix_fmt = PIX_FMT_YUV420P;
2898 else if (g_str_equal (format, "A420"))
2899 context->pix_fmt = PIX_FMT_YUVA420P;
2900 else if (g_str_equal (format, "Y41B"))
2901 context->pix_fmt = PIX_FMT_YUV411P;
2902 else if (g_str_equal (format, "Y42B"))
2903 context->pix_fmt = PIX_FMT_YUV422P;
2904 else if (g_str_equal (format, "YUV9"))
2905 context->pix_fmt = PIX_FMT_YUV410P;
2907 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2911 GST_WARNING ("No specified format");
2914 case CODEC_ID_H263P:
2918 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2919 context->flags |= CODEC_FLAG_4MV;
2921 context->flags &= ~CODEC_FLAG_4MV;
2922 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2923 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2924 context->flags |= CODEC_FLAG_AC_PRED;
2926 context->flags &= ~CODEC_FLAG_AC_PRED;
2927 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2928 context->flags |= CODEC_FLAG_LOOP_FILTER;
2930 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2933 case CODEC_ID_ADPCM_G726:
2935 const gchar *layout;
2937 if ((layout = gst_structure_get_string (str, "layout"))) {
2938 if (!strcmp (layout, "g721")) {
2939 context->sample_rate = 8000;
2940 context->channels = 1;
2941 context->bit_rate = 32000;
2950 if (!gst_caps_is_fixed (caps))
2953 /* common properties (width, height, fps) */
2954 switch (codec_type) {
2955 case AVMEDIA_TYPE_VIDEO:
2956 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2958 case AVMEDIA_TYPE_AUDIO:
2959 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2965 /* fixup of default settings */
2967 case CODEC_ID_QCELP:
2968 /* QCELP is always mono, no matter what the caps say */
2969 context->channels = 1;
2971 case CODEC_ID_ADPCM_G726:
2972 if (context->sample_rate && context->bit_rate)
2973 context->bits_per_coded_sample =
2974 context->bit_rate / context->sample_rate;
2981 /* _formatid_to_caps () is meant for muxers/demuxers, it
2982 * transforms a name (ffmpeg way of ID'ing these, why don't
2983 * they have unique numerical IDs?) to the corresponding
2984 * caps belonging to that mux-format
2986 * Note: we don't need any additional info because the caps
2987 * isn't supposed to contain any useful info besides the
2992 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2994 GstCaps *caps = NULL;
2996 if (!strcmp (format_name, "mpeg")) {
2997 caps = gst_caps_new_simple ("video/mpeg",
2998 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2999 } else if (!strcmp (format_name, "mpegts")) {
3000 caps = gst_caps_new_simple ("video/mpegts",
3001 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3002 } else if (!strcmp (format_name, "rm")) {
3003 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3004 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3005 } else if (!strcmp (format_name, "asf")) {
3006 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3007 } else if (!strcmp (format_name, "avi")) {
3008 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3009 } else if (!strcmp (format_name, "wav")) {
3010 caps = gst_caps_new_empty_simple ("audio/x-wav");
3011 } else if (!strcmp (format_name, "ape")) {
3012 caps = gst_caps_new_empty_simple ("application/x-ape");
3013 } else if (!strcmp (format_name, "swf")) {
3014 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3015 } else if (!strcmp (format_name, "au")) {
3016 caps = gst_caps_new_empty_simple ("audio/x-au");
3017 } else if (!strcmp (format_name, "dv")) {
3018 caps = gst_caps_new_simple ("video/x-dv",
3019 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3020 } else if (!strcmp (format_name, "4xm")) {
3021 caps = gst_caps_new_empty_simple ("video/x-4xm");
3022 } else if (!strcmp (format_name, "matroska")) {
3023 caps = gst_caps_new_empty_simple ("video/x-matroska");
3024 } else if (!strcmp (format_name, "mp3")) {
3025 caps = gst_caps_new_empty_simple ("application/x-id3");
3026 } else if (!strcmp (format_name, "flic")) {
3027 caps = gst_caps_new_empty_simple ("video/x-fli");
3028 } else if (!strcmp (format_name, "flv")) {
3029 caps = gst_caps_new_empty_simple ("video/x-flv");
3030 } else if (!strcmp (format_name, "tta")) {
3031 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3032 } else if (!strcmp (format_name, "aiff")) {
3033 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3034 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3036 gst_caps_from_string
3037 ("application/x-3gp; video/quicktime; audio/x-m4a");
3038 } else if (!strcmp (format_name, "mov")) {
3039 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3040 } else if (!strcmp (format_name, "mp4")) {
3041 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3042 } else if (!strcmp (format_name, "3gp")) {
3043 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3044 } else if (!strcmp (format_name, "3g2")) {
3045 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3046 } else if (!strcmp (format_name, "psp")) {
3047 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3048 } else if (!strcmp (format_name, "ipod")) {
3049 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3050 } else if (!strcmp (format_name, "aac")) {
3051 caps = gst_caps_new_simple ("audio/mpeg",
3052 "mpegversion", G_TYPE_INT, 4, NULL);
3053 } else if (!strcmp (format_name, "gif")) {
3054 caps = gst_caps_from_string ("image/gif");
3055 } else if (!strcmp (format_name, "ogg")) {
3056 caps = gst_caps_from_string ("application/ogg");
3057 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3058 caps = gst_caps_from_string ("application/mxf");
3059 } else if (!strcmp (format_name, "gxf")) {
3060 caps = gst_caps_from_string ("application/gxf");
3061 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3062 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3063 "y4mversion", G_TYPE_INT, 2, NULL);
3064 } else if (!strcmp (format_name, "mpc")) {
3065 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3066 } else if (!strcmp (format_name, "vqf")) {
3067 caps = gst_caps_from_string ("audio/x-vqf");
3068 } else if (!strcmp (format_name, "nsv")) {
3069 caps = gst_caps_from_string ("video/x-nsv");
3070 } else if (!strcmp (format_name, "amr")) {
3071 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3072 } else if (!strcmp (format_name, "webm")) {
3073 caps = gst_caps_from_string ("video/webm");
3074 } else if (!strcmp (format_name, "voc")) {
3075 caps = gst_caps_from_string ("audio/x-voc");
3079 GST_LOG ("Could not create stream format caps for %s", format_name);
3080 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3081 caps = gst_caps_new_empty_simple (name);
3089 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3090 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3091 AVOutputFormat * plugin)
3093 static enum CodecID tmp_vlist[] = {
3097 static enum CodecID tmp_alist[] = {
3102 GST_LOG ("format_name : %s", format_name);
3104 if (!strcmp (format_name, "mp4")) {
3105 static enum CodecID mp4_video_list[] = {
3106 CODEC_ID_MPEG4, CODEC_ID_H264,
3110 static enum CodecID mp4_audio_list[] = {
3111 CODEC_ID_AAC, CODEC_ID_MP3,
3115 *video_codec_list = mp4_video_list;
3116 *audio_codec_list = mp4_audio_list;
3117 } else if (!strcmp (format_name, "mpeg")) {
3118 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
3119 CODEC_ID_MPEG2VIDEO,
3123 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
3129 *video_codec_list = mpeg_video_list;
3130 *audio_codec_list = mpeg_audio_list;
3131 } else if (!strcmp (format_name, "dvd")) {
3132 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
3135 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
3142 *video_codec_list = mpeg_video_list;
3143 *audio_codec_list = mpeg_audio_list;
3144 } else if (!strcmp (format_name, "mpegts")) {
3145 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
3146 CODEC_ID_MPEG2VIDEO,
3150 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
3158 *video_codec_list = mpegts_video_list;
3159 *audio_codec_list = mpegts_audio_list;
3160 } else if (!strcmp (format_name, "vob")) {
3161 static enum CodecID vob_video_list[] =
3162 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
3163 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
3164 CODEC_ID_DTS, CODEC_ID_NONE
3167 *video_codec_list = vob_video_list;
3168 *audio_codec_list = vob_audio_list;
3169 } else if (!strcmp (format_name, "flv")) {
3170 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
3171 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
3173 *video_codec_list = flv_video_list;
3174 *audio_codec_list = flv_audio_list;
3175 } else if (!strcmp (format_name, "asf")) {
3176 static enum CodecID asf_video_list[] =
3177 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
3178 static enum CodecID asf_audio_list[] =
3179 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
3181 *video_codec_list = asf_video_list;
3182 *audio_codec_list = asf_audio_list;
3183 } else if (!strcmp (format_name, "dv")) {
3184 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
3185 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
3187 *video_codec_list = dv_video_list;
3188 *audio_codec_list = dv_audio_list;
3189 } else if (!strcmp (format_name, "mov")) {
3190 static enum CodecID mov_video_list[] = {
3191 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
3192 CODEC_ID_H263, CODEC_ID_H263P,
3193 CODEC_ID_H264, CODEC_ID_DVVIDEO,
3197 static enum CodecID mov_audio_list[] = {
3198 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
3199 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
3200 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3201 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
3202 CODEC_ID_MP3, CODEC_ID_NONE
3205 *video_codec_list = mov_video_list;
3206 *audio_codec_list = mov_audio_list;
3207 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3208 static enum CodecID tgp_video_list[] = {
3209 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
3212 static enum CodecID tgp_audio_list[] = {
3213 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3218 *video_codec_list = tgp_video_list;
3219 *audio_codec_list = tgp_audio_list;
3220 } else if (!strcmp (format_name, "mmf")) {
3221 static enum CodecID mmf_audio_list[] = {
3222 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
3224 *video_codec_list = NULL;
3225 *audio_codec_list = mmf_audio_list;
3226 } else if (!strcmp (format_name, "amr")) {
3227 static enum CodecID amr_audio_list[] = {
3228 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3231 *video_codec_list = NULL;
3232 *audio_codec_list = amr_audio_list;
3233 } else if (!strcmp (format_name, "gif")) {
3234 static enum CodecID gif_image_list[] = {
3235 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
3237 *video_codec_list = gif_image_list;
3238 *audio_codec_list = NULL;
3239 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
3240 (plugin->video_codec != CODEC_ID_NONE)) {
3241 tmp_vlist[0] = plugin->video_codec;
3242 tmp_alist[0] = plugin->audio_codec;
3244 *video_codec_list = tmp_vlist;
3245 *audio_codec_list = tmp_alist;
3247 GST_LOG ("Format %s not found", format_name);
3254 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3255 * are omitted, that can be queried by the user itself,
3256 * we're not eating the GstCaps or anything
3257 * A pointer to an allocated context is also needed for
3258 * optional extra info
3262 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3264 enum CodecID id = CODEC_ID_NONE;
3265 const gchar *mimetype;
3266 const GstStructure *structure;
3267 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3269 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3270 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3271 structure = gst_caps_get_structure (caps, 0);
3273 mimetype = gst_structure_get_name (structure);
3275 if (!strcmp (mimetype, "video/x-raw")) {
3276 id = CODEC_ID_RAWVIDEO;
3278 } else if (!strcmp (mimetype, "audio/x-raw")) {
3281 if (gst_audio_info_from_caps (&info, caps)) {
3282 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3283 case GST_AUDIO_FORMAT_S8:
3284 id = CODEC_ID_PCM_S8;
3286 case GST_AUDIO_FORMAT_U8:
3287 id = CODEC_ID_PCM_U8;
3289 case GST_AUDIO_FORMAT_S16LE:
3290 id = CODEC_ID_PCM_S16LE;
3292 case GST_AUDIO_FORMAT_S16BE:
3293 id = CODEC_ID_PCM_S16BE;
3295 case GST_AUDIO_FORMAT_U16LE:
3296 id = CODEC_ID_PCM_U16LE;
3298 case GST_AUDIO_FORMAT_U16BE:
3299 id = CODEC_ID_PCM_U16BE;
3304 if (id != CODEC_ID_NONE)
3307 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3308 id = CODEC_ID_PCM_MULAW;
3310 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3311 id = CODEC_ID_PCM_ALAW;
3313 } else if (!strcmp (mimetype, "video/x-dv")) {
3316 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3318 id = CODEC_ID_DVVIDEO;
3321 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3322 id = CODEC_ID_DVAUDIO;
3324 } else if (!strcmp (mimetype, "video/x-h263")) {
3325 const gchar *h263version =
3326 gst_structure_get_string (structure, "h263version");
3327 if (h263version && !strcmp (h263version, "h263p"))
3328 id = CODEC_ID_H263P;
3332 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3333 id = CODEC_ID_H263I;
3335 } else if (!strcmp (mimetype, "video/x-h261")) {
3338 } else if (!strcmp (mimetype, "video/mpeg")) {
3342 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3343 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3345 switch (mpegversion) {
3347 id = CODEC_ID_MPEG1VIDEO;
3350 id = CODEC_ID_MPEG2VIDEO;
3353 id = CODEC_ID_MPEG4;
3357 if (id != CODEC_ID_NONE)
3359 } else if (!strcmp (mimetype, "image/jpeg")) {
3360 id = CODEC_ID_MJPEG; /* A... B... */
3362 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3363 id = CODEC_ID_MJPEGB;
3365 } else if (!strcmp (mimetype, "video/x-wmv")) {
3366 gint wmvversion = 0;
3368 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3369 switch (wmvversion) {
3378 const gchar *format;
3380 /* WMV3 unless the fourcc exists and says otherwise */
3383 if ((format = gst_structure_get_string (structure, "format")) &&
3384 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3391 if (id != CODEC_ID_NONE)
3393 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3394 id = CODEC_ID_VORBIS;
3396 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3399 } else if (!strcmp (mimetype, "audio/mpeg")) {
3401 gint mpegversion = 0;
3403 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3404 switch (mpegversion) {
3405 case 2: /* ffmpeg uses faad for both... */
3410 if (gst_structure_get_int (structure, "layer", &layer)) {
3425 if (id != CODEC_ID_NONE)
3427 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3428 gint streamversion = -1;
3430 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3431 if (streamversion == 7)
3432 id = CODEC_ID_MUSEPACK7;
3434 id = CODEC_ID_MUSEPACK7;
3436 } else if (!strcmp (mimetype, "audio/x-wma")) {
3437 gint wmaversion = 0;
3439 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3440 switch (wmaversion) {
3442 id = CODEC_ID_WMAV1;
3445 id = CODEC_ID_WMAV2;
3448 id = CODEC_ID_WMAPRO;
3452 if (id != CODEC_ID_NONE)
3454 } else if (!strcmp (mimetype, "audio/x-wms")) {
3455 id = CODEC_ID_WMAVOICE;
3457 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3460 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3463 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3464 !strcmp (mimetype, "audio/atrac3")) {
3465 id = CODEC_ID_ATRAC3;
3467 } else if (!strcmp (mimetype, "audio/x-dts")) {
3470 } else if (!strcmp (mimetype, "application/x-ape")) {
3473 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3474 gint msmpegversion = 0;
3476 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3477 switch (msmpegversion) {
3479 id = CODEC_ID_MSMPEG4V1;
3482 id = CODEC_ID_MSMPEG4V2;
3485 id = CODEC_ID_MSMPEG4V3;
3489 if (id != CODEC_ID_NONE)
3491 } else if (!strcmp (mimetype, "video/x-svq")) {
3492 gint svqversion = 0;
3494 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3495 switch (svqversion) {
3504 if (id != CODEC_ID_NONE)
3506 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3507 id = CODEC_ID_HUFFYUV;
3509 } else if (!strcmp (mimetype, "audio/x-mace")) {
3510 gint maceversion = 0;
3512 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3513 switch (maceversion) {
3515 id = CODEC_ID_MACE3;
3518 id = CODEC_ID_MACE6;
3522 if (id != CODEC_ID_NONE)
3524 } else if (!strcmp (mimetype, "video/x-theora")) {
3525 id = CODEC_ID_THEORA;
3527 } else if (!strcmp (mimetype, "video/x-vp3")) {
3530 } else if (!strcmp (mimetype, "video/x-vp5")) {
3533 } else if (!strcmp (mimetype, "video/x-vp6")) {
3536 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3539 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3542 } else if (!strcmp (mimetype, "video/x-vp8")) {
3545 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3546 id = CODEC_ID_FLASHSV;
3548 } else if (!strcmp (mimetype, "video/x-indeo")) {
3549 gint indeoversion = 0;
3551 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3552 switch (indeoversion) {
3554 id = CODEC_ID_INDEO5;
3557 id = CODEC_ID_INDEO4;
3560 id = CODEC_ID_INDEO3;
3563 id = CODEC_ID_INDEO2;
3566 if (id != CODEC_ID_NONE)
3569 } else if (!strcmp (mimetype, "video/x-divx")) {
3570 gint divxversion = 0;
3572 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3573 switch (divxversion) {
3575 id = CODEC_ID_MSMPEG4V3;
3579 id = CODEC_ID_MPEG4;
3583 if (id != CODEC_ID_NONE)
3585 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3586 id = CODEC_ID_MPEG4;
3588 } else if (!strcmp (mimetype, "video/x-xvid")) {
3589 id = CODEC_ID_MPEG4;
3591 } else if (!strcmp (mimetype, "video/x-ffv")) {
3592 gint ffvversion = 0;
3594 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3599 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3600 const gchar *layout;
3602 layout = gst_structure_get_string (structure, "layout");
3603 if (layout == NULL) {
3605 } else if (!strcmp (layout, "quicktime")) {
3606 id = CODEC_ID_ADPCM_IMA_QT;
3607 } else if (!strcmp (layout, "microsoft")) {
3608 id = CODEC_ID_ADPCM_MS;
3609 } else if (!strcmp (layout, "dvi")) {
3610 id = CODEC_ID_ADPCM_IMA_WAV;
3611 } else if (!strcmp (layout, "4xm")) {
3612 id = CODEC_ID_ADPCM_4XM;
3613 } else if (!strcmp (layout, "smjpeg")) {
3614 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3615 } else if (!strcmp (layout, "dk3")) {
3616 id = CODEC_ID_ADPCM_IMA_DK3;
3617 } else if (!strcmp (layout, "dk4")) {
3618 id = CODEC_ID_ADPCM_IMA_DK4;
3619 } else if (!strcmp (layout, "westwood")) {
3620 id = CODEC_ID_ADPCM_IMA_WS;
3621 } else if (!strcmp (layout, "iss")) {
3622 id = CODEC_ID_ADPCM_IMA_ISS;
3623 } else if (!strcmp (layout, "xa")) {
3624 id = CODEC_ID_ADPCM_XA;
3625 } else if (!strcmp (layout, "adx")) {
3626 id = CODEC_ID_ADPCM_ADX;
3627 } else if (!strcmp (layout, "ea")) {
3628 id = CODEC_ID_ADPCM_EA;
3629 } else if (!strcmp (layout, "g726")) {
3630 id = CODEC_ID_ADPCM_G726;
3631 } else if (!strcmp (layout, "g721")) {
3632 id = CODEC_ID_ADPCM_G726;
3633 } else if (!strcmp (layout, "ct")) {
3634 id = CODEC_ID_ADPCM_CT;
3635 } else if (!strcmp (layout, "swf")) {
3636 id = CODEC_ID_ADPCM_SWF;
3637 } else if (!strcmp (layout, "yamaha")) {
3638 id = CODEC_ID_ADPCM_YAMAHA;
3639 } else if (!strcmp (layout, "sbpro2")) {
3640 id = CODEC_ID_ADPCM_SBPRO_2;
3641 } else if (!strcmp (layout, "sbpro3")) {
3642 id = CODEC_ID_ADPCM_SBPRO_3;
3643 } else if (!strcmp (layout, "sbpro4")) {
3644 id = CODEC_ID_ADPCM_SBPRO_4;
3646 if (id != CODEC_ID_NONE)
3648 } else if (!strcmp (mimetype, "video/x-4xm")) {
3651 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3652 const gchar *layout;
3654 layout = gst_structure_get_string (structure, "layout");
3657 } else if (!strcmp (layout, "roq")) {
3658 id = CODEC_ID_ROQ_DPCM;
3659 } else if (!strcmp (layout, "interplay")) {
3660 id = CODEC_ID_INTERPLAY_DPCM;
3661 } else if (!strcmp (layout, "xan")) {
3662 id = CODEC_ID_XAN_DPCM;
3663 } else if (!strcmp (layout, "sol")) {
3664 id = CODEC_ID_SOL_DPCM;
3666 if (id != CODEC_ID_NONE)
3668 } else if (!strcmp (mimetype, "audio/x-flac")) {
3671 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3672 id = CODEC_ID_SHORTEN;
3674 } else if (!strcmp (mimetype, "audio/x-alac")) {
3677 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3678 id = CODEC_ID_CINEPAK;
3680 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3683 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3684 switch (rmversion) {
3699 if (id != CODEC_ID_NONE)
3701 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3704 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3707 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3708 switch (raversion) {
3710 id = CODEC_ID_RA_144;
3713 id = CODEC_ID_RA_288;
3720 if (id != CODEC_ID_NONE)
3722 } else if (!strcmp (mimetype, "video/x-rle")) {
3723 const gchar *layout;
3725 if ((layout = gst_structure_get_string (structure, "layout"))) {
3726 if (!strcmp (layout, "microsoft")) {
3727 id = CODEC_ID_MSRLE;
3731 } else if (!strcmp (mimetype, "video/x-xan")) {
3734 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3735 switch (wcversion) {
3737 id = CODEC_ID_XAN_WC3;
3741 id = CODEC_ID_XAN_WC4;
3748 } else if (!strcmp (mimetype, "audio/AMR")) {
3750 id = CODEC_ID_AMR_NB;
3751 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3752 id = CODEC_ID_AMR_WB;
3754 } else if (!strcmp (mimetype, "audio/qcelp")) {
3755 id = CODEC_ID_QCELP;
3757 } else if (!strcmp (mimetype, "video/x-h264")) {
3760 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3761 gint flvversion = 0;
3763 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3764 switch (flvversion) {
3774 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3775 id = CODEC_ID_NELLYMOSER;
3777 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3781 if (strlen (mimetype) <= 30 &&
3782 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3783 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3784 (codec = avcodec_find_encoder_by_name (ext))) {
3789 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3793 if (strlen (mimetype) <= 30 &&
3794 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3795 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3796 (codec = avcodec_find_encoder_by_name (ext))) {
3803 if (context != NULL) {
3804 if (video == TRUE) {
3805 context->codec_type = AVMEDIA_TYPE_VIDEO;
3806 } else if (audio == TRUE) {
3807 context->codec_type = AVMEDIA_TYPE_AUDIO;
3809 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3811 context->codec_id = id;
3812 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3815 if (id != CODEC_ID_NONE) {
3816 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3818 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);