commit 5ce968888b7feb777a0da84207e43cb93da56444
Author: Mohamed El Morabity <melmorabity(a)fedoraproject.org>
Date: Tue Aug 9 10:45:52 2016 +0200
First import
.gitignore | 1 +
sources | 1 +
tvheadend-4.0.9-build.patch | 21 ++
tvheadend-4.0.9-crypto_policies.patch | 12 +
tvheadend-4.0.9-dtv_scan_tables.patch | 12 +
tvheadend-4.0.9-ffmpeg_3.0.patch | 432 +++++++++++++++++++++++++++++++++
tvheadend-4.0.9-hdhomerun.patch | 24 ++
tvheadend-4.0.9-service.patch | 8 +
tvheadend-4.0.9-use_system_queue.patch | 12 +
tvheadend.spec | 146 +++++++++++
10 files changed, 669 insertions(+)
---
diff --git a/.gitignore b/.gitignore
index e69de29..1fa2f2c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/tvheadend-4.0.9.tar.gz
diff --git a/sources b/sources
index e69de29..be67fa0 100644
--- a/sources
+++ b/sources
@@ -0,0 +1 @@
+afe45a345151e7ce31db673e0c738e6e tvheadend-4.0.9.tar.gz
diff --git a/tvheadend-4.0.9-build.patch b/tvheadend-4.0.9-build.patch
new file mode 100644
index 0000000..6b15a48
--- /dev/null
+++ b/tvheadend-4.0.9-build.patch
@@ -0,0 +1,21 @@
+diff -up ./src/htsmsg.c.orig ./src/htsmsg.c
+--- ./src/htsmsg.c.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./src/htsmsg.c 2016-07-05 00:38:18.670529721 +0200
+@@ -760,13 +760,15 @@ htsmsg_print0(htsmsg_t *msg, int indent)
+ case HMF_MAP:
+ printf("MAP) = {\n");
+ htsmsg_print0(&f->hmf_msg, indent + 1);
+- for(i = 0; i < indent; i++) printf("\t"); printf("}\n");
++ for(i = 0; i < indent; i++) printf("\t");
++ printf("}\n");
+ break;
+
+ case HMF_LIST:
+ printf("LIST) = {\n");
+ htsmsg_print0(&f->hmf_msg, indent + 1);
+- for(i = 0; i < indent; i++) printf("\t"); printf("}\n");
++ for(i = 0; i < indent; i++) printf("\t");
++ printf("}\n");
+ break;
+
+ case HMF_STR:
diff --git a/tvheadend-4.0.9-crypto_policies.patch
b/tvheadend-4.0.9-crypto_policies.patch
new file mode 100644
index 0000000..0896462
--- /dev/null
+++ b/tvheadend-4.0.9-crypto_policies.patch
@@ -0,0 +1,12 @@
+diff -up ./src/httpc.c.orig ./src/httpc.c
+--- ./src/httpc.c.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./src/httpc.c 2016-07-05 01:59:47.616987692 +0200
+@@ -1294,7 +1294,7 @@ http_client_reconnect
+ /* do not use SSLv2 */
+ SSL_CTX_set_options(ssl->ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION);
+ /* adjust cipher list */
+- if (SSL_CTX_set_cipher_list(ssl->ctx, "HIGH:MEDIUM") != 1) {
++ if (SSL_CTX_set_cipher_list(ssl->ctx, "PROFILE=SYSTEM") != 1) {
+ tvhlog(LOG_ERR, "httpc", "%04X: Unable to adjust SSL cipher
list", shortid(hc));
+ goto err2;
+ }
diff --git a/tvheadend-4.0.9-dtv_scan_tables.patch
b/tvheadend-4.0.9-dtv_scan_tables.patch
new file mode 100644
index 0000000..2279d10
--- /dev/null
+++ b/tvheadend-4.0.9-dtv_scan_tables.patch
@@ -0,0 +1,12 @@
+diff -up ./src/input/mpegts/scanfile.c.orig ./src/input/mpegts/scanfile.c
+--- ./src/input/mpegts/scanfile.c.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./src/input/mpegts/scanfile.c 2016-07-05 01:51:10.519638550 +0200
+@@ -718,7 +718,7 @@ scanfile_init ( void )
+ #elif defined(PLATFORM_FREEBSD)
+ path = "/usr/local/share/dtv-scan-tables";
+ #else
+- path = "/usr/share/dvb";
++ path = "/usr/share/dvbv5";
+ #endif
+ scanfile_load_dir(path, NULL, 0);
+
diff --git a/tvheadend-4.0.9-ffmpeg_3.0.patch b/tvheadend-4.0.9-ffmpeg_3.0.patch
new file mode 100644
index 0000000..f127b0e
--- /dev/null
+++ b/tvheadend-4.0.9-ffmpeg_3.0.patch
@@ -0,0 +1,432 @@
+diff -up ./configure.orig ./configure
+--- ./configure.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./configure 2016-07-05 00:18:31.023320750 +0200
+@@ -395,7 +395,7 @@ else
+ 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 @@ else
+ has_libav=false
+ fi
+
+- if $has_libav && ! check_pkg libswscale ">=2.1.2"; then
++ if $has_libav && ! check_pkg libacvfilter ">=4.0.0"; then
+ has_libav=false
+ fi
+
+diff -up ./src/libav.c.orig ./src/libav.c
+--- ./src/libav.c.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./src/libav.c 2016-07-05 00:19:19.154076349 +0200
+@@ -186,4 +186,5 @@ libav_init(void)
+ av_log_set_callback(libav_log_callback);
+ av_log_set_level(AV_LOG_VERBOSE);
+ av_register_all();
++ avfilter_register_all();
+ }
+diff -up ./src/libav.h.orig ./src/libav.h
+--- ./src/libav.h.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./src/libav.h 2016-07-05 00:21:52.805103748 +0200
+@@ -21,6 +21,7 @@
+
+
+ #include <libavformat/avformat.h>
++#include <libavfilter/avfilter.h>
+ #include "tvheadend.h"
+
+ /*
+diff -up ./src/plumbing/transcoding.c.orig ./src/plumbing/transcoding.c
+--- ./src/plumbing/transcoding.c.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./src/plumbing/transcoding.c 2016-07-05 00:33:28.319065719 +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 @@ typedef struct video_stream {
+ 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;
+
+@@ -267,6 +272,125 @@ transcoder_stream_packet(transcoder_t *t
+ }
+
+
++/* 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;
++ enum AVPixelFormat pix_fmts[] = { 0, AV_PIX_FMT_NONE };
++ 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;
++ }
++
++ pix_fmts[0] = octx->pix_fmt;
++ err = av_opt_set_int_list(vs->flt_bufsinkctx, "pix_fmts", pix_fmts,
++ AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
++ if (err < 0) {
++ tvherror("transcode", "%08X: fltchain cannot set output
pixfmt",
++ 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;
++}
++
++
+ /**
+ *
+ */
+@@ -592,10 +716,10 @@ transcoder_stream_audio(transcoder_t *t,
+ // 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);
+
+@@ -962,9 +1086,7 @@ transcoder_stream_video(transcoder_t *t,
+ 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 +1102,6 @@ transcoder_stream_video(transcoder_t *t,
+ icodec = vs->vid_icodec;
+ ocodec = vs->vid_ocodec;
+
+- buf = deint = NULL;
+ opts = NULL;
+
+ got_ref = 0;
+@@ -1061,7 +1182,7 @@ transcoder_stream_video(transcoder_t *t,
+ 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 +1210,7 @@ transcoder_stream_video(transcoder_t *t,
+
+ 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 +1241,7 @@ transcoder_stream_video(transcoder_t *t,
+
+ 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 +1298,53 @@ transcoder_stream_video(transcoder_t *t,
+ 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 +1358,6 @@ transcoder_stream_video(transcoder_t *t,
+
+ av_free_packet(&packet);
+
+- if(buf)
+- av_free(buf);
+-
+- if(deint)
+- av_free(deint);
+-
+ if(opts)
+ av_dict_free(&opts);
+
+@@ -1548,15 +1637,17 @@ transcoder_destroy_video(transcoder_t *t
+ 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 +1694,13 @@ transcoder_init_video(transcoder_t *t, s
+ 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);
+
diff --git a/tvheadend-4.0.9-hdhomerun.patch b/tvheadend-4.0.9-hdhomerun.patch
new file mode 100644
index 0000000..cf776ea
--- /dev/null
+++ b/tvheadend-4.0.9-hdhomerun.patch
@@ -0,0 +1,24 @@
+diff -up ./configure.orig ./configure
+--- ./configure.orig 2016-07-05 01:42:43.615016618 +0200
++++ ./configure 2016-07-05 01:44:12.239677665 +0200
+@@ -290,7 +290,7 @@ if enabled hdhomerun_static; then
+ else
+
+ if enabled_or_auto hdhomerun_client; then
+- if check_cc_header 'libhdhomerun/hdhomerun' libhdhomerun; then
++ if check_cc_header 'hdhomerun/hdhomerun' libhdhomerun; then
+ enable hdhomerun_client
+ LDFLAGS="$LDFLAGS -lhdhomerun"
+ fi
+diff -up ./src/input/mpegts/tvhdhomerun/tvhdhomerun_private.h.orig
./src/input/mpegts/tvhdhomerun/tvhdhomerun_private.h
+--- ./src/input/mpegts/tvhdhomerun/tvhdhomerun_private.h.orig 2016-03-14
10:10:57.000000000 +0100
++++ ./src/input/mpegts/tvhdhomerun/tvhdhomerun_private.h 2016-07-05 01:44:32.826134351
+0200
+@@ -24,7 +24,7 @@
+ #include "htsbuf.h"
+ #include "tvhdhomerun.h"
+
+-#include <libhdhomerun/hdhomerun.h>
++#include <hdhomerun/hdhomerun.h>
+
+ typedef struct tvhdhomerun_device_info tvhdhomerun_device_info_t;
+ typedef struct tvhdhomerun_device tvhdhomerun_device_t;
diff --git a/tvheadend-4.0.9-service.patch b/tvheadend-4.0.9-service.patch
new file mode 100644
index 0000000..eea8b22
--- /dev/null
+++ b/tvheadend-4.0.9-service.patch
@@ -0,0 +1,8 @@
+diff -up ./rpm/tvheadend.sysconfig.orig ./rpm/tvheadend.sysconfig
+--- ./rpm/tvheadend.sysconfig.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./rpm/tvheadend.sysconfig 2016-07-05 01:56:33.730282240 +0200
+@@ -1,3 +1,3 @@
+ # Configuration file for the tvheadend service.
+
+-OPTIONS="-c /home/tvheadend/config -u tvheadend -g tvheadend -6 --http_port 9981
--htsp_port 9982"
++OPTIONS="-c /var/lib/tvheadend/config -u tvheadend -g video -6 -C --http_port 9981
--htsp_port 9982"
diff --git a/tvheadend-4.0.9-use_system_queue.patch
b/tvheadend-4.0.9-use_system_queue.patch
new file mode 100644
index 0000000..13ac357
--- /dev/null
+++ b/tvheadend-4.0.9-use_system_queue.patch
@@ -0,0 +1,12 @@
+diff -up ./src/queue.h.orig ./src/queue.h
+--- ./src/queue.h.orig 2016-03-14 10:10:57.000000000 +0100
++++ ./src/queue.h 2016-07-04 17:47:22.480252171 +0200
+@@ -5,7 +5,7 @@
+ #ifndef HTSQ_H
+ #define HTSQ_H
+
+-#include "../vendor/include/sys/queue.h"
++#include <sys/queue.h>
+
+ /*
+ * Extra LIST-ops
diff --git a/tvheadend.spec b/tvheadend.spec
new file mode 100644
index 0000000..3080dbe
--- /dev/null
+++ b/tvheadend.spec
@@ -0,0 +1,146 @@
+%global tvheadend_user %{name}
+%global tvheadend_group video
+
+Name: tvheadend
+Version: 4.0.9
+Release: 1%{?dist}
+Summary: TV streaming server and digital video recorder
+
+Group: Applications/Multimedia
+License: GPLv3+
+URL:
https://tvheadend.org/
+Source0:
https://github.com/tvheadend/%{name}/archive/v%{version}/%{name}-%{versio...
+# Fix build, see
https://github.com/tvheadend/tvheadend/commit/9ddcb8d
+Patch0: %{name}-4.0.9-build.patch
+# Fix build with FFmpeg >= 3.0, based on:
+# -
https://github.com/tvheadend/tvheadend/commit/ea02889
+# -
https://github.com/tvheadend/tvheadend/commit/c63371c
+# -
https://github.com/tvheadend/tvheadend/commit/3cbee55
+Patch1: %{name}-4.0.9-ffmpeg_3.0.patch
+# Use system queue.h header
+Patch2: %{name}-4.0.9-use_system_queue.patch
+# Fix build with hdhomerun
+Patch3: %{name}-4.0.9-hdhomerun.patch
+# Fix system DTV scan tables path
+Patch4: %{name}-4.0.9-dtv_scan_tables.patch
+# Fix systemd service and configuration:
+# - Fix daemon user path
+# - Fix daemon group (use video to access DVB devices)
+# - Add -C option to allow UI access without login at first run
+Patch5: %{name}-4.0.9-service.patch
+# Enforcing system crypto policies, see
+#
https://fedoraproject.org/wiki/Packaging:CryptoPolicies
+Patch6: %{name}-4.0.9-crypto_policies.patch
+
+BuildRequires: bzip2
+BuildRequires: gcc
+BuildRequires: gzip
+BuildRequires: hdhomerun-devel
+BuildRequires: pkgconfig(avahi-client)
+BuildRequires: pkgconfig(dbus-1)
+BuildRequires: pkgconfig(libavcodec)
+BuildRequires: pkgconfig(libavfilter)
+BuildRequires: pkgconfig(libavformat)
+BuildRequires: pkgconfig(libavresample)
+BuildRequires: pkgconfig(libavutil)
+BuildRequires: pkgconfig(liburiparser)
+BuildRequires: pkgconfig(openssl)
+BuildRequires: pkgconfig(zlib)
+BuildRequires: python2
+BuildRequires: systemd
+Requires: dtv-scan-tables
+%{?systemd_requires}
+Provides: bundled(extjs) = 3.4.1
+
+%description
+Tvheadend is a TV streaming server and recorder supporting DVB-S, DVB-S2, DVB-C,
+DVB-T, ATSC, IPTV, SAT>IP and HDHomeRun as input sources.
+
+Tvheadend offers the HTTP (VLC, MPlayer), HTSP (Kodi, Movian) and SAT>IP
+streaming.
+
+Multiple EPG sources are supported (over-the-air DVB and ATSC including OpenTV
+DVB extensions, XMLTV, PyXML).
+
+The Analog video (V4L) is supported directly up to version 3.4. In recent
+version, the pipe:// source (in IPTV network) might be used to obtain the
+MPEG-TS stream generated by ffmpeg/libav from a V4L device.
+
+
+%prep
+%setup -q
+%patch0 -p0 -b .build
+# RPM Fusion provides FFMpeg 3.0 for Fedora >= 24
+%if 0%{?fedora} >= 24
+%patch1 -p0 -b .ffmpeg_3.0
+%endif
+%patch2 -p0 -b .use_system_queue
+%patch3 -p0 -b .hdhomerun
+%patch4 -p0 -b .dtv_scan_tables
+%patch5 -p0 -b .service
+%patch6 -p0 -b .crypto_policies
+
+# Delete bundled system headers
+rm -r vendor/{dvb-api,include}/
+
+
+%build
+# Use touch to be sure that configure, after being patched, is still older than
+# generated .config.mk file (otherwise the build fails)
+touch -r Makefile configure
+%configure \
+ --disable-dvbscan \
+ --disable-hdhomerun_static \
+ --disable-libffmpeg_static_x264 \
+ --enable-hdhomerun_client
+%make_build V=1
+
+
+%install
+%make_install
+
+install -Dpm 0644 rpm/%{name}.service $RPM_BUILD_ROOT%{_unitdir}/%{name}.service
+install -Dpm 0644 rpm/%{name}.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/%{name}
+
+install -dm 0755 $RPM_BUILD_ROOT%{_sharedstatedir}/%{name}/
+
+# Fix permissions
+chmod 0644 $RPM_BUILD_ROOT%{_mandir}/man1/%{name}.1
+
+# Drop bundled Ext JS resources not required by Tvheadend UI
+pushd $RPM_BUILD_ROOT%{_datadir}/%{name}/src/webui/static/extjs/
+rm -r *.js adapter/ examples/ resources/css/
resources/images/{access,gray,vista,yourtheme}/
+popd
+
+
+%pre
+getent passwd %{tvheadend_user} >/dev/null || useradd -r -g %{tvheadend_group} -d
%{_sharedstatedir}/%{name}/ -s /sbin/nologin -c "%{name} daemon account"
%{name}
+exit 0
+
+
+%post
+%systemd_post %{name}.service
+
+
+%preun
+%systemd_preun %{name}.service
+
+
+%postun
+%systemd_postun_with_restart %{name}.service
+
+
+%files
+%doc CONTRIBUTING.md README.md
+%license LICENSE.md licenses/gpl-3.0.txt
+%{_bindir}/%{name}
+%{_datadir}/%{name}/
+%{_unitdir}/%{name}.service
+%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
+%attr(-,%{tvheadend_user},%{tvheadend_group}) %dir %{_sharedstatedir}/%{tvheadend_user}/
+%{_mandir}/man1/*.1.*
+
+
+%changelog
+* Thu Jul 28 2016 Mohamed El Morabity <melmorabity(a)fedoraproject.org> - 4.0.9-1
+- Initial RPM release