112 lines
4.3 KiB
C++
112 lines
4.3 KiB
C++
#include "source_bin.hpp"
|
|
|
|
// Initialize static member (required for non-const static members)
|
|
// int MyClass::staticCounter = 0;
|
|
|
|
// Definition of static function
|
|
void SourceBin::decodebin_child_added(GstChildProxy *child_proxy,
|
|
GObject *object, gchar *name,
|
|
gpointer user_data) {
|
|
(void)child_proxy; // This explicitly marks it as unused
|
|
|
|
StreamData *data = static_cast<StreamData *>(user_data);
|
|
gint source_id = data->source_id;
|
|
// gint source_id = (*(gint *) user_data);
|
|
|
|
g_print(
|
|
"Decodebin child added %s for stream_id %d"
|
|
"\n",
|
|
name, source_id);
|
|
if (g_strrstr(name, "decodebin") == name) {
|
|
g_signal_connect(G_OBJECT(object), "child-added",
|
|
G_CALLBACK(decodebin_child_added), user_data);
|
|
}
|
|
|
|
if (g_strrstr(name, "nvv4l2decoder") == name) {
|
|
if (data->prop.integrated) {
|
|
g_object_set(object, "enable-max-performance", TRUE, NULL);
|
|
g_object_set(object, "bufapi-version", TRUE, NULL);
|
|
g_object_set(object, "drop-frame-interval", 0, NULL);
|
|
g_object_set(object, "num-extra-surfaces", 0, NULL);
|
|
} else {
|
|
g_object_set(object, "gpu-id", GPU_ID, NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Definition of static function
|
|
void SourceBin::cb_newpad(GstElement *decodebin, GstPad *pad,
|
|
gpointer user_data, gboolean *flag) {
|
|
(void)decodebin; // This explicitly marks it as unused
|
|
(void)flag; // This explicitly marks it as unused
|
|
StreamData *data = static_cast<StreamData *>(user_data);
|
|
gint source_id = data->source_id;
|
|
GstElement *streammux = data->streammux;
|
|
// gint source_id = (*(gint *) data);
|
|
g_print(
|
|
"In cb_newpad for stream_id %d"
|
|
"\n",
|
|
source_id);
|
|
GstCaps *caps = gst_pad_query_caps(pad, NULL);
|
|
const GstStructure *str = gst_caps_get_structure(caps, 0);
|
|
const gchar *name = gst_structure_get_name(str);
|
|
|
|
// g_print ("decodebin new pad %s\n", name);
|
|
g_print(
|
|
"decodebin new pad %s for stream_id %d"
|
|
"\n",
|
|
name, source_id);
|
|
if (!strncmp(name, "video", 5)) {
|
|
gchar pad_name[16] = {0};
|
|
GstPad *sinkpad = NULL;
|
|
g_snprintf(pad_name, 15, "sink_%u", source_id);
|
|
sinkpad = gst_element_request_pad_simple(
|
|
streammux, pad_name); // gst_element_get_request_pad
|
|
|
|
if (!sinkpad) {
|
|
g_printerr(
|
|
"Streammux request sink pad failed for stream_id %d or "
|
|
". Exiting. \n",
|
|
source_id);
|
|
}
|
|
if (gst_pad_link(pad, sinkpad) != GST_PAD_LINK_OK) {
|
|
g_printerr(
|
|
"Failed to link decodebin bin to pipeline for stream_id %d or "
|
|
". Exiting.\n",
|
|
source_id);
|
|
} else {
|
|
// g_print ("Decodebin linked to pipeline\n");
|
|
g_print(
|
|
"Decodebin linked to pipeline for stream_id %d"
|
|
"\n",
|
|
source_id);
|
|
}
|
|
gst_object_unref(sinkpad);
|
|
}
|
|
}
|
|
|
|
// Definition of static function
|
|
GstElement *SourceBin::create_nvurisrc_bin(guint index, gchar *filename,
|
|
GstElement *streammux,
|
|
cudaDeviceProp prop) {
|
|
GstElement *decodebin = NULL;
|
|
gchar decodebin_name[16] = {};
|
|
// Create data structure for callbacks
|
|
StreamData *stream_data = new StreamData{(int)index, streammux, prop};
|
|
|
|
// g_print ("creating nvurisrcbin for [%s]\n", filename);
|
|
g_print("Creating nvurisrcbin for stream_id %d or stream %s \n", index,
|
|
filename);
|
|
// g_source_id_list[index] = index;
|
|
g_snprintf(decodebin_name, 15, "source-bin-%02d", index);
|
|
decodebin = gst_element_factory_make("nvurisrcbin", decodebin_name);
|
|
g_object_set(G_OBJECT(decodebin), "uri", filename, NULL);
|
|
g_signal_connect(G_OBJECT(decodebin), "pad-added", G_CALLBACK(cb_newpad),
|
|
stream_data); //&g_source_id_list[index]
|
|
g_signal_connect(
|
|
G_OBJECT(decodebin), "child-added", G_CALLBACK(decodebin_child_added),
|
|
stream_data); //&g_source_id_list[index] //&stream_data->source_id
|
|
// g_source_enabled[index] = TRUE;
|
|
|
|
return decodebin;
|
|
} |