From: Jaroslav Kysela Date: Tue, 20 Jun 2017 12:36:36 +0000 (+0200) Subject: satip server: start streaming directly after SETUP, but RTCP only, fixes #4449 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7086200a02964dd9f9d88b3e9b779940762cd48;p=thirdparty%2Ftvheadend.git satip server: start streaming directly after SETUP, but RTCP only, fixes #4449 --- diff --git a/src/satip/rtp.c b/src/satip/rtp.c index c170cb900..c77bc772a 100644 --- a/src/satip/rtp.c +++ b/src/satip/rtp.c @@ -56,6 +56,7 @@ typedef struct satip_rtp_session { int fd_rtcp; int frontend; int source; + int allow_data; dvb_mux_conf_t dmc; mpegts_apids_t pids; TAILQ_HEAD(, satip_rtp_table) pmt_tables; @@ -388,13 +389,15 @@ satip_rtp_thread(void *aux) case SMT_MPEGTS: pb = sm->sm_data; subscription_add_bytes_out(subs, pktbuf_len(pb)); - pthread_mutex_lock(&rtp->lock); - if (tcp) - r = satip_rtp_tcp_loop(rtp, pktbuf_ptr(pb), pktbuf_len(pb)); - else - r = satip_rtp_loop(rtp, pktbuf_ptr(pb), pktbuf_len(pb)); - pthread_mutex_unlock(&rtp->lock); - if (r) fatal = 1; + if (atomic_get(&rtp->allow_data)) { + pthread_mutex_lock(&rtp->lock); + if (tcp) + r = satip_rtp_tcp_loop(rtp, pktbuf_ptr(pb), pktbuf_len(pb)); + else + r = satip_rtp_loop(rtp, pktbuf_ptr(pb), pktbuf_len(pb)); + pthread_mutex_unlock(&rtp->lock); + if (r) fatal = 1; + } break; case SMT_SIGNAL_STATUS: satip_rtp_signal_status(rtp, sm->sm_data); @@ -452,7 +455,7 @@ void satip_rtp_queue(void *id, th_subscription_t *subs, struct sockaddr_storage *peer, int port, int fd_rtp, int fd_rtcp, int frontend, int source, dvb_mux_conf_t *dmc, - mpegts_apids_t *pids, int perm_lock) + mpegts_apids_t *pids, int allow_data, int perm_lock) { satip_rtp_session_t *rtp = calloc(1, sizeof(*rtp)); int dscp; @@ -471,6 +474,7 @@ void satip_rtp_queue(void *id, th_subscription_t *subs, rtp->subs = subs; rtp->sq = sq; rtp->tcp_lock = tcp_lock; + atomic_set(&rtp->allow_data, allow_data); mpegts_pid_init(&rtp->pids); mpegts_pid_copy(&rtp->pids, pids); TAILQ_INIT(&rtp->pmt_tables); @@ -504,6 +508,17 @@ void satip_rtp_queue(void *id, th_subscription_t *subs, pthread_mutex_unlock(&satip_rtp_lock); } +void satip_rtp_allow_data(void *id) +{ + satip_rtp_session_t *rtp; + + pthread_mutex_lock(&satip_rtp_lock); + rtp = satip_rtp_find(id); + if (rtp) + atomic_set(&rtp->allow_data, 1); + pthread_mutex_unlock(&satip_rtp_lock); +} + void satip_rtp_update_pids(void *id, mpegts_apids_t *pids) { satip_rtp_session_t *rtp; diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c index 4f3bf87ef..94b433332 100644 --- a/src/satip/rtsp.c +++ b/src/satip/rtsp.c @@ -508,6 +508,7 @@ rtsp_start dvb_mux_conf_t dmc; char buf[384]; int res = HTTP_STATUS_NOT_ALLOWED, qsize = 3000000, created = 0, weight; + int osetup = setup; pthread_mutex_lock(&global_lock); weight = satip_server_conf.satip_weight; @@ -588,8 +589,9 @@ rtsp_start goto endclean; if (!rs->pids.all && rs->pids.count == 0) mpegts_pid_add(&rs->pids, 0, MPS_WEIGHT_RAW); + /* trigger play when first SETUP arrived */ /* retrigger play when new setup arrived */ - if (oldstate) { + if (oldstate != STATE_DESCRIBE || setup) { setup = 0; rs->state = STATE_SETUP; } @@ -614,13 +616,15 @@ pids: rs->udp_rtp ? rs->udp_rtp->fd : hc->hc_fd, rs->udp_rtcp ? rs->udp_rtcp->fd : -1, rs->frontend, rs->findex, &rs->dmc_tuned, - &rs->pids, rs->perm_lock); + &rs->pids, osetup == 0, rs->perm_lock); rs->tcp_data = rs->udp_rtp ? NULL : hc; if (!rs->pids.all && rs->pids.count == 0) mpegts_pid_add(&rs->pids, 0, MPS_WEIGHT_RAW); svc = (mpegts_service_t *)rs->subs->ths_raw_service; svc->s_update_pids(svc, &rs->pids); rs->state = STATE_PLAY; + } else if (osetup == 0) { + satip_rtp_allow_data((void *)(intptr_t)rs->stream); } rtsp_manage_descramble(rs); pthread_mutex_unlock(&global_lock); diff --git a/src/satip/server.h b/src/satip/server.h index fd07c59fb..2219b9a16 100644 --- a/src/satip/server.h +++ b/src/satip/server.h @@ -70,13 +70,15 @@ void satip_rtp_queue(void *id, th_subscription_t *subs, int fd_rtp, int fd_rtcp, int frontend, int source, dvb_mux_conf_t *dmc, - mpegts_apids_t *pids, int perm_lock); + mpegts_apids_t *pids, + int allow_data, int perm_lock); void satip_rtp_update(void *id, th_subscription_t *subs, streaming_queue_t *sq, int frontend, int source, dvb_mux_conf_t *dmc, mpegts_apids_t *pids, mpegts_apids_t *pmt_pids); +void satip_rtp_allow_data(void *id); void satip_rtp_update_pids(void *id, mpegts_apids_t *pids); void satip_rtp_update_pmt_pids(void *id, mpegts_apids_t *pmt_pids); int satip_rtp_status(void *id, char *buf, int len);