summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs')
-rw-r--r--lib/rbcodec/codecs/opus.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/rbcodec/codecs/opus.c b/lib/rbcodec/codecs/opus.c
index 89eb4fe3ad..acae1aaacc 100644
--- a/lib/rbcodec/codecs/opus.c
+++ b/lib/rbcodec/codecs/opus.c
@@ -78,6 +78,29 @@ static int seek_ogg_page(uint64_t filepos)
78 return 0; 78 return 0;
79} 79}
80 80
81/* seek to comment header */
82static int seek_opus_tags(void)
83{
84 int pos = 0;
85 const int64_t maxpos = sizeof(OpusHeader) + 1024;
86 const char synccode[] = "OpusTags";
87 char buf[sizeof(synccode)];
88 ci->seek_buffer(0);
89 while (ci->read_filebuf(buf, 1) == 1 && ci->curpos < maxpos) {
90 if (buf[0] == synccode[0]) {
91 if (ci->read_filebuf(&buf[1], sizeof(buf) - 2) != sizeof(buf) - 2)
92 break;
93 if (memcmp(buf, synccode, sizeof(buf)) == 0) {
94 ci->seek_buffer(ci->curpos - sizeof(buf));
95 LOGF("OpusTags %ld", ci->curpos);
96 return 1;
97 }
98 }
99 }
100 /* comment header not found probably invalid file */
101 return 0;
102}
103
81/* The read/seek functions track absolute position within the stream */ 104/* The read/seek functions track absolute position within the stream */
82static int64_t get_next_page(ogg_sync_state *oy, ogg_page *og, 105static int64_t get_next_page(ogg_sync_state *oy, ogg_page *og,
83 int64_t boundary) 106 int64_t boundary)
@@ -455,7 +478,12 @@ enum codec_status codec_run(void)
455 /* seek buffer directly to the first audio packet to avoid 478 /* seek buffer directly to the first audio packet to avoid
456 allocating space for huge comment packets 479 allocating space for huge comment packets
457 (embedded Album Art) */ 480 (embedded Album Art) */
458 seek_ogg_page(ci->curpos - oy.returned); 481 if (seek_opus_tags())
482 seek_ogg_page(ci->curpos);
483 else {
484 LOGF("Could not find comment header");
485 goto done;
486 }
459 } 487 }
460 LOGF("sync reset"); 488 LOGF("sync reset");
461 ogg_sync_reset(&oy); /* next page */ 489 ogg_sync_reset(&oy); /* next page */