[NUT-devel] [nut]: r179 - in trunk/nututils: demux_avi.c demux_ogg.c framer_mpeg4.c framer_vorbis.c nutmerge.c nutmerge.h

ods15 subversion at mplayerhq.hu
Sat Nov 4 13:50:48 CET 2006


Author: ods15
Date: Sat Nov  4 13:50:47 2006
New Revision: 179

Modified:
   trunk/nututils/demux_avi.c
   trunk/nututils/demux_ogg.c
   trunk/nututils/framer_mpeg4.c
   trunk/nututils/framer_vorbis.c
   trunk/nututils/nutmerge.c
   trunk/nututils/nutmerge.h

Log:
add somewhat better error messaging in nutmerge using enum


Modified: trunk/nututils/demux_avi.c
==============================================================================
--- trunk/nututils/demux_avi.c	(original)
+++ trunk/nututils/demux_avi.c	Sat Nov  4 13:50:47 2006
@@ -19,7 +19,7 @@
 #define FIXENDIAN16(a) do{}while(0)
 #endif
 
-#define FREAD(file, len, var) do { if (fread((var), 1, (len), (file)) != (len)) return 1; }while(0)
+#define FREAD(file, len, var) do { if (fread((var), 1, (len), (file)) != (len)) return err_unexpected_eof; }while(0)
 
 typedef struct riff_tree_s {
 	uint32_t len;
@@ -208,12 +208,12 @@
 
 	for (i = 0; i < tree->amount; i++) {
 		if (tree->tree[i].type == 1 && !strncmp(tree->tree[i].name, "strh", 4)) {
-			if (tree->tree[i].len != 56) return 2;
+			if (tree->tree[i].len != 56) return err_avi_bad_strh_len;
 			stream->strh = (AVIStreamHeader*)tree->tree[i].data;
 			break;
 		}
 	}
-	if (i == tree->amount) return 3;
+	if (i == tree->amount) return err_avi_no_strh;
 
 	for(i = 2; i < 12; i++) FIXENDIAN32(((uint32_t*)stream->strh)[i]);
 
@@ -222,7 +222,7 @@
 			int len = tree->tree[i].len;
 			switch(strFOURCC(stream->strh->fccType)) {
 				case mmioFOURCC('v','i','d','s'):
-					if (len < 40) return 4;
+					if (len < 40) return err_avi_bad_vids_len;
 					stream->type = 0;
 					stream->video = (BITMAPINFOHEADER*)tree->tree[i].data;
 					for(j = 0; j < 3; j++)  FIXENDIAN32(((uint32_t*)stream->video)[j]);
@@ -232,7 +232,7 @@
 					if (len > 40) stream->extra = (uint8_t*)tree->tree[i].data + 40;
 					break;
 				case mmioFOURCC('a','u','d','s'):
-					if (len < 18) return 5;
+					if (len < 18) return err_avi_bad_auds_len;
 					stream->type = 1;
 					stream->audio = (WAVEFORMATEX *)tree->tree[i].data;
 					for(j = 1; j < 2; j++) FIXENDIAN16(((uint16_t*)stream->audio)[j]);
@@ -242,12 +242,12 @@
 					if (len > 18) stream->extra = (uint8_t*)tree->tree[i].data + 18;
 					break;
 				default:
-					return 6;
+					return err_avi_bad_strf_type;
 			}
 			break;
 		}
 	}
-	if (i == tree->amount) return 7;
+	if (i == tree->amount) return err_avi_no_strf;
 
 	return 0;
 }
@@ -259,16 +259,16 @@
 
 	for (i = 0; i < tree->amount; i++) {
 		if (tree->tree[i].type == 1 && !strncmp(tree->tree[i].name, "avih", 4)) {
-			if (tree->tree[i].len != 56) return 8;
+			if (tree->tree[i].len != 56) return err_avi_bad_avih_len;
 			avi->avih = (MainAVIHeader*)tree->tree[i].data;
 			break;
 		}
 	}
-	if (i == tree->amount) return 9;
+	if (i == tree->amount) return err_avi_no_avih;
 
 	for(i = 0; i < 14; i++) FIXENDIAN32(((uint32_t*)avi->avih)[i]);
 
-	if (avi->avih->dwStreams > 200) return 10;
+	if (avi->avih->dwStreams > 200) return err_avi_stream_overflow;
 	avi->stream = malloc(avi->avih->dwStreams * sizeof(AVIStreamContext));
 	for (i = 0; i < avi->avih->dwStreams; i++) {
 		avi->stream[i].video = NULL;
@@ -282,7 +282,7 @@
 			if ((err = avi_read_stream_header(&avi->stream[tmp++], &tree->tree[i]))) return err;
 		}
 	}
-	if (tmp != avi->avih->dwStreams) return 11;
+	if (tmp != avi->avih->dwStreams) return err_avi_no_strl;
 	return 0;
 }
 
@@ -291,16 +291,16 @@
 	int i, err;
 	if ((err = get_full_riff_tree(avi->in, avi->riff))) return err;
 	tree = &avi->riff->tree[0];
-	if (tree->type != 0) return 12;
-	if (strncmp(tree->name, "RIFF", 4)) return 13;
-	if (strncmp(tree->listname, "AVI ", 4)) return 14;
+	if (tree->type != 0) return err_avi_bad_riff;
+	if (strncmp(tree->name, "RIFF", 4)) return err_avi_bad_riff;
+	if (strncmp(tree->listname, "AVI ", 4)) return err_avi_bad_avi;
 	for (i = 0; i < tree->amount; i++) {
 		if (tree->tree[i].type == 0 && !strncmp(tree->tree[i].listname, "hdrl", 4)) {
 			if ((err = avi_read_main_header(avi, &tree->tree[i]))) return err;
 			break;
 		}
 	}
-	if (i == tree->amount) return 15;
+	if (i == tree->amount) return err_avi_no_hdrl;
 	for (i = 0; i < avi->riff->amount; i++) {
 		int j;
 		tree = &avi->riff->tree[i];
@@ -318,14 +318,14 @@
 		}
 		if (j != tree->amount) break;
 	}
-	if (i == avi->riff->amount) return 16;
+	if (i == avi->riff->amount) return err_avi_no_idx;
 	for (i = 0; i < tree->amount; i++) {
 		if (tree->tree[i].type == 0 && !strncmp(tree->tree[i].listname, "movi", 4)) {
 			fseek(avi->in, tree->tree[i].offset + 12, SEEK_SET);
 			break;
 		}
 	}
-	if (i == tree->amount) return 17;
+	if (i == tree->amount) return err_avi_no_movi;
 	return 0;
 }
 
@@ -344,10 +344,10 @@
 			for (j = sizeof(fourccs)/sizeof(fourccs[0]); j--; ) {
 				if (!strncmp(avi->stream[i].video->biCompression, fourccs[j], 4)) break;
 			}
-			if (j == -1) return 18;
+			if (j == -1) return err_avi_no_video_codec;
 		} else {
 			if (avi->stream[i].audio->wFormatTag[0] != 0x55 ||
-			    avi->stream[i].audio->wFormatTag[1] != 0x00) return 19;
+			    avi->stream[i].audio->wFormatTag[1] != 0x00) return err_avi_no_audio_codec;
 		}
 	}
 
@@ -422,7 +422,7 @@
 	p.p.next_pts = p.p.pts = 0;
 	if ((unsigned)(fourcc[0] - '0') > 9 || (unsigned)(fourcc[1] - '0') > 9 || p.p.stream >= avi->avih->dwStreams) {
 		fprintf(stderr, "%d %4.4s\n", avi->cur, fourcc);
-		return 3;
+		return err_avi_bad_packet;
 	}
 	if (p.p.stream == 1) {
 		// 0.5 secs of audio or a single packet

Modified: trunk/nututils/demux_ogg.c
==============================================================================
--- trunk/nututils/demux_ogg.c	(original)
+++ trunk/nututils/demux_ogg.c	Sat Nov  4 13:50:47 2006
@@ -57,7 +57,7 @@
 	int len, tot = 0;
 
 	FREAD(ogg->in, 27, tmp_header);
-	if (strncmp(tmp_header, "OggS", 5)) return 2; // including version
+	if (strncmp(tmp_header, "OggS", 5)) return err_bad_oggs_magic; // including version
 
 	serial = (tmp_header[14] << 24) |
 		 (tmp_header[15] << 16) |
@@ -111,7 +111,7 @@
 			if (codecs[j].magic_len > ogg->s[i].packets[0].p.len) continue;
 			if (!memcmp(codecs[j].magic, ogg->s[i].packets[0].buf, codecs[j].magic_len)) break;
 		}
-		if (!codecs[j].magic) return 6;
+		if (!codecs[j].magic) return err_ogg_no_codec;
 		ogg->s[i].codec_id = codecs[j].id;
 	}
 
@@ -124,7 +124,7 @@
 	int err, dummy;
 
 	if ((err = read_page(ogg, &dummy))) return err;
-	if (ogg->stream_count != ogg->nstreams) return 2;
+	if (ogg->stream_count != ogg->nstreams) return err_ogg_non_interleaved;
 
 	return 0;
 }

Modified: trunk/nututils/framer_mpeg4.c
==============================================================================
--- trunk/nututils/framer_mpeg4.c	(original)
+++ trunk/nututils/framer_mpeg4.c	Sat Nov  4 13:50:47 2006
@@ -15,7 +15,7 @@
 		*type = *buf >> 6;
 		return 0;
 	}
-	return 13;
+	return err_mpeg4_no_frame_type;
 }
 
 #define CHECK(x) do{ if ((err = (x))) return err; }while(0)

Modified: trunk/nututils/framer_vorbis.c
==============================================================================
--- trunk/nututils/framer_vorbis.c	(original)
+++ trunk/nututils/framer_vorbis.c	Sat Nov  4 13:50:47 2006
@@ -37,7 +37,7 @@
 	uint64_t val = 0;
 	int pos = 0;
 	bp->left -= bits;
-	if (bp->left < 0) return 1;
+	if (bp->left < 0) return err_vorbis_header;
 
 	if (!bits) return 0;
 	if (bp->pos) {
@@ -88,7 +88,7 @@
 	}
 	for (i = 0; i < 3; i++) { memcpy(p, pd[i].buf, pd[i].p.len); p += pd[i].p.len; }
 
-	if (pd[0].p.len < 30) { err = 1; goto err_out; }
+	if (pd[0].p.len < 30) { err = err_vorbis_header; goto err_out; }
 	p = pd[0].buf;
 	channels = p[11];
 	sample_rate = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12];
@@ -116,7 +116,7 @@
 	bp.left = pd[2].p.len*8;
 	bp.pos = 0;
 
-	CHECK(get_bits(&bp, 8, &num)); if (num != 5) { err = 2; goto err_out; }
+	CHECK(get_bits(&bp, 8, &num)); if (num != 5) { err = err_vorbis_header; goto err_out; }
 	CHECK(get_bits(&bp, 8*6, NULL)); // "vorbis"
 
 	// codebook
@@ -158,7 +158,7 @@
 				break;
 			case 2: j = dimentions * entries; break;
 			default:
-				err = 3;
+				err = err_vorbis_header;
 				goto err_out;
 		}
 		if (j >= 0) {
@@ -212,7 +212,7 @@
 				CHECK(get_bits(&bp, classes[class_list[j]]*rangebits, NULL));
 			}
 			}}
-		} else { err = 5; goto err_out; } // unknown floor
+		} else { err = err_vorbis_header; goto err_out; } // unknown floor
 	}
 
 	// residues
@@ -220,7 +220,7 @@
 	for (; i > 0; i--) {
 		int j, classifications;
 		CHECK(get_bits(&bp, 16, &num));
-		if ((int)num > 2) { err = 6; goto err_out; } // unkown residue
+		if ((int)num > 2) { err = err_vorbis_header; goto err_out; } // unkown residue
 		CHECK(get_bits(&bp, 24, NULL)); // residue_begin
 		CHECK(get_bits(&bp, 24, NULL)); // residue_end
 		CHECK(get_bits(&bp, 24, NULL)); // residue_partition_size
@@ -249,7 +249,7 @@
 	for (; i > 0; i--) {
 		int submaps = 1;
 		CHECK(get_bits(&bp, 16, &num)); // type
-		if (num) { err = 7; goto err_out; } // bad mapping type
+		if (num) { err = err_vorbis_header; goto err_out; } // bad mapping type
 		CHECK(get_bits(&bp, 1, &num)); // is submaps
 		if (num) {
 			CHECK(get_bits(&bp, 4, &num));
@@ -261,7 +261,7 @@
 			CHECK(get_bits(&bp, ilog(channels - 1) * 2 * (num + 1), NULL));
 		}
 		CHECK(get_bits(&bp, 2, &num)); // reserved
-		if (num) { err = 8; goto err_out; }
+		if (num) { err = err_vorbis_header; goto err_out; }
 		if (submaps > 1) CHECK(get_bits(&bp, 4 * channels, NULL));
 		CHECK(get_bits(&bp, submaps*(8+8+8), NULL));
 	}
@@ -275,7 +275,7 @@
 		CHECK(get_bits(&bp, 16 + 16 + 8, NULL));
 	}
 	CHECK(get_bits(&bp, 1, &num)); // framing
-	if (!num) { err = 9; goto err_out; }
+	if (!num) { err = err_vorbis_header; goto err_out; }
 
 err_out:
 	for (i = 0; i < pd_read; i++) free(pd[i].buf);
@@ -297,7 +297,7 @@
 	bp.pos = 0;
 	CHECK(get_bits(&bp, 1, NULL));
 	CHECK(get_bits(&bp, ilog(vc->mode_count - 1), &num));
-	if ((int)num >= vc->mode_count) return 10; // ERROR
+	if ((int)num >= vc->mode_count) return err_vorbis_packet; // ERROR
 
 	mode = vc->modes[num];
 	prevbs = nextbs = mybs = vc->blocksize[mode];
@@ -316,7 +316,7 @@
 	p->p.next_pts = vc->pts;
 	p->p.flags = NUT_FLAG_KEY;
 err_out:
-	return err;
+	return err == err_vorbis_header ? err_vorbis_packet : err;
 }
 
 static framer_priv_t * init(stream_t * s) {

Modified: trunk/nututils/nutmerge.c
==============================================================================
--- trunk/nututils/nutmerge.c	(original)
+++ trunk/nututils/nutmerge.c	Sat Nov  4 13:50:47 2006
@@ -195,5 +195,34 @@
 	if (in) fclose(in);
 	if (out) fclose(out);
 	if (stats) fclose(stats);
+	if (err) switch ((enum nutmerge_errors)err) {
+#define ERR_CASE(a) case a: fprintf(stderr, "%s\n", #a); break;
+		ERR_CASE(err_unexpected_eof)
+		ERR_CASE(err_avi_bad_riff)
+		ERR_CASE(err_avi_bad_avi)
+		ERR_CASE(err_avi_no_avih)
+		ERR_CASE(err_avi_no_strl)
+		ERR_CASE(err_avi_no_strh)
+		ERR_CASE(err_avi_no_strf)
+		ERR_CASE(err_avi_no_hdrl)
+		ERR_CASE(err_avi_no_idx)
+		ERR_CASE(err_avi_no_movi)
+		ERR_CASE(err_avi_bad_avih_len)
+		ERR_CASE(err_avi_bad_strh_len)
+		ERR_CASE(err_avi_bad_vids_len)
+		ERR_CASE(err_avi_bad_auds_len)
+		ERR_CASE(err_avi_bad_strf_type)
+		ERR_CASE(err_avi_stream_overflow)
+		ERR_CASE(err_avi_no_video_codec)
+		ERR_CASE(err_avi_no_audio_codec)
+		ERR_CASE(err_avi_bad_packet)
+		ERR_CASE(err_mpeg4_no_frame_type)
+		ERR_CASE(err_bad_oggs_magic)
+		ERR_CASE(err_ogg_no_codec)
+		ERR_CASE(err_ogg_non_interleaved)
+		ERR_CASE(err_vorbis_header)
+		ERR_CASE(err_vorbis_packet)
+#undef ERR_CASE
+	}
 	return err;
 }

Modified: trunk/nututils/nutmerge.h
==============================================================================
--- trunk/nututils/nutmerge.h	(original)
+++ trunk/nututils/nutmerge.h	Sat Nov  4 13:50:47 2006
@@ -67,3 +67,31 @@
 int get_stream_packet(stream_t * stream, packet_t * p);
 
 void free_streams(stream_t * streams); // all the way to -1 terminated list, not the actual 'streams' though
+
+enum nutmerge_errors {
+	err_unexpected_eof = 1,
+	err_avi_bad_riff,
+	err_avi_bad_avi,
+	err_avi_no_avih,
+	err_avi_no_strl,
+	err_avi_no_strh,
+	err_avi_no_strf,
+	err_avi_no_hdrl,
+	err_avi_no_idx,
+	err_avi_no_movi,
+	err_avi_bad_avih_len,
+	err_avi_bad_strh_len,
+	err_avi_bad_vids_len,
+	err_avi_bad_auds_len,
+	err_avi_bad_strf_type,
+	err_avi_stream_overflow,
+	err_avi_no_video_codec,
+	err_avi_no_audio_codec,
+	err_avi_bad_packet,
+	err_mpeg4_no_frame_type,
+	err_bad_oggs_magic,
+	err_ogg_no_codec,
+	err_ogg_non_interleaved,
+	err_vorbis_header,
+	err_vorbis_packet,
+};



More information about the NUT-devel mailing list