mirror of https://github.com/mpv-player/mpv
better checks
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10370 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
188460e7ee
commit
a63bbf43fd
|
@ -14,7 +14,10 @@ static int tabsel_123[2][3][16] = {
|
||||||
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0},
|
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0},
|
||||||
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0} }
|
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0} }
|
||||||
};
|
};
|
||||||
static long freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 };
|
|
||||||
|
static long freqs[9] = { 44100, 48000, 32000, // MPEG 1.0
|
||||||
|
22050, 24000, 16000, // MPEG 2.0
|
||||||
|
11025, 12000 , 8000 }; // MPEG 2.5
|
||||||
|
|
||||||
int mp_mp3_get_lsf(unsigned char* hbuf){
|
int mp_mp3_get_lsf(unsigned char* hbuf){
|
||||||
unsigned long newhead =
|
unsigned long newhead =
|
||||||
|
@ -32,7 +35,7 @@ int mp_mp3_get_lsf(unsigned char* hbuf){
|
||||||
* return frame size or -1 (bad frame)
|
* return frame size or -1 (bad frame)
|
||||||
*/
|
*/
|
||||||
int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate){
|
int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate){
|
||||||
int stereo,ssize,crc,lsf,mpeg25,framesize,padding,bitrate_index,sampling_frequency;
|
int stereo,ssize,lsf,framesize,padding,bitrate_index,sampling_frequency;
|
||||||
unsigned long newhead =
|
unsigned long newhead =
|
||||||
hbuf[0] << 24 |
|
hbuf[0] << 24 |
|
||||||
hbuf[1] << 16 |
|
hbuf[1] << 16 |
|
||||||
|
@ -43,8 +46,7 @@ int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate){
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
// head_check:
|
// head_check:
|
||||||
if( (newhead & 0xffe00000) != 0xffe00000 ||
|
if( (newhead & 0xffe00000) != 0xffe00000 ){
|
||||||
(newhead & 0x0000fc00) == 0x0000fc00){
|
|
||||||
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"head_check failed\n");
|
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"head_check failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -55,25 +57,23 @@ int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( newhead & ((long)1<<20) ) {
|
sampling_frequency = ((newhead>>10)&0x3);
|
||||||
lsf = (newhead & ((long)1<<19)) ? 0x0 : 0x1;
|
if(sampling_frequency==3){
|
||||||
mpeg25 = 0;
|
|
||||||
} else {
|
|
||||||
lsf = 1;
|
|
||||||
mpeg25 = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mpeg25)
|
|
||||||
sampling_frequency = 6 + ((newhead>>10)&0x3);
|
|
||||||
else
|
|
||||||
sampling_frequency = ((newhead>>10)&0x3) + (lsf*3);
|
|
||||||
|
|
||||||
if(sampling_frequency>8){
|
|
||||||
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"invalid sampling_frequency\n");
|
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"invalid sampling_frequency\n");
|
||||||
return -1; // valid: 0..8
|
return -1; // valid: 0..8
|
||||||
}
|
}
|
||||||
|
|
||||||
crc = ((newhead>>16)&0x1)^0x1;
|
if( newhead & ((long)1<<20) ) {
|
||||||
|
// MPEG 1.0 (lsf==0) or MPEG 2.0 (lsf==1)
|
||||||
|
lsf = (newhead & ((long)1<<19)) ? 0x0 : 0x1;
|
||||||
|
sampling_frequency += (lsf*3);
|
||||||
|
} else {
|
||||||
|
// MPEG 2.5
|
||||||
|
lsf = 1;
|
||||||
|
sampling_frequency += 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// crc = ((newhead>>16)&0x1)^0x1;
|
||||||
bitrate_index = ((newhead>>12)&0xf);
|
bitrate_index = ((newhead>>12)&0xf);
|
||||||
padding = ((newhead>>9)&0x1);
|
padding = ((newhead>>9)&0x1);
|
||||||
// fr->extension = ((newhead>>8)&0x1);
|
// fr->extension = ((newhead>>8)&0x1);
|
||||||
|
@ -85,16 +85,17 @@ int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate){
|
||||||
|
|
||||||
stereo = ( (((newhead>>6)&0x3)) == 3) ? 1 : 2;
|
stereo = ( (((newhead>>6)&0x3)) == 3) ? 1 : 2;
|
||||||
|
|
||||||
if(!bitrate_index){
|
// !checked later through tabsel_123[]!
|
||||||
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"Free format not supported.\n");
|
// if(!bitrate_index || bitrate_index==15){
|
||||||
return -1;
|
// mp_msg(MSGT_DEMUXER,MSGL_DBG2,"Free format not supported.\n");
|
||||||
}
|
// return -1;
|
||||||
|
// }
|
||||||
|
|
||||||
if(lsf)
|
if(lsf)
|
||||||
ssize = (stereo == 1) ? 9 : 17;
|
ssize = (stereo == 1) ? 9 : 17;
|
||||||
else
|
else
|
||||||
ssize = (stereo == 1) ? 17 : 32;
|
ssize = (stereo == 1) ? 17 : 32;
|
||||||
if(crc) ssize += 2;
|
if(!((newhead>>16)&0x1)) ssize += 2; // CRC
|
||||||
|
|
||||||
framesize = tabsel_123[lsf][2][bitrate_index] * 144000;
|
framesize = tabsel_123[lsf][2][bitrate_index] * 144000;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue