jpeg: code cleanups for encoder
Remove some disabled code in encoder. Try #if 0'ed code and add comments about why it is disabled. Move idct-method enum to jpeg.c and use in both encoder and decoder. Add idct-method property to encoder.
This commit is contained in:
parent
b7bf2f6820
commit
11c93fc1df
@ -29,6 +29,23 @@
|
|||||||
#include "gstsmokeenc.h"
|
#include "gstsmokeenc.h"
|
||||||
#include "gstsmokedec.h"
|
#include "gstsmokedec.h"
|
||||||
|
|
||||||
|
GType
|
||||||
|
gst_idct_method_get_type (void)
|
||||||
|
{
|
||||||
|
static GType idct_method_type = 0;
|
||||||
|
static const GEnumValue idct_method[] = {
|
||||||
|
{JDCT_ISLOW, "Slow but accurate integer algorithm", "islow"},
|
||||||
|
{JDCT_IFAST, "Faster, less accurate integer method", "ifast"},
|
||||||
|
{JDCT_FLOAT, "Floating-point: accurate, fast on fast HW", "float"},
|
||||||
|
{0, NULL, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!idct_method_type) {
|
||||||
|
idct_method_type = g_enum_register_static ("GstIDCTMethod", idct_method);
|
||||||
|
}
|
||||||
|
return idct_method_type;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
plugin_init (GstPlugin * plugin)
|
plugin_init (GstPlugin * plugin)
|
||||||
{
|
{
|
||||||
|
@ -60,23 +60,8 @@ enum
|
|||||||
PROP_IDCT_METHOD
|
PROP_IDCT_METHOD
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern GType gst_idct_method_get_type (void);
|
||||||
#define GST_TYPE_IDCT_METHOD (gst_idct_method_get_type())
|
#define GST_TYPE_IDCT_METHOD (gst_idct_method_get_type())
|
||||||
static GType
|
|
||||||
gst_idct_method_get_type (void)
|
|
||||||
{
|
|
||||||
static GType idct_method_type = 0;
|
|
||||||
static const GEnumValue idct_method[] = {
|
|
||||||
{JDCT_ISLOW, "Slow but accurate integer algorithm", "islow"},
|
|
||||||
{JDCT_IFAST, "Faster, less accurate integer method", "ifast"},
|
|
||||||
{JDCT_FLOAT, "Floating-point: accurate, fast on fast HW", "float"},
|
|
||||||
{0, NULL, NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!idct_method_type) {
|
|
||||||
idct_method_type = g_enum_register_static ("GstIDCTMethod", idct_method);
|
|
||||||
}
|
|
||||||
return idct_method_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_jpeg_dec_src_pad_template =
|
static GstStaticPadTemplate gst_jpeg_dec_src_pad_template =
|
||||||
GST_STATIC_PAD_TEMPLATE ("src",
|
GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
|
@ -38,6 +38,12 @@
|
|||||||
#include "gstjpegenc.h"
|
#include "gstjpegenc.h"
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
|
|
||||||
|
/* experimental */
|
||||||
|
/* setting smoothig seems to have no effect in libjepeg
|
||||||
|
#define ENABLE_SMOOTHING 1
|
||||||
|
*/
|
||||||
|
/*#define ENABLE_COLORSPACE_RGB 1 */
|
||||||
|
|
||||||
/* elementfactory information */
|
/* elementfactory information */
|
||||||
static const GstElementDetails gst_jpegenc_details =
|
static const GstElementDetails gst_jpegenc_details =
|
||||||
GST_ELEMENT_DETAILS ("JPEG image encoder",
|
GST_ELEMENT_DETAILS ("JPEG image encoder",
|
||||||
@ -48,7 +54,9 @@ GST_ELEMENT_DETAILS ("JPEG image encoder",
|
|||||||
GST_DEBUG_CATEGORY_STATIC (jpegenc_debug);
|
GST_DEBUG_CATEGORY_STATIC (jpegenc_debug);
|
||||||
#define GST_CAT_DEFAULT jpegenc_debug
|
#define GST_CAT_DEFAULT jpegenc_debug
|
||||||
|
|
||||||
#define JPEG_DEFAULT_QUALITY 85
|
#define DEFAULT_QUALITY 85
|
||||||
|
#define DEFAULT_SMOOTHING 0
|
||||||
|
#define DEFAULT_IDCT_METHOD JDCT_FASTEST
|
||||||
|
|
||||||
/* These macros are adapted from videotestsrc.c
|
/* These macros are adapted from videotestsrc.c
|
||||||
* and/or gst-plugins/gst/games/gstvideoimage.c */
|
* and/or gst-plugins/gst/games/gstvideoimage.c */
|
||||||
@ -74,12 +82,15 @@ enum
|
|||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ARG_0,
|
PROP_0,
|
||||||
ARG_QUALITY,
|
PROP_QUALITY,
|
||||||
ARG_SMOOTHING
|
PROP_SMOOTHING,
|
||||||
/* FILL ME */
|
PROP_IDCT_METHOD
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern GType gst_idct_method_get_type (void);
|
||||||
|
#define GST_TYPE_IDCT_METHOD (gst_idct_method_get_type())
|
||||||
|
|
||||||
static void gst_jpegenc_base_init (gpointer g_class);
|
static void gst_jpegenc_base_init (gpointer g_class);
|
||||||
static void gst_jpegenc_class_init (GstJpegEnc * klass);
|
static void gst_jpegenc_class_init (GstJpegEnc * klass);
|
||||||
static void gst_jpegenc_init (GstJpegEnc * jpegenc);
|
static void gst_jpegenc_init (GstJpegEnc * jpegenc);
|
||||||
@ -174,16 +185,22 @@ gst_jpegenc_class_init (GstJpegEnc * klass)
|
|||||||
gobject_class->get_property = gst_jpegenc_get_property;
|
gobject_class->get_property = gst_jpegenc_get_property;
|
||||||
|
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_QUALITY,
|
g_object_class_install_property (gobject_class, PROP_QUALITY,
|
||||||
g_param_spec_int ("quality", "Quality", "Quality of encoding",
|
g_param_spec_int ("quality", "Quality", "Quality of encoding",
|
||||||
0, 100, JPEG_DEFAULT_QUALITY, G_PARAM_READWRITE));
|
0, 100, DEFAULT_QUALITY, G_PARAM_READWRITE));
|
||||||
#if 0
|
|
||||||
|
#if ENABLE_SMOOTHING
|
||||||
/* disabled, since it doesn't seem to work */
|
/* disabled, since it doesn't seem to work */
|
||||||
g_object_class_install_property (gobject_class, ARG_SMOOTHING,
|
g_object_class_install_property (gobject_class, PROP_SMOOTHING,
|
||||||
g_param_spec_int ("smoothing", "Smoothing", "Smoothing factor",
|
g_param_spec_int ("smoothing", "Smoothing", "Smoothing factor",
|
||||||
0, 100, 0, G_PARAM_READWRITE));
|
0, 100, DEFAULT_SMOOTHING, G_PARAM_READWRITE));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class, PROP_IDCT_METHOD,
|
||||||
|
g_param_spec_enum ("idct-method", "IDCT Method",
|
||||||
|
"The IDCT algorithm to use", GST_TYPE_IDCT_METHOD,
|
||||||
|
DEFAULT_IDCT_METHOD, G_PARAM_READWRITE));
|
||||||
|
|
||||||
gstelement_class->change_state = gst_jpegenc_change_state;
|
gstelement_class->change_state = gst_jpegenc_change_state;
|
||||||
|
|
||||||
gobject_class->finalize = gst_jpegenc_finalize;
|
gobject_class->finalize = gst_jpegenc_finalize;
|
||||||
@ -248,14 +265,15 @@ gst_jpegenc_init (GstJpegEnc * jpegenc)
|
|||||||
jpegenc->jdest.term_destination = gst_jpegenc_term_destination;
|
jpegenc->jdest.term_destination = gst_jpegenc_term_destination;
|
||||||
jpegenc->cinfo.dest = &jpegenc->jdest;
|
jpegenc->cinfo.dest = &jpegenc->jdest;
|
||||||
|
|
||||||
jpegenc->quality = JPEG_DEFAULT_QUALITY;
|
/* init properties */
|
||||||
jpegenc->smoothing = 0;
|
jpegenc->quality = DEFAULT_QUALITY;
|
||||||
|
jpegenc->smoothing = DEFAULT_SMOOTHING;
|
||||||
|
jpegenc->idct_method = DEFAULT_IDCT_METHOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_jpegenc_finalize (GObject * object)
|
gst_jpegenc_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
|
|
||||||
GstJpegEnc *filter = GST_JPEGENC (object);
|
GstJpegEnc *filter = GST_JPEGENC (object);
|
||||||
|
|
||||||
jpeg_destroy_compress (&filter->cinfo);
|
jpeg_destroy_compress (&filter->cinfo);
|
||||||
@ -360,8 +378,7 @@ gst_jpegenc_resync (GstJpegEnc * jpegenc)
|
|||||||
|
|
||||||
GST_DEBUG_OBJECT (jpegenc, "width %d, height %d", width, height);
|
GST_DEBUG_OBJECT (jpegenc, "width %d, height %d", width, height);
|
||||||
|
|
||||||
|
#if ENABLE_COLORSPACE_RGB
|
||||||
#if 0
|
|
||||||
switch (jpegenc->format) {
|
switch (jpegenc->format) {
|
||||||
case GST_COLORSPACE_RGB24:
|
case GST_COLORSPACE_RGB24:
|
||||||
jpegenc->bufsize = jpegenc->width * jpegenc->height * 3;
|
jpegenc->bufsize = jpegenc->width * jpegenc->height * 3;
|
||||||
@ -377,12 +394,13 @@ gst_jpegenc_resync (GstJpegEnc * jpegenc)
|
|||||||
jpegenc->cinfo.in_color_space = JCS_YCbCr;
|
jpegenc->cinfo.in_color_space = JCS_YCbCr;
|
||||||
|
|
||||||
jpeg_set_defaults (&jpegenc->cinfo);
|
jpeg_set_defaults (&jpegenc->cinfo);
|
||||||
|
/* thsese are set in _chain()
|
||||||
jpeg_set_quality (&jpegenc->cinfo, jpegenc->quality, TRUE);
|
jpeg_set_quality (&jpegenc->cinfo, jpegenc->quality, TRUE);
|
||||||
|
jpegenc->cinfo.smoothing_factor = jpegenc->smoothing;
|
||||||
|
jpegenc->cinfo.dct_method = jpegenc->idct_method;
|
||||||
|
*/
|
||||||
|
|
||||||
jpegenc->cinfo.raw_data_in = TRUE;
|
jpegenc->cinfo.raw_data_in = TRUE;
|
||||||
jpegenc->cinfo.dct_method = JDCT_FASTEST;
|
|
||||||
/*jpegenc->cinfo.dct_method = JDCT_DEFAULT; */
|
|
||||||
/*jpegenc->cinfo.smoothing_factor = jpegenc->smoothing; */
|
|
||||||
|
|
||||||
if (height != -1) {
|
if (height != -1) {
|
||||||
jpegenc->line[0] =
|
jpegenc->line[0] =
|
||||||
@ -394,7 +412,7 @@ gst_jpegenc_resync (GstJpegEnc * jpegenc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (jpegenc, "setting format done");
|
GST_DEBUG_OBJECT (jpegenc, "setting format done");
|
||||||
#if 0
|
#if ENABLE_COLORSPACE_RGB
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf ("gst_jpegenc_resync: unsupported colorspace, using RGB\n");
|
printf ("gst_jpegenc_resync: unsupported colorspace, using RGB\n");
|
||||||
@ -405,7 +423,6 @@ gst_jpegenc_resync (GstJpegEnc * jpegenc)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
jpeg_suppress_tables (&jpegenc->cinfo, TRUE);
|
jpeg_suppress_tables (&jpegenc->cinfo, TRUE);
|
||||||
//jpeg_suppress_tables(&jpegenc->cinfo, FALSE);
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (jpegenc, "resync done");
|
GST_DEBUG_OBJECT (jpegenc, "resync done");
|
||||||
}
|
}
|
||||||
@ -430,7 +447,7 @@ gst_jpegenc_chain (GstPad * pad, GstBuffer * buf)
|
|||||||
data = GST_BUFFER_DATA (buf);
|
data = GST_BUFFER_DATA (buf);
|
||||||
size = GST_BUFFER_SIZE (buf);
|
size = GST_BUFFER_SIZE (buf);
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (jpegenc, "got buffer of %lu bytes", size);
|
GST_LOG_OBJECT (jpegenc, "got buffer of %lu bytes", size);
|
||||||
|
|
||||||
ret =
|
ret =
|
||||||
gst_pad_alloc_buffer_and_set_caps (jpegenc->srcpad,
|
gst_pad_alloc_buffer_and_set_caps (jpegenc->srcpad,
|
||||||
@ -457,10 +474,11 @@ gst_jpegenc_chain (GstPad * pad, GstBuffer * buf)
|
|||||||
jpegenc->jdest.free_in_buffer = GST_BUFFER_SIZE (outbuf);
|
jpegenc->jdest.free_in_buffer = GST_BUFFER_SIZE (outbuf);
|
||||||
|
|
||||||
jpegenc->cinfo.smoothing_factor = jpegenc->smoothing;
|
jpegenc->cinfo.smoothing_factor = jpegenc->smoothing;
|
||||||
|
jpegenc->cinfo.dct_method = jpegenc->idct_method;
|
||||||
jpeg_set_quality (&jpegenc->cinfo, jpegenc->quality, TRUE);
|
jpeg_set_quality (&jpegenc->cinfo, jpegenc->quality, TRUE);
|
||||||
jpeg_start_compress (&jpegenc->cinfo, TRUE);
|
jpeg_start_compress (&jpegenc->cinfo, TRUE);
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (jpegenc, "compressing");
|
GST_LOG_OBJECT (jpegenc, "compressing");
|
||||||
|
|
||||||
for (i = 0; i < height; i += 2 * DCTSIZE) {
|
for (i = 0; i < height; i += 2 * DCTSIZE) {
|
||||||
/*g_print ("next scanline: %d\n", jpegenc->cinfo.next_scanline); */
|
/*g_print ("next scanline: %d\n", jpegenc->cinfo.next_scanline); */
|
||||||
@ -482,7 +500,7 @@ gst_jpegenc_chain (GstPad * pad, GstBuffer * buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
jpeg_finish_compress (&jpegenc->cinfo);
|
jpeg_finish_compress (&jpegenc->cinfo);
|
||||||
GST_DEBUG_OBJECT (jpegenc, "compressing done");
|
GST_LOG_OBJECT (jpegenc, "compressing done");
|
||||||
|
|
||||||
GST_BUFFER_SIZE (outbuf) =
|
GST_BUFFER_SIZE (outbuf) =
|
||||||
GST_ROUND_UP_4 (jpegenc->bufsize - jpegenc->jdest.free_in_buffer);
|
GST_ROUND_UP_4 (jpegenc->bufsize - jpegenc->jdest.free_in_buffer);
|
||||||
@ -514,12 +532,17 @@ gst_jpegenc_set_property (GObject * object, guint prop_id,
|
|||||||
GST_OBJECT_LOCK (jpegenc);
|
GST_OBJECT_LOCK (jpegenc);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case ARG_QUALITY:
|
case PROP_QUALITY:
|
||||||
jpegenc->quality = g_value_get_int (value);
|
jpegenc->quality = g_value_get_int (value);
|
||||||
break;
|
break;
|
||||||
case ARG_SMOOTHING:
|
#if ENABLE_SMOOTHING
|
||||||
|
case PROP_SMOOTHING:
|
||||||
jpegenc->smoothing = g_value_get_int (value);
|
jpegenc->smoothing = g_value_get_int (value);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
case PROP_IDCT_METHOD:
|
||||||
|
jpegenc->idct_method = g_value_get_enum (value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -537,12 +560,17 @@ gst_jpegenc_get_property (GObject * object, guint prop_id, GValue * value,
|
|||||||
GST_OBJECT_LOCK (jpegenc);
|
GST_OBJECT_LOCK (jpegenc);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case ARG_QUALITY:
|
case PROP_QUALITY:
|
||||||
g_value_set_int (value, jpegenc->quality);
|
g_value_set_int (value, jpegenc->quality);
|
||||||
break;
|
break;
|
||||||
case ARG_SMOOTHING:
|
#if ENABLE_SMOOTHING
|
||||||
|
case PROP_SMOOTHING:
|
||||||
g_value_set_int (value, jpegenc->smoothing);
|
g_value_set_int (value, jpegenc->smoothing);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
case PROP_IDCT_METHOD:
|
||||||
|
g_value_set_enum (value, jpegenc->idct_method);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -65,8 +65,10 @@ struct _GstJpegEnc {
|
|||||||
struct jpeg_error_mgr jerr;
|
struct jpeg_error_mgr jerr;
|
||||||
struct jpeg_destination_mgr jdest;
|
struct jpeg_destination_mgr jdest;
|
||||||
|
|
||||||
int quality;
|
/* properties */
|
||||||
int smoothing;
|
gint quality;
|
||||||
|
gint smoothing;
|
||||||
|
gint idct_method;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstJpegEncClass {
|
struct _GstJpegEncClass {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user