From 07df79f2ee62ce649d6e1b0c5e472c869ddb3a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Thu, 8 Mar 2012 10:53:07 +0100 Subject: [PATCH 1/6] sanity checks for mkv muxer --- src/dvr/mkmux.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/dvr/mkmux.c b/src/dvr/mkmux.c index 54a350ce..1303d69f 100644 --- a/src/dvr/mkmux.c +++ b/src/dvr/mkmux.c @@ -810,10 +810,13 @@ mk_write_frame_i(mk_mux_t *mkm, mk_track *t, th_pkt_t *pkt) int skippable = pkt->pkt_frametype == PKT_B_FRAME; int vkeyframe = SCT_ISVIDEO(t->type) && keyframe; - uint8_t *data; - size_t len; + uint8_t *data = pktbuf_ptr(pkt->pkt_payload); + size_t len = pktbuf_len(pkt->pkt_payload); const int clusersizemax = 2000000; + if(!data || len <= 0) + return; + if(pts == PTS_UNSET) // This is our best guess, it might be wrong but... oh well pts = t->nextpts; @@ -863,10 +866,6 @@ mk_write_frame_i(mk_mux_t *mkm, mk_track *t, th_pkt_t *pkt) addcue(mkm, pts, t->tracknum); } - - data = pktbuf_ptr(pkt->pkt_payload); - len = pktbuf_len(pkt->pkt_payload); - if(t->type == SCT_AAC || t->type == SCT_MP4A) { // Skip ADTS header if(len < 7) From d204718cf9a9dcfe1d88d14cbc99ff9a734e6e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sun, 11 Mar 2012 18:08:45 +0100 Subject: [PATCH 2/6] Log timeouts as warnings --- src/webui/webui.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/webui/webui.c b/src/webui/webui.c index ed69ebdf..1b3d8ca9 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -157,8 +157,9 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq, th_subscription_t getsockopt(hc->hc_fd, SOL_SOCKET, SO_ERROR, (char *)&err, &errlen); //Abort upon socket error, or after 20 seconds of silence - if(err || timeouts >= 20){ - run = 0; + if(err || timeouts >= 20) { + tvhlog(LOG_WARNING, "webui", "Timeout waiting for packets"); + run = 0; } } pthread_mutex_unlock(&sq->sq_mutex); From 86cd61f21927ec1183ac2efed9fc24f592fc33cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sun, 11 Mar 2012 18:10:45 +0100 Subject: [PATCH 3/6] unlock mutex earlier --- src/webui/webui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webui/webui.c b/src/webui/webui.c index 1b3d8ca9..bcb75b66 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -168,6 +168,7 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq, th_subscription_t timeouts = 0; //Reset timeout counter TAILQ_REMOVE(&sq->sq_queue, sm, sm_link); + pthread_mutex_unlock(&sq->sq_mutex); switch(sm->sm_type) { case SMT_PACKET: { @@ -220,7 +221,6 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq, th_subscription_t break; } streaming_msg_free(sm); - pthread_mutex_unlock(&sq->sq_mutex); } if(mkm) From 47bc9b2d8f02d88ca24e145b208b2b282e7f1abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sun, 11 Mar 2012 18:13:05 +0100 Subject: [PATCH 4/6] Removed a call to pkt_ref_inc. I am not sure if this is OK or not. other parts of tvheadend don't seem to do it (like file recorder) so I guess it should work. --- src/webui/webui.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/webui/webui.c b/src/webui/webui.c index bcb75b66..2483c2be 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -175,7 +175,6 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq, th_subscription_t if(!mkm) break; - pkt_ref_inc(sm->sm_data); run = !mk_mux_write_pkt(mkm, sm->sm_data); sm->sm_data = NULL; From 36af656f2e4fc1d61dd4ab03857ac7ddea6ec7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sat, 10 Mar 2012 12:14:26 +0100 Subject: [PATCH 5/6] Fixed crash when subscribing to a channel or service would fail --- src/webui/webui.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/webui/webui.c b/src/webui/webui.c index 2483c2be..71122d00 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -376,11 +376,12 @@ http_stream_service(http_connection_t *hc, service_t *service) pthread_mutex_unlock(&global_lock); - http_stream_run(hc, &sq, s); - - pthread_mutex_lock(&global_lock); - subscription_unsubscribe(s); - pthread_mutex_unlock(&global_lock); + if(s) { + http_stream_run(hc, &sq, s); + pthread_mutex_lock(&global_lock); + subscription_unsubscribe(s); + pthread_mutex_unlock(&global_lock); + } globalheaders_destroy(gh); tsfix_destroy(tsfix); @@ -411,11 +412,12 @@ http_stream_channel(http_connection_t *hc, channel_t *ch) 0); pthread_mutex_unlock(&global_lock); - http_stream_run(hc, &sq, s); - - pthread_mutex_lock(&global_lock); - subscription_unsubscribe(s); - pthread_mutex_unlock(&global_lock); + if(s) { + http_stream_run(hc, &sq, s); + pthread_mutex_lock(&global_lock); + subscription_unsubscribe(s); + pthread_mutex_unlock(&global_lock); + } globalheaders_destroy(gh); tsfix_destroy(tsfix); From cac15666af2f60133c8fd376b9d28b98af0abb6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sun, 11 Mar 2012 18:29:49 +0100 Subject: [PATCH 6/6] Cosmetics --- src/webui/webui.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/webui/webui.c b/src/webui/webui.c index 71122d00..9aefb0a5 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -155,9 +155,10 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq, th_subscription_t //Check socket status getsockopt(hc->hc_fd, SOL_SOCKET, SO_ERROR, (char *)&err, &errlen); - - //Abort upon socket error, or after 20 seconds of silence - if(err || timeouts >= 20) { + if(err) { + tvhlog(LOG_DEBUG, "webui", "Client hung up, exit streaming"); + run = 0; + }else if(timeouts >= 20) { tvhlog(LOG_WARNING, "webui", "Timeout waiting for packets"); run = 0; }