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);
390 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
397 /* no fixed caps or special restrictions applied;
398 * default unfixed setting */
400 GST_DEBUG ("Creating default caps");
401 caps = gst_caps_new_empty_simple (mimetype);
404 va_start (var_args, fieldname);
405 gst_caps_set_simple_valist (caps, fieldname, var_args);
412 get_nbits_set (guint64 n)
417 for (i = 0; i < 64; i++) {
418 if ((n & (G_GUINT64_CONSTANT (1) << i)))
426 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
427 const enum AVSampleFormat *fmts)
431 GstAudioFormat format;
433 if (!fmts || fmts[0] == -1) {
436 g_value_init (&va, GST_TYPE_LIST);
437 g_value_init (&v, G_TYPE_STRING);
438 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
439 format = gst_ffmpeg_smpfmt_to_audioformat (i);
440 if (format == GST_AUDIO_FORMAT_UNKNOWN)
442 g_value_set_string (&v, gst_audio_format_to_string (format));
443 gst_value_list_append_value (&va, &v);
445 gst_caps_set_value (caps, "format", &va);
451 g_value_init (&va, GST_TYPE_LIST);
452 g_value_init (&v, G_TYPE_STRING);
453 while (*fmts != -1) {
454 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
455 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
456 g_value_set_string (&v, gst_audio_format_to_string (format));
457 gst_value_list_append_value (&va, &v);
461 if (gst_value_list_get_size (&va) == 1) {
462 /* The single value is still in v */
463 gst_caps_set_value (caps, "format", &v);
464 } else if (gst_value_list_get_size (&va) > 1) {
465 gst_caps_set_value (caps, "format", &va);
471 /* same for audio - now with channels/sample rate
474 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
475 enum CodecID codec_id, gboolean encode, const char *mimetype,
476 const char *fieldname, ...)
478 GstCaps *caps = NULL;
482 /* fixed, non-probing context */
483 if (context != NULL && context->channels != -1) {
484 GstAudioChannelPosition pos[64];
486 caps = gst_caps_new_simple (mimetype,
487 "rate", G_TYPE_INT, context->sample_rate,
488 "channels", G_TYPE_INT, context->channels, NULL);
490 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
491 context->channels, pos)) {
494 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
496 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
501 gint maxchannels = 2;
502 const gint *rates = NULL;
505 /* so we must be after restricted caps in this case */
508 case CODEC_ID_AAC_LATM:
514 const static gint l_rates[] =
515 { 48000, 44100, 32000, 24000, 22050, 16000 };
516 n_rates = G_N_ELEMENTS (l_rates);
523 const static gint l_rates[] = { 48000, 44100, 32000 };
525 n_rates = G_N_ELEMENTS (l_rates);
529 case CODEC_ID_ADPCM_G722:
531 const static gint l_rates[] = { 16000 };
532 n_rates = G_N_ELEMENTS (l_rates);
537 case CODEC_ID_ADPCM_G726:
539 const static gint l_rates[] = { 8000 };
540 n_rates = G_N_ELEMENTS (l_rates);
545 case CODEC_ID_ADPCM_SWF:
547 const static gint l_rates[] = { 11025, 22050, 44100 };
548 n_rates = G_N_ELEMENTS (l_rates);
552 case CODEC_ID_ROQ_DPCM:
554 const static gint l_rates[] = { 22050 };
555 n_rates = G_N_ELEMENTS (l_rates);
559 case CODEC_ID_AMR_NB:
561 const static gint l_rates[] = { 8000 };
563 n_rates = G_N_ELEMENTS (l_rates);
567 case CODEC_ID_AMR_WB:
569 const static gint l_rates[] = { 16000 };
571 n_rates = G_N_ELEMENTS (l_rates);
579 /* regardless of encode/decode, open up channels if applicable */
580 /* Until decoders/encoders expose the maximum number of channels
581 * they support, we whitelist them here. */
583 case CODEC_ID_WMAPRO:
584 case CODEC_ID_TRUEHD:
591 if (codec && codec->channel_layouts) {
592 const uint64_t *layouts = codec->channel_layouts;
593 GstAudioChannelPosition pos[64];
595 caps = gst_caps_new_empty ();
597 gint nbits_set = get_nbits_set (*layouts);
599 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
602 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
605 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
607 "channels", G_TYPE_INT, nbits_set, NULL);
609 gst_caps_append (caps, tmp);
615 if (maxchannels == 1)
616 caps = gst_caps_new_simple (mimetype,
617 "channels", G_TYPE_INT, maxchannels, NULL);
619 caps = gst_caps_new_simple (mimetype,
620 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
624 GValue list = { 0, };
626 g_value_init (&list, GST_TYPE_LIST);
627 for (i = 0; i < n_rates; i++) {
630 g_value_init (&v, G_TYPE_INT);
631 g_value_set_int (&v, rates[i]);
632 gst_value_list_append_value (&list, &v);
635 gst_caps_set_value (caps, "rate", &list);
636 g_value_unset (&list);
637 } else if (codec && codec->supported_samplerates
638 && codec->supported_samplerates[0]) {
642 if (!codec->supported_samplerates[1]) {
643 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
644 codec->supported_samplerates[0], NULL);
646 const int *rates = codec->supported_samplerates;
648 g_value_init (&va, GST_TYPE_LIST);
649 g_value_init (&v, G_TYPE_INT);
652 g_value_set_int (&v, *rates);
653 gst_value_list_append_value (&va, &v);
656 gst_caps_set_value (caps, "rate", &va);
661 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
664 caps = gst_caps_new_empty_simple (mimetype);
667 gst_ffmpeg_audio_set_sample_fmts (caps, codec ? codec->sample_fmts : NULL);
669 va_start (var_args, fieldname);
670 gst_caps_set_simple_valist (caps, fieldname, var_args);
676 /* Convert a FFMPEG codec ID and optional AVCodecContext
677 * to a GstCaps. If the context is ommitted, no fixed values
678 * for video/audio size will be included in the GstCaps
680 * CodecID is primarily meant for compressed data GstCaps!
682 * encode is a special parameter. gstffmpegdec will say
683 * FALSE, gstffmpegenc will say TRUE. The output caps
684 * depends on this, in such a way that it will be very
685 * specific, defined, fixed and correct caps for encoders,
686 * yet very wide, "forgiving" caps for decoders. Example
687 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
688 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
693 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
694 AVCodecContext * context, gboolean encode)
696 GstCaps *caps = NULL;
697 gboolean buildcaps = FALSE;
699 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
702 case CODEC_ID_MPEG1VIDEO:
704 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
705 "mpegversion", G_TYPE_INT, 1,
706 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
709 case CODEC_ID_MPEG2VIDEO:
713 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
714 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
717 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
718 * the MPEG video stream headers, so may be omitted from caps. */
719 caps = gst_caps_new_simple ("video/mpeg",
720 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
721 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
725 case CODEC_ID_MPEG2VIDEO_XVMC:
726 /* this is a special ID - don't need it in GStreamer, I think */
732 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
733 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
734 G_TYPE_STRING, "h263", NULL);
736 /* don't pass codec_id, we can decode other variants with the H263
737 * decoder that don't have specific size requirements
740 gst_ff_vid_caps_new (context, NULL, CODEC_ID_NONE, encode,
741 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
747 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
748 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
750 if (encode && context) {
752 gst_caps_set_simple (caps,
753 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
754 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
755 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
756 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
763 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
764 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
769 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
795 /* FIXME: context->sub_id must be filled in during decoding */
797 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
798 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
799 "rmversion", G_TYPE_INT, version, NULL);
801 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
802 if (context->extradata_size >= 8) {
803 gst_caps_set_simple (caps,
804 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
813 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
814 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
819 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
820 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
827 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
828 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
830 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
831 * in the MPEG audio header, so may be omitted from caps. */
832 caps = gst_caps_new_simple ("audio/mpeg",
833 "mpegversion", G_TYPE_INT, 1,
834 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
838 case CODEC_ID_MUSEPACK7:
840 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
841 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
845 case CODEC_ID_MUSEPACK8:
847 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
848 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
855 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
862 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
866 case CODEC_ID_TRUEHD:
868 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
869 "audio/x-true-hd", NULL);
872 case CODEC_ID_ATRAC1:
874 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
875 "audio/x-vnd.sony.atrac1", NULL);
878 case CODEC_ID_ATRAC3:
880 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
881 "audio/x-vnd.sony.atrac3", NULL);
886 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
892 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
893 "audio/x-ffmpeg-parsed-ape", NULL);
895 gst_caps_set_simple (caps,
896 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
902 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
908 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
912 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
913 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
914 * sp5x is, but it's apparently something JPEG... We don't separate
915 * between those in GStreamer. Should we (at least between MJPEG,
916 * MJPEG-B and sp5x decoding...)? */
920 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
926 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
930 case CODEC_ID_MJPEGB:
932 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
933 "video/x-mjpeg-b", NULL);
937 if (encode && context != NULL) {
938 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
939 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
940 switch (context->codec_tag) {
941 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
943 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
944 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
946 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
950 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
951 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
952 "mpegversion", G_TYPE_INT, 4, NULL);
956 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
958 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
959 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
962 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
963 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
965 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
966 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
968 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
969 encode, "video/x-xvid", NULL));
970 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
971 encode, "video/x-3ivx", NULL));
976 case CODEC_ID_RAWVIDEO:
978 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
981 case CODEC_ID_MSMPEG4V1:
982 case CODEC_ID_MSMPEG4V2:
983 case CODEC_ID_MSMPEG4V3:
985 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
987 /* encode-FIXME: bitrate */
989 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
990 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
991 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
992 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
993 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1001 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
1004 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1005 "wmvversion", G_TYPE_INT, version, NULL);
1011 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1012 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1017 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1018 "svqversion", G_TYPE_INT, 1, NULL);
1023 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1024 "svqversion", G_TYPE_INT, 3, NULL);
1027 case CODEC_ID_DVAUDIO:
1029 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1033 case CODEC_ID_DVVIDEO:
1035 if (encode && context) {
1036 const gchar *format;
1038 switch (context->pix_fmt) {
1039 case PIX_FMT_YUYV422:
1042 case PIX_FMT_YUV420P:
1045 case PIX_FMT_YUVA420P:
1048 case PIX_FMT_YUV411P:
1051 case PIX_FMT_YUV422P:
1054 case PIX_FMT_YUV410P:
1059 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1065 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1066 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1070 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1071 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1076 case CODEC_ID_WMAV1:
1077 case CODEC_ID_WMAV2:
1079 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
1083 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1084 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1085 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1089 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1090 "wmaversion", G_TYPE_INT, version, "block_align",
1091 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1096 case CODEC_ID_WMAPRO:
1099 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1100 "wmaversion", G_TYPE_INT, 3, NULL);
1104 case CODEC_ID_WMAVOICE:
1107 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1112 case CODEC_ID_MACE3:
1113 case CODEC_ID_MACE6:
1115 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
1118 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1119 "maceversion", G_TYPE_INT, version, NULL);
1123 case CODEC_ID_HUFFYUV:
1125 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1126 "video/x-huffyuv", NULL);
1128 gst_caps_set_simple (caps,
1129 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1135 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1136 "video/x-compressed-yuv", NULL);
1141 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1142 "alignment", G_TYPE_STRING, "au", NULL);
1145 case CODEC_ID_INDEO5:
1147 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1148 "indeoversion", G_TYPE_INT, 5, NULL);
1151 case CODEC_ID_INDEO4:
1153 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1154 "indeoversion", G_TYPE_INT, 4, NULL);
1157 case CODEC_ID_INDEO3:
1159 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1160 "indeoversion", G_TYPE_INT, 3, NULL);
1163 case CODEC_ID_INDEO2:
1165 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1166 "indeoversion", G_TYPE_INT, 2, NULL);
1169 case CODEC_ID_FLASHSV:
1171 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1172 "video/x-flash-screen", NULL);
1177 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1183 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1189 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1195 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1196 "video/x-vp6-flash", NULL);
1201 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1202 "video/x-vp6-alpha", NULL);
1207 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1211 case CODEC_ID_THEORA:
1213 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1214 "video/x-theora", NULL);
1220 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1224 GValue arr = { 0, };
1225 GValue item = { 0, };
1227 g_value_init (&arr, GST_TYPE_LIST);
1228 g_value_init (&item, G_TYPE_INT);
1229 g_value_set_int (&item, 2);
1230 gst_value_list_append_value (&arr, &item);
1231 g_value_set_int (&item, 4);
1232 gst_value_list_append_value (&arr, &item);
1233 g_value_unset (&item);
1235 gst_caps_set_value (caps, "mpegversion", &arr);
1236 g_value_unset (&arr);
1238 g_value_init (&arr, GST_TYPE_LIST);
1239 g_value_init (&item, G_TYPE_STRING);
1240 g_value_set_string (&item, "raw");
1241 gst_value_list_append_value (&arr, &item);
1242 g_value_set_string (&item, "adts");
1243 gst_value_list_append_value (&arr, &item);
1244 g_value_set_string (&item, "adif");
1245 gst_value_list_append_value (&arr, &item);
1246 g_value_unset (&item);
1248 gst_caps_set_value (caps, "stream-format", &arr);
1249 g_value_unset (&arr);
1251 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1252 "stream-format", G_TYPE_STRING, "raw",
1253 "base-profile", G_TYPE_STRING, "lc", NULL);
1255 if (context && context->extradata_size > 0)
1256 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1257 context->extradata, context->extradata_size);
1262 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1263 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1264 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1270 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1271 "asusversion", G_TYPE_INT, 1, NULL);
1275 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1276 "asusversion", G_TYPE_INT, 2, NULL);
1281 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1282 "ffvversion", G_TYPE_INT, 1, NULL);
1287 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1291 case CODEC_ID_XAN_WC3:
1292 case CODEC_ID_XAN_WC4:
1294 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1295 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1300 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1301 "video/x-cirrus-logic-accupak", NULL);
1304 case CODEC_ID_FRAPS:
1306 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1312 case CODEC_ID_INTERPLAY_VIDEO:
1318 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1319 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1324 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1325 "video/x-apple-video", NULL);
1328 case CODEC_ID_CINEPAK:
1330 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1331 "video/x-cinepak", NULL);
1334 /* WS_VQA belogns here (order) */
1336 case CODEC_ID_MSRLE:
1338 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1339 "layout", G_TYPE_STRING, "microsoft", NULL);
1341 gst_caps_set_simple (caps,
1342 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1344 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1348 case CODEC_ID_QTRLE:
1350 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1351 "layout", G_TYPE_STRING, "quicktime", NULL);
1353 gst_caps_set_simple (caps,
1354 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1356 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1360 case CODEC_ID_MSVIDEO1:
1362 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1363 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1368 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1369 "wmvversion", G_TYPE_INT, 3, NULL);
1373 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1374 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1378 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1384 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1390 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1394 case CODEC_ID_TRUEMOTION1:
1396 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1397 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1399 case CODEC_ID_TRUEMOTION2:
1401 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1402 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1407 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1408 "video/x-ultimotion", NULL);
1413 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1414 "video/x-camtasia", NULL);
1416 gst_caps_set_simple (caps,
1417 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1419 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1425 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1431 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1437 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1443 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1449 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1455 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1461 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1462 "image/x-portable-anymap", NULL);
1467 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1468 "image/x-portable-graymap", NULL);
1473 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1479 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1483 case CODEC_ID_TARGA:
1485 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1491 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1495 case CODEC_ID_SUNRAST:
1497 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1498 "image/x-sun-raster", NULL);
1503 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1507 case CODEC_ID_QDRAW:
1509 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1513 case CODEC_ID_DNXHD:
1515 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1519 case CODEC_ID_PRORES:
1521 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1522 "video/x-prores", NULL);
1525 case CODEC_ID_MIMIC:
1527 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1533 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1537 case CODEC_ID_TRUESPEECH:
1539 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1540 "audio/x-truespeech", NULL);
1543 case CODEC_ID_QCELP:
1545 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1551 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1557 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1563 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1569 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1573 case CODEC_ID_LAGARITH:
1575 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1576 "video/x-lagarith", NULL);
1581 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1582 "video/x-camstudio", NULL);
1584 gst_caps_set_simple (caps,
1585 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1587 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1591 case CODEC_ID_WS_VQA:
1592 case CODEC_ID_IDCIN:
1595 case CODEC_ID_VMDVIDEO:
1596 case CODEC_ID_VMDAUDIO:
1600 case CODEC_ID_PGMYUV:
1601 case CODEC_ID_FFVHUFF:
1603 case CODEC_ID_MP3ADU:
1604 case CODEC_ID_MP3ON4:
1605 case CODEC_ID_WESTWOOD_SND1:
1606 case CODEC_ID_MMVIDEO:
1612 /* weird quasi-codecs for the demuxers only */
1613 case CODEC_ID_PCM_S16LE:
1614 case CODEC_ID_PCM_S16BE:
1615 case CODEC_ID_PCM_U16LE:
1616 case CODEC_ID_PCM_U16BE:
1617 case CODEC_ID_PCM_S8:
1618 case CODEC_ID_PCM_U8:
1620 GstAudioFormat format;
1623 case CODEC_ID_PCM_S16LE:
1624 format = GST_AUDIO_FORMAT_S16LE;
1626 case CODEC_ID_PCM_S16BE:
1627 format = GST_AUDIO_FORMAT_S16BE;
1629 case CODEC_ID_PCM_U16LE:
1630 format = GST_AUDIO_FORMAT_U16LE;
1632 case CODEC_ID_PCM_U16BE:
1633 format = GST_AUDIO_FORMAT_U16BE;
1635 case CODEC_ID_PCM_S8:
1636 format = GST_AUDIO_FORMAT_S8;
1638 case CODEC_ID_PCM_U8:
1639 format = GST_AUDIO_FORMAT_U8;
1642 g_assert (0); /* don't worry, we never get here */
1647 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1648 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1649 "layout", G_TYPE_STRING, "interleaved", NULL);
1653 case CODEC_ID_PCM_MULAW:
1655 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1659 case CODEC_ID_PCM_ALAW:
1661 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1665 case CODEC_ID_ADPCM_G722:
1667 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1670 gst_caps_set_simple (caps,
1671 "block_align", G_TYPE_INT, context->block_align,
1672 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1675 case CODEC_ID_ADPCM_G726:
1677 /* the G726 decoder can also handle G721 */
1679 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1680 "layout", G_TYPE_STRING, "g726", NULL);
1682 gst_caps_set_simple (caps,
1683 "block_align", G_TYPE_INT, context->block_align,
1684 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1687 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1688 "layout", G_TYPE_STRING, "g721",
1689 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1693 case CODEC_ID_ADPCM_IMA_QT:
1694 case CODEC_ID_ADPCM_IMA_WAV:
1695 case CODEC_ID_ADPCM_IMA_DK3:
1696 case CODEC_ID_ADPCM_IMA_DK4:
1697 case CODEC_ID_ADPCM_IMA_WS:
1698 case CODEC_ID_ADPCM_IMA_SMJPEG:
1699 case CODEC_ID_ADPCM_IMA_AMV:
1700 case CODEC_ID_ADPCM_IMA_ISS:
1701 case CODEC_ID_ADPCM_IMA_EA_EACS:
1702 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1703 case CODEC_ID_ADPCM_MS:
1704 case CODEC_ID_ADPCM_4XM:
1705 case CODEC_ID_ADPCM_XA:
1706 case CODEC_ID_ADPCM_ADX:
1707 case CODEC_ID_ADPCM_EA:
1708 case CODEC_ID_ADPCM_CT:
1709 case CODEC_ID_ADPCM_SWF:
1710 case CODEC_ID_ADPCM_YAMAHA:
1711 case CODEC_ID_ADPCM_SBPRO_2:
1712 case CODEC_ID_ADPCM_SBPRO_3:
1713 case CODEC_ID_ADPCM_SBPRO_4:
1714 case CODEC_ID_ADPCM_EA_R1:
1715 case CODEC_ID_ADPCM_EA_R2:
1716 case CODEC_ID_ADPCM_EA_R3:
1717 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1718 case CODEC_ID_ADPCM_EA_XAS:
1719 case CODEC_ID_ADPCM_THP:
1721 const gchar *layout = NULL;
1724 case CODEC_ID_ADPCM_IMA_QT:
1725 layout = "quicktime";
1727 case CODEC_ID_ADPCM_IMA_WAV:
1730 case CODEC_ID_ADPCM_IMA_DK3:
1733 case CODEC_ID_ADPCM_IMA_DK4:
1736 case CODEC_ID_ADPCM_IMA_WS:
1737 layout = "westwood";
1739 case CODEC_ID_ADPCM_IMA_SMJPEG:
1742 case CODEC_ID_ADPCM_IMA_AMV:
1745 case CODEC_ID_ADPCM_IMA_ISS:
1748 case CODEC_ID_ADPCM_IMA_EA_EACS:
1751 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1754 case CODEC_ID_ADPCM_MS:
1755 layout = "microsoft";
1757 case CODEC_ID_ADPCM_4XM:
1760 case CODEC_ID_ADPCM_XA:
1763 case CODEC_ID_ADPCM_ADX:
1766 case CODEC_ID_ADPCM_EA:
1769 case CODEC_ID_ADPCM_CT:
1772 case CODEC_ID_ADPCM_SWF:
1775 case CODEC_ID_ADPCM_YAMAHA:
1778 case CODEC_ID_ADPCM_SBPRO_2:
1781 case CODEC_ID_ADPCM_SBPRO_3:
1784 case CODEC_ID_ADPCM_SBPRO_4:
1787 case CODEC_ID_ADPCM_EA_R1:
1790 case CODEC_ID_ADPCM_EA_R2:
1793 case CODEC_ID_ADPCM_EA_R3:
1796 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1797 layout = "ea-maxis-xa";
1799 case CODEC_ID_ADPCM_EA_XAS:
1802 case CODEC_ID_ADPCM_THP:
1806 g_assert (0); /* don't worry, we never get here */
1810 /* FIXME: someone please check whether we need additional properties
1811 * in this caps definition. */
1813 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1814 "layout", G_TYPE_STRING, layout, NULL);
1816 gst_caps_set_simple (caps,
1817 "block_align", G_TYPE_INT, context->block_align,
1818 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1822 case CODEC_ID_AMR_NB:
1824 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1828 case CODEC_ID_AMR_WB:
1830 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1836 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1840 case CODEC_ID_GSM_MS:
1842 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1846 case CODEC_ID_NELLYMOSER:
1848 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1849 "audio/x-nellymoser", NULL);
1855 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1858 gst_caps_set_simple (caps,
1859 "leaf_size", G_TYPE_INT, context->block_align,
1860 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1865 case CODEC_ID_RA_144:
1866 case CODEC_ID_RA_288:
1872 case CODEC_ID_RA_144:
1875 case CODEC_ID_RA_288:
1885 /* FIXME: properties? */
1887 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1888 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1890 gst_caps_set_simple (caps,
1891 "leaf_size", G_TYPE_INT, context->block_align,
1892 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1897 case CODEC_ID_ROQ_DPCM:
1898 case CODEC_ID_INTERPLAY_DPCM:
1899 case CODEC_ID_XAN_DPCM:
1900 case CODEC_ID_SOL_DPCM:
1902 const gchar *layout = NULL;
1905 case CODEC_ID_ROQ_DPCM:
1908 case CODEC_ID_INTERPLAY_DPCM:
1909 layout = "interplay";
1911 case CODEC_ID_XAN_DPCM:
1914 case CODEC_ID_SOL_DPCM:
1918 g_assert (0); /* don't worry, we never get here */
1922 /* FIXME: someone please check whether we need additional properties
1923 * in this caps definition. */
1925 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1926 "layout", G_TYPE_STRING, layout, NULL);
1928 gst_caps_set_simple (caps,
1929 "block_align", G_TYPE_INT, context->block_align,
1930 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1934 case CODEC_ID_SHORTEN:
1935 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1940 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1943 gst_caps_set_simple (caps,
1944 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1949 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1950 * encoder case, we want to add things like samplerate, channels... */
1952 caps = gst_caps_new_empty_simple ("audio/x-flac");
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 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2125 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2127 GstCaps *caps = NULL;
2129 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2130 context, codec_id, encode, codec);
2132 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2133 codec->sample_fmts, codec->supported_samplerates);
2136 /* Specific codec context */
2138 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2141 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2142 "layout", G_TYPE_STRING, "interleaved", NULL);
2149 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2150 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2154 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2155 context, codec_id, encode, codec);
2158 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2161 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2167 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2168 * and other audio properties in a AVCodecContext.
2170 * For usefullness, see below
2174 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2175 AVCodecContext * context, gboolean raw)
2177 GstStructure *structure;
2179 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2181 g_return_if_fail (gst_caps_get_size (caps) == 1);
2183 structure = gst_caps_get_structure (caps, 0);
2185 gst_structure_get_int (structure, "channels", &context->channels);
2186 gst_structure_get_int (structure, "rate", &context->sample_rate);
2187 gst_structure_get_int (structure, "block_align", &context->block_align);
2188 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2193 if (gst_structure_has_name (structure, "audio/x-raw")) {
2194 if ((fmt = gst_structure_get_string (structure, "format"))) {
2195 format = gst_audio_format_from_string (fmt);
2200 case GST_AUDIO_FORMAT_F32:
2201 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2203 case GST_AUDIO_FORMAT_F64:
2204 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2206 case GST_AUDIO_FORMAT_S32:
2207 context->sample_fmt = AV_SAMPLE_FMT_S32;
2209 case GST_AUDIO_FORMAT_S16:
2210 context->sample_fmt = AV_SAMPLE_FMT_S16;
2217 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2218 * and other video properties in a AVCodecContext.
2220 * For usefullness, see below
2224 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2225 AVCodecContext * context, gboolean raw)
2227 GstStructure *structure;
2229 const GValue *par = NULL;
2231 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2233 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2234 g_return_if_fail (gst_caps_get_size (caps) == 1);
2235 structure = gst_caps_get_structure (caps, 0);
2237 gst_structure_get_int (structure, "width", &context->width);
2238 gst_structure_get_int (structure, "height", &context->height);
2239 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2241 fps = gst_structure_get_value (structure, "framerate");
2242 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2244 /* somehow these seem mixed up.. */
2245 context->time_base.den = gst_value_get_fraction_numerator (fps);
2246 context->time_base.num = gst_value_get_fraction_denominator (fps);
2247 context->ticks_per_frame = 1;
2249 GST_DEBUG ("setting framerate %d/%d = %lf",
2250 context->time_base.den, context->time_base.num,
2251 1. * context->time_base.den / context->time_base.num);
2254 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2255 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2257 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2258 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2260 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2261 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2262 1. * context->sample_aspect_ratio.den /
2263 context->sample_aspect_ratio.num);
2269 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2271 if (gst_structure_has_name (structure, "video/x-raw")) {
2272 if ((fmt = gst_structure_get_string (structure, "format"))) {
2273 format = gst_video_format_from_string (fmt);
2278 case GST_VIDEO_FORMAT_YUY2:
2279 context->pix_fmt = PIX_FMT_YUYV422;
2281 case GST_VIDEO_FORMAT_I420:
2282 context->pix_fmt = PIX_FMT_YUV420P;
2284 case GST_VIDEO_FORMAT_A420:
2285 context->pix_fmt = PIX_FMT_YUVA420P;
2287 case GST_VIDEO_FORMAT_Y41B:
2288 context->pix_fmt = PIX_FMT_YUV411P;
2290 case GST_VIDEO_FORMAT_Y42B:
2291 context->pix_fmt = PIX_FMT_YUV422P;
2293 case GST_VIDEO_FORMAT_YUV9:
2294 context->pix_fmt = PIX_FMT_YUV410P;
2296 case GST_VIDEO_FORMAT_Y444:
2297 context->pix_fmt = PIX_FMT_YUV444P;
2299 case GST_VIDEO_FORMAT_GRAY8:
2300 context->pix_fmt = PIX_FMT_GRAY8;
2302 case GST_VIDEO_FORMAT_xRGB:
2303 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2304 context->pix_fmt = PIX_FMT_RGB32;
2307 case GST_VIDEO_FORMAT_BGRx:
2308 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2309 context->pix_fmt = PIX_FMT_RGB32;
2312 case GST_VIDEO_FORMAT_RGB:
2313 context->pix_fmt = PIX_FMT_RGB24;
2315 case GST_VIDEO_FORMAT_BGR:
2316 context->pix_fmt = PIX_FMT_BGR24;
2318 case GST_VIDEO_FORMAT_RGB16:
2319 context->pix_fmt = PIX_FMT_RGB565;
2321 case GST_VIDEO_FORMAT_RGB15:
2322 context->pix_fmt = PIX_FMT_RGB555;
2324 case GST_VIDEO_FORMAT_RGB8P:
2325 context->pix_fmt = PIX_FMT_PAL8;
2334 GstVideoFormat format;
2335 enum PixelFormat pixfmt;
2338 /* FIXME : FILLME */
2339 static const PixToFmt pixtofmttable[] = {
2340 /* GST_VIDEO_FORMAT_I420, */
2341 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2342 /* Note : this should use a different chroma placement */
2343 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2345 /* GST_VIDEO_FORMAT_YV12, */
2346 /* GST_VIDEO_FORMAT_YUY2, */
2347 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2348 /* GST_VIDEO_FORMAT_UYVY, */
2349 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2350 /* GST_VIDEO_FORMAT_AYUV, */
2351 /* GST_VIDEO_FORMAT_RGBx, */
2352 /* GST_VIDEO_FORMAT_BGRx, */
2353 /* GST_VIDEO_FORMAT_xRGB, */
2354 /* GST_VIDEO_FORMAT_xBGR, */
2355 /* GST_VIDEO_FORMAT_RGBA, */
2356 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2357 /* GST_VIDEO_FORMAT_BGRA, */
2358 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2359 /* GST_VIDEO_FORMAT_ARGB, */
2360 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2361 /* GST_VIDEO_FORMAT_ABGR, */
2362 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2363 /* GST_VIDEO_FORMAT_RGB, */
2364 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2365 /* GST_VIDEO_FORMAT_BGR, */
2366 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2367 /* GST_VIDEO_FORMAT_Y41B, */
2368 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2369 /* GST_VIDEO_FORMAT_Y42B, */
2370 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2371 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2372 /* GST_VIDEO_FORMAT_YVYU, */
2373 /* GST_VIDEO_FORMAT_Y444, */
2374 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2375 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2376 /* GST_VIDEO_FORMAT_v210, */
2377 /* GST_VIDEO_FORMAT_v216, */
2378 /* GST_VIDEO_FORMAT_NV12, */
2379 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2380 /* GST_VIDEO_FORMAT_NV21, */
2381 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2382 /* GST_VIDEO_FORMAT_GRAY8, */
2383 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2384 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2385 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2386 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2387 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2388 /* GST_VIDEO_FORMAT_v308, */
2389 /* GST_VIDEO_FORMAT_Y800, */
2390 /* GST_VIDEO_FORMAT_Y16, */
2391 /* GST_VIDEO_FORMAT_RGB16, */
2392 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2393 /* GST_VIDEO_FORMAT_BGR16, */
2394 /* GST_VIDEO_FORMAT_RGB15, */
2395 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2396 /* GST_VIDEO_FORMAT_BGR15, */
2397 /* GST_VIDEO_FORMAT_UYVP, */
2398 /* GST_VIDEO_FORMAT_A420, */
2399 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2400 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2401 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2402 /* GST_VIDEO_FORMAT_YUV9, */
2403 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2404 /* GST_VIDEO_FORMAT_YVU9, */
2405 /* GST_VIDEO_FORMAT_IYU1, */
2406 /* GST_VIDEO_FORMAT_ARGB64, */
2407 /* GST_VIDEO_FORMAT_AYUV64, */
2408 /* GST_VIDEO_FORMAT_r210, */
2409 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2410 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2411 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2412 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2413 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2414 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2415 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2416 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2417 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2421 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2425 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2426 if (pixtofmttable[i].pixfmt == pixfmt)
2427 return pixtofmttable[i].format;
2429 GST_WARNING ("Unknown pixel format %d", pixfmt);
2430 return GST_VIDEO_FORMAT_UNKNOWN;
2434 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2438 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2439 if (pixtofmttable[i].format == format)
2440 return pixtofmttable[i].pixfmt;
2441 return PIX_FMT_NONE;
2445 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2449 context->width = GST_VIDEO_INFO_WIDTH (info);
2450 context->height = GST_VIDEO_INFO_HEIGHT (info);
2451 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2452 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2453 context->bits_per_coded_sample = bpp;
2455 context->ticks_per_frame = 1;
2456 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2457 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2459 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2460 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2463 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2467 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2469 const AVCodec *codec;
2470 const enum AVSampleFormat *smpl_fmts;
2471 enum AVSampleFormat smpl_fmt = -1;
2473 context->channels = info->channels;
2474 context->sample_rate = info->rate;
2475 context->channel_layout =
2476 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2478 codec = context->codec;
2480 smpl_fmts = codec->sample_fmts;
2482 switch (info->finfo->format) {
2483 case GST_AUDIO_FORMAT_F32:
2485 while (*smpl_fmts != -1) {
2486 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2487 smpl_fmt = *smpl_fmts;
2489 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2490 smpl_fmt = *smpl_fmts;
2496 smpl_fmt = AV_SAMPLE_FMT_FLT;
2499 case GST_AUDIO_FORMAT_F64:
2501 while (*smpl_fmts != -1) {
2502 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2503 smpl_fmt = *smpl_fmts;
2505 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2506 smpl_fmt = *smpl_fmts;
2512 smpl_fmt = AV_SAMPLE_FMT_DBL;
2515 case GST_AUDIO_FORMAT_S32:
2517 while (*smpl_fmts != -1) {
2518 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2519 smpl_fmt = *smpl_fmts;
2521 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2522 smpl_fmt = *smpl_fmts;
2528 smpl_fmt = AV_SAMPLE_FMT_S32;
2531 case GST_AUDIO_FORMAT_S16:
2533 while (*smpl_fmts != -1) {
2534 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2535 smpl_fmt = *smpl_fmts;
2537 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2538 smpl_fmt = *smpl_fmts;
2544 smpl_fmt = AV_SAMPLE_FMT_S16;
2547 case GST_AUDIO_FORMAT_U8:
2549 while (*smpl_fmts != -1) {
2550 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2551 smpl_fmt = *smpl_fmts;
2553 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2554 smpl_fmt = *smpl_fmts;
2560 smpl_fmt = AV_SAMPLE_FMT_U8;
2567 g_assert (smpl_fmt != -1);
2569 context->sample_fmt = smpl_fmt;
2572 /* Convert a GstCaps and a FFMPEG codec Type to a
2573 * AVCodecContext. If the context is ommitted, no fixed values
2574 * for video/audio size will be included in the context
2576 * AVMediaType is primarily meant for uncompressed data GstCaps!
2580 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2581 const GstCaps * caps, AVCodecContext * context)
2583 if (context == NULL)
2587 case AVMEDIA_TYPE_VIDEO:
2588 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2591 case AVMEDIA_TYPE_AUDIO:
2592 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2603 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2607 guint8 *end = src + size;
2610 while (srcp < end) {
2611 if (count == 2 && *srcp <= 0x03) {
2612 GST_DEBUG ("added escape code");
2621 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2624 *destsize = dstp - dst;
2627 /* copy the config, escaping NAL units as we iterate them, if something fails we
2628 * copy everything and hope for the best. */
2630 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2635 guint nalsize, esize;
2645 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2647 GST_DEBUG ("num SPS %d", cnt);
2649 memcpy (dstp, srcp, 6);
2653 for (i = 0; i < cnt; i++) {
2654 GST_DEBUG ("copy SPS %d", i);
2655 nalsize = (srcp[0] << 8) | srcp[1];
2656 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2657 dstp[0] = esize >> 8;
2658 dstp[1] = esize & 0xff;
2660 srcp += nalsize + 2;
2663 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2665 GST_DEBUG ("num PPS %d", cnt);
2667 for (i = 0; i < cnt; i++) {
2668 GST_DEBUG ("copy PPS %d", i);
2669 nalsize = (srcp[0] << 8) | srcp[1];
2670 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2671 dstp[0] = esize >> 8;
2672 dstp[1] = esize & 0xff;
2674 srcp += nalsize + 2;
2676 *destsize = dstp - dst;
2682 GST_DEBUG ("something unexpected, doing full copy");
2683 memcpy (dst, src, size);
2691 * caps_with_codecid () transforms a GstCaps for a known codec
2692 * ID into a filled-in context.
2693 * codec_data from caps will override possible extradata already in the context
2697 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2698 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2701 const GValue *value;
2704 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2705 codec_id, codec_type, caps, context);
2707 if (!context || !gst_caps_get_size (caps))
2710 str = gst_caps_get_structure (caps, 0);
2712 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2713 if ((value = gst_structure_get_value (str, "codec_data"))) {
2716 buf = gst_value_get_buffer (value);
2717 gst_buffer_map (buf, &map, GST_MAP_READ);
2719 /* free the old one if it is there */
2720 if (context->extradata)
2721 av_free (context->extradata);
2724 if (codec_id == CODEC_ID_H264) {
2727 GST_DEBUG ("copy, escaping codec_data %d", size);
2728 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2729 * reason for this but let's just escape it for now. Start by allocating
2730 * enough space, x2 is more than enough.
2732 * FIXME, we disabled escaping because some file already contain escaped
2733 * codec_data and then we escape twice and fail. It's better to leave it
2734 * as is, as that is what most players do. */
2735 context->extradata =
2736 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2737 FF_INPUT_BUFFER_PADDING_SIZE));
2738 copy_config (context->extradata, data, size, &extrasize);
2739 GST_DEBUG ("escaped size: %d", extrasize);
2740 context->extradata_size = extrasize;
2744 /* allocate with enough padding */
2745 GST_DEBUG ("copy codec_data");
2746 context->extradata =
2747 av_mallocz (GST_ROUND_UP_16 (map.size +
2748 FF_INPUT_BUFFER_PADDING_SIZE));
2749 memcpy (context->extradata, map.data, map.size);
2750 context->extradata_size = map.size;
2753 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2754 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2755 context->extradata[0] = (guint8) map.size;
2758 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2760 gst_buffer_unmap (buf, &map);
2761 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2762 codec_id != CODEC_ID_FLAC) {
2763 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2764 * extradata anyway which makes then segfault. */
2765 context->extradata =
2766 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2767 context->extradata_size = 0;
2768 GST_DEBUG ("no codec data");
2772 case CODEC_ID_MPEG4:
2774 const gchar *mime = gst_structure_get_name (str);
2776 if (!strcmp (mime, "video/x-divx"))
2777 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2778 else if (!strcmp (mime, "video/x-xvid"))
2779 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2780 else if (!strcmp (mime, "video/x-3ivx"))
2781 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2782 else if (!strcmp (mime, "video/mpeg"))
2783 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2788 /* FIXME: this is a workaround for older gst-plugins releases
2789 * (<= 0.8.9). This should be removed at some point, because
2790 * it causes wrong decoded frame order. */
2791 if (!context->extradata) {
2792 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2795 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2796 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2797 gst_structure_get_int (str, "low_delay", &low_delay) ||
2798 gst_structure_get_int (str, "unknown_svq3_flag",
2799 &unknown_svq3_flag)) {
2800 context->extradata = (guint8 *) av_mallocz (0x64);
2801 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2805 flags |= unknown_svq3_flag;
2807 flags |= halfpel_flag;
2809 flags |= thirdpel_flag;
2812 flags = GUINT16_FROM_LE (flags);
2814 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2815 context->extradata_size = 0x64;
2820 case CODEC_ID_MSRLE:
2821 case CODEC_ID_QTRLE:
2828 if (gst_structure_get_int (str, "depth", &depth)) {
2829 context->bits_per_coded_sample = depth;
2831 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2844 if (gst_structure_get_int (str, "format", &format))
2845 context->sub_id = format;
2850 case CODEC_ID_RA_288:
2851 case CODEC_ID_RA_144:
2857 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2858 context->block_align = leaf_size;
2859 if (gst_structure_get_int (str, "bitrate", &bitrate))
2860 context->bit_rate = bitrate;
2863 gst_structure_get_int (str, "samplesize",
2864 &context->bits_per_coded_sample);
2867 case CODEC_ID_DVVIDEO:
2869 const gchar *format;
2871 if ((format = gst_structure_get_string (str, "format"))) {
2873 if (g_str_equal (format, "YUY2"))
2874 context->pix_fmt = PIX_FMT_YUYV422;
2875 else if (g_str_equal (format, "I420"))
2876 context->pix_fmt = PIX_FMT_YUV420P;
2877 else if (g_str_equal (format, "A420"))
2878 context->pix_fmt = PIX_FMT_YUVA420P;
2879 else if (g_str_equal (format, "Y41B"))
2880 context->pix_fmt = PIX_FMT_YUV411P;
2881 else if (g_str_equal (format, "Y42B"))
2882 context->pix_fmt = PIX_FMT_YUV422P;
2883 else if (g_str_equal (format, "YUV9"))
2884 context->pix_fmt = PIX_FMT_YUV410P;
2886 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2890 GST_WARNING ("No specified format");
2893 case CODEC_ID_H263P:
2897 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2898 context->flags |= CODEC_FLAG_4MV;
2900 context->flags &= ~CODEC_FLAG_4MV;
2901 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2902 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2903 context->flags |= CODEC_FLAG_AC_PRED;
2905 context->flags &= ~CODEC_FLAG_AC_PRED;
2906 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2907 context->flags |= CODEC_FLAG_LOOP_FILTER;
2909 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2912 case CODEC_ID_ADPCM_G726:
2914 const gchar *layout;
2916 if ((layout = gst_structure_get_string (str, "layout"))) {
2917 if (!strcmp (layout, "g721")) {
2918 context->sample_rate = 8000;
2919 context->channels = 1;
2920 context->bit_rate = 32000;
2929 if (!gst_caps_is_fixed (caps))
2932 /* common properties (width, height, fps) */
2933 switch (codec_type) {
2934 case AVMEDIA_TYPE_VIDEO:
2935 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2937 case AVMEDIA_TYPE_AUDIO:
2938 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2944 /* fixup of default settings */
2946 case CODEC_ID_QCELP:
2947 /* QCELP is always mono, no matter what the caps say */
2948 context->channels = 1;
2950 case CODEC_ID_ADPCM_G726:
2951 if (context->sample_rate && context->bit_rate)
2952 context->bits_per_coded_sample =
2953 context->bit_rate / context->sample_rate;
2960 /* _formatid_to_caps () is meant for muxers/demuxers, it
2961 * transforms a name (ffmpeg way of ID'ing these, why don't
2962 * they have unique numerical IDs?) to the corresponding
2963 * caps belonging to that mux-format
2965 * Note: we don't need any additional info because the caps
2966 * isn't supposed to contain any useful info besides the
2971 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2973 GstCaps *caps = NULL;
2975 if (!strcmp (format_name, "mpeg")) {
2976 caps = gst_caps_new_simple ("video/mpeg",
2977 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2978 } else if (!strcmp (format_name, "mpegts")) {
2979 caps = gst_caps_new_simple ("video/mpegts",
2980 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2981 } else if (!strcmp (format_name, "rm")) {
2982 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2983 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2984 } else if (!strcmp (format_name, "asf")) {
2985 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2986 } else if (!strcmp (format_name, "avi")) {
2987 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2988 } else if (!strcmp (format_name, "wav")) {
2989 caps = gst_caps_new_empty_simple ("audio/x-wav");
2990 } else if (!strcmp (format_name, "ape")) {
2991 caps = gst_caps_new_empty_simple ("application/x-ape");
2992 } else if (!strcmp (format_name, "swf")) {
2993 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2994 } else if (!strcmp (format_name, "au")) {
2995 caps = gst_caps_new_empty_simple ("audio/x-au");
2996 } else if (!strcmp (format_name, "dv")) {
2997 caps = gst_caps_new_simple ("video/x-dv",
2998 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2999 } else if (!strcmp (format_name, "4xm")) {
3000 caps = gst_caps_new_empty_simple ("video/x-4xm");
3001 } else if (!strcmp (format_name, "matroska")) {
3002 caps = gst_caps_new_empty_simple ("video/x-matroska");
3003 } else if (!strcmp (format_name, "mp3")) {
3004 caps = gst_caps_new_empty_simple ("application/x-id3");
3005 } else if (!strcmp (format_name, "flic")) {
3006 caps = gst_caps_new_empty_simple ("video/x-fli");
3007 } else if (!strcmp (format_name, "flv")) {
3008 caps = gst_caps_new_empty_simple ("video/x-flv");
3009 } else if (!strcmp (format_name, "tta")) {
3010 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3011 } else if (!strcmp (format_name, "aiff")) {
3012 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3013 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3015 gst_caps_from_string
3016 ("application/x-3gp; video/quicktime; audio/x-m4a");
3017 } else if (!strcmp (format_name, "mov")) {
3018 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3019 } else if (!strcmp (format_name, "mp4")) {
3020 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3021 } else if (!strcmp (format_name, "3gp")) {
3022 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3023 } else if (!strcmp (format_name, "3g2")) {
3024 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3025 } else if (!strcmp (format_name, "psp")) {
3026 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3027 } else if (!strcmp (format_name, "ipod")) {
3028 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3029 } else if (!strcmp (format_name, "aac")) {
3030 caps = gst_caps_new_simple ("audio/mpeg",
3031 "mpegversion", G_TYPE_INT, 4, NULL);
3032 } else if (!strcmp (format_name, "gif")) {
3033 caps = gst_caps_from_string ("image/gif");
3034 } else if (!strcmp (format_name, "ogg")) {
3035 caps = gst_caps_from_string ("application/ogg");
3036 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3037 caps = gst_caps_from_string ("application/mxf");
3038 } else if (!strcmp (format_name, "gxf")) {
3039 caps = gst_caps_from_string ("application/gxf");
3040 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3041 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3042 "y4mversion", G_TYPE_INT, 2, NULL);
3043 } else if (!strcmp (format_name, "mpc")) {
3044 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3045 } else if (!strcmp (format_name, "vqf")) {
3046 caps = gst_caps_from_string ("audio/x-vqf");
3047 } else if (!strcmp (format_name, "nsv")) {
3048 caps = gst_caps_from_string ("video/x-nsv");
3049 } else if (!strcmp (format_name, "amr")) {
3050 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3051 } else if (!strcmp (format_name, "webm")) {
3052 caps = gst_caps_from_string ("video/webm");
3053 } else if (!strcmp (format_name, "voc")) {
3054 caps = gst_caps_from_string ("audio/x-voc");
3058 GST_LOG ("Could not create stream format caps for %s", format_name);
3059 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3060 caps = gst_caps_new_empty_simple (name);
3068 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3069 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3070 AVOutputFormat * plugin)
3072 static enum CodecID tmp_vlist[] = {
3076 static enum CodecID tmp_alist[] = {
3081 GST_LOG ("format_name : %s", format_name);
3083 if (!strcmp (format_name, "mp4")) {
3084 static enum CodecID mp4_video_list[] = {
3085 CODEC_ID_MPEG4, CODEC_ID_H264,
3089 static enum CodecID mp4_audio_list[] = {
3090 CODEC_ID_AAC, CODEC_ID_MP3,
3094 *video_codec_list = mp4_video_list;
3095 *audio_codec_list = mp4_audio_list;
3096 } else if (!strcmp (format_name, "mpeg")) {
3097 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
3098 CODEC_ID_MPEG2VIDEO,
3102 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
3108 *video_codec_list = mpeg_video_list;
3109 *audio_codec_list = mpeg_audio_list;
3110 } else if (!strcmp (format_name, "dvd")) {
3111 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
3114 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
3121 *video_codec_list = mpeg_video_list;
3122 *audio_codec_list = mpeg_audio_list;
3123 } else if (!strcmp (format_name, "mpegts")) {
3124 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
3125 CODEC_ID_MPEG2VIDEO,
3129 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
3137 *video_codec_list = mpegts_video_list;
3138 *audio_codec_list = mpegts_audio_list;
3139 } else if (!strcmp (format_name, "vob")) {
3140 static enum CodecID vob_video_list[] =
3141 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
3142 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
3143 CODEC_ID_DTS, CODEC_ID_NONE
3146 *video_codec_list = vob_video_list;
3147 *audio_codec_list = vob_audio_list;
3148 } else if (!strcmp (format_name, "flv")) {
3149 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
3150 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
3152 *video_codec_list = flv_video_list;
3153 *audio_codec_list = flv_audio_list;
3154 } else if (!strcmp (format_name, "asf")) {
3155 static enum CodecID asf_video_list[] =
3156 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
3157 static enum CodecID asf_audio_list[] =
3158 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
3160 *video_codec_list = asf_video_list;
3161 *audio_codec_list = asf_audio_list;
3162 } else if (!strcmp (format_name, "dv")) {
3163 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
3164 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
3166 *video_codec_list = dv_video_list;
3167 *audio_codec_list = dv_audio_list;
3168 } else if (!strcmp (format_name, "mov")) {
3169 static enum CodecID mov_video_list[] = {
3170 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
3171 CODEC_ID_H263, CODEC_ID_H263P,
3172 CODEC_ID_H264, CODEC_ID_DVVIDEO,
3176 static enum CodecID mov_audio_list[] = {
3177 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
3178 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
3179 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3180 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
3181 CODEC_ID_MP3, CODEC_ID_NONE
3184 *video_codec_list = mov_video_list;
3185 *audio_codec_list = mov_audio_list;
3186 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3187 static enum CodecID tgp_video_list[] = {
3188 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
3191 static enum CodecID tgp_audio_list[] = {
3192 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3197 *video_codec_list = tgp_video_list;
3198 *audio_codec_list = tgp_audio_list;
3199 } else if (!strcmp (format_name, "mmf")) {
3200 static enum CodecID mmf_audio_list[] = {
3201 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
3203 *video_codec_list = NULL;
3204 *audio_codec_list = mmf_audio_list;
3205 } else if (!strcmp (format_name, "amr")) {
3206 static enum CodecID amr_audio_list[] = {
3207 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
3210 *video_codec_list = NULL;
3211 *audio_codec_list = amr_audio_list;
3212 } else if (!strcmp (format_name, "gif")) {
3213 static enum CodecID gif_image_list[] = {
3214 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
3216 *video_codec_list = gif_image_list;
3217 *audio_codec_list = NULL;
3218 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
3219 (plugin->video_codec != CODEC_ID_NONE)) {
3220 tmp_vlist[0] = plugin->video_codec;
3221 tmp_alist[0] = plugin->audio_codec;
3223 *video_codec_list = tmp_vlist;
3224 *audio_codec_list = tmp_alist;
3226 GST_LOG ("Format %s not found", format_name);
3233 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3234 * are omitted, that can be queried by the user itself,
3235 * we're not eating the GstCaps or anything
3236 * A pointer to an allocated context is also needed for
3237 * optional extra info
3241 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3243 enum CodecID id = CODEC_ID_NONE;
3244 const gchar *mimetype;
3245 const GstStructure *structure;
3246 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3248 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
3249 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
3250 structure = gst_caps_get_structure (caps, 0);
3252 mimetype = gst_structure_get_name (structure);
3254 if (!strcmp (mimetype, "video/x-raw")) {
3255 id = CODEC_ID_RAWVIDEO;
3257 } else if (!strcmp (mimetype, "audio/x-raw")) {
3260 if (gst_audio_info_from_caps (&info, caps)) {
3261 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3262 case GST_AUDIO_FORMAT_S8:
3263 id = CODEC_ID_PCM_S8;
3265 case GST_AUDIO_FORMAT_U8:
3266 id = CODEC_ID_PCM_U8;
3268 case GST_AUDIO_FORMAT_S16LE:
3269 id = CODEC_ID_PCM_S16LE;
3271 case GST_AUDIO_FORMAT_S16BE:
3272 id = CODEC_ID_PCM_S16BE;
3274 case GST_AUDIO_FORMAT_U16LE:
3275 id = CODEC_ID_PCM_U16LE;
3277 case GST_AUDIO_FORMAT_U16BE:
3278 id = CODEC_ID_PCM_U16BE;
3283 if (id != CODEC_ID_NONE)
3286 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3287 id = CODEC_ID_PCM_MULAW;
3289 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3290 id = CODEC_ID_PCM_ALAW;
3292 } else if (!strcmp (mimetype, "video/x-dv")) {
3295 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3297 id = CODEC_ID_DVVIDEO;
3300 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3301 id = CODEC_ID_DVAUDIO;
3303 } else if (!strcmp (mimetype, "video/x-h263")) {
3304 const gchar *h263version =
3305 gst_structure_get_string (structure, "h263version");
3306 if (h263version && !strcmp (h263version, "h263p"))
3307 id = CODEC_ID_H263P;
3311 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3312 id = CODEC_ID_H263I;
3314 } else if (!strcmp (mimetype, "video/x-h261")) {
3317 } else if (!strcmp (mimetype, "video/mpeg")) {
3321 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3322 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3324 switch (mpegversion) {
3326 id = CODEC_ID_MPEG1VIDEO;
3329 id = CODEC_ID_MPEG2VIDEO;
3332 id = CODEC_ID_MPEG4;
3336 if (id != CODEC_ID_NONE)
3338 } else if (!strcmp (mimetype, "image/jpeg")) {
3339 id = CODEC_ID_MJPEG; /* A... B... */
3341 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3342 id = CODEC_ID_MJPEGB;
3344 } else if (!strcmp (mimetype, "video/x-wmv")) {
3345 gint wmvversion = 0;
3347 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3348 switch (wmvversion) {
3357 const gchar *format;
3359 /* WMV3 unless the fourcc exists and says otherwise */
3362 if ((format = gst_structure_get_string (structure, "format")) &&
3363 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3370 if (id != CODEC_ID_NONE)
3372 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3373 id = CODEC_ID_VORBIS;
3375 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3378 } else if (!strcmp (mimetype, "audio/mpeg")) {
3380 gint mpegversion = 0;
3382 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3383 switch (mpegversion) {
3384 case 2: /* ffmpeg uses faad for both... */
3389 if (gst_structure_get_int (structure, "layer", &layer)) {
3404 if (id != CODEC_ID_NONE)
3406 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3407 gint streamversion = -1;
3409 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3410 if (streamversion == 7)
3411 id = CODEC_ID_MUSEPACK7;
3413 id = CODEC_ID_MUSEPACK7;
3415 } else if (!strcmp (mimetype, "audio/x-wma")) {
3416 gint wmaversion = 0;
3418 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3419 switch (wmaversion) {
3421 id = CODEC_ID_WMAV1;
3424 id = CODEC_ID_WMAV2;
3427 id = CODEC_ID_WMAPRO;
3431 if (id != CODEC_ID_NONE)
3433 } else if (!strcmp (mimetype, "audio/x-wms")) {
3434 id = CODEC_ID_WMAVOICE;
3436 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3439 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3442 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3443 !strcmp (mimetype, "audio/atrac3")) {
3444 id = CODEC_ID_ATRAC3;
3446 } else if (!strcmp (mimetype, "audio/x-dts")) {
3449 } else if (!strcmp (mimetype, "application/x-ape")) {
3452 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3453 gint msmpegversion = 0;
3455 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3456 switch (msmpegversion) {
3458 id = CODEC_ID_MSMPEG4V1;
3461 id = CODEC_ID_MSMPEG4V2;
3464 id = CODEC_ID_MSMPEG4V3;
3468 if (id != CODEC_ID_NONE)
3470 } else if (!strcmp (mimetype, "video/x-svq")) {
3471 gint svqversion = 0;
3473 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3474 switch (svqversion) {
3483 if (id != CODEC_ID_NONE)
3485 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3486 id = CODEC_ID_HUFFYUV;
3488 } else if (!strcmp (mimetype, "audio/x-mace")) {
3489 gint maceversion = 0;
3491 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3492 switch (maceversion) {
3494 id = CODEC_ID_MACE3;
3497 id = CODEC_ID_MACE6;
3501 if (id != CODEC_ID_NONE)
3503 } else if (!strcmp (mimetype, "video/x-theora")) {
3504 id = CODEC_ID_THEORA;
3506 } else if (!strcmp (mimetype, "video/x-vp3")) {
3509 } else if (!strcmp (mimetype, "video/x-vp5")) {
3512 } else if (!strcmp (mimetype, "video/x-vp6")) {
3515 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3518 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3521 } else if (!strcmp (mimetype, "video/x-vp8")) {
3524 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3525 id = CODEC_ID_FLASHSV;
3527 } else if (!strcmp (mimetype, "video/x-indeo")) {
3528 gint indeoversion = 0;
3530 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3531 switch (indeoversion) {
3533 id = CODEC_ID_INDEO5;
3536 id = CODEC_ID_INDEO4;
3539 id = CODEC_ID_INDEO3;
3542 id = CODEC_ID_INDEO2;
3545 if (id != CODEC_ID_NONE)
3548 } else if (!strcmp (mimetype, "video/x-divx")) {
3549 gint divxversion = 0;
3551 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3552 switch (divxversion) {
3554 id = CODEC_ID_MSMPEG4V3;
3558 id = CODEC_ID_MPEG4;
3562 if (id != CODEC_ID_NONE)
3564 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3565 id = CODEC_ID_MPEG4;
3567 } else if (!strcmp (mimetype, "video/x-xvid")) {
3568 id = CODEC_ID_MPEG4;
3570 } else if (!strcmp (mimetype, "video/x-ffv")) {
3571 gint ffvversion = 0;
3573 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3578 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3579 const gchar *layout;
3581 layout = gst_structure_get_string (structure, "layout");
3582 if (layout == NULL) {
3584 } else if (!strcmp (layout, "quicktime")) {
3585 id = CODEC_ID_ADPCM_IMA_QT;
3586 } else if (!strcmp (layout, "microsoft")) {
3587 id = CODEC_ID_ADPCM_MS;
3588 } else if (!strcmp (layout, "dvi")) {
3589 id = CODEC_ID_ADPCM_IMA_WAV;
3590 } else if (!strcmp (layout, "4xm")) {
3591 id = CODEC_ID_ADPCM_4XM;
3592 } else if (!strcmp (layout, "smjpeg")) {
3593 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3594 } else if (!strcmp (layout, "dk3")) {
3595 id = CODEC_ID_ADPCM_IMA_DK3;
3596 } else if (!strcmp (layout, "dk4")) {
3597 id = CODEC_ID_ADPCM_IMA_DK4;
3598 } else if (!strcmp (layout, "westwood")) {
3599 id = CODEC_ID_ADPCM_IMA_WS;
3600 } else if (!strcmp (layout, "iss")) {
3601 id = CODEC_ID_ADPCM_IMA_ISS;
3602 } else if (!strcmp (layout, "xa")) {
3603 id = CODEC_ID_ADPCM_XA;
3604 } else if (!strcmp (layout, "adx")) {
3605 id = CODEC_ID_ADPCM_ADX;
3606 } else if (!strcmp (layout, "ea")) {
3607 id = CODEC_ID_ADPCM_EA;
3608 } else if (!strcmp (layout, "g726")) {
3609 id = CODEC_ID_ADPCM_G726;
3610 } else if (!strcmp (layout, "g721")) {
3611 id = CODEC_ID_ADPCM_G726;
3612 } else if (!strcmp (layout, "ct")) {
3613 id = CODEC_ID_ADPCM_CT;
3614 } else if (!strcmp (layout, "swf")) {
3615 id = CODEC_ID_ADPCM_SWF;
3616 } else if (!strcmp (layout, "yamaha")) {
3617 id = CODEC_ID_ADPCM_YAMAHA;
3618 } else if (!strcmp (layout, "sbpro2")) {
3619 id = CODEC_ID_ADPCM_SBPRO_2;
3620 } else if (!strcmp (layout, "sbpro3")) {
3621 id = CODEC_ID_ADPCM_SBPRO_3;
3622 } else if (!strcmp (layout, "sbpro4")) {
3623 id = CODEC_ID_ADPCM_SBPRO_4;
3625 if (id != CODEC_ID_NONE)
3627 } else if (!strcmp (mimetype, "video/x-4xm")) {
3630 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3631 const gchar *layout;
3633 layout = gst_structure_get_string (structure, "layout");
3636 } else if (!strcmp (layout, "roq")) {
3637 id = CODEC_ID_ROQ_DPCM;
3638 } else if (!strcmp (layout, "interplay")) {
3639 id = CODEC_ID_INTERPLAY_DPCM;
3640 } else if (!strcmp (layout, "xan")) {
3641 id = CODEC_ID_XAN_DPCM;
3642 } else if (!strcmp (layout, "sol")) {
3643 id = CODEC_ID_SOL_DPCM;
3645 if (id != CODEC_ID_NONE)
3647 } else if (!strcmp (mimetype, "audio/x-flac")) {
3650 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3651 id = CODEC_ID_SHORTEN;
3653 } else if (!strcmp (mimetype, "audio/x-alac")) {
3656 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3657 id = CODEC_ID_CINEPAK;
3659 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3662 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3663 switch (rmversion) {
3678 if (id != CODEC_ID_NONE)
3680 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3683 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3686 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3687 switch (raversion) {
3689 id = CODEC_ID_RA_144;
3692 id = CODEC_ID_RA_288;
3699 if (id != CODEC_ID_NONE)
3701 } else if (!strcmp (mimetype, "video/x-rle")) {
3702 const gchar *layout;
3704 if ((layout = gst_structure_get_string (structure, "layout"))) {
3705 if (!strcmp (layout, "microsoft")) {
3706 id = CODEC_ID_MSRLE;
3710 } else if (!strcmp (mimetype, "video/x-xan")) {
3713 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3714 switch (wcversion) {
3716 id = CODEC_ID_XAN_WC3;
3720 id = CODEC_ID_XAN_WC4;
3727 } else if (!strcmp (mimetype, "audio/AMR")) {
3729 id = CODEC_ID_AMR_NB;
3730 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3731 id = CODEC_ID_AMR_WB;
3733 } else if (!strcmp (mimetype, "audio/qcelp")) {
3734 id = CODEC_ID_QCELP;
3736 } else if (!strcmp (mimetype, "video/x-h264")) {
3739 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3740 gint flvversion = 0;
3742 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3743 switch (flvversion) {
3753 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3754 id = CODEC_ID_NELLYMOSER;
3756 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3760 if (strlen (mimetype) <= 30 &&
3761 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3762 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3763 (codec = avcodec_find_encoder_by_name (ext))) {
3768 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3772 if (strlen (mimetype) <= 30 &&
3773 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3774 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3775 (codec = avcodec_find_encoder_by_name (ext))) {
3782 if (context != NULL) {
3783 if (video == TRUE) {
3784 context->codec_type = AVMEDIA_TYPE_VIDEO;
3785 } else if (audio == TRUE) {
3786 context->codec_type = AVMEDIA_TYPE_AUDIO;
3788 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3790 context->codec_id = id;
3791 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3794 if (id != CODEC_ID_NONE) {
3795 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3797 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);