Skip to content

Commit

Permalink
Merge pull request gfto#7 from ningpeng/master
Browse files Browse the repository at this point in the history
1. when pat table changed in ts stream ,  Reconnect ts stream
  • Loading branch information
Georgi Chorbadzhiyski authored Oct 11, 2016
2 parents a0000ff + a968158 commit 27b879c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int process_pat(INPUT *r, uint16_t pid, uint8_t *ts_packet) {
// Process PAT
s->pat = ts_pat_push_packet(s->pat, ts_packet);

s->last_pat = ts_pat_push_packet(s->last_pat, ts_packet);

if (s->last_pat->initialized) {
if (!ts_pat_is_same(s->pat, s->last_pat)) {
proxy_log(r, "PAT changed.");
Expand All @@ -191,7 +191,7 @@ int process_pat(INPUT *r, uint16_t pid, uint8_t *ts_packet) {
ts_pat_free(&s->last_pat);
s->last_pat = ts_pat_alloc();
}

s->last_pat = ts_pat_push_packet(s->last_pat, ts_packet);
if (s->pat->initialized) {
// PMT pid is still unknown
if (!s->pmt_pid) {
Expand Down
26 changes: 16 additions & 10 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ int connect_source(INPUT *r, int retries, int readbuflen, int *http_code) {
}
// connected ok, continue
} else {
if (!IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr))) {
LOGf("ERR : %s is not multicast address\n", r->channel->source);
FATAL_ERROR;
}

char multicast = IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr));

//if (!IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr))) {
// LOGf("ERR : %s is not multicast address\n", r->channel->source);
// FATAL_ERROR;
//}
struct ip_mreq mreq;
struct sockaddr_in receiving_from;

Expand All @@ -217,12 +220,15 @@ int connect_source(INPUT *r, int retries, int readbuflen, int *http_code) {
// LOGf("CONN : Listening on multicast socket %s srv_fd: %i retries left: %i\n", r->channel->source, r->sock, retries);
int on = 1;
setsockopt(r->sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
// subscribe to multicast group
memcpy(&mreq.imr_multiaddr, &(r->src_sockname.sin_addr), sizeof(struct in_addr));
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(r->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
LOGf("ERR : Failed to add IP membership on %s srv_fd: %i\n", r->channel->source, r->sock);
FATAL_ERROR;

if (multicast) {
// subscribe to multicast group
memcpy(&mreq.imr_multiaddr, &(r->src_sockname.sin_addr), sizeof(struct in_addr));
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(r->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
LOGf("ERR : Failed to add IP membership on %s srv_fd: %i\n", r->channel->source, r->sock);
FATAL_ERROR;
}
}
// bind to the socket so data can be read
memset(&receiving_from, 0, sizeof(receiving_from));
Expand Down

0 comments on commit 27b879c

Please sign in to comment.