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) diff --git a/src/webui/webui.c b/src/webui/webui.c index ed69ebdf..9aefb0a5 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -155,10 +155,12 @@ 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){ - run = 0; + 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; } } pthread_mutex_unlock(&sq->sq_mutex); @@ -167,13 +169,13 @@ 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: { if(!mkm) break; - pkt_ref_inc(sm->sm_data); run = !mk_mux_write_pkt(mkm, sm->sm_data); sm->sm_data = NULL; @@ -219,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) @@ -376,11 +377,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 +413,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);