From a39b2bf47a70559ca8bcad2b2d178fadfe68688c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Tue, 4 Apr 2023 22:46:28 +0200 Subject: [PATCH] Make sync track compress better (backported from 88834b8) * Delta encoding for sync track frames. * Fix non-monotonic track frames --- lib/libmisc/sync.c | 13 +++++++++++++ tools/sync2c/main.go | 18 +++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/libmisc/sync.c b/lib/libmisc/sync.c index 06c3cc7e..2a4ae770 100644 --- a/lib/libmisc/sync.c +++ b/lib/libmisc/sync.c @@ -28,6 +28,19 @@ void TrackInit(TrackT *track) { track->type = TRACK_LINEAR; track->pending = true; + { + short prevFrame = -1; + TrackKeyT *curr; + + for (curr = track->data; curr->frame != END_KEY; curr++) { + if (curr->frame < 0) + continue; + if (prevFrame >= 0) + curr->frame += prevFrame; + prevFrame = curr->frame; + } + } + TrackAdvance(track, track->data); } diff --git a/tools/sync2c/main.go b/tools/sync2c/main.go index acaf08ae..b59a4235 100644 --- a/tools/sync2c/main.go +++ b/tools/sync2c/main.go @@ -82,6 +82,18 @@ func parseFrame(token string) (frame int64, err error) { } } + if prevFrame >= 0 { + delta := frame - prevFrame + if delta < 0 { + return 0, &parseError{ + "frame numbers must be specified in ascending order"} + } + prevFrame = frame + frame = delta + } else { + prevFrame = frame + } + return frame, err } @@ -89,6 +101,8 @@ func parseValue(token string) (value int64, err error) { return strconv.ParseInt(token, 0, 16) } +var prevFrame int64 + func parseTrack(tokens []string, track *Track) (err error) { var frame, value int64 @@ -105,9 +119,6 @@ func parseTrack(tokens []string, track *Track) (err error) { if value, err = parseValue(tokens[1]); err != nil { return err } - if track.First != nil && track.First.Key > int(frame) { - return &parseError{"frame numbers must be specified in ascending order"} - } if len(tokens) == 3 && tokens[2][0] == '!' { typ := tokens[2][1:] @@ -167,6 +178,7 @@ func parseSyncFile(path string) []Track { // Create new track if tokens[0] == "@track" { + prevFrame = -1 track = &Track{RawName: tokens[1]} continue }