#ifndef DVR_H
#define DVR_H
-#include <libavformat/avformat.h>
#include <regex.h>
#include "epg.h"
#include "channels.h"
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdarg.h>
#include <pthread.h>
#include <assert.h>
#include <string.h>
#include <sys/stat.h>
#include <libgen.h> /* basename */
-#include <libavutil/avstring.h>
-#include <libavcodec/avcodec.h>
-
#include "htsstr.h"
#include "tvhead.h"
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 */
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
+#include <string.h>
#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);
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:
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);
#include "settings.h"
#include <sys/time.h>
+#include "libavcodec/avcodec.h"
static void *htsp_server;
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);
}
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);
#include <errno.h>
#include <linux/netdevice.h>
-//#include <libavutil/avstring.h>
-
#include "tvhead.h"
#include "htsmsg.h"
#include "channels.h"
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <libavformat/avformat.h>
-
#include "tvhead.h"
#include "tcp.h"
#include "access.h"
/**
* Initialize subsystems
*/
- av_register_all();
-
xmltv_init(); /* Must be initialized before channels */
transport_init();
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);
}
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);
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);
}
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);
} else {
// Marker bits not present
- return AV_NOPTS_VALUE;
+ return PTS_UNSET;
}
}
parser_deliver(t, st, pkt);
- st->st_curdts = AV_NOPTS_VALUE;
+ st->st_curdts = PTS_UNSET;
st->st_nextdts = dts + duration;
}
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)) {
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);
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)
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;
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;
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;
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;
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)
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;
}
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);
TAILQ_INIT(&tf->tf_ptsq);
- tf->tf_tsref = AV_NOPTS_VALUE;
+ tf->tf_tsref = PTS_UNSET;
tf->tf_hasvideo = hasvideo;
}
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;
}
/* 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);
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;
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),
}
/* 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);
}
- 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;
}
#include <stdlib.h>
#include <string.h>
-#include <libavutil/common.h>
-#include <libavutil/avstring.h>
-
#include "tvhead.h"
#include "psi.h"
#include "transports.h"
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;
}
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;
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;
}
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);
}
}
-static const AVRational mpeg_tc = {1, 90000};
-
/**
* Recover PCR
*
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;
}
#include "avg.h"
#include "hts_strtab.h"
-#include <libavcodec/avcodec.h>
-
#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;
#include <assert.h>
#include <pthread.h>
-
+#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <arpa/inet.h>
-#include <libavutil/avstring.h>
#include "htsmsg.h"
#include "htsmsg_json.h"
#include <stdarg.h>
#include <arpa/inet.h>
-#include <libavutil/avstring.h>
#include "htsmsg.h"
#include "htsmsg_json.h"
#include <stdarg.h>
#include <arpa/inet.h>
-#include <libavutil/avstring.h>
#include "htsmsg.h"
#include "htsmsg_json.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include "tvhead.h"
#include "http.h"