Hi,I'm trying to create a custom audio sink plugin for gstreamer using the
Gst::AudioSink as a base class.,i have gone through a previous mail on april and created a sample plugin.but plugin fails by audiobasesink gstaudiobasesink.c:1193:gst_audio_base_sink_preroll:< customaudiosink0> [00m error: sink not negotiated. i have looked into gstaudiobasesink.cit fails at !gst_audio_ring_buffer_is_acquired .am i missing something here.i am including the sample here--------- .h#include <gstreamermm.h>
#include <gstreamermm/audiosink.h>
#include <gstreamermm/private/audiosink_p.h>
#include <iostream>
class CustomAudioSink: public Gst::AudioSink {
public:
explicit CustomAudioSink(GstAudioSink * gobj);
virtual ~CustomAudioSink();
static void class_init(Gst::ElementClass<CustomAudioSink> *klass);
static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
bool open_vfunc() override;
bool close_vfunc() override;
int write_vfunc(gpointer data, guint length) override;
guint get_delay_vfunc() const override;
Glib::RefPtr<Gst::AudioRingBuffer> create_ring_buffer_vfunc() override
{
const auto base = static_cast<BaseClassType*>(g_type_class_peek_parent(
G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
);
const auto newbase = (_GstAudioBaseSinkClass *) base;
if (newbase && newbase->create_ringbuffer) {
Glib::RefPtr<Gst::AudioRingBuffer> retval(
Glib::wrap(
(*newbase->create_ringbuffer)(
(_GstAudioBaseSink *) gobj()), true));
return retval;
}
using RType = Glib::RefPtr<Gst::AudioRingBuffer>;
return RType();
}
};---------- .cpp#include "CustomAudioSink.h"
#include <iostream>
CustomAudioSink::CustomAudioSink(GstAudioSink * gobj) :
Glib::ObjectBase(typeid(CustomAudioSink)), Gst::AudioSink(gobj) {
}
CustomAudioSink::~CustomAudioSink() {
// TODO Auto-generated destructor stub
}
void CustomAudioSink::class_init(Gst::ElementClass< CustomAudioSink> *klass) {
klass->set_metadata("foo_longname", "foo_classification",
"foo_detail_description", "foo_detail_author"); //channel-mask=(bitmask)0x1,layout=(string)interleaved
klass->add_pad_template(
Gst::PadTemplate::create("sink", Gst::PadDirection::PAD_SINK,
Gst::PAD_ALWAYS, Gst::Caps::create_any()));
}
bool CustomAudioSink::register_element(Glib::RefPtr<Gst:: Plugin> plugin) {
Gst::ElementFactory::register_element(plugin, "customaudiosink", 0,
Gst::register_mm_type<CustomAudioSink>(" customaudiosink"));
return true;
}
bool CustomAudioSink::open_vfunc() {
std::cout << "*** CustomAudioSink: " << __FUNCTION__ << " Called ***"
<< std::endl;
return true;
}
bool CustomAudioSink::close_vfunc() {
std::cout << "*** CustomAudioSink: " << __FUNCTION__ << " Called ***"
<< std::endl;
return true;
}
int CustomAudioSink::write_vfunc(gpointer data, guint length) {
std::cout << "Writing Audio : " << length << std::endl;
return length;
}
guint CustomAudioSink::get_delay_vfunc() const {
return 0;
}------ main.cpp#include <gstreamermm.h>
#include <giomm.h>
#include <iostream>
#include "CustomAudioSink.h"
using namespace std;
bool on_bus_message(const Glib::RefPtr<Gst::Bus> & bus, const Glib::RefPtr<Gst::Message> & message)
{
std::cout << "Bus Message : " << message->get_message_type() << ":" << GST_MESSAGE_TYPE_NAME(message.get())
<< std::endl;
return true;
}
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
Gst::init();
Gio::init();
auto mainloop = Glib::MainLoop::create();
Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR,
"customaudiosink", "customaudiosink",
sigc::ptr_fun(&CustomAudioSink::register_ element), "0.123",
"LGPL", "source?", "package?", "abcd.com");
std::string description =
"audiotestsrc blocksize=16000 num-buffers=100 ! audio/x-raw,format=(string)S16LE,rate=(int)16000, channels=(int)1 ! customaudiosink";
auto bin = Gst::Parse::create_bin(description, true);
auto pipeline = Gst::Pipeline::create();
pipeline->get_bus()->add_watch(sigc::ptr_fun(&on_bus_ message));
pipeline->add(bin);
pipeline->set_state(Gst::State::STATE_PLAYING);
mainloop->run();
pipeline->set_state(Gst::State::STATE_NULL);
return 0;
}
--RegardsAnkur Deep Jaiswal