[gegl/video-rejuvenation: 1/83] add GeglAudio - for carrying audio of a video frame
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/video-rejuvenation: 1/83] add GeglAudio - for carrying audio of a video frame
- Date: Thu, 19 Nov 2015 21:42:25 +0000 (UTC)
commit 8708aa8fcdfeda8dd5eaa37839876034c0b59919
Author: Øyvind Kolås <pippin gimp org>
Date: Wed Sep 30 16:05:07 2015 +0200
add GeglAudio - for carrying audio of a video frame
For now limited to holding 4000 samples of stereo floating point audio. Should
be extended to handle up to 6 channels.
gegl/Makefile.am | 1 +
gegl/gegl-op.h | 31 +++++
gegl/gegl-plugin.h | 2 +
gegl/gegl-types.h | 1 +
gegl/property-types/Makefile.am | 2 +
gegl/property-types/gegl-audio.c | 227 +++++++++++++++++++++++++++++++++
gegl/property-types/gegl-audio.h | 100 +++++++++++++++
gegl/property-types/gegl-paramspecs.c | 1 +
operations/external/ff-load.c | 11 +-
9 files changed, 373 insertions(+), 3 deletions(-)
---
diff --git a/gegl/Makefile.am b/gegl/Makefile.am
index 4128504..683386e 100644
--- a/gegl/Makefile.am
+++ b/gegl/Makefile.am
@@ -66,6 +66,7 @@ GEGL_introspectable_headers = \
process/gegl-processor.h \
property-types/gegl-paramspecs.h \
property-types/gegl-color.h \
+ property-types/gegl-audio.h \
property-types/gegl-path.h \
property-types/gegl-curve.h
diff --git a/gegl/gegl-op.h b/gegl/gegl-op.h
index 6bd6913..06efa9a 100644
--- a/gegl/gegl-op.h
+++ b/gegl/gegl-op.h
@@ -268,6 +268,7 @@ gegl_module_register (GTypeModule *module)
#define property_curve(name, label, def_val) ITEM2(name,label,def_val,object)
#define property_path(name, label, def_val) ITEM2(name,label,def_val,object)
#define property_color(name, label, def_val) ITEM2(name,label,def_val,object)
+#define property_audio(name, label, def_val) ITEM2(name,label,NULL,object)
#define enum_start(enum_name) typedef enum {
#define enum_value(value, nick, name) value ,
@@ -331,6 +332,7 @@ static GType enum_name ## _get_type (void) \
#undef property_seed
#undef property_curve
#undef property_color
+#undef property_audio
#undef property_path
#undef enum_start
#undef enum_value
@@ -353,6 +355,7 @@ struct _GeglProperties
#define property_object(name, label, def_val) GObject *name;
#define property_curve(name, label, def_val) GeglCurve *name;
#define property_color(name, label, def_val) GeglColor *name;
+#define property_audio(name, label, def_val) GeglAudio *name;
#define property_path(name, label, def_val) GeglPath *name; gulong path_changed_handler;
#define property_pointer(name, label, def_val) gpointer name;
#define property_format(name, label, def_val) gpointer name;
@@ -375,6 +378,7 @@ struct _GeglProperties
#undef property_seed
#undef property_curve
#undef property_color
+#undef property_audio
#undef property_path
};
@@ -397,6 +401,7 @@ enum
#define property_object(name, label, def_val) ITEM2(name,label,def_val,object)
#define property_curve(name, label, def_val) ITEM2(name,label,def_val,object)
#define property_color(name, label, def_val) ITEM2(name,label,def_val,object)
+#define property_audio(name, label, def_val) ITEM2(name,label,def_val,object)
#define property_path(name, label, def_val) ITEM2(name,label,def_val,object)
#define property_pointer(name, label, def_val) ITEM(name,label,def_val,pointer)
#define property_format(name, label, def_val) ITEM(name,label,def_val,pointer)
@@ -443,6 +448,7 @@ get_property (GObject *gobject,
#undef property_seed
#undef property_curve
#undef property_color
+#undef property_audio
#undef property_path
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
@@ -511,6 +517,12 @@ set_property (GObject *gobject,
g_object_unref (properties->name); \
properties->name = g_value_dup_object (value); \
break;
+#define property_audio(name, label, def_val) \
+ case PROP_##name: \
+ if (properties->name != NULL) \
+ g_object_unref (properties->name); \
+ properties->name = g_value_dup_object (value); \
+ break;
#define property_path(name, label, def_val) \
case PROP_##name: \
if (properties->name != NULL) \
@@ -562,6 +574,7 @@ set_property (GObject *gobject,
#undef property_pointer
#undef property_curve
#undef property_color
+#undef property_audio
#undef property_path
#undef property_format
#undef property_enum
@@ -618,6 +631,12 @@ static void gegl_op_destroy_notify (gpointer data)
g_object_unref (properties->name); \
properties->name = NULL; \
}
+#define property_audio(name, label, def_val) \
+ if (properties->name) \
+ { \
+ g_object_unref (properties->name); \
+ properties->name = NULL; \
+ }
#define property_path(name, label, def_val) \
if (properties->name) \
{ \
@@ -644,6 +663,7 @@ static void gegl_op_destroy_notify (gpointer data)
#undef property_seed
#undef property_curve
#undef property_color
+#undef property_audio
#undef property_path
g_slice_free (GeglProperties, properties);
@@ -673,6 +693,9 @@ gegl_op_constructor (GType type,
#define property_pointer(name, label, def_val)
#define property_format(name, label, def_val)
#define property_curve(name, label, def_val)
+#define property_audio(name, label, def_val)\
+ if (properties->name == NULL) \
+ {properties->name = gegl_audio_new();}
#define property_color(name, label, def_val)\
if (properties->name == NULL) \
{properties->name = gegl_color_new(def_val?def_val:"black");}
@@ -697,6 +720,7 @@ gegl_op_constructor (GType type,
#undef property_seed
#undef property_curve
#undef property_color
+#undef property_audio
#undef property_path
g_object_set_data_full (obj, "chant-data", obj, gegl_op_destroy_notify);
@@ -940,6 +964,12 @@ gegl_op_class_intern_init (gpointer klass)
gegl_param_spec_color_from_string (#name, label, NULL, def_val, flags);\
current_prop = PROP_##name ;
+#define property_audio(name, label, def_val) \
+ REGISTER_IF_ANY \
+ }{ GParamSpec *pspec = \
+ gegl_param_spec_audio (#name, label, NULL, flags);\
+ current_prop = PROP_##name ;
+
#define property_path(name, label, def_val) \
REGISTER_IF_ANY \
}{ GParamSpec *pspec = \
@@ -989,6 +1019,7 @@ gegl_op_class_intern_init (gpointer klass)
#undef property_path
#undef property_curve
#undef property_color
+#undef property_audio
#undef property_object
#undef property_format
diff --git a/gegl/gegl-plugin.h b/gegl/gegl-plugin.h
index 2c334d3..7ca428a 100644
--- a/gegl/gegl-plugin.h
+++ b/gegl/gegl-plugin.h
@@ -28,7 +28,9 @@
#include <glib-object.h>
#include <gmodule.h>
#include <gegl.h>
+#include <gegl-types.h>
#include <gegl-paramspecs.h>
+#include <gegl-audio.h>
G_BEGIN_DECLS
diff --git a/gegl/gegl-types.h b/gegl/gegl-types.h
index 714bdd3..2c54f54 100644
--- a/gegl/gegl-types.h
+++ b/gegl/gegl-types.h
@@ -50,6 +50,7 @@ typedef struct _GeglSampler GeglSampler;
typedef struct _GeglCurve GeglCurve;
typedef struct _GeglPath GeglPath;
typedef struct _GeglColor GeglColor;
+typedef struct _GeglAudio GeglAudio;
typedef struct _GeglRectangle GeglRectangle;
diff --git a/gegl/property-types/Makefile.am b/gegl/property-types/Makefile.am
index 6e44158..1acd124 100644
--- a/gegl/property-types/Makefile.am
+++ b/gegl/property-types/Makefile.am
@@ -20,11 +20,13 @@ AM_CFLAGS = $(DEP_CFLAGS) $(BABL_CFLAGS)
noinst_LTLIBRARIES = libpropertytypes.la
libpropertytypes_la_SOURCES = \
+ gegl-audio.c \
gegl-color.c \
gegl-curve.c \
gegl-path.c \
gegl-paramspecs.c \
\
+ gegl-audio.h \
gegl-color.h \
gegl-curve.h \
gegl-path.h \
diff --git a/gegl/property-types/gegl-audio.c b/gegl/property-types/gegl-audio.c
new file mode 100644
index 0000000..9223c41
--- /dev/null
+++ b/gegl/property-types/gegl-audio.c
@@ -0,0 +1,227 @@
+/* This file is part of GEGL
+ *
+ * GEGL 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 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <glib-object.h>
+
+#include "gegl.h"
+#include "gegl-types-internal.h"
+#include "gegl-audio.h"
+
+enum
+{
+ PROP_0,
+ PROP_STRING
+};
+
+struct _GeglAudioPrivate
+{
+ int foo;
+};
+
+static void set_property (GObject *gobject,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void get_property (GObject *gobject,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+G_DEFINE_TYPE (GeglAudio, gegl_audio, G_TYPE_OBJECT)
+
+static void
+gegl_audio_init (GeglAudio *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), GEGL_TYPE_AUDIO, GeglAudioPrivate);
+}
+
+static void
+gegl_audio_class_init (GeglAudioClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->set_property = set_property;
+ gobject_class->get_property = get_property;
+
+ g_object_class_install_property (gobject_class, PROP_STRING,
+ g_param_spec_string ("string",
+ "String",
+ "A String representation of the GeglAudio",
+ "",
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (klass, sizeof (GeglAudioPrivate));
+}
+
+static void
+set_property (GObject *gobject,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ //GeglAudio *audio = GEGL_AUDIO (gobject);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
+ break;
+ }
+}
+
+static void
+get_property (GObject *gobject,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ //GeglAudio *audio = GEGL_AUDIO (gobject);
+
+ switch (property_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
+ break;
+ }
+}
+
+GeglAudio *
+gegl_audio_new (void)
+{
+ void *string = NULL;
+ if (string)
+ return g_object_new (GEGL_TYPE_AUDIO, "string", string, NULL);
+
+ return g_object_new (GEGL_TYPE_AUDIO, NULL);
+}
+
+GeglAudio *
+gegl_audio_duplicate (GeglAudio *audio)
+{
+ GeglAudio *new;
+
+ g_return_val_if_fail (GEGL_IS_AUDIO (audio), NULL);
+
+ new = g_object_new (GEGL_TYPE_AUDIO, NULL);
+
+ memcpy (new->priv, audio->priv, sizeof (GeglAudioPrivate));
+
+ return new;
+}
+
+/* --------------------------------------------------------------------------
+ * A GParamSpec class to describe behavior of GeglAudio as an object property
+ * follows.
+ * --------------------------------------------------------------------------
+ */
+
+#define GEGL_PARAM_AUDIO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_PARAM_AUDIO,
GeglParamAudio))
+#define GEGL_IS_PARAM_AUDIO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEGL_TYPE_PARAM_AUDIO))
+
+typedef struct _GeglParamAudio GeglParamAudio;
+
+struct _GeglParamAudio
+{
+ GParamSpec parent_instance;
+
+ GeglAudio *default_audio;
+};
+
+static void
+gegl_param_audio_init (GParamSpec *self)
+{
+ GEGL_PARAM_AUDIO (self)->default_audio = NULL;
+}
+
+#if 0
+GeglAudio *
+gegl_param_spec_audio_get_default (GParamSpec *self)
+{
+ return GEGL_PARAM_AUDIO (self)->default_audio;
+}
+#endif
+
+static void
+gegl_param_audio_finalize (GParamSpec *self)
+{
+ GeglParamAudio *param_audio = GEGL_PARAM_AUDIO (self);
+ GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GEGL_TYPE_PARAM_AUDIO));
+
+ if (param_audio->default_audio)
+ {
+ g_object_unref (param_audio->default_audio);
+ param_audio->default_audio = NULL;
+ }
+
+ parent_class->finalize (self);
+}
+
+static void
+gegl_param_audio_set_default (GParamSpec *param_spec,
+ GValue *value)
+{
+ GeglParamAudio *gegl_audio = GEGL_PARAM_AUDIO (param_spec);
+
+ if (gegl_audio->default_audio)
+ g_value_take_object (value, gegl_audio_duplicate (gegl_audio->default_audio));
+}
+
+GType
+gegl_param_audio_get_type (void)
+{
+ static GType param_audio_type = 0;
+
+ if (G_UNLIKELY (param_audio_type == 0))
+ {
+ static GParamSpecTypeInfo param_audio_type_info = {
+ sizeof (GeglParamAudio),
+ 0,
+ gegl_param_audio_init,
+ 0,
+ gegl_param_audio_finalize,
+ gegl_param_audio_set_default,
+ NULL,
+ NULL
+ };
+ param_audio_type_info.value_type = GEGL_TYPE_AUDIO;
+
+ param_audio_type = g_param_type_register_static ("GeglParamAudio",
+ ¶m_audio_type_info);
+ }
+
+ return param_audio_type;
+}
+
+GParamSpec *
+gegl_param_spec_audio (const gchar *name,
+ const gchar *nick,
+ const gchar *blurb,
+ // GeglAudio *default_audio,
+ GParamFlags flags)
+{
+ GeglParamAudio *param_audio;
+
+ param_audio = g_param_spec_internal (GEGL_TYPE_PARAM_AUDIO,
+ name, nick, blurb, flags);
+
+ //param_audio->default_audio = default_audio;
+ //if (default_audio)
+ // g_object_ref (default_audio);
+
+ return G_PARAM_SPEC (param_audio);
+}
diff --git a/gegl/property-types/gegl-audio.h b/gegl/property-types/gegl-audio.h
new file mode 100644
index 0000000..06ad66b
--- /dev/null
+++ b/gegl/property-types/gegl-audio.h
@@ -0,0 +1,100 @@
+/* This file is part of GEGL
+ *
+ * GEGL 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 3 of the License, or (at your option) any later version.
+ *
+ * GEGL 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 GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2006 Martin Nordholts <enselic hotmail com>
+ */
+
+#ifndef __GEGL_AUDIO_H__
+#define __GEGL_AUDIO_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GEGL_TYPE_AUDIO (gegl_audio_get_type ())
+#define GEGL_AUDIO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_AUDIO, GeglAudio))
+#define GEGL_AUDIO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEGL_TYPE_AUDIO, GeglAudioClass))
+#define GEGL_IS_AUDIO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_AUDIO))
+#define GEGL_IS_AUDIO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEGL_TYPE_AUDIO))
+#define GEGL_AUDIO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEGL_TYPE_AUDIO, GeglAudioClass))
+
+typedef struct _GeglAudioClass GeglAudioClass;
+typedef struct _GeglAudioPrivate GeglAudioPrivate;
+
+struct _GeglAudio
+{
+ GObject parent_instance;
+ float left[4000];
+ float right[4000];
+ int samples;
+ int samplerate;
+ GeglAudioPrivate *priv;
+};
+
+struct _GeglAudioClass
+{
+ GObjectClass parent_class;
+};
+
+GType gegl_audio_get_type (void) G_GNUC_CONST;
+
+GeglAudio * gegl_audio_new (void);
+
+/**
+ * gegl_audio_duplicate:
+ * @audio: the audio to duplicate.
+ *
+ * Creates a copy of @audio.
+ *
+ * Return value: (transfer full): A new copy of @audio.
+ */
+GeglAudio * gegl_audio_duplicate (GeglAudio *audio);
+
+#define GEGL_TYPE_PARAM_AUDIO (gegl_param_audio_get_type ())
+#define GEGL_IS_PARAM_SPEC_AUDIO(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GEGL_TYPE_PARAM_AUDIO))
+
+GType gegl_param_audio_get_type (void) G_GNUC_CONST;
+
+/**
+ * gegl_param_spec_audio:
+ * @name: canonical name of the property specified
+ * @nick: nick name for the property specified
+ * @blurb: description of the property specified
+ * @flags: flags for the property specified
+ *
+ * Creates a new #GParamSpec instance specifying a #GeglAudio property.
+ *
+ * Returns: (transfer full): a newly created parameter specification
+ */
+GParamSpec * gegl_param_spec_audio (const gchar *name,
+ const gchar *nick,
+ const gchar *blurb,
+ GParamFlags flags);
+#if 0
+/**
+ * gegl_param_spec_audio_get_default:
+ * @self: a #GeglAudio #GParamSpec
+ *
+ * Get the default audio value of the param spec
+ *
+ * Returns: (transfer none): the default #GeglAudio
+ */
+GeglAudio *
+gegl_param_spec_audio_get_default (GParamSpec *self);
+#endif
+
+G_END_DECLS
+
+#endif /* __GEGL_AUDIO_H__ */
diff --git a/gegl/property-types/gegl-paramspecs.c b/gegl/property-types/gegl-paramspecs.c
index 8db15ee..3e26a26 100644
--- a/gegl/property-types/gegl-paramspecs.c
+++ b/gegl/property-types/gegl-paramspecs.c
@@ -28,6 +28,7 @@
#include "gegl-types.h"
#include <babl/babl.h>
#include "gegl-color.h"
+#include "gegl-audio.h"
#include "gegl-curve.h"
#include "gegl-path.h"
diff --git a/operations/external/ff-load.c b/operations/external/ff-load.c
index aeb2eb3..e4d1a59 100644
--- a/operations/external/ff-load.c
+++ b/operations/external/ff-load.c
@@ -33,6 +33,8 @@ property_int (frames, _("frames"), 0)
value_range (0, G_MAXINT)
ui_range (0, 10000)
+property_audio (audio, _("audio"), 0)
+
#else
#define GEGL_OP_SOURCE
@@ -215,7 +217,6 @@ decode_frame (GeglOperation *operation,
while (decodeframe <= frame)
{
int got_picture = 0;
-
do
{
int decoded_bytes;
@@ -246,7 +247,7 @@ decode_frame (GeglOperation *operation,
return -1;
}
- p->coded_buf += decoded_bytes;
+ p->coded_buf += decoded_bytes;
p->coded_bytes -= decoded_bytes;
}
while (!got_picture);
@@ -394,7 +395,11 @@ process (GeglOperation *operation,
gint pxsize;
gint x,y;
-
+ o->audio->left[0]=23;
+ o->audio->right[0]=23;
+ o->audio->samplerate = 44100;
+ o->audio->samples = 1;
+
g_object_get (output, "px-size", &pxsize, NULL);
buf = g_new (guchar, p->width * p->height * pxsize);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]