From b02f2f7daefb38c9eee671ca695c4980b464e697 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Fri, 24 Feb 2017 19:13:41 +0100 Subject: encca_aac: flush all the remaining packets from encoders --- libhb/platform/macosx/encca_aac.c | 47 +++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'libhb') diff --git a/libhb/platform/macosx/encca_aac.c b/libhb/platform/macosx/encca_aac.c index 422c59bdb..052eadb4b 100644 --- a/libhb/platform/macosx/encca_aac.c +++ b/libhb/platform/macosx/encca_aac.c @@ -51,6 +51,8 @@ struct hb_work_private_s uint64_t samples, ibytes; Float64 osamplerate; + int input_done; + hb_audio_remap_t *remap; }; @@ -377,7 +379,17 @@ static OSStatus inInputDataProc(AudioConverterRef converter, UInt32 *npackets, if (!pv->ibytes) { *npackets = 0; - return 1; + if (pv->input_done) + { + // EOF on input + buffers->mBuffers[0].mDataByteSize = 0; + return noErr; + } + else + { + // Not enough data available + return 1; + } } if (pv->buf != NULL) @@ -420,8 +432,12 @@ static hb_buffer_t* Encode(hb_work_object_t *w) hb_work_private_t *pv = w->private_data; UInt32 npackets = 1; - /* check if we need more data */ - if ((pv->ibytes = hb_list_bytes(pv->list)) < pv->isamples * pv->isamplesiz) + /* check if we need more data or we have already got to EOF + if so, we need to call the audio converter again even + without data to get out the remaining packets. + */ + if (pv->input_done != 1 && + (pv->ibytes = hb_list_bytes(pv->list)) < pv->isamples * pv->isamplesiz) { return NULL; } @@ -449,7 +465,6 @@ static hb_buffer_t* Encode(hb_work_object_t *w) // only drop the output buffer if it's actually empty if (!npackets || odesc.mDataByteSize <= 0) { - hb_log("encCoreAudio: 0 packets returned"); return NULL; } @@ -480,23 +495,20 @@ static hb_buffer_t* Flush(hb_work_object_t *w, hb_buffer_t *bufin) hb_list_add(pv->list, tmp); } - hb_buffer_t *bufout = NULL, *buf = NULL; - while (hb_list_bytes(pv->list) >= pv->isamples * pv->isamplesiz) + hb_buffer_t *bufout = NULL, *buf = NULL, *b = NULL; + while ((b = Encode(w))) { - hb_buffer_t *b = Encode(w); - if (b != NULL) + if (bufout == NULL) { - if (bufout == NULL) - { - bufout = b; - } - else - { - buf->next = b; - } - buf = b; + bufout = b; } + else + { + buf->next = b; + } + buf = b; } + // add the eof marker to the end of our buf chain if (buf != NULL) { @@ -526,6 +538,7 @@ int encCoreAudioWork(hb_work_object_t *w, hb_buffer_t **buf_in, { // EOF on input. Finish encoding what we have buffered then send // it & the eof downstream. + pv->input_done = 1; *buf_out = Flush(w, in); return HB_WORK_DONE; } -- cgit v1.2.3