Mercurial > mplayer.hg
annotate libmpdemux/mp3_hdr.c @ 15158:d570dfbf9ef6
--Patch by Stefan '1stein' Schuermans <1stein@schuermans.info>:
bugfix of the "grayscale" output scheme; the height and width of the movie
were written als -1 and -1 into the resulting *.bml file
author | rik |
---|---|
date | Thu, 14 Apr 2005 12:44:28 +0000 |
parents | c9e2d75a9013 |
children | 980910eb6f0c |
rev | line source |
---|---|
2588 | 1 #include <stdio.h> |
2 | |
3 #include "config.h" | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
4 #include "../mp_msg.h" |
2588 | 5 |
6 //----------------------- mp3 audio frame header parser ----------------------- | |
7 | |
8 static int tabsel_123[2][3][16] = { | |
7910
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
9 { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0}, |
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
10 {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,0}, |
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
11 {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,0} }, |
2588 | 12 |
7910
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
13 { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,0}, |
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
14 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0}, |
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
15 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0} } |
2588 | 16 }; |
10369 | 17 |
18 static long freqs[9] = { 44100, 48000, 32000, // MPEG 1.0 | |
19 22050, 24000, 16000, // MPEG 2.0 | |
10370 | 20 11025, 12000, 8000}; // MPEG 2.5 |
2588 | 21 |
5806 | 22 int mp_mp3_get_lsf(unsigned char* hbuf){ |
23 unsigned long newhead = | |
24 hbuf[0] << 24 | | |
25 hbuf[1] << 16 | | |
26 hbuf[2] << 8 | | |
27 hbuf[3]; | |
28 if( newhead & ((long)1<<20) ) { | |
29 return (newhead & ((long)1<<19)) ? 0x0 : 0x1; | |
30 } | |
31 return 1; | |
32 } | |
33 | |
2588 | 34 /* |
35 * return frame size or -1 (bad frame) | |
36 */ | |
6763 | 37 int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate){ |
10369 | 38 int stereo,ssize,lsf,framesize,padding,bitrate_index,sampling_frequency; |
15039 | 39 int layer, mult[3] = { 12000, 144000, 144000 }; |
2588 | 40 unsigned long newhead = |
41 hbuf[0] << 24 | | |
42 hbuf[1] << 16 | | |
43 hbuf[2] << 8 | | |
44 hbuf[3]; | |
45 | |
46 // printf("head=0x%08X\n",newhead); | |
47 | |
48 #if 1 | |
49 // head_check: | |
10369 | 50 if( (newhead & 0xffe00000) != 0xffe00000 ){ |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
51 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"head_check failed\n"); |
2588 | 52 return -1; |
53 } | |
54 #endif | |
55 | |
15039 | 56 layer = 4-((newhead>>17)&3); |
57 if(layer==4){ | |
58 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"not layer-1/2/3\n"); | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
59 return -1; |
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
60 } |
2588 | 61 |
10370 | 62 sampling_frequency = ((newhead>>10)&0x3); // valid: 0..2 |
10369 | 63 if(sampling_frequency==3){ |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
64 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"invalid sampling_frequency\n"); |
10370 | 65 return -1; |
2588 | 66 } |
67 | |
10369 | 68 if( newhead & ((long)1<<20) ) { |
69 // MPEG 1.0 (lsf==0) or MPEG 2.0 (lsf==1) | |
70 lsf = (newhead & ((long)1<<19)) ? 0x0 : 0x1; | |
71 sampling_frequency += (lsf*3); | |
72 } else { | |
73 // MPEG 2.5 | |
74 lsf = 1; | |
75 sampling_frequency += 6; | |
76 } | |
77 | |
78 // crc = ((newhead>>16)&0x1)^0x1; | |
10370 | 79 bitrate_index = ((newhead>>12)&0xf); // valid: 1..14 |
2588 | 80 padding = ((newhead>>9)&0x1); |
81 // fr->extension = ((newhead>>8)&0x1); | |
82 // fr->mode = ((newhead>>6)&0x3); | |
83 // fr->mode_ext = ((newhead>>4)&0x3); | |
84 // fr->copyright = ((newhead>>3)&0x1); | |
85 // fr->original = ((newhead>>2)&0x1); | |
86 // fr->emphasis = newhead & 0x3; | |
87 | |
88 stereo = ( (((newhead>>6)&0x3)) == 3) ? 1 : 2; | |
89 | |
10369 | 90 // !checked later through tabsel_123[]! |
91 // if(!bitrate_index || bitrate_index==15){ | |
92 // mp_msg(MSGT_DEMUXER,MSGL_DBG2,"Free format not supported.\n"); | |
93 // return -1; | |
94 // } | |
2588 | 95 |
96 if(lsf) | |
97 ssize = (stereo == 1) ? 9 : 17; | |
98 else | |
99 ssize = (stereo == 1) ? 17 : 32; | |
10369 | 100 if(!((newhead>>16)&0x1)) ssize += 2; // CRC |
2588 | 101 |
15039 | 102 framesize = tabsel_123[lsf][layer-1][bitrate_index] * mult[layer-1]; |
7910
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
103 |
15039 | 104 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"FRAMESIZE: %d, layer: %d, bitrate: %d, mult: %d\n", |
105 framesize, layer, tabsel_123[lsf][layer-1][bitrate_index], mult[layer-1]); | |
7910
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
106 if(!framesize){ |
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
107 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"invalid framesize/bitrate_index\n"); |
10370 | 108 return -1; |
7910
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
109 } |
5a276890cec4
check for framesize validity, return -1 (error) for zero size (bug found by pl)
arpi
parents:
6763
diff
changeset
|
110 |
2588 | 111 framesize /= freqs[sampling_frequency]<<lsf; |
15039 | 112 if(layer==1) |
113 framesize = (framesize+padding)*4; | |
114 else | |
115 framesize += padding; | |
2588 | 116 |
117 // if(framesize<=0 || framesize>MAXFRAMESIZE) return FALSE; | |
6763 | 118 if(srate) *srate = freqs[sampling_frequency]; |
119 if(chans) *chans = stereo; | |
2588 | 120 |
121 return framesize; | |
122 } | |
123 |