[MPlayer-cvslog] CVS: main/libmpdemux mp3_hdr.c, 1.9, 1.10 mp3_hdr.h, 1.2, 1.3 demux_audio.c, 1.31, 1.32
Nico Sabbi CVS
syncmail at mplayerhq.hu
Sun Apr 17 11:42:53 CEST 2005
CVS change done by Nico Sabbi CVS
Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var2/tmp/cvs-serv27674
Modified Files:
mp3_hdr.c mp3_hdr.h demux_audio.c
Log Message:
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
Index: mp3_hdr.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/mp3_hdr.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- mp3_hdr.c 2 Apr 2005 10:30:19 -0000 1.9
+++ mp3_hdr.c 17 Apr 2005 09:42:51 -0000 1.10
@@ -34,7 +34,7 @@
/*
* 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* spf, int* mpa_layer){
int stereo,ssize,lsf,framesize,padding,bitrate_index,sampling_frequency;
int layer, mult[3] = { 12000, 144000, 144000 };
unsigned long newhead =
@@ -115,7 +115,20 @@
framesize += padding;
// if(framesize<=0 || framesize>MAXFRAMESIZE) return FALSE;
- if(srate) *srate = freqs[sampling_frequency];
+ if(srate) {
+ *srate = freqs[sampling_frequency];
+ if(spf) {
+ if(layer == 1)
+ *spf = 384;
+ else if(layer == 2)
+ *spf = 1152;
+ else if(*srate < 32000)
+ *spf = 576;
+ else
+ *spf = 1152;
+ }
+ }
+ if(mpa_layer) *mpa_layer = layer;
if(chans) *chans = stereo;
return framesize;
Index: mp3_hdr.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/mp3_hdr.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- mp3_hdr.h 21 Jul 2002 14:36:33 -0000 1.2
+++ mp3_hdr.h 17 Apr 2005 09:42:51 -0000 1.3
@@ -1,7 +1,7 @@
-int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* freq);
+int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* freq, int* spf, int* mpa_layer);
-#define mp_decode_mp3_header(hbuf) mp_get_mp3_header(hbuf,NULL,NULL)
+#define mp_decode_mp3_header(hbuf) mp_get_mp3_header(hbuf,NULL,NULL,NULL,NULL)
static inline int mp_check_mp3_header(unsigned int head){
if( (head & 0x0000e0ff) != 0x0000e0ff ||
Index: demux_audio.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_audio.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- demux_audio.c 4 Mar 2005 01:53:55 -0000 1.31
+++ demux_audio.c 17 Apr 2005 09:42:51 -0000 1.32
@@ -117,7 +117,7 @@
stream_t *s;
sh_audio_t* sh_audio;
uint8_t hdr[HDR_SIZE];
- int frmt = 0, n = 0, step, mp3_freq, mp3_chans, mp3_flen;
+ int frmt = 0, n = 0, step, mp3_freq, mp3_chans, mp3_flen, mpa_layer = 3, mpa_spf = 1152;
off_t st_pos = 0, next_frame_pos = 0;
// mp3_hdrs list is sorted first by next_frame_pos and then by frame_pos
mp3_hdr_t *mp3_hdrs = NULL, *mp3_found = NULL;
@@ -157,7 +157,7 @@
} else if( hdr[0] == 'f' && hdr[1] == 'm' && hdr[2] == 't' && hdr[3] == ' ' ) {
frmt = WAV;
break;
- } else if((mp3_flen = mp_get_mp3_header(hdr,&mp3_chans,&mp3_freq)) > 0) {
+ } else if((mp3_flen = mp_get_mp3_header(hdr,&mp3_chans,&mp3_freq,&mpa_spf,&mpa_layer)) > 0) {
mp3_found = add_mp3_hdr(&mp3_hdrs, st_pos, mp3_chans, mp3_freq, mp3_flen);
if (mp3_found) {
frmt = MP3;
@@ -184,17 +184,17 @@
switch(frmt) {
case MP3:
- sh_audio->format = 0x55;
+ sh_audio->format = (mpa_layer < 3 ? 0x50 : 0x55);
demuxer->movi_start = mp3_found->frame_pos;
next_frame_pos = mp3_found->next_frame_pos;
sh_audio->audio.dwSampleSize= 0;
- sh_audio->audio.dwScale = 1152;
+ sh_audio->audio.dwScale = mpa_spf;
sh_audio->audio.dwRate = mp3_found->mp3_freq;
sh_audio->wf = malloc(sizeof(WAVEFORMATEX));
sh_audio->wf->wFormatTag = sh_audio->format;
sh_audio->wf->nChannels = mp3_found->mp3_chans;
sh_audio->wf->nSamplesPerSec = mp3_found->mp3_freq;
- sh_audio->wf->nBlockAlign = 1152;
+ sh_audio->wf->nBlockAlign = mpa_spf;
sh_audio->wf->wBitsPerSample = 16;
sh_audio->wf->cbSize = 0;
free(mp3_found);
@@ -397,7 +397,7 @@
dp = new_demux_packet(l);
memcpy(dp->buffer,hdr,4);
stream_read(s,dp->buffer + 4,l-4);
- priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + 1152/(float)sh_audio->samplerate; // FIXME: 1152->576 if MPEG-2
+ priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + sh_audio->audio.dwScale/(float)sh_audio->samplerate;
break;
}
} break;
@@ -433,7 +433,7 @@
da_priv_t* priv = demuxer->priv;
sh_audio_t* sh = (sh_audio_t*)demuxer->audio->sh;
- nf = time*sh->samplerate/1152;
+ nf = time*sh->samplerate/sh->audio.dwScale;
while(nf > 0) {
stream_read(demuxer->stream,hdr,4);
len = mp_decode_mp3_header(hdr);
@@ -442,7 +442,7 @@
continue;
}
stream_skip(demuxer->stream,len-4);
- priv->last_pts += 1152/(float)sh->samplerate;
+ priv->last_pts += sh->audio.dwScale/(float)sh->samplerate;
nf--;
}
}
More information about the MPlayer-cvslog
mailing list