History

flac: parse seek table as toc

Sigrid Solveig Haflínudóttir committed 2 years ago

Commit f68e9971 parent c074cc22 files · +34 −2Browse files

Unified · Split

2 files
  1. flac.c +33 −2
  2. tagspriv.h +1 −0
flac.c+33−2
@@ -6,8 +6,8 @@ · 5 unmodified lines
66 int
77 tagflac(Tagctx *ctx)
88 {
9+ int sz, last, type, seektbloff, seektblsz, off;
910 uint8_t *d;
10− int sz, last, type;
1111 uint64_t g;
1212
1313 d = (uint8_t*)ctx->buf;
@@ -37,7 +37,12 @@ tagflac(Tagctx *ctx) · 23 unmodified lines
3737 if((d[0] & 0x80) != 0)
3838 last = 1;
3939
40− if((d[0] & 0x7f) == 6){ /* 6 = picture */
40+ if((d[0] & 0x7f) == 3 && ctx->toc != nil){ /* 3 = seek table */
41+ seektbloff = ctx->seek(ctx, 0, 1);
42+ seektblsz = sz;
43+ if(ctx->seek(ctx, sz, 1) <= 0)
44+ return -1;
45+ }else if((d[0] & 0x7f) == 6){ /* 6 = picture */
4146 int n, offset;
4247 char *mime;
4348
@@ -117,5 +122,31 @@ tagflac(Tagctx *ctx) · 73 unmodified lines
117122 return -1;
118123 }
119124
125+ if(ctx->toc == nil)
126+ return 0;
127+ off = ctx->seek(ctx, 0, 1);
128+ if(seektbloff <= 0 || off <= seektbloff || ctx->seek(ctx, seektbloff, 0) != seektbloff)
129+ return 0;
130+
131+ for(; seektblsz >= 18; seektblsz -= 18){
132+ if(ctx->read(ctx, d, 18) != 18)
133+ break;
134+
135+ /* sample offset */
136+ g = (uint64_t)beuint(d+0)<<32 | beuint(d+4);
137+ if(g == ~0ULL) /* placeholder */
138+ break;
139+ g = g * 1000 / ctx->samplerate;
140+ if(g > INT_MAX)
141+ break;
142+ int ms = g;
143+
144+ /* frame offset */
145+ g = off + ((uint64_t)beuint(d+8)<<32 | beuint(d+12));
146+ if(g > INT_MAX)
147+ break;
148+ ctx->toc(ctx, ms, g);
149+ }
150+
120151 return 0;
121152 }
tagspriv.h+1−0
@@ -1,3 +1,4 @@
1+#include <limits.h>
12 #include <stdbool.h>
23 #include <stdint.h>
34 #include <stdio.h>

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t