Skip to content

Commit

Permalink
Add support for handling .ubv files with Track Number 1003 (unknown w…
Browse files Browse the repository at this point in the history
…hat this track does, see #44 for initial report). Also introduce constants for track numbers instead of magic numbers
  • Loading branch information
petergeneric committed Jul 31, 2024
1 parent 82f4d67 commit d900315
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions ubv/ubvinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import (
"unicode"
)

const (
// The string to use to find ubnt_ubvinfo if it's on the path
ubntUbvInfoPath1 = "ubnt_ubvinfo"
// The path to ubnt_ubvinfo on a Protect installation
ubntUbvInfoPath2 = "/usr/share/unifi-protect/app/node_modules/.bin/ubnt_ubvinfo"
)
// The string to use to find ubnt_ubvinfo if it's on the path
const ubntUbvInfoPath1 = "ubnt_ubvinfo"

// The path to ubnt_ubvinfo on a Protect installation
const ubntUbvInfoPath2 = "/usr/share/unifi-protect/app/node_modules/.bin/ubnt_ubvinfo"

const TrackAudio = 1000
const TrackVideo = 7
const TrackUnknown = 1003

// Analyse a .ubv file (picking between ubnt_ubvinfo or a pre-prepared .txt file as appropriate)
func Analyse(ubvFile string, includeAudio bool) UbvFile {
Expand Down Expand Up @@ -149,18 +152,23 @@ func parseUbvInfo(ubvFile string, scanner *bufio.Scanner) UbvFile {
log.Fatal("Error parsing frame size!", err)
}

// Ignore Track 1003 (unknown purpose, first discovered in #44)
if frame.TrackNumber == TrackUnknown {
continue
}

// Bail if we encounter an unexpected track number
// We could silently ignore it, but it seems more useful to know about new cases
if frame.TrackNumber != 7 && frame.TrackNumber != 1000 {
log.Fatal("Encountered track number other than 7 or 1000: ", frame.TrackNumber)
if frame.TrackNumber != TrackVideo && frame.TrackNumber != TrackAudio {
log.Fatal("Encountered unrecognisdd track number, please report this. Track Number: ", frame.TrackNumber)
}

track, ok := current.Tracks[frame.TrackNumber]

if !ok {
track = &UbvTrack{
// TODO should really test field FIELD_TRACK_TYPE holds (A or V)
IsVideo: frame.TrackNumber == 7,
IsVideo: frame.TrackNumber == TrackVideo,
TrackNumber: frame.TrackNumber,
FrameCount: 0,
}
Expand Down

0 comments on commit d900315

Please sign in to comment.