以下是我的代码块,我试图从传入的mediapipeline中删除噪音。
VADCustomFilterImpl::VADCustomFilterImpl(const boost::property_tree::ptree & config,std::shared_ptr <MediaPipeline > mediaPipeline) :FilterImpl (config,std::dynamic_pointer_cast <MediaObjectImpl> (mediaPipeline))
{
/* audio cheb limit - to remove noise */
//GST_WARNING("------------------------audiocheblimit");
g_object_set(element, "filter-factory", "audiocheblimit", NULL);
g_object_get(G_OBJECT(element), "filter", &audiocheblimitfilter, NULL);
if (audiocheblimitfilter == NULL) {
throw KurentoException(MEDIA_OBJECT_NOT_FOUND, "MediaObject not found: audiocheblimitfilter");
}
g_object_set(G_OBJECT(audiocheblimitfilter), "mode", "low-pass", NULL);
g_object_set(G_OBJECT(audiocheblimitfilter),"cutoff", 700, NULL);
//GST_WARNING("----------------cutter");
/*Cutter*/
g_object_set(element, "filter-factory", "cutter", NULL);
g_object_get(G_OBJECT(element), "filter", &cutterfilter, NULL);
if (cutterfilter == NULL) {
throw KurentoException(MEDIA_OBJECT_NOT_FOUND, "MediaObject not found: cutterfilter");
}
g_object_set(G_OBJECT(cutterfilter), "threshold-dB", -40.0, NULL);
g_object_set(G_OBJECT(cutterfilter), "run-length", 500000000, NULL);
//GST_WARNING("~~~~~~~~~~~~~~~~~~~~audiocheblimit+cutter");
bus_handler_id = 0;
g_object_unref(audiocheblimitfilter);
g_object_unref(cutterfilter);
}
在kurento日志中只打印------------------------audiocheblimit
,之后没有日志,在我的java服务器控制台中得到Websocket disconnected by WebSocket Read EOF (status code 1006)
这有什么特别的原因导致崩溃吗? 我们可以在kurento中一个接一个地应用两个GStreamer插件吗?
或者我们是否需要创建多个kurento自定义过滤器,其中将使用一个单独的GStreamer插件?
修改1:
正如@santoscadenas指出的那样,我调查了faceoverlay
项目并在我的代码中进行了相应的更改,
#include "gstvadcustomfilter.h"
#include <gst/gst.h>
#include <glib/gstdio.h>
#include <gst/audio/audio.h>
#include <opencv2/opencv.hpp>
#include <cv.h>
#include <memory>
GST_DEBUG_CATEGORY_STATIC (gst_v_a_d_custom_filter_debug_category);
#define GST_CAT_DEFAULT gst_v_a_d_custom_filter_debug_category
#define PLUGIN_NAME "voicedetector"
#define GST_V_A_D_CUSTOM_FILTER_GET_PRIVATE(obj) ( \
G_TYPE_INSTANCE_GET_PRIVATE ( \
(obj), \
GST_TYPE_V_A_D_CUSTOM_FILTER, \
GstVADCustomFilterPrivate \
) \
)
/* pad templates */
#define AUDIO_SRC_CAPS \
GST_AUDIO_CAPS_MAKE("{ S16LE }")
#define AUDIO_SINK_CAPS \
GST_AUDIO_CAPS_MAKE("{ S16LE }")
/* class initialization */
struct _GstVADCustomFilterPrivate
{
GstElement *audiocheb_limit;
GstElement *cutter_filter;
GstPad *src, *sink;
}priv;
//GstPad *tempsrc , *cuttersrcpad, *audiocheblimitsinkpad;
/* the capabilities of the inputs and outputs. */
GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ( // the capabilities of the padtemplate
AUDIO_SINK_CAPS
)
);
GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_REQUEST,
GST_STATIC_CAPS ( // the capabilities of the padtemplate
AUDIO_SRC_CAPS
)
);
//G_DEFINE_TYPE (GstVADCustomFilter, gst_v_a_d_custom_filter, GST_TYPE_BIN);
G_DEFINE_TYPE_WITH_CODE (GstVADCustomFilter, gst_v_a_d_custom_filter,
GST_TYPE_BIN,
GST_DEBUG_CATEGORY_INIT (gst_v_a_d_custom_filter_debug_category,
PLUGIN_NAME, 0,
"debug category for v_a_d_custom_filter element") );
/*static GstFlowReturn
gst_v_a_d_custom_filter_transform_frame_ip (GstVideoFilter *filter,
GstVideoFrame *frame)
{
GST_WARNING("gst_v_a_d_custom_filter_transform_frame_ip");
return GST_FLOW_OK;
}*/
static void
gst_v_a_d_custom_filter_finalize (GObject *object)
{
GST_WARNING("Inside gst_v_a_d_custom_filter_finalize");
}
static void
gst_v_a_d_custom_filter_init (GstVADCustomFilter *v_a_d_custom_filter)
{
GstPadTemplate *templ;
GstPad *target;
GST_ERROR("Inside gst_v_a_d_custom_filter_init");
v_a_d_custom_filter->priv = GST_V_A_D_CUSTOM_FILTER_GET_PRIVATE (v_a_d_custom_filter);
GST_ERROR("audio cheb limit");
v_a_d_custom_filter->priv->audiocheb_limit =
gst_element_factory_make ("audiocheblimit", NULL);
g_object_set (v_a_d_custom_filter->priv->audiocheb_limit, "cutoff",700.0, NULL);
gst_bin_add (GST_BIN (v_a_d_custom_filter), v_a_d_custom_filter->priv->audiocheb_limit);
GST_ERROR("cutter");
/*cutter*/
v_a_d_custom_filter->priv->cutter_filter =
gst_element_factory_make ("cutter", NULL);
g_object_set (v_a_d_custom_filter->priv->cutter_filter, "threshold-dB",-40.0, NULL);
g_object_set (v_a_d_custom_filter->priv->cutter_filter, "run-length",500000000, NULL);
gst_bin_add (GST_BIN (v_a_d_custom_filter), v_a_d_custom_filter->priv->cutter_filter);
GST_ERROR("cutter added to the bus");
target = gst_element_get_static_pad (v_a_d_custom_filter->priv->audiocheb_limit, "sink");
GST_ERROR("sink factory");
templ = gst_static_pad_template_get (&sink_factory);
GST_ERROR("sink , target, templ");
v_a_d_custom_filter->priv->sink =
gst_ghost_pad_new_from_template ("sink", target, templ);
GST_ERROR("g_object_unref");
g_object_unref (templ);
g_object_unref (target);
GST_ERROR("GST_ELEMENT (v_a_d_custom_filter), v_a_d_custom_filter->priv->sink");
gst_element_add_pad (GST_ELEMENT (v_a_d_custom_filter), v_a_d_custom_filter->priv->sink);
target = gst_element_get_static_pad (v_a_d_custom_filter->priv->cutter_filter, "src");
GST_ERROR("src factory");
templ = gst_static_pad_template_get (&src_factory);
v_a_d_custom_filter->priv->src = gst_ghost_pad_new_from_template ("src", target, templ);
g_object_unref (templ);
g_object_unref (target);
gst_element_add_pad (GST_ELEMENT (v_a_d_custom_filter), v_a_d_custom_filter->priv->src);
gst_element_link (v_a_d_custom_filter->priv->audiocheb_limit, v_a_d_custom_filter->priv->cutter_filter);
}
static void
gst_v_a_d_custom_filter_class_init (GstVADCustomFilterClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
//GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass);
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, PLUGIN_NAME, 0, PLUGIN_NAME);
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
gst_pad_template_new ("src", GST_PAD_SRC,
GST_PAD_ALWAYS,
gst_caps_from_string (AUDIO_SRC_CAPS) ) );
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
gst_pad_template_new ("sink", GST_PAD_SINK,
GST_PAD_ALWAYS,
gst_caps_from_string (AUDIO_SINK_CAPS) ) );
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
"Voice Activity Detector", "Audio/Filter",
"Using GStreamer Cutter Element",
"Author: Sagar Pilkhwal");
gobject_class->finalize = gst_v_a_d_custom_filter_finalize;
//video_filter_class->transform_frame_ip = GST_DEBUG_FUNCPTR (gst_v_a_d_custom_filter_transform_frame_ip);
}
gboolean
gst_v_a_d_custom_filter_plugin_init (GstPlugin *plugin)
{
GST_WARNING("Inside gst_v_a_d_custom_filter_plugin_init");
return gst_element_register (plugin, PLUGIN_NAME, GST_RANK_NONE, GST_TYPE_V_A_D_CUSTOM_FILTER);
}
服务器日志:
(kurento-media-server:27765): GLib-GObject-CRITICAL **: g_object_set: assertion 'G_IS_OBJECT (object)' failed
(kurento-media-server:27765): GStreamer-CRITICAL **: gst_bin_add: assertion 'GST_IS_ELEMENT (element)' failed
(kurento-media-server:27765): GStreamer-CRITICAL **: gst_element_get_static_pad: assertion 'GST_IS_ELEMENT (element)' failed
(kurento-media-server:27765): GStreamer-CRITICAL **: gst_ghost_pad_new_from_template: assertion 'GST_IS_PAD (target)' failed
(kurento-media-server:27765): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
(kurento-media-server:27765): GStreamer-CRITICAL **: gst_element_add_pad: assertion 'GST_IS_PAD (pad)' failed
[31;1mSegmentation fault[0m (thread [33;1m140450597959424[0m, pid [33;1m27765[0m)
答案 0 :(得分:1)
问题是过滤器工厂只能设置一次。设置它两次不会工作,这是我们没有测试过的东西,也可能是段错误(因为它似乎正在发生)。
如果您需要应用的不仅仅是一个gstreamer元素,请创建一个包含两者的包装器(GstBin),并提供与一个简单过滤器(一个接收器和一个src)相同的接口接口。在GstBin中,您可以根据需要连接多个元素。
修改强>
你可以有一个GstBin的例子,它封装了各种元素here
修改2
问题在于这一行:
g_object_set (G_OBJECT (audiocheblimit), "mode", "low-pass", NULL);
"mode"
是一个枚举,可以作为字符串传递,但作为整数值传递。
编辑3
您似乎没有在.h
文件中声明您的元素相关性:
typedef _GstVADCustomFilter {
GstBin parent;
...
} GstVADCustomFilter;
在您的.c
文件中:
G_DEFINE_TYPE (GstVADCustomFilter, gst_v_a_d_custom_filter, GST_TYPE_BIN);