Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add corrupted_packets_mode option #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ int config_load_channels(CONFIG *conf) {
}

int eit_mode = ini_get_int(ini, 0, "Channel%d:eit_mode", i);
int corrupted_packets_mode = ini_get_int(ini, 0, "Channel%d:corrupted_packets_mode", i);

for (j=1;j<8;j++) {
char *source = ini_get_string(ini, NULL, "Channel%d:source%d", i, j);
Expand All @@ -147,7 +148,7 @@ int config_load_channels(CONFIG *conf) {
}
// Init channel
if (channel == NULL) {
channel = channel_new(service_id, is_radio, id, name, eit_mode, source, i, lcn, is_lcn_visible);
channel = channel_new(service_id, is_radio, id, name, eit_mode, corrupted_packets_mode, source, i, lcn, is_lcn_visible);
} else {
chansrc_add(channel, source);
}
Expand Down Expand Up @@ -227,7 +228,7 @@ int config_load_channels(CONFIG *conf) {
if (r->cookie != cookie) {
proxy_log(r, "Remove");
/* Replace channel reference with real object and instruct free_restreamer to free it */
r->channel = channel_new(r->channel->service_id, r->channel->radio, r->channel->id, r->channel->name, r->channel->eit_mode, r->channel->source, r->channel->index, r->channel->lcn, r->channel->lcn_visible);
r->channel = channel_new(r->channel->service_id, r->channel->radio, r->channel->id, r->channel->name, r->channel->eit_mode, r->channel->corrupted_packets_mode, r->channel->source, r->channel->index, r->channel->lcn, r->channel->lcn_visible);
r->freechannel = 1;
r->dienow = 1;
}
Expand Down
15 changes: 14 additions & 1 deletion data.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>

#include "libfuncs/io.h"
#include "libfuncs/log.h"
Expand Down Expand Up @@ -121,7 +122,7 @@ void chansrc_set(CHANNEL *c, uint8_t src_id) {



CHANNEL *channel_new(int service_id, int is_radio, const char *id, const char *name, int eit_mode, const char *source, int channel_index, int lcn, int is_lcn_visible){
CHANNEL *channel_new(int service_id, int is_radio, const char *id, const char *name, int eit_mode, int corrupted_packets_mode, const char *source, int channel_index, int lcn, int is_lcn_visible){

if (channel_index<=0 || channel_index>=256)
{
Expand All @@ -142,6 +143,7 @@ CHANNEL *channel_new(int service_id, int is_radio, const char *id, const char *n
c->id = strdup(id);
c->name = strdup(name);
c->eit_mode = eit_mode;
c->corrupted_packets_mode = corrupted_packets_mode;
chansrc_add(c, source);


Expand Down Expand Up @@ -434,6 +436,17 @@ void proxy_log(INPUT *r, char *msg) {
LOGf("INPUT : [%-12s] %s fd: %d src: %s\n", r->channel->id, msg, r->sock, r->channel->source);
}

void proxy_logf(INPUT *r, const char *fmt, ...) {
char msg[1024];
va_list args;
va_start(args, fmt);
vsnprintf(msg, sizeof(msg) - 1, fmt, args);
va_end(args);
msg[sizeof(msg) - 1] = '\0';

proxy_log(r, msg);
}

void proxy_close(LIST *inputs, INPUT **input) {
proxy_log(*input, "Stop");
// If there are no clients left, no "Timeout" messages will be logged
Expand Down
14 changes: 13 additions & 1 deletion data.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@

#include "pidref.h"

typedef struct {
uint64_t count;
uint64_t events;
} CORRUPTION_STATS;

typedef enum { udp_sock, tcp_sock } channel_source;

typedef struct {
Expand Down Expand Up @@ -66,6 +71,10 @@ typedef struct {
int radio;
int lcn;
int lcn_visible;
int corrupted_packets_mode; /* 0 = don't check Transport error indicator (default)
1 = process corrupted TS packets normally
2 = drop corrupted TS packets
*/
char * id;
char * name;
int eit_mode; /* 0 = ignore EIT data from input
Expand Down Expand Up @@ -134,6 +143,8 @@ typedef struct {
int cookie; /* Used in chanconf to determine if the restreamer is alrady checked */
int ifd;

CORRUPTION_STATS corruption_stats;

pthread_t thread;

uint16_t output_pcr_pid;
Expand Down Expand Up @@ -231,7 +242,7 @@ EPG_ENTRY * epg_new (time_t start, int duration, char *encoding, char *event,
void epg_free (EPG_ENTRY **e);
int epg_changed (EPG_ENTRY *a, EPG_ENTRY *b);

CHANNEL * channel_new (int service_id, int is_radio, const char *id, const char *name, int eit_mode, const char *source, int channel_index, int lcn, int is_lcn_visible);
CHANNEL * channel_new (int service_id, int is_radio, const char *id, const char *name, int eit_mode, int corrupted_packets_mode, const char *source, int channel_index, int lcn, int is_lcn_visible);
void channel_free (CHANNEL **c);
void channel_free_epg(CHANNEL *c);

Expand Down Expand Up @@ -259,6 +270,7 @@ NIT * nit_new (uint16_t ts_id, char *freq, char *modulation, char *symbol_rat
void nit_free (NIT **nit);

void proxy_log (INPUT *r, char *msg);
void proxy_logf (INPUT *r, const char *fmt, ...);
void proxy_close (LIST *inputs, INPUT **input);

#endif
29 changes: 29 additions & 0 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <inttypes.h>

#include "libfuncs/io.h"
#include "libfuncs/log.h"
Expand Down Expand Up @@ -417,6 +418,7 @@ void * input_stream(void *self) {

ssize_t readen;
int max_zero_reads = MAX_ZERO_READS;
uint64_t corrupted_packets = 0;

// Reset all stream parameters on reconnect.
input_stream_reset(r);
Expand Down Expand Up @@ -462,6 +464,33 @@ void * input_stream(void *self) {
if (r->dienow)
goto QUIT;
uint8_t *ts_packet = (uint8_t *)buf + i;

// handle packets with Transport error indicator (TEI) set
if (r->channel->corrupted_packets_mode > 0) {
if (ts_packet_is_tei_set(ts_packet)) {
if (!corrupted_packets) {
r->corruption_stats.events++;
proxy_log(r, "corrupted package received");
}
if (corrupted_packets % 1000 == 0) {
proxy_logf(
r, "still getting corrupt input packets (%" PRIu64 ")",
corrupted_packets);
}
r->corruption_stats.count++;
corrupted_packets += 1;
if (r->channel->corrupted_packets_mode == 2) {
// drop corrupted TS packet
continue;
}
} else if (corrupted_packets) {
proxy_logf(r,
"corruption ended after %" PRIu64 " packets",
corrupted_packets);
corrupted_packets = 0;
}
}

uint16_t pid = ts_packet_get_pid(ts_packet);

int pat_result = process_pat(r, pid, ts_packet);
Expand Down
3 changes: 3 additions & 0 deletions mptsd_channels.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ id = btv
name = bTV
eit_mode = 0 # 0 = ignore EIT data from input
# 1 = forward EIT data for the configured service, ignore any other EIT data
corrupted_packets_mode = 0 # 0 = don't check Transport error indicator (default)
# 1 = process corrupted TS packets normally
# 2 = drop corrupted TS packets
source1 = http://signal-server/stb/btv.mpg
#source2 = http://signal-server2/stb/btv.mpg
#source3 = http://signal-server3/stb/btv.mpg
Expand Down