Browse Source

Try to fix broken stream after short read (reconnect directly)

Georgi Chorbadzhiyski 2 years ago
parent
commit
9d83cc51e2
1 changed files with 7 additions and 4 deletions
  1. 7
    4
      tomcast.c

+ 7
- 4
tomcast.c View File

@@ -875,6 +875,7 @@ void * proxy_ts_stream(void *self) {
875 875
 
876 876
 	int http_code = 0;
877 877
 	while (1) {
878
+NEW_SOURCE:
878 879
 		r->conn_ts = 0;
879 880
 		r->read_bytes = 0;
880 881
 
@@ -917,8 +918,8 @@ void * proxy_ts_stream(void *self) {
917 918
 
918 919
 			// Fill short frame with NULL packets
919 920
 			if (readen < FRAME_PACKET_SIZE) {
920
-				//LOGf("DEBUG: Short read (%d) on retreamer srv_fd: %i | Channel: %s\n", readen, sock, chan->name);
921
-				memcpy(buf+readen, TS_NULL_FRAME+readen, FRAME_PACKET_SIZE - readen);
921
+				LOGf("DEBUG: Short read (%zd) on retreamer srv_fd: %i | Channel: %s Source: %s\n", readen, r->sock, r->channel->name, r->channel->source);
922
+				goto RECONNECT;
922 923
 			}
923 924
 			pthread_rwlock_wrlock(&r->lock);
924 925
 			r->read_bytes += readen;
@@ -944,7 +945,7 @@ void * proxy_ts_stream(void *self) {
944 945
 				}
945 946
 			}
946 947
 
947
-			written = fdwrite(r->clientsock, buf, FRAME_PACKET_SIZE);
948
+			written = fdwrite(r->clientsock, buf, readen);
948 949
 			if (written == -1) {
949 950
 				LOGf("PROXY: Error writing to dst_fd: %i on srv_fd: %i | Channel: %s Source: %s\n", r->clientsock, r->sock, r->channel->name, r->channel->source);
950 951
 				connect_destination(r);
@@ -953,6 +954,8 @@ void * proxy_ts_stream(void *self) {
953 954
 		LOGf("DEBUG: fdread timeout restreamer srv_fd: %i | Channel: %s\n", r->sock, r->channel->name);
954 955
 		proxy_set_status(r, "ERROR: Read timeout");
955 956
 RECONNECT:
957
+		if (send_reset_opt)
958
+			fdwrite(r->clientsock, reset, FRAME_PACKET_SIZE);
956 959
 		pthread_rwlock_wrlock(&r->lock);
957 960
 		r->conn_ts = 0;
958 961
 		pthread_rwlock_unlock(&r->lock);
@@ -960,7 +963,7 @@ RECONNECT:
960 963
 		proxy_set_status(r, "Reconnecting");
961 964
 		shutdown_fd(&(r->sock));
962 965
 		next_channel_source(r->channel);
963
-		continue;
966
+		goto NEW_SOURCE;
964 967
 QUIT:
965 968
 		LOGf("DEBUG: quit srv_fd: %i | Channel: %s\n", r->sock, r->channel->name);
966 969
 		break;

Loading…
Cancel
Save