+++ /dev/null
-diff -ur tvheadend-4.0.8.orig/src/plumbing/transcoding.c tvheadend-4.0.8/src/plumbing/transcoding.c
---- tvheadend-4.0.8.orig/src/plumbing/transcoding.c 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/src/plumbing/transcoding.c 2016-04-16 19:53:13.907273675 +0200
-@@ -592,10 +597,10 @@
- // Convert audio
- tvhtrace("transcode", "%04X: converting audio", shortid(t));
-
-- tvhtrace("transcode", "%04X: IN : channels=%d, layout=%" PRIi64 ", rate=%d, fmt=%d, bitrate=%d",
-+ tvhtrace("transcode", "%04X: IN : channels=%d, layout=%" PRIi64 ", rate=%d, fmt=%d, bitrate=%lld",
- shortid(t), ictx->channels, ictx->channel_layout, ictx->sample_rate,
- ictx->sample_fmt, ictx->bit_rate);
-- tvhtrace("transcode", "%04X: OUT: channels=%d, layout=%" PRIi64 ", rate=%d, fmt=%d, bitrate=%d",
-+ tvhtrace("transcode", "%04X: OUT: channels=%d, layout=%" PRIi64 ", rate=%d, fmt=%d, bitrate=%lld",
- shortid(t), octx->channels, octx->channel_layout, octx->sample_rate,
- octx->sample_fmt, octx->bit_rate);
-
+++ /dev/null
-diff -ur tvheadend-4.0.8.orig/src/plumbing/transcoding.c tvheadend-4.0.8/src/plumbing/transcoding.c
---- tvheadend-4.0.8.orig/src/plumbing/transcoding.c 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/src/plumbing/transcoding.c 2016-04-16 19:53:13.907273675 +0200
-@@ -592,10 +597,10 @@
- // Convert audio
- tvhtrace("transcode", "%04X: converting audio", shortid(t));
-
-- tvhtrace("transcode", "%04X: IN : channels=%d, layout=%" PRIi64 ", rate=%d, fmt=%d, bitrate=%d",
-+ tvhtrace("transcode", "%04X: IN : channels=%d, layout=%" PRIi64 ", rate=%d, fmt=%d, bitrate=%ld",
- shortid(t), ictx->channels, ictx->channel_layout, ictx->sample_rate,
- ictx->sample_fmt, ictx->bit_rate);
-- tvhtrace("transcode", "%04X: OUT: channels=%d, layout=%" PRIi64 ", rate=%d, fmt=%d, bitrate=%d",
-+ tvhtrace("transcode", "%04X: OUT: channels=%d, layout=%" PRIi64 ", rate=%d, fmt=%d, bitrate=%ld",
- shortid(t), octx->channels, octx->channel_layout, octx->sample_rate,
- octx->sample_fmt, octx->bit_rate);
-
+++ /dev/null
-diff -ur tvheadend-4.0.8.orig/configure tvheadend-4.0.8/configure
---- tvheadend-4.0.8.orig/configure 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/configure 2016-04-16 19:41:41.685840403 +0200
-@@ -395,7 +395,7 @@
- has_libav=false
- fi
-
-- if $has_libav && ! check_pkg libswscale ">=2.3.100"; then
-+ if $has_libav && ! check_pkg libavfilter ">=4.0.0"; then
- has_libav=false
- fi
-
-@@ -421,7 +421,7 @@
- has_libav=false
- fi
-
-- if $has_libav && ! check_pkg libswscale ">=2.1.2"; then
-+ if $has_libav && ! check_pkg libavfilter ">=4.0.0"; then
- has_libav=false
- fi
-
-diff -ur tvheadend-4.0.8.orig/Makefile tvheadend-4.0.8/Makefile
---- tvheadend-4.0.8.orig/Makefile 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/Makefile 2016-04-16 19:41:41.685840403 +0200
-@@ -60,7 +60,7 @@
- LDFLAGS_FFDIR = ${ROOTDIR}/libav_static/build/ffmpeg/lib
- LDFLAGS += ${LDFLAGS_FFDIR}/libavresample.a
- LDFLAGS += ${LDFLAGS_FFDIR}/libswresample.a
--LDFLAGS += ${LDFLAGS_FFDIR}/libswscale.a
-+LDFLAGS += ${LDFLAGS_FFDIR}/libavfilter.a
- LDFLAGS += ${LDFLAGS_FFDIR}/libavutil.a
- LDFLAGS += ${LDFLAGS_FFDIR}/libavformat.a
- LDFLAGS += ${LDFLAGS_FFDIR}/libavcodec.a
-diff -ur tvheadend-4.0.8.orig/Makefile.ffmpeg tvheadend-4.0.8/Makefile.ffmpeg
---- tvheadend-4.0.8.orig/Makefile.ffmpeg 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/Makefile.ffmpeg 2016-04-16 19:41:41.685840403 +0200
-@@ -60,7 +60,7 @@
- FFMPEG_SHA1 = 65470c9b967485f72f81758a7bad44cf7a1763db
-
- EXTLIBS = libx264 libvorbis libvpx
--COMPONENTS = avutil avformat avcodec swresample swscale avresample
-+COMPONENTS = avutil avformat avcodec swresample avfilter avresample
- PROTOCOLS = file
- DECODERS = mpeg2video mp2 ac3 eac3 h264 h264_vdpau aac aac_latm vorbis libvorbis
- ENCODERS = mpeg2video mp2 libx264 libvpx_vp8 libvpx_vp9 aac libaacplus vorbis libvorbis
-diff -ur tvheadend-4.0.8.orig/src/libav.c tvheadend-4.0.8/src/libav.c
---- tvheadend-4.0.8.orig/src/libav.c 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/src/libav.c 2016-04-16 19:44:03.666521276 +0200
-@@ -186,4 +186,5 @@
- av_log_set_callback(libav_log_callback);
- av_log_set_level(AV_LOG_VERBOSE);
- av_register_all();
-+ avfilter_register_all();
- }
-diff -ur tvheadend-4.0.8.orig/src/libav.h tvheadend-4.0.8/src/libav.h
---- tvheadend-4.0.8.orig/src/libav.h 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/src/libav.h 2016-04-16 19:41:41.685840403 +0200
-@@ -21,6 +21,7 @@
-
-
- #include <libavformat/avformat.h>
-+#include <libavfilter/avfilter.h>
- #include "tvheadend.h"
-
- /*
-diff -ur tvheadend-4.0.8.orig/src/plumbing/transcoding.c tvheadend-4.0.8/src/plumbing/transcoding.c
---- tvheadend-4.0.8.orig/src/plumbing/transcoding.c 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/src/plumbing/transcoding.c 2016-04-16 19:53:13.907273675 +0200
-@@ -19,12 +19,14 @@
- #include <unistd.h>
- #include <libavformat/avformat.h>
- #include <libavcodec/avcodec.h>
--#include <libswscale/swscale.h>
-+#include <libavfilter/avfiltergraph.h>
-+#include <libavfilter/buffersink.h>
-+#include <libavfilter/buffersrc.h>
-+#include <libavutil/opt.h>
- #include <libavresample/avresample.h>
- #include <libavutil/opt.h>
- #include <libavutil/audio_fifo.h>
- #include <libavutil/dict.h>
--#include <libavutil/audioconvert.h>
-
- #if LIBAVUTIL_VERSION_MICRO >= 100 /* FFMPEG */
- #define USING_FFMPEG 1
-@@ -91,9 +93,12 @@
- AVCodec *vid_ocodec;
-
- AVFrame *vid_dec_frame;
-- struct SwsContext *vid_scaler;
- AVFrame *vid_enc_frame;
-
-+ AVFilterGraph *flt_graph;
-+ AVFilterContext *flt_bufsrcctx;
-+ AVFilterContext *flt_bufsinkctx;
-+
- int16_t vid_width;
- int16_t vid_height;
-
-@@ -952,6 +957,114 @@
-
- }
-
-+/* create a simple deinterlacer-scaler video filter chain */
-+static int
-+create_video_filter(video_stream_t *vs, transcoder_t *t,
-+ AVCodecContext *ictx, AVCodecContext *octx)
-+{
-+ AVFilterInOut *flt_inputs, *flt_outputs;
-+ AVFilter *flt_bufsrc, *flt_bufsink;
-+ char opt[128];
-+ int err;
-+
-+ err = 1;
-+ flt_inputs = flt_outputs = NULL;
-+ flt_bufsrc = flt_bufsink = NULL;
-+
-+ if (vs->flt_graph)
-+ avfilter_graph_free(&vs->flt_graph);
-+
-+ vs->flt_graph = avfilter_graph_alloc();
-+ if (!vs->flt_graph)
-+ return err;
-+
-+ flt_inputs = avfilter_inout_alloc();
-+ if (!flt_inputs)
-+ goto out_err;
-+
-+ flt_outputs = avfilter_inout_alloc();
-+ if (!flt_outputs)
-+ goto out_err;
-+
-+ flt_bufsrc = avfilter_get_by_name("buffer");
-+ flt_bufsink = avfilter_get_by_name("buffersink");
-+ if (!flt_bufsrc || !flt_bufsink) {
-+ tvherror("transcode", "%04X: libav default buffers unknown", shortid(t));
-+ goto out_err;
-+ }
-+
-+ memset(opt, 0, sizeof(opt));
-+ snprintf(opt, sizeof(opt), "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
-+ ictx->width,
-+ ictx->height,
-+ ictx->pix_fmt,
-+ ictx->time_base.num,
-+ ictx->time_base.den,
-+ ictx->sample_aspect_ratio.num,
-+ ictx->sample_aspect_ratio.den);
-+
-+ err = avfilter_graph_create_filter(&vs->flt_bufsrcctx, flt_bufsrc, "in",
-+ opt, NULL, vs->flt_graph);
-+ if (err < 0) {
-+ tvherror("transcode", "%04X: fltchain IN init error", shortid(t));
-+ goto out_err;
-+ }
-+
-+ err = avfilter_graph_create_filter(&vs->flt_bufsinkctx, flt_bufsink,
-+ "out", NULL, NULL, vs->flt_graph);
-+ if (err < 0) {
-+ tvherror("transcode", "%04X: fltchain OUT init error", shortid(t));
-+ goto out_err;
-+ }
-+
-+ flt_outputs->name = av_strdup("in");
-+ flt_outputs->filter_ctx = vs->flt_bufsrcctx;
-+ flt_outputs->pad_idx = 0;
-+ flt_outputs->next = NULL;
-+ flt_inputs->name = av_strdup("out");
-+ flt_inputs->filter_ctx = vs->flt_bufsinkctx;
-+ flt_inputs->pad_idx = 0;
-+ flt_inputs->next = NULL;
-+
-+ /* add filters: yadif to deinterlace and a scaler */
-+ memset(opt, 0, sizeof(opt));
-+ snprintf(opt, sizeof(opt), "yadif,scale=%dx%d",
-+ octx->width,
-+ octx->height);
-+ err = avfilter_graph_parse_ptr(vs->flt_graph,
-+ opt,
-+ &flt_inputs,
-+ &flt_outputs,
-+ NULL);
-+ if (err < 0) {
-+ tvherror("transcode", "%04X: failed to init filter chain", shortid(t));
-+ goto out_err;
-+ }
-+
-+ err = avfilter_graph_config(vs->flt_graph, NULL);
-+ if (err < 0) {
-+ tvherror("transcode", "%04X: failed to config filter chain", shortid(t));
-+ goto out_err;
-+ }
-+
-+ avfilter_inout_free(&flt_inputs);
-+ avfilter_inout_free(&flt_outputs);
-+
-+ return 0; /* all OK */
-+
-+out_err:
-+ if (flt_inputs)
-+ avfilter_inout_free(&flt_inputs);
-+ if (flt_outputs)
-+ avfilter_inout_free(&flt_outputs);
-+ if (vs->flt_graph) {
-+ avfilter_graph_free(&vs->flt_graph);
-+ vs->flt_graph = NULL;
-+ }
-+
-+ return err;
-+}
-+
- /**
- *
- */
-@@ -962,9 +1075,7 @@
- AVCodecContext *ictx, *octx;
- AVDictionary *opts;
- AVPacket packet, packet2;
-- AVPicture deint_pic;
-- uint8_t *buf, *deint;
-- int length, len, ret, got_picture, got_output, got_ref;
-+ int length, ret, got_picture, got_output, got_ref;
- video_stream_t *vs = (video_stream_t*)ts;
- streaming_message_t *sm;
- th_pkt_t *pkt2;
-@@ -980,7 +1091,6 @@
- icodec = vs->vid_icodec;
- ocodec = vs->vid_ocodec;
-
-- buf = deint = NULL;
- opts = NULL;
-
- got_ref = 0;
-@@ -1061,7 +1171,7 @@
- switch (ts->ts_type) {
- case SCT_MPEG2VIDEO:
- octx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
-- octx->pix_fmt = PIX_FMT_YUV420P;
-+ octx->pix_fmt = AV_PIX_FMT_YUV420P;
- octx->flags |= CODEC_FLAG_GLOBAL_HEADER;
-
- // Default settings for quantizer. Best quality unless changed by the streaming profile.
-@@ -1089,7 +1199,7 @@
-
- case SCT_VP8:
- octx->codec_id = AV_CODEC_ID_VP8;
-- octx->pix_fmt = PIX_FMT_YUV420P;
-+ octx->pix_fmt = AV_PIX_FMT_YUV420P;
-
- av_dict_set(&opts, "quality", "realtime", 0);
-
-@@ -1120,7 +1230,7 @@
-
- case SCT_H264:
- octx->codec_id = AV_CODEC_ID_H264;
-- octx->pix_fmt = PIX_FMT_YUV420P;
-+ octx->pix_fmt = AV_PIX_FMT_YUV420P;
- octx->flags |= CODEC_FLAG_GLOBAL_HEADER;
-
- // Qscale difference between I-frames and P-frames.
-@@ -1177,79 +1287,53 @@
- transcoder_stream_invalidate(ts);
- goto cleanup;
- }
-- }
-
-- len = avpicture_get_size(ictx->pix_fmt, ictx->width, ictx->height);
-- deint = av_malloc(len);
--
-- avpicture_fill(&deint_pic,
-- deint,
-- ictx->pix_fmt,
-- ictx->width,
-- ictx->height);
--
-- if (avpicture_deinterlace(&deint_pic,
-- (AVPicture *)vs->vid_dec_frame,
-- ictx->pix_fmt,
-- ictx->width,
-- ictx->height) < 0) {
-- tvherror("transcode", "%04X: Cannot deinterlace frame", shortid(t));
-- transcoder_stream_invalidate(ts);
-- goto cleanup;
-+ if (create_video_filter(vs, t, ictx, octx)) {
-+ tvherror("transcode", "%04X: Video filter creation failed",
-+ shortid(t));
-+ transcoder_stream_invalidate(ts);
-+ goto cleanup;
-+ }
- }
-
-- len = avpicture_get_size(octx->pix_fmt, octx->width, octx->height);
-- buf = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
-- memset(buf, 0, len);
--
-- avpicture_fill((AVPicture *)vs->vid_enc_frame,
-- buf,
-- octx->pix_fmt,
-- octx->width,
-- octx->height);
--
-- vs->vid_scaler = sws_getCachedContext(vs->vid_scaler,
-- ictx->width,
-- ictx->height,
-- ictx->pix_fmt,
-- octx->width,
-- octx->height,
-- octx->pix_fmt,
-- 1,
-- NULL,
-- NULL,
-- NULL);
--
-- if (sws_scale(vs->vid_scaler,
-- (const uint8_t * const*)deint_pic.data,
-- deint_pic.linesize,
-- 0,
-- ictx->height,
-- vs->vid_enc_frame->data,
-- vs->vid_enc_frame->linesize) < 0) {
-- tvherror("transcode", "%04X: Cannot scale frame", shortid(t));
-+ /* push decoded frame into filter chain */
-+ if (av_buffersrc_add_frame(vs->flt_bufsrcctx, vs->vid_dec_frame) < 0) {
-+ tvherror("transcode", "%04X: filter input error", shortid(t));
- transcoder_stream_invalidate(ts);
- goto cleanup;
- }
-
-- vs->vid_enc_frame->format = octx->pix_fmt;
-- vs->vid_enc_frame->width = octx->width;
-- vs->vid_enc_frame->height = octx->height;
--
-- vs->vid_enc_frame->pkt_pts = vs->vid_dec_frame->pkt_pts;
-- vs->vid_enc_frame->pkt_dts = vs->vid_dec_frame->pkt_dts;
--
-- if (vs->vid_dec_frame->reordered_opaque != AV_NOPTS_VALUE)
-- vs->vid_enc_frame->pts = vs->vid_dec_frame->reordered_opaque;
--
-- else if (ictx->coded_frame && ictx->coded_frame->pts != AV_NOPTS_VALUE)
-- vs->vid_enc_frame->pts = vs->vid_dec_frame->pts;
--
-- ret = avcodec_encode_video2(octx, &packet2, vs->vid_enc_frame, &got_output);
-- if (ret < 0) {
-- tvherror("transcode", "%04X: Error encoding frame", shortid(t));
-- transcoder_stream_invalidate(ts);
-- goto cleanup;
-+ /* and pull out a filtered frame */
-+ while (1) {
-+ ret = av_buffersink_get_frame(vs->flt_bufsinkctx, vs->vid_enc_frame);
-+ if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
-+ break;
-+ if (ret < 0) {
-+ tvherror("transcode", "%04X: filter output error", shortid(t));
-+ transcoder_stream_invalidate(ts);
-+ goto cleanup;
-+ }
-+
-+ vs->vid_enc_frame->format = octx->pix_fmt;
-+ vs->vid_enc_frame->width = octx->width;
-+ vs->vid_enc_frame->height = octx->height;
-+
-+ vs->vid_enc_frame->pkt_pts = vs->vid_dec_frame->pkt_pts;
-+ vs->vid_enc_frame->pkt_dts = vs->vid_dec_frame->pkt_dts;
-+
-+ if (vs->vid_dec_frame->reordered_opaque != AV_NOPTS_VALUE)
-+ vs->vid_enc_frame->pts = vs->vid_dec_frame->reordered_opaque;
-+
-+ else if (ictx->coded_frame && ictx->coded_frame->pts != AV_NOPTS_VALUE)
-+ vs->vid_enc_frame->pts = vs->vid_dec_frame->pts;
-+
-+ ret = avcodec_encode_video2(octx, &packet2, vs->vid_enc_frame, &got_output);
-+ if (ret < 0) {
-+ tvherror("transcode", "%04X: Error encoding frame", shortid(t));
-+ transcoder_stream_invalidate(ts);
-+ goto cleanup;
-+ }
-+ av_frame_unref(vs->vid_enc_frame);
- }
-
- if (got_output)
-@@ -1263,12 +1347,6 @@
-
- av_free_packet(&packet);
-
-- if(buf)
-- av_free(buf);
--
-- if(deint)
-- av_free(deint);
--
- if(opts)
- av_dict_free(&opts);
-
-@@ -1548,15 +1626,17 @@
- if(vs->vid_dec_frame)
- av_free(vs->vid_dec_frame);
-
-- if(vs->vid_scaler)
-- sws_freeContext(vs->vid_scaler);
--
- if(vs->vid_enc_frame)
- av_free(vs->vid_enc_frame);
-
- if (vs->vid_first_pkt)
- pkt_ref_dec(vs->vid_first_pkt);
-
-+ if (vs->flt_graph) {
-+ avfilter_graph_free(&vs->flt_graph);
-+ vs->flt_graph = NULL;
-+ }
-+
- free(ts);
- }
-
-@@ -1603,11 +1683,13 @@
- vs->vid_ictx->thread_count =
- vs->vid_octx->thread_count = transcoder_thread_count(t, sct);
-
-- vs->vid_dec_frame = avcodec_alloc_frame();
-- vs->vid_enc_frame = avcodec_alloc_frame();
-+ vs->vid_dec_frame = av_frame_alloc();
-+ vs->vid_enc_frame = av_frame_alloc();
-+
-+ av_frame_unref(vs->vid_dec_frame);
-+ av_frame_unref(vs->vid_enc_frame);
-
-- avcodec_get_frame_defaults(vs->vid_dec_frame);
-- avcodec_get_frame_defaults(vs->vid_enc_frame);
-+ vs->flt_graph = NULL; /* allocated in packet processor */
-
- LIST_INSERT_HEAD(&t->t_stream_list, (transcoder_stream_t*)vs, ts_link);
-
+++ /dev/null
---- tvheadend-4.0.8/src/muxer/muxer_libav.c~ 2015-12-16 18:33:33.000000000 +0100
-+++ tvheadend-4.0.8/src/muxer/muxer_libav.c 2018-04-29 19:32:22.156055706 +0200
-@@ -160,7 +160,7 @@
- }
-
- if(lm->lm_oc->oformat->flags & AVFMT_GLOBALHEADER)
-- c->flags |= CODEC_FLAG_GLOBAL_HEADER;
-+ c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
-
- return 0;
- }
---- tvheadend-4.0.8/src/plumbing/transcoding.c~ 2018-04-29 19:28:53.000000000 +0200
-+++ tvheadend-4.0.8/src/plumbing/transcoding.c 2018-04-29 19:33:35.763344908 +0200
-@@ -19,7 +19,7 @@
- #include <unistd.h>
- #include <libavformat/avformat.h>
- #include <libavcodec/avcodec.h>
--#include <libavfilter/avfiltergraph.h>
-+#include <libavfilter/avfilter.h>
- #include <libavfilter/buffersink.h>
- #include <libavfilter/buffersrc.h>
- #include <libavutil/opt.h>
-@@ -559,12 +559,12 @@
- break;
-
- case SCT_AAC:
-- octx->flags |= CODEC_FLAG_BITEXACT;
-+ octx->flags |= AV_CODEC_FLAG_BITEXACT;
- break;
-
- case SCT_VORBIS:
-- octx->flags |= CODEC_FLAG_QSCALE;
-- octx->flags |= CODEC_FLAG_GLOBAL_HEADER;
-+ octx->flags |= AV_CODEC_FLAG_QSCALE;
-+ octx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
- octx->global_quality = 4*FF_QP2LAMBDA;
- break;
-
-@@ -1172,7 +1172,7 @@
- case SCT_MPEG2VIDEO:
- octx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
- octx->pix_fmt = AV_PIX_FMT_YUV420P;
-- octx->flags |= CODEC_FLAG_GLOBAL_HEADER;
-+ octx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
-
- // Default settings for quantizer. Best quality unless changed by the streaming profile.
- octx->qmin = 1;
-@@ -1231,7 +1231,7 @@
- case SCT_H264:
- octx->codec_id = AV_CODEC_ID_H264;
- octx->pix_fmt = AV_PIX_FMT_YUV420P;
-- octx->flags |= CODEC_FLAG_GLOBAL_HEADER;
-+ octx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
-
- // Qscale difference between I-frames and P-frames.
- // Note: -i_qfactor is handled a little differently than --ipratio.
-@@ -1965,7 +1965,7 @@
- if (!WORKING_ENCODER(p->id))
- continue;
-
-- if ((p->capabilities & CODEC_CAP_EXPERIMENTAL) && !experimental)
-+ if ((p->capabilities & AV_CODEC_CAP_EXPERIMENTAL) && !experimental)
- continue;
-
- sct = codec_id2streaming_component_type(p->id);
-@@ -1978,7 +1978,7 @@
- htsmsg_add_str(m, "name", p->name);
- snprintf(buf, sizeof(buf), "%s%s",
- p->long_name ?: "",
-- (p->capabilities & CODEC_CAP_EXPERIMENTAL) ?
-+ (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ?
- " (Experimental)" : "");
- if (buf[0] != '\0')
- htsmsg_add_str(m, "long_name", buf);
--- /dev/null
+From 8bd059550c641fcaae3a360c527ada6ec74ce9e7 Mon Sep 17 00:00:00 2001
+From: Flole998 <Flole998@users.noreply.github.com>
+Date: Mon, 8 Jun 2020 21:43:18 +0200
+Subject: [PATCH] Allocate space for buf on heap (modified PR #1324)
+
+---
+ src/epggrab/module/xmltv.c | 7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c
+index 34ab05bdb7..d48bdbbb1e 100644
+--- a/src/epggrab/module/xmltv.c
++++ b/src/epggrab/module/xmltv.c
+@@ -197,11 +197,12 @@ static void parse_xmltv_dd_progid
+ (epggrab_module_t *mod, const char *s, char **uri, char **suri,
+ epg_episode_num_t *epnum)
+ {
+- char buf[128];
+ if (strlen(s) < 2) return;
+
++ const int buf_size = s_len + strlen(mod->id) + 13;
++ char * buf = (char *) malloc( buf_size);
+ /* Raw URI */
+- snprintf(buf, sizeof(buf)-1, "ddprogid://%s/%s", mod->id, s);
++ int e = snprintf( buf, buf_size, "ddprogid://%s/%s", mod->id, s);
+
+ /* SH - series without episode id so ignore */
+ if (strncmp("SH", s, 2))
+@@ -212,7 +213,7 @@ static void parse_xmltv_dd_progid
+ /* Episode */
+ if (!strncmp("EP", s, 2)) {
+ int e = strlen(buf)-1;
+- while (e && buf[e] != '.') e--;
++ while (--e && buf[e] != '.') {}
+ if (e) {
+ buf[e] = '\0';
+ *suri = strdup(buf);
+From e1031ce5d55275e1606643133b8168adcbe5f231 Mon Sep 17 00:00:00 2001
+From: Flole998 <Flole998@users.noreply.github.com>
+Date: Mon, 8 Jun 2020 21:46:22 +0200
+Subject: [PATCH] Allocate space for buf on heap (modified PR #1324)
+
+---
+ src/epggrab/module/xmltv.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c
+index d48bdbbb1e..fa36640f7e 100644
+--- a/src/epggrab/module/xmltv.c
++++ b/src/epggrab/module/xmltv.c
+@@ -197,7 +197,8 @@ static void parse_xmltv_dd_progid
+ (epggrab_module_t *mod, const char *s, char **uri, char **suri,
+ epg_episode_num_t *epnum)
+ {
+- if (strlen(s) < 2) return;
++ const int s_len = strlen(s);
++ if (s_len < 2) return;
+
+ const int buf_size = s_len + strlen(mod->id) + 13;
+ char * buf = (char *) malloc( buf_size);
+@@ -212,7 +213,6 @@ static void parse_xmltv_dd_progid
+
+ /* Episode */
+ if (!strncmp("EP", s, 2)) {
+- int e = strlen(buf)-1;
+ while (--e && buf[e] != '.') {}
+ if (e) {
+ buf[e] = '\0';
+From 51a4c5bec7b6fc69dab7b8d559f9b1b881f0eb8e Mon Sep 17 00:00:00 2001
+From: Flole998 <Flole998@users.noreply.github.com>
+Date: Wed, 10 Jun 2020 23:27:21 +0200
+Subject: [PATCH] Fix memory leak
+
+---
+ src/epggrab/module/xmltv.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c
+index fa36640f7e..6f09f3e18a 100644
+--- a/src/epggrab/module/xmltv.c
++++ b/src/epggrab/module/xmltv.c
+@@ -220,6 +220,7 @@ static void parse_xmltv_dd_progid
+ if (buf[e+1]) sscanf(&buf[e+1], "%hu", &(epnum->e_num));
+ }
+ }
++ free(buf);
+ }
+
+ /**
--- /dev/null
+From 1f2a0a59e3acaef88509d3ac899b905c73b7b8f8 Mon Sep 17 00:00:00 2001
+From: James Le Cuirot <chewi@gentoo.org>
+Date: Fri, 15 May 2020 17:45:30 +0100
+Subject: [PATCH] Fix building with -fno-common (default from GCC 10)
+
+---
+ src/input.h | 4 ++--
+ src/input/mpegts.c | 2 ++
+ src/input/mpegts.h | 2 +-
+ 3 files changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/src/input.h b/src/input.h
+index a9c96df04..3dce355c6 100644
+--- a/src/input.h
++++ b/src/input.h
+@@ -133,8 +133,8 @@ void tvh_hardware_delete ( tvh_hardware_t *th );
+ extern const idclass_t tvh_input_class;
+ extern const idclass_t tvh_input_instance_class;
+
+-tvh_input_list_t tvh_inputs;
+-tvh_hardware_list_t tvh_hardware;
++extern tvh_input_list_t tvh_inputs;
++extern tvh_hardware_list_t tvh_hardware;
+
+ #define TVH_INPUT_FOREACH(x) LIST_FOREACH(x, &tvh_inputs, ti_link)
+ #define TVH_HARDWARE_FOREACH(x) LIST_FOREACH(x, &tvh_hardware, th_link)
+diff --git a/src/input/mpegts.c b/src/input/mpegts.c
+index e02d491f1..fca4f3429 100644
+--- a/src/input/mpegts.c
++++ b/src/input/mpegts.c
+@@ -20,6 +20,8 @@
+ #include "mpegts/fastscan.h"
+ #include "memoryinfo.h"
+
++struct mpegts_listeners mpegts_listeners;
++
+ extern memoryinfo_t mpegts_input_queue_memoryinfo;
+ extern memoryinfo_t mpegts_input_table_memoryinfo;
+
+diff --git a/src/input/mpegts.h b/src/input/mpegts.h
+index 9dda3baca..9c4c57b73 100644
+--- a/src/input/mpegts.h
++++ b/src/input/mpegts.h
+@@ -1149,7 +1149,7 @@ typedef struct mpegts_listener
+ void (*ml_mux_delete) (mpegts_mux_t *mm, void *p);
+ } mpegts_listener_t;
+
+-LIST_HEAD(,mpegts_listener) mpegts_listeners;
++extern LIST_HEAD(mpegts_listeners, mpegts_listener) mpegts_listeners;
+
+ #define mpegts_add_listener(ml)\
+ LIST_INSERT_HEAD(&mpegts_listeners, ml, ml_link)
+--
+2.26.2
+
+++ /dev/null
---- tvheadend-4.0.8/Makefile~ 2018-04-29 19:28:53.000000000 +0200
-+++ tvheadend-4.0.8/Makefile 2018-04-29 19:31:17.392096527 +0200
-@@ -28,7 +28,7 @@
- #
-
- CFLAGS += -g -O2 -Wunused-result
--CFLAGS += -Wall -Werror -Wwrite-strings -Wno-deprecated-declarations
-+CFLAGS += -Wall -Wwrite-strings -Wno-deprecated-declarations
- CFLAGS += -Wmissing-prototypes
- CFLAGS += -fms-extensions -funsigned-char -fno-strict-aliasing
- CFLAGS += -D_FILE_OFFSET_BITS=64
--- /dev/null
+From 8de98367c223d9e2899acd787a8e2ce55b1a1c37 Mon Sep 17 00:00:00 2001
+From: Niels Ole Salscheider <niels_ole@salscheider-online.de>
+Date: Sun, 3 Feb 2019 11:01:01 +0100
+Subject: [PATCH] Replace strncpy with strlcpy
+
+Without this patch, tvheadend does not compile with GCC 8.
+---
+ src/plumbing/transcoding.c | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/src/plumbing/transcoding.c b/src/plumbing/transcoding.c
+index cf48f9b36c..6ff1665f8f 100644
+--- a/src/plumbing/transcoding.c
++++ b/src/plumbing/transcoding.c
+@@ -1804,7 +1804,7 @@ transcoder_init_video(transcoder_t *t, streaming_start_component_t *ssc)
+ char *str, *token, *saveptr, codec_list[sizeof(tp->tp_src_vcodec)];
+ int codec_match=0;
+
+- strncpy(codec_list, tp->tp_src_vcodec, sizeof(tp->tp_src_vcodec)-1);
++ strlcpy(codec_list, tp->tp_src_vcodec, sizeof(codec_list));
+
+ tvhtrace(LS_TRANSCODE, "src_vcodec=\"%s\" ssc_type=%d (%s)\n",
+ tp->tp_src_vcodec,
+@@ -2130,10 +2130,10 @@ transcoder_set_properties(streaming_target_t *st,
+ transcoder_t *t = (transcoder_t *)st;
+ transcoder_props_t *tp = &t->t_props;
+
+- strncpy(tp->tp_vcodec, props->tp_vcodec, sizeof(tp->tp_vcodec)-1);
+- strncpy(tp->tp_vcodec_preset, props->tp_vcodec_preset, sizeof(tp->tp_vcodec_preset)-1);
+- strncpy(tp->tp_acodec, props->tp_acodec, sizeof(tp->tp_acodec)-1);
+- strncpy(tp->tp_scodec, props->tp_scodec, sizeof(tp->tp_scodec)-1);
++ strlcpy(tp->tp_vcodec, props->tp_vcodec, sizeof(tp->tp_vcodec));
++ strlcpy(tp->tp_vcodec_preset, props->tp_vcodec_preset, sizeof(tp->tp_vcodec_preset));
++ strlcpy(tp->tp_acodec, props->tp_acodec, sizeof(tp->tp_acodec));
++ strlcpy(tp->tp_scodec, props->tp_scodec, sizeof(tp->tp_scodec));
+ tp->tp_channels = props->tp_channels;
+ tp->tp_vbitrate = props->tp_vbitrate;
+ tp->tp_abitrate = props->tp_abitrate;
+@@ -2141,7 +2141,7 @@ transcoder_set_properties(streaming_target_t *st,
+
+ memcpy(tp->tp_language, props->tp_language, 4);
+
+- strncpy(tp->tp_src_vcodec, props->tp_src_vcodec, sizeof(tp->tp_src_vcodec)-1);
++ strlcpy(tp->tp_src_vcodec, props->tp_src_vcodec, sizeof(tp->tp_src_vcodec));
+ }
+
+
+++ /dev/null
-{
- "enabled": 1,
- "username": "tvheadend",
- "password": "dummypassword",
- "comment": "Default access entry",
- "prefix": "0.0.0.0/0",
- "streaming": 1,
- "dvr": 1,
- "webui": 1,
- "admin": 1,
- "id": "1"
-}
+#
+# Conditional build:
+%bcond_without systemd # without systemd support
+
Summary: TV streaming server
Name: tvheadend
# https://tvheadend.org/projects/tvheadend/wiki/Releases
-Version: 4.0.8
-Release: 3
+Version: 4.2.8
+Release: 1
License: GPL v3
Group: Applications/Multimedia
Source0: https://github.com/tvheadend/tvheadend/archive/v%{version}/%{name}-%{version}.tar.gz
-# Source0-md5: dbb33a9b27a68749961f6aae700d9848
-Source1: %{name}.conf
-Source2: %{name}.service
-Source3: %{name}.sysconfig
-Source4: %{name}.init
-Patch0: x32.patch
-Patch1: ffmpeg3.patch
-Patch2: 64bit.patch
-Patch3: 32bit.patch
-Patch4: ffmpeg4.patch
-Patch5: no-Werror.patch
+# Source0-md5: b9571efa46dd489f9fe87acdb391d591
+Source1: %{name}.service
+Source2: %{name}.sysconfig
+Source3: %{name}.init
+Patch0: format-security.patch
+Patch1: strncpy.patch
+Patch2: gcc10.patch
+Patch3: x32.patch
URL: https://tvheadend.org/projects/tvheadend
BuildRequires: avahi-devel
-BuildRequires: curl-devel
-BuildRequires: ffmpeg-devel
-BuildRequires: python-modules
+BuildRequires: dbus-devel
+BuildRequires: ffmpeg-devel >= 3.0
+BuildRequires: gettext-tools
+BuildRequires: libdvbcsa-devel
+BuildRequires: openssl-devel
+BuildRequires: pkgconfig
+BuildRequires: python3-modules
BuildRequires: rpmbuild(macros) >= 1.647
+%{?with_systemd:BuildRequires: systemd-devel}
BuildRequires: uriparser-devel
BuildRequires: zlib-devel
-Requires(post): pwgen
Requires(post): sed >= 4.0
Requires(post,preun): /sbin/chkconfig
-Requires(post,preun,postun): systemd-units >= 38
+%{?with_systemd:Requires(post,preun,postun): systemd-units >= 38}
Requires(postun): /usr/sbin/userdel
Requires(pre): /bin/id
Requires(pre): /usr/sbin/useradd
Requires: setup
-Requires: systemd-units >= 0.38
+%{?with_systemd:Requires: systemd-units >= 0.38}
Provides: user(tvheadend)
BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
%setup -q
%patch0 -p1
%patch1 -p1
-%ifarch %{x8664}
%patch2 -p1
-%endif
-%ifarch %{ix86} x32
+%ifarch x32
%patch3 -p1
%endif
-%patch4 -p1
-%patch5 -p1
%build
export CFLAGS="%{rpmcflags}"
-export CC="%{__cc}"
+export LDFLAGS="%{rpmldflags}"
# tvheadend uses a custom script, so %%configure cannot be used
# as not all options are supported
./configure \
+ --cc="%{__cc}" \
--release \
--prefix=%{_prefix} \
--libdir=%{_libdir} \
--mandir=%{_mandir} \
- --disable-dvbscan
+ --python=%{__python3} \
+ --disable-dvbscan \
+ --disable-ffmpeg_static \
+ --disable-hdhomerun_static \
+ --disable-libfdkaac_static \
+ --disable-libmfx_static \
+ --disable-libtheora_static \
+ --disable-libvorbis_static \
+ --disable-libvpx_static \
+ --disable-libx264_static \
+ --disable-libx265_static \
+ %{!?with_systemd:--disable-libsystemd_daemon}
%{__make} V=1
%install
rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT%{_localstatedir}/lib/%{name}/.hts/%{name}/accesscontrol \
+install -d $RPM_BUILD_ROOT%{_localstatedir}/lib/%{name}/.hts/%{name} \
$RPM_BUILD_ROOT%{_localstatedir}/lib/%{name}/Videos \
- $RPM_BUILD_ROOT%{systemdunitdir} \
+ %{?with_systemd:$RPM_BUILD_ROOT%{systemdunitdir}} \
$RPM_BUILD_ROOT/etc/{rc.d/init.d,sysconfig}
%{__make} install \
- DESTDIR=$RPM_BUILD_ROOT
+ DESTDIR=$RPM_BUILD_ROOT \
+ V=1
-cp -p %{SOURCE1} $RPM_BUILD_ROOT%{_localstatedir}/lib/%{name}/.hts/%{name}/accesscontrol/1
-cp -p %{SOURCE2} $RPM_BUILD_ROOT%{systemdunitdir}/%{name}.service
-cp -p %{SOURCE3} $RPM_BUILD_ROOT/etc/sysconfig/%{name}
-install -p %{SOURCE4} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name}
+%{?with_systemd:cp -p %{SOURCE1} $RPM_BUILD_ROOT%{systemdunitdir}/%{name}.service}
+cp -p %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/%{name}
+install -p %{SOURCE3} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name}
chmod +x $RPM_BUILD_ROOT%{_bindir}/%{name}
%post
/sbin/chkconfig --add tvheadend
%service tvheadend reload "tvheadend"
-%systemd_post %{name}.service
-
-# check if the access control file still has the initial dummy password, and
-# replace the dummy password by a random, 12-character pwgen-generated password
-if grep -q '"password": "dummypassword"' %{_localstatedir}/lib/%{name}/.hts/%{name}/accesscontrol/1; then
- sed -i "s,\"password\": \"dummypassword\",\"password\": \"$(pwgen -s 12 1)\"," %{_localstatedir}/lib/%{name}/.hts/%{name}/accesscontrol/1
-fi
+%{?with_systemd:%systemd_post %{name}.service}
%preun
if [ "$1" = "0" ]; then
%service tvheadend stop
/sbin/chkconfig --del tvheadend
fi
-%systemd_preun %{name}.service
+%{?with_systemd:%systemd_preun %{name}.service}
%postun
if [ "$1" = "0" ]; then
%userremove tvheadend
fi
-%systemd_reload
+%{?with_systemd:%systemd_reload}
%files
%defattr(644,root,root,755)
%config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/%{name}
%{_mandir}/man1/%{name}.1*
%{_datadir}/%{name}
-%{systemdunitdir}/%{name}.service
+%{?with_systemd:%{systemdunitdir}/%{name}.service}
# home directory and config file
%dir %attr(755,tvheadend,root) %{_localstatedir}/lib/%{name}
%dir %attr(755,tvheadend,video) %{_localstatedir}/lib/%{name}/Videos
%dir %attr(750,tvheadend,video) %{_localstatedir}/lib/%{name}/.hts
%dir %attr(750,tvheadend,video) %{_localstatedir}/lib/%{name}/.hts/%{name}
-%dir %attr(750,tvheadend,video) %{_localstatedir}/lib/%{name}/.hts/%{name}/accesscontrol
-%attr(600,tvheadend,video) %config(noreplace) %verify(not md5 mtime size) %{_localstatedir}/lib/%{name}/.hts/%{name}/accesscontrol/1
#else
#define PRItime_t "ld"
#endif
---- tvheadend-4.0.2/src/descrambler/descrambler.c~ 2015-05-25 15:44:34.000000000 +0000
-+++ tvheadend-4.0.2/src/descrambler/descrambler.c 2015-07-16 20:09:10.140620617 +0000
-@@ -477,7 +477,7 @@
- (ki & 0x40) ? "odd" : "even",
- ((mpegts_service_t *)t)->s_dvb_svcname);
- if (key_late(dr, ki)) {
-- tvherror("descrambler", "ECM late (%ld seconds) for service \"%s\"",
-+ tvherror("descrambler", "ECM late (%"PRItime_t" seconds) for service \"%s\"",
- dispatch_clock - dr->dr_ecm_key_time,
- ((mpegts_service_t *)t)->s_dvb_svcname);
- if (ecm_reset(t, dr)) {
--- tvheadend-4.0.2/src/epggrab/otamux.c~ 2015-05-25 15:44:34.000000000 +0000
+++ tvheadend-4.0.2/src/epggrab/otamux.c 2015-07-16 20:10:34.961370520 +0000
@@ -592,7 +592,7 @@
static void
epggrab_ota_next_arm( time_t next )
{
-- tvhtrace("epggrab", "next ota start event in %li seconds", next - time(NULL));
-+ tvhtrace("epggrab", "next ota start event in %"PRItime_t" seconds", next - time(NULL));
- gtimer_arm_abs(&epggrab_ota_start_timer, epggrab_ota_start_cb, NULL, next);
+- tvhtrace(LS_EPGGRAB, "next ota start event in %li seconds", next - time(NULL));
++ tvhtrace(LS_EPGGRAB, "next ota start event in %"PRItime_t" seconds", next - time(NULL));
+ gtimer_arm_absn(&epggrab_ota_start_timer, epggrab_ota_start_cb, NULL, next);
dbus_emit_signal_s64("/epggrab/ota", "next", next);
}