ref: dd41cd4fed85524d9fdf6f2e5be442080f5f0537
parent: 1ca49d92b96753fad580a3f2e9867836d379809d
author: Jean-Marc Valin <[email protected]>
date: Fri May 5 12:38:20 EDT 2017
switch for the packer
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -113,6 +113,15 @@
EncStream *last_stream;
};
+#ifdef USE_OGGP
+static void output_pages(OggOpusEnc *enc) {
+ unsigned char *page;
+ int len;
+ while (oggp_get_next_page(enc->oggp, &page, &len)) {
+ enc->callbacks.write(enc->streams->user_data, page, len);
+ }
+}
+#else
static int oe_write_page(OggOpusEnc *enc, ogg_page *page, void *user_data)
{
int length;
@@ -125,6 +134,7 @@
if (enc->page_callback) enc->page_callback(user_data, length, 0);
return length;
}
+#endif
static int oe_flush_page(OggOpusEnc *enc) {
ogg_page og;
@@ -133,13 +143,7 @@
#ifdef USE_OGGP
oggp_flush_page(enc->oggp);
- {
- unsigned char *page;
- int len;
- while (oggp_get_next_page(enc->oggp, &page, &len)) {
- enc->callbacks.write(enc->streams->user_data, page, len);
- }
- }
+ output_pages(enc);
#endif
while ( (ret = ogg_stream_flush_fill(&enc->streams->os, &og, 255*255))) {
@@ -384,7 +388,9 @@
opus_int32 pred;
int flush_needed;
ogg_packet op;
+#ifndef USE_OGGP
ogg_page og;
+#endif
int nbBytes;
unsigned char packet[MAX_PACKET_SIZE];
int is_keyframe=0;
@@ -419,27 +425,14 @@
}
if (enc->packet_callback) enc->packet_callback(enc->streams->user_data, op.packet, op.bytes, 0);
/* FIXME: Also flush on too many segments. */
+#ifdef USE_OGGP
+ flush_needed = op.e_o_s;
+ if (flush_needed) oe_flush_page(enc);
+ else output_pages(enc);
+#else
flush_needed = op.e_o_s || enc->curr_granule - enc->last_page_granule >= enc->max_ogg_delay;
if (flush_needed) {
-#if 1
oe_flush_page(enc);
-#else
- oggp_flush_page(enc->oggp);
- {
- unsigned char *page;
- int len;
- while (oggp_get_next_page(enc->oggp, &page, &len)) {
- fwrite(page, 1, len, stdout);
- fflush(stdout);
- }
- }
- while (ogg_stream_flush_fill(&enc->streams->os, &og, 255*255)) {
- if (ogg_page_packets(&og) != 0) enc->last_page_granule = ogg_page_granulepos(&og) + enc->streams->granule_offset;
- int ret = oe_write_page(enc, &og, enc->streams->user_data);
- /* FIXME: what do we do if this fails? */
- assert(ret != -1);
- }
-#endif
} else {
while (ogg_stream_pageout_fill(&enc->streams->os, &og, 255*255)) {
if (ogg_page_packets(&og) != 0) enc->last_page_granule = ogg_page_granulepos(&og) + enc->streams->granule_offset;
@@ -448,6 +441,7 @@
assert(ret != -1);
}
}
+#endif
if (op.e_o_s) {
EncStream *tmp;
tmp = enc->streams->next;