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_compliance_get_type (void)
72 static GType ffmpeg_compliance_type = 0;
73 static const GEnumValue compliance_types[] = {
74 {GST_FFMPEG_VERY_STRICT, "Strictly conform to older spec",
76 {GST_FFMPEG_STRICT, "Strictly conform to current spec", "strict"},
77 {GST_FFMPEG_NORMAL, "Normal behavior", "normal"},
78 {GST_FFMPEG_UNOFFICIAL, "Allow unofficial extensions", "unofficial"},
79 {GST_FFMPEG_EXPERIMENTAL, "Allow nonstandardized experimental things",
84 if (!ffmpeg_compliance_type) {
85 ffmpeg_compliance_type =
86 g_enum_register_static ("GstFFMpegCompliance", compliance_types);
88 return ffmpeg_compliance_type;
92 gst_ffmpeg_channel_positions_to_layout (GstAudioChannelPosition * pos,
97 gint channels_found = 0;
102 for (i = 0; i < channels; i++) {
103 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
104 if (_ff_to_gst_layout[j].gst == pos[i]) {
105 ret |= _ff_to_gst_layout[j].ff;
112 if (channels_found != channels)
118 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
119 GstAudioChannelPosition * pos)
122 gboolean none_layout = FALSE;
124 if (channel_layout == 0) {
125 nchannels = channels;
130 for (i = 0; i < 64; i++) {
131 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
136 if (nchannels != channels) {
137 GST_ERROR ("Number of channels is different (%u != %u)", channels,
139 nchannels = channels;
143 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
144 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
145 pos[j++] = _ff_to_gst_layout[i].gst;
147 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
152 if (j != nchannels) {
154 ("Unknown channels in channel layout - assuming NONE layout");
161 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
162 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
163 " - assuming NONE layout", channel_layout);
168 if (nchannels == 1) {
169 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
170 } else if (nchannels == 2) {
171 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
172 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
176 for (i = 0; i < nchannels; i++)
177 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
185 _gst_value_list_contains (const GValue * list, const GValue * value)
190 n = gst_value_list_get_size (list);
191 for (i = 0; i < n; i++) {
192 tmp = gst_value_list_get_value (list, i);
193 if (gst_value_compare (value, tmp) == GST_VALUE_EQUAL)
201 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
205 GstVideoFormat format;
207 if (!fmts || fmts[0] == -1) {
210 g_value_init (&va, GST_TYPE_LIST);
211 g_value_init (&v, G_TYPE_STRING);
212 for (i = 0; i <= PIX_FMT_NB; i++) {
213 format = gst_ffmpeg_pixfmt_to_videoformat (i);
214 if (format == GST_VIDEO_FORMAT_UNKNOWN)
216 g_value_set_string (&v, gst_video_format_to_string (format));
217 gst_value_list_append_value (&va, &v);
219 gst_caps_set_value (caps, "format", &va);
225 /* Only a single format */
226 g_value_init (&va, GST_TYPE_LIST);
227 g_value_init (&v, G_TYPE_STRING);
228 while (*fmts != -1) {
229 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
230 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
231 g_value_set_string (&v, gst_video_format_to_string (format));
232 /* Only append values we don't have yet */
233 if (!_gst_value_list_contains (&va, &v))
234 gst_value_list_append_value (&va, &v);
238 if (gst_value_list_get_size (&va) == 1) {
239 /* The single value is still in v */
240 gst_caps_set_value (caps, "format", &v);
241 } else if (gst_value_list_get_size (&va) > 1) {
242 gst_caps_set_value (caps, "format", &va);
248 /* this macro makes a caps width fixed or unfixed width/height
249 * properties depending on whether we've got a context.
251 * See below for why we use this.
253 * We should actually do this stuff at the end, like in riff-media.c,
254 * but I'm too lazy today. Maybe later.
257 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
258 enum CodecID codec_id, gboolean encode, const char *mimetype,
259 const char *fieldname, ...)
261 GstCaps *caps = NULL;
265 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
267 /* fixed, non probing context */
268 if (context != NULL && context->width != -1) {
271 caps = gst_caps_new_simple (mimetype,
272 "width", G_TYPE_INT, context->width,
273 "height", G_TYPE_INT, context->height, NULL);
275 num = context->time_base.den / context->ticks_per_frame;
276 denom = context->time_base.num;
279 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
282 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
283 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
287 GST_LOG ("setting framerate: %d/%d", num, denom);
288 gst_caps_set_simple (caps,
289 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
291 /* so we are after restricted caps in this case */
293 case AV_CODEC_ID_H261:
295 caps = gst_caps_new_simple (mimetype,
296 "width", G_TYPE_INT, 352,
297 "height", G_TYPE_INT, 288,
298 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
299 gst_caps_append (caps, gst_caps_new_simple (mimetype,
300 "width", G_TYPE_INT, 176,
301 "height", G_TYPE_INT, 144,
302 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
305 case AV_CODEC_ID_H263:
307 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
308 * because we want automatic negotiation to go as close to 320x240 as
310 const static gint widths[] = { 352, 704, 176, 1408, 128 };
311 const static gint heights[] = { 288, 576, 144, 1152, 96 };
313 gint n_sizes = G_N_ELEMENTS (widths);
315 caps = gst_caps_new_empty ();
316 for (i = 0; i < n_sizes; i++) {
317 temp = gst_caps_new_simple (mimetype,
318 "width", G_TYPE_INT, widths[i],
319 "height", G_TYPE_INT, heights[i],
320 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
322 gst_caps_append (caps, temp);
326 case AV_CODEC_ID_DVVIDEO:
333 gint framerate_n, framerate_d;
336 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
337 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
338 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
339 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
340 "I420", 720, 576, 16, 15, 25, 1}, {
341 "I420", 720, 576, 64, 45, 25, 1}, {
342 "Y41B", 720, 576, 16, 15, 25, 1}, {
343 "Y41B", 720, 576, 64, 45, 25, 1}, {
344 "Y42B", 720, 576, 16, 15, 25, 1}, {
345 "Y42B", 720, 576, 64, 45, 25, 1}, {
346 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
347 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
348 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
349 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
350 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
351 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
352 "Y42B", 960, 720, 1, 1, 50, 1}, {
353 "Y42B", 960, 720, 4, 3, 50, 1},};
355 gint n_sizes = G_N_ELEMENTS (profiles);
357 if (strcmp (mimetype, "video/x-raw") == 0) {
358 caps = gst_caps_new_empty ();
359 for (i = 0; i < n_sizes; i++) {
360 temp = gst_caps_new_simple (mimetype,
361 "format", G_TYPE_STRING, profiles[i].csp,
362 "width", G_TYPE_INT, profiles[i].width,
363 "height", G_TYPE_INT, profiles[i].height,
364 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
365 profiles[i].framerate_d, "pixel-aspect-ratio",
366 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
368 gst_caps_append (caps, temp);
371 caps = gst_caps_new_empty ();
372 for (i = 0; i < n_sizes; i++) {
373 temp = gst_caps_new_simple (mimetype,
374 "width", G_TYPE_INT, profiles[i].width,
375 "height", G_TYPE_INT, profiles[i].height,
376 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
377 profiles[i].framerate_d, "pixel-aspect-ratio",
378 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
380 gst_caps_append (caps, temp);
385 case AV_CODEC_ID_DNXHD:
387 caps = gst_caps_new_simple (mimetype,
388 "width", G_TYPE_INT, 1920,
389 "height", G_TYPE_INT, 1080,
390 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
391 gst_caps_append (caps, gst_caps_new_simple (mimetype,
392 "width", G_TYPE_INT, 1280,
393 "height", G_TYPE_INT, 720,
394 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
399 if (codec && codec->supported_framerates
400 && codec->supported_framerates[0].num != 0
401 && codec->supported_framerates[0].den != 0) {
404 const AVRational *rates = codec->supported_framerates;
406 if (rates[1].num == 0 && rates[1].den == 0) {
408 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
409 rates[0].num, rates[0].den, NULL);
411 g_value_init (&va, GST_TYPE_LIST);
412 g_value_init (&v, GST_TYPE_FRACTION);
414 while (rates->num != 0 && rates->den != 0) {
415 gst_value_set_fraction (&v, rates->num, rates->den);
416 gst_value_list_append_value (&va, &v);
420 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
421 gst_caps_set_value (caps, "framerate", &va);
427 caps = gst_caps_new_empty_simple (mimetype);
435 /* no fixed caps or special restrictions applied;
436 * default unfixed setting */
438 GST_DEBUG ("Creating default caps");
439 caps = gst_caps_new_empty_simple (mimetype);
442 va_start (var_args, fieldname);
443 gst_caps_set_simple_valist (caps, fieldname, var_args);
450 get_nbits_set (guint64 n)
455 for (i = 0; i < 64; i++) {
456 if ((n & (G_GUINT64_CONSTANT (1) << i)))
464 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
465 const enum AVSampleFormat *fmts)
469 GstAudioFormat format;
471 if (!fmts || fmts[0] == -1) {
474 g_value_init (&va, GST_TYPE_LIST);
475 g_value_init (&v, G_TYPE_STRING);
476 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
477 format = gst_ffmpeg_smpfmt_to_audioformat (i);
478 if (format == GST_AUDIO_FORMAT_UNKNOWN)
480 g_value_set_string (&v, gst_audio_format_to_string (format));
481 gst_value_list_append_value (&va, &v);
483 gst_caps_set_value (caps, "format", &va);
489 g_value_init (&va, GST_TYPE_LIST);
490 g_value_init (&v, G_TYPE_STRING);
491 while (*fmts != -1) {
492 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
493 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
494 g_value_set_string (&v, gst_audio_format_to_string (format));
495 /* Only append values we don't have yet */
496 if (!_gst_value_list_contains (&va, &v))
497 gst_value_list_append_value (&va, &v);
501 if (gst_value_list_get_size (&va) == 1) {
502 /* The single value is still in v */
503 gst_caps_set_value (caps, "format", &v);
504 } else if (gst_value_list_get_size (&va) > 1) {
505 gst_caps_set_value (caps, "format", &va);
511 /* same for audio - now with channels/sample rate
514 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
515 enum CodecID codec_id, gboolean encode, const char *mimetype,
516 const char *fieldname, ...)
518 GstCaps *caps = NULL;
522 /* fixed, non-probing context */
523 if (context != NULL && context->channels != -1) {
524 GstAudioChannelPosition pos[64];
527 caps = gst_caps_new_simple (mimetype,
528 "rate", G_TYPE_INT, context->sample_rate,
529 "channels", G_TYPE_INT, context->channels, NULL);
531 if (context->channels > 1 &&
532 gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
533 context->channels, pos) &&
534 gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
536 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask, NULL);
539 gint maxchannels = 2;
540 const gint *rates = NULL;
543 /* so we must be after restricted caps in this case */
545 case AV_CODEC_ID_AAC:
546 case AV_CODEC_ID_AAC_LATM:
547 case AV_CODEC_ID_DTS:
550 case AV_CODEC_ID_MP2:
552 const static gint l_rates[] =
553 { 48000, 44100, 32000, 24000, 22050, 16000 };
554 n_rates = G_N_ELEMENTS (l_rates);
558 case AV_CODEC_ID_EAC3:
559 case AV_CODEC_ID_AC3:
561 const static gint l_rates[] = { 48000, 44100, 32000 };
563 n_rates = G_N_ELEMENTS (l_rates);
567 case AV_CODEC_ID_ADPCM_G722:
569 const static gint l_rates[] = { 16000 };
570 n_rates = G_N_ELEMENTS (l_rates);
575 case AV_CODEC_ID_ADPCM_G726:
577 const static gint l_rates[] = { 8000 };
578 n_rates = G_N_ELEMENTS (l_rates);
583 case AV_CODEC_ID_ADPCM_SWF:
585 const static gint l_rates[] = { 11025, 22050, 44100 };
586 n_rates = G_N_ELEMENTS (l_rates);
590 case AV_CODEC_ID_ROQ_DPCM:
592 const static gint l_rates[] = { 22050 };
593 n_rates = G_N_ELEMENTS (l_rates);
597 case AV_CODEC_ID_AMR_NB:
599 const static gint l_rates[] = { 8000 };
601 n_rates = G_N_ELEMENTS (l_rates);
605 case AV_CODEC_ID_AMR_WB:
607 const static gint l_rates[] = { 16000 };
609 n_rates = G_N_ELEMENTS (l_rates);
617 /* regardless of encode/decode, open up channels if applicable */
618 /* Until decoders/encoders expose the maximum number of channels
619 * they support, we whitelist them here. */
621 case AV_CODEC_ID_WMAPRO:
622 case AV_CODEC_ID_TRUEHD:
629 if (codec && codec->channel_layouts) {
630 const uint64_t *layouts = codec->channel_layouts;
631 GstAudioChannelPosition pos[64];
633 caps = gst_caps_new_empty ();
635 gint nbits_set = get_nbits_set (*layouts);
637 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
640 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
643 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
645 "channels", G_TYPE_INT, nbits_set, NULL);
647 gst_caps_append (caps, tmp);
653 if (maxchannels == 1)
654 caps = gst_caps_new_simple (mimetype,
655 "channels", G_TYPE_INT, maxchannels, NULL);
657 caps = gst_caps_new_simple (mimetype,
658 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
662 GValue list = { 0, };
664 g_value_init (&list, GST_TYPE_LIST);
665 for (i = 0; i < n_rates; i++) {
668 g_value_init (&v, G_TYPE_INT);
669 g_value_set_int (&v, rates[i]);
670 gst_value_list_append_value (&list, &v);
673 gst_caps_set_value (caps, "rate", &list);
674 g_value_unset (&list);
675 } else if (codec && codec->supported_samplerates
676 && codec->supported_samplerates[0]) {
680 if (!codec->supported_samplerates[1]) {
681 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
682 codec->supported_samplerates[0], NULL);
684 const int *rates = codec->supported_samplerates;
686 g_value_init (&va, GST_TYPE_LIST);
687 g_value_init (&v, G_TYPE_INT);
690 g_value_set_int (&v, *rates);
691 gst_value_list_append_value (&va, &v);
694 gst_caps_set_value (caps, "rate", &va);
699 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
702 caps = gst_caps_new_empty_simple (mimetype);
705 va_start (var_args, fieldname);
706 gst_caps_set_simple_valist (caps, fieldname, var_args);
712 /* Convert a FFMPEG codec ID and optional AVCodecContext
713 * to a GstCaps. If the context is ommitted, no fixed values
714 * for video/audio size will be included in the GstCaps
716 * CodecID is primarily meant for compressed data GstCaps!
718 * encode is a special parameter. gstffmpegdec will say
719 * FALSE, gstffmpegenc will say TRUE. The output caps
720 * depends on this, in such a way that it will be very
721 * specific, defined, fixed and correct caps for encoders,
722 * yet very wide, "forgiving" caps for decoders. Example
723 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
724 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
729 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
730 AVCodecContext * context, gboolean encode)
732 GstCaps *caps = NULL;
733 gboolean buildcaps = FALSE;
735 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
738 case AV_CODEC_ID_MPEG1VIDEO:
740 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
741 "mpegversion", G_TYPE_INT, 1,
742 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
745 case AV_CODEC_ID_MPEG2VIDEO:
749 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
750 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
753 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
754 * the MPEG video stream headers, so may be omitted from caps. */
755 caps = gst_caps_new_simple ("video/mpeg",
756 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
757 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
761 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
762 /* this is a special ID - don't need it in GStreamer, I think */
765 case AV_CODEC_ID_H263:
768 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
769 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
770 G_TYPE_STRING, "h263", NULL);
772 /* don't pass codec_id, we can decode other variants with the H263
773 * decoder that don't have specific size requirements
776 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
777 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
781 case AV_CODEC_ID_H263P:
783 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
784 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
786 if (encode && context) {
788 gst_caps_set_simple (caps,
789 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
790 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
791 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
792 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
797 case AV_CODEC_ID_H263I:
799 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
800 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
803 case AV_CODEC_ID_H261:
805 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
809 case AV_CODEC_ID_RV10:
810 case AV_CODEC_ID_RV20:
811 case AV_CODEC_ID_RV30:
812 case AV_CODEC_ID_RV40:
817 case AV_CODEC_ID_RV40:
820 case AV_CODEC_ID_RV30:
823 case AV_CODEC_ID_RV20:
831 /* FIXME: context->sub_id must be filled in during decoding */
833 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
834 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
836 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
837 if (context->extradata_size >= 8) {
838 gst_caps_set_simple (caps,
839 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
846 case AV_CODEC_ID_MP1:
848 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
849 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
852 case AV_CODEC_ID_MP2:
854 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
855 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
858 case AV_CODEC_ID_MP3:
862 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
863 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
865 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
866 * in the MPEG audio header, so may be omitted from caps. */
867 caps = gst_caps_new_simple ("audio/mpeg",
868 "mpegversion", G_TYPE_INT, 1,
869 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
873 case AV_CODEC_ID_MUSEPACK7:
875 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
876 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
880 case AV_CODEC_ID_MUSEPACK8:
882 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
883 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
887 case AV_CODEC_ID_AC3:
890 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
894 case AV_CODEC_ID_EAC3:
897 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
901 case AV_CODEC_ID_TRUEHD:
903 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
904 "audio/x-true-hd", NULL);
907 case AV_CODEC_ID_ATRAC1:
909 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
910 "audio/x-vnd.sony.atrac1", NULL);
913 case AV_CODEC_ID_ATRAC3:
915 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
916 "audio/x-vnd.sony.atrac3", NULL);
919 case AV_CODEC_ID_DTS:
921 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
925 case AV_CODEC_ID_APE:
927 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
928 "audio/x-ffmpeg-parsed-ape", NULL);
930 gst_caps_set_simple (caps,
931 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
935 case AV_CODEC_ID_MLP:
937 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
941 case AV_CODEC_ID_IMC:
943 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
947 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
948 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
949 * sp5x is, but it's apparently something JPEG... We don't separate
950 * between those in GStreamer. Should we (at least between MJPEG,
951 * MJPEG-B and sp5x decoding...)? */
952 case AV_CODEC_ID_MJPEG:
953 case AV_CODEC_ID_LJPEG:
955 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
956 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
959 case AV_CODEC_ID_SP5X:
961 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
965 case AV_CODEC_ID_MJPEGB:
967 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
968 "video/x-mjpeg-b", NULL);
971 case AV_CODEC_ID_MPEG4:
972 if (encode && context != NULL) {
973 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
974 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
975 switch (context->codec_tag) {
976 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
978 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
979 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
981 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
985 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
986 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
987 "mpegversion", G_TYPE_INT, 4, NULL);
991 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
993 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
994 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
997 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
998 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
1000 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1001 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1003 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1004 encode, "video/x-xvid", NULL));
1005 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1006 encode, "video/x-3ivx", NULL));
1011 case AV_CODEC_ID_RAWVIDEO:
1013 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1016 case AV_CODEC_ID_MSMPEG4V1:
1017 case AV_CODEC_ID_MSMPEG4V2:
1018 case AV_CODEC_ID_MSMPEG4V3:
1020 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1022 /* encode-FIXME: bitrate */
1024 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1025 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1026 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1027 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1028 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1033 case AV_CODEC_ID_WMV1:
1034 case AV_CODEC_ID_WMV2:
1036 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1039 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1040 "wmvversion", G_TYPE_INT, version, NULL);
1044 case AV_CODEC_ID_FLV1:
1046 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1047 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1050 case AV_CODEC_ID_SVQ1:
1052 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1053 "svqversion", G_TYPE_INT, 1, NULL);
1056 case AV_CODEC_ID_SVQ3:
1058 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1059 "svqversion", G_TYPE_INT, 3, NULL);
1062 case AV_CODEC_ID_DVAUDIO:
1064 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1068 case AV_CODEC_ID_DVVIDEO:
1070 if (encode && context) {
1071 const gchar *format;
1073 switch (context->pix_fmt) {
1074 case PIX_FMT_YUYV422:
1077 case PIX_FMT_YUV420P:
1080 case PIX_FMT_YUVA420P:
1083 case PIX_FMT_YUV411P:
1086 case PIX_FMT_YUV422P:
1089 case PIX_FMT_YUV410P:
1094 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1100 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1101 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1105 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1106 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1111 case AV_CODEC_ID_WMAV1:
1112 case AV_CODEC_ID_WMAV2:
1114 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1118 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1119 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1120 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1124 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1125 "wmaversion", G_TYPE_INT, version, "block_align",
1126 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1131 case AV_CODEC_ID_WMAPRO:
1134 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1135 "wmaversion", G_TYPE_INT, 3, NULL);
1138 case AV_CODEC_ID_WMALOSSLESS:
1140 /* libav only supports a depth of 16 at the moment */
1142 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1143 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1146 case AV_CODEC_ID_WMAVOICE:
1149 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1154 case AV_CODEC_ID_MACE3:
1155 case AV_CODEC_ID_MACE6:
1157 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1160 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1161 "maceversion", G_TYPE_INT, version, NULL);
1165 case AV_CODEC_ID_HUFFYUV:
1167 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1168 "video/x-huffyuv", NULL);
1170 gst_caps_set_simple (caps,
1171 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1175 case AV_CODEC_ID_CYUV:
1177 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1178 "video/x-compressed-yuv", NULL);
1181 case AV_CODEC_ID_H264:
1183 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1184 "alignment", G_TYPE_STRING, "au", NULL);
1186 GValue arr = { 0, };
1187 GValue item = { 0, };
1188 g_value_init (&arr, GST_TYPE_LIST);
1189 g_value_init (&item, G_TYPE_STRING);
1190 g_value_set_string (&item, "avc");
1191 gst_value_list_append_value (&arr, &item);
1192 g_value_set_string (&item, "byte-stream");
1193 gst_value_list_append_value (&arr, &item);
1194 g_value_unset (&item);
1195 gst_caps_set_value (caps, "stream-format", &arr);
1196 g_value_unset (&arr);
1200 case AV_CODEC_ID_INDEO5:
1202 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1203 "indeoversion", G_TYPE_INT, 5, NULL);
1206 case AV_CODEC_ID_INDEO4:
1208 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1209 "indeoversion", G_TYPE_INT, 4, NULL);
1212 case AV_CODEC_ID_INDEO3:
1214 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1215 "indeoversion", G_TYPE_INT, 3, NULL);
1218 case AV_CODEC_ID_INDEO2:
1220 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1221 "indeoversion", G_TYPE_INT, 2, NULL);
1224 case AV_CODEC_ID_FLASHSV:
1226 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1227 "video/x-flash-screen", NULL);
1230 case AV_CODEC_ID_VP3:
1232 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1236 case AV_CODEC_ID_VP5:
1238 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1242 case AV_CODEC_ID_VP6:
1244 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1248 case AV_CODEC_ID_VP6F:
1250 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1251 "video/x-vp6-flash", NULL);
1254 case AV_CODEC_ID_VP6A:
1256 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1257 "video/x-vp6-alpha", NULL);
1260 case AV_CODEC_ID_VP8:
1262 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1266 case AV_CODEC_ID_THEORA:
1268 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1269 "video/x-theora", NULL);
1272 case AV_CODEC_ID_AAC:
1275 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1279 GValue arr = { 0, };
1280 GValue item = { 0, };
1282 g_value_init (&arr, GST_TYPE_LIST);
1283 g_value_init (&item, G_TYPE_INT);
1284 g_value_set_int (&item, 2);
1285 gst_value_list_append_value (&arr, &item);
1286 g_value_set_int (&item, 4);
1287 gst_value_list_append_value (&arr, &item);
1288 g_value_unset (&item);
1290 gst_caps_set_value (caps, "mpegversion", &arr);
1291 g_value_unset (&arr);
1293 g_value_init (&arr, GST_TYPE_LIST);
1294 g_value_init (&item, G_TYPE_STRING);
1295 g_value_set_string (&item, "raw");
1296 gst_value_list_append_value (&arr, &item);
1297 g_value_set_string (&item, "adts");
1298 gst_value_list_append_value (&arr, &item);
1299 g_value_set_string (&item, "adif");
1300 gst_value_list_append_value (&arr, &item);
1301 g_value_unset (&item);
1303 gst_caps_set_value (caps, "stream-format", &arr);
1304 g_value_unset (&arr);
1306 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1307 "stream-format", G_TYPE_STRING, "raw",
1308 "base-profile", G_TYPE_STRING, "lc", NULL);
1310 if (context && context->extradata_size > 0)
1311 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1312 context->extradata, context->extradata_size);
1317 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1318 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1319 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1323 case AV_CODEC_ID_ASV1:
1325 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1326 "asusversion", G_TYPE_INT, 1, NULL);
1328 case AV_CODEC_ID_ASV2:
1330 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1331 "asusversion", G_TYPE_INT, 2, NULL);
1334 case AV_CODEC_ID_FFV1:
1336 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1337 "ffvversion", G_TYPE_INT, 1, NULL);
1340 case AV_CODEC_ID_4XM:
1342 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1346 case AV_CODEC_ID_XAN_WC3:
1347 case AV_CODEC_ID_XAN_WC4:
1349 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1350 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1353 case AV_CODEC_ID_CLJR:
1355 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1356 "video/x-cirrus-logic-accupak", NULL);
1359 case AV_CODEC_ID_FRAPS:
1361 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1365 case AV_CODEC_ID_MDEC:
1366 case AV_CODEC_ID_ROQ:
1367 case AV_CODEC_ID_INTERPLAY_VIDEO:
1371 case AV_CODEC_ID_VCR1:
1373 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1374 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1377 case AV_CODEC_ID_RPZA:
1379 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1380 "video/x-apple-video", NULL);
1383 case AV_CODEC_ID_CINEPAK:
1385 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1386 "video/x-cinepak", NULL);
1389 /* WS_VQA belogns here (order) */
1391 case AV_CODEC_ID_MSRLE:
1393 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1394 "layout", G_TYPE_STRING, "microsoft", NULL);
1396 gst_caps_set_simple (caps,
1397 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1399 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1403 case AV_CODEC_ID_QTRLE:
1405 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1406 "layout", G_TYPE_STRING, "quicktime", NULL);
1408 gst_caps_set_simple (caps,
1409 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1411 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1415 case AV_CODEC_ID_MSVIDEO1:
1417 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1418 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1421 case AV_CODEC_ID_MSS1:
1423 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1424 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1427 case AV_CODEC_ID_MSS2:
1429 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1430 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1433 case AV_CODEC_ID_WMV3:
1435 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1436 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1438 case AV_CODEC_ID_VC1:
1440 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1441 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1443 case AV_CODEC_ID_QDM2:
1445 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1449 case AV_CODEC_ID_MSZH:
1451 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1455 case AV_CODEC_ID_ZLIB:
1457 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1461 case AV_CODEC_ID_TRUEMOTION1:
1463 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1464 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1466 case AV_CODEC_ID_TRUEMOTION2:
1468 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1469 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1472 case AV_CODEC_ID_ULTI:
1474 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1475 "video/x-ultimotion", NULL);
1478 case AV_CODEC_ID_TSCC:
1480 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1481 "video/x-camtasia", NULL);
1483 gst_caps_set_simple (caps,
1484 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1486 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1490 case AV_CODEC_ID_TSCC2:
1492 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1493 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1496 case AV_CODEC_ID_KMVC:
1498 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1502 case AV_CODEC_ID_NUV:
1504 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1508 case AV_CODEC_ID_GIF:
1510 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1514 case AV_CODEC_ID_PNG:
1516 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1520 case AV_CODEC_ID_PPM:
1522 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1526 case AV_CODEC_ID_PBM:
1528 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1532 case AV_CODEC_ID_PAM:
1534 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1535 "image/x-portable-anymap", NULL);
1538 case AV_CODEC_ID_PGM:
1540 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1541 "image/x-portable-graymap", NULL);
1544 case AV_CODEC_ID_PCX:
1546 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1550 case AV_CODEC_ID_SGI:
1552 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1556 case AV_CODEC_ID_TARGA:
1558 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1562 case AV_CODEC_ID_TIFF:
1564 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1568 case AV_CODEC_ID_SUNRAST:
1570 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1571 "image/x-sun-raster", NULL);
1574 case AV_CODEC_ID_SMC:
1576 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1580 case AV_CODEC_ID_QDRAW:
1582 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1586 case AV_CODEC_ID_DNXHD:
1588 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1592 case AV_CODEC_ID_PRORES:
1594 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1595 "video/x-prores", NULL);
1598 case AV_CODEC_ID_MIMIC:
1600 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1604 case AV_CODEC_ID_VMNC:
1606 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1610 case AV_CODEC_ID_TRUESPEECH:
1612 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1613 "audio/x-truespeech", NULL);
1616 case AV_CODEC_ID_QCELP:
1618 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1622 case AV_CODEC_ID_AMV:
1624 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1628 case AV_CODEC_ID_AASC:
1630 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1634 case AV_CODEC_ID_LOCO:
1636 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1640 case AV_CODEC_ID_ZMBV:
1642 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1646 case AV_CODEC_ID_LAGARITH:
1648 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1649 "video/x-lagarith", NULL);
1652 case AV_CODEC_ID_CSCD:
1654 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1655 "video/x-camstudio", NULL);
1657 gst_caps_set_simple (caps,
1658 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1660 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1664 case AV_CODEC_ID_WS_VQA:
1665 case AV_CODEC_ID_IDCIN:
1666 case AV_CODEC_ID_8BPS:
1667 case AV_CODEC_ID_FLIC:
1668 case AV_CODEC_ID_VMDVIDEO:
1669 case AV_CODEC_ID_VMDAUDIO:
1670 case AV_CODEC_ID_SNOW:
1671 case AV_CODEC_ID_VIXL:
1672 case AV_CODEC_ID_QPEG:
1673 case AV_CODEC_ID_PGMYUV:
1674 case AV_CODEC_ID_FFVHUFF:
1675 case AV_CODEC_ID_WNV1:
1676 case AV_CODEC_ID_MP3ADU:
1677 case AV_CODEC_ID_MP3ON4:
1678 case AV_CODEC_ID_WESTWOOD_SND1:
1679 case AV_CODEC_ID_MMVIDEO:
1680 case AV_CODEC_ID_AVS:
1681 case AV_CODEC_ID_CAVS:
1685 /* weird quasi-codecs for the demuxers only */
1686 case AV_CODEC_ID_PCM_S16LE:
1687 case AV_CODEC_ID_PCM_S16BE:
1688 case AV_CODEC_ID_PCM_U16LE:
1689 case AV_CODEC_ID_PCM_U16BE:
1690 case AV_CODEC_ID_PCM_S8:
1691 case AV_CODEC_ID_PCM_U8:
1693 GstAudioFormat format;
1696 case AV_CODEC_ID_PCM_S16LE:
1697 format = GST_AUDIO_FORMAT_S16LE;
1699 case AV_CODEC_ID_PCM_S16BE:
1700 format = GST_AUDIO_FORMAT_S16BE;
1702 case AV_CODEC_ID_PCM_U16LE:
1703 format = GST_AUDIO_FORMAT_U16LE;
1705 case AV_CODEC_ID_PCM_U16BE:
1706 format = GST_AUDIO_FORMAT_U16BE;
1708 case AV_CODEC_ID_PCM_S8:
1709 format = GST_AUDIO_FORMAT_S8;
1711 case AV_CODEC_ID_PCM_U8:
1712 format = GST_AUDIO_FORMAT_U8;
1716 g_assert (0); /* don't worry, we never get here */
1721 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1722 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1723 "layout", G_TYPE_STRING, "interleaved", NULL);
1727 case AV_CODEC_ID_PCM_MULAW:
1729 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1733 case AV_CODEC_ID_PCM_ALAW:
1735 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1739 case AV_CODEC_ID_ADPCM_G722:
1741 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1744 gst_caps_set_simple (caps,
1745 "block_align", G_TYPE_INT, context->block_align,
1746 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1749 case AV_CODEC_ID_ADPCM_G726:
1751 /* the G726 decoder can also handle G721 */
1753 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1754 "layout", G_TYPE_STRING, "g726", NULL);
1756 gst_caps_set_simple (caps,
1757 "block_align", G_TYPE_INT, context->block_align,
1758 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1761 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1762 "layout", G_TYPE_STRING, "g721",
1763 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1767 case AV_CODEC_ID_ADPCM_IMA_QT:
1768 case AV_CODEC_ID_ADPCM_IMA_WAV:
1769 case AV_CODEC_ID_ADPCM_IMA_DK3:
1770 case AV_CODEC_ID_ADPCM_IMA_DK4:
1771 case AV_CODEC_ID_ADPCM_IMA_WS:
1772 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1773 case AV_CODEC_ID_ADPCM_IMA_AMV:
1774 case AV_CODEC_ID_ADPCM_IMA_ISS:
1775 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1776 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1777 case AV_CODEC_ID_ADPCM_MS:
1778 case AV_CODEC_ID_ADPCM_4XM:
1779 case AV_CODEC_ID_ADPCM_XA:
1780 case AV_CODEC_ID_ADPCM_ADX:
1781 case AV_CODEC_ID_ADPCM_EA:
1782 case AV_CODEC_ID_ADPCM_CT:
1783 case AV_CODEC_ID_ADPCM_SWF:
1784 case AV_CODEC_ID_ADPCM_YAMAHA:
1785 case AV_CODEC_ID_ADPCM_SBPRO_2:
1786 case AV_CODEC_ID_ADPCM_SBPRO_3:
1787 case AV_CODEC_ID_ADPCM_SBPRO_4:
1788 case AV_CODEC_ID_ADPCM_EA_R1:
1789 case AV_CODEC_ID_ADPCM_EA_R2:
1790 case AV_CODEC_ID_ADPCM_EA_R3:
1791 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1792 case AV_CODEC_ID_ADPCM_EA_XAS:
1793 case AV_CODEC_ID_ADPCM_THP:
1795 const gchar *layout = NULL;
1798 case AV_CODEC_ID_ADPCM_IMA_QT:
1799 layout = "quicktime";
1801 case AV_CODEC_ID_ADPCM_IMA_WAV:
1804 case AV_CODEC_ID_ADPCM_IMA_DK3:
1807 case AV_CODEC_ID_ADPCM_IMA_DK4:
1810 case AV_CODEC_ID_ADPCM_IMA_WS:
1811 layout = "westwood";
1813 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1816 case AV_CODEC_ID_ADPCM_IMA_AMV:
1819 case AV_CODEC_ID_ADPCM_IMA_ISS:
1822 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1825 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1828 case AV_CODEC_ID_ADPCM_MS:
1829 layout = "microsoft";
1831 case AV_CODEC_ID_ADPCM_4XM:
1834 case AV_CODEC_ID_ADPCM_XA:
1837 case AV_CODEC_ID_ADPCM_ADX:
1840 case AV_CODEC_ID_ADPCM_EA:
1843 case AV_CODEC_ID_ADPCM_CT:
1846 case AV_CODEC_ID_ADPCM_SWF:
1849 case AV_CODEC_ID_ADPCM_YAMAHA:
1852 case AV_CODEC_ID_ADPCM_SBPRO_2:
1855 case AV_CODEC_ID_ADPCM_SBPRO_3:
1858 case AV_CODEC_ID_ADPCM_SBPRO_4:
1861 case AV_CODEC_ID_ADPCM_EA_R1:
1864 case AV_CODEC_ID_ADPCM_EA_R2:
1867 case AV_CODEC_ID_ADPCM_EA_R3:
1870 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1871 layout = "ea-maxis-xa";
1873 case AV_CODEC_ID_ADPCM_EA_XAS:
1876 case AV_CODEC_ID_ADPCM_THP:
1880 g_assert (0); /* don't worry, we never get here */
1884 /* FIXME: someone please check whether we need additional properties
1885 * in this caps definition. */
1887 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1888 "layout", G_TYPE_STRING, layout, NULL);
1890 gst_caps_set_simple (caps,
1891 "block_align", G_TYPE_INT, context->block_align,
1892 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1896 case AV_CODEC_ID_AMR_NB:
1898 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1902 case AV_CODEC_ID_AMR_WB:
1904 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1908 case AV_CODEC_ID_GSM:
1910 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1914 case AV_CODEC_ID_GSM_MS:
1916 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1920 case AV_CODEC_ID_NELLYMOSER:
1922 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1923 "audio/x-nellymoser", NULL);
1926 case AV_CODEC_ID_SIPR:
1929 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1932 gst_caps_set_simple (caps,
1933 "leaf_size", G_TYPE_INT, context->block_align,
1934 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1939 case AV_CODEC_ID_RA_144:
1940 case AV_CODEC_ID_RA_288:
1941 case AV_CODEC_ID_COOK:
1946 case AV_CODEC_ID_RA_144:
1949 case AV_CODEC_ID_RA_288:
1952 case AV_CODEC_ID_COOK:
1959 /* FIXME: properties? */
1961 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1962 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1964 gst_caps_set_simple (caps,
1965 "leaf_size", G_TYPE_INT, context->block_align,
1966 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1971 case AV_CODEC_ID_ROQ_DPCM:
1972 case AV_CODEC_ID_INTERPLAY_DPCM:
1973 case AV_CODEC_ID_XAN_DPCM:
1974 case AV_CODEC_ID_SOL_DPCM:
1976 const gchar *layout = NULL;
1979 case AV_CODEC_ID_ROQ_DPCM:
1982 case AV_CODEC_ID_INTERPLAY_DPCM:
1983 layout = "interplay";
1985 case AV_CODEC_ID_XAN_DPCM:
1988 case AV_CODEC_ID_SOL_DPCM:
1992 g_assert (0); /* don't worry, we never get here */
1996 /* FIXME: someone please check whether we need additional properties
1997 * in this caps definition. */
1999 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2000 "layout", G_TYPE_STRING, layout, NULL);
2002 gst_caps_set_simple (caps,
2003 "block_align", G_TYPE_INT, context->block_align,
2004 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2008 case AV_CODEC_ID_SHORTEN:
2009 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2012 case AV_CODEC_ID_ALAC:
2014 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2017 gst_caps_set_simple (caps,
2018 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2022 case AV_CODEC_ID_FLAC:
2023 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2024 * encoder case, we want to add things like samplerate, channels... */
2026 caps = gst_caps_new_empty_simple ("audio/x-flac");
2030 case AV_CODEC_ID_S302M:
2031 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2034 case AV_CODEC_ID_DVD_SUBTITLE:
2035 case AV_CODEC_ID_DVB_SUBTITLE:
2038 case AV_CODEC_ID_BMP:
2039 caps = gst_caps_new_empty_simple ("image/bmp");
2041 case AV_CODEC_ID_TTA:
2043 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2046 gst_caps_set_simple (caps,
2047 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2050 case AV_CODEC_ID_TWINVQ:
2052 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2053 "audio/x-twin-vq", NULL);
2056 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2063 if ((codec = avcodec_find_decoder (codec_id)) ||
2064 (codec = avcodec_find_encoder (codec_id))) {
2067 GST_LOG ("Could not create stream format caps for %s", codec->name);
2069 switch (codec->type) {
2070 case AVMEDIA_TYPE_VIDEO:
2071 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2073 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2076 case AVMEDIA_TYPE_AUDIO:
2077 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2079 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2081 gst_caps_set_simple (caps,
2082 "block_align", G_TYPE_INT, context->block_align,
2083 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2094 /* set private data */
2095 if (context && context->extradata_size > 0) {
2096 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2098 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2099 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2100 gst_buffer_unref (data);
2103 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2106 GST_LOG ("No caps found for codec_id=%d", codec_id);
2112 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2113 * to a GstCaps. If the context is ommitted, no fixed values
2114 * for video/audio size will be included in the GstCaps
2116 * See below for usefullness
2120 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2121 enum CodecID codec_id)
2123 GstCaps *caps = NULL;
2124 GstVideoFormat format;
2126 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2128 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2129 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2130 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2134 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2136 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2143 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2145 switch (sample_fmt) {
2146 case AV_SAMPLE_FMT_U8:
2147 case AV_SAMPLE_FMT_U8P:
2148 return GST_AUDIO_FORMAT_U8;
2150 case AV_SAMPLE_FMT_S16:
2151 case AV_SAMPLE_FMT_S16P:
2152 return GST_AUDIO_FORMAT_S16;
2154 case AV_SAMPLE_FMT_S32:
2155 case AV_SAMPLE_FMT_S32P:
2156 return GST_AUDIO_FORMAT_S32;
2158 case AV_SAMPLE_FMT_FLT:
2159 case AV_SAMPLE_FMT_FLTP:
2160 return GST_AUDIO_FORMAT_F32;
2162 case AV_SAMPLE_FMT_DBL:
2163 case AV_SAMPLE_FMT_DBLP:
2164 return GST_AUDIO_FORMAT_F64;
2168 return GST_AUDIO_FORMAT_UNKNOWN;
2173 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2174 * to a GstCaps. If the context is ommitted, no fixed values
2175 * for video/audio size will be included in the GstCaps
2177 * See below for usefullness
2181 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2182 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2184 GstCaps *caps = NULL;
2185 GstAudioFormat format;
2187 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2189 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2190 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2191 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2192 "layout", G_TYPE_STRING, "interleaved", NULL);
2193 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2195 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2202 caps_has_field (GstCaps * caps, const gchar * field)
2206 n = gst_caps_get_size (caps);
2207 for (i = 0; i < n; i++) {
2208 GstStructure *s = gst_caps_get_structure (caps, i);
2210 if (gst_structure_has_field (s, field))
2218 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2219 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2221 GstCaps *caps = NULL;
2223 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2224 context, codec_id, encode, codec);
2226 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2227 codec->sample_fmts, codec->supported_samplerates);
2230 /* Specific codec context */
2232 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2235 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2236 "layout", G_TYPE_STRING, "interleaved", NULL);
2237 if (!caps_has_field (caps, "format"))
2238 gst_ffmpeg_audio_set_sample_fmts (caps,
2239 codec ? codec->sample_fmts : NULL);
2246 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2247 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2251 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2252 context, codec_id, encode, codec);
2255 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2258 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2260 if (!caps_has_field (caps, "format"))
2261 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2266 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2267 * and other audio properties in a AVCodecContext.
2269 * For usefullness, see below
2273 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2274 AVCodecContext * context, gboolean raw)
2276 GstStructure *structure;
2278 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2280 g_return_if_fail (gst_caps_get_size (caps) == 1);
2282 structure = gst_caps_get_structure (caps, 0);
2284 gst_structure_get_int (structure, "channels", &context->channels);
2285 gst_structure_get_int (structure, "rate", &context->sample_rate);
2286 gst_structure_get_int (structure, "block_align", &context->block_align);
2287 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2292 if (gst_structure_has_name (structure, "audio/x-raw")) {
2293 if ((fmt = gst_structure_get_string (structure, "format"))) {
2294 format = gst_audio_format_from_string (fmt);
2299 case GST_AUDIO_FORMAT_F32:
2300 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2302 case GST_AUDIO_FORMAT_F64:
2303 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2305 case GST_AUDIO_FORMAT_S32:
2306 context->sample_fmt = AV_SAMPLE_FMT_S32;
2308 case GST_AUDIO_FORMAT_S16:
2309 context->sample_fmt = AV_SAMPLE_FMT_S16;
2316 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2317 * and other video properties in a AVCodecContext.
2319 * For usefullness, see below
2323 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2324 AVCodecContext * context, gboolean raw)
2326 GstStructure *structure;
2328 const GValue *par = NULL;
2330 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2332 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2333 g_return_if_fail (gst_caps_get_size (caps) == 1);
2334 structure = gst_caps_get_structure (caps, 0);
2336 gst_structure_get_int (structure, "width", &context->width);
2337 gst_structure_get_int (structure, "height", &context->height);
2338 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2340 fps = gst_structure_get_value (structure, "framerate");
2341 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2343 /* somehow these seem mixed up.. */
2344 context->time_base.den = gst_value_get_fraction_numerator (fps);
2345 context->time_base.num = gst_value_get_fraction_denominator (fps);
2346 context->ticks_per_frame = 1;
2348 GST_DEBUG ("setting framerate %d/%d = %lf",
2349 context->time_base.den, context->time_base.num,
2350 1. * context->time_base.den / context->time_base.num);
2353 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2354 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2356 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2357 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2359 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2360 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2361 1. * context->sample_aspect_ratio.den /
2362 context->sample_aspect_ratio.num);
2368 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2370 if (gst_structure_has_name (structure, "video/x-raw")) {
2371 if ((fmt = gst_structure_get_string (structure, "format"))) {
2372 format = gst_video_format_from_string (fmt);
2377 case GST_VIDEO_FORMAT_YUY2:
2378 context->pix_fmt = PIX_FMT_YUYV422;
2380 case GST_VIDEO_FORMAT_I420:
2381 context->pix_fmt = PIX_FMT_YUV420P;
2383 case GST_VIDEO_FORMAT_A420:
2384 context->pix_fmt = PIX_FMT_YUVA420P;
2386 case GST_VIDEO_FORMAT_Y41B:
2387 context->pix_fmt = PIX_FMT_YUV411P;
2389 case GST_VIDEO_FORMAT_Y42B:
2390 context->pix_fmt = PIX_FMT_YUV422P;
2392 case GST_VIDEO_FORMAT_YUV9:
2393 context->pix_fmt = PIX_FMT_YUV410P;
2395 case GST_VIDEO_FORMAT_Y444:
2396 context->pix_fmt = PIX_FMT_YUV444P;
2398 case GST_VIDEO_FORMAT_GRAY8:
2399 context->pix_fmt = PIX_FMT_GRAY8;
2401 case GST_VIDEO_FORMAT_xRGB:
2402 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2403 context->pix_fmt = PIX_FMT_RGB32;
2406 case GST_VIDEO_FORMAT_BGRx:
2407 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2408 context->pix_fmt = PIX_FMT_RGB32;
2411 case GST_VIDEO_FORMAT_RGB:
2412 context->pix_fmt = PIX_FMT_RGB24;
2414 case GST_VIDEO_FORMAT_BGR:
2415 context->pix_fmt = PIX_FMT_BGR24;
2417 case GST_VIDEO_FORMAT_RGB16:
2418 context->pix_fmt = PIX_FMT_RGB565;
2420 case GST_VIDEO_FORMAT_RGB15:
2421 context->pix_fmt = PIX_FMT_RGB555;
2423 case GST_VIDEO_FORMAT_RGB8P:
2424 context->pix_fmt = PIX_FMT_PAL8;
2433 GstVideoFormat format;
2434 enum PixelFormat pixfmt;
2437 /* FIXME : FILLME */
2438 static const PixToFmt pixtofmttable[] = {
2439 /* GST_VIDEO_FORMAT_I420, */
2440 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2441 /* Note : this should use a different chroma placement */
2442 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2444 /* GST_VIDEO_FORMAT_YV12, */
2445 /* GST_VIDEO_FORMAT_YUY2, */
2446 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2447 /* GST_VIDEO_FORMAT_UYVY, */
2448 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2449 /* GST_VIDEO_FORMAT_AYUV, */
2450 /* GST_VIDEO_FORMAT_RGBx, */
2451 /* GST_VIDEO_FORMAT_BGRx, */
2452 /* GST_VIDEO_FORMAT_xRGB, */
2453 /* GST_VIDEO_FORMAT_xBGR, */
2454 /* GST_VIDEO_FORMAT_RGBA, */
2455 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2456 /* GST_VIDEO_FORMAT_BGRA, */
2457 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2458 /* GST_VIDEO_FORMAT_ARGB, */
2459 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2460 /* GST_VIDEO_FORMAT_ABGR, */
2461 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2462 /* GST_VIDEO_FORMAT_RGB, */
2463 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2464 /* GST_VIDEO_FORMAT_BGR, */
2465 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2466 /* GST_VIDEO_FORMAT_Y41B, */
2467 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2468 /* GST_VIDEO_FORMAT_Y42B, */
2469 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2470 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2471 /* GST_VIDEO_FORMAT_YVYU, */
2472 /* GST_VIDEO_FORMAT_Y444, */
2473 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2474 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2475 /* GST_VIDEO_FORMAT_v210, */
2476 /* GST_VIDEO_FORMAT_v216, */
2477 /* GST_VIDEO_FORMAT_NV12, */
2478 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2479 /* GST_VIDEO_FORMAT_NV21, */
2480 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2481 /* GST_VIDEO_FORMAT_GRAY8, */
2482 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2483 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2484 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2485 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2486 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2487 /* GST_VIDEO_FORMAT_v308, */
2488 /* GST_VIDEO_FORMAT_Y800, */
2489 /* GST_VIDEO_FORMAT_Y16, */
2490 /* GST_VIDEO_FORMAT_RGB16, */
2491 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2492 /* GST_VIDEO_FORMAT_BGR16, */
2493 /* GST_VIDEO_FORMAT_RGB15, */
2494 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2495 /* GST_VIDEO_FORMAT_BGR15, */
2496 /* GST_VIDEO_FORMAT_UYVP, */
2497 /* GST_VIDEO_FORMAT_A420, */
2498 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2499 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2500 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2501 /* GST_VIDEO_FORMAT_YUV9, */
2502 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2503 /* GST_VIDEO_FORMAT_YVU9, */
2504 /* GST_VIDEO_FORMAT_IYU1, */
2505 /* GST_VIDEO_FORMAT_ARGB64, */
2506 /* GST_VIDEO_FORMAT_AYUV64, */
2507 /* GST_VIDEO_FORMAT_r210, */
2508 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2509 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2510 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2511 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2512 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2513 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2514 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2515 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2516 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2520 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2524 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2525 if (pixtofmttable[i].pixfmt == pixfmt)
2526 return pixtofmttable[i].format;
2528 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2529 return GST_VIDEO_FORMAT_UNKNOWN;
2533 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2537 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2538 if (pixtofmttable[i].format == format)
2539 return pixtofmttable[i].pixfmt;
2540 return PIX_FMT_NONE;
2544 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2548 context->width = GST_VIDEO_INFO_WIDTH (info);
2549 context->height = GST_VIDEO_INFO_HEIGHT (info);
2550 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2551 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2552 context->bits_per_coded_sample = bpp;
2554 context->ticks_per_frame = 1;
2555 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2556 GST_DEBUG ("Using 25/1 framerate");
2557 context->time_base.den = 25;
2558 context->time_base.num = 1;
2560 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2561 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2564 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2565 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2568 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2572 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2574 const AVCodec *codec;
2575 const enum AVSampleFormat *smpl_fmts;
2576 enum AVSampleFormat smpl_fmt = -1;
2578 context->channels = info->channels;
2579 context->sample_rate = info->rate;
2580 context->channel_layout =
2581 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2583 codec = context->codec;
2585 smpl_fmts = codec->sample_fmts;
2587 switch (info->finfo->format) {
2588 case GST_AUDIO_FORMAT_F32:
2590 while (*smpl_fmts != -1) {
2591 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2592 smpl_fmt = *smpl_fmts;
2594 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2595 smpl_fmt = *smpl_fmts;
2601 smpl_fmt = AV_SAMPLE_FMT_FLT;
2604 case GST_AUDIO_FORMAT_F64:
2606 while (*smpl_fmts != -1) {
2607 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2608 smpl_fmt = *smpl_fmts;
2610 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2611 smpl_fmt = *smpl_fmts;
2617 smpl_fmt = AV_SAMPLE_FMT_DBL;
2620 case GST_AUDIO_FORMAT_S32:
2622 while (*smpl_fmts != -1) {
2623 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2624 smpl_fmt = *smpl_fmts;
2626 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2627 smpl_fmt = *smpl_fmts;
2633 smpl_fmt = AV_SAMPLE_FMT_S32;
2636 case GST_AUDIO_FORMAT_S16:
2638 while (*smpl_fmts != -1) {
2639 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2640 smpl_fmt = *smpl_fmts;
2642 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2643 smpl_fmt = *smpl_fmts;
2649 smpl_fmt = AV_SAMPLE_FMT_S16;
2652 case GST_AUDIO_FORMAT_U8:
2654 while (*smpl_fmts != -1) {
2655 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2656 smpl_fmt = *smpl_fmts;
2658 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2659 smpl_fmt = *smpl_fmts;
2665 smpl_fmt = AV_SAMPLE_FMT_U8;
2672 g_assert (smpl_fmt != -1);
2674 context->sample_fmt = smpl_fmt;
2677 /* Convert a GstCaps and a FFMPEG codec Type to a
2678 * AVCodecContext. If the context is ommitted, no fixed values
2679 * for video/audio size will be included in the context
2681 * AVMediaType is primarily meant for uncompressed data GstCaps!
2685 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2686 const GstCaps * caps, AVCodecContext * context)
2688 if (context == NULL)
2692 case AVMEDIA_TYPE_VIDEO:
2693 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2696 case AVMEDIA_TYPE_AUDIO:
2697 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2708 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2712 guint8 *end = src + size;
2715 while (srcp < end) {
2716 if (count == 2 && *srcp <= 0x03) {
2717 GST_DEBUG ("added escape code");
2726 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2729 *destsize = dstp - dst;
2732 /* copy the config, escaping NAL units as we iterate them, if something fails we
2733 * copy everything and hope for the best. */
2735 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2740 guint nalsize, esize;
2750 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2752 GST_DEBUG ("num SPS %d", cnt);
2754 memcpy (dstp, srcp, 6);
2758 for (i = 0; i < cnt; i++) {
2759 GST_DEBUG ("copy SPS %d", i);
2760 nalsize = (srcp[0] << 8) | srcp[1];
2761 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2762 dstp[0] = esize >> 8;
2763 dstp[1] = esize & 0xff;
2765 srcp += nalsize + 2;
2768 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2770 GST_DEBUG ("num PPS %d", cnt);
2772 for (i = 0; i < cnt; i++) {
2773 GST_DEBUG ("copy PPS %d", i);
2774 nalsize = (srcp[0] << 8) | srcp[1];
2775 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2776 dstp[0] = esize >> 8;
2777 dstp[1] = esize & 0xff;
2779 srcp += nalsize + 2;
2781 *destsize = dstp - dst;
2787 GST_DEBUG ("something unexpected, doing full copy");
2788 memcpy (dst, src, size);
2796 * caps_with_codecid () transforms a GstCaps for a known codec
2797 * ID into a filled-in context.
2798 * codec_data from caps will override possible extradata already in the context
2802 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2803 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2806 const GValue *value;
2809 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2810 codec_id, codec_type, caps, context);
2812 if (!context || !gst_caps_get_size (caps))
2815 str = gst_caps_get_structure (caps, 0);
2817 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2818 if ((value = gst_structure_get_value (str, "codec_data"))) {
2821 buf = gst_value_get_buffer (value);
2822 gst_buffer_map (buf, &map, GST_MAP_READ);
2824 /* free the old one if it is there */
2825 if (context->extradata)
2826 av_free (context->extradata);
2829 if (codec_id == AV_CODEC_ID_H264) {
2832 GST_DEBUG ("copy, escaping codec_data %d", size);
2833 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2834 * reason for this but let's just escape it for now. Start by allocating
2835 * enough space, x2 is more than enough.
2837 * FIXME, we disabled escaping because some file already contain escaped
2838 * codec_data and then we escape twice and fail. It's better to leave it
2839 * as is, as that is what most players do. */
2840 context->extradata =
2841 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2842 FF_INPUT_BUFFER_PADDING_SIZE));
2843 copy_config (context->extradata, data, size, &extrasize);
2844 GST_DEBUG ("escaped size: %d", extrasize);
2845 context->extradata_size = extrasize;
2849 /* allocate with enough padding */
2850 GST_DEBUG ("copy codec_data");
2851 context->extradata =
2852 av_mallocz (GST_ROUND_UP_16 (map.size +
2853 FF_INPUT_BUFFER_PADDING_SIZE));
2854 memcpy (context->extradata, map.data, map.size);
2855 context->extradata_size = map.size;
2858 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2859 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2860 context->extradata[0] = (guint8) map.size;
2863 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2865 gst_buffer_unmap (buf, &map);
2866 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2867 codec_id != AV_CODEC_ID_FLAC) {
2868 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2869 * extradata anyway which makes then segfault. */
2870 context->extradata =
2871 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2872 context->extradata_size = 0;
2873 GST_DEBUG ("no codec data");
2877 case AV_CODEC_ID_MPEG4:
2879 const gchar *mime = gst_structure_get_name (str);
2881 if (!strcmp (mime, "video/x-divx"))
2882 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2883 else if (!strcmp (mime, "video/x-xvid"))
2884 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2885 else if (!strcmp (mime, "video/x-3ivx"))
2886 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2887 else if (!strcmp (mime, "video/mpeg"))
2888 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2892 case AV_CODEC_ID_SVQ3:
2893 /* FIXME: this is a workaround for older gst-plugins releases
2894 * (<= 0.8.9). This should be removed at some point, because
2895 * it causes wrong decoded frame order. */
2896 if (!context->extradata) {
2897 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2900 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
2901 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
2902 gst_structure_get_int (str, "low_delay", &low_delay) &&
2903 gst_structure_get_int (str, "unknown_svq3_flag",
2904 &unknown_svq3_flag)) {
2905 context->extradata = (guint8 *) av_mallocz (0x64);
2906 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2910 flags |= unknown_svq3_flag;
2912 flags |= halfpel_flag;
2914 flags |= thirdpel_flag;
2917 flags = GUINT16_FROM_LE (flags);
2919 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2920 context->extradata_size = 0x64;
2925 case AV_CODEC_ID_MSRLE:
2926 case AV_CODEC_ID_QTRLE:
2927 case AV_CODEC_ID_TSCC:
2928 case AV_CODEC_ID_CSCD:
2929 case AV_CODEC_ID_APE:
2933 if (gst_structure_get_int (str, "depth", &depth)) {
2934 context->bits_per_coded_sample = depth;
2936 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2942 case AV_CODEC_ID_RV10:
2943 case AV_CODEC_ID_RV20:
2944 case AV_CODEC_ID_RV30:
2945 case AV_CODEC_ID_RV40:
2949 if (gst_structure_get_int (str, "format", &format))
2950 context->sub_id = format;
2954 case AV_CODEC_ID_COOK:
2955 case AV_CODEC_ID_RA_288:
2956 case AV_CODEC_ID_RA_144:
2957 case AV_CODEC_ID_SIPR:
2962 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2963 context->block_align = leaf_size;
2964 if (gst_structure_get_int (str, "bitrate", &bitrate))
2965 context->bit_rate = bitrate;
2967 case AV_CODEC_ID_ALAC:
2968 gst_structure_get_int (str, "samplesize",
2969 &context->bits_per_coded_sample);
2972 case AV_CODEC_ID_DVVIDEO:
2974 const gchar *format;
2976 if ((format = gst_structure_get_string (str, "format"))) {
2978 if (g_str_equal (format, "YUY2"))
2979 context->pix_fmt = PIX_FMT_YUYV422;
2980 else if (g_str_equal (format, "I420"))
2981 context->pix_fmt = PIX_FMT_YUV420P;
2982 else if (g_str_equal (format, "A420"))
2983 context->pix_fmt = PIX_FMT_YUVA420P;
2984 else if (g_str_equal (format, "Y41B"))
2985 context->pix_fmt = PIX_FMT_YUV411P;
2986 else if (g_str_equal (format, "Y42B"))
2987 context->pix_fmt = PIX_FMT_YUV422P;
2988 else if (g_str_equal (format, "YUV9"))
2989 context->pix_fmt = PIX_FMT_YUV410P;
2991 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2995 GST_WARNING ("No specified format");
2998 case AV_CODEC_ID_H263P:
3002 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3003 context->flags |= CODEC_FLAG_4MV;
3005 context->flags &= ~CODEC_FLAG_4MV;
3006 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3007 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3008 context->flags |= CODEC_FLAG_AC_PRED;
3010 context->flags &= ~CODEC_FLAG_AC_PRED;
3011 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3012 context->flags |= CODEC_FLAG_LOOP_FILTER;
3014 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3017 case AV_CODEC_ID_ADPCM_G726:
3019 const gchar *layout;
3021 if ((layout = gst_structure_get_string (str, "layout"))) {
3022 if (!strcmp (layout, "g721")) {
3023 context->sample_rate = 8000;
3024 context->channels = 1;
3025 context->bit_rate = 32000;
3034 if (!gst_caps_is_fixed (caps))
3037 /* common properties (width, height, fps) */
3038 switch (codec_type) {
3039 case AVMEDIA_TYPE_VIDEO:
3040 gst_ffmpeg_caps_to_pixfmt (caps, context,
3041 codec_id == AV_CODEC_ID_RAWVIDEO);
3043 case AVMEDIA_TYPE_AUDIO:
3044 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3050 /* fixup of default settings */
3052 case AV_CODEC_ID_QCELP:
3053 /* QCELP is always mono, no matter what the caps say */
3054 context->channels = 1;
3056 case AV_CODEC_ID_ADPCM_G726:
3057 if (context->sample_rate && context->bit_rate)
3058 context->bits_per_coded_sample =
3059 context->bit_rate / context->sample_rate;
3066 /* _formatid_to_caps () is meant for muxers/demuxers, it
3067 * transforms a name (ffmpeg way of ID'ing these, why don't
3068 * they have unique numerical IDs?) to the corresponding
3069 * caps belonging to that mux-format
3071 * Note: we don't need any additional info because the caps
3072 * isn't supposed to contain any useful info besides the
3077 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3079 GstCaps *caps = NULL;
3081 if (!strcmp (format_name, "mpeg")) {
3082 caps = gst_caps_new_simple ("video/mpeg",
3083 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3084 } else if (!strcmp (format_name, "mpegts")) {
3085 caps = gst_caps_new_simple ("video/mpegts",
3086 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3087 } else if (!strcmp (format_name, "rm")) {
3088 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3089 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3090 } else if (!strcmp (format_name, "asf")) {
3091 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3092 } else if (!strcmp (format_name, "avi")) {
3093 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3094 } else if (!strcmp (format_name, "wav")) {
3095 caps = gst_caps_new_empty_simple ("audio/x-wav");
3096 } else if (!strcmp (format_name, "ape")) {
3097 caps = gst_caps_new_empty_simple ("application/x-ape");
3098 } else if (!strcmp (format_name, "swf")) {
3099 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3100 } else if (!strcmp (format_name, "au")) {
3101 caps = gst_caps_new_empty_simple ("audio/x-au");
3102 } else if (!strcmp (format_name, "dv")) {
3103 caps = gst_caps_new_simple ("video/x-dv",
3104 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3105 } else if (!strcmp (format_name, "4xm")) {
3106 caps = gst_caps_new_empty_simple ("video/x-4xm");
3107 } else if (!strcmp (format_name, "matroska")) {
3108 caps = gst_caps_new_empty_simple ("video/x-matroska");
3109 } else if (!strcmp (format_name, "mp3")) {
3110 caps = gst_caps_new_empty_simple ("application/x-id3");
3111 } else if (!strcmp (format_name, "flic")) {
3112 caps = gst_caps_new_empty_simple ("video/x-fli");
3113 } else if (!strcmp (format_name, "flv")) {
3114 caps = gst_caps_new_empty_simple ("video/x-flv");
3115 } else if (!strcmp (format_name, "tta")) {
3116 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3117 } else if (!strcmp (format_name, "aiff")) {
3118 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3119 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3121 gst_caps_from_string
3122 ("application/x-3gp; video/quicktime; audio/x-m4a");
3123 } else if (!strcmp (format_name, "mov")) {
3124 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3125 } else if (!strcmp (format_name, "mp4")) {
3126 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3127 } else if (!strcmp (format_name, "3gp")) {
3128 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3129 } else if (!strcmp (format_name, "3g2")) {
3130 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3131 } else if (!strcmp (format_name, "psp")) {
3132 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3133 } else if (!strcmp (format_name, "ipod")) {
3134 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3135 } else if (!strcmp (format_name, "aac")) {
3136 caps = gst_caps_new_simple ("audio/mpeg",
3137 "mpegversion", G_TYPE_INT, 4, NULL);
3138 } else if (!strcmp (format_name, "gif")) {
3139 caps = gst_caps_from_string ("image/gif");
3140 } else if (!strcmp (format_name, "ogg")) {
3141 caps = gst_caps_from_string ("application/ogg");
3142 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3143 caps = gst_caps_from_string ("application/mxf");
3144 } else if (!strcmp (format_name, "gxf")) {
3145 caps = gst_caps_from_string ("application/gxf");
3146 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3147 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3148 "y4mversion", G_TYPE_INT, 2, NULL);
3149 } else if (!strcmp (format_name, "mpc")) {
3150 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3151 } else if (!strcmp (format_name, "vqf")) {
3152 caps = gst_caps_from_string ("audio/x-vqf");
3153 } else if (!strcmp (format_name, "nsv")) {
3154 caps = gst_caps_from_string ("video/x-nsv");
3155 } else if (!strcmp (format_name, "amr")) {
3156 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3157 } else if (!strcmp (format_name, "webm")) {
3158 caps = gst_caps_from_string ("video/webm");
3159 } else if (!strcmp (format_name, "voc")) {
3160 caps = gst_caps_from_string ("audio/x-voc");
3161 } else if (!strcmp (format_name, "pva")) {
3162 caps = gst_caps_from_string ("video/x-pva");
3166 GST_LOG ("Could not create stream format caps for %s", format_name);
3167 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3168 caps = gst_caps_new_empty_simple (name);
3176 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3177 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3178 AVOutputFormat * plugin)
3180 static enum CodecID tmp_vlist[] = {
3184 static enum CodecID tmp_alist[] = {
3189 GST_LOG ("format_name : %s", format_name);
3191 if (!strcmp (format_name, "mp4")) {
3192 static enum CodecID mp4_video_list[] = {
3193 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3197 static enum CodecID mp4_audio_list[] = {
3198 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3202 *video_codec_list = mp4_video_list;
3203 *audio_codec_list = mp4_audio_list;
3204 } else if (!strcmp (format_name, "mpeg")) {
3205 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3206 AV_CODEC_ID_MPEG2VIDEO,
3210 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3216 *video_codec_list = mpeg_video_list;
3217 *audio_codec_list = mpeg_audio_list;
3218 } else if (!strcmp (format_name, "dvd")) {
3219 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3222 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3225 AV_CODEC_ID_PCM_S16BE,
3229 *video_codec_list = mpeg_video_list;
3230 *audio_codec_list = mpeg_audio_list;
3231 } else if (!strcmp (format_name, "mpegts")) {
3232 static enum CodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3233 AV_CODEC_ID_MPEG2VIDEO,
3237 static enum CodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3245 *video_codec_list = mpegts_video_list;
3246 *audio_codec_list = mpegts_audio_list;
3247 } else if (!strcmp (format_name, "vob")) {
3248 static enum CodecID vob_video_list[] =
3249 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3250 static enum CodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3251 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3254 *video_codec_list = vob_video_list;
3255 *audio_codec_list = vob_audio_list;
3256 } else if (!strcmp (format_name, "flv")) {
3257 static enum CodecID flv_video_list[] =
3258 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3259 static enum CodecID flv_audio_list[] =
3260 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3262 *video_codec_list = flv_video_list;
3263 *audio_codec_list = flv_audio_list;
3264 } else if (!strcmp (format_name, "asf")) {
3265 static enum CodecID asf_video_list[] =
3266 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3269 static enum CodecID asf_audio_list[] =
3270 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3274 *video_codec_list = asf_video_list;
3275 *audio_codec_list = asf_audio_list;
3276 } else if (!strcmp (format_name, "dv")) {
3277 static enum CodecID dv_video_list[] =
3278 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3279 static enum CodecID dv_audio_list[] =
3280 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3282 *video_codec_list = dv_video_list;
3283 *audio_codec_list = dv_audio_list;
3284 } else if (!strcmp (format_name, "mov")) {
3285 static enum CodecID mov_video_list[] = {
3286 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3287 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3288 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3292 static enum CodecID mov_audio_list[] = {
3293 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3294 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3295 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3296 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3297 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3300 *video_codec_list = mov_video_list;
3301 *audio_codec_list = mov_audio_list;
3302 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3303 static enum CodecID tgp_video_list[] = {
3304 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3307 static enum CodecID tgp_audio_list[] = {
3308 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3313 *video_codec_list = tgp_video_list;
3314 *audio_codec_list = tgp_audio_list;
3315 } else if (!strcmp (format_name, "mmf")) {
3316 static enum CodecID mmf_audio_list[] = {
3317 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3319 *video_codec_list = NULL;
3320 *audio_codec_list = mmf_audio_list;
3321 } else if (!strcmp (format_name, "amr")) {
3322 static enum CodecID amr_audio_list[] = {
3323 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3326 *video_codec_list = NULL;
3327 *audio_codec_list = amr_audio_list;
3328 } else if (!strcmp (format_name, "gif")) {
3329 static enum CodecID gif_image_list[] = {
3330 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3332 *video_codec_list = gif_image_list;
3333 *audio_codec_list = NULL;
3334 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3335 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3336 tmp_vlist[0] = plugin->video_codec;
3337 tmp_alist[0] = plugin->audio_codec;
3339 *video_codec_list = tmp_vlist;
3340 *audio_codec_list = tmp_alist;
3341 } else if ((!strcmp (format_name, "pva"))) {
3342 static enum CodecID tgp_video_list[] = {
3343 AV_CODEC_ID_MPEG2VIDEO,
3346 static enum CodecID tgp_audio_list[] = {
3351 *video_codec_list = tgp_video_list;
3352 *audio_codec_list = tgp_audio_list;
3354 GST_LOG ("Format %s not found", format_name);
3361 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3362 * are omitted, that can be queried by the user itself,
3363 * we're not eating the GstCaps or anything
3364 * A pointer to an allocated context is also needed for
3365 * optional extra info
3369 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3371 enum CodecID id = AV_CODEC_ID_NONE;
3372 const gchar *mimetype;
3373 const GstStructure *structure;
3374 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3376 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3377 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3378 structure = gst_caps_get_structure (caps, 0);
3380 mimetype = gst_structure_get_name (structure);
3382 if (!strcmp (mimetype, "video/x-raw")) {
3383 id = AV_CODEC_ID_RAWVIDEO;
3385 } else if (!strcmp (mimetype, "audio/x-raw")) {
3388 if (gst_audio_info_from_caps (&info, caps)) {
3389 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3390 case GST_AUDIO_FORMAT_S8:
3391 id = AV_CODEC_ID_PCM_S8;
3393 case GST_AUDIO_FORMAT_U8:
3394 id = AV_CODEC_ID_PCM_U8;
3396 case GST_AUDIO_FORMAT_S16LE:
3397 id = AV_CODEC_ID_PCM_S16LE;
3399 case GST_AUDIO_FORMAT_S16BE:
3400 id = AV_CODEC_ID_PCM_S16BE;
3402 case GST_AUDIO_FORMAT_U16LE:
3403 id = AV_CODEC_ID_PCM_U16LE;
3405 case GST_AUDIO_FORMAT_U16BE:
3406 id = AV_CODEC_ID_PCM_U16BE;
3411 if (id != AV_CODEC_ID_NONE)
3414 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3415 id = AV_CODEC_ID_PCM_MULAW;
3417 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3418 id = AV_CODEC_ID_PCM_ALAW;
3420 } else if (!strcmp (mimetype, "video/x-dv")) {
3423 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3425 id = AV_CODEC_ID_DVVIDEO;
3428 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3429 id = AV_CODEC_ID_DVAUDIO;
3431 } else if (!strcmp (mimetype, "video/x-h263")) {
3432 const gchar *h263version =
3433 gst_structure_get_string (structure, "h263version");
3434 if (h263version && !strcmp (h263version, "h263p"))
3435 id = AV_CODEC_ID_H263P;
3437 id = AV_CODEC_ID_H263;
3439 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3440 id = AV_CODEC_ID_H263I;
3442 } else if (!strcmp (mimetype, "video/x-h261")) {
3443 id = AV_CODEC_ID_H261;
3445 } else if (!strcmp (mimetype, "video/mpeg")) {
3449 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3450 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3452 switch (mpegversion) {
3454 id = AV_CODEC_ID_MPEG1VIDEO;
3457 id = AV_CODEC_ID_MPEG2VIDEO;
3460 id = AV_CODEC_ID_MPEG4;
3464 if (id != AV_CODEC_ID_NONE)
3466 } else if (!strcmp (mimetype, "image/jpeg")) {
3467 id = AV_CODEC_ID_MJPEG; /* A... B... */
3469 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3470 id = AV_CODEC_ID_MJPEGB;
3472 } else if (!strcmp (mimetype, "video/x-wmv")) {
3473 gint wmvversion = 0;
3475 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3476 switch (wmvversion) {
3478 id = AV_CODEC_ID_WMV1;
3481 id = AV_CODEC_ID_WMV2;
3485 const gchar *format;
3487 /* WMV3 unless the fourcc exists and says otherwise */
3488 id = AV_CODEC_ID_WMV3;
3490 if ((format = gst_structure_get_string (structure, "format")) &&
3491 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3492 id = AV_CODEC_ID_VC1;
3498 if (id != AV_CODEC_ID_NONE)
3500 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3501 id = AV_CODEC_ID_VORBIS;
3503 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3504 id = AV_CODEC_ID_QDM2;
3506 } else if (!strcmp (mimetype, "audio/mpeg")) {
3508 gint mpegversion = 0;
3510 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3511 switch (mpegversion) {
3512 case 2: /* ffmpeg uses faad for both... */
3514 id = AV_CODEC_ID_AAC;
3517 if (gst_structure_get_int (structure, "layer", &layer)) {
3520 id = AV_CODEC_ID_MP1;
3523 id = AV_CODEC_ID_MP2;
3526 id = AV_CODEC_ID_MP3;
3532 if (id != AV_CODEC_ID_NONE)
3534 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3535 gint streamversion = -1;
3537 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3538 if (streamversion == 7)
3539 id = AV_CODEC_ID_MUSEPACK7;
3541 id = AV_CODEC_ID_MUSEPACK7;
3543 } else if (!strcmp (mimetype, "audio/x-wma")) {
3544 gint wmaversion = 0;
3546 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3547 switch (wmaversion) {
3549 id = AV_CODEC_ID_WMAV1;
3552 id = AV_CODEC_ID_WMAV2;
3555 id = AV_CODEC_ID_WMAPRO;
3559 if (id != AV_CODEC_ID_NONE)
3561 } else if (!strcmp (mimetype, "audio/x-wms")) {
3562 id = AV_CODEC_ID_WMAVOICE;
3564 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3565 id = AV_CODEC_ID_AC3;
3567 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3568 id = AV_CODEC_ID_EAC3;
3570 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3571 !strcmp (mimetype, "audio/atrac3")) {
3572 id = AV_CODEC_ID_ATRAC3;
3574 } else if (!strcmp (mimetype, "audio/x-dts")) {
3575 id = AV_CODEC_ID_DTS;
3577 } else if (!strcmp (mimetype, "application/x-ape")) {
3578 id = AV_CODEC_ID_APE;
3580 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3581 gint msmpegversion = 0;
3583 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3584 switch (msmpegversion) {
3586 id = AV_CODEC_ID_MSMPEG4V1;
3589 id = AV_CODEC_ID_MSMPEG4V2;
3592 id = AV_CODEC_ID_MSMPEG4V3;
3596 if (id != AV_CODEC_ID_NONE)
3598 } else if (!strcmp (mimetype, "video/x-svq")) {
3599 gint svqversion = 0;
3601 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3602 switch (svqversion) {
3604 id = AV_CODEC_ID_SVQ1;
3607 id = AV_CODEC_ID_SVQ3;
3611 if (id != AV_CODEC_ID_NONE)
3613 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3614 id = AV_CODEC_ID_HUFFYUV;
3616 } else if (!strcmp (mimetype, "audio/x-mace")) {
3617 gint maceversion = 0;
3619 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3620 switch (maceversion) {
3622 id = AV_CODEC_ID_MACE3;
3625 id = AV_CODEC_ID_MACE6;
3629 if (id != AV_CODEC_ID_NONE)
3631 } else if (!strcmp (mimetype, "video/x-theora")) {
3632 id = AV_CODEC_ID_THEORA;
3634 } else if (!strcmp (mimetype, "video/x-vp3")) {
3635 id = AV_CODEC_ID_VP3;
3637 } else if (!strcmp (mimetype, "video/x-vp5")) {
3638 id = AV_CODEC_ID_VP5;
3640 } else if (!strcmp (mimetype, "video/x-vp6")) {
3641 id = AV_CODEC_ID_VP6;
3643 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3644 id = AV_CODEC_ID_VP6F;
3646 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3647 id = AV_CODEC_ID_VP6A;
3649 } else if (!strcmp (mimetype, "video/x-vp8")) {
3650 id = AV_CODEC_ID_VP8;
3652 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3653 id = AV_CODEC_ID_FLASHSV;
3655 } else if (!strcmp (mimetype, "video/x-indeo")) {
3656 gint indeoversion = 0;
3658 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3659 switch (indeoversion) {
3661 id = AV_CODEC_ID_INDEO5;
3664 id = AV_CODEC_ID_INDEO4;
3667 id = AV_CODEC_ID_INDEO3;
3670 id = AV_CODEC_ID_INDEO2;
3673 if (id != AV_CODEC_ID_NONE)
3676 } else if (!strcmp (mimetype, "video/x-divx")) {
3677 gint divxversion = 0;
3679 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3680 switch (divxversion) {
3682 id = AV_CODEC_ID_MSMPEG4V3;
3686 id = AV_CODEC_ID_MPEG4;
3690 if (id != AV_CODEC_ID_NONE)
3692 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3693 id = AV_CODEC_ID_MPEG4;
3695 } else if (!strcmp (mimetype, "video/x-xvid")) {
3696 id = AV_CODEC_ID_MPEG4;
3698 } else if (!strcmp (mimetype, "video/x-ffv")) {
3699 gint ffvversion = 0;
3701 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3703 id = AV_CODEC_ID_FFV1;
3706 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3707 const gchar *layout;
3709 layout = gst_structure_get_string (structure, "layout");
3710 if (layout == NULL) {
3712 } else if (!strcmp (layout, "quicktime")) {
3713 id = AV_CODEC_ID_ADPCM_IMA_QT;
3714 } else if (!strcmp (layout, "microsoft")) {
3715 id = AV_CODEC_ID_ADPCM_MS;
3716 } else if (!strcmp (layout, "dvi")) {
3717 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3718 } else if (!strcmp (layout, "4xm")) {
3719 id = AV_CODEC_ID_ADPCM_4XM;
3720 } else if (!strcmp (layout, "smjpeg")) {
3721 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3722 } else if (!strcmp (layout, "dk3")) {
3723 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3724 } else if (!strcmp (layout, "dk4")) {
3725 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3726 } else if (!strcmp (layout, "westwood")) {
3727 id = AV_CODEC_ID_ADPCM_IMA_WS;
3728 } else if (!strcmp (layout, "iss")) {
3729 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3730 } else if (!strcmp (layout, "xa")) {
3731 id = AV_CODEC_ID_ADPCM_XA;
3732 } else if (!strcmp (layout, "adx")) {
3733 id = AV_CODEC_ID_ADPCM_ADX;
3734 } else if (!strcmp (layout, "ea")) {
3735 id = AV_CODEC_ID_ADPCM_EA;
3736 } else if (!strcmp (layout, "g726")) {
3737 id = AV_CODEC_ID_ADPCM_G726;
3738 } else if (!strcmp (layout, "g721")) {
3739 id = AV_CODEC_ID_ADPCM_G726;
3740 } else if (!strcmp (layout, "ct")) {
3741 id = AV_CODEC_ID_ADPCM_CT;
3742 } else if (!strcmp (layout, "swf")) {
3743 id = AV_CODEC_ID_ADPCM_SWF;
3744 } else if (!strcmp (layout, "yamaha")) {
3745 id = AV_CODEC_ID_ADPCM_YAMAHA;
3746 } else if (!strcmp (layout, "sbpro2")) {
3747 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3748 } else if (!strcmp (layout, "sbpro3")) {
3749 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3750 } else if (!strcmp (layout, "sbpro4")) {
3751 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3753 if (id != AV_CODEC_ID_NONE)
3755 } else if (!strcmp (mimetype, "video/x-4xm")) {
3756 id = AV_CODEC_ID_4XM;
3758 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3759 const gchar *layout;
3761 layout = gst_structure_get_string (structure, "layout");
3764 } else if (!strcmp (layout, "roq")) {
3765 id = AV_CODEC_ID_ROQ_DPCM;
3766 } else if (!strcmp (layout, "interplay")) {
3767 id = AV_CODEC_ID_INTERPLAY_DPCM;
3768 } else if (!strcmp (layout, "xan")) {
3769 id = AV_CODEC_ID_XAN_DPCM;
3770 } else if (!strcmp (layout, "sol")) {
3771 id = AV_CODEC_ID_SOL_DPCM;
3773 if (id != AV_CODEC_ID_NONE)
3775 } else if (!strcmp (mimetype, "audio/x-flac")) {
3776 id = AV_CODEC_ID_FLAC;
3778 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3779 id = AV_CODEC_ID_SHORTEN;
3781 } else if (!strcmp (mimetype, "audio/x-alac")) {
3782 id = AV_CODEC_ID_ALAC;
3784 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3785 id = AV_CODEC_ID_CINEPAK;
3787 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3790 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3791 switch (rmversion) {
3793 id = AV_CODEC_ID_RV10;
3796 id = AV_CODEC_ID_RV20;
3799 id = AV_CODEC_ID_RV30;
3802 id = AV_CODEC_ID_RV40;
3806 if (id != AV_CODEC_ID_NONE)
3808 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3809 id = AV_CODEC_ID_SIPR;
3811 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3814 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3815 switch (raversion) {
3817 id = AV_CODEC_ID_RA_144;
3820 id = AV_CODEC_ID_RA_288;
3823 id = AV_CODEC_ID_COOK;
3827 if (id != AV_CODEC_ID_NONE)
3829 } else if (!strcmp (mimetype, "video/x-rle")) {
3830 const gchar *layout;
3832 if ((layout = gst_structure_get_string (structure, "layout"))) {
3833 if (!strcmp (layout, "microsoft")) {
3834 id = AV_CODEC_ID_MSRLE;
3838 } else if (!strcmp (mimetype, "video/x-xan")) {
3841 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3842 switch (wcversion) {
3844 id = AV_CODEC_ID_XAN_WC3;
3848 id = AV_CODEC_ID_XAN_WC4;
3855 } else if (!strcmp (mimetype, "audio/AMR")) {
3857 id = AV_CODEC_ID_AMR_NB;
3858 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3859 id = AV_CODEC_ID_AMR_WB;
3861 } else if (!strcmp (mimetype, "audio/qcelp")) {
3862 id = AV_CODEC_ID_QCELP;
3864 } else if (!strcmp (mimetype, "video/x-h264")) {
3865 id = AV_CODEC_ID_H264;
3867 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3868 gint flvversion = 0;
3870 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3871 switch (flvversion) {
3873 id = AV_CODEC_ID_FLV1;
3881 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3882 id = AV_CODEC_ID_NELLYMOSER;
3884 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3888 if (strlen (mimetype) <= 30 &&
3889 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3890 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3891 (codec = avcodec_find_encoder_by_name (ext))) {
3896 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3900 if (strlen (mimetype) <= 30 &&
3901 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3902 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3903 (codec = avcodec_find_encoder_by_name (ext))) {
3910 if (context != NULL) {
3911 if (video == TRUE) {
3912 context->codec_type = AVMEDIA_TYPE_VIDEO;
3913 } else if (audio == TRUE) {
3914 context->codec_type = AVMEDIA_TYPE_AUDIO;
3916 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3918 context->codec_id = id;
3919 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3922 if (id != AV_CODEC_ID_NONE) {
3923 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3925 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);