multifdsink/fdsrc from python socket ?

Adrien Aubourg adrien.aubourg at gmail.com
Mon Mar 31 00:52:10 PDT 2014


Oups, attachments do not work here...
So as I said, if I add anything between fdsrc and filesink (or imagesink for
instance), no buffer is received from fdsrc.

Here is the client script:
https://gist.github.com/Vagdish/9886296

And the server script:
https://gist.github.com/Vagdish/9886291

Let me copy/paste them here:

#### client.py ####

#!/usr/bin/python3

import asyncio, threading
from gi.repository import GObject, Gst

connList = {}

def createPipeline(conn):
    """ Function doc """
    print('creating pipe')
    print('sockno: {}'.format(connList[conn]))
    pipe = Gst.Pipeline()
    src = Gst.ElementFactory.make('fdsrc', None)
    sink = Gst.ElementFactory.make('filesink', None)
    sink.set_property('location', 'test')
    pipe.add(src)
    pipe.add(sink)
    src.link(sink)
    src.set_property('fd', connList[conn])
    pipe.set_state(Gst.State.PLAYING)

class EchoClient(asyncio.Protocol):
    
    def __init__(self):
        """ Function doc """
        super().__init__()

    def connection_made(self, transport):
        print('connection made:
{}'.format(transport.get_extra_info('peername')))
        print('creating pipeline')
        connList[self] = transport.get_extra_info('socket').fileno()
        createPipeline(self)

    def connection_lost(self, exc):
        print('server closed the connection')
        del connList[self]
        asyncio.get_event_loop().stop()
        
    def data_received(self, data):
        print(len(data))


if __name__ == "__main__":
    GObject.threads_init()
    Gst.init(None)
    gstThread = threading.Thread(target=GObject.MainLoop().run, daemon=True)
    gstThread.start()
    
    mainLoop = asyncio.get_event_loop()
    coro = mainLoop.create_connection(EchoClient, '127.0.0.1', 12000)
    mainLoop.run_until_complete(coro)
    mainLoop.run_forever()
    mainLoop.close()


#### server.py ####

#!/usr/bin/python3

import asyncio, threading
from gi.repository import GObject, Gst

DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 12000

connList = {}

def createPipeline(conn):
    """ Function doc """
    print('creating pipe')
    print('sockno: {}'.format(connList[conn]))
    pipe = Gst.Pipeline()
    src = Gst.ElementFactory.make('videotestsrc', None)
    src.set_property('horizontal-speed', 2)
    sink = Gst.ElementFactory.make('multifdsink', None)
    sink.set_property('sync-method',0)
    pipe.add(src)
    pipe.add(sink)
    src.link(sink)
    pipe.set_state(Gst.State.READY)
    sink.emit('add', connList[conn])
    pipe.set_state(Gst.State.PLAYING)

class PyVicoServer(asyncio.Protocol):
    """ Class doc """
    
    def __init__(self):
        """ Function doc """
        super().__init__()
        
    def connection_made(self, transport):
        """ Function doc """
        print('new connection from
{}'.format(transport.get_extra_info('peername')))
        connList[self] = transport.get_extra_info('socket').fileno()
        print(connList)
        createPipeline(self)

    def connection_lost(self, info):
        """ Function doc """
        print('lost connection: {}'.format(info))
        del connList[self]
        print(connList)

if __name__ == "__main__":
    GObject.threads_init()
    Gst.init(None)
    gstThread = threading.Thread(target=GObject.MainLoop().run, daemon=True)
    gstThread.start()
    
    mainLoop = asyncio.get_event_loop()
    serverCoroutine = mainLoop.create_server(PyVicoServer, DEFAULT_HOST,
DEFAULT_PORT)
    mainLoop.run_until_complete(serverCoroutine)
    
    try:
        mainLoop.run_forever()
    except KeyboardInterrupt:
        print('exit')
    finally:
        serverCoroutine.close()
        mainLoop.close()




--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/multifdsink-fdsrc-from-python-socket-tp4666205p4666206.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list