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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
29 #include <libavcodec/avcodec.h>
32 #include "gstavcodecmap.h"
34 #include <gst/video/video.h>
35 #include <gst/audio/audio.h>
36 #include <gst/pbutils/codec-utils.h>
39 * Read a palette from a caps.
43 gst_ffmpeg_get_palette (const GstCaps * caps, AVCodecContext * context)
45 GstStructure *str = gst_caps_get_structure (caps, 0);
46 const GValue *palette_v;
49 /* do we have a palette? */
50 if ((palette_v = gst_structure_get_value (str, "palette_data")) && context) {
51 palette = gst_value_get_buffer (palette_v);
52 GST_DEBUG ("got palette data %p", palette);
53 if (gst_buffer_get_size (palette) >= AVPALETTE_SIZE) {
55 av_free (context->palctrl);
56 context->palctrl = av_malloc (sizeof (AVPaletteControl));
57 context->palctrl->palette_changed = 1;
58 gst_buffer_extract (palette, 0, context->palctrl->palette,
60 GST_DEBUG ("extracted palette data");
66 gst_ffmpeg_set_palette (GstCaps * caps, AVCodecContext * context)
68 if (context->palctrl) {
69 GstBuffer *palette = gst_buffer_new_and_alloc (AVPALETTE_SIZE);
71 gst_buffer_fill (palette, 0, context->palctrl->palette, AVPALETTE_SIZE);
72 gst_caps_set_simple (caps, "palette_data", GST_TYPE_BUFFER, palette, NULL);
76 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
80 GstAudioChannelPosition gst;
81 } _ff_to_gst_layout[] = {
83 CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
84 CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
85 CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
86 CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
87 CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
88 CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
89 CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
90 CH_FRONT_RIGHT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
91 CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
92 CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
93 CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
94 CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
95 CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
96 CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
97 CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
98 CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
99 CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
100 CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}, {
101 CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
102 CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
106 gst_ffmpeg_channel_layout_to_gst (AVCodecContext * context,
107 GstAudioChannelPosition * pos)
109 guint nchannels = 0, channels = context->channels;
110 guint64 channel_layout = context->channel_layout;
111 gboolean none_layout = FALSE;
113 if (channel_layout == 0) {
114 nchannels = channels;
119 for (i = 0; i < 64; i++) {
120 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
125 if (nchannels != channels) {
126 GST_ERROR ("Number of channels is different (%u != %u)", channels,
128 nchannels = channels;
132 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
133 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
134 pos[j++] = _ff_to_gst_layout[i].gst;
136 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
141 if (j != nchannels) {
143 ("Unknown channels in channel layout - assuming NONE layout");
150 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
151 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
152 " - assuming NONE layout", channel_layout);
157 if (nchannels == 1) {
158 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
159 } else if (nchannels == 2) {
160 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
161 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
165 for (i = 0; i < nchannels; i++)
166 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
173 /* this macro makes a caps width fixed or unfixed width/height
174 * properties depending on whether we've got a context.
176 * See below for why we use this.
178 * We should actually do this stuff at the end, like in riff-media.c,
179 * but I'm too lazy today. Maybe later.
182 gst_ff_vid_caps_new (AVCodecContext * context, enum CodecID codec_id,
183 gboolean encode, const char *mimetype, const char *fieldname, ...)
185 GstStructure *structure = NULL;
186 GstCaps *caps = NULL;
190 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
192 /* fixed, non probing context */
193 if (context != NULL && context->width != -1) {
196 caps = gst_caps_new_simple (mimetype,
197 "width", G_TYPE_INT, context->width,
198 "height", G_TYPE_INT, context->height, NULL);
200 num = context->time_base.den / context->ticks_per_frame;
201 denom = context->time_base.num;
204 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
207 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
208 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
212 GST_LOG ("setting framerate: %d/%d", num, denom);
213 gst_caps_set_simple (caps,
214 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
216 /* so we are after restricted caps in this case */
220 caps = gst_caps_new_simple (mimetype,
221 "width", G_TYPE_INT, 352,
222 "height", G_TYPE_INT, 288,
223 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
224 gst_caps_append (caps, gst_caps_new_simple (mimetype,
225 "width", G_TYPE_INT, 176,
226 "height", G_TYPE_INT, 144,
227 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
232 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
233 * because we want automatic negotiation to go as close to 320x240 as
235 const static gint widths[] = { 352, 704, 176, 1408, 128 };
236 const static gint heights[] = { 288, 576, 144, 1152, 96 };
238 gint n_sizes = G_N_ELEMENTS (widths);
240 caps = gst_caps_new_empty ();
241 for (i = 0; i < n_sizes; i++) {
242 temp = gst_caps_new_simple (mimetype,
243 "width", G_TYPE_INT, widths[i],
244 "height", G_TYPE_INT, heights[i],
245 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
247 gst_caps_append (caps, temp);
251 case CODEC_ID_DVVIDEO:
258 gint framerate_n, framerate_d;
261 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 10, 11, 30000, 1001}, {
262 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 480, 40, 33, 30000, 1001}, {
263 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 59, 54, 25, 1}, {
264 GST_MAKE_FOURCC ('I', '4', '2', '0'), 720, 576, 118, 81, 25, 1}, {
265 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 59, 54, 25, 1}, {
266 GST_MAKE_FOURCC ('Y', '4', '1', 'B'), 720, 576, 118, 81, 25, 1}
269 gint n_sizes = G_N_ELEMENTS (profiles);
271 caps = gst_caps_new_empty ();
272 for (i = 0; i < n_sizes; i++) {
273 temp = gst_caps_new_simple (mimetype,
274 "width", G_TYPE_INT, profiles[i].width,
275 "height", G_TYPE_INT, profiles[i].height,
276 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
277 profiles[i].framerate_d, "pixel-aspect-ratio", GST_TYPE_FRACTION,
278 profiles[i].par_n, profiles[i].par_d, NULL);
280 gst_caps_append (caps, temp);
286 caps = gst_caps_new_simple (mimetype,
287 "width", G_TYPE_INT, 1920,
288 "height", G_TYPE_INT, 1080,
289 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
290 gst_caps_append (caps, gst_caps_new_simple (mimetype,
291 "width", G_TYPE_INT, 1280,
292 "height", G_TYPE_INT, 720,
293 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
301 /* no fixed caps or special restrictions applied;
302 * default unfixed setting */
304 GST_DEBUG ("Creating default caps");
305 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
308 for (i = 0; i < gst_caps_get_size (caps); i++) {
309 va_start (var_args, fieldname);
310 structure = gst_caps_get_structure (caps, i);
311 gst_structure_set_valist (structure, fieldname, var_args);
318 /* same for audio - now with channels/sample rate
321 gst_ff_aud_caps_new (AVCodecContext * context, enum CodecID codec_id,
322 gboolean encode, const char *mimetype, const char *fieldname, ...)
324 GstCaps *caps = NULL;
325 GstStructure *structure = NULL;
329 /* fixed, non-probing context */
330 if (context != NULL && context->channels != -1) {
331 GstAudioChannelPosition pos[64];
333 caps = gst_caps_new_simple (mimetype,
334 "rate", G_TYPE_INT, context->sample_rate,
335 "channels", G_TYPE_INT, context->channels, NULL);
337 if (gst_ffmpeg_channel_layout_to_gst (context, pos)) {
340 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
342 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
347 gint maxchannels = 2;
348 const gint *rates = NULL;
351 /* so we must be after restricted caps in this case */
354 case CODEC_ID_AAC_LATM:
360 const static gint l_rates[] =
361 { 48000, 44100, 32000, 24000, 22050, 16000 };
362 n_rates = G_N_ELEMENTS (l_rates);
369 const static gint l_rates[] = { 48000, 44100, 32000 };
371 n_rates = G_N_ELEMENTS (l_rates);
375 case CODEC_ID_ADPCM_G722:
377 const static gint l_rates[] = { 16000 };
378 n_rates = G_N_ELEMENTS (l_rates);
383 case CODEC_ID_ADPCM_G726:
385 const static gint l_rates[] = { 8000 };
386 n_rates = G_N_ELEMENTS (l_rates);
391 case CODEC_ID_ADPCM_SWF:
393 const static gint l_rates[] = { 11025, 22050, 44100 };
394 n_rates = G_N_ELEMENTS (l_rates);
398 case CODEC_ID_ROQ_DPCM:
400 const static gint l_rates[] = { 22050 };
401 n_rates = G_N_ELEMENTS (l_rates);
405 case CODEC_ID_AMR_NB:
407 const static gint l_rates[] = { 8000 };
409 n_rates = G_N_ELEMENTS (l_rates);
413 case CODEC_ID_AMR_WB:
415 const static gint l_rates[] = { 16000 };
417 n_rates = G_N_ELEMENTS (l_rates);
425 /* TODO: handle context->channel_layouts here to set
426 * the list of channel layouts supported by the encoder.
427 * Unfortunately no encoder uses this yet....
429 /* regardless of encode/decode, open up channels if applicable */
430 /* Until decoders/encoders expose the maximum number of channels
431 * they support, we whitelist them here. */
433 case CODEC_ID_WMAPRO:
434 case CODEC_ID_TRUEHD:
441 if (maxchannels == 1)
442 caps = gst_caps_new_simple (mimetype,
443 "channels", G_TYPE_INT, maxchannels, NULL);
445 caps = gst_caps_new_simple (mimetype,
446 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
448 GValue list = { 0, };
449 GstStructure *structure;
451 g_value_init (&list, GST_TYPE_LIST);
452 for (i = 0; i < n_rates; i++) {
455 g_value_init (&v, G_TYPE_INT);
456 g_value_set_int (&v, rates[i]);
457 gst_value_list_append_value (&list, &v);
460 structure = gst_caps_get_structure (caps, 0);
461 gst_structure_set_value (structure, "rate", &list);
462 g_value_unset (&list);
464 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
466 caps = gst_caps_new_empty_simple (mimetype);
469 for (i = 0; i < gst_caps_get_size (caps); i++) {
470 va_start (var_args, fieldname);
471 structure = gst_caps_get_structure (caps, i);
472 gst_structure_set_valist (structure, fieldname, var_args);
479 /* Convert a FFMPEG codec ID and optional AVCodecContext
480 * to a GstCaps. If the context is ommitted, no fixed values
481 * for video/audio size will be included in the GstCaps
483 * CodecID is primarily meant for compressed data GstCaps!
485 * encode is a special parameter. gstffmpegdec will say
486 * FALSE, gstffmpegenc will say TRUE. The output caps
487 * depends on this, in such a way that it will be very
488 * specific, defined, fixed and correct caps for encoders,
489 * yet very wide, "forgiving" caps for decoders. Example
490 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
491 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
496 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
497 AVCodecContext * context, gboolean encode)
499 GstCaps *caps = NULL;
500 gboolean buildcaps = FALSE;
502 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
505 case CODEC_ID_MPEG1VIDEO:
507 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
508 "mpegversion", G_TYPE_INT, 1,
509 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
512 case CODEC_ID_MPEG2VIDEO:
515 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
516 "mpegversion", G_TYPE_INT, 2,
517 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
519 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
520 * the MPEG video stream headers, so may be omitted from caps. */
521 caps = gst_caps_new_simple ("video/mpeg",
522 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
523 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
527 case CODEC_ID_MPEG2VIDEO_XVMC:
528 /* this is a special ID - don't need it in GStreamer, I think */
533 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
534 "variant", G_TYPE_STRING, "itu",
535 "h263version", G_TYPE_STRING, "h263", NULL);
537 /* don't pass codec_id, we can decode other variants with the H263
538 * decoder that don't have specific size requirements
541 gst_ff_vid_caps_new (context, CODEC_ID_NONE, encode, "video/x-h263",
542 "variant", G_TYPE_STRING, "itu", NULL);
547 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h263",
548 "variant", G_TYPE_STRING, "itu",
549 "h263version", G_TYPE_STRING, "h263p", NULL);
550 if (encode && context) {
552 gst_caps_set_simple (caps,
553 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
554 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
555 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
556 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
563 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-intel-h263",
564 "variant", G_TYPE_STRING, "intel", NULL);
569 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h261", NULL);
594 /* FIXME: context->sub_id must be filled in during decoding */
596 gst_ff_vid_caps_new (context, codec_id, encode,
597 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
598 "rmversion", G_TYPE_INT, version, NULL);
600 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
601 if (context->extradata_size >= 8) {
602 gst_caps_set_simple (caps,
603 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
612 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
613 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
618 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
619 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
625 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
626 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
628 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
629 * in the MPEG audio header, so may be omitted from caps. */
630 caps = gst_caps_new_simple ("audio/mpeg",
631 "mpegversion", G_TYPE_INT, 1,
632 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
636 case CODEC_ID_MUSEPACK7:
638 gst_ff_aud_caps_new (context, codec_id, encode,
639 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
643 case CODEC_ID_MUSEPACK8:
645 gst_ff_aud_caps_new (context, codec_id, encode,
646 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
653 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-ac3", NULL);
659 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-eac3", NULL);
662 case CODEC_ID_TRUEHD:
664 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-true-hd",
668 case CODEC_ID_ATRAC1:
670 gst_ff_aud_caps_new (context, codec_id, encode,
671 "audio/x-vnd.sony.atrac1", NULL);
674 case CODEC_ID_ATRAC3:
676 gst_ff_aud_caps_new (context, codec_id, encode,
677 "audio/x-vnd.sony.atrac3", NULL);
682 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dts", NULL);
687 gst_ff_aud_caps_new (context, codec_id, encode,
688 "audio/x-ffmpeg-parsed-ape", NULL);
690 gst_caps_set_simple (caps,
691 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
697 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mlp", NULL);
702 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-imc", NULL);
705 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
706 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
707 * sp5x is, but it's apparently something JPEG... We don't separate
708 * between those in GStreamer. Should we (at least between MJPEG,
709 * MJPEG-B and sp5x decoding...)? */
713 gst_ff_vid_caps_new (context, codec_id, encode, "image/jpeg", NULL);
718 gst_ff_vid_caps_new (context, codec_id, encode, "video/sp5x", NULL);
721 case CODEC_ID_MJPEGB:
723 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mjpeg-b",
728 if (encode && context != NULL) {
729 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
730 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
731 switch (context->codec_tag) {
732 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
734 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-divx",
735 "divxversion", G_TYPE_INT, 5, NULL);
737 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
740 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
741 "systemstream", G_TYPE_BOOLEAN, FALSE,
742 "mpegversion", G_TYPE_INT, 4, NULL);
746 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
747 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/mpeg",
748 "mpegversion", G_TYPE_INT, 4,
749 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
751 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
752 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
754 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
755 "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4, 5,
757 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
758 "video/x-xvid", NULL));
759 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
760 "video/x-3ivx", NULL));
765 case CODEC_ID_RAWVIDEO:
767 gst_ffmpeg_codectype_to_caps (AVMEDIA_TYPE_VIDEO, context, codec_id,
771 case CODEC_ID_MSMPEG4V1:
772 case CODEC_ID_MSMPEG4V2:
773 case CODEC_ID_MSMPEG4V3:
775 gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
777 /* encode-FIXME: bitrate */
778 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-msmpeg",
779 "msmpegversion", G_TYPE_INT, version, NULL);
780 if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
781 gst_caps_append (caps, gst_ff_vid_caps_new (context, codec_id, encode,
782 "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
790 gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
792 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
793 "wmvversion", G_TYPE_INT, version, NULL);
799 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-flash-video",
800 "flvversion", G_TYPE_INT, 1, NULL);
804 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
805 "svqversion", G_TYPE_INT, 1, NULL);
809 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-svq",
810 "svqversion", G_TYPE_INT, 3, NULL);
813 case CODEC_ID_DVAUDIO:
815 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dv", NULL);
818 case CODEC_ID_DVVIDEO:
820 if (encode && context) {
823 switch (context->pix_fmt) {
824 case PIX_FMT_YUYV422:
827 case PIX_FMT_YUV420P:
830 case PIX_FMT_YUVA420P:
833 case PIX_FMT_YUV411P:
836 case PIX_FMT_YUV422P:
839 case PIX_FMT_YUV410P:
844 ("Couldnt' find format for pixfmt %d, defaulting to I420",
849 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
850 "systemstream", G_TYPE_BOOLEAN, FALSE,
851 "format", G_TYPE_STRING, format, NULL);
853 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dv",
854 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
862 gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
865 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
866 "wmaversion", G_TYPE_INT, version,
867 "block_align", G_TYPE_INT, context->block_align,
868 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
870 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
871 "wmaversion", G_TYPE_INT, version,
872 "block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT,
873 "bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
877 case CODEC_ID_WMAPRO:
879 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wma",
880 "wmaversion", G_TYPE_INT, 3, NULL);
884 case CODEC_ID_WMAVOICE:
887 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-wms", NULL);
894 gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
896 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mace",
897 "maceversion", G_TYPE_INT, version, NULL);
901 case CODEC_ID_HUFFYUV:
903 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-huffyuv",
906 gst_caps_set_simple (caps,
907 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
913 gst_ff_vid_caps_new (context, codec_id, encode,
914 "video/x-compressed-yuv", NULL);
919 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-h264",
920 "alignment", G_TYPE_STRING, "au", NULL);
923 case CODEC_ID_INDEO5:
924 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
925 "indeoversion", G_TYPE_INT, 5, NULL);
928 case CODEC_ID_INDEO4:
929 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
930 "indeoversion", G_TYPE_INT, 4, NULL);
933 case CODEC_ID_INDEO3:
934 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
935 "indeoversion", G_TYPE_INT, 3, NULL);
938 case CODEC_ID_INDEO2:
939 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-indeo",
940 "indeoversion", G_TYPE_INT, 2, NULL);
943 case CODEC_ID_FLASHSV:
945 gst_ff_vid_caps_new (context, codec_id, encode,
946 "video/x-flash-screen", NULL);
951 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp3", NULL);
956 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp5", NULL);
961 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6", NULL);
966 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-flash",
972 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp6-alpha",
978 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vp8", NULL);
981 case CODEC_ID_THEORA:
983 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-theora",
990 gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg", NULL);
994 GValue item = { 0, };
996 g_value_init (&arr, GST_TYPE_LIST);
997 g_value_init (&item, G_TYPE_INT);
998 g_value_set_int (&item, 2);
999 gst_value_list_append_value (&arr, &item);
1000 g_value_set_int (&item, 4);
1001 gst_value_list_append_value (&arr, &item);
1002 g_value_unset (&item);
1004 gst_caps_set_value (caps, "mpegversion", &arr);
1005 g_value_unset (&arr);
1007 g_value_init (&arr, GST_TYPE_LIST);
1008 g_value_init (&item, G_TYPE_STRING);
1009 g_value_set_string (&item, "raw");
1010 gst_value_list_append_value (&arr, &item);
1011 g_value_set_string (&item, "adts");
1012 gst_value_list_append_value (&arr, &item);
1013 g_value_set_string (&item, "adif");
1014 gst_value_list_append_value (&arr, &item);
1015 g_value_unset (&item);
1017 gst_caps_set_value (caps, "stream-format", &arr);
1018 g_value_unset (&arr);
1020 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1021 "stream-format", G_TYPE_STRING, "raw",
1022 "base-profile", G_TYPE_STRING, "lc", NULL);
1024 if (context && context->extradata_size > 0)
1025 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1026 context->extradata, context->extradata_size);
1031 case CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1032 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/mpeg",
1033 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1038 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1039 "asusversion", G_TYPE_INT, 1, NULL);
1042 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-asus",
1043 "asusversion", G_TYPE_INT, 2, NULL);
1047 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ffv",
1048 "ffvversion", G_TYPE_INT, 1, NULL);
1053 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-4xm", NULL);
1056 case CODEC_ID_XAN_WC3:
1057 case CODEC_ID_XAN_WC4:
1058 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-xan",
1059 "wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
1064 gst_ff_vid_caps_new (context, codec_id, encode,
1065 "video/x-cirrus-logic-accupak", NULL);
1068 case CODEC_ID_FRAPS:
1070 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-fraps",
1076 case CODEC_ID_INTERPLAY_VIDEO:
1081 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ati-vcr",
1082 "vcrversion", G_TYPE_INT, 1, NULL);
1087 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-apple-video",
1091 case CODEC_ID_CINEPAK:
1093 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-cinepak",
1097 /* WS_VQA belogns here (order) */
1099 case CODEC_ID_MSRLE:
1100 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1101 "layout", G_TYPE_STRING, "microsoft", NULL);
1103 gst_caps_set_simple (caps,
1104 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1106 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1110 case CODEC_ID_QTRLE:
1111 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-rle",
1112 "layout", G_TYPE_STRING, "quicktime", NULL);
1114 gst_caps_set_simple (caps,
1115 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1117 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1121 case CODEC_ID_MSVIDEO1:
1123 gst_ff_vid_caps_new (context, codec_id, encode,
1124 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1128 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1129 "wmvversion", G_TYPE_INT, 3, NULL);
1132 caps = gst_ff_vid_caps_new (context, codec_id, encode, "video/x-wmv",
1133 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1137 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-qdm2", NULL);
1142 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mszh", NULL);
1147 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zlib", NULL);
1150 case CODEC_ID_TRUEMOTION1:
1152 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1153 "trueversion", G_TYPE_INT, 1, NULL);
1155 case CODEC_ID_TRUEMOTION2:
1157 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-truemotion",
1158 "trueversion", G_TYPE_INT, 2, NULL);
1163 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-ultimotion",
1169 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camtasia",
1172 gst_caps_set_simple (caps,
1173 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1175 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1181 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-kmvc", NULL);
1186 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-nuv", NULL);
1190 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/gif", NULL);
1194 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/png", NULL);
1198 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/ppm", NULL);
1202 caps = gst_ff_vid_caps_new (context, codec_id, encode, "image/pbm", NULL);
1207 gst_ff_vid_caps_new (context, codec_id, encode,
1208 "image/x-portable-anymap", NULL);
1213 gst_ff_vid_caps_new (context, codec_id, encode,
1214 "image/x-portable-graymap", NULL);
1219 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-pcx", NULL);
1224 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sgi", NULL);
1227 case CODEC_ID_TARGA:
1229 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-tga", NULL);
1234 gst_ff_vid_caps_new (context, codec_id, encode, "image/tiff", NULL);
1237 case CODEC_ID_SUNRAST:
1239 gst_ff_vid_caps_new (context, codec_id, encode, "image/x-sun-raster",
1245 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-smc", NULL);
1248 case CODEC_ID_QDRAW:
1250 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-qdrw", NULL);
1253 case CODEC_ID_DNXHD:
1255 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-dnxhd",
1259 case CODEC_ID_PRORES:
1261 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-prores",
1265 case CODEC_ID_MIMIC:
1267 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-mimic",
1273 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-vmnc", NULL);
1276 case CODEC_ID_TRUESPEECH:
1278 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-truespeech",
1282 case CODEC_ID_QCELP:
1284 gst_ff_aud_caps_new (context, codec_id, encode, "audio/qcelp", NULL);
1289 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-amv", NULL);
1294 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-aasc", NULL);
1299 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-loco", NULL);
1304 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-zmbv", NULL);
1307 case CODEC_ID_LAGARITH:
1309 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-lagarith",
1315 gst_ff_vid_caps_new (context, codec_id, encode, "video/x-camstudio",
1318 gst_caps_set_simple (caps,
1319 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1321 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1325 case CODEC_ID_WS_VQA:
1326 case CODEC_ID_IDCIN:
1329 case CODEC_ID_VMDVIDEO:
1330 case CODEC_ID_VMDAUDIO:
1331 case CODEC_ID_SONIC:
1332 case CODEC_ID_SONIC_LS:
1336 case CODEC_ID_PGMYUV:
1337 case CODEC_ID_FFVHUFF:
1339 case CODEC_ID_MP3ADU:
1340 case CODEC_ID_MP3ON4:
1341 case CODEC_ID_WESTWOOD_SND1:
1342 case CODEC_ID_MMVIDEO:
1348 /* weird quasi-codecs for the demuxers only */
1349 case CODEC_ID_PCM_S16LE:
1350 case CODEC_ID_PCM_S16BE:
1351 case CODEC_ID_PCM_U16LE:
1352 case CODEC_ID_PCM_U16BE:
1353 case CODEC_ID_PCM_S8:
1354 case CODEC_ID_PCM_U8:
1356 GstAudioFormat format;
1359 case CODEC_ID_PCM_S16LE:
1360 format = GST_AUDIO_FORMAT_S16LE;
1362 case CODEC_ID_PCM_S16BE:
1363 format = GST_AUDIO_FORMAT_S16BE;
1365 case CODEC_ID_PCM_U16LE:
1366 format = GST_AUDIO_FORMAT_U16LE;
1368 case CODEC_ID_PCM_U16BE:
1369 format = GST_AUDIO_FORMAT_U16BE;
1371 case CODEC_ID_PCM_S8:
1372 format = GST_AUDIO_FORMAT_S8;
1374 case CODEC_ID_PCM_U8:
1375 format = GST_AUDIO_FORMAT_U8;
1378 g_assert (0); /* don't worry, we never get here */
1382 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-raw",
1383 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1384 "layout", G_TYPE_STRING, "interleaved", NULL);
1388 case CODEC_ID_PCM_MULAW:
1390 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-mulaw",
1394 case CODEC_ID_PCM_ALAW:
1396 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-alaw", NULL);
1399 case CODEC_ID_ADPCM_G722:
1401 gst_ff_aud_caps_new (context, codec_id, encode, "audio/G722", NULL);
1403 gst_caps_set_simple (caps,
1404 "block_align", G_TYPE_INT, context->block_align,
1405 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1408 case CODEC_ID_ADPCM_G726:
1410 /* the G726 decoder can also handle G721 */
1411 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-adpcm",
1412 "layout", G_TYPE_STRING, "g726", NULL);
1414 gst_caps_set_simple (caps,
1415 "block_align", G_TYPE_INT, context->block_align,
1416 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1419 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1420 "layout", G_TYPE_STRING, "g721",
1421 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1425 case CODEC_ID_ADPCM_IMA_QT:
1426 case CODEC_ID_ADPCM_IMA_WAV:
1427 case CODEC_ID_ADPCM_IMA_DK3:
1428 case CODEC_ID_ADPCM_IMA_DK4:
1429 case CODEC_ID_ADPCM_IMA_WS:
1430 case CODEC_ID_ADPCM_IMA_SMJPEG:
1431 case CODEC_ID_ADPCM_IMA_AMV:
1432 case CODEC_ID_ADPCM_IMA_ISS:
1433 case CODEC_ID_ADPCM_IMA_EA_EACS:
1434 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1435 case CODEC_ID_ADPCM_MS:
1436 case CODEC_ID_ADPCM_4XM:
1437 case CODEC_ID_ADPCM_XA:
1438 case CODEC_ID_ADPCM_ADX:
1439 case CODEC_ID_ADPCM_EA:
1440 case CODEC_ID_ADPCM_CT:
1441 case CODEC_ID_ADPCM_SWF:
1442 case CODEC_ID_ADPCM_YAMAHA:
1443 case CODEC_ID_ADPCM_SBPRO_2:
1444 case CODEC_ID_ADPCM_SBPRO_3:
1445 case CODEC_ID_ADPCM_SBPRO_4:
1446 case CODEC_ID_ADPCM_EA_R1:
1447 case CODEC_ID_ADPCM_EA_R2:
1448 case CODEC_ID_ADPCM_EA_R3:
1449 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1450 case CODEC_ID_ADPCM_EA_XAS:
1451 case CODEC_ID_ADPCM_THP:
1453 const gchar *layout = NULL;
1456 case CODEC_ID_ADPCM_IMA_QT:
1457 layout = "quicktime";
1459 case CODEC_ID_ADPCM_IMA_WAV:
1462 case CODEC_ID_ADPCM_IMA_DK3:
1465 case CODEC_ID_ADPCM_IMA_DK4:
1468 case CODEC_ID_ADPCM_IMA_WS:
1469 layout = "westwood";
1471 case CODEC_ID_ADPCM_IMA_SMJPEG:
1474 case CODEC_ID_ADPCM_IMA_AMV:
1477 case CODEC_ID_ADPCM_IMA_ISS:
1480 case CODEC_ID_ADPCM_IMA_EA_EACS:
1483 case CODEC_ID_ADPCM_IMA_EA_SEAD:
1486 case CODEC_ID_ADPCM_MS:
1487 layout = "microsoft";
1489 case CODEC_ID_ADPCM_4XM:
1492 case CODEC_ID_ADPCM_XA:
1495 case CODEC_ID_ADPCM_ADX:
1498 case CODEC_ID_ADPCM_EA:
1501 case CODEC_ID_ADPCM_CT:
1504 case CODEC_ID_ADPCM_SWF:
1507 case CODEC_ID_ADPCM_YAMAHA:
1510 case CODEC_ID_ADPCM_SBPRO_2:
1513 case CODEC_ID_ADPCM_SBPRO_3:
1516 case CODEC_ID_ADPCM_SBPRO_4:
1519 case CODEC_ID_ADPCM_EA_R1:
1522 case CODEC_ID_ADPCM_EA_R2:
1525 case CODEC_ID_ADPCM_EA_R3:
1528 case CODEC_ID_ADPCM_EA_MAXIS_XA:
1529 layout = "ea-maxis-xa";
1531 case CODEC_ID_ADPCM_EA_XAS:
1534 case CODEC_ID_ADPCM_THP:
1538 g_assert (0); /* don't worry, we never get here */
1542 /* FIXME: someone please check whether we need additional properties
1543 * in this caps definition. */
1544 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-adpcm",
1545 "layout", G_TYPE_STRING, layout, NULL);
1547 gst_caps_set_simple (caps,
1548 "block_align", G_TYPE_INT, context->block_align,
1549 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1553 case CODEC_ID_AMR_NB:
1554 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/AMR", NULL);
1557 case CODEC_ID_AMR_WB:
1559 gst_ff_aud_caps_new (context, codec_id, encode, "audio/AMR-WB", NULL);
1564 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-gsm", NULL);
1567 case CODEC_ID_GSM_MS:
1569 gst_ff_aud_caps_new (context, codec_id, encode, "audio/ms-gsm", NULL);
1572 case CODEC_ID_NELLYMOSER:
1574 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-nellymoser",
1581 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-sipro",
1584 gst_caps_set_simple (caps,
1585 "leaf_size", G_TYPE_INT, context->block_align,
1586 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1591 case CODEC_ID_RA_144:
1592 case CODEC_ID_RA_288:
1598 case CODEC_ID_RA_144:
1601 case CODEC_ID_RA_288:
1611 /* FIXME: properties? */
1613 gst_ff_aud_caps_new (context, codec_id, encode,
1614 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1616 gst_caps_set_simple (caps,
1617 "leaf_size", G_TYPE_INT, context->block_align,
1618 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1623 case CODEC_ID_ROQ_DPCM:
1624 case CODEC_ID_INTERPLAY_DPCM:
1625 case CODEC_ID_XAN_DPCM:
1626 case CODEC_ID_SOL_DPCM:
1628 const gchar *layout = NULL;
1631 case CODEC_ID_ROQ_DPCM:
1634 case CODEC_ID_INTERPLAY_DPCM:
1635 layout = "interplay";
1637 case CODEC_ID_XAN_DPCM:
1640 case CODEC_ID_SOL_DPCM:
1644 g_assert (0); /* don't worry, we never get here */
1648 /* FIXME: someone please check whether we need additional properties
1649 * in this caps definition. */
1650 caps = gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-dpcm",
1651 "layout", G_TYPE_STRING, layout, NULL);
1653 gst_caps_set_simple (caps,
1654 "block_align", G_TYPE_INT, context->block_align,
1655 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1659 case CODEC_ID_SHORTEN:
1660 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1665 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-alac", NULL);
1667 gst_caps_set_simple (caps,
1668 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1673 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1674 * encoder case, we want to add things like samplerate, channels... */
1676 caps = gst_caps_new_empty_simple ("audio/x-flac");
1680 case CODEC_ID_DVD_SUBTITLE:
1681 case CODEC_ID_DVB_SUBTITLE:
1685 caps = gst_caps_new_empty_simple ("image/bmp");
1689 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-tta", NULL);
1691 gst_caps_set_simple (caps,
1692 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1695 case CODEC_ID_TWINVQ:
1697 gst_ff_aud_caps_new (context, codec_id, encode, "audio/x-twin-vq",
1701 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1708 if ((codec = avcodec_find_decoder (codec_id)) ||
1709 (codec = avcodec_find_encoder (codec_id))) {
1712 GST_LOG ("Could not create stream format caps for %s", codec->name);
1714 switch (codec->type) {
1715 case AVMEDIA_TYPE_VIDEO:
1716 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
1717 caps = gst_ff_vid_caps_new (context, codec_id, encode, mime, NULL);
1720 case AVMEDIA_TYPE_AUDIO:
1721 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
1722 caps = gst_ff_aud_caps_new (context, codec_id, encode, mime, NULL);
1724 gst_caps_set_simple (caps,
1725 "block_align", G_TYPE_INT, context->block_align,
1726 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1737 /* set private data */
1738 if (context && context->extradata_size > 0) {
1739 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
1741 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
1742 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
1743 gst_buffer_unref (data);
1748 gst_ffmpeg_set_palette (caps, context);
1751 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
1754 GST_LOG ("No caps found for codec_id=%d", codec_id);
1760 /* Convert a FFMPEG Pixel Format to a GStreamer VideoFormat */
1762 gst_ffmpeg_pixfmt_to_video_format (enum PixelFormat pix_fmt)
1767 case PIX_FMT_YUVJ420P:
1768 case PIX_FMT_YUV420P:
1769 fmt = GST_VIDEO_FORMAT_I420;
1771 case PIX_FMT_YUVA420P:
1772 fmt = GST_VIDEO_FORMAT_A420;
1774 case PIX_FMT_YUYV422:
1775 fmt = GST_VIDEO_FORMAT_YUY2;
1778 fmt = GST_VIDEO_FORMAT_RGB;
1781 fmt = GST_VIDEO_FORMAT_BGR;
1783 case PIX_FMT_YUVJ422P:
1784 case PIX_FMT_YUV422P:
1785 fmt = GST_VIDEO_FORMAT_Y42B;
1787 case PIX_FMT_YUVJ444P:
1788 case PIX_FMT_YUV444P:
1789 fmt = GST_VIDEO_FORMAT_Y444;
1792 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
1793 fmt = GST_VIDEO_FORMAT_xRGB;
1795 fmt = GST_VIDEO_FORMAT_BGRx;
1798 case PIX_FMT_YUV410P:
1799 fmt = GST_VIDEO_FORMAT_YUV9;
1801 case PIX_FMT_YUV411P:
1802 fmt = GST_VIDEO_FORMAT_Y41B;
1804 case PIX_FMT_RGB565:
1805 fmt = GST_VIDEO_FORMAT_RGB16;
1807 case PIX_FMT_RGB555:
1808 fmt = GST_VIDEO_FORMAT_RGB15;
1811 fmt = GST_VIDEO_FORMAT_RGB8P;
1814 fmt = GST_VIDEO_FORMAT_GRAY8;
1816 case PIX_FMT_YUV420P10LE:
1817 fmt = GST_VIDEO_FORMAT_I420_10LE;
1819 case PIX_FMT_YUV420P10BE:
1820 fmt = GST_VIDEO_FORMAT_I420_10BE;
1824 fmt = GST_VIDEO_FORMAT_UNKNOWN;
1830 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
1831 * to a GstCaps. If the context is ommitted, no fixed values
1832 * for video/audio size will be included in the GstCaps
1834 * See below for usefullness
1838 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
1839 enum CodecID codec_id)
1841 GstCaps *caps = NULL;
1842 GstVideoFormat format;
1844 format = gst_ffmpeg_pixfmt_to_video_format (pix_fmt);
1846 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
1847 caps = gst_ff_vid_caps_new (context, codec_id, TRUE, "video/x-raw",
1848 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1852 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
1854 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
1860 /* Convert a FFMPEG Sample Format and optional AVCodecContext
1861 * to a GstCaps. If the context is ommitted, no fixed values
1862 * for video/audio size will be included in the GstCaps
1864 * See below for usefullness
1868 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
1869 AVCodecContext * context, enum CodecID codec_id)
1871 GstCaps *caps = NULL;
1872 GstAudioFormat format;
1874 switch (sample_fmt) {
1875 case AV_SAMPLE_FMT_S16:
1876 format = GST_AUDIO_FORMAT_S16;
1878 case AV_SAMPLE_FMT_S32:
1879 format = GST_AUDIO_FORMAT_S32;
1881 case AV_SAMPLE_FMT_FLT:
1882 format = GST_AUDIO_FORMAT_F32;
1884 case AV_SAMPLE_FMT_DBL:
1885 format = GST_AUDIO_FORMAT_F64;
1889 format = GST_AUDIO_FORMAT_UNKNOWN;
1893 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
1894 caps = gst_ff_aud_caps_new (context, codec_id, TRUE, "audio/x-raw",
1895 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1896 "layout", G_TYPE_STRING, "interleaved", NULL);
1897 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
1899 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
1906 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
1907 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1909 GstCaps *caps = NULL;
1911 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1912 context, codec_id, encode, codec);
1914 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
1915 codec->sample_fmts, codec->supported_samplerates);
1918 /* Specific codec context */
1919 caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec_id);
1920 } else if (codec && codec->sample_fmts) {
1924 caps = gst_caps_new_empty ();
1925 for (i = 0; codec->sample_fmts[i] != -1; i++) {
1927 gst_ffmpeg_smpfmt_to_caps (codec->sample_fmts[i], context, codec_id);
1929 gst_caps_append (caps, temp);
1933 enum AVSampleFormat i;
1934 AVCodecContext ctx = { 0, };
1937 caps = gst_caps_new_empty ();
1938 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
1939 temp = gst_ffmpeg_smpfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1941 gst_caps_append (caps, temp);
1949 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
1950 enum CodecID codec_id, gboolean encode, AVCodec * codec)
1954 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
1955 context, codec_id, encode, codec);
1958 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
1962 AVCodecContext ctx = { 0, };
1964 caps = gst_caps_new_empty ();
1965 for (i = 0; i < PIX_FMT_NB; i++) {
1968 temp = gst_ffmpeg_pixfmt_to_caps (i, encode ? &ctx : NULL, codec_id);
1970 gst_caps_append (caps, temp);
1977 /* Convert a FFMPEG codec Type and optional AVCodecContext
1978 * to a GstCaps. If the context is ommitted, no fixed values
1979 * for video/audio size will be included in the GstCaps
1981 * AVMediaType is primarily meant for uncompressed data GstCaps!
1985 gst_ffmpeg_codectype_to_caps (enum AVMediaType codec_type,
1986 AVCodecContext * context, enum CodecID codec_id, gboolean encode)
1990 switch (codec_type) {
1991 case AVMEDIA_TYPE_VIDEO:
1993 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1995 case AVMEDIA_TYPE_AUDIO:
1997 gst_ffmpeg_codectype_to_audio_caps (context, codec_id, encode, NULL);
2007 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2008 * and other audio properties in a AVCodecContext.
2010 * For usefullness, see below
2014 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2015 AVCodecContext * context, gboolean raw)
2017 GstStructure *structure;
2019 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2021 g_return_if_fail (gst_caps_get_size (caps) == 1);
2023 structure = gst_caps_get_structure (caps, 0);
2025 gst_structure_get_int (structure, "channels", &context->channels);
2026 gst_structure_get_int (structure, "rate", &context->sample_rate);
2027 gst_structure_get_int (structure, "block_align", &context->block_align);
2028 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2033 if (gst_structure_has_name (structure, "audio/x-raw")) {
2034 if ((fmt = gst_structure_get_string (structure, "format"))) {
2035 format = gst_audio_format_from_string (fmt);
2040 case GST_AUDIO_FORMAT_F32:
2041 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2043 case GST_AUDIO_FORMAT_F64:
2044 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2046 case GST_AUDIO_FORMAT_S32:
2047 context->sample_fmt = AV_SAMPLE_FMT_S32;
2049 case GST_AUDIO_FORMAT_S16:
2050 context->sample_fmt = AV_SAMPLE_FMT_S16;
2057 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2058 * and other video properties in a AVCodecContext.
2060 * For usefullness, see below
2064 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2065 AVCodecContext * context, gboolean raw)
2067 GstStructure *structure;
2069 const GValue *par = NULL;
2071 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2073 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2074 g_return_if_fail (gst_caps_get_size (caps) == 1);
2075 structure = gst_caps_get_structure (caps, 0);
2077 gst_structure_get_int (structure, "width", &context->width);
2078 gst_structure_get_int (structure, "height", &context->height);
2079 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2081 fps = gst_structure_get_value (structure, "framerate");
2082 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2084 /* somehow these seem mixed up.. */
2085 context->time_base.den = gst_value_get_fraction_numerator (fps);
2086 context->time_base.num = gst_value_get_fraction_denominator (fps);
2087 context->ticks_per_frame = 1;
2089 GST_DEBUG ("setting framerate %d/%d = %lf",
2090 context->time_base.den, context->time_base.num,
2091 1. * context->time_base.den / context->time_base.num);
2094 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2095 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2097 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2098 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2100 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2101 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2102 1. * context->sample_aspect_ratio.den /
2103 context->sample_aspect_ratio.num);
2106 gst_ffmpeg_get_palette (caps, context);
2111 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2113 if (gst_structure_has_name (structure, "video/x-raw")) {
2114 if ((fmt = gst_structure_get_string (structure, "format"))) {
2115 format = gst_video_format_from_string (fmt);
2120 case GST_VIDEO_FORMAT_YUY2:
2121 context->pix_fmt = PIX_FMT_YUYV422;
2123 case GST_VIDEO_FORMAT_I420:
2124 context->pix_fmt = PIX_FMT_YUV420P;
2126 case GST_VIDEO_FORMAT_A420:
2127 context->pix_fmt = PIX_FMT_YUVA420P;
2129 case GST_VIDEO_FORMAT_Y41B:
2130 context->pix_fmt = PIX_FMT_YUV411P;
2132 case GST_VIDEO_FORMAT_Y42B:
2133 context->pix_fmt = PIX_FMT_YUV422P;
2135 case GST_VIDEO_FORMAT_YUV9:
2136 context->pix_fmt = PIX_FMT_YUV410P;
2138 case GST_VIDEO_FORMAT_Y444:
2139 context->pix_fmt = PIX_FMT_YUV444P;
2141 case GST_VIDEO_FORMAT_GRAY8:
2142 context->pix_fmt = PIX_FMT_GRAY8;
2144 case GST_VIDEO_FORMAT_xRGB:
2145 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2146 context->pix_fmt = PIX_FMT_RGB32;
2149 case GST_VIDEO_FORMAT_BGRx:
2150 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2151 context->pix_fmt = PIX_FMT_RGB32;
2154 case GST_VIDEO_FORMAT_RGB:
2155 context->pix_fmt = PIX_FMT_RGB24;
2157 case GST_VIDEO_FORMAT_BGR:
2158 context->pix_fmt = PIX_FMT_BGR24;
2160 case GST_VIDEO_FORMAT_RGB16:
2161 context->pix_fmt = PIX_FMT_RGB565;
2163 case GST_VIDEO_FORMAT_RGB15:
2164 context->pix_fmt = PIX_FMT_RGB555;
2166 case GST_VIDEO_FORMAT_RGB8P:
2167 context->pix_fmt = PIX_FMT_PAL8;
2176 GstVideoFormat format;
2177 enum PixelFormat pixfmt;
2180 /* FIXME : FILLME */
2181 static const PixToFmt pixtofmttable[] = {
2182 /* GST_VIDEO_FORMAT_I420, */
2183 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2184 /* Note : this should use a different chroma placement */
2185 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2187 /* GST_VIDEO_FORMAT_YV12, */
2188 /* GST_VIDEO_FORMAT_YUY2, */
2189 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2190 /* GST_VIDEO_FORMAT_UYVY, */
2191 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2192 /* GST_VIDEO_FORMAT_AYUV, */
2193 /* GST_VIDEO_FORMAT_RGBx, */
2194 /* GST_VIDEO_FORMAT_BGRx, */
2195 /* GST_VIDEO_FORMAT_xRGB, */
2196 /* GST_VIDEO_FORMAT_xBGR, */
2197 /* GST_VIDEO_FORMAT_RGBA, */
2198 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGB32},
2199 /* GST_VIDEO_FORMAT_BGRA, */
2200 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGR32},
2201 /* GST_VIDEO_FORMAT_ARGB, */
2202 /* GST_VIDEO_FORMAT_ABGR, */
2203 /* GST_VIDEO_FORMAT_RGB, */
2204 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2205 /* GST_VIDEO_FORMAT_BGR, */
2206 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2207 /* GST_VIDEO_FORMAT_Y41B, */
2208 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV410P},
2209 /* GST_VIDEO_FORMAT_Y42B, */
2210 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2211 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2212 /* GST_VIDEO_FORMAT_YVYU, */
2213 /* GST_VIDEO_FORMAT_Y444, */
2214 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2215 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2216 /* GST_VIDEO_FORMAT_v210, */
2217 /* GST_VIDEO_FORMAT_v216, */
2218 /* GST_VIDEO_FORMAT_NV12, */
2219 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2220 /* GST_VIDEO_FORMAT_NV21, */
2221 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2222 /* GST_VIDEO_FORMAT_GRAY8, */
2223 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2224 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2225 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2226 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2227 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2228 /* GST_VIDEO_FORMAT_v308, */
2229 /* GST_VIDEO_FORMAT_Y800, */
2230 /* GST_VIDEO_FORMAT_Y16, */
2231 /* GST_VIDEO_FORMAT_RGB16, */
2232 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2233 /* GST_VIDEO_FORMAT_BGR16, */
2234 /* GST_VIDEO_FORMAT_RGB15, */
2235 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2236 /* GST_VIDEO_FORMAT_BGR15, */
2237 /* GST_VIDEO_FORMAT_UYVP, */
2238 /* GST_VIDEO_FORMAT_A420, */
2239 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2240 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2241 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2242 /* GST_VIDEO_FORMAT_YUV9, */
2243 /* GST_VIDEO_FORMAT_YVU9, */
2244 /* GST_VIDEO_FORMAT_IYU1, */
2245 /* GST_VIDEO_FORMAT_ARGB64, */
2246 /* GST_VIDEO_FORMAT_AYUV64, */
2247 /* GST_VIDEO_FORMAT_r210, */
2248 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2249 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2253 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2257 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2258 if (pixtofmttable[i].pixfmt == pixfmt)
2259 return pixtofmttable[i].format;
2261 GST_WARNING ("Unknown pixel format %d", pixfmt);
2262 return GST_VIDEO_FORMAT_UNKNOWN;
2266 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2270 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2271 if (pixtofmttable[i].format == format)
2272 return pixtofmttable[i].pixfmt;
2273 return PIX_FMT_NONE;
2277 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2281 context->width = GST_VIDEO_INFO_WIDTH (info);
2282 context->height = GST_VIDEO_INFO_HEIGHT (info);
2283 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2284 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2285 context->bits_per_coded_sample = bpp;
2287 context->ticks_per_frame = 1;
2288 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2289 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2291 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2292 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2295 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2298 /* Convert a GstCaps and a FFMPEG codec Type to a
2299 * AVCodecContext. If the context is ommitted, no fixed values
2300 * for video/audio size will be included in the context
2302 * AVMediaType is primarily meant for uncompressed data GstCaps!
2306 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2307 const GstCaps * caps, AVCodecContext * context)
2309 if (context == NULL)
2313 case AVMEDIA_TYPE_VIDEO:
2314 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2317 case AVMEDIA_TYPE_AUDIO:
2318 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2329 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2333 guint8 *end = src + size;
2336 while (srcp < end) {
2337 if (count == 2 && *srcp <= 0x03) {
2338 GST_DEBUG ("added escape code");
2347 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2350 *destsize = dstp - dst;
2353 /* copy the config, escaping NAL units as we iterate them, if something fails we
2354 * copy everything and hope for the best. */
2356 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2361 guint nalsize, esize;
2371 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2373 GST_DEBUG ("num SPS %d", cnt);
2375 memcpy (dstp, srcp, 6);
2379 for (i = 0; i < cnt; i++) {
2380 GST_DEBUG ("copy SPS %d", i);
2381 nalsize = (srcp[0] << 8) | srcp[1];
2382 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2383 dstp[0] = esize >> 8;
2384 dstp[1] = esize & 0xff;
2386 srcp += nalsize + 2;
2389 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2391 GST_DEBUG ("num PPS %d", cnt);
2393 for (i = 0; i < cnt; i++) {
2394 GST_DEBUG ("copy PPS %d", i);
2395 nalsize = (srcp[0] << 8) | srcp[1];
2396 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2397 dstp[0] = esize >> 8;
2398 dstp[1] = esize & 0xff;
2400 srcp += nalsize + 2;
2402 *destsize = dstp - dst;
2408 GST_DEBUG ("something unexpected, doing full copy");
2409 memcpy (dst, src, size);
2417 * caps_with_codecid () transforms a GstCaps for a known codec
2418 * ID into a filled-in context.
2419 * codec_data from caps will override possible extradata already in the context
2423 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2424 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2427 const GValue *value;
2430 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2431 codec_id, codec_type, caps, context);
2433 if (!context || !gst_caps_get_size (caps))
2436 str = gst_caps_get_structure (caps, 0);
2438 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2439 if ((value = gst_structure_get_value (str, "codec_data"))) {
2442 buf = gst_value_get_buffer (value);
2443 gst_buffer_map (buf, &map, GST_MAP_READ);
2445 /* free the old one if it is there */
2446 if (context->extradata)
2447 av_free (context->extradata);
2450 if (codec_id == CODEC_ID_H264) {
2453 GST_DEBUG ("copy, escaping codec_data %d", size);
2454 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2455 * reason for this but let's just escape it for now. Start by allocating
2456 * enough space, x2 is more than enough.
2458 * FIXME, we disabled escaping because some file already contain escaped
2459 * codec_data and then we escape twice and fail. It's better to leave it
2460 * as is, as that is what most players do. */
2461 context->extradata =
2462 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2463 FF_INPUT_BUFFER_PADDING_SIZE));
2464 copy_config (context->extradata, data, size, &extrasize);
2465 GST_DEBUG ("escaped size: %d", extrasize);
2466 context->extradata_size = extrasize;
2470 /* allocate with enough padding */
2471 GST_DEBUG ("copy codec_data");
2472 context->extradata =
2473 av_mallocz (GST_ROUND_UP_16 (map.size +
2474 FF_INPUT_BUFFER_PADDING_SIZE));
2475 memcpy (context->extradata, map.data, map.size);
2476 context->extradata_size = map.size;
2479 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2480 if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2481 context->extradata[0] = (guint8) map.size;
2484 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2486 gst_buffer_unmap (buf, &map);
2487 } else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
2488 codec_id != CODEC_ID_FLAC) {
2489 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2490 * extradata anyway which makes then segfault. */
2491 context->extradata =
2492 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2493 context->extradata_size = 0;
2494 GST_DEBUG ("no codec data");
2498 case CODEC_ID_MPEG4:
2500 const gchar *mime = gst_structure_get_name (str);
2502 if (!strcmp (mime, "video/x-divx"))
2503 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2504 else if (!strcmp (mime, "video/x-xvid"))
2505 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2506 else if (!strcmp (mime, "video/x-3ivx"))
2507 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2508 else if (!strcmp (mime, "video/mpeg"))
2509 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2514 /* FIXME: this is a workaround for older gst-plugins releases
2515 * (<= 0.8.9). This should be removed at some point, because
2516 * it causes wrong decoded frame order. */
2517 if (!context->extradata) {
2518 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2521 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2522 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2523 gst_structure_get_int (str, "low_delay", &low_delay) ||
2524 gst_structure_get_int (str, "unknown_svq3_flag",
2525 &unknown_svq3_flag)) {
2526 context->extradata = (guint8 *) av_mallocz (0x64);
2527 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2531 flags |= unknown_svq3_flag;
2533 flags |= halfpel_flag;
2535 flags |= thirdpel_flag;
2538 flags = GUINT16_FROM_LE (flags);
2540 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2541 context->extradata_size = 0x64;
2546 case CODEC_ID_MSRLE:
2547 case CODEC_ID_QTRLE:
2554 if (gst_structure_get_int (str, "depth", &depth)) {
2555 context->bits_per_coded_sample = depth;
2557 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2570 if (gst_structure_get_int (str, "format", &format))
2571 context->sub_id = format;
2576 case CODEC_ID_RA_288:
2577 case CODEC_ID_RA_144:
2583 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2584 context->block_align = leaf_size;
2585 if (gst_structure_get_int (str, "bitrate", &bitrate))
2586 context->bit_rate = bitrate;
2589 gst_structure_get_int (str, "samplesize",
2590 &context->bits_per_coded_sample);
2593 case CODEC_ID_DVVIDEO:
2595 const gchar *format;
2597 if ((format = gst_structure_get_string (str, "format"))) {
2599 if (g_str_equal (format, "YUY2"))
2600 context->pix_fmt = PIX_FMT_YUYV422;
2601 else if (g_str_equal (format, "I420"))
2602 context->pix_fmt = PIX_FMT_YUV420P;
2603 else if (g_str_equal (format, "A420"))
2604 context->pix_fmt = PIX_FMT_YUVA420P;
2605 else if (g_str_equal (format, "Y41B"))
2606 context->pix_fmt = PIX_FMT_YUV411P;
2607 else if (g_str_equal (format, "Y42B"))
2608 context->pix_fmt = PIX_FMT_YUV422P;
2609 else if (g_str_equal (format, "YUV9"))
2610 context->pix_fmt = PIX_FMT_YUV410P;
2612 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2616 GST_WARNING ("No specified format");
2619 case CODEC_ID_H263P:
2623 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2624 context->flags |= CODEC_FLAG_4MV;
2626 context->flags &= ~CODEC_FLAG_4MV;
2627 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2628 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2629 context->flags |= CODEC_FLAG_AC_PRED;
2631 context->flags &= ~CODEC_FLAG_AC_PRED;
2632 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2633 context->flags |= CODEC_FLAG_LOOP_FILTER;
2635 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2638 case CODEC_ID_ADPCM_G726:
2640 const gchar *layout;
2642 if ((layout = gst_structure_get_string (str, "layout"))) {
2643 if (!strcmp (layout, "g721")) {
2644 context->sample_rate = 8000;
2645 context->channels = 1;
2646 context->bit_rate = 32000;
2655 if (!gst_caps_is_fixed (caps))
2658 /* common properties (width, height, fps) */
2659 switch (codec_type) {
2660 case AVMEDIA_TYPE_VIDEO:
2661 gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
2663 case AVMEDIA_TYPE_AUDIO:
2664 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2670 /* fixup of default settings */
2672 case CODEC_ID_QCELP:
2673 /* QCELP is always mono, no matter what the caps say */
2674 context->channels = 1;
2681 /* _formatid_to_caps () is meant for muxers/demuxers, it
2682 * transforms a name (ffmpeg way of ID'ing these, why don't
2683 * they have unique numerical IDs?) to the corresponding
2684 * caps belonging to that mux-format
2686 * Note: we don't need any additional info because the caps
2687 * isn't supposed to contain any useful info besides the
2692 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
2694 GstCaps *caps = NULL;
2696 if (!strcmp (format_name, "mpeg")) {
2697 caps = gst_caps_new_simple ("video/mpeg",
2698 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2699 } else if (!strcmp (format_name, "mpegts")) {
2700 caps = gst_caps_new_simple ("video/mpegts",
2701 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2702 } else if (!strcmp (format_name, "rm")) {
2703 caps = gst_caps_new_simple ("application/x-pn-realmedia",
2704 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2705 } else if (!strcmp (format_name, "asf")) {
2706 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
2707 } else if (!strcmp (format_name, "avi")) {
2708 caps = gst_caps_new_empty_simple ("video/x-msvideo");
2709 } else if (!strcmp (format_name, "wav")) {
2710 caps = gst_caps_new_empty_simple ("audio/x-wav");
2711 } else if (!strcmp (format_name, "ape")) {
2712 caps = gst_caps_new_empty_simple ("application/x-ape");
2713 } else if (!strcmp (format_name, "swf")) {
2714 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
2715 } else if (!strcmp (format_name, "au")) {
2716 caps = gst_caps_new_empty_simple ("audio/x-au");
2717 } else if (!strcmp (format_name, "dv")) {
2718 caps = gst_caps_new_simple ("video/x-dv",
2719 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
2720 } else if (!strcmp (format_name, "4xm")) {
2721 caps = gst_caps_new_empty_simple ("video/x-4xm");
2722 } else if (!strcmp (format_name, "matroska")) {
2723 caps = gst_caps_new_empty_simple ("video/x-matroska");
2724 } else if (!strcmp (format_name, "mp3")) {
2725 caps = gst_caps_new_empty_simple ("application/x-id3");
2726 } else if (!strcmp (format_name, "flic")) {
2727 caps = gst_caps_new_empty_simple ("video/x-fli");
2728 } else if (!strcmp (format_name, "flv")) {
2729 caps = gst_caps_new_empty_simple ("video/x-flv");
2730 } else if (!strcmp (format_name, "tta")) {
2731 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
2732 } else if (!strcmp (format_name, "aiff")) {
2733 caps = gst_caps_new_empty_simple ("audio/x-aiff");
2734 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
2736 gst_caps_from_string
2737 ("application/x-3gp; video/quicktime; audio/x-m4a");
2738 } else if (!strcmp (format_name, "mov")) {
2739 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
2740 } else if (!strcmp (format_name, "mp4")) {
2741 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
2742 } else if (!strcmp (format_name, "3gp")) {
2743 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
2744 } else if (!strcmp (format_name, "3g2")) {
2745 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
2746 } else if (!strcmp (format_name, "psp")) {
2747 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
2748 } else if (!strcmp (format_name, "ipod")) {
2749 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
2750 } else if (!strcmp (format_name, "aac")) {
2751 caps = gst_caps_new_simple ("audio/mpeg",
2752 "mpegversion", G_TYPE_INT, 4, NULL);
2753 } else if (!strcmp (format_name, "gif")) {
2754 caps = gst_caps_from_string ("image/gif");
2755 } else if (!strcmp (format_name, "ogg")) {
2756 caps = gst_caps_from_string ("application/ogg");
2757 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
2758 caps = gst_caps_from_string ("application/mxf");
2759 } else if (!strcmp (format_name, "gxf")) {
2760 caps = gst_caps_from_string ("application/gxf");
2761 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
2762 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
2763 "y4mversion", G_TYPE_INT, 2, NULL);
2764 } else if (!strcmp (format_name, "mpc")) {
2765 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
2766 } else if (!strcmp (format_name, "vqf")) {
2767 caps = gst_caps_from_string ("audio/x-vqf");
2768 } else if (!strcmp (format_name, "nsv")) {
2769 caps = gst_caps_from_string ("video/x-nsv");
2770 } else if (!strcmp (format_name, "amr")) {
2771 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
2772 } else if (!strcmp (format_name, "webm")) {
2773 caps = gst_caps_from_string ("video/webm");
2774 } else if (!strcmp (format_name, "voc")) {
2775 caps = gst_caps_from_string ("audio/x-voc");
2779 GST_LOG ("Could not create stream format caps for %s", format_name);
2780 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
2781 caps = gst_caps_new_empty_simple (name);
2789 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
2790 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
2791 AVOutputFormat * plugin)
2793 static enum CodecID tmp_vlist[] = {
2797 static enum CodecID tmp_alist[] = {
2802 GST_LOG ("format_name : %s", format_name);
2804 if (!strcmp (format_name, "mp4")) {
2805 static enum CodecID mp4_video_list[] = {
2806 CODEC_ID_MPEG4, CODEC_ID_H264,
2810 static enum CodecID mp4_audio_list[] = {
2811 CODEC_ID_AAC, CODEC_ID_MP3,
2815 *video_codec_list = mp4_video_list;
2816 *audio_codec_list = mp4_audio_list;
2817 } else if (!strcmp (format_name, "mpeg")) {
2818 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO,
2819 CODEC_ID_MPEG2VIDEO,
2823 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP1,
2829 *video_codec_list = mpeg_video_list;
2830 *audio_codec_list = mpeg_audio_list;
2831 } else if (!strcmp (format_name, "dvd")) {
2832 static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG2VIDEO,
2835 static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2,
2842 *video_codec_list = mpeg_video_list;
2843 *audio_codec_list = mpeg_audio_list;
2844 } else if (!strcmp (format_name, "mpegts")) {
2845 static enum CodecID mpegts_video_list[] = { CODEC_ID_MPEG1VIDEO,
2846 CODEC_ID_MPEG2VIDEO,
2850 static enum CodecID mpegts_audio_list[] = { CODEC_ID_MP2,
2858 *video_codec_list = mpegts_video_list;
2859 *audio_codec_list = mpegts_audio_list;
2860 } else if (!strcmp (format_name, "vob")) {
2861 static enum CodecID vob_video_list[] =
2862 { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
2863 static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3,
2864 CODEC_ID_DTS, CODEC_ID_NONE
2867 *video_codec_list = vob_video_list;
2868 *audio_codec_list = vob_audio_list;
2869 } else if (!strcmp (format_name, "flv")) {
2870 static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
2871 static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
2873 *video_codec_list = flv_video_list;
2874 *audio_codec_list = flv_audio_list;
2875 } else if (!strcmp (format_name, "asf")) {
2876 static enum CodecID asf_video_list[] =
2877 { CODEC_ID_WMV1, CODEC_ID_WMV2, CODEC_ID_MSMPEG4V3, CODEC_ID_NONE };
2878 static enum CodecID asf_audio_list[] =
2879 { CODEC_ID_WMAV1, CODEC_ID_WMAV2, CODEC_ID_MP3, CODEC_ID_NONE };
2881 *video_codec_list = asf_video_list;
2882 *audio_codec_list = asf_audio_list;
2883 } else if (!strcmp (format_name, "dv")) {
2884 static enum CodecID dv_video_list[] = { CODEC_ID_DVVIDEO, CODEC_ID_NONE };
2885 static enum CodecID dv_audio_list[] = { CODEC_ID_PCM_S16LE, CODEC_ID_NONE };
2887 *video_codec_list = dv_video_list;
2888 *audio_codec_list = dv_audio_list;
2889 } else if (!strcmp (format_name, "mov")) {
2890 static enum CodecID mov_video_list[] = {
2891 CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_MPEG4,
2892 CODEC_ID_H263, CODEC_ID_H263P,
2893 CODEC_ID_H264, CODEC_ID_DVVIDEO,
2897 static enum CodecID mov_audio_list[] = {
2898 CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, CODEC_ID_ADPCM_IMA_QT,
2899 CODEC_ID_MACE3, CODEC_ID_MACE6, CODEC_ID_AAC,
2900 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2901 CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE,
2902 CODEC_ID_MP3, CODEC_ID_NONE
2905 *video_codec_list = mov_video_list;
2906 *audio_codec_list = mov_audio_list;
2907 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
2908 static enum CodecID tgp_video_list[] = {
2909 CODEC_ID_MPEG4, CODEC_ID_H263, CODEC_ID_H263P, CODEC_ID_H264,
2912 static enum CodecID tgp_audio_list[] = {
2913 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2918 *video_codec_list = tgp_video_list;
2919 *audio_codec_list = tgp_audio_list;
2920 } else if (!strcmp (format_name, "mmf")) {
2921 static enum CodecID mmf_audio_list[] = {
2922 CODEC_ID_ADPCM_YAMAHA, CODEC_ID_NONE
2924 *video_codec_list = NULL;
2925 *audio_codec_list = mmf_audio_list;
2926 } else if (!strcmp (format_name, "amr")) {
2927 static enum CodecID amr_audio_list[] = {
2928 CODEC_ID_AMR_NB, CODEC_ID_AMR_WB,
2931 *video_codec_list = NULL;
2932 *audio_codec_list = amr_audio_list;
2933 } else if (!strcmp (format_name, "gif")) {
2934 static enum CodecID gif_image_list[] = {
2935 CODEC_ID_RAWVIDEO, CODEC_ID_NONE
2937 *video_codec_list = gif_image_list;
2938 *audio_codec_list = NULL;
2939 } else if ((plugin->audio_codec != CODEC_ID_NONE) ||
2940 (plugin->video_codec != CODEC_ID_NONE)) {
2941 tmp_vlist[0] = plugin->video_codec;
2942 tmp_alist[0] = plugin->audio_codec;
2944 *video_codec_list = tmp_vlist;
2945 *audio_codec_list = tmp_alist;
2947 GST_LOG ("Format %s not found", format_name);
2954 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
2955 * are omitted, that can be queried by the user itself,
2956 * we're not eating the GstCaps or anything
2957 * A pointer to an allocated context is also needed for
2958 * optional extra info
2962 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
2964 enum CodecID id = CODEC_ID_NONE;
2965 const gchar *mimetype;
2966 const GstStructure *structure;
2967 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
2969 g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
2970 g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
2971 structure = gst_caps_get_structure (caps, 0);
2973 mimetype = gst_structure_get_name (structure);
2975 if (!strcmp (mimetype, "video/x-raw")) {
2976 id = CODEC_ID_RAWVIDEO;
2978 } else if (!strcmp (mimetype, "audio/x-raw")) {
2981 if (gst_audio_info_from_caps (&info, caps)) {
2982 switch (GST_AUDIO_INFO_FORMAT (&info)) {
2983 case GST_AUDIO_FORMAT_S8:
2984 id = CODEC_ID_PCM_S8;
2986 case GST_AUDIO_FORMAT_U8:
2987 id = CODEC_ID_PCM_U8;
2989 case GST_AUDIO_FORMAT_S16LE:
2990 id = CODEC_ID_PCM_S16LE;
2992 case GST_AUDIO_FORMAT_S16BE:
2993 id = CODEC_ID_PCM_S16BE;
2995 case GST_AUDIO_FORMAT_U16LE:
2996 id = CODEC_ID_PCM_U16LE;
2998 case GST_AUDIO_FORMAT_U16BE:
2999 id = CODEC_ID_PCM_U16BE;
3004 if (id != CODEC_ID_NONE)
3007 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3008 id = CODEC_ID_PCM_MULAW;
3010 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3011 id = CODEC_ID_PCM_ALAW;
3013 } else if (!strcmp (mimetype, "video/x-dv")) {
3016 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3018 id = CODEC_ID_DVVIDEO;
3021 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3022 id = CODEC_ID_DVAUDIO;
3024 } else if (!strcmp (mimetype, "video/x-h263")) {
3025 const gchar *h263version =
3026 gst_structure_get_string (structure, "h263version");
3027 if (h263version && !strcmp (h263version, "h263p"))
3028 id = CODEC_ID_H263P;
3032 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3033 id = CODEC_ID_H263I;
3035 } else if (!strcmp (mimetype, "video/x-h261")) {
3038 } else if (!strcmp (mimetype, "video/mpeg")) {
3042 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3043 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3045 switch (mpegversion) {
3047 id = CODEC_ID_MPEG1VIDEO;
3050 id = CODEC_ID_MPEG2VIDEO;
3053 id = CODEC_ID_MPEG4;
3057 if (id != CODEC_ID_NONE)
3059 } else if (!strcmp (mimetype, "image/jpeg")) {
3060 id = CODEC_ID_MJPEG; /* A... B... */
3062 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3063 id = CODEC_ID_MJPEGB;
3065 } else if (!strcmp (mimetype, "video/x-wmv")) {
3066 gint wmvversion = 0;
3068 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3069 switch (wmvversion) {
3078 const gchar *format;
3080 /* WMV3 unless the fourcc exists and says otherwise */
3083 if ((format = gst_structure_get_string (structure, "format")) &&
3084 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3091 if (id != CODEC_ID_NONE)
3093 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3094 id = CODEC_ID_VORBIS;
3096 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3099 } else if (!strcmp (mimetype, "audio/mpeg")) {
3101 gint mpegversion = 0;
3103 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3104 switch (mpegversion) {
3105 case 2: /* ffmpeg uses faad for both... */
3110 if (gst_structure_get_int (structure, "layer", &layer)) {
3125 if (id != CODEC_ID_NONE)
3127 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3128 gint streamversion = -1;
3130 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3131 if (streamversion == 7)
3132 id = CODEC_ID_MUSEPACK7;
3134 id = CODEC_ID_MUSEPACK7;
3136 } else if (!strcmp (mimetype, "audio/x-wma")) {
3137 gint wmaversion = 0;
3139 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3140 switch (wmaversion) {
3142 id = CODEC_ID_WMAV1;
3145 id = CODEC_ID_WMAV2;
3148 id = CODEC_ID_WMAPRO;
3152 if (id != CODEC_ID_NONE)
3154 } else if (!strcmp (mimetype, "audio/x-wms")) {
3155 id = CODEC_ID_WMAVOICE;
3157 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3160 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3163 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3164 !strcmp (mimetype, "audio/atrac3")) {
3165 id = CODEC_ID_ATRAC3;
3167 } else if (!strcmp (mimetype, "audio/x-dts")) {
3170 } else if (!strcmp (mimetype, "application/x-ape")) {
3173 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3174 gint msmpegversion = 0;
3176 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3177 switch (msmpegversion) {
3179 id = CODEC_ID_MSMPEG4V1;
3182 id = CODEC_ID_MSMPEG4V2;
3185 id = CODEC_ID_MSMPEG4V3;
3189 if (id != CODEC_ID_NONE)
3191 } else if (!strcmp (mimetype, "video/x-svq")) {
3192 gint svqversion = 0;
3194 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3195 switch (svqversion) {
3204 if (id != CODEC_ID_NONE)
3206 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3207 id = CODEC_ID_HUFFYUV;
3209 } else if (!strcmp (mimetype, "audio/x-mace")) {
3210 gint maceversion = 0;
3212 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3213 switch (maceversion) {
3215 id = CODEC_ID_MACE3;
3218 id = CODEC_ID_MACE6;
3222 if (id != CODEC_ID_NONE)
3224 } else if (!strcmp (mimetype, "video/x-theora")) {
3225 id = CODEC_ID_THEORA;
3227 } else if (!strcmp (mimetype, "video/x-vp3")) {
3230 } else if (!strcmp (mimetype, "video/x-vp5")) {
3233 } else if (!strcmp (mimetype, "video/x-vp6")) {
3236 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3239 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3242 } else if (!strcmp (mimetype, "video/x-vp8")) {
3245 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3246 id = CODEC_ID_FLASHSV;
3248 } else if (!strcmp (mimetype, "video/x-indeo")) {
3249 gint indeoversion = 0;
3251 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3252 switch (indeoversion) {
3254 id = CODEC_ID_INDEO5;
3257 id = CODEC_ID_INDEO4;
3260 id = CODEC_ID_INDEO3;
3263 id = CODEC_ID_INDEO2;
3266 if (id != CODEC_ID_NONE)
3269 } else if (!strcmp (mimetype, "video/x-divx")) {
3270 gint divxversion = 0;
3272 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3273 switch (divxversion) {
3275 id = CODEC_ID_MSMPEG4V3;
3279 id = CODEC_ID_MPEG4;
3283 if (id != CODEC_ID_NONE)
3285 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3286 id = CODEC_ID_MPEG4;
3288 } else if (!strcmp (mimetype, "video/x-xvid")) {
3289 id = CODEC_ID_MPEG4;
3291 } else if (!strcmp (mimetype, "video/x-ffv")) {
3292 gint ffvversion = 0;
3294 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3299 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3300 const gchar *layout;
3302 layout = gst_structure_get_string (structure, "layout");
3303 if (layout == NULL) {
3305 } else if (!strcmp (layout, "quicktime")) {
3306 id = CODEC_ID_ADPCM_IMA_QT;
3307 } else if (!strcmp (layout, "microsoft")) {
3308 id = CODEC_ID_ADPCM_MS;
3309 } else if (!strcmp (layout, "dvi")) {
3310 id = CODEC_ID_ADPCM_IMA_WAV;
3311 } else if (!strcmp (layout, "4xm")) {
3312 id = CODEC_ID_ADPCM_4XM;
3313 } else if (!strcmp (layout, "smjpeg")) {
3314 id = CODEC_ID_ADPCM_IMA_SMJPEG;
3315 } else if (!strcmp (layout, "dk3")) {
3316 id = CODEC_ID_ADPCM_IMA_DK3;
3317 } else if (!strcmp (layout, "dk4")) {
3318 id = CODEC_ID_ADPCM_IMA_DK4;
3319 } else if (!strcmp (layout, "westwood")) {
3320 id = CODEC_ID_ADPCM_IMA_WS;
3321 } else if (!strcmp (layout, "iss")) {
3322 id = CODEC_ID_ADPCM_IMA_ISS;
3323 } else if (!strcmp (layout, "xa")) {
3324 id = CODEC_ID_ADPCM_XA;
3325 } else if (!strcmp (layout, "adx")) {
3326 id = CODEC_ID_ADPCM_ADX;
3327 } else if (!strcmp (layout, "ea")) {
3328 id = CODEC_ID_ADPCM_EA;
3329 } else if (!strcmp (layout, "g726")) {
3330 id = CODEC_ID_ADPCM_G726;
3331 } else if (!strcmp (layout, "g721")) {
3332 id = CODEC_ID_ADPCM_G726;
3333 } else if (!strcmp (layout, "ct")) {
3334 id = CODEC_ID_ADPCM_CT;
3335 } else if (!strcmp (layout, "swf")) {
3336 id = CODEC_ID_ADPCM_SWF;
3337 } else if (!strcmp (layout, "yamaha")) {
3338 id = CODEC_ID_ADPCM_YAMAHA;
3339 } else if (!strcmp (layout, "sbpro2")) {
3340 id = CODEC_ID_ADPCM_SBPRO_2;
3341 } else if (!strcmp (layout, "sbpro3")) {
3342 id = CODEC_ID_ADPCM_SBPRO_3;
3343 } else if (!strcmp (layout, "sbpro4")) {
3344 id = CODEC_ID_ADPCM_SBPRO_4;
3346 if (id != CODEC_ID_NONE)
3348 } else if (!strcmp (mimetype, "video/x-4xm")) {
3351 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3352 const gchar *layout;
3354 layout = gst_structure_get_string (structure, "layout");
3357 } else if (!strcmp (layout, "roq")) {
3358 id = CODEC_ID_ROQ_DPCM;
3359 } else if (!strcmp (layout, "interplay")) {
3360 id = CODEC_ID_INTERPLAY_DPCM;
3361 } else if (!strcmp (layout, "xan")) {
3362 id = CODEC_ID_XAN_DPCM;
3363 } else if (!strcmp (layout, "sol")) {
3364 id = CODEC_ID_SOL_DPCM;
3366 if (id != CODEC_ID_NONE)
3368 } else if (!strcmp (mimetype, "audio/x-flac")) {
3371 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3372 id = CODEC_ID_SHORTEN;
3374 } else if (!strcmp (mimetype, "audio/x-alac")) {
3377 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3378 id = CODEC_ID_CINEPAK;
3380 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3383 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3384 switch (rmversion) {
3399 if (id != CODEC_ID_NONE)
3401 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3404 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3407 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3408 switch (raversion) {
3410 id = CODEC_ID_RA_144;
3413 id = CODEC_ID_RA_288;
3420 if (id != CODEC_ID_NONE)
3422 } else if (!strcmp (mimetype, "video/x-rle")) {
3423 const gchar *layout;
3425 if ((layout = gst_structure_get_string (structure, "layout"))) {
3426 if (!strcmp (layout, "microsoft")) {
3427 id = CODEC_ID_MSRLE;
3431 } else if (!strcmp (mimetype, "video/x-xan")) {
3434 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3435 switch (wcversion) {
3437 id = CODEC_ID_XAN_WC3;
3441 id = CODEC_ID_XAN_WC4;
3448 } else if (!strcmp (mimetype, "audio/AMR")) {
3450 id = CODEC_ID_AMR_NB;
3451 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3452 id = CODEC_ID_AMR_WB;
3454 } else if (!strcmp (mimetype, "audio/qcelp")) {
3455 id = CODEC_ID_QCELP;
3457 } else if (!strcmp (mimetype, "video/x-h264")) {
3460 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3461 gint flvversion = 0;
3463 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3464 switch (flvversion) {
3474 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3475 id = CODEC_ID_NELLYMOSER;
3477 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3481 if (strlen (mimetype) <= 30 &&
3482 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3483 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3484 (codec = avcodec_find_encoder_by_name (ext))) {
3489 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3493 if (strlen (mimetype) <= 30 &&
3494 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3495 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3496 (codec = avcodec_find_encoder_by_name (ext))) {
3503 if (context != NULL) {
3504 if (video == TRUE) {
3505 context->codec_type = AVMEDIA_TYPE_VIDEO;
3506 } else if (audio == TRUE) {
3507 context->codec_type = AVMEDIA_TYPE_AUDIO;
3509 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3511 context->codec_id = id;
3512 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3515 if (id != CODEC_ID_NONE) {
3516 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3518 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);