diff --git a/src/dvr/dvr.h b/src/dvr/dvr.h index 60df7840..9413a0c6 100644 --- a/src/dvr/dvr.h +++ b/src/dvr/dvr.h @@ -19,7 +19,6 @@ #ifndef DVR_H #define DVR_H -#include #include #include "epg.h" #include "channels.h" diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c index 1a35e2e3..003a1d85 100644 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -16,15 +16,13 @@ * along with this program. If not, see . */ +#include #include #include #include #include #include /* basename */ -#include -#include - #include "htsstr.h" #include "tvhead.h" @@ -192,7 +190,7 @@ pvr_generate_filename(dvr_entry_t *de) filename = strdup(de->de_ititle); cleanupfilename(filename); - av_strlcpy(path, dvr_storage, sizeof(path)); + snprintf(path, sizeof(path), "%s", dvr_storage); /* Append per-day directory */ diff --git a/src/dvr/mkmux.c b/src/dvr/mkmux.c index 223fca56..4e35d5b3 100644 --- a/src/dvr/mkmux.c +++ b/src/dvr/mkmux.c @@ -23,12 +23,14 @@ #include #include #include +#include #include "tvhead.h" #include "streaming.h" #include "dvr.h" #include "mkmux.h" #include "ebml.h" +#include "libavcodec/avcodec.h" TAILQ_HEAD(mk_cue_queue, mk_cue); @@ -176,7 +178,7 @@ mk_build_tracks(mk_mux_t *mkm, const struct streaming_start *ss) mkm->tracks[i].index = ssc->ssc_index; mkm->tracks[i].type = ssc->ssc_type; - mkm->tracks[i].nextpts = AV_NOPTS_VALUE; + mkm->tracks[i].nextpts = PTS_UNSET; switch(ssc->ssc_type) { case SCT_MPEG2VIDEO: @@ -572,11 +574,11 @@ mk_write_frame_i(mk_mux_t *mkm, mk_track *t, th_pkt_t *pkt) size_t len; const int clusersizemax = 2000000; - if(pts == AV_NOPTS_VALUE) + if(pts == PTS_UNSET) // This is our best guess, it might be wrong but... oh well pts = t->nextpts; - if(pts != AV_NOPTS_VALUE) { + if(pts != PTS_UNSET) { t->nextpts = pts + (pkt->pkt_duration >> pkt->pkt_field); nxt = av_rescale_q(t->nextpts, mpeg_tc, mkv_tc); diff --git a/src/htsp.c b/src/htsp.c index 8e3b4b65..de326cb2 100644 --- a/src/htsp.c +++ b/src/htsp.c @@ -45,6 +45,7 @@ #include "settings.h" #include +#include "libavcodec/avcodec.h" static void *htsp_server; @@ -1406,12 +1407,12 @@ htsp_stream_deliver(htsp_subscription_t *hs, th_pkt_t *pkt) htsmsg_add_u32(m, "com", pkt->pkt_commercial); - if(pkt->pkt_pts != AV_NOPTS_VALUE) { + if(pkt->pkt_pts != PTS_UNSET) { int64_t pts = av_rescale_q(pkt->pkt_pts, mpeg_tc, AV_TIME_BASE_Q); htsmsg_add_s64(m, "pts", pts); } - if(pkt->pkt_dts != AV_NOPTS_VALUE) { + if(pkt->pkt_dts != PTS_UNSET) { int64_t dts = av_rescale_q(pkt->pkt_dts, mpeg_tc, AV_TIME_BASE_Q); htsmsg_add_s64(m, "dts", dts); } @@ -1449,7 +1450,7 @@ htsp_stream_deliver(htsp_subscription_t *hs, th_pkt_t *pkt) htsmsg_add_s64(m, "delay", 0); } else if((hm = TAILQ_FIRST(&hs->hs_q.hmq_q)) != NULL && (n = hm->hm_msg) != NULL && !htsmsg_get_s64(n, "dts", &ts) && - pkt->pkt_dts != AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE) { + pkt->pkt_dts != PTS_UNSET && ts != PTS_UNSET) { htsmsg_add_s64(m, "delay", pkt->pkt_dts - ts); } pthread_mutex_unlock(&htsp->htsp_out_mutex); diff --git a/src/iptv_input.c b/src/iptv_input.c index 60f22802..ef7ae143 100644 --- a/src/iptv_input.c +++ b/src/iptv_input.c @@ -33,8 +33,6 @@ #include #include -//#include - #include "tvhead.h" #include "htsmsg.h" #include "channels.h" diff --git a/src/main.c b/src/main.c index 703e9921..b66ce193 100644 --- a/src/main.c +++ b/src/main.c @@ -35,8 +35,6 @@ #include #include -#include - #include "tvhead.h" #include "tcp.h" #include "access.h" @@ -360,8 +358,6 @@ main(int argc, char **argv) /** * Initialize subsystems */ - av_register_all(); - xmltv_init(); /* Must be initialized before channels */ transport_init(); diff --git a/src/packet.c b/src/packet.c index e8089082..9231a6e0 100644 --- a/src/packet.c +++ b/src/packet.c @@ -46,7 +46,7 @@ pkt_alloc(const void *data, size_t datalen, int64_t pts, int64_t dts) pkt = calloc(1, sizeof(th_pkt_t)); pkt->pkt_payloadlen = datalen; if(datalen > 0) { - pkt->pkt_payload = malloc(datalen + FF_INPUT_BUFFER_PADDING_SIZE); + pkt->pkt_payload = malloc(datalen); if(data != NULL) memcpy(pkt->pkt_payload, data, datalen); } @@ -123,7 +123,7 @@ pkt_merge_global(th_pkt_t *pkt) n->pkt_payloadlen = pkt->pkt_globaldata_len + pkt->pkt_payloadlen; - n->pkt_payload = malloc(n->pkt_payloadlen + FF_INPUT_BUFFER_PADDING_SIZE); + n->pkt_payload = malloc(n->pkt_payloadlen); memcpy(n->pkt_payload, pkt->pkt_globaldata, pkt->pkt_globaldata_len); memcpy(n->pkt_payload + pkt->pkt_globaldata_len, pkt->pkt_payload, pkt->pkt_payloadlen); @@ -147,14 +147,12 @@ pkt_copy(th_pkt_t *pkt) n->pkt_refcount = 1; if(pkt->pkt_globaldata_len) { - n->pkt_globaldata = malloc(pkt->pkt_globaldata_len + - FF_INPUT_BUFFER_PADDING_SIZE); + n->pkt_globaldata = malloc(pkt->pkt_globaldata_len); memcpy(n->pkt_globaldata, pkt->pkt_globaldata, pkt->pkt_globaldata_len); } if(pkt->pkt_payloadlen) { - n->pkt_payload = malloc(pkt->pkt_payloadlen + - FF_INPUT_BUFFER_PADDING_SIZE); + n->pkt_payload = malloc(pkt->pkt_payloadlen); memcpy(n->pkt_payload, pkt->pkt_payload, pkt->pkt_payloadlen); } diff --git a/src/parser_latm.c b/src/parser_latm.c index 62e94425..d1a318f3 100644 --- a/src/parser_latm.c +++ b/src/parser_latm.c @@ -191,7 +191,7 @@ parse_latm_audio_mux_element(th_transport_t *t, th_stream_t *st, uint8_t *data, if(slot_len * 8 > remaining_bits(&bs)) return NULL; - if(st->st_curdts == AV_NOPTS_VALUE) + if(st->st_curdts == PTS_UNSET) return NULL; th_pkt_t *pkt = pkt_alloc(NULL, 0, st->st_curdts, st->st_curdts); diff --git a/src/parsers.c b/src/parsers.c index 1c25ad54..80110204 100644 --- a/src/parsers.c +++ b/src/parsers.c @@ -76,7 +76,7 @@ getpts(const uint8_t *p) } else { // Marker bits not present - return AV_NOPTS_VALUE; + return PTS_UNSET; } } @@ -458,7 +458,7 @@ makeapkt(th_transport_t *t, th_stream_t *st, const void *buf, parser_deliver(t, st, pkt); - st->st_curdts = AV_NOPTS_VALUE; + st->st_curdts = PTS_UNSET; st->st_nextdts = dts + duration; } @@ -506,10 +506,10 @@ parse_mpa(th_transport_t *t, th_stream_t *st, size_t ilen, int duration = 90000 * 1152 / sr; int64_t dts = st->st_curdts; - if(dts == AV_NOPTS_VALUE) + if(dts == PTS_UNSET) dts = st->st_nextdts; - if(dts != AV_NOPTS_VALUE && + if(dts != PTS_UNSET && len >= i + fsize + 4 && mpa_valid_frame(buf + i + fsize)) { @@ -637,10 +637,10 @@ parse_ac3(th_transport_t *t, th_stream_t *st, size_t ilen, int duration = 90000 * 1536 / sr; int64_t dts = st->st_curdts; - if(dts == AV_NOPTS_VALUE) + if(dts == PTS_UNSET) dts = st->st_nextdts; - if(dts != AV_NOPTS_VALUE && + if(dts != PTS_UNSET && len >= i + fsize + 6 && ac3_valid_frame(buf + i + fsize)) { makeapkt(t, st, buf + i, fsize, dts, duration); @@ -684,7 +684,7 @@ parse_pes_header(th_transport_t *t, th_stream_t *st, d = (pts - dts) & PTS_MASK; if(d > 180000) // More than two seconds of PTS/DTS delta, probably corrupt - pts = dts = AV_NOPTS_VALUE; + pts = dts = PTS_UNSET; } else if((flags & 0xc0) == 0x80) { if(hlen < 5) @@ -695,8 +695,8 @@ parse_pes_header(th_transport_t *t, th_stream_t *st, return hlen + 3; if(st->st_buffer_errors) { - st->st_curdts = AV_NOPTS_VALUE; - st->st_curpts = AV_NOPTS_VALUE; + st->st_curdts = PTS_UNSET; + st->st_curpts = PTS_UNSET; } else { st->st_curdts = dts; st->st_curpts = pts; @@ -704,8 +704,8 @@ parse_pes_header(th_transport_t *t, th_stream_t *st, return hlen + 3; err: - st->st_curdts = AV_NOPTS_VALUE; - st->st_curpts = AV_NOPTS_VALUE; + st->st_curdts = PTS_UNSET; + st->st_curpts = PTS_UNSET; limitedlog(&st->st_loglimit_pes, "TS", transport_component_nicename(st), "Corrupted PES header"); return -1; @@ -835,9 +835,7 @@ parser_global_data_move(th_stream_t *st, const uint8_t *data, size_t len) int len2 = drop_trailing_zeroes(data, len); st->st_global_data = realloc(st->st_global_data, - st->st_global_data_len + len2 + - FF_INPUT_BUFFER_PADDING_SIZE); - + st->st_global_data_len + len2); memcpy(st->st_global_data + st->st_global_data_len, data, len2); st->st_global_data_len += len2; @@ -944,11 +942,11 @@ parse_mpeg2video(th_transport_t *t, th_stream_t *st, size_t len, st->st_buffer = malloc(st->st_buffer_size); /* If we know the frame duration, increase DTS accordingly */ - if(st->st_curdts != AV_NOPTS_VALUE) + if(st->st_curdts != PTS_UNSET) st->st_curdts += st->st_frame_duration; /* PTS cannot be extrapolated (it's not linear) */ - st->st_curpts = AV_NOPTS_VALUE; + st->st_curpts = PTS_UNSET; return 1; } break; @@ -990,7 +988,7 @@ parse_h264(th_transport_t *t, th_stream_t *st, size_t len, if(len >= 9) parse_pes_header(t, st, buf + 6, len - 6); - if(st->st_prevdts != AV_NOPTS_VALUE && st->st_curdts != AV_NOPTS_VALUE) { + if(st->st_prevdts != PTS_UNSET && st->st_curdts != PTS_UNSET) { d = (st->st_curdts - st->st_prevdts) & 0x1ffffffffLL; if(d < 90000) @@ -1077,8 +1075,8 @@ parse_h264(th_transport_t *t, th_stream_t *st, size_t len, st->st_curpkt = NULL; st->st_buffer = malloc(st->st_buffer_size); - st->st_curdts = AV_NOPTS_VALUE; - st->st_curpts = AV_NOPTS_VALUE; + st->st_curdts = PTS_UNSET; + st->st_curpts = PTS_UNSET; } return 1; } diff --git a/src/plumbing/tsfix.c b/src/plumbing/tsfix.c index f56c38f9..f9cf8c30 100644 --- a/src/plumbing/tsfix.c +++ b/src/plumbing/tsfix.c @@ -96,8 +96,8 @@ tsfix_add_stream(tsfix_t *tf, int index, streaming_component_type_t type) tfs->tfs_type = type; tfs->tfs_index = index; - tfs->tfs_last_dts_norm = AV_NOPTS_VALUE; - tfs->tfs_last_dts_in = AV_NOPTS_VALUE; + tfs->tfs_last_dts_norm = PTS_UNSET; + tfs->tfs_last_dts_in = PTS_UNSET; tfs->tfs_dts_epoch = 0; LIST_INSERT_HEAD(&tf->tf_streams, tfs, tfs_link); @@ -121,7 +121,7 @@ tsfix_start(tsfix_t *tf, streaming_start_t *ss) TAILQ_INIT(&tf->tf_ptsq); - tf->tf_tsref = AV_NOPTS_VALUE; + tf->tf_tsref = PTS_UNSET; tf->tf_hasvideo = hasvideo; } @@ -148,7 +148,7 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) int checkts = SCT_ISAUDIO(tfs->tfs_type) || SCT_ISVIDEO(tfs->tfs_type); - if(tf->tf_tsref == AV_NOPTS_VALUE) { + if(tf->tf_tsref == PTS_UNSET) { pkt_ref_dec(pkt); return; } @@ -156,7 +156,7 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) /* Subtract the transport wide start offset */ dts = pkt->pkt_dts - tf->tf_tsref; - if(tfs->tfs_last_dts_norm == AV_NOPTS_VALUE) { + if(tfs->tfs_last_dts_norm == PTS_UNSET) { if(dts < 0) { /* Early packet with negative time stamp, drop those */ pkt_ref_dec(pkt); @@ -191,7 +191,7 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) dts += tfs->tfs_dts_epoch; tfs->tfs_last_dts_norm = dts; - if(pkt->pkt_pts != AV_NOPTS_VALUE) { + if(pkt->pkt_pts != PTS_UNSET) { /* Compute delta between PTS and DTS (and watch out for 33 bit wrap) */ int64_t ptsoff = (pkt->pkt_pts - pkt->pkt_dts) & PTS_MASK; @@ -286,7 +286,7 @@ static void compute_pts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) { // If PTS is missing, set it to DTS if not video - if(pkt->pkt_pts == AV_NOPTS_VALUE && !SCT_ISVIDEO(tfs->tfs_type)) { + if(pkt->pkt_pts == PTS_UNSET && !SCT_ISVIDEO(tfs->tfs_type)) { pkt->pkt_pts = pkt->pkt_dts; tsfixprintf("TSFIX: %-12s PTS set to %lld\n", streaming_component_type2txt(tfs->tfs_type), @@ -294,7 +294,7 @@ compute_pts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt) } /* PTS known and no other packets in queue, deliver at once */ - if(pkt->pkt_pts != AV_NOPTS_VALUE && TAILQ_FIRST(&tf->tf_ptsq) == NULL) + if(pkt->pkt_pts != PTS_UNSET && TAILQ_FIRST(&tf->tf_ptsq) == NULL) normalize_ts(tf, tfs, pkt); else recover_pts(tf, tfs, pkt); @@ -317,18 +317,18 @@ tsfix_input_packet(tsfix_t *tf, streaming_message_t *sm) } - if(tf->tf_tsref == AV_NOPTS_VALUE && + if(tf->tf_tsref == PTS_UNSET && (!tf->tf_hasvideo || (SCT_ISVIDEO(tfs->tfs_type) && pkt->pkt_frametype == PKT_I_FRAME))) { tf->tf_tsref = pkt->pkt_dts; tsfixprintf("reference clock set to %lld\n", tf->tf_tsref); } - if(pkt->pkt_dts == AV_NOPTS_VALUE) { + if(pkt->pkt_dts == PTS_UNSET) { int pdur = pkt->pkt_duration >> pkt->pkt_field; - if(tfs->tfs_last_dts_in == AV_NOPTS_VALUE) { + if(tfs->tfs_last_dts_in == PTS_UNSET) { pkt_ref_dec(pkt); return; } diff --git a/src/psi.c b/src/psi.c index 2496e766..c0cd9057 100644 --- a/src/psi.c +++ b/src/psi.c @@ -22,9 +22,6 @@ #include #include -#include -#include - #include "tvhead.h" #include "psi.h" #include "transports.h" @@ -1031,7 +1028,7 @@ psi_load_transport_settings(htsmsg_t *m, th_transport_t *t) st = transport_stream_create(t, pid, type); if((v = htsmsg_get_str(c, "language")) != NULL) - av_strlcpy(st->st_lang, v, 4); + snprintf(st->st_lang, 4, "%s", v); if(!htsmsg_get_u32(c, "position", &u32)) st->st_position = u32; diff --git a/src/rawtsinput.c b/src/rawtsinput.c index dc1d60a7..3c39e120 100644 --- a/src/rawtsinput.c +++ b/src/rawtsinput.c @@ -243,17 +243,17 @@ process_ts_packet(rawts_t *rt, uint8_t *tsb) } LIST_FOREACH(t, &rt->rt_transports, tht_group_link) { - pcr = AV_NOPTS_VALUE; + pcr = PTS_UNSET; ts_recv_packet1(t, tsb, &pcr); - if(pcr != AV_NOPTS_VALUE) { + if(pcr != PTS_UNSET) { if(rt->rt_pcr_pid == 0) rt->rt_pcr_pid = pid; if(rt->rt_pcr_pid == pid) { - if(t->tht_pcr_last != AV_NOPTS_VALUE && didsleep == 0) { + if(t->tht_pcr_last != PTS_UNSET && didsleep == 0) { struct timespec slp; int64_t delta = pcr - t->tht_pcr_last; diff --git a/src/transports.c b/src/transports.c index d659111d..dceb446b 100644 --- a/src/transports.c +++ b/src/transports.c @@ -63,12 +63,12 @@ stream_init(th_stream_t *st) st->st_cc_valid = 0; st->st_startcond = 0xffffffff; - st->st_curdts = AV_NOPTS_VALUE; - st->st_curpts = AV_NOPTS_VALUE; - st->st_prevdts = AV_NOPTS_VALUE; + st->st_curdts = PTS_UNSET; + st->st_curpts = PTS_UNSET; + st->st_prevdts = PTS_UNSET; - st->st_pcr_real_last = AV_NOPTS_VALUE; - st->st_pcr_last = AV_NOPTS_VALUE; + st->st_pcr_real_last = PTS_UNSET; + st->st_pcr_last = PTS_UNSET; st->st_pcr_drift = 0; st->st_pcr_recovery_fails = 0; } @@ -502,7 +502,7 @@ transport_create(const char *identifier, int type, int source_type) t->tht_source_type = source_type; t->tht_refcount = 1; t->tht_enabled = 1; - t->tht_pcr_last = AV_NOPTS_VALUE; + t->tht_pcr_last = PTS_UNSET; TAILQ_INIT(&t->tht_components); streaming_pad_init(&t->tht_streaming_pad); diff --git a/src/tsdemux.c b/src/tsdemux.c index 555d05fa..83f91fcf 100644 --- a/src/tsdemux.c +++ b/src/tsdemux.c @@ -125,8 +125,6 @@ ts_recv_packet0(th_transport_t *t, th_stream_t *st, const uint8_t *tsb) } } -static const AVRational mpeg_tc = {1, 90000}; - /** * Recover PCR * @@ -155,14 +153,14 @@ ts_extract_pcr(th_transport_t *t, th_stream_t *st, const uint8_t *tsb, real = getmonoclock(); - if(st->st_pcr_real_last != AV_NOPTS_VALUE) { + if(st->st_pcr_real_last != PTS_UNSET) { d = (real - st->st_pcr_real_last) - (pcr - st->st_pcr_last); if(d < -90000LL || d > 90000LL) { st->st_pcr_recovery_fails++; if(st->st_pcr_recovery_fails > 10) { st->st_pcr_recovery_fails = 0; - st->st_pcr_real_last = AV_NOPTS_VALUE; + st->st_pcr_real_last = PTS_UNSET; } return; } diff --git a/src/tvhead.h b/src/tvhead.h index 5d824f0f..7814b386 100644 --- a/src/tvhead.h +++ b/src/tvhead.h @@ -32,10 +32,10 @@ #include "avg.h" #include "hts_strtab.h" -#include - #include "redblack.h" +#define PTS_UNSET INT64_C(0x8000000000000000) + extern pthread_mutex_t global_lock; extern pthread_mutex_t ffmpeg_lock; extern pthread_mutex_t fork_lock; diff --git a/src/v4l.c b/src/v4l.c index 6d1d3308..0754079e 100644 --- a/src/v4l.c +++ b/src/v4l.c @@ -18,7 +18,7 @@ #include #include - +#include #include #include #include diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 94a1c117..18edc653 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -25,7 +25,6 @@ #include #include -#include #include "htsmsg.h" #include "htsmsg_json.h" diff --git a/src/webui/extjs_dvb.c b/src/webui/extjs_dvb.c index f17b4876..a4da7b74 100644 --- a/src/webui/extjs_dvb.c +++ b/src/webui/extjs_dvb.c @@ -25,7 +25,6 @@ #include #include -#include #include "htsmsg.h" #include "htsmsg_json.h" diff --git a/src/webui/extjs_v4l.c b/src/webui/extjs_v4l.c index ab817258..4b22e938 100644 --- a/src/webui/extjs_v4l.c +++ b/src/webui/extjs_v4l.c @@ -25,7 +25,6 @@ #include #include -#include #include "htsmsg.h" #include "htsmsg_json.h" diff --git a/src/webui/simpleui.c b/src/webui/simpleui.c index f2392c24..4fae2d8d 100644 --- a/src/webui/simpleui.c +++ b/src/webui/simpleui.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "tvhead.h" #include "http.h"