Hi, all!
In my setup, I have two HTPCs each with their own HDHomeRun Prime unit (HDHR3-US). Recently I started having problems with the kernel module causing the HTPCs to hang before suspend, or TV viewing to not work properly upon resume. Tired of this, I sought out a solution based on userspace and after some research I came up with this script.
This script (capture-hdh) simply captures the feed from an HDHomeRun unit using command-line hdhomerun_config. It practices sane and safe locking/unlocking of tuners, and can output to a file or stdout (using - as the output target). More importantly: I've completely replaced my HDHomeRun-compatible tvheadend build with the default one, interfacing with this script, and it works flawlessly!
Here's what I did:
# Make sure hdhomerun_config is installed, and works (hdhomerun_config discover usually does the trick)
# (optional) make sure uuidgen is available (provided by uuid-runtime for Debian-ish Linuxes)
#* If uuidgen isn't available, a key is generated randomly, which
_+SHOULD+_ be unique.
# Make sure the script is in the path, and works fine from the command-line (instructions below)
# Define a new IPTV Network in which the muxes would live for each channel I wished to support (this will be improved upon later, for now bear with me)
# Define a new MUX for each channel on that network, with the URL being of the pipe:// variety, and triggering the invocation of the script (with -o - for stdout output). Let the MUX "scan"
#* Here's the line from my setup:
pipe://capture-hdh -c <channel> -o -
#* In my setup, each HTPC is "linked" to its own HDHomeRun device, so the configuration file (see below) enforces that restriction. Hence, I don't need to include configuration information about which device to talk to in this URL.
#* The next revision of this script will generate multiple services from a scan, but I have to research how to return that information such that TVH understands it, and also have to define a way to do the scan and return the results
# Once each MUX has been scanned, its named service should appear on the "Services" tab - simply map each service to its (set of) channels like you normally would
#* If the services don't appear, then check the TVH logs - it's likely the script isn't on the path, or there's a typo somewhere. Simply fix it, then set the MUX's scan status to "PEND" (editing the MUX), and it'll re-attempt the scan. Once the scan is successful, the service
will show up.
# VoliĆ”! You're done!
The attached script uses simple round-robin logic to iterate over whatever devices (and tuners) are available until one is successfully "_acquired_" (i.e. locked by setting a lockkey via hdhomerun_config). Once that happens, then that device+tuner will be tuned to the given channel (and, optionally, program), and its output (MPEGTS stream) will be written out to wherever the "-o" option (see below) points.
The script can use a configuration file in /etc/default/capture-hdh.conf. Please note that if you decide to name the script something else, that configuration file's name must also match the script'snew name (i.e._${scriptName}_.conf), butmustalways reside in /etc/default. In the configurations, a single DEVICES="" line is supported, where you may specify complete devices (i.e. deviceId or deviceId-* for including all tuners in a device), or specific tuners (i.e. deviceId-tuner or even deviceId-tuner1,tuner2,...,tunerN). The devices and tuners will be tried in order. The script isn't "smart enough" yet to aggregate information, so you specify duplicate stuff, you'll get duplicate attempts. This will be fixed later.
For example, if the DEVICES line reads DEVICES="1039D860-* 103DD502-1 103DD502-2", then the script will first try all tuners in 1039D860, in order. Then it will try tuner #1 at 103DD502, and then tuner #2 at 103DD502, butNOT tuner #0 at 103DD502.
Finally, if no "DEVICES" line is present, or its contents are empty (all-spaces, etc.), then devices will be discovered viahdhomerun_config discover.
The script itself accepts the following command-line arguments:
* -d devices: the list of devices to consider as candidates (same syntax as
DEVICES, above. Space-separated so be mindful of that)
This overrides the value from the configuration file
* -c channel: the channel to which you wish to tune, in F.P notation where F is the frequency or channel number you wish to tune to, and P is the program number within that frequency. The program number is optional.
* -o output: the file to which output will be written (use
-
for stdout, this is what TVH needs)
* -g: enable trace mode, showing every instruction as it's executed
* -h: help message
* -?: help message
I hope to eventually make this a userland frontend for the HDHomeRun, so we don't have to muck around with the driver. The newer HDHomeRun devices, however, apparently support IPTV so this won't be necessary. Older devices, however, can definitely benefit from this.
Interestingly, with minimum modification this script can be made to process the stream as it flows - i.e. remove interlacing (need to look into that :) )
Hope this works! And thanks to the TVH team for all the great work on TVHeadEnd!!
<<