[xiph-cvs] cvs commit: vorbis-tools/oggenc encode.c encode.h oggenc.c

Michael Smith msmith at xiph.org
Sat Nov 4 20:52:22 PST 2000



msmith      00/11/04 20:52:22

  Modified:    oggenc   encode.c encode.h oggenc.c
  Log:
  Handle errors in writing the file (for example, running out of disk space).
  This needs to be extended somewhat to check for libvorbis error returns,
  too. Not crucial at this point.

Revision  Changes    Path
1.7       +30 -6     vorbis-tools/oggenc/encode.c

Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- encode.c	2000/11/04 10:04:58	1.6
+++ encode.c	2000/11/05 04:52:21	1.7
@@ -38,6 +38,7 @@
     int eos;
         long bytes_written = 0, packetsdone=0;
         double time_elapsed;
+	int ret=0;
 
         TIMER *timer;
 
@@ -81,7 +82,15 @@
                 while((result = ogg_stream_flush(&os, &og)))
                 {
                         if(!result) break;
-			bytes_written += oe_write_page(&og, opt->out);
+			ret = oe_write_page(&og, opt->out);
+			if(!ret)
+			{
+				opt->error("Failed writing header to output stream\n");
+				ret = 1;
+				goto cleanup; /* Bail and try to clean up stuff */
+			}
+			else
+				bytes_written += ret;
                 }
         }
 
@@ -138,7 +147,15 @@
                                 int result = ogg_stream_pageout(&os,&og);
                                 if(!result) break;
 
-				bytes_written += oe_write_page(&og, opt->out);
+				ret = oe_write_page(&og, opt->out);
+				if(!ret)
+				{
+					opt->error("Failed writing data to output stream\n");
+					ret = 1;
+					goto cleanup; /* Bail */
+				}
+				else
+					bytes_written += ret; 
 
                                 if(ogg_page_eos(&og))
                                         eos = 1;
@@ -147,6 +164,7 @@
         }
 
         /* Cleanup time */
+cleanup:
 
         ogg_stream_clear(&os);
 
@@ -159,7 +177,7 @@
 
         timer_clear(timer);
 
-	return 0;
+	return ret;
 }
 
 void update_statistics_full(char *fn, long total, long done, double time)
@@ -190,10 +208,11 @@
 
 int oe_write_page(ogg_page *page, FILE *fp)
 {
-	fwrite(page->header,1,page->header_len, fp);
-	fwrite(page->body,1,page->body_len, fp);
+	int written;
+	written = fwrite(page->header,1,page->header_len, fp);
+	written += fwrite(page->body,1,page->body_len, fp);
 
-	return page->header_len+page->body_len;
+	return written;
 }
 
 void final_statistics(char *fn, double time, int rate, long samples, long bytes)
@@ -227,6 +246,11 @@
 void update_statistics_null(char *fn, long total, long done, double time)
 {
         /* So is this */
+}
+
+void encode_error(char *errmsg)
+{
+	fprintf(stderr, "\n%s\n", errmsg);
 }
 
 

1.4       +3 -0      vorbis-tools/oggenc/encode.h

Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- encode.h	2000/11/04 10:04:58	1.3
+++ encode.h	2000/11/05 04:52:21	1.4
@@ -11,6 +11,7 @@
                 long samples, double time);
 typedef void (*enc_end_func)(char *fn, double time, int rate, 
                 long samples, long bytes);
+typedef void (*error_func)(char *errormessage);
 
 
 void *timer_start(void);
@@ -24,6 +25,7 @@
                 long bytes);
 void final_statistics_null(char *fn, double time, int rate, long total_samples,
                 long bytes);
+void encode_error(char *errmsg);
 
 typedef struct
 {
@@ -56,6 +58,7 @@
         audio_read_func read_samples;
         progress_func progress_update;
         enc_end_func end_encode;
+	error_func error;
         
         void *readdata;
 

1.4       +2 -1      vorbis-tools/oggenc/oggenc.c

Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- oggenc.c	2000/11/04 10:04:58	1.3
+++ oggenc.c	2000/11/05 04:52:21	1.4
@@ -116,6 +116,7 @@
                 enc_opts.serialno = nextserial++;
                 enc_opts.progress_update = update_statistics_full;
                 enc_opts.end_encode = final_statistics;
+		enc_opts.error = encode_error;
                 
                 /* OK, let's build the vorbis_comments structure */
                 build_comments(&vc, &opt, i, &artist, &album, &title, &track, &date);
@@ -235,7 +236,7 @@
                         enc_opts.end_encode = final_statistics_null;
                 }
 
-		oe_encode(&enc_opts);
+		oe_encode(&enc_opts); /* Should we care about return val? */
 
                 if(out_fn) free(out_fn);
                 vorbis_comment_clear(&vc);

--- >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