2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * Copyright (c) 2002-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include <libavcodec/avcodec.h>
30 #include <libavutil/channel_layout.h>
33 #include "gstavcodecmap.h"
35 #include <gst/video/video.h>
36 #include <gst/audio/audio.h>
37 #include <gst/pbutils/codec-utils.h>
39 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
43 GstAudioChannelPosition gst;
44 } _ff_to_gst_layout[] = {
46 AV_CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
47 AV_CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
48 AV_CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
49 AV_CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
50 AV_CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
51 AV_CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
52 AV_CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
53 AV_CH_FRONT_RIGHT_OF_CENTER,
54 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
55 AV_CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
56 AV_CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
57 AV_CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
58 AV_CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
59 AV_CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
60 AV_CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
61 AV_CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
62 AV_CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
63 AV_CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
64 AV_CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}, {
65 AV_CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
66 AV_CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
70 gst_ffmpeg_channel_layout_to_gst (AVCodecContext * context,
71 GstAudioChannelPosition * pos)
73 guint nchannels = 0, channels = context->channels;
74 guint64 channel_layout = context->channel_layout;
75 gboolean none_layout = FALSE;
77 if (channel_layout == 0) {
83 for (i = 0; i < 64; i++) {
84 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
89 if (nchannels != channels) {
90 GST_ERROR ("Number of channels is different (%u != %u)", channels,
96 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
97 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
98 pos[j++] = _ff_to_gst_layout[i].gst;
100 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
105 if (j != nchannels) {
107 ("Unknown channels in channel layout - assuming NONE layout");
114 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
115 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
116 " - assuming NONE layout", channel_layout);
121 if (nchannels == 1) {
122 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
123 } else if (nchannels == 2) {
124 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
125 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
129 for (i = 0; i < nchannels; i++)
130 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
137 /* this macro makes a caps width fixed or unfixed width/height
138 * properties depending on whether we've got a context.
140 * See below for why we use this.
142 * We should actually do this stuff at the end, like in riff-media.c,
143 * but I'm too lazy today. Maybe later.
146 gst_ff_vid_caps_new (AVCodecContext * context, enum CodecID codec_id,
147 gboolean encode, const char *mimetype, const char *fieldname, ...)
149 GstStructure *structure = NULL;
150 GstCaps *caps = NULL;
154 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
156 /* fixed, non probing context */
157 if (context != NULL && context->width != -1) {
160 caps = gst_caps_new_simple (mimetype,
161 "width", G_TYPE_INT, context->width,
162 "height", G_TYPE_INT, context->height, NULL);
164 num = context->time_base.den / context->ticks_per_frame;
165 denom = context->time_base.num;
168 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
171 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
172 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
176 GST_LOG ("setting framerate: %d/%d", num, denom);
177 gst_caps_set_simple (caps,
178 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
180 /* so we are after restricted caps in this case */
184 caps = gst_caps_new_simple (mimetype,
185 "width", G_TYPE_INT, 352,
186 "height", G_TYPE_INT, 288,
187 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
188 gst_caps_append (caps, gst_caps_new_simple (mimetype,
189 "width", G_TYPE_INT, 176,
190 "height", G_TYPE_INT, 144,
191 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
196 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
197 * because we want automatic negotiation to go as close to 320x240 as
199 const static gint widths[] = { 352, 704, 176, 1408, 128 };
200 const static gint heights[] = { 288, 576, 144, 1152, 96 };
202 gint n_sizes = G_N_ELEMENTS (widths);
204 caps = gst_caps_new_empty ();
205 for (i = 0; i < n_sizes; i++) {
206 temp = gst_caps_new_simple (mimetype,
207 "width", G_TYPE_INT, widths[i],
208 "height", G_TYPE_INT, heights[i],
209 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
211 gst_caps_append (caps, temp);
215 case CODEC_ID_DVVIDEO:
222 gint framerate_n, framerate_d;
225 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 10, 11, 30000, 1001}, {
226 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 40, 33, 30000, 1001}, {
227 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 59, 54, 25, 1}, {
228 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 118, 81, 25, 1}, {
229 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 59, 54, 25, 1}, {
230 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 118, 81, 25, 1}
233 gint n_sizes = G_N_ELEMENTS (profiles);
235 caps = gst_caps_new_empty ();
236 for (i = 0; i < n_sizes; i++) {
237 temp = gst_caps_new_simple (mimetype,
238 "width", G_TYPE_INT, profiles[i].width,
239 "height", G_TYPE_INT, profiles[i].height,
240 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
241 profiles[i].framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION,
242 profiles[i].par_n, profiles[i].par_d, NULL);
244 gst_caps_append (caps, temp);
250 caps = gst_caps_new_simple (mimetype,
251 "width", G_TYPE_INT, 1920,
252 "height", G_TYPE_INT, 1080,
253 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
254 gst_caps_append (caps, gst_caps_new_simple (mimetype,
255 "width", G_TYPE_INT, 1280,
256 "height", G_TYPE_INT, 720,
257 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
265 /* no fixed caps or special restrictions applied;
266 * default unfixed setting */
268 GST_DEBUG ("Creating default caps");
269 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
272 for (i = 0; i < gst_caps_get_size (caps); i++) {
273 va_start (var_args, fieldname);
274 structure = gst_caps_get_structure (caps, i);
275 gst_structure_set_valist (structure, fieldname, var_args);
282 /* same for audio - now with channels/sample rate
285 gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
286 gboolean encode, const char *mimetype, const char *fieldname, ...)
288 GstCaps *caps = NULL;
289 GstStructure *structure = NULL;
293 /* fixed, non-probing context */
294 if (context != NULL && context->channels != -1) {
295 GstAudioChannelPosition pos[64];
297 caps = gst_caps_new_simple (mimetype,
298 "rate", G_TYPE_INT, context->sample_rate,
299 "channels", G_TYPE_INT, context->channels, NULL);
301 if (gst_ffmpeg_channel_layout_to_gst (context, pos)) {
304 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
306 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
311 gint maxchannels = 2;
312 const gint *rates = NULL;
315 /* so we must be after restricted caps in this case */
318 case CODEC_ID_AAC_LATM:
324 const static gint l_rates[] =
325 { 48000, 44100, 32000, 24000, 22050, 16000 };
326 n_rates = G_N_ELEMENTS (l_rates);
333 const static gint l_rates[] = { 48000, 44100, 32000 };
335 n_rates = G_N_ELEMENTS (l_rates);
339 case CODEC_ID_ADPCM_G722:
341 const static gint l_rates[] = { 16000 };
342 n_rates = G_N_ELEMENTS (l_rates);
347 case CODEC_ID_ADPCM_G726:
349 const static gint l_rates[] = { 8000 };
350 n_rates = G_N_ELEMENTS (l_rates);
355 case CODEC_ID_ADPCM_SWF:
357 const static gint l_rates[] = { 11025, 22050, 44100 };
358 n_rates = G_N_ELEMENTS (l_rates);
362 case CODEC_ID_ROQ_DPCM:
364 const static gint l_rates[] = { 22050 };
365 n_rates = G_N_ELEMENTS (l_rates);
369 case CODEC_ID_AMR_NB:
371 const static gint l_rates[] = { 8000 };
373 n_rates = G_N_ELEMENTS (l_rates);
377 case CODEC_ID_AMR_WB:
379 const static gint l_rates[] = { 16000 };
381 n_rates = G_N_ELEMENTS (l_rates);
389 /* TODO: handle context->channel_layouts here to set
390 * the list of channel layouts supported by the encoder.
391 * Unfortunately no encoder uses this yet....
393 /* regardless of encode/decode, open up channels if applicable */
394 /* Until decoders/encoders expose the maximum number of channels
395 * they support, we whitelist them here. */
397 case CODEC_ID_WMAPRO:
398 case CODEC_ID_TRUEHD:
405 if (maxchannels == 1)
406 caps = gst_caps_new_simple (mimetype,
407 "channels", G_TYPE_INT, maxchannels, NULL);
409 caps = gst_caps_new_simple (mimetype,
410 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
412 GValue list = { 0, };
413 GstStructure *structure;
415 g_value_init (&list, GST_TYPE_LIST);
416 for (i = 0; i < n_rates; i++) {
419 g_value_init (&v, G_TYPE_INT);
420 g_value_set_int (&v, rates[i]);
421 gst_value_list_append_value (&list, &v);
424 structure = gst_caps_get_structure (caps, 0);
425 gst_structure_set_value (structure, "rate", &list);
426 g_value_unset (&list);
428 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
430 caps = gst_caps_new_empty_simple (mimetype);
433 for (i = 0; i < gst_caps_get_size (caps); i++) {
434 va_start (var_args, fieldname);
435 structure = gst_caps_get_structure (caps, i);
436 gst_structure_set_valist (structure, fieldname, var_args);
443 /* Convert a FFMPEG codec ID and optional AVCodecContext
444 * to a GstCaps. If the context is ommitted, no fixed values
445 * for video/audio size will be included in the GstCaps
447 * CodecID is primarily meant for compressed data GstCaps!
449 * encode is a special parameter. gstffmpegdec will say
450 * FALSE, gstffmpegenc will say TRUE. The output caps
451 * depends on this, in such a way that it will be very
452 * specific, defined, fixed and correct caps for encoders,
453 * yet very wide, "forgiving" caps for decoders. Example
454 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
455 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
460 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
461 AVCodecContext * context, gboolean encode)
463 GstCaps *caps = NULL;
464 gboolean buildcaps = FALSE;
466 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
469 case CODEC_ID_MPEG1VIDEO:
471 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
472 "mpegversion", G_TYPE_INT, 1,
473 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
476 case CODEC_ID_MPEG2VIDEO:
479 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
480 "mpegversion", G_TYPE_INT, 2,
481 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
483 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
484 * the MPEG video stream headers, so may be omitted from caps. */
485 caps = gst_caps_new_simple ("video/mpeg",
486 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
487 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
491 case CODEC_ID_MPEG2VIDEO_XVMC:
492 /* this is a special ID - don't need it in GStreamer, I think */
497 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
498 "variant", G_TYPE_STRING, "itu",
499 "h263version", G_TYPE_STRING, "h263", NULL);
501 /* don't pass codec_id, we can decode other variants with the H263
502 * decoder that don't have specific size requirements
505 gst_ff_vid_caps_new (context, CODEC_ID_NONE, encode, "video/x-h263",
506 "variant", G_TYPE_STRING, "itu", NULL);
511 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
512 "variant", G_TYPE_STRING, "itu",
513 "h263version", G_TYPE_STRING, "h263p", NULL);
514 if (encode && context) {
516 gst_caps_set_simple (caps,
517 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
518 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
519 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
520 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
527 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-intel-h263",
528 "variant", G_TYPE_STRING, "intel", NULL);
533 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h261", NULL);
558 /* FIXME: context->sub_id must be filled in during decoding */
560 gst_ff_vid_caps_new (context, codec_id, encode,
561 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
562 "rmversion", G_TYPE_INT, version, NULL);
564 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
565 if (context->extradata_size >= 8) {
566 gst_caps_set_simple (caps,
567 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
576 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
577 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
582 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
583 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
589 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
590 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
592 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
593 * in the MPEG audio header, so may be omitted from caps. */
594 caps = gst_caps_new_simple ("audio/mpeg",
595 "mpegversion", G_TYPE_INT, 1,
596 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
600 case CODEC_ID_MUSEPACK7:
602 gst_ff_aud_caps_new (context, codec_id, encode,
603 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
607 case CODEC_ID_MUSEPACK8:
609 gst_ff_aud_caps_new (context, codec_id, encode,
610 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
617 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-ac3", NULL);
623 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-eac3", NULL);
626 case CODEC_ID_TRUEHD:
628 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-true-hd",
632 case CODEC_ID_ATRAC1:
634 gst_ff_aud_caps_new (context, codec_id, encode,
635 "audio/x-vnd.sony.atrac1", NULL);
638 case CODEC_ID_ATRAC3:
640 gst_ff_aud_caps_new (context, codec_id, encode,
641 "audio/x-vnd.sony.atrac3", NULL);
646 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dts", NULL);
651 gst_ff_aud_caps_new (context, codec_id, encode,
652 "audio/x-ffmpeg-parsed-ape", NULL);
654 gst_caps_set_simple (caps,
655 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
661 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mlp", NULL);
666 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-imc", NULL);
669 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
670 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
671 * sp5x is, but it's apparently something JPEG... We don't separate
672 * between those in GStreamer. Should we (at least between MJPEG,
673 * MJPEG-B and sp5x decoding...)? */
677 gst_ff_vid_caps_new (context, codec_id, encode, "image/jpeg", NULL);
682 gst_ff_vid_caps_new (context, codec_id, encode, "video/sp5x", NULL);
685 case CODEC_ID_MJPEGB:
687 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mjpeg-b",
692 if (encode && context != NULL) {
693 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
694 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
695 switch (context->codec_tag) {
696 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
698 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-divx",
699 "divxversion", G_TYPE_INT, 5, NULL);
701 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
704 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
705 "systemstream", G_TYPE_BOOLEAN, FALSE,
706 "mpegversion", G_TYPE_INT, 4, NULL);
710 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
711 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
712 "mpegversion", G_TYPE_INT, 4,
713 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
715 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
716 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
718 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
719 "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4, 5,
721 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
722 "video/x-xvid", NULL));
723 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
724 "video/x-3ivx", NULL));
729 case CODEC_ID_RAWVIDEO:
731 gst_ffmpeg_codectype_to_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
735 case CODEC_ID_MSMPEG4V1:
736 case CODEC_ID_MSMPEG4V2:
737 case CODEC_ID_MSMPEG4V3:
739 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
741 /* encode-FIXME: bitrate */
742 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-msmpeg",
743 "msmpegversion", G_TYPE_INT, version, NULL);
744 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
745 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
746 "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
754 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
756 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
757 "wmvversion", G_TYPE_INT, version, NULL);
763 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-flash-video",
764 "flvversion", G_TYPE_INT, 1, NULL);
768 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
769 "svqversion", G_TYPE_INT, 1, NULL);
773 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
774 "svqversion", G_TYPE_INT, 3, NULL);
777 case CODEC_ID_DVAUDIO:
779 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dv", NULL);
782 case CODEC_ID_DVVIDEO:
784 if (encode && context) {
787 switch (context->pix_fmt) {
788 case PIX_FMT_YUYV422:
791 case PIX_FMT_YUV420P:
794 case PIX_FMT_YUVA420P:
797 case PIX_FMT_YUV411P:
800 case PIX_FMT_YUV422P:
803 case PIX_FMT_YUV410P:
808 ("Couldnt' find format for pixfmt %d, defaulting to I420",
813 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
814 "systemstream", G_TYPE_BOOLEAN, FALSE,
815 "format", G_TYPE_STRING, format, NULL);
817 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
818 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
826 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
829 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
830 "wmaversion", G_TYPE_INT, version,
831 "block_align", G_TYPE_INT, context->block_align,
832 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
834 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
835 "wmaversion", G_TYPE_INT, version,
836 "block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT,
837 "bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
841 case CODEC_ID_WMAPRO:
843 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
844 "wmaversion", G_TYPE_INT, 3, NULL);
848 case CODEC_ID_WMAVOICE:
851 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wms", NULL);
858 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
860 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mace",
861 "maceversion", G_TYPE_INT, version, NULL);
865 case CODEC_ID_HUFFYUV:
867 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-huffyuv",
870 gst_caps_set_simple (caps,
871 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
877 gst_ff_vid_caps_new (context, codec_id, encode,
878 "video/x-compressed-yuv", NULL);
883 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h264",
884 "alignment", G_TYPE_STRING, "au", NULL);
887 case CODEC_ID_INDEO5:
888 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
889 "indeoversion", G_TYPE_INT, 5, NULL);
892 case CODEC_ID_INDEO4:
893 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
894 "indeoversion", G_TYPE_INT, 4, NULL);
897 case CODEC_ID_INDEO3:
898 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
899 "indeoversion", G_TYPE_INT, 3, NULL);
902 case CODEC_ID_INDEO2:
903 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
904 "indeoversion", G_TYPE_INT, 2, NULL);
907 case CODEC_ID_FLASHSV:
909 gst_ff_vid_caps_new (context, codec_id, encode,
910 "video/x-flash-screen", NULL);
915 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp3", NULL);
920 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp5", NULL);
925 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6", NULL);
930 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-flash",
936 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-alpha",
942 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp8", NULL);
945 case CODEC_ID_THEORA:
947 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-theora",
954 gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg", NULL);
958 GValue item = { 0, };
960 g_value_init (&arr, GST_TYPE_LIST);
961 g_value_init (&item, G_TYPE_INT);
962 g_value_set_int (&item, 2);
963 gst_value_list_append_value (&arr, &item);
964 g_value_set_int (&item, 4);
965 gst_value_list_append_value (&arr, &item);
966 g_value_unset (&item);
968 gst_caps_set_value (caps, "mpegversion", &arr);
969 g_value_unset (&arr);
971 g_value_init (&arr, GST_TYPE_LIST);
972 g_value_init (&item, G_TYPE_STRING);
973 g_value_set_string (&item, "raw");
974 gst_value_list_append_value (&arr, &item);
975 g_value_set_string (&item, "adts");
976 gst_value_list_append_value (&arr, &item);
977 g_value_set_string (&item, "adif");
978 gst_value_list_append_value (&arr, &item);
979 g_value_unset (&item);
981 gst_caps_set_value (caps, "stream-format", &arr);
982 g_value_unset (&arr);
984 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
985 "stream-format", G_TYPE_STRING, "raw",
986 "base-profile", G_TYPE_STRING, "lc", NULL);
988 if (context && context->extradata_size > 0)
989 gst_codec_utils_aac_caps_set_level_and_profile (caps,
990 context->extradata, context->extradata_size);
995 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
996 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
997 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1002 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1003 "asusversion", G_TYPE_INT, 1, NULL);
1006 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1007 "asusversion", G_TYPE_INT, 2, NULL);
1011 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ffv",
1012 "ffvversion", G_TYPE_INT, 1, NULL);
1017 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-4xm", NULL);
1020 case CODEC_ID_XAN_WC3:
1021 case CODEC_ID_XAN_WC4:
1022 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-xan",
1023 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1028 gst_ff_vid_caps_new (context, codec_id, encode,
1029 "video/x-cirrus-logic-accupak", NULL);
1032 case CODEC_ID_FRAPS:
1034 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-fraps",
1040 case CODEC_ID_INTERPLAY_VIDEO:
1045 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ati-vcr",
1046 "vcrversion", G_TYPE_INT, 1, NULL);
1051 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-apple-video",
1055 case CODEC_ID_CINEPAK:
1057 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-cinepak",
1061 /* WS_VQA belogns here (order) */
1063 case CODEC_ID_MSRLE:
1064 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1065 "layout", G_TYPE_STRING, "microsoft", NULL);
1067 gst_caps_set_simple (caps,
1068 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1070 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1074 case CODEC_ID_QTRLE:
1075 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1076 "layout", G_TYPE_STRING, "quicktime", NULL);
1078 gst_caps_set_simple (caps,
1079 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1081 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1085 case CODEC_ID_MSVIDEO1:
1087 gst_ff_vid_caps_new (context, codec_id, encode,
1088 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1092 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1093 "wmvversion", G_TYPE_INT, 3, NULL);
1096 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1097 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1101 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-qdm2", NULL);
1106 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mszh", NULL);
1111 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zlib", NULL);
1114 case CODEC_ID_TRUEMOTION1:
1116 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1117 "trueversion", G_TYPE_INT, 1, NULL);
1119 case CODEC_ID_TRUEMOTION2:
1121 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1122 "trueversion", G_TYPE_INT, 2, NULL);
1127 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ultimotion",
1133 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camtasia",
1136 gst_caps_set_simple (caps,
1137 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1139 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1145 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-kmvc", NULL);
1150 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-nuv", NULL);
1154 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/gif", NULL);
1158 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/png", NULL);
1162 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/ppm", NULL);
1166 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/pbm", NULL);
1171 gst_ff_vid_caps_new (context, codec_id, encode,
1172 "image/x-portable-anymap", NULL);
1177 gst_ff_vid_caps_new (context, codec_id, encode,
1178 "image/x-portable-graymap", NULL);
1183 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-pcx", NULL);
1188 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sgi", NULL);
1191 case CODEC_ID_TARGA:
1193 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-tga", NULL);
1198 gst_ff_vid_caps_new (context, codec_id, encode, "image/tiff", NULL);
1201 case CODEC_ID_SUNRAST:
1203 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sun-raster",
1209 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-smc", NULL);
1212 case CODEC_ID_QDRAW:
1214 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-qdrw", NULL);
1217 case CODEC_ID_DNXHD:
1219 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dnxhd",
1223 case CODEC_ID_PRORES:
1225 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-prores",
1229 case CODEC_ID_MIMIC:
1231 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mimic",
1237 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vmnc", NULL);
1240 case CODEC_ID_TRUESPEECH:
1242 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-truespeech",
1246 case CODEC_ID_QCELP:
1248 gst_ff_aud_caps_new (context, codec_id, encode, "audio/qcelp", NULL);
1253 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-amv", NULL);
1258 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-aasc", NULL);
1263 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-loco", NULL);
1268 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zmbv", NULL);
1271 case CODEC_ID_LAGARITH:
1273 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-lagarith",
1279 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camstudio",
1282 gst_caps_set_simple (caps,
1283 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1285 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1289 case CODEC_ID_WS_VQA:
1290 case CODEC_ID_IDCIN:
1293 case CODEC_ID_VMDVIDEO:
1294 case CODEC_ID_VMDAUDIO:
1298 case CODEC_ID_PGMYUV:
1299 case CODEC_ID_FFVHUFF:
1301 case CODEC_ID_MP3ADU:
1302 case CODEC_ID_MP3ON4:
1303 case CODEC_ID_WESTWOOD_SND1:
1304 case CODEC_ID_MMVIDEO:
1310 /* weird quasi-codecs for the demuxers only */
1311 case CODEC_ID_PCM_S16LE:
1312 case CODEC_ID_PCM_S16BE:
1313 case CODEC_ID_PCM_U16LE:
1314 case CODEC_ID_PCM_U16BE:
1315 case CODEC_ID_PCM_S8:
1316 case CODEC_ID_PCM_U8:
1318 GstAudioFormat format;
1321 case CODEC_ID_PCM_S16LE:
1322 format = GST_AUDIO_FORMAT_S16LE;
1324 case CODEC_ID_PCM_S16BE:
1325 format = GST_AUDIO_FORMAT_S16BE;
1327 case CODEC_ID_PCM_U16LE:
1328 format = GST_AUDIO_FORMAT_U16LE;
1330 case CODEC_ID_PCM_U16BE:
1331 format = GST_AUDIO_FORMAT_U16BE;
1333 case CODEC_ID_PCM_S8:
1334 format = GST_AUDIO_FORMAT_S8;
1336 case CODEC_ID_PCM_U8:
1337 format = GST_AUDIO_FORMAT_U8;
1340 g_assert (0); /* don't worry, we never get here */
1344 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-raw",
1345 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1346 "layout", G_TYPE_STRING, "interleaved", NULL);
1350 case CODEC_ID_PCM_MULAW:
1352 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mulaw",
1356 case CODEC_ID_PCM_ALAW:
1358 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-alaw", NULL);
1361 case CODEC_ID_ADPCM_G722:
1363 gst_ff_aud_caps_new (context, codec_id, encode, "audio/G722", NULL);
1365 gst_caps_set_simple (caps,
1366 "block_align", G_TYPE_INT, context->block_align,
1367 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1370 case CODEC_ID_ADPCM_G726:
1372 /* the G726 decoder can also handle G721 */
1373 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-adpcm",
1374 "layout", G_TYPE_STRING, "g726", NULL);
1376 gst_caps_set_simple (caps,
1377 "block_align", G_TYPE_INT, context->block_align,
1378 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1381 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1382 "layout", G_TYPE_STRING, "g721",
1383 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1387 case CODEC_ID_ADPCM_IMA_QT:
1388 case CODEC_ID_ADPCM_IMA_WAV:
1389 case CODEC_ID_ADPCM_IMA_DK3:
1390 case CODEC_ID_ADPCM_IMA_DK4:
1391 case CODEC_ID_ADPCM_IMA_WS:
1392 case CODEC_ID_ADPCM_IMA_SMJPEG:
1393 case CODEC_ID_ADPCM_IMA_AMV:
1394 case CODEC_ID_ADPCM_IMA_ISS:
1395 case CODEC_ID_ADPCM_IMA_EA_EACS:
1396 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1397 case CODEC_ID_ADPCM_MS:
1398 case CODEC_ID_ADPCM_4XM:
1399 case CODEC_ID_ADPCM_XA:
1400 case CODEC_ID_ADPCM_ADX:
1401 case CODEC_ID_ADPCM_EA:
1402 case CODEC_ID_ADPCM_CT:
1403 case CODEC_ID_ADPCM_SWF:
1404 case CODEC_ID_ADPCM_YAMAHA:
1405 case CODEC_ID_ADPCM_SBPRO_2:
1406 case CODEC_ID_ADPCM_SBPRO_3:
1407 case CODEC_ID_ADPCM_SBPRO_4:
1408 case CODEC_ID_ADPCM_EA_R1:
1409 case CODEC_ID_ADPCM_EA_R2:
1410 case CODEC_ID_ADPCM_EA_R3:
1411 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1412 case CODEC_ID_ADPCM_EA_XAS:
1413 case CODEC_ID_ADPCM_THP:
1415 const gchar *layout = NULL;
1418 case CODEC_ID_ADPCM_IMA_QT:
1419 layout = "quicktime";
1421 case CODEC_ID_ADPCM_IMA_WAV:
1424 case CODEC_ID_ADPCM_IMA_DK3:
1427 case CODEC_ID_ADPCM_IMA_DK4:
1430 case CODEC_ID_ADPCM_IMA_WS:
1431 layout = "westwood";
1433 case CODEC_ID_ADPCM_IMA_SMJPEG:
1436 case CODEC_ID_ADPCM_IMA_AMV:
1439 case CODEC_ID_ADPCM_IMA_ISS:
1442 case CODEC_ID_ADPCM_IMA_EA_EACS:
1445 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1448 case CODEC_ID_ADPCM_MS:
1449 layout = "microsoft";
1451 case CODEC_ID_ADPCM_4XM:
1454 case CODEC_ID_ADPCM_XA:
1457 case CODEC_ID_ADPCM_ADX:
1460 case CODEC_ID_ADPCM_EA:
1463 case CODEC_ID_ADPCM_CT:
1466 case CODEC_ID_ADPCM_SWF:
1469 case CODEC_ID_ADPCM_YAMAHA:
1472 case CODEC_ID_ADPCM_SBPRO_2:
1475 case CODEC_ID_ADPCM_SBPRO_3:
1478 case CODEC_ID_ADPCM_SBPRO_4:
1481 case CODEC_ID_ADPCM_EA_R1:
1484 case CODEC_ID_ADPCM_EA_R2:
1487 case CODEC_ID_ADPCM_EA_R3:
1490 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1491 layout = "ea-maxis-xa";
1493 case CODEC_ID_ADPCM_EA_XAS:
1496 case CODEC_ID_ADPCM_THP:
1500 g_assert (0); /* don't worry, we never get here */
1504 /* FIXME: someone please check whether we need additional properties
1505 * in this caps definition. */
1506 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-adpcm",
1507 "layout", G_TYPE_STRING, layout, NULL);
1509 gst_caps_set_simple (caps,
1510 "block_align", G_TYPE_INT, context->block_align,
1511 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1515 case CODEC_ID_AMR_NB:
1516 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/AMR", NULL);
1519 case CODEC_ID_AMR_WB:
1521 gst_ff_aud_caps_new (context, codec_id, encode, "audio/AMR-WB", NULL);
1526 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-gsm", NULL);
1529 case CODEC_ID_GSM_MS:
1531 gst_ff_aud_caps_new (context, codec_id, encode, "audio/ms-gsm", NULL);
1534 case CODEC_ID_NELLYMOSER:
1536 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-nellymoser",
1543 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-sipro",
1546 gst_caps_set_simple (caps,
1547 "leaf_size", G_TYPE_INT, context->block_align,
1548 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1553 case CODEC_ID_RA_144:
1554 case CODEC_ID_RA_288:
1560 case CODEC_ID_RA_144:
1563 case CODEC_ID_RA_288:
1573 /* FIXME: properties? */
1575 gst_ff_aud_caps_new (context, codec_id, encode,
1576 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1578 gst_caps_set_simple (caps,
1579 "leaf_size", G_TYPE_INT, context->block_align,
1580 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1585 case CODEC_ID_ROQ_DPCM:
1586 case CODEC_ID_INTERPLAY_DPCM:
1587 case CODEC_ID_XAN_DPCM:
1588 case CODEC_ID_SOL_DPCM:
1590 const gchar *layout = NULL;
1593 case CODEC_ID_ROQ_DPCM:
1596 case CODEC_ID_INTERPLAY_DPCM:
1597 layout = "interplay";
1599 case CODEC_ID_XAN_DPCM:
1602 case CODEC_ID_SOL_DPCM:
1606 g_assert (0); /* don't worry, we never get here */
1610 /* FIXME: someone please check whether we need additional properties
1611 * in this caps definition. */
1612 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dpcm",
1613 "layout", G_TYPE_STRING, layout, NULL);
1615 gst_caps_set_simple (caps,
1616 "block_align", G_TYPE_INT, context->block_align,
1617 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1621 case CODEC_ID_SHORTEN:
1622 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1627 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-alac", NULL);
1629 gst_caps_set_simple (caps,
1630 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1635 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1636 * encoder case, we want to add things like samplerate, channels... */
1638 caps = gst_caps_new_empty_simple ("audio/x-flac");
1642 case CODEC_ID_DVD_SUBTITLE:
1643 case CODEC_ID_DVB_SUBTITLE:
1647 caps = gst_caps_new_empty_simple ("image/bmp");
1651 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-tta", NULL);
1653 gst_caps_set_simple (caps,
1654 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1657 case CODEC_ID_TWINVQ:
1659 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-twin-vq",
1663 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1670 if ((codec = avcodec_find_decoder (codec_id)) ||
1671 (codec = avcodec_find_encoder (codec_id))) {
1674 GST_LOG ("Could not create stream format caps for %s", codec->name);
1676 switch (codec->type) {
1677 case AVMEDIA_TYPE_VIDEO:
1678 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1679 caps = gst_ff_vid_caps_new (context, codec_id, encode, mime, NULL);
1682 case AVMEDIA_TYPE_AUDIO:
1683 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1684 caps = gst_ff_aud_caps_new (context, codec_id, encode, mime, NULL);
1686 gst_caps_set_simple (caps,
1687 "block_align", G_TYPE_INT, context->block_align,
1688 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1699 /* set private data */
1700 if (context && context->extradata_size > 0) {
1701 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1703 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1704 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1705 gst_buffer_unref (data);
1708 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1711 GST_LOG ("No caps found for codec_id=%d", codec_id);
1717 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1718 * to a GstCaps. If the context is ommitted, no fixed values
1719 * for video/audio size will be included in the GstCaps
1721 * See below for usefullness
1725 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1726 enum CodecID codec_id)
1728 GstCaps *caps = NULL;
1729 GstVideoFormat format;
1731 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
1733 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1734 caps = gst_ff_vid_caps_new (context, codec_id, TRUE, "video/x-raw",
1735 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1739 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1741 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1748 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
1750 sample_fmt = av_get_packed_sample_fmt (sample_fmt);
1752 switch (sample_fmt) {
1753 case AV_SAMPLE_FMT_S16:
1754 return GST_AUDIO_FORMAT_S16;
1756 case AV_SAMPLE_FMT_S32:
1757 return GST_AUDIO_FORMAT_S32;
1759 case AV_SAMPLE_FMT_FLT:
1760 return GST_AUDIO_FORMAT_F32;
1762 case AV_SAMPLE_FMT_DBL:
1763 return GST_AUDIO_FORMAT_F64;
1767 return GST_AUDIO_FORMAT_UNKNOWN;
1772 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1773 * to a GstCaps. If the context is ommitted, no fixed values
1774 * for video/audio size will be included in the GstCaps
1776 * See below for usefullness
1780 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
1781 AVCodecContext * context, enum CodecID codec_id)
1783 GstCaps *caps = NULL;
1784 GstAudioFormat format;
1786 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
1788 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1789 caps = gst_ff_aud_caps_new (context, codec_id, TRUE, "audio/x-raw",
1790 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1791 "layout", G_TYPE_STRING, "interleaved", NULL);
1792 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1794 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1801 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
1802 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1804 GstCaps *caps = NULL;
1806 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1807 context, codec_id, encode, codec);
1809 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
1810 codec->sample_fmts, codec->supported_samplerates);
1813 /* Specific codec context */
1814 caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec_id);
1815 } else if (codec && codec->sample_fmts) {
1819 caps = gst_caps_new_empty ();
1820 for (i = 0; codec->sample_fmts[i] != -1; i++) {
1822 gst_ffmpeg_smpfmt_to_caps (codec->sample_fmts[i], context, codec_id);
1824 gst_caps_append (caps, temp);
1828 enum AVSampleFormat i;
1829 AVCodecContext ctx = { 0, };
1832 caps = gst_caps_new_empty ();
1833 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
1834 temp = gst_ffmpeg_smpfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1836 gst_caps_append (caps, temp);
1844 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
1845 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1849 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1850 context, codec_id, encode, codec);
1853 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
1857 AVCodecContext ctx = { 0, };
1859 caps = gst_caps_new_empty ();
1860 for (i = 0; i < PIX_FMT_NB; i++) {
1863 temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1865 gst_caps_append (caps, temp);
1872 /* Convert a FFMPEG codec Type and optional AVCodecContext
1873 * to a GstCaps. If the context is ommitted, no fixed values
1874 * for video/audio size will be included in the GstCaps
1876 * AVMediaType is primarily meant for uncompressed data GstCaps!
1880 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
1881 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
1885 switch (codec_type) {
1886 case AVMEDIA_TYPE_VIDEO:
1888 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1890 case AVMEDIA_TYPE_AUDIO:
1892 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
1902 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
1903 * and other audio properties in a AVCodecContext.
1905 * For usefullness, see below
1909 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
1910 AVCodecContext * context, gboolean raw)
1912 GstStructure *structure;
1914 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
1916 g_return_if_fail (gst_caps_get_size (caps) == 1);
1918 structure = gst_caps_get_structure (caps, 0);
1920 gst_structure_get_int (structure, "channels", &context->channels);
1921 gst_structure_get_int (structure, "rate", &context->sample_rate);
1922 gst_structure_get_int (structure, "block_align", &context->block_align);
1923 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
1928 if (gst_structure_has_name (structure, "audio/x-raw")) {
1929 if ((fmt = gst_structure_get_string (structure, "format"))) {
1930 format = gst_audio_format_from_string (fmt);
1935 case GST_AUDIO_FORMAT_F32:
1936 context->sample_fmt = AV_SAMPLE_FMT_FLT;
1938 case GST_AUDIO_FORMAT_F64:
1939 context->sample_fmt = AV_SAMPLE_FMT_DBL;
1941 case GST_AUDIO_FORMAT_S32:
1942 context->sample_fmt = AV_SAMPLE_FMT_S32;
1944 case GST_AUDIO_FORMAT_S16:
1945 context->sample_fmt = AV_SAMPLE_FMT_S16;
1952 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
1953 * and other video properties in a AVCodecContext.
1955 * For usefullness, see below
1959 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
1960 AVCodecContext * context, gboolean raw)
1962 GstStructure *structure;
1964 const GValue *par = NULL;
1966 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
1968 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
1969 g_return_if_fail (gst_caps_get_size (caps) == 1);
1970 structure = gst_caps_get_structure (caps, 0);
1972 gst_structure_get_int (structure, "width", &context->width);
1973 gst_structure_get_int (structure, "height", &context->height);
1974 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
1976 fps = gst_structure_get_value (structure, "framerate");
1977 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
1979 /* somehow these seem mixed up.. */
1980 context->time_base.den = gst_value_get_fraction_numerator (fps);
1981 context->time_base.num = gst_value_get_fraction_denominator (fps);
1982 context->ticks_per_frame = 1;
1984 GST_DEBUG ("setting framerate %d/%d = %lf",
1985 context->time_base.den, context->time_base.num,
1986 1. * context->time_base.den / context->time_base.num);
1989 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
1990 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
1992 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
1993 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
1995 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
1996 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
1997 1. * context->sample_aspect_ratio.den /
1998 context->sample_aspect_ratio.num);
2004 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2006 if (gst_structure_has_name (structure, "video/x-raw")) {
2007 if ((fmt = gst_structure_get_string (structure, "format"))) {
2008 format = gst_video_format_from_string (fmt);
2013 case GST_VIDEO_FORMAT_YUY2:
2014 context->pix_fmt = PIX_FMT_YUYV422;
2016 case GST_VIDEO_FORMAT_I420:
2017 context->pix_fmt = PIX_FMT_YUV420P;
2019 case GST_VIDEO_FORMAT_A420:
2020 context->pix_fmt = PIX_FMT_YUVA420P;
2022 case GST_VIDEO_FORMAT_Y41B:
2023 context->pix_fmt = PIX_FMT_YUV411P;
2025 case GST_VIDEO_FORMAT_Y42B:
2026 context->pix_fmt = PIX_FMT_YUV422P;
2028 case GST_VIDEO_FORMAT_YUV9:
2029 context->pix_fmt = PIX_FMT_YUV410P;
2031 case GST_VIDEO_FORMAT_Y444:
2032 context->pix_fmt = PIX_FMT_YUV444P;
2034 case GST_VIDEO_FORMAT_GRAY8:
2035 context->pix_fmt = PIX_FMT_GRAY8;
2037 case GST_VIDEO_FORMAT_xRGB:
2038 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2039 context->pix_fmt = PIX_FMT_RGB32;
2042 case GST_VIDEO_FORMAT_BGRx:
2043 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2044 context->pix_fmt = PIX_FMT_RGB32;
2047 case GST_VIDEO_FORMAT_RGB:
2048 context->pix_fmt = PIX_FMT_RGB24;
2050 case GST_VIDEO_FORMAT_BGR:
2051 context->pix_fmt = PIX_FMT_BGR24;
2053 case GST_VIDEO_FORMAT_RGB16:
2054 context->pix_fmt = PIX_FMT_RGB565;
2056 case GST_VIDEO_FORMAT_RGB15:
2057 context->pix_fmt = PIX_FMT_RGB555;
2059 case GST_VIDEO_FORMAT_RGB8P:
2060 context->pix_fmt = PIX_FMT_PAL8;
2069 GstVideoFormat format;
2070 enum PixelFormat pixfmt;
2073 /* FIXME : FILLME */
2074 static const PixToFmt pixtofmttable[] = {
2075 /* GST_VIDEO_FORMAT_I420, */
2076 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2077 /* Note : this should use a different chroma placement */
2078 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2080 /* GST_VIDEO_FORMAT_YV12, */
2081 /* GST_VIDEO_FORMAT_YUY2, */
2082 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2083 /* GST_VIDEO_FORMAT_UYVY, */
2084 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2085 /* GST_VIDEO_FORMAT_AYUV, */
2086 /* GST_VIDEO_FORMAT_RGBx, */
2087 /* GST_VIDEO_FORMAT_BGRx, */
2088 /* GST_VIDEO_FORMAT_xRGB, */
2089 /* GST_VIDEO_FORMAT_xBGR, */
2090 /* GST_VIDEO_FORMAT_RGBA, */
2091 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2092 /* GST_VIDEO_FORMAT_BGRA, */
2093 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2094 /* GST_VIDEO_FORMAT_ARGB, */
2095 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2096 /* GST_VIDEO_FORMAT_ABGR, */
2097 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2098 /* GST_VIDEO_FORMAT_RGB, */
2099 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2100 /* GST_VIDEO_FORMAT_BGR, */
2101 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2102 /* GST_VIDEO_FORMAT_Y41B, */
2103 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2104 /* GST_VIDEO_FORMAT_Y42B, */
2105 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2106 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2107 /* GST_VIDEO_FORMAT_YVYU, */
2108 /* GST_VIDEO_FORMAT_Y444, */
2109 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2110 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2111 /* GST_VIDEO_FORMAT_v210, */
2112 /* GST_VIDEO_FORMAT_v216, */
2113 /* GST_VIDEO_FORMAT_NV12, */
2114 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2115 /* GST_VIDEO_FORMAT_NV21, */
2116 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2117 /* GST_VIDEO_FORMAT_GRAY8, */
2118 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2119 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2120 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2121 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2122 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2123 /* GST_VIDEO_FORMAT_v308, */
2124 /* GST_VIDEO_FORMAT_Y800, */
2125 /* GST_VIDEO_FORMAT_Y16, */
2126 /* GST_VIDEO_FORMAT_RGB16, */
2127 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2128 /* GST_VIDEO_FORMAT_BGR16, */
2129 /* GST_VIDEO_FORMAT_RGB15, */
2130 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2131 /* GST_VIDEO_FORMAT_BGR15, */
2132 /* GST_VIDEO_FORMAT_UYVP, */
2133 /* GST_VIDEO_FORMAT_A420, */
2134 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2135 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2136 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2137 /* GST_VIDEO_FORMAT_YUV9, */
2138 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2139 /* GST_VIDEO_FORMAT_YVU9, */
2140 /* GST_VIDEO_FORMAT_IYU1, */
2141 /* GST_VIDEO_FORMAT_ARGB64, */
2142 /* GST_VIDEO_FORMAT_AYUV64, */
2143 /* GST_VIDEO_FORMAT_r210, */
2144 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2145 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2146 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2147 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2148 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2149 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2150 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2151 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2152 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2156 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2160 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2161 if (pixtofmttable[i].pixfmt == pixfmt)
2162 return pixtofmttable[i].format;
2164 GST_WARNING ("Unknown pixel format %d", pixfmt);
2165 return GST_VIDEO_FORMAT_UNKNOWN;
2169 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2173 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2174 if (pixtofmttable[i].format == format)
2175 return pixtofmttable[i].pixfmt;
2176 return PIX_FMT_NONE;
2180 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2184 context->width = GST_VIDEO_INFO_WIDTH (info);
2185 context->height = GST_VIDEO_INFO_HEIGHT (info);
2186 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2187 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2188 context->bits_per_coded_sample = bpp;
2190 context->ticks_per_frame = 1;
2191 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2192 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2194 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2195 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2198 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2202 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2204 context->channels = info->channels;
2205 context->sample_rate = info->rate;
2207 switch (info->finfo->format) {
2208 case GST_AUDIO_FORMAT_F32:
2209 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2211 case GST_AUDIO_FORMAT_F64:
2212 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2214 case GST_AUDIO_FORMAT_S32:
2215 context->sample_fmt = AV_SAMPLE_FMT_S32;
2217 case GST_AUDIO_FORMAT_S16:
2218 context->sample_fmt = AV_SAMPLE_FMT_S16;
2225 /* Convert a GstCaps and a FFMPEG codec Type to a
2226 * AVCodecContext. If the context is ommitted, no fixed values
2227 * for video/audio size will be included in the context
2229 * AVMediaType is primarily meant for uncompressed data GstCaps!
2233 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2234 const GstCaps * caps, AVCodecContext * context)
2236 if (context == NULL)
2240 case AVMEDIA_TYPE_VIDEO:
2241 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2244 case AVMEDIA_TYPE_AUDIO:
2245 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2256 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2260 guint8 *end = src + size;
2263 while (srcp < end) {
2264 if (count == 2 && *srcp <= 0x03) {
2265 GST_DEBUG ("added escape code");
2274 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2277 *destsize = dstp - dst;
2280 /* copy the config, escaping NAL units as we iterate them, if something fails we
2281 * copy everything and hope for the best. */
2283 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2288 guint nalsize, esize;
2298 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2300 GST_DEBUG ("num SPS %d", cnt);
2302 memcpy (dstp, srcp, 6);
2306 for (i = 0; i < cnt; i++) {
2307 GST_DEBUG ("copy SPS %d", i);
2308 nalsize = (srcp[0] << 8) | srcp[1];
2309 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2310 dstp[0] = esize >> 8;
2311 dstp[1] = esize & 0xff;
2313 srcp += nalsize + 2;
2316 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2318 GST_DEBUG ("num PPS %d", cnt);
2320 for (i = 0; i < cnt; i++) {
2321 GST_DEBUG ("copy PPS %d", i);
2322 nalsize = (srcp[0] << 8) | srcp[1];
2323 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2324 dstp[0] = esize >> 8;
2325 dstp[1] = esize & 0xff;
2327 srcp += nalsize + 2;
2329 *destsize = dstp - dst;
2335 GST_DEBUG ("something unexpected, doing full copy");
2336 memcpy (dst, src, size);
2344 * caps_with_codecid () transforms a GstCaps for a known codec
2345 * ID into a filled-in context.
2346 * codec_data from caps will override possible extradata already in the context
2350 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2351 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2354 const GValue *value;
2357 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2358 codec_id, codec_type, caps, context);
2360 if (!context || !gst_caps_get_size (caps))
2363 str = gst_caps_get_structure (caps, 0);
2365 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2366 if ((value = gst_structure_get_value (str, "codec_data"))) {
2369 buf = gst_value_get_buffer (value);
2370 gst_buffer_map (buf, &map, GST_MAP_READ);
2372 /* free the old one if it is there */
2373 if (context->extradata)
2374 av_free (context->extradata);
2377 if (codec_id == CODEC_ID_H264) {
2380 GST_DEBUG ("copy, escaping codec_data %d", size);
2381 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2382 * reason for this but let's just escape it for now. Start by allocating
2383 * enough space, x2 is more than enough.
2385 * FIXME, we disabled escaping because some file already contain escaped
2386 * codec_data and then we escape twice and fail. It's better to leave it
2387 * as is, as that is what most players do. */
2388 context->extradata =
2389 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2390 FF_INPUT_BUFFER_PADDING_SIZE));
2391 copy_config (context->extradata, data, size, &extrasize);
2392 GST_DEBUG ("escaped size: %d", extrasize);
2393 context->extradata_size = extrasize;
2397 /* allocate with enough padding */
2398 GST_DEBUG ("copy codec_data");
2399 context->extradata =
2400 av_mallocz (GST_ROUND_UP_16 (map.size +
2401 FF_INPUT_BUFFER_PADDING_SIZE));
2402 memcpy (context->extradata, map.data, map.size);
2403 context->extradata_size = map.size;
2406 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2407 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2408 context->extradata[0] = (guint8) map.size;
2411 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2413 gst_buffer_unmap (buf, &map);
2414 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2415 codec_id != CODEC_ID_FLAC) {
2416 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2417 * extradata anyway which makes then segfault. */
2418 context->extradata =
2419 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2420 context->extradata_size = 0;
2421 GST_DEBUG ("no codec data");
2425 case CODEC_ID_MPEG4:
2427 const gchar *mime = gst_structure_get_name (str);
2429 if (!strcmp (mime, "video/x-divx"))
2430 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2431 else if (!strcmp (mime, "video/x-xvid"))
2432 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2433 else if (!strcmp (mime, "video/x-3ivx"))
2434 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2435 else if (!strcmp (mime, "video/mpeg"))
2436 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2441 /* FIXME: this is a workaround for older gst-plugins releases
2442 * (<= 0.8.9). This should be removed at some point, because
2443 * it causes wrong decoded frame order. */
2444 if (!context->extradata) {
2445 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2448 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2449 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2450 gst_structure_get_int (str, "low_delay", &low_delay) ||
2451 gst_structure_get_int (str, "unknown_svq3_flag",
2452 &unknown_svq3_flag)) {
2453 context->extradata = (guint8 *) av_mallocz (0x64);
2454 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2458 flags |= unknown_svq3_flag;
2460 flags |= halfpel_flag;
2462 flags |= thirdpel_flag;
2465 flags = GUINT16_FROM_LE (flags);
2467 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2468 context->extradata_size = 0x64;
2473 case CODEC_ID_MSRLE:
2474 case CODEC_ID_QTRLE:
2481 if (gst_structure_get_int (str, "depth", &depth)) {
2482 context->bits_per_coded_sample = depth;
2484 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2497 if (gst_structure_get_int (str, "format", &format))
2498 context->sub_id = format;
2503 case CODEC_ID_RA_288:
2504 case CODEC_ID_RA_144:
2510 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2511 context->block_align = leaf_size;
2512 if (gst_structure_get_int (str, "bitrate", &bitrate))
2513 context->bit_rate = bitrate;
2516 gst_structure_get_int (str, "samplesize",
2517 &context->bits_per_coded_sample);
2520 case CODEC_ID_DVVIDEO:
2522 const gchar *format;
2524 if ((format = gst_structure_get_string (str, "format"))) {
2526 if (g_str_equal (format, "YUY2"))
2527 context->pix_fmt = PIX_FMT_YUYV422;
2528 else if (g_str_equal (format, "I420"))
2529 context->pix_fmt = PIX_FMT_YUV420P;
2530 else if (g_str_equal (format, "A420"))
2531 context->pix_fmt = PIX_FMT_YUVA420P;
2532 else if (g_str_equal (format, "Y41B"))
2533 context->pix_fmt = PIX_FMT_YUV411P;
2534 else if (g_str_equal (format, "Y42B"))
2535 context->pix_fmt = PIX_FMT_YUV422P;
2536 else if (g_str_equal (format, "YUV9"))
2537 context->pix_fmt = PIX_FMT_YUV410P;
2539 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2543 GST_WARNING ("No specified format");
2546 case CODEC_ID_H263P:
2550 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2551 context->flags |= CODEC_FLAG_4MV;
2553 context->flags &= ~CODEC_FLAG_4MV;
2554 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2555 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2556 context->flags |= CODEC_FLAG_AC_PRED;
2558 context->flags &= ~CODEC_FLAG_AC_PRED;
2559 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2560 context->flags |= CODEC_FLAG_LOOP_FILTER;
2562 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2565 case CODEC_ID_ADPCM_G726:
2567 const gchar *layout;
2569 if ((layout = gst_structure_get_string (str, "layout"))) {
2570 if (!strcmp (layout, "g721")) {
2571 context->sample_rate = 8000;
2572 context->channels = 1;
2573 context->bit_rate = 32000;
2582 if (!gst_caps_is_fixed (caps))
2585 /* common properties (width, height, fps) */
2586 switch (codec_type) {
2587 case AVMEDIA_TYPE_VIDEO:
2588 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2590 case AVMEDIA_TYPE_AUDIO:
2591 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2597 /* fixup of default settings */
2599 case CODEC_ID_QCELP:
2600 /* QCELP is always mono, no matter what the caps say */
2601 context->channels = 1;
2608 /* _formatid_to_caps () is meant for muxers/demuxers, it
2609 * transforms a name (ffmpeg way of ID'ing these, why don't
2610 * they have unique numerical IDs?) to the corresponding
2611 * caps belonging to that mux-format
2613 * Note: we don't need any additional info because the caps
2614 * isn't supposed to contain any useful info besides the
2619 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2621 GstCaps *caps = NULL;
2623 if (!strcmp (format_name, "mpeg")) {
2624 caps = gst_caps_new_simple ("video/mpeg",
2625 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2626 } else if (!strcmp (format_name, "mpegts")) {
2627 caps = gst_caps_new_simple ("video/mpegts",
2628 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2629 } else if (!strcmp (format_name, "rm")) {
2630 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2631 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2632 } else if (!strcmp (format_name, "asf")) {
2633 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2634 } else if (!strcmp (format_name, "avi")) {
2635 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2636 } else if (!strcmp (format_name, "wav")) {
2637 caps = gst_caps_new_empty_simple ("audio/x-wav");
2638 } else if (!strcmp (format_name, "ape")) {
2639 caps = gst_caps_new_empty_simple ("application/x-ape");
2640 } else if (!strcmp (format_name, "swf")) {
2641 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2642 } else if (!strcmp (format_name, "au")) {
2643 caps = gst_caps_new_empty_simple ("audio/x-au");
2644 } else if (!strcmp (format_name, "dv")) {
2645 caps = gst_caps_new_simple ("video/x-dv",
2646 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2647 } else if (!strcmp (format_name, "4xm")) {
2648 caps = gst_caps_new_empty_simple ("video/x-4xm");
2649 } else if (!strcmp (format_name, "matroska")) {
2650 caps = gst_caps_new_empty_simple ("video/x-matroska");
2651 } else if (!strcmp (format_name, "mp3")) {
2652 caps = gst_caps_new_empty_simple ("application/x-id3");
2653 } else if (!strcmp (format_name, "flic")) {
2654 caps = gst_caps_new_empty_simple ("video/x-fli");
2655 } else if (!strcmp (format_name, "flv")) {
2656 caps = gst_caps_new_empty_simple ("video/x-flv");
2657 } else if (!strcmp (format_name, "tta")) {
2658 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
2659 } else if (!strcmp (format_name, "aiff")) {
2660 caps = gst_caps_new_empty_simple ("audio/x-aiff");
2661 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2663 gst_caps_from_string
2664 ("application/x-3gp; video/quicktime; audio/x-m4a");
2665 } else if (!strcmp (format_name, "mov")) {
2666 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2667 } else if (!strcmp (format_name, "mp4")) {
2668 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2669 } else if (!strcmp (format_name, "3gp")) {
2670 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2671 } else if (!strcmp (format_name, "3g2")) {
2672 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2673 } else if (!strcmp (format_name, "psp")) {
2674 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2675 } else if (!strcmp (format_name, "ipod")) {
2676 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2677 } else if (!strcmp (format_name, "aac")) {
2678 caps = gst_caps_new_simple ("audio/mpeg",
2679 "mpegversion", G_TYPE_INT, 4, NULL);
2680 } else if (!strcmp (format_name, "gif")) {
2681 caps = gst_caps_from_string ("image/gif");
2682 } else if (!strcmp (format_name, "ogg")) {
2683 caps = gst_caps_from_string ("application/ogg");
2684 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
2685 caps = gst_caps_from_string ("application/mxf");
2686 } else if (!strcmp (format_name, "gxf")) {
2687 caps = gst_caps_from_string ("application/gxf");
2688 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
2689 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
2690 "y4mversion", G_TYPE_INT, 2, NULL);
2691 } else if (!strcmp (format_name, "mpc")) {
2692 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
2693 } else if (!strcmp (format_name, "vqf")) {
2694 caps = gst_caps_from_string ("audio/x-vqf");
2695 } else if (!strcmp (format_name, "nsv")) {
2696 caps = gst_caps_from_string ("video/x-nsv");
2697 } else if (!strcmp (format_name, "amr")) {
2698 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
2699 } else if (!strcmp (format_name, "webm")) {
2700 caps = gst_caps_from_string ("video/webm");
2701 } else if (!strcmp (format_name, "voc")) {
2702 caps = gst_caps_from_string ("audio/x-voc");
2706 GST_LOG ("Could not create stream format caps for %s", format_name);
2707 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
2708 caps = gst_caps_new_empty_simple (name);
2716 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
2717 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
2718 AVOutputFormat * plugin)
2720 static enum CodecID tmp_vlist[] = {
2724 static enum CodecID tmp_alist[] = {
2729 GST_LOG ("format_name : %s", format_name);
2731 if (!strcmp (format_name, "mp4")) {
2732 static enum CodecID mp4_video_list[] = {
2733 CODEC_ID_MPEG4, CODEC_ID_H264,
2737 static enum CodecID mp4_audio_list[] = {
2738 CODEC_ID_AAC, CODEC_ID_MP3,
2742 *video_codec_list = mp4_video_list;
2743 *audio_codec_list = mp4_audio_list;
2744 } else if (!strcmp (format_name, "mpeg")) {
2745 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
2746 CODEC_ID_MPEG2VIDEO,
2750 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
2756 *video_codec_list = mpeg_video_list;
2757 *audio_codec_list = mpeg_audio_list;
2758 } else if (!strcmp (format_name, "dvd")) {
2759 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
2762 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
2769 *video_codec_list = mpeg_video_list;
2770 *audio_codec_list = mpeg_audio_list;
2771 } else if (!strcmp (format_name, "mpegts")) {
2772 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
2773 CODEC_ID_MPEG2VIDEO,
2777 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
2785 *video_codec_list = mpegts_video_list;
2786 *audio_codec_list = mpegts_audio_list;
2787 } else if (!strcmp (format_name, "vob")) {
2788 static enum CodecID vob_video_list[] =
2789 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
2790 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
2791 CODEC_ID_DTS, CODEC_ID_NONE
2794 *video_codec_list = vob_video_list;
2795 *audio_codec_list = vob_audio_list;
2796 } else if (!strcmp (format_name, "flv")) {
2797 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
2798 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
2800 *video_codec_list = flv_video_list;
2801 *audio_codec_list = flv_audio_list;
2802 } else if (!strcmp (format_name, "asf")) {
2803 static enum CodecID asf_video_list[] =
2804 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
2805 static enum CodecID asf_audio_list[] =
2806 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
2808 *video_codec_list = asf_video_list;
2809 *audio_codec_list = asf_audio_list;
2810 } else if (!strcmp (format_name, "dv")) {
2811 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
2812 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
2814 *video_codec_list = dv_video_list;
2815 *audio_codec_list = dv_audio_list;
2816 } else if (!strcmp (format_name, "mov")) {
2817 static enum CodecID mov_video_list[] = {
2818 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
2819 CODEC_ID_H263, CODEC_ID_H263P,
2820 CODEC_ID_H264, CODEC_ID_DVVIDEO,
2824 static enum CodecID mov_audio_list[] = {
2825 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
2826 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
2827 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2828 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
2829 CODEC_ID_MP3, CODEC_ID_NONE
2832 *video_codec_list = mov_video_list;
2833 *audio_codec_list = mov_audio_list;
2834 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
2835 static enum CodecID tgp_video_list[] = {
2836 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
2839 static enum CodecID tgp_audio_list[] = {
2840 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2845 *video_codec_list = tgp_video_list;
2846 *audio_codec_list = tgp_audio_list;
2847 } else if (!strcmp (format_name, "mmf")) {
2848 static enum CodecID mmf_audio_list[] = {
2849 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
2851 *video_codec_list = NULL;
2852 *audio_codec_list = mmf_audio_list;
2853 } else if (!strcmp (format_name, "amr")) {
2854 static enum CodecID amr_audio_list[] = {
2855 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2858 *video_codec_list = NULL;
2859 *audio_codec_list = amr_audio_list;
2860 } else if (!strcmp (format_name, "gif")) {
2861 static enum CodecID gif_image_list[] = {
2862 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
2864 *video_codec_list = gif_image_list;
2865 *audio_codec_list = NULL;
2866 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
2867 (plugin->video_codec != CODEC_ID_NONE)) {
2868 tmp_vlist[0] = plugin->video_codec;
2869 tmp_alist[0] = plugin->audio_codec;
2871 *video_codec_list = tmp_vlist;
2872 *audio_codec_list = tmp_alist;
2874 GST_LOG ("Format %s not found", format_name);
2881 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
2882 * are omitted, that can be queried by the user itself,
2883 * we're not eating the GstCaps or anything
2884 * A pointer to an allocated context is also needed for
2885 * optional extra info
2889 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
2891 enum CodecID id = CODEC_ID_NONE;
2892 const gchar *mimetype;
2893 const GstStructure *structure;
2894 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
2896 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
2897 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
2898 structure = gst_caps_get_structure (caps, 0);
2900 mimetype = gst_structure_get_name (structure);
2902 if (!strcmp (mimetype, "video/x-raw")) {
2903 id = CODEC_ID_RAWVIDEO;
2905 } else if (!strcmp (mimetype, "audio/x-raw")) {
2908 if (gst_audio_info_from_caps (&info, caps)) {
2909 switch (GST_AUDIO_INFO_FORMAT (&info)) {
2910 case GST_AUDIO_FORMAT_S8:
2911 id = CODEC_ID_PCM_S8;
2913 case GST_AUDIO_FORMAT_U8:
2914 id = CODEC_ID_PCM_U8;
2916 case GST_AUDIO_FORMAT_S16LE:
2917 id = CODEC_ID_PCM_S16LE;
2919 case GST_AUDIO_FORMAT_S16BE:
2920 id = CODEC_ID_PCM_S16BE;
2922 case GST_AUDIO_FORMAT_U16LE:
2923 id = CODEC_ID_PCM_U16LE;
2925 case GST_AUDIO_FORMAT_U16BE:
2926 id = CODEC_ID_PCM_U16BE;
2931 if (id != CODEC_ID_NONE)
2934 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
2935 id = CODEC_ID_PCM_MULAW;
2937 } else if (!strcmp (mimetype, "audio/x-alaw")) {
2938 id = CODEC_ID_PCM_ALAW;
2940 } else if (!strcmp (mimetype, "video/x-dv")) {
2943 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
2945 id = CODEC_ID_DVVIDEO;
2948 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
2949 id = CODEC_ID_DVAUDIO;
2951 } else if (!strcmp (mimetype, "video/x-h263")) {
2952 const gchar *h263version =
2953 gst_structure_get_string (structure, "h263version");
2954 if (h263version && !strcmp (h263version, "h263p"))
2955 id = CODEC_ID_H263P;
2959 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
2960 id = CODEC_ID_H263I;
2962 } else if (!strcmp (mimetype, "video/x-h261")) {
2965 } else if (!strcmp (mimetype, "video/mpeg")) {
2969 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
2970 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
2972 switch (mpegversion) {
2974 id = CODEC_ID_MPEG1VIDEO;
2977 id = CODEC_ID_MPEG2VIDEO;
2980 id = CODEC_ID_MPEG4;
2984 if (id != CODEC_ID_NONE)
2986 } else if (!strcmp (mimetype, "image/jpeg")) {
2987 id = CODEC_ID_MJPEG; /* A... B... */
2989 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
2990 id = CODEC_ID_MJPEGB;
2992 } else if (!strcmp (mimetype, "video/x-wmv")) {
2993 gint wmvversion = 0;
2995 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
2996 switch (wmvversion) {
3005 const gchar *format;
3007 /* WMV3 unless the fourcc exists and says otherwise */
3010 if ((format = gst_structure_get_string (structure, "format")) &&
3011 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3018 if (id != CODEC_ID_NONE)
3020 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3021 id = CODEC_ID_VORBIS;
3023 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3026 } else if (!strcmp (mimetype, "audio/mpeg")) {
3028 gint mpegversion = 0;
3030 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3031 switch (mpegversion) {
3032 case 2: /* ffmpeg uses faad for both... */
3037 if (gst_structure_get_int (structure, "layer", &layer)) {
3052 if (id != CODEC_ID_NONE)
3054 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3055 gint streamversion = -1;
3057 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3058 if (streamversion == 7)
3059 id = CODEC_ID_MUSEPACK7;
3061 id = CODEC_ID_MUSEPACK7;
3063 } else if (!strcmp (mimetype, "audio/x-wma")) {
3064 gint wmaversion = 0;
3066 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3067 switch (wmaversion) {
3069 id = CODEC_ID_WMAV1;
3072 id = CODEC_ID_WMAV2;
3075 id = CODEC_ID_WMAPRO;
3079 if (id != CODEC_ID_NONE)
3081 } else if (!strcmp (mimetype, "audio/x-wms")) {
3082 id = CODEC_ID_WMAVOICE;
3084 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3087 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3090 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3091 !strcmp (mimetype, "audio/atrac3")) {
3092 id = CODEC_ID_ATRAC3;
3094 } else if (!strcmp (mimetype, "audio/x-dts")) {
3097 } else if (!strcmp (mimetype, "application/x-ape")) {
3100 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3101 gint msmpegversion = 0;
3103 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3104 switch (msmpegversion) {
3106 id = CODEC_ID_MSMPEG4V1;
3109 id = CODEC_ID_MSMPEG4V2;
3112 id = CODEC_ID_MSMPEG4V3;
3116 if (id != CODEC_ID_NONE)
3118 } else if (!strcmp (mimetype, "video/x-svq")) {
3119 gint svqversion = 0;
3121 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3122 switch (svqversion) {
3131 if (id != CODEC_ID_NONE)
3133 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3134 id = CODEC_ID_HUFFYUV;
3136 } else if (!strcmp (mimetype, "audio/x-mace")) {
3137 gint maceversion = 0;
3139 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3140 switch (maceversion) {
3142 id = CODEC_ID_MACE3;
3145 id = CODEC_ID_MACE6;
3149 if (id != CODEC_ID_NONE)
3151 } else if (!strcmp (mimetype, "video/x-theora")) {
3152 id = CODEC_ID_THEORA;
3154 } else if (!strcmp (mimetype, "video/x-vp3")) {
3157 } else if (!strcmp (mimetype, "video/x-vp5")) {
3160 } else if (!strcmp (mimetype, "video/x-vp6")) {
3163 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3166 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3169 } else if (!strcmp (mimetype, "video/x-vp8")) {
3172 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3173 id = CODEC_ID_FLASHSV;
3175 } else if (!strcmp (mimetype, "video/x-indeo")) {
3176 gint indeoversion = 0;
3178 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3179 switch (indeoversion) {
3181 id = CODEC_ID_INDEO5;
3184 id = CODEC_ID_INDEO4;
3187 id = CODEC_ID_INDEO3;
3190 id = CODEC_ID_INDEO2;
3193 if (id != CODEC_ID_NONE)
3196 } else if (!strcmp (mimetype, "video/x-divx")) {
3197 gint divxversion = 0;
3199 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3200 switch (divxversion) {
3202 id = CODEC_ID_MSMPEG4V3;
3206 id = CODEC_ID_MPEG4;
3210 if (id != CODEC_ID_NONE)
3212 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3213 id = CODEC_ID_MPEG4;
3215 } else if (!strcmp (mimetype, "video/x-xvid")) {
3216 id = CODEC_ID_MPEG4;
3218 } else if (!strcmp (mimetype, "video/x-ffv")) {
3219 gint ffvversion = 0;
3221 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3226 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3227 const gchar *layout;
3229 layout = gst_structure_get_string (structure, "layout");
3230 if (layout == NULL) {
3232 } else if (!strcmp (layout, "quicktime")) {
3233 id = CODEC_ID_ADPCM_IMA_QT;
3234 } else if (!strcmp (layout, "microsoft")) {
3235 id = CODEC_ID_ADPCM_MS;
3236 } else if (!strcmp (layout, "dvi")) {
3237 id = CODEC_ID_ADPCM_IMA_WAV;
3238 } else if (!strcmp (layout, "4xm")) {
3239 id = CODEC_ID_ADPCM_4XM;
3240 } else if (!strcmp (layout, "smjpeg")) {
3241 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3242 } else if (!strcmp (layout, "dk3")) {
3243 id = CODEC_ID_ADPCM_IMA_DK3;
3244 } else if (!strcmp (layout, "dk4")) {
3245 id = CODEC_ID_ADPCM_IMA_DK4;
3246 } else if (!strcmp (layout, "westwood")) {
3247 id = CODEC_ID_ADPCM_IMA_WS;
3248 } else if (!strcmp (layout, "iss")) {
3249 id = CODEC_ID_ADPCM_IMA_ISS;
3250 } else if (!strcmp (layout, "xa")) {
3251 id = CODEC_ID_ADPCM_XA;
3252 } else if (!strcmp (layout, "adx")) {
3253 id = CODEC_ID_ADPCM_ADX;
3254 } else if (!strcmp (layout, "ea")) {
3255 id = CODEC_ID_ADPCM_EA;
3256 } else if (!strcmp (layout, "g726")) {
3257 id = CODEC_ID_ADPCM_G726;
3258 } else if (!strcmp (layout, "g721")) {
3259 id = CODEC_ID_ADPCM_G726;
3260 } else if (!strcmp (layout, "ct")) {
3261 id = CODEC_ID_ADPCM_CT;
3262 } else if (!strcmp (layout, "swf")) {
3263 id = CODEC_ID_ADPCM_SWF;
3264 } else if (!strcmp (layout, "yamaha")) {
3265 id = CODEC_ID_ADPCM_YAMAHA;
3266 } else if (!strcmp (layout, "sbpro2")) {
3267 id = CODEC_ID_ADPCM_SBPRO_2;
3268 } else if (!strcmp (layout, "sbpro3")) {
3269 id = CODEC_ID_ADPCM_SBPRO_3;
3270 } else if (!strcmp (layout, "sbpro4")) {
3271 id = CODEC_ID_ADPCM_SBPRO_4;
3273 if (id != CODEC_ID_NONE)
3275 } else if (!strcmp (mimetype, "video/x-4xm")) {
3278 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3279 const gchar *layout;
3281 layout = gst_structure_get_string (structure, "layout");
3284 } else if (!strcmp (layout, "roq")) {
3285 id = CODEC_ID_ROQ_DPCM;
3286 } else if (!strcmp (layout, "interplay")) {
3287 id = CODEC_ID_INTERPLAY_DPCM;
3288 } else if (!strcmp (layout, "xan")) {
3289 id = CODEC_ID_XAN_DPCM;
3290 } else if (!strcmp (layout, "sol")) {
3291 id = CODEC_ID_SOL_DPCM;
3293 if (id != CODEC_ID_NONE)
3295 } else if (!strcmp (mimetype, "audio/x-flac")) {
3298 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3299 id = CODEC_ID_SHORTEN;
3301 } else if (!strcmp (mimetype, "audio/x-alac")) {
3304 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3305 id = CODEC_ID_CINEPAK;
3307 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3310 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3311 switch (rmversion) {
3326 if (id != CODEC_ID_NONE)
3328 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3331 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3334 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3335 switch (raversion) {
3337 id = CODEC_ID_RA_144;
3340 id = CODEC_ID_RA_288;
3347 if (id != CODEC_ID_NONE)
3349 } else if (!strcmp (mimetype, "video/x-rle")) {
3350 const gchar *layout;
3352 if ((layout = gst_structure_get_string (structure, "layout"))) {
3353 if (!strcmp (layout, "microsoft")) {
3354 id = CODEC_ID_MSRLE;
3358 } else if (!strcmp (mimetype, "video/x-xan")) {
3361 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3362 switch (wcversion) {
3364 id = CODEC_ID_XAN_WC3;
3368 id = CODEC_ID_XAN_WC4;
3375 } else if (!strcmp (mimetype, "audio/AMR")) {
3377 id = CODEC_ID_AMR_NB;
3378 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3379 id = CODEC_ID_AMR_WB;
3381 } else if (!strcmp (mimetype, "audio/qcelp")) {
3382 id = CODEC_ID_QCELP;
3384 } else if (!strcmp (mimetype, "video/x-h264")) {
3387 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3388 gint flvversion = 0;
3390 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3391 switch (flvversion) {
3401 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3402 id = CODEC_ID_NELLYMOSER;
3404 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3408 if (strlen (mimetype) <= 30 &&
3409 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3410 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3411 (codec = avcodec_find_encoder_by_name (ext))) {
3416 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3420 if (strlen (mimetype) <= 30 &&
3421 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3422 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3423 (codec = avcodec_find_encoder_by_name (ext))) {
3430 if (context != NULL) {
3431 if (video == TRUE) {
3432 context->codec_type = AVMEDIA_TYPE_VIDEO;
3433 } else if (audio == TRUE) {
3434 context->codec_type = AVMEDIA_TYPE_AUDIO;
3436 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3438 context->codec_id = id;
3439 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3442 if (id != CODEC_ID_NONE) {
3443 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3445 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);