ref: 4b7cc4e78aaf63bf3ac16e6ab1d62d8094517023
parent: f96fe8f3ed9930800a20fdacbb2b2d0569b49f8b
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Tue May 2 10:49:17 EDT 2017
per-stream end granule
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -87,6 +87,7 @@
int comment_length;
int seen_file_icons;
int close_at_end;
+ ogg_int64_t end_granule;
EncStream *next;
};
@@ -102,7 +103,7 @@
int decision_delay;
int max_ogg_delay;
ogg_int64_t curr_granule;
- ogg_int64_t end_granule;
+ ogg_int64_t write_granule;
ogg_int64_t last_page_granule;
OpusEncCallbacks callbacks;
OpusHeader header;
@@ -249,7 +250,7 @@
else enc->header.preskip = 0;
}
enc->curr_granule = 0;
- enc->end_granule = 0;
+ enc->write_granule = 0;
enc->last_page_granule = 0;
if ( (enc->buffer = malloc(sizeof(*enc->buffer)*BUFFER_SAMPLES*channels)) == NULL) goto fail;
enc->buffer_start = enc->buffer_end = 0;
@@ -325,7 +326,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->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->header.preskip;
while (enc->buffer_end-enc->buffer_start > enc->frame_size + enc->decision_delay) {
int flush_needed;
ogg_packet op;
@@ -386,7 +387,8 @@
int channels = enc->channels;
if (!enc->streams->stream_is_init) init_stream(enc);
if (samples_per_channel < 0) return OPE_BAD_ARG;
- enc->end_granule += samples_per_channel;
+ enc->write_granule += samples_per_channel;
+ enc->last_stream->end_granule = enc->write_granule;
do {
int i;
spx_uint32_t in_samples, out_samples;
@@ -417,7 +419,8 @@
int channels = enc->channels;
if (!enc->streams->stream_is_init) init_stream(enc);
if (samples_per_channel < 0) return OPE_BAD_ARG;
- enc->end_granule += samples_per_channel;
+ enc->write_granule += samples_per_channel;
+ enc->last_stream->end_granule = enc->write_granule;
do {
int i;
spx_uint32_t in_samples, out_samples;