Esempio n. 1
0
    def __init__(self, e_emitter, room_id):

        self.em = e_emitter
        self.setup_events()

        self.pipeline = None
        self.config = None
        self.webrtcbin = None
        self.preview_sink = None
        self.benchmark = None
        self.benchmark_started = False
        self.benchmark_mode = False
        self.decoding_errors = 0
        self.chance_of_dropping_packets = 0.00
        self.network_filter = ""
        self.benchmark_duration = None
        self.network_throttle_thread = threading.Thread(
            target=self.start_traffic_control)
        self.network_throttle_thread.daemon = True
        self.room_id = room_id

        Gst.debug_add_log_function(self.handle_gst_log_message)

        print("Creating Receiver")
        self.connection = SignallingServerConnection("receiver", "sender",
                                                     "wss://localhost:8443",
                                                     self.room_id,
                                                     self.msg_handler)

        # needed because run in extra thread
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        loop.run_until_complete(self.connection.connect())
        loop.run_until_complete(self.connection.loop())
Esempio n. 2
0
 def run_recorder(self):
     try:
         signal.signal(signal.SIGINT, self.stop_pipeline)
         signal.signal(signal.SIGTERM, self.stop_pipeline)
         Gst.init(None)
         Gst.debug_add_log_function(self.on_debug, None)
         Gst.debug_remove_log_function(None)
         self.loop = GLib.MainLoop()
         while not self.exit:
             segment_path = os.path.join(self.base_path, self.broadcastday,
                                         "segment_%05d.ts")
             if not os.path.exists(os.path.dirname(segment_path)):
                 os.makedirs(os.path.dirname(segment_path))
             if os.path.isfile(
                     os.path.join(os.path.dirname(segment_path),
                                  "playlist.m3u8")):
                 self.playlist = m3u8.load(
                     os.path.join(os.path.dirname(segment_path),
                                  "playlist.m3u8"))
                 self.insertdiscontinuity = True
                 start_index = int(self.playlist.segments[-1].uri[-8:-3]
                                   ) + 2  #get the index from the filename
             else:
                 self.playlist = m3u8.M3U8()
                 self.playlist.version = "3"
                 self.playlist.is_endlist = False
                 start_index = 0
             command = self.pipeline_desc.format(loc=segment_path,
                                                 index=start_index)
             logger.info("Saving segments to:{}".format(segment_path))
             self.pipeline = Gst.parse_launch(command)
             if not self.pipeline:
                 logger.error(
                     "Couldn't create pipeline for recorder:{}".format(
                         command))
                 return
             bus = self.pipeline.get_bus()
             bus.add_signal_watch()
             bus.connect("message", self.bus_callback)
             bus.connect("message::element", self.on_element_message)
             self.pipeline.set_state(Gst.State.PLAYING)
             self.loop.run()
             self.pipeline.set_state(Gst.State.NULL)
     except Exception as e:
         logger.error('Encoding failed: ' + str(e))
     logger.info("Setting pipline to NULL.")
     self.pipeline.set_state(Gst.State.NULL)