aac: moved code to adts_check_frame()
adts_check_frame() checks whether the buffer head is an AAC frame, and returns the frame length.
This commit is contained in:
parent
b7ad3e4121
commit
f43e39047d
@ -93,6 +93,24 @@ static int adtsSampleRates[] =
|
|||||||
16000, 12000, 11025, 8000, 7350, 0, 0, 0
|
16000, 12000, 11025, 8000, 7350, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the buffer head is an AAC frame, and return the frame
|
||||||
|
* length. Returns 0 if it is not a frame.
|
||||||
|
*/
|
||||||
|
static size_t adts_check_frame(AacBuffer * b)
|
||||||
|
{
|
||||||
|
if (b->bytesIntoBuffer <= 7)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* check syncword */
|
||||||
|
if (!((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return (((unsigned int)b->buffer[3] & 0x3) << 11) |
|
||||||
|
(((unsigned int)b->buffer[4]) << 3) |
|
||||||
|
(b->buffer[5] >> 5);
|
||||||
|
}
|
||||||
|
|
||||||
static void adtsParse(AacBuffer * b, float *length)
|
static void adtsParse(AacBuffer * b, float *length)
|
||||||
{
|
{
|
||||||
unsigned int frames, frameLength;
|
unsigned int frames, frameLength;
|
||||||
@ -103,23 +121,14 @@ static void adtsParse(AacBuffer * b, float *length)
|
|||||||
for (frames = 0;; frames++) {
|
for (frames = 0;; frames++) {
|
||||||
fillAacBuffer(b);
|
fillAacBuffer(b);
|
||||||
|
|
||||||
if (b->bytesIntoBuffer > 7) {
|
frameLength = adts_check_frame(b);
|
||||||
/* check syncword */
|
if (frameLength > 0) {
|
||||||
if (!((b->buffer[0] == 0xFF) &&
|
|
||||||
((b->buffer[1] & 0xF6) == 0xF0))) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frames == 0) {
|
if (frames == 0) {
|
||||||
sampleRate = adtsSampleRates[(b->
|
sampleRate = adtsSampleRates[(b->
|
||||||
buffer[2] & 0x3c)
|
buffer[2] & 0x3c)
|
||||||
>> 2];
|
>> 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
frameLength = ((((unsigned int)b->buffer[3] & 0x3))
|
|
||||||
<< 11) | (((unsigned int)b->buffer[4])
|
|
||||||
<< 3) | (b->buffer[5] >> 5);
|
|
||||||
|
|
||||||
if (frameLength > b->bytesIntoBuffer)
|
if (frameLength > b->bytesIntoBuffer)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user