[NUT-devel] [nut]: r237 - trunk/libnut/demuxer.c
ods15
subversion at mplayerhq.hu
Sat Nov 18 15:38:19 CET 2006
Author: ods15
Date: Sat Nov 18 15:38:19 2006
New Revision: 237
Modified:
trunk/libnut/demuxer.c
Log:
make the search for main header in 4kb chunks instead of 0.5mb chunks to
save memory, while still keeping same effectiveness...
Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c (original)
+++ trunk/libnut/demuxer.c Sat Nov 18 15:38:19 2006
@@ -714,17 +714,15 @@
static int find_main_headers(nut_context_t * nut) {
int err = 0;
uint64_t tmp;
- int read_data = 512*1024;
+ int len = PREALLOC_SIZE;
+ int read_data = ready_read_buf(nut->i, len);
// don't waste cpu by running this check every damn time for EAGAIN
- // Except for the first time, to not waste memory
- if (!nut->seek_status && ready_read_buf(nut->i, read_data) < read_data && buf_eof(nut->i) == NUT_ERR_EAGAIN)
- return NUT_ERR_EAGAIN;
-
- CHECK(get_bytes(nut->i, 7, &tmp));
- read_data -= 7;
- while (read_data--) {
- ERROR(ready_read_buf(nut->i, 30) < 1, buf_eof(nut->i));
+ if (read_data < len && buf_eof(nut->i) != NUT_ERR_EOF) return buf_eof(nut->i);
+
+ CHECK(get_bytes(nut->i, 7, &tmp)); // true EOF will fail here
+ len = (read_data -= 7);
+ while (len--) {
tmp = (tmp << 8) | *(nut->i->buf_ptr++);
if (tmp == MAIN_STARTCODE) break;
// give up if we reach a syncpoint, unless we're searching the file end
@@ -743,6 +741,7 @@
ERROR(err, err); // if get_bytes returns EAGAIN or a memory error, check for that
} while (tmp != SYNCPOINT_STARTCODE);
if (tmp == SYNCPOINT_STARTCODE) { // success!
+ nut->before_seek = nut->seek_status = 0;
nut->last_headers = pos;
nut->i->buf_ptr = get_buf(nut->i, nut->last_headers);
flush_buf(nut->i);
@@ -751,6 +750,11 @@
}
// failure
+ if (len == -1 && (nut->before_seek += read_data) < 512*1024) {
+ nut->i->buf_ptr -= 7; // rewind 7 bytes, try again
+ flush_buf(nut->i);
+ return find_main_headers(nut);
+ } else nut->before_seek = 0;
if (!nut->i->isc.seek) return NUT_ERR_NO_HEADERS;
if (!nut->seek_status) {
nut->seek_status = 18; // start search at 512kb
More information about the NUT-devel
mailing list