This repository has been archived by the owner on Nov 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
srt: add authentication to srtsink and srtsrc elements #6
Open
raghaven447
wants to merge
1
commit into
hwangsaeul:ubuntu/focal
Choose a base branch
from
raghaven447:srt-dev-branch
base: ubuntu/focal
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ enum | |
PROP_STATS, | ||
PROP_WAIT_FOR_CONNECTION, | ||
PROP_STREAMID, | ||
PROP_AUTHENTICATION, | ||
PROP_LAST | ||
}; | ||
|
||
|
@@ -352,6 +353,9 @@ gst_srt_object_set_property_helper (GstSRTObject * srtobject, | |
case PROP_STREAMID: | ||
gst_structure_set_value (srtobject->parameters, "streamid", value); | ||
break; | ||
case PROP_AUTHENTICATION: | ||
srtobject->authentication = g_value_get_boolean (value); | ||
break; | ||
default: | ||
goto err; | ||
} | ||
|
@@ -435,7 +439,10 @@ gst_srt_object_get_property_helper (GstSRTObject * srtobject, | |
g_value_set_string (value, | ||
gst_structure_get_string (srtobject->parameters, "streamid")); | ||
break; | ||
} | ||
} | ||
case PROP_AUTHENTICATION: | ||
g_value_set_boolean (value, srtobject->authentication); | ||
break; | ||
default: | ||
goto err; | ||
} | ||
|
@@ -583,6 +590,22 @@ gst_srt_object_install_properties_helper (GObjectClass * gobject_class) | |
"Stream ID for the SRT access control", "", | ||
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | | ||
G_PARAM_STATIC_STRINGS)); | ||
|
||
/** | ||
* GstSRTSink:authentication: | ||
* | ||
* Boolean to authenticate a connection. If TRUE, | ||
* the incoming connection is authenticated. Else, | ||
* all the connections are accepted. | ||
* | ||
* Since: 1.20 | ||
* | ||
*/ | ||
g_object_class_install_property (gobject_class, PROP_AUTHENTICATION, | ||
g_param_spec_boolean ("authentication", | ||
"Authentication", | ||
"Authenticate a connection", | ||
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | ||
} | ||
|
||
static void | ||
|
@@ -829,6 +852,58 @@ thread_func (gpointer data) | |
} | ||
} | ||
|
||
static GSocketAddress * | ||
peeraddr_to_g_socket_address (const struct sockaddr *peeraddr) | ||
{ | ||
gsize peeraddr_len; | ||
|
||
switch (peeraddr->sa_family) { | ||
case AF_INET: | ||
peeraddr_len = sizeof (struct sockaddr_in); | ||
break; | ||
case AF_INET6: | ||
peeraddr_len = sizeof (struct sockaddr_in6); | ||
break; | ||
default: | ||
g_warning ("Unsupported address family %d", peeraddr->sa_family); | ||
return NULL; | ||
} | ||
return g_socket_address_new_from_native ((gpointer) peeraddr, peeraddr_len); | ||
} | ||
|
||
static gint | ||
srt_listen_callback_func (GstSRTObject * self, SRTSOCKET sock, int hs_version, | ||
const struct sockaddr *peeraddr, const char *stream_id) | ||
{ | ||
g_autoptr (GSocketAddress) addr = peeraddr_to_g_socket_address (peeraddr); | ||
|
||
if (!addr) { | ||
GST_WARNING_OBJECT (self->element, | ||
"Invalid peer address. Rejecting sink %d streamid: %s", sock, | ||
stream_id); | ||
return -1; | ||
} | ||
|
||
if (self->authentication) { | ||
gboolean authenticated = FALSE; | ||
|
||
/* notifying caller-connecting */ | ||
g_signal_emit_by_name (self->element, "caller-connecting", addr, | ||
raghaven447 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stream_id, &authenticated); | ||
|
||
if (!authenticated) | ||
goto reject; | ||
} | ||
|
||
g_debug ("Accepting sink %d streamid: %s", sock, stream_id); | ||
return 0; | ||
reject: | ||
/* notifying caller-rejected */ | ||
g_warning ("Rejecting sink %d streamid: %s", sock, stream_id); | ||
g_signal_emit_by_name (self->element, "caller-rejected"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add some information that identify the rejected caller into the callback. Let's put |
||
return -1; | ||
} | ||
|
||
static gboolean | ||
gst_srt_object_wait_connect (GstSRTObject * srtobject, | ||
GCancellable * cancellable, GSocketFamily sa_family, gpointer sa, | ||
|
@@ -910,10 +985,16 @@ gst_srt_object_wait_connect (GstSRTObject * srtobject, | |
|
||
srtobject->listener_sock = sock; | ||
|
||
/* Register the SRT listen callback */ | ||
if (srt_listen_callback (srtobject->listener_sock, | ||
(srt_listen_callback_fn *) srt_listen_callback_func, srtobject)) { | ||
goto failed; | ||
} | ||
|
||
srtobject->thread = | ||
g_thread_try_new ("GstSRTObjectListener", thread_func, srtobject, error); | ||
|
||
if (*error != NULL) { | ||
if (srtobject->thread == NULL) { | ||
GST_ERROR_OBJECT (srtobject->element, "Failed to start thread"); | ||
goto failed; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at least MSVC doesn't support
g_autoptr
and the like. We couldn't care less for MSVC in Hwangsaeul, but in upstream GStreamer autocleanup is better avoided.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the Hwangsaeul project supports only the Linux platform and the latest GLib, but GStreamer-wise, we should follow their rules.