scaletempo: Store instance private data in the instance struct

Getting it over and over again via G_TYPE_INSTANCE_GET_PRIVATE()
is really slow.
This commit is contained in:
Sebastian Dröge 2012-10-23 13:39:17 +02:00
parent 1bafd6191a
commit 9319b48d24
2 changed files with 21 additions and 15 deletions

View file

@ -113,7 +113,7 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
G_DEFINE_TYPE_WITH_CODE (GstScaletempo, gst_scaletempo, G_DEFINE_TYPE_WITH_CODE (GstScaletempo, gst_scaletempo,
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT (0)); GST_TYPE_BASE_TRANSFORM, DEBUG_INIT (0));
typedef struct _GstScaletempoPrivate struct _GstScaletempoPrivate
{ {
gdouble scale; gdouble scale;
/* parameters */ /* parameters */
@ -153,14 +153,14 @@ typedef struct _GstScaletempoPrivate
gint64 segment_start; gint64 segment_start;
/* threads */ /* threads */
gboolean reinit_buffers; gboolean reinit_buffers;
} GstScaletempoPrivate; };
#define GST_SCALETEMPO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GST_TYPE_SCALETEMPO, GstScaletempoPrivate)) #define GST_SCALETEMPO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GST_TYPE_SCALETEMPO, GstScaletempoPrivate))
static guint static guint
best_overlap_offset_float (GstScaletempo * scaletempo) best_overlap_offset_float (GstScaletempo * scaletempo)
{ {
GstScaletempoPrivate *p = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *p = scaletempo->priv;
gfloat *pw, *po, *ppc, *search_start; gfloat *pw, *po, *ppc, *search_start;
gfloat best_corr = G_MININT; gfloat best_corr = G_MININT;
guint best_off = 0; guint best_off = 0;
@ -197,7 +197,7 @@ best_overlap_offset_float (GstScaletempo * scaletempo)
static guint static guint
best_overlap_offset_s16 (GstScaletempo * scaletempo) best_overlap_offset_s16 (GstScaletempo * scaletempo)
{ {
GstScaletempoPrivate *p = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *p = scaletempo->priv;
gint32 *pw, *ppc; gint32 *pw, *ppc;
gint16 *po, *search_start; gint16 *po, *search_start;
gint64 best_corr = G_MININT64; gint64 best_corr = G_MININT64;
@ -242,7 +242,7 @@ static void
output_overlap_float (GstScaletempo * scaletempo, output_overlap_float (GstScaletempo * scaletempo,
gpointer buf_out, guint bytes_off) gpointer buf_out, guint bytes_off)
{ {
GstScaletempoPrivate *p = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *p = scaletempo->priv;
gfloat *pout = buf_out; gfloat *pout = buf_out;
gfloat *pb = p->table_blend; gfloat *pb = p->table_blend;
gfloat *po = p->buf_overlap; gfloat *po = p->buf_overlap;
@ -258,7 +258,7 @@ static void
output_overlap_s16 (GstScaletempo * scaletempo, output_overlap_s16 (GstScaletempo * scaletempo,
gpointer buf_out, guint bytes_off) gpointer buf_out, guint bytes_off)
{ {
GstScaletempoPrivate *p = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *p = scaletempo->priv;
gint16 *pout = buf_out; gint16 *pout = buf_out;
gint32 *pb = p->table_blend; gint32 *pb = p->table_blend;
gint16 *po = p->buf_overlap; gint16 *po = p->buf_overlap;
@ -273,7 +273,7 @@ output_overlap_s16 (GstScaletempo * scaletempo,
static guint static guint
fill_queue (GstScaletempo * scaletempo, GstBuffer * buf_in, guint offset) fill_queue (GstScaletempo * scaletempo, GstBuffer * buf_in, guint offset)
{ {
GstScaletempoPrivate *p = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *p = scaletempo->priv;
guint bytes_in = gst_buffer_get_size (buf_in) - offset; guint bytes_in = gst_buffer_get_size (buf_in) - offset;
guint offset_unchanged = offset; guint offset_unchanged = offset;
GstMapInfo map; GstMapInfo map;
@ -310,7 +310,7 @@ fill_queue (GstScaletempo * scaletempo, GstBuffer * buf_in, guint offset)
static void static void
reinit_buffers (GstScaletempo * scaletempo) reinit_buffers (GstScaletempo * scaletempo)
{ {
GstScaletempoPrivate *p = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *p = scaletempo->priv;
gint i, j; gint i, j;
guint frames_overlap; guint frames_overlap;
guint new_size; guint new_size;
@ -436,7 +436,7 @@ gst_scaletempo_transform (GstBaseTransform * trans,
GstBuffer * inbuf, GstBuffer * outbuf) GstBuffer * inbuf, GstBuffer * outbuf)
{ {
GstScaletempo *scaletempo = GST_SCALETEMPO (trans); GstScaletempo *scaletempo = GST_SCALETEMPO (trans);
GstScaletempoPrivate *p = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *p = scaletempo->priv;
gint8 *pout; gint8 *pout;
guint offset_in, bytes_out; guint offset_in, bytes_out;
GstMapInfo omap; GstMapInfo omap;
@ -490,7 +490,7 @@ gst_scaletempo_transform_size (GstBaseTransform * trans,
{ {
if (direction == GST_PAD_SINK) { if (direction == GST_PAD_SINK) {
GstScaletempo *scaletempo = GST_SCALETEMPO (trans); GstScaletempo *scaletempo = GST_SCALETEMPO (trans);
GstScaletempoPrivate *priv = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *priv = scaletempo->priv;
gint bytes_to_out; gint bytes_to_out;
if (priv->reinit_buffers) if (priv->reinit_buffers)
@ -517,7 +517,7 @@ gst_scaletempo_sink_event (GstBaseTransform * trans, GstEvent * event)
{ {
if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) { if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
GstScaletempo *scaletempo = GST_SCALETEMPO (trans); GstScaletempo *scaletempo = GST_SCALETEMPO (trans);
GstScaletempoPrivate *priv = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *priv = scaletempo->priv;
GstSegment segment; GstSegment segment;
gst_event_copy_segment (event, &segment); gst_event_copy_segment (event, &segment);
@ -566,7 +566,7 @@ gst_scaletempo_set_caps (GstBaseTransform * trans,
GstCaps * incaps, GstCaps * outcaps) GstCaps * incaps, GstCaps * outcaps)
{ {
GstScaletempo *scaletempo = GST_SCALETEMPO (trans); GstScaletempo *scaletempo = GST_SCALETEMPO (trans);
GstScaletempoPrivate *priv = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *priv = scaletempo->priv;
gint width, bps, nch, rate; gint width, bps, nch, rate;
gboolean use_int; gboolean use_int;
@ -605,7 +605,7 @@ gst_scaletempo_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec) guint prop_id, GValue * value, GParamSpec * pspec)
{ {
GstScaletempo *scaletempo = GST_SCALETEMPO (object); GstScaletempo *scaletempo = GST_SCALETEMPO (object);
GstScaletempoPrivate *priv = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *priv = scaletempo->priv;
switch (prop_id) { switch (prop_id) {
case PROP_RATE: case PROP_RATE:
@ -631,7 +631,7 @@ gst_scaletempo_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec) guint prop_id, const GValue * value, GParamSpec * pspec)
{ {
GstScaletempo *scaletempo = GST_SCALETEMPO (object); GstScaletempo *scaletempo = GST_SCALETEMPO (object);
GstScaletempoPrivate *priv = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *priv = scaletempo->priv;
switch (prop_id) { switch (prop_id) {
case PROP_STRIDE:{ case PROP_STRIDE:{
@ -715,7 +715,10 @@ gst_scaletempo_class_init (GstScaletempoClass * klass)
static void static void
gst_scaletempo_init (GstScaletempo * scaletempo) gst_scaletempo_init (GstScaletempo * scaletempo)
{ {
GstScaletempoPrivate *priv = GST_SCALETEMPO_GET_PRIVATE (scaletempo); GstScaletempoPrivate *priv;
scaletempo->priv = priv = GST_SCALETEMPO_GET_PRIVATE (scaletempo);
/* defaults */ /* defaults */
priv->ms_stride = 30; priv->ms_stride = 30;
priv->percent_overlap = .2; priv->percent_overlap = .2;

View file

@ -32,10 +32,13 @@ G_BEGIN_DECLS
#define GST_IS_SCALETEMPO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_SCALETEMPO)) #define GST_IS_SCALETEMPO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_SCALETEMPO))
typedef struct _GstScaletempo GstScaletempo; typedef struct _GstScaletempo GstScaletempo;
typedef struct _GstScaletempoClass GstScaletempoClass; typedef struct _GstScaletempoClass GstScaletempoClass;
typedef struct _GstScaletempoPrivate GstScaletempoPrivate;
struct _GstScaletempo struct _GstScaletempo
{ {
GstBaseTransform element; GstBaseTransform element;
GstScaletempoPrivate *priv;
}; };
struct _GstScaletempoClass struct _GstScaletempoClass