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

fix(kvs/sink_gstreamer_sample): Use videotestsrc and add additional debug logging #1047

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions samples/kvs_gstreamer_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,10 @@ static bool format_supported_by_source(GstCaps *src_caps, GstCaps *query_caps, i
static bool resolution_supported(GstCaps *src_caps, GstCaps *query_caps_raw, GstCaps *query_caps_h264,
CustomData &data, int width, int height, int framerate) {
if (query_caps_h264 && format_supported_by_source(src_caps, query_caps_h264, width, height, framerate)) {
LOG_DEBUG("src supports h264")
data.h264_stream_supported = true;
} else if (query_caps_raw && format_supported_by_source(src_caps, query_caps_raw, width, height, framerate)) {
LOG_DEBUG("src supports raw")
data.h264_stream_supported = false;
} else {
return false;
Expand Down Expand Up @@ -694,21 +696,39 @@ int gstreamer_live_source_init(int argc, char* argv[], CustomData *data, GstElem
// Attempt to create vtenc encoder
encoder = gst_element_factory_make("vtenc_h264_hw", "encoder");
if (encoder) {
source = gst_element_factory_make("autovideosrc", "source");
vtenc = true;
source = gst_element_factory_make("videotestsrc", "source");
if (source) {
LOG_DEBUG("Using videotestsrc");
} else {
LOG_ERROR("Failed to create videotestsrc");
}
} else {
// Failed creating vtenc - check pi hardware encoder
encoder = gst_element_factory_make("omxh264enc", "encoder");
if (encoder) {
LOG_DEBUG("Using omxh264enc");
isOnRpi = true;
} else {
// - attempt x264enc
encoder = gst_element_factory_make("x264enc", "encoder");
isOnRpi = false;
encoder = gst_element_factory_make("x264enc", "encoder");
if (encoder) {
LOG_DEBUG("Using x264enc");
} else {
LOG_ERROR("Failed to create x264enc");
}
}
source = gst_element_factory_make("v4l2src", "source");
if (!source) {
if (source) {
LOG_DEBUG("Using v4l2src");
} else {
source = gst_element_factory_make("ksvideosrc", "source");
sirknightj marked this conversation as resolved.
Show resolved Hide resolved
sirknightj marked this conversation as resolved.
Show resolved Hide resolved
if (source) {
LOG_DEBUG("Using ksvideosrc");
} else {
LOG_ERROR("Unable to create src element. Tried v4l2src and ksvideosrc");
}
}
vtenc = false;
}
Expand All @@ -719,7 +739,9 @@ int gstreamer_live_source_init(int argc, char* argv[], CustomData *data, GstElem
}

/* configure source */
if (!vtenc) {
if (vtenc) {
g_object_set(G_OBJECT (source), "is-live", TRUE, NULL);
} else {
g_object_set(G_OBJECT (source), "do-timestamp", TRUE, "device", "/dev/video0", NULL);
}

Expand Down Expand Up @@ -833,6 +855,7 @@ int gstreamer_live_source_init(int argc, char* argv[], CustomData *data, GstElem

/* build the pipeline */
if (!data->h264_stream_supported) {
LOG_DEBUG("Constructing pipeline with encoding element")
gst_bin_add_many(GST_BIN (pipeline), source, video_convert, source_filter, encoder, h264parse, filter,
appsink, NULL);
if (!gst_element_link_many(source, video_convert, source_filter, encoder, h264parse, filter, appsink, NULL)) {
Expand All @@ -841,6 +864,7 @@ int gstreamer_live_source_init(int argc, char* argv[], CustomData *data, GstElem
return 1;
}
} else {
LOG_DEBUG("Constructing pipeline without encoding element")
gst_bin_add_many(GST_BIN (pipeline), source, source_filter, h264parse, filter, appsink, NULL);
if (!gst_element_link_many(source, source_filter, h264parse, filter, appsink, NULL)) {
g_printerr("Elements could not be linked.\n");
Expand Down
32 changes: 28 additions & 4 deletions samples/kvssink_gstreamer_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ static bool format_supported_by_source(GstCaps *src_caps, GstCaps *query_caps, i
static bool resolution_supported(GstCaps *src_caps, GstCaps *query_caps_raw, GstCaps *query_caps_h264,
CustomData &data, int width, int height, int framerate) {
if (query_caps_h264 && format_supported_by_source(src_caps, query_caps_h264, width, height, framerate)) {
LOG_DEBUG("src supports h264")
data.h264_stream_supported = true;
} else if (query_caps_raw && format_supported_by_source(src_caps, query_caps_raw, width, height, framerate)) {
LOG_DEBUG("src supports raw")
data.h264_stream_supported = false;
} else {
return false;
Expand Down Expand Up @@ -340,21 +342,39 @@ int gstreamer_live_source_init(int argc, char *argv[], CustomData *data, GstElem
// Attempt to create vtenc encoder
encoder = gst_element_factory_make("vtenc_h264_hw", "encoder");
if (encoder) {
source = gst_element_factory_make("autovideosrc", "source");
vtenc = true;
source = gst_element_factory_make("videotestsrc", "source");
if (source) {
LOG_DEBUG("Using videotestsrc");
} else {
LOG_ERROR("Failed to create videotestsrc");
}
} else {
// Failed creating vtenc - check pi hardware encoder
encoder = gst_element_factory_make("omxh264enc", "encoder");
if (encoder) {
LOG_DEBUG("Using omxh264enc")
isOnRpi = true;
} else {
// - attempt x264enc
encoder = gst_element_factory_make("x264enc", "encoder");
isOnRpi = false;
encoder = gst_element_factory_make("x264enc", "encoder");
if (encoder) {
LOG_DEBUG("Using x264enc");
} else {
LOG_ERROR("Failed to create x264enc");
}
}
source = gst_element_factory_make("v4l2src", "source");
if (!source) {
if (source) {
LOG_DEBUG("Using v4l2src");
} else {
source = gst_element_factory_make("ksvideosrc", "source");
if (source) {
LOG_DEBUG("Using ksvideosrc");
} else {
LOG_ERROR("Unable to create src element. Tried v4l2src and ksvideosrc");
}
}
vtenc = false;
}
Expand All @@ -365,7 +385,9 @@ int gstreamer_live_source_init(int argc, char *argv[], CustomData *data, GstElem
}

/* configure source */
if (!vtenc) {
if (vtenc) {
g_object_set(G_OBJECT(source), "is-live", TRUE, NULL);
} else {
g_object_set(G_OBJECT(source), "do-timestamp", TRUE, "device", "/dev/video0", NULL);
}

Expand Down Expand Up @@ -482,12 +504,14 @@ int gstreamer_live_source_init(int argc, char *argv[], CustomData *data, GstElem
if (!data->h264_stream_supported) {
gst_bin_add_many(GST_BIN(pipeline), source, video_convert, source_filter, encoder, h264parse, filter,
kvssink, NULL);
LOG_DEBUG("Constructing pipeline with encoding element")
if (!gst_element_link_many(source, video_convert, source_filter, encoder, h264parse, filter, kvssink, NULL)) {
g_printerr("Elements could not be linked.\n");
gst_object_unref(pipeline);
return 1;
}
} else {
LOG_DEBUG("Constructing pipeline without encoding element")
gst_bin_add_many(GST_BIN(pipeline), source, source_filter, h264parse, filter, kvssink, NULL);
if (!gst_element_link_many(source, source_filter, h264parse, filter, kvssink, NULL)) {
g_printerr("Elements could not be linked.\n");
Expand Down