Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Commit

Permalink
Add PlayTestTone method and PropertiesCommitted signal to dbus interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePBone committed Jan 16, 2020
1 parent 03c9d96 commit a2112a7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ file(GLOB SOURCES

add_library(gst-plugin-viperfx SHARED ${SOURCES})

find_package(PkgConfig REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0 gio-unix-2.0)
target_include_directories(gst-plugin-viperfx PUBLIC ${GST_INCLUDE_DIRS})
target_compile_options(gst-plugin-viperfx PUBLIC ${GST_CFLAGS})
Expand Down
40 changes: 40 additions & 0 deletions src/dbus-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ static const gchar introspection_xml[] =
" <method name='CommitProperties'>"
" <arg type='u' name='response' direction='out'/>"
" </method>"
" <method name='PlayTestTone'>"
" <arg type='u' name='freq' direction='in'/>"
" <arg type='u' name='dur' direction='in'/>"
" <arg type='u' name='response' direction='out'/>\""
" </method>"
" <signal name='PropertiesCommitted'>"
" <arg type='u' name='bitmask' />"
" <annotation name='org.gtk.GDBus.Annotation' value='Onsignal'/>"
" </signal>"
" <property type='b' name='agc_enable' access='readwrite'/>"
" <property type='i' name='agc_maxgain' access='readwrite'/>"
" <property type='i' name='agc_ratio' access='readwrite'/>"
Expand Down Expand Up @@ -208,6 +217,15 @@ handle_method_call (GDBusConnection *connection,
ret = 2;
else
user->sync_all_parameters_fun(intf,PARAM_GROUP_ALL);

if(ret == 0) g_dbus_connection_emit_signal (connection,
NULL,
object_path,
interface_name,
"PropertiesCommitted",
g_variant_new ("(u)", PARAM_GROUP_ALL),
NULL);

g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(u)", ret));
}
Expand All @@ -225,9 +243,31 @@ handle_method_call (GDBusConnection *connection,
ret = 3;
else
user->sync_all_parameters_fun(intf,(PARAM_GROUP)bitmask);

if(ret == 0) g_dbus_connection_emit_signal (connection,
NULL,
object_path,
interface_name,
"PropertiesCommitted",
g_variant_new ("(u)", bitmask),
NULL);

g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(u)", ret));
}
else if (g_strcmp0 (method_name, "PlayTestTone") == 0)
{
guint32 freq = 0x0;
guint32 dur = 0x0;
g_variant_get (parameters, "(uu)", &freq, &dur);
if(dur > 200000) dur = 200000;
intf->sine_duration = dur;
intf->sine_sample_counter = 0;
intf->sine_frequency = freq;
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(u)", 0));

}
}

static GVariant *
Expand Down
30 changes: 22 additions & 8 deletions src/gstviperfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <gst/audio/audio.h>
#include <gst/audio/gstaudiofilter.h>
#include <gst/controller/controller.h>
#include <math.h>
#include "gstviperfx.h"
#include "dbus-interface.h"

Expand Down Expand Up @@ -773,6 +774,11 @@ gst_viperfx_init (Gstviperfx *self)
}
}

self->samplerate = 0;
self->sine_sample_counter = -1;
self->sine_duration = -1;
self->sine_frequency = 100;

if (self->vfx != NULL)
sync_all_parameters (self, PARAM_GROUP_ALL);

Expand Down Expand Up @@ -1615,23 +1621,22 @@ static gboolean
gst_viperfx_setup (GstAudioFilter * base, const GstAudioInfo * info)
{
Gstviperfx *self = GST_VIPERFX (base);
gint sample_rate = 0;

if (self->vfx == NULL)
return FALSE;

if (info) {
sample_rate = GST_AUDIO_INFO_RATE (info);
self->samplerate = GST_AUDIO_INFO_RATE (info);
} else {
sample_rate = GST_AUDIO_FILTER_RATE (self);
self->samplerate = GST_AUDIO_FILTER_RATE (self);
}
if (sample_rate <= 0)
if (self->samplerate <= 0)
return FALSE;

GST_DEBUG_OBJECT (self, "current sample_rate = %d", sample_rate);
GST_DEBUG_OBJECT (self, "current sample_rate = %d", self->samplerate);

g_mutex_lock (&self->lock);
if (!self->vfx->set_samplerate (self->vfx, sample_rate)) {
if (!self->vfx->set_samplerate (self->vfx, self->samplerate)) {
g_mutex_unlock (&self->lock);
return FALSE;
}
Expand Down Expand Up @@ -1687,8 +1692,17 @@ gst_viperfx_transform_ip (GstBaseTransform * base, GstBuffer * buf)
pcm_data[idx] >>= 1;
if (filter->vfx != NULL) {
g_mutex_lock (&filter->lock);
filter->vfx->process (filter->vfx,
pcm_data, (int)num_samples);
if(filter->sine_duration == -1)
filter->vfx->process (filter->vfx,
pcm_data, (int)num_samples);
else{
for (int n = 0; n < num_samples*2; n++)
pcm_data[n] = (short)(0.25 * SHRT_MAX * sin((M_PI * n * filter->sine_frequency) / 44100));
filter->sine_sample_counter += num_samples * 2;
if(filter->sine_duration < filter->sine_sample_counter)
filter->sine_duration = -1;
}

g_mutex_unlock (&filter->lock);
}
gst_buffer_unmap (buf, &map);
Expand Down
6 changes: 5 additions & 1 deletion src/gstviperfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ struct _Gstviperfx {
fn_viperfx_ep so_entrypoint;
viperfx_interface *vfx;
GMutex lock;
guint dbus_owner_id;
guint32 samplerate;
guint32 dbus_owner_id;
guint32 sine_sample_counter;
gint32 sine_duration;
gint32 sine_frequency;
};

struct _GstviperfxClass {
Expand Down

0 comments on commit a2112a7

Please sign in to comment.