looks like seeing frames on new sample

This commit is contained in:
talksik
2023-07-23 13:44:51 -07:00
parent 9f880edd7d
commit 567e1a7a9c
3 changed files with 28 additions and 5 deletions
+24 -4
View File
@@ -11,17 +11,21 @@ LocalCapture::LocalCapture() {
GstElement *video = gst_element_factory_make("v4l2src", "video");
GstElement *videoconvert =
gst_element_factory_make("videoconvert", "videoconvert");
gtksink = gst_element_factory_make("autovideosink", "sink");
sink = gst_element_factory_make("appsink", "sink");
if (!video || !videoconvert || !gtksink) {
// set callback for appsink
g_object_set(G_OBJECT(sink), "emit-signals", TRUE, "sync", FALSE, nullptr);
g_signal_connect(sink, "new-sample", G_CALLBACK(on_new_sample), this);
if (!video || !videoconvert || !sink) {
std::cerr << "failed to create elements" << std::endl;
return;
}
m_pipeline = gst_pipeline_new("local_capture");
gst_bin_add_many(GST_BIN(m_pipeline), video, videoconvert, gtksink, nullptr);
if (!gst_element_link_many(video, videoconvert, gtksink, nullptr)) {
gst_bin_add_many(GST_BIN(m_pipeline), video, videoconvert, sink, nullptr);
if (!gst_element_link_many(video, videoconvert, sink, nullptr)) {
g_printerr("Elements could not be linked.\n");
}
@@ -58,6 +62,22 @@ LocalCapture::LocalCapture() {
std::cout << "local capture ready" << std::endl;
}
int LocalCapture::on_new_sample(GstElement *sink, gpointer data) {
GstSample *sample;
/* Retrieve the buffer */
g_signal_emit_by_name(sink, "pull-sample", &sample);
if (sample) {
/* The only thing we do in this example is print a * to indicate a received
* buffer */
g_print("*");
gst_sample_unref(sample);
return GST_FLOW_OK;
}
return GST_FLOW_ERROR;
}
void LocalCapture::start() {
if (m_isRunning) {
return;
+3 -1
View File
@@ -11,13 +11,15 @@ public:
gst_object_unref(m_bus);
gst_element_set_state(m_pipeline, GST_STATE_NULL);
gst_object_unref(m_pipeline);
gst_object_unref(sink);
}
bool isRunning() const { return m_isRunning; }
GstElement *gtksink;
GstElement *sink;
private:
bool m_isRunning;
gboolean bus_watch(GMainLoop *loop);
GstElement *m_pipeline;
GstBus *m_bus;
static int on_new_sample(GstElement *sink, gpointer data);
};
+1
View File
@@ -14,6 +14,7 @@ MyWindow::MyWindow() {
m_localCapture = new LocalCapture();
// todo: show frames here
//GtkWidget *area;
// g_object_get(m_localCapture->gtksink, "widget", &area, NULL);
// Gtk::Widget *widget = Glib::wrap(area);