Ejemplo n.º 1
0
    def createLiveContext(self):
        """Creates a LiveConnectionContext and registers it to LiveThread
        """
        self.ctx = core.LiveConnectionContext()
        self.ctx.slot = self.slot

        if (self.address.find("rtsp://") == 0):
            self.ctx.connection_type = core.LiveConnectionType_rtsp
        else:
            self.ctx.connection_type = core.LiveConnectionType_sdp

        self.ctx.address = self.address
        self.ctx.framefilter = self.fork  # writes to self.fork
        self.ctx.msreconnect = self.msreconnect

        # some extra parameters
        """
        ctx.time_correction =TimeCorrectionType::none;
        ctx.time_correction =TimeCorrectionType::dummy;
        default time correction is smart
        ctx.recv_buffer_size=1024*1024*2;  // Operating system ringbuffer size for incoming socket
        ctx.reordering_time =100000;       // Live555 packet reordering treshold time (microsecs)
        """
        if (self.time_correction is not None):
            self.ctx.time_correction = self.time_correction
        self.ctx.recv_buffer_size = self.recv_buffer_size
        self.ctx.reordering_time = self.reordering_mstime * 1000  # from millisecs to microsecs

        # send the information about the stream to LiveThread
        self.livethread.registerStream(self.ctx)
        self.livethread.playStream(self.ctx)
Ejemplo n.º 2
0
 def createContext(self):
   """Creates a LiveConnectionContext and registers it to LiveThread
   """
   # define stream source, how the stream is passed on, etc.
   
   self.ctx=core.LiveConnectionContext()
   self.ctx.slot=self.slot                          # slot number identifies the stream source
   
   if (self.address.find("rtsp://")==0):
     self.ctx.connection_type=core.LiveConnectionType_rtsp
   else:
     self.ctx.connection_type=core.LiveConnectionType_sdp # this is an rtsp connection
   
   self.ctx.address=self.address         
   # stream address, i.e. "rtsp://.."
   
   self.ctx.framefilter=self.av_in_filter
   
   self.ctx.msreconnect=self.msreconnect
   
   # some extra parameters
   """
   // ctx.time_correction =TimeCorrectionType::none;
   // ctx.time_correction =TimeCorrectionType::dummy;
   // default time correction is smart
   // ctx.recv_buffer_size=1024*1024*2;  // Operating system ringbuffer size for incoming socket
   // ctx.reordering_time =100000;       // Live555 packet reordering treshold time (microsecs)
   """
   if (self.time_correction!=None): self.ctx.time_correction =self.time_correction
   self.ctx.recv_buffer_size =self.recv_buffer_size
   self.ctx.reordering_time  =self.reordering_mstime*1000 # from millisecs to microsecs
   
   # send the information about the stream to LiveThread
   self.livethread.registerStream(self.ctx)
   self.livethread.playStream(self.ctx)
Ejemplo n.º 3
0
    def createLiveContext(self):
        """Context for LiveThread
        
        Creates & registers a context to LiveThread and connects it to the main filterchain
        
        Parameters required:
        
        ::
        
            self.slot
            self.address
            self.msreconnect
            
            self.time_correction
            self.recv_buffer_size
            self.reordering_mstime
        """
        
        self.ctx = core.LiveConnectionContext()
        self.ctx.slot = self.slot

        if (self.address.find("rtsp://") == 0):
            self.ctx.connection_type = core.LiveConnectionType_rtsp # rtsp connection
        else:
            self.ctx.connection_type = core.LiveConnectionType_sdp  # an sdp file

        if (self.request_tcp):
            self.ctx.request_tcp = self.request_tcp

        self.ctx.address = self.address
        # stream address, i.e. "rtsp://.."
        self.ctx.msreconnect = self.msreconnect
        
        self.ctx.recv_buffer_size = self.recv_buffer_size
        self.ctx.reordering_time = self.reordering_mstime * 1000  # from millisecs to microsecs

        self.ctx.time_correction = self.time_correction
        if self.ctx.time_correction == core.TimeCorrectionType_smart:
            print("createLiveContext: smart timestamps")
        else:
            print("createLiveContext: dummy timestamps")
            

        # connect to the main filterchain
        self.ctx.framefilter = self.fork_filter_main

        # send the information about the stream to LiveThread
        self.livethread.registerStream(self.ctx)
        self.livethread.playStream(self.ctx)
Ejemplo n.º 4
0
    def createContext(self):
        """
        Creates a LiveConnectionContext and registers it to LiveThread
        """

        # Define the stream source, how the stream is passed on, etc
        self.ctx = core.LiveConnectionContext()
        # slot number identifies the stream source
        self.ctx.slot = self.slot

        if (self.address.find("rtsp://")) == 0:
            self.ctx.connection_type = core.LiveConnectionType_rtsp
        else:
            self.ctx.connection_type = core.LiveConnectionType_sdp

        self.ctx.address = self.address

        self.ctx.framefilter = self.fork_filter
        self.ctx.msreconnect = self.msreconnect

        # some extra parameters
        """
        // ctx.time_correction =TimeCorrectionType::none;
        // ctx.time_correction =TimeCorrectionType::dummy;
        // default time correction is smart
        // ctx.recv_buffer_size=1024*1024*2;  // Operating system ringbuffer size for incoming socket
        // ctx.reordering_time =100000;       // Live555 packet reordering treshold time (microsecs)
        """

        if (self.time_correction is not None):
            self.ctx.time_correction = self.time_correction
        # self.time_correction = core.TimeCorrectionType_smart # default
        self.ctx.recv_buffer_size = self.recv_buffer_size
        self.ctx.reordering_time = self.reordering_mstime * 1000

        # send information about the stream to livethread
        self.livethread.registerStream(self.ctx)
        self.livethread.playStream(self.ctx)
        self.mux_filter.activate()
Ejemplo n.º 5
0
    def createContext(self):
        """Creates a LiveConnectionContext and registers it to LiveThread.
    """
        # define stream source, how the stream is passed on, etc.

        self.ctx = core.LiveConnectionContext()
        self.ctx.slot = self.slot  # slot number identifies the stream source

        if (self.address.find("rtsp://") == 0):
            self.ctx.connection_type = core.LiveConnectionType_rtsp
        else:
            self.ctx.connection_type = core.LiveConnectionType_sdp  # this is an rtsp connection

        self.ctx.address = self.address
        # stream address, i.e. "rtsp://.."

        self.ctx.framefilter = self.fork

        self.ctx.msreconnect = self.msreconnect

        # send the information about the stream to LiveThread
        self.incoming_livethread.registerStream(self.ctx)
        self.incoming_livethread.playStream(self.ctx)
Ejemplo n.º 6
0
 def setLiveContext(self,address):
   """
   The user is responsible for:
   
   self.livethread.registerStream(self.ctx)
   self.livethread.playStream(self.ctx)
   self.livethread.stopStream(self.ctx)
   self.livethread.deregisterStream(self.ctx)
   """
   
   self.live_ctx=core.LiveConnectionContext()
   self.live_ctx.slot=self.slot                          # slot number identifies the stream source
   
   if (address.find("rtsp://")==0):
     self.live_ctx.connection_type=core.LiveConnectionType_rtsp
   else:
     self.live_ctx.connection_type=core.LiveConnectionType_sdp # this is an rtsp connection
   
   self.live_ctx.address=address         
   # stream address, i.e. "rtsp://.."
   
   self.live_ctx.framefilter=self.av_in_filter
   
   self.live_ctx.msreconnect=self.msreconnect # if no frames received in this time, attempt to reconnect
Ejemplo n.º 7
0
print("   Core loaded from ", core.__file__)
"""Test instantiation of some objects
"""
print()
print("   Testing Valkka classes")
live = core.LiveThread("live")
# inp  =core.FrameFifo("fifo") # in the API no more
# ff   =core.FifoFrameFilter("fifo",inp)
out = core.DummyFrameFilter("dummy")
av = core.AVThread("av", out)
gl = core.OpenGLThread("gl")

av_in = av.getFrameFilter()
gl_in = gl.getFrameFilter()

ctx = core.LiveConnectionContext()
ctx.slot = 1
ctx.connection_type = core.LiveConnectionType_rtsp
ctx.address = "rtsp://*****:*****@192.168.0.157"
ctx2 = core.LiveConnectionContext(core.LiveConnectionType_rtsp,
                                  "rtsp://*****:*****@192.168.0.157", 1, out)
print("   Valkka classes ok")
print()

# this is modified automatically by setver.bash - don't touch!
VERSION_MAJOR = 0
VERSION_MINOR = 16
VERSION_PATCH = 0

print("Checking Valkka python examples")
print("   version:",
Ejemplo n.º 8
0
    def __call__(self, livethread=None, openglthread=None):
        """
        Register running live & openglthreads, construct filterchain, start threads

        """
        assert (livethread is not None)
        self.livethread = livethread
        self.openglthread = openglthread

        # Construct Filter graph from end to beginning
        # Main branch
        self.main_fork = core.ForkFrameFilterN("main_fork" + str(self.slot))

        # connect livethread to main branch
        self.live_ctx = core.LiveConnectionContext(
            core.LiveConnectionType_rtsp, self.rtsp_address, self.slot,
            self.main_fork)  # stream rights to main_fork

        # Some aditional parameters you can give to livethread streaming context
        ## 1 : for NATs and Streaming over the internet, use tcp streaming
        self.live_ctx.request_tcp = True
        ## 2 : if you don't have enough buffering or timestamps are wrong, use this:
        # self.live_ctx.time_correction = core.TimeCorrectionType_smart
        ## 3 : enable automatic reconnection every 10 seconds if camera is offline
        self.live_ctx.mstimeout = 10000

        self.livethread.registerStreamCall(self.live_ctx)

        # Branch B : Mux Branch
        self.fmp4_shmem = core.FragMP4ShmemFrameFilter(
            self.fmp4_shmem_name, self.fmp4_shmem_buffers,
            self.fmp4_shmem_cellsize)
        print(">", self.fmp4_sync_event)
        self.fmp4_shmem.useFd(self.fmp4_sync_event)
        self.fmp4_muxer = core.FragMP4MuxFrameFilter("mp4_muxer",
                                                     self.fmp4_shmem)
        # self.fmp4_muxer.activate()
        # connect main branch to mux branch
        self.main_fork.connect("fragmp4_terminal" + str(self.slot),
                               self.fmp4_muxer)
        # muxer must be connected from the very beginning so that it receives setupframes, sent only in the beginning of streaming process

        # Branch A : Decoding Branch
        self.decode_fork = core.ForkFrameFilterN("decode_fork_" +
                                                 str(self.slot))
        self.avthread = core.AVThread(
            "avthread_" + str(self.slot),
            self.decode_fork)  # Here avthread feeds decode_fork
        # connect main branch to avthread to decode_fork
        self.avthread_in_filter = self.avthread.getFrameFilter()
        self.main_fork.connect("decoder_" + str(self.slot),
                               self.avthread_in_filter)

        # Branch A : Sub_Branch_A.1 : RGB shared memory
        self.rgb_shmem_filter = core.RGBShmemFrameFilter(
            self.rgb_shmem_name, self.rgb_shmem_buffers, self.width,
            self.height)
        self.rgb_shmem_filter.useFd(self.rgb_sync_event)
        self.sws_filter = core.SwScaleFrameFilter("sws_filter", self.width,
                                                  self.height,
                                                  self.rgb_shmem_filter)
        self.interval_filter = core.TimeIntervalFrameFilter(
            "interval_filter", self.image_interval, self.sws_filter)
        self.decode_fork.connect("rgb_shmem_terminal" + str(self.slot),
                                 self.interval_filter)

        # Branch A : Sub_Branch_A.2 : OpenGl branch Displaying
        if self.openglthread is not None:
            # connect decode frames in opengl
            self.opengl_input_filter = self.openglthread.getFrameFilter()
            self.decode_fork.connect("gl_terminal" + str(self.slot),
                                     self.opengl_input_filter)
            # Create X window
            #
            # win_id = self.openglthread.createWindow(show=False)
            # frame = QtFrame(self.widget, win_id)
            # self.lay.addWidget(frame.widget, 0, 0)
            #
            # token = self.openglthread.connect(slot=self.slot, window_id=win_id)
            # if token == 0:
            #     print("mapping failled  ! ")
            # else:
            #     print("mapping done ! ")
            self.window_id = self.openglthread.createWindow()
            self.openglthread.newRenderGroupCall(self.window_id)

            self.context_id = self.openglthread.newRenderContextCall(
                self.slot, self.window_id, 0)

        self.livethread.playStreamCall(self.live_ctx)
        self.avthread.startCall()
        self.avthread.decodingOnCall()