[ekiga] Reorganized the gstreamer audio input code like the audio output one
- From: Julien Puydt <jpuydt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] Reorganized the gstreamer audio input code like the audio output one
- Date: Wed, 1 Feb 2012 17:28:56 +0000 (UTC)
commit 71421216da1d78050699744e66cf788b96e67634
Author: Julien Puydt <jpuydt newton localdomain>
Date: Wed Feb 1 14:44:11 2012 +0100
Reorganized the gstreamer audio input code like the audio output one
It doesn't work worse now (sic).
plugins/gstreamer/gst-audioinput.cpp | 238 +++++++++++++++++++---------------
plugins/gstreamer/gst-audioinput.h | 4 +-
2 files changed, 134 insertions(+), 108 deletions(-)
---
diff --git a/plugins/gstreamer/gst-audioinput.cpp b/plugins/gstreamer/gst-audioinput.cpp
index a26be76..3af8036 100644
--- a/plugins/gstreamer/gst-audioinput.cpp
+++ b/plugins/gstreamer/gst-audioinput.cpp
@@ -38,14 +38,114 @@
#include <glib/gi18n.h>
#include "gst-audioinput.h"
+#include "runtime.h"
#include <gst/interfaces/propertyprobe.h>
#include <gst/app/gstappsink.h>
#include <string.h>
+struct gstreamer_worker
+{
+ GstElement* pipeline;
+ GstElement* volume;
+ GstElement* sink;
+};
+
+static void
+gstreamer_worker_setup (gstreamer_worker* self,
+ const gchar* command)
+{
+ g_message ("%s\t%s\n", __PRETTY_FUNCTION__, command);
+ self->pipeline = gst_parse_launch (command, NULL);
+ (void)gst_element_set_state (self->pipeline, GST_STATE_PLAYING);
+ self->volume = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_volume");
+ self->sink = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_sink");
+}
+
+static void
+gstreamer_worker_destroy (gstreamer_worker* self)
+{
+ g_object_unref (self->sink);
+ self->sink = NULL;
+ if (self->volume)
+ g_object_unref (self->volume);
+ self->volume = NULL;
+ g_object_unref (self->pipeline);
+ self->pipeline = NULL;
+ g_free (self);
+}
+
+static void
+gstreamer_worker_close (gstreamer_worker* self)
+{
+ g_message ("%s\n", __PRETTY_FUNCTION__);
+ gst_element_set_state (self->pipeline, GST_STATE_NULL);
+ Ekiga::Runtime::run_in_main (boost::bind(&gstreamer_worker_destroy, self), 1);
+}
+
+static void
+gstreamer_worker_set_volume (gstreamer_worker* self,
+ gfloat valf)
+{
+ g_message ("%s\t%f\n", __PRETTY_FUNCTION__, valf);
+ if (self->volume)
+ g_object_set (G_OBJECT (self->volume),
+ "volume", valf,
+ NULL);
+}
+
+static gfloat
+gstreamer_worker_get_volume (gstreamer_worker* self)
+{
+ gfloat result = -1;
+ if (self->volume)
+ g_object_get (G_OBJECT (self->volume),
+ "volume", &result,
+ NULL);
+
+ return result;
+}
+
+static void
+gstreamer_worker_set_buffer_size (gstreamer_worker* self,
+ unsigned size)
+{
+ g_message ("%s\t%d\n", __PRETTY_FUNCTION__, size);
+ if (self->sink)
+ g_object_set (G_OBJECT (self->sink),
+ "blocksize", size,
+ NULL);
+}
+
+
+
+bool
+gstreamer_worker_get_frame_data (gstreamer_worker* self,
+ char* data,
+ unsigned size,
+ unsigned& read)
+{
+ bool result = false;
+ GstBuffer* buffer = NULL;
+
+ read = 0;
+
+ buffer = gst_app_sink_pull_buffer (GST_APP_SINK (self->sink));
+
+ if (buffer != NULL) {
+
+ read = MIN (GST_BUFFER_SIZE (buffer), size);
+ memcpy (data, GST_BUFFER_DATA (buffer), read);
+ result = true;
+ gst_buffer_unref (buffer);
+ }
+
+ return result;
+}
+
GST::AudioInputManager::AudioInputManager ():
- already_detected_devices(false), pipeline(NULL)
+ already_detected_devices(false), worker(NULL)
{
}
@@ -94,10 +194,10 @@ GST::AudioInputManager::open (unsigned channels,
unsigned samplerate,
unsigned bits_per_sample)
{
- bool result = false;
+ g_message ("%s\n", __PRETTY_FUNCTION__);
gchar* command = NULL;
- GError* error = NULL;
- GstState current;
+
+ worker = g_new0 (gstreamer_worker, 1);
if ( !already_detected_devices)
detect_devices ();
@@ -110,91 +210,46 @@ GST::AudioInputManager::open (unsigned channels,
" name=ekiga_sink",
devices_by_name[std::pair<std::string,std::string>(current_state.device.source, current_state.device.name)].c_str (),
samplerate, channels, bits_per_sample);
- //g_print ("Pipeline: %s\n", command);
- pipeline = gst_parse_launch (command, &error);
-
- if (error == NULL) {
-
- (void)gst_element_set_state (pipeline, GST_STATE_PLAYING);
-
- // this will make us wait so we can return the right value...
- (void)gst_element_get_state (pipeline,
- ¤t,
- NULL,
- GST_SECOND);
-
- if (current != GST_STATE_PLAYING) {
-
- gst_element_set_state (pipeline, GST_STATE_NULL);
- gst_object_unref (GST_OBJECT (pipeline));
- pipeline = NULL;
- result = false;
- } else {
-
- Ekiga::AudioInputSettings settings;
- GstElement* volume = NULL;
- gfloat val;
-
- volume = gst_bin_get_by_name (GST_BIN (pipeline), "ekiga_volume");
- if (volume != NULL) {
- g_object_get (G_OBJECT (volume),
- "volume", &val,
- NULL);
- settings.volume = (unsigned)(255*val);
- settings.modifyable = true;
- g_object_unref (volume);
- } else {
-
- settings.modifyable = false;
- }
- current_state.channels = channels;
- current_state.samplerate = samplerate;
- current_state.bits_per_sample = bits_per_sample;
- device_opened (current_state.device, settings);
- result = true;
- }
+ gstreamer_worker_setup (worker, command);
+ g_free (command);
- } else {
+ Ekiga::AudioInputSettings settings;
+ gfloat vol = gstreamer_worker_get_volume (worker);
+ if (vol >= 0) {
- g_error_free (error);
- result = false;
+ settings.volume = (unsigned)(255*vol);
+ settings.modifyable = true;
}
-
- g_free (command);
-
- current_state.opened = result;
- return result;
+ current_state.channels = channels;
+ current_state.samplerate = samplerate;
+ current_state.bits_per_sample = bits_per_sample;
+ device_opened (current_state.device, settings);
+ current_state.opened = true;
+ Ekiga::Runtime::run_in_main (boost::bind (boost::ref(device_opened), current_state.device, settings));
+
+ return true;
}
void
GST::AudioInputManager::close ()
{
- if (pipeline != NULL) {
+ g_message ("%s\n", __PRETTY_FUNCTION__);
- gst_element_set_state (pipeline, GST_STATE_NULL);
- g_object_unref (pipeline);
- pipeline = NULL;
- device_closed (current_state.device);
- }
+ if (worker)
+ gstreamer_worker_close (worker);
+ Ekiga::Runtime::run_in_main (boost::bind (boost::ref(device_closed),
+ current_state.device));
current_state.opened = false;
+ worker = NULL;
}
void
GST::AudioInputManager::set_buffer_size (unsigned buffer_size,
unsigned /*num_buffers*/)
{
- GstElement* sink = NULL;
-
- sink = gst_bin_get_by_name (GST_BIN (pipeline), "ekiga_sink");
-
- if (sink != NULL) {
-
- g_object_set (G_OBJECT (sink),
- "blocksize", buffer_size,
- NULL);
- g_object_unref (sink);
- }
+ if (worker)
+ gstreamer_worker_set_buffer_size (worker, buffer_size);
}
bool
@@ -203,28 +258,9 @@ GST::AudioInputManager::get_frame_data (char* data,
unsigned& read)
{
bool result = false;
- GstBuffer* buffer = NULL;
- GstElement* sink = NULL;
-
read = 0;
-
- g_return_val_if_fail (GST_IS_BIN (pipeline), false);
-
- sink = gst_bin_get_by_name (GST_BIN (pipeline), "ekiga_sink");
-
- if (sink != NULL) {
-
- buffer = gst_app_sink_pull_buffer (GST_APP_SINK (sink));
-
- if (buffer != NULL) {
-
- read = MIN (GST_BUFFER_SIZE (buffer), size);
- memcpy (data, GST_BUFFER_DATA (buffer), read);
- result = true;
- gst_buffer_unref (buffer);
- }
- g_object_unref (sink);
- }
+ if (worker)
+ result = gstreamer_worker_get_frame_data (worker, data, size, read);
return result;
}
@@ -232,19 +268,7 @@ GST::AudioInputManager::get_frame_data (char* data,
void
GST::AudioInputManager::set_volume (unsigned valu)
{
- GstElement* volume = NULL;
- gfloat valf;
-
- valf = valu / 255.0;
-
- volume = gst_bin_get_by_name (GST_BIN (pipeline), "ekiga_volume");
- if (volume != NULL) {
-
- g_object_set (G_OBJECT (volume),
- "volume", valf,
- NULL);
- g_object_unref (volume);
- }
+ gstreamer_worker_set_volume (worker, valu / 255.0);
}
bool
diff --git a/plugins/gstreamer/gst-audioinput.h b/plugins/gstreamer/gst-audioinput.h
index da3770a..0009190 100644
--- a/plugins/gstreamer/gst-audioinput.h
+++ b/plugins/gstreamer/gst-audioinput.h
@@ -44,6 +44,8 @@
#include <map>
+struct gstreamer_worker;
+
namespace GST
{
class AudioInputManager: public Ekiga::AudioInputManager
@@ -88,7 +90,7 @@ namespace GST
* the actual device */
std::map<std::pair<std::string, std::string>, std::string> devices_by_name;
- GstElement* pipeline;
+ gstreamer_worker* worker;
};
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]