<commit_before>/*
 * GStreamer
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/**
 * SECTION:element-echoprint
 *
 * Listens to ~30 seconds of audio and posts an echoprint code.
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/audio/audio.h>

#include <Codegen.h>

#include "gstechoprint.h"

GST_DEBUG_CATEGORY_STATIC (gst_echoprint_debug);
#define GST_CAT_DEFAULT gst_echoprint_debug

/* Filter signals and args */
enum
{
LAST_SIGNAL
};

enum
{
PROP_0,
PROP_SILENT,
PROP_SECONDS,
};

#define ECHOPRINT_CAPS "audio/x-raw-float, channels=(int)1, rate=(int)11025, width=(int)32 , endianness=1234"
#define EP_RATE (11025)

/* the capabilities of the inputs and outputs.
 *
 */
static GstStaticPadTemplate sink_template=
GST_STATIC_PAD_TEMPLATE (
	"sink",
	GST_PAD_SINK,
	GST_PAD_ALWAYS,
	GST_STATIC_CAPS (ECHOPRINT_CAPS)
);

static GstStaticPadTemplate src_template=
GST_STATIC_PAD_TEMPLATE (
	"src",
	GST_PAD_SRC,
	GST_PAD_ALWAYS,
	GST_STATIC_CAPS (ECHOPRINT_CAPS)
);

/* debug category for fltering log messages
 *
 */
#define DEBUG_INIT(bla) \
	GST_DEBUG_CATEGORY_INIT (gst_echoprint_debug, "echoprint", 0, "echoprint");

GST_BOILERPLATE_FULL (Gstechoprint, gst_echoprint, GstBaseTransform, GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);

static void gst_echoprint_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_echoprint_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec);
static gboolean gst_echoprint_set_caps (GstBaseTransform * btrans, GstCaps * incaps, GstCaps * outcaps);
static GstFlowReturn gst_echoprint_transform_ip (GstBaseTransform * base, GstBuffer * outbuf);
static gboolean gst_echoprint_start (GstBaseTransform * base);
static gboolean gst_echoprint_stop (GstBaseTransform * base);
static gboolean gst_echoprint_src_event (GstBaseTransform *trans, GstEvent *event);

/* GObject vmethod implementations */

static void
gst_echoprint_base_init(gpointer klass)
{
GstElementClass *element_class=GST_ELEMENT_CLASS (klass);

gst_element_class_set_details_simple (element_class,
	"echoprint",
	"Echoprint/Filter",
	"Echoprint codegenerator using libcodegen",
	" <<EMAIL>>");

gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_template));
gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&sink_template));
}

/* initialize the echoprint's class */
static void
gst_echoprint_class_init(GstechoprintClass * klass)
{
GObjectClass *gobject_class;

gobject_class=(GObjectClass *) klass;
gobject_class->set_property=gst_echoprint_set_property;
gobject_class->get_property=gst_echoprint_get_property;

g_object_class_install_property (gobject_class, PROP_SILENT, g_param_spec_boolean ("silent", "Silent", "Turn of bus messages", FALSE, (GParamFlags)G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_SECONDS, g_param_spec_int ("seconds", "Seconds", "Seconds of audio to buffer", 20, 40, 30, (GParamFlags)G_PARAM_READWRITE));

GST_BASE_TRANSFORM_CLASS (klass)->set_caps=GST_DEBUG_FUNCPTR (gst_echoprint_set_caps);
GST_BASE_TRANSFORM_CLASS (klass)->transform_ip=GST_DEBUG_FUNCPTR (gst_echoprint_transform_ip);
GST_BASE_TRANSFORM_CLASS (klass)->start=GST_DEBUG_FUNCPTR (gst_echoprint_start);
GST_BASE_TRANSFORM_CLASS (klass)->stop=GST_DEBUG_FUNCPTR (gst_echoprint_stop);
GST_BASE_TRANSFORM_CLASS (klass)->src_event=GST_DEBUG_FUNCPTR (gst_echoprint_src_event);
}

static gboolean
gst_echoprint_set_caps(GstBaseTransform * btrans, GstCaps * incaps, GstCaps * outcaps)
{
return TRUE;
}

/* initialize the new element
 * initialize instance structure
 */
static void
gst_echoprint_init(Gstechoprint *filter, GstechoprintClass * klass)
{
g_debug("init");

filter->silent=FALSE;
filter->seconds=30;
filter->done=FALSE;
}

static gboolean
gst_echoprint_src_event(GstBaseTransform *trans, GstEvent *event)
{
return TRUE;
}

static gboolean
gst_echoprint_start(GstBaseTransform *base)
{
Gstechoprint *filter=GST_ECHOPRINT(base);

g_debug("start");

filter->silent=FALSE;
filter->done=FALSE;
filter->buffer=gst_buffer_new();

return TRUE;
}

static gboolean
gst_echoprint_stop(GstBaseTransform *base)
{
Gstechoprint *filter=GST_ECHOPRINT(base);

g_debug("stop");

filter->silent=FALSE;
filter->done=FALSE;
if (filter->buffer)
	gst_buffer_unref(filter->buffer);

return TRUE;
}

static void
gst_echoprint_set_property(GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
{
Gstechoprint *filter=GST_ECHOPRINT(object);

switch (prop_id) {
	case PROP_SILENT:
		GST_OBJECT_LOCK(object);
		filter->silent=g_value_get_boolean (value);
		GST_OBJECT_UNLOCK(object);
	break;
	case PROP_SECONDS:
		GST_OBJECT_LOCK(object);
		filter->seconds=g_value_get_int (value);<commit_msg>remove debug<commit_after>/*
 * GStreamer
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/**
 * SECTION:element-echoprint
 *
 * Listens to ~30 seconds of audio and posts an echoprint code.
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/audio/audio.h>

#include <Codegen.h>

#include "gstechoprint.h"

GST_DEBUG_CATEGORY_STATIC (gst_echoprint_debug);
#define GST_CAT_DEFAULT gst_echoprint_debug

/* Filter signals and args */
enum
{
LAST_SIGNAL
};

enum
{
PROP_0,
PROP_SILENT,
PROP_SECONDS,
};

#define ECHOPRINT_CAPS "audio/x-raw-float, channels=(int)1, rate=(int)11025, width=(int)32 , endianness=1234"
#define EP_RATE (11025)

/* the capabilities of the inputs and outputs.
 *
 */
static GstStaticPadTemplate sink_template=
GST_STATIC_PAD_TEMPLATE (
	"sink",
	GST_PAD_SINK,
	GST_PAD_ALWAYS,
	GST_STATIC_CAPS (ECHOPRINT_CAPS)
);

static GstStaticPadTemplate src_template=
GST_STATIC_PAD_TEMPLATE (
	"src",
	GST_PAD_SRC,
	GST_PAD_ALWAYS,
	GST_STATIC_CAPS (ECHOPRINT_CAPS)
);

/* debug category for fltering log messages
 *
 */
#define DEBUG_INIT(bla) \
	GST_DEBUG_CATEGORY_INIT (gst_echoprint_debug, "echoprint", 0, "echoprint");

GST_BOILERPLATE_FULL (Gstechoprint, gst_echoprint, GstBaseTransform, GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);

static void gst_echoprint_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_echoprint_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec);
static gboolean gst_echoprint_set_caps (GstBaseTransform * btrans, GstCaps * incaps, GstCaps * outcaps);
static GstFlowReturn gst_echoprint_transform_ip (GstBaseTransform * base, GstBuffer * outbuf);
static gboolean gst_echoprint_start (GstBaseTransform * base);
static gboolean gst_echoprint_stop (GstBaseTransform * base);
static gboolean gst_echoprint_src_event (GstBaseTransform *trans, GstEvent *event);

/* GObject vmethod implementations */

static void
gst_echoprint_base_init(gpointer klass)
{
GstElementClass *element_class=GST_ELEMENT_CLASS (klass);

gst_element_class_set_details_simple (element_class,
	"echoprint",
	"Echoprint/Filter",
	"Echoprint codegenerator using libcodegen",
	" <<EMAIL>>");

gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_template));
gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&sink_template));
}

/* initialize the echoprint's class */
static void
gst_echoprint_class_init(GstechoprintClass * klass)
{
GObjectClass *gobject_class;

gobject_class=(GObjectClass *) klass;
gobject_class->set_property=gst_echoprint_set_property;
gobject_class->get_property=gst_echoprint_get_property;

g_object_class_install_property (gobject_class, PROP_SILENT, g_param_spec_boolean ("silent", "Silent", "Turn of bus messages", FALSE, (GParamFlags)G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_SECONDS, g_param_spec_int ("seconds", "Seconds", "Seconds of audio to buffer", 20, 40, 30, (GParamFlags)G_PARAM_READWRITE));

GST_BASE_TRANSFORM_CLASS (klass)->set_caps=GST_DEBUG_FUNCPTR (gst_echoprint_set_caps);
GST_BASE_TRANSFORM_CLASS (klass)->transform_ip=GST_DEBUG_FUNCPTR (gst_echoprint_transform_ip);
GST_BASE_TRANSFORM_CLASS (klass)->start=GST_DEBUG_FUNCPTR (gst_echoprint_start);
GST_BASE_TRANSFORM_CLASS (klass)->stop=GST_DEBUG_FUNCPTR (gst_echoprint_stop);
GST_BASE_TRANSFORM_CLASS (klass)->src_event=GST_DEBUG_FUNCPTR (gst_echoprint_src_event);
}

static gboolean
gst_echoprint_set_caps(GstBaseTransform * btrans, GstCaps * incaps, GstCaps * outcaps)
{
return TRUE;
}

/* initialize the new element
 * initialize instance structure
 */
static void
gst_echoprint_init(Gstechoprint *filter, GstechoprintClass * klass)
{
filter->silent=FALSE;
filter->seconds=30;
filter->done=FALSE;
}

static gboolean
gst_echoprint_src_event(GstBaseTransform *trans, GstEvent *event)
{
return TRUE;
}

static gboolean
gst_echoprint_start(GstBaseTransform *base)
{
Gstechoprint *filter=GST_ECHOPRINT(base);

filter->silent=FALSE;
filter->done=FALSE;
filter->buffer=gst_buffer_new();

return TRUE;
}

static gboolean
gst_echoprint_stop(GstBaseTransform *base)
{
Gstechoprint *filter=GST_ECHOPRINT(base);

filter->silent=FALSE;
filter->done=FALSE;
if (filter->buffer)
	gst_buffer_unref(filter->buffer);

return TRUE;
}

static void
gst_echoprint_set_property(GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
{
Gstechoprint *filter=GST_ECHOPRINT(object);

switch (prop_id) {
	case PROP_SILENT:
		GST_OBJECT_LOCK(object);
		filter->silent=g_value_get_boolean (value);
		GST_OBJECT_UNLOCK(object);
	break;
	case PROP_SECONDS:
		GST_OBJECT_LOCK(object);
		filter->seconds=g_value_get_int (value);
{'fraction_non_alphanumeric': 0.09718738803296309, 'fraction_numerical': 0.009315657470440702, 'mean_word_length': 7.043948126801153, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7446615', 'n_tokens_mistral': 4278, 'n_tokens_neox': 4169, 'n_words': 899}