Forums » Tutorial and setups »
HDHomeRun Support without module or special compilation
Added by Diego Rivera almost 9 years ago
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
- Here's the line from my setup:
- 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's new name (i.e. ${scriptName}.conf), but must always 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, but NOT tuner #0 at 103DD502.
Finally, if no "DEVICES" line is present, or its contents are empty (all-spaces, etc.), then devices will be discovered via hdhomerun_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!!
capture-hdh (4.12 KB) capture-hdh | capture-hdh BASH script (tested on Ubuntu wily, should work on others) |
Replies (11)
RE: HDHomeRun Support without module or special compilation - Added by Diego Rivera almost 9 years ago
For those of you who may have been interested, this is the latest version of the script.
The syntax for the configuration file has changed slightly (same name + location): instead of DEVICES, the term is now SOURCES. The syntax is the same, except it now supports specifying multiple tuners in a single device via comma separation, so the following service syntaxes are supported:- DEVICE_ID : use all tuners in the given HDHomeRun device ID
- DEVICE_ID-* : same as DEVICE_ID
- DEVICE_ID-P1,P2,P3,...,PN : Use tuners P1, P2, P3, etc. on that device, in the given order. This allows you to restrict to which tuners the script will have access to by default.
This is the updated usage information:
- -s sources: the list of devices to consider as candidates (same syntax as SERVICES, above. Space-separated so be mindful of that)
- You may specify multiple -s options with different source lists. They will be analyzed, and duplicates will be removed (see below for details)
- -S : run a channel scan
- 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, if ommitted stdout is assumed)
- -g: enable trace mode, showing every instruction as it's executed
- -h: help message
- -?: help message
Also, the script has been modified to not try tuners twice. That means that if a tuner is listed twice, it will only be tried the first time it's referenced.
capture-hdh (4.65 KB) capture-hdh | capture-hdh BASH script (tested on Ubuntu wily, should work on others) |
RE: HDHomeRun Support without module or special compilation - Added by Mark Walker almost 9 years ago
Diego Rivera wrote:
For those of you who may have been interested, this is the latest version of the script.
Hi Diego,
Any chance of you adding complete, step by step guide for a newbie?
I've been struggling trying to get TVHeadend to recognize my HDHomerun tuners, and this looks like a good option.
Thanks.
RE: HDHomeRun Support without module or special compilation - Added by Diego Rivera almost 9 years ago
Hi there!
There are three options: use the dvbhdhomerun-utils driver (kernel driver), use an hdhomerun-compatible build of TVH, or use my script (updated version attached to this reply). Here's a rundown of what you're up against:
- Kernel Driver (https://launchpad.net/~tfylliv/+archive/ubuntu/dvbhdhomerun for Ubuntu)
- Works well, has some issues with suspend/resume on the newer kernels
- Can scan channels
- Makes the HDH devices appear as V4L2 devices, which means TVH sees them out of the box, and can handle channel scanning/setup automatically
- Requires some effort to build because some headers that it needs for compilation may not be there
- Not recommended for newbies
- HDHomerun-compatible build of TVH
- Uses libhdhomerun to talk to the devices
- Can scan channels
- Just as effective as the kernel driver, but no issues with newer kernels
- Requires a little effort to build the newer package with HDHomerun support
- Whenever there's an updated version, you can't just download it, you have to (again) recompile to re-add the HDH support
- My script
- Uses hdhomerun_config to talk to the devices and reproduce the video
- Just as effective as the other two
- Requires significant effort to configure TVH to use it since TVH can't scan for channels, and TVH lacks the ability (to my knowledge) for mass-importing IPTV channels (which would be the solution)
So...
What you need to decide is what kind of "extra" work you wish to do. It's entirely possible that the simplest solution for you is to build the HDHomeRun-enabled version of TVH, as I don't know what level of linux expertise you have. The kernel driver doesn't quite work with newer kernels (I tried it, it didn't fully work). And my script won't scan (not because it can't, but because TVH doesn't know how to scan from an IPTV source...at least, I'm not clear how it would).
Hope this helps inform your decision.
capture-hdh (4.65 KB) capture-hdh | Updated Script |
RE: HDHomeRun Support without module or special compilation - Added by Mark Walker almost 9 years ago
Hi Diego,
thanks for the information.
I'd rather not recompile anything, so using your script seems the best way to go.
hdhomerun_config discovers both of my devices no problem - I only have 14 channels locally, so setting up the muxes shouldn't be too much work.
An example configuration file would be appreciated. Just to compare and see if I'm missing anything obvious.
Mark
RE: HDHomeRun Support without module or special compilation - Added by Diego Rivera almost 9 years ago
You won't need one. All you need is the list of channel numbers (you can use hdhomerun_config_gui, for instance, to write them down). Once you have that, you create the IPTV network and a MUX for each channel.
Be advised: they must all be digital channels (i.e. QAM/ATSC) - the HDH devices don't support analog signals (learned that one the hard way). If you're going for analog, I can also offer info on a solution.
Cheers!
RE: HDHomeRun Support without module or special compilation - Added by Mark Walker almost 9 years ago
No problem, they're all digital (ATSC)
Mark
RE: HDHomeRun Support without module or special compilation - Added by Diego Rivera almost 9 years ago
Then that's all you need to do:
- Add an IPTV Network
- Add one mux per channel, tied to that IPTV network, where the URL is pipe://capture-hdh -c ${channel}
- Mux name - whatever you like, I tend to name them like the service name will be (i.e. FOX.mux or CH7.mux)
- Service name - the name of the channel
You should then do a network scan, and it will result in the creation of the service(s) for the muxes created. You can then associate each service to its EPG data.
Cheers!
RE: HDHomeRun Support without module or special compilation - Added by Mark Walker almost 9 years ago
Thanks for the assist Diego, I'll try it later today and post an update.
Mark
RE: HDHomeRun Support without module or special compilation - Added by Mark Walker almost 9 years ago
Hi Diego,
Just one quick question, given the following excerpt from an hdhomerun_config scan:
SCANNING: 533000000 (us-bcast:24)
LOCK: 8vsb (ss=100 snq=98 seq=100)
TSID: 0x4333
PROGRAM 1: 24.1 TVO
Which value do I use for channel?
Thanks,
Mark
RE: HDHomeRun Support without module or special compilation - Added by Diego Rivera almost 9 years ago
You can use 24.1.
Cheers!
RE: HDHomeRun Support without module or special compilation - Added by Mark Walker almost 9 years ago
Diego Rivera wrote:
You can use 24.1.
Cheers!
Thanks for all your help, I ended up with a mix of frequency and channel numbers, but I did manage to get all my muxes up and running.
Mark