Beispiel #1
0
    def connect(self):
        if self._enabled:
            _logger.log('Janus: Connecting')

            def _on_error(ws, error):
                _logger.log('Janus Error: %s' % error)

            def _on_message(ws, msg):
                self._process_msg(msg)

            def _on_close(ws):
                _logger.log('Janus: Ws Closed')
                self._callback.disconnected()

            def _on_open(ws):
                _logger.log('Janus: Ws Opened')
                self._create_session()

            try:
                self._ws = websocket.WebSocketApp(
                    self._url,
                    on_open=_on_open,
                    on_message=_on_message,
                    on_close=_on_close,
                    on_error=_on_error,
                    subprotocols=['janus-protocol'])
                self._ws_thread = threading.Thread(target=self._ws.run_forever)
                self._ws_thread.daemon = True
                self._ws_thread.start()
            except Exception as e:
                _logger.warn(e)
Beispiel #2
0
    def _connect(self, username, session):
        if self._thread is None:
            _logger.log('Octoprint Socket: Connecting')

            def _on_message(ws, message):
                # _logger.log('Octoprint socket message recieved: %s' % message)
                self._callback.on_event(event=message)

            def _on_error(ws, error):
                _logger.log('Octoprint Socket Error: %s' % error)

            def _on_close(ws):
                _logger.log('Octoprint Socket: Ws Closed')
                self._callback.disconnected()

            def _on_open(ws):
                _logger.log('Octoprint Socket: Ws Opened')
                self._ws.send(
                    _json.dumps({'auth': '%s:%s' % (username, session)}))
                self._ws.send(_json.dumps({'throttle': 10}))
                self._callback.connected()

            try:
                self._ws = websocket.WebSocketApp(
                    "ws://localhost:5000/sockjs/websocket",
                    on_message=_on_message,
                    on_error=_on_error,
                    on_close=_on_close,
                    on_open=_on_open)

                self._thread = threading.Thread(target=self._ws.run_forever)
                self._thread.daemon = True
                self._thread.start()
            except Exception as e:
                _logger.warn(e)
Beispiel #3
0
	def connect(self):
		try:
			if not self._sio.connected and not self._connecting:
				self._connecting = True
				_logger.log('Plabric Socket: Connecting')
				self._sio.connect(self._domain, namespaces=[config.PLABRIC_SOCKET_NAMESPACE])
		except (socketio.exceptions.ConnectionError, ValueError) as e:
			_logger.warn(e)
			self._connecting = False
			self._callback.on_connection_error()
Beispiel #4
0
    def _disconnect_janus(self):
        self._paused = False
        self._stream_on_start = False

        if self._janus_proc:
            try:
                self._janus_proc.terminate()
            except Exception as e:
                _logger.warn(e)

        self._janus_thread = None
Beispiel #5
0
 def stop(self):
     if self._process:
         self._shutting_down = True
         try:
             self._process.communicate(input=str.encode("q"))
             self._process.terminate()
             self._process.kill()
         except Exception as e:
             _logger.warn(e)
         self._process = None
         self._callback.on_video_stopped()
Beispiel #6
0
    def _stream(self, base):
        arguments = self._extra_arguments
        r = self.get_rotation_params()
        if r:
            arguments['vf'] = r

        try:
            self._process = base\
             .output(self._url, format='rtp', vcodec=self._vcodec, pix_fmt='yuv420p', an=None, ** arguments)\
             .run_async(cmd=self._ffmpeg_dir, pipe_stdin=True, pipe_stderr=True, quiet=True)
        except Exception as e:
            _logger.warn(e)
Beispiel #7
0
 def monitor_ffmpeg_process():
     while True:
         ring_buffer = deque(maxlen=200)
         err = process.stderr.readline()
         if not err:
             if self._shutting_down:
                 return
             process.wait()
             _logger.warn('STDERR:\n{}\n'.format(
                 '\n'.join(ring_buffer)))
             self.stop()
             return
         else:
             ring_buffer.append(err)
Beispiel #8
0
    def disconnect(self):
        _logger.log('Janus: Disconnecting')

        if self._ws:
            self._ws.close()
            self._ws.keep_running = False
            self._ws_thread = None
            self._ws = None

        self._paused = False
        self._stream_on_start = False

        if self._janus_proc:
            try:
                self._janus_proc.terminate()
            except Exception as e:
                _logger.warn(e)

        self._janus_thread = None
Beispiel #9
0
    def connect(self):
        if self._enabled and not self.ws_connected():
            _logger.log('Janus: Connecting')

            def _on_error(ws, error):
                _logger.log('Janus Error: %s' % error)
                self._reset_janus_ws()

            def _on_message(ws, msg):
                self._process_msg(msg)

            def _on_close(ws):
                _logger.log('Janus: Ws Closed')
                self._callback.disconnected()
                self._reset_janus_ws()

            def _on_open(ws):
                _logger.log('Janus: Ws Opened')
                self._create_session()

            try:
                if self._janus_thread is None:
                    self._run_janus()

                if self._started_at is not None and time.time(
                ) - self._started_at < 4:
                    time.sleep(2)

                self._ws = websocket.WebSocketApp(
                    self._url,
                    on_open=_on_open,
                    on_message=_on_message,
                    on_close=_on_close,
                    on_error=_on_error,
                    subprotocols=['janus-protocol'])
                _ws_thread = threading.Thread(target=self._ws.run_forever)
                _ws_thread.daemon = True
                _ws_thread.start()

            except Exception as e:
                _logger.warn(e)
Beispiel #10
0
 def _stream_from_url(self, url):
     _logger.log('Video stream: Start from url %s' % url)
     try:
         self._stream(ffmpeg.input(url))
     except Exception as e:
         _logger.warn(e)
Beispiel #11
0
 def _stream_from_device(self):
     _logger.log('Video stream: Start from device')
     try:
         self._stream(ffmpeg.input('/dev/video0', input_format='mjpeg'))
     except Exception as e:
         _logger.warn(e)