jasper: remove jasper jpeg2000 plugin, replaced by openjpeg plugin

libjasper isn't really maintained any longer, we probably
don't want to port this.
This commit is contained in:
Tim-Philipp Müller 2013-01-07 10:36:45 +00:00
parent 6d9260e049
commit 8436a7d8ae
9 changed files with 22 additions and 1713 deletions

View file

@ -321,7 +321,7 @@ GST_PLUGINS_NONPORTED=" aiff \
videomeasure videosignal vmnc \
decklink fbdev linsys vcd \
apexsink cdaudio cog dc1394 dirac directfb \
gsettings jasper ladspa \
gsettings ladspa \
musepack musicbrainz nas neon ofa openal rsvg sdl sndfile timidity \
directdraw direct3d9 acm wininet \
wildmidi xvid lv2 teletextdec sndio uvch264 wasapi"
@ -1181,26 +1181,6 @@ AG_GST_CHECK_FEATURE(GSM, [GSM library], gsmenc gsmdec, [
AC_SUBST(GSM_LIBS)
])
dnl *** jasper ***
translit(dnm, m, l) AM_CONDITIONAL(USE_JASPER, true)
AG_GST_CHECK_FEATURE(JASPER, [jasper], jasperdec jasperenc, [
AG_GST_CHECK_LIBHEADER(JASPER, jasper, jas_stream_fopen, , jasper/jasper.h,
JASPER_LIBS="-ljasper")
AC_SUBST(JASPER_LIBS)
])
dnl *** OpenJPEG ***
translit(dnm, m, l) AM_CONDITIONAL(USE_OPENJPEG, true)
AG_GST_CHECK_FEATURE(OPENJPEG, [openjpeg library], openjpeg, [
HAVE_OPENJPEG="no"
PKG_CHECK_MODULES(OPENJPEG, libopenjpeg1,
HAVE_OPENJPEG="yes",
AG_GST_CHECK_LIBHEADER(OPENJPEG, openjpeg, opj_version, , openjpeg.h, OPENJPEG_LIBS="-lopenjpeg")
)
AC_SUBST(OPENJPEG_CFLAGS)
AC_SUBST(OPENJPEG_LIBS)
])
dnl *** kate ***
translit(dnm, m, l) AM_CONDITIONAL(USE_KATE, true)
AG_GST_CHECK_FEATURE(KATE, [Kate], kate, [
@ -1590,6 +1570,18 @@ AG_GST_CHECK_FEATURE(OPENCV, [opencv plugins], opencv, [
AC_SUBST(OPENCV_LIBS)
])
dnl *** OpenJPEG ***
translit(dnm, m, l) AM_CONDITIONAL(USE_OPENJPEG, true)
AG_GST_CHECK_FEATURE(OPENJPEG, [openjpeg library], openjpeg, [
HAVE_OPENJPEG="no"
PKG_CHECK_MODULES(OPENJPEG, libopenjpeg1,
HAVE_OPENJPEG="yes",
AG_GST_CHECK_LIBHEADER(OPENJPEG, openjpeg, opj_version, , openjpeg.h, OPENJPEG_LIBS="-lopenjpeg")
)
AC_SUBST(OPENJPEG_CFLAGS)
AC_SUBST(OPENJPEG_LIBS)
])
dnl *** Opus ***
translit(dnm, m, l) AM_CONDITIONAL(USE_OPUS, true)
AG_GST_CHECK_FEATURE(OPUS, [opus], opus, [
@ -2058,8 +2050,6 @@ AM_CONDITIONAL(USE_FAAD, false)
AM_CONDITIONAL(USE_FBDEV, false)
AM_CONDITIONAL(USE_FLITE, false)
AM_CONDITIONAL(USE_GSM, false)
AM_CONDITIONAL(USE_JASPER, false)
AM_CONDITIONAL(USE_OPENJPEG, false)
AM_CONDITIONAL(USE_KATE, false)
AM_CONDITIONAL(USE_TIGER, false)
AM_CONDITIONAL(USE_LADSPA, false)
@ -2079,6 +2069,7 @@ AM_CONDITIONAL(USE_NEON, false)
AM_CONDITIONAL(USE_OFA, false)
AM_CONDITIONAL(USE_OPENAL, false)
AM_CONDITIONAL(USE_OPENCV, false)
AM_CONDITIONAL(USE_OPENJPEG, false)
AM_CONDITIONAL(USE_OPUS, false)
AM_CONDITIONAL(USE_PVR, false)
AM_CONDITIONAL(USE_RSVG, false)
@ -2318,7 +2309,6 @@ ext/faac/Makefile
ext/faad/Makefile
ext/flite/Makefile
ext/gsm/Makefile
ext/jasper/Makefile
ext/kate/Makefile
ext/ladspa/Makefile
ext/lv2/Makefile

View file

@ -136,18 +136,6 @@ else
GSM_DIR=
endif
if USE_JASPER
JASPER_DIR = jasper
else
JASPER_DIR =
endif
if USE_OPENJPEG
OPENJPEG_DIR = openjpeg
else
OPENJPEG_DIR =
endif
if USE_KATE
KATE_DIR=kate
else
@ -256,6 +244,12 @@ else
OPENCV_DIR=
endif
if USE_OPENJPEG
OPENJPEG_DIR = openjpeg
else
OPENJPEG_DIR =
endif
if USE_OPUS
OPUS_DIR=opus
else
@ -398,8 +392,6 @@ SUBDIRS=\
$(GSETTINGS_DIR) \
$(GSM_DIR) \
$(G729_DIR) \
$(JASPER_DIR) \
$(OPENJPEG_DIR) \
$(KATE_DIR) \
$(LADSPA_DIR) \
$(LV2_DIR) \
@ -418,6 +410,7 @@ SUBDIRS=\
$(OFA_DIR) \
$(OPENAL_DIR) \
$(OPENCV_DIR) \
$(OPENJPEG_DIR) \
$(OPUS_DIR) \
$(RSVG_DIR) \
$(SCHRO_DIR) \
@ -455,8 +448,6 @@ DIST_SUBDIRS = \
gsettings \
gsm \
ladspa \
jasper \
openjpeg \
kate \
libmms \
lv2 \
@ -475,6 +466,7 @@ DIST_SUBDIRS = \
ofa \
openal \
opencv \
openjpeg \
opus \
rsvg \
resindvd \

View file

@ -1,14 +0,0 @@
plugin_LTLIBRARIES = libgstjasper.la
libgstjasper_la_SOURCES = gstjasperdec.c gstjasperenc.c gstjasper.c
libgstjasper_la_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(JASPER_CFLAGS)
libgstjasper_la_LIBADD = \
$(GST_PLUGINS_BASE_LIBS) -lgstvideo-$(GST_API_VERSION) \
$(GST_LIBS) $(JASPER_LIBS)
libgstjasper_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstjasper_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = \
gstjasperdec.h \
gstjasperenc.h

View file

@ -1,54 +0,0 @@
/* GStreamer Jasper based j2k image decoder/encoder
* Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstjasperdec.h"
#include "gstjasperenc.h"
/* entry point to initialize the plug-in
* initialize the plug-in itself
* register the element factories and pad templates
* register the features
*/
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_element_register (plugin, "jasperdec", GST_RANK_MARGINAL,
GST_TYPE_JASPER_DEC))
return FALSE;
if (!gst_element_register (plugin, "jasperenc", GST_RANK_MARGINAL,
GST_TYPE_JASPER_ENC))
return FALSE;
/* plugin initialisation succeeded */
return TRUE;
}
/* this is the structure that gst-register looks for
* so keep the name plugin_desc, or you cannot get your plug-in registered */
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
jasper,
"Jasper-based JPEG2000 image decoder/encoder",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)

View file

@ -1,850 +0,0 @@
/* GStreamer Jasper based j2k image decoder
* Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* SECTION:element-jasperdec
*
* Decodes jpeg2000 images.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gst/video/video.h>
#include <string.h>
#include <jasper/jasper.h>
#include "gstjasperdec.h"
GST_DEBUG_CATEGORY_STATIC (gst_jasper_dec_debug);
#define GST_CAT_DEFAULT gst_jasper_dec_debug
enum
{
ARG_0,
};
/* FIXME 0.11: Use a single caps name for jpeg2000 codestreams
* and drop the "boxed" variant
*/
static GstStaticPadTemplate gst_jasper_dec_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("image/x-j2c, "
"framerate = " GST_VIDEO_FPS_RANGE ", "
"fields = (int) 1; "
"image/x-jpc, "
"framerate = " GST_VIDEO_FPS_RANGE ", "
"fields = (int) 1; " "image/jp2")
);
static GstStaticPadTemplate gst_jasper_dec_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB "; " GST_VIDEO_CAPS_BGR "; "
GST_VIDEO_CAPS_RGBx "; " GST_VIDEO_CAPS_xRGB "; "
GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_xBGR "; "
GST_VIDEO_CAPS_YUV ("{ I420, YV12, YUY2, UYVY, Y41B, Y42B, v308 }"))
);
static void gst_jasper_dec_reset (GstJasperDec * dec);
static GstStateChangeReturn gst_jasper_dec_change_state (GstElement * element,
GstStateChange transition);
static gboolean gst_jasper_dec_sink_setcaps (GstPad * pad, GstCaps * caps);
static GstFlowReturn gst_jasper_dec_chain (GstPad * pad, GstBuffer * buffer);
static gboolean gst_jasper_dec_src_event (GstPad * pad, GstEvent * event);
static gboolean gst_jasper_dec_sink_event (GstPad * pad, GstEvent * event);
static void gst_jasper_dec_update_qos (GstJasperDec * dec, gdouble proportion,
GstClockTime time);
static void gst_jasper_dec_reset_qos (GstJasperDec * dec);
static void gst_jasper_dec_read_qos (GstJasperDec * dec, gdouble * proportion,
GstClockTime * time);
/* minor trick:
* keep original naming but use unique name here for a happy type system
*/
GST_BOILERPLATE (GstJasperDec, gst_jasper_dec, GstElement, GST_TYPE_ELEMENT);
static void
gst_jasper_dec_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_jasper_dec_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_jasper_dec_sink_template));
gst_element_class_set_static_metadata (element_class,
"Jasper JPEG2000 image decoder", "Codec/Decoder/Image",
"Decodes JPEG2000 encoded images using jasper",
"Mark Nauwelaerts <mnauw@users.sf.net>");
}
/* initialize the plugin's class */
static void
gst_jasper_dec_class_init (GstJasperDecClass * klass)
{
GstElementClass *gstelement_class;
gstelement_class = (GstElementClass *) klass;
GST_DEBUG_CATEGORY_INIT (gst_jasper_dec_debug, "jasperdec", 0,
"Jasper JPEG2000 decoder");
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_jasper_dec_change_state);
}
static void
gst_jasper_dec_init (GstJasperDec * dec, GstJasperDecClass * klass)
{
dec->sinkpad =
gst_pad_new_from_static_template (&gst_jasper_dec_sink_template, "sink");
gst_pad_set_setcaps_function (dec->sinkpad,
GST_DEBUG_FUNCPTR (gst_jasper_dec_sink_setcaps));
gst_pad_set_chain_function (dec->sinkpad,
GST_DEBUG_FUNCPTR (gst_jasper_dec_chain));
gst_pad_set_event_function (dec->sinkpad,
GST_DEBUG_FUNCPTR (gst_jasper_dec_sink_event));
gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
dec->srcpad =
gst_pad_new_from_static_template (&gst_jasper_dec_src_template, "src");
gst_pad_use_fixed_caps (dec->srcpad);
gst_pad_set_event_function (dec->srcpad,
GST_DEBUG_FUNCPTR (gst_jasper_dec_src_event));
gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
dec->codec_data = NULL;
dec->buf = NULL;
gst_jasper_dec_reset (dec);
}
static void
gst_jasper_dec_reset (GstJasperDec * dec)
{
if (dec->codec_data)
gst_buffer_unref (dec->codec_data);
dec->codec_data = NULL;
if (dec->buf)
g_free (dec->buf);
dec->buf = NULL;
dec->fmt = -1;
dec->clrspc = JAS_CLRSPC_UNKNOWN;
dec->format = GST_VIDEO_FORMAT_UNKNOWN;
gst_jasper_dec_reset_qos (dec);
gst_segment_init (&dec->segment, GST_FORMAT_TIME);
dec->discont = TRUE;
}
static gboolean
gst_jasper_dec_sink_setcaps (GstPad * pad, GstCaps * caps)
{
GstJasperDec *dec;
const GValue *framerate;
GstStructure *s;
const gchar *mimetype;
guint32 fourcc;
dec = GST_JASPER_DEC (GST_PAD_PARENT (pad));
s = gst_caps_get_structure (caps, 0);
mimetype = gst_structure_get_name (s);
/* reset negotiation */
dec->fmt = -1;
dec->strip = 0;
dec->format = GST_VIDEO_FORMAT_UNKNOWN;
if (dec->codec_data) {
gst_buffer_unref (dec->codec_data);
dec->codec_data = NULL;
}
if (!strcmp (mimetype, "image/x-j2c") || !strcmp (mimetype, "image/x-jpc")) {
const GValue *codec_data;
gint fields;
/* we only handle single field, packetized input */
if (gst_structure_get_value (s, "framerate") == NULL)
goto refuse_caps;
if (gst_structure_get_int (s, "fields", &fields) && fields != 1)
goto refuse_caps;
if (!gst_structure_get_fourcc (s, "fourcc", &fourcc))
goto refuse_caps;
switch (fourcc) {
case GST_MAKE_FOURCC ('s', 'R', 'G', 'B'):
dec->clrspc = JAS_CLRSPC_SRGB;
break;
case GST_MAKE_FOURCC ('s', 'Y', 'U', 'V'):
dec->clrspc = JAS_CLRSPC_SYCBCR;
break;
default:
goto refuse_caps;
break;
}
dec->fmt = jas_image_strtofmt ((char *) "jpc");
/* strip the j2c box stuff it is embedded in */
if (!strcmp (mimetype, "image/x-jpc"))
dec->strip = 0;
else
dec->strip = 8;
codec_data = gst_structure_get_value (s, "codec_data");
if (codec_data) {
dec->codec_data = gst_value_get_buffer (codec_data);
gst_buffer_ref (dec->codec_data);
}
} else if (!strcmp (mimetype, "image/jp2"))
dec->fmt = jas_image_strtofmt ((char *) "jp2");
if (dec->fmt < 0)
goto refuse_caps;
if ((framerate = gst_structure_get_value (s, "framerate")) != NULL) {
dec->framerate_numerator = gst_value_get_fraction_numerator (framerate);
dec->framerate_denominator = gst_value_get_fraction_denominator (framerate);
GST_DEBUG_OBJECT (dec, "got framerate of %d/%d fps => packetized mode",
dec->framerate_numerator, dec->framerate_denominator);
} else {
dec->framerate_numerator = 0;
dec->framerate_denominator = 1;
GST_DEBUG_OBJECT (dec, "no framerate, assuming single image");
}
return TRUE;
refuse_caps:
{
GST_WARNING_OBJECT (dec, "refused caps %" GST_PTR_FORMAT, caps);
return FALSE;
}
}
static GstFlowReturn
gst_jasper_dec_negotiate (GstJasperDec * dec, jas_image_t * image)
{
GstFlowReturn flow_ret = GST_FLOW_OK;
gint width, height, channels;
gint i, j;
gboolean negotiate = FALSE;
jas_clrspc_t clrspc;
GstCaps *allowed_caps, *caps;
width = jas_image_width (image);
height = jas_image_height (image);
channels = jas_image_numcmpts (image);
GST_LOG_OBJECT (dec, "%d x %d, %d components", width, height, channels);
/* jp2c bitstream has no real colour space info (kept in container),
* so decoder may only pretend to know, where it really does not */
if (!jas_clrspc_isunknown (dec->clrspc)) {
clrspc = dec->clrspc;
GST_DEBUG_OBJECT (dec, "forcing container supplied colour space %d",
clrspc);
jas_image_setclrspc (image, clrspc);
} else
clrspc = jas_image_clrspc (image);
if (!width || !height || !channels || jas_clrspc_isunknown (clrspc))
goto fail_image;
if (dec->width != width || dec->height != height ||
dec->channels != channels || dec->clrspc != clrspc)
negotiate = TRUE;
if (channels != 3)
goto not_supported;
for (i = 0; i < channels; i++) {
gint cheight, cwidth, depth, sgnd;
cheight = jas_image_cmptheight (image, i);
cwidth = jas_image_cmptwidth (image, i);
depth = jas_image_cmptprec (image, i);
sgnd = jas_image_cmptsgnd (image, i);
GST_LOG_OBJECT (dec, "image component %d, %dx%d, depth %d, sgnd %d", i,
cwidth, cheight, depth, sgnd);
if (depth != 8 || sgnd)
goto not_supported;
if (dec->cheight[i] != cheight || dec->cwidth[i] != cwidth) {
dec->cheight[i] = cheight;
dec->cwidth[i] = cwidth;
negotiate = TRUE;
}
}
if (!negotiate && dec->format != GST_VIDEO_FORMAT_UNKNOWN)
goto done;
/* clear and refresh to new state */
flow_ret = GST_FLOW_NOT_NEGOTIATED;
dec->format = GST_VIDEO_FORMAT_UNKNOWN;
dec->width = width;
dec->height = height;
dec->channels = channels;
/* retrieve allowed caps, and find the first one that reasonably maps
* to the parameters of the colourspace */
caps = gst_pad_get_allowed_caps (dec->srcpad);
if (!caps) {
GST_DEBUG_OBJECT (dec, "... but no peer, using template caps");
/* need to copy because get_allowed_caps returns a ref,
and get_pad_template_caps doesn't */
caps = gst_caps_copy (gst_pad_get_pad_template_caps (dec->srcpad));
}
/* avoid lists of fourcc, etc */
allowed_caps = gst_caps_normalize (caps);
caps = NULL;
GST_LOG_OBJECT (dec, "allowed source caps %" GST_PTR_FORMAT, allowed_caps);
for (i = 0; i < gst_caps_get_size (allowed_caps); i++) {
GstVideoFormat format;
gboolean ok;
if (caps)
gst_caps_unref (caps);
caps = gst_caps_copy_nth (allowed_caps, i);
/* sigh, ds and _parse_caps need fixed caps for parsing, fixate */
gst_pad_fixate_caps (dec->srcpad, caps);
GST_LOG_OBJECT (dec, "checking caps %" GST_PTR_FORMAT, caps);
if (!gst_video_format_parse_caps (caps, &format, NULL, NULL))
continue;
if (gst_video_format_is_rgb (format) &&
jas_clrspc_fam (clrspc) == JAS_CLRSPC_FAM_RGB) {
GST_DEBUG_OBJECT (dec, "trying RGB");
if ((dec->cmpt[0] = jas_image_getcmptbytype (image,
JAS_IMAGE_CT_COLOR (JAS_CLRSPC_CHANIND_RGB_R))) < 0 ||
(dec->cmpt[1] = jas_image_getcmptbytype (image,
JAS_IMAGE_CT_COLOR (JAS_CLRSPC_CHANIND_RGB_G))) < 0 ||
(dec->cmpt[2] = jas_image_getcmptbytype (image,
JAS_IMAGE_CT_COLOR (JAS_CLRSPC_CHANIND_RGB_B))) < 0) {
GST_DEBUG_OBJECT (dec, "missing RGB color component");
continue;
}
} else if (gst_video_format_is_yuv (format) &&
jas_clrspc_fam (clrspc) == JAS_CLRSPC_FAM_YCBCR) {
GST_DEBUG_OBJECT (dec, "trying YUV");
if ((dec->cmpt[0] = jas_image_getcmptbytype (image,
JAS_IMAGE_CT_COLOR (JAS_CLRSPC_CHANIND_YCBCR_Y))) < 0 ||
(dec->cmpt[1] = jas_image_getcmptbytype (image,
JAS_IMAGE_CT_COLOR (JAS_CLRSPC_CHANIND_YCBCR_CB))) < 0 ||
(dec->cmpt[2] = jas_image_getcmptbytype (image,
JAS_IMAGE_CT_COLOR (JAS_CLRSPC_CHANIND_YCBCR_CR))) < 0) {
GST_DEBUG_OBJECT (dec, "missing YUV color component");
continue;
}
} else
continue;
/* match format with validity checks */
ok = TRUE;
for (j = 0; j < channels; j++) {
gint cmpt;
cmpt = dec->cmpt[j];
if (dec->cwidth[cmpt] != gst_video_format_get_component_width (format, j,
width) ||
dec->cheight[cmpt] != gst_video_format_get_component_height (format,
j, height))
ok = FALSE;
}
/* commit to this format */
if (ok) {
dec->format = format;
break;
}
}
if (caps)
gst_caps_unref (caps);
gst_caps_unref (allowed_caps);
if (dec->format != GST_VIDEO_FORMAT_UNKNOWN) {
/* cache some video format properties */
for (j = 0; j < channels; ++j) {
dec->offset[j] = gst_video_format_get_component_offset (dec->format, j,
dec->width, dec->height);
dec->inc[j] = gst_video_format_get_pixel_stride (dec->format, j);
dec->stride[j] = gst_video_format_get_row_stride (dec->format, j,
dec->width);
}
dec->image_size = gst_video_format_get_size (dec->format, width, height);
dec->alpha = gst_video_format_has_alpha (dec->format);
if (dec->buf)
g_free (dec->buf);
dec->buf = g_new0 (glong, dec->width);
caps = gst_video_format_new_caps (dec->format, dec->width, dec->height,
dec->framerate_numerator, dec->framerate_denominator, 1, 1);
GST_DEBUG_OBJECT (dec, "Set format to %d, size to %dx%d", dec->format,
dec->width, dec->height);
if (!gst_pad_set_caps (dec->srcpad, caps))
flow_ret = GST_FLOW_NOT_NEGOTIATED;
else
flow_ret = GST_FLOW_OK;
gst_caps_unref (caps);
}
done:
return flow_ret;
/* ERRORS */
fail_image:
{
GST_DEBUG_OBJECT (dec, "Failed to process decoded image.");
flow_ret = GST_FLOW_NOT_NEGOTIATED;
goto done;
}
not_supported:
{
GST_DEBUG_OBJECT (dec, "Decoded image has unsupported colour space.");
GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("Unsupported colorspace"));
flow_ret = GST_FLOW_ERROR;
goto done;
}
}
static GstFlowReturn
gst_jasper_dec_get_picture (GstJasperDec * dec, guint8 * data,
guint size, GstBuffer ** outbuf)
{
GstFlowReturn ret = GST_FLOW_OK;
jas_stream_t *stream = NULL;
jas_image_t *image = NULL;
gint i;
g_return_val_if_fail (outbuf != NULL, GST_FLOW_ERROR);
*outbuf = NULL;
if (!(stream = jas_stream_memopen ((gpointer) data, size)))
goto fail_stream;
if (!(image = jas_image_decode (stream, dec->fmt, (char *) "")))
goto fail_decode;
ret = gst_jasper_dec_negotiate (dec, image);
if (ret != GST_FLOW_OK)
goto fail_negotiate;
ret = gst_pad_alloc_buffer_and_set_caps (dec->srcpad,
GST_BUFFER_OFFSET_NONE,
dec->image_size, GST_PAD_CAPS (dec->srcpad), outbuf);
if (ret != GST_FLOW_OK)
goto no_buffer;
if (dec->alpha)
memset (GST_BUFFER_DATA (*outbuf), 0xff, dec->image_size);
for (i = 0; i < dec->channels; ++i) {
gint x, y, cwidth, cheight, inc, stride, cmpt;
guint8 *row_pix, *out_pix;
glong *tb;
inc = dec->inc[i];
stride = dec->stride[i];
cmpt = dec->cmpt[i];
cheight = dec->cheight[cmpt];
cwidth = dec->cwidth[cmpt];
GST_LOG_OBJECT (dec,
"retrieve component %d<=%d, size %dx%d, offset %d, inc %d, stride %d",
i, cmpt, cwidth, cheight, dec->offset[i], inc, stride);
out_pix = GST_BUFFER_DATA (*outbuf) + dec->offset[i];
for (y = 0; y < cheight; y++) {
row_pix = out_pix;
tb = dec->buf;
if (jas_image_readcmpt2 (image, i, 0, y, cwidth, 1, dec->buf))
goto fail_image;
for (x = 0; x < cwidth; x++) {
*out_pix = *tb;
tb++;
out_pix += inc;
}
out_pix = row_pix + stride;
}
}
GST_LOG_OBJECT (dec, "all components retrieved");
done:
if (image)
jas_image_destroy (image);
if (stream)
jas_stream_close (stream);
return ret;
/* ERRORS */
fail_stream:
{
GST_DEBUG_OBJECT (dec, "Failed to create inputstream.");
goto fail;
}
fail_decode:
{
GST_DEBUG_OBJECT (dec, "Failed to decode image.");
goto fail;
}
fail_image:
{
GST_DEBUG_OBJECT (dec, "Failed to process decoded image.");
goto fail;
}
fail:
{
if (*outbuf)
gst_buffer_unref (*outbuf);
*outbuf = NULL;
GST_ELEMENT_WARNING (dec, STREAM, DECODE, (NULL), (NULL));
ret = GST_FLOW_OK;
goto done;
}
no_buffer:
{
GST_DEBUG_OBJECT (dec, "Failed to create outbuffer - %s",
gst_flow_get_name (ret));
goto done;
}
fail_negotiate:
{
GST_DEBUG_OBJECT (dec, "Failed to determine output caps.");
goto done;
}
}
/* Perform qos calculations before decoding the next frame. Returns TRUE if the
* frame should be decoded, FALSE if the frame can be dropped entirely */
static gboolean
gst_jasper_dec_do_qos (GstJasperDec * dec, GstClockTime timestamp)
{
GstClockTime qostime, earliest_time;
gdouble proportion;
/* no timestamp, can't do QoS => decode frame */
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (timestamp))) {
GST_LOG_OBJECT (dec, "invalid timestamp, can't do QoS, decode frame");
return TRUE;
}
/* get latest QoS observation values */
gst_jasper_dec_read_qos (dec, &proportion, &earliest_time);
/* skip qos if we have no observation (yet) => decode frame */
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (earliest_time))) {
GST_LOG_OBJECT (dec, "no observation yet, decode frame");
return TRUE;
}
/* qos is done on running time */
qostime = gst_segment_to_running_time (&dec->segment, GST_FORMAT_TIME,
timestamp);
/* see how our next timestamp relates to the latest qos timestamp */
GST_LOG_OBJECT (dec, "qostime %" GST_TIME_FORMAT ", earliest %"
GST_TIME_FORMAT, GST_TIME_ARGS (qostime), GST_TIME_ARGS (earliest_time));
if (qostime != GST_CLOCK_TIME_NONE && qostime <= earliest_time) {
GST_DEBUG_OBJECT (dec, "we are late, drop frame");
return FALSE;
}
GST_LOG_OBJECT (dec, "decode frame");
return TRUE;
}
static GstFlowReturn
gst_jasper_dec_chain (GstPad * pad, GstBuffer * buf)
{
GstJasperDec *dec;
GstFlowReturn ret = GST_FLOW_OK;
GstClockTime ts;
GstBuffer *outbuf = NULL;
guint8 *data;
guint size;
gboolean decode;
dec = GST_JASPER_DEC (GST_PAD_PARENT (pad));
if (dec->fmt < 0)
goto not_negotiated;
ts = GST_BUFFER_TIMESTAMP (buf);
GST_LOG_OBJECT (dec, "buffer with ts: %" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT))
dec->discont = TRUE;
decode = gst_jasper_dec_do_qos (dec, ts);
/* FIXME: do clipping */
if (G_UNLIKELY (!decode)) {
dec->discont = TRUE;
goto done;
}
/* strip possible prefix */
if (dec->strip) {
GstBuffer *tmp;
tmp = gst_buffer_create_sub (buf, dec->strip,
GST_BUFFER_SIZE (buf) - dec->strip);
gst_buffer_copy_metadata (tmp, buf, GST_BUFFER_COPY_TIMESTAMPS);
gst_buffer_unref (buf);
buf = tmp;
}
/* preprend possible codec_data */
if (dec->codec_data) {
GstBuffer *tmp;
tmp =
gst_buffer_append (gst_buffer_ref (dec->codec_data),
gst_buffer_ref (buf));
gst_buffer_copy_metadata (tmp, buf, GST_BUFFER_COPY_TIMESTAMPS);
gst_buffer_unref (buf);
buf = tmp;
}
/* now really feed the data to decoder */
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
ret = gst_jasper_dec_get_picture (dec, data, size, &outbuf);
if (outbuf) {
gst_buffer_copy_metadata (outbuf, buf, GST_BUFFER_COPY_TIMESTAMPS);
if (dec->discont) {
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
dec->discont = FALSE;
}
if (ret == GST_FLOW_OK)
ret = gst_pad_push (dec->srcpad, outbuf);
else
gst_buffer_unref (outbuf);
}
done:
gst_buffer_unref (buf);
return ret;
/* ERRORS */
not_negotiated:
{
GST_ELEMENT_ERROR (dec, CORE, NEGOTIATION, (NULL),
("format wasn't negotiated before chain function"));
ret = GST_FLOW_NOT_NEGOTIATED;
goto done;
}
}
static void
gst_jasper_dec_update_qos (GstJasperDec * dec, gdouble proportion,
GstClockTime time)
{
GST_OBJECT_LOCK (dec);
dec->proportion = proportion;
dec->earliest_time = time;
GST_OBJECT_UNLOCK (dec);
}
static void
gst_jasper_dec_reset_qos (GstJasperDec * dec)
{
gst_jasper_dec_update_qos (dec, 0.5, GST_CLOCK_TIME_NONE);
}
static void
gst_jasper_dec_read_qos (GstJasperDec * dec, gdouble * proportion,
GstClockTime * time)
{
GST_OBJECT_LOCK (dec);
*proportion = dec->proportion;
*time = dec->earliest_time;
GST_OBJECT_UNLOCK (dec);
}
static gboolean
gst_jasper_dec_src_event (GstPad * pad, GstEvent * event)
{
GstJasperDec *dec;
gboolean res;
dec = GST_JASPER_DEC (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_QOS:{
GstClockTimeDiff diff;
GstClockTime timestamp;
gdouble proportion;
gst_event_parse_qos (event, &proportion, &diff, &timestamp);
gst_jasper_dec_update_qos (dec, proportion, timestamp + diff);
break;
}
default:
break;
}
res = gst_pad_push_event (dec->sinkpad, event);
gst_object_unref (dec);
return res;
}
static gboolean
gst_jasper_dec_sink_event (GstPad * pad, GstEvent * event)
{
GstJasperDec *dec;
gboolean res = FALSE;
dec = GST_JASPER_DEC (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_STOP:
gst_jasper_dec_reset_qos (dec);
gst_segment_init (&dec->segment, GST_FORMAT_TIME);
dec->discont = TRUE;
break;
case GST_EVENT_NEWSEGMENT:{
gboolean update;
GstFormat fmt;
gint64 start, stop, time;
gdouble rate, arate;
gst_event_parse_new_segment_full (event, &update, &rate, &arate, &fmt,
&start, &stop, &time);
switch (fmt) {
case GST_FORMAT_TIME:
/* great, our native segment format */
break;
case GST_FORMAT_BYTES:
/* hmm .. */
if (start != 0 || time != 0)
goto invalid_bytes_segment;
/* create bogus segment in TIME format, starting from 0 */
gst_event_unref (event);
fmt = GST_FORMAT_TIME;
start = 0;
stop = -1;
time = 0;
event = gst_event_new_new_segment (update, rate, fmt, start, stop,
time);
break;
default:
/* invalid format */
goto invalid_format;
}
gst_segment_set_newsegment_full (&dec->segment, update, rate, arate,
fmt, start, stop, time);
GST_DEBUG_OBJECT (dec, "NEWSEGMENT %" GST_SEGMENT_FORMAT, &dec->segment);
break;
}
default:
break;
}
res = gst_pad_push_event (dec->srcpad, event);
done:
gst_object_unref (dec);
return res;
/* ERRORS */
invalid_format:
{
GST_WARNING_OBJECT (dec, "unknown format received in NEWSEGMENT event");
gst_event_unref (event);
goto done;
}
invalid_bytes_segment:
{
GST_WARNING_OBJECT (dec, "can't handle NEWSEGMENT event in BYTES format "
"with a non-0 start or non-0 time value");
gst_event_unref (event);
goto done;
}
}
static GstStateChangeReturn
gst_jasper_dec_change_state (GstElement * element, GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstJasperDec *dec = GST_JASPER_DEC (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (jas_init ())
goto fail_init;
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_jasper_dec_reset (dec);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
jas_cleanup ();
break;
default:
break;
}
return ret;
/* ERRORS */
fail_init:
{
GST_ELEMENT_ERROR (dec, LIBRARY, INIT, (NULL), (NULL));
return GST_STATE_CHANGE_FAILURE;
}
}

View file

@ -1,98 +0,0 @@
/* GStreamer Jasper based j2k image decoder
* Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_JASPER_DEC_H__
#define __GST_JASPER_DEC_H__
#include <gst/gst.h>
#include <gst/video/video.h>
#include <jasper/jasper.h>
G_BEGIN_DECLS
/* #define's don't like whitespacey bits */
#define GST_TYPE_JASPER_DEC \
(gst_jasper_dec_get_type())
#define GST_JASPER_DEC(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_JASPER_DEC,GstJasperDec))
#define GST_JASPER_DEC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_JASPER_DEC,GstJasperDecClass))
#define GST_IS_JASPER_DEC(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_JASPER_DEC))
#define GST_IS_JASPER_DEC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_JASPER_DEC))
typedef struct _GstJasperDec GstJasperDec;
typedef struct _GstJasperDecClass GstJasperDecClass;
#define GST_JASPER_DEC_MAX_COMPONENT 4
struct _GstJasperDec
{
GstElement element;
GstPad *sinkpad, *srcpad;
GstBuffer *codec_data;
/* jasper image fmt */
gint fmt;
jas_clrspc_t clrspc;
gint strip;
/* stream/image properties */
GstVideoFormat format;
gint width;
gint height;
gint channels;
guint image_size;
gint stride[GST_JASPER_DEC_MAX_COMPONENT];
gint offset[GST_JASPER_DEC_MAX_COMPONENT];
gint inc[GST_JASPER_DEC_MAX_COMPONENT];
gboolean alpha;
glong *buf;
/* image cmpt indexed */
gint cwidth[GST_JASPER_DEC_MAX_COMPONENT];
gint cheight[GST_JASPER_DEC_MAX_COMPONENT];
/* standard video_format indexed */
gint cmpt[GST_JASPER_DEC_MAX_COMPONENT];
gint framerate_numerator;
gint framerate_denominator;
GstSegment segment;
gboolean discont;
/* QoS stuff *//* with LOCK */
gdouble proportion;
GstClockTime earliest_time;
};
struct _GstJasperDecClass
{
GstElementClass parent_class;
};
GType gst_jasper_dec_get_type (void);
G_END_DECLS
#endif /* __GST_JASPER_DEC_H__ */

View file

@ -1,565 +0,0 @@
/* GStreamer Jasper based j2k image encoder
* Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* SECTION:element-jasperenc
*
* Encodes video to jpeg2000 images.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gst/video/video.h>
#include <string.h>
#include <jasper/jasper.h>
#include "gstjasperenc.h"
GST_DEBUG_CATEGORY_STATIC (gst_jasper_enc_debug);
#define GST_CAT_DEFAULT gst_jasper_enc_debug
enum
{
ARG_0,
};
static GstStaticPadTemplate gst_jasper_enc_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB "; " GST_VIDEO_CAPS_BGR "; "
GST_VIDEO_CAPS_RGBx "; " GST_VIDEO_CAPS_xRGB "; "
GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_xBGR "; "
GST_VIDEO_CAPS_YUV ("{ I420, YV12, v308 }"))
);
static GstStaticPadTemplate gst_jasper_enc_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("image/x-j2c, width = " GST_VIDEO_SIZE_RANGE ", height = "
GST_VIDEO_SIZE_RANGE ", fourcc = (GstFourcc) { sRGB, sYUV },"
"framerate = " GST_VIDEO_FPS_RANGE ", " "fields = (int) 1; "
"image/x-jpc, width = " GST_VIDEO_SIZE_RANGE ", height = "
GST_VIDEO_SIZE_RANGE ", fourcc = (GstFourcc) { sRGB, sYUV },"
"framerate = " GST_VIDEO_FPS_RANGE ", " "fields = (int) 1; "
"image/jp2")
);
static void gst_jasper_enc_reset (GstJasperEnc * enc);
static GstStateChangeReturn gst_jasper_enc_change_state (GstElement * element,
GstStateChange transition);
static gboolean gst_jasper_enc_sink_setcaps (GstPad * pad, GstCaps * caps);
static GstFlowReturn gst_jasper_enc_chain (GstPad * pad, GstBuffer * buffer);
/* minor trick:
* keep original naming but use unique name here for a happy type system
*/
static void
_do_init (GType object_type)
{
const GInterfaceInfo preset_interface_info = {
NULL, /* interface_init */
NULL, /* interface_finalize */
NULL /* interface_data */
};
g_type_add_interface_static (object_type, GST_TYPE_PRESET,
&preset_interface_info);
}
GST_BOILERPLATE_FULL (GstJasperEnc, gst_jasper_enc, GstElement,
GST_TYPE_ELEMENT, _do_init);
static void
gst_jasper_enc_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_jasper_enc_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_jasper_enc_sink_template));
gst_element_class_set_static_metadata (element_class,
"Jasper JPEG2000 image encoder", "Codec/Encoder/Image",
"Encodes video to JPEG2000 using jasper",
"Mark Nauwelaerts <mnauw@users.sf.net>");
}
/* initialize the plugin's class */
static void
gst_jasper_enc_class_init (GstJasperEncClass * klass)
{
GstElementClass *gstelement_class;
gstelement_class = (GstElementClass *) klass;
GST_DEBUG_CATEGORY_INIT (gst_jasper_enc_debug, "jasperenc", 0,
"Jasper JPEG2000 encoder");
/* FIXME add some encoder properties */
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_jasper_enc_change_state);
}
static void
gst_jasper_enc_init (GstJasperEnc * enc, GstJasperEncClass * klass)
{
enc->sinkpad =
gst_pad_new_from_static_template (&gst_jasper_enc_sink_template, "sink");
gst_pad_set_setcaps_function (enc->sinkpad,
GST_DEBUG_FUNCPTR (gst_jasper_enc_sink_setcaps));
gst_pad_set_chain_function (enc->sinkpad,
GST_DEBUG_FUNCPTR (gst_jasper_enc_chain));
gst_element_add_pad (GST_ELEMENT (enc), enc->sinkpad);
enc->srcpad =
gst_pad_new_from_static_template (&gst_jasper_enc_src_template, "src");
gst_pad_use_fixed_caps (enc->srcpad);
gst_element_add_pad (GST_ELEMENT (enc), enc->srcpad);
enc->buf = NULL;
gst_jasper_enc_reset (enc);
}
static void
gst_jasper_enc_reset (GstJasperEnc * enc)
{
if (enc->buf)
g_free (enc->buf);
enc->buf = NULL;
if (enc->image)
jas_image_destroy (enc->image);
enc->image = NULL;
enc->fmt = -1;
enc->mode = GST_JP2ENC_MODE_J2C;
enc->clrspc = JAS_CLRSPC_UNKNOWN;
enc->format = GST_VIDEO_FORMAT_UNKNOWN;
}
static gboolean
gst_jasper_enc_set_src_caps (GstJasperEnc * enc)
{
GstCaps *caps;
guint32 fourcc;
gboolean ret;
GstCaps *peercaps;
peercaps = gst_pad_peer_get_caps (enc->srcpad);
if (peercaps) {
guint i, n;
n = gst_caps_get_size (peercaps);
for (i = 0; i < n; i++) {
GstStructure *s = gst_caps_get_structure (peercaps, i);
const gchar *name = gst_structure_get_name (s);
if (!strcmp (name, "image/x-j2c")) {
enc->mode = GST_JP2ENC_MODE_J2C;
break;
} else if (!strcmp (name, "image/x-jpc")) {
enc->mode = GST_JP2ENC_MODE_JPC;
break;
} else if (!strcmp (name, "image/jp2")) {
enc->mode = GST_JP2ENC_MODE_JP2;
break;
}
}
gst_caps_unref (peercaps);
}
/* enumerated colourspace */
if (gst_video_format_is_rgb (enc->format)) {
fourcc = GST_MAKE_FOURCC ('s', 'R', 'G', 'B');
} else {
fourcc = GST_MAKE_FOURCC ('s', 'Y', 'U', 'V');
}
switch (enc->mode) {
case GST_JP2ENC_MODE_J2C:
caps =
gst_caps_new_simple ("image/x-j2c", "width", G_TYPE_INT, enc->width,
"height", G_TYPE_INT, enc->height, "fourcc", GST_TYPE_FOURCC, fourcc,
NULL);
break;
case GST_JP2ENC_MODE_JPC:
caps =
gst_caps_new_simple ("image/x-jpc", "width", G_TYPE_INT, enc->width,
"height", G_TYPE_INT, enc->height, "fourcc", GST_TYPE_FOURCC, fourcc,
NULL);
break;
case GST_JP2ENC_MODE_JP2:
caps = gst_caps_new_simple ("image/jp2", "width", G_TYPE_INT, enc->width,
"height", G_TYPE_INT, enc->height, "fourcc", GST_TYPE_FOURCC, fourcc,
NULL);
break;
default:
g_assert_not_reached ();
}
if (enc->fps_den > 0)
gst_caps_set_simple (caps,
"framerate", GST_TYPE_FRACTION, enc->fps_num, enc->fps_den, NULL);
if (enc->par_den > 0)
gst_caps_set_simple (caps,
"pixel-aspect-ratio", GST_TYPE_FRACTION, enc->par_num, enc->par_den,
NULL);
ret = gst_pad_set_caps (enc->srcpad, caps);
gst_caps_unref (caps);
return ret;
}
static gboolean
gst_jasper_enc_init_encoder (GstJasperEnc * enc)
{
jas_image_cmptparm_t param[GST_JASPER_ENC_MAX_COMPONENT];
gint i;
switch (enc->mode) {
case GST_JP2ENC_MODE_J2C:
case GST_JP2ENC_MODE_JPC:
enc->fmt = jas_image_strtofmt ((char *) "jpc");
break;
case GST_JP2ENC_MODE_JP2:
enc->fmt = jas_image_strtofmt ((char *) "jp2");
break;
}
if (gst_video_format_is_rgb (enc->format))
enc->clrspc = JAS_CLRSPC_SRGB;
else
enc->clrspc = JAS_CLRSPC_SYCBCR;
if (enc->buf) {
g_free (enc->buf);
enc->buf = NULL;
}
enc->buf = g_new0 (glong, enc->width);
if (enc->image) {
jas_image_destroy (enc->image);
enc->image = NULL;
}
for (i = 0; i < enc->channels; ++i) {
param[i].tlx = 0;
param[i].tly = 0;
param[i].prec = 8;
param[i].sgnd = 0;
param[i].height = enc->cheight[i];
param[i].width = enc->cwidth[i];
param[i].hstep = enc->height / param[i].height;
param[i].vstep = enc->width / param[i].width;
}
if (!(enc->image = jas_image_create (enc->channels, param, enc->clrspc)))
return FALSE;
return TRUE;
}
static gboolean
gst_jasper_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
{
GstJasperEnc *enc;
GstVideoFormat format;
gint width, height;
gint fps_num, fps_den;
gint par_num, par_den;
gint i;
enc = GST_JASPER_ENC (GST_PAD_PARENT (pad));
/* get info from caps */
if (!gst_video_format_parse_caps (caps, &format, &width, &height))
goto refuse_caps;
/* optional; pass along if present */
fps_num = fps_den = -1;
par_num = par_den = -1;
gst_video_parse_caps_framerate (caps, &fps_num, &fps_den);
gst_video_parse_caps_pixel_aspect_ratio (caps, &par_num, &par_den);
if (width == enc->width && height == enc->height && enc->format == format
&& fps_num == enc->fps_num && fps_den == enc->fps_den
&& par_num == enc->par_num && par_den == enc->par_den)
return TRUE;
/* store input description */
enc->format = format;
enc->width = width;
enc->height = height;
enc->fps_num = fps_num;
enc->fps_den = fps_den;
enc->par_num = par_num;
enc->par_den = par_den;
/* prepare a cached image description */
enc->channels = 3 + (gst_video_format_has_alpha (format) ? 1 : 0);
for (i = 0; i < enc->channels; ++i) {
enc->cwidth[i] = gst_video_format_get_component_width (format, i, width);
enc->cheight[i] = gst_video_format_get_component_height (format, i, height);
enc->offset[i] = gst_video_format_get_component_offset (format, i, width,
height);
enc->stride[i] = gst_video_format_get_row_stride (format, i, width);
enc->inc[i] = gst_video_format_get_pixel_stride (format, i);
}
if (!gst_jasper_enc_set_src_caps (enc))
goto setcaps_failed;
if (!gst_jasper_enc_init_encoder (enc))
goto setup_failed;
return TRUE;
/* ERRORS */
setup_failed:
{
GST_ELEMENT_ERROR (enc, LIBRARY, SETTINGS, (NULL), (NULL));
return FALSE;
}
setcaps_failed:
{
GST_WARNING_OBJECT (enc, "Setting src caps failed");
GST_ELEMENT_ERROR (enc, LIBRARY, SETTINGS, (NULL), (NULL));
return FALSE;
}
refuse_caps:
{
GST_WARNING_OBJECT (enc, "refused caps %" GST_PTR_FORMAT, caps);
gst_object_unref (enc);
return FALSE;
}
}
static GstFlowReturn
gst_jasper_enc_get_data (GstJasperEnc * enc, guint8 * data, GstBuffer ** outbuf)
{
GstFlowReturn ret = GST_FLOW_OK;
jas_stream_t *stream = NULL;
gint i;
guint size, boxsize;
g_return_val_if_fail (outbuf != NULL, GST_FLOW_ERROR);
*outbuf = NULL;
boxsize = (enc->mode == GST_JP2ENC_MODE_J2C) ? 8 : 0;
if (!(stream = jas_stream_memopen (NULL, 0)))
goto fail_stream;
for (i = 0; i < enc->channels; ++i) {
gint x, y, cwidth, cheight, inc, stride, cmpt;
guint8 *row_pix, *in_pix;
glong *tb;
cmpt = i;
inc = enc->inc[i];
stride = enc->stride[i];
cheight = enc->cheight[cmpt];
cwidth = enc->cwidth[cmpt];
GST_LOG_OBJECT (enc,
"write component %d<=%d, size %dx%d, offset %d, inc %d, stride %d",
i, cmpt, cwidth, cheight, enc->offset[i], inc, stride);
row_pix = data + enc->offset[i];
for (y = 0; y < cheight; y++) {
in_pix = row_pix;
tb = enc->buf;
for (x = 0; x < cwidth; x++) {
*tb = *in_pix;
in_pix += inc;
tb++;
}
if (jas_image_writecmpt2 (enc->image, cmpt, 0, y, cwidth, 1, enc->buf))
goto fail_image;
row_pix += stride;
}
}
GST_LOG_OBJECT (enc, "all components written");
if (jas_image_encode (enc->image, stream, enc->fmt, (char *) "sop"))
goto fail_encode;
GST_LOG_OBJECT (enc, "image encoded");
size = jas_stream_length (stream);
ret = gst_pad_alloc_buffer_and_set_caps (enc->srcpad,
GST_BUFFER_OFFSET_NONE, size + boxsize, GST_PAD_CAPS (enc->srcpad),
outbuf);
if (ret != GST_FLOW_OK)
goto no_buffer;
data = GST_BUFFER_DATA (*outbuf);
if (jas_stream_flush (stream) ||
jas_stream_rewind (stream) < 0 ||
jas_stream_read (stream, data + boxsize, size) < size)
goto fail_image_out;
if (boxsize) {
/* write atom prefix */
GST_WRITE_UINT32_BE (data, size + 8);
GST_WRITE_UINT32_LE (data + 4, GST_MAKE_FOURCC ('j', 'p', '2', 'c'));
}
done:
if (stream)
jas_stream_close (stream);
return ret;
/* ERRORS */
fail_stream:
{
GST_DEBUG_OBJECT (enc, "Failed to create inputstream.");
goto fail;
}
fail_encode:
{
GST_DEBUG_OBJECT (enc, "Failed to encode image.");
goto fail;
}
fail_image:
{
GST_DEBUG_OBJECT (enc, "Failed to process input image.");
goto fail;
}
fail_image_out:
{
GST_DEBUG_OBJECT (enc, "Failed to process encoded image.");
goto fail;
}
fail:
{
if (*outbuf)
gst_buffer_unref (*outbuf);
*outbuf = NULL;
GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL), (NULL));
ret = GST_FLOW_ERROR;
goto done;
}
no_buffer:
{
GST_DEBUG_OBJECT (enc, "Failed to create outbuffer - %s",
gst_flow_get_name (ret));
goto done;
}
}
static GstFlowReturn
gst_jasper_enc_chain (GstPad * pad, GstBuffer * buf)
{
GstJasperEnc *enc;
GstFlowReturn ret = GST_FLOW_OK;
GstBuffer *outbuf = NULL;
guint8 *data;
gboolean discont = FALSE;
enc = GST_JASPER_ENC (gst_pad_get_parent (pad));
if (enc->fmt < 0)
goto not_negotiated;
GST_LOG_OBJECT (enc, "buffer with ts: %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
discont = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT);
/* now really feed the data to encoder */
data = GST_BUFFER_DATA (buf);
ret = gst_jasper_enc_get_data (enc, data, &outbuf);
if (outbuf) {
gst_buffer_copy_metadata (outbuf, buf, GST_BUFFER_COPY_TIMESTAMPS);
if (discont)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
}
if (ret == GST_FLOW_OK && outbuf)
ret = gst_pad_push (enc->srcpad, outbuf);
done:
gst_buffer_unref (buf);
gst_object_unref (enc);
return ret;
/* ERRORS */
not_negotiated:
{
GST_ELEMENT_ERROR (enc, CORE, NEGOTIATION, (NULL),
("format wasn't negotiated before chain function"));
ret = GST_FLOW_NOT_NEGOTIATED;
goto done;
}
}
static GstStateChangeReturn
gst_jasper_enc_change_state (GstElement * element, GstStateChange transition)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstJasperEnc *enc = GST_JASPER_ENC (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (jas_init ())
goto fail_init;
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_jasper_enc_reset (enc);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
jas_cleanup ();
break;
default:
break;
}
return ret;
/* ERRORS */
fail_init:
{
GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL), (NULL));
return GST_STATE_CHANGE_FAILURE;
}
}

View file

@ -1,91 +0,0 @@
/* GStreamer Jasper based j2k image encoder
* Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_JASPER_ENC_H__
#define __GST_JASPER_ENC_H__
#include <gst/gst.h>
#include <gst/video/video.h>
#include <jasper/jasper.h>
G_BEGIN_DECLS
/* #define's don't like whitespacey bits */
#define GST_TYPE_JASPER_ENC \
(gst_jasper_enc_get_type())
#define GST_JASPER_ENC(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_JASPER_ENC,GstJasperEnc))
#define GST_JASPER_ENC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_JASPER_ENC,GstJasperEncClass))
#define GST_IS_JASPER_ENC(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_JASPER_ENC))
#define GST_IS_JASPER_ENC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_JASPER_ENC))
typedef struct _GstJasperEnc GstJasperEnc;
typedef struct _GstJasperEncClass GstJasperEncClass;
enum {
GST_JP2ENC_MODE_J2C = 0,
GST_JP2ENC_MODE_JPC,
GST_JP2ENC_MODE_JP2
};
#define GST_JASPER_ENC_MAX_COMPONENT 4
struct _GstJasperEnc
{
GstElement element;
GstPad *sinkpad, *srcpad;
jas_image_t *image;
glong *buf;
/* jasper image fmt */
gint fmt;
gint mode;
jas_clrspc_t clrspc;
/* stream/image properties */
GstVideoFormat format;
gint width;
gint height;
gint channels;
gint fps_num, fps_den;
gint par_num, par_den;
/* standard video_format indexed */
gint stride[GST_JASPER_ENC_MAX_COMPONENT];
gint offset[GST_JASPER_ENC_MAX_COMPONENT];
gint inc[GST_JASPER_ENC_MAX_COMPONENT];
gint cwidth[GST_JASPER_ENC_MAX_COMPONENT];
gint cheight[GST_JASPER_ENC_MAX_COMPONENT];
};
struct _GstJasperEncClass
{
GstElementClass parent_class;
};
GType gst_jasper_enc_get_type (void);
G_END_DECLS
#endif /* __GST_JASPER_ENC_H__ */

View file

@ -28,7 +28,6 @@ BuildRequires: gtk-doc
BuildRequires: bzip2-devel
BuildRequires: celt-devel
BuildRequires: exempi-devel
BuildRequires: jasper-devel
BuildRequires: ladspa-devel
BuildRequires: libass-devel
%ifnarch s390 s390x