[NUT-devel] [NUT] (ods15): r93 - in /trunk: libnut/demuxer.c libnut/muxer.c libnut/nut.h libnut/priv.h nututils/demux_avi.c nututils/demux_ogg.c nututils/nutmerge.c

syncmail at mplayerhq.hu syncmail at mplayerhq.hu
Sat Mar 11 16:35:57 CET 2006


Author: ods15
Date: Sat Mar 11 16:35:56 2006
New Revision: 93

Log:
sync to spec, remove sflags, checksums after frame headers

Modified:
    trunk/libnut/demuxer.c
    trunk/libnut/muxer.c
    trunk/libnut/nut.h
    trunk/libnut/priv.h
    trunk/nututils/demux_avi.c
    trunk/nututils/demux_ogg.c
    trunk/nututils/nutmerge.c

Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c (original)
+++ trunk/libnut/demuxer.c Sat Mar 11 16:35:56 2006
@@ -200,7 +200,7 @@
 
 	GET_V(in, forward_ptr);
 	if (forward_ptr > 4096) {
-		skip_buffer(in, 4); // header_checksum
+		CHECK(skip_buffer(in, 4)); // header_checksum
 		ERROR(crc32(get_buf(in, start), bctello(in) - start), -ERR_BAD_CHECKSUM);
 	}
 
@@ -220,7 +220,7 @@
 static int get_main_header(nut_context_t * nut) {
 	input_buffer_t itmp, * tmp = new_mem_buffer(&itmp);
 	int i, j, err = 0;
-	int flag, fields, timestamp = 0, mul = 1, stream = 0, sflag, size, count, reserved;
+	int flag, fields, timestamp = 0, mul = 1, stream = 0, size, count, reserved;
 
 	CHECK(get_header(nut->i, tmp));
 
@@ -234,21 +234,17 @@
 		int scrap;
 		GET_V(tmp, flag);
 		GET_V(tmp, fields);
-		if (fields > 0) GET_V(tmp, sflag);
-		else sflag = 0;
-		if (fields > 1) GET_S(tmp, timestamp);
-		if (fields > 2) GET_V(tmp, mul);
-		if (fields > 3) GET_V(tmp, stream);
-		if (fields > 4) GET_V(tmp, size);
+		if (fields > 0) GET_S(tmp, timestamp);
+		if (fields > 1) GET_V(tmp, mul);
+		if (fields > 2) GET_V(tmp, stream);
+		if (fields > 3) GET_V(tmp, size);
 		else size = 0;
-		if (fields > 5) GET_V(tmp, reserved);
+		if (fields > 4) GET_V(tmp, reserved);
 		else reserved = 0;
-		if (fields > 6) GET_V(tmp, count);
+		if (fields > 5) GET_V(tmp, count);
 		else count = mul - size;
 
-		for (j = 7; j < fields; j++) {
-			GET_V(tmp, scrap);
-		}
+		for (j = 6; j < fields; j++) GET_V(tmp, scrap);
 
 		for(j = 0; j < count && i < 256; j++, i++) {
 			if (i == 'N') {
@@ -257,7 +253,6 @@
 				continue;
 			}
 			nut->ft[i].flags = flag;
-			nut->ft[i].stream_flags = sflag;
 			nut->ft[i].stream_plus1 = stream;
 			nut->ft[i].mul = mul;
 			nut->ft[i].lsb = size + j;
@@ -483,17 +478,16 @@
 }
 
 static int get_packet(nut_context_t * nut, nut_packet_t * pd, int * saw_syncpoint) {
-	int err = 0;
-	off_t after_sync = 0;
 	uint64_t tmp;
-	int coded_pts, size_lsb = 0, stream_flags = 0, i;
+	int err = 0, after_sync = 0, checksum = 0, flags, i;
+	off_t start;
 
 	CHECK(get_bytes(nut->i, 1, &tmp)); // frame_code or 'N'
 	if (tmp == 'N') {
 		CHECK(get_bytes(nut->i, 7, &tmp));
 		tmp |= (uint64_t)'N' << 56;
 		if (tmp == SYNCPOINT_STARTCODE) {
-			after_sync = bctello(nut->i);
+			after_sync = 1;
 			CHECK(get_syncpoint(nut));
 			CHECK(get_bytes(nut->i, 1, &tmp));
 		} else {
@@ -502,15 +496,19 @@
 		}
 	}
 
-	ERROR(nut->ft[tmp].flags & INVALID_FLAG, -ERR_NOT_FRAME_NOT_N);
-
+	start = bctello(nut->i) - 1;
 	pd->type = e_frame;
+
+	flags = nut->ft[tmp].flags;
+	ERROR(flags & FLAG_INVALID, -ERR_NOT_FRAME_NOT_N);
+
 	if (!nut->ft[tmp].stream_plus1) GET_V(nut->i, pd->stream);
 	else pd->stream = nut->ft[tmp].stream_plus1 - 1;
 
 	ERROR(pd->stream >= nut->stream_count, -ERR_NOT_FRAME_NOT_N);
 
 	if (!nut->ft[tmp].pts_delta) {
+		uint64_t coded_pts;
 		GET_V(nut->i, coded_pts);
 		if (coded_pts >= (1 << nut->sc[pd->stream].msb_pts_shift))
 			pd->pts = coded_pts - (1 << nut->sc[pd->stream].msb_pts_shift);
@@ -524,25 +522,32 @@
 		pd->pts = nut->sc[pd->stream].last_pts + nut->ft[tmp].pts_delta;
 	}
 
-	if (nut->ft[tmp].flags & MSB_CODED_FLAG) GET_V(nut->i, size_lsb);
-	pd->len = size_lsb * nut->ft[tmp].mul + nut->ft[tmp].lsb;
-
-	if (nut->ft[tmp].flags & STREAM_CODED_FLAG) GET_V(nut->i, stream_flags);
-	pd->flags = nut->ft[tmp].stream_flags ^ stream_flags;
+	if (flags & FLAG_CODED) {
+		int coded_flags;
+		GET_V(nut->i, coded_flags);
+		flags ^= coded_flags;
+	}
+	pd->flags = flags & NUT_API_FLAGS;
+
+	if (flags & FLAG_SIZE_MSB) {
+		int size_msb;
+		GET_V(nut->i, size_msb);
+		pd->len = size_msb * nut->ft[tmp].mul + nut->ft[tmp].lsb;
+	} else pd->len = nut->ft[tmp].lsb;
 
 	for (i = 0; i < nut->ft[tmp].reserved; i++) { int scrap; GET_V(nut->i, scrap); }
 
-	if (0) {
-		uint64_t checksum;
-		off_t pos = bctello(nut->i);
-		CHECK(get_bytes(nut->i, 4, &checksum));
-		ERROR(checksum != crc32(nut->i->buf_ptr - (bctello(nut->i) - after_sync), pos - after_sync), -ERR_BAD_CHECKSUM);
+	if (flags & FLAG_CHECKSUM) {
+		CHECK(skip_buffer(nut->i, 4)); // header_checksum
+		ERROR(crc32(nut->i->buf_ptr - (bctello(nut->i) - start), bctello(nut->i) - start), -ERR_BAD_CHECKSUM);
+		checksum = 1;
 	}
 
 	// error checking - max distance
 	ERROR(!after_sync && bctello(nut->i) + pd->len - nut->last_syncpoint > nut->max_distance, -ERR_MAX_DISTANCE);
+	ERROR(!checksum && pd->len > nut->max_distance, -ERR_MAX_DISTANCE);
 	// error checking - max pts distance
-	ERROR(!after_sync && ABS((int64_t)pd->pts - (int64_t)nut->sc[pd->stream].last_pts) > nut->sc[pd->stream].max_pts_distance, -ERR_MAX_PTS_DISTANCE);
+	ERROR(!checksum && ABS((int64_t)pd->pts - (int64_t)nut->sc[pd->stream].last_pts) > nut->sc[pd->stream].max_pts_distance, -ERR_MAX_PTS_DISTANCE);
 	// error checking - out of order dts
 	for (i = 0; i < nut->stream_count; i++) {
 		if (nut->sc[i].last_dts == -1) continue;
@@ -562,8 +567,8 @@
 	stream_context_t * sc = &nut->sc[pd->stream];
 	sc->last_pts = pd->pts;
 	sc->last_dts = get_dts(sc->sh.decode_delay, sc->pts_cache, pd->pts);
-	if (pd->flags & NUT_KEY_STREAM_FLAG && !sc->last_key) sc->last_key = pd->pts + 1;
-	if (pd->flags & NUT_EOR_STREAM_FLAG) sc->eor = pd->pts + 1;
+	if (pd->flags & NUT_FLAG_KEY && !sc->last_key) sc->last_key = pd->pts + 1;
+	if (pd->flags & NUT_FLAG_EOR) sc->eor = pd->pts + 1;
 	else sc->eor = 0;
 }
 
@@ -1010,10 +1015,10 @@
 				}
 				if (n) break; // pts for all active streams higher than requested pts
 			}
-			if (pd.flags & NUT_KEY_STREAM_FLAG) {
+			if (pd.flags & NUT_FLAG_KEY) {
 				if (pd.pts <= pts[pd.stream]>>1) {
 					good_key[pd.stream] = buf_before<<1;
-					if (pd.flags & NUT_EOR_STREAM_FLAG) good_key[pd.stream] = 0;
+					if (pd.flags & NUT_FLAG_EOR) good_key[pd.stream] = 0;
 				}
 				if (!end && pd.pts >= pts[pd.stream]>>1) { // forward seek end
 					if (saw_syncpoint) nut->last_syncpoint = 0;
@@ -1021,7 +1026,7 @@
 					break;
 				}
 			}
-		} else if (stopper && pd.flags&NUT_KEY_STREAM_FLAG && !(good_key[i]&1)) {
+		} else if (stopper && pd.flags&NUT_FLAG_KEY && !(good_key[i]&1)) {
 			TO_PTS(stopper, stopper->pts)
 			if (compare_ts(nut, stopper_p, stopper_s, pd.pts, pd.stream) > 0) {
 				good_key[pd.stream] = buf_before<<1;

Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 16:35:56 2006
@@ -135,7 +135,7 @@
 static void put_main_header(nut_context_t * nut) {
 	output_buffer_t * tmp = clear_buffer(nut->tmp_buffer);
 	int i;
-	int flag, fields, sflag, timestamp = 0, mul = 1, stream = 0, size, count;
+	int flag, fields, timestamp = 0, mul = 1, stream = 0, size, count;
 
 	put_v(tmp, NUT_VERSION);
 	put_v(tmp, nut->stream_count);
@@ -143,37 +143,33 @@
 	for(i = 0; i < 256; ) {
 		fields = 0;
 		flag = nut->ft[i].flags;
-		if (nut->ft[i].stream_flags != 0) fields = 1;
-		sflag = nut->ft[i].stream_flags;
-		if (nut->ft[i].pts_delta != timestamp) fields = 2;
+		if (nut->ft[i].pts_delta != timestamp) fields = 1;
 		timestamp = nut->ft[i].pts_delta;
-		if (nut->ft[i].mul != mul) fields = 3;
+		if (nut->ft[i].mul != mul) fields = 2;
 		mul = nut->ft[i].mul;
-		if (nut->ft[i].stream_plus1 != stream) fields = 4;
+		if (nut->ft[i].stream_plus1 != stream) fields = 3;
 		stream = nut->ft[i].stream_plus1;
-		if (nut->ft[i].lsb != 0) fields = 5;
+		if (nut->ft[i].lsb != 0) fields = 4;
 		size = nut->ft[i].lsb;
 
 		for (count = 0; i < 256; count++, i++) {
 			if (i == 'N') { count--; continue; }
 			if (nut->ft[i].flags != flag) break;
-			if (nut->ft[i].stream_flags != sflag) break;
 			if (nut->ft[i].stream_plus1 != stream) break;
 			if (nut->ft[i].mul != mul) break;
 			if (nut->ft[i].lsb != size + count) break;
 			if (nut->ft[i].pts_delta != timestamp) break;
 		}
-		if (count != mul - size) fields = 7;
+		if (count != mul - size) fields = 6;
 
 		put_v(tmp, flag);
 		put_v(tmp, fields);
-		if (fields > 0) put_v(tmp, sflag);
-		if (fields > 1) put_s(tmp, timestamp);
-		if (fields > 2) put_v(tmp, mul);
-		if (fields > 3) put_v(tmp, stream);
-		if (fields > 4) put_v(tmp, size);
-		if (fields > 5) put_v(tmp, 0); // reserved
-		if (fields > 6) put_v(tmp, count);
+		if (fields > 0) put_s(tmp, timestamp);
+		if (fields > 1) put_v(tmp, mul);
+		if (fields > 2) put_v(tmp, stream);
+		if (fields > 3) put_v(tmp, size);
+		if (fields > 4) put_v(tmp, 0); // reserved
+		if (fields > 5) put_v(tmp, count);
 	}
 
 	put_header(nut->o, tmp, nut->tmp_buffer2, MAIN_STARTCODE, 0);
@@ -386,65 +382,82 @@
 	put_header(nut->o, tmp, nut->tmp_buffer2, INDEX_STARTCODE, 1);
 }
 
-static int frame_header(nut_context_t * nut, const nut_packet_t * fd, int * rftnum) {
-	int i, ftnum = -1, size = 0, coded_pts, pts_delta;
+static int frame_header(nut_context_t * nut, output_buffer_t * tmp, const nut_packet_t * fd) {
 	stream_context_t * sc = &nut->sc[fd->stream];
-	pts_delta = fd->pts - sc->last_pts;
-	// ### check lsb pts
-	if (MAX(pts_delta, -pts_delta) < (1 << (sc->msb_pts_shift - 1)) - 1)
-		coded_pts = fd->pts & ((1 << sc->msb_pts_shift) - 1);
-	else
-		coded_pts = fd->pts + (1 << sc->msb_pts_shift);
+	int i, ftnum = -1, size = 0, coded_pts, coded_flags = 0, msb_pts = (1 << sc->msb_pts_shift);
+	int checksum = 0, pts_delta = (int64_t)fd->pts - (int64_t)sc->last_pts;
+
+	if (ABS(pts_delta) < (msb_pts/2) - 1) coded_pts = fd->pts & (msb_pts - 1);
+	else coded_pts = fd->pts + msb_pts;
+
+	if (fd->len > nut->max_distance) checksum = 1;
+	if (ABS(pts_delta) > sc->max_pts_distance) {
+		fprintf(stderr, "%d > %d || %d - %d > %d   \n", fd->len, nut->max_distance, (int)fd->pts, (int)sc->last_pts, sc->max_pts_distance);
+		checksum = 1;
+	}
+
 	for (i = 0; i < 256; i++) {
-		int len = 1;
-		if (nut->ft[i].flags & INVALID_FLAG) continue;
+		int len = 1; // frame code
+		int flags = nut->ft[i].flags;
+		if (flags & FLAG_INVALID) continue;
 		if (nut->ft[i].stream_plus1 && nut->ft[i].stream_plus1 - 1 != fd->stream) continue;
 		if (nut->ft[i].pts_delta && nut->ft[i].pts_delta != pts_delta) continue;
-		if (nut->ft[i].flags & MSB_CODED_FLAG) {
-			if ((fd->len - nut->ft[i].lsb) % nut->ft[i].mul) continue;
-		} else {
-			if (nut->ft[i].lsb != fd->len) continue;
-		}
-		if (!(nut->ft[i].flags & STREAM_CODED_FLAG) && (fd->flags & 3) != nut->ft[i].stream_flags) continue;
-		len += nut->ft[i].stream_plus1 ? 0 : v_len(fd->stream);
-		len += nut->ft[i].pts_delta ? 0 : v_len(coded_pts);
-		len += nut->ft[i].flags & MSB_CODED_FLAG ? v_len((fd->len - nut->ft[i].lsb) / nut->ft[i].mul) : 0;
-		len += nut->ft[i].flags & STREAM_CODED_FLAG ? v_len((fd->flags & 3) ^ nut->ft[i].stream_flags) : 0;
-		if (!size || len < size) { ftnum = i; size = len; }
+		if (flags & FLAG_CODED) {
+			flags = fd->flags & NUT_API_FLAGS;
+			if (nut->ft[i].lsb != fd->len) flags |= FLAG_SIZE_MSB;
+			if (checksum) flags |= FLAG_CHECKSUM;
+			flags |= FLAG_CODED;
+		}
+		if (flags & FLAG_SIZE_MSB) { if ((fd->len - nut->ft[i].lsb) % nut->ft[i].mul) continue; }
+		else { if (nut->ft[i].lsb != fd->len) continue; }
+		if ((flags ^ fd->flags) & NUT_API_FLAGS) continue;
+		if (checksum && !(flags & FLAG_CHECKSUM)) continue;
+
+		len += nut->ft[i].stream_plus1  ? 0 : v_len(fd->stream);
+		len += nut->ft[i].pts_delta     ? 0 : v_len(coded_pts);
+		len += !(flags & FLAG_CODED)    ? 0 : v_len(flags ^ nut->ft[i].flags);
+		len += !(flags & FLAG_SIZE_MSB) ? 0 : v_len((fd->len - nut->ft[i].lsb) / nut->ft[i].mul);
+		len += !(flags & FLAG_CHECKSUM) ? 0 : 4;
+		if (!size || len < size) { ftnum = i; coded_flags = flags; size = len; }
 	}
 	assert(ftnum != -1);
-	if (rftnum) *rftnum = ftnum;
+	if (tmp) {
+		put_bytes(tmp, 1, ftnum); // frame_code
+		if (!nut->ft[ftnum].stream_plus1) put_v(tmp, fd->stream);
+		if (!nut->ft[ftnum].pts_delta)    put_v(tmp, coded_pts);
+		if (coded_flags & FLAG_CODED)     put_v(tmp, coded_flags ^ nut->ft[ftnum].flags);
+		if (coded_flags & FLAG_SIZE_MSB)  put_v(tmp, (fd->len - nut->ft[ftnum].lsb) / nut->ft[ftnum].mul);
+		if (coded_flags & FLAG_CHECKSUM)  put_bytes(tmp, 4, crc32(tmp->buf, bctello(tmp)));
+	}
 	return size;
 }
 
-static void put_frame(nut_context_t * nut, const nut_packet_t * fd, const uint8_t * data) {
-	output_buffer_t * tmp = clear_buffer(nut->tmp_buffer);
+void nut_write_frame(nut_context_t * nut, const nut_packet_t * fd, const uint8_t * buf) {
 	stream_context_t * sc = &nut->sc[fd->stream];
-	int ftnum = -1, coded_pts, pts_delta = fd->pts - sc->last_pts;
-	int i;
-
-	if (ABS(pts_delta) < (1 << (sc->msb_pts_shift - 1)) - 1)
-		coded_pts = fd->pts & ((1 << sc->msb_pts_shift) - 1);
-	else
-		coded_pts = fd->pts + (1 << sc->msb_pts_shift);
-
-	sc->overhead += frame_header(nut, fd, &ftnum);
-
-	put_bytes(tmp, 1, ftnum); // frame_code
-
-	if (!nut->ft[ftnum].stream_plus1) put_v(tmp, fd->stream);
-	if (!nut->ft[ftnum].pts_delta)    put_v(tmp, coded_pts);
-	if (nut->ft[ftnum].flags & MSB_CODED_FLAG)
-		put_v(tmp, (fd->len - nut->ft[ftnum].lsb) / nut->ft[ftnum].mul);
-	if (nut->ft[ftnum].flags & STREAM_CODED_FLAG)
-		put_v(tmp, (fd->flags & 3) ^ nut->ft[ftnum].stream_flags);
-
-	if (0) put_bytes(tmp, 4, crc32(tmp->buf + 8, tmp->buf_ptr - tmp->buf - 8)); // not including startcode
-
-	put_data(nut->o, bctello(tmp), tmp->buf);
-
+	output_buffer_t * tmp;
+	int i;
+
+	if (bctello(nut->o) > (1 << 23)) { // main header repetition
+		i = 23; // ### magic value for header repetition
+		if (bctello(nut->o) > (1 << 25)) {
+			for (i = 26; bctello(nut->o) > (1 << i); i++);
+			i--;
+		}
+		if (nut->last_headers < (1 << i)) {
+			put_headers(nut);
+		}
+	}
+	// distance syncpoints
+	if (nut->last_syncpoint < nut->last_headers  ||
+		bctello(nut->o) - nut->last_syncpoint + fd->len + frame_header(nut, NULL, fd) > nut->max_distance) put_syncpoint(nut);
+
+	tmp = clear_buffer(nut->tmp_buffer);
+	sc->overhead += frame_header(nut, tmp, fd);
 	sc->total_frames++;
 	sc->tot_size += fd->len;
+
+	put_data(nut->o, bctello(tmp), tmp->buf);
+	put_data(nut->o, fd->len, buf);
 
         for (i = 0; i < nut->stream_count; i++) {
 		if (nut->sc[i].last_dts == -1) continue;
@@ -455,35 +468,12 @@
 		assert(compare_ts(nut, fd->pts, fd->stream, nut->sc[i].last_dts, i) >= 0);
 	}
 
-	put_data(nut->o, fd->len, data);
 	sc->last_pts = fd->pts;
 	sc->last_dts = get_dts(sc->sh.decode_delay, sc->pts_cache, fd->pts);
 	sc->sh.max_pts = MAX(sc->sh.max_pts, fd->pts);
-}
-
-void nut_write_frame(nut_context_t * nut, const nut_packet_t * fd, const uint8_t * buf) {
-	stream_context_t * sc = &nut->sc[fd->stream];
-
-	if (bctello(nut->o) > (1 << 23)) { // main header repetition
-		int i = 23; // ### magic value for header repetition
-		if (bctello(nut->o) > (1 << 25)) {
-			for (i = 26; bctello(nut->o) > (1 << i); i++);
-			i--;
-		}
-		if (nut->last_headers < (1 << i)) {
-			put_headers(nut);
-		}
-	}
-	// distance syncpoints
-	if (ABS((int64_t)fd->pts - (int64_t)sc->last_pts) > sc->max_pts_distance)
-		fprintf(stderr, "%d - %d > %d   \n", (int)fd->pts, (int)sc->last_pts, sc->max_pts_distance);
-	if (nut->last_syncpoint < nut->last_headers || ABS((int64_t)fd->pts - (int64_t)sc->last_pts) > sc->max_pts_distance ||
-		bctello(nut->o) - nut->last_syncpoint + fd->len + frame_header(nut, fd, NULL) > nut->max_distance) put_syncpoint(nut);
-
-	put_frame(nut, fd, buf);
-
-	if ((fd->flags & NUT_KEY_STREAM_FLAG) && !sc->last_key) sc->last_key = fd->pts + 1;
-	if (fd->flags & NUT_EOR_STREAM_FLAG) sc->eor = fd->pts + 1;
+
+	if ((fd->flags & NUT_FLAG_KEY) && !sc->last_key) sc->last_key = fd->pts + 1;
+	if (fd->flags & NUT_FLAG_EOR) sc->eor = fd->pts + 1;
 	else sc->eor = 0;
 }
 
@@ -502,20 +492,18 @@
 
 	{
 	int j, n;
-	int flag, fields, sflag, timestamp = 0, mul = 1, stream = 0, size, count;
+	int flag, fields, timestamp = 0, mul = 1, stream = 0, size, count;
 
 	for(n=i=0; i < 256; n++) {
 		assert(mopts->fti[n].tmp_flag != -1);
 		flag   = mopts->fti[n].tmp_flag;
 		fields = mopts->fti[n].tmp_fields;
-		if (fields > 0) sflag     = mopts->fti[n].tmp_sflag;
-		else sflag = 0;
-		if (fields > 1) timestamp = mopts->fti[n].tmp_pts;
-		if (fields > 2) mul       = mopts->fti[n].tmp_mul;
-		if (fields > 3) stream    = mopts->fti[n].tmp_stream;
-		if (fields > 4) size      = mopts->fti[n].tmp_size;
+		if (fields > 0) timestamp = mopts->fti[n].tmp_pts;
+		if (fields > 1) mul       = mopts->fti[n].tmp_mul;
+		if (fields > 2) stream    = mopts->fti[n].tmp_stream;
+		if (fields > 3) size      = mopts->fti[n].tmp_size;
 		else size = 0;
-		if (fields > 6) count     = mopts->fti[n].count;
+		if (fields > 5) count     = mopts->fti[n].count;
 		else count = mul - size;
 
 		for(j = 0; j < count && i < 256; j++, i++) {
@@ -525,7 +513,6 @@
 				continue;
 			}
 			nut->ft[i].flags = flag;
-			nut->ft[i].stream_flags = sflag;
 			nut->ft[i].stream_plus1 = stream;
 			nut->ft[i].mul = mul;
 			nut->ft[i].lsb = size + j;

Modified: trunk/libnut/nut.h
==============================================================================
--- trunk/libnut/nut.h (original)
+++ trunk/libnut/nut.h Sat Mar 11 16:35:56 2006
@@ -3,11 +3,13 @@
 
 #define NUT_VERSION 2
 
-#define NUT_VIDEO_CLASS 0
-#define NUT_AUDIO_CLASS 1
-
-#define NUT_KEY_STREAM_FLAG 1
-#define NUT_EOR_STREAM_FLAG 2
+#define NUT_VIDEO_CLASS    0
+#define NUT_AUDIO_CLASS    1
+#define NUT_SUBTITLE_CLASS 2
+#define NUT_USERDATA_CLASS 3
+
+#define NUT_FLAG_KEY 1
+#define NUT_FLAG_EOR 2
 
 typedef struct {
 	void * priv;
@@ -51,14 +53,13 @@
 } nut_stream_header_t;
 
 typedef struct {
-	int tmp_flag;      // 1 => use msb, 2 => coded sflags, 4 => invalid, -1 => end
+	int tmp_flag;      // -1 => end
 	int tmp_fields;
-	int tmp_sflag;     // tmp_fields = 1
-	int tmp_pts;       // tmp_fields = 2
-	int tmp_mul;       // tmp_fields = 3
-	int tmp_stream;    // tmp_fields = 4
-	int tmp_size;      // tmp_fields = 5
-	int count;         // tmp_fields = 7 (6 is reserved)
+	int tmp_pts;       // tmp_fields = 1
+	int tmp_mul;       // tmp_fields = 2
+	int tmp_stream;    // tmp_fields = 3
+	int tmp_size;      // tmp_fields = 4
+	int count;         // tmp_fields = 6 (5 is reserved)
 } frame_table_input_t;
 
 typedef struct {

Modified: trunk/libnut/priv.h
==============================================================================
--- trunk/libnut/priv.h (original)
+++ trunk/libnut/priv.h Sat Mar 11 16:35:56 2006
@@ -17,7 +17,13 @@
 #define     INDEX_STARTCODE (0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48))
 #define      INFO_STARTCODE (0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48))
 
-#define MSB_CODED_FLAG 1
+#define NUT_API_FLAGS    3
+
+#define FLAG_SIZE_MSB   32
+#define FLAG_CHECKSUM   64
+#define FLAG_CODED    4096
+#define FLAG_INVALID  8192
+
 #define STREAM_CODED_FLAG 2
 #define INVALID_FLAG 4
 
@@ -63,13 +69,12 @@
 } output_buffer_t;
 
 typedef struct {
-	int flags;
-	int stream_flags;
-	int stream_plus1;
-	int pts_delta;
-	int lsb;
-	int mul;
-	int reserved;
+	uint16_t flags;
+	uint16_t mul;
+	uint16_t lsb;
+	int16_t pts_delta;
+	uint8_t reserved;
+	uint8_t stream_plus1;
 } frame_table_t;
 
 typedef struct {

Modified: trunk/nututils/demux_avi.c
==============================================================================
--- trunk/nututils/demux_avi.c (original)
+++ trunk/nututils/demux_avi.c Sat Mar 11 16:35:56 2006
@@ -417,10 +417,10 @@
 	if ((avi->stream[0].last_pts % 1000) < N && avi->buf) {
 		p->next_pts = 0;
 		p->len = 5;
-		p->flags = NUT_KEY_STREAM_FLAG;
+		p->flags = NUT_FLAG_KEY;
 		p->stream = 2;//2 + (avi->stream[0].last_pts % 100);
 		p->pts = avi->stream[0].last_pts;
-		if (avi->stream[0].last_pts % 1000) p->flags |= NUT_EOR_STREAM_FLAG;
+		if (avi->stream[0].last_pts % 1000) p->flags |= NUT_FLAG_EOR;
 		*buf = (void*)avi;
 		free(avi->buf);
 		avi->buf = NULL;
@@ -432,7 +432,7 @@
 	FIXENDIAN32(len);
 	p->next_pts = 0;
 	p->len = len;
-	p->flags = (avi->index[avi->cur++].dwFlags & 0x10) ? NUT_KEY_STREAM_FLAG : 0;
+	p->flags = (avi->index[avi->cur++].dwFlags & 0x10) ? NUT_FLAG_KEY : 0;
 	p->stream = s = (fourcc[0] - '0') * 10 + (fourcc[1] - '0');
 	if (s == 0) { // 1 frame of video
 		int type;
@@ -441,8 +441,8 @@
 		if (stats) fprintf(stats, "%c", type==0?'I':type==1?'P':type==2?'B':'S');
 		switch (type) {
 			case 0: // I
-				if (!(p->flags & NUT_KEY_STREAM_FLAG)) printf("Error detected stream %d frame %d\n", s, (int)p->pts);
-				p->flags |= NUT_KEY_STREAM_FLAG;
+				if (!(p->flags & NUT_FLAG_KEY)) printf("Error detected stream %d frame %d\n", s, (int)p->pts);
+				p->flags |= NUT_FLAG_KEY;
 				break;
 			case 3: // S
 				printf("S-Frame %d\n", (int)ftell(avi->in));
@@ -476,8 +476,8 @@
 		if (samplesize) avi->stream[s].last_pts += p->len / samplesize;
 		else avi->stream[s].last_pts++;
 
-		if (!(p->flags & NUT_KEY_STREAM_FLAG)) printf("Error detected stream %d frame %d\n", s, (int)p->pts);
-		p->flags |= NUT_KEY_STREAM_FLAG;
+		if (!(p->flags & NUT_FLAG_KEY)) printf("Error detected stream %d frame %d\n", s, (int)p->pts);
+		p->flags |= NUT_FLAG_KEY;
 	} else {
 		printf("%d %4.4s\n", avi->cur, fourcc);
 		err = 10;

Modified: trunk/nututils/demux_ogg.c
==============================================================================
--- trunk/nututils/demux_ogg.c (original)
+++ trunk/nututils/demux_ogg.c Sat Mar 11 16:35:56 2006
@@ -571,7 +571,7 @@
 
 	p->next_pts = 0;
 	p->stream = stream;
-	p->flags = os->oc->is_key ? os->oc->is_key(os) : NUT_KEY_STREAM_FLAG;
+	p->flags = !os->oc->is_key || os->oc->is_key(os) ? NUT_FLAG_KEY : 0;
 	p->pts = os->oc->get_pts(os);
 
 	*buf = os->buf + os->buf_pos;

Modified: trunk/nututils/nutmerge.c
==============================================================================
--- trunk/nututils/nutmerge.c (original)
+++ trunk/nututils/nutmerge.c Sat Mar 11 16:35:56 2006
@@ -17,28 +17,29 @@
 
 frame_table_input_t ft_default[] = {
 	// There must be atleast this safety net:
-	//{    3,      3,     0,   0,   1,      0,    0,     0 },
-	//{ flag, fields, sflag, pts, mul, stream, size, count }
-	  {    4,      0,     0,   0,   1,      0,    0,     0 }, // invalid 0x00
-	  {    1,      1,     1,   0,   1,      0,    0,     0 }, // safety net non key frame
-	  {    1,      0,     0,   0,   1,      0,    0,     0 }, // safety net key frame
-	  {    3,      0,     0,   0,   1,      0,    0,     0 }, // one more safety net
-	  {    0,      5,     1,   1, 337,      2,  336,     0 }, // used 82427 times
-	  {    0,      5,     1,   1, 385,      2,  384,     0 }, // used 56044 times
-	  {    0,      5,     0,   2,   7,      1,    6,     0 }, // used 20993 times
-	  {    0,      5,     0,   1,   7,      1,    6,     0 }, // used 10398 times
-	  {    0,      5,     1,   1, 481,      2,  480,     0 }, // used 3527 times
-	  {    0,      5,     1,   1, 289,      2,  288,     0 }, // used 2042 times
-	  {    0,      5,     1,   1, 577,      2,  576,     0 }, // used 1480 times
-	  {    0,      5,     1,   1, 673,      2,  672,     0 }, // used 862 times
-	  {    0,      5,     1,   1, 769,      2,  768,     0 }, // used 433 times
-	  {    0,      5,     1,   1, 961,      2,  960,     0 }, // used 191 times
-	  {    1,      4,     0,   2, 104,      1,    0,     0 }, // "1.2.0" => 14187
-	  {    1,      4,     0,  -1,  42,      1,    0,     0 }, // "1.-1.0" => 5707
-	  {    1,      4,     0,   1,  83,      1,    0,     0 }, // "1.1.0" => 11159
-	  {    1,      4,     1,   1,  11,      1,    0,     0 }, // "1.1.1" => 1409
-	  {    4,      3,     0,   0,   1,      0,    0,     0 }, // invalid 0xFF
-	  {   -1,      0,     0,   0,   0,      0,    0,     0 }, // end
+	//{ 4128,      3,   0,   1,      0,    0,     0 },
+	//{ flag, fields, pts, mul, stream, size, count }
+	  { 8192,      0,   0,   1,      0,    0,     0 }, // invalid 0x00
+	  {   32,      1,   0,   1,      0,    0,     0 }, // safety net non key frame
+	  {   33,      0,   0,   1,      0,    0,     0 }, // safety net key frame
+	  { 4128,      0,   0,   1,      0,    0,     0 }, // one more safety net
+	  {    1,      4,   1, 337,      2,  336,     0 }, // used 82427 times
+	  {    1,      4,   1, 385,      2,  384,     0 }, // used 56044 times
+	  {    0,      4,   2,   7,      1,    6,     0 }, // used 20993 times
+	  {    0,      4,   1,   7,      1,    6,     0 }, // used 10398 times
+	  {    1,      4,   1, 481,      2,  480,     0 }, // used 3527 times
+	  {    1,      4,   1, 289,      2,  288,     0 }, // used 2042 times
+	  {    1,      4,   1, 577,      2,  576,     0 }, // used 1480 times
+	  {    1,      4,   1, 673,      2,  672,     0 }, // used 862 times
+	  {    1,      4,   1, 769,      2,  768,     0 }, // used 433 times
+	  {    1,      4,   1, 961,      2,  960,     0 }, // used 191 times
+	  {   32,      3,   2, 101,      1,    0,     0 }, // "1.2.0" => 14187
+	  {   32,      3,  -1,  41,      1,    0,     0 }, // "1.-1.0" => 5707
+	  {   32,      3,   1,  81,      1,    0,     0 }, // "1.1.0" => 11159
+	  {   33,      3,   1,  11,      1,    0,     0 }, // "1.1.1" => 1409
+	  {   97,      3,   0,   6,      1,    0,     0 }, // checksum for video
+	  { 8192,      2,   0,   1,      0,    0,     0 }, // invalid 0xFF
+	  {   -1,      0,   0,   0,      0,    0,     0 }, // end
 };
 
 int main(int argc, char * argv []) {




More information about the NUT-devel mailing list