python: Can't set RTSPContext properties (like the current token)
When trying to implement custom authentication on gst-rtsp-server
from Python, it is not possible to set the token property in the RTSPContext. I believe this is because Python has no access to properly set properties on the GstRTSPContext
struct.
The error output is:
Traceback (most recent call last):
File "test-auth.py", line 27, in do_authenticate
context.token = self.get_default_token()
RuntimeError: unable to set value for field
I could work around this by overriding the check method too, but I'd rather use GStreamer's built in default check.
Sample code (fails assigning the default token):
#!/usr/bin/env python
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GstRtsp, GLib
loop = GLib.MainLoop()
Gst.init(None)
class MyAuth(GstRtspServer.RTSPAuth):
def __init__(self):
GstRtspServer.RTSPAuth.__init__(self)
anonymous = GstRtspServer.RTSPToken()
anonymous.set_string(GstRtspServer.RTSP_TOKEN_MEDIA_FACTORY_ROLE, "anonymous")
self.set_default_token(anonymous)
def get_supported_methods(self):
return GstRtsp.RTSPAuthMethod.BASIC
def do_authenticate(self, context):
# Fails to assign
context.token = self.get_default_token()
return True
class MyFactory(GstRtspServer.RTSPMediaFactory):
def __init__(self):
GstRtspServer.RTSPMediaFactory.__init__(self)
def do_create_element(self, url):
input_str = "videotestsrc is-live=true ! x264enc"
pipeline_str = " {input_str} ! rtph264pay name=pay0 pt=96".format(**locals())
print(pipeline_str)
return Gst.parse_launch(pipeline_str)
class GstServer():
def __init__(self):
self.server = GstRtspServer.RTSPServer()
self.auth = MyAuth()
self.server.set_auth(self.auth)
f = MyFactory()
f.set_shared(True)
m = self.server.get_mount_points()
m.add_factory("/test", f)
self.server.attach(None)
print(self.server.get_bound_port())
if __name__ == '__main__':
s = GstServer()
loop.run()
The PyGI say the property is r/w, so to enable this do we need to build an override into gst-python or perhaps add a method to rtsp-context.c
to enable setting the property?