Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yanghongtian opened this issue Mar 27, 2022 · 1 comment
Open

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

yanghongtian opened this issue Mar 27, 2022 · 1 comment

Comments

@yanghongtian
Copy link

#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
Copy link
Author

yanghongtian commented Mar 27, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant