Guest User

Untitled

a guest
Sep 30th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1.  
  2. # create a pipeline
  3. self.pipeline = Gst.parse_launch('rtspsrc name=source  latency=150  !  rtph264depay name=demux !  tee name=fork fork. ! queue name=delay ! mpegtsmux name=mux  ! tcpserversink host=0.0.0.0 port=0 name=stream timeout=4000000000  fork. ! queue ! h264parse !  matroskamux !  multifilesink name=persist aggregate-gops=true   post-messages=true next-file=5')
  4.  
  5. # find key elements and set properties done in separate function, returns pipeline or None if error.
  6.  
  7. source = pipeline.get_by_name('source')
  8. demux = pipeline.get_by_name('demux')
  9. mux = pipeline.get_by_name('mux')
  10. pers_sink = pipeline.get_by_name('persist')
  11. stream_sink = pipeline.get_by_name('stream')
  12.        
  13. os.makedirs(self.tempdir)
  14.        
  15. tlocation = os.path.join(self.tempdir,'%05d')
  16.    
  17. if username and password:
  18.     source.set_property('user-id', username)
  19.     source.set_property('user-pw', password)
  20.        
  21.    
  22. source.set_property('location',location)
  23. pers_sink.set_property('location',tlocation)
  24.  
  25.  
  26.  
  27. #setup message bus and start the pipeline
  28. self.bus = self.pipeline.get_bus()
  29. self.bus.add_signal_watch()
  30. self.bus.connect('message',self.message_handler)
  31. self.sink = self.pipeline.get_by_name('stream')
  32. self.writer = self.pipeline.get_by_name('persist')
  33. self.sink.connect('client-added',self.add_client)
  34. self.sink.connect('client-socket-removed', self.remove_client)
  35. self.pipeline.set_state(Gst.State.READY)
  36. self.pipeline.get_state(1*Gst.SECOND)
  37. self.port = self.sink.get_property('current-port')
  38. self.http_type = self.get_http_content_type(self.mux_type)
  39. self.pipeline.set_state(Gst.State.PLAYING)
  40. self.mainloop.run()
  41.  
  42. # Free the pipeline on eos, error on when requested. Done in kill() and __del__
  43.  
  44. if self.pipeline:
  45.     self.sink.emit('clear')
  46.     self.bus.remove_signal_watch()
  47.     name = self.pipeline.get_property('name')
  48.     self.pipeline.set_state(Gst.State.NULL)
  49.     state = self.pipeline.get_state(timeout=1*Gst.SECOND)
  50.     while state[1] != Gst.State.NULL:
  51.         self.sink.emit('clear')
  52.         state = self.pipeline.get_state(timeout=1*Gst.SECOND)
  53.    
  54.     self.mainloop.quit()
Advertisement
Add Comment
Please, Sign In to add comment