RidgeRun / gst-interpipe

GStreamer plug-in for interpipeline communication
Other
140 stars 63 forks source link

interpipesink does not emit signals 'new-sample' #121

Open yanghongtian opened 2 years ago

yanghongtian commented 2 years ago

include <gst/gst.h>

include <gst/gstbin.h>

include

struct CustomData { GstElement pipeline; GMainLoop loop; };

gboolean bus_call(GstBus bus, GstMessage msg, gpointer user_data) { CustomData data = reinterpret_cast<CustomData>(user_data);

GMainLoop* loop = data->loop;
switch (GST_MESSAGE_TYPE(msg)) {
    case GST_MESSAGE_EOS:
        g_main_loop_quit(loop);
        break;
    case GST_MESSAGE_ERROR: {
        gchar* debug = NULL;
        GError* error = NULL;
        gst_message_parse_error(msg, &error, &debug);
        if (debug) {
            g_free(debug);
        }
        if (error) {
            g_error_free(error);
        }
        g_main_loop_quit(loop);
        break;
    }
    case GST_MESSAGE_STATE_CHANGED: {
        if (GST_MESSAGE_SRC(msg) == GST_OBJECT(data->pipeline)) {
            GstState old_state, new_state;
            gst_message_parse_state_changed(
                msg, &old_state, &new_state, NULL);
        }
        break;
    }
    default:
        break;
}
return TRUE;

}

GstFlowReturn user_function (GstElement* object, gpointer user_data) { printf("-------------new sample\n"); return GST_FLOW_OK; }

int main(int argc, char* argv) { CustomData data; GstBus bus;

/* Initialize GStreamer */
gst_init(&argc, &argv);

/* Build the pipeline */
data.pipeline =
    gst_parse_launch
    ("videotestsrc ! interpipesink name=sink0",
    NULL);
GstElement* sink = gst_bin_get_by_name((GstBin*)data.pipeline, "sink0");
g_signal_connect(sink, "new-sample", G_CALLBACK(user_function), NULL);
g_object_set(sink, "emit-signals", TRUE, NULL);
data.loop = g_main_loop_new(NULL, false);
bus = gst_pipeline_get_bus((GstPipeline*)data.pipeline);
int bus_id_ = gst_bus_add_watch(bus, bus_call, &data);

gst_element_set_state(data.pipeline, GST_STATE_PLAYING);

g_main_loop_run(data.loop); 

gst_object_unref(bus);
gst_element_set_state (data.pipeline, GST_STATE_NULL);
gst_object_unref (data.pipeline);
return 0;

}

yanghongtian commented 2 years ago

if I replace interpipesink with appsink, the new-sample signal can emit, and call the user_function