summaryrefslogtreecommitdiff
path: root/ext/jpeg
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2006-03-03 15:50:40 +0000
committerWim Taymans <wim.taymans@gmail.com>2006-03-03 15:50:40 +0000
commit188bd155cde994b5c2a69b1a25a900c8b30d1608 (patch)
treedb7cab9fcb72f9aedf01f0224609061ae5283a9c /ext/jpeg
parente85d1638c3e2199998ed8a31af1a2c654354fcba (diff)
docs/plugins/: Added smoke and jpeg to the docs.
Original commit message from CVS: * docs/plugins/Makefile.am: * docs/plugins/gst-plugins-good-plugins-docs.sgml: * docs/plugins/gst-plugins-good-plugins-sections.txt: * docs/plugins/gst-plugins-good-plugins.hierarchy: Added smoke and jpeg to the docs. * ext/jpeg/Makefile.am: * ext/jpeg/gstjpeg.c: (plugin_init): * ext/jpeg/gstjpegdec.c: (gst_jpeg_dec_chain): * ext/jpeg/gstjpegenc.h: * ext/jpeg/gstsmokedec.c: (gst_smokedec_init), (gst_smokedec_chain): * ext/jpeg/gstsmokedec.h: * ext/jpeg/gstsmokeenc.c: (gst_smokeenc_chain): * ext/jpeg/gstsmokeenc.h: * ext/jpeg/smokecodec.h: Port smokedec (fixes #331905). Added some docs. Some cleanups.
Diffstat (limited to 'ext/jpeg')
-rw-r--r--ext/jpeg/Makefile.am5
-rw-r--r--ext/jpeg/gstjpeg.c13
-rw-r--r--ext/jpeg/gstjpegdec.c4
-rw-r--r--ext/jpeg/gstjpegenc.h11
-rw-r--r--ext/jpeg/gstsmokedec.c163
-rw-r--r--ext/jpeg/gstsmokedec.h14
-rw-r--r--ext/jpeg/gstsmokeenc.c7
-rw-r--r--ext/jpeg/gstsmokeenc.h11
-rw-r--r--ext/jpeg/smokecodec.h2
9 files changed, 108 insertions, 122 deletions
diff --git a/ext/jpeg/Makefile.am b/ext/jpeg/Makefile.am
index e7c88f1ca..a2142cecb 100644
--- a/ext/jpeg/Makefile.am
+++ b/ext/jpeg/Makefile.am
@@ -5,9 +5,8 @@ libgstjpeg_la_SOURCES = \
gstjpegenc.c \
gstjpegdec.c \
gstsmokeenc.c \
- smokecodec.c
-
-# gstsmokedec.c
+ smokecodec.c \
+ gstsmokedec.c
libgstjpeg_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
libgstjpeg_la_LIBADD = $(GST_LIBS) $(JPEG_LIBS)
diff --git a/ext/jpeg/gstjpeg.c b/ext/jpeg/gstjpeg.c
index 43d7cdf74..bfb62549e 100644
--- a/ext/jpeg/gstjpeg.c
+++ b/ext/jpeg/gstjpeg.c
@@ -27,11 +27,11 @@
#include "gstjpegdec.h"
#include "gstjpegenc.h"
#include "gstsmokeenc.h"
-/*
#include "gstsmokedec.h"
-
+#if 0
static GstStaticCaps smoke_caps = GST_STATIC_CAPS ("video/x-smoke");
+
#define SMOKE_CAPS (gst_static_caps_get(&smoke_caps))
static void
smoke_type_find (GstTypeFind * tf, gpointer private)
@@ -46,7 +46,7 @@ smoke_type_find (GstTypeFind * tf, gpointer private)
gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, SMOKE_CAPS);
}
}
-*/
+#endif
static gboolean
plugin_init (GstPlugin * plugin)
@@ -63,15 +63,16 @@ plugin_init (GstPlugin * plugin)
if (!gst_element_register (plugin, "smokeenc", GST_RANK_PRIMARY,
GST_TYPE_SMOKEENC))
return FALSE;
-/*
+
if (!gst_element_register (plugin, "smokedec", GST_RANK_PRIMARY,
GST_TYPE_SMOKEDEC))
- return FALSE;
+ return FALSE;
+#if 0
if (!gst_type_find_register (plugin, "video/x-smoke", GST_RANK_PRIMARY,
smoke_type_find, NULL, SMOKE_CAPS, NULL))
return FALSE;
-*/
+#endif
return TRUE;
}
diff --git a/ext/jpeg/gstjpegdec.c b/ext/jpeg/gstjpegdec.c
index eb5fb8139..84f353907 100644
--- a/ext/jpeg/gstjpegdec.c
+++ b/ext/jpeg/gstjpegdec.c
@@ -828,8 +828,8 @@ gst_jpeg_dec_chain (GstPad * pad, GstBuffer * buf)
GstClockTime next_ts;
dec->frames_decoded++;
- next_ts = dec->frames_decoded * GST_SECOND *
- dec->framerate_denominator / dec->framerate_numerator;
+ next_ts = gst_util_uint64_scale (dec->frames_decoded,
+ GST_SECOND * dec->framerate_denominator, dec->framerate_numerator);
duration = next_ts - dec->next_ts;
dec->next_ts = next_ts;
diff --git a/ext/jpeg/gstjpegenc.h b/ext/jpeg/gstjpegenc.h
index d2f9401f3..74b8409dd 100644
--- a/ext/jpeg/gstjpegenc.h
+++ b/ext/jpeg/gstjpegenc.h
@@ -29,10 +29,7 @@
#endif
#include <jpeglib.h>
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
+G_BEGIN_DECLS
#define GST_TYPE_JPEGENC \
(gst_jpegenc_get_type())
@@ -82,10 +79,6 @@ struct _GstJpegEncClass {
GType gst_jpegenc_get_type(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
+G_END_DECLS
#endif /* __GST_JPEGENC_H__ */
diff --git a/ext/jpeg/gstsmokedec.c b/ext/jpeg/gstsmokedec.c
index 8aebefc7e..88fa726f1 100644
--- a/ext/jpeg/gstsmokedec.c
+++ b/ext/jpeg/gstsmokedec.c
@@ -41,22 +41,19 @@ GST_DEBUG_CATEGORY (smokedec_debug);
/* SmokeDec signals and args */
enum
{
- /* FILL ME */
LAST_SIGNAL
};
enum
{
- ARG_0
- /* FILL ME */
+ PROP_0
};
static void gst_smokedec_base_init (gpointer g_class);
static void gst_smokedec_class_init (GstSmokeDec * klass);
static void gst_smokedec_init (GstSmokeDec * smokedec);
-static void gst_smokedec_chain (GstPad * pad, GstData * _data);
-static GstPadLinkReturn gst_smokedec_link (GstPad * pad, const GstCaps * caps);
+static GstFlowReturn gst_smokedec_chain (GstPad * pad, GstBuffer * buf);
static GstElementClass *parent_class = NULL;
@@ -100,7 +97,7 @@ GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-smoke, "
"width = (int) [ 16, 4096 ], "
- "height = (int) [ 16, 4096 ], " "framerate = (double) [ 1, MAX ]")
+ "height = (int) [ 16, 4096 ], " "framerate = (fraction) [ 0/1, MAX ]")
);
static void
@@ -130,94 +127,96 @@ gst_smokedec_class_init (GstSmokeDec * klass)
static void
gst_smokedec_init (GstSmokeDec * smokedec)
{
- GST_DEBUG ("gst_smokedec_init: initializing");
+ GST_DEBUG_OBJECT (smokedec, "gst_smokedec_init: initializing");
/* create the sink and src pads */
smokedec->sinkpad =
gst_pad_new_from_template (gst_static_pad_template_get
(&gst_smokedec_sink_pad_template), "sink");
- gst_element_add_pad (GST_ELEMENT (smokedec), smokedec->sinkpad);
gst_pad_set_chain_function (smokedec->sinkpad, gst_smokedec_chain);
- gst_pad_set_link_function (smokedec->sinkpad, gst_smokedec_link);
+ gst_element_add_pad (GST_ELEMENT (smokedec), smokedec->sinkpad);
smokedec->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get
(&gst_smokedec_src_pad_template), "src");
- gst_pad_use_explicit_caps (smokedec->srcpad);
+ gst_pad_use_fixed_caps (smokedec->srcpad);
gst_element_add_pad (GST_ELEMENT (smokedec), smokedec->srcpad);
/* reset the initial video state */
smokedec->format = -1;
smokedec->width = -1;
smokedec->height = -1;
+ smokedec->fps_num = -1;
+ smokedec->fps_denom = -1;
smokedec->next_time = 0;
-}
-
-static GstPadLinkReturn
-gst_smokedec_link (GstPad * pad, const GstCaps * caps)
-{
- GstSmokeDec *smokedec = GST_SMOKEDEC (gst_pad_get_parent (pad));
- GstStructure *structure;
- GstCaps *srccaps;
-
- structure = gst_caps_get_structure (caps, 0);
-
- gst_structure_get_double (structure, "framerate", &smokedec->fps);
- gst_structure_get_int (structure, "width", &smokedec->width);
- gst_structure_get_int (structure, "height", &smokedec->height);
-
- srccaps = gst_caps_new_simple ("video/x-raw-yuv",
- "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),
- "width", G_TYPE_INT, smokedec->width,
- "height", G_TYPE_INT, smokedec->height,
- "framerate", G_TYPE_DOUBLE, smokedec->fps, NULL);
-
- /* at this point, we're pretty sure that this will be the output
- * format, so we'll set it. */
- gst_pad_set_explicit_caps (smokedec->srcpad, srccaps);
smokecodec_decode_new (&smokedec->info);
-
- return GST_PAD_LINK_OK;
}
-static void
-gst_smokedec_chain (GstPad * pad, GstData * _data)
+static GstFlowReturn
+gst_smokedec_chain (GstPad * pad, GstBuffer * buf)
{
- GstBuffer *buf = GST_BUFFER (_data);
GstSmokeDec *smokedec;
- guchar *data, *outdata;
+ guint8 *data, *outdata;
gulong size, outsize;
GstBuffer *outbuf;
SmokeCodecFlags flags;
GstClockTime time;
+ guint width, height;
+ guint fps_num, fps_denom;
+ gint smokeret;
+ GstFlowReturn ret;
- gint width, height;
- gint fps_num, fps_denom;
-
- smokedec = GST_SMOKEDEC (GST_OBJECT_PARENT (pad));
+ smokedec = GST_SMOKEDEC (gst_pad_get_parent (pad));
- if (!GST_PAD_IS_LINKED (smokedec->srcpad)) {
- gst_buffer_unref (buf);
- return;
- }
-
- data = (guchar *) GST_BUFFER_DATA (buf);
+ data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
time = GST_BUFFER_TIMESTAMP (buf);
- GST_DEBUG ("gst_smokedec_chain: got buffer of %ld bytes in '%s'", size,
+ GST_DEBUG_OBJECT (smokedec,
+ "gst_smokedec_chain: got buffer of %ld bytes in '%s'", size,
GST_OBJECT_NAME (smokedec));
+ /* have the ID packet. */
if (data[0] == SMOKECODEC_TYPE_ID) {
- smokecodec_parse_id (smokedec->info, data, size);
- return;
+ smokeret = smokecodec_parse_id (smokedec->info, data, size);
+ if (smokeret != SMOKECODEC_OK)
+ goto header_error;
+
+ return GST_FLOW_OK;
}
- GST_DEBUG ("gst_smokedec_chain: reading header %08lx", *(gulong *) data);
+ /* now handle data packets */
+ GST_DEBUG_OBJECT (smokedec, "gst_smokedec_chain: reading header %08lx",
+ *(gulong *) data);
smokecodec_parse_header (smokedec->info, data, size, &flags, &width, &height,
&fps_num, &fps_denom);
+ if (smokedec->height != height || smokedec->width != width ||
+ smokedec->fps_num != fps_num || smokedec->fps_denom != fps_denom) {
+ GstCaps *caps;
+
+ smokedec->height = height;
+ smokedec->width = width;
+
+ caps = gst_caps_new_simple ("video/x-raw-yuv",
+ "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),
+ "width", G_TYPE_INT, width,
+ "height", G_TYPE_INT, height,
+ "framerate", GST_TYPE_FRACTION, fps_num, fps_denom, NULL);
+
+ gst_pad_set_caps (smokedec->srcpad, caps);
+ gst_caps_unref (caps);
+ }
+
+
+ if (smokedec->need_keyframe) {
+ if (!(flags & SMOKECODEC_KEYFRAME))
+ goto keyframe_skip;
+
+ smokedec->need_keyframe = FALSE;
+ }
+
outbuf = gst_buffer_new ();
outsize = GST_BUFFER_SIZE (outbuf) = width * height + width * height / 2;
outdata = g_malloc (outsize);
@@ -226,6 +225,7 @@ gst_smokedec_chain (GstPad * pad, GstData * _data)
GST_BUFFER_DURATION (outbuf) = GST_SECOND * fps_denom / fps_num;
GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buf);
+ gst_buffer_set_caps (outbuf, GST_PAD_CAPS (smokedec->srcpad));
if (time == GST_CLOCK_TIME_NONE) {
if (GST_BUFFER_OFFSET (buf) == -1) {
@@ -237,35 +237,38 @@ gst_smokedec_chain (GstPad * pad, GstData * _data)
GST_BUFFER_TIMESTAMP (outbuf) = time;
smokedec->next_time = time + GST_BUFFER_DURATION (outbuf);
- if (smokedec->height != height) {
- GstCaps *caps;
-
- smokedec->height = height;
+ smokeret = smokecodec_decode (smokedec->info, data, size, outdata);
+ if (smokeret != SMOKECODEC_OK)
+ goto decode_error;
- caps = gst_caps_new_simple ("video/x-raw-yuv",
- "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),
- "width", G_TYPE_INT, width,
- "height", G_TYPE_INT, height,
- "framerate", G_TYPE_DOUBLE, ((double) fps_num) / fps_denom, NULL);
- gst_pad_set_explicit_caps (smokedec->srcpad, caps);
- gst_caps_free (caps);
- }
+ GST_DEBUG_OBJECT (smokedec, "gst_smokedec_chain: sending buffer");
+ ret = gst_pad_push (smokedec->srcpad, outbuf);
- if (smokedec->need_keyframe) {
- if (flags & SMOKECODEC_KEYFRAME) {
- smokedec->need_keyframe = FALSE;
- } else {
- GST_DEBUG_OBJECT (smokedec, "dropping buffer while waiting for keyframe");
- gst_buffer_unref (buf);
- return;
- }
- }
+done:
+ gst_buffer_unref (buf);
+ gst_object_unref (smokedec);
- if (!smokedec->need_keyframe) {
- smokecodec_decode (smokedec->info, data, size, outdata);
- gst_buffer_unref (buf);
+ return ret;
- GST_DEBUG ("gst_smokedec_chain: sending buffer");
- gst_pad_push (smokedec->srcpad, GST_DATA (outbuf));
+ /* ERRORS */
+header_error:
+ {
+ GST_ELEMENT_ERROR (smokedec, STREAM, DECODE,
+ (NULL), ("Could not parse smoke header, reason: %d", smokeret));
+ ret = GST_FLOW_ERROR;
+ goto done;
+ }
+keyframe_skip:
+ {
+ GST_DEBUG_OBJECT (smokedec, "dropping buffer while waiting for keyframe");
+ ret = GST_FLOW_OK;
+ goto done;
+ }
+decode_error:
+ {
+ GST_ELEMENT_ERROR (smokedec, STREAM, DECODE,
+ (NULL), ("Could not decode smoke frame, reason: %d", smokeret));
+ ret = GST_FLOW_ERROR;
+ goto done;
}
}
diff --git a/ext/jpeg/gstsmokedec.h b/ext/jpeg/gstsmokedec.h
index d3e73d908..8e62d02ea 100644
--- a/ext/jpeg/gstsmokedec.h
+++ b/ext/jpeg/gstsmokedec.h
@@ -25,10 +25,7 @@
#include <gst/gst.h>
#include "smokecodec.h"
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
+G_BEGIN_DECLS
#define GST_TYPE_SMOKEDEC \
(gst_smokedec_get_type())
@@ -54,7 +51,8 @@ struct _GstSmokeDec {
gint format;
gint width;
gint height;
- gdouble fps;
+ gint fps_num;
+ gint fps_denom;
GstClockTime next_time;
SmokeCodecInfo *info;
@@ -72,10 +70,6 @@ struct _GstSmokeDecClass {
GType gst_smokedec_get_type(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
+G_END_DECLS
#endif /* __GST_SMOKEDEC_H__ */
diff --git a/ext/jpeg/gstsmokeenc.c b/ext/jpeg/gstsmokeenc.c
index de62a9be5..392f0a887 100644
--- a/ext/jpeg/gstsmokeenc.c
+++ b/ext/jpeg/gstsmokeenc.c
@@ -296,6 +296,7 @@ gst_smokeenc_chain (GstPad * pad, GstBuffer * buf)
guint encsize;
GstBuffer *outbuf;
SmokeCodecFlags flags;
+ GstFlowReturn ret;
smokeenc = GST_SMOKEENC (GST_OBJECT_PARENT (pad));
@@ -318,7 +319,7 @@ gst_smokeenc_chain (GstPad * pad, GstBuffer * buf)
GST_BUFFER_SIZE (outbuf) = encsize;
- gst_pad_push (smokeenc->srcpad, outbuf);
+ ret = gst_pad_push (smokeenc->srcpad, outbuf);
smokeenc->need_header = FALSE;
}
@@ -346,11 +347,11 @@ gst_smokeenc_chain (GstPad * pad, GstBuffer * buf)
GST_BUFFER_OFFSET (outbuf) = smokeenc->frame;
GST_BUFFER_OFFSET_END (outbuf) = smokeenc->frame + 1;
- gst_pad_push (smokeenc->srcpad, outbuf);
+ ret = gst_pad_push (smokeenc->srcpad, outbuf);
smokeenc->frame++;
- return GST_FLOW_OK;
+ return ret;
}
static void
diff --git a/ext/jpeg/gstsmokeenc.h b/ext/jpeg/gstsmokeenc.h
index 9c9f64304..2ebc6ec6f 100644
--- a/ext/jpeg/gstsmokeenc.h
+++ b/ext/jpeg/gstsmokeenc.h
@@ -25,10 +25,7 @@
#include <gst/gst.h>
#include "smokecodec.h"
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
+G_BEGIN_DECLS
#define GST_TYPE_SMOKEENC \
(gst_smokeenc_get_type())
@@ -73,10 +70,6 @@ struct _GstSmokeEncClass {
GType gst_smokeenc_get_type(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
+G_END_DECLS
#endif /* __GST_SMOKEENC_H__ */
diff --git a/ext/jpeg/smokecodec.h b/ext/jpeg/smokecodec.h
index b6b7e305d..a44d9bb24 100644
--- a/ext/jpeg/smokecodec.h
+++ b/ext/jpeg/smokecodec.h
@@ -61,6 +61,8 @@ int smokecodec_encode_new (SmokeCodecInfo **info,
int smokecodec_decode_new (SmokeCodecInfo **info);
+int smokecodec_info_free (SmokeCodecInfo * info);
+
/* config */
SmokeCodecResult smokecodec_set_quality (SmokeCodecInfo *info,
const unsigned int min,