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 if (channels == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_MONO)
103 return AV_CH_LAYOUT_MONO;
105 for (i = 0; i < channels; i++) {
106 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
107 if (_ff_to_gst_layout[j].gst == pos[i]) {
108 ret |= _ff_to_gst_layout[j].ff;
115 if (channels_found != channels)
121 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
122 GstAudioChannelPosition * pos)
125 gboolean none_layout = FALSE;
127 if (channel_layout == 0) {
128 nchannels = channels;
133 /* Special path for mono, as AV_CH_LAYOUT_MONO is the same
134 * as FRONT_CENTER but we distinguish between the two in
137 if (channels == 1 && channel_layout == AV_CH_LAYOUT_MONO) {
138 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
142 for (i = 0; i < 64; i++) {
143 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
148 if (nchannels != channels) {
149 GST_ERROR ("Number of channels is different (%u != %u)", channels,
151 nchannels = channels;
155 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
156 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
157 pos[j++] = _ff_to_gst_layout[i].gst;
159 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
164 if (j != nchannels) {
166 ("Unknown channels in channel layout - assuming NONE layout");
173 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
174 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
175 " - assuming NONE layout", channel_layout);
180 if (nchannels == 1) {
181 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
182 } else if (nchannels == 2) {
183 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
184 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
188 for (i = 0; i < nchannels; i++)
189 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
197 _gst_value_list_contains (const GValue * list, const GValue * value)
202 n = gst_value_list_get_size (list);
203 for (i = 0; i < n; i++) {
204 tmp = gst_value_list_get_value (list, i);
205 if (gst_value_compare (value, tmp) == GST_VALUE_EQUAL)
213 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
217 GstVideoFormat format;
219 if (!fmts || fmts[0] == -1) {
222 g_value_init (&va, GST_TYPE_LIST);
223 g_value_init (&v, G_TYPE_STRING);
224 for (i = 0; i <= AV_PIX_FMT_NB; i++) {
225 format = gst_ffmpeg_pixfmt_to_videoformat (i);
226 if (format == GST_VIDEO_FORMAT_UNKNOWN)
228 g_value_set_string (&v, gst_video_format_to_string (format));
229 gst_value_list_append_value (&va, &v);
231 gst_caps_set_value (caps, "format", &va);
237 /* Only a single format */
238 g_value_init (&va, GST_TYPE_LIST);
239 g_value_init (&v, G_TYPE_STRING);
240 while (*fmts != -1) {
241 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
242 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
243 g_value_set_string (&v, gst_video_format_to_string (format));
244 /* Only append values we don't have yet */
245 if (!_gst_value_list_contains (&va, &v))
246 gst_value_list_append_value (&va, &v);
250 if (gst_value_list_get_size (&va) == 1) {
251 /* The single value is still in v */
252 gst_caps_set_value (caps, "format", &v);
253 } else if (gst_value_list_get_size (&va) > 1) {
254 gst_caps_set_value (caps, "format", &va);
260 /* this macro makes a caps width fixed or unfixed width/height
261 * properties depending on whether we've got a context.
263 * See below for why we use this.
265 * We should actually do this stuff at the end, like in riff-media.c,
266 * but I'm too lazy today. Maybe later.
269 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
270 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
271 const char *fieldname, ...)
273 GstCaps *caps = NULL;
277 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
279 /* fixed, non probing context */
280 if (context != NULL && context->width != -1) {
283 caps = gst_caps_new_simple (mimetype,
284 "width", G_TYPE_INT, context->width,
285 "height", G_TYPE_INT, context->height, NULL);
287 num = context->time_base.den / context->ticks_per_frame;
288 denom = context->time_base.num;
291 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
294 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
295 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
299 GST_LOG ("setting framerate: %d/%d", num, denom);
300 gst_caps_set_simple (caps,
301 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
303 /* so we are after restricted caps in this case */
305 case AV_CODEC_ID_H261:
307 caps = gst_caps_new_simple (mimetype,
308 "width", G_TYPE_INT, 352,
309 "height", G_TYPE_INT, 288,
310 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
311 gst_caps_append (caps, gst_caps_new_simple (mimetype,
312 "width", G_TYPE_INT, 176,
313 "height", G_TYPE_INT, 144,
314 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
317 case AV_CODEC_ID_H263:
319 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
320 * because we want automatic negotiation to go as close to 320x240 as
322 const static gint widths[] = { 352, 704, 176, 1408, 128 };
323 const static gint heights[] = { 288, 576, 144, 1152, 96 };
325 gint n_sizes = G_N_ELEMENTS (widths);
327 caps = gst_caps_new_empty ();
328 for (i = 0; i < n_sizes; i++) {
329 temp = gst_caps_new_simple (mimetype,
330 "width", G_TYPE_INT, widths[i],
331 "height", G_TYPE_INT, heights[i],
332 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
334 gst_caps_append (caps, temp);
338 case AV_CODEC_ID_DVVIDEO:
345 gint framerate_n, framerate_d;
348 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
349 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
350 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
351 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
352 "I420", 720, 576, 16, 15, 25, 1}, {
353 "I420", 720, 576, 64, 45, 25, 1}, {
354 "Y41B", 720, 576, 16, 15, 25, 1}, {
355 "Y41B", 720, 576, 64, 45, 25, 1}, {
356 "Y42B", 720, 576, 16, 15, 25, 1}, {
357 "Y42B", 720, 576, 64, 45, 25, 1}, {
358 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
359 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
360 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
361 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
362 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
363 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
364 "Y42B", 960, 720, 1, 1, 50, 1}, {
365 "Y42B", 960, 720, 4, 3, 50, 1},};
367 gint n_sizes = G_N_ELEMENTS (profiles);
369 if (strcmp (mimetype, "video/x-raw") == 0) {
370 caps = gst_caps_new_empty ();
371 for (i = 0; i < n_sizes; i++) {
372 temp = gst_caps_new_simple (mimetype,
373 "format", G_TYPE_STRING, profiles[i].csp,
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);
383 caps = gst_caps_new_empty ();
384 for (i = 0; i < n_sizes; i++) {
385 temp = gst_caps_new_simple (mimetype,
386 "width", G_TYPE_INT, profiles[i].width,
387 "height", G_TYPE_INT, profiles[i].height,
388 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
389 profiles[i].framerate_d, "pixel-aspect-ratio",
390 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
392 gst_caps_append (caps, temp);
397 case AV_CODEC_ID_DNXHD:
399 caps = gst_caps_new_simple (mimetype,
400 "width", G_TYPE_INT, 1920,
401 "height", G_TYPE_INT, 1080,
402 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
403 gst_caps_append (caps, gst_caps_new_simple (mimetype,
404 "width", G_TYPE_INT, 1280,
405 "height", G_TYPE_INT, 720,
406 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
411 if (codec && codec->supported_framerates
412 && codec->supported_framerates[0].num != 0
413 && codec->supported_framerates[0].den != 0) {
416 const AVRational *rates = codec->supported_framerates;
418 if (rates[1].num == 0 && rates[1].den == 0) {
420 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
421 rates[0].num, rates[0].den, NULL);
423 g_value_init (&va, GST_TYPE_LIST);
424 g_value_init (&v, GST_TYPE_FRACTION);
426 while (rates->num != 0 && rates->den != 0) {
427 gst_value_set_fraction (&v, rates->num, rates->den);
428 gst_value_list_append_value (&va, &v);
432 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
433 gst_caps_set_value (caps, "framerate", &va);
439 caps = gst_caps_new_empty_simple (mimetype);
447 /* no fixed caps or special restrictions applied;
448 * default unfixed setting */
450 GST_DEBUG ("Creating default caps");
451 caps = gst_caps_new_empty_simple (mimetype);
454 va_start (var_args, fieldname);
455 gst_caps_set_simple_valist (caps, fieldname, var_args);
462 get_nbits_set (guint64 n)
467 for (i = 0; i < 64; i++) {
468 if ((n & (G_GUINT64_CONSTANT (1) << i)))
476 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
477 const enum AVSampleFormat *fmts, gboolean always_interleaved)
482 GstAudioFormat format;
483 GstAudioLayout layout;
484 GstCaps *caps_copy = NULL;
486 if (!fmts || fmts[0] == -1) {
489 g_value_init (&va, GST_TYPE_LIST);
490 g_value_init (&v, G_TYPE_STRING);
491 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
492 format = gst_ffmpeg_smpfmt_to_audioformat (i, NULL);
493 if (format == GST_AUDIO_FORMAT_UNKNOWN)
495 g_value_set_string (&v, gst_audio_format_to_string (format));
496 gst_value_list_append_value (&va, &v);
498 gst_caps_set_value (caps, "format", &va);
499 if (!always_interleaved) {
500 g_value_init (&vap, GST_TYPE_LIST);
501 g_value_set_string (&v, "interleaved");
502 gst_value_list_append_value (&vap, &v);
503 g_value_set_string (&v, "non-interleaved");
504 gst_value_list_append_value (&vap, &v);
505 gst_caps_set_value (caps, "layout", &vap);
506 g_value_unset (&vap);
508 gst_caps_set_simple (caps, "layout", G_TYPE_STRING, "interleaved", NULL);
515 g_value_init (&va, GST_TYPE_LIST);
516 g_value_init (&vap, GST_TYPE_LIST);
517 g_value_init (&v, G_TYPE_STRING);
518 while (*fmts != -1) {
519 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts, &layout);
520 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
521 g_value_set_string (&v, gst_audio_format_to_string (format));
522 /* Only append values we don't have yet */
523 if (layout == GST_AUDIO_LAYOUT_INTERLEAVED || always_interleaved) {
524 if (!_gst_value_list_contains (&va, &v))
525 gst_value_list_append_value (&va, &v);
527 if (!_gst_value_list_contains (&vap, &v))
528 gst_value_list_append_value (&vap, &v);
533 if (gst_value_list_get_size (&va) >= 1 && gst_value_list_get_size (&vap) >= 1) {
534 caps_copy = gst_caps_copy (caps);
536 if (gst_value_list_get_size (&va) == 1) {
537 gst_caps_set_value (caps, "format", gst_value_list_get_value (&va, 0));
538 gst_caps_set_simple (caps, "layout", G_TYPE_STRING, "interleaved", NULL);
539 } else if (gst_value_list_get_size (&va) > 1) {
540 gst_caps_set_value (caps, "format", &va);
541 gst_caps_set_simple (caps, "layout", G_TYPE_STRING, "interleaved", NULL);
543 if (gst_value_list_get_size (&vap) == 1) {
544 gst_caps_set_value (caps_copy ? caps_copy : caps, "format",
545 gst_value_list_get_value (&vap, 0));
546 gst_caps_set_simple (caps_copy ? caps_copy : caps, "layout", G_TYPE_STRING,
547 "non-interleaved", NULL);
548 } else if (gst_value_list_get_size (&vap) > 1) {
549 gst_caps_set_value (caps_copy ? caps_copy : caps, "format", &vap);
550 gst_caps_set_simple (caps_copy ? caps_copy : caps, "layout", G_TYPE_STRING,
551 "non-interleaved", NULL);
554 gst_caps_append (caps, caps_copy);
558 g_value_unset (&vap);
561 /* same for audio - now with channels/sample rate
564 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
565 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
566 const char *fieldname, ...)
568 GstCaps *caps = NULL;
572 /* fixed, non-probing context */
573 if (context != NULL && context->channels != -1) {
574 GstAudioChannelPosition pos[64];
577 caps = gst_caps_new_simple (mimetype,
578 "rate", G_TYPE_INT, context->sample_rate,
579 "channels", G_TYPE_INT, context->channels, NULL);
581 if (context->channels > 1 &&
582 gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
583 context->channels, pos) &&
584 gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
586 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask, NULL);
589 gint maxchannels = 2;
590 const gint *rates = NULL;
593 /* so we must be after restricted caps in this case */
595 case AV_CODEC_ID_AAC:
596 case AV_CODEC_ID_AAC_LATM:
597 case AV_CODEC_ID_DTS:
600 case AV_CODEC_ID_MP2:
602 const static gint l_rates[] =
603 { 48000, 44100, 32000, 24000, 22050, 16000 };
604 n_rates = G_N_ELEMENTS (l_rates);
608 case AV_CODEC_ID_EAC3:
609 case AV_CODEC_ID_AC3:
611 const static gint l_rates[] = { 48000, 44100, 32000 };
613 n_rates = G_N_ELEMENTS (l_rates);
617 case AV_CODEC_ID_ADPCM_G722:
619 const static gint l_rates[] = { 16000 };
620 n_rates = G_N_ELEMENTS (l_rates);
625 case AV_CODEC_ID_ADPCM_G726:
627 const static gint l_rates[] = { 8000 };
628 n_rates = G_N_ELEMENTS (l_rates);
633 case AV_CODEC_ID_ADPCM_SWF:
635 const static gint l_rates[] = { 11025, 22050, 44100 };
636 n_rates = G_N_ELEMENTS (l_rates);
640 case AV_CODEC_ID_ROQ_DPCM:
642 const static gint l_rates[] = { 22050 };
643 n_rates = G_N_ELEMENTS (l_rates);
647 case AV_CODEC_ID_AMR_NB:
649 const static gint l_rates[] = { 8000 };
651 n_rates = G_N_ELEMENTS (l_rates);
655 case AV_CODEC_ID_AMR_WB:
657 const static gint l_rates[] = { 16000 };
659 n_rates = G_N_ELEMENTS (l_rates);
667 /* regardless of encode/decode, open up channels if applicable */
668 /* Until decoders/encoders expose the maximum number of channels
669 * they support, we whitelist them here. */
671 case AV_CODEC_ID_WMAPRO:
672 case AV_CODEC_ID_TRUEHD:
679 if (codec && codec->channel_layouts) {
680 const uint64_t *layouts = codec->channel_layouts;
681 GstAudioChannelPosition pos[64];
683 caps = gst_caps_new_empty ();
685 gint nbits_set = get_nbits_set (*layouts);
687 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
690 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
693 gst_structure_new (mimetype, "channels", G_TYPE_INT, nbits_set,
696 /* No need to require a channel mask for mono or stereo */
697 if (!(nbits_set == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_MONO)
699 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
700 && pos[1] == GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT))
701 gst_structure_set (s, "channel-mask", GST_TYPE_BITMASK, mask,
704 gst_caps_append_structure (caps, s);
710 if (maxchannels == 1)
711 caps = gst_caps_new_simple (mimetype,
712 "channels", G_TYPE_INT, maxchannels, NULL);
714 caps = gst_caps_new_simple (mimetype,
715 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
719 GValue list = { 0, };
721 g_value_init (&list, GST_TYPE_LIST);
722 for (i = 0; i < n_rates; i++) {
725 g_value_init (&v, G_TYPE_INT);
726 g_value_set_int (&v, rates[i]);
727 gst_value_list_append_value (&list, &v);
730 gst_caps_set_value (caps, "rate", &list);
731 g_value_unset (&list);
732 } else if (codec && codec->supported_samplerates
733 && codec->supported_samplerates[0]) {
737 if (!codec->supported_samplerates[1]) {
738 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
739 codec->supported_samplerates[0], NULL);
741 const int *rates = codec->supported_samplerates;
743 g_value_init (&va, GST_TYPE_LIST);
744 g_value_init (&v, G_TYPE_INT);
747 g_value_set_int (&v, *rates);
748 gst_value_list_append_value (&va, &v);
751 gst_caps_set_value (caps, "rate", &va);
756 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
759 caps = gst_caps_new_empty_simple (mimetype);
762 va_start (var_args, fieldname);
763 gst_caps_set_simple_valist (caps, fieldname, var_args);
769 /* Check if the given codec ID is an image format -- for now this is just
770 * anything whose caps is image/... */
772 gst_ffmpeg_codecid_is_image (enum AVCodecID codec_id)
775 case AV_CODEC_ID_MJPEG:
776 case AV_CODEC_ID_LJPEG:
777 case AV_CODEC_ID_GIF:
778 case AV_CODEC_ID_PPM:
779 case AV_CODEC_ID_PBM:
780 case AV_CODEC_ID_PCX:
781 case AV_CODEC_ID_SGI:
782 case AV_CODEC_ID_TARGA:
783 case AV_CODEC_ID_TIFF:
784 case AV_CODEC_ID_SUNRAST:
785 case AV_CODEC_ID_BMP:
793 /* Convert a FFMPEG codec ID and optional AVCodecContext
794 * to a GstCaps. If the context is ommitted, no fixed values
795 * for video/audio size will be included in the GstCaps
797 * CodecID is primarily meant for compressed data GstCaps!
799 * encode is a special parameter. gstffmpegdec will say
800 * FALSE, gstffmpegenc will say TRUE. The output caps
801 * depends on this, in such a way that it will be very
802 * specific, defined, fixed and correct caps for encoders,
803 * yet very wide, "forgiving" caps for decoders. Example
804 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
805 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
810 gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
811 AVCodecContext * context, gboolean encode)
813 GstCaps *caps = NULL;
814 gboolean buildcaps = FALSE;
816 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
819 case AV_CODEC_ID_MPEG1VIDEO:
821 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
822 "mpegversion", G_TYPE_INT, 1,
823 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
826 case AV_CODEC_ID_MPEG2VIDEO:
830 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
831 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
834 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
835 * the MPEG video stream headers, so may be omitted from caps. */
836 caps = gst_caps_new_simple ("video/mpeg",
837 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
838 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
842 case AV_CODEC_ID_H263:
845 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
846 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
847 G_TYPE_STRING, "h263", NULL);
849 /* don't pass codec_id, we can decode other variants with the H263
850 * decoder that don't have specific size requirements
853 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
854 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
858 case AV_CODEC_ID_H263P:
860 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
861 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
863 if (encode && context) {
865 gst_caps_set_simple (caps,
866 "annex-f", G_TYPE_BOOLEAN, context->flags & AV_CODEC_FLAG_4MV,
867 "annex-j", G_TYPE_BOOLEAN,
868 context->flags & AV_CODEC_FLAG_LOOP_FILTER,
869 "annex-i", G_TYPE_BOOLEAN, context->flags & AV_CODEC_FLAG_AC_PRED,
870 "annex-t", G_TYPE_BOOLEAN, context->flags & AV_CODEC_FLAG_AC_PRED,
875 case AV_CODEC_ID_H263I:
877 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
878 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
881 case AV_CODEC_ID_H261:
883 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
887 case AV_CODEC_ID_RV10:
888 case AV_CODEC_ID_RV20:
889 case AV_CODEC_ID_RV30:
890 case AV_CODEC_ID_RV40:
895 case AV_CODEC_ID_RV40:
898 case AV_CODEC_ID_RV30:
901 case AV_CODEC_ID_RV20:
910 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
911 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
913 if (context->extradata_size >= 8) {
914 gst_caps_set_simple (caps,
915 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
922 case AV_CODEC_ID_MP1:
924 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
925 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
928 case AV_CODEC_ID_MP2:
930 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
931 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
934 case AV_CODEC_ID_MP3:
938 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
939 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
941 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
942 * in the MPEG audio header, so may be omitted from caps. */
943 caps = gst_caps_new_simple ("audio/mpeg",
944 "mpegversion", G_TYPE_INT, 1,
945 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
949 case AV_CODEC_ID_MUSEPACK7:
951 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
952 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
956 case AV_CODEC_ID_MUSEPACK8:
958 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
959 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
963 case AV_CODEC_ID_AC3:
966 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
970 case AV_CODEC_ID_EAC3:
973 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
977 case AV_CODEC_ID_TRUEHD:
979 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
980 "audio/x-true-hd", NULL);
983 case AV_CODEC_ID_ATRAC1:
985 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
986 "audio/x-vnd.sony.atrac1", NULL);
989 case AV_CODEC_ID_ATRAC3:
991 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
992 "audio/x-vnd.sony.atrac3", NULL);
995 case AV_CODEC_ID_DTS:
997 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
1001 case AV_CODEC_ID_APE:
1003 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1004 "audio/x-ffmpeg-parsed-ape", NULL);
1006 gst_caps_set_simple (caps,
1007 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1011 case AV_CODEC_ID_MLP:
1013 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
1017 case AV_CODEC_ID_METASOUND:
1019 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1020 "audio/x-voxware", NULL);
1023 case AV_CODEC_ID_IMC:
1025 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
1029 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
1030 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
1031 * sp5x is, but it's apparently something JPEG... We don't separate
1032 * between those in GStreamer. Should we (at least between MJPEG,
1033 * MJPEG-B and sp5x decoding...)? */
1034 case AV_CODEC_ID_MJPEG:
1035 case AV_CODEC_ID_LJPEG:
1037 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
1038 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
1041 case AV_CODEC_ID_JPEG2000:
1043 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-j2c",
1046 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1047 encode, "image/x-jpc", NULL));
1048 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1049 encode, "image/jp2", NULL));
1053 case AV_CODEC_ID_SP5X:
1055 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
1059 case AV_CODEC_ID_MJPEGB:
1061 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1062 "video/x-mjpeg-b", NULL);
1065 case AV_CODEC_ID_MPEG4:
1066 if (encode && context != NULL) {
1067 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
1068 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
1069 switch (context->codec_tag) {
1070 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
1072 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1073 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
1075 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
1077 /* FIXME: bitrate. libav doesn't expose the used profile and level */
1079 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1080 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
1081 "mpegversion", G_TYPE_INT, 4, NULL);
1085 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
1087 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
1088 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
1092 GValue arr = { 0, };
1093 GValue item = { 0, };
1095 g_value_init (&arr, GST_TYPE_LIST);
1096 g_value_init (&item, G_TYPE_STRING);
1097 g_value_set_string (&item, "simple");
1098 gst_value_list_append_value (&arr, &item);
1099 g_value_set_string (&item, "advanced-simple");
1100 gst_value_list_append_value (&arr, &item);
1101 g_value_unset (&item);
1103 gst_caps_set_value (caps, "profile", &arr);
1104 g_value_unset (&arr);
1106 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1107 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
1109 #ifndef TIZEN_FEATURE_LIBAV
1111 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1112 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1119 case AV_CODEC_ID_RAWVIDEO:
1121 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1124 case AV_CODEC_ID_MSMPEG4V1:
1125 case AV_CODEC_ID_MSMPEG4V2:
1126 case AV_CODEC_ID_MSMPEG4V3:
1128 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1130 /* encode-FIXME: bitrate */
1132 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1133 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1134 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1135 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1136 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1141 case AV_CODEC_ID_WMV1:
1142 case AV_CODEC_ID_WMV2:
1144 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1147 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1148 "wmvversion", G_TYPE_INT, version, NULL);
1152 case AV_CODEC_ID_FLV1:
1154 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1155 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1158 case AV_CODEC_ID_SVQ1:
1160 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1161 "svqversion", G_TYPE_INT, 1, NULL);
1164 case AV_CODEC_ID_SVQ3:
1166 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1167 "svqversion", G_TYPE_INT, 3, NULL);
1170 case AV_CODEC_ID_DVAUDIO:
1172 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1176 case AV_CODEC_ID_DVVIDEO:
1178 if (encode && context) {
1179 const gchar *format;
1181 switch (context->pix_fmt) {
1182 case AV_PIX_FMT_YUYV422:
1185 case AV_PIX_FMT_YUV420P:
1188 case AV_PIX_FMT_YUVA420P:
1191 case AV_PIX_FMT_YUV411P:
1194 case AV_PIX_FMT_YUV422P:
1197 case AV_PIX_FMT_YUV410P:
1202 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1208 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1209 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1213 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1214 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1219 case AV_CODEC_ID_WMAV1:
1220 case AV_CODEC_ID_WMAV2:
1222 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1226 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1227 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1228 context->block_align, "bitrate", G_TYPE_INT,
1229 (guint) context->bit_rate, NULL);
1232 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1233 "wmaversion", G_TYPE_INT, version, "block_align",
1234 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1239 case AV_CODEC_ID_WMAPRO:
1242 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1243 "wmaversion", G_TYPE_INT, 3, NULL);
1246 case AV_CODEC_ID_WMALOSSLESS:
1248 /* libav only supports a depth of 16 at the moment */
1250 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1251 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1254 case AV_CODEC_ID_WMAVOICE:
1257 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1262 case AV_CODEC_ID_MACE3:
1263 case AV_CODEC_ID_MACE6:
1265 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1268 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1269 "maceversion", G_TYPE_INT, version, NULL);
1273 case AV_CODEC_ID_HUFFYUV:
1275 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1276 "video/x-huffyuv", NULL);
1278 gst_caps_set_simple (caps,
1279 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1283 case AV_CODEC_ID_CYUV:
1285 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1286 "video/x-compressed-yuv", NULL);
1289 case AV_CODEC_ID_H264:
1291 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1292 "alignment", G_TYPE_STRING, "au", NULL);
1294 GValue arr = { 0, };
1295 GValue item = { 0, };
1296 g_value_init (&arr, GST_TYPE_LIST);
1297 g_value_init (&item, G_TYPE_STRING);
1298 g_value_set_string (&item, "avc");
1299 gst_value_list_append_value (&arr, &item);
1300 g_value_set_string (&item, "byte-stream");
1301 gst_value_list_append_value (&arr, &item);
1302 g_value_unset (&item);
1303 gst_caps_set_value (caps, "stream-format", &arr);
1304 g_value_unset (&arr);
1308 case AV_CODEC_ID_HEVC:
1310 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h265",
1311 "alignment", G_TYPE_STRING, "au", NULL);
1313 GValue arr = { 0, };
1314 GValue item = { 0, };
1315 g_value_init (&arr, GST_TYPE_LIST);
1316 g_value_init (&item, G_TYPE_STRING);
1317 g_value_set_string (&item, "hvc1");
1318 gst_value_list_append_value (&arr, &item);
1319 g_value_set_string (&item, "hev1");
1320 gst_value_list_append_value (&arr, &item);
1321 g_value_set_string (&item, "byte-stream");
1322 gst_value_list_append_value (&arr, &item);
1323 g_value_unset (&item);
1324 gst_caps_set_value (caps, "stream-format", &arr);
1325 g_value_unset (&arr);
1329 case AV_CODEC_ID_INDEO5:
1331 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1332 "indeoversion", G_TYPE_INT, 5, NULL);
1335 case AV_CODEC_ID_INDEO4:
1337 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1338 "indeoversion", G_TYPE_INT, 4, NULL);
1341 case AV_CODEC_ID_INDEO3:
1343 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1344 "indeoversion", G_TYPE_INT, 3, NULL);
1347 case AV_CODEC_ID_INDEO2:
1349 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1350 "indeoversion", G_TYPE_INT, 2, NULL);
1353 case AV_CODEC_ID_FLASHSV:
1355 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1356 "video/x-flash-screen", NULL);
1359 case AV_CODEC_ID_FLASHSV2:
1361 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1362 "video/x-flash-screen2", NULL);
1365 case AV_CODEC_ID_VP3:
1367 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1371 case AV_CODEC_ID_VP5:
1373 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1377 case AV_CODEC_ID_VP6:
1379 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1383 case AV_CODEC_ID_VP6F:
1385 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1386 "video/x-vp6-flash", NULL);
1389 case AV_CODEC_ID_VP6A:
1391 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1392 "video/x-vp6-alpha", NULL);
1395 case AV_CODEC_ID_VP8:
1397 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1401 case AV_CODEC_ID_VP9:
1403 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp9",
1407 case AV_CODEC_ID_THEORA:
1409 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1410 "video/x-theora", NULL);
1413 case AV_CODEC_ID_CFHD:
1415 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1416 "video/x-cineform", NULL);
1419 case AV_CODEC_ID_AAC:
1422 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1426 GValue arr = { 0, };
1427 GValue item = { 0, };
1429 g_value_init (&arr, GST_TYPE_LIST);
1430 g_value_init (&item, G_TYPE_INT);
1431 g_value_set_int (&item, 2);
1432 gst_value_list_append_value (&arr, &item);
1433 g_value_set_int (&item, 4);
1434 gst_value_list_append_value (&arr, &item);
1435 g_value_unset (&item);
1437 gst_caps_set_value (caps, "mpegversion", &arr);
1438 g_value_unset (&arr);
1440 g_value_init (&arr, GST_TYPE_LIST);
1441 g_value_init (&item, G_TYPE_STRING);
1442 g_value_set_string (&item, "raw");
1443 gst_value_list_append_value (&arr, &item);
1444 g_value_set_string (&item, "adts");
1445 gst_value_list_append_value (&arr, &item);
1446 g_value_set_string (&item, "adif");
1447 gst_value_list_append_value (&arr, &item);
1448 g_value_unset (&item);
1450 gst_caps_set_value (caps, "stream-format", &arr);
1451 g_value_unset (&arr);
1453 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1454 "stream-format", G_TYPE_STRING, "raw",
1455 "base-profile", G_TYPE_STRING, "lc", NULL);
1457 if (context && context->extradata_size > 0)
1458 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1459 context->extradata, context->extradata_size);
1464 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1465 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1466 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1470 case AV_CODEC_ID_ASV1:
1472 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1473 "asusversion", G_TYPE_INT, 1, NULL);
1475 case AV_CODEC_ID_ASV2:
1477 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1478 "asusversion", G_TYPE_INT, 2, NULL);
1481 case AV_CODEC_ID_FFV1:
1483 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1484 "ffvversion", G_TYPE_INT, 1, NULL);
1487 case AV_CODEC_ID_4XM:
1489 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1493 case AV_CODEC_ID_XAN_WC3:
1494 case AV_CODEC_ID_XAN_WC4:
1496 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1497 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1500 case AV_CODEC_ID_CLJR:
1502 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1503 "video/x-cirrus-logic-accupak", NULL);
1506 case AV_CODEC_ID_FRAPS:
1508 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1512 case AV_CODEC_ID_MDEC:
1513 case AV_CODEC_ID_ROQ:
1514 case AV_CODEC_ID_INTERPLAY_VIDEO:
1518 case AV_CODEC_ID_VCR1:
1520 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1521 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1524 case AV_CODEC_ID_RPZA:
1526 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1527 "video/x-apple-video", NULL);
1530 case AV_CODEC_ID_CINEPAK:
1532 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1533 "video/x-cinepak", NULL);
1536 /* WS_VQA belogns here (order) */
1538 case AV_CODEC_ID_MSRLE:
1540 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1541 "layout", G_TYPE_STRING, "microsoft", NULL);
1543 gst_caps_set_simple (caps,
1544 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1546 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1550 case AV_CODEC_ID_QTRLE:
1552 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1553 "layout", G_TYPE_STRING, "quicktime", NULL);
1555 gst_caps_set_simple (caps,
1556 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1558 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1562 case AV_CODEC_ID_MSVIDEO1:
1564 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1565 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1568 case AV_CODEC_ID_MSS1:
1570 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1571 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1574 case AV_CODEC_ID_MSS2:
1576 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1577 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1580 case AV_CODEC_ID_WMV3:
1582 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1583 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1585 case AV_CODEC_ID_VC1:
1587 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1588 "wmvversion", G_TYPE_INT, 3, NULL);
1589 if (!context && !encode) {
1590 GValue arr = { 0, };
1591 GValue item = { 0, };
1593 g_value_init (&arr, GST_TYPE_LIST);
1594 g_value_init (&item, G_TYPE_STRING);
1595 g_value_set_string (&item, "WVC1");
1596 gst_value_list_append_value (&arr, &item);
1597 g_value_set_string (&item, "WMVA");
1598 gst_value_list_append_and_take_value (&arr, &item);
1599 gst_caps_set_value (caps, "format", &arr);
1600 g_value_unset (&arr);
1602 gst_caps_set_simple (caps, "format", G_TYPE_STRING, "WVC1", NULL);
1605 case AV_CODEC_ID_QDM2:
1607 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1611 case AV_CODEC_ID_MSZH:
1613 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1617 case AV_CODEC_ID_ZLIB:
1619 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1623 case AV_CODEC_ID_TRUEMOTION1:
1625 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1626 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1628 case AV_CODEC_ID_TRUEMOTION2:
1630 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1631 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1634 case AV_CODEC_ID_ULTI:
1636 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1637 "video/x-ultimotion", NULL);
1640 case AV_CODEC_ID_TSCC:
1642 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1643 "video/x-camtasia", NULL);
1645 gst_caps_set_simple (caps,
1646 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1648 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1652 case AV_CODEC_ID_TSCC2:
1654 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1655 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1658 case AV_CODEC_ID_KMVC:
1660 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1664 case AV_CODEC_ID_NUV:
1666 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1670 case AV_CODEC_ID_GIF:
1672 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1673 "image/gst-libav-gif", "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
1676 case AV_CODEC_ID_PNG:
1678 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1682 case AV_CODEC_ID_PPM:
1684 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1688 case AV_CODEC_ID_PBM:
1690 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1694 case AV_CODEC_ID_PAM:
1696 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1697 "image/x-portable-anymap", NULL);
1700 case AV_CODEC_ID_PGM:
1702 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1703 "image/x-portable-graymap", NULL);
1706 case AV_CODEC_ID_PCX:
1708 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1712 case AV_CODEC_ID_SGI:
1714 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1718 case AV_CODEC_ID_TARGA:
1720 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1724 case AV_CODEC_ID_TIFF:
1726 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1730 case AV_CODEC_ID_SUNRAST:
1732 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1733 "image/x-sun-raster", NULL);
1736 case AV_CODEC_ID_SMC:
1738 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1742 case AV_CODEC_ID_QDRAW:
1744 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1748 case AV_CODEC_ID_DNXHD:
1750 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1754 case AV_CODEC_ID_PRORES:
1756 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1757 "video/x-prores", NULL);
1759 switch (context->codec_tag) {
1760 case GST_MAKE_FOURCC ('a', 'p', 'c', 'o'):
1761 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "proxy", NULL);
1763 case GST_MAKE_FOURCC ('a', 'p', 'c', 's'):
1764 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "lt", NULL);
1767 case GST_MAKE_FOURCC ('a', 'p', 'c', 'n'):
1768 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "standard",
1771 case GST_MAKE_FOURCC ('a', 'p', 'c', 'h'):
1772 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "hq", NULL);
1774 case GST_MAKE_FOURCC ('a', 'p', '4', 'h'):
1775 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "4444", NULL);
1777 case GST_MAKE_FOURCC ('a', 'p', '4', 'x'):
1778 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "4444xq",
1785 case AV_CODEC_ID_MIMIC:
1787 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1791 case AV_CODEC_ID_VMNC:
1793 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1797 case AV_CODEC_ID_TRUESPEECH:
1799 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1800 "audio/x-truespeech", NULL);
1803 case AV_CODEC_ID_QCELP:
1805 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1809 case AV_CODEC_ID_AMV:
1811 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1815 case AV_CODEC_ID_AASC:
1817 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1821 case AV_CODEC_ID_LOCO:
1823 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1827 case AV_CODEC_ID_ZMBV:
1829 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1833 case AV_CODEC_ID_LAGARITH:
1835 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1836 "video/x-lagarith", NULL);
1839 case AV_CODEC_ID_CSCD:
1841 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1842 "video/x-camstudio", NULL);
1844 gst_caps_set_simple (caps,
1845 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1847 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1851 case AV_CODEC_ID_AIC:
1853 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1854 "video/x-apple-intermediate-codec", NULL);
1857 case AV_CODEC_ID_CAVS:
1859 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1860 "video/x-cavs", NULL);
1863 case AV_CODEC_ID_WS_VQA:
1864 case AV_CODEC_ID_IDCIN:
1865 case AV_CODEC_ID_8BPS:
1866 case AV_CODEC_ID_FLIC:
1867 case AV_CODEC_ID_VMDVIDEO:
1868 case AV_CODEC_ID_VMDAUDIO:
1869 case AV_CODEC_ID_VIXL:
1870 case AV_CODEC_ID_QPEG:
1871 case AV_CODEC_ID_PGMYUV:
1872 case AV_CODEC_ID_FFVHUFF:
1873 case AV_CODEC_ID_WNV1:
1874 case AV_CODEC_ID_MP3ADU:
1875 case AV_CODEC_ID_MP3ON4:
1876 case AV_CODEC_ID_WESTWOOD_SND1:
1877 case AV_CODEC_ID_MMVIDEO:
1878 case AV_CODEC_ID_AVS:
1882 /* weird quasi-codecs for the demuxers only */
1883 case AV_CODEC_ID_PCM_S16LE:
1884 case AV_CODEC_ID_PCM_S16BE:
1885 case AV_CODEC_ID_PCM_U16LE:
1886 case AV_CODEC_ID_PCM_U16BE:
1887 case AV_CODEC_ID_PCM_S8:
1888 case AV_CODEC_ID_PCM_U8:
1890 GstAudioFormat format;
1893 case AV_CODEC_ID_PCM_S16LE:
1894 format = GST_AUDIO_FORMAT_S16LE;
1896 case AV_CODEC_ID_PCM_S16BE:
1897 format = GST_AUDIO_FORMAT_S16BE;
1899 case AV_CODEC_ID_PCM_U16LE:
1900 format = GST_AUDIO_FORMAT_U16LE;
1902 case AV_CODEC_ID_PCM_U16BE:
1903 format = GST_AUDIO_FORMAT_U16BE;
1905 case AV_CODEC_ID_PCM_S8:
1906 format = GST_AUDIO_FORMAT_S8;
1908 case AV_CODEC_ID_PCM_U8:
1909 format = GST_AUDIO_FORMAT_U8;
1913 g_assert (0); /* don't worry, we never get here */
1918 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1919 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1920 "layout", G_TYPE_STRING, "interleaved", NULL);
1924 case AV_CODEC_ID_PCM_MULAW:
1926 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1930 case AV_CODEC_ID_PCM_ALAW:
1932 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1936 case AV_CODEC_ID_ADPCM_G722:
1938 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1941 gst_caps_set_simple (caps,
1942 "block_align", G_TYPE_INT, context->block_align,
1943 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
1946 case AV_CODEC_ID_ADPCM_G726:
1948 /* the G726 decoder can also handle G721 */
1950 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1951 "layout", G_TYPE_STRING, "g726", NULL);
1953 gst_caps_set_simple (caps,
1954 "block_align", G_TYPE_INT, context->block_align,
1955 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
1958 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1959 "layout", G_TYPE_STRING, "g721",
1960 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1964 case AV_CODEC_ID_ADPCM_IMA_QT:
1965 case AV_CODEC_ID_ADPCM_IMA_WAV:
1966 case AV_CODEC_ID_ADPCM_IMA_DK3:
1967 case AV_CODEC_ID_ADPCM_IMA_DK4:
1968 case AV_CODEC_ID_ADPCM_IMA_WS:
1969 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1970 case AV_CODEC_ID_ADPCM_IMA_AMV:
1971 case AV_CODEC_ID_ADPCM_IMA_ISS:
1972 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1973 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1974 case AV_CODEC_ID_ADPCM_MS:
1975 case AV_CODEC_ID_ADPCM_4XM:
1976 case AV_CODEC_ID_ADPCM_XA:
1977 case AV_CODEC_ID_ADPCM_ADX:
1978 case AV_CODEC_ID_ADPCM_EA:
1979 case AV_CODEC_ID_ADPCM_CT:
1980 case AV_CODEC_ID_ADPCM_SWF:
1981 case AV_CODEC_ID_ADPCM_YAMAHA:
1982 case AV_CODEC_ID_ADPCM_SBPRO_2:
1983 case AV_CODEC_ID_ADPCM_SBPRO_3:
1984 case AV_CODEC_ID_ADPCM_SBPRO_4:
1985 case AV_CODEC_ID_ADPCM_EA_R1:
1986 case AV_CODEC_ID_ADPCM_EA_R2:
1987 case AV_CODEC_ID_ADPCM_EA_R3:
1988 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1989 case AV_CODEC_ID_ADPCM_EA_XAS:
1990 case AV_CODEC_ID_ADPCM_THP:
1992 const gchar *layout = NULL;
1995 case AV_CODEC_ID_ADPCM_IMA_QT:
1996 layout = "quicktime";
1998 case AV_CODEC_ID_ADPCM_IMA_WAV:
2001 case AV_CODEC_ID_ADPCM_IMA_DK3:
2004 case AV_CODEC_ID_ADPCM_IMA_DK4:
2007 case AV_CODEC_ID_ADPCM_IMA_WS:
2008 layout = "westwood";
2010 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
2013 case AV_CODEC_ID_ADPCM_IMA_AMV:
2016 case AV_CODEC_ID_ADPCM_IMA_ISS:
2019 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
2022 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
2025 case AV_CODEC_ID_ADPCM_MS:
2026 layout = "microsoft";
2028 case AV_CODEC_ID_ADPCM_4XM:
2031 case AV_CODEC_ID_ADPCM_XA:
2034 case AV_CODEC_ID_ADPCM_ADX:
2037 case AV_CODEC_ID_ADPCM_EA:
2040 case AV_CODEC_ID_ADPCM_CT:
2043 case AV_CODEC_ID_ADPCM_SWF:
2046 case AV_CODEC_ID_ADPCM_YAMAHA:
2049 case AV_CODEC_ID_ADPCM_SBPRO_2:
2052 case AV_CODEC_ID_ADPCM_SBPRO_3:
2055 case AV_CODEC_ID_ADPCM_SBPRO_4:
2058 case AV_CODEC_ID_ADPCM_EA_R1:
2061 case AV_CODEC_ID_ADPCM_EA_R2:
2064 case AV_CODEC_ID_ADPCM_EA_R3:
2067 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
2068 layout = "ea-maxis-xa";
2070 case AV_CODEC_ID_ADPCM_EA_XAS:
2073 case AV_CODEC_ID_ADPCM_THP:
2077 g_assert (0); /* don't worry, we never get here */
2081 /* FIXME: someone please check whether we need additional properties
2082 * in this caps definition. */
2084 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
2085 "layout", G_TYPE_STRING, layout, NULL);
2087 gst_caps_set_simple (caps,
2088 "block_align", G_TYPE_INT, context->block_align,
2089 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2093 case AV_CODEC_ID_AMR_NB:
2095 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
2099 case AV_CODEC_ID_AMR_WB:
2101 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
2105 case AV_CODEC_ID_GSM:
2107 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
2111 case AV_CODEC_ID_GSM_MS:
2113 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
2117 case AV_CODEC_ID_NELLYMOSER:
2119 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2120 "audio/x-nellymoser", NULL);
2123 case AV_CODEC_ID_SIPR:
2126 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
2129 gst_caps_set_simple (caps,
2130 "leaf_size", G_TYPE_INT, context->block_align,
2131 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2136 case AV_CODEC_ID_RA_144:
2137 case AV_CODEC_ID_RA_288:
2138 case AV_CODEC_ID_COOK:
2143 case AV_CODEC_ID_RA_144:
2146 case AV_CODEC_ID_RA_288:
2149 case AV_CODEC_ID_COOK:
2156 /* FIXME: properties? */
2158 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2159 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
2161 gst_caps_set_simple (caps,
2162 "leaf_size", G_TYPE_INT, context->block_align,
2163 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2168 case AV_CODEC_ID_ROQ_DPCM:
2169 case AV_CODEC_ID_INTERPLAY_DPCM:
2170 case AV_CODEC_ID_XAN_DPCM:
2171 case AV_CODEC_ID_SOL_DPCM:
2173 const gchar *layout = NULL;
2176 case AV_CODEC_ID_ROQ_DPCM:
2179 case AV_CODEC_ID_INTERPLAY_DPCM:
2180 layout = "interplay";
2182 case AV_CODEC_ID_XAN_DPCM:
2185 case AV_CODEC_ID_SOL_DPCM:
2189 g_assert (0); /* don't worry, we never get here */
2193 /* FIXME: someone please check whether we need additional properties
2194 * in this caps definition. */
2196 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2197 "layout", G_TYPE_STRING, layout, NULL);
2199 gst_caps_set_simple (caps,
2200 "block_align", G_TYPE_INT, context->block_align,
2201 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2205 case AV_CODEC_ID_SHORTEN:
2206 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2209 case AV_CODEC_ID_ALAC:
2211 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2214 gst_caps_set_simple (caps,
2215 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2219 case AV_CODEC_ID_FLAC:
2220 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2221 * encoder case, we want to add things like samplerate, channels... */
2223 caps = gst_caps_new_empty_simple ("audio/x-flac");
2227 case AV_CODEC_ID_OPUS:
2228 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2229 * encoder case, we want to add things like samplerate, channels... */
2231 /* FIXME: can ffmpeg handle multichannel Opus? */
2232 caps = gst_caps_new_simple ("audio/x-opus",
2233 "channel-mapping-family", G_TYPE_INT, 0, NULL);
2237 case AV_CODEC_ID_S302M:
2238 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2241 case AV_CODEC_ID_DVD_SUBTITLE:
2242 case AV_CODEC_ID_DVB_SUBTITLE:
2245 case AV_CODEC_ID_BMP:
2246 caps = gst_caps_new_empty_simple ("image/bmp");
2248 case AV_CODEC_ID_TTA:
2250 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2253 gst_caps_set_simple (caps,
2254 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2257 case AV_CODEC_ID_TWINVQ:
2259 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2260 "audio/x-twin-vq", NULL);
2262 case AV_CODEC_ID_G729:
2264 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G729",
2267 case AV_CODEC_ID_DSD_LSBF:
2269 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2271 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2272 TRUE, "planar", G_TYPE_BOOLEAN, FALSE, NULL);
2274 case AV_CODEC_ID_DSD_MSBF:
2276 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2278 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2279 FALSE, "planar", G_TYPE_BOOLEAN, FALSE, NULL);
2281 case AV_CODEC_ID_DSD_LSBF_PLANAR:
2283 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2285 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2286 TRUE, "planar", G_TYPE_BOOLEAN, TRUE, NULL);
2288 case AV_CODEC_ID_DSD_MSBF_PLANAR:
2290 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2292 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2293 FALSE, "planar", G_TYPE_BOOLEAN, TRUE, NULL);
2296 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2303 if ((codec = avcodec_find_decoder (codec_id)) ||
2304 (codec = avcodec_find_encoder (codec_id))) {
2307 GST_LOG ("Could not create stream format caps for %s", codec->name);
2309 switch (codec->type) {
2310 case AVMEDIA_TYPE_VIDEO:
2311 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2313 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2316 case AVMEDIA_TYPE_AUDIO:
2317 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2319 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2321 gst_caps_set_simple (caps,
2322 "block_align", G_TYPE_INT, context->block_align,
2323 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2334 /* set private data */
2335 if (context && context->extradata_size > 0) {
2336 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2338 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2339 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2340 gst_buffer_unref (data);
2343 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2346 GST_LOG ("No caps found for codec_id=%d", codec_id);
2352 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2353 * to a GstCaps. If the context is ommitted, no fixed values
2354 * for video/audio size will be included in the GstCaps
2356 * See below for usefullness
2360 gst_ffmpeg_pixfmt_to_caps (enum AVPixelFormat pix_fmt, AVCodecContext * context,
2361 enum AVCodecID codec_id)
2363 GstCaps *caps = NULL;
2364 GstVideoFormat format;
2366 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2368 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2369 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2370 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2374 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2376 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2383 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt,
2384 GstAudioLayout * layout)
2387 *layout = GST_AUDIO_LAYOUT_NON_INTERLEAVED;
2389 switch (sample_fmt) {
2390 case AV_SAMPLE_FMT_U8:
2392 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2393 case AV_SAMPLE_FMT_U8P:
2394 return GST_AUDIO_FORMAT_U8;
2397 case AV_SAMPLE_FMT_S16:
2399 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2400 case AV_SAMPLE_FMT_S16P:
2401 return GST_AUDIO_FORMAT_S16;
2404 case AV_SAMPLE_FMT_S32:
2406 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2407 case AV_SAMPLE_FMT_S32P:
2408 return GST_AUDIO_FORMAT_S32;
2410 case AV_SAMPLE_FMT_FLT:
2412 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2413 case AV_SAMPLE_FMT_FLTP:
2414 return GST_AUDIO_FORMAT_F32;
2417 case AV_SAMPLE_FMT_DBL:
2419 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2420 case AV_SAMPLE_FMT_DBLP:
2421 return GST_AUDIO_FORMAT_F64;
2426 return GST_AUDIO_FORMAT_UNKNOWN;
2431 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2432 * to a GstCaps. If the context is ommitted, no fixed values
2433 * for video/audio size will be included in the GstCaps
2435 * See below for usefullness
2439 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2440 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2442 GstCaps *caps = NULL;
2443 GstAudioFormat format;
2444 GstAudioLayout layout;
2446 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt, &layout);
2448 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2449 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2450 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2451 "layout", G_TYPE_STRING,
2452 (layout == GST_AUDIO_LAYOUT_INTERLEAVED) ?
2453 "interleaved" : "non-interleaved", NULL);
2454 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2456 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2463 caps_has_field (GstCaps * caps, const gchar * field)
2467 n = gst_caps_get_size (caps);
2468 for (i = 0; i < n; i++) {
2469 GstStructure *s = gst_caps_get_structure (caps, i);
2471 if (gst_structure_has_field (s, field))
2479 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2480 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2482 GstCaps *caps = NULL;
2484 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2485 context, codec_id, encode, codec);
2487 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2488 codec->sample_fmts, codec->supported_samplerates);
2491 /* Specific codec context */
2493 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2496 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2498 if (!caps_has_field (caps, "format"))
2499 gst_ffmpeg_audio_set_sample_fmts (caps,
2500 codec ? codec->sample_fmts : NULL, encode);
2507 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2508 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2512 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2513 context, codec_id, encode, codec);
2516 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2519 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2521 if (!caps_has_field (caps, "format"))
2522 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2527 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2528 * and other audio properties in a AVCodecContext.
2530 * For usefullness, see below
2534 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2535 AVCodecContext * context, gboolean raw)
2537 GstStructure *structure;
2539 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2541 const gchar *layout;
2542 gboolean interleaved;
2544 g_return_if_fail (gst_caps_get_size (caps) == 1);
2546 structure = gst_caps_get_structure (caps, 0);
2548 gst_structure_get_int (structure, "channels", &context->channels);
2549 gst_structure_get_int (structure, "rate", &context->sample_rate);
2550 gst_structure_get_int (structure, "block_align", &context->block_align);
2551 if (gst_structure_get_int (structure, "bitrate", &bitrate))
2552 context->bit_rate = bitrate;
2557 if (gst_structure_has_name (structure, "audio/x-raw")) {
2558 if ((fmt = gst_structure_get_string (structure, "format"))) {
2559 format = gst_audio_format_from_string (fmt);
2563 layout = gst_structure_get_string (structure, "layout");
2564 interleaved = ! !g_strcmp0 (layout, "non-interleaved");
2567 case GST_AUDIO_FORMAT_F32:
2568 context->sample_fmt =
2569 interleaved ? AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_FLTP;
2571 case GST_AUDIO_FORMAT_F64:
2572 context->sample_fmt =
2573 interleaved ? AV_SAMPLE_FMT_DBL : AV_SAMPLE_FMT_DBLP;
2575 case GST_AUDIO_FORMAT_S32:
2576 context->sample_fmt =
2577 interleaved ? AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S32P;
2579 case GST_AUDIO_FORMAT_S16:
2580 context->sample_fmt =
2581 interleaved ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_S16P;
2588 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2589 * and other video properties in a AVCodecContext.
2591 * For usefullness, see below
2595 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2596 AVCodecContext * context, gboolean raw)
2598 GstStructure *structure;
2600 const GValue *par = NULL;
2602 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2605 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2606 g_return_if_fail (gst_caps_get_size (caps) == 1);
2607 structure = gst_caps_get_structure (caps, 0);
2609 gst_structure_get_int (structure, "width", &context->width);
2610 gst_structure_get_int (structure, "height", &context->height);
2611 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2613 fps = gst_structure_get_value (structure, "framerate");
2614 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2616 int num = gst_value_get_fraction_numerator (fps);
2617 int den = gst_value_get_fraction_denominator (fps);
2619 if (num > 0 && den > 0) {
2620 /* somehow these seem mixed up.. */
2621 /* they're fine, this is because it does period=1/frequency */
2622 context->time_base.den = gst_value_get_fraction_numerator (fps);
2623 context->time_base.num = gst_value_get_fraction_denominator (fps);
2624 context->ticks_per_frame = 1;
2626 GST_DEBUG ("setting framerate %d/%d = %lf",
2627 context->time_base.den, context->time_base.num,
2628 1. * context->time_base.den / context->time_base.num);
2630 GST_INFO ("ignoring framerate %d/%d (probably variable framerate)",
2631 context->time_base.num, context->time_base.den);
2635 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2636 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2638 int num = gst_value_get_fraction_numerator (par);
2639 int den = gst_value_get_fraction_denominator (par);
2641 if (num > 0 && den > 0) {
2642 context->sample_aspect_ratio.num = num;
2643 context->sample_aspect_ratio.den = den;
2645 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2646 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2647 1. * context->sample_aspect_ratio.num /
2648 context->sample_aspect_ratio.den);
2650 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2651 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2658 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2660 if (gst_structure_has_name (structure, "video/x-raw")) {
2661 if ((fmt = gst_structure_get_string (structure, "format"))) {
2662 format = gst_video_format_from_string (fmt);
2667 case GST_VIDEO_FORMAT_YUY2:
2668 context->pix_fmt = AV_PIX_FMT_YUYV422;
2670 case GST_VIDEO_FORMAT_I420:
2671 context->pix_fmt = AV_PIX_FMT_YUV420P;
2673 case GST_VIDEO_FORMAT_A420:
2674 context->pix_fmt = AV_PIX_FMT_YUVA420P;
2676 case GST_VIDEO_FORMAT_Y41B:
2677 context->pix_fmt = AV_PIX_FMT_YUV411P;
2679 case GST_VIDEO_FORMAT_Y42B:
2680 context->pix_fmt = AV_PIX_FMT_YUV422P;
2682 case GST_VIDEO_FORMAT_YUV9:
2683 context->pix_fmt = AV_PIX_FMT_YUV410P;
2685 case GST_VIDEO_FORMAT_Y444:
2686 context->pix_fmt = AV_PIX_FMT_YUV444P;
2688 case GST_VIDEO_FORMAT_GRAY8:
2689 context->pix_fmt = AV_PIX_FMT_GRAY8;
2691 case GST_VIDEO_FORMAT_xRGB:
2692 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2693 context->pix_fmt = AV_PIX_FMT_RGB32;
2696 case GST_VIDEO_FORMAT_BGRx:
2697 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2698 context->pix_fmt = AV_PIX_FMT_RGB32;
2701 case GST_VIDEO_FORMAT_RGB:
2702 context->pix_fmt = AV_PIX_FMT_RGB24;
2704 case GST_VIDEO_FORMAT_BGR:
2705 context->pix_fmt = AV_PIX_FMT_BGR24;
2707 case GST_VIDEO_FORMAT_RGB16:
2708 context->pix_fmt = AV_PIX_FMT_RGB565;
2710 case GST_VIDEO_FORMAT_RGB15:
2711 context->pix_fmt = AV_PIX_FMT_RGB555;
2713 case GST_VIDEO_FORMAT_RGB8P:
2714 context->pix_fmt = AV_PIX_FMT_PAL8;
2720 s = gst_structure_get_string (structure, "interlace-mode");
2722 if (strcmp (s, "progressive") == 0) {
2723 context->field_order = AV_FIELD_PROGRESSIVE;
2724 } else if (strcmp (s, "interleaved") == 0) {
2725 s = gst_structure_get_string (structure, "field-order");
2727 if (strcmp (s, "top-field-first") == 0) {
2728 context->field_order = AV_FIELD_TT;
2729 } else if (strcmp (s, "bottom-field-first") == 0) {
2730 context->field_order = AV_FIELD_TB;
2739 GstVideoFormat format;
2740 enum AVPixelFormat pixfmt;
2743 /* FIXME : FILLME */
2744 static const PixToFmt pixtofmttable[] = {
2745 /* GST_VIDEO_FORMAT_I420, */
2746 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P},
2747 /* Note : this should use a different chroma placement */
2748 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUVJ420P},
2750 /* GST_VIDEO_FORMAT_YV12, */
2751 /* GST_VIDEO_FORMAT_YUY2, */
2752 {GST_VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422},
2753 /* GST_VIDEO_FORMAT_UYVY, */
2754 {GST_VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422},
2755 /* GST_VIDEO_FORMAT_AYUV, */
2756 /* GST_VIDEO_FORMAT_RGBx, */
2757 {GST_VIDEO_FORMAT_RGBx, AV_PIX_FMT_RGB0},
2758 /* GST_VIDEO_FORMAT_BGRx, */
2759 {GST_VIDEO_FORMAT_BGRx, AV_PIX_FMT_BGR0},
2760 /* GST_VIDEO_FORMAT_xRGB, */
2761 {GST_VIDEO_FORMAT_xRGB, AV_PIX_FMT_0RGB},
2762 /* GST_VIDEO_FORMAT_xBGR, */
2763 {GST_VIDEO_FORMAT_xBGR, AV_PIX_FMT_0BGR},
2764 /* GST_VIDEO_FORMAT_RGBA, */
2765 {GST_VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA},
2766 /* GST_VIDEO_FORMAT_BGRA, */
2767 {GST_VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA},
2768 /* GST_VIDEO_FORMAT_ARGB, */
2769 {GST_VIDEO_FORMAT_ARGB, AV_PIX_FMT_ARGB},
2770 /* GST_VIDEO_FORMAT_ABGR, */
2771 {GST_VIDEO_FORMAT_ABGR, AV_PIX_FMT_ABGR},
2772 /* GST_VIDEO_FORMAT_RGB, */
2773 {GST_VIDEO_FORMAT_RGB, AV_PIX_FMT_RGB24},
2774 /* GST_VIDEO_FORMAT_BGR, */
2775 {GST_VIDEO_FORMAT_BGR, AV_PIX_FMT_BGR24},
2776 /* GST_VIDEO_FORMAT_Y41B, */
2777 {GST_VIDEO_FORMAT_Y41B, AV_PIX_FMT_YUV411P},
2778 /* GST_VIDEO_FORMAT_Y42B, */
2779 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUV422P},
2780 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUVJ422P},
2781 /* GST_VIDEO_FORMAT_YVYU, */
2782 /* GST_VIDEO_FORMAT_Y444, */
2783 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUV444P},
2784 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUVJ444P},
2785 /* GST_VIDEO_FORMAT_v210, */
2786 /* GST_VIDEO_FORMAT_v216, */
2787 /* GST_VIDEO_FORMAT_NV12, */
2788 {GST_VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12},
2789 /* GST_VIDEO_FORMAT_NV21, */
2790 {GST_VIDEO_FORMAT_NV21, AV_PIX_FMT_NV21},
2791 /* GST_VIDEO_FORMAT_GRAY8, */
2792 {GST_VIDEO_FORMAT_GRAY8, AV_PIX_FMT_GRAY8},
2793 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2794 {GST_VIDEO_FORMAT_GRAY16_BE, AV_PIX_FMT_GRAY16BE},
2795 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2796 {GST_VIDEO_FORMAT_GRAY16_LE, AV_PIX_FMT_GRAY16LE},
2797 /* GST_VIDEO_FORMAT_v308, */
2798 /* GST_VIDEO_FORMAT_Y800, */
2799 /* GST_VIDEO_FORMAT_Y16, */
2800 /* GST_VIDEO_FORMAT_RGB16, */
2801 {GST_VIDEO_FORMAT_RGB16, AV_PIX_FMT_RGB565},
2802 /* GST_VIDEO_FORMAT_BGR16, */
2803 /* GST_VIDEO_FORMAT_RGB15, */
2804 {GST_VIDEO_FORMAT_RGB15, AV_PIX_FMT_RGB555},
2805 /* GST_VIDEO_FORMAT_BGR15, */
2806 /* GST_VIDEO_FORMAT_UYVP, */
2807 /* GST_VIDEO_FORMAT_A420, */
2808 {GST_VIDEO_FORMAT_A420, AV_PIX_FMT_YUVA420P},
2809 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2810 {GST_VIDEO_FORMAT_RGB8P, AV_PIX_FMT_PAL8},
2811 /* GST_VIDEO_FORMAT_YUV9, */
2812 {GST_VIDEO_FORMAT_YUV9, AV_PIX_FMT_YUV410P},
2813 /* GST_VIDEO_FORMAT_YVU9, */
2814 /* GST_VIDEO_FORMAT_IYU1, */
2815 /* GST_VIDEO_FORMAT_ARGB64, */
2816 /* GST_VIDEO_FORMAT_AYUV64, */
2817 /* GST_VIDEO_FORMAT_r210, */
2818 {GST_VIDEO_FORMAT_I420_10LE, AV_PIX_FMT_YUV420P10LE},
2819 {GST_VIDEO_FORMAT_I420_10BE, AV_PIX_FMT_YUV420P10BE},
2820 {GST_VIDEO_FORMAT_I422_10LE, AV_PIX_FMT_YUV422P10LE},
2821 {GST_VIDEO_FORMAT_I422_10BE, AV_PIX_FMT_YUV422P10BE},
2822 {GST_VIDEO_FORMAT_Y444_10LE, AV_PIX_FMT_YUV444P10LE},
2823 {GST_VIDEO_FORMAT_Y444_10BE, AV_PIX_FMT_YUV444P10BE},
2824 {GST_VIDEO_FORMAT_GBR, AV_PIX_FMT_GBRP},
2825 {GST_VIDEO_FORMAT_GBRA, AV_PIX_FMT_GBRAP},
2826 {GST_VIDEO_FORMAT_GBR_10LE, AV_PIX_FMT_GBRP10LE},
2827 {GST_VIDEO_FORMAT_GBR_10BE, AV_PIX_FMT_GBRP10BE},
2828 {GST_VIDEO_FORMAT_GBR_12LE, AV_PIX_FMT_GBRP12LE},
2829 {GST_VIDEO_FORMAT_GBR_12BE, AV_PIX_FMT_GBRP12BE},
2830 {GST_VIDEO_FORMAT_GBRA_12LE, AV_PIX_FMT_GBRAP12LE},
2831 {GST_VIDEO_FORMAT_GBRA_12BE, AV_PIX_FMT_GBRAP12BE},
2832 {GST_VIDEO_FORMAT_A420_10LE, AV_PIX_FMT_YUVA420P10LE},
2833 {GST_VIDEO_FORMAT_A420_10BE, AV_PIX_FMT_YUVA420P10BE},
2834 {GST_VIDEO_FORMAT_A422_10LE, AV_PIX_FMT_YUVA422P10LE},
2835 {GST_VIDEO_FORMAT_A422_10BE, AV_PIX_FMT_YUVA422P10BE},
2836 {GST_VIDEO_FORMAT_A444_10LE, AV_PIX_FMT_YUVA444P10LE},
2837 {GST_VIDEO_FORMAT_A444_10BE, AV_PIX_FMT_YUVA444P10BE},
2838 {GST_VIDEO_FORMAT_I420_12LE, AV_PIX_FMT_YUV420P12LE},
2839 {GST_VIDEO_FORMAT_I420_12BE, AV_PIX_FMT_YUV420P12BE},
2840 {GST_VIDEO_FORMAT_I422_12LE, AV_PIX_FMT_YUV422P12LE},
2841 {GST_VIDEO_FORMAT_I422_12BE, AV_PIX_FMT_YUV422P12BE},
2842 {GST_VIDEO_FORMAT_Y444_12LE, AV_PIX_FMT_YUV444P12LE},
2843 {GST_VIDEO_FORMAT_Y444_12BE, AV_PIX_FMT_YUV444P12BE},
2847 gst_ffmpeg_pixfmt_to_videoformat (enum AVPixelFormat pixfmt)
2851 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2852 if (pixtofmttable[i].pixfmt == pixfmt)
2853 return pixtofmttable[i].format;
2855 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2856 return GST_VIDEO_FORMAT_UNKNOWN;
2859 static enum AVPixelFormat
2860 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GstVideoFormat format,
2861 const AVCodec * codec)
2865 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++) {
2866 if (pixtofmttable[i].format == format) {
2869 if (codec && codec->pix_fmts) {
2870 for (j = 0; codec->pix_fmts[j] != -1; j++) {
2871 if (pixtofmttable[i].pixfmt == codec->pix_fmts[j])
2872 return pixtofmttable[i].pixfmt;
2875 return pixtofmttable[i].pixfmt;
2880 return AV_PIX_FMT_NONE;
2884 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2886 return gst_ffmpeg_videoformat_to_pixfmt_for_codec (format, NULL);
2890 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2894 context->width = GST_VIDEO_INFO_WIDTH (info);
2895 context->height = GST_VIDEO_INFO_HEIGHT (info);
2896 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2897 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2898 context->bits_per_coded_sample = bpp;
2900 context->ticks_per_frame = 1;
2901 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2902 GST_DEBUG ("Using 25/1 framerate");
2903 context->time_base.den = 25;
2904 context->time_base.num = 1;
2906 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2907 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2910 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2911 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2914 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GST_VIDEO_INFO_FORMAT (info),
2917 switch (info->chroma_site) {
2918 case GST_VIDEO_CHROMA_SITE_MPEG2:
2919 context->chroma_sample_location = AVCHROMA_LOC_LEFT;
2921 case GST_VIDEO_CHROMA_SITE_JPEG:
2922 context->chroma_sample_location = AVCHROMA_LOC_CENTER;
2924 case GST_VIDEO_CHROMA_SITE_DV:
2925 context->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
2927 case GST_VIDEO_CHROMA_SITE_V_COSITED:
2928 context->chroma_sample_location = AVCHROMA_LOC_TOP;
2934 switch (info->colorimetry.primaries) {
2935 case GST_VIDEO_COLOR_PRIMARIES_BT709:
2936 context->color_primaries = AVCOL_PRI_BT709;
2938 case GST_VIDEO_COLOR_PRIMARIES_BT470M:
2939 context->color_primaries = AVCOL_PRI_BT470M;
2941 case GST_VIDEO_COLOR_PRIMARIES_BT470BG:
2942 context->color_primaries = AVCOL_PRI_BT470BG;
2944 case GST_VIDEO_COLOR_PRIMARIES_SMPTE170M:
2945 context->color_primaries = AVCOL_PRI_SMPTE170M;
2947 case GST_VIDEO_COLOR_PRIMARIES_SMPTE240M:
2948 context->color_primaries = AVCOL_PRI_SMPTE240M;
2950 case GST_VIDEO_COLOR_PRIMARIES_FILM:
2951 context->color_primaries = AVCOL_PRI_FILM;
2953 case GST_VIDEO_COLOR_PRIMARIES_BT2020:
2954 context->color_primaries = AVCOL_PRI_BT2020;
2960 switch (info->colorimetry.transfer) {
2961 case GST_VIDEO_TRANSFER_BT709:
2962 context->color_trc = AVCOL_TRC_BT709;
2964 case GST_VIDEO_TRANSFER_GAMMA22:
2965 context->color_trc = AVCOL_TRC_GAMMA22;
2967 case GST_VIDEO_TRANSFER_GAMMA28:
2968 context->color_trc = AVCOL_TRC_GAMMA28;
2970 case GST_VIDEO_TRANSFER_SMPTE240M:
2971 context->color_trc = AVCOL_TRC_SMPTE240M;
2973 case GST_VIDEO_TRANSFER_GAMMA10:
2974 context->color_trc = AVCOL_TRC_LINEAR;
2976 case GST_VIDEO_TRANSFER_LOG100:
2977 context->color_trc = AVCOL_TRC_LOG;
2979 case GST_VIDEO_TRANSFER_LOG316:
2980 context->color_trc = AVCOL_TRC_LOG_SQRT;
2982 case GST_VIDEO_TRANSFER_BT2020_12:
2983 context->color_trc = AVCOL_TRC_BT2020_12;
2989 switch (info->colorimetry.matrix) {
2990 case GST_VIDEO_COLOR_MATRIX_RGB:
2991 context->colorspace = AVCOL_SPC_RGB;
2993 case GST_VIDEO_COLOR_MATRIX_BT709:
2994 context->colorspace = AVCOL_SPC_BT709;
2996 case GST_VIDEO_COLOR_MATRIX_FCC:
2997 context->colorspace = AVCOL_SPC_FCC;
2999 case GST_VIDEO_COLOR_MATRIX_BT601:
3000 context->colorspace = AVCOL_SPC_BT470BG;
3002 case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
3003 context->colorspace = AVCOL_SPC_SMPTE240M;
3005 case GST_VIDEO_COLOR_MATRIX_BT2020:
3006 context->colorspace = AVCOL_SPC_BT2020_NCL;
3012 if (info->colorimetry.range == GST_VIDEO_COLOR_RANGE_0_255) {
3013 context->color_range = AVCOL_RANGE_JPEG;
3015 context->color_range = AVCOL_RANGE_MPEG;
3020 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
3022 const AVCodec *codec;
3023 const enum AVSampleFormat *smpl_fmts;
3024 enum AVSampleFormat smpl_fmt = -1;
3026 context->channels = info->channels;
3027 context->sample_rate = info->rate;
3028 context->channel_layout =
3029 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
3031 codec = context->codec;
3033 smpl_fmts = codec->sample_fmts;
3035 switch (info->finfo->format) {
3036 case GST_AUDIO_FORMAT_F32:
3038 while (*smpl_fmts != -1) {
3039 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
3040 smpl_fmt = *smpl_fmts;
3042 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
3043 smpl_fmt = *smpl_fmts;
3049 smpl_fmt = AV_SAMPLE_FMT_FLT;
3052 case GST_AUDIO_FORMAT_F64:
3054 while (*smpl_fmts != -1) {
3055 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
3056 smpl_fmt = *smpl_fmts;
3058 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
3059 smpl_fmt = *smpl_fmts;
3065 smpl_fmt = AV_SAMPLE_FMT_DBL;
3068 case GST_AUDIO_FORMAT_S32:
3070 while (*smpl_fmts != -1) {
3071 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
3072 smpl_fmt = *smpl_fmts;
3074 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
3075 smpl_fmt = *smpl_fmts;
3081 smpl_fmt = AV_SAMPLE_FMT_S32;
3084 case GST_AUDIO_FORMAT_S16:
3086 while (*smpl_fmts != -1) {
3087 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
3088 smpl_fmt = *smpl_fmts;
3090 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
3091 smpl_fmt = *smpl_fmts;
3097 smpl_fmt = AV_SAMPLE_FMT_S16;
3100 case GST_AUDIO_FORMAT_U8:
3102 while (*smpl_fmts != -1) {
3103 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
3104 smpl_fmt = *smpl_fmts;
3106 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
3107 smpl_fmt = *smpl_fmts;
3113 smpl_fmt = AV_SAMPLE_FMT_U8;
3120 g_assert (smpl_fmt != -1);
3122 context->sample_fmt = smpl_fmt;
3125 /* Convert a GstCaps and a FFMPEG codec Type to a
3126 * AVCodecContext. If the context is ommitted, no fixed values
3127 * for video/audio size will be included in the context
3129 * AVMediaType is primarily meant for uncompressed data GstCaps!
3133 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
3134 const GstCaps * caps, AVCodecContext * context)
3136 if (context == NULL)
3140 case AVMEDIA_TYPE_VIDEO:
3141 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
3144 case AVMEDIA_TYPE_AUDIO:
3145 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
3156 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
3160 guint8 *end = src + size;
3163 while (srcp < end) {
3164 if (count == 2 && *srcp <= 0x03) {
3165 GST_DEBUG ("added escape code");
3174 GST_DEBUG ("copy %02x, count %d", *srcp, count);
3177 *destsize = dstp - dst;
3180 /* copy the config, escaping NAL units as we iterate them, if something fails we
3181 * copy everything and hope for the best. */
3183 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
3188 guint nalsize, esize;
3198 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
3200 GST_DEBUG ("num SPS %d", cnt);
3202 memcpy (dstp, srcp, 6);
3206 for (i = 0; i < cnt; i++) {
3207 GST_DEBUG ("copy SPS %d", i);
3208 nalsize = (srcp[0] << 8) | srcp[1];
3209 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
3210 dstp[0] = esize >> 8;
3211 dstp[1] = esize & 0xff;
3213 srcp += nalsize + 2;
3216 cnt = *(dstp++) = *(srcp++); /* Number of pps */
3218 GST_DEBUG ("num PPS %d", cnt);
3220 for (i = 0; i < cnt; i++) {
3221 GST_DEBUG ("copy PPS %d", i);
3222 nalsize = (srcp[0] << 8) | srcp[1];
3223 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
3224 dstp[0] = esize >> 8;
3225 dstp[1] = esize & 0xff;
3227 srcp += nalsize + 2;
3229 *destsize = dstp - dst;
3235 GST_DEBUG ("something unexpected, doing full copy");
3236 memcpy (dst, src, size);
3244 * caps_with_codecid () transforms a GstCaps for a known codec
3245 * ID into a filled-in context.
3246 * codec_data from caps will override possible extradata already in the context
3250 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
3251 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
3254 const GValue *value;
3257 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
3258 codec_id, codec_type, caps, context);
3260 if (!context || !gst_caps_get_size (caps))
3263 str = gst_caps_get_structure (caps, 0);
3265 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
3266 if ((value = gst_structure_get_value (str, "codec_data"))) {
3269 buf = gst_value_get_buffer (value);
3270 gst_buffer_map (buf, &map, GST_MAP_READ);
3272 /* free the old one if it is there */
3273 if (context->extradata)
3274 av_free (context->extradata);
3277 if (codec_id == AV_CODEC_ID_H264) {
3280 GST_DEBUG ("copy, escaping codec_data %d", size);
3281 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
3282 * reason for this but let's just escape it for now. Start by allocating
3283 * enough space, x2 is more than enough.
3285 * FIXME, we disabled escaping because some file already contain escaped
3286 * codec_data and then we escape twice and fail. It's better to leave it
3287 * as is, as that is what most players do. */
3288 context->extradata =
3289 av_mallocz (GST_ROUND_UP_16 (size * 2 +
3290 AV_INPUT_BUFFER_PADDING_SIZE));
3291 copy_config (context->extradata, data, size, &extrasize);
3292 GST_DEBUG ("escaped size: %d", extrasize);
3293 context->extradata_size = extrasize;
3297 /* allocate with enough padding */
3298 GST_DEBUG ("copy codec_data");
3299 context->extradata =
3300 av_mallocz (GST_ROUND_UP_16 (map.size +
3301 AV_INPUT_BUFFER_PADDING_SIZE));
3302 memcpy (context->extradata, map.data, map.size);
3303 context->extradata_size = map.size;
3306 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
3307 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
3308 context->extradata[0] = (guint8) map.size;
3311 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
3313 gst_buffer_unmap (buf, &map);
3314 #ifdef GST_TIZEN_MODIFICATION
3315 } else if (!context->extradata) {
3318 context->extradata = NULL;
3320 context->extradata_size = 0;
3321 GST_DEBUG ("no codec data");
3325 case AV_CODEC_ID_MPEG4:
3327 const gchar *mime = gst_structure_get_name (str);
3329 context->flags |= AV_CODEC_FLAG_4MV;
3331 if (!strcmp (mime, "video/x-divx"))
3332 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
3333 else if (!strcmp (mime, "video/mpeg")) {
3334 const gchar *profile;
3336 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
3338 profile = gst_structure_get_string (str, "profile");
3340 if (g_strcmp0 (profile, "advanced-simple") == 0)
3341 context->flags |= AV_CODEC_FLAG_QPEL;
3347 case AV_CODEC_ID_SVQ3:
3348 /* FIXME: this is a workaround for older gst-plugins releases
3349 * (<= 0.8.9). This should be removed at some point, because
3350 * it causes wrong decoded frame order. */
3351 if (!context->extradata) {
3352 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
3355 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
3356 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
3357 gst_structure_get_int (str, "low_delay", &low_delay) &&
3358 gst_structure_get_int (str, "unknown_svq3_flag",
3359 &unknown_svq3_flag)) {
3360 context->extradata = (guint8 *) av_mallocz (0x64);
3361 g_stpcpy ((gchar *) context->extradata, "SVQ3");
3365 flags |= unknown_svq3_flag;
3367 flags |= halfpel_flag;
3369 flags |= thirdpel_flag;
3372 flags = GUINT16_FROM_LE (flags);
3374 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
3375 context->extradata_size = 0x64;
3380 case AV_CODEC_ID_MSRLE:
3381 case AV_CODEC_ID_QTRLE:
3382 case AV_CODEC_ID_TSCC:
3383 case AV_CODEC_ID_CSCD:
3384 case AV_CODEC_ID_APE:
3388 if (gst_structure_get_int (str, "depth", &depth)) {
3389 context->bits_per_coded_sample = depth;
3391 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
3397 case AV_CODEC_ID_COOK:
3398 case AV_CODEC_ID_RA_288:
3399 case AV_CODEC_ID_RA_144:
3400 case AV_CODEC_ID_SIPR:
3405 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3406 context->block_align = leaf_size;
3407 if (gst_structure_get_int (str, "bitrate", &bitrate))
3408 context->bit_rate = bitrate;
3411 case AV_CODEC_ID_ALAC:
3412 gst_structure_get_int (str, "samplesize",
3413 &context->bits_per_coded_sample);
3416 case AV_CODEC_ID_DVVIDEO:
3418 const gchar *format;
3420 if ((format = gst_structure_get_string (str, "format"))) {
3422 if (g_str_equal (format, "YUY2"))
3423 context->pix_fmt = AV_PIX_FMT_YUYV422;
3424 else if (g_str_equal (format, "I420"))
3425 context->pix_fmt = AV_PIX_FMT_YUV420P;
3426 else if (g_str_equal (format, "A420"))
3427 context->pix_fmt = AV_PIX_FMT_YUVA420P;
3428 else if (g_str_equal (format, "Y41B"))
3429 context->pix_fmt = AV_PIX_FMT_YUV411P;
3430 else if (g_str_equal (format, "Y42B"))
3431 context->pix_fmt = AV_PIX_FMT_YUV422P;
3432 else if (g_str_equal (format, "YUV9"))
3433 context->pix_fmt = AV_PIX_FMT_YUV410P;
3435 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3439 GST_WARNING ("No specified format");
3442 case AV_CODEC_ID_H263P:
3446 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3447 context->flags |= AV_CODEC_FLAG_4MV;
3449 context->flags &= ~AV_CODEC_FLAG_4MV;
3450 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3451 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3452 context->flags |= AV_CODEC_FLAG_AC_PRED;
3454 context->flags &= ~AV_CODEC_FLAG_AC_PRED;
3455 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3456 context->flags |= AV_CODEC_FLAG_LOOP_FILTER;
3458 context->flags &= ~AV_CODEC_FLAG_LOOP_FILTER;
3461 case AV_CODEC_ID_ADPCM_G726:
3463 const gchar *layout;
3465 if ((layout = gst_structure_get_string (str, "layout"))) {
3466 if (!strcmp (layout, "g721")) {
3467 context->sample_rate = 8000;
3468 context->channels = 1;
3469 context->bit_rate = 32000;
3478 if (!gst_caps_is_fixed (caps))
3481 /* common properties (width, height, fps) */
3482 switch (codec_type) {
3483 case AVMEDIA_TYPE_VIDEO:
3484 gst_ffmpeg_caps_to_pixfmt (caps, context,
3485 codec_id == AV_CODEC_ID_RAWVIDEO);
3487 case AVMEDIA_TYPE_AUDIO:
3488 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3494 /* fixup of default settings */
3496 case AV_CODEC_ID_QCELP:
3497 /* QCELP is always mono, no matter what the caps say */
3498 context->channels = 1;
3500 case AV_CODEC_ID_ADPCM_G726:
3501 if (context->sample_rate && context->bit_rate)
3502 context->bits_per_coded_sample =
3503 context->bit_rate / context->sample_rate;
3510 /* _formatid_to_caps () is meant for muxers/demuxers, it
3511 * transforms a name (ffmpeg way of ID'ing these, why don't
3512 * they have unique numerical IDs?) to the corresponding
3513 * caps belonging to that mux-format
3515 * Note: we don't need any additional info because the caps
3516 * isn't supposed to contain any useful info besides the
3521 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3523 GstCaps *caps = NULL;
3525 if (!strcmp (format_name, "mpeg")) {
3526 caps = gst_caps_new_simple ("video/mpeg",
3527 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3528 } else if (!strcmp (format_name, "mpegts")) {
3529 caps = gst_caps_new_simple ("video/mpegts",
3530 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3531 } else if (!strcmp (format_name, "rm")) {
3532 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3533 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3534 } else if (!strcmp (format_name, "asf")) {
3535 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3536 } else if (!strcmp (format_name, "avi")) {
3537 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3538 } else if (!strcmp (format_name, "wav")) {
3539 caps = gst_caps_new_empty_simple ("audio/x-wav");
3540 } else if (!strcmp (format_name, "ape")) {
3541 caps = gst_caps_new_empty_simple ("application/x-ape");
3542 } else if (!strcmp (format_name, "swf")) {
3543 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3544 } else if (!strcmp (format_name, "au")) {
3545 caps = gst_caps_new_empty_simple ("audio/x-au");
3546 } else if (!strcmp (format_name, "dv")) {
3547 caps = gst_caps_new_simple ("video/x-dv",
3548 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3549 } else if (!strcmp (format_name, "4xm")) {
3550 caps = gst_caps_new_empty_simple ("video/x-4xm");
3551 } else if (!strcmp (format_name, "matroska")) {
3552 caps = gst_caps_new_empty_simple ("video/x-matroska");
3553 } else if (!strcmp (format_name, "ivf")) {
3554 caps = gst_caps_new_empty_simple ("video/x-ivf");
3555 } else if (!strcmp (format_name, "mp3")) {
3556 caps = gst_caps_new_empty_simple ("application/x-id3");
3557 } else if (!strcmp (format_name, "flic")) {
3558 caps = gst_caps_new_empty_simple ("video/x-fli");
3559 } else if (!strcmp (format_name, "flv")) {
3560 caps = gst_caps_new_empty_simple ("video/x-flv");
3561 } else if (!strcmp (format_name, "tta")) {
3562 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3563 } else if (!strcmp (format_name, "aiff")) {
3564 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3565 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3567 gst_caps_from_string
3568 ("application/x-3gp; video/quicktime; audio/x-m4a");
3569 } else if (!strcmp (format_name, "mov")) {
3570 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3571 } else if (!strcmp (format_name, "mp4")) {
3572 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3573 } else if (!strcmp (format_name, "3gp")) {
3574 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3575 } else if (!strcmp (format_name, "3g2")) {
3576 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3577 } else if (!strcmp (format_name, "psp")) {
3578 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3579 } else if (!strcmp (format_name, "ipod")) {
3580 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3581 } else if (!strcmp (format_name, "aac")) {
3582 caps = gst_caps_new_simple ("audio/mpeg",
3583 "mpegversion", G_TYPE_INT, 4, NULL);
3584 } else if (!strcmp (format_name, "gif")) {
3585 caps = gst_caps_from_string ("image/gif");
3586 } else if (!strcmp (format_name, "ogg")) {
3587 caps = gst_caps_from_string ("application/ogg");
3588 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3589 caps = gst_caps_from_string ("application/mxf");
3590 } else if (!strcmp (format_name, "gxf")) {
3591 caps = gst_caps_from_string ("application/gxf");
3592 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3593 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3594 "y4mversion", G_TYPE_INT, 2, NULL);
3595 } else if (!strcmp (format_name, "mpc")) {
3596 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3597 } else if (!strcmp (format_name, "mpc8")) {
3598 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 8");
3599 } else if (!strcmp (format_name, "vqf")) {
3600 caps = gst_caps_from_string ("audio/x-vqf");
3601 } else if (!strcmp (format_name, "nsv")) {
3602 caps = gst_caps_from_string ("video/x-nsv");
3603 } else if (!strcmp (format_name, "amr")) {
3604 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3605 } else if (!strcmp (format_name, "webm")) {
3606 caps = gst_caps_from_string ("video/webm");
3607 } else if (!strcmp (format_name, "voc")) {
3608 caps = gst_caps_from_string ("audio/x-voc");
3609 } else if (!strcmp (format_name, "pva")) {
3610 caps = gst_caps_from_string ("video/x-pva");
3611 } else if (!strcmp (format_name, "brstm")) {
3612 caps = gst_caps_from_string ("audio/x-brstm");
3613 } else if (!strcmp (format_name, "bfstm")) {
3614 caps = gst_caps_from_string ("audio/x-bfstm");
3618 GST_LOG ("Could not create stream format caps for %s", format_name);
3619 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3620 caps = gst_caps_new_empty_simple (name);
3628 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3629 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3630 AVOutputFormat * plugin)
3632 static enum AVCodecID tmp_vlist[] = {
3636 static enum AVCodecID tmp_alist[] = {
3641 GST_LOG ("format_name : %s", format_name);
3643 if (!strcmp (format_name, "mp4")) {
3644 static enum AVCodecID mp4_video_list[] = {
3645 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3649 static enum AVCodecID mp4_audio_list[] = {
3650 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3654 *video_codec_list = mp4_video_list;
3655 *audio_codec_list = mp4_audio_list;
3656 } else if (!strcmp (format_name, "mpeg")) {
3657 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3658 AV_CODEC_ID_MPEG2VIDEO,
3662 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3668 *video_codec_list = mpeg_video_list;
3669 *audio_codec_list = mpeg_audio_list;
3670 } else if (!strcmp (format_name, "dvd")) {
3671 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3674 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3677 AV_CODEC_ID_PCM_S16BE,
3681 *video_codec_list = mpeg_video_list;
3682 *audio_codec_list = mpeg_audio_list;
3683 } else if (!strcmp (format_name, "mpegts")) {
3684 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3685 AV_CODEC_ID_MPEG2VIDEO,
3689 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3697 *video_codec_list = mpegts_video_list;
3698 *audio_codec_list = mpegts_audio_list;
3699 } else if (!strcmp (format_name, "vob")) {
3700 static enum AVCodecID vob_video_list[] =
3701 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3702 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3703 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3706 *video_codec_list = vob_video_list;
3707 *audio_codec_list = vob_audio_list;
3708 } else if (!strcmp (format_name, "flv")) {
3709 static enum AVCodecID flv_video_list[] =
3710 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3711 static enum AVCodecID flv_audio_list[] =
3712 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3714 *video_codec_list = flv_video_list;
3715 *audio_codec_list = flv_audio_list;
3716 } else if (!strcmp (format_name, "asf")) {
3717 static enum AVCodecID asf_video_list[] =
3718 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3721 static enum AVCodecID asf_audio_list[] =
3722 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3726 *video_codec_list = asf_video_list;
3727 *audio_codec_list = asf_audio_list;
3728 } else if (!strcmp (format_name, "dv")) {
3729 static enum AVCodecID dv_video_list[] =
3730 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3731 static enum AVCodecID dv_audio_list[] =
3732 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3734 *video_codec_list = dv_video_list;
3735 *audio_codec_list = dv_audio_list;
3736 } else if (!strcmp (format_name, "mov")) {
3737 static enum AVCodecID mov_video_list[] = {
3738 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3739 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3740 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3744 static enum AVCodecID mov_audio_list[] = {
3745 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3746 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3747 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3748 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3749 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3752 *video_codec_list = mov_video_list;
3753 *audio_codec_list = mov_audio_list;
3754 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3755 static enum AVCodecID tgp_video_list[] = {
3756 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3759 static enum AVCodecID tgp_audio_list[] = {
3760 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3765 *video_codec_list = tgp_video_list;
3766 *audio_codec_list = tgp_audio_list;
3767 } else if (!strcmp (format_name, "mmf")) {
3768 static enum AVCodecID mmf_audio_list[] = {
3769 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3771 *video_codec_list = NULL;
3772 *audio_codec_list = mmf_audio_list;
3773 } else if (!strcmp (format_name, "amr")) {
3774 static enum AVCodecID amr_audio_list[] = {
3775 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3778 *video_codec_list = NULL;
3779 *audio_codec_list = amr_audio_list;
3780 } else if (!strcmp (format_name, "gif")) {
3781 static enum AVCodecID gif_image_list[] = {
3782 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3784 *video_codec_list = gif_image_list;
3785 *audio_codec_list = NULL;
3786 } else if ((!strcmp (format_name, "pva"))) {
3787 static enum AVCodecID pga_video_list[] = {
3788 AV_CODEC_ID_MPEG2VIDEO,
3791 static enum AVCodecID pga_audio_list[] = {
3796 *video_codec_list = pga_video_list;
3797 *audio_codec_list = pga_audio_list;
3798 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3799 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3800 tmp_vlist[0] = plugin->video_codec;
3801 tmp_alist[0] = plugin->audio_codec;
3803 *video_codec_list = tmp_vlist;
3804 *audio_codec_list = tmp_alist;
3806 GST_LOG ("Format %s not found", format_name);
3813 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3814 * are omitted, that can be queried by the user itself,
3815 * we're not eating the GstCaps or anything
3816 * A pointer to an allocated context is also needed for
3817 * optional extra info
3821 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3823 enum AVCodecID id = AV_CODEC_ID_NONE;
3824 const gchar *mimetype;
3825 const GstStructure *structure;
3826 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3828 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3829 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3830 structure = gst_caps_get_structure (caps, 0);
3832 mimetype = gst_structure_get_name (structure);
3834 if (!strcmp (mimetype, "video/x-raw")) {
3835 id = AV_CODEC_ID_RAWVIDEO;
3837 } else if (!strcmp (mimetype, "audio/x-raw")) {
3840 if (gst_audio_info_from_caps (&info, caps)) {
3841 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3842 case GST_AUDIO_FORMAT_S8:
3843 id = AV_CODEC_ID_PCM_S8;
3845 case GST_AUDIO_FORMAT_U8:
3846 id = AV_CODEC_ID_PCM_U8;
3848 case GST_AUDIO_FORMAT_S16LE:
3849 id = AV_CODEC_ID_PCM_S16LE;
3851 case GST_AUDIO_FORMAT_S16BE:
3852 id = AV_CODEC_ID_PCM_S16BE;
3854 case GST_AUDIO_FORMAT_U16LE:
3855 id = AV_CODEC_ID_PCM_U16LE;
3857 case GST_AUDIO_FORMAT_U16BE:
3858 id = AV_CODEC_ID_PCM_U16BE;
3863 if (id != AV_CODEC_ID_NONE)
3866 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3867 id = AV_CODEC_ID_PCM_MULAW;
3869 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3870 id = AV_CODEC_ID_PCM_ALAW;
3872 } else if (!strcmp (mimetype, "video/x-dv")) {
3875 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3877 id = AV_CODEC_ID_DVVIDEO;
3880 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3881 id = AV_CODEC_ID_DVAUDIO;
3883 } else if (!strcmp (mimetype, "video/x-h263")) {
3884 const gchar *h263version =
3885 gst_structure_get_string (structure, "h263version");
3886 if (h263version && !strcmp (h263version, "h263p"))
3887 id = AV_CODEC_ID_H263P;
3889 id = AV_CODEC_ID_H263;
3891 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3892 id = AV_CODEC_ID_H263I;
3894 } else if (!strcmp (mimetype, "video/x-h261")) {
3895 id = AV_CODEC_ID_H261;
3897 } else if (!strcmp (mimetype, "video/mpeg")) {
3901 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3902 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3904 switch (mpegversion) {
3906 id = AV_CODEC_ID_MPEG1VIDEO;
3909 id = AV_CODEC_ID_MPEG2VIDEO;
3912 id = AV_CODEC_ID_MPEG4;
3916 if (id != AV_CODEC_ID_NONE)
3918 } else if (!strcmp (mimetype, "image/jpeg")) {
3919 id = AV_CODEC_ID_MJPEG; /* A... B... */
3921 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3922 id = AV_CODEC_ID_MJPEGB;
3924 } else if (!strcmp (mimetype, "video/x-wmv")) {
3925 gint wmvversion = 0;
3927 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3928 switch (wmvversion) {
3930 id = AV_CODEC_ID_WMV1;
3933 id = AV_CODEC_ID_WMV2;
3937 const gchar *format;
3939 /* WMV3 unless the fourcc exists and says otherwise */
3940 id = AV_CODEC_ID_WMV3;
3942 if ((format = gst_structure_get_string (structure, "format")) &&
3943 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3944 id = AV_CODEC_ID_VC1;
3950 if (id != AV_CODEC_ID_NONE)
3952 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3953 id = AV_CODEC_ID_VORBIS;
3955 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3956 id = AV_CODEC_ID_QDM2;
3958 } else if (!strcmp (mimetype, "audio/mpeg")) {
3960 gint mpegversion = 0;
3962 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3963 switch (mpegversion) {
3964 case 2: /* ffmpeg uses faad for both... */
3966 id = AV_CODEC_ID_AAC;
3969 if (gst_structure_get_int (structure, "layer", &layer)) {
3972 id = AV_CODEC_ID_MP1;
3975 id = AV_CODEC_ID_MP2;
3978 id = AV_CODEC_ID_MP3;
3984 if (id != AV_CODEC_ID_NONE)
3986 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3987 gint streamversion = -1;
3989 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3990 if (streamversion == 7)
3991 id = AV_CODEC_ID_MUSEPACK7;
3993 id = AV_CODEC_ID_MUSEPACK7;
3995 } else if (!strcmp (mimetype, "audio/x-wma")) {
3996 gint wmaversion = 0;
3998 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3999 switch (wmaversion) {
4001 id = AV_CODEC_ID_WMAV1;
4004 id = AV_CODEC_ID_WMAV2;
4007 id = AV_CODEC_ID_WMAPRO;
4011 if (id != AV_CODEC_ID_NONE)
4013 } else if (!strcmp (mimetype, "audio/x-wms")) {
4014 id = AV_CODEC_ID_WMAVOICE;
4016 } else if (!strcmp (mimetype, "audio/x-ac3")) {
4017 id = AV_CODEC_ID_AC3;
4019 } else if (!strcmp (mimetype, "audio/x-eac3")) {
4020 id = AV_CODEC_ID_EAC3;
4022 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
4023 !strcmp (mimetype, "audio/atrac3")) {
4024 id = AV_CODEC_ID_ATRAC3;
4026 } else if (!strcmp (mimetype, "audio/x-dts")) {
4027 id = AV_CODEC_ID_DTS;
4029 } else if (!strcmp (mimetype, "application/x-ape")) {
4030 id = AV_CODEC_ID_APE;
4032 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
4033 gint msmpegversion = 0;
4035 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
4036 switch (msmpegversion) {
4038 id = AV_CODEC_ID_MSMPEG4V1;
4041 id = AV_CODEC_ID_MSMPEG4V2;
4044 id = AV_CODEC_ID_MSMPEG4V3;
4048 if (id != AV_CODEC_ID_NONE)
4050 } else if (!strcmp (mimetype, "video/x-svq")) {
4051 gint svqversion = 0;
4053 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
4054 switch (svqversion) {
4056 id = AV_CODEC_ID_SVQ1;
4059 id = AV_CODEC_ID_SVQ3;
4063 if (id != AV_CODEC_ID_NONE)
4065 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
4066 id = AV_CODEC_ID_HUFFYUV;
4068 } else if (!strcmp (mimetype, "audio/x-mace")) {
4069 gint maceversion = 0;
4071 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
4072 switch (maceversion) {
4074 id = AV_CODEC_ID_MACE3;
4077 id = AV_CODEC_ID_MACE6;
4081 if (id != AV_CODEC_ID_NONE)
4083 } else if (!strcmp (mimetype, "video/x-theora")) {
4084 id = AV_CODEC_ID_THEORA;
4086 } else if (!strcmp (mimetype, "video/x-vp3")) {
4087 id = AV_CODEC_ID_VP3;
4089 } else if (!strcmp (mimetype, "video/x-vp5")) {
4090 id = AV_CODEC_ID_VP5;
4092 } else if (!strcmp (mimetype, "video/x-vp6")) {
4093 id = AV_CODEC_ID_VP6;
4095 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
4096 id = AV_CODEC_ID_VP6F;
4098 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
4099 id = AV_CODEC_ID_VP6A;
4101 } else if (!strcmp (mimetype, "video/x-vp8")) {
4102 id = AV_CODEC_ID_VP8;
4104 } else if (!strcmp (mimetype, "video/x-vp9")) {
4105 id = AV_CODEC_ID_VP9;
4107 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
4108 id = AV_CODEC_ID_FLASHSV;
4110 } else if (!strcmp (mimetype, "video/x-flash-screen2")) {
4111 id = AV_CODEC_ID_FLASHSV2;
4113 } else if (!strcmp (mimetype, "video/x-cineform")) {
4114 id = AV_CODEC_ID_CFHD;
4116 } else if (!strcmp (mimetype, "video/x-indeo")) {
4117 gint indeoversion = 0;
4119 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
4120 switch (indeoversion) {
4122 id = AV_CODEC_ID_INDEO5;
4125 id = AV_CODEC_ID_INDEO4;
4128 id = AV_CODEC_ID_INDEO3;
4131 id = AV_CODEC_ID_INDEO2;
4134 if (id != AV_CODEC_ID_NONE)
4137 } else if (!strcmp (mimetype, "video/x-divx")) {
4138 gint divxversion = 0;
4140 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
4141 switch (divxversion) {
4143 id = AV_CODEC_ID_MSMPEG4V3;
4147 id = AV_CODEC_ID_MPEG4;
4151 if (id != AV_CODEC_ID_NONE)
4153 } else if (!strcmp (mimetype, "video/x-ffv")) {
4154 gint ffvversion = 0;
4156 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
4158 id = AV_CODEC_ID_FFV1;
4161 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
4162 id = AV_CODEC_ID_AIC;
4164 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
4165 const gchar *layout;
4167 layout = gst_structure_get_string (structure, "layout");
4168 if (layout == NULL) {
4170 } else if (!strcmp (layout, "quicktime")) {
4171 id = AV_CODEC_ID_ADPCM_IMA_QT;
4172 } else if (!strcmp (layout, "microsoft")) {
4173 id = AV_CODEC_ID_ADPCM_MS;
4174 } else if (!strcmp (layout, "dvi")) {
4175 id = AV_CODEC_ID_ADPCM_IMA_WAV;
4176 } else if (!strcmp (layout, "4xm")) {
4177 id = AV_CODEC_ID_ADPCM_4XM;
4178 } else if (!strcmp (layout, "smjpeg")) {
4179 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
4180 } else if (!strcmp (layout, "dk3")) {
4181 id = AV_CODEC_ID_ADPCM_IMA_DK3;
4182 } else if (!strcmp (layout, "dk4")) {
4183 id = AV_CODEC_ID_ADPCM_IMA_DK4;
4184 } else if (!strcmp (layout, "westwood")) {
4185 id = AV_CODEC_ID_ADPCM_IMA_WS;
4186 } else if (!strcmp (layout, "iss")) {
4187 id = AV_CODEC_ID_ADPCM_IMA_ISS;
4188 } else if (!strcmp (layout, "xa")) {
4189 id = AV_CODEC_ID_ADPCM_XA;
4190 } else if (!strcmp (layout, "adx")) {
4191 id = AV_CODEC_ID_ADPCM_ADX;
4192 } else if (!strcmp (layout, "ea")) {
4193 id = AV_CODEC_ID_ADPCM_EA;
4194 } else if (!strcmp (layout, "g726")) {
4195 id = AV_CODEC_ID_ADPCM_G726;
4196 } else if (!strcmp (layout, "g721")) {
4197 id = AV_CODEC_ID_ADPCM_G726;
4198 } else if (!strcmp (layout, "ct")) {
4199 id = AV_CODEC_ID_ADPCM_CT;
4200 } else if (!strcmp (layout, "swf")) {
4201 id = AV_CODEC_ID_ADPCM_SWF;
4202 } else if (!strcmp (layout, "yamaha")) {
4203 id = AV_CODEC_ID_ADPCM_YAMAHA;
4204 } else if (!strcmp (layout, "sbpro2")) {
4205 id = AV_CODEC_ID_ADPCM_SBPRO_2;
4206 } else if (!strcmp (layout, "sbpro3")) {
4207 id = AV_CODEC_ID_ADPCM_SBPRO_3;
4208 } else if (!strcmp (layout, "sbpro4")) {
4209 id = AV_CODEC_ID_ADPCM_SBPRO_4;
4211 if (id != AV_CODEC_ID_NONE)
4213 } else if (!strcmp (mimetype, "video/x-4xm")) {
4214 id = AV_CODEC_ID_4XM;
4216 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
4217 const gchar *layout;
4219 layout = gst_structure_get_string (structure, "layout");
4222 } else if (!strcmp (layout, "roq")) {
4223 id = AV_CODEC_ID_ROQ_DPCM;
4224 } else if (!strcmp (layout, "interplay")) {
4225 id = AV_CODEC_ID_INTERPLAY_DPCM;
4226 } else if (!strcmp (layout, "xan")) {
4227 id = AV_CODEC_ID_XAN_DPCM;
4228 } else if (!strcmp (layout, "sol")) {
4229 id = AV_CODEC_ID_SOL_DPCM;
4231 if (id != AV_CODEC_ID_NONE)
4233 } else if (!strcmp (mimetype, "audio/x-flac")) {
4234 id = AV_CODEC_ID_FLAC;
4236 } else if (!strcmp (mimetype, "audio/x-shorten")) {
4237 id = AV_CODEC_ID_SHORTEN;
4239 } else if (!strcmp (mimetype, "audio/x-alac")) {
4240 id = AV_CODEC_ID_ALAC;
4242 } else if (!strcmp (mimetype, "video/x-cinepak")) {
4243 id = AV_CODEC_ID_CINEPAK;
4245 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
4248 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
4249 switch (rmversion) {
4251 id = AV_CODEC_ID_RV10;
4254 id = AV_CODEC_ID_RV20;
4257 id = AV_CODEC_ID_RV30;
4260 id = AV_CODEC_ID_RV40;
4264 if (id != AV_CODEC_ID_NONE)
4266 } else if (!strcmp (mimetype, "audio/x-sipro")) {
4267 id = AV_CODEC_ID_SIPR;
4269 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
4272 if (gst_structure_get_int (structure, "raversion", &raversion)) {
4273 switch (raversion) {
4275 id = AV_CODEC_ID_RA_144;
4278 id = AV_CODEC_ID_RA_288;
4281 id = AV_CODEC_ID_COOK;
4285 if (id != AV_CODEC_ID_NONE)
4287 } else if (!strcmp (mimetype, "video/x-rle")) {
4288 const gchar *layout;
4290 if ((layout = gst_structure_get_string (structure, "layout"))) {
4291 if (!strcmp (layout, "microsoft")) {
4292 id = AV_CODEC_ID_MSRLE;
4296 } else if (!strcmp (mimetype, "video/x-xan")) {
4299 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
4300 switch (wcversion) {
4302 id = AV_CODEC_ID_XAN_WC3;
4306 id = AV_CODEC_ID_XAN_WC4;
4313 } else if (!strcmp (mimetype, "audio/AMR")) {
4315 id = AV_CODEC_ID_AMR_NB;
4316 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
4317 id = AV_CODEC_ID_AMR_WB;
4319 } else if (!strcmp (mimetype, "audio/qcelp")) {
4320 id = AV_CODEC_ID_QCELP;
4322 } else if (!strcmp (mimetype, "video/x-h264")) {
4323 id = AV_CODEC_ID_H264;
4325 } else if (!strcmp (mimetype, "video/x-h265")) {
4326 id = AV_CODEC_ID_HEVC;
4328 } else if (!strcmp (mimetype, "video/x-flash-video")) {
4329 gint flvversion = 0;
4331 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
4332 switch (flvversion) {
4334 id = AV_CODEC_ID_FLV1;
4342 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
4343 id = AV_CODEC_ID_NELLYMOSER;
4345 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
4349 if (strlen (mimetype) <= 30 &&
4350 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
4351 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4352 (codec = avcodec_find_encoder_by_name (ext))) {
4357 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
4361 if (strlen (mimetype) <= 30 &&
4362 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
4363 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4364 (codec = avcodec_find_encoder_by_name (ext))) {
4371 if (context != NULL) {
4372 if (video == TRUE) {
4373 context->codec_type = AVMEDIA_TYPE_VIDEO;
4374 } else if (audio == TRUE) {
4375 context->codec_type = AVMEDIA_TYPE_AUDIO;
4377 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
4379 context->codec_id = id;
4380 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
4383 if (id != AV_CODEC_ID_NONE) {
4384 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
4386 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);