[xiph-cvs] cvs commit: win32-tools/oggdrop Script.rc audio.c audio.h build_oggdrop.bat encthread.c main.c resource.h

Jack Moffitt jack at xiph.org
Sun Aug 12 13:08:39 PDT 2001



jack        01/08/12 13:08:39

  Modified:    oggdrop  Script.rc audio.c audio.h build_oggdrop.bat
                        encthread.c main.c resource.h
  Log:
  Added Chris Wolf's .wav patch.  That patch includes extra error handling.
  Also updated automated build script.

Revision  Changes    Path
1.3       +4 -0      win32-tools/oggdrop/Script.rc

Index: Script.rc
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/Script.rc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Script.rc	2000/11/18 03:30:20	1.2
+++ Script.rc	2001/08/12 20:08:38	1.3
@@ -82,6 +82,10 @@
             MENUITEM "256 kbps",                    IDM_BITRATE256
             MENUITEM "350 kbps",                    IDM_BITRATE350
         END
+        POPUP "Options"
+        BEGIN
+            MENUITEM "Errors to log file",          IDM_LOGERR
+        END
         MENUITEM "Always On Top",               IDM_ONTOP
         MENUITEM SEPARATOR
         MENUITEM "Quit",                        IDM_QUIT

1.2       +159 -18   win32-tools/oggdrop/audio.c

Index: audio.c
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/audio.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- audio.c	2000/11/07 09:01:39	1.1
+++ audio.c	2001/08/12 20:08:38	1.2
@@ -15,10 +15,10 @@
 #include <string.h>
 #include <sys/types.h>
 #include <malloc.h>
+#include <windows.h>
+#include <stdarg.h>
 #include "audio.h"
 
-#define WAV_HEADER_SIZE 44
-
 /* Macros to read header data */
 #define READ_U32(buf) \
         (((buf)[3]<<24)|((buf)[2]<<16)|((buf)[1]<<8)|((buf)[0]&0xff));
@@ -26,6 +26,9 @@
 #define READ_U16(buf) \
         (((buf)[1]<<8)|((buf)[0]&0xff));
 
+static char *_filename;
+void (*error_handler)(const char *fmt, ...) = error_dialog;
+
 static int find_chunk(FILE *in, char *type, unsigned int *len)
 {
         unsigned char buf[8];
@@ -34,6 +37,7 @@
         {
                 if(fread(buf,1,8,in) < 8) /* Suck down a chunk specifier */
                 {
+			error_handler("Unexpected EOF in reader WAV header");
                         fprintf(stderr, "Warning: Unexpected EOF in reading WAV header\n");
                         return 0; /* EOF before reaching the appropriate chunk */
                 }
@@ -49,9 +53,10 @@
                                 while(seek_needed>0)
                                 {
                                         seeked = fread(buf2,1,seek_needed>1024?1024:seek_needed,in);
-					if(!seeked)
+					if(!seeked) {
+						error_handler("Unexpected EOF in reading WAV header");
                                                 return 0; /* Couldn't read more, can't read file */
-					else
+					} else
                                                 seek_needed -= seeked;
                                 }
                         }
@@ -68,20 +73,22 @@
 
 int wav_open(FILE *in, oe_enc_opt *opt)
 {
-	unsigned char buf[16];
+	unsigned char hdrbuf[12];
+	unsigned char *buf;
         unsigned int len;
         wav_fmt format;
         wavfile *wav = malloc(sizeof(wavfile));
 
-	int ret = fread(buf, 1, 12, in);
+	int ret = fread(hdrbuf, 1, 12, in);
+
         if(ret < 12)
                 return 0;
 
-	if(memcmp(buf, "RIFF", 4))
+	if(memcmp(hdrbuf, "RIFF", 4))
                 return 0;
 
-	len = READ_U32(buf+4); /* We don't actually use this */
-	if(memcmp(buf+8, "WAVE",4))
+	len = READ_U32(hdrbuf+4); /* We don't actually use this */
+	if(memcmp(hdrbuf+8, "WAVE",4))
                 return 0; /* Not wave file */
 
         /* Ok. At this point, we know we have a WAV file. Now we have to detect
@@ -90,26 +97,56 @@
 
         if(!find_chunk(in, "fmt ", &len))
                 return 0; /* EOF */
+
+	/* dunamic allocation, since "fmt" chunk can be any length */
+	buf = malloc(len);
 
-	if(len!=16) 
+	if(len<16) 
         {
-		fprintf(stderr, "Warning: Unrecognised format chunk in WAV header\n");
+		free(buf);
+		error_handler("Truncated format chunk of length %d in WAV header", len);
+		fprintf(stderr, "Error: Truncated format chunk in WAV header\n");
                 return 0; /* Weird format chunk */
         }
 
-	if(fread(buf,1,16,in) < 16)
+	if(fread(buf,1,len,in) < 16)
         {
-		fprintf(stderr, "Warning: Unexpected EOF in reading WAV header\n");
+		free(buf);
+		error_handler("Unexpected EOF in reading WAV header");
+		fprintf(stderr, "Error: Unexpected EOF in reading WAV header\n");
                 return 0;
         }
 
         format.format =      READ_U16(buf); 
+
+/* temporary hack, until we decide where to put this defined constant */
+#ifndef WAVE_FORMAT_PCM
+# define WAVE_FORMAT_PCM 0x0001
+#endif
+
+	if (format.format != WAVE_FORMAT_PCM)
+	{
+		free(buf);
+		error_handler("WAVE format: %#02.02x not supported.", format.format);
+		fprintf(stderr, "Error: WAVE format: %#02.02x not supported.\n", format.format);
+		return 0;
+	} 
+	else if (len > 18)
+	{
+		free(buf);
+		error_handler("WAVE PCM with bad format size %d\n", len);
+		fprintf(stderr, "Error: WAVE PCM with bad format size: %d\n", len);
+		return 0;
+	}
+
         format.channels =    READ_U16(buf+2); 
         format.samplerate =  READ_U32(buf+4);
         format.bytespersec = READ_U32(buf+8);
         format.align =       READ_U16(buf+12);
         format.samplesize =  READ_U16(buf+14);
 
+	free(buf);
+
         if(!find_chunk(in, "data", &len))
                 return 0; /* EOF */
 
@@ -118,10 +155,6 @@
                 format.align == format.channels*2 && /* We could deal with this one pretty easily */
                 format.samplesize == 16)
         {
-		if(format.samplerate != 44100)
-			fprintf(stderr, "Warning: Vorbis is currently not tuned for input\n"
-							" at other than 44.1kHz. Quality may be somewhat\n"
-							" degraded.\n");
                 /* OK, good - we have the one supported format,
                    now we want to find the size of the file */
                 opt->rate = format.samplerate;
@@ -160,7 +193,14 @@
         }
         else
         {
-		fprintf(stderr, "ERROR: Wav file is unsupported subformat (must be 44.1kHz/16bit, this is %f/%dbit, %s)\n", (double)format.samplerate/1000, format.samplesize, (format.channels ==1)?"mono":"stereo");
+		error_handler("WAV file is unsupported subformat (must be 44.1kHz/16bit, this is %f/%dbit, %s)\n",
+			(double)format.samplerate / 1000,
+			format.samplesize,
+			(format.channels == 1) ? "mono" : "stereo");
+		fprintf(stderr, "ERROR: WAV file is unsupported subformat (must be 44.1kHz/16bit, this is %f/%dbit, %s)\n",
+			(double)format.samplerate / 1000,
+			format.samplesize,
+			(format.channels == 1) ? "mono" : "stereo");
                 return 0;
         }
 }
@@ -234,4 +274,105 @@
         opt->read_samples = raw_read_stereo; /* it's the same, currently */
         opt->total_samples_per_channel = 0; /* raw mode, don't bother */
         return 1;
+}
+
+/**
+ * Set teh current input file name.
+ */
+void set_filename(const char *filename)
+{
+	_filename = filename;
+}
+
+/**
+ * Display an error dialog, possibly adding system error information.
+ */
+void error_dialog(const char *fmt, ...)
+{
+	va_list ap;
+	char msgbuf[1024];
+	char *bufp = msgbuf;
+
+	/* A really rough sanity check to protect against blatant buffer overrun */
+	if (strlen(fmt) > 750)
+	{
+		sprintf(msgbuf, "%s %s", "<buffer overflow> ", fmt);
+	} 
+	else 
+	{
+		if (_filename != NULL && strlen(_filename) < 255)
+		{
+			sprintf(msgbuf, "%s: ", _filename);
+			bufp += strlen(msgbuf);
+		}
+
+		va_start(ap, fmt);
+		
+		vsprintf(bufp, fmt, ap);
+
+		va_end(ap);
+
+		if (errno != 0)
+		{
+			bufp = msgbuf + strlen(msgbuf);
+			sprintf(bufp, " error is %s (%d)", strerror(errno), errno);
+			errno = 0;
+		}
+	}
+
+	MessageBox(NULL, msgbuf, "Error", 0);
+}
+
+void log_error(const char *fmt, ...)
+{
+	va_list ap;
+	FILE *fp;
+	char msgbuf[1024];
+	char *bufp = msgbuf;
+
+	/* A really rough sanity check to protect against blatant buffer overrun */
+	if (strlen(fmt) > 750)
+	{
+		sprintf(msgbuf, "%s %s", "<buffer overflow> ", fmt);
+	}
+	else
+	{
+		if (_filename != NULL && strlen(_filename) < 255)
+		{
+			sprintf(msgbuf, "%s : ", _filename);
+			bufp += strlen(msgbuf);
+		}
+
+		va_start(ap, fmt);
+
+		vsprintf(bufp, fmt, ap);
+
+		va_end(ap);
+
+		if (errno != 0)
+		{
+			bufp = msgbuf + strlen(msgbuf);
+			sprintf(bufp, " error is: %s (%d)", strerror(errno), errno);
+			errno = 0;
+		}
+	}
+
+	va_start(ap, fmt);
+
+	if ((fp = fopen("oggdrop.log", "a")) == (FILE *)NULL)
+		return;
+
+	fprintf(fp, "%s\n", msgbuf);
+	fflush(fp);
+	fclose(fp);
+
+	va_end(ap);
+}
+
+void set_use_dialogs(int use_dialogs)
+{
+	if (!use_dialogs)
+		error_handler = log_error;
+	else
+		error_handler = error_dialog;
 }

1.2       +7 -0      win32-tools/oggdrop/audio.h

Index: audio.h
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/audio.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- audio.h	2000/11/07 09:01:39	1.1
+++ audio.h	2001/08/12 20:08:38	1.2
@@ -29,5 +29,12 @@
 long wav_read_mono(void *, float **buffer, int samples);
 long raw_read_stereo(void *, float **buffer, int samples);
 
+void set_filename(const char *filename);
+
+extern void error_dialog(const char *fmt, ...);
+extern void log_error(const char *fmt, ...);
+extern void set_use_dialogs(int use_dialogs);
+extern void (*error_handler)(const char *fmt, ...);
+
 #endif /* __AUDIO_H */
 

1.2       +1 -1      win32-tools/oggdrop/build_oggdrop.bat

Index: build_oggdrop.bat
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/build_oggdrop.bat,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- build_oggdrop.bat	2000/11/07 19:51:08	1.1
+++ build_oggdrop.bat	2001/08/12 20:08:38	1.2
@@ -10,7 +10,7 @@
 call "c:\program files\microsoft visual studio\vc98\bin\vcvars32.bat"
 echo Setting include/lib paths for Vorbis
 set INCLUDE=%INCLUDE%;%SRCROOT%\ogg\include;%SRCROOT%\vorbis\include
-set LIB=%LIB%;%SRCROOT%\ogg\win32\Static_Release;%SRCROOT%\vorbis\win32\Static_Release
+set LIB=%LIB%;%SRCROOT%\ogg\win32\Static_Release;%SRCROOT%\vorbis\win32\Vorbis_Static_Release;%SRCROOT%\vorbis\win32\Vorbisenc_Static_Release
 echo Compiling...
 msdev oggdrop.dsp /useenv /make "oggdrop - Win32 Release" /rebuild
 

1.3       +5 -7      win32-tools/oggdrop/encthread.c

Index: encthread.c
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/encthread.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- encthread.c	2000/11/07 17:54:35	1.2
+++ encthread.c	2001/08/12 20:08:38	1.3
@@ -134,7 +134,6 @@
 {
         char *in_file;
         long nextserial;
-	char buf[1024];
 
         /* Now, do some checking for illegal argument combinations */
 
@@ -160,12 +159,13 @@
                         enc_opts.progress_update = _update;
                         enc_opts.end_encode = _nothing_end;
                         enc_opts.error = _error;
-		
 
+			set_filename(in_file);
+
                         in = fopen(in_file, "rb");
 
                         if (in == NULL) {
-				MessageBox(NULL, "blah", "error opening inputfile", 0);
+				error_handler("Can't open %s", in_file);
                                 numfiles--;
                                 continue;
                         }
@@ -195,16 +195,14 @@
 
                         if (!foundformat) {
                                 free(out_fn);
-				_snprintf(buf, 1024, "Format not supported!  Skipping file %s...", in_file);
-				MessageBox(NULL, buf, "error", 0);
+				/* error reported by reader */
                                 numfiles--;
                                 continue;
                         }
 
                         out = fopen(out_fn, "wb");
                         if(out == NULL) {
-				_snprintf(buf, 1024, "Error opening/writing to output files %s...", out_fn);
-				MessageBox(NULL, buf, "error", 0);
+				error_handler("Error opening/writing to output file %s", out_fn);
                                 numfiles--;
                                 continue;
                         }	

1.3       +13 -1     win32-tools/oggdrop/main.c

Index: main.c
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/main.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- main.c	2000/11/18 03:30:20	1.2
+++ main.c	2001/08/12 20:08:38	1.3
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include "resource.h"
 #include "encthread.h"
+#include "audio.h"
 
 HANDLE event = NULL;
 int width = 120, height = 120;
@@ -240,7 +241,18 @@
                                 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOMOVE);
                         }
                         break;
-			
+	
+		case IDM_LOGERR:
+			state = GetMenuState(menu, LOWORD(wParam), MF_BYCOMMAND);
+			if ((state & MF_CHECKED) == MF_CHECKED) {
+				CheckMenuItem(menu, LOWORD(wParam), MF_UNCHECKED);
+				set_use_dialogs(1);
+			} else {
+				CheckMenuItem(menu, LOWORD(wParam), MF_CHECKED);
+				set_use_dialogs(0);
+			}
+			break;
+
                 case IDM_BITRATE128:
                         CheckMenuItem(menu, IDM_BITRATE128, MF_CHECKED);
                         CheckMenuItem(menu, IDM_BITRATE160, MF_UNCHECKED);

1.3       +2 -1      win32-tools/oggdrop/resource.h

Index: resource.h
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/resource.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- resource.h	2000/11/18 03:30:20	1.2
+++ resource.h	2001/08/12 20:08:38	1.3
@@ -23,6 +23,7 @@
 #define IDM_BITRATE350                  40009
 #define IDM_BITRATE192                  40010
 #define IDM_BITRATE160                  40011
+#define IDM_LOGERR                      40012
 
 // Next default values for new objects
 // 
@@ -30,7 +31,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NO_MFC                     1
 #define _APS_NEXT_RESOURCE_VALUE        132
-#define _APS_NEXT_COMMAND_VALUE         40012
+#define _APS_NEXT_COMMAND_VALUE         40013
 #define _APS_NEXT_CONTROL_VALUE         1000
 #define _APS_NEXT_SYMED_VALUE           101
 #endif

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list