shithub: libopusenc

Download patch

ref: 501276975a414ebae14193db2d9e1f8fab644fbe
parent: 3e3296d3231e93a864782f5314f405dc332cdac0
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Thu Dec 28 13:12:48 EST 2017

fixes lookahead when application is changed

--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -323,14 +323,7 @@
     enc->re = NULL;
   }
   opus_multistream_encoder_ctl(st, OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_20_MS));
-  {
-    opus_int32 tmp;
-    int ret;
-    ret = opus_multistream_encoder_ctl(st, OPUS_GET_LOOKAHEAD(&tmp));
-    if (ret == OPUS_OK) enc->header.preskip = tmp;
-    else enc->header.preskip = 0;
-    enc->global_granule_offset = enc->header.preskip;
-  }
+  enc->global_granule_offset = -1;
   enc->curr_granule = 0;
   enc->write_granule = 0;
   enc->last_page_granule = 0;
@@ -389,6 +382,15 @@
   }
   comment_pad(&enc->streams->comment, &enc->streams->comment_length, enc->comment_padding);
 
+  /* Get preskip at the last minute (when it can no longer change). */
+  if (enc->global_granule_offset == -1) {
+    opus_int32 tmp;
+    int ret;
+    ret = opus_multistream_encoder_ctl(enc->st, OPUS_GET_LOOKAHEAD(&tmp));
+    if (ret == OPUS_OK) enc->header.preskip = tmp;
+    else enc->header.preskip = 0;
+    enc->global_granule_offset = enc->header.preskip;
+  }
   /*Write header*/
   {
     int packet_size;