summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/opus.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/opus.c')
-rw-r--r--lib/rbcodec/codecs/opus.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/rbcodec/codecs/opus.c b/lib/rbcodec/codecs/opus.c
index 1ce7f19dfd..6574d6c052 100644
--- a/lib/rbcodec/codecs/opus.c
+++ b/lib/rbcodec/codecs/opus.c
@@ -57,6 +57,27 @@ static int get_more_data(ogg_sync_state *oy)
57 57
58 return bytes; 58 return bytes;
59} 59}
60
61/* seek to ogg page after given file position */
62static int seek_ogg_page(int64_t filepos)
63{
64 const char synccode[] = "OggS\0"; /* Note: there are two nulls here */
65 char buf[sizeof(synccode)];
66 ci->seek_buffer(filepos);
67 while (ci->read_filebuf(buf, 1) == 1) {
68 if (buf[0] == synccode[0]) {
69 if (ci->read_filebuf(&buf[1], sizeof(buf) - 1) != sizeof(buf) - 1)
70 break;
71 if (memcmp(buf, synccode, sizeof(buf)) == 0) {
72 ci->seek_buffer(ci->curpos - sizeof(buf));
73 LOGF("next page %ld", ci->curpos);
74 return 1;
75 }
76 }
77 }
78 return 0;
79}
80
60/* The read/seek functions track absolute position within the stream */ 81/* The read/seek functions track absolute position within the stream */
61static int64_t get_next_page(ogg_sync_state *oy, ogg_page *og, 82static int64_t get_next_page(ogg_sync_state *oy, ogg_page *og,
62 int64_t boundary) 83 int64_t boundary)
@@ -408,8 +429,12 @@ enum codec_status codec_run(void)
408 429
409 /* Do this to avoid allocating space for huge comment packets 430 /* Do this to avoid allocating space for huge comment packets
410 (embedded Album Art) */ 431 (embedded Album Art) */
411 if(os.packetno == 1 && ogg_stream_packetpeek(&os, &op) != 1){ 432 if (os.packetno == 1 && ogg_stream_packetpeek(&os, NULL) == 0){
412 ogg_sync_reset(&oy); 433 LOGF("sync reset");
434 /* seek buffer directly to the first audio packet */
435 seek_ogg_page(ci->curpos - oy.returned);
436 ogg_sync_reset(&oy);
437 break;
413 } 438 }
414 439
415 while ((ogg_stream_packetout(&os, &op) == 1) && !op.e_o_s) { 440 while ((ogg_stream_packetout(&os, &op) == 1) && !op.e_o_s) {