summaryrefslogtreecommitdiff
path: root/plugins/mpgmad
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-02-12 17:52:06 +0100
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2014-02-12 17:52:06 +0100
commit417370b9319ee9aca376fdd50480b1b8d97960a0 (patch)
tree18ca280ea15f6d0f47feb38d75f2b7167c916a79 /plugins/mpgmad
parent1c2464304743732edc342f94d227cebfdfb33ed6 (diff)
mpgmad: optimize frame syncing by reducing number of backward seeks
Diffstat (limited to 'plugins/mpgmad')
-rw-r--r--plugins/mpgmad/mpgmad.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c
index b450ffbc..e3bbd68a 100644
--- a/plugins/mpgmad/mpgmad.c
+++ b/plugins/mpgmad/mpgmad.c
@@ -238,6 +238,8 @@ cmp3_scan_stream (buffer_t *buffer, int sample) {
}
for (;;) {
+ uint32_t hdr;
+ uint8_t sync;
// {{{ parse frame header, sync stream
// mp3 files often have some garbage in the beginning
// try to skip it if this is the case
@@ -254,12 +256,18 @@ cmp3_scan_stream (buffer_t *buffer, int sample) {
break; // eof
}
- uint32_t hdr;
- uint8_t sync = fb[0];
+retry_sync:
+
+ sync = fb[0];
if (sync != 0xff) {
// trace ("[1]frame %d didn't seek to frame end\n", nframe);
lastframe_valid = 0;
- continue; // not an mpeg frame
+ memmove (fb, fb+1, 3);
+ if (deadbeef->fread (fb+3, 1, 1, buffer->file) != 1) {
+ break; // eof
+ }
+ offs++;
+ goto retry_sync; // not an mpeg frame
}
else {
// 2nd sync byte
@@ -267,7 +275,12 @@ cmp3_scan_stream (buffer_t *buffer, int sample) {
if ((sync >> 5) != 7) {
// trace ("[2]frame %d didn't seek to frame end\n", nframe);
lastframe_valid = 0;
- continue;
+ memmove (fb, fb+1, 3);
+ if (deadbeef->fread (fb+3, 1, 1, buffer->file) != 1) {
+ break; // eof
+ }
+ offs++;
+ goto retry_sync; // not an mpeg frame
}
}
// found frame