changeset 5206:2ca5a9bfaa98

allow sh_audio struct to be initialized by demuxer, add parsing of mp4 esds header to mov demuxer, init faad from info from mov header
author atmos4
date Tue, 19 Mar 2002 21:48:55 +0000
parents 47259a4f3216
children d337cc4ab0ee
files dec_audio.c libmpdemux/demux_mov.c
diffstat 2 files changed, 86 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/dec_audio.c	Tue Mar 19 19:22:00 2002 +0000
+++ b/dec_audio.c	Tue Mar 19 21:48:55 2002 +0000
@@ -328,15 +328,17 @@
 int init_audio(sh_audio_t *sh_audio){
 int driver=sh_audio->codec->driver;
 
-sh_audio->samplesize=2;
+if(!sh_audio->samplesize)
+  sh_audio->samplesize=2;
+if(!sh_audio->sample_format)
 #ifdef WORDS_BIGENDIAN
-sh_audio->sample_format=AFMT_S16_BE;
+  sh_audio->sample_format=AFMT_S16_BE;
 #else
-sh_audio->sample_format=AFMT_S16_LE;
+  sh_audio->sample_format=AFMT_S16_LE;
 #endif
-sh_audio->samplerate=0;
+//sh_audio->samplerate=0;
 //sh_audio->pcm_bswap=0;
-sh_audio->o_bps=0;
+//sh_audio->o_bps=0;
 
 sh_audio->a_buffer_size=0;
 sh_audio->a_buffer=NULL;
@@ -840,16 +842,15 @@
   faacDecConfigurationPtr faac_conf;
   faac_hdec = faacDecOpen();
 
-#if 0
+#if 1
   /* Set the default object type and samplerate */
   /* This is useful for RAW AAC files */
   faac_conf = faacDecGetCurrentConfiguration(faac_hdec);
   if(sh_audio->samplerate)
     faac_conf->defSampleRate = sh_audio->samplerate;
-  /* XXX: is outputFormat samplesize of compressed data or samplesize of
-   * decoded data, maybe upsampled? Also, FAAD support FLOAT output,
-   * how do we handle that (FAAD_FMT_FLOAT)? ::atmos
-   */
+   /* XXX: FAAD support FLOAT output, how do we handle
+    * that (FAAD_FMT_FLOAT)? ::atmos
+    */
   if(sh_audio->samplesize)
     switch(sh_audio->samplesize){
       case 1: // 8Bit
@@ -865,7 +866,7 @@
 	faac_conf->outputFormat = FAAD_FMT_32BIT;
 	break;
     }
-  faac_conf->defObjectType = LTP; // => MAIN, LC, SSR, LTP available.
+  //faac_conf->defObjectType = LTP; // => MAIN, LC, SSR, LTP available.
 
   faacDecSetConfiguration(faac_hdec, faac_conf);
 #endif
@@ -887,7 +888,11 @@
     mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: Negotiated samplerate: %dHz  channels: %d\n", faac_samplerate, faac_channels);
     sh_audio->channels = faac_channels;
     sh_audio->samplerate = faac_samplerate;
-    sh_audio->i_bps = 128*1000/8; // XXX: HACK!!! There's currently no way to get bitrate from libfaad2! ::atmos
+    if(!sh_audio->i_bps) {
+      mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: compressed input bitrate missing, assuming 128kbit/s!\n");
+      sh_audio->i_bps = 128*1000/8; // XXX: HACK!!! There's currently no way to get bitrate from libfaad2! ::atmos
+    } else 
+      mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: got %dkbit/s rate from MP4 header!\n",sh_audio->i_bps*8/1000);
   }  
 	    
 } break;		
--- a/libmpdemux/demux_mov.c	Tue Mar 19 19:22:00 2002 +0000
+++ b/libmpdemux/demux_mov.c	Tue Mar 19 21:48:55 2002 +0000
@@ -562,9 +562,37 @@
 	    mov_build_index(trak);
 	    switch(trak->type){
 	    case MOV_TRAK_AUDIO: {
+#if 0				   
+		struct {
+		   int16_t version;		// 0 or 1 (version 1 is qt3.0+)
+		   int16_t revision;		// 0
+		   int32_t vendor_id;		// 0
+		   int16_t channels;		// 1 or 2  (Mono/Stereo)
+		   int16_t samplesize;		// 8 or 16 (8Bit/16Bit)	
+		   int16_t compression_id;	// if version 0 then 0
+		  				// if version 1 and vbr then -2 else 0
+		   int16_t packet_size;		// 0
+		   uint32_t sample_rate;	// samplerate (Hz)
+		   // qt3.0+ (version == 1)
+		   uint32_t samples_per_packet;	// 0 or num uncompressed samples in a packet
+		   				// if 0 below three values are also 0
+		   uint32_t bytes_per_packet;	// 0 or num compressed bytes for one channel
+		   uint32_t bytes_per_frame;	// 0 or num compressed bytes for all channels
+		   				// (channels * bytes_per_packet)
+		   uint32_t bytes_per_sample;	// 0 or size of uncompressed sample
+		   // if samples_per_packet and bytes_per_packet are constant (CBR)
+		   // then bytes_per_frame and bytes_per_sample must be 0 (else is VBR)
+		   // ---
+		   // optional additional atom-based fields
+		   // ([int32_t size,int32_t type,some data ],repeat)
+		} my_stdata;		  
+#endif		
 		sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db);
 		sh->format=trak->fourcc;
 
+// assumptions for below table: short is 16bit, int is 32bit		
+// short values are usually one byte leftpadded by zero		
+//   int values are usually two byte leftpadded by zero		
 //  stdata[]:
 //	8   short	version
 //	10  short	revision
@@ -579,8 +607,48 @@
 //	32  int		bytes_per_packet
 //	36  int		bytes_per_frame
 //	40  int		bytes_per_sample
+// my recoveries from .mp4 files with correct index (counting from 0):
+// it's always start with padding/real start		
+//    8/ 9  short	version	
+//   10/11  short	revision	
+//   12/14  int		vendor_id	
+//   16/17  short	channels
+//   18/19  short	samplesize
+//   20/21  short	compression_id		
+//   22/23  short	packet_size (XXX: this overlaps with sample_rate ?)		
+//   22/24  int		sample_rate		
+// esds atom:
+//   28/31  int		atom size (bytes of int size, int type and data)
+//   32/32  int		atom type (fourc charater code -> esds)		
+//   62/63  int  	compressed datarate (Bits)
 
-		mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio bits: %d  chans: %d\n",trak->stdata[19],trak->stdata[17]);
+#define char2short(x,y) ((x[y]<<8)|x[y+1])
+#define char2int(x,y) ((x[y]<<24)|(x[y+1]<<16)|(x[y+2]<<8)|x[y+3])
+
+		sh->samplesize=char2short(trak->stdata,18)/8;
+		sh->channels=char2short(trak->stdata,16);
+		sh->samplerate=char2short(trak->stdata,24);
+
+		mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio bits: %d  chans: %d\n",
+		    trak->stdata[19],trak->stdata[17]);
+		mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio sample rate: %d\n",
+		    char2short(trak->stdata,24));
+		if((trak->stdata[9]==0) && trak->stdata_len >= 36) { // version 0 with extra atoms
+		    int atom_len = char2int(trak->stdata,28);
+		    switch(char2int(trak->stdata,32)) { // atom type
+		      case MOV_FOURCC('e','s','d','s'):
+			mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: MP4 esds audio atom found (%d)!\n", atom_len);
+			if(atom_len >= 28)
+			  mp_msg(MSGT_DEMUX, MSGL_INFO, "Audio compressed datarate: %dkbit/s\n",
+			      char2int(trak->stdata,62)/1000);
+			  sh->i_bps=char2int(trak->stdata,62)/8;
+			break;
+		      default:
+			mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: unknown audio atom %c%c%c%c found (%d)!\n",
+			    trak->stdata[32],trak->stdata[33],trak->stdata[34],trak->stdata[35],
+			    atom_len);
+		    }
+		}  
 		mp_msg(MSGT_DEMUX, MSGL_INFO, "Fourcc: %.4s\n",&trak->fourcc);
 #if 0
 		{ FILE* f=fopen("stdata.dat","wb");