Commit ba86a1d9 authored by Matthieu Crapet's avatar Matthieu Crapet Committed by Tim-Philipp Müller

jpegenc: add snapshot property

Like pngenc, automatically send an EOS message.

Example of bin:
appsrc ! jpegenc snapshot=true ! filesink location=out.jpg

This is especially useful for limited/slow hardware.

Otherwise calling gst_video_convert_sample() is a better option
(internally uses videoconvert and videoscale).

https://bugzilla.gnome.org/show_bug.cgi?id=755453
parent cbb9c312
...@@ -54,6 +54,7 @@ GST_DEBUG_CATEGORY_STATIC (jpegenc_debug); ...@@ -54,6 +54,7 @@ GST_DEBUG_CATEGORY_STATIC (jpegenc_debug);
#define JPEG_DEFAULT_QUALITY 85 #define JPEG_DEFAULT_QUALITY 85
#define JPEG_DEFAULT_SMOOTHING 0 #define JPEG_DEFAULT_SMOOTHING 0
#define JPEG_DEFAULT_IDCT_METHOD JDCT_FASTEST #define JPEG_DEFAULT_IDCT_METHOD JDCT_FASTEST
#define JPEG_DEFAULT_SNAPSHOT FALSE
/* JpegEnc signals and args */ /* JpegEnc signals and args */
enum enum
...@@ -67,7 +68,8 @@ enum ...@@ -67,7 +68,8 @@ enum
PROP_0, PROP_0,
PROP_QUALITY, PROP_QUALITY,
PROP_SMOOTHING, PROP_SMOOTHING,
PROP_IDCT_METHOD PROP_IDCT_METHOD,
PROP_SNAPSHOT
}; };
static void gst_jpegenc_finalize (GObject * object); static void gst_jpegenc_finalize (GObject * object);
...@@ -150,11 +152,23 @@ gst_jpegenc_class_init (GstJpegEncClass * klass) ...@@ -150,11 +152,23 @@ gst_jpegenc_class_init (GstJpegEncClass * klass)
"The IDCT algorithm to use", GST_TYPE_IDCT_METHOD, "The IDCT algorithm to use", GST_TYPE_IDCT_METHOD,
JPEG_DEFAULT_IDCT_METHOD, JPEG_DEFAULT_IDCT_METHOD,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstJpegEnc:snapshot:
*
* Send EOS after encoding a frame, useful for snapshots.
*
* Since: 1.14
*/
g_object_class_install_property (gobject_class, PROP_SNAPSHOT,
g_param_spec_boolean ("snapshot", "Snapshot",
"Send EOS after encoding a frame, useful for snapshots",
JPEG_DEFAULT_SNAPSHOT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_add_static_pad_template (element_class, gst_element_class_add_static_pad_template (element_class,
&gst_jpegenc_sink_pad_template); &gst_jpegenc_sink_pad_template);
gst_element_class_add_static_pad_template (element_class, gst_element_class_add_static_pad_template (element_class,
&gst_jpegenc_src_pad_template); &gst_jpegenc_src_pad_template);
gst_element_class_set_static_metadata (element_class, "JPEG image encoder", gst_element_class_set_static_metadata (element_class, "JPEG image encoder",
"Codec/Encoder/Image", "Encode images in JPEG format", "Codec/Encoder/Image", "Encode images in JPEG format",
"Wim Taymans <wim.taymans@tvd.be>"); "Wim Taymans <wim.taymans@tvd.be>");
...@@ -303,6 +317,7 @@ gst_jpegenc_init (GstJpegEnc * jpegenc) ...@@ -303,6 +317,7 @@ gst_jpegenc_init (GstJpegEnc * jpegenc)
jpegenc->quality = JPEG_DEFAULT_QUALITY; jpegenc->quality = JPEG_DEFAULT_QUALITY;
jpegenc->smoothing = JPEG_DEFAULT_SMOOTHING; jpegenc->smoothing = JPEG_DEFAULT_SMOOTHING;
jpegenc->idct_method = JPEG_DEFAULT_IDCT_METHOD; jpegenc->idct_method = JPEG_DEFAULT_IDCT_METHOD;
jpegenc->snapshot = JPEG_DEFAULT_SNAPSHOT;
} }
static void static void
...@@ -528,7 +543,7 @@ gst_jpegenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame) ...@@ -528,7 +543,7 @@ gst_jpegenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame)
jpeg_finish_compress (&jpegenc->cinfo); jpeg_finish_compress (&jpegenc->cinfo);
GST_LOG_OBJECT (jpegenc, "compressing done"); GST_LOG_OBJECT (jpegenc, "compressing done");
return jpegenc->res; return (jpegenc->snapshot) ? GST_FLOW_EOS : jpegenc->res;
invalid_frame: invalid_frame:
{ {
...@@ -566,6 +581,9 @@ gst_jpegenc_set_property (GObject * object, guint prop_id, ...@@ -566,6 +581,9 @@ gst_jpegenc_set_property (GObject * object, guint prop_id,
case PROP_IDCT_METHOD: case PROP_IDCT_METHOD:
jpegenc->idct_method = g_value_get_enum (value); jpegenc->idct_method = g_value_get_enum (value);
break; break;
case PROP_SNAPSHOT:
jpegenc->snapshot = g_value_get_boolean (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;
...@@ -594,6 +612,9 @@ gst_jpegenc_get_property (GObject * object, guint prop_id, GValue * value, ...@@ -594,6 +612,9 @@ gst_jpegenc_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_IDCT_METHOD: case PROP_IDCT_METHOD:
g_value_set_enum (value, jpegenc->idct_method); g_value_set_enum (value, jpegenc->idct_method);
break; break;
case PROP_SNAPSHOT:
g_value_set_boolean (value, jpegenc->snapshot);
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;
......
...@@ -86,6 +86,7 @@ struct _GstJpegEnc ...@@ -86,6 +86,7 @@ struct _GstJpegEnc
gint quality; gint quality;
gint smoothing; gint smoothing;
gint idct_method; gint idct_method;
gboolean snapshot;
GstMemory *output_mem; GstMemory *output_mem;
GstMapInfo output_map; GstMapInfo output_map;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment