Olliver Schinagl [Fri, 16 Jun 2023 21:55:26 +0000 (23:55 +0200)]
Fix time for 32bit systems again
In issue #6257 an issue mentioning that time_t isn't properly supported
when printing on 32-bit systems, specifically on FreeBSD. However, intel
32-bit systems suffer from a similar fate:
src/rtsp.c:333:30: error: format '%ld' expects argument of type 'long int',
but argument 4 has type 'time_t' {aka 'long long int'} [-Werror=format=]
333 | snprintf(buf, sizeof(buf), "npt=%" PRItime_t "-", position);
| ^~~~~~~ ~~~~~~~~
| |
| time_t {aka long long int}
In commit 76a6263f1be4 ("fix for 64bit time_t on 32bit systems") was
attempted to be fixed by turning it into a PRId64, which was reverted
again in commit 9e1eb89be731 ("Revert "fix for 64bit time_t on 32bit
systems""), sadly without a reason as to why in the commit message.
We should however, migrate to 64bit timestamps on all platforms anyway,
due to the Y2038 problem. Debian is heavily working on this issue too.
This commit is just the first step, in that we ensure our time_t is
always 64bits.
The next steps would be to use difftime where possible instead of
subtractions, and ensure all stored timestamps have room for 64bit
time_t (htsmsg_get_u32_or_default for example breaks this presumption
already).
To keep this issue small, and tackle one problem at a time, lets just
fix time_t first. We do still have 15 years to fix the other issues.
Note, that this patch leaves out FreeBSD specifics, as it is unclear
what is specific about 32bit FreeBSD. It should be using the same glibc
headers after all. If not, we can always add if needed, but adding
usless code doesn't help anyone generally.
Michael Marley [Thu, 22 Jun 2023 21:02:40 +0000 (17:02 -0400)]
Update Debian packaging to use the new configuration directories
This updates the Debian packaging to use the new configuration
directories introduced by
https://github.com/tvheadend/tvheadend/pull/1535 and
https://github.com/tvheadend/tvheadend/pull/1538. Instead of being
in /home/hts/.hts/tvheadend, the configuration will now be stored in
/var/lib/tvheadend by default, which is consistent with how many
other "server"-style Debian packages handle their home directories
and configuration.
Michael Marley [Thu, 22 Jun 2023 20:55:38 +0000 (16:55 -0400)]
Fix configuration-loading logic to account for forking operation
Since config_get_dir() is executed before forking, the uid will
always be 0 at this point. Instead, use the uid of the user to
which we will fork if a fork will occur.
Olliver Schinagl [Fri, 16 Jun 2023 15:02:19 +0000 (17:02 +0200)]
dvr_storage: Also support server configurations for recordings
Like in commit e15c1abe9737 ("config: Support server configurations"),
dvr_recordings are probably best stored in a 'server known
configuration', as otherwise they can end up in `/Videos`. While the
user can always configure this nicely, having a server sensible default
is good.
Olliver Schinagl [Fri, 16 Jun 2023 13:25:36 +0000 (15:25 +0200)]
spawn: Do not close every possible file descriptor
When close is called with a non-existant file descriptor, it will happily
do so. Since we do not even check for the error code, trying to close a
non existant/not-open file descriptor does not even cause an error.
This in itself is not a problem at all, however, we try to close every
open file descriptor beyond stderr, upto whatever _SC_OPEN_MAX returns.
Some systems may have a very large ulimit set for `_SC_OPEN_MAX` and
thus `maxfd` may return something in the millions. This means that the
simple `for() close();` loop now has to iterate a million file
descriptors which may not even be open/exist.
Instead, we can use the power of `/proc/self/fd` to list our open
file descriptors, and only close open ones.
Olliver Schinagl [Sat, 10 Jun 2023 13:42:03 +0000 (15:42 +0200)]
dvr_storage: Use XDG spec directories
The XDG spec has a way to determine the users preferred Video directory.
This is important, because in different locales, this may be a different
directory, preventing annoyance for users who have a localized home dir.
With the newly added XDG helpers, this becomes a triviality.
This change does mean, that the behavior is slightly changed, as XDG
directories are probed first.
However since this only affects the startup, after which these
directories are stored in the config, the impact should be neglectable.
Olliver Schinagl [Tue, 13 Jun 2023 13:35:25 +0000 (15:35 +0200)]
config: Support server configurations
On server loads, it is not uncommon to have the config directory live in
`/var/lib/tvheadend`. While `/etc/tvheadend` is also common, it's more
for manually written configuration files, tvheadend is more a 'config
state'. Support both regardless.
This change shouldn't impact desktop users, presuming they do not have
these locations installed.
Olliver Schinagl [Sat, 10 Jun 2023 13:35:26 +0000 (15:35 +0200)]
config: Add support for XDG config
Over the last years, the freedesktop organization has promoted the use
of XDG_HOME_CONFIG for storing configuration data.
Since TVHeadend also wants to help declutter the home directory, lets
follow the spec for our own configuration. While here, reduce the path
from `hts/tvheaded` to just `hts`.
The implementation does not change behavior of existing installations!
If `.hts/tvheadend` exists, it will be used as before.
New installations, will try to use `.config/hts` instead, and
'migrating' is as easy as `mv .hts/tvheadend .config/hts`.
Olliver Schinagl [Sat, 10 Jun 2023 13:20:25 +0000 (15:20 +0200)]
config: Store config directory variable internally
Currently `config_boot` 'abuses' the path-pointer and stores its own
internal path if needed. While this is _technically_ fine, it prevents
us from a) making `path` a const argument, b) makes things a little
harder to read and maintain and c) makes it harder for future changes to
the configuration path.
Instead, lets store the configuration path internally in our
configuration structure, as is done with most things. This could even
allow us to technically get rid of `hts_settings_init` in the future,
and get this from the config struct instead.
Olliver Schinagl [Sat, 10 Jun 2023 15:16:06 +0000 (17:16 +0200)]
Add simple 'ping' endpoint for healthchecks
To determine if the server is online, we want to be able to 'ping' it
with as little configuration and access possibilities as possible. The
only available option for this today, is anonymous access.
Let us thus add a new endpoint, that replies with 'PONG' when queried.
This will need anonymous access enabled, but can be restricted to:
a) localhost
b) without any access permissions
Gene C [Mon, 17 Apr 2023 12:55:50 +0000 (08:55 -0400)]
- fixed bug with _lang3_to_lang2()
Typo made using lang instead of lang3 in lookup map
- clean by running through autopep8
- Add more exception handling to prevent it crashing
Still needs some improvements with exception types
- tidy up for pylint
- python 2 is deprecated - simplify for python 3
- remove deprecated FF_API_CODED_FRAME
- remove pict_type from AVPacket_SideData
- use AVFrame->pict_type (same like ffmpeg 5.1.2 - ffprobe.c line 2595)
- remove patch for vaapi_encode
- ffmpeg_static will always compile with ffmpeg 5.1.2
- Makefile.ffmpeg added to 5.1.2
- src/muxer/muxer_libav.c: update 'AVOutputFrmat' to 'const AVOutputFrmat'
- src/transcoding/transcode/hwaccels/vaapi.c --> incorporated the struct from libavcodec/vaapi.h
- src/transcoding/transcode/video.c: update type for qdata_size
alingherghescu [Thu, 23 Mar 2023 03:23:50 +0000 (20:23 -0700)]
remove ffmpeg component avresample
- remove ffmpeg component avresample. Is deprecated and replaced by swresample. I verified that all functions from this component are not used in tvh (https://www.ffmpeg.org/doxygen/2.3/group__lavr.html)
alingherghescu [Tue, 31 Jan 2023 00:15:04 +0000 (16:15 -0800)]
update vaapi
- update libvpx to ver. 1.12.0
- replaced tvherror() with tvhinfo for bitrate report
- converted from bps to kbps
- reduced B frame to max 3 (4 is generating artifacts on my system)
- I had to set also bf otherwise will be set later in profile_video_class() with 3
- when low power is enabled max B frame will be disabled (because codec is not using B frames in low power mode)
- h264_vaapi and hevc_vaapi have also dynamic enable/disable for max B frame
- vp9 super frames can be enabled/disabled from the interface
- clean-up some javascript code
alingherghescu [Mon, 23 Jan 2023 06:54:06 +0000 (22:54 -0800)]
update vaapi
- updated function _video_filters_get_filters() due to a bug hidden by previous bug (Bug #6247)
- fixed Decoder HW + Encoder HW --> was generating download / upload that increase CPU usage
- remove vp9 profile0 to 3 (ffmpeg vaapi is not supporting profiles for vp9)
- improve 'tier' and added: level, qmin, qmax, desired_b_depth
- printing Bitrate, Buffer size, Max bitrate (for each transcoding start)
- added superframe for vp9
Peter Bašista [Sun, 15 Jan 2023 19:31:55 +0000 (20:31 +0100)]
Preserve existing Unicable idnode during the set operation
Currently, the Unicable settings are always cleared
when enabling or disabling the corresponding satellite position
or its owning adapter. The reason is that the idnode with Unicable
configuration is always unconditionally deleted
during the "set" operation.
This change adds a check for the existing Unicable configuration
and preserves the existing idnode if its type remains the same.
The same logic is already used when changing the configuration
related to LNB, switch and rotor.
dave-p [Sun, 25 Dec 2022 10:07:13 +0000 (10:07 +0000)]
Add autorec duplicate handling default to dvr config.
Default will be applied to new autorecs unless overridden.
duplicate_handling.md: Add details of "Record if Unique" option.
alingherghescu [Sat, 7 Jan 2023 02:09:28 +0000 (18:09 -0800)]
update vaapi
- added new settings: platform, bitrate scale factor, low power, loop filter level, loop filter sharpness, async depth
- implemented new (dynamic) settings adjustment (in js)
- added new parameters: b, low_power, loop_filter_level, loop_filter_sharpness, async_depth
- tvhva_context_check_profile() will change TVHVAContext->entrypoint from VAEntrypointEncSlice into VAEntrypointEncSliceLP if VAEntrypointEncSlice is not available for that CODEC (according to VAAPI info)
- moved low_power to tvh_codeo_profile in order to initialize properly the entrypoint
- many error reporting improvements
- separated some bundled conditions
In file included from src/main.c:41:
src/tcp.h: In function ‘ip_check_equal_v4’:
src/tcp.h:29:31: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
29 | #define IP_AS_V4(storage, f) ((struct sockaddr_in *)&(storage))->sin_##f
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/tcp.h:67:14: note: in expansion of macro ‘IP_AS_V4’
67 | { return IP_AS_V4(a, addr).s_addr == IP_AS_V4(b, addr).s_addr; }
| ^~~~~~~~
storage (a) here is a pointer to sockaddr_storage which is either backed
by a sockaddr_in or sockaddr_in6 struct (here, it would be good if it is
the former, we decided based on sa_family in ip_check_equal). Referencing
it means we have a pointer to a pointer to sockaddr_storage here, which
we then cast to a pointer to sockaddr_in. Our so type-punned pointer is
then dereferenced breaking strict-aliasing as this pointer as well as
our original pointer share a memory location and both could be used to
change it even through they are of different types.
We can avoid this situation simply by removing the reference as then it
is just casting a pointer to a different type (which in this case is
legal as storage is really a sockaddr_in).
Removing the reference breaks users of the macro who do not feed it a
pointer to a sockaddr_storage, so while the warnings were all produced
by tcp.h, we end up changing code everywhere else to resolve them –
usually by just taking a reference or not dereferencing there.
As this is the only instance of (detected) strict-aliasing breakage
the Makefile is also changed to no longer build the entirety of
tvheadend with strict-aliasing rules disabled. Similar for the disabled
stringop warnings which weren't (correctly) triggered in the current
code.
As a small bonus, this also prevents gcc-11 from tripping with a false
positive over the previous tcp change in c0f616e / #1473.
Simplify IPv6 compare functions to unconfuse gcc compiler
In file included from src/tcp.c:32:
In function ‘ip_check_is_any_v6’,
inlined from ‘ip_check_is_any’ at src/tcp.h:110:46,
inlined from ‘ip_check_is_local_address’ at src/tcp.c:89:17:
src/tcp.h:105:57: warning: array subscript 1 is outside array bounds of ‘const struct sockaddr_storage[0]’ [-Warray-bounds]
105 | { return ((uint64_t *)IP_AS_V6(address, addr).s6_addr)[0] == ((uint64_t *)(&in6addr_any.s6_addr))[0] &&
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:108:19: note: at offset 8 into object ‘address’ of size 8
108 | static inline int ip_check_is_any(const struct sockaddr_storage *address)
| ^~~~~~~~~~~~~~~
And more for the other half of the function and its three-times more or
less copy-paste instances. sockaddr_storage is not an array, but what
we actually do here is access s6_addr – which is an array of uint8_t.
Accessing the 16 uint8_t as 2 uint64_t apparently works, but not doing
it results in hopefully simpler to understand code for both humans and
compilers alike.
If you have e.g. all but dvb disabled and forgot to plug in your usb
adapter the wizard would crash upon you as no inputs are defined and the
looping assumes there is at least one. Ideally a message should be shown
to indicate that you need inputs, but a wizard displaying a mostly empty
page is far better than a crash to discover your mistake.
Use application/json instead of text/x-json as mimetype
The web has mostly agreed on this standardized mimetype and e.g.
trying to open an API URI with Firefox is now opened in its friendly
JSON viewer rather than downloaded.
epgdb: Resolve symlinks before using file location
The new epgdb is written to a temporary file and later renamed to
override the old epgdb file atomically. If you diverted the epgdb
to a different place away from your usual configuration (e.g. for
space and/or disk usage reasons like on an OpenWrt router) this
leads to overriding the symlink with a real file defeating the point.
By applying realpath on the path first we can resolve any symlink
along the path, while not considering it a failure if the epgdb
file doesn't exist yet. If on the other hand the path up to the file
doesn't exist we default to the old way of just taking the path
verbatim and let them be created by hts_settings_makedirs as before.
Note that this relies on the paths being sized PATH_MAX, which as the
manpage notes is POSIX.1-2001 conform, but broken by design as PATH_MAX
can't be relied upon, but the entire codebase makes heavy use of PATH_MAX
and there is a pre-existing usage of realpath() in this way so lets
pretend its okay for now.
Michael Marley [Thu, 27 Oct 2022 21:48:46 +0000 (17:48 -0400)]
iptv_auto: Add support for m3u "channel-number" tag
SiliconDust recently added m3u playlist generation support to the
HDHomeRun products. They use "channel-number" for the channel
number, so add support for that value to TVHeadend. It is used as
a fallback only if the previously-supported "tvh-chnum" and
"tvg-chno" tags aren't present. This should be particularly useful
for usage with ATSC 3.0 channels, as those aren't supported in the
libhdhomerun library that TVHeadend normally uses for HDHomeRun
devices. Without this, the channel number for all channels
imported from the HDHomeRun m3u is "0".