[Sugar-devel] [PATCH gst-plugins-espeak] Port to gstreamer 1.0

Daniel Narvaez dwnarvaez at gmail.com
Sat Aug 11 03:58:21 EDT 2012


From: Daniel Narvaez <dwnarvaez at gmail.com>

---
 configure.ac    |    2 +-
 src/espeak.c    |    9 +++---
 src/gstespeak.c |   84 ++++++++++++++++++++++++++-----------------------------
 3 files changed, 45 insertions(+), 50 deletions(-)

diff --git a/configure.ac b/configure.ac
index 84c98c2..fc4b799 100644
--- a/configure.ac
+++ b/configure.ac
@@ -10,7 +10,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 AC_PROG_CC
 AC_PROG_LIBTOOL
 
-GST_MAJORMINOR=0.10
+GST_MAJORMINOR=1.0
 
 PKG_CHECK_MODULES(GST, gstreamer-$GST_MAJORMINOR)
 PKG_CHECK_MODULES(GST_AUDIO, gstreamer-audio-$GST_MAJORMINOR, have_audio=yes, have_audio=no)
diff --git a/src/espeak.c b/src/espeak.c
index 5cceffa..004fdf1 100644
--- a/src/espeak.c
+++ b/src/espeak.c
@@ -257,10 +257,9 @@ GstBuffer *play (Econtext * self, Espin * spin, gsize size_to_play) {
     espeak_EVENT *event = &g_array_index (spin->events, espeak_EVENT,
             spin->events_pos);
 
-    GstBuffer *out = gst_buffer_new ();
+    GstBuffer *out = gst_buffer_new_and_alloc (size_to_play);
+    gst_buffer_fill(out, 0, spin->sound->data + spin->sound_offset, size_to_play);
     GST_BUFFER_OFFSET (out) = spin->sound_offset;
-    GST_BUFFER_DATA (out) = spin->sound->data + spin->sound_offset;
-    GST_BUFFER_SIZE (out) = size_to_play;
     GST_BUFFER_TIMESTAMP (out) = spin->audio_position;
     spin->audio_position =
             gst_util_uint64_scale_int (event->audio_position, GST_SECOND, 1000);
@@ -270,8 +269,8 @@ GstBuffer *play (Econtext * self, Espin * spin, gsize size_to_play) {
     spin->sound_offset += size_to_play;
     spin->events_pos += 1;
 
-    GST_DEBUG ("out=%p size_to_play=%zd tell=%zd ts=%" G_GUINT64_FORMAT " dur=%"
-            G_GUINT64_FORMAT, GST_BUFFER_DATA (out), size_to_play,
+    GST_DEBUG ("size_to_play=%zd tell=%zd ts=%" G_GUINT64_FORMAT " dur=%"
+            G_GUINT64_FORMAT, size_to_play,
             spin->sound_offset, GST_BUFFER_TIMESTAMP (out),
             GST_BUFFER_DURATION (out));
 
diff --git a/src/gstespeak.c b/src/gstespeak.c
index f7a05fa..d86e465 100644
--- a/src/gstespeak.c
+++ b/src/gstespeak.c
@@ -58,6 +58,7 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
         GST_PAD_ALWAYS,
         GST_STATIC_CAPS_ANY);
 
+static void gst_espeak_uri_handler_init (gpointer g_iface, gpointer iface_data);
 static GstFlowReturn gst_espeak_create (GstBaseSrc *,
         guint64, guint, GstBuffer **);
 static gboolean gst_espeak_start (GstBaseSrc *);
@@ -68,33 +69,19 @@ static void gst_espeak_finalize (GObject *);
 static void gst_espeak_set_property (GObject *, guint, const GValue *,
         GParamSpec *);
 static void gst_espeak_get_property (GObject *, guint, GValue *, GParamSpec *);
-static GstCaps *gst_espeak_getcaps (GstBaseSrc *);
+static GstCaps *gst_espeak_getcaps (GstBaseSrc *self_, GstCaps *filter);
 
-GST_BOILERPLATE_FULL (GstEspeak, gst_espeak, GstBaseSrc, GST_TYPE_BASE_SRC,
-        gst_espeak_init_uri);
+G_DEFINE_TYPE_EXTENDED (GstEspeak, gst_espeak, GST_TYPE_BASE_SRC, 0,
+                        G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
+                                               gst_espeak_uri_handler_init));
 
 /******************************************************************************/
 
-static void gst_espeak_base_init (gpointer gclass) {
-    GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
-
-    static GstElementDetails details = {
-        "Espeak",
-        "Source",
-        "Uses eSpeak library as a sound source for GStreamer",
-        "Aleksey S. Lim <alsroot at member.fsf.org>"
-    };
-
-    gst_element_class_set_details (element_class, &details);
-
-    gst_element_class_add_pad_template (element_class,
-            gst_static_pad_template_get (&src_factory));
-}
-
 /* initialize the espeak's class */
 static void gst_espeak_class_init (GstEspeakClass * klass) {
     GObjectClass *gobject_class = (GObjectClass *) klass;
     GstBaseSrcClass *basesrc_class = (GstBaseSrcClass *) klass;
+    GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
 
     basesrc_class->create = gst_espeak_create;
     basesrc_class->start = gst_espeak_start;
@@ -138,6 +125,16 @@ static void gst_espeak_class_init (GstEspeakClass * klass) {
             g_param_spec_boxed ("caps", "Caps",
                     "Caps describing the format of the data", GST_TYPE_CAPS,
                     G_PARAM_READABLE));
+
+    gst_element_class_set_static_metadata (
+        element_class,
+        "Espeak",
+        "Source",
+        "Uses eSpeak library as a sound source for GStreamer",
+        "Aleksey S. Lim <alsroot at member.fsf.org>");
+
+    gst_element_class_add_pad_template (element_class,
+            gst_static_pad_template_get (&src_factory));
 }
 
 /* initialize the new element
@@ -145,7 +142,7 @@ static void gst_espeak_class_init (GstEspeakClass * klass) {
  * set pad calback functions
  * initialize instance structure
  */
-static void gst_espeak_init (GstEspeak * self, GstEspeakClass * gclass) {
+static void gst_espeak_init (GstEspeak * self) {
     self->text = NULL;
     self->pitch = 0;
     self->rate = 0;
@@ -153,14 +150,17 @@ static void gst_espeak_init (GstEspeak * self, GstEspeakClass * gclass) {
     self->voices = espeak_get_voices ();
     self->speak = espeak_new (GST_ELEMENT (self));
 
-    self->caps = gst_caps_new_simple ("audio/x-raw-int",
+    self->caps = gst_caps_new_simple ("audio/x-raw",
             "rate", G_TYPE_INT, espeak_get_sample_rate (),
             "channels", G_TYPE_INT, 1,
-            "endianness", G_TYPE_INT, G_BYTE_ORDER,
-            "width", G_TYPE_INT, 16,
-            "depth", G_TYPE_INT, 16, "signed", G_TYPE_BOOLEAN, TRUE, NULL);
+            "format", G_TYPE_STRING, "S16LE",
+            "layout", G_TYPE_STRING, "interleaved",
+            NULL);
 
-    gst_base_src_set_format (GST_BASE_SRC (self), GST_FORMAT_DEFAULT);
+    GstPad *pad = gst_element_get_static_pad(GST_ELEMENT(self), "src");
+    gst_pad_set_caps(pad, self->caps);
+
+    gst_base_src_set_format (GST_BASE_SRC (self), GST_FORMAT_TIME);
 }
 
 static void gst_espeak_finalize (GObject * self_) {
@@ -177,7 +177,7 @@ static void gst_espeak_finalize (GObject * self_) {
     g_value_array_free (self->voices);
     self->voices = NULL;
 
-    G_OBJECT_CLASS (parent_class)->dispose (self_);
+    G_OBJECT_CLASS (gst_espeak_parent_class)->dispose (self_);
 }
 
 /******************************************************************************/
@@ -268,10 +268,9 @@ gst_espeak_create (GstBaseSrc * self_, guint64 offset, guint size,
     *buf = espeak_out (self->speak, size);
 
     if (*buf) {
-        gst_buffer_set_caps (*buf, self->caps);
         return GST_FLOW_OK;
     } else
-        return GST_FLOW_UNEXPECTED;
+        return GST_FLOW_EOS;
 }
 
 static gboolean gst_espeak_start (GstBaseSrc * self_) {
@@ -292,24 +291,24 @@ static gboolean gst_espeak_is_seekable (GstBaseSrc * src) {
     return FALSE;
 }
 
-static GstCaps *gst_espeak_getcaps (GstBaseSrc * self_) {
+static GstCaps *gst_espeak_getcaps (GstBaseSrc * self_, GstCaps *filter) {
     GstEspeak *self = GST_ESPEAK (self_);
     return gst_caps_ref (self->caps);
 }
 
 /******************************************************************************/
 
-static GstURIType gst_espeak_uri_get_type (void) {
+static GstURIType gst_espeak_uri_get_type (GType type) {
     return GST_URI_SRC;
 }
 
-static gchar **gst_espeak_uri_get_protocols (void) {
-    static gchar *protocols[] = { "espeak", NULL };
+static const gchar * const * gst_espeak_uri_get_protocols (GType type) {
+    static const gchar *protocols[] = { "espeak", NULL };
     return protocols;
 }
 
 static gboolean
-gst_espeak_uri_set_uri (GstURIHandler * handler, const gchar * uri) {
+gst_espeak_uri_set_uri (GstURIHandler * handler, const gchar * uri, GError ** error) {
     gchar *protocol, *text;
     gboolean ret;
 
@@ -330,22 +329,19 @@ gst_espeak_uri_set_uri (GstURIHandler * handler, const gchar * uri) {
     return TRUE;
 }
 
+static gchar *
+gst_espeak_uri_get_uri (GstURIHandler * handler)
+{
+    return g_strdup_printf("espeak://%s", GST_ESPEAK (handler)->text);
+}
+
 static void gst_espeak_uri_handler_init (gpointer g_iface, gpointer iface_data) {
     GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
 
     iface->get_type = gst_espeak_uri_get_type;
     iface->get_protocols = gst_espeak_uri_get_protocols;
     iface->set_uri = gst_espeak_uri_set_uri;
-}
-
-static void gst_espeak_init_uri (GType filesrc_type) {
-    static const GInterfaceInfo urihandler_info = {
-        gst_espeak_uri_handler_init,
-        NULL,
-        NULL
-    };
-    g_type_add_interface_static (filesrc_type, GST_TYPE_URI_HANDLER,
-            &urihandler_info);
+    iface->get_uri = gst_espeak_uri_get_uri;
 }
 
 /******************************************************************************/
@@ -367,7 +363,7 @@ static gboolean espeak_init (GstPlugin * espeak) {
 
 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
         GST_VERSION_MINOR,
-        "espeak",
+        espeak,
         "Uses eSpeak library as a sound source for GStreamer",
         espeak_init,
         PACKAGE_VERSION,
-- 
1.7.10.4



More information about the Sugar-devel mailing list