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 */
253 case AV_CODEC_ID_H261:
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));
265 case AV_CODEC_ID_H263:
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 AV_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);
345 case AV_CODEC_ID_DNXHD:
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 */
505 case AV_CODEC_ID_AAC:
506 case AV_CODEC_ID_AAC_LATM:
507 case AV_CODEC_ID_DTS:
510 case AV_CODEC_ID_MP2:
512 const static gint l_rates[] =
513 { 48000, 44100, 32000, 24000, 22050, 16000 };
514 n_rates = G_N_ELEMENTS (l_rates);
518 case AV_CODEC_ID_EAC3:
519 case AV_CODEC_ID_AC3:
521 const static gint l_rates[] = { 48000, 44100, 32000 };
523 n_rates = G_N_ELEMENTS (l_rates);
527 case AV_CODEC_ID_ADPCM_G722:
529 const static gint l_rates[] = { 16000 };
530 n_rates = G_N_ELEMENTS (l_rates);
535 case AV_CODEC_ID_ADPCM_G726:
537 const static gint l_rates[] = { 8000 };
538 n_rates = G_N_ELEMENTS (l_rates);
543 case AV_CODEC_ID_ADPCM_SWF:
545 const static gint l_rates[] = { 11025, 22050, 44100 };
546 n_rates = G_N_ELEMENTS (l_rates);
550 case AV_CODEC_ID_ROQ_DPCM:
552 const static gint l_rates[] = { 22050 };
553 n_rates = G_N_ELEMENTS (l_rates);
557 case AV_CODEC_ID_AMR_NB:
559 const static gint l_rates[] = { 8000 };
561 n_rates = G_N_ELEMENTS (l_rates);
565 case AV_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 AV_CODEC_ID_WMAPRO:
582 case AV_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 AV_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 AV_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 AV_CODEC_ID_MPEG2VIDEO_XVMC:
722 /* this is a special ID - don't need it in GStreamer, I think */
725 case AV_CODEC_ID_H263:
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, AV_CODEC_ID_NONE, encode,
737 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
741 case AV_CODEC_ID_H263P:
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,
757 case AV_CODEC_ID_H263I:
759 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
760 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
763 case AV_CODEC_ID_H261:
765 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
769 case AV_CODEC_ID_RV10:
770 case AV_CODEC_ID_RV20:
771 case AV_CODEC_ID_RV30:
772 case AV_CODEC_ID_RV40:
777 case AV_CODEC_ID_RV40:
780 case AV_CODEC_ID_RV30:
783 case AV_CODEC_ID_RV20:
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", "rmversion", G_TYPE_INT, version, NULL);
796 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
797 if (context->extradata_size >= 8) {
798 gst_caps_set_simple (caps,
799 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
806 case AV_CODEC_ID_MP1:
808 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
809 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
812 case AV_CODEC_ID_MP2:
814 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
815 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
818 case AV_CODEC_ID_MP3:
822 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
823 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
825 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
826 * in the MPEG audio header, so may be omitted from caps. */
827 caps = gst_caps_new_simple ("audio/mpeg",
828 "mpegversion", G_TYPE_INT, 1,
829 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
833 case AV_CODEC_ID_MUSEPACK7:
835 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
836 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
840 case AV_CODEC_ID_MUSEPACK8:
842 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
843 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
847 case AV_CODEC_ID_AC3:
850 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
854 case AV_CODEC_ID_EAC3:
857 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
861 case AV_CODEC_ID_TRUEHD:
863 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
864 "audio/x-true-hd", NULL);
867 case AV_CODEC_ID_ATRAC1:
869 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
870 "audio/x-vnd.sony.atrac1", NULL);
873 case AV_CODEC_ID_ATRAC3:
875 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
876 "audio/x-vnd.sony.atrac3", NULL);
879 case AV_CODEC_ID_DTS:
881 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
885 case AV_CODEC_ID_APE:
887 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
888 "audio/x-ffmpeg-parsed-ape", NULL);
890 gst_caps_set_simple (caps,
891 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
895 case AV_CODEC_ID_MLP:
897 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
901 case AV_CODEC_ID_IMC:
903 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
907 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
908 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
909 * sp5x is, but it's apparently something JPEG... We don't separate
910 * between those in GStreamer. Should we (at least between MJPEG,
911 * MJPEG-B and sp5x decoding...)? */
912 case AV_CODEC_ID_MJPEG:
913 case AV_CODEC_ID_LJPEG:
915 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
919 case AV_CODEC_ID_SP5X:
921 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
925 case AV_CODEC_ID_MJPEGB:
927 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
928 "video/x-mjpeg-b", NULL);
931 case AV_CODEC_ID_MPEG4:
932 if (encode && context != NULL) {
933 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
934 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
935 switch (context->codec_tag) {
936 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
938 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
939 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
941 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
945 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
946 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
947 "mpegversion", G_TYPE_INT, 4, NULL);
951 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
953 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
954 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
957 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
958 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
960 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
961 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
963 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
964 encode, "video/x-xvid", NULL));
965 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
966 encode, "video/x-3ivx", NULL));
971 case AV_CODEC_ID_RAWVIDEO:
973 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
976 case AV_CODEC_ID_MSMPEG4V1:
977 case AV_CODEC_ID_MSMPEG4V2:
978 case AV_CODEC_ID_MSMPEG4V3:
980 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
982 /* encode-FIXME: bitrate */
984 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
985 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
986 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
987 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
988 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
993 case AV_CODEC_ID_WMV1:
994 case AV_CODEC_ID_WMV2:
996 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
999 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1000 "wmvversion", G_TYPE_INT, version, NULL);
1004 case AV_CODEC_ID_FLV1:
1006 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1007 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1010 case AV_CODEC_ID_SVQ1:
1012 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1013 "svqversion", G_TYPE_INT, 1, NULL);
1016 case AV_CODEC_ID_SVQ3:
1018 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1019 "svqversion", G_TYPE_INT, 3, NULL);
1022 case AV_CODEC_ID_DVAUDIO:
1024 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1028 case AV_CODEC_ID_DVVIDEO:
1030 if (encode && context) {
1031 const gchar *format;
1033 switch (context->pix_fmt) {
1034 case PIX_FMT_YUYV422:
1037 case PIX_FMT_YUV420P:
1040 case PIX_FMT_YUVA420P:
1043 case PIX_FMT_YUV411P:
1046 case PIX_FMT_YUV422P:
1049 case PIX_FMT_YUV410P:
1054 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1060 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1061 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1065 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1066 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1071 case AV_CODEC_ID_WMAV1:
1072 case AV_CODEC_ID_WMAV2:
1074 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1078 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1079 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1080 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1084 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1085 "wmaversion", G_TYPE_INT, version, "block_align",
1086 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1091 case AV_CODEC_ID_WMAPRO:
1094 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1095 "wmaversion", G_TYPE_INT, 3, NULL);
1098 case AV_CODEC_ID_WMALOSSLESS:
1100 /* libav only supports a depth of 16 at the moment */
1102 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1103 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1106 case AV_CODEC_ID_WMAVOICE:
1109 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1114 case AV_CODEC_ID_MACE3:
1115 case AV_CODEC_ID_MACE6:
1117 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1120 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1121 "maceversion", G_TYPE_INT, version, NULL);
1125 case AV_CODEC_ID_HUFFYUV:
1127 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1128 "video/x-huffyuv", NULL);
1130 gst_caps_set_simple (caps,
1131 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1135 case AV_CODEC_ID_CYUV:
1137 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1138 "video/x-compressed-yuv", NULL);
1141 case AV_CODEC_ID_H264:
1143 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1144 "alignment", G_TYPE_STRING, "au", NULL);
1147 case AV_CODEC_ID_INDEO5:
1149 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1150 "indeoversion", G_TYPE_INT, 5, NULL);
1153 case AV_CODEC_ID_INDEO4:
1155 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1156 "indeoversion", G_TYPE_INT, 4, NULL);
1159 case AV_CODEC_ID_INDEO3:
1161 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1162 "indeoversion", G_TYPE_INT, 3, NULL);
1165 case AV_CODEC_ID_INDEO2:
1167 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1168 "indeoversion", G_TYPE_INT, 2, NULL);
1171 case AV_CODEC_ID_FLASHSV:
1173 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1174 "video/x-flash-screen", NULL);
1177 case AV_CODEC_ID_VP3:
1179 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1183 case AV_CODEC_ID_VP5:
1185 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1189 case AV_CODEC_ID_VP6:
1191 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1195 case AV_CODEC_ID_VP6F:
1197 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1198 "video/x-vp6-flash", NULL);
1201 case AV_CODEC_ID_VP6A:
1203 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1204 "video/x-vp6-alpha", NULL);
1207 case AV_CODEC_ID_VP8:
1209 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1213 case AV_CODEC_ID_THEORA:
1215 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1216 "video/x-theora", NULL);
1219 case AV_CODEC_ID_AAC:
1222 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1226 GValue arr = { 0, };
1227 GValue item = { 0, };
1229 g_value_init (&arr, GST_TYPE_LIST);
1230 g_value_init (&item, G_TYPE_INT);
1231 g_value_set_int (&item, 2);
1232 gst_value_list_append_value (&arr, &item);
1233 g_value_set_int (&item, 4);
1234 gst_value_list_append_value (&arr, &item);
1235 g_value_unset (&item);
1237 gst_caps_set_value (caps, "mpegversion", &arr);
1238 g_value_unset (&arr);
1240 g_value_init (&arr, GST_TYPE_LIST);
1241 g_value_init (&item, G_TYPE_STRING);
1242 g_value_set_string (&item, "raw");
1243 gst_value_list_append_value (&arr, &item);
1244 g_value_set_string (&item, "adts");
1245 gst_value_list_append_value (&arr, &item);
1246 g_value_set_string (&item, "adif");
1247 gst_value_list_append_value (&arr, &item);
1248 g_value_unset (&item);
1250 gst_caps_set_value (caps, "stream-format", &arr);
1251 g_value_unset (&arr);
1253 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1254 "stream-format", G_TYPE_STRING, "raw",
1255 "base-profile", G_TYPE_STRING, "lc", NULL);
1257 if (context && context->extradata_size > 0)
1258 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1259 context->extradata, context->extradata_size);
1264 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1265 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1266 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1270 case AV_CODEC_ID_ASV1:
1272 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1273 "asusversion", G_TYPE_INT, 1, NULL);
1275 case AV_CODEC_ID_ASV2:
1277 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1278 "asusversion", G_TYPE_INT, 2, NULL);
1281 case AV_CODEC_ID_FFV1:
1283 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1284 "ffvversion", G_TYPE_INT, 1, NULL);
1287 case AV_CODEC_ID_4XM:
1289 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1293 case AV_CODEC_ID_XAN_WC3:
1294 case AV_CODEC_ID_XAN_WC4:
1296 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1297 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1300 case AV_CODEC_ID_CLJR:
1302 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1303 "video/x-cirrus-logic-accupak", NULL);
1306 case AV_CODEC_ID_FRAPS:
1308 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1312 case AV_CODEC_ID_MDEC:
1313 case AV_CODEC_ID_ROQ:
1314 case AV_CODEC_ID_INTERPLAY_VIDEO:
1318 case AV_CODEC_ID_VCR1:
1320 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1321 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1324 case AV_CODEC_ID_RPZA:
1326 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1327 "video/x-apple-video", NULL);
1330 case AV_CODEC_ID_CINEPAK:
1332 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1333 "video/x-cinepak", NULL);
1336 /* WS_VQA belogns here (order) */
1338 case AV_CODEC_ID_MSRLE:
1340 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1341 "layout", G_TYPE_STRING, "microsoft", NULL);
1343 gst_caps_set_simple (caps,
1344 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1346 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1350 case AV_CODEC_ID_QTRLE:
1352 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1353 "layout", G_TYPE_STRING, "quicktime", NULL);
1355 gst_caps_set_simple (caps,
1356 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1358 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1362 case AV_CODEC_ID_MSVIDEO1:
1364 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1365 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1368 case AV_CODEC_ID_WMV3:
1370 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1371 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1373 case AV_CODEC_ID_VC1:
1375 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1376 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1378 case AV_CODEC_ID_QDM2:
1380 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1384 case AV_CODEC_ID_MSZH:
1386 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1390 case AV_CODEC_ID_ZLIB:
1392 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1396 case AV_CODEC_ID_TRUEMOTION1:
1398 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1399 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1401 case AV_CODEC_ID_TRUEMOTION2:
1403 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1404 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1407 case AV_CODEC_ID_ULTI:
1409 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1410 "video/x-ultimotion", NULL);
1413 case AV_CODEC_ID_TSCC:
1415 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1416 "video/x-camtasia", NULL);
1418 gst_caps_set_simple (caps,
1419 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1421 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1425 case AV_CODEC_ID_KMVC:
1427 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1431 case AV_CODEC_ID_NUV:
1433 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1437 case AV_CODEC_ID_GIF:
1439 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1443 case AV_CODEC_ID_PNG:
1445 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1449 case AV_CODEC_ID_PPM:
1451 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1455 case AV_CODEC_ID_PBM:
1457 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1461 case AV_CODEC_ID_PAM:
1463 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1464 "image/x-portable-anymap", NULL);
1467 case AV_CODEC_ID_PGM:
1469 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1470 "image/x-portable-graymap", NULL);
1473 case AV_CODEC_ID_PCX:
1475 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1479 case AV_CODEC_ID_SGI:
1481 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1485 case AV_CODEC_ID_TARGA:
1487 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1491 case AV_CODEC_ID_TIFF:
1493 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1497 case AV_CODEC_ID_SUNRAST:
1499 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1500 "image/x-sun-raster", NULL);
1503 case AV_CODEC_ID_SMC:
1505 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1509 case AV_CODEC_ID_QDRAW:
1511 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1515 case AV_CODEC_ID_DNXHD:
1517 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1521 case AV_CODEC_ID_PRORES:
1523 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1524 "video/x-prores", NULL);
1527 case AV_CODEC_ID_MIMIC:
1529 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1533 case AV_CODEC_ID_VMNC:
1535 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1539 case AV_CODEC_ID_TRUESPEECH:
1541 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1542 "audio/x-truespeech", NULL);
1545 case AV_CODEC_ID_QCELP:
1547 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1551 case AV_CODEC_ID_AMV:
1553 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1557 case AV_CODEC_ID_AASC:
1559 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1563 case AV_CODEC_ID_LOCO:
1565 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1569 case AV_CODEC_ID_ZMBV:
1571 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1575 case AV_CODEC_ID_LAGARITH:
1577 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1578 "video/x-lagarith", NULL);
1581 case AV_CODEC_ID_CSCD:
1583 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1584 "video/x-camstudio", NULL);
1586 gst_caps_set_simple (caps,
1587 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1589 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1593 case AV_CODEC_ID_WS_VQA:
1594 case AV_CODEC_ID_IDCIN:
1595 case AV_CODEC_ID_8BPS:
1596 case AV_CODEC_ID_FLIC:
1597 case AV_CODEC_ID_VMDVIDEO:
1598 case AV_CODEC_ID_VMDAUDIO:
1599 case AV_CODEC_ID_SNOW:
1600 case AV_CODEC_ID_VIXL:
1601 case AV_CODEC_ID_QPEG:
1602 case AV_CODEC_ID_PGMYUV:
1603 case AV_CODEC_ID_FFVHUFF:
1604 case AV_CODEC_ID_WNV1:
1605 case AV_CODEC_ID_MP3ADU:
1606 case AV_CODEC_ID_MP3ON4:
1607 case AV_CODEC_ID_WESTWOOD_SND1:
1608 case AV_CODEC_ID_MMVIDEO:
1609 case AV_CODEC_ID_AVS:
1610 case AV_CODEC_ID_CAVS:
1614 /* weird quasi-codecs for the demuxers only */
1615 case AV_CODEC_ID_PCM_S16LE:
1616 case AV_CODEC_ID_PCM_S16BE:
1617 case AV_CODEC_ID_PCM_U16LE:
1618 case AV_CODEC_ID_PCM_U16BE:
1619 case AV_CODEC_ID_PCM_S8:
1620 case AV_CODEC_ID_PCM_U8:
1622 GstAudioFormat format;
1625 case AV_CODEC_ID_PCM_S16LE:
1626 format = GST_AUDIO_FORMAT_S16LE;
1628 case AV_CODEC_ID_PCM_S16BE:
1629 format = GST_AUDIO_FORMAT_S16BE;
1631 case AV_CODEC_ID_PCM_U16LE:
1632 format = GST_AUDIO_FORMAT_U16LE;
1634 case AV_CODEC_ID_PCM_U16BE:
1635 format = GST_AUDIO_FORMAT_U16BE;
1637 case AV_CODEC_ID_PCM_S8:
1638 format = GST_AUDIO_FORMAT_S8;
1640 case AV_CODEC_ID_PCM_U8:
1641 format = GST_AUDIO_FORMAT_U8;
1644 g_assert (0); /* don't worry, we never get here */
1649 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1650 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1651 "layout", G_TYPE_STRING, "interleaved", NULL);
1655 case AV_CODEC_ID_PCM_MULAW:
1657 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1661 case AV_CODEC_ID_PCM_ALAW:
1663 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1667 case AV_CODEC_ID_ADPCM_G722:
1669 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1672 gst_caps_set_simple (caps,
1673 "block_align", G_TYPE_INT, context->block_align,
1674 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1677 case AV_CODEC_ID_ADPCM_G726:
1679 /* the G726 decoder can also handle G721 */
1681 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1682 "layout", G_TYPE_STRING, "g726", NULL);
1684 gst_caps_set_simple (caps,
1685 "block_align", G_TYPE_INT, context->block_align,
1686 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1689 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1690 "layout", G_TYPE_STRING, "g721",
1691 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1695 case AV_CODEC_ID_ADPCM_IMA_QT:
1696 case AV_CODEC_ID_ADPCM_IMA_WAV:
1697 case AV_CODEC_ID_ADPCM_IMA_DK3:
1698 case AV_CODEC_ID_ADPCM_IMA_DK4:
1699 case AV_CODEC_ID_ADPCM_IMA_WS:
1700 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1701 case AV_CODEC_ID_ADPCM_IMA_AMV:
1702 case AV_CODEC_ID_ADPCM_IMA_ISS:
1703 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1704 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1705 case AV_CODEC_ID_ADPCM_MS:
1706 case AV_CODEC_ID_ADPCM_4XM:
1707 case AV_CODEC_ID_ADPCM_XA:
1708 case AV_CODEC_ID_ADPCM_ADX:
1709 case AV_CODEC_ID_ADPCM_EA:
1710 case AV_CODEC_ID_ADPCM_CT:
1711 case AV_CODEC_ID_ADPCM_SWF:
1712 case AV_CODEC_ID_ADPCM_YAMAHA:
1713 case AV_CODEC_ID_ADPCM_SBPRO_2:
1714 case AV_CODEC_ID_ADPCM_SBPRO_3:
1715 case AV_CODEC_ID_ADPCM_SBPRO_4:
1716 case AV_CODEC_ID_ADPCM_EA_R1:
1717 case AV_CODEC_ID_ADPCM_EA_R2:
1718 case AV_CODEC_ID_ADPCM_EA_R3:
1719 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1720 case AV_CODEC_ID_ADPCM_EA_XAS:
1721 case AV_CODEC_ID_ADPCM_THP:
1723 const gchar *layout = NULL;
1726 case AV_CODEC_ID_ADPCM_IMA_QT:
1727 layout = "quicktime";
1729 case AV_CODEC_ID_ADPCM_IMA_WAV:
1732 case AV_CODEC_ID_ADPCM_IMA_DK3:
1735 case AV_CODEC_ID_ADPCM_IMA_DK4:
1738 case AV_CODEC_ID_ADPCM_IMA_WS:
1739 layout = "westwood";
1741 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1744 case AV_CODEC_ID_ADPCM_IMA_AMV:
1747 case AV_CODEC_ID_ADPCM_IMA_ISS:
1750 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1753 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1756 case AV_CODEC_ID_ADPCM_MS:
1757 layout = "microsoft";
1759 case AV_CODEC_ID_ADPCM_4XM:
1762 case AV_CODEC_ID_ADPCM_XA:
1765 case AV_CODEC_ID_ADPCM_ADX:
1768 case AV_CODEC_ID_ADPCM_EA:
1771 case AV_CODEC_ID_ADPCM_CT:
1774 case AV_CODEC_ID_ADPCM_SWF:
1777 case AV_CODEC_ID_ADPCM_YAMAHA:
1780 case AV_CODEC_ID_ADPCM_SBPRO_2:
1783 case AV_CODEC_ID_ADPCM_SBPRO_3:
1786 case AV_CODEC_ID_ADPCM_SBPRO_4:
1789 case AV_CODEC_ID_ADPCM_EA_R1:
1792 case AV_CODEC_ID_ADPCM_EA_R2:
1795 case AV_CODEC_ID_ADPCM_EA_R3:
1798 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1799 layout = "ea-maxis-xa";
1801 case AV_CODEC_ID_ADPCM_EA_XAS:
1804 case AV_CODEC_ID_ADPCM_THP:
1808 g_assert (0); /* don't worry, we never get here */
1812 /* FIXME: someone please check whether we need additional properties
1813 * in this caps definition. */
1815 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1816 "layout", G_TYPE_STRING, layout, NULL);
1818 gst_caps_set_simple (caps,
1819 "block_align", G_TYPE_INT, context->block_align,
1820 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1824 case AV_CODEC_ID_AMR_NB:
1826 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1830 case AV_CODEC_ID_AMR_WB:
1832 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1836 case AV_CODEC_ID_GSM:
1838 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1842 case AV_CODEC_ID_GSM_MS:
1844 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1848 case AV_CODEC_ID_NELLYMOSER:
1850 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1851 "audio/x-nellymoser", NULL);
1854 case AV_CODEC_ID_SIPR:
1857 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1860 gst_caps_set_simple (caps,
1861 "leaf_size", G_TYPE_INT, context->block_align,
1862 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1867 case AV_CODEC_ID_RA_144:
1868 case AV_CODEC_ID_RA_288:
1869 case AV_CODEC_ID_COOK:
1874 case AV_CODEC_ID_RA_144:
1877 case AV_CODEC_ID_RA_288:
1880 case AV_CODEC_ID_COOK:
1887 /* FIXME: properties? */
1889 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1890 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1892 gst_caps_set_simple (caps,
1893 "leaf_size", G_TYPE_INT, context->block_align,
1894 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1899 case AV_CODEC_ID_ROQ_DPCM:
1900 case AV_CODEC_ID_INTERPLAY_DPCM:
1901 case AV_CODEC_ID_XAN_DPCM:
1902 case AV_CODEC_ID_SOL_DPCM:
1904 const gchar *layout = NULL;
1907 case AV_CODEC_ID_ROQ_DPCM:
1910 case AV_CODEC_ID_INTERPLAY_DPCM:
1911 layout = "interplay";
1913 case AV_CODEC_ID_XAN_DPCM:
1916 case AV_CODEC_ID_SOL_DPCM:
1920 g_assert (0); /* don't worry, we never get here */
1924 /* FIXME: someone please check whether we need additional properties
1925 * in this caps definition. */
1927 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1928 "layout", G_TYPE_STRING, layout, NULL);
1930 gst_caps_set_simple (caps,
1931 "block_align", G_TYPE_INT, context->block_align,
1932 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1936 case AV_CODEC_ID_SHORTEN:
1937 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1940 case AV_CODEC_ID_ALAC:
1942 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1945 gst_caps_set_simple (caps,
1946 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1950 case AV_CODEC_ID_FLAC:
1951 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1952 * encoder case, we want to add things like samplerate, channels... */
1954 caps = gst_caps_new_empty_simple ("audio/x-flac");
1958 case AV_CODEC_ID_S302M:
1959 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
1962 case AV_CODEC_ID_DVD_SUBTITLE:
1963 case AV_CODEC_ID_DVB_SUBTITLE:
1966 case AV_CODEC_ID_BMP:
1967 caps = gst_caps_new_empty_simple ("image/bmp");
1969 case AV_CODEC_ID_TTA:
1971 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1974 gst_caps_set_simple (caps,
1975 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1978 case AV_CODEC_ID_TWINVQ:
1980 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1981 "audio/x-twin-vq", NULL);
1984 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1991 if ((codec = avcodec_find_decoder (codec_id)) ||
1992 (codec = avcodec_find_encoder (codec_id))) {
1995 GST_LOG ("Could not create stream format caps for %s", codec->name);
1997 switch (codec->type) {
1998 case AVMEDIA_TYPE_VIDEO:
1999 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2001 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2004 case AVMEDIA_TYPE_AUDIO:
2005 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2007 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2009 gst_caps_set_simple (caps,
2010 "block_align", G_TYPE_INT, context->block_align,
2011 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2022 /* set private data */
2023 if (context && context->extradata_size > 0) {
2024 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2026 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2027 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2028 gst_buffer_unref (data);
2031 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2034 GST_LOG ("No caps found for codec_id=%d", codec_id);
2040 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2041 * to a GstCaps. If the context is ommitted, no fixed values
2042 * for video/audio size will be included in the GstCaps
2044 * See below for usefullness
2048 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2049 enum CodecID codec_id)
2051 GstCaps *caps = NULL;
2052 GstVideoFormat format;
2054 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2056 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2057 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2058 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2062 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2064 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2071 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2073 switch (sample_fmt) {
2074 case AV_SAMPLE_FMT_U8:
2075 case AV_SAMPLE_FMT_U8P:
2076 return GST_AUDIO_FORMAT_U8;
2078 case AV_SAMPLE_FMT_S16:
2079 case AV_SAMPLE_FMT_S16P:
2080 return GST_AUDIO_FORMAT_S16;
2082 case AV_SAMPLE_FMT_S32:
2083 case AV_SAMPLE_FMT_S32P:
2084 return GST_AUDIO_FORMAT_S32;
2086 case AV_SAMPLE_FMT_FLT:
2087 case AV_SAMPLE_FMT_FLTP:
2088 return GST_AUDIO_FORMAT_F32;
2090 case AV_SAMPLE_FMT_DBL:
2091 case AV_SAMPLE_FMT_DBLP:
2092 return GST_AUDIO_FORMAT_F64;
2096 return GST_AUDIO_FORMAT_UNKNOWN;
2101 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2102 * to a GstCaps. If the context is ommitted, no fixed values
2103 * for video/audio size will be included in the GstCaps
2105 * See below for usefullness
2109 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2110 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2112 GstCaps *caps = NULL;
2113 GstAudioFormat format;
2115 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2117 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2118 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2119 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2120 "layout", G_TYPE_STRING, "interleaved", NULL);
2121 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2123 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2130 caps_has_field (GstCaps * caps, const gchar * field)
2134 n = gst_caps_get_size (caps);
2135 for (i = 0; i < n; i++) {
2136 GstStructure *s = gst_caps_get_structure (caps, i);
2138 if (gst_structure_has_field (s, field))
2146 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2147 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2149 GstCaps *caps = NULL;
2151 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2152 context, codec_id, encode, codec);
2154 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2155 codec->sample_fmts, codec->supported_samplerates);
2158 /* Specific codec context */
2160 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2163 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2164 "layout", G_TYPE_STRING, "interleaved", NULL);
2165 if (!caps_has_field (caps, "format"))
2166 gst_ffmpeg_audio_set_sample_fmts (caps,
2167 codec ? codec->sample_fmts : NULL);
2174 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2175 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2179 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2180 context, codec_id, encode, codec);
2183 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2186 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2188 if (!caps_has_field (caps, "format"))
2189 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2194 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2195 * and other audio properties in a AVCodecContext.
2197 * For usefullness, see below
2201 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2202 AVCodecContext * context, gboolean raw)
2204 GstStructure *structure;
2206 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2208 g_return_if_fail (gst_caps_get_size (caps) == 1);
2210 structure = gst_caps_get_structure (caps, 0);
2212 gst_structure_get_int (structure, "channels", &context->channels);
2213 gst_structure_get_int (structure, "rate", &context->sample_rate);
2214 gst_structure_get_int (structure, "block_align", &context->block_align);
2215 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2220 if (gst_structure_has_name (structure, "audio/x-raw")) {
2221 if ((fmt = gst_structure_get_string (structure, "format"))) {
2222 format = gst_audio_format_from_string (fmt);
2227 case GST_AUDIO_FORMAT_F32:
2228 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2230 case GST_AUDIO_FORMAT_F64:
2231 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2233 case GST_AUDIO_FORMAT_S32:
2234 context->sample_fmt = AV_SAMPLE_FMT_S32;
2236 case GST_AUDIO_FORMAT_S16:
2237 context->sample_fmt = AV_SAMPLE_FMT_S16;
2244 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2245 * and other video properties in a AVCodecContext.
2247 * For usefullness, see below
2251 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2252 AVCodecContext * context, gboolean raw)
2254 GstStructure *structure;
2256 const GValue *par = NULL;
2258 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2260 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2261 g_return_if_fail (gst_caps_get_size (caps) == 1);
2262 structure = gst_caps_get_structure (caps, 0);
2264 gst_structure_get_int (structure, "width", &context->width);
2265 gst_structure_get_int (structure, "height", &context->height);
2266 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2268 fps = gst_structure_get_value (structure, "framerate");
2269 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2271 /* somehow these seem mixed up.. */
2272 context->time_base.den = gst_value_get_fraction_numerator (fps);
2273 context->time_base.num = gst_value_get_fraction_denominator (fps);
2274 context->ticks_per_frame = 1;
2276 GST_DEBUG ("setting framerate %d/%d = %lf",
2277 context->time_base.den, context->time_base.num,
2278 1. * context->time_base.den / context->time_base.num);
2281 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2282 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2284 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2285 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2287 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2288 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2289 1. * context->sample_aspect_ratio.den /
2290 context->sample_aspect_ratio.num);
2296 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2298 if (gst_structure_has_name (structure, "video/x-raw")) {
2299 if ((fmt = gst_structure_get_string (structure, "format"))) {
2300 format = gst_video_format_from_string (fmt);
2305 case GST_VIDEO_FORMAT_YUY2:
2306 context->pix_fmt = PIX_FMT_YUYV422;
2308 case GST_VIDEO_FORMAT_I420:
2309 context->pix_fmt = PIX_FMT_YUV420P;
2311 case GST_VIDEO_FORMAT_A420:
2312 context->pix_fmt = PIX_FMT_YUVA420P;
2314 case GST_VIDEO_FORMAT_Y41B:
2315 context->pix_fmt = PIX_FMT_YUV411P;
2317 case GST_VIDEO_FORMAT_Y42B:
2318 context->pix_fmt = PIX_FMT_YUV422P;
2320 case GST_VIDEO_FORMAT_YUV9:
2321 context->pix_fmt = PIX_FMT_YUV410P;
2323 case GST_VIDEO_FORMAT_Y444:
2324 context->pix_fmt = PIX_FMT_YUV444P;
2326 case GST_VIDEO_FORMAT_GRAY8:
2327 context->pix_fmt = PIX_FMT_GRAY8;
2329 case GST_VIDEO_FORMAT_xRGB:
2330 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2331 context->pix_fmt = PIX_FMT_RGB32;
2334 case GST_VIDEO_FORMAT_BGRx:
2335 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2336 context->pix_fmt = PIX_FMT_RGB32;
2339 case GST_VIDEO_FORMAT_RGB:
2340 context->pix_fmt = PIX_FMT_RGB24;
2342 case GST_VIDEO_FORMAT_BGR:
2343 context->pix_fmt = PIX_FMT_BGR24;
2345 case GST_VIDEO_FORMAT_RGB16:
2346 context->pix_fmt = PIX_FMT_RGB565;
2348 case GST_VIDEO_FORMAT_RGB15:
2349 context->pix_fmt = PIX_FMT_RGB555;
2351 case GST_VIDEO_FORMAT_RGB8P:
2352 context->pix_fmt = PIX_FMT_PAL8;
2361 GstVideoFormat format;
2362 enum PixelFormat pixfmt;
2365 /* FIXME : FILLME */
2366 static const PixToFmt pixtofmttable[] = {
2367 /* GST_VIDEO_FORMAT_I420, */
2368 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2369 /* Note : this should use a different chroma placement */
2370 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2372 /* GST_VIDEO_FORMAT_YV12, */
2373 /* GST_VIDEO_FORMAT_YUY2, */
2374 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2375 /* GST_VIDEO_FORMAT_UYVY, */
2376 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2377 /* GST_VIDEO_FORMAT_AYUV, */
2378 /* GST_VIDEO_FORMAT_RGBx, */
2379 /* GST_VIDEO_FORMAT_BGRx, */
2380 /* GST_VIDEO_FORMAT_xRGB, */
2381 /* GST_VIDEO_FORMAT_xBGR, */
2382 /* GST_VIDEO_FORMAT_RGBA, */
2383 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2384 /* GST_VIDEO_FORMAT_BGRA, */
2385 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2386 /* GST_VIDEO_FORMAT_ARGB, */
2387 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2388 /* GST_VIDEO_FORMAT_ABGR, */
2389 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2390 /* GST_VIDEO_FORMAT_RGB, */
2391 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2392 /* GST_VIDEO_FORMAT_BGR, */
2393 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2394 /* GST_VIDEO_FORMAT_Y41B, */
2395 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2396 /* GST_VIDEO_FORMAT_Y42B, */
2397 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2398 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2399 /* GST_VIDEO_FORMAT_YVYU, */
2400 /* GST_VIDEO_FORMAT_Y444, */
2401 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2402 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2403 /* GST_VIDEO_FORMAT_v210, */
2404 /* GST_VIDEO_FORMAT_v216, */
2405 /* GST_VIDEO_FORMAT_NV12, */
2406 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2407 /* GST_VIDEO_FORMAT_NV21, */
2408 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2409 /* GST_VIDEO_FORMAT_GRAY8, */
2410 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2411 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2412 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2413 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2414 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2415 /* GST_VIDEO_FORMAT_v308, */
2416 /* GST_VIDEO_FORMAT_Y800, */
2417 /* GST_VIDEO_FORMAT_Y16, */
2418 /* GST_VIDEO_FORMAT_RGB16, */
2419 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2420 /* GST_VIDEO_FORMAT_BGR16, */
2421 /* GST_VIDEO_FORMAT_RGB15, */
2422 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2423 /* GST_VIDEO_FORMAT_BGR15, */
2424 /* GST_VIDEO_FORMAT_UYVP, */
2425 /* GST_VIDEO_FORMAT_A420, */
2426 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2427 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2428 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2429 /* GST_VIDEO_FORMAT_YUV9, */
2430 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2431 /* GST_VIDEO_FORMAT_YVU9, */
2432 /* GST_VIDEO_FORMAT_IYU1, */
2433 /* GST_VIDEO_FORMAT_ARGB64, */
2434 /* GST_VIDEO_FORMAT_AYUV64, */
2435 /* GST_VIDEO_FORMAT_r210, */
2436 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2437 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2438 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2439 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2440 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2441 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2442 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2443 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2444 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2448 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2452 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2453 if (pixtofmttable[i].pixfmt == pixfmt)
2454 return pixtofmttable[i].format;
2456 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2457 return GST_VIDEO_FORMAT_UNKNOWN;
2461 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2465 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2466 if (pixtofmttable[i].format == format)
2467 return pixtofmttable[i].pixfmt;
2468 return PIX_FMT_NONE;
2472 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2476 context->width = GST_VIDEO_INFO_WIDTH (info);
2477 context->height = GST_VIDEO_INFO_HEIGHT (info);
2478 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2479 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2480 context->bits_per_coded_sample = bpp;
2482 context->ticks_per_frame = 1;
2483 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2484 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2486 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2487 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2490 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2494 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2496 const AVCodec *codec;
2497 const enum AVSampleFormat *smpl_fmts;
2498 enum AVSampleFormat smpl_fmt = -1;
2500 context->channels = info->channels;
2501 context->sample_rate = info->rate;
2502 context->channel_layout =
2503 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2505 codec = context->codec;
2507 smpl_fmts = codec->sample_fmts;
2509 switch (info->finfo->format) {
2510 case GST_AUDIO_FORMAT_F32:
2512 while (*smpl_fmts != -1) {
2513 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2514 smpl_fmt = *smpl_fmts;
2516 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2517 smpl_fmt = *smpl_fmts;
2523 smpl_fmt = AV_SAMPLE_FMT_FLT;
2526 case GST_AUDIO_FORMAT_F64:
2528 while (*smpl_fmts != -1) {
2529 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2530 smpl_fmt = *smpl_fmts;
2532 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2533 smpl_fmt = *smpl_fmts;
2539 smpl_fmt = AV_SAMPLE_FMT_DBL;
2542 case GST_AUDIO_FORMAT_S32:
2544 while (*smpl_fmts != -1) {
2545 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2546 smpl_fmt = *smpl_fmts;
2548 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2549 smpl_fmt = *smpl_fmts;
2555 smpl_fmt = AV_SAMPLE_FMT_S32;
2558 case GST_AUDIO_FORMAT_S16:
2560 while (*smpl_fmts != -1) {
2561 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2562 smpl_fmt = *smpl_fmts;
2564 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2565 smpl_fmt = *smpl_fmts;
2571 smpl_fmt = AV_SAMPLE_FMT_S16;
2574 case GST_AUDIO_FORMAT_U8:
2576 while (*smpl_fmts != -1) {
2577 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2578 smpl_fmt = *smpl_fmts;
2580 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2581 smpl_fmt = *smpl_fmts;
2587 smpl_fmt = AV_SAMPLE_FMT_U8;
2594 g_assert (smpl_fmt != -1);
2596 context->sample_fmt = smpl_fmt;
2599 /* Convert a GstCaps and a FFMPEG codec Type to a
2600 * AVCodecContext. If the context is ommitted, no fixed values
2601 * for video/audio size will be included in the context
2603 * AVMediaType is primarily meant for uncompressed data GstCaps!
2607 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2608 const GstCaps * caps, AVCodecContext * context)
2610 if (context == NULL)
2614 case AVMEDIA_TYPE_VIDEO:
2615 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2618 case AVMEDIA_TYPE_AUDIO:
2619 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2630 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2634 guint8 *end = src + size;
2637 while (srcp < end) {
2638 if (count == 2 && *srcp <= 0x03) {
2639 GST_DEBUG ("added escape code");
2648 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2651 *destsize = dstp - dst;
2654 /* copy the config, escaping NAL units as we iterate them, if something fails we
2655 * copy everything and hope for the best. */
2657 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2662 guint nalsize, esize;
2672 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2674 GST_DEBUG ("num SPS %d", cnt);
2676 memcpy (dstp, srcp, 6);
2680 for (i = 0; i < cnt; i++) {
2681 GST_DEBUG ("copy SPS %d", i);
2682 nalsize = (srcp[0] << 8) | srcp[1];
2683 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2684 dstp[0] = esize >> 8;
2685 dstp[1] = esize & 0xff;
2687 srcp += nalsize + 2;
2690 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2692 GST_DEBUG ("num PPS %d", cnt);
2694 for (i = 0; i < cnt; i++) {
2695 GST_DEBUG ("copy PPS %d", i);
2696 nalsize = (srcp[0] << 8) | srcp[1];
2697 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2698 dstp[0] = esize >> 8;
2699 dstp[1] = esize & 0xff;
2701 srcp += nalsize + 2;
2703 *destsize = dstp - dst;
2709 GST_DEBUG ("something unexpected, doing full copy");
2710 memcpy (dst, src, size);
2718 * caps_with_codecid () transforms a GstCaps for a known codec
2719 * ID into a filled-in context.
2720 * codec_data from caps will override possible extradata already in the context
2724 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2725 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2728 const GValue *value;
2731 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2732 codec_id, codec_type, caps, context);
2734 if (!context || !gst_caps_get_size (caps))
2737 str = gst_caps_get_structure (caps, 0);
2739 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2740 if ((value = gst_structure_get_value (str, "codec_data"))) {
2743 buf = gst_value_get_buffer (value);
2744 gst_buffer_map (buf, &map, GST_MAP_READ);
2746 /* free the old one if it is there */
2747 if (context->extradata)
2748 av_free (context->extradata);
2751 if (codec_id == AV_CODEC_ID_H264) {
2754 GST_DEBUG ("copy, escaping codec_data %d", size);
2755 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2756 * reason for this but let's just escape it for now. Start by allocating
2757 * enough space, x2 is more than enough.
2759 * FIXME, we disabled escaping because some file already contain escaped
2760 * codec_data and then we escape twice and fail. It's better to leave it
2761 * as is, as that is what most players do. */
2762 context->extradata =
2763 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2764 FF_INPUT_BUFFER_PADDING_SIZE));
2765 copy_config (context->extradata, data, size, &extrasize);
2766 GST_DEBUG ("escaped size: %d", extrasize);
2767 context->extradata_size = extrasize;
2771 /* allocate with enough padding */
2772 GST_DEBUG ("copy codec_data");
2773 context->extradata =
2774 av_mallocz (GST_ROUND_UP_16 (map.size +
2775 FF_INPUT_BUFFER_PADDING_SIZE));
2776 memcpy (context->extradata, map.data, map.size);
2777 context->extradata_size = map.size;
2780 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2781 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2782 context->extradata[0] = (guint8) map.size;
2785 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2787 gst_buffer_unmap (buf, &map);
2788 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2789 codec_id != AV_CODEC_ID_FLAC) {
2790 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2791 * extradata anyway which makes then segfault. */
2792 context->extradata =
2793 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2794 context->extradata_size = 0;
2795 GST_DEBUG ("no codec data");
2799 case AV_CODEC_ID_MPEG4:
2801 const gchar *mime = gst_structure_get_name (str);
2803 if (!strcmp (mime, "video/x-divx"))
2804 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2805 else if (!strcmp (mime, "video/x-xvid"))
2806 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2807 else if (!strcmp (mime, "video/x-3ivx"))
2808 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2809 else if (!strcmp (mime, "video/mpeg"))
2810 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2814 case AV_CODEC_ID_SVQ3:
2815 /* FIXME: this is a workaround for older gst-plugins releases
2816 * (<= 0.8.9). This should be removed at some point, because
2817 * it causes wrong decoded frame order. */
2818 if (!context->extradata) {
2819 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2822 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2823 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2824 gst_structure_get_int (str, "low_delay", &low_delay) ||
2825 gst_structure_get_int (str, "unknown_svq3_flag",
2826 &unknown_svq3_flag)) {
2827 context->extradata = (guint8 *) av_mallocz (0x64);
2828 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2832 flags |= unknown_svq3_flag;
2834 flags |= halfpel_flag;
2836 flags |= thirdpel_flag;
2839 flags = GUINT16_FROM_LE (flags);
2841 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2842 context->extradata_size = 0x64;
2847 case AV_CODEC_ID_MSRLE:
2848 case AV_CODEC_ID_QTRLE:
2849 case AV_CODEC_ID_TSCC:
2850 case AV_CODEC_ID_CSCD:
2851 case AV_CODEC_ID_APE:
2855 if (gst_structure_get_int (str, "depth", &depth)) {
2856 context->bits_per_coded_sample = depth;
2858 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2864 case AV_CODEC_ID_RV10:
2865 case AV_CODEC_ID_RV20:
2866 case AV_CODEC_ID_RV30:
2867 case AV_CODEC_ID_RV40:
2871 if (gst_structure_get_int (str, "format", &format))
2872 context->sub_id = format;
2876 case AV_CODEC_ID_COOK:
2877 case AV_CODEC_ID_RA_288:
2878 case AV_CODEC_ID_RA_144:
2879 case AV_CODEC_ID_SIPR:
2884 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2885 context->block_align = leaf_size;
2886 if (gst_structure_get_int (str, "bitrate", &bitrate))
2887 context->bit_rate = bitrate;
2889 case AV_CODEC_ID_ALAC:
2890 gst_structure_get_int (str, "samplesize",
2891 &context->bits_per_coded_sample);
2894 case AV_CODEC_ID_DVVIDEO:
2896 const gchar *format;
2898 if ((format = gst_structure_get_string (str, "format"))) {
2900 if (g_str_equal (format, "YUY2"))
2901 context->pix_fmt = PIX_FMT_YUYV422;
2902 else if (g_str_equal (format, "I420"))
2903 context->pix_fmt = PIX_FMT_YUV420P;
2904 else if (g_str_equal (format, "A420"))
2905 context->pix_fmt = PIX_FMT_YUVA420P;
2906 else if (g_str_equal (format, "Y41B"))
2907 context->pix_fmt = PIX_FMT_YUV411P;
2908 else if (g_str_equal (format, "Y42B"))
2909 context->pix_fmt = PIX_FMT_YUV422P;
2910 else if (g_str_equal (format, "YUV9"))
2911 context->pix_fmt = PIX_FMT_YUV410P;
2913 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2917 GST_WARNING ("No specified format");
2920 case AV_CODEC_ID_H263P:
2924 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2925 context->flags |= CODEC_FLAG_4MV;
2927 context->flags &= ~CODEC_FLAG_4MV;
2928 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2929 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2930 context->flags |= CODEC_FLAG_AC_PRED;
2932 context->flags &= ~CODEC_FLAG_AC_PRED;
2933 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2934 context->flags |= CODEC_FLAG_LOOP_FILTER;
2936 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2939 case AV_CODEC_ID_ADPCM_G726:
2941 const gchar *layout;
2943 if ((layout = gst_structure_get_string (str, "layout"))) {
2944 if (!strcmp (layout, "g721")) {
2945 context->sample_rate = 8000;
2946 context->channels = 1;
2947 context->bit_rate = 32000;
2956 if (!gst_caps_is_fixed (caps))
2959 /* common properties (width, height, fps) */
2960 switch (codec_type) {
2961 case AVMEDIA_TYPE_VIDEO:
2962 gst_ffmpeg_caps_to_pixfmt (caps, context,
2963 codec_id == AV_CODEC_ID_RAWVIDEO);
2965 case AVMEDIA_TYPE_AUDIO:
2966 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2972 /* fixup of default settings */
2974 case AV_CODEC_ID_QCELP:
2975 /* QCELP is always mono, no matter what the caps say */
2976 context->channels = 1;
2978 case AV_CODEC_ID_ADPCM_G726:
2979 if (context->sample_rate && context->bit_rate)
2980 context->bits_per_coded_sample =
2981 context->bit_rate / context->sample_rate;
2988 /* _formatid_to_caps () is meant for muxers/demuxers, it
2989 * transforms a name (ffmpeg way of ID'ing these, why don't
2990 * they have unique numerical IDs?) to the corresponding
2991 * caps belonging to that mux-format
2993 * Note: we don't need any additional info because the caps
2994 * isn't supposed to contain any useful info besides the
2999 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3001 GstCaps *caps = NULL;
3003 if (!strcmp (format_name, "mpeg")) {
3004 caps = gst_caps_new_simple ("video/mpeg",
3005 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3006 } else if (!strcmp (format_name, "mpegts")) {
3007 caps = gst_caps_new_simple ("video/mpegts",
3008 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3009 } else if (!strcmp (format_name, "rm")) {
3010 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3011 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3012 } else if (!strcmp (format_name, "asf")) {
3013 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3014 } else if (!strcmp (format_name, "avi")) {
3015 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3016 } else if (!strcmp (format_name, "wav")) {
3017 caps = gst_caps_new_empty_simple ("audio/x-wav");
3018 } else if (!strcmp (format_name, "ape")) {
3019 caps = gst_caps_new_empty_simple ("application/x-ape");
3020 } else if (!strcmp (format_name, "swf")) {
3021 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3022 } else if (!strcmp (format_name, "au")) {
3023 caps = gst_caps_new_empty_simple ("audio/x-au");
3024 } else if (!strcmp (format_name, "dv")) {
3025 caps = gst_caps_new_simple ("video/x-dv",
3026 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3027 } else if (!strcmp (format_name, "4xm")) {
3028 caps = gst_caps_new_empty_simple ("video/x-4xm");
3029 } else if (!strcmp (format_name, "matroska")) {
3030 caps = gst_caps_new_empty_simple ("video/x-matroska");
3031 } else if (!strcmp (format_name, "mp3")) {
3032 caps = gst_caps_new_empty_simple ("application/x-id3");
3033 } else if (!strcmp (format_name, "flic")) {
3034 caps = gst_caps_new_empty_simple ("video/x-fli");
3035 } else if (!strcmp (format_name, "flv")) {
3036 caps = gst_caps_new_empty_simple ("video/x-flv");
3037 } else if (!strcmp (format_name, "tta")) {
3038 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3039 } else if (!strcmp (format_name, "aiff")) {
3040 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3041 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3043 gst_caps_from_string
3044 ("application/x-3gp; video/quicktime; audio/x-m4a");
3045 } else if (!strcmp (format_name, "mov")) {
3046 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3047 } else if (!strcmp (format_name, "mp4")) {
3048 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3049 } else if (!strcmp (format_name, "3gp")) {
3050 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3051 } else if (!strcmp (format_name, "3g2")) {
3052 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3053 } else if (!strcmp (format_name, "psp")) {
3054 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3055 } else if (!strcmp (format_name, "ipod")) {
3056 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3057 } else if (!strcmp (format_name, "aac")) {
3058 caps = gst_caps_new_simple ("audio/mpeg",
3059 "mpegversion", G_TYPE_INT, 4, NULL);
3060 } else if (!strcmp (format_name, "gif")) {
3061 caps = gst_caps_from_string ("image/gif");
3062 } else if (!strcmp (format_name, "ogg")) {
3063 caps = gst_caps_from_string ("application/ogg");
3064 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3065 caps = gst_caps_from_string ("application/mxf");
3066 } else if (!strcmp (format_name, "gxf")) {
3067 caps = gst_caps_from_string ("application/gxf");
3068 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3069 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3070 "y4mversion", G_TYPE_INT, 2, NULL);
3071 } else if (!strcmp (format_name, "mpc")) {
3072 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3073 } else if (!strcmp (format_name, "vqf")) {
3074 caps = gst_caps_from_string ("audio/x-vqf");
3075 } else if (!strcmp (format_name, "nsv")) {
3076 caps = gst_caps_from_string ("video/x-nsv");
3077 } else if (!strcmp (format_name, "amr")) {
3078 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3079 } else if (!strcmp (format_name, "webm")) {
3080 caps = gst_caps_from_string ("video/webm");
3081 } else if (!strcmp (format_name, "voc")) {
3082 caps = gst_caps_from_string ("audio/x-voc");
3086 GST_LOG ("Could not create stream format caps for %s", format_name);
3087 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3088 caps = gst_caps_new_empty_simple (name);
3096 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3097 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3098 AVOutputFormat * plugin)
3100 static enum CodecID tmp_vlist[] = {
3104 static enum CodecID tmp_alist[] = {
3109 GST_LOG ("format_name : %s", format_name);
3111 if (!strcmp (format_name, "mp4")) {
3112 static enum CodecID mp4_video_list[] = {
3113 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3117 static enum CodecID mp4_audio_list[] = {
3118 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3122 *video_codec_list = mp4_video_list;
3123 *audio_codec_list = mp4_audio_list;
3124 } else if (!strcmp (format_name, "mpeg")) {
3125 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3126 AV_CODEC_ID_MPEG2VIDEO,
3130 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3136 *video_codec_list = mpeg_video_list;
3137 *audio_codec_list = mpeg_audio_list;
3138 } else if (!strcmp (format_name, "dvd")) {
3139 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3142 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3145 AV_CODEC_ID_PCM_S16BE,
3149 *video_codec_list = mpeg_video_list;
3150 *audio_codec_list = mpeg_audio_list;
3151 } else if (!strcmp (format_name, "mpegts")) {
3152 static enum CodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3153 AV_CODEC_ID_MPEG2VIDEO,
3157 static enum CodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3165 *video_codec_list = mpegts_video_list;
3166 *audio_codec_list = mpegts_audio_list;
3167 } else if (!strcmp (format_name, "vob")) {
3168 static enum CodecID vob_video_list[] =
3169 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3170 static enum CodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3171 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3174 *video_codec_list = vob_video_list;
3175 *audio_codec_list = vob_audio_list;
3176 } else if (!strcmp (format_name, "flv")) {
3177 static enum CodecID flv_video_list[] =
3178 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3179 static enum CodecID flv_audio_list[] =
3180 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3182 *video_codec_list = flv_video_list;
3183 *audio_codec_list = flv_audio_list;
3184 } else if (!strcmp (format_name, "asf")) {
3185 static enum CodecID asf_video_list[] =
3186 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3189 static enum CodecID asf_audio_list[] =
3190 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3194 *video_codec_list = asf_video_list;
3195 *audio_codec_list = asf_audio_list;
3196 } else if (!strcmp (format_name, "dv")) {
3197 static enum CodecID dv_video_list[] =
3198 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3199 static enum CodecID dv_audio_list[] =
3200 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3202 *video_codec_list = dv_video_list;
3203 *audio_codec_list = dv_audio_list;
3204 } else if (!strcmp (format_name, "mov")) {
3205 static enum CodecID mov_video_list[] = {
3206 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3207 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3208 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3212 static enum CodecID mov_audio_list[] = {
3213 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3214 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3215 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3216 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3217 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3220 *video_codec_list = mov_video_list;
3221 *audio_codec_list = mov_audio_list;
3222 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3223 static enum CodecID tgp_video_list[] = {
3224 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3227 static enum CodecID tgp_audio_list[] = {
3228 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3233 *video_codec_list = tgp_video_list;
3234 *audio_codec_list = tgp_audio_list;
3235 } else if (!strcmp (format_name, "mmf")) {
3236 static enum CodecID mmf_audio_list[] = {
3237 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3239 *video_codec_list = NULL;
3240 *audio_codec_list = mmf_audio_list;
3241 } else if (!strcmp (format_name, "amr")) {
3242 static enum CodecID amr_audio_list[] = {
3243 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3246 *video_codec_list = NULL;
3247 *audio_codec_list = amr_audio_list;
3248 } else if (!strcmp (format_name, "gif")) {
3249 static enum CodecID gif_image_list[] = {
3250 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3252 *video_codec_list = gif_image_list;
3253 *audio_codec_list = NULL;
3254 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3255 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3256 tmp_vlist[0] = plugin->video_codec;
3257 tmp_alist[0] = plugin->audio_codec;
3259 *video_codec_list = tmp_vlist;
3260 *audio_codec_list = tmp_alist;
3262 GST_LOG ("Format %s not found", format_name);
3269 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3270 * are omitted, that can be queried by the user itself,
3271 * we're not eating the GstCaps or anything
3272 * A pointer to an allocated context is also needed for
3273 * optional extra info
3277 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3279 enum CodecID id = AV_CODEC_ID_NONE;
3280 const gchar *mimetype;
3281 const GstStructure *structure;
3282 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3284 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3285 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3286 structure = gst_caps_get_structure (caps, 0);
3288 mimetype = gst_structure_get_name (structure);
3290 if (!strcmp (mimetype, "video/x-raw")) {
3291 id = AV_CODEC_ID_RAWVIDEO;
3293 } else if (!strcmp (mimetype, "audio/x-raw")) {
3296 if (gst_audio_info_from_caps (&info, caps)) {
3297 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3298 case GST_AUDIO_FORMAT_S8:
3299 id = AV_CODEC_ID_PCM_S8;
3301 case GST_AUDIO_FORMAT_U8:
3302 id = AV_CODEC_ID_PCM_U8;
3304 case GST_AUDIO_FORMAT_S16LE:
3305 id = AV_CODEC_ID_PCM_S16LE;
3307 case GST_AUDIO_FORMAT_S16BE:
3308 id = AV_CODEC_ID_PCM_S16BE;
3310 case GST_AUDIO_FORMAT_U16LE:
3311 id = AV_CODEC_ID_PCM_U16LE;
3313 case GST_AUDIO_FORMAT_U16BE:
3314 id = AV_CODEC_ID_PCM_U16BE;
3319 if (id != AV_CODEC_ID_NONE)
3322 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3323 id = AV_CODEC_ID_PCM_MULAW;
3325 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3326 id = AV_CODEC_ID_PCM_ALAW;
3328 } else if (!strcmp (mimetype, "video/x-dv")) {
3331 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3333 id = AV_CODEC_ID_DVVIDEO;
3336 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3337 id = AV_CODEC_ID_DVAUDIO;
3339 } else if (!strcmp (mimetype, "video/x-h263")) {
3340 const gchar *h263version =
3341 gst_structure_get_string (structure, "h263version");
3342 if (h263version && !strcmp (h263version, "h263p"))
3343 id = AV_CODEC_ID_H263P;
3345 id = AV_CODEC_ID_H263;
3347 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3348 id = AV_CODEC_ID_H263I;
3350 } else if (!strcmp (mimetype, "video/x-h261")) {
3351 id = AV_CODEC_ID_H261;
3353 } else if (!strcmp (mimetype, "video/mpeg")) {
3357 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3358 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3360 switch (mpegversion) {
3362 id = AV_CODEC_ID_MPEG1VIDEO;
3365 id = AV_CODEC_ID_MPEG2VIDEO;
3368 id = AV_CODEC_ID_MPEG4;
3372 if (id != AV_CODEC_ID_NONE)
3374 } else if (!strcmp (mimetype, "image/jpeg")) {
3375 id = AV_CODEC_ID_MJPEG; /* A... B... */
3377 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3378 id = AV_CODEC_ID_MJPEGB;
3380 } else if (!strcmp (mimetype, "video/x-wmv")) {
3381 gint wmvversion = 0;
3383 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3384 switch (wmvversion) {
3386 id = AV_CODEC_ID_WMV1;
3389 id = AV_CODEC_ID_WMV2;
3393 const gchar *format;
3395 /* WMV3 unless the fourcc exists and says otherwise */
3396 id = AV_CODEC_ID_WMV3;
3398 if ((format = gst_structure_get_string (structure, "format")) &&
3399 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3400 id = AV_CODEC_ID_VC1;
3406 if (id != AV_CODEC_ID_NONE)
3408 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3409 id = AV_CODEC_ID_VORBIS;
3411 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3412 id = AV_CODEC_ID_QDM2;
3414 } else if (!strcmp (mimetype, "audio/mpeg")) {
3416 gint mpegversion = 0;
3418 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3419 switch (mpegversion) {
3420 case 2: /* ffmpeg uses faad for both... */
3422 id = AV_CODEC_ID_AAC;
3425 if (gst_structure_get_int (structure, "layer", &layer)) {
3428 id = AV_CODEC_ID_MP1;
3431 id = AV_CODEC_ID_MP2;
3434 id = AV_CODEC_ID_MP3;
3440 if (id != AV_CODEC_ID_NONE)
3442 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3443 gint streamversion = -1;
3445 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3446 if (streamversion == 7)
3447 id = AV_CODEC_ID_MUSEPACK7;
3449 id = AV_CODEC_ID_MUSEPACK7;
3451 } else if (!strcmp (mimetype, "audio/x-wma")) {
3452 gint wmaversion = 0;
3454 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3455 switch (wmaversion) {
3457 id = AV_CODEC_ID_WMAV1;
3460 id = AV_CODEC_ID_WMAV2;
3463 id = AV_CODEC_ID_WMAPRO;
3467 if (id != AV_CODEC_ID_NONE)
3469 } else if (!strcmp (mimetype, "audio/x-wms")) {
3470 id = AV_CODEC_ID_WMAVOICE;
3472 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3473 id = AV_CODEC_ID_AC3;
3475 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3476 id = AV_CODEC_ID_EAC3;
3478 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3479 !strcmp (mimetype, "audio/atrac3")) {
3480 id = AV_CODEC_ID_ATRAC3;
3482 } else if (!strcmp (mimetype, "audio/x-dts")) {
3483 id = AV_CODEC_ID_DTS;
3485 } else if (!strcmp (mimetype, "application/x-ape")) {
3486 id = AV_CODEC_ID_APE;
3488 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3489 gint msmpegversion = 0;
3491 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3492 switch (msmpegversion) {
3494 id = AV_CODEC_ID_MSMPEG4V1;
3497 id = AV_CODEC_ID_MSMPEG4V2;
3500 id = AV_CODEC_ID_MSMPEG4V3;
3504 if (id != AV_CODEC_ID_NONE)
3506 } else if (!strcmp (mimetype, "video/x-svq")) {
3507 gint svqversion = 0;
3509 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3510 switch (svqversion) {
3512 id = AV_CODEC_ID_SVQ1;
3515 id = AV_CODEC_ID_SVQ3;
3519 if (id != AV_CODEC_ID_NONE)
3521 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3522 id = AV_CODEC_ID_HUFFYUV;
3524 } else if (!strcmp (mimetype, "audio/x-mace")) {
3525 gint maceversion = 0;
3527 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3528 switch (maceversion) {
3530 id = AV_CODEC_ID_MACE3;
3533 id = AV_CODEC_ID_MACE6;
3537 if (id != AV_CODEC_ID_NONE)
3539 } else if (!strcmp (mimetype, "video/x-theora")) {
3540 id = AV_CODEC_ID_THEORA;
3542 } else if (!strcmp (mimetype, "video/x-vp3")) {
3543 id = AV_CODEC_ID_VP3;
3545 } else if (!strcmp (mimetype, "video/x-vp5")) {
3546 id = AV_CODEC_ID_VP5;
3548 } else if (!strcmp (mimetype, "video/x-vp6")) {
3549 id = AV_CODEC_ID_VP6;
3551 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3552 id = AV_CODEC_ID_VP6F;
3554 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3555 id = AV_CODEC_ID_VP6A;
3557 } else if (!strcmp (mimetype, "video/x-vp8")) {
3558 id = AV_CODEC_ID_VP8;
3560 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3561 id = AV_CODEC_ID_FLASHSV;
3563 } else if (!strcmp (mimetype, "video/x-indeo")) {
3564 gint indeoversion = 0;
3566 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3567 switch (indeoversion) {
3569 id = AV_CODEC_ID_INDEO5;
3572 id = AV_CODEC_ID_INDEO4;
3575 id = AV_CODEC_ID_INDEO3;
3578 id = AV_CODEC_ID_INDEO2;
3581 if (id != AV_CODEC_ID_NONE)
3584 } else if (!strcmp (mimetype, "video/x-divx")) {
3585 gint divxversion = 0;
3587 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3588 switch (divxversion) {
3590 id = AV_CODEC_ID_MSMPEG4V3;
3594 id = AV_CODEC_ID_MPEG4;
3598 if (id != AV_CODEC_ID_NONE)
3600 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3601 id = AV_CODEC_ID_MPEG4;
3603 } else if (!strcmp (mimetype, "video/x-xvid")) {
3604 id = AV_CODEC_ID_MPEG4;
3606 } else if (!strcmp (mimetype, "video/x-ffv")) {
3607 gint ffvversion = 0;
3609 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3611 id = AV_CODEC_ID_FFV1;
3614 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3615 const gchar *layout;
3617 layout = gst_structure_get_string (structure, "layout");
3618 if (layout == NULL) {
3620 } else if (!strcmp (layout, "quicktime")) {
3621 id = AV_CODEC_ID_ADPCM_IMA_QT;
3622 } else if (!strcmp (layout, "microsoft")) {
3623 id = AV_CODEC_ID_ADPCM_MS;
3624 } else if (!strcmp (layout, "dvi")) {
3625 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3626 } else if (!strcmp (layout, "4xm")) {
3627 id = AV_CODEC_ID_ADPCM_4XM;
3628 } else if (!strcmp (layout, "smjpeg")) {
3629 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3630 } else if (!strcmp (layout, "dk3")) {
3631 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3632 } else if (!strcmp (layout, "dk4")) {
3633 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3634 } else if (!strcmp (layout, "westwood")) {
3635 id = AV_CODEC_ID_ADPCM_IMA_WS;
3636 } else if (!strcmp (layout, "iss")) {
3637 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3638 } else if (!strcmp (layout, "xa")) {
3639 id = AV_CODEC_ID_ADPCM_XA;
3640 } else if (!strcmp (layout, "adx")) {
3641 id = AV_CODEC_ID_ADPCM_ADX;
3642 } else if (!strcmp (layout, "ea")) {
3643 id = AV_CODEC_ID_ADPCM_EA;
3644 } else if (!strcmp (layout, "g726")) {
3645 id = AV_CODEC_ID_ADPCM_G726;
3646 } else if (!strcmp (layout, "g721")) {
3647 id = AV_CODEC_ID_ADPCM_G726;
3648 } else if (!strcmp (layout, "ct")) {
3649 id = AV_CODEC_ID_ADPCM_CT;
3650 } else if (!strcmp (layout, "swf")) {
3651 id = AV_CODEC_ID_ADPCM_SWF;
3652 } else if (!strcmp (layout, "yamaha")) {
3653 id = AV_CODEC_ID_ADPCM_YAMAHA;
3654 } else if (!strcmp (layout, "sbpro2")) {
3655 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3656 } else if (!strcmp (layout, "sbpro3")) {
3657 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3658 } else if (!strcmp (layout, "sbpro4")) {
3659 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3661 if (id != AV_CODEC_ID_NONE)
3663 } else if (!strcmp (mimetype, "video/x-4xm")) {
3664 id = AV_CODEC_ID_4XM;
3666 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3667 const gchar *layout;
3669 layout = gst_structure_get_string (structure, "layout");
3672 } else if (!strcmp (layout, "roq")) {
3673 id = AV_CODEC_ID_ROQ_DPCM;
3674 } else if (!strcmp (layout, "interplay")) {
3675 id = AV_CODEC_ID_INTERPLAY_DPCM;
3676 } else if (!strcmp (layout, "xan")) {
3677 id = AV_CODEC_ID_XAN_DPCM;
3678 } else if (!strcmp (layout, "sol")) {
3679 id = AV_CODEC_ID_SOL_DPCM;
3681 if (id != AV_CODEC_ID_NONE)
3683 } else if (!strcmp (mimetype, "audio/x-flac")) {
3684 id = AV_CODEC_ID_FLAC;
3686 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3687 id = AV_CODEC_ID_SHORTEN;
3689 } else if (!strcmp (mimetype, "audio/x-alac")) {
3690 id = AV_CODEC_ID_ALAC;
3692 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3693 id = AV_CODEC_ID_CINEPAK;
3695 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3698 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3699 switch (rmversion) {
3701 id = AV_CODEC_ID_RV10;
3704 id = AV_CODEC_ID_RV20;
3707 id = AV_CODEC_ID_RV30;
3710 id = AV_CODEC_ID_RV40;
3714 if (id != AV_CODEC_ID_NONE)
3716 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3717 id = AV_CODEC_ID_SIPR;
3719 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3722 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3723 switch (raversion) {
3725 id = AV_CODEC_ID_RA_144;
3728 id = AV_CODEC_ID_RA_288;
3731 id = AV_CODEC_ID_COOK;
3735 if (id != AV_CODEC_ID_NONE)
3737 } else if (!strcmp (mimetype, "video/x-rle")) {
3738 const gchar *layout;
3740 if ((layout = gst_structure_get_string (structure, "layout"))) {
3741 if (!strcmp (layout, "microsoft")) {
3742 id = AV_CODEC_ID_MSRLE;
3746 } else if (!strcmp (mimetype, "video/x-xan")) {
3749 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3750 switch (wcversion) {
3752 id = AV_CODEC_ID_XAN_WC3;
3756 id = AV_CODEC_ID_XAN_WC4;
3763 } else if (!strcmp (mimetype, "audio/AMR")) {
3765 id = AV_CODEC_ID_AMR_NB;
3766 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3767 id = AV_CODEC_ID_AMR_WB;
3769 } else if (!strcmp (mimetype, "audio/qcelp")) {
3770 id = AV_CODEC_ID_QCELP;
3772 } else if (!strcmp (mimetype, "video/x-h264")) {
3773 id = AV_CODEC_ID_H264;
3775 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3776 gint flvversion = 0;
3778 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3779 switch (flvversion) {
3781 id = AV_CODEC_ID_FLV1;
3789 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3790 id = AV_CODEC_ID_NELLYMOSER;
3792 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3796 if (strlen (mimetype) <= 30 &&
3797 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3798 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3799 (codec = avcodec_find_encoder_by_name (ext))) {
3804 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3808 if (strlen (mimetype) <= 30 &&
3809 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3810 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3811 (codec = avcodec_find_encoder_by_name (ext))) {
3818 if (context != NULL) {
3819 if (video == TRUE) {
3820 context->codec_type = AVMEDIA_TYPE_VIDEO;
3821 } else if (audio == TRUE) {
3822 context->codec_type = AVMEDIA_TYPE_AUDIO;
3824 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3826 context->codec_id = id;
3827 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3830 if (id != AV_CODEC_ID_NONE) {
3831 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3833 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);