Unverified Commit b7182675 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

split the calls for draining and destroying the object

parent cd2f3a7f
......@@ -30,7 +30,8 @@ int main(int argc, char **argv) {
ope_write(enc, buf, ret);
} else break;
}
ope_close_and_free(enc);
ope_drain(enc);
ope_destroy(enc);
fclose(fin);
return 0;
}
......@@ -114,8 +114,11 @@ OPE_EXPORT int ope_write_float(OggOpusEnc *enc, const float *pcm, int samples_pe
/** Add/encode any number of int16 samples to the file. */
OPE_EXPORT int ope_write(OggOpusEnc *enc, const opus_int16 *pcm, int samples_per_channel);
/** Close/finalize the stream. */
OPE_EXPORT int ope_close_and_free(OggOpusEnc *enc);
/** Finalizes the stream, but does not deallocate the object. */
OPE_EXPORT int ope_drain(OggOpusEnc *enc);
/** Deallocates the obect. Make sure to ope_drain() first. */
OPE_EXPORT void ope_destroy(OggOpusEnc *enc);
/** Ends the stream and create a new stream within the same file. */
OPE_EXPORT int ope_chain_current(OggOpusEnc *enc);
......
......@@ -577,7 +577,7 @@ int ope_write(OggOpusEnc *enc, const opus_int16 *pcm, int samples_per_channel) {
return OPE_OK;
}
static void finalize_all_streams(OggOpusEnc *enc) {
int ope_drain(OggOpusEnc *enc) {
/* FIXME: Use a better value. */
int pad_samples = 3000;
if (!enc->streams->stream_is_init) init_stream(enc);
......@@ -589,11 +589,12 @@ static void finalize_all_streams(OggOpusEnc *enc) {
assert(enc->buffer_end <= BUFFER_SAMPLES);
encode_buffer(enc);
assert(enc->streams == NULL);
return OPE_OK;
}
/* Close/finalize the stream. */
int ope_close_and_free(OggOpusEnc *enc) {
finalize_all_streams(enc);
void ope_destroy(OggOpusEnc *enc) {
/* FIXME: cleanup non-closed streams if any remain. */
if (enc->chaining_keyframe) free(enc->chaining_keyframe);
free(enc->buffer);
#ifdef USE_OGGP
......@@ -602,7 +603,6 @@ int ope_close_and_free(OggOpusEnc *enc) {
opus_multistream_encoder_destroy(enc->st);
if (enc->re) speex_resampler_destroy(enc->re);
free(enc);
return OPE_OK;
}
/* Ends the stream and create a new stream within the same file. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment