changeset 5305:77ac28af44ec

- Add parsing of Sync Layer Descriptor - Add a function to cleanup malloced mem from mp4_parse_esds - Fix some weird code from me :)
author atmos4
date Sun, 24 Mar 2002 06:10:13 +0000
parents 6175c9cfab11
children 4b32fe3758fa
files libmpdemux/demux_mov.c libmpdemux/parse_mp4.c libmpdemux/parse_mp4.h
diffstat 3 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_mov.c	Sun Mar 24 03:08:20 2002 +0000
+++ b/libmpdemux/demux_mov.c	Sun Mar 24 06:10:13 2002 +0000
@@ -706,21 +706,17 @@
 		      case MOV_FOURCC('e','s','d','s'): {
 			mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Found MPEG4 audio Elementary Stream Descriptor atom (%d)!\n", atom_len);
 			if(atom_len >= 8) {
-			  esds_t *esds = (esds_t *)malloc(sizeof(esds_t)); 				  
-			  if(esds && !mp4_parse_esds(&trak->stdata[36], atom_len-8, esds)) {
+			  esds_t esds; 				  
+			  if(!mp4_parse_esds(&trak->stdata[36], atom_len-8, &esds)) {
 			    
-			    sh->i_bps = esds->avgBitrate/8; 
+			    sh->i_bps = esds.avgBitrate/8; 
 
 			    // dump away the codec specific configuration for the AAC decoder
-			    sh->codecdata_len = esds->decoderConfigLen;
+			    sh->codecdata_len = esds.decoderConfigLen;
 			    sh->codecdata = (unsigned char *)malloc(sh->codecdata_len);
-			    memcpy(sh->codecdata, esds->decoderConfig, sh->codecdata_len);
+			    memcpy(sh->codecdata, esds.decoderConfig, sh->codecdata_len);
 			  }
-			  if(esds) {
-			    if(esds->decoderConfig)
-			      free(esds->decoderConfig);
-			    free(esds);
-			  }
+			  mp4_free_esds(&esds); // freeup esds mem
 #if 0
 	  		  { FILE* f=fopen("esds.dat","wb");
 			  fwrite(&trak->stdata[36],atom_len-8,1,f);
--- a/libmpdemux/parse_mp4.c	Sun Mar 24 03:08:20 2002 +0000
+++ b/libmpdemux/parse_mp4.c	Sun Mar 24 06:10:13 2002 +0000
@@ -29,10 +29,10 @@
   return length;
 }
 
+/* parse the data part of MP4 esds atoms */
 int mp4_parse_esds(unsigned char *data, int datalen, esds_t *esds) {
   /* create memory stream from data */
   stream_t *s = new_memory_stream(data, datalen);
-  uint8_t tag;
   uint8_t len;
 
   esds->version = stream_read_char(s);
@@ -42,8 +42,7 @@
       esds->version, esds->flags);
 
   /* get and verify ES_DescrTag */
-  tag = stream_read_char(s);
-  if (tag == MP4ESDescrTag) {
+  if (stream_read_char(s) == MP4ESDescrTag) {
     /* read length */
     if ((len = mp4_read_descr_len(s)) < 5 + 15) {
       freereturn(s,1);
@@ -107,11 +106,40 @@
   mp_msg(MSGT_DEMUX, MP4_DL,
       "ESDS MPEG4 Decoder Specific Descriptor (%dBytes)\n", len);
 
+  /* get and verify SLConfigDescrTag */
+  if(stream_read_char(s) != MP4SLConfigDescrTag) {
+    freereturn(s,1);
+  }
+
+  if((len = mp4_read_descr_len(s)) < 1) {
+    freereturn(s,1);
+  }
+
+  /* Note: SLConfig is usually constant value 2 size 1Byte */
+  esds->SLConfigLen = len;
+  esds->SLConfig = malloc(esds->SLConfigLen);
+  if (esds->SLConfig) {
+    stream_read(s, esds->SLConfig, esds->SLConfigLen);
+  } else {
+    esds->SLConfigLen = 0;
+  }
+  mp_msg(MSGT_DEMUX, MP4_DL,
+      "ESDS MPEG4 Sync Layer Config Descriptor (%dBytes)\n"
+      " -> predefined: %d\n", len, esds->SLConfig[0]);
+
   /* will skip the remainder of the atom */
   freereturn(s,0);
 
 }
 
+/* cleanup all mem occupied by mp4_parse_esds */
+void mp4_free_esds(esds_t *esds) {
+  if(esds->decoderConfig)
+    free(esds->decoderConfig);
+  if(esds->SLConfig)
+    free(esds->SLConfig);
+}
+
 #undef freereturn
 #undef MP4_DL
 
--- a/libmpdemux/parse_mp4.h	Sun Mar 24 03:08:20 2002 +0000
+++ b/libmpdemux/parse_mp4.h	Sun Mar 24 06:10:13 2002 +0000
@@ -73,6 +73,7 @@
 } esds_t;
 
 int mp4_parse_esds(unsigned char *data, int datalen, esds_t *esds);
+void mp4_free_esds(esds_t *esds); 
 
 #endif /* !__PARSE_MP4_H */