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 };
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 */
fprintf(stderr, "ERROR: aacEncEncode() failed\n");
return -1;
}
- *olen = oargs.numOutBytes;
+ output->len = oargs.numOutBytes;
return oargs.numInSamples / format->channels_per_frame;
}
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,
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
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;
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;