]> iEval git - fdkaac.git/commitdiff
cleanup interface of aac_encode_frame()
authornu774 <honeycomb77@gmail.com>
Tue, 29 Oct 2013 15:46:11 +0000 (00:46 +0900)
committernu774 <honeycomb77@gmail.com>
Tue, 29 Oct 2013 17:09:23 +0000 (02:09 +0900)
src/aacenc.c
src/aacenc.h
src/main.c

index bf975d0778c67ce71cfbee8b97415a6e0782461c..99c288a03a2d8feea78a6327118e81e93051dddf 100644 (file)
@@ -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;
 }
index 2db945f6b7d0fae181bd3a4dc387fdc31fb7a661..dc6751baad831449ad6c392d64a3ce674805e0b5 100644 (file)
@@ -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
index 5e0dc0cfdcc9902a10e821c02d5e9f16a6f78825..d06c6830fefdc69a11c99440422247886aba008b 100644 (file)
@@ -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;
This page took 0.032707 seconds and 4 git commands to generate.