shithub: aacenc

Download patch

ref: 19f9c28af484bf6a00d42aec2e2243fd14c53df7
parent: 191d2de75e1259a15d2d84ece35b688a13615329
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Sat Sep 2 07:22:51 EDT 2017

MP4 max frame size calculation moved to library

--- a/frontend/main.c
+++ b/frontend/main.c
@@ -273,12 +273,6 @@
 volatile int running = 1;
 #endif
 
-enum stream_format
-{
-    RAW_STREAM = 0,
-    ADTS_STREAM = 1,
-};
-
 enum container_format
 {
     NO_CONTAINER,
@@ -827,7 +821,7 @@
 
     /* open the encoder library */
     hEncoder = faacEncOpen(infile->samplerate, infile->channels,
-                           &samplesInput, &maxBytesOutput);
+                           &samplesInput, &maxBytesOutput, container == MP4_CONTAINER);
 
     if (hEncoder == NULL)
     {
@@ -850,7 +844,6 @@
     {
         mpegVersion = MPEG4;
         stream = RAW_STREAM;
-        maxBytesOutput = 0x1000 * infile->channels;
     }
 
     frameSize = samplesInput / infile->channels;
--- a/include/faac.h
+++ b/include/faac.h
@@ -76,8 +76,9 @@
 faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
 				  unsigned int numChannels,
 				  unsigned long *inputSamples,
-				  unsigned long *maxOutputBytes);
-
+                                  unsigned long *maxOutputBytes,
+                                  int mp4file
+                                 );
 
 int FAACAPI faacEncGetDecoderSpecificInfo(faacEncHandle hEncoder, unsigned char **ppBuffer,
 					  unsigned long *pSizeOfDecoderSpecificInfo);
--- a/include/faaccfg.h
+++ b/include/faaccfg.h
@@ -45,6 +45,12 @@
 #define SHORTCTL_NOSHORT   1
 #define SHORTCTL_NOLONG    2
 
+enum stream_format
+{
+    RAW_STREAM = 0,
+    ADTS_STREAM = 1,
+};
+
 #pragma pack(push, 1)
 typedef struct faacEncConfiguration
 {
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -275,7 +275,9 @@
 faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
                                   unsigned int numChannels,
                                   unsigned long *inputSamples,
-                                  unsigned long *maxOutputBytes)
+                                  unsigned long *maxOutputBytes,
+                                  int mp4file
+                                 )
 {
     unsigned int channel;
     faacEncStruct* hEncoder;
@@ -284,7 +286,10 @@
 	return NULL;
 
     *inputSamples = FRAME_LEN*numChannels;
-    *maxOutputBytes = (6144/8)*numChannels;
+    if (mp4file)
+        *maxOutputBytes = 0x1000 * numChannels;
+    else
+        *maxOutputBytes = (6144/8)*numChannels;
 
 #ifdef DRM
     *maxOutputBytes += 1; /* for CRC */
@@ -323,12 +328,10 @@
 	for( channel = 0; channel < MAX_CHANNELS; channel++ )
 		hEncoder->config.channel_map[channel] = channel;
 	
-    /*
-        by default we have to be compatible with all previous software
-        which assumes that we will generate ADTS
-        /AV
-    */
-    hEncoder->config.outputFormat = 1;
+    if (mp4file)
+        hEncoder->config.outputFormat = RAW_STREAM;
+    else
+        hEncoder->config.outputFormat = ADTS_STREAM;
 
     /*
         be compatible with software which assumes 24bit in 32bit PCM