adding ffmpegcolorspace element, thanks ronald

Original commit message from CVS:
adding ffmpegcolorspace element, thanks ronald
parent 2622996a
2004-03-15 Thomas Vander Stichele <thomas at apestaart dot org>
* configure.ac:
adding ffmpegcolorspace element
* gst/ffmpegcolorspace/Makefile.am:
* gst/ffmpegcolorspace/avcodec.h:
* gst/ffmpegcolorspace/common.h:
* gst/ffmpegcolorspace/dsputil.c: (dsputil_static_init):
* gst/ffmpegcolorspace/dsputil.h:
* gst/ffmpegcolorspace/gstffmpeg.c: (plugin_init):
* gst/ffmpegcolorspace/gstffmpegcodecmap.c:
(gst_ffmpeg_pixfmt_to_caps), (gst_ffmpeg_pix_fmt_to_caps),
(gst_ffmpeg_caps_to_pix_fmt):
* gst/ffmpegcolorspace/gstffmpegcodecmap.h:
* gst/ffmpegcolorspace/gstffmpegcolorspace.c:
(gst_ffmpegcolorspace_caps_remove_format_info),
(gst_ffmpegcolorspace_getcaps), (gst_ffmpegcolorspace_pad_link),
(gst_ffmpegcolorspace_get_type), (gst_ffmpegcolorspace_base_init),
(gst_ffmpegcolorspace_class_init), (gst_ffmpegcolorspace_init),
(gst_ffmpegcolorspace_chain), (gst_ffmpegcolorspace_change_state),
(gst_ffmpegcolorspace_set_property),
(gst_ffmpegcolorspace_get_property),
(gst_ffmpegcolorspace_register):
* gst/ffmpegcolorspace/imgconvert.c:
(avcodec_get_chroma_sub_sample), (avcodec_get_pix_fmt_name),
(avcodec_get_pix_fmt), (avpicture_fill), (avpicture_layout),
(avpicture_get_size), (avcodec_get_pix_fmt_loss),
(avg_bits_per_pixel), (avcodec_find_best_pix_fmt1),
(avcodec_find_best_pix_fmt), (img_copy_plane), (img_copy),
(yuv422_to_yuv420p), (yuv422_to_yuv422p), (yuv422p_to_yuv422),
(C_JPEG_TO_CCIR), (img_convert_init), (img_apply_table),
(shrink41), (shrink21), (shrink12), (shrink22), (shrink44),
(grow21_line), (grow41_line), (grow21), (grow22), (grow41),
(grow44), (conv411), (gif_clut_index), (build_rgb_palette),
(bitcopy_n), (mono_to_gray), (monowhite_to_gray),
(monoblack_to_gray), (gray_to_mono), (gray_to_monowhite),
(gray_to_monoblack), (avpicture_alloc), (avpicture_free),
(is_yuv_planar), (img_convert), (get_alpha_info_pal8),
(img_get_alpha_info), (deinterlace_line),
(deinterlace_line_inplace), (deinterlace_bottom_field),
(deinterlace_bottom_field_inplace), (avpicture_deinterlace):
* gst/ffmpegcolorspace/imgconvert_template.h:
* gst/ffmpegcolorspace/mem.c: (av_malloc), (av_realloc), (av_free):
* gst/ffmpegcolorspace/mmx.h:
* gst/ffmpegcolorspace/utils.c: (avcodec_init):
adding ffmpegcolorspace element supplied by Ronald after cleaning
up and pulling in the right bits of upstream source.
I'm sure a better C/compiler wizard could do some cleaning up (for
example use GLIB's malloc stuff), but as a first pass this
works very well
2004-03-15 Thomas Vander Stichele <thomas at apestaart dot org>
* ext/alsa/gstalsa.h:
......
......@@ -87,6 +87,11 @@ AC_HEADER_STDC([])
AC_C_INLINE
AX_CREATE_STDINT_H
dnl Check for malloc.h
AC_CHECK_HEADER(malloc.h,[
AC_DEFINE(HAVE_MALLOC_H, 1, [whether malloc.h available])
])
dnl Check for a way to display the function name in debug output
GST_CHECK_FUNCTION()
......@@ -348,6 +353,7 @@ GST_PLUGINS_ALL="\
deinterlace \
effectv \
festival \
ffmpegcolorspace \
filter \
flx \
goom \
......@@ -1597,6 +1603,7 @@ gst/debug/Makefile
gst/deinterlace/Makefile
gst/effectv/Makefile
gst/festival/Makefile
gst/ffmpegcolorspace/Makefile
gst/filter/Makefile
gst/flx/Makefile
gst/goom/Makefile
......
plugin_LTLIBRARIES = libgstffmpegcolorspace.la
libgstffmpegcolorspace_la_SOURCES = \
gstffmpeg.c \
gstffmpegcolorspace.c \
gstffmpegcodecmap.c \
dsputil.c \
mem.c \
utils.c \
imgconvert.c
libgstffmpegcolorspace_la_CFLAGS = $(GST_CFLAGS)
libgstffmpegcolorspace_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = \
gstffmpegcodecmap.h \
imgconvert_template.h \
mmx.h \
avcodec.h
#ifndef AVCODEC_H
#define AVCODEC_H
/**
* @file avcodec.h
* external api header.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "common.h"
#include <sys/types.h> /* size_t */
#define FFMPEG_VERSION_INT 0x000408
#define FFMPEG_VERSION "0.4.8"
#define LIBAVCODEC_BUILD 4707
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION
#define AV_STRINGIFY(s) AV_TOSTRING(s)
#define AV_TOSTRING(s) #s
#define LIBAVCODEC_IDENT "FFmpeg" LIBAVCODEC_VERSION "b" AV_STRINGIFY(LIBAVCODEC_BUILD)
#define AV_NOPTS_VALUE int64_t_C(0x8000000000000000)
#define AV_TIME_BASE 1000000
enum CodecType {
CODEC_TYPE_UNKNOWN = -1,
CODEC_TYPE_VIDEO,
CODEC_TYPE_AUDIO,
CODEC_TYPE_DATA,
};
/**
* Pixel format. Notes:
*
* PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA
* color is put together as:
* (A << 24) | (R << 16) | (G << 8) | B
* This is stored as BGRA on little endian CPU architectures and ARGB on
* big endian CPUs.
*
* When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
* image data is stored in AVFrame.data[0]. The palette is transported in
* AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
* formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is
* also endian-specific). Note also that the individual RGB palette
* components stored in AVFrame.data[1] should be in the range 0..255.
* This is important as many custom PAL8 video codecs that were designed
* to run on the IBM VGA graphics adapter use 6-bit palette components.
*/
enum PixelFormat {
PIX_FMT_YUV420P, ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples)
PIX_FMT_YUV422,
PIX_FMT_RGB24, ///< Packed pixel, 3 bytes per pixel, RGBRGB...
PIX_FMT_BGR24, ///< Packed pixel, 3 bytes per pixel, BGRBGR...
PIX_FMT_YUV422P, ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples)
PIX_FMT_YUV444P, ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples)
PIX_FMT_RGBA32, ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness
PIX_FMT_YUV410P, ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
PIX_FMT_YUV411P, ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples)
PIX_FMT_RGB565, ///< always stored in cpu endianness
PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1
PIX_FMT_GRAY8,
PIX_FMT_MONOWHITE, ///< 0 is white
PIX_FMT_MONOBLACK, ///< 0 is black
PIX_FMT_PAL8, ///< 8 bit with RGBA palette
PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0 full scale (jpeg)
PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2 full scale (jpeg)
PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4 full scale (jpeg)
PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
PIX_FMT_XVMC_MPEG2_IDCT,
PIX_FMT_NB,
};
/**
* four components are given, that's all.
* the last component is alpha
*/
typedef struct AVPicture {
uint8_t *data[4];
int linesize[4]; ///< number of bytes per line
} AVPicture;
/**
* Allocate memory for a picture. Call avpicture_free to free it.
*
* @param picture the picture to be filled in.
* @param pix_fmt the format of the picture.
* @param width the width of the picture.
* @param height the height of the picture.
* @return 0 if successful, -1 if not.
*/
int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height);
/* Free a picture previously allocated by avpicture_alloc. */
void avpicture_free(AVPicture *picture);
int avpicture_fill(AVPicture *picture, uint8_t *ptr,
int pix_fmt, int width, int height);
int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
unsigned char *dest, int dest_size);
int avpicture_get_size(int pix_fmt, int width, int height);
void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
const char *avcodec_get_pix_fmt_name(int pix_fmt);
enum PixelFormat avcodec_get_pix_fmt(const char* name);
#define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */
#define FF_LOSS_DEPTH 0x0002 /* loss due to color depth change */
#define FF_LOSS_COLORSPACE 0x0004 /* loss due to color space conversion */
#define FF_LOSS_ALPHA 0x0008 /* loss of alpha bits */
#define FF_LOSS_COLORQUANT 0x0010 /* loss due to color quantization */
#define FF_LOSS_CHROMA 0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
int has_alpha);
int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
int has_alpha, int *loss_ptr);
#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
int img_get_alpha_info(const AVPicture *src,
int pix_fmt, int width, int height);
/* convert among pixel formats */
int img_convert(AVPicture *dst, int dst_pix_fmt,
const AVPicture *src, int pix_fmt,
int width, int height);
/* deinterlace a picture */
int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
int pix_fmt, int width, int height);
void avcodec_init(void);
/* memory */
void *av_malloc(unsigned int size);
void *av_mallocz(unsigned int size);
void *av_realloc(void *ptr, unsigned int size);
void av_free(void *ptr);
char *av_strdup(const char *s);
void av_freep(void *ptr);
void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
/* for static data only */
/* call av_free_static to release all staticaly allocated tables */
void av_free_static(void);
void *__av_mallocz_static(void** location, unsigned int size);
#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
/* add by bero : in adx.c */
int is_adx(const unsigned char *buf,size_t bufsize);
void img_copy(AVPicture *dst, const AVPicture *src,
int pix_fmt, int width, int height);
#ifdef __cplusplus
}
#endif
#endif /* AVCODEC_H */
This diff is collapsed.
/*
* DSP utils
* Copyright (c) 2000, 2001 Fabrice Bellard.
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
*/
/**
* @file dsputil.c
* DSP utils
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "avcodec.h"
#include "dsputil.h"
uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
/* init static data */
void
dsputil_static_init (void)
{
int i;
for (i = 0; i < 256; i++)
cropTbl[i + MAX_NEG_CROP] = i;
for (i = 0; i < MAX_NEG_CROP; i++) {
cropTbl[i] = 0;
cropTbl[i + MAX_NEG_CROP + 256] = 255;
}
}
This diff is collapsed.
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* First, include the header file for the plugin, to bring in the
* object definition and other useful things.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <avcodec.h>
extern gboolean gst_ffmpegcolorspace_register (GstPlugin * plugin);
static gboolean
plugin_init (GstPlugin * plugin)
{
gst_ffmpegcolorspace_register (plugin);
/* Now we can return the pointer to the newly created Plugin object. */
return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"ffmpegcolorspace",
"colorspace conversion copied from FFMpeg",
plugin_init,
FFMPEG_VERSION, "LGPL", "FFMpeg", "http://ffmpeg.sourceforge.net/")
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* This file:
* Copyright (c) 2002-2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <avcodec.h>
#include <string.h>
#include "gstffmpegcodecmap.h"
/* this macro makes a caps width fixed or unfixed width/height
* properties depending on whether we've got a context.
*
* See below for why we use this.
*/
#define GST_FF_VID_CAPS_NEW(mimetype, props...) \
gst_caps_new_simple (mimetype, \
"width", GST_TYPE_INT_RANGE, 16, 4096, \
"height", GST_TYPE_INT_RANGE, 16, 4096, \
"framerate", GST_TYPE_DOUBLE_RANGE, 0., G_MAXDOUBLE, \
##props, NULL)
/* Convert a FFMPEG Pixel Format and optional AVCodecContext
* to a GstCaps. If the context is ommitted, no fixed values
* for video/audio size will be included in the GstCaps
*
* See below for usefullness
*/
static GstCaps *
gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt)
{
GstCaps *caps = NULL;
int bpp = 0, depth = 0, endianness = 0;
gulong g_mask = 0, r_mask = 0, b_mask = 0;
guint32 fmt = 0;
switch (pix_fmt) {
case PIX_FMT_YUV420P:
fmt = GST_MAKE_FOURCC ('I', '4', '2', '0');
break;
case PIX_FMT_YUV422:
fmt = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
break;
case PIX_FMT_RGB24:
bpp = depth = 24;
endianness = G_BIG_ENDIAN;
r_mask = 0xff0000;
g_mask = 0x00ff00;
b_mask = 0x0000ff;
break;
case PIX_FMT_BGR24:
bpp = depth = 24;
endianness = G_BIG_ENDIAN;
r_mask = 0x0000ff;
g_mask = 0x00ff00;
b_mask = 0xff0000;
break;
case PIX_FMT_YUV422P:
fmt = GST_MAKE_FOURCC ('Y', '4', '2', 'B');
break;
case PIX_FMT_YUV444P:
/* .. */
break;
case PIX_FMT_RGBA32:
bpp = 32;
depth = 24;
endianness = G_BIG_ENDIAN;
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
r_mask = 0x00ff0000;
g_mask = 0x0000ff00;
b_mask = 0x000000ff;
#else
r_mask = 0x0000ff00;
g_mask = 0x00ff0000;
b_mask = 0xff000000;
#endif
break;
case PIX_FMT_YUV410P:
fmt = GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
break;
case PIX_FMT_YUV411P:
fmt = GST_MAKE_FOURCC ('Y', '4', '1', 'B');
break;
case PIX_FMT_RGB565:
bpp = depth = 16;
endianness = G_BYTE_ORDER;
r_mask = 0xf800;
g_mask = 0x07e0;
b_mask = 0x001f;
break;
case PIX_FMT_RGB555:
bpp = 16;
depth = 15;
endianness = G_BYTE_ORDER;
r_mask = 0x7c00;
g_mask = 0x03e0;
b_mask = 0x001f;
break;
default:
/* give up ... */
break;
}
if (bpp != 0) {
caps = GST_FF_VID_CAPS_NEW ("video/x-raw-rgb",
"bpp", G_TYPE_INT, bpp,
"depth", G_TYPE_INT, depth,
"red_mask", G_TYPE_INT, r_mask,
"green_mask", G_TYPE_INT, g_mask,
"blue_mask", G_TYPE_INT, b_mask,
"endianness", G_TYPE_INT, endianness, NULL);
} else if (fmt) {
caps = GST_FF_VID_CAPS_NEW ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, fmt, NULL);
}
if (caps != NULL) {
char *str = gst_caps_to_string (caps);
GST_DEBUG ("caps for pix_fmt=%d: %s", pix_fmt, str);
g_free (str);
} else {
GST_WARNING ("No caps found for pix_fmt=%d", pix_fmt);
}
return caps;
}
/* Convert a FFMPEG codec Type and optional AVCodecContext
* to a GstCaps. If the context is ommitted, no fixed values
* for video/audio size will be included in the GstCaps
*
* CodecType is primarily meant for uncompressed data GstCaps!
*/
GstCaps *
gst_ffmpeg_pix_fmt_to_caps (void)
{
GstCaps *caps, *temp;
enum PixelFormat i;
caps = gst_caps_new_empty ();
for (i = 0; i < PIX_FMT_NB; i++) {
temp = gst_ffmpeg_pixfmt_to_caps (i);
if (temp != NULL) {
gst_caps_append (caps, temp);
}
}
return caps;
}
/* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
* and other video properties in a AVCodecContext.
*
* For usefullness, see below
*/
enum PixelFormat
gst_ffmpeg_caps_to_pix_fmt (const GstCaps * caps,
int *width, int *height, double *framerate)
{
GstStructure *structure;
enum PixelFormat pix_fmt = PIX_FMT_NB;
g_return_val_if_fail (gst_caps_get_size (caps) == 1, PIX_FMT_NB);
structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "width", width);
gst_structure_get_int (structure, "height", height);
gst_structure_get_double (structure, "framerate", framerate);
if (strcmp (gst_structure_get_name (structure), "video/x-raw-yuv") == 0) {
guint32 fourcc;
if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
switch (fourcc) {
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
pix_fmt = PIX_FMT_YUV422;
break;
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
pix_fmt = PIX_FMT_YUV420P;
break;
case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
pix_fmt = PIX_FMT_YUV411P;
break;
case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
pix_fmt = PIX_FMT_YUV422P;
break;
case GST_MAKE_FOURCC ('Y', 'U', 'V', '9'):
pix_fmt = PIX_FMT_YUV410P;
break;
#if 0
case FIXME:
pix_fmt = PIX_FMT_YUV444P;
break;
#endif
}
}
} else if (strcmp (gst_structure_get_name (structure),
"video/x-raw-rgb") == 0) {
gint bpp = 0, rmask = 0, endianness = 0;
if (gst_structure_get_int (structure, "bpp", &bpp) &&
gst_structure_get_int (structure, "endianness", &endianness) &&
gst_structure_get_int (structure, "red_mask", &rmask)) {
switch (bpp) {
case 32:
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
if (rmask == 0x00ff0000)
#else
if (rmask == 0x0000ff00)
#endif
pix_fmt = PIX_FMT_RGBA32;
break;
case 24:
if (rmask == 0x0000FF)
pix_fmt = PIX_FMT_BGR24;
else
pix_fmt = PIX_FMT_RGB24;
break;
case 16:
if (endianness == G_BYTE_ORDER)
pix_fmt = PIX_FMT_RGB565;
break;
case 15:
if (endianness == G_BYTE_ORDER)
pix_fmt = PIX_FMT_RGB555;
break;
default:
/* nothing */
break;
}
}
}
return pix_fmt;
}
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_FFMPEG_CODECMAP_H__
#define __GST_FFMPEG_CODECMAP_H__
#include <avcodec.h>