From 188bd155cde994b5c2a69b1a25a900c8b30d1608 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 3 Mar 2006 15:50:40 +0000 Subject: [PATCH] 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. --- ChangeLog | 22 +++ docs/plugins/Makefile.am | 4 + .../gst-plugins-good-plugins-docs.sgml | 4 + .../gst-plugins-good-plugins-sections.txt | 58 +++++++ .../gst-plugins-good-plugins.hierarchy | 1 + ext/jpeg/Makefile.am | 5 +- ext/jpeg/gstjpeg.c | 13 +- ext/jpeg/gstjpegdec.c | 4 +- ext/jpeg/gstjpegenc.h | 11 +- ext/jpeg/gstsmokedec.c | 163 +++++++++--------- ext/jpeg/gstsmokedec.h | 14 +- ext/jpeg/gstsmokeenc.c | 7 +- ext/jpeg/gstsmokeenc.h | 11 +- ext/jpeg/smokecodec.h | 2 + 14 files changed, 197 insertions(+), 122 deletions(-) diff --git a/ChangeLog b/ChangeLog index 23b96bb075..afd81eccce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2006-03-03 Wim Taymans + + * 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. + 2006-03-03 Wim Taymans * docs/plugins/Makefile.am: diff --git a/docs/plugins/Makefile.am b/docs/plugins/Makefile.am index 5a307da3a4..990e1fa145 100644 --- a/docs/plugins/Makefile.am +++ b/docs/plugins/Makefile.am @@ -87,6 +87,10 @@ EXTRA_HFILES = \ $(top_srcdir)/ext/flac/gstflacdec.h \ $(top_srcdir)/ext/hal/gsthalaudiosink.h \ $(top_srcdir)/ext/hal/gsthalaudiosrc.h \ + $(top_srcdir)/ext/jpeg/gstjpegdec.h \ + $(top_srcdir)/ext/jpeg/gstjpegenc.h \ + $(top_srcdir)/ext/jpeg/gstsmokedec.h \ + $(top_srcdir)/ext/jpeg/gstsmokeenc.h \ $(top_srcdir)/gst/multipart/multipartmux.c \ $(top_srcdir)/gst/multipart/multipartdemux.c \ $(top_srcdir)/gst/udp/gstudpsrc.h \ diff --git a/docs/plugins/gst-plugins-good-plugins-docs.sgml b/docs/plugins/gst-plugins-good-plugins-docs.sgml index a7d51e0ad9..721ebfea2d 100644 --- a/docs/plugins/gst-plugins-good-plugins-docs.sgml +++ b/docs/plugins/gst-plugins-good-plugins-docs.sgml @@ -24,11 +24,15 @@ + + + + diff --git a/docs/plugins/gst-plugins-good-plugins-sections.txt b/docs/plugins/gst-plugins-good-plugins-sections.txt index d9cc917832..a3e1ba48ed 100644 --- a/docs/plugins/gst-plugins-good-plugins-sections.txt +++ b/docs/plugins/gst-plugins-good-plugins-sections.txt @@ -94,6 +94,64 @@ GstHalAudioSrc GstHalAudioSrcClass +
+element-jpegdec +GstJpegDec +GstJpegDecErrorMgr +GstJpegDecSourceMgr +jpegdec + +GstJpegDecClass +GST_JPEG_DEC +GST_IS_JPEG_DEC +GST_TYPE_JPEG_DEC +gst_jpeg_dec_get_type +GST_JPEG_DEC_CLASS +GST_IS_JPEG_DEC_CLASS +
+ +
+element-jpegenc +jpegenc +GstJpegEnc + +GstJpegEncClass +GST_JPEGENC +GST_IS_JPEGENC +GST_TYPE_JPEGENC +gst_jpegenc_get_type +GST_JPEGENC_CLASS +GST_IS_JPEGENC_CLASS +
+ +
+element-smokedec +GstSmokeDec +smokedec + +GstSmokeDecClass +GST_SMOKEDEC +GST_IS_SMOKEDEC +GST_TYPE_SMOKEDEC +gst_smokedec_get_type +GST_SMOKEDEC_CLASS +GST_IS_SMOKEDEC_CLASS +
+ +
+element-smokeenc +GstSmokeEnc +smokeenc + +GstSmokeEncClass +GST_SMOKEENC +GST_IS_SMOKEENC +GST_TYPE_SMOKEENC +gst_smokeenc_get_type +GST_SMOKEENC_CLASS +GST_IS_SMOKEENC_CLASS +
+
element-id3demux GstID3Demux diff --git a/docs/plugins/gst-plugins-good-plugins.hierarchy b/docs/plugins/gst-plugins-good-plugins.hierarchy index c11200174d..6210a5ecb2 100644 --- a/docs/plugins/gst-plugins-good-plugins.hierarchy +++ b/docs/plugins/gst-plugins-good-plugins.hierarchy @@ -39,6 +39,7 @@ GObject GstPngEnc GstJpegEnc GstJpegDec + GstSmokeDec GstSmokeEnc GstFlacEnc GstFlacDec diff --git a/ext/jpeg/Makefile.am b/ext/jpeg/Makefile.am index e7c88f1ca9..a2142cecb5 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 43d7cdf749..bfb62549e5 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 eb5fb81392..84f3539071 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 d2f9401f36..74b8409dd9 100644 --- a/ext/jpeg/gstjpegenc.h +++ b/ext/jpeg/gstjpegenc.h @@ -29,10 +29,7 @@ #endif #include -#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 8aebefc7ef..88fa726f16 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_pad_get_parent (pad)); - smokedec = GST_SMOKEDEC (GST_OBJECT_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; + smokeret = smokecodec_decode (smokedec->info, data, size, outdata); + if (smokeret != SMOKECODEC_OK) + goto decode_error; - smokedec->height = height; + GST_DEBUG_OBJECT (smokedec, "gst_smokedec_chain: sending buffer"); + ret = gst_pad_push (smokedec->srcpad, outbuf); - 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); +done: + gst_buffer_unref (buf); + gst_object_unref (smokedec); + + return ret; + + /* ERRORS */ +header_error: + { + GST_ELEMENT_ERROR (smokedec, STREAM, DECODE, + (NULL), ("Could not parse smoke header, reason: %d", smokeret)); + ret = GST_FLOW_ERROR; + goto done; } - - 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; - } +keyframe_skip: + { + GST_DEBUG_OBJECT (smokedec, "dropping buffer while waiting for keyframe"); + ret = GST_FLOW_OK; + goto done; } - - if (!smokedec->need_keyframe) { - smokecodec_decode (smokedec->info, data, size, outdata); - gst_buffer_unref (buf); - - GST_DEBUG ("gst_smokedec_chain: sending buffer"); - gst_pad_push (smokedec->srcpad, GST_DATA (outbuf)); +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 d3e73d9081..8e62d02ea6 100644 --- a/ext/jpeg/gstsmokedec.h +++ b/ext/jpeg/gstsmokedec.h @@ -25,10 +25,7 @@ #include #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 de62a9be5f..392f0a887b 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 9c9f643048..2ebc6ec6fa 100644 --- a/ext/jpeg/gstsmokeenc.h +++ b/ext/jpeg/gstsmokeenc.h @@ -25,10 +25,7 @@ #include #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 b6b7e305d8..a44d9bb242 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,