AndroidHDMI for Channels (ah4c): A virtual channel tuner using HDMI Encoder(s) + streaming stick(s)

Thanks!
Should i change
STREAMER_APP=scripts/firetv/directv to
STREAMER_APP=scripts/android/allente
And put the scrips in allente folder ?

That would be just right. :slight_smile:

1 Like

Could be useful for those who own those ADTH boxes. Usually, those boxes could work with channel numbers

1 Like
#!/bin/bash
#prebmitune.sh for android/allente
echo "Script not required"
#!/bin/bash
#stopbmitune.sh for android/allente
echo "Script not required"

Is this how it should look ?

Those should work.

Update - last night recordings didn't happen - tracked it down to the 2 onn devices were stuck on the Fubo select profile screen. They must not shutdown the Fubo app like the Firestick does or it shouldn't be shutdown.

I just moved tuners around so my new Firestick 4k max is tuner 1 and an older Firestick I had in the drawer as tuner 2 - with tuner 3 still an onn. Have several sport recordings today - report back tomorrow...

1 Like

Yesterday's 2 recordings were fine. I just tried to watch something while monitoring vlc session. It was asleep, I tuned to a channel - woke it up and went to black screen 'error occurred'. I hit the 'Home" button and it went home - then went to sleep after a couple of seconds. Tried the watch it again and it stuck on the Fubo pick a profile screen. Selected my profile with the remote and it started streaming the channel.
I've pasted the log file to a .txt file for this sequence, around 500 lines - didn't want to clog up the thread being that long.

1 Like

We're talking about the ah4c log here right? If you could post just the log lines surrounding a bad tune, that might be helpful -- but 500 lines would cover many tuning cycles, so is more than necessary. Be sure to use 3 backticks before and after the log lines, so they end up in a code block.

yeah - its the ah4c log. It's is actually 572 lines in 1minutes 20 seconds for this whole cycle.
I hope you mean a "tilde" character - at least what us in IT call it - I'm trying it.. Here's the first 80 lines or so...

This starts about 2 seconds after the request.

2024-03-03T11:34:09.796075869Z Attempting network tune for device http://10.0.0.60/0.ts 10.0.0.64:5555 32639 
2024-03-03T11:34:09.853233658Z [EXECUTE] Running [./scripts/firetv/fubo/prebmitune.sh 10.0.0.64:5555 32639]
2024-03-03T11:34:09.980434105Z [EXECUTE] Stdout: 'already connected to 10.0.0.64:5555
2024-03-03T11:34:09.980502056Z prebmitune.sh is exiting for 10.0.0.64:5555 with exit code 0
2024-03-03T11:34:09.980510754Z '
2024-03-03T11:34:09.980517030Z [EXECUTE] Stderr: '+ streamerIP=10.0.0.64:5555
2024-03-03T11:34:09.980523436Z + streamerNoPort=10.0.0.64
2024-03-03T11:34:09.980529988Z + adbTarget='adb -s 10.0.0.64:5555'
2024-03-03T11:34:09.980537204Z + mkdir -p 10.0.0.64
2024-03-03T11:34:09.980543584Z + trap finish EXIT
2024-03-03T11:34:09.980550161Z + main
2024-03-03T11:34:09.980557044Z + adbConnect
2024-03-03T11:34:09.980563794Z + adb connect 10.0.0.64:5555
2024-03-03T11:34:09.980569724Z + local -i adbMaxRetries=2
2024-03-03T11:34:09.980575734Z + local -i adbCounter=0
2024-03-03T11:34:09.980582284Z + true
2024-03-03T11:34:09.980588523Z + adb -s 10.0.0.64:5555 shell input keyevent KEYCODE_WAKEUP
2024-03-03T11:34:09.980595445Z + local adbEventSuccess=0
2024-03-03T11:34:09.980601510Z + [[ 0 -eq 0 ]]
2024-03-03T11:34:09.980607333Z + break
2024-03-03T11:34:09.980612946Z + finish
2024-03-03T11:34:09.980618854Z + echo 'prebmitune.sh is exiting for 10.0.0.64:5555 with exit code 0'
2024-03-03T11:34:09.980625131Z '
2024-03-03T11:34:09.980630872Z [EXECUTE] Finished running ./scripts/firetv/fubo/prebmitune.sh in 127.286156ms
2024-03-03T11:34:09.980798666Z [EXECUTE] Running [./scripts/firetv/fubo/bmitune.sh 32639 10.0.0.64:5555]
2024-03-03T11:35:11.401442264Z [EXECUTE] Stdout: 'Current PID for this script is 5276
2024-03-03T11:35:11.401469353Z Not a special channel (exit nor reboot)
2024-03-03T11:35:11.401471687Z Starting: Intent { act=android.intent.action.VIEW dat=https://link.fubo.tv/... }
2024-03-03T11:35:11.401473523Z No active audio stream detected and app is not in focus after 4 seconds -- attempting to tune again...
2024-03-03T11:35:11.401475220Z No active audio stream detected and app is not in focus after 6 seconds -- attempting to tune again...
2024-03-03T11:35:11.401477026Z No active audio stream detected and app is not in focus after 9 seconds -- attempting to tune again...
2024-03-03T11:35:11.401478813Z No active audio stream detected and app is not in focus after 11 seconds -- attempting to tune again...
2024-03-03T11:35:11.401480499Z No active audio stream detected and app is not in focus after 14 seconds -- attempting to tune again...
2024-03-03T11:35:11.401482176Z No active audio stream detected and app is not in focus after 16 seconds -- attempting to tune again...
2024-03-03T11:35:11.401483849Z No active audio stream detected and app is not in focus after 19 seconds -- attempting to tune again...
2024-03-03T11:35:11.401485527Z No active audio stream detected and app is not in focus after 22 seconds -- attempting to tune again...
2024-03-03T11:35:11.401496662Z No active audio stream detected and app is not in focus after 24 seconds -- attempting to tune again...
2024-03-03T11:35:11.401498396Z No active audio stream detected and app is not in focus after 27 seconds -- attempting to tune again...
2024-03-03T11:35:11.401500104Z No active audio stream detected and app is not in focus after 29 seconds -- attempting to tune again...
2024-03-03T11:35:11.401501797Z No active audio stream detected and app is not in focus after 32 seconds -- attempting to tune again...
2024-03-03T11:35:11.401503444Z No active audio stream detected and app is not in focus after 34 seconds -- attempting to tune again...
2024-03-03T11:35:11.401505124Z No active audio stream detected and app is not in focus after 37 seconds -- attempting to tune again...
2024-03-03T11:35:11.401506761Z No active audio stream detected and app is not in focus after 40 seconds -- attempting to tune again...
2024-03-03T11:35:11.401508379Z No active audio stream detected and app is not in focus after 42 seconds -- attempting to tune again...
2024-03-03T11:35:11.401510029Z No active audio stream detected and app is not in focus after 45 seconds -- attempting to tune again...
2024-03-03T11:35:11.401511701Z No active audio stream detected and app is not in focus after 48 seconds -- attempting to tune again...
2024-03-03T11:35:11.401514116Z No active audio stream detected and app is not in focus after 50 seconds -- attempting to tune again...
2024-03-03T11:35:11.401515819Z No active audio stream detected and app is not in focus after 53 seconds -- attempting to tune again...
2024-03-03T11:35:11.401517465Z No active audio stream detected and app is not in focus after 56 seconds -- attempting to tune again...
2024-03-03T11:35:11.401519112Z No active audio stream detected and app is not in focus after 58 seconds -- attempting to tune again...
2024-03-03T11:35:11.401520775Z Active audio stream not detected in 60 seconds.
2024-03-03T11:35:11.401522374Z bmitune.sh is exiting for 10.0.0.64:5555 with exit code 1
2024-03-03T11:35:11.401524010Z '
2024-03-03T11:35:11.401525620Z [EXECUTE] Stderr: '+ channelID=32639
2024-03-03T11:35:11.401527274Z + specialID=32639
2024-03-03T11:35:11.401528887Z + streamerIP=10.0.0.64:5555
2024-03-03T11:35:11.401530407Z + streamerNoPort=10.0.0.64
2024-03-03T11:35:11.401531952Z + adbTarget='adb -s 10.0.0.64:5555'
2024-03-03T11:35:11.401533530Z + packageName=com.fubo.firetv.screen
2024-03-03T11:35:11.401535120Z + trap finish EXIT
2024-03-03T11:35:11.401536678Z + main
2024-03-03T11:35:11.401538183Z + updateReferenceFiles
2024-03-03T11:35:11.401539897Z + mkdir -p 10.0.0.64
2024-03-03T11:35:11.401541532Z + [[ -f 10.0.0.64/stream_stopped ]]
2024-03-03T11:35:11.401543239Z + [[ -f 10.0.0.64/last_channel ]]
2024-03-03T11:35:11.401544890Z + echo 5276
2024-03-03T11:35:11.401546590Z + echo 'Current PID for this script is 5276'
2024-03-03T11:35:11.401550326Z + matchEncoderURL
2024-03-03T11:35:11.401551949Z + case "$streamerIP" in
2024-03-03T11:35:11.401553787Z + encoderURL=http://10.0.0.60/0.ts
2024-03-03T11:35:11.401555485Z + specialChannels
2024-03-03T11:35:11.401557097Z + '[' 32639 = exit ']'
2024-03-03T11:35:11.401558749Z + '[' 32639 = reboot ']'
2024-03-03T11:35:11.401560389Z + [[ -f 10.0.0.64/adbCommunicationFail ]]
2024-03-03T11:35:11.401562133Z + echo 'Not a special channel (exit nor reboot)'
2024-03-03T11:35:11.401563772Z + tuneChannel
1 Like

I started writing you a completely different message, but then I looked at the code for the activeAudioCheck() function in the Fubo bmitune.sh script, and I see a mistake:

#Check for active audio stream
activeAudioCheck() {
  local startTime=$(date +%s)
  local maxDuration=60
  local minimumLoudness=-50
  local sleepDuration=0.5
  
  while true; do
    checkLoudness=$(ffmpeg -t 1 -i $encoderURL -filter:a ebur128 -map 0:a -f null -hide_banner - 2>&1 | awk '/I:        /{print $2}')

    if (( $(date +%s) - $startTime > $maxDuration )); then
      echo "Active audio stream not detected in $maxDuration seconds."
      exit 1
    fi

    if (( $(echo "$checkLoudness > $minimumLoudness" | bc -l) )); then
      echo "Active audio stream detected with $checkLoudness LUF."
      break
    fi

    if appFocusCheck 0; then
      echo "Active audio stream not yet detected -- loudness is $checkLoudness LUF. Continuing..."
      sleep $sleepDuration
    else
      echo "No active audio stream detected and app is not in focus after $(($(date +%s) - $startTime)) seconds -- attempting to tune again..."
      #tuneChannel
      $adbTarget shell input keyevent KEYCODE_CENTER
    fi

  done
}

This line:

      $adbTarget shell input keyevent KEYCODE_CENTER

Should actually be:

      $adbTarget shell input keyevent KEYCODE_DPAD_CENTER

So give that a try, as that hopefully will get you past the profile screen when it appears. And, of course, you can adjust that as need if different keyevent(s) are required.

BTW, the tilde is the shift of the backtick on most keyboards, and either works to define a code block on this forum -- though the 3x backticks is the markdown standard I do believe.

From the "Markdown Cheat Sheet":

I tried this change and it just pauses the screen. I verified thru adblink while watching something. Running it a 2nd time resumes playing. I should say this was not while getting the profile screen - if that helps. I can't narrow that issue down to what causes that, prolly just Fubo's flakey app.

I'll try to do some testing if I can catch the profile screen up. When that happens, I just hit enter since my profile is the 1st one and it's setting on it. I'm guessing KEYCODE_ENTER is the same.

Unless you can think of a way to know that the profile screen is up - easily without rewriting a bunch of code - just for me, I may try to at least get an alert so I could grab the remote and get past the screen.

I haven't set email alerts up yet. What conditions are built in for generating alerts?

Also - thanks for the info on the backtick - Don't think I've ever used that or knew it existed...

I doesn't surprise me that KEYCODE_DPAD_CENTER functions as pause/play when the stream is active. However, in this script we'd only send that key if virtual tuning is complete, and active audio is not heard. The hope is, that would only happen when the profile screen is up.

KEYCODE_DPAD_CENTER is equivalent to the center button between all the directional arrows on Android remotes. KEYCODE_ENTER is often times the same, but not always, and is not found on typical remote controls.

So, I'd suggest you correct the error in the script and let it do its thing -- to see if it works or not in a real world scenario. I don't think you'll be any worse off, as it should only kick-in if there's no audio stream, and the current keyevent is basically a typo.

E-mail alerts will trigger on failed tuning. If you're going to set it up, create an "app" password in Gmail or Yahoo mail, and use that along with their SMTP server.

That didn't work - I got a hour recording of Jimmy Fallon on a paused screen. Trying to watch something live I can see it play for a split second - then it pauses as well. Almost like it needs to of those commands to start playing again using that command.

Looking at the code I was wondering if you have 4 boxes with 4 encoders what part of the code is it that let’s channels know what channel is coming in from each encoder?

It's a proxy -- Channels makes the request via URL, and ah4c does the virtual tuning and passes along the stream.

ah4c knows the particulars, Channels does not.

Since the DirecTV app no longer seems to work properly if the app is left active when streaming is concluded, I've created a new all-in-one version of this container that terminates the app after each streaming session. The impact on tuning time seems relatively small.

This is currently available under the :test tag, as I've also incorporated support for using AppleTVs as the streaming device connected to the HDMI encoder. This support uses pyatv rather than adb to send commands for the virtual tuning. Primarily recommended when the streaming app you'd like to use is only available through Apple -- with Spectrum being the best current example.

1 Like

@chrispederick If you've added those premium channels and Regional Sports Networks into the dtvstream.m3u you're using, I'd like to add those to next build.

Also, in this test release, I've included your San Francisco locals and the Philadelphia locals from @gfhartzell in the M3U. They are BOTH commented out however to avoid conflicts, so you'd each need to remove the #<space> from your respective locals if you allow your local M3U to be overwritten.

I would suggest just merging and let us delete or disable channels they appear to be unique. I'm getting an error on first run through.:
Failed to parse m3u for FiretvDTV: unexpected URL without #EXTINF header

1 Like

That's a good idea. Comments in M3U files can be tricky. Roll back to :latest for now, and I'll fix that in the next build.

Btw, have you been seeing this issue with a black screen when you tune to something, after a recent successful tune?

The DTV app always reloads after about 4 hours, so the first tune after that reload would work, but the second would not. Took me awhile to recognize the pattern, but it's fixed by "force" stopping the app in the stopbmitune.sh script.

Just saw that once yesterday I thought it was the server causing the problem. reboot fixed it maybe not!