NUT-devel
Threads by month
- ----- 2025 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 753 discussions

11 Mar '06
Author: ods15
Date: Sat Mar 11 17:06:05 2006
New Revision: 94
Log:
sync to spec, back_ptr div16 instead of div8
Modified:
trunk/libnut/demuxer.c
trunk/libnut/muxer.c
Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c (original)
+++ trunk/libnut/demuxer.c Sat Mar 11 17:06:05 2006
@@ -311,7 +311,7 @@
for (i = sl->len; i--; ) { // more often than not, we're adding at end of list
off_t pos = sl->s[i].pos >> 1;
if (pos > sp.pos) continue;
- if (sp.pos < pos + 8) { // syncpoint already in list
+ if (sp.pos < pos + 16) { // syncpoint already in list
sl->s[i].pos = (sp.pos << 1) | (sl->s[i].pos & 1); // refine accuracy of syncpoint position
if (pts) {
sl->s[i].pos |= 1;
@@ -369,7 +369,7 @@
GET_V(tmp, s.pts);
GET_V(tmp, s.back_ptr);
- s.back_ptr = (s.back_ptr * 8 + 7)<<1;
+ s.back_ptr = (s.back_ptr * 16 + 15)<<1;
set_global_pts(nut, s.pts);
@@ -421,7 +421,7 @@
for (i = 0; i < sl->len; i++) {
GET_V(tmp, x);
- x *= 8;
+ x *= 16;
sl->s[i].pos = (x << 1) + (i ? sl->s[i-1].pos : 1);
sl->s[i].back_ptr = 1;
sl->s[i].pts = 0;
@@ -599,7 +599,7 @@
GET_V(tmp, res->pts);
GET_V(tmp, res->back_ptr);
- res->back_ptr = (res->back_ptr * 8 + 7) << 1;
+ res->back_ptr = (res->back_ptr * 16 + 15) << 1;
}
if (!backwards) return 0;
else ptr = bctello(nut->i);
@@ -882,7 +882,7 @@
double hi_pd = TO_DOUBLE_PTS(hip);
double lo_pd = TO_DOUBLE_PTS(lop);
a++;
- if (hi - lo < nut->max_distance*2) guess = lo + 8;
+ if (hi - lo < nut->max_distance*2) guess = lo + 16;
else { // linear interpolation
#define INTERPOLATE_WEIGHT (19./20)
double a = (double)(hi - lo) / (hi_pd - lo_pd);
@@ -890,7 +890,7 @@
guess = guess * INTERPOLATE_WEIGHT + (lo+hi)/2 * (1 - INTERPOLATE_WEIGHT);
if (hi - guess < nut->max_distance*2) guess = hi - nut->max_distance*2; //(lo + hi)/2;
}
- if (guess < lo + 8) guess = lo + 8;
+ if (guess < lo + 8) guess = lo + 16;
fprintf(stderr, "\n%d [ (%d,%.3f) .. (%d,%.3f) .. (%d,%.3f) ] ", i, (int)lo, lo_pd, (int)guess, time_pos, (int)hi, hi_pd);
if (!nut->seek_status) seek_buf(nut->i, guess, SEEK_SET);
nut->seek_status = hi; // so we know where to continue off...
@@ -899,7 +899,7 @@
if (s.back_ptr == 1 || s.pos >= hi) { // we got back to 'hi'
// either we scanned everything from lo to hi, or we keep trying
- if (guess <= lo + 11) sl->s[i].back_ptr |= 1; // we are done!
+ if (guess <= lo + 16) sl->s[i].back_ptr |= 1; // we are done!
else hi = guess;
continue;
}
@@ -964,13 +964,13 @@
nut->last_syncpoint = 0; // last_key is invalid
seek_buf(nut->i, s.pos, SEEK_SET); // go back to syncpoint. This will not need a seek.
nut->seek_status = s.pos << 1;
- if (s.pos > start + 7) goto err_out; // error condition, we didn't get the syncpoint we wanted
+ if (s.pos > start + 15) goto err_out; // error condition, we didn't get the syncpoint we wanted
}
if (stopper) {
off_t back_ptr = (stopper->pos >> 1) - (stopper->back_ptr>>1);
for (i = 1; i < sl->len; i++) {
- if ((sl->s[i].pos >> 1) > back_ptr + 7) {
+ if ((sl->s[i].pos >> 1) > back_ptr + 15) {
if (sl->s[i-1].back_ptr & 1) stopper_syncpoint = sl->s[i].pos >> 1;
break;
}
@@ -989,7 +989,7 @@
int header_size = bctello(nut->i) - buf_before;
nut->i->buf_ptr -= header_size;
if (stopper) {
- if ((!stopper_syncpoint && buf_before > (stopper->pos >> 1) - (stopper->back_ptr>>1) + 7) || stopper_syncpoint == buf_before) {
+ if ((!stopper_syncpoint && buf_before > (stopper->pos >> 1) - (stopper->back_ptr>>1) + 15) || stopper_syncpoint == buf_before) {
int n = 1;
stopper_syncpoint = buf_before;
for (i = 0; i < nut->stream_count; i++) {
Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 17:06:05 2006
@@ -299,7 +299,7 @@
for (j = 0; j < nut->stream_count; j++) n &= keys[j];
if (n) { i--; break; }
}
- back_ptr = (nut->last_syncpoint - s->s[i].pos) / 8;
+ back_ptr = (nut->last_syncpoint - s->s[i].pos) / 16;
for (i = 0; i < nut->stream_count; i++) {
nut->sc[i].last_pts = convert_ts(nut, pts, stream, i);
@@ -332,8 +332,8 @@
put_v(tmp, s->len);
for (i = 0; i < s->len; i++) {
- off_t pos = s->s[i].pos / 8;
- off_t last_pos = i ? s->s[i-1].pos / 8 : 0;
+ off_t pos = s->s[i].pos / 16;
+ off_t last_pos = i ? s->s[i-1].pos / 16 : 0;
put_v(tmp, pos - last_pos);
}
1
0

[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
by syncmail@mplayerhq.hu 11 Mar '06
by syncmail@mplayerhq.hu 11 Mar '06
11 Mar '06
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 []) {
1
0
Any objection to this patch? It makes it somewhat easier/nicer to move over
the stream flags to API, and keep the nut flags in the demuxer...
Also, 128 is low enough for the flags which have no use to be coded in
frame header, because vlc's can only store up to 127 in a single byte.
Also, the non-stream flags are pushed to top of first byte so they can
expand towards down while stream flags expand toward up...
(I know, this is all very silly, but I see no reason against any of this,
the decision between this is almost arbitrary, so might as well go with the
more convinient direction?)
- ods15
2
1

11 Mar '06
Author: ods15
Date: Sat Mar 11 13:49:12 2006
New Revision: 92
Log:
sync to spec, syncpoints are their own headers
some more asserts
small bugfix in demuxer, ptr could be invalid in find_syncpoint
less waste in demuxer with no unnecessary memcpy and malloc
Modified:
trunk/libnut/demuxer.c
trunk/libnut/muxer.c
Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c (original)
+++ trunk/libnut/demuxer.c Sat Mar 11 13:49:12 2006
@@ -77,8 +77,7 @@
return bc->buf + start;
}
-static input_buffer_t * new_mem_buffer() {
- input_buffer_t * bc = malloc(sizeof(input_buffer_t));
+static input_buffer_t * new_mem_buffer(input_buffer_t * bc) {
bc->read_len = 0;
bc->write_len = 0;
bc->is_mem = 1;
@@ -89,7 +88,7 @@
}
static input_buffer_t * new_input_buffer(nut_input_stream_t isc) {
- input_buffer_t * bc = new_mem_buffer();
+ input_buffer_t * bc = new_mem_buffer(malloc(sizeof(input_buffer_t)));
bc->is_mem = 0;
bc->isc = isc;
bc->file_pos = isc.file_pos;
@@ -102,6 +101,7 @@
}
static void free_buffer(input_buffer_t * bc) {
+ assert(!bc->is_mem);
if (!bc) return;
free(bc->buf);
free(bc);
@@ -210,19 +210,15 @@
if (out) {
assert(out->is_mem);
assert(out->buf == out->buf_ptr);
- if (out->write_len < forward_ptr - 4) {
- out->write_len = forward_ptr - 4;
- out->buf_ptr = out->buf = realloc(out->buf, out->write_len);
- }
- memcpy(out->buf, in->buf_ptr - forward_ptr, forward_ptr - 4);
- out->read_len = forward_ptr - 4; // not including checksum
+ out->buf_ptr = out->buf = in->buf_ptr - forward_ptr;
+ out->write_len = out->read_len = forward_ptr - 4; // not including checksum
}
err_out:
return err;
}
static int get_main_header(nut_context_t * nut) {
- input_buffer_t * tmp = new_mem_buffer();
+ 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;
@@ -270,12 +266,11 @@
}
}
err_out:
- free_buffer(tmp);
return err;
}
static int get_stream_header(nut_context_t * nut, int id) {
- input_buffer_t * tmp = new_mem_buffer();
+ input_buffer_t itmp, * tmp = new_mem_buffer(&itmp);
stream_context_t * sc = &nut->sc[id];
int i, err = 0;
uint64_t a;
@@ -311,7 +306,6 @@
break;
}
err_out:
- free_buffer(tmp);
return err;
}
@@ -372,11 +366,14 @@
int err = 0;
syncpoint_t s;
int after_seek = nut->last_syncpoint ? 0 : 1;
+ input_buffer_t itmp, * tmp = new_mem_buffer(&itmp);
nut->last_syncpoint = s.pos = bctello(nut->i) - 8;
- GET_V(nut->i, s.pts);
- GET_V(nut->i, s.back_ptr);
+ CHECK(get_header(nut->i, tmp));
+
+ GET_V(tmp, s.pts);
+ GET_V(tmp, s.back_ptr);
s.back_ptr = (s.back_ptr * 8 + 7)<<1;
set_global_pts(nut, s.pts);
@@ -404,7 +401,7 @@
}
static int get_index(nut_context_t * nut) {
- input_buffer_t * tmp = new_mem_buffer();
+ input_buffer_t itmp, * tmp = new_mem_buffer(&itmp);
int err = 0;
syncpoint_list_t * sl = &nut->syncpoints;
uint64_t x;
@@ -473,7 +470,6 @@
fprintf(stderr, "NUT index read successfully, %d syncpoints\n", sl->len);
err_out:
- free_buffer(tmp);
return err;
}
@@ -496,37 +492,13 @@
if (tmp == 'N') {
CHECK(get_bytes(nut->i, 7, &tmp));
tmp |= (uint64_t)'N' << 56;
- if (tmp == MAIN_STARTCODE) {
- int i;
- GET_V(nut->i, pd->len);
- CHECK(skip_buffer(nut->i, pd->len));
- for (i = 0; i < nut->stream_count; i++) {
- CHECK(get_bytes(nut->i, 8, &tmp));
- ERROR(tmp != STREAM_STARTCODE, -ERR_NOSTREAM_STARTCODE);
- GET_V(nut->i, pd->len);
- CHECK(skip_buffer(nut->i, pd->len));
- }
- CHECK(get_bytes(nut->i, 8, &tmp));
- while (tmp == INFO_STARTCODE) {
- GET_V(nut->i, pd->len);
- CHECK(skip_buffer(nut->i, pd->len));
- CHECK(get_bytes(nut->i, 8, &tmp));
- }
- if (tmp == INDEX_STARTCODE) {
- GET_V(nut->i, pd->len);
- CHECK(skip_buffer(nut->i, pd->len));
- CHECK(get_bytes(nut->i, 8, &tmp));
- }
- ERROR(tmp != SYNCPOINT_STARTCODE && tmp != MAIN_STARTCODE, -ERR_NO_HEADERS);
- nut->i->buf_ptr -= 8;
- return get_packet(nut, pd, saw_syncpoint);
- } else if (tmp == SYNCPOINT_STARTCODE) {
+ if (tmp == SYNCPOINT_STARTCODE) {
after_sync = bctello(nut->i);
CHECK(get_syncpoint(nut));
CHECK(get_bytes(nut->i, 1, &tmp));
} else {
- nut->i->buf_ptr -= 7;
- tmp = 'N';
+ CHECK(get_header(nut->i, NULL));
+ return get_packet(nut, pd, saw_syncpoint);
}
}
@@ -560,7 +532,7 @@
for (i = 0; i < nut->ft[tmp].reserved; i++) { int scrap; GET_V(nut->i, scrap); }
- if (after_sync) {
+ if (0) {
uint64_t checksum;
off_t pos = bctello(nut->i);
CHECK(get_bytes(nut->i, 4, &checksum));
@@ -599,7 +571,7 @@
int read;
int err = 0;
uint64_t tmp;
- uint8_t * ptr = NULL;
+ off_t ptr = 0;
assert(!backwards || !stop); // can't have both
if (backwards) seek_buf(nut->i, -nut->max_distance, SEEK_CUR);
@@ -614,32 +586,22 @@
tmp = (tmp << 8) | *(nut->i->buf_ptr++);
if (tmp != SYNCPOINT_STARTCODE) continue;
if (res) {
- int i, scrap;
+ input_buffer_t itmp, * tmp = new_mem_buffer(&itmp);
res->pos = bctello(nut->i) - 8;
- GET_V(nut->i, res->pts);
- GET_V(nut->i, tmp);
- res->back_ptr = (tmp * 8 + 7) << 1;
-
- CHECK(get_bytes(nut->i, 1, &tmp));
- if (!nut->ft[tmp].stream_plus1) GET_V(nut->i, scrap);
- if (!nut->ft[tmp].pts_delta) GET_V(nut->i, scrap);
- if (nut->ft[tmp].flags & MSB_CODED_FLAG) GET_V(nut->i, scrap);
- if (nut->ft[tmp].flags & STREAM_CODED_FLAG) GET_V(nut->i, scrap);
- for (i = 0; i < nut->ft[tmp].reserved; i++) GET_V(nut->i, scrap);
- CHECK(get_bytes(nut->i, 4, &tmp));
-
- if (tmp != crc32(nut->i->buf_ptr - (bctello(nut->i) - res->pos - 8), bctello(nut->i) - 4 - res->pos - 8)) {
- tmp = 0;
- nut->i->buf_ptr -= bctello(nut->i) - res->pos - 8; // rewind to right after the startcode
- continue;
- }
+
+ if ((err = get_header(nut->i, tmp)) == 2) goto err_out;
+ if (err) { err = 0; continue; }
+
+ GET_V(tmp, res->pts);
+ GET_V(tmp, res->back_ptr);
+ res->back_ptr = (res->back_ptr * 8 + 7) << 1;
}
if (!backwards) return 0;
- else ptr = nut->i->buf_ptr;
+ else ptr = bctello(nut->i);
}
if (ptr) {
- nut->i->buf_ptr = ptr;
+ nut->i->buf_ptr -= bctello(nut->i) - ptr;
return 0;
}
Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 13:49:12 2006
@@ -57,6 +57,7 @@
}
static output_buffer_t * clear_buffer(output_buffer_t * bc) {
+ assert(bc->is_mem);
bc->buf_ptr = bc->buf;
return bc;
}
@@ -258,7 +259,8 @@
for (i = 0; i < nut->info_count; i++) put_info(nut, &nut->info[i]);
}
-static void put_syncpoint(nut_context_t * nut, output_buffer_t * bc) {
+static void put_syncpoint(nut_context_t * nut) {
+ output_buffer_t * tmp = clear_buffer(nut->tmp_buffer);
int i;
uint64_t pts = 0;
int stream = 0;
@@ -309,11 +311,12 @@
if (nut->sc[i].eor) nut->sc[i].eor = -1; // so we know to ignore this stream in future syncpoints
}
- put_bytes(bc, 8, SYNCPOINT_STARTCODE);
- put_v(bc, pts * nut->stream_count + stream);
- put_v(bc, back_ptr);
-
- nut->sync_overhead += bctello(bc) + 4/*checksum*/;
+ put_v(tmp, pts * nut->stream_count + stream);
+ put_v(tmp, back_ptr);
+
+ put_header(nut->o, tmp, nut->tmp_buffer2, SYNCPOINT_STARTCODE, 0);
+
+ nut->sync_overhead += bctello(tmp) + bctello(nut->tmp_buffer2);
}
static void put_index(nut_context_t * nut) {
@@ -414,42 +417,31 @@
return size;
}
-static int put_frame_header(nut_context_t * nut, output_buffer_t * bc, const nut_packet_t * fd) {
+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);
stream_context_t * sc = &nut->sc[fd->stream];
int ftnum = -1, coded_pts, pts_delta = fd->pts - sc->last_pts;
- int size;
+ 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);
- size = frame_header(nut, fd, &ftnum);
-
- put_bytes(bc, 1, ftnum); // frame_code
-
- if (!nut->ft[ftnum].stream_plus1) put_v(bc, fd->stream);
- if (!nut->ft[ftnum].pts_delta) put_v(bc, coded_pts);
+ 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(bc, (fd->len - nut->ft[ftnum].lsb) / nut->ft[ftnum].mul);
+ put_v(tmp, (fd->len - nut->ft[ftnum].lsb) / nut->ft[ftnum].mul);
if (nut->ft[ftnum].flags & STREAM_CODED_FLAG)
- put_v(bc, (fd->flags & 3) ^ nut->ft[ftnum].stream_flags);
-
- return size;
-}
-
-static void put_frame(nut_context_t * nut, const nut_packet_t * fd, const uint8_t * data, int write_syncpoint) {
- output_buffer_t * tmp = clear_buffer(nut->tmp_buffer);
- stream_context_t * sc = &nut->sc[fd->stream];
- int i;
-
- if (write_syncpoint) put_syncpoint(nut, tmp);
-
- sc->overhead += put_frame_header(nut, tmp, fd);
-
- put_data(nut->o, tmp->buf_ptr - tmp->buf, tmp->buf);
-
- if (write_syncpoint) put_bytes(nut->o, 4, crc32(tmp->buf + 8, tmp->buf_ptr - tmp->buf - 8)); // not including startcode
+ 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);
sc->total_frames++;
sc->tot_size += fd->len;
@@ -471,7 +463,6 @@
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 write_syncpoint = 0;
if (bctello(nut->o) > (1 << 23)) { // main header repetition
int i = 23; // ### magic value for header repetition
@@ -487,9 +478,9 @@
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) write_syncpoint = 1;
-
- put_frame(nut, fd, buf, write_syncpoint);
+ 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;
1
0

[NUT] (ods15): r91 - in /trunk: demux_nut.c libnut/demuxer.c libnut/muxer.c libnut/nut.h libnut/priv.h nututils/demux_nut.c
by syncmail@mplayerhq.hu 11 Mar '06
by syncmail@mplayerhq.hu 11 Mar '06
11 Mar '06
Author: ods15
Date: Sat Mar 11 13:10:33 2006
New Revision: 91
Log:
sync to spec, forward_ptr has its own checksum.
API change, nut_read_headers() must be called first.
Modified:
trunk/demux_nut.c
trunk/libnut/demuxer.c
trunk/libnut/muxer.c
trunk/libnut/nut.h
trunk/libnut/priv.h
trunk/nututils/demux_nut.c
Modified: trunk/demux_nut.c
==============================================================================
--- trunk/demux_nut.c (original)
+++ trunk/demux_nut.c Sat Mar 11 13:10:33 2006
@@ -52,6 +52,7 @@
if (memcmp(buf, ID_STRING, ID_LENGTH)) return 0;
+ stream_seek(demuxer->stream, 0);
return DEMUXER_TYPE_NUT;
}
@@ -63,28 +64,17 @@
.seek = mp_seek,
.read = mp_read,
.eof = NULL,
- .file_pos = ID_LENGTH,
+ .file_pos = stream_tell(demuxer->stream),
},
.read_index = index_mode
};
nut_priv_t * priv = demuxer->priv;
nut_context_t * nut = priv->nut = nut_demuxer_init(&dopts);
- nut_packet_t pd;
nut_stream_header_t * s;
int ret;
int i;
- while ((ret = nut_read_next_packet(nut, &pd))) {
- if (ret < 0) mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n", nut_error(-ret));
- if (ret == 1) break;
- }
- if (ret || pd.type != e_headers) {
- nut_demuxer_uninit(nut);
- free(priv);
- return NULL;
- }
-
- if ((ret = nut_read_headers(nut, &pd, &s))) {
+ if ((ret = nut_read_headers(nut, &s))) {
if (ret < 0) mp_msg(MSGT_HEADER, MSGL_ERR, "NUT error: %s\n", nut_error(-ret));
nut_demuxer_uninit(nut);
free(priv);
Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c (original)
+++ trunk/libnut/demuxer.c Sat Mar 11 13:10:33 2006
@@ -71,6 +71,12 @@
return 0;
}
+static uint8_t * get_buf(input_buffer_t * bc, off_t start) {
+ start -= bc->file_pos;
+ assert((unsigned)start < bc->read_len);
+ return bc->buf + start;
+}
+
static input_buffer_t * new_mem_buffer() {
input_buffer_t * bc = malloc(sizeof(input_buffer_t));
bc->read_len = 0;
@@ -187,33 +193,40 @@
return 0;
}
-static int get_header(input_buffer_t * in, input_buffer_t * out, int len) {
- uint64_t code;
-
- assert(out->is_mem);
- assert(out->buf == out->buf_ptr);
-
- len -= 4; // checksum
-
- if (out->write_len < len) {
- out->write_len = len;
- out->buf_ptr = out->buf = realloc(out->buf, out->write_len);
- }
- if (get_data(in, len, out->buf) != len) return buf_eof(in);
- out->read_len = len;
-
- if (get_bytes(in, 4, &code)) return buf_eof(in); // checksum
- if (code != crc32(out->buf, len)) return -ERR_BAD_CHECKSUM;
-
- return 0;
-}
-
-static int get_main_header(nut_context_t *nut, int len) {
+static int get_header(input_buffer_t * in, input_buffer_t * out) {
+ off_t start = bctello(in) - 8; // startcode
+ int forward_ptr;
+ int err = 0;
+
+ GET_V(in, forward_ptr);
+ if (forward_ptr > 4096) {
+ skip_buffer(in, 4); // header_checksum
+ ERROR(crc32(get_buf(in, start), bctello(in) - start), -ERR_BAD_CHECKSUM);
+ }
+
+ CHECK(skip_buffer(in, forward_ptr));
+ ERROR(crc32(in->buf_ptr - forward_ptr, forward_ptr), -ERR_BAD_CHECKSUM);
+
+ if (out) {
+ assert(out->is_mem);
+ assert(out->buf == out->buf_ptr);
+ if (out->write_len < forward_ptr - 4) {
+ out->write_len = forward_ptr - 4;
+ out->buf_ptr = out->buf = realloc(out->buf, out->write_len);
+ }
+ memcpy(out->buf, in->buf_ptr - forward_ptr, forward_ptr - 4);
+ out->read_len = forward_ptr - 4; // not including checksum
+ }
+err_out:
+ return err;
+}
+
+static int get_main_header(nut_context_t * nut) {
input_buffer_t * tmp = new_mem_buffer();
int i, j, err = 0;
int flag, fields, timestamp = 0, mul = 1, stream = 0, sflag, size, count, reserved;
- CHECK(get_header(nut->i, tmp, len));
+ CHECK(get_header(nut->i, tmp));
GET_V(tmp, i);
ERROR(i != NUT_VERSION, -ERR_BAD_VERSION);
@@ -264,11 +277,10 @@
static int get_stream_header(nut_context_t * nut, int id) {
input_buffer_t * tmp = new_mem_buffer();
stream_context_t * sc = &nut->sc[id];
- int i, err = 0, len;
+ int i, err = 0;
uint64_t a;
- GET_V(nut->i, len);
- CHECK(get_header(nut->i, tmp, len));
+ CHECK(get_header(nut->i, tmp));
GET_V(tmp, i);
ERROR(i != id, -ERR_BAD_STREAM_ORDER);
@@ -401,8 +413,7 @@
CHECK(get_bytes(nut->i, 8, &x));
ERROR(x != INDEX_STARTCODE, -ERR_GENERAL_ERROR);
- GET_V(nut->i, x);
- CHECK(get_header(nut->i, tmp, x));
+ CHECK(get_header(nut->i, tmp));
GET_V(tmp, x);
for (i = 0; i < nut->stream_count; i++) {
@@ -655,24 +666,7 @@
int nut_read_next_packet(nut_context_t * nut, nut_packet_t * pd) {
int err = 0;
- uint64_t tmp;
- if (!nut->last_headers) {
- const int len = strlen(ID_STRING) + 1;
- char str[len];
- ERROR(get_data(nut->i, len, str) != len, buf_eof(nut->i));
- if (memcmp(str, ID_STRING, len)) nut->i->buf_ptr = nut->i->buf; // rewind
- CHECK(get_bytes(nut->i, 8, &tmp));
- do {
- if (tmp == MAIN_STARTCODE) {
- GET_V(nut->i, pd->len);
- pd->type = e_headers;
- return 0;
- }
- ERROR(ready_read_buf(nut->i, 1) < 1, buf_eof(nut->i));
- tmp = (tmp << 8) | *(nut->i->buf_ptr++);
- } while (bctello(nut->i) < 4096);
- }
- ERROR(!nut->last_headers, -ERR_NO_HEADERS);
+ ERROR(!nut->last_headers, -ERR_NO_HEADERS); // paranoia, old API
if (nut->seek_status) { // in error mode!
syncpoint_t s;
@@ -702,11 +696,32 @@
return err;
}
-int nut_read_headers(nut_context_t * nut, nut_packet_t * pd, nut_stream_header_t * s []) {
+int nut_read_headers(nut_context_t * nut, nut_stream_header_t * s []) {
int i, err = 0;
*s = NULL;
- if (!nut->last_headers) { // we already have headers, we were called just for index
- CHECK(get_main_header(nut, pd->len));
+ if (!nut->seek_status) { // we already have headers, we were called just for index
+ if (!nut->last_headers) {
+ off_t start = bctello(nut->i);
+ uint64_t tmp;
+ if (start < strlen(ID_STRING) + 1) {
+ int n = strlen(ID_STRING) + 1 - start;
+ ERROR(ready_read_buf(nut->i, n) < n, buf_eof(nut->i));
+ if (memcmp(get_buf(nut->i, start), ID_STRING + start, n)) nut->i->buf_ptr = nut->i->buf; // rewind
+ fprintf(stderr, "NUT file_id checks out\n");
+ }
+
+ CHECK(get_bytes(nut->i, 7, &tmp));
+ ERROR(ready_read_buf(nut->i, 4096) < 4096, buf_eof(nut->i));
+ while (bctello(nut->i) < 4096) {
+ tmp = (tmp << 8) | *(nut->i->buf_ptr++);
+ if (tmp == MAIN_STARTCODE) break;
+ }
+ ERROR(tmp != MAIN_STARTCODE, -ERR_NO_HEADERS);
+ nut->last_headers = bctello(nut->i);
+ flush_buf(nut->i);
+ }
+
+ CHECK(get_main_header(nut));
if (!nut->sc) {
nut->sc = malloc(sizeof(stream_context_t) * nut->stream_count);
@@ -741,7 +756,6 @@
nut->i->buf_ptr -= 8;
flush_buf(nut->i);
}
- nut->last_headers = 1;
}
if (nut->dopts.read_index && nut->i->isc.seek) {
Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 13:10:33 2006
@@ -107,21 +107,28 @@
put_data(bc, len, data);
}
-static void put_header(output_buffer_t * bc, output_buffer_t * tmp, uint64_t startcode, int index_ptr) {
+static void put_header(output_buffer_t * bc, output_buffer_t * in, output_buffer_t * tmp, uint64_t startcode, int index_ptr) {
int forward_ptr;
+ assert(in->is_mem);
assert(tmp->is_mem);
-
- forward_ptr = tmp->buf_ptr - tmp->buf;
+ clear_buffer(tmp);
+
+ forward_ptr = bctello(in);
forward_ptr += 4; // checksum
if (index_ptr) forward_ptr += 8;
- fprintf(stderr, "header/index size: %d\n", forward_ptr + 8 + v_len(forward_ptr));
-
- if (index_ptr) put_bytes(tmp, 8, 8 + v_len(forward_ptr) + forward_ptr);
-
- put_bytes(bc, 8, startcode);
- put_v(bc, forward_ptr);
- put_data(bc, tmp->buf_ptr - tmp->buf, tmp->buf);
- put_bytes(bc, 4, crc32(tmp->buf, tmp->buf_ptr - tmp->buf));
+
+ // packet_header
+ put_bytes(tmp, 8, startcode);
+ put_v(tmp, forward_ptr);
+ if (forward_ptr > 4096) put_bytes(tmp, 4, crc32(tmp->buf, bctello(tmp)));
+ put_data(bc, bctello(tmp), tmp->buf);
+
+ // packet_footer
+ if (index_ptr) put_bytes(in, 8, bctello(tmp) + bctello(in) + 8 + 4);
+ put_bytes(in, 4, crc32(in->buf, bctello(in)));
+
+ put_data(bc, bctello(in), in->buf);
+ if (startcode != SYNCPOINT_STARTCODE) fprintf(stderr, "header/index size: %d\n", (int)(bctello(tmp) + bctello(in)));
}
static void put_main_header(nut_context_t * nut) {
@@ -168,7 +175,7 @@
if (fields > 6) put_v(tmp, count);
}
- put_header(nut->o, tmp, MAIN_STARTCODE, 0);
+ put_header(nut->o, tmp, nut->tmp_buffer2, MAIN_STARTCODE, 0);
}
static void put_stream_header(nut_context_t * nut, int id) {
@@ -201,7 +208,7 @@
break;
}
- put_header(nut->o, tmp, STREAM_STARTCODE, 0);
+ put_header(nut->o, tmp, nut->tmp_buffer2, STREAM_STARTCODE, 0);
}
static void put_info(nut_context_t * nut, nut_info_packet_t * info) {
@@ -239,7 +246,7 @@
}
}
- put_header(nut->o, tmp, INFO_STARTCODE, 0);
+ put_header(nut->o, tmp, nut->tmp_buffer2, INFO_STARTCODE, 0);
}
static void put_headers(nut_context_t * nut) {
@@ -373,7 +380,7 @@
}
}
- put_header(nut->o, tmp, INDEX_STARTCODE, 1);
+ 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) {
@@ -496,6 +503,7 @@
nut->o = new_output_buffer(mopts->output);
nut->tmp_buffer = new_mem_buffer(); // general purpose buffer
+ nut->tmp_buffer2 = new_mem_buffer(); // for packet_headers
nut->max_distance = mopts->max_distance;
nut->mopts = *mopts;
@@ -651,6 +659,7 @@
free(nut->syncpoints.eor);
free_buffer(nut->tmp_buffer);
+ free_buffer(nut->tmp_buffer2);
free_buffer(nut->o); // flushes file
fprintf(stderr, "TOTAL: %d bytes data, %d bytes overhead, %.2lf%% overhead\n", total,
(int)ftell(nut->mopts.output.priv) - total, (double)(ftell(nut->mopts.output.priv) - total) / total*100);
Modified: trunk/libnut/nut.h
==============================================================================
--- trunk/libnut/nut.h (original)
+++ trunk/libnut/nut.h Sat Mar 11 13:10:33 2006
@@ -161,11 +161,10 @@
len is the amount of bytes that are LEFT, not the ones read. */
int nut_skip_packet(nut_context_t * nut, int * len);
-/** Read headers, must be called ONLY after read_next_packet
-gave e_headers.
+/** Read headers, must be called at begginning
@brief "s" is malloced and needs to be free'd.
*/
-int nut_read_headers(nut_context_t * nut, nut_packet_t * pd, nut_stream_header_t * s []);
+int nut_read_headers(nut_context_t * nut, nut_stream_header_t * s []);
/** Just reads the frame DATA. all it's header has already been
read by nut_read_next_packet. buf must be allocated and big enough.
Modified: trunk/libnut/priv.h
==============================================================================
--- trunk/libnut/priv.h (original)
+++ trunk/libnut/priv.h Sat Mar 11 13:10:33 2006
@@ -118,6 +118,7 @@
input_buffer_t * i;
output_buffer_t * o;
output_buffer_t * tmp_buffer;
+ output_buffer_t * tmp_buffer2;
int stream_count;
stream_context_t * sc;
Modified: trunk/nututils/demux_nut.c
==============================================================================
--- trunk/nututils/demux_nut.c (original)
+++ trunk/nututils/demux_nut.c Sat Mar 11 13:10:33 2006
@@ -23,12 +23,7 @@
static int read_headers(void * priv, nut_stream_header_t ** nut_streams) {
nutmerge_nut_t * nut = priv;
- nut_packet_t tmp;
- int err;
- if ((err = nut_read_next_packet(nut->nut, &tmp))) goto err_out;
- if (tmp.type != e_headers) return 2;
- err = nut_read_headers(nut->nut, &tmp, nut_streams);
-err_out:
+ int err = nut_read_headers(nut->nut, nut_streams);
return err == 1 ? -1 : ABS(err);
}
1
0
Author: ods15
Date: Sat Mar 11 11:05:42 2006
New Revision: 90
Log:
cosmetic, move around functions
sync to spec, max_distance not higher than 65536
Modified:
trunk/libnut/muxer.c
Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 11:05:42 2006
@@ -105,150 +105,6 @@
static void put_vb(output_buffer_t * bc, int len, uint8_t * data) {
put_v(bc, len);
put_data(bc, len, data);
-}
-
-static void put_syncpoint(nut_context_t * nut, output_buffer_t * bc) {
- int i;
- uint64_t pts = 0;
- int stream = 0;
- int back_ptr = 0;
- int keys[nut->stream_count];
- syncpoint_list_t * s = &nut->syncpoints;
-
- nut->last_syncpoint = bctello(nut->o);
-
- for (i = 0; i < nut->stream_count; i++) {
- if (nut->sc[i].last_dts > 0 && compare_ts(nut, nut->sc[i].last_dts, i, pts, stream) > 0) {
- pts = nut->sc[i].last_dts;
- stream = i;
- }
- }
-
- if (s->alloc_len <= s->len) {
- s->alloc_len += PREALLOC_SIZE;
- s->s = realloc(s->s, s->alloc_len * sizeof(syncpoint_t));
- s->pts = realloc(s->pts, s->alloc_len * nut->stream_count * sizeof(uint64_t));
- s->eor = realloc(s->eor, s->alloc_len * nut->stream_count * sizeof(uint64_t));
- }
-
- for (i = 0; i < nut->stream_count; i++) {
- s->pts[s->len * nut->stream_count + i] = nut->sc[i].last_key;
- s->eor[s->len * nut->stream_count + i] = nut->sc[i].eor > 0 ? nut->sc[i].eor : 0;
- }
- s->s[s->len].pos = nut->last_syncpoint;
- s->len++;
-
- for (i = 0; i < nut->stream_count; i++) keys[i] = !!nut->sc[i].eor;
- for (i = s->len; --i; ) {
- int j;
- int n = 1;
- for (j = 0; j < nut->stream_count; j++) {
- if (keys[j]) continue;
- if (!s->pts[i * nut->stream_count + j]) continue;
- if (compare_ts(nut, s->pts[i * nut->stream_count + j] - 1, j, pts, stream) <= 0) keys[j] = 1;
- }
- for (j = 0; j < nut->stream_count; j++) n &= keys[j];
- if (n) { i--; break; }
- }
- back_ptr = (nut->last_syncpoint - s->s[i].pos) / 8;
-
- for (i = 0; i < nut->stream_count; i++) {
- nut->sc[i].last_pts = convert_ts(nut, pts, stream, i);
- nut->sc[i].last_key = 0;
- if (nut->sc[i].eor) nut->sc[i].eor = -1; // so we know to ignore this stream in future syncpoints
- }
-
- put_bytes(bc, 8, SYNCPOINT_STARTCODE);
- put_v(bc, pts * nut->stream_count + stream);
- put_v(bc, back_ptr);
-
- nut->sync_overhead += bctello(bc) + 4/*checksum*/;
-}
-
-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;
- 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);
- for (i = 0; i < 256; i++) {
- int len = 1;
- if (nut->ft[i].flags & INVALID_FLAG) 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; }
- }
- assert(ftnum != -1);
- if (rftnum) *rftnum = ftnum;
- return size;
-}
-
-static int put_frame_header(nut_context_t * nut, output_buffer_t * bc, const nut_packet_t * fd) {
- stream_context_t * sc = &nut->sc[fd->stream];
- int ftnum = -1, coded_pts, pts_delta = fd->pts - sc->last_pts;
- int size;
-
- 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);
-
- size = frame_header(nut, fd, &ftnum);
-
- put_bytes(bc, 1, ftnum); // frame_code
-
- if (!nut->ft[ftnum].stream_plus1) put_v(bc, fd->stream);
- if (!nut->ft[ftnum].pts_delta) put_v(bc, coded_pts);
- if (nut->ft[ftnum].flags & MSB_CODED_FLAG)
- put_v(bc, (fd->len - nut->ft[ftnum].lsb) / nut->ft[ftnum].mul);
- if (nut->ft[ftnum].flags & STREAM_CODED_FLAG)
- put_v(bc, (fd->flags & 3) ^ nut->ft[ftnum].stream_flags);
-
- return size;
-}
-
-static void put_frame(nut_context_t * nut, const nut_packet_t * fd, const uint8_t * data, int write_syncpoint) {
- output_buffer_t * tmp = clear_buffer(nut->tmp_buffer);
- stream_context_t * sc = &nut->sc[fd->stream];
- int i;
-
- if (write_syncpoint) put_syncpoint(nut, tmp);
-
- sc->overhead += put_frame_header(nut, tmp, fd);
-
- put_data(nut->o, tmp->buf_ptr - tmp->buf, tmp->buf);
-
- if (write_syncpoint) put_bytes(nut->o, 4, crc32(tmp->buf + 8, tmp->buf_ptr - tmp->buf - 8)); // not including startcode
-
- sc->total_frames++;
- sc->tot_size += fd->len;
-
- for (i = 0; i < nut->stream_count; i++) {
- if (nut->sc[i].last_dts == -1) continue;
- if (compare_ts(nut, fd->pts, fd->stream, nut->sc[i].last_dts, i) < 0)
- fprintf(stderr, "%lld %d (%f) %lld %d (%f) \n",
- fd->pts, fd->stream, TO_DOUBLE(fd->stream, fd->pts),
- nut->sc[i].last_dts, i, TO_DOUBLE(i, nut->sc[i].last_dts));
- 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);
}
static void put_header(output_buffer_t * bc, output_buffer_t * tmp, uint64_t startcode, int index_ptr) {
@@ -393,6 +249,64 @@
put_main_header(nut);
for (i = 0; i < nut->stream_count; i++) put_stream_header(nut, i);
for (i = 0; i < nut->info_count; i++) put_info(nut, &nut->info[i]);
+}
+
+static void put_syncpoint(nut_context_t * nut, output_buffer_t * bc) {
+ int i;
+ uint64_t pts = 0;
+ int stream = 0;
+ int back_ptr = 0;
+ int keys[nut->stream_count];
+ syncpoint_list_t * s = &nut->syncpoints;
+
+ nut->last_syncpoint = bctello(nut->o);
+
+ for (i = 0; i < nut->stream_count; i++) {
+ if (nut->sc[i].last_dts > 0 && compare_ts(nut, nut->sc[i].last_dts, i, pts, stream) > 0) {
+ pts = nut->sc[i].last_dts;
+ stream = i;
+ }
+ }
+
+ if (s->alloc_len <= s->len) {
+ s->alloc_len += PREALLOC_SIZE;
+ s->s = realloc(s->s, s->alloc_len * sizeof(syncpoint_t));
+ s->pts = realloc(s->pts, s->alloc_len * nut->stream_count * sizeof(uint64_t));
+ s->eor = realloc(s->eor, s->alloc_len * nut->stream_count * sizeof(uint64_t));
+ }
+
+ for (i = 0; i < nut->stream_count; i++) {
+ s->pts[s->len * nut->stream_count + i] = nut->sc[i].last_key;
+ s->eor[s->len * nut->stream_count + i] = nut->sc[i].eor > 0 ? nut->sc[i].eor : 0;
+ }
+ s->s[s->len].pos = nut->last_syncpoint;
+ s->len++;
+
+ for (i = 0; i < nut->stream_count; i++) keys[i] = !!nut->sc[i].eor;
+ for (i = s->len; --i; ) {
+ int j;
+ int n = 1;
+ for (j = 0; j < nut->stream_count; j++) {
+ if (keys[j]) continue;
+ if (!s->pts[i * nut->stream_count + j]) continue;
+ if (compare_ts(nut, s->pts[i * nut->stream_count + j] - 1, j, pts, stream) <= 0) keys[j] = 1;
+ }
+ for (j = 0; j < nut->stream_count; j++) n &= keys[j];
+ if (n) { i--; break; }
+ }
+ back_ptr = (nut->last_syncpoint - s->s[i].pos) / 8;
+
+ for (i = 0; i < nut->stream_count; i++) {
+ nut->sc[i].last_pts = convert_ts(nut, pts, stream, i);
+ nut->sc[i].last_key = 0;
+ if (nut->sc[i].eor) nut->sc[i].eor = -1; // so we know to ignore this stream in future syncpoints
+ }
+
+ put_bytes(bc, 8, SYNCPOINT_STARTCODE);
+ put_v(bc, pts * nut->stream_count + stream);
+ put_v(bc, back_ptr);
+
+ nut->sync_overhead += bctello(bc) + 4/*checksum*/;
}
static void put_index(nut_context_t * nut) {
@@ -462,6 +376,92 @@
put_header(nut->o, tmp, 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;
+ 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);
+ for (i = 0; i < 256; i++) {
+ int len = 1;
+ if (nut->ft[i].flags & INVALID_FLAG) 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; }
+ }
+ assert(ftnum != -1);
+ if (rftnum) *rftnum = ftnum;
+ return size;
+}
+
+static int put_frame_header(nut_context_t * nut, output_buffer_t * bc, const nut_packet_t * fd) {
+ stream_context_t * sc = &nut->sc[fd->stream];
+ int ftnum = -1, coded_pts, pts_delta = fd->pts - sc->last_pts;
+ int size;
+
+ 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);
+
+ size = frame_header(nut, fd, &ftnum);
+
+ put_bytes(bc, 1, ftnum); // frame_code
+
+ if (!nut->ft[ftnum].stream_plus1) put_v(bc, fd->stream);
+ if (!nut->ft[ftnum].pts_delta) put_v(bc, coded_pts);
+ if (nut->ft[ftnum].flags & MSB_CODED_FLAG)
+ put_v(bc, (fd->len - nut->ft[ftnum].lsb) / nut->ft[ftnum].mul);
+ if (nut->ft[ftnum].flags & STREAM_CODED_FLAG)
+ put_v(bc, (fd->flags & 3) ^ nut->ft[ftnum].stream_flags);
+
+ return size;
+}
+
+static void put_frame(nut_context_t * nut, const nut_packet_t * fd, const uint8_t * data, int write_syncpoint) {
+ output_buffer_t * tmp = clear_buffer(nut->tmp_buffer);
+ stream_context_t * sc = &nut->sc[fd->stream];
+ int i;
+
+ if (write_syncpoint) put_syncpoint(nut, tmp);
+
+ sc->overhead += put_frame_header(nut, tmp, fd);
+
+ put_data(nut->o, tmp->buf_ptr - tmp->buf, tmp->buf);
+
+ if (write_syncpoint) put_bytes(nut->o, 4, crc32(tmp->buf + 8, tmp->buf_ptr - tmp->buf - 8)); // not including startcode
+
+ sc->total_frames++;
+ sc->tot_size += fd->len;
+
+ for (i = 0; i < nut->stream_count; i++) {
+ if (nut->sc[i].last_dts == -1) continue;
+ if (compare_ts(nut, fd->pts, fd->stream, nut->sc[i].last_dts, i) < 0)
+ fprintf(stderr, "%lld %d (%f) %lld %d (%f) \n",
+ fd->pts, fd->stream, TO_DOUBLE(fd->stream, fd->pts),
+ nut->sc[i].last_dts, i, TO_DOUBLE(i, nut->sc[i].last_dts));
+ 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];
int write_syncpoint = 0;
@@ -498,6 +498,8 @@
nut->tmp_buffer = new_mem_buffer(); // general purpose buffer
nut->max_distance = mopts->max_distance;
nut->mopts = *mopts;
+
+ if (nut->max_distance > 65536) nut->max_distance = 65536;
{
int j, n;
1
0
Author: ods15
Date: Sat Mar 11 11:02:21 2006
New Revision: 89
Log:
sync to spec, max_distance not higher than 65536
Modified:
trunk/libnut/demuxer.c
Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c (original)
+++ trunk/libnut/demuxer.c Sat Mar 11 11:02:21 2006
@@ -219,6 +219,7 @@
ERROR(i != NUT_VERSION, -ERR_BAD_VERSION);
GET_V(tmp, nut->stream_count);
GET_V(tmp, nut->max_distance);
+ if (nut->max_distance > 65536) nut->max_distance = 65536;
for(i = 0; i < 256; ) {
int scrap;
1
0

11 Mar '06
Author: ods15
Date: Sat Mar 11 11:00:02 2006
New Revision: 88
Log:
sync to spec, remove info crud from demuxer
Modified:
trunk/libnut/demuxer.c
trunk/libnut/muxer.c
Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c (original)
+++ trunk/libnut/demuxer.c Sat Mar 11 11:00:02 2006
@@ -811,31 +811,6 @@
}
int nut_read_info(nut_context_t * nut, nut_info_packet_t * info []) {
-#if 0
- BufferContext *tmp = new_mem_buffer();
-
- for(;;){
- char * type;
- int id = info[0].id;
- put_v(tmp, id);
- if (!id) break;
- type = info_table[id].type;
- if (!type) {
- type = info[0].type.data;
- put_vb(tmp, info[0].type.len, info[0].type.data);
- }
- if (!info_table[id].name)
- put_vb(tmp, info[0].name.len, info[0].name.data);
- if (!strcmp(type, "v"))
- put_v(tmp, info[0].val.i);
- else
- put_vb(tmp, info[0].val.s.len, info[0].val.s.data);
- id++;
- }
-
- put_header(nut->i, tmp, INFO_STARTCODE, 1);
- free_buffer(tmp);
-#endif
return 0;
}
Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 11:00:02 2006
@@ -354,10 +354,8 @@
put_v(tmp, info->stream_id_plus1);
put_v(tmp, info->chapter_id);
- if (info->chapter_id) {
- put_v(tmp, info->chapter_start);
- put_v(tmp, info->chapter_len);
- }
+ put_v(tmp, info->chapter_start);
+ put_v(tmp, info->chapter_len);
put_v(tmp, info->count);
for(i = 0; i < info->count; i++){
@@ -368,8 +366,11 @@
} else if (!strcmp(field->type, "s")) {
put_s(tmp, -3);
put_s(tmp, field->val);
+ } else if (!strcmp(field->type, "t")) {
+ put_s(tmp, -4);
+ put_v(tmp, field->val);
} else if (!strcmp(field->type, "r")) {
- put_s(tmp, -(field->den + 3));
+ put_s(tmp, -(field->den + 4));
put_s(tmp, field->val);
} else {
if (strcmp(field->type, "UTF-8")) {
1
0
Author: ods15
Date: Sat Mar 11 10:54:27 2006
New Revision: 87
Log:
main header frame code generation on the fly...
Modified:
trunk/libnut/muxer.c
Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 10:54:27 2006
@@ -270,43 +270,48 @@
static void put_main_header(nut_context_t * nut) {
output_buffer_t * tmp = clear_buffer(nut->tmp_buffer);
- int i, j, n;
+ int i;
int flag, fields, sflag, timestamp = 0, mul = 1, stream = 0, size, count;
put_v(tmp, NUT_VERSION);
put_v(tmp, nut->stream_count);
put_v(tmp, nut->max_distance);
- for(n=i=0; i < 256; n++) {
- assert(nut->mopts.fti[n].tmp_flag != -1);
- put_v(tmp, flag = nut->mopts.fti[n].tmp_flag);
- put_v(tmp, fields = nut->mopts.fti[n].tmp_fields);
- if (fields > 0) put_v(tmp, sflag = nut->mopts.fti[n].tmp_sflag);
- else sflag = 0;
- if (fields > 1) put_s(tmp, timestamp = nut->mopts.fti[n].tmp_pts);
- if (fields > 2) put_v(tmp, mul = nut->mopts.fti[n].tmp_mul);
- if (fields > 3) put_v(tmp, stream = nut->mopts.fti[n].tmp_stream);
- if (fields > 4) put_v(tmp, size = nut->mopts.fti[n].tmp_size);
- else size = 0;
+ 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;
+ timestamp = nut->ft[i].pts_delta;
+ if (nut->ft[i].mul != mul) fields = 3;
+ mul = nut->ft[i].mul;
+ if (nut->ft[i].stream_plus1 != stream) fields = 4;
+ stream = nut->ft[i].stream_plus1;
+ if (nut->ft[i].lsb != 0) fields = 5;
+ 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;
+
+ 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 = nut->mopts.fti[n].count);
- else count = mul - size;
-
- for(j = 0; j < count && i < 256; j++, i++) {
- if (i == 'N') {
- nut->ft[i].flags = INVALID_FLAG;
- j--;
- 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;
- nut->ft[i].pts_delta = timestamp;
- }
- }
-
- assert(nut->mopts.fti[n].tmp_flag == -1);
+ if (fields > 6) put_v(tmp, count);
+ }
+
put_header(nut->o, tmp, MAIN_STARTCODE, 0);
}
@@ -493,9 +498,40 @@
nut->max_distance = mopts->max_distance;
nut->mopts = *mopts;
- for (i = 0; mopts->fti[i].tmp_flag != -1; i++);
- nut->mopts.fti = malloc(++i * sizeof(frame_table_input_t));
- memcpy(nut->mopts.fti, mopts->fti, i * sizeof(frame_table_input_t));
+ {
+ int j, n;
+ int flag, fields, sflag, 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;
+ else size = 0;
+ if (fields > 6) count = mopts->fti[n].count;
+ else count = mul - size;
+
+ for(j = 0; j < count && i < 256; j++, i++) {
+ if (i == 'N') {
+ nut->ft[i].flags = INVALID_FLAG;
+ j--;
+ 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;
+ nut->ft[i].pts_delta = timestamp;
+ }
+ }
+ assert(mopts->fti[n].tmp_flag == -1);
+ }
nut->sync_overhead = 0;
@@ -610,7 +646,6 @@
free(nut->syncpoints.s);
free(nut->syncpoints.pts);
free(nut->syncpoints.eor);
- free(nut->mopts.fti);
free_buffer(nut->tmp_buffer);
free_buffer(nut->o); // flushes file
1
0

[NUT] (ods15): r86 - in /trunk: libnut/demuxer.c libnut/muxer.c libnut/nut.h libnut/priv.h libnut/reorder.c nututils/demux_avi.c nututils/demux_ogg.c nututils/nutmerge.c
by syncmail@mplayerhq.hu 11 Mar '06
by syncmail@mplayerhq.hu 11 Mar '06
11 Mar '06
Author: ods15
Date: Sat Mar 11 10:31:41 2006
New Revision: 86
Log:
decode_delay, framecode table and max_distance are configurable via libnut
api.
some cleanup
Modified:
trunk/libnut/demuxer.c
trunk/libnut/muxer.c
trunk/libnut/nut.h
trunk/libnut/priv.h
trunk/libnut/reorder.c
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 10:31:41 2006
@@ -278,7 +278,7 @@
GET_V(tmp, sc->sh.timebase.den);
GET_V(tmp, sc->msb_pts_shift);
GET_V(tmp, sc->max_pts_distance);
- GET_V(tmp, sc->decode_delay);
+ GET_V(tmp, sc->sh.decode_delay);
CHECK(get_bytes(tmp, 1, &a));
sc->sh.fixed_fps = a & 1;
CHECK(get_vb(tmp, &sc->sh.codec_specific_len, &sc->sh.codec_specific));
@@ -469,7 +469,7 @@
int i;
for (i = 0; i < nut->stream_count; i++) {
int j;
- for (j = 0; j < nut->sc[i].decode_delay; j++) nut->sc[i].pts_cache[j] = -1;
+ for (j = 0; j < nut->sc[i].sh.decode_delay; j++) nut->sc[i].pts_cache[j] = -1;
nut->sc[i].last_dts = -1;
}
}
@@ -577,7 +577,7 @@
static void push_frame(nut_context_t * nut, nut_packet_t * pd) {
stream_context_t * sc = &nut->sc[pd->stream];
sc->last_pts = pd->pts;
- sc->last_dts = get_dts(sc->decode_delay, sc->pts_cache, 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;
else sc->eor = 0;
@@ -728,13 +728,12 @@
if (tmp != STREAM_STARTCODE) return -ERR_NOSTREAM_STARTCODE;
CHECK(get_stream_header(nut, i));
if (!nut->sc[i].pts_cache) {
- nut->sc[i].pts_cache = malloc(nut->sc[i].decode_delay * sizeof(int64_t));
- for (j = 0; j < nut->sc[i].decode_delay; j++)
+ nut->sc[i].pts_cache = malloc(nut->sc[i].sh.decode_delay * sizeof(int64_t));
+ for (j = 0; j < nut->sc[i].sh.decode_delay; j++)
nut->sc[i].pts_cache[j] = -1;
}
}
if (nut->dopts.read_index) {
- off_t pos = bctello(nut->i);
uint64_t tmp;
CHECK(get_bytes(nut->i, 8, &tmp));
if (tmp == INDEX_STARTCODE) nut->seek_status = 2;
@@ -1038,7 +1037,7 @@
stopper_syncpoint = buf_before;
for (i = 0; i < nut->stream_count; i++) {
if (!(pts[i] & 1)) {
- if ((good_key[i]>>1) > (stopper->back_ptr>>1)) n = 0;
+ if (good_key[i]>>1) n = 0;
else good_key[i] |= 1; // flag that we don't care about this stream
}
}
@@ -1265,7 +1264,6 @@
nut->syncpoints.pts = NULL;
nut->syncpoints.eor = NULL;
- nut->fti = NULL;
nut->sc = NULL;
nut->last_headers = 0;
nut->stream_count = 0;
Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 10:31:41 2006
@@ -3,32 +3,6 @@
#include <stdio.h>
#include "nut.h"
#include "priv.h"
-
-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
-};
static int stream_write(void * priv, size_t len, const uint8_t * buf) {
return fwrite(buf, 1, len, priv);
@@ -273,7 +247,7 @@
put_data(nut->o, fd->len, data);
sc->last_pts = fd->pts;
- sc->last_dts = get_dts(sc->decode_delay, sc->pts_cache, 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);
}
@@ -303,18 +277,18 @@
put_v(tmp, nut->stream_count);
put_v(tmp, nut->max_distance);
for(n=i=0; i < 256; n++) {
- assert(nut->fti[n].tmp_flag != -1);
- put_v(tmp, flag = nut->fti[n].tmp_flag);
- put_v(tmp, fields = nut->fti[n].tmp_fields);
- if (fields > 0) put_v(tmp, sflag = nut->fti[n].tmp_sflag);
+ assert(nut->mopts.fti[n].tmp_flag != -1);
+ put_v(tmp, flag = nut->mopts.fti[n].tmp_flag);
+ put_v(tmp, fields = nut->mopts.fti[n].tmp_fields);
+ if (fields > 0) put_v(tmp, sflag = nut->mopts.fti[n].tmp_sflag);
else sflag = 0;
- if (fields > 1) put_s(tmp, timestamp = nut->fti[n].tmp_pts);
- if (fields > 2) put_v(tmp, mul = nut->fti[n].tmp_mul);
- if (fields > 3) put_v(tmp, stream = nut->fti[n].tmp_stream);
- if (fields > 4) put_v(tmp, size = nut->fti[n].tmp_size);
+ if (fields > 1) put_s(tmp, timestamp = nut->mopts.fti[n].tmp_pts);
+ if (fields > 2) put_v(tmp, mul = nut->mopts.fti[n].tmp_mul);
+ if (fields > 3) put_v(tmp, stream = nut->mopts.fti[n].tmp_stream);
+ if (fields > 4) put_v(tmp, size = nut->mopts.fti[n].tmp_size);
else size = 0;
if (fields > 5) put_v(tmp, 0); // reserved
- if (fields > 6) put_v(tmp, count = nut->fti[n].count);
+ if (fields > 6) put_v(tmp, count = nut->mopts.fti[n].count);
else count = mul - size;
for(j = 0; j < count && i < 256; j++, i++) {
@@ -332,7 +306,7 @@
}
}
- assert(nut->fti[n].tmp_flag == -1);
+ assert(nut->mopts.fti[n].tmp_flag == -1);
put_header(nut->o, tmp, MAIN_STARTCODE, 0);
}
@@ -347,7 +321,7 @@
put_v(tmp, sc->sh.timebase.den);
put_v(tmp, sc->msb_pts_shift);
put_v(tmp, sc->max_pts_distance);
- put_v(tmp, sc->decode_delay);
+ put_v(tmp, sc->sh.decode_delay);
put_bytes(tmp, 1, sc->sh.fixed_fps ? 1 : 0);
put_vb(tmp, sc->sh.codec_specific_len, sc->sh.codec_specific);
@@ -516,9 +490,12 @@
nut->o = new_output_buffer(mopts->output);
nut->tmp_buffer = new_mem_buffer(); // general purpose buffer
- nut->max_distance = 32768; // TODO
- nut->fti = ft_default; // TODO
+ nut->max_distance = mopts->max_distance;
nut->mopts = *mopts;
+
+ for (i = 0; mopts->fti[i].tmp_flag != -1; i++);
+ nut->mopts.fti = malloc(++i * sizeof(frame_table_input_t));
+ memcpy(nut->mopts.fti, mopts->fti, i * sizeof(frame_table_input_t));
nut->sync_overhead = 0;
@@ -540,7 +517,6 @@
nut->sc[i].last_dts = -1;
nut->sc[i].msb_pts_shift = 7; // TODO
nut->sc[i].max_pts_distance = (s[i].timebase.den + s[i].timebase.nom - 1) / s[i].timebase.nom; // TODO
- nut->sc[i].decode_delay = !i; // ### TODO
nut->sc[i].eor = 0;
nut->sc[i].sh = s[i];
nut->sc[i].sh.max_pts = 0;
@@ -551,11 +527,11 @@
nut->sc[i].sh.codec_specific = malloc(s[i].codec_specific_len);
memcpy(nut->sc[i].sh.codec_specific, s[i].codec_specific, s[i].codec_specific_len);
- nut->sc[i].pts_cache = malloc(nut->sc[i].decode_delay * sizeof(int64_t));
+ nut->sc[i].pts_cache = malloc(nut->sc[i].sh.decode_delay * sizeof(int64_t));
// reorder.c
- nut->sc[i].reorder_pts_cache = malloc(nut->sc[i].decode_delay * sizeof(int64_t));
- for (j = 0; j < nut->sc[i].decode_delay; j++) nut->sc[i].reorder_pts_cache[j] = nut->sc[i].pts_cache[j] = -1;
+ nut->sc[i].reorder_pts_cache = malloc(nut->sc[i].sh.decode_delay * sizeof(int64_t));
+ for (j = 0; j < nut->sc[i].sh.decode_delay; j++) nut->sc[i].reorder_pts_cache[j] = nut->sc[i].pts_cache[j] = -1;
nut->sc[i].next_pts = 0;
nut->sc[i].packets = NULL;
nut->sc[i].num_packets = 0;
@@ -634,6 +610,7 @@
free(nut->syncpoints.s);
free(nut->syncpoints.pts);
free(nut->syncpoints.eor);
+ free(nut->mopts.fti);
free_buffer(nut->tmp_buffer);
free_buffer(nut->o); // flushes file
Modified: trunk/libnut/nut.h
==============================================================================
--- trunk/libnut/nut.h (original)
+++ trunk/libnut/nut.h Sat Mar 11 10:31:41 2006
@@ -33,6 +33,7 @@
uint8_t * fourcc;
nut_timebase_t timebase;
int fixed_fps;
+ int decode_delay;
int codec_specific_len;
uint8_t * codec_specific;
// video
@@ -50,8 +51,21 @@
} nut_stream_header_t;
typedef struct {
+ int tmp_flag; // 1 => use msb, 2 => coded sflags, 4 => invalid, -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)
+} frame_table_input_t;
+
+typedef struct {
nut_output_stream_t output;
int write_index;
+ int max_distance;
+ frame_table_input_t * fti;
} nut_muxer_opts_t;
typedef struct {
Modified: trunk/libnut/priv.h
==============================================================================
--- trunk/libnut/priv.h (original)
+++ trunk/libnut/priv.h Sat Mar 11 10:31:41 2006
@@ -98,7 +98,6 @@
int64_t last_dts;
int msb_pts_shift;
int max_pts_distance;
- int decode_delay;
nut_stream_header_t sh;
int64_t * pts_cache;
int64_t eor;
@@ -112,17 +111,6 @@
int tot_size;
int total_frames;
} stream_context_t;
-
-typedef struct {
- int tmp_flag; // 1 => use msb, 2 => coded sflags, 4 => invalid
- 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)
-} frame_table_input_t;
struct nut_context_s {
nut_muxer_opts_t mopts;
@@ -138,7 +126,6 @@
nut_info_packet_t * info;
int max_distance;
- frame_table_input_t * fti;
frame_table_t ft[256];
off_t last_syncpoint; // for checking corruption and putting syncpoints, also for back_ptr
Modified: trunk/libnut/reorder.c
==============================================================================
--- trunk/libnut/reorder.c (original)
+++ trunk/libnut/reorder.c Sat Mar 11 10:31:41 2006
@@ -80,7 +80,7 @@
s->num_packets++;
s->packets = realloc(s->packets, s->num_packets * sizeof(reorder_packet_t));
s->packets[s->num_packets - 1].p = *p;
- s->packets[s->num_packets - 1].dts = get_dts(s->decode_delay, s->reorder_pts_cache, p->pts);
+ s->packets[s->num_packets - 1].dts = get_dts(s->sh.decode_delay, s->reorder_pts_cache, p->pts);
s->packets[s->num_packets - 1].buf = malloc(p->len); // FIXME
memcpy(s->packets[s->num_packets - 1].buf, buf, p->len);
Modified: trunk/nututils/demux_avi.c
==============================================================================
--- trunk/nututils/demux_avi.c (original)
+++ trunk/nututils/demux_avi.c Sat Mar 11 10:31:41 2006
@@ -362,6 +362,7 @@
s[i].timebase.den = avi->stream[i].strh->dwRate;
s[i].timebase.nom = avi->stream[i].strh->dwScale;
s[i].fixed_fps = 1;
+ s[i].decode_delay = !i; // FIXME
s[i].codec_specific_len = avi->stream[i].extra_len;
s[i].codec_specific = avi->stream[i].extra;
if (avi->stream[i].type == 0) { // video
Modified: trunk/nututils/demux_ogg.c
==============================================================================
--- trunk/nututils/demux_ogg.c (original)
+++ trunk/nututils/demux_ogg.c Sat Mar 11 10:31:41 2006
@@ -40,6 +40,7 @@
int time_base_denom;
int time_base_nom;
int fixed_fps;
+ int decode_delay;
int codec_specific_len;
uint8_t * codec_specific;
int width;
@@ -262,6 +263,7 @@
os->time_base_denom = sample_rate / gcd(sample_rate, i);
os->time_base_nom = i / gcd(sample_rate, i);
os->fixed_fps = 0;
+ os->decode_delay = 0;
os->codec_specific_len = 0;
os->codec_specific = NULL;
os->samplerate_nom = sample_rate;
@@ -530,6 +532,7 @@
s[i].timebase.den = os->time_base_denom;
s[i].timebase.nom = os->time_base_nom;
s[i].fixed_fps = os->fixed_fps;
+ s[i].decode_delay = os->decode_delay;
s[i].codec_specific = os->codec_specific;
s[i].codec_specific_len = os->codec_specific_len;
switch (os->oc->type) {
Modified: trunk/nututils/nutmerge.c
==============================================================================
--- trunk/nututils/nutmerge.c (original)
+++ trunk/nututils/nutmerge.c Sat Mar 11 10:31:41 2006
@@ -13,6 +13,32 @@
&nut_demuxer,
&ogg_demuxer,
NULL
+};
+
+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
};
int main(int argc, char * argv []) {
@@ -56,6 +82,8 @@
if ((err = demuxer->read_headers(demuxer_priv, &nut_stream))) goto err_out;
mopts.output = (nut_output_stream_t){ .priv = out, .write = NULL };
mopts.write_index = 1;
+ mopts.fti = ft_default;
+ mopts.max_distance = 32768;
nut = nut_muxer_init(&mopts, nut_stream, NULL);
for (i = 0; nut_stream[i].type >= 0; i++);
1
0