Project

General

Profile

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

Lars Op den Kamp -, 2010-10-09 10:13

View differences:

src/dvb/dvb.h
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
src/dvb/dvb_adapter.c
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

  
src/dvb/dvb_fe.c
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

  
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
  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
}
src/htsp.c
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
 *
......
1387 1389
  htsp_connection_t *htsp = hs->hs_htsp;
1388 1390
  int64_t ts;
1389 1391
  int qlen = hs->hs_q.hmq_payload;
1392
  signal_status_t *status = malloc(sizeof(signal_status_t));
1390 1393

  
1391 1394
  if((qlen > 500000 && pkt->pkt_frametype == PKT_B_FRAME) ||
1392 1395
     (qlen > 750000 && pkt->pkt_frametype == PKT_P_FRAME) || 
......
1431 1434
  htsp_send(htsp, m, pkt->pkt_payload, &hs->hs_q, pktbuf_len(pkt->pkt_payload));
1432 1435

  
1433 1436
  if(hs->hs_last_report != dispatch_clock) {
1434
    /* Send a queue status report every second */
1437
    /* Send a queue and signal status report every second */
1438

  
1439
    htsp_get_signal_status(hs, status);
1435 1440

  
1436 1441
    hs->hs_last_report = dispatch_clock;
1437 1442

  
......
1460 1465
    htsmsg_add_u32(m, "Pdrops", hs->hs_dropstats[PKT_P_FRAME]);
1461 1466
    htsmsg_add_u32(m, "Idrops", hs->hs_dropstats[PKT_I_FRAME]);
1462 1467

  
1468
    /* add the signal status */
1469
    if (status->status_text != NULL)
1470
      htsmsg_add_str(m, "feStatus", status->status_text);
1471
    htsmsg_add_u32(m, "feSNR",      status->snr);
1472
    htsmsg_add_u32(m, "feSignal",   status->signal);
1473
    htsmsg_add_u32(m, "feBER",      status->ber);
1474
    htsmsg_add_u32(m, "feUNC",      status->unc);
1475

  
1476
    /* add the tuner name */
1477
    if (status->name != NULL)
1478
      htsmsg_add_str(m, "feName",   status->name);
1479

  
1463 1480
    /* We use a special queue for queue status message so they're not
1464 1481
       blocked by anything else */
1465 1482

  
......
1611 1628
  }
1612 1629
  streaming_msg_free(sm);
1613 1630
}
1631

  
1632

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

  
1647
  // get signal status from the current transport
1648
  if (hs->hs_s && hs->hs_s->ths_transport)
1649
  {
1650
    return get_signal_status_from_transport(hs->hs_s->ths_transport, status);
1651
  }
1652
}
src/transports.c
1050 1050

  
1051 1051
  return 0;
1052 1052
}
1053

  
1054

  
1055
/**
1056
 * Get the signal status from a transport
1057
 */
1058
void
1059
get_signal_status_from_transport(th_transport_t *current_transport,
1060
                 signal_status_t *status)
1061
{
1062
  if (current_transport)
1063
  {
1064
    // get signal status from the transport
1065
    switch (current_transport->tht_type)
1066
    {
1067
      case TRANSPORT_DVB:
1068
        dvb_transport_get_signal_status(current_transport, status);
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 get_signal_status_from_transport(th_transport_t *current_transport,
104
                 signal_status_t *status);
105

  
103 106
#endif /* TRANSPORTS_H */
src/tvhead.h
166 166
#define SCT_ISVIDEO(t) ((t) == SCT_MPEG2VIDEO || (t) == SCT_H264)
167 167
#define SCT_ISAUDIO(t) ((t) == SCT_MPEG2AUDIO || (t) == SCT_AC3 || \
168 168
                        (t) == SCT_AAC)
169

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

  
169 183
/**
170 184
 * A streaming pad generates data.
171 185
 * It has one or more streaming targets attached to it.
172
- 
(2-2/3)