Ejemplo n.º 1
0
    def _handle_packet(self, pkt_raw):
        # Get the structure
        pkt = json.loads(pkt_raw)

        # Prepare to log
        pkt.update(cli_time=time.time(),
                   _type='srv-state')

        if self.video:
            # Add locally derived values
            pkt['cli_pts'] = self.video.get_video_pts()

        if 'srv_pts' in pkt and (pkt.get('cli_pts') is not None):
            # Video latency
            latency = pkt['srv_pts'] - pkt['cli_pts']
            pkt['latency_video'] = latency
                # Store min and max control latency for stats output
            self.video_extra_stats['lat_video'] = max(
                self.video_extra_stats.get('lat_video', -1),
                latency)
            self.video_extra_stats['lat_video_min'] = min(
                self.video_extra_stats.get('lat_video_min', 1e12),
                latency)

        if pkt['est_cli_time']:
            # Control link latency
            latency = pkt['cli_time'] - pkt['est_cli_time']
            pkt['latency_ctrl'] = latency
            # Store max control latency for stats output
            self.video_extra_stats['lat_ctrl'] = max(
                self.video_extra_stats.get('lat_ctrl', -1),
                latency)

        server_time_offset = pkt['srv_time'] - pkt['cli_time']
        if (self.server_time_offset is None) or \
                abs(self.server_time_offset - server_time_offset) > 1.0:
            self.logger.debug('Server time offset %.3f sec', server_time_offset)
            self.server_time_offset = server_time_offset

        # Parse out messages -- no need to log them twice
        logs = pkt.pop('logs_data', None) or []
        for entry in logs:
            if entry[0] > self.remote_logs_from:
                # new record
                self.remote_logs_from = entry[0]
                log_dict = MemoryLoggingHandler.to_dict(
                    entry, time_field='srv_time')
                log_dict.update(
                    _type='srv-log', cli_time=pkt['cli_time'])
                self._log_struct(log_dict)
                MemoryLoggingHandler.relog(entry, prefix='srv.')

        # Log it and store (for display)
        self._log_struct(pkt)
        self.server_state = pkt
        self.update_video_overlay()
Ejemplo n.º 2
0
 def _emit_json_logsaver_data(self):
     while self.json_logsaver.data:
         entry = self.json_logsaver.data.pop(0)
         log_dict = MemoryLoggingHandler.to_dict(
             entry, time_field='cli_time')
         if log_dict["name"].startswith("srv."):
             # Do not double-save server messages
             return
         log_dict.update(_type='cli-log')
         self._log_struct(log_dict)
Ejemplo n.º 3
0
 def _emit_json_logsaver_data(self):
     while self.json_logsaver.data:
         entry = self.json_logsaver.data.pop(0)
         log_dict = MemoryLoggingHandler.to_dict(entry,
                                                 time_field='cli_time')
         if log_dict["name"].startswith("srv."):
             # Do not double-save server messages
             return
         log_dict.update(_type='cli-log')
         self._log_struct(log_dict)
Ejemplo n.º 4
0
    def _handle_packet(self, pkt_raw):
        # Get the structure
        pkt = json.loads(pkt_raw)

        # Prepare to log
        pkt.update(cli_time=time.time(), _type='srv-state')

        if self.video:
            # Add locally derived values
            pkt['cli_pts'] = self.video.get_video_pts()

        if 'srv_pts' in pkt and (pkt.get('cli_pts') is not None):
            # Video latency
            latency = pkt['srv_pts'] - pkt['cli_pts']
            pkt['latency_video'] = latency
            # Store min and max control latency for stats output
            self.video_extra_stats['lat_video'] = max(
                self.video_extra_stats.get('lat_video', -1), latency)
            self.video_extra_stats['lat_video_min'] = min(
                self.video_extra_stats.get('lat_video_min', 1e12), latency)

        if pkt['est_cli_time']:
            # Control link latency
            latency = pkt['cli_time'] - pkt['est_cli_time']
            pkt['latency_ctrl'] = latency
            # Store max control latency for stats output
            self.video_extra_stats['lat_ctrl'] = max(
                self.video_extra_stats.get('lat_ctrl', -1), latency)

        server_time_offset = pkt['srv_time'] - pkt['cli_time']
        if (self.server_time_offset is None) or \
                abs(self.server_time_offset - server_time_offset) > 1.0:
            self.logger.debug('Server time offset %.3f sec',
                              server_time_offset)
            self.server_time_offset = server_time_offset

        # Parse out messages -- no need to log them twice
        logs = pkt.pop('logs_data', None) or []
        for entry in logs:
            if entry[0] > self.remote_logs_from:
                # new record
                self.remote_logs_from = entry[0]
                log_dict = MemoryLoggingHandler.to_dict(entry,
                                                        time_field='srv_time')
                log_dict.update(_type='srv-log', cli_time=pkt['cli_time'])
                self._log_struct(log_dict)
                MemoryLoggingHandler.relog(entry, prefix='srv.')

        # Log it and store (for display)
        self._log_struct(pkt)
        self.server_state = pkt
        self.update_video_overlay()