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

kvssink - Add Missing Null Checks #1214

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all 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
13 changes: 11 additions & 2 deletions src/gstreamer/gstkvssink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,10 @@ init_track_data(GstKvsSink *kvssink) {
gchar *video_content_type = NULL, *audio_content_type = NULL;
const gchar *media_type;

if (kvssink == NULL || kvssink->collect == NULL || kvssink->data == NULL) {
LOG_AND_THROW("Error initializing track data: kvssink, kvssink->collect, or kvssink->data is NULL.");
}

for (walk = kvssink->collect->data; walk != NULL; walk = g_slist_next (walk)) {
GstKvsSinkTrackData *kvs_sink_track_data = (GstKvsSinkTrackData *) walk->data;

Expand All @@ -1505,6 +1509,11 @@ init_track_data(GstKvsSink *kvssink) {

// extract media type from GstCaps to check whether it's h264 or h265
caps = gst_pad_get_allowed_caps(collect_data->pad);

if (caps == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we print caps and also check non empty?

LOG_AND_THROW("Error, GStreamer pad returned NULL caps. Pad has no peer for stream: " << kvssink->stream_name);
}

media_type = gst_structure_get_name(gst_caps_get_structure(caps, 0));
if (strncmp(media_type, GSTREAMER_MEDIA_TYPE_H264, MAX_GSTREAMER_MEDIA_TYPE_LEN) == 0) {
// default codec id is for h264 video.
Expand All @@ -1515,7 +1524,7 @@ init_track_data(GstKvsSink *kvssink) {
video_content_type = g_strdup(MKV_H265_CONTENT_TYPE);
} else {
// no-op, should result in a caps negotiation error before getting here.
LOG_AND_THROW("Error, media type " << media_type << "not accepted by kvssink" << " for " << kvssink->stream_name);
LOG_AND_THROW("Error, media type " << media_type << " not accepted by kvssink" << " for " << kvssink->stream_name);
}
gst_caps_unref(caps);

Expand Down Expand Up @@ -1666,4 +1675,4 @@ GST_PLUGIN_DEFINE (
"Proprietary",
"GStreamer",
"http://gstreamer.net/"
)
)
Loading