Project

General

Profile

Feature #300 » 01-tvheadend-add-signal-status.patch

patch: report signal quality - Lars Op den Kamp -, 2010-10-05 23:41

View differences:

src/dvb/dvb.h
307 307

308 308
htsmsg_t *dvb_transport_build_msg(th_transport_t *t);
309 309

310
void
311
dvb_transport_get_signal_status(th_transport_t *current_transport,
312
				   signal_status_t *status);
310 313

311 314
/**
312 315
 * DVB Frontend
src/dvb/dvb_transport.c
460 460
  htsmsg_add_str(m, "adapterId", tdmi->tdmi_adapter->tda_identifier);
461 461
  notify_by_msg("dvbService", m);
462 462
}
463

464

465
/**
466
 * Get the signal status from a DVB transport
467
 */
468
void
469
dvb_transport_get_signal_status(th_transport_t *current_transport,
470
	       signal_status_t *status)
471
{
472
  fe_status_t dvb_status;
473
  char fe_status[100];
474

475
  th_dvb_adapter_t *tda =
476
  	       current_transport->tht_dvb_mux_instance->tdmi_adapter;
477

478
  memset(&dvb_status, 0, sizeof(dvb_status));
479

480
  if (tda && tda->tda_fe_fd) {
481
    ioctl(tda->tda_fe_fd, FE_READ_STATUS, &dvb_status);
482

483
    /* signal strength */
484
    if (ioctl(tda->tda_fe_fd, FE_READ_SIGNAL_STRENGTH, &status->signal) == -1)
485
      status->signal = -2;
486

487
    /* signal/noise ratio */
488
    if (ioctl(tda->tda_fe_fd, FE_READ_SNR, &status->snr) == -1)
489
      status->snr = -2;
490

491
    /* bit error rate */
492
    if (ioctl(tda->tda_fe_fd, FE_READ_BER, &status->ber) == -1)
493
      status->ber = -2;
494

495
    /* uncorrected blocks */
496
    if (ioctl(tda->tda_fe_fd, FE_READ_UNCORRECTED_BLOCKS, &status->unc) == -1)
497
      status->unc = -2;
498

499
    /* adapter status */
500
    snprintf(fe_status, sizeof(fe_status), "%s:%s:%s:%s:%s",
501
                (dvb_status & FE_HAS_LOCK) ? "LOCKED" : "-",
502
                (dvb_status & FE_HAS_SIGNAL) ? "SIGNAL" : "-",
503
                (dvb_status & FE_HAS_CARRIER) ? "CARRIER" : "-",
504
                (dvb_status & FE_HAS_VITERBI) ? "VITERBI" : "-",
505
                (dvb_status & FE_HAS_SYNC) ? "SYNC" : "-");
506
    tvh_str_update(&status->status, fe_status);
507

508
    /* adapter name */
509
    status->name = tda->tda_displayname;
510
  }
511
}
src/htsp.c
165 165

166 166
} htsp_subscription_t;
167 167

168

168
static void htsp_get_signal_status(htsp_subscription_t *hs, signal_status_t *status);
169 169

170 170
/**
171 171
 *
......
1387 1387
  htsp_connection_t *htsp = hs->hs_htsp;
1388 1388
  int64_t ts;
1389 1389
  int qlen = hs->hs_q.hmq_payload;
1390
  signal_status_t *status = malloc(sizeof(signal_status_t));
1390 1391

1391 1392
  if((qlen > 500000 && pkt->pkt_frametype == PKT_B_FRAME) ||
1392 1393
     (qlen > 750000 && pkt->pkt_frametype == PKT_P_FRAME) || 
......
1460 1461
    htsmsg_add_u32(m, "Pdrops", hs->hs_dropstats[PKT_P_FRAME]);
1461 1462
    htsmsg_add_u32(m, "Idrops", hs->hs_dropstats[PKT_I_FRAME]);
1462 1463

1464
    htsp_get_signal_status(hs, status);
1465

1466
    htsmsg_add_str(m, "feStatus", status->status);
1467
    htsmsg_add_str(m, "feName", status->name);
1468
    htsmsg_add_u32(m, "feSNR", status->snr);
1469
    htsmsg_add_u32(m, "feSignal", status->signal);
1470
    htsmsg_add_u32(m, "feBER", status->ber);
1471
    htsmsg_add_u32(m, "feUNC", status->unc);
1472

1463 1473
    /* We use a special queue for queue status message so they're not
1464 1474
       blocked by anything else */
1465 1475

......
1608 1618
  }
1609 1619
  streaming_msg_free(sm);
1610 1620
}
1621

1622
/**
1623
 * Adds the signal status of the adapter used by a subscription
1624
 */
1625
static void
1626
htsp_get_signal_status(htsp_subscription_t *hs, signal_status_t *status)
1627
{
1628
  status->status = NULL;
1629
  status->snr = -2;
1630
  status->signal = -2;
1631
  status->ber = -2;
1632
  status->unc = -2;
1633

1634
  // get signal status from the current transport
1635
  if (hs->hs_s && hs->hs_s->ths_transport)
1636
  {
1637
    transport_get_signal_status(hs->hs_s->ths_transport, status);
1638
  }
1639
}
src/transports.c
1050 1050

1051 1051
  return 0;
1052 1052
}
1053

1054
/**
1055
 * Get the signal status from a transport
1056
 */
1057
void
1058
transport_get_signal_status(th_transport_t *current_transport,
1059
	       signal_status_t *status)
1060
{
1061
  if (current_transport)
1062
  {
1063
    // get signal status from the transport
1064
    switch (current_transport->tht_type)
1065
    {
1066
      case TRANSPORT_DVB:
1067
        dvb_transport_get_signal_status(current_transport, status);
1068
        break;
1069
      case TRANSPORT_V4L:
1070
        //TODO add signal status from a V4L adapter
1071
        break;
1072
      case TRANSPORT_IPTV:
1073
        //TODO add signal status from an IPTV adapter
1074
        break;
1075
    }
1076
  }
1077
}
src/transports.h
100 100

101 101
uint16_t get_encryption_from_transport(th_transport_t *t);
102 102

103
void
104
transport_get_signal_status(th_transport_t *current_transport,
105
				 signal_status_t *status);
106

103 107
#endif /* TRANSPORTS_H */
src/tvhead.h
874 874

875 875
void sbuf_cut(sbuf_t *sb, int off);
876 876

877
typedef struct signal_status {
878
  char *status; /* adapter status */
879
  char *name; /* adapter name */
880
  uint16_t snr; /* signal/noise ratio */
881
  uint16_t signal; /* signal strength */
882
  uint32_t ber; /* bit error rate */
883
  uint32_t unc; /* uncorrected blocks */
884
} signal_status_t;
885

877 886
#endif /* TV_HEAD_H */
(1-1/3)