summaryrefslogtreecommitdiff
path: root/src/encoder/plugins
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2016-05-09 14:13:45 +0200
committerMax Kellermann <max@duempel.org>2016-05-09 14:51:07 +0200
commit068de7cf40bf2d0cd7c15f18980a35cb228ba97c (patch)
tree6762ab2b3b3df28fdefc892fd520eacf31559f52 /src/encoder/plugins
parentd04eb87c4f9fe91123c525d9967d05dbc4b5c85f (diff)
encoder/ogg: use class OggStreamState
Diffstat (limited to 'src/encoder/plugins')
-rw-r--r--src/encoder/plugins/OggEncoder.hxx38
-rw-r--r--src/encoder/plugins/OpusEncoderPlugin.cxx6
-rw-r--r--src/encoder/plugins/VorbisEncoderPlugin.cxx2
3 files changed, 32 insertions, 14 deletions
diff --git a/src/encoder/plugins/OggEncoder.hxx b/src/encoder/plugins/OggEncoder.hxx
index 7a64c4dc1..8749aaf87 100644
--- a/src/encoder/plugins/OggEncoder.hxx
+++ b/src/encoder/plugins/OggEncoder.hxx
@@ -22,7 +22,8 @@
#include "config.h"
#include "../EncoderAPI.hxx"
-#include "lib/xiph/OggStream.hxx"
+#include "lib/xiph/OggStreamState.hxx"
+#include "lib/xiph/OggPage.hxx"
#include "lib/xiph/OggSerial.hxx"
#include <ogg/ogg.h>
@@ -32,27 +33,44 @@
* with Ogg container output.
*/
class OggEncoder : public Encoder {
+ /* initialize "flush" to true, so the caller gets the full
+ headers on the first read */
+ bool flush = true;
+
protected:
- OggStream stream;
+ OggStreamState stream;
public:
OggEncoder(bool _implements_tag)
- :Encoder(_implements_tag) {
- stream.Initialize(GenerateOggSerial());
- }
-
- ~OggEncoder() override {
- stream.Deinitialize();
+ :Encoder(_implements_tag),
+ stream(GenerateOggSerial()) {
}
/* virtual methods from class Encoder */
bool Flush(Error &) override {
- stream.Flush();
+ Flush();
return true;
}
size_t Read(void *dest, size_t length) override {
- return stream.PageOut(dest, length);
+ ogg_page page;
+ bool success = stream.PageOut(page);
+ if (!success) {
+ if (flush) {
+ flush = false;
+ success = stream.Flush(page);
+ }
+
+ if (!success)
+ return 0;
+ }
+
+ return ReadPage(page, dest, length);
+ }
+
+protected:
+ void Flush() {
+ flush = true;
}
};
diff --git a/src/encoder/plugins/OpusEncoderPlugin.cxx b/src/encoder/plugins/OpusEncoderPlugin.cxx
index b01201501..63fcf557d 100644
--- a/src/encoder/plugins/OpusEncoderPlugin.cxx
+++ b/src/encoder/plugins/OpusEncoderPlugin.cxx
@@ -244,7 +244,7 @@ OpusEncoder::DoEncode(bool eos, Error &error)
bool
OpusEncoder::End(Error &error)
{
- stream.Flush();
+ Flush();
memset(buffer + buffer_position, 0,
buffer_size - buffer_position);
@@ -331,7 +331,7 @@ OpusEncoder::GenerateHead()
packet.granulepos = 0;
packet.packetno = packetno++;
stream.PacketIn(packet);
- stream.Flush();
+ Flush();
}
void
@@ -355,7 +355,7 @@ OpusEncoder::GenerateTags()
packet.granulepos = 0;
packet.packetno = packetno++;
stream.PacketIn(packet);
- stream.Flush();
+ Flush();
free(comments);
}
diff --git a/src/encoder/plugins/VorbisEncoderPlugin.cxx b/src/encoder/plugins/VorbisEncoderPlugin.cxx
index cad00bd9f..5ca2346a0 100644
--- a/src/encoder/plugins/VorbisEncoderPlugin.cxx
+++ b/src/encoder/plugins/VorbisEncoderPlugin.cxx
@@ -244,7 +244,7 @@ VorbisEncoder::PreTag(gcc_unused Error &error)
vorbis_analysis_init(&vd, &vi);
vorbis_block_init(&vd, &vb);
- stream.Flush();
+ Flush();
return true;
}