From d6a2f1a7c3356ce063feda3f1f3436076469ec9b Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 28 Aug 2005 02:15:49 +0000 Subject: [PATCH] Corruption fixes --- demuxer.cc | 30 +++++++++++++++--------------- stream.cc | 9 +++++++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/demuxer.cc b/demuxer.cc index d360795..cf36905 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -46,19 +46,19 @@ int Demuxer::init() { if (!initted) { - if ( videostream.init(demuxMemory) || - audiostream.init(demuxMemory) || + if ( !videostream.init(demuxMemory) || + !audiostream.init(demuxMemory) || !(local_frame = (UCHAR *) malloc(0x10000))) { printf("failed to initialize demuxer\n"); shutdown(); - return 1; + return 0; } } reset(); initted = 1; - return 0; + return 1; } void Demuxer::reset() @@ -224,7 +224,7 @@ int Demuxer::parse_find_frame(int len) int Demuxer::parse_video_frame(int len, int* full) { int ret = 0; // return number of bytes consumed - int stream_sent, bytes_remaining; + int /*stream_sent,*/ bytes_remaining; switch(state_framepos) { @@ -247,14 +247,14 @@ int Demuxer::parse_video_frame(int len, int* full) ++inbuf; ++state_framepos; ++ret; --len; if (len == 0) return ret; // FALL THROUGH TO NEXT BYTE IN STREAM - case 2: // First data byte - if (len >= frame_length // If we have the entire frame - && !state_vid_parsed) // and haven't parsed it yet - { - if (video_current == state_frametype) // and we're interested - parse_video_details(inbuf, frame_length); // then parse it - state_vid_parsed = 1; - } +// case 2: // First data byte +// if (len >= frame_length // If we have the entire frame +// && !state_vid_parsed) // and haven't parsed it yet +// { +// if (video_current == state_frametype) // and we're interested +// parse_video_details(inbuf, frame_length); // then parse it +// state_vid_parsed = 1; +// } } // We are in the frame data bytes_remaining = 2 + frame_length - state_framepos; @@ -276,7 +276,7 @@ int Demuxer::parse_video_frame(int len, int* full) } } // No fall through here - if (state_vid_parsed) +/* if (state_vid_parsed) { // We have already parsed the whole frame if (seeking) // Still not found a sync point. Throw this frame away. @@ -319,7 +319,7 @@ int Demuxer::parse_video_frame(int len, int* full) } return ret; } // No fall through is allowed here - +*/ // We haven't parsed the frame yet. It's arriving in pieces. if (bytes_remaining) // There is data yet to copy to local_frame { diff --git a/stream.cc b/stream.cc index 5ff40cd..00665d8 100644 --- a/stream.cc +++ b/stream.cc @@ -41,11 +41,11 @@ void Stream::shutdown() int Stream::init(int bufsize) { outbuf = (UCHAR*) malloc(bufsize); - if (!outbuf) return 1; + if (!outbuf) return 0; bufferSize = bufsize; bufferHead = bufferTail = 0; initted = 1; - return 0; + return 1; } void Stream::flush() @@ -56,10 +56,15 @@ void Stream::flush() int Stream::put(UCHAR* inbuf, int len) { int ret = 0; + int freespace; int localTail = bufferTail; if (localTail == 0) localTail = bufferSize; if (len == 0) return ret; + freespace = localTail - bufferHead - 1; + if (freespace < 0) freespace += bufferSize; + if (len > freespace) return ret; + if (bufferHead >= localTail) { // We have free rein to the end of the buffer -- 2.39.5