From: nu774 Date: Tue, 29 Oct 2013 15:46:11 +0000 (+0900) Subject: cleanup interface of aac_encode_frame() X-Git-Tag: v0.4.2~4 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=3b518efd31691737ad2cca7764554208198f59a3;p=fdkaac.git cleanup interface of aac_encode_frame() --- diff --git a/src/aacenc.c b/src/aacenc.c index bf975d0..99c288a 100644 --- a/src/aacenc.c +++ b/src/aacenc.c @@ -187,7 +187,7 @@ FAIL: int aac_encode_frame(HANDLE_AACENCODER encoder, const pcm_sample_description_t *format, const int16_t *input, unsigned iframes, - uint8_t **output, uint32_t *olen, uint32_t *osize) + aacenc_result_t *output) { uint32_t ilen = iframes * format->channels_per_frame; AACENC_BufDesc ibdesc = { 0 }, obdesc = { 0 }; @@ -205,12 +205,14 @@ int aac_encode_frame(HANDLE_AACENCODER encoder, unsigned channel_mode, obytes; channel_mode = aacEncoder_GetParam(encoder, AACENC_CHANNELMODE); - obytes = 6144 / 8 * channel_mode + 7; - if (!*output || *osize < obytes) { - *osize = obytes; - *output = realloc(*output, obytes); + obytes = 6144 / 8 * channel_mode; + if (!output->data || output->size < obytes) { + uint8_t *p = realloc(output->data, obytes); + if (!p) return -1; + output->size = obytes; + output->data = p; } - obufs[0] = *output; + obufs[0] = output->data; obuf_sizes[0] = obytes; iargs.numInSamples = ilen ? ilen : -1; /* -1 for signaling EOF */ @@ -230,6 +232,6 @@ int aac_encode_frame(HANDLE_AACENCODER encoder, fprintf(stderr, "ERROR: aacEncEncode() failed\n"); return -1; } - *olen = oargs.numOutBytes; + output->len = oargs.numOutBytes; return oargs.numInSamples / format->channels_per_frame; } diff --git a/src/aacenc.h b/src/aacenc.h index 2db945f..dc6751b 100644 --- a/src/aacenc.h +++ b/src/aacenc.h @@ -24,6 +24,11 @@ typedef struct aacenc_param_t { AACENC_PARAMS } aacenc_param_t; +typedef struct aacenc_result_t { + uint8_t *data; + uint32_t len, size; +} aacenc_result_t; + int aacenc_is_sbr_active(const aacenc_param_t *params); int aacenc_mp4asc(const aacenc_param_t *params, @@ -37,6 +42,6 @@ int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params, int aac_encode_frame(HANDLE_AACENCODER encoder, const pcm_sample_description_t *format, const int16_t *input, unsigned iframes, - uint8_t **output, uint32_t *olen, uint32_t *osize); + aacenc_result_t *output); #endif diff --git a/src/main.c b/src/main.c index 5e0dc0c..d06c683 100644 --- a/src/main.c +++ b/src/main.c @@ -493,12 +493,8 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader, HANDLE_AACENCODER encoder, uint32_t frame_length, m4af_ctx_t *m4af) { - struct buffer_t { - uint8_t *data; - uint32_t len, size; - }; int16_t *ibuf = 0, *ip; - struct buffer_t obuf[2] = {{ 0 }}, *obp; + aacenc_result_t obuf[2] = {{ 0 }}, *obp; unsigned flip = 0; int nread = 1; int rc = -1; @@ -530,8 +526,7 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader, remaining = nread; do { obp = &obuf[flip]; - consumed = aac_encode_frame(encoder, fmt, ip, remaining, - &obp->data, &obp->len, &obp->size); + consumed = aac_encode_frame(encoder, fmt, ip, remaining, obp); if (consumed < 0) goto END; if (consumed == 0 && obp->len == 0) goto DONE; if (obp->len == 0) break;