ref: f7eb13670a2aabafd990a84dd91f14cce156bc1a
parent: 9a523c9fb2d7dda319bbf2df013541962eb3ba6a
author: menno <menno>
date: Tue Jan 23 08:48:53 EST 2001
ADTS headers supported
--- a/libfaac/bitstream.c
+++ b/libfaac/bitstream.c
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: bitstream.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ * $Id: bitstream.c,v 1.2 2001/01/23 13:46:18 menno Exp $
*/
#include <stdlib.h>
@@ -28,7 +28,8 @@
#include "bitstream.h"
-int WriteBitstream(CoderInfo *coderInfo,
+int WriteBitstream(faacEncHandle hEncoder,
+ CoderInfo *coderInfo,
ChannelInfo *channelInfo,
BitStream *bitStream,
int numChannel)
@@ -37,6 +38,10 @@
int bits = 0;
int bitsLeftAfterFill, numFillBits;
+ CountBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannel);
+
+ bits += WriteADTSHeader(hEncoder, bitStream, 1);
+
for (channel = 0; channel < numChannel; channel++) {
if (channelInfo[channel].present) {
@@ -96,15 +101,18 @@
return bits;
}
-int CountBitstream(CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int numChannel)
+static int CountBitstream(faacEncHandle hEncoder,
+ CoderInfo *coderInfo,
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int numChannel)
{
int channel;
int bits = 0;
int bitsLeftAfterFill, numFillBits;
+ bits += WriteADTSHeader(hEncoder, bitStream, 0);
+
for (channel = 0; channel < numChannel; channel++) {
if (channelInfo[channel].present) {
@@ -160,7 +168,37 @@
/* Now byte align the bitstream */
bits += ByteAlign(bitStream, 0);
+ hEncoder->usedBytes = bit2byte(bits);
+
return bits;
+}
+
+static int WriteADTSHeader(faacEncHandle hEncoder,
+ BitStream *bitStream,
+ int writeFlag)
+{
+ if (writeFlag) {
+ /* Fixed ADTS header */
+ PutBit(bitStream, 0xFFFF, 12); // 12 bit Syncword
+ PutBit(bitStream, 1, 1); // ID
+ PutBit(bitStream, 0, 2); // layer
+ PutBit(bitStream, 1, 1); // protection absent
+ PutBit(bitStream, hEncoder->aacProfile, 2); // profile
+ PutBit(bitStream, hEncoder->sampleRateIdx, 4); // sampling rate
+ PutBit(bitStream, 0, 1); // private bit
+ PutBit(bitStream, 1, 3); // ch. config (must be > 0)
+ PutBit(bitStream, 0, 1); // original/copy
+ PutBit(bitStream, 0, 1); // home
+ PutBit(bitStream, 0, 2); // emphasis
+
+ /* Variable ADTS header */
+ PutBit(bitStream, 0, 1); // copyr. id. bit
+ PutBit(bitStream, 0, 1); // copyr. id. start
+ PutBit(bitStream, hEncoder->usedBytes, 13);
+ PutBit(bitStream, 0x7FF, 11); // buffer fullness (0x7FF for VBR)
+ PutBit(bitStream, 0, 2); // raw data blocks (0+1=1)
+ }
+ return 58;
}
static int WriteCPE(CoderInfo *coderInfoL,
--- a/libfaac/bitstream.h
+++ b/libfaac/bitstream.h
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: bitstream.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ * $Id: bitstream.h,v 1.2 2001/01/23 13:46:18 menno Exp $
*/
#ifndef BITSTREAM_H
@@ -26,6 +26,7 @@
extern "C" {
#endif /* __cplusplus */
+#include "frame.h"
#include "coder.h"
#include "channels.h"
@@ -113,15 +114,21 @@
-int WriteBitstream(CoderInfo *coderInfo,
+int WriteBitstream(faacEncHandle hEncoder,
+ CoderInfo *coderInfo,
ChannelInfo *channelInfo,
BitStream *bitStream,
int numChannels);
-int CountBitstream(CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int numChannels);
+static int CountBitstream(faacEncHandle hEncoder,
+ CoderInfo *coderInfo,
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int numChannels);
+
+static int WriteADTSHeader(faacEncHandle hEncoder,
+ BitStream *bitStream,
+ int writeFlag);
static int WriteCPE(CoderInfo *coderInfoL,
CoderInfo *coderInfoR,
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: frame.c,v 1.2 2001/01/17 15:51:15 menno Exp $
+ * $Id: frame.c,v 1.3 2001/01/23 13:46:18 menno Exp $
*/
/*
@@ -74,6 +74,7 @@
/* Initialize variables to default values */
hEncoder->frameNum = 0;
hEncoder->flushFrame = 0;
+ hEncoder->aacProfile = 0; /* MAIN = 0, LOW = 1, SSR = 2 */
hEncoder->config.allowMidside = 1;
hEncoder->config.useLfe = 0;
hEncoder->config.bitRate = 64000; /* default bitrate / channel */
@@ -280,7 +281,7 @@
/* Write the AAC bitstream */
bitStream = OpenBitStream(bufferSize, outputBuffer);
- WriteBitstream(coderInfo, channelInfo, bitStream, numChannels);
+ WriteBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannels);
/* Close the bitstream and return the number of bytes written */
frameBytes = CloseBitStream(bitStream);
--- a/libfaac/frame.h
+++ b/libfaac/frame.h
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: frame.h,v 1.2 2001/01/17 15:51:15 menno Exp $
+ * $Id: frame.h,v 1.3 2001/01/23 13:46:18 menno Exp $
*/
#ifndef FRAME_H
@@ -66,6 +66,9 @@
/* samplerate of AAC file */
unsigned long sampleRate;
unsigned int sampleRateIdx;
+
+ unsigned int aacProfile;
+ unsigned int usedBytes;
/* frame number */
unsigned int frameNum;
--- a/todo.txt
+++ b/todo.txt
@@ -3,7 +3,7 @@
- DONE: Add frequency cutoff filter
-- Add ADTS headers
+- DONE: Add ADTS headers
- Add TNS
- Add PNS
- Add LTP