00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027
00028 #include "avcodec.h"
00029 #include "mpegaudio.h"
00030 #include "mpegaudiodata.h"
00031
00032
00033 int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
00034 {
00035 int sample_rate, frame_size, mpeg25, padding;
00036 int sample_rate_index, bitrate_index;
00037 if (header & (1<<20)) {
00038 s->lsf = (header & (1<<19)) ? 0 : 1;
00039 mpeg25 = 0;
00040 } else {
00041 s->lsf = 1;
00042 mpeg25 = 1;
00043 }
00044
00045 s->layer = 4 - ((header >> 17) & 3);
00046
00047 sample_rate_index = (header >> 10) & 3;
00048 sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
00049 sample_rate_index += 3 * (s->lsf + mpeg25);
00050 s->sample_rate_index = sample_rate_index;
00051 s->error_protection = ((header >> 16) & 1) ^ 1;
00052 s->sample_rate = sample_rate;
00053
00054 bitrate_index = (header >> 12) & 0xf;
00055 padding = (header >> 9) & 1;
00056
00057 s->mode = (header >> 6) & 3;
00058 s->mode_ext = (header >> 4) & 3;
00059
00060
00061
00062
00063 if (s->mode == MPA_MONO)
00064 s->nb_channels = 1;
00065 else
00066 s->nb_channels = 2;
00067
00068 if (bitrate_index != 0) {
00069 frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
00070 s->bit_rate = frame_size * 1000;
00071 switch(s->layer) {
00072 case 1:
00073 frame_size = (frame_size * 12000) / sample_rate;
00074 frame_size = (frame_size + padding) * 4;
00075 break;
00076 case 2:
00077 frame_size = (frame_size * 144000) / sample_rate;
00078 frame_size += padding;
00079 break;
00080 default:
00081 case 3:
00082 frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
00083 frame_size += padding;
00084 break;
00085 }
00086 s->frame_size = frame_size;
00087 } else {
00088
00089 return 1;
00090 }
00091
00092 #if defined(DEBUG)
00093 dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ",
00094 s->layer, s->sample_rate, s->bit_rate);
00095 if (s->nb_channels == 2) {
00096 if (s->layer == 3) {
00097 if (s->mode_ext & MODE_EXT_MS_STEREO)
00098 dprintf(s->avctx, "ms-");
00099 if (s->mode_ext & MODE_EXT_I_STEREO)
00100 dprintf(s->avctx, "i-");
00101 }
00102 dprintf(s->avctx, "stereo");
00103 } else {
00104 dprintf(s->avctx, "mono");
00105 }
00106 dprintf(s->avctx, "\n");
00107 #endif
00108 return 0;
00109 }