int WINAPI ftl_status_thread()

in ftl_app/main.c [360:460]


int WINAPI ftl_status_thread(LPVOID data)
#else
static void *ftl_status_thread(void *data)
#endif
{
  ftl_handle_t *handle = (ftl_handle_t *)data;
  ftl_status_msg_t status;
  ftl_status_t status_code;
  int retries = 10;
  int retry_sleep = 5000;

  while (1)
  {
    if ((status_code = ftl_ingest_get_status(handle, &status, 1000)) == FTL_STATUS_TIMEOUT)
    {
      continue;
    }

    if (status_code == FTL_NOT_INITIALIZED)
    {
      break;
    }

  if (status.type == FTL_STATUS_EVENT && status.msg.event.type == FTL_STATUS_EVENT_TYPE_DESTROYED)
  {
    break;
  }

    if (status.type == FTL_STATUS_EVENT && status.msg.event.type == FTL_STATUS_EVENT_TYPE_DISCONNECTED)
    {
      printf("Disconnected from ingest for reason: %s (%d)\n", ftl_status_code_to_string(status.msg.event.error_code), status.msg.event.reason);

      if (status.msg.event.reason == FTL_STATUS_EVENT_REASON_API_REQUEST)
      {
        continue;
      }

    /*dont reconnect for speed test*/
    if (speedtest_duration) {
      continue;
    }

      //attempt reconnection
      while (retries-- > 0)
      {
        sleep_ms(retry_sleep);
        printf("Attempting to reconnect to ingest (retires left %d)\n", retries);
        if ((status_code = ftl_ingest_connect(handle)) == FTL_SUCCESS)
        {
          retries = 10;
          break;
        }
        printf("Failed to connect to ingest: %s (%d)\n", ftl_status_code_to_string(status_code), status_code);
        retry_sleep = retry_sleep * 3 / 2;
      }
      if (retries <= 0)
      {
        break;
      }
    }
    else if (status.type == FTL_STATUS_LOG)
    {
      printf("[%d] %s\n", status.msg.log.log_level, status.msg.log.string);
    }
    else if (status.type == FTL_STATUS_VIDEO_PACKETS)
    {
      ftl_packet_stats_msg_t *p = &status.msg.pkt_stats;

      printf("Avg packet send per second %3.1f, total nack requests %d\n",
             (float)p->sent * 1000.f / p->period,
             p->nack_reqs);
    }
  else if (status.type == FTL_STATUS_VIDEO_PACKETS_INSTANT)
  {
    ftl_packet_stats_instant_msg_t *p = &status.msg.ipkt_stats;

    printf("avg transmit delay %dms (min: %d, max: %d), avg rtt %dms (min: %d, max: %d)\n",
      p->avg_xmit_delay, p->min_xmit_delay, p->max_xmit_delay,
      p->avg_rtt, p->min_rtt, p->max_rtt);
  }
    else if (status.type == FTL_STATUS_VIDEO)
    {
      ftl_video_frame_stats_msg_t *v = &status.msg.video_stats;

      printf("Queue an average of %3.2f fps (%3.1f kbps), sent an average of %3.2f fps (%3.1f kbps), queue fullness %d, max frame size %d\n",
             (float)v->frames_queued * 1000.f / v->period,
             (float)v->bytes_queued / v->period * 8,
             (float)v->frames_sent * 1000.f / v->period,
             (float)v->bytes_sent / v->period * 8,
             v->queue_fullness, v->max_frame_size);
    }
    else
    {
      printf("Status:  Got Status message of type %d\n", status.type);
    }
  }

  printf("exited ftl_status_thread\n");

  return 0;
}