[NUT-devel] r60 - trunk/libnut
ods15 at mplayerhq.hu
ods15 at mplayerhq.hu
Sat Feb 11 18:04:36 CET 2006
Author: ods15
Date: 2006-02-11 18:04:36 +0100 (Sat, 11 Feb 2006)
New Revision: 60
Modified:
trunk/libnut/demuxer.c
trunk/libnut/muxer.c
Log:
add syncpoint_checksum to muxer and demuxer, fix put_frame_header()
Modified: trunk/libnut/demuxer.c
===================================================================
--- trunk/libnut/demuxer.c 2006-02-11 16:25:50 UTC (rev 59)
+++ trunk/libnut/demuxer.c 2006-02-11 17:04:36 UTC (rev 60)
@@ -451,7 +451,7 @@
static int get_packet(nut_context_t * nut, nut_packet_t * pd, int * saw_syncpoint) {
int err = 0;
- int after_sync = 0;
+ off_t after_sync = 0;
uint64_t tmp;
int coded_pts, size_lsb = 0, stream_flags = 0, i;
@@ -484,9 +484,9 @@
nut->i->buf_ptr -= 8;
return get_packet(nut, pd, saw_syncpoint);
} else if (tmp == SYNCPOINT_STARTCODE) {
+ after_sync = bctello(nut->i);
CHECK(get_syncpoint(nut));
CHECK(get_bytes(nut->i, 1, &tmp));
- after_sync = 1;
} else {
nut->i->buf_ptr -= 7;
tmp = 'N';
@@ -523,6 +523,13 @@
for (i = 0; i < nut->ft[tmp].reserved; i++) { int scrap; GET_V(nut->i, scrap); }
+ if (after_sync) {
+ 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);
+ }
+
// error checking - max distance
ERROR(!after_sync && bctello(nut->i) + pd->len - nut->last_syncpoint > nut->max_distance, -ERR_MAX_DISTANCE);
// error checking - max pts distance
Modified: trunk/libnut/muxer.c
===================================================================
--- trunk/libnut/muxer.c 2006-02-11 16:25:50 UTC (rev 59)
+++ trunk/libnut/muxer.c 2006-02-11 17:04:36 UTC (rev 60)
@@ -135,7 +135,7 @@
put_data(bc, len, data);
}
-static void put_syncpoint(nut_context_t * nut, const nut_packet_t * fd) {
+static void put_syncpoint(nut_context_t * nut, output_buffer_t * bc) {
int i;
uint64_t pts = 0;
int stream = 0;
@@ -176,16 +176,16 @@
}
back_ptr = (nut->last_syncpoint - s->s[i].pos) / 8;
- put_bytes(nut->o, 8, SYNCPOINT_STARTCODE);
- put_v(nut->o, pts * nut->stream_count + stream);
- put_v(nut->o, back_ptr);
-
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;
}
- nut->sync_overhead += bctello(nut->o) - nut->last_syncpoint;
+ 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) {
@@ -219,36 +219,44 @@
return size;
}
-static void put_frame_header(nut_context_t * nut, output_buffer_t * bc, const nut_packet_t * fd) {
+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);
- frame_header(nut, fd, &ftnum);
+ size = frame_header(nut, fd, &ftnum);
put_bytes(bc, 1, ftnum); // frame_code
- if (!nut->ft[ftnum].stream_plus1) put_v(nut->o, fd->stream);
- if (!nut->ft[ftnum].pts_delta) put_v(nut->o, coded_pts);
+ 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(nut->o, (fd->len - nut->ft[ftnum].lsb) / nut->ft[ftnum].mul);
+ put_v(bc, (fd->len - nut->ft[ftnum].lsb) / nut->ft[ftnum].mul);
if (nut->ft[ftnum].flags & STREAM_CODED_FLAG)
- put_v(nut->o, (fd->flags & 3) ^ nut->ft[ftnum].stream_flags);
+ 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) {
- off_t start = bctello(nut->o);
+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;
- put_frame_header(nut, nut->o, fd);
+ 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->overhead += bctello(nut->o) - start;
sc->tot_size += fd->len;
for (i = 0; i < nut->stream_count; i++) {
@@ -450,6 +458,7 @@
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
@@ -465,9 +474,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) put_syncpoint(nut, fd);
+ bctello(nut->o) - nut->last_syncpoint + fd->len + frame_header(nut, fd, NULL) > nut->max_distance) write_syncpoint = 1;
- put_frame(nut, fd, buf);
+ put_frame(nut, fd, buf, write_syncpoint);
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;
More information about the NUT-devel
mailing list