Skip to content

Commit

Permalink
Make sync track compress better (backported from 88834b8)
Browse files Browse the repository at this point in the history
* Delta encoding for sync track frames.
* Fix non-monotonic track frames
  • Loading branch information
cahirwpz committed Dec 16, 2023
1 parent 977aee6 commit a39b2bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/libmisc/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
18 changes: 15 additions & 3 deletions tools/sync2c/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,27 @@ 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
}

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

Expand All @@ -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:]
Expand Down Expand Up @@ -167,6 +178,7 @@ func parseSyncFile(path string) []Track {

// Create new track
if tokens[0] == "@track" {
prevFrame = -1
track = &Track{RawName: tokens[1]}
continue
}
Expand Down

0 comments on commit a39b2bf

Please sign in to comment.