aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/decoder/OggUtil.cxx25
-rw-r--r--src/decoder/OggUtil.hxx20
-rw-r--r--src/decoder/OpusDecoderPlugin.cxx11
3 files changed, 48 insertions, 8 deletions
diff --git a/src/decoder/OggUtil.cxx b/src/decoder/OggUtil.cxx
index 7dda282c8..b821acfc6 100644
--- a/src/decoder/OggUtil.cxx
+++ b/src/decoder/OggUtil.cxx
@@ -51,3 +51,28 @@ OggExpectPage(ogg_sync_state &oy, ogg_page &page,
return false;
}
}
+
+bool
+OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
+ decoder *decoder, input_stream *is)
+{
+ ogg_page page;
+ if (!OggExpectPage(oy, page, decoder, is))
+ return false;
+
+ ogg_stream_init(&os, ogg_page_serialno(&page));
+ ogg_stream_pagein(&os, &page);
+ return true;
+}
+
+bool
+OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
+ decoder *decoder, input_stream *is)
+{
+ ogg_page page;
+ if (!OggExpectPage(oy, page, decoder, is))
+ return false;
+
+ ogg_stream_pagein(&os, &page);
+ return true;
+}
diff --git a/src/decoder/OggUtil.hxx b/src/decoder/OggUtil.hxx
index c0be21faa..0ef4a0fa2 100644
--- a/src/decoder/OggUtil.hxx
+++ b/src/decoder/OggUtil.hxx
@@ -48,4 +48,24 @@ bool
OggExpectPage(ogg_sync_state &oy, ogg_page &page,
decoder *decoder, input_stream *input_stream);
+/**
+ * Combines OggExpectPage(), ogg_stream_init() and
+ * ogg_stream_pagein().
+ *
+ * @return true if the stream was initialized and the first page was
+ * delivered to it
+ */
+bool
+OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
+ decoder *decoder, input_stream *is);
+
+/**
+ * Combines OggExpectPage() and ogg_stream_pagein().
+ *
+ * @return true if a page was delivered to the stream
+ */
+bool
+OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
+ decoder *decoder, input_stream *is);
+
#endif
diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx
index 27bd702fa..827285775 100644
--- a/src/decoder/OpusDecoderPlugin.cxx
+++ b/src/decoder/OpusDecoderPlugin.cxx
@@ -269,8 +269,8 @@ mpd_opus_scan_stream(struct input_stream *is,
ogg_sync_state oy;
ogg_sync_init(&oy);
- ogg_page page;
- if (!OggExpectPage(oy, page, nullptr, is)) {
+ ogg_stream_state os;
+ if (!OggExpectFirstPage(oy, os, nullptr, is)) {
ogg_sync_clear(&oy);
return false;
}
@@ -280,10 +280,6 @@ mpd_opus_scan_stream(struct input_stream *is,
bool result = false;
- ogg_stream_state os;
- ogg_stream_init(&os, ogg_page_serialno(&page));
- ogg_stream_pagein(&os, &page);
-
ogg_packet packet;
while (true) {
int r = ogg_stream_packetout(&os, &packet);
@@ -296,12 +292,11 @@ mpd_opus_scan_stream(struct input_stream *is,
if (remaining_pages-- == 0)
break;
- if (!OggExpectPage(oy, page, nullptr, is)) {
+ if (!OggExpectPageIn(oy, os, nullptr, is)) {
result = false;
break;
}
- ogg_stream_pagein(&os, &page);
continue;
}