mirror of https://github.com/nu774/fdkaac.git
cleanup interface of aac_encode_frame()
This commit is contained in:
parent
556a3db11b
commit
3b518efd31
16
src/aacenc.c
16
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue