summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2019-01-24 21:11:38 -0600
committerWilliam Wilgus <me.theuser@yahoo.com>2019-01-25 04:18:51 +0100
commit96052373490095cd02fca7eb6ccdcfabe6403803 (patch)
tree8a78cfd440f853e395adec247538f153983992d5 /lib/rbcodec/codecs
parentcdd470832628b4d8b1db86dc597fec89a027fc37 (diff)
downloadrockbox-96052373490095cd02fca7eb6ccdcfabe6403803.tar.gz
rockbox-96052373490095cd02fca7eb6ccdcfabe6403803.zip
opus fix comment skipping code
opus requires the comment header to be a valid file our codec attemps to skip the comment data in order to reduce the ram allocated originally it caused files with large album art to skip the beginning of tracks my first attempt at fixing this then caused files with low bitrates to do the same while fixing files with large album art This patch should fix both although the initial start might be a bit slower but this shouldn't cause too much of an issue Change-Id: Ia1c3561347894cc45f24bb2659436914f8f03b43
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 */