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.
26
#ifdef HAVE_FFMPEG_UNINSTALLED
29
#include <ffmpeg/avcodec.h>
33
#include "gstffmpeg.h"
34
#include "gstffmpegcodecmap.h"
37
* Read a palette from a caps.
41
gst_ffmpeg_get_palette (const GstCaps *caps, AVCodecContext *context)
43
GstStructure *str = gst_caps_get_structure (caps, 0);
44
const GValue *palette_v;
45
const GstBuffer *palette;
47
/* do we have a palette? */
48
if ((palette_v = gst_structure_get_value (str,
49
"palette_data")) && context) {
50
palette = g_value_get_boxed (palette_v);
51
if (GST_BUFFER_SIZE (palette) >= 256 * 4) {
53
av_free (context->palctrl);
54
context->palctrl = av_malloc (sizeof (AVPaletteControl));
55
context->palctrl->palette_changed = 1;
56
memcpy (context->palctrl->palette, GST_BUFFER_DATA (palette),
63
gst_ffmpeg_set_palette (GstCaps *caps, AVCodecContext *context)
65
if (context->palctrl) {
66
GstBuffer *palette = gst_buffer_new_and_alloc (256 * 4);
68
memcpy (GST_BUFFER_DATA (palette), context->palctrl->palette,
70
gst_caps_set_simple (caps,
71
"palette_data", GST_TYPE_BUFFER, palette, NULL);
75
/* this macro makes a caps width fixed or unfixed width/height
76
* properties depending on whether we've got a context.
78
* See below for why we use this.
80
* We should actually do this stuff at the end, like in riff-media.c,
81
* but I'm too lazy today. Maybe later.
84
#define GST_FF_VID_CAPS_NEW(mimetype, ...) \
86
gst_caps_new_simple (mimetype, \
87
"width", G_TYPE_INT, context->width, \
88
"height", G_TYPE_INT, context->height, \
89
"framerate", GST_TYPE_FRACTION, context->time_base.den, \
90
context->time_base.num, __VA_ARGS__, NULL) \
92
gst_caps_new_simple (mimetype, \
93
"width", GST_TYPE_INT_RANGE, 16, 4096, \
94
"height", GST_TYPE_INT_RANGE, 16, 4096, \
95
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, \
96
G_MAXINT, 1, __VA_ARGS__, NULL)
98
/* same for audio - now with channels/sample rate
101
#define GST_FF_AUD_CAPS_NEW(mimetype, ...) \
102
(context != NULL) ? \
103
gst_caps_new_simple (mimetype, \
104
"rate", G_TYPE_INT, context->sample_rate, \
105
"channels", G_TYPE_INT, context->channels, \
108
gst_caps_new_simple (mimetype, \
109
"rate", GST_TYPE_INT_RANGE, 8000, 96000, \
110
"channels", GST_TYPE_INT_RANGE, 1, 2, \
113
/* Convert a FFMPEG codec ID and optional AVCodecContext
114
* to a GstCaps. If the context is ommitted, no fixed values
115
* for video/audio size will be included in the GstCaps
117
* CodecID is primarily meant for compressed data GstCaps!
119
* encode is a special parameter. gstffmpegdec will say
120
* FALSE, gstffmpegenc will say TRUE. The output caps
121
* depends on this, in such a way that it will be very
122
* specific, defined, fixed and correct caps for encoders,
123
* yet very wide, "forgiving" caps for decoders. Example
124
* for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
125
* but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
130
gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
131
AVCodecContext * context, gboolean encode)
133
GstCaps *caps = NULL;
134
gboolean buildcaps = FALSE;
137
case CODEC_ID_MPEG1VIDEO:
138
/* For decoding, CODEC_ID_MPEG2VIDEO is preferred... So omit here */
141
caps = GST_FF_VID_CAPS_NEW ("video/mpeg",
142
"mpegversion", G_TYPE_INT, 1,
143
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
147
case CODEC_ID_MPEG2VIDEO:
150
caps = GST_FF_VID_CAPS_NEW ("video/mpeg",
151
"mpegversion", G_TYPE_INT, 2,
152
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
154
/* decode both MPEG-1 and MPEG-2; width/height/fps are all in
155
* the MPEG video stream headers, so may be omitted from caps. */
156
caps = gst_caps_new_simple ("video/mpeg",
157
"mpegversion", GST_TYPE_INT_RANGE, 1, 2,
158
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
162
case CODEC_ID_MPEG2VIDEO_XVMC:
163
/* this is a special ID - don't need it in GStreamer, I think */
166
/* I don't know the exact differences between those... Anyone? */
169
caps = GST_FF_VID_CAPS_NEW ("video/x-h263", NULL);
173
caps = GST_FF_VID_CAPS_NEW ("video/x-intel-h263", NULL);
177
caps = GST_FF_VID_CAPS_NEW ("video/x-h261", NULL);
183
gint version = (codec_id == CODEC_ID_RV10) ? 1 : 2;
185
/* FIXME: context->sub_id must be filled in during decoding */
186
caps = GST_FF_VID_CAPS_NEW ("video/x-pn-realvideo",
187
"systemstream", G_TYPE_BOOLEAN, FALSE,
188
"rmversion", G_TYPE_INT, version, NULL);
190
gst_caps_set_simple (caps,
191
"rmsubid", GST_TYPE_FOURCC, context->sub_id, NULL);
197
/* we use CODEC_ID_MP3 for decoding */
200
caps = GST_FF_AUD_CAPS_NEW ("audio/mpeg",
201
"mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
208
caps = GST_FF_AUD_CAPS_NEW ("audio/mpeg",
209
"mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
211
/* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
212
* in the MPEG audio header, so may be omitted from caps. */
213
caps = gst_caps_new_simple ("audio/mpeg",
214
"mpegversion", G_TYPE_INT, 1,
215
"layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
219
case CODEC_ID_VORBIS:
220
/* This one is disabled for several reasons:
221
* - GStreamer already has perfect Ogg and Vorbis support
222
* - The ffmpeg implementation depends on libvorbis/libogg,
223
* which are not included in the ffmpeg that GStreamer ships.
224
* - The ffmpeg implementation depends on shared objects between
225
* the ogg demuxer and vorbis decoder, which GStreamer doesn't.
230
/* Decoding is disabled, because:
231
* - it depends on liba52, which we don't ship in ffmpeg.
232
* - we already have a liba52 plugin ourselves.
236
caps = GST_FF_AUD_CAPS_NEW ("audio/x-ac3", NULL);
240
/* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
241
* is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
242
* sp5x is, but it's apparently something JPEG... We don't separate
243
* between those in GStreamer. Should we (at least between MJPEG,
244
* MJPEG-B and sp5x decoding...)? */
248
caps = GST_FF_VID_CAPS_NEW ("image/jpeg", NULL);
251
case CODEC_ID_MJPEGB:
252
caps = GST_FF_VID_CAPS_NEW ("video/x-mjpeg-b", NULL);
256
if (encode && context != NULL) {
257
/* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
258
* the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
259
switch (context->codec_tag) {
260
case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
261
caps = GST_FF_VID_CAPS_NEW ("video/x-divx",
262
"divxversion", G_TYPE_INT, 5, NULL);
264
case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
267
caps = GST_FF_VID_CAPS_NEW ("video/mpeg",
268
"systemstream", G_TYPE_BOOLEAN, FALSE,
269
"mpegversion", G_TYPE_INT, 4, NULL);
273
/* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
274
caps = GST_FF_VID_CAPS_NEW ("video/mpeg",
275
"mpegversion", G_TYPE_INT, 4,
276
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
278
gst_caps_append (caps, GST_FF_VID_CAPS_NEW ("video/x-divx",
279
"divxversion", G_TYPE_INT, 5, NULL));
281
gst_caps_append (caps, GST_FF_VID_CAPS_NEW ("video/x-divx",
282
"divxversion", GST_TYPE_INT_RANGE, 4, 5, NULL));
283
gst_caps_append (caps, GST_FF_VID_CAPS_NEW ("video/x-xvid", NULL));
284
gst_caps_append (caps, GST_FF_VID_CAPS_NEW ("video/x-3ivx", NULL));
289
case CODEC_ID_RAWVIDEO:
290
caps = gst_ffmpeg_codectype_to_caps (CODEC_TYPE_VIDEO, context);
293
case CODEC_ID_MSMPEG4V1:
294
case CODEC_ID_MSMPEG4V2:
295
case CODEC_ID_MSMPEG4V3:
297
gint version = 41 + codec_id - CODEC_ID_MSMPEG4V1;
299
/* encode-FIXME: bitrate */
300
caps = GST_FF_VID_CAPS_NEW ("video/x-msmpeg",
301
"msmpegversion", G_TYPE_INT, version, NULL);
302
if (!encode && codec_id == CODEC_ID_MSMPEG4V3) {
303
gst_caps_append (caps, GST_FF_VID_CAPS_NEW ("video/x-divx",
304
"divxversion", G_TYPE_INT, 3, NULL));
312
gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2;
314
caps = GST_FF_VID_CAPS_NEW ("video/x-wmv",
315
"wmvversion", G_TYPE_INT, version, NULL);
324
caps = GST_FF_VID_CAPS_NEW ("video/x-svq",
325
"svqversion", G_TYPE_INT, 1, NULL);
329
caps = GST_FF_VID_CAPS_NEW ("video/x-svq",
330
"svqversion", G_TYPE_INT, 3, NULL);
333
case CODEC_ID_DVAUDIO:
334
caps = GST_FF_AUD_CAPS_NEW ("audio/x-dv", NULL);
337
case CODEC_ID_DVVIDEO:
338
caps = GST_FF_VID_CAPS_NEW ("video/x-dv",
339
"systemstream", G_TYPE_BOOLEAN, FALSE,
346
gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2;
349
caps = GST_FF_AUD_CAPS_NEW ("audio/x-wma",
350
"wmaversion", G_TYPE_INT, version,
351
"block_align", G_TYPE_INT, context->block_align,
352
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
354
caps = GST_FF_AUD_CAPS_NEW ("audio/x-wma",
355
"wmaversion", G_TYPE_INT, version,
356
"block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT,
357
"bitrate", GST_TYPE_INT_RANGE, 0, G_MAXINT, NULL);
365
gint version = (codec_id == CODEC_ID_MACE3) ? 3 : 6;
367
caps = GST_FF_AUD_CAPS_NEW ("audio/x-mace",
368
"maceversion", G_TYPE_INT, version, NULL);
372
case CODEC_ID_HUFFYUV:
373
caps = GST_FF_VID_CAPS_NEW ("video/x-huffyuv", NULL);
375
gst_caps_set_simple (caps,
376
"bpp", G_TYPE_INT, context->bits_per_sample, NULL);
385
caps = GST_FF_VID_CAPS_NEW ("video/x-h264", NULL);
388
case CODEC_ID_INDEO3:
389
caps = GST_FF_VID_CAPS_NEW ("video/x-indeo",
390
"indeoversion", G_TYPE_INT, 3, NULL);
393
case CODEC_ID_INDEO2:
394
caps = GST_FF_VID_CAPS_NEW ("video/x-indeo",
395
"indeoversion", G_TYPE_INT, 2, NULL);
399
caps = GST_FF_VID_CAPS_NEW ("video/x-vp3", NULL);
402
case CODEC_ID_THEORA:
403
caps = GST_FF_VID_CAPS_NEW ("video/x-theora", NULL);
407
case CODEC_ID_MPEG4AAC:
408
caps = GST_FF_AUD_CAPS_NEW ("audio/mpeg",
409
"mpegversion", G_TYPE_INT, 4, NULL);
418
caps = GST_FF_VID_CAPS_NEW ("video/x-ffv",
419
"ffvversion", G_TYPE_INT, 1, NULL);
423
caps = GST_FF_VID_CAPS_NEW ("video/x-4xm", NULL);
426
case CODEC_ID_XAN_WC3:
427
case CODEC_ID_XAN_WC4:
428
caps = GST_FF_VID_CAPS_NEW ("video/x-xan",
429
"wcversion", G_TYPE_INT, 3 - CODEC_ID_XAN_WC3 + codec_id, NULL);
437
case CODEC_ID_INTERPLAY_VIDEO:
442
caps = GST_FF_VID_CAPS_NEW ("video/x-apple-video", NULL);
445
case CODEC_ID_CINEPAK:
446
caps = GST_FF_VID_CAPS_NEW ("video/x-cinepak", NULL);
449
/* WS_VQA belogns here (order) */
452
caps = GST_FF_VID_CAPS_NEW ("video/x-rle",
453
"layout", G_TYPE_STRING, "microsoft", NULL);
455
gst_caps_set_simple (caps,
456
"depth", G_TYPE_INT, (gint) context->bits_per_sample, NULL);
458
gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
463
caps = GST_FF_VID_CAPS_NEW ("video/x-rle",
464
"layout", G_TYPE_STRING, "quicktime", NULL);
466
gst_caps_set_simple (caps,
467
"depth", G_TYPE_INT, (gint) context->bits_per_sample, NULL);
469
gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
473
case CODEC_ID_MSVIDEO1:
474
caps = GST_FF_VID_CAPS_NEW ("video/x-msvideocodec",
475
"msvideoversion", G_TYPE_INT, 1, NULL);
480
caps = GST_FF_VID_CAPS_NEW ("video/x-wmv",
481
"wmvversion", G_TYPE_INT, 3, NULL);
484
caps = GST_FF_AUD_CAPS_NEW ("audio/x-qdm2", NULL);
487
case CODEC_ID_WS_VQA:
492
case CODEC_ID_TRUEMOTION1:
493
case CODEC_ID_TRUEMOTION2:
494
case CODEC_ID_VMDVIDEO:
495
case CODEC_ID_VMDAUDIO:
499
case CODEC_ID_SONIC_LS:
511
case CODEC_ID_PGMYUV:
513
case CODEC_ID_FFVHUFF:
517
case CODEC_ID_MP3ADU:
518
case CODEC_ID_MP3ON4:
519
case CODEC_ID_WESTWOOD_SND1:
523
/* weird quasi-codecs for the demuxers only */
524
case CODEC_ID_PCM_S16LE:
525
case CODEC_ID_PCM_S16BE:
526
case CODEC_ID_PCM_U16LE:
527
case CODEC_ID_PCM_U16BE:
528
case CODEC_ID_PCM_S8:
529
case CODEC_ID_PCM_U8:
531
gint width = 0, depth = 0, endianness = 0;
532
gboolean signedness = FALSE; /* blabla */
535
case CODEC_ID_PCM_S16LE:
538
endianness = G_LITTLE_ENDIAN;
541
case CODEC_ID_PCM_S16BE:
544
endianness = G_BIG_ENDIAN;
547
case CODEC_ID_PCM_U16LE:
550
endianness = G_LITTLE_ENDIAN;
553
case CODEC_ID_PCM_U16BE:
556
endianness = G_BIG_ENDIAN;
559
case CODEC_ID_PCM_S8:
562
endianness = G_BYTE_ORDER;
565
case CODEC_ID_PCM_U8:
568
endianness = G_BYTE_ORDER;
572
g_assert (0); /* don't worry, we never get here */
576
caps = GST_FF_AUD_CAPS_NEW ("audio/x-raw-int",
577
"width", G_TYPE_INT, width,
578
"depth", G_TYPE_INT, depth,
579
"endianness", G_TYPE_INT, endianness,
580
"signed", G_TYPE_BOOLEAN, signedness, NULL);
584
case CODEC_ID_PCM_MULAW:
585
caps = GST_FF_AUD_CAPS_NEW ("audio/x-mulaw", NULL);
588
case CODEC_ID_PCM_ALAW:
589
caps = GST_FF_AUD_CAPS_NEW ("audio/x-alaw", NULL);
592
case CODEC_ID_ADPCM_IMA_QT:
593
case CODEC_ID_ADPCM_IMA_WAV:
594
case CODEC_ID_ADPCM_IMA_DK3:
595
case CODEC_ID_ADPCM_IMA_DK4:
596
case CODEC_ID_ADPCM_IMA_WS:
597
case CODEC_ID_ADPCM_IMA_SMJPEG:
598
case CODEC_ID_ADPCM_MS:
599
case CODEC_ID_ADPCM_4XM:
600
case CODEC_ID_ADPCM_XA:
601
case CODEC_ID_ADPCM_ADX:
602
case CODEC_ID_ADPCM_EA:
603
case CODEC_ID_ADPCM_G726:
604
case CODEC_ID_ADPCM_CT:
605
case CODEC_ID_ADPCM_SWF:
606
case CODEC_ID_ADPCM_YAMAHA:
608
gchar *layout = NULL;
611
case CODEC_ID_ADPCM_IMA_QT:
612
layout = "quicktime";
614
case CODEC_ID_ADPCM_IMA_WAV:
617
case CODEC_ID_ADPCM_IMA_DK3:
620
case CODEC_ID_ADPCM_IMA_DK4:
623
case CODEC_ID_ADPCM_IMA_WS:
626
case CODEC_ID_ADPCM_IMA_SMJPEG:
629
case CODEC_ID_ADPCM_MS:
630
layout = "microsoft";
632
case CODEC_ID_ADPCM_4XM:
635
case CODEC_ID_ADPCM_XA:
638
case CODEC_ID_ADPCM_ADX:
641
case CODEC_ID_ADPCM_EA:
644
case CODEC_ID_ADPCM_G726:
647
case CODEC_ID_ADPCM_CT:
650
case CODEC_ID_ADPCM_SWF:
653
case CODEC_ID_ADPCM_YAMAHA:
657
g_assert (0); /* don't worry, we never get here */
661
/* FIXME: someone please check whether we need additional properties
662
* in this caps definition. */
663
caps = GST_FF_AUD_CAPS_NEW ("audio/x-adpcm",
664
"layout", G_TYPE_STRING, layout, NULL);
666
gst_caps_set_simple (caps,
667
"block_align", G_TYPE_INT, context->block_align,
668
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
672
case CODEC_ID_AMR_NB:
673
caps = GST_FF_AUD_CAPS_NEW ("audio/x-amr-nb", NULL);
676
case CODEC_ID_AMR_WB:
677
caps = GST_FF_AUD_CAPS_NEW ("audio/x-amr-wb", NULL);
680
case CODEC_ID_RA_144:
681
case CODEC_ID_RA_288:
683
gint version = (codec_id == CODEC_ID_RA_144) ? 1 : 2;
685
/* FIXME: properties? */
686
caps = GST_FF_AUD_CAPS_NEW ("audio/x-pn-realaudio",
687
"raversion", G_TYPE_INT, version, NULL);
691
case CODEC_ID_ROQ_DPCM:
692
case CODEC_ID_INTERPLAY_DPCM:
693
case CODEC_ID_XAN_DPCM:
694
case CODEC_ID_SOL_DPCM:
696
gchar *layout = NULL;
699
case CODEC_ID_ROQ_DPCM:
702
case CODEC_ID_INTERPLAY_DPCM:
703
layout = "interplay";
705
case CODEC_ID_XAN_DPCM:
708
case CODEC_ID_SOL_DPCM:
712
g_assert (0); /* don't worry, we never get here */
716
/* FIXME: someone please check whether we need additional properties
717
* in this caps definition. */
718
caps = GST_FF_AUD_CAPS_NEW ("audio/x-dpcm",
719
"layout", G_TYPE_STRING, layout, NULL);
721
gst_caps_set_simple (caps,
722
"block_align", G_TYPE_INT, context->block_align,
723
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
727
case CODEC_ID_SHORTEN:
728
caps = gst_caps_new_simple ("audio/x-shorten", NULL);
732
caps = GST_FF_AUD_CAPS_NEW ("audio/x-alac", NULL);
734
gst_caps_set_simple (caps,
735
"samplesize", G_TYPE_INT, context->bits_per_sample, NULL);
740
/* Note that ffmpeg has no encoder yet, but just for safety. In the
741
* encoder case, we want to add things like samplerate, channels... */
743
caps = gst_caps_new_simple ("audio/x-flac", NULL);
747
case CODEC_ID_DVD_SUBTITLE:
748
case CODEC_ID_DVB_SUBTITLE:
753
g_warning ("Unknown codec ID %d, please add here", codec_id);
760
if ((codec = avcodec_find_decoder (codec_id)) ||
761
(codec = avcodec_find_encoder (codec_id))) {
764
switch (codec->type) {
765
case CODEC_TYPE_VIDEO:
766
mime = g_strdup_printf ("video/x-gst_ff-%s", codec->name);
767
caps = GST_FF_VID_CAPS_NEW (mime, NULL);
770
case CODEC_TYPE_AUDIO:
771
mime = g_strdup_printf ("audio/x-gst_ff-%s", codec->name);
772
caps = GST_FF_AUD_CAPS_NEW (mime, NULL);
774
gst_caps_set_simple (caps,
775
"block_align", G_TYPE_INT, context->block_align,
776
"bitrate", G_TYPE_INT, context->bit_rate, NULL);
787
/* set private data */
788
if (context && context->extradata_size > 0) {
789
GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
791
memcpy (GST_BUFFER_DATA (data), context->extradata,
792
context->extradata_size);
793
gst_caps_set_simple (caps,
794
"codec_data", GST_TYPE_BUFFER, data, NULL);
795
gst_buffer_unref (data);
800
gst_ffmpeg_set_palette (caps, context);
803
GST_DEBUG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
806
GST_WARNING ("No caps found for codec_id=%d", codec_id);
812
/* Convert a FFMPEG Pixel Format and optional AVCodecContext
813
* to a GstCaps. If the context is ommitted, no fixed values
814
* for video/audio size will be included in the GstCaps
816
* See below for usefullness
820
gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context)
822
GstCaps *caps = NULL;
824
int bpp = 0, depth = 0, endianness = 0;
825
gulong g_mask = 0, r_mask = 0, b_mask = 0, a_mask = 0;
829
case PIX_FMT_YUVJ420P:
830
case PIX_FMT_YUV420P:
831
fmt = GST_MAKE_FOURCC ('I', '4', '2', '0');
834
fmt = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
838
endianness = G_BIG_ENDIAN;
845
endianness = G_BIG_ENDIAN;
850
case PIX_FMT_YUVJ422P:
851
case PIX_FMT_YUV422P:
852
fmt = GST_MAKE_FOURCC ('Y', '4', '2', 'B');
854
case PIX_FMT_YUVJ444P:
855
case PIX_FMT_YUV444P:
856
fmt = GST_MAKE_FOURCC ('Y', '4', '4', '4');
861
endianness = G_BIG_ENDIAN;
862
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
874
case PIX_FMT_YUV410P:
875
fmt = GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
877
case PIX_FMT_YUV411P:
878
fmt = GST_MAKE_FOURCC ('Y', '4', '1', 'B');
882
endianness = G_BYTE_ORDER;
890
endianness = G_BYTE_ORDER;
897
endianness = G_BYTE_ORDER;
901
caps = GST_FF_VID_CAPS_NEW ("video/x-raw-gray",
902
"bpp", G_TYPE_INT, bpp,
903
"depth", G_TYPE_INT, depth, NULL);
913
caps = GST_FF_VID_CAPS_NEW ("video/x-raw-rgb",
914
"bpp", G_TYPE_INT, bpp,
915
"depth", G_TYPE_INT, depth,
916
"red_mask", G_TYPE_INT, r_mask,
917
"green_mask", G_TYPE_INT, g_mask,
918
"blue_mask", G_TYPE_INT, b_mask,
919
"endianness", G_TYPE_INT, endianness, NULL);
921
gst_caps_set_simple (caps, "alpha_mask", G_TYPE_INT, a_mask, NULL);
924
caps = GST_FF_VID_CAPS_NEW ("video/x-raw-rgb",
925
"bpp", G_TYPE_INT, bpp,
926
"depth", G_TYPE_INT, depth,
927
"endianness", G_TYPE_INT, endianness, NULL);
929
gst_ffmpeg_set_palette (caps, context);
933
caps = GST_FF_VID_CAPS_NEW ("video/x-raw-yuv",
934
"format", GST_TYPE_FOURCC, fmt, NULL);
939
char *str = gst_caps_to_string (caps);
941
GST_DEBUG ("caps for pix_fmt=%d: %s", pix_fmt, str);
944
GST_WARNING ("No caps found for pix_fmt=%d", pix_fmt);
950
/* Convert a FFMPEG Sample Format and optional AVCodecContext
951
* to a GstCaps. If the context is ommitted, no fixed values
952
* for video/audio size will be included in the GstCaps
954
* See below for usefullness
958
gst_ffmpeg_smpfmt_to_caps (enum SampleFormat sample_fmt,
959
AVCodecContext * context)
961
GstCaps *caps = NULL;
964
gboolean signedness = FALSE;
966
switch (sample_fmt) {
978
caps = GST_FF_AUD_CAPS_NEW ("audio/x-raw-int",
979
"signed", G_TYPE_BOOLEAN, signedness,
980
"endianness", G_TYPE_INT, G_BYTE_ORDER,
981
"width", G_TYPE_INT, bpp, "depth", G_TYPE_INT, bpp, NULL);
985
char *str = gst_caps_to_string (caps);
987
GST_DEBUG ("caps for sample_fmt=%d: %s", sample_fmt, str);
990
GST_WARNING ("No caps found for sample_fmt=%d", sample_fmt);
996
/* Convert a FFMPEG codec Type and optional AVCodecContext
997
* to a GstCaps. If the context is ommitted, no fixed values
998
* for video/audio size will be included in the GstCaps
1000
* CodecType is primarily meant for uncompressed data GstCaps!
1004
gst_ffmpeg_codectype_to_caps (enum CodecType codec_type,
1005
AVCodecContext * context)
1009
switch (codec_type) {
1010
case CODEC_TYPE_VIDEO:
1012
caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt,
1013
context->width == -1 ? NULL : context);
1018
caps = gst_caps_new_empty ();
1019
for (i = 0; i < PIX_FMT_NB; i++) {
1020
temp = gst_ffmpeg_pixfmt_to_caps (i, NULL);
1022
gst_caps_append (caps, temp);
1028
case CODEC_TYPE_AUDIO:
1030
caps = gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context);
1033
enum SampleFormat i;
1035
caps = gst_caps_new_empty ();
1036
for (i = 0; i <= SAMPLE_FMT_S16; i++) {
1037
temp = gst_ffmpeg_smpfmt_to_caps (i, NULL);
1039
gst_caps_append (caps, temp);
1054
/* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
1055
* and other audio properties in a AVCodecContext.
1057
* For usefullness, see below
1061
gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
1062
AVCodecContext * context, gboolean raw)
1064
GstStructure *structure;
1065
gint depth = 0, width = 0, endianness = 0;
1066
gboolean signedness = FALSE;
1068
g_return_if_fail (gst_caps_get_size (caps) == 1);
1069
structure = gst_caps_get_structure (caps, 0);
1071
gst_structure_get_int (structure, "channels", &context->channels);
1072
gst_structure_get_int (structure, "rate", &context->sample_rate);
1073
gst_structure_get_int (structure, "block_align", &context->block_align);
1074
gst_structure_get_int (structure, "bitrate", &context->bit_rate);
1079
if (gst_structure_get_int (structure, "width", &width) &&
1080
gst_structure_get_int (structure, "depth", &depth) &&
1081
gst_structure_get_int (structure, "signed", &signedness) &&
1082
gst_structure_get_int (structure, "endianness", &endianness)) {
1083
if (width == 16 && depth == 16 &&
1084
endianness == G_BYTE_ORDER && signedness == TRUE) {
1085
context->sample_fmt = SAMPLE_FMT_S16;
1091
/* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
1092
* and other video properties in a AVCodecContext.
1094
* For usefullness, see below
1098
gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
1099
AVCodecContext * context, gboolean raw)
1101
GstStructure *structure;
1104
g_return_if_fail (gst_caps_get_size (caps) == 1);
1105
structure = gst_caps_get_structure (caps, 0);
1107
gst_structure_get_int (structure, "width", &context->width);
1108
gst_structure_get_int (structure, "height", &context->height);
1109
gst_structure_get_int (structure, "bpp", &context->bits_per_sample);
1111
fps = gst_structure_get_value (structure, "framerate");
1112
if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
1114
/* somehow these seem mixed up.. */
1115
context->time_base.den = gst_value_get_fraction_numerator (fps);
1116
context->time_base.num = gst_value_get_fraction_denominator (fps);
1118
GST_DEBUG ("setting framerate %d/%d = %lf",
1119
context->time_base.den, context->time_base.num,
1120
1. * context->time_base.den / context->time_base.num);
1126
g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
1128
if (strcmp (gst_structure_get_name (structure), "video/x-raw-yuv") == 0) {
1131
if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
1133
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
1134
context->pix_fmt = PIX_FMT_YUV422;
1136
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
1137
context->pix_fmt = PIX_FMT_YUV420P;
1139
case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
1140
context->pix_fmt = PIX_FMT_YUV411P;
1142
case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
1143
context->pix_fmt = PIX_FMT_YUV422P;
1145
case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
1146
context->pix_fmt = PIX_FMT_YUV410P;
1150
context->pix_fmt = PIX_FMT_YUV444P;
1155
} else if (strcmp (gst_structure_get_name (structure),
1156
"video/x-raw-rgb") == 0) {
1157
gint bpp = 0, rmask = 0, endianness = 0;
1159
if (gst_structure_get_int (structure, "bpp", &bpp) &&
1160
gst_structure_get_int (structure, "endianness", &endianness)) {
1161
if (gst_structure_get_int (structure, "red_mask", &rmask)) {
1164
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
1165
if (rmask == 0x00ff0000)
1167
if (rmask == 0x0000ff00)
1169
context->pix_fmt = PIX_FMT_RGBA32;
1172
if (rmask == 0x0000FF)
1173
context->pix_fmt = PIX_FMT_BGR24;
1175
context->pix_fmt = PIX_FMT_RGB24;
1178
if (endianness == G_BYTE_ORDER)
1179
context->pix_fmt = PIX_FMT_RGB565;
1182
if (endianness == G_BYTE_ORDER)
1183
context->pix_fmt = PIX_FMT_RGB555;
1191
context->pix_fmt = PIX_FMT_PAL8;
1192
gst_ffmpeg_get_palette (caps, context);
1199
/* Convert a GstCaps and a FFMPEG codec Type to a
1200
* AVCodecContext. If the context is ommitted, no fixed values
1201
* for video/audio size will be included in the context
1203
* CodecType is primarily meant for uncompressed data GstCaps!
1207
gst_ffmpeg_caps_with_codectype (enum CodecType type,
1208
const GstCaps * caps, AVCodecContext * context)
1210
if (context == NULL)
1214
case CODEC_TYPE_VIDEO:
1215
gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
1218
case CODEC_TYPE_AUDIO:
1219
gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
1229
* caps_with_codecid () transforms a GstCaps for a known codec
1230
* ID into a filled-in context.
1234
gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
1235
enum CodecType codec_type, const GstCaps *caps, AVCodecContext *context)
1237
GstStructure *str = gst_caps_get_structure (caps, 0);
1238
const GValue *value;
1239
const GstBuffer *buf;
1244
/* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
1245
if ((value = gst_structure_get_value (str, "codec_data"))) {
1246
buf = GST_BUFFER (gst_value_get_mini_object (value));
1247
context->extradata = av_mallocz (GST_BUFFER_SIZE (buf));
1248
memcpy (context->extradata, GST_BUFFER_DATA (buf),
1249
GST_BUFFER_SIZE (buf));
1250
context->extradata_size = GST_BUFFER_SIZE (buf);
1254
case CODEC_ID_MPEG4:
1256
const gchar *mime = gst_structure_get_name (str);
1258
if (!strcmp (mime, "video/x-divx"))
1259
context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
1260
else if (!strcmp (mime, "video/x-xvid"))
1261
context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
1262
else if (!strcmp (mime, "video/x-3ivx"))
1263
context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
1264
else if (!strcmp (mime, "video/mpeg"))
1265
context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
1270
/* FIXME: this is a workaround for older gst-plugins releases
1271
* (<= 0.8.9). This should be removed at some point, because
1272
* it causes wrong decoded frame order. */
1273
if (!context->extradata) {
1274
gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
1277
if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
1278
gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
1279
gst_structure_get_int (str, "low_delay", &low_delay) ||
1280
gst_structure_get_int (str, "unknown_svq3_flag",
1281
&unknown_svq3_flag)) {
1282
context->extradata = (guint8 *) av_mallocz (0x64);
1283
g_stpcpy (context->extradata, "SVQ3");
1287
flags |= unknown_svq3_flag;
1289
flags |= halfpel_flag;
1291
flags |= thirdpel_flag;
1294
flags = GUINT16_FROM_LE (flags);
1296
memcpy (context->extradata + 0x62, &flags, 2);
1297
context->extradata_size = 0x64;
1302
case CODEC_ID_MSRLE:
1303
case CODEC_ID_QTRLE:
1307
if (gst_structure_get_int (str, "depth", &depth))
1308
context->bits_per_sample = depth;
1317
if (gst_structure_get_fourcc (str, "rmsubid", &fourcc))
1318
context->sub_id = fourcc;
1323
gst_structure_get_int (str, "samplesize", &context->bits_per_sample);
1330
if (!gst_caps_is_fixed (caps))
1333
/* common properties (width, height, fps) */
1334
switch (codec_type) {
1335
case CODEC_TYPE_VIDEO:
1336
gst_ffmpeg_caps_to_pixfmt (caps, context, codec_id == CODEC_ID_RAWVIDEO);
1337
gst_ffmpeg_get_palette (caps, context);
1339
case CODEC_TYPE_AUDIO:
1340
gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
1347
/* _formatid_to_caps () is meant for muxers/demuxers, it
1348
* transforms a name (ffmpeg way of ID'ing these, why don't
1349
* they have unique numerical IDs?) to the corresponding
1350
* caps belonging to that mux-format
1352
* Note: we don't need any additional info because the caps
1353
* isn't supposed to contain any useful info besides the
1358
gst_ffmpeg_formatid_to_caps (const gchar * format_name)
1360
GstCaps *caps = NULL;
1362
if (!strcmp (format_name, "mpeg")) {
1363
caps = gst_caps_new_simple ("video/mpeg",
1364
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
1365
} else if (!strcmp (format_name, "mpegts")) {
1366
caps = gst_caps_new_simple ("video/mpegts",
1367
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
1368
} else if (!strcmp (format_name, "rm")) {
1369
caps = gst_caps_new_simple ("application/x-pn-realmedia",
1370
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
1371
} else if (!strcmp (format_name, "asf")) {
1372
caps = gst_caps_new_simple ("video/x-ms-asf", NULL);
1373
} else if (!strcmp (format_name, "avi")) {
1374
caps = gst_caps_new_simple ("video/x-msvideo", NULL);
1375
} else if (!strcmp (format_name, "wav")) {
1376
caps = gst_caps_new_simple ("audio/x-wav", NULL);
1377
} else if (!strcmp (format_name, "swf")) {
1378
caps = gst_caps_new_simple ("application/x-shockwave-flash", NULL);
1379
} else if (!strcmp (format_name, "au")) {
1380
caps = gst_caps_new_simple ("audio/x-au", NULL);
1381
} else if (!strcmp (format_name, "mov_mp4_m4a_3gp")) {
1382
caps = gst_caps_new_simple ("video/quicktime", NULL);
1383
} else if (!strcmp (format_name, "dv")) {
1384
caps = gst_caps_new_simple ("video/x-dv",
1385
"systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
1386
} else if (!strcmp (format_name, "4xm")) {
1387
caps = gst_caps_new_simple ("video/x-4xm", NULL);
1388
} else if (!strcmp (format_name, "matroska")) {
1389
caps = gst_caps_new_simple ("video/x-matroska", NULL);
1390
} else if (!strcmp (format_name, "mp3")) {
1391
caps = gst_caps_new_simple ("application/x-id3", NULL);
1392
} else if (!strcmp (format_name, "flic")) {
1393
caps = gst_caps_new_simple ("video/x-fli", NULL);
1394
} else if (!strcmp (format_name, "flv")) {
1395
caps = gst_caps_new_simple ("video/x-flv", NULL);
1399
GST_WARNING ("Could not create stream format caps for %s", format_name);
1400
name = g_strdup_printf ("application/x-gst_ff-%s", format_name);
1401
caps = gst_caps_new_simple (name, NULL);
1409
gst_ffmpeg_formatid_get_codecids (const gchar *format_name,
1410
enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list)
1412
if (!strcmp (format_name, "mp4")) {
1413
static enum CodecID mp4_video_list[] = { CODEC_ID_MPEG4, CODEC_ID_H264, CODEC_ID_NONE };
1414
static enum CodecID mp4_audio_list[] = { CODEC_ID_AAC, CODEC_ID_NONE };
1416
*video_codec_list = mp4_video_list;
1417
*audio_codec_list = mp4_audio_list;
1418
} else if (!strcmp (format_name, "mpeg")) {
1419
static enum CodecID mpeg_video_list[] = { CODEC_ID_MPEG1VIDEO, CODEC_ID_NONE };
1420
static enum CodecID mpeg_audio_list[] = { CODEC_ID_MP2, CODEC_ID_NONE };
1422
*video_codec_list = mpeg_video_list;
1423
*audio_codec_list = mpeg_audio_list;
1424
} else if (!strcmp (format_name, "vob")) {
1425
static enum CodecID vob_video_list[] = { CODEC_ID_MPEG2VIDEO, CODEC_ID_NONE };
1426
static enum CodecID vob_audio_list[] = { CODEC_ID_MP2, CODEC_ID_AC3, CODEC_ID_NONE };
1428
*video_codec_list = vob_video_list;
1429
*audio_codec_list = vob_audio_list;
1430
} else if (!strcmp (format_name, "flv")) {
1431
static enum CodecID flv_video_list[] = { CODEC_ID_FLV1, CODEC_ID_NONE };
1432
static enum CodecID flv_audio_list[] = { CODEC_ID_MP3, CODEC_ID_NONE };
1434
*video_codec_list = flv_video_list;
1435
*audio_codec_list = flv_audio_list;
1437
GST_WARNING ("Format %s not found", format_name);
1444
/* Convert a GstCaps to a FFMPEG codec ID. Size et all
1445
* are omitted, that can be queried by the user itself,
1446
* we're not eating the GstCaps or anything
1447
* A pointer to an allocated context is also needed for
1448
* optional extra info
1452
gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
1454
enum CodecID id = CODEC_ID_NONE;
1455
const gchar *mimetype;
1456
const GstStructure *structure;
1457
gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
1459
g_return_val_if_fail (caps != NULL, CODEC_ID_NONE);
1460
g_return_val_if_fail (gst_caps_get_size (caps) == 1, CODEC_ID_NONE);
1461
structure = gst_caps_get_structure (caps, 0);
1463
mimetype = gst_structure_get_name (structure);
1465
if (!strcmp (mimetype, "video/x-raw-rgb") ||
1466
!strcmp (mimetype, "video/x-raw-yuv")) {
1467
id = CODEC_ID_RAWVIDEO;
1469
} else if (!strcmp (mimetype, "audio/x-raw-int")) {
1470
gint depth, width, endianness;
1471
gboolean signedness;
1473
if (gst_structure_get_int (structure, "endianness", &endianness) &&
1474
gst_structure_get_boolean (structure, "signed", &signedness) &&
1475
gst_structure_get_int (structure, "width", &width) &&
1476
gst_structure_get_int (structure, "depth", &depth) &&
1481
id = CODEC_ID_PCM_S8;
1483
id = CODEC_ID_PCM_U8;
1487
switch (endianness) {
1490
id = CODEC_ID_PCM_S16BE;
1492
id = CODEC_ID_PCM_U16BE;
1495
case G_LITTLE_ENDIAN:
1497
id = CODEC_ID_PCM_S16LE;
1499
id = CODEC_ID_PCM_U16LE;
1505
if (id != CODEC_ID_NONE)
1508
} else if (!strcmp (mimetype, "audio/x-mulaw")) {
1509
id = CODEC_ID_PCM_MULAW;
1511
} else if (!strcmp (mimetype, "audio/x-alaw")) {
1512
id = CODEC_ID_PCM_ALAW;
1514
} else if (!strcmp (mimetype, "video/x-dv")) {
1517
if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
1519
id = CODEC_ID_DVVIDEO;
1522
} else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
1523
id = CODEC_ID_DVAUDIO;
1525
} else if (!strcmp (mimetype, "video/x-h263")) {
1526
id = CODEC_ID_H263; /* or H263P */
1528
} else if (!strcmp (mimetype, "video/x-intel-h263")) {
1529
id = CODEC_ID_H263I;
1531
} else if (!strcmp (mimetype, "video/x-h261")) {
1534
} else if (!strcmp (mimetype, "video/mpeg")) {
1538
if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
1539
gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
1541
switch (mpegversion) {
1543
id = CODEC_ID_MPEG1VIDEO;
1546
id = CODEC_ID_MPEG2VIDEO;
1549
id = CODEC_ID_MPEG4;
1553
if (id != CODEC_ID_NONE)
1555
} else if (!strcmp (mimetype, "image/jpeg")) {
1556
id = CODEC_ID_MJPEG; /* A... B... */
1558
} else if (!strcmp (mimetype, "video/x-jpeg-b")) {
1559
id = CODEC_ID_MJPEGB;
1561
} else if (!strcmp (mimetype, "video/x-wmv")) {
1562
gint wmvversion = 0;
1564
if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
1565
switch (wmvversion) {
1577
if (id != CODEC_ID_NONE)
1579
} else if (!strcmp (mimetype, "audio/x-vorbis")) {
1580
id = CODEC_ID_VORBIS;
1582
} else if (!strcmp (mimetype, "audio/x-qdm2")) {
1585
} else if (!strcmp (mimetype, "audio/mpeg")) {
1587
gint mpegversion = 0;
1589
if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
1590
switch (mpegversion) {
1591
case 2: /* ffmpeg uses faad for both... */
1596
if (gst_structure_get_int (structure, "layer", &layer)) {
1609
if (id != CODEC_ID_NONE)
1611
} else if (!strcmp (mimetype, "audio/x-wma")) {
1612
gint wmaversion = 0;
1614
if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
1615
switch (wmaversion) {
1617
id = CODEC_ID_WMAV1;
1620
id = CODEC_ID_WMAV2;
1624
if (id != CODEC_ID_NONE)
1626
} else if (!strcmp (mimetype, "audio/x-ac3")) {
1629
} else if (!strcmp (mimetype, "video/x-msmpeg")) {
1630
gint msmpegversion = 0;
1632
if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
1633
switch (msmpegversion) {
1635
id = CODEC_ID_MSMPEG4V1;
1638
id = CODEC_ID_MSMPEG4V2;
1641
id = CODEC_ID_MSMPEG4V3;
1645
if (id != CODEC_ID_NONE)
1647
} else if (!strcmp (mimetype, "video/x-svq")) {
1648
gint svqversion = 0;
1650
if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
1651
switch (svqversion) {
1660
if (id != CODEC_ID_NONE)
1662
} else if (!strcmp (mimetype, "video/x-huffyuv")) {
1663
id = CODEC_ID_HUFFYUV;
1665
} else if (!strcmp (mimetype, "audio/x-mace")) {
1666
gint maceversion = 0;
1668
if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
1669
switch (maceversion) {
1671
id = CODEC_ID_MACE3;
1674
id = CODEC_ID_MACE6;
1678
if (id != CODEC_ID_NONE)
1680
} else if (!strcmp (mimetype, "video/x-theora")) {
1681
id = CODEC_ID_THEORA;
1683
} else if (!strcmp (mimetype, "video/x-vp3")) {
1686
} else if (!strcmp (mimetype, "video/x-indeo")) {
1687
gint indeoversion = 0;
1689
if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
1690
switch (indeoversion) {
1692
id = CODEC_ID_INDEO3;
1695
id = CODEC_ID_INDEO2;
1698
if (id != CODEC_ID_NONE)
1701
} else if (!strcmp (mimetype, "video/x-divx")) {
1702
gint divxversion = 0;
1704
if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
1705
switch (divxversion) {
1707
id = CODEC_ID_MSMPEG4V3;
1711
id = CODEC_ID_MPEG4;
1715
if (id != CODEC_ID_NONE)
1717
} else if (!strcmp (mimetype, "video/x-3ivx")) {
1718
id = CODEC_ID_MPEG4;
1720
} else if (!strcmp (mimetype, "video/x-xvid")) {
1721
id = CODEC_ID_MPEG4;
1723
} else if (!strcmp (mimetype, "video/x-ffv")) {
1724
gint ffvversion = 0;
1726
if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
1731
} else if (!strcmp (mimetype, "x-adpcm")) {
1732
const gchar *layout;
1734
layout = gst_structure_get_string (structure, "layout");
1735
if (layout == NULL) {
1737
} else if (!strcmp (layout, "quicktime")) {
1738
id = CODEC_ID_ADPCM_IMA_QT;
1739
} else if (!strcmp (layout, "microsoft")) {
1740
id = CODEC_ID_ADPCM_MS;
1741
} else if (!strcmp (layout, "dvi")) {
1742
id = CODEC_ID_ADPCM_IMA_WAV;
1743
} else if (!strcmp (layout, "4xm")) {
1744
id = CODEC_ID_ADPCM_4XM;
1745
} else if (!strcmp (layout, "smjpeg")) {
1746
id = CODEC_ID_ADPCM_IMA_SMJPEG;
1747
} else if (!strcmp (layout, "dk3")) {
1748
id = CODEC_ID_ADPCM_IMA_DK3;
1749
} else if (!strcmp (layout, "dk4")) {
1750
id = CODEC_ID_ADPCM_IMA_DK4;
1751
} else if (!strcmp (layout, "westwood")) {
1752
id = CODEC_ID_ADPCM_IMA_WS;
1753
} else if (!strcmp (layout, "xa")) {
1754
id = CODEC_ID_ADPCM_XA;
1755
} else if (!strcmp (layout, "adx")) {
1756
id = CODEC_ID_ADPCM_ADX;
1757
} else if (!strcmp (layout, "ea")) {
1758
id = CODEC_ID_ADPCM_EA;
1759
} else if (!strcmp (layout, "g726")) {
1760
id = CODEC_ID_ADPCM_G726;
1761
} else if (!strcmp (layout, "ct")) {
1762
id = CODEC_ID_ADPCM_CT;
1763
} else if (!strcmp (layout, "swf")) {
1764
id = CODEC_ID_ADPCM_SWF;
1765
} else if (!strcmp (layout, "yamaha")) {
1766
id = CODEC_ID_ADPCM_YAMAHA;
1768
if (id != CODEC_ID_NONE)
1770
} else if (!strcmp (mimetype, "video/x-4xm")) {
1773
} else if (!strcmp (mimetype, "audio/x-dpcm")) {
1774
const gchar *layout;
1776
layout = gst_structure_get_string (structure, "layout");
1779
} else if (!strcmp (layout, "roq")) {
1780
id = CODEC_ID_ROQ_DPCM;
1781
} else if (!strcmp (layout, "interplay")) {
1782
id = CODEC_ID_INTERPLAY_DPCM;
1783
} else if (!strcmp (layout, "xan")) {
1784
id = CODEC_ID_XAN_DPCM;
1785
} else if (!strcmp (layout, "sol")) {
1786
id = CODEC_ID_SOL_DPCM;
1788
if (id != CODEC_ID_NONE)
1790
} else if (!strcmp (mimetype, "audio/x-flac")) {
1793
} else if (!strcmp (mimetype, "audio/x-shorten")) {
1794
id = CODEC_ID_SHORTEN;
1796
} else if (!strcmp (mimetype, "audio/x-alac")) {
1799
} else if (!strcmp (mimetype, "video/x-cinepak")) {
1800
id = CODEC_ID_CINEPAK;
1802
} else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
1805
if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
1806
switch (rmversion) {
1815
if (id != CODEC_ID_NONE)
1817
} else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
1820
if (gst_structure_get_int (structure, "raversion", &raversion)) {
1821
switch (raversion) {
1823
id = CODEC_ID_RA_144;
1826
id = CODEC_ID_RA_288;
1830
if (id != CODEC_ID_NONE)
1832
} else if (!strcmp (mimetype, "video/x-rle")) {
1833
const gchar *layout;
1835
if ((layout = gst_structure_get_string (structure, "layout"))) {
1836
if (!strcmp (layout, "microsoft")) {
1837
id = CODEC_ID_MSRLE;
1841
} else if (!strcmp (mimetype, "video/x-xan")) {
1844
if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
1845
switch (wcversion) {
1847
id = CODEC_ID_XAN_WC3;
1851
id = CODEC_ID_XAN_WC4;
1858
} else if (!strcmp (mimetype, "audio/x-amrnb")) {
1860
id = CODEC_ID_AMR_NB;
1861
} else if (!strcmp (mimetype, "audio/x-amrwb")) {
1862
id = CODEC_ID_AMR_WB;
1864
} else if (!strcmp (mimetype, "video/x-h264")) {
1867
} else if (!strncmp (mimetype, "audio/x-gst_ff-", 15) ) {
1870
if (strlen (mimetype) <= 30 &&
1871
sscanf (mimetype, "audio/x-gst_ff-%s", ext) == 1) {
1872
if ((codec = avcodec_find_decoder_by_name (ext)) ||
1873
(codec = avcodec_find_encoder_by_name (ext))) {
1878
} else if (!strncmp (mimetype, "video/x-gst_ff-", 15)) {
1881
if (strlen (mimetype) <= 30 &&
1882
sscanf (mimetype, "video/x-gst_ff-%s", ext) == 1) {
1883
if ((codec = avcodec_find_decoder_by_name (ext)) ||
1884
(codec = avcodec_find_encoder_by_name (ext))) {
1891
if (context != NULL) {
1892
if (video == TRUE) {
1893
context->codec_type = CODEC_TYPE_VIDEO;
1894
} else if (audio == TRUE) {
1895
context->codec_type = CODEC_TYPE_AUDIO;
1897
context->codec_type = CODEC_TYPE_UNKNOWN;
1899
context->codec_id = id;
1900
gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
1903
if (id != CODEC_ID_NONE) {
1904
char *str = gst_caps_to_string (caps);
1906
GST_DEBUG ("The id=%d belongs to the caps %s", id, str);
1913
G_CONST_RETURN gchar *
1914
gst_ffmpeg_get_codecid_longname (enum CodecID codec_id)
1916
const gchar *name = NULL;
1919
case CODEC_ID_MPEG1VIDEO:
1920
name = "MPEG-1 video";
1922
case CODEC_ID_MPEG2VIDEO:
1923
name = "MPEG-2 video";
1926
name = "H.263 video";
1929
name = "H.261 video";
1932
name = "Realvideo 1.0";
1935
name = "Realvideo 2.0";
1938
name = "MPEG-1 layer 2 audio";
1941
name = "MPEG-1 layer 3 audio";
1943
case CODEC_ID_VORBIS:
1944
name = "Vorbis audio";
1947
name = "QDesign Music 2";
1950
name = "AC-3 audio";
1952
case CODEC_ID_MJPEG:
1953
name = "Motion-JPEG";
1955
case CODEC_ID_MJPEGB:
1956
name = "Quicktime Motion-JPEG B";
1958
case CODEC_ID_LJPEG:
1959
name = "Lossless JPEG";
1962
name = "Sp5x-like JPEG";
1964
case CODEC_ID_MPEG4:
1965
name = "MPEG-4 compatible video";
1967
case CODEC_ID_MSMPEG4V1:
1968
name = "Microsoft MPEG-4 v1";
1970
case CODEC_ID_MSMPEG4V2:
1971
name = "Microsoft MPEG-4 v2";
1973
case CODEC_ID_MSMPEG4V3:
1974
name = "Microsoft MPEG-4 v3";
1977
name = "Windows Media Video v7";
1980
name = "Windows Media Video v8";
1983
name = "Windows Media Video v9";
1986
name = "Microsoft Video Codec v1";
1988
case CODEC_ID_H263P:
1989
name = "H.263 (P) video";
1991
case CODEC_ID_H263I:
1992
name = "Intel H.263 video";
1998
name = "Sorensen-1 video";
2001
name = "Sorensen-3 video";
2003
case CODEC_ID_DVVIDEO:
2004
name = "Digital video";
2006
case CODEC_ID_DVAUDIO:
2007
name = "Digital audio";
2009
case CODEC_ID_WMAV1:
2010
name = "Windows Media Audio v7";
2012
case CODEC_ID_WMAV2:
2013
name = "Windows Media Audio v8/9";
2015
case CODEC_ID_MACE3:
2016
name = "MACE-3 audio";
2018
case CODEC_ID_MACE6:
2019
name = "MACE-6 audio";
2021
case CODEC_ID_HUFFYUV:
2022
name = "Huffyuv lossless video";
2025
name = "CYUV lossless video";
2028
name = "H.264 video";
2030
case CODEC_ID_INDEO3:
2031
name = "Indeo-3 video";
2033
case CODEC_ID_INDEO2:
2034
name = "Indeo=2 video";
2039
case CODEC_ID_THEORA:
2040
name = "Theora video";
2043
case CODEC_ID_MPEG4AAC:
2044
name = "MPEG-2/4 AAC audio";
2047
name = "Asus video v1";
2050
name = "Asus video v2";
2053
name = "FFMpeg video v1";
2056
name = "4-XM video";
2059
name = "ATI VCR-1 video";
2062
name = "Cirrus Logipak AccuPak video";
2065
name = "Playstation MDEC video";
2068
name = "ID/RoQ video";
2070
case CODEC_ID_INTERPLAY_VIDEO:
2071
name = "Interplay video";
2073
case CODEC_ID_XAN_WC3:
2074
name = "XAN Wing Commander 3 video";
2076
case CODEC_ID_XAN_WC4:
2077
name = "XAN Wing Commander 4 video";
2080
name = "Apple RPZA video";
2082
case CODEC_ID_CINEPAK:
2083
name = "Cinepak video";
2085
case CODEC_ID_WS_VQA:
2086
name = "Westwood VQA video";
2088
case CODEC_ID_MSRLE:
2089
name = "Microsoft RLE video";
2091
case CODEC_ID_MSVIDEO1:
2092
name = "Microsoft video v1";
2094
case CODEC_ID_IDCIN:
2095
name = "ID Quake II CIN video";
2098
name = "Quicktime planar 8bps video";
2101
name = "Quicktime SMC graphics video";
2104
name = "FLIC animation video";
2106
case CODEC_ID_TRUEMOTION1:
2107
name = "Duck Truemotion video";
2109
case CODEC_ID_TRUEMOTION2:
2110
name = "Duck Truemotion 2 video";
2112
case CODEC_ID_VMDVIDEO:
2113
name = "Sierra VMD video";
2115
case CODEC_ID_VMDAUDIO:
2116
name = "Sierra VMD audio";
2119
name = "Lossless MSZH video";
2122
name = "Lossless zlib video";
2124
case CODEC_ID_QTRLE:
2125
name = "Quicktime RLE animation video";
2127
case CODEC_ID_SONIC:
2128
name = "Sonic audio";
2130
case CODEC_ID_SONIC_LS:
2131
name = "Sonic lossless audio";
2134
name = "Snow wave video";
2137
name = "Techsmith Camtasia video";
2140
name = "Ultimotion video";
2142
case CODEC_ID_QDRAW:
2143
name = "Applet Quickdraw video";
2146
name = "Miro VideoXL";
2149
name = "QPEG video";
2152
name = "XviD video";
2166
case CODEC_ID_PGMYUV:
2167
name = "PGM-YUV image";
2172
case CODEC_ID_FFVHUFF:
2173
name = "FFMPEG non-compliant Huffyuv video";
2176
name = "LOCO video";
2179
name = "Winnov video 1";
2182
name = "Autodesk RLE video";
2184
case CODEC_ID_MP3ADU:
2185
name = "ADU-formatted MPEG-1 layer 3 audio";
2187
case CODEC_ID_MP3ON4:
2190
case CODEC_ID_WESTWOOD_SND1:
2191
name = "Westwood Sound-1";
2193
case CODEC_ID_PCM_MULAW:
2194
name = "Mu-law audio";
2196
case CODEC_ID_PCM_ALAW:
2197
name = "A-law audio";
2199
case CODEC_ID_ADPCM_IMA_QT:
2200
name = "IMA/Quicktime ADPCM audio";
2202
case CODEC_ID_ADPCM_IMA_WAV:
2203
name = "IMA/DVI ADPCM audio";
2205
case CODEC_ID_ADPCM_IMA_DK3:
2206
name = "IMA/DK3 ADPCM audio";
2208
case CODEC_ID_ADPCM_IMA_DK4:
2209
name = "IMA/DK4 ADPCM";
2211
case CODEC_ID_ADPCM_IMA_WS:
2212
name = "IMA/Westwood ADPCM audio";
2214
case CODEC_ID_ADPCM_IMA_SMJPEG:
2215
name = "IMA/SMJPEG ADPCM audio";
2217
case CODEC_ID_ADPCM_MS:
2218
name = "Microsoft ADPCM audio";
2220
case CODEC_ID_ADPCM_4XM:
2221
name = "4-XM ADPCM audio";
2223
case CODEC_ID_ADPCM_XA:
2224
name = "CD-ROM XA ADPCM";
2226
case CODEC_ID_ADPCM_ADX:
2229
case CODEC_ID_ADPCM_EA:
2230
name = "Electronic Arts ADPCM";
2232
case CODEC_ID_ADPCM_G726:
2233
name = "G.726 ADPCM";
2235
case CODEC_ID_ADPCM_CT:
2238
case CODEC_ID_ADPCM_SWF:
2239
name = "Shockwave ADPCM";
2241
case CODEC_ID_ADPCM_YAMAHA:
2242
name = "Yamaha ADPCM";
2244
case CODEC_ID_RA_144:
2245
name = "Realaudio 14k4bps";
2247
case CODEC_ID_RA_288:
2248
name = "Realaudio 28k8bps";
2250
case CODEC_ID_ROQ_DPCM:
2251
name = "RoQ DPCM audio";
2253
case CODEC_ID_INTERPLAY_DPCM:
2254
name = "Interplay DPCM audio";
2256
case CODEC_ID_XAN_DPCM:
2257
name = "XAN DPCM audio";
2259
case CODEC_ID_SOL_DPCM:
2260
name = "SOL DPCM audio";
2263
name = "FLAC lossless audio";
2265
case CODEC_ID_SHORTEN:
2266
name = "Shorten lossless audio";
2269
name = "Apple lossless audio";
2271
case CODEC_ID_DVD_SUBTITLE:
2272
name = "DVD subtitle";
2274
case CODEC_ID_DVB_SUBTITLE:
2275
name = "DVB subtitle";
2277
case CODEC_ID_FRAPS:
2278
name = "FRAPS video";
2281
GST_WARNING ("Unknown codecID 0x%x", codec_id);
2289
* Fill in pointers to memory in a AVPicture, where
2290
* everything is aligned by 4 (as required by X).
2291
* This is mostly a copy from imgconvert.c with some
2295
#define FF_COLOR_RGB 0 /* RGB color space */
2296
#define FF_COLOR_GRAY 1 /* gray color space */
2297
#define FF_COLOR_YUV 2 /* YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
2298
#define FF_COLOR_YUV_JPEG 3 /* YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
2300
#define FF_PIXEL_PLANAR 0 /* each channel has one component in AVPicture */
2301
#define FF_PIXEL_PACKED 1 /* only one components containing all the channels */
2302
#define FF_PIXEL_PALETTE 2 /* one components containing indexes for a palette */
2304
typedef struct PixFmtInfo {
2306
uint8_t nb_channels; /* number of channels (including alpha) */
2307
uint8_t color_type; /* color type (see FF_COLOR_xxx constants) */
2308
uint8_t pixel_type; /* pixel storage type (see FF_PIXEL_xxx constants) */
2309
uint8_t is_alpha : 1; /* true if alpha can be specified */
2310
uint8_t x_chroma_shift; /* X chroma subsampling factor is 2 ^ shift */
2311
uint8_t y_chroma_shift; /* Y chroma subsampling factor is 2 ^ shift */
2312
uint8_t depth; /* bit depth of the color components */
2315
/* this table gives more information about formats */
2316
static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
2318
[PIX_FMT_YUV420P] = {
2321
.color_type = FF_COLOR_YUV,
2322
.pixel_type = FF_PIXEL_PLANAR,
2324
.x_chroma_shift = 1, .y_chroma_shift = 1,
2326
[PIX_FMT_YUV422P] = {
2329
.color_type = FF_COLOR_YUV,
2330
.pixel_type = FF_PIXEL_PLANAR,
2332
.x_chroma_shift = 1, .y_chroma_shift = 0,
2334
[PIX_FMT_YUV444P] = {
2337
.color_type = FF_COLOR_YUV,
2338
.pixel_type = FF_PIXEL_PLANAR,
2340
.x_chroma_shift = 0, .y_chroma_shift = 0,
2342
[PIX_FMT_YUV422] = {
2345
.color_type = FF_COLOR_YUV,
2346
.pixel_type = FF_PIXEL_PACKED,
2348
.x_chroma_shift = 1, .y_chroma_shift = 0,
2350
[PIX_FMT_YUV410P] = {
2353
.color_type = FF_COLOR_YUV,
2354
.pixel_type = FF_PIXEL_PLANAR,
2356
.x_chroma_shift = 2, .y_chroma_shift = 2,
2358
[PIX_FMT_YUV411P] = {
2361
.color_type = FF_COLOR_YUV,
2362
.pixel_type = FF_PIXEL_PLANAR,
2364
.x_chroma_shift = 2, .y_chroma_shift = 0,
2368
[PIX_FMT_YUVJ420P] = {
2371
.color_type = FF_COLOR_YUV_JPEG,
2372
.pixel_type = FF_PIXEL_PLANAR,
2374
.x_chroma_shift = 1, .y_chroma_shift = 1,
2376
[PIX_FMT_YUVJ422P] = {
2379
.color_type = FF_COLOR_YUV_JPEG,
2380
.pixel_type = FF_PIXEL_PLANAR,
2382
.x_chroma_shift = 1, .y_chroma_shift = 0,
2384
[PIX_FMT_YUVJ444P] = {
2387
.color_type = FF_COLOR_YUV_JPEG,
2388
.pixel_type = FF_PIXEL_PLANAR,
2390
.x_chroma_shift = 0, .y_chroma_shift = 0,
2397
.color_type = FF_COLOR_RGB,
2398
.pixel_type = FF_PIXEL_PACKED,
2400
.x_chroma_shift = 0, .y_chroma_shift = 0,
2405
.color_type = FF_COLOR_RGB,
2406
.pixel_type = FF_PIXEL_PACKED,
2408
.x_chroma_shift = 0, .y_chroma_shift = 0,
2410
[PIX_FMT_RGBA32] = {
2412
.nb_channels = 4, .is_alpha = 1,
2413
.color_type = FF_COLOR_RGB,
2414
.pixel_type = FF_PIXEL_PACKED,
2416
.x_chroma_shift = 0, .y_chroma_shift = 0,
2418
[PIX_FMT_RGB565] = {
2421
.color_type = FF_COLOR_RGB,
2422
.pixel_type = FF_PIXEL_PACKED,
2424
.x_chroma_shift = 0, .y_chroma_shift = 0,
2426
[PIX_FMT_RGB555] = {
2428
.nb_channels = 4, .is_alpha = 1,
2429
.color_type = FF_COLOR_RGB,
2430
.pixel_type = FF_PIXEL_PACKED,
2432
.x_chroma_shift = 0, .y_chroma_shift = 0,
2435
/* gray / mono formats */
2439
.color_type = FF_COLOR_GRAY,
2440
.pixel_type = FF_PIXEL_PLANAR,
2443
[PIX_FMT_MONOWHITE] = {
2446
.color_type = FF_COLOR_GRAY,
2447
.pixel_type = FF_PIXEL_PLANAR,
2450
[PIX_FMT_MONOBLACK] = {
2453
.color_type = FF_COLOR_GRAY,
2454
.pixel_type = FF_PIXEL_PLANAR,
2458
/* paletted formats */
2461
.nb_channels = 4, .is_alpha = 1,
2462
.color_type = FF_COLOR_RGB,
2463
.pixel_type = FF_PIXEL_PALETTE,
2469
gst_ffmpeg_avpicture_get_size (int pix_fmt, int width, int height)
2471
AVPicture dummy_pict;
2473
return gst_ffmpeg_avpicture_fill (&dummy_pict, NULL, pix_fmt, width, height);
2476
#define GEN_MASK(x) ((1<<(x))-1)
2477
#define ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) & ~GEN_MASK(x))
2478
#define ROUND_UP_2(x) ROUND_UP_X (x, 1)
2479
#define ROUND_UP_4(x) ROUND_UP_X (x, 2)
2480
#define ROUND_UP_8(x) ROUND_UP_X (x, 3)
2481
#define DIV_ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) >> (x))
2484
gst_ffmpeg_avpicture_fill (AVPicture * picture,
2485
uint8_t * ptr, enum PixelFormat pix_fmt, int width, int height)
2487
int size, w2, h2, size2;
2488
int stride, stride2;
2491
pinfo = &pix_fmt_info[pix_fmt];
2494
case PIX_FMT_YUV420P:
2495
case PIX_FMT_YUV422P:
2496
case PIX_FMT_YUV444P:
2497
case PIX_FMT_YUV410P:
2498
case PIX_FMT_YUV411P:
2499
case PIX_FMT_YUVJ420P:
2500
case PIX_FMT_YUVJ422P:
2501
case PIX_FMT_YUVJ444P:
2502
stride = ROUND_UP_4 (width);
2503
h2 = ROUND_UP_X (height, pinfo->y_chroma_shift);
2505
w2 = DIV_ROUND_UP_X (width, pinfo->x_chroma_shift);
2506
stride2 = ROUND_UP_4 (w2);
2507
h2 = DIV_ROUND_UP_X (height, pinfo->y_chroma_shift);
2508
size2 = stride2 * h2;
2509
picture->data[0] = ptr;
2510
picture->data[1] = picture->data[0] + size;
2511
picture->data[2] = picture->data[1] + size2;
2512
picture->linesize[0] = stride;
2513
picture->linesize[1] = stride2;
2514
picture->linesize[2] = stride2;
2515
return size + 2 * size2;
2518
stride = ROUND_UP_4 (width * 3);
2519
size = stride * height;
2520
picture->data[0] = ptr;
2521
picture->data[1] = NULL;
2522
picture->data[2] = NULL;
2523
picture->linesize[0] = stride;
2525
/*case PIX_FMT_AYUV4444:
2526
case PIX_FMT_RGB32:*/
2527
case PIX_FMT_RGBA32:
2529
size = stride * height;
2530
picture->data[0] = ptr;
2531
picture->data[1] = NULL;
2532
picture->data[2] = NULL;
2533
picture->linesize[0] = stride;
2535
case PIX_FMT_RGB555:
2536
case PIX_FMT_RGB565:
2537
case PIX_FMT_YUV422:
2538
case PIX_FMT_UYVY422:
2539
stride = ROUND_UP_4 (width * 2);
2540
size = stride * height;
2541
picture->data[0] = ptr;
2542
picture->data[1] = NULL;
2543
picture->data[2] = NULL;
2544
picture->linesize[0] = stride;
2546
case PIX_FMT_UYVY411:
2547
/* FIXME, probably not the right stride */
2548
stride = ROUND_UP_4 (width);
2549
size = stride * height;
2550
picture->data[0] = ptr;
2551
picture->data[1] = NULL;
2552
picture->data[2] = NULL;
2553
picture->linesize[0] = width + width / 2;
2554
return size + size / 2;
2556
stride = ROUND_UP_4 (width);
2557
size = stride * height;
2558
picture->data[0] = ptr;
2559
picture->data[1] = NULL;
2560
picture->data[2] = NULL;
2561
picture->linesize[0] = stride;
2563
case PIX_FMT_MONOWHITE:
2564
case PIX_FMT_MONOBLACK:
2565
stride = ROUND_UP_4 ((width + 7) >> 3);
2566
size = stride * height;
2567
picture->data[0] = ptr;
2568
picture->data[1] = NULL;
2569
picture->data[2] = NULL;
2570
picture->linesize[0] = stride;
2573
/* already forced to be with stride, so same result as other function */
2574
stride = ROUND_UP_4 (width);
2575
size = stride * height;
2576
picture->data[0] = ptr;
2577
picture->data[1] = ptr + size; /* palette is stored here as 256 32 bit words */
2578
picture->data[2] = NULL;
2579
picture->linesize[0] = stride;
2580
picture->linesize[1] = 4;
2581
return size + 256 * 4;
2583
picture->data[0] = NULL;
2584
picture->data[1] = NULL;
2585
picture->data[2] = NULL;
2586
picture->data[3] = NULL;
2594
* Convert image 'src' to 'dst'.
2596
* We use this code to copy two pictures between the same
2597
* colorspaces, so this function is not realy used to do
2598
* colorspace conversion.
2599
* The ffmpeg code has a bug in it where odd sized frames were
2600
* not copied completely. We adjust the input parameters for
2601
* the original ffmpeg img_convert function here so that it
2602
* still does the right thing.
2605
gst_ffmpeg_img_convert (AVPicture * dst, int dst_pix_fmt,
2606
const AVPicture * src, int src_pix_fmt, int src_width, int src_height)
2608
PixFmtInfo *pf = &pix_fmt_info[src_pix_fmt];
2610
pf = &pix_fmt_info[src_pix_fmt];
2611
switch (pf->pixel_type) {
2612
case FF_PIXEL_PACKED:
2613
/* nothing wrong here */
2615
case FF_PIXEL_PLANAR:
2616
/* patch up, so that img_copy copies all of the pixels */
2617
src_width = ROUND_UP_X (src_width, pf->x_chroma_shift);
2618
src_height = ROUND_UP_X (src_height, pf->y_chroma_shift);
2620
case FF_PIXEL_PALETTE:
2621
/* nothing wrong here */
2624
return img_convert (dst, dst_pix_fmt, src, src_pix_fmt, src_width, src_height);