Project

General

Profile

Feature #300 » 0002-add-signal-status-in-HTSP.patch

updated to apply to the current trunk - Lars Op den Kamp -, 2010-11-06 15:12

View differences:

tvheadend-patch/src/dvb/dvb_adapter.c 2010-11-06 14:50:26.043504304 +0100
64 64
  tda->tda_allpids_dmx_fd = -1;
65 65
  tda->tda_dump_fd = -1;
66 66

  
67
  /* current signal status */
68
  tda->sig_status = malloc(sizeof(signal_status_t));
69

  
70
  tda->sig_status->snr         = -2;
71
  tda->sig_status->signal      = -2;
72
  tda->sig_status->ber         = -2;
73
  tda->sig_status->unc         = -2;
74
  tda->sig_status->status      = -2;
75
  tda->sig_status->status_text = NULL;
76
  tda->sig_status->name        = NULL;
77

  
78
  pthread_mutex_init(&tda->sig_status_update_mutex, NULL);
79

  
67 80
  return tda;
68 81
}
69 82

  
tvheadend-patch/src/dvb/dvb_fe.c 2010-11-06 14:50:26.043504304 +0100
51 51
{
52 52
  th_dvb_adapter_t *tda = aux;
53 53
  fe_status_t fe_status;
54
  int status, v, update = 0, vv, i, fec, q;
54
  int status, v, update = 0, vv, i, fec, q, ber, signal, snr;
55 55
  th_dvb_mux_instance_t *tdmi = tda->tda_mux_current;
56 56
  char buf[50];
57 57

  
......
112 112
    } else {
113 113
      status = TDMI_FE_CONSTANT_FEC;
114 114
    }
115

  
116
    /* bit error rate */
117
    if (ioctl(tda->tda_fe_fd, FE_READ_BER, &ber) == -1)
118
      ber = -2;
119

  
120
    /* signal strength */
121
    if (ioctl(tda->tda_fe_fd, FE_READ_SIGNAL_STRENGTH, &signal) == -1)
122
      signal = -2;
123

  
124
    /* signal/noise ratio */
125
    if (ioctl(tda->tda_fe_fd, FE_READ_SNR, &snr) == -1)
126
      snr = -2;
115 127
  }
116 128

  
117 129
  if(status != tdmi->tdmi_fe_status) {
......
137 149
    }
138 150
  } 
139 151

  
152
  /* update transport status */
153
  pthread_mutex_lock(&tda->sig_status_update_mutex);
154

  
155
  tda->sig_status->ber =    ber;
156
  tda->sig_status->signal = signal;
157
  tda->sig_status->snr =    snr;
158
  tda->sig_status->status = fe_status;
159
  tda->sig_status->unc =    fec;
160
  tvh_str_update(&tda->sig_status->status_text, dvb_mux_status(tdmi));
161

  
162
  pthread_mutex_unlock(&tda->sig_status_update_mutex);
163

  
140 164
  if(update) {
141 165
    htsmsg_t *m = htsmsg_create_map();
142 166

  
tvheadend-patch/src/dvb/dvb.h 2010-11-06 14:50:26.043504304 +0100
200 200
  int tda_allpids_dmx_fd;
201 201
  int tda_dump_fd;
202 202

  
203

  
204
  pthread_mutex_t sig_status_update_mutex;
205
  signal_status_t *sig_status; /* current signal status */
206

  
203 207
} th_dvb_adapter_t;
204 208

  
205 209

  
......
307 311

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

  
314
void dvb_transport_get_signal_status(th_transport_t *current_transport,
315
                   signal_status_t *status);
310 316

  
311 317
/**
312 318
 * DVB Frontend
tvheadend-patch/src/dvb/dvb_transport.c 2010-11-06 14:50:26.043504304 +0100
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
  if (current_transport && current_transport->tht_dvb_mux_instance &&
473
              current_transport->tht_dvb_mux_instance->tdmi_adapter)
474
  {
475
    th_dvb_adapter_t *tda =
476
            current_transport->tht_dvb_mux_instance->tdmi_adapter;
477

  
478
    pthread_mutex_lock(&tda->sig_status_update_mutex);
479

  
480
    status->ber =         tda->sig_status->ber;
481
    status->signal =      tda->sig_status->signal;
482
    status->snr =         tda->sig_status->snr;
483
    status->status =      tda->sig_status->status;
484
    status->unc =         tda->sig_status->unc;
485
    status->status_text = strdup(tda->sig_status->status_text);
486
    status->name =        strdup(tda->tda_displayname);
487

  
488
    pthread_mutex_unlock(&tda->sig_status_update_mutex);
489
  }
490
}
tvheadend-patch/src/htsp.c 2010-11-06 14:50:26.095507576 +0100
166 166
} htsp_subscription_t;
167 167

  
168 168

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

  
169 171

  
170 172
/**
171 173
 *
......
1392 1394
  htsp_connection_t *htsp = hs->hs_htsp;
1393 1395
  int64_t ts;
1394 1396
  int qlen = hs->hs_q.hmq_payload;
1397
  signal_status_t *status = malloc(sizeof(signal_status_t));
1395 1398

  
1396 1399
  if((qlen > 500000 && pkt->pkt_frametype == PKT_B_FRAME) ||
1397 1400
     (qlen > 750000 && pkt->pkt_frametype == PKT_P_FRAME) || 
......
1436 1439
  htsp_send(htsp, m, pkt->pkt_payload, &hs->hs_q, pktbuf_len(pkt->pkt_payload));
1437 1440

  
1438 1441
  if(hs->hs_last_report != dispatch_clock) {
1439
    /* Send a queue status report every second */
1442
    /* Send a queue and signal status report every second */
1443

  
1444
    htsp_get_signal_status(hs, status);
1440 1445

  
1441 1446
    hs->hs_last_report = dispatch_clock;
1442 1447

  
......
1465 1470
    htsmsg_add_u32(m, "Pdrops", hs->hs_dropstats[PKT_P_FRAME]);
1466 1471
    htsmsg_add_u32(m, "Idrops", hs->hs_dropstats[PKT_I_FRAME]);
1467 1472

  
1473
    /* add the signal status */
1474
    if (status->status_text != NULL)
1475
      htsmsg_add_str(m, "feStatus", status->status_text);
1476
    htsmsg_add_u32(m, "feSNR",      status->snr);
1477
    htsmsg_add_u32(m, "feSignal",   status->signal);
1478
    htsmsg_add_u32(m, "feBER",      status->ber);
1479
    htsmsg_add_u32(m, "feUNC",      status->unc);
1480

  
1481
    /* add the tuner name */
1482
    if (status->name != NULL)
1483
      htsmsg_add_str(m, "feName",   status->name);
1484

  
1468 1485
    /* We use a special queue for queue status message so they're not
1469 1486
       blocked by anything else */
1470 1487

  
......
1613 1630
  }
1614 1631
  streaming_msg_free(sm);
1615 1632
}
1633

  
1634

  
1635
/**
1636
 * Adds the signal status of the adapter used by a subscription
1637
 */
1638
static void
1639
htsp_get_signal_status(htsp_subscription_t *hs, signal_status_t *status)
1640
{
1641
  status->status_text = NULL;
1642
  status->name        = NULL;
1643
  status->status      = 0;
1644
  status->snr         = -2;
1645
  status->signal      = -2;
1646
  status->ber         = -2;
1647
  status->unc         = -2;
1648

  
1649
  // get signal status from the current transport
1650
  if (hs->hs_s && hs->hs_s->ths_transport)
1651
  {
1652
    return get_signal_status_from_transport(hs->hs_s->ths_transport, status);
1653
  }
1654
}
tvheadend-patch/src/transports.c 2010-11-06 14:51:44.015507336 +0100
1054 1054
  return 0;
1055 1055
}
1056 1056

  
1057

  
1058
/**
1059
 * Get the signal status from a transport
1060
 */
1061
void
1062
get_signal_status_from_transport(th_transport_t *current_transport,
1063
                 signal_status_t *status)
1064
{
1065
  if (current_transport)
1066
  {
1067
    // get signal status from the transport
1068
    switch (current_transport->tht_type)
1069
    {
1070
      case TRANSPORT_DVB:
1071
        dvb_transport_get_signal_status(current_transport, status);
1072
        break;
1073
      case TRANSPORT_V4L:
1074
        //TODO add signal status from a V4L adapter
1075
        break;
1076
      case TRANSPORT_IPTV:
1077
        //TODO add signal status from an IPTV adapter
1078
        break;
1079
    }
1080
  }
1081
}
1082

  
tvheadend-patch/src/transports.h 2010-11-06 14:50:26.095507576 +0100
100 100

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

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

  
103 106
#endif /* TRANSPORTS_H */
tvheadend-patch/src/tvhead.h 2010-11-06 14:50:26.095507576 +0100
168 168
#define SCT_ISVIDEO(t) ((t) == SCT_MPEG2VIDEO || (t) == SCT_H264)
169 169
#define SCT_ISAUDIO(t) ((t) == SCT_MPEG2AUDIO || (t) == SCT_AC3 || \
170 170
                        (t) == SCT_AAC)
171

  
172
/**
173
 * The signal status of a tuner
174
 */
175
typedef struct signal_status {
176
  char *name;        /* adapter name */
177
  char *status_text; /* adapter status text */
178
  int status;        /* adapter status code */
179
  uint16_t snr;      /* signal/noise ratio */
180
  uint16_t signal;   /* signal strength */
181
  uint32_t ber;      /* bit error rate */
182
  uint32_t unc;      /* uncorrected blocks */
183
} signal_status_t;
184

  
171 185
/**
172 186
 * A streaming pad generates data.
173 187
 * It has one or more streaming targets attached to it.
(3-3/3)