plugins: Add JPEG encoder element

This commit is contained in:
Sreerenj Balachandran 2015-02-04 11:18:29 +02:00
parent 4c7c858374
commit d2e2784a78
4 changed files with 273 additions and 14 deletions

View file

@ -77,6 +77,13 @@ libgstvaapi_source_c += $(libgstvaapi_enc_source_c)
libgstvaapi_source_h += $(libgstvaapi_enc_source_h)
endif
libgstvaapi_jpegenc_source_c = gstvaapiencode_jpeg.c
libgstvaapi_jpegenc_source_h = gstvaapiencode_jpeg.h
if USE_JPEG_ENCODER
libgstvaapi_source_c += $(libgstvaapi_jpegenc_source_c)
libgstvaapi_source_h += $(libgstvaapi_jpegenc_source_h)
endif
libgstvaapi_x11_source_c = gstvaapivideoconverter_x11.c
libgstvaapi_x11_source_h = gstvaapivideoconverter_x11.h
@ -235,20 +242,22 @@ CLEANFILES = \
$(libgstvaapi_parse_gen_sources)
EXTRA_DIST = \
$(libgstvaapi_enc_source_c) \
$(libgstvaapi_enc_source_h) \
$(libgstvaapi_x11_source_c) \
$(libgstvaapi_x11_source_h) \
$(libgstvaapi_glx_source_c) \
$(libgstvaapi_glx_source_h) \
$(libgstvaapi_1_2p_source_c) \
$(libgstvaapi_1_2p_source_h) \
$(libgstvaapi_1_0p_source_c) \
$(libgstvaapi_1_0p_source_h) \
$(libgstvaapi_0_10_source_c) \
$(libgstvaapi_0_10_source_h) \
$(libgstvaapi_parse_source_c) \
$(libgstvaapi_parse_source_h) \
$(libgstvaapi_enc_source_c) \
$(libgstvaapi_enc_source_h) \
$(libgstvaapi_jpeg_enc_source_c) \
$(libgstvaapi_jpeg_enc_source_h) \
$(libgstvaapi_x11_source_c) \
$(libgstvaapi_x11_source_h) \
$(libgstvaapi_glx_source_c) \
$(libgstvaapi_glx_source_h) \
$(libgstvaapi_1_2p_source_c) \
$(libgstvaapi_1_2p_source_h) \
$(libgstvaapi_1_0p_source_c) \
$(libgstvaapi_1_0p_source_h) \
$(libgstvaapi_0_10_source_c) \
$(libgstvaapi_0_10_source_h) \
$(libgstvaapi_parse_source_c) \
$(libgstvaapi_parse_source_h) \
$(NULL)
# Extra clean files so that maintainer-clean removes *everything*

View file

@ -35,6 +35,10 @@
#include "gstvaapiencode_mpeg2.h"
#endif
#if USE_JPEG_ENCODER
#include "gstvaapiencode_jpeg.h"
#endif
#define PLUGIN_NAME "vaapi"
#define PLUGIN_DESC "VA-API based elements"
#define PLUGIN_LICENSE "LGPL"
@ -67,6 +71,11 @@ plugin_init (GstPlugin *plugin)
GST_RANK_PRIMARY,
GST_TYPE_VAAPIENCODE_MPEG2);
#endif
#if USE_JPEG_ENCODER
gst_element_register(plugin, "vaapiencode_jpeg",
GST_RANK_PRIMARY,
GST_TYPE_VAAPIENCODE_JPEG);
#endif
return TRUE;
}

View file

@ -0,0 +1,172 @@
/*
* gstvaapiencode_jpeg.c - VA-API JPEG encoder
*
* Copyright (C) 2015 Intel Corporation
* Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "gst/vaapi/sysdeps.h"
#include <gst/vaapi/gstvaapidisplay.h>
#include <gst/vaapi/gstvaapiencoder_jpeg.h>
#include "gstvaapiencode_jpeg.h"
#include "gstvaapipluginutil.h"
#if GST_CHECK_VERSION(1,0,0)
#include "gstvaapivideomemory.h"
#endif
#define GST_PLUGIN_NAME "vaapiencode_jpeg"
#define GST_PLUGIN_DESC "A VA-API based JPEG video encoder"
GST_DEBUG_CATEGORY_STATIC (gst_vaapi_jpeg_encode_debug);
#define GST_CAT_DEFAULT gst_vaapi_jpeg_encode_debug
#define GST_CODEC_CAPS \
"image/jpeg"
/* *INDENT-OFF* */
static const char gst_vaapiencode_jpeg_sink_caps_str[] =
#if GST_CHECK_VERSION(1,1,0)
GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE,
"{ ENCODED, NV12, I420, YV12 }") ", "
#else
GST_VAAPI_SURFACE_CAPS ", "
#endif
GST_CAPS_INTERLACED_FALSE "; "
#if GST_CHECK_VERSION(1,0,0)
GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) ", "
#endif
GST_CAPS_INTERLACED_FALSE;
/* *INDENT-ON* */
/* *INDENT-OFF* */
static const char gst_vaapiencode_jpeg_src_caps_str[] =
GST_CODEC_CAPS;
/* *INDENT-ON* */
/* *INDENT-OFF* */
static GstStaticPadTemplate gst_vaapiencode_jpeg_sink_factory =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (gst_vaapiencode_jpeg_sink_caps_str));
/* *INDENT-ON* */
/* *INDENT-OFF* */
static GstStaticPadTemplate gst_vaapiencode_jpeg_src_factory =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (gst_vaapiencode_jpeg_src_caps_str));
/* *INDENT-ON* */
/* jpeg encode */
G_DEFINE_TYPE (GstVaapiEncodeJpeg, gst_vaapiencode_jpeg,
GST_TYPE_VAAPIENCODE);
static void
gst_vaapiencode_jpeg_init (GstVaapiEncodeJpeg * encode)
{
gst_vaapiencode_init_properties (GST_VAAPIENCODE_CAST (encode));
}
static void
gst_vaapiencode_jpeg_finalize (GObject * object)
{
G_OBJECT_CLASS (gst_vaapiencode_jpeg_parent_class)->finalize (object);
}
static void
gst_vaapiencode_jpeg_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec)
{
GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
switch (prop_id) {
default:
if (!encode_class->set_property (base_encode, prop_id, value))
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_vaapiencode_jpeg_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec)
{
GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_GET_CLASS (object);
GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (object);
switch (prop_id) {
default:
if (!encode_class->get_property (base_encode, prop_id, value))
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GstCaps *
gst_vaapiencode_jpeg_get_caps (GstVaapiEncode * base_encode)
{
GstCaps *caps;
caps = gst_caps_from_string (GST_CODEC_CAPS);
return caps;
}
static GstVaapiEncoder *
gst_vaapiencode_jpeg_alloc_encoder (GstVaapiEncode * base,
GstVaapiDisplay * display)
{
return gst_vaapi_encoder_jpeg_new (display);
}
static void
gst_vaapiencode_jpeg_class_init (GstVaapiEncodeJpegClass * klass)
{
GObjectClass *const object_class = G_OBJECT_CLASS (klass);
GstElementClass *const element_class = GST_ELEMENT_CLASS (klass);
GstVaapiEncodeClass *const encode_class = GST_VAAPIENCODE_CLASS (klass);
GST_DEBUG_CATEGORY_INIT (gst_vaapi_jpeg_encode_debug,
GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
object_class->finalize = gst_vaapiencode_jpeg_finalize;
object_class->set_property = gst_vaapiencode_jpeg_set_property;
object_class->get_property = gst_vaapiencode_jpeg_get_property;
encode_class->get_properties = gst_vaapi_encoder_jpeg_get_default_properties;
encode_class->get_caps = gst_vaapiencode_jpeg_get_caps;
encode_class->alloc_encoder = gst_vaapiencode_jpeg_alloc_encoder;
gst_element_class_set_static_metadata (element_class,
"VA-API JPEG encoder",
"Codec/Encoder/Image",
GST_PLUGIN_DESC, "Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
/* sink pad */
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_vaapiencode_jpeg_sink_factory));
/* src pad */
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_vaapiencode_jpeg_src_factory));
gst_vaapiencode_class_init_properties (encode_class);
}

View file

@ -0,0 +1,69 @@
/*
* gstvaapiencode_jpeg.h - VA-API JPEG encoder
*
* Copyright (C) 2015 Intel Corporation
* Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef GST_VAAPIENCODE_JPEG_H
#define GST_VAAPIENCODE_JPEG_H
#include <gst/gst.h>
#include "gstvaapiencode.h"
G_BEGIN_DECLS
#define GST_TYPE_VAAPIENCODE_JPEG \
(gst_vaapiencode_jpeg_get_type ())
#define GST_VAAPIENCODE_JPEG_CAST(obj) \
((GstVaapiEncodeJpeg *)(obj))
#define GST_VAAPIENCODE_JPEG(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VAAPIENCODE_JPEG, \
GstVaapiEncodeJpeg))
#define GST_VAAPIENCODE_JPEG_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VAAPIENCODE_JPEG, \
GstVaapiEncodeJpegClass))
#define GST_VAAPIENCODE_JPEG_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VAAPIENCODE_JPEG, \
GstVaapiEncodeJpegClass))
#define GST_IS_VAAPIENCODE_JPEG(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VAAPIENCODE_JPEG))
#define GST_IS_VAAPIENCODE_JPEG_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VAAPIENCODE_JPEG))
typedef struct _GstVaapiEncodeJpeg GstVaapiEncodeJpeg;
typedef struct _GstVaapiEncodeJpegClass GstVaapiEncodeJpegClass;
struct _GstVaapiEncodeJpeg
{
/*< private >*/
GstVaapiEncode parent_instance;
};
struct _GstVaapiEncodeJpegClass
{
/*< private >*/
GstVaapiEncodeClass parent_class;
};
GType
gst_vaapiencode_jpeg_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* GST_VAAPIENCODE_JPEG_H */