gst-rtsp-server: update python bindings
authorAndré Dieb Martins <andre.dieb@gmail.com>
Tue, 21 Sep 2010 20:04:02 +0000 (17:04 -0300)
committerWim Taymans <wim.taymans@collabora.co.uk>
Wed, 12 Jan 2011 15:31:26 +0000 (16:31 +0100)
bindings/python/rtspserver-types.defs
bindings/python/rtspserver.defs
bindings/python/rtspserver.override
bindings/python/test.py [new file with mode: 0644]

index 133ed8f..04949af 100644 (file)
@@ -1,6 +1,63 @@
+;; From gst/rtsp-server/rtsp-server.h
+
 (define-object Server
   (in-module "Gst.RTSPServer")
   (parent "GObject")
   (c-name "GstRTSPServer")
   (gtype-id "GST_TYPE_RTSP_SERVER")
 )
+
+;; From gst/rtsp-server/rtsp-media-mapping.h
+
+(define-object MediaMapping
+  (in-module "Gst.RTSPServer")
+  (parent "GObject")
+  (c-name "GstRTSPMediaMapping")
+  (gtype-id "GST_TYPE_RTSP_MEDIA_MAPPING")
+)
+
+;; From gst/rtsp-server/rtsp-media-factory.h
+
+(define-object MediaFactory
+  (in-module "Gst.RTSPServer")
+  (parent "GObject")
+  (c-name "GstRTSPMediaFactory")
+  (gtype-id "GST_TYPE_RTSP_MEDIA_FACTORY")
+)
+
+;; From gst/rtsp-server/rtsp-media.h
+
+(define-object Media
+  (in-module "Gst.RTSPServer")
+  (parent "GObject")
+  (c-name "GstRTSPMedia")
+  (gtype-id "GST_TYPE_RTSP_MEDIA")
+)
+
+;; From gst/rtsp-server/rtsp-session-pool.h
+
+(define-object SessionPool
+  (in-module "Gst")
+  (parent "GObject")
+  (c-name "GstRTSPSessionPool")
+  (gtype-id "GST_TYPE_RTSP_SESSION_POOL")
+)
+
+;; From gst/rtsp-server/rtsp-session.h
+
+(define-object Session
+  (in-module "Gst")
+  (parent "GObject")
+  (c-name "GstRTSPSession")
+  (gtype-id "GST_TYPE_RTSP_SESSION")
+)
+
+;; From gst/rtsp-server/rtsp-client.h
+
+(define-object Client
+  (in-module "Gst")
+  (parent "GObject")
+  (c-name "GstRTSPClient")
+  (gtype-id "GST_TYPE_RTSP_CLIENT")
+)
+
index 4442f9f..25d190b 100644 (file)
@@ -1,11 +1,99 @@
 (include "rtspserver-types.defs")
 
+;; From gst/rtsp-server/rtsp-server.h
+
 (define-function rtsp_server_new
   (c-name "gst_rtsp_server_new")
   (is-constructor-of "GstRTSPServer")
   (return-type "GstRTSPServer*")
 )
 
+(define-method set_address
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_set_address")
+  (parameters
+    '("const-gchar*" "address")
+  )
+)
+
+(define-method get_address
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_get_address")
+  (return-type "const-gchar*")
+)
+
+(define-method set_service
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_set_service")
+  (parameters
+    '("const-gchar*" "service")
+  )
+)
+
+(define-method get_service
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_get_service")
+  (return-type "const-gchar*")
+)
+
+(define-method set_backlog
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_set_backlog")
+  (parameters
+    '("gint" "backlog")
+  )
+)
+
+(define-method get_backlog
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_get_backlog")
+  (return-type "gint")
+)
+
+(define-method set_session_pool
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_set_session_pool")
+  (parameters
+    '("GstRTSPSessionPool*" "pool")
+  )
+)
+
+(define-method get_session_pool
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_get_session_pool")
+  (return-type "GstRTSPSessionPool*")
+)
+
+(define-method set_media_mapping
+ (of-object "GstRTSPServer")
+ (c-name "gst_rtsp_server_set_media_mapping")
+  (parameters
+    '("GstRTSPMediaMapping*" "mapping")
+  )
+)
+
+(define-method get_media_mapping
+ (of-object "GstRTSPServer")
+ (c-name "gst_rtsp_server_get_media_mapping")
+ (return-type "GstRTSPMediaMapping*")
+)
+
+(define-function io_func
+ (c-name "gst_rtsp_server_io_func")
+ (return-type "gboolean")
+  (parameters
+    '("GIOChannel*" "channel")
+    '("GIOCondition" "condition")
+    '("GstRTSPServer*" "server")
+  )
+)
+
+(define-method get_io_channel
+ (of-object "GstRTSPServer")
+ (c-name "gst_rtsp_server_get_io_channel")
+ (return-type "GIOChannel*")
+)
+
 (define-method attach
   (of-object "GstRTSPServer")
   (c-name "gst_rtsp_server_attach")
     '("GMainContext*" "context")
   )
 )
+
+(define-method create_watch
+  (of-object "GstRTSPServer")
+  (c-name "gst_rtsp_server_create_watch")
+  (return-type "GSource*")
+)
+
+;; From gst/rtsp-server/rtsp-media-mapping.h
+
+(define-function rtsp_media_mapping_new
+  (c-name "gst_rtsp_media_mapping_new")
+  (is-constructor-of "GstRTSPMediaMapping")
+  (return-type "GstRTSPMediaMapping*")
+)
+
+
+;; TODO define const-GstRTSPUrl* on arg-types.py
+(define-method find_factory
+  (of-object "GstRTSPMediaMapping")
+  (c-name "gst_rtsp_media_mapping_find_factory")
+  (return-type "GstRTSPMediaFactory*")
+  (parameters
+   '("const-GstRTSPUrl*" "url")
+  )
+)
+
+(define-method add_factory
+  (of-object "GstRTSPMediaMapping")
+  (c-name "gst_rtsp_media_mapping_add_factory")
+  (parameters
+   '("const-gchar*" "path")
+   '("GstRTSPMediaFactory*" "factory")
+  )
+)
+
+(define-method remove_factory
+  (of-object "GstRTSPMediaMapping")
+  (c-name "gst_rtsp_media_mapping_remove_factory")
+  (parameters
+   '("const-gchar*" "path")
+  )
+)
+
+;; From gst/rtsp-server/rtsp-media-factory.h
+
+(define-function rtsp_media_factory_new
+  (c-name "gst_rtsp_media_factory_new")
+  (is-constructor-of "GstRTSMediaFactory")
+  (return-type "GstRTSPMediaFactory*")
+)
+
+(define-method set_launch
+  (of-object "GstRTSPMediaFactory")
+  (c-name "gst_rtsp_media_factory_set_launch")
+  (parameters
+   '("gchar*" "launch")
+  )
+)
+
+(define-method get_launch
+  (of-object "GstRTSPMediaFactory")
+  (c-name "gst_rtsp_media_factory_get_launch")
+  (return-type "gchar*")
+)
+
+(define-method set_shared
+  (of-object "GstRTSPMediaFactory")
+  (c-name "gst_rtsp_media_factory_set_shared")
+  (parameters
+   '("gboolean" "shared")
+  )
+)
+
+(define-method is_shared
+  (of-object "GstRTSPMediaFactory")
+  (c-name "gst_rtsp_media_factory_is_shared")
+  (return-type "gboolean")
+)
+
+(define-method set_eos_shutdown
+  (of-object "GstRTSPMediaFactory")
+  (c-name "gst_rtsp_media_factory_set_eos_shutdown")
+  (parameters
+   '("gboolean" "eos_shutdown")
+  )
+)
+
+(define-method is_eos_shutdown
+  (of-object "GstRTSPMediaFactory")
+  (c-name "gst_rtsp_media_factory_is_eos_shutdown")
+  (return-type "gboolean")
+)
+
+;; TODO define const-GstRTSPUrl* on arg-types.py
+(define-method construct
+  (of-object "GstRTSPMediaFactory")
+  (c-name "gst_rtsp_media_factory_construct")
+  (return-type "GstRTSPMedia*")
+  (parameters
+   '("const-GstRTSPUrl*" "url")
+  )
+)
+
+(define-method collect_streams
+  (of-object "GstRTSPMediaFactory")
+  (c-name "gst_rtsp_media_factory_construct")
+  (parameters
+   '("const-GstRTSPUrl*" "url")
+   '("GstRTSPMedia*" "media")
+  )
+)
+
+;; From gst/rtsp-server/rtsp-session-pool.h
+
+(define-function gst_rtsp_session_pool_new
+  (c-name "gst_rtsp_session_pool_new")
+  (is-constructor-of "GstRTSPSessionPool")
+  (return-type "GstRTSPSessionPool*")
+)
+
+(define-method set_max_sessions
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_set_max_sessions")
+  (return-type "none")
+  (parameters
+    '("guint" "max")
+  )
+)
+
+(define-method get_max_sessions
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_get_max_sessions")
+  (return-type "guint")
+)
+
+(define-method get_n_sessions
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_get_n_sessions")
+  (return-type "guint")
+)
+
+(define-method create
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_create")
+  (return-type "GstRTSPSession*")
+)
+
+(define-method find
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_find")
+  (return-type "GstRTSPSession*")
+  (parameters
+    '("const-gchar*" "sessionid")
+  )
+)
+
+(define-method remove
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_remove")
+  (return-type "gboolean")
+  (parameters
+    '("GstRTSPSession*" "sess")
+  )
+)
+
+(define-method filter
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_filter")
+  (return-type "GList*")
+  (parameters
+    '("GstRTSPSessionFilterFunc" "func")
+    '("gpointer" "user_data")
+  )
+)
+
+(define-method cleanup
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_cleanup")
+  (return-type "guint")
+)
+
+(define-method create_watch
+  (of-object "GstRTSPSessionPool")
+  (c-name "gst_rtsp_session_pool_create_watch")
+  (return-type "GSource*")
+)
+
+;; From gst/rtsp-server/rtsp-client.h
+
+(define-function gst_rtsp_client_new
+  (c-name "gst_rtsp_client_new")
+  (is-constructor-of "GstRTSPClient")
+  (return-type "GstRTSPClient*")
+)
+
+(define-method set_session_pool
+  (of-object "GstRTSPClient")
+  (c-name "gst_rtsp_client_set_session_pool")
+  (return-type "none")
+  (parameters
+    '("GstRTSPSessionPool*" "pool")
+  )
+)
+
+(define-method get_session_pool
+  (of-object "GstRTSPClient")
+  (c-name "gst_rtsp_client_get_session_pool")
+  (return-type "GstRTSPSessionPool*")
+)
+
+(define-method set_media_mapping
+  (of-object "GstRTSPClient")
+  (c-name "gst_rtsp_client_set_media_mapping")
+  (return-type "none")
+  (parameters
+    '("GstRTSPMediaMapping*" "mapping")
+  )
+)
+
+(define-method get_media_mapping
+  (of-object "GstRTSPClient")
+  (c-name "gst_rtsp_client_get_media_mapping")
+  (return-type "GstRTSPMediaMapping*")
+)
+
+(define-method accept
+  (of-object "GstRTSPClient")
+  (c-name "gst_rtsp_client_accept")
+  (return-type "gboolean")
+  (parameters
+    '("GIOChannel*" "channel")
+  )
+)
+
+;; From bindings/python/rtsp-params.h
+
+(define-function gst_rtsp_params_set
+  (c-name "gst_rtsp_params_set")
+  (return-type "GstRTSPResult")
+  (parameters
+    '("GstRTSPClient*" "client")
+    '("GstRTSPUrl*" "uri")
+    '("GstRTSPSession*" "session")
+    '("GstRTSPMessage*" "request")
+    '("GstRTSPMessage*" "response")
+  )
+)
+
+(define-function gst_rtsp_params_get
+  (c-name "gst_rtsp_params_get")
+  (return-type "GstRTSPResult")
+  (parameters
+    '("GstRTSPClient*" "client")
+    '("GstRTSPUrl*" "uri")
+    '("GstRTSPSession*" "session")
+    '("GstRTSPMessage*" "request")
+    '("GstRTSPMessage*" "response")
+  )
+)
index 3cab9d6..eda93e8 100644 (file)
@@ -5,6 +5,11 @@ headers
 #define NO_IMPORT_PYGOBJECT
 #include <pygobject.h>
 
+#include <gst/gst.h>
+#include <gst/rtsp-server/rtsp-server.h>
+
+#include <glib.h>
+
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
@@ -24,29 +29,39 @@ typedef struct {
 %%
 import gobject.GObject as PyGObject_Type
 import gobject.MainContext as PyGMainContext_Type
-
 %%
 override gst_rtsp_server_attach kwargs
 static PyObject *
 _wrap_gst_rtsp_server_attach (PyGObject *self,
-               PyObject *args, PyObject *keywords)
+    PyObject *args, PyObject *keywords)
 {
-       static char *kwlist[] = {"context", NULL};
-       PyGMainContext *py_context = NULL;
-       GMainContext *context = NULL;
-       guint res;
+  static char *kwlist[] = {"context", NULL};
+  PyGMainContext *py_context = NULL;
+  GMainContext *context = NULL;
+  guint res;
 
-       if (!PyArg_ParseTupleAndKeywords (args, keywords,
-                       "|O!:GstRTSPServer.__init__", kwlist,
-                       &PyGMainContext_Type, &py_context))
-               return NULL;
+  if (!PyArg_ParseTupleAndKeywords (args, keywords,
+      "|O!:GstRTSPServer.__init__", kwlist,
+      &PyGMainContext_Type, &py_context))
+    return NULL;
 
-       if (py_context)
-               context = py_context->context;
+  if (py_context)
+    context = py_context->context;
 
-       pyg_begin_allow_threads;
-       res = gst_rtsp_server_attach (GST_RTSP_SERVER (self->obj), context);
-       pyg_end_allow_threads;
+  pyg_begin_allow_threads;
+  res = gst_rtsp_server_attach (GST_RTSP_SERVER (self->obj), context);
+  pyg_end_allow_threads;
 
-       return PyLong_FromLong (res);
+  return PyLong_FromLong (res);
+}
+%%
+override gst_rtsp_server_create_watch kwargs
+static PyObject *
+_wrap_gst_rtsp_server_create_watch(PyGObject *self, PyObject *args, PyObject *keywords)
+{
+    GSource *ret;
+    pyg_begin_allow_threads;
+    ret = gst_rtsp_server_create_watch(GST_RTSP_SERVER(self->obj));
+    pyg_end_allow_threads;
+    return pygobject_new((GObject *)ret);
 }
diff --git a/bindings/python/test.py b/bindings/python/test.py
new file mode 100644 (file)
index 0000000..3278faa
--- /dev/null
@@ -0,0 +1,130 @@
+import unittest
+import rtspserver
+
+
+def pubdir(obj):
+    return [d for d in dir(obj) if not d.startswith('_')]
+
+#print 'Module listing:', pubdir(rtspserver)
+
+from rtspserver import Server, SessionPool, Session, MediaMapping, MediaFactory
+
+#print 'Server listing: ', pubdir(Server)
+#print 'MediaMapping listing: ', pubdir(MediaMapping)
+#print 'MediaFactory listing: ', pubdir(MediaFactory)
+#print 'SessionPool listing: ', pubdir(SessionPool)
+#print 'Session listing: ', pubdir(Session)
+
+
+class ServerTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.server = Server()
+
+    def tearDown(self):
+        del self.server
+
+    def test_address(self):
+        """ Server address set/get """
+        addr = '1.2.3.4'
+        self.server.set_address(addr)
+        self.assertEquals(addr, self.server.get_address())
+
+    def test_service(self):
+        """ Server service set/get """
+        service = '12345'
+        self.server.set_service(service)
+        self.assertEquals(service, self.server.get_service())
+
+    def test_backlog(self):
+        """ Server backlog set/get """
+        backlog = 1234
+        self.server.set_backlog(backlog)
+        self.assertEquals(backlog, self.server.get_backlog())
+
+    def test_session_pool(self):
+        """ Server session pool set/get """
+        pool = SessionPool()
+        self.server.set_session_pool(pool)
+        self.assertEquals(pool, self.server.get_session_pool())
+
+    def test_media_mapping(self):
+        """ Server media mapping set/get """
+        mmap = MediaMapping()
+        self.server.set_media_mapping(mmap)
+        self.assertEquals(mmap, self.server.get_media_mapping())
+
+
+class MediaMappingTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.mmap = MediaMapping()
+
+    def tearDown(self):
+        del self.mmap
+
+    def test_factory(self):
+        """ MediaMapping factory add/remove """
+        self.factory = MediaFactory()
+        self.mmap.add_factory("/test", self.factory)
+        self.mmap.remove_factory("/test")
+
+
+class MediaFactoryTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.factory = MediaFactory()
+
+    def tearDown(self):
+        del self.factory
+
+    def test_launch(self):
+        """ MediaFactory launch set/get """
+        launch = "videotestsrc ! xvimagesink"
+        self.factory.set_launch(launch)
+        self.assertEquals(launch, self.factory.get_launch())
+
+    def test_shared(self):
+        """ MediaFactory shared set/is """
+        self.factory.set_shared(True)
+        self.assert_(self.factory.is_shared())
+        self.factory.set_shared(False)
+        self.assert_(not self.factory.is_shared())
+
+    def test_eos_shutdown(self):
+        """ MediaFactory eos_shutdown set/is """
+        self.factory.set_eos_shutdown(True)
+        self.assert_(self.factory.is_eos_shutdown())
+        self.factory.set_eos_shutdown(False)
+        self.assert_(not self.factory.is_eos_shutdown())
+
+
+
+def alltests():
+    tests = []
+
+    for p in dir(ServerTestCase):
+        try:
+            if 'test_' in p:
+                tests.append(ServerTestCase(p))
+        except:
+            pass
+
+    for p in dir(MediaMappingTestCase):
+        try:
+            if 'test_' in p:
+                tests.append(MediaMappingTestCase(p))
+        except:
+            pass
+
+    for p in dir(MediaFactoryTestCase):
+        try:
+            if 'test_' in p:
+                tests.append(MediaFactoryTestCase(p))
+        except:
+            pass
+
+    return unittest.TestSuite(tests)
+
+
+unittest.TextTestRunner(verbosity=2).run(alltests())