rename aacenc_result_t -> aacenc_frame_t, simplify write_sample()
authornu774 <honeycomb77@gmail.com>
Wed, 30 Oct 2013 02:58:30 +0000 (11:58 +0900)
committernu774 <honeycomb77@gmail.com>
Wed, 30 Oct 2013 02:58:30 +0000 (11:58 +0900)
src/aacenc.c
src/aacenc.h
src/main.c

index 99c288a03a2d8feea78a6327118e81e93051dddf..364049884796370f732f845e989c7e4dcbc9d7c2 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,
-                     aacenc_result_t *output)
+                     aacenc_frame_t *output)
 {
     uint32_t ilen = iframes * format->channels_per_frame;
     AACENC_BufDesc ibdesc = { 0 }, obdesc = { 0 };
@@ -206,10 +206,10 @@ int aac_encode_frame(HANDLE_AACENCODER encoder,
 
     channel_mode = aacEncoder_GetParam(encoder, AACENC_CHANNELMODE);
     obytes = 6144 / 8 * channel_mode;
-    if (!output->data || output->size < obytes) {
+    if (!output->data || output->capacity < obytes) {
         uint8_t *p = realloc(output->data, obytes);
         if (!p) return -1;
-        output->size = obytes;
+        output->capacity = obytes;
         output->data = p;
     }
     obufs[0] = output->data;
@@ -232,6 +232,6 @@ int aac_encode_frame(HANDLE_AACENCODER encoder,
         fprintf(stderr, "ERROR: aacEncEncode() failed\n");
         return -1;
     }
-    output->len = oargs.numOutBytes;
+    output->size = oargs.numOutBytes;
     return oargs.numInSamples / format->channels_per_frame;
 }
index dc6751baad831449ad6c392d64a3ce674805e0b5..e622054ab265bf1218e4df88525e4de32ca4f099 100644 (file)
@@ -24,10 +24,10 @@ typedef struct aacenc_param_t {
     AACENC_PARAMS
 } aacenc_param_t;
 
-typedef struct aacenc_result_t {
+typedef struct aacenc_frame_t {
     uint8_t *data;
-    uint32_t len, size;
-} aacenc_result_t;
+    uint32_t size, capacity;
+} aacenc_frame_t;
 
 int aacenc_is_sbr_active(const aacenc_param_t *params);
 
@@ -42,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,
-                     aacenc_result_t *output);
+                     aacenc_frame_t *output);
 
 #endif
index 7d1a68fc885fb1abbe95b878b3161063eac15f98..c3a9cca5e45020283061491e274d479ec091b3ea 100644 (file)
@@ -472,16 +472,15 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
 };
 
 static
-int write_sample(FILE *ofp, m4af_ctx_t *m4af,
-                 const void *data, uint32_t size, uint32_t duration)
+int write_sample(FILE *ofp, m4af_ctx_t *m4af, aacenc_frame_t *frame)
 {
     if (!m4af) {
-        fwrite(data, 1, size, ofp);
+        fwrite(frame->data, 1, frame->size, ofp);
         if (ferror(ofp)) {
             fprintf(stderr, "ERROR: fwrite(): %s\n", strerror(errno));
             return -1;
         }
-    } else if (m4af_write_sample(m4af, 0, data, size, duration) < 0) {
+    } else if (m4af_write_sample(m4af, 0, frame->data, frame->size, 0) < 0) {
         fprintf(stderr, "ERROR: failed to write m4a sample\n");
         return -1;
     }
@@ -494,7 +493,7 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
            m4af_ctx_t *m4af)
 {
     int16_t *ibuf = 0, *ip;
-    aacenc_result_t obuf[2] = {{ 0 }}, *obp;
+    aacenc_frame_t obuf[2] = {{ 0 }}, *obp;
     unsigned flip = 0;
     int nread = 1;
     int rc = -1;
@@ -528,8 +527,8 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
             obp = &obuf[flip];
             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;
+            if (consumed == 0 && obp->size == 0) goto DONE;
+            if (obp->size == 0) break;
 
             remaining -= consumed;
             ip += consumed * fmt->channels_per_frame;
@@ -546,8 +545,7 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
             if (encoded == 1 || encoded == 3)
                 continue;
             obp = &obuf[flip];
-            if (write_sample(params->output_fp, m4af, obp->data, obp->len,
-                             frame_length) < 0)
+            if (write_sample(params->output_fp, m4af, obp) < 0)
                 goto END;
             ++frames_written;
         } while (remaining > 0);
@@ -829,9 +827,9 @@ int main(int argc, char **argv)
          * we push one zero frame to the encoder here, to make delay even
          */
         int16_t zero[8] = { 0 };
-        aacenc_result_t obuf = { 0 };
-        aac_encode_frame(encoder, sample_format, zero, 1, &obuf);
-        free(obuf.data);
+        aacenc_frame_t frame = { 0 };
+        aac_encode_frame(encoder, sample_format, zero, 1, &frame);
+        free(frame.data);
     }
     frame_count = encode(&params, reader, encoder, aacinfo.frameLength, m4af);
     if (frame_count < 0)
This page took 0.016427 seconds and 4 git commands to generate.