shithub: libopusenc

Download patch

ref: 8ff3ed213f0d01ef7eef1dcca27bed4393cf6e1d
parent: 2347d1570f016b15d4fa2afc641b77e5dfcda2a3
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Tue May 2 13:51:59 EDT 2017

trying to compute preskip (doesn't work)

--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -103,6 +103,7 @@
   int frame_size;
   int decision_delay;
   int max_ogg_delay;
+  int granule_offset;
   ogg_int64_t curr_granule;
   ogg_int64_t write_granule;
   ogg_int64_t last_page_granule;
@@ -250,6 +251,7 @@
     ret = opus_multistream_encoder_ctl(st, OPUS_GET_LOOKAHEAD(&tmp));
     if (ret == OPUS_OK) enc->header.preskip = tmp;
     else enc->header.preskip = 0;
+    enc->granule_offset = enc->header.preskip;
   }
   enc->curr_granule = 0;
   enc->write_granule = 0;
@@ -325,7 +327,7 @@
 
 static void encode_buffer(OggOpusEnc *enc) {
   /* Round up when converting the granule pos because the decoder will round down. */
-  ogg_int64_t end_granule48k = (enc->streams->end_granule*48000 + enc->rate - 1)/enc->rate + enc->header.preskip;
+  ogg_int64_t end_granule48k = (enc->streams->end_granule*48000 + enc->rate - 1)/enc->rate + enc->granule_offset;
   while (enc->buffer_end-enc->buffer_start > enc->frame_size + enc->decision_delay) {
     int cont;
     int flush_needed;
@@ -374,9 +376,10 @@
         if (!tmp) enc->last_stream = NULL;
         if (enc->last_stream == NULL) return;
         /* We're done with this stream, start the next one. */
-        /* FIXME: Update preskip. */
+        /* FIXME: preskip seems to not work right. */
+        enc->header.preskip = end_granule48k + enc->frame_size - enc->curr_granule;
         init_stream(enc);
-        end_granule48k = (enc->streams->end_granule*48000 + enc->rate - 1)/enc->rate + enc->header.preskip;
+        end_granule48k = (enc->streams->end_granule*48000 + enc->rate - 1)/enc->rate + enc->granule_offset;
         op.granulepos=enc->curr_granule;
         op.e_o_s=enc->curr_granule >= end_granule48k;
         cont = 1;