[Asterisk-cvs] asterisk/formats format_wav.c,1.14,1.15

markster at lists.digium.com markster at lists.digium.com
Mon Feb 2 00:25:46 CST 2004


Update of /usr/cvsroot/asterisk/formats
In directory mongoose.digium.com:/tmp/cvs-serv17920/formats

Modified Files:
	format_wav.c 
Log Message:
Handle more complex wav files


Index: format_wav.c
===================================================================
RCS file: /usr/cvsroot/asterisk/formats/format_wav.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- format_wav.c	22 Jan 2004 21:30:04 -0000	1.14
+++ format_wav.c	2 Feb 2004 06:34:27 -0000	1.15
@@ -128,7 +128,7 @@
 		ast_log(LOG_WARNING, "Read failed (formtype)\n");
 		return -1;
 	}
-	if (ltohl(hsize) != 16) {
+	if (ltohl(hsize) < 16) {
 		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
 		return -1;
 	}
@@ -174,19 +174,36 @@
 		ast_log(LOG_WARNING, "Read failed (Bits Per Sample): %d\n", ltohs(bisam));
 		return -1;
 	}
-        /* Begin data chunk */
-	if (read(fd, &data, 4) != 4) {
-		ast_log(LOG_WARNING, "Read failed (data)\n");
+	// Skip any additional header
+	if ( lseek(fd,ltohl(hsize)-16,SEEK_CUR) == -1 ) {
+		ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 );
 		return -1;
 	}
-	if (memcmp(&data, "data", 4)) {
-		ast_log(LOG_WARNING, "Does not say data\n");
+	// Skip any facts and get the first data block
+	for(;;)
+	{ 
+            char buf[4];
+	    
+	    /* Begin data chunk */
+	    if (read(fd, &buf, 4) != 4) {
+		ast_log(LOG_WARNING, "Read failed (data)\n");
 		return -1;
-	}
-	/* Data has the actual length of data in it */
-	if (read(fd, &data, 4) != 4) {
+	    }
+	    /* Data has the actual length of data in it */
+	    if (read(fd, &data, 4) != 4) {
 		ast_log(LOG_WARNING, "Read failed (data)\n");
 		return -1;
+	    }
+	    data = ltohl(data);
+	    if( memcmp(buf, "data", 4) == 0 ) break;
+	    if( memcmp(buf, "fact", 4) != 0 ) {
+		ast_log(LOG_WARNING, "Unknown block - not fact or data\n");
+		return -1;
+	    }
+	    if ( lseek(fd,data,SEEK_CUR) == -1 ) {
+		ast_log(LOG_WARNING, "Failed to skip fact block: %d\n", data );
+		return -1;
+	    }
 	}
 #if 0
 	curpos = lseek(fd, 0, SEEK_CUR);
@@ -194,7 +211,7 @@
 	lseek(fd, curpos, SEEK_SET);
 	truelength -= curpos;
 #endif	
-	return ltohl(data);
+	return data;
 }
 
 static int update_header(int fd)




More information about the svn-commits mailing list