Browse Source

Merge pull request #7 from ningpeng/master

1. when pat table changed in ts stream ,  Reconnect ts stream
Georgi Chorbadzhiyski 7 years ago
parent
commit
27b879cb86
2 changed files with 18 additions and 12 deletions
  1. 2
    2
      input.c
  2. 16
    10
      network.c

+ 2
- 2
input.c View File

@@ -182,7 +182,7 @@ int process_pat(INPUT *r, uint16_t pid, uint8_t *ts_packet) {
182 182
 	// Process PAT
183 183
 	s->pat = ts_pat_push_packet(s->pat, ts_packet);
184 184
 
185
-	s->last_pat = ts_pat_push_packet(s->last_pat, ts_packet);
185
+	
186 186
 	if (s->last_pat->initialized) {
187 187
 		if (!ts_pat_is_same(s->pat, s->last_pat)) {
188 188
 			proxy_log(r, "PAT changed.");
@@ -191,7 +191,7 @@ int process_pat(INPUT *r, uint16_t pid, uint8_t *ts_packet) {
191 191
 		ts_pat_free(&s->last_pat);
192 192
 		s->last_pat = ts_pat_alloc();
193 193
 	}
194
-
194
+    s->last_pat = ts_pat_push_packet(s->last_pat, ts_packet);
195 195
 	if (s->pat->initialized) {
196 196
 		// PMT pid is still unknown
197 197
 		if (!s->pmt_pid) {

+ 16
- 10
network.c View File

@@ -202,10 +202,13 @@ int connect_source(INPUT *r, int retries, int readbuflen, int *http_code) {
202 202
 		}
203 203
 		// connected ok, continue
204 204
 	} else {
205
-		if (!IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr))) {
206
-			LOGf("ERR  : %s is not multicast address\n", r->channel->source);
207
-			FATAL_ERROR;
208
-		}
205
+
206
+		char multicast = IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr));
207
+		
208
+		//if (!IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr))) {
209
+		//	LOGf("ERR  : %s is not multicast address\n", r->channel->source);
210
+		//	FATAL_ERROR;
211
+		//}
209 212
 		struct ip_mreq mreq;
210 213
 		struct sockaddr_in receiving_from;
211 214
 
@@ -217,12 +220,15 @@ int connect_source(INPUT *r, int retries, int readbuflen, int *http_code) {
217 220
 		// LOGf("CONN : Listening on multicast socket %s srv_fd: %i retries left: %i\n", r->channel->source, r->sock, retries);
218 221
 		int on = 1;
219 222
 		setsockopt(r->sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
220
-		// subscribe to multicast group
221
-		memcpy(&mreq.imr_multiaddr, &(r->src_sockname.sin_addr), sizeof(struct in_addr));
222
-		mreq.imr_interface.s_addr = htonl(INADDR_ANY);
223
-		if (setsockopt(r->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
224
-			LOGf("ERR  : Failed to add IP membership on %s srv_fd: %i\n", r->channel->source, r->sock);
225
-			FATAL_ERROR;
223
+		
224
+		if (multicast)  {
225
+    		// subscribe to multicast group
226
+    		memcpy(&mreq.imr_multiaddr, &(r->src_sockname.sin_addr), sizeof(struct in_addr));
227
+    		mreq.imr_interface.s_addr = htonl(INADDR_ANY);
228
+    		if (setsockopt(r->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
229
+    			LOGf("ERR  : Failed to add IP membership on %s srv_fd: %i\n", r->channel->source, r->sock);
230
+    			FATAL_ERROR;
231
+    		}
226 232
 		}
227 233
 		// bind to the socket so data can be read
228 234
 		memset(&receiving_from, 0, sizeof(receiving_from));

Loading…
Cancel
Save