From c9c21ffd13ebe85234b81ecd5e5ee80d17350b60 Mon Sep 17 00:00:00 2001 From: Mark Calderbank Date: Tue, 30 Aug 2005 20:40:36 +0000 Subject: [PATCH] Demuxer: Don't output partial frames --- demuxer.cc | 109 +++++++++++++---------------------------------------- 1 file changed, 26 insertions(+), 83 deletions(-) diff --git a/demuxer.cc b/demuxer.cc index cf36905..16fb793 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -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 bytes_remaining; switch(state_framepos) { @@ -246,15 +246,6 @@ int Demuxer::parse_video_frame(int len, int* full) local_frame[5] = *inbuf; ++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; -// } } // We are in the frame data bytes_remaining = 2 + frame_length - state_framepos; @@ -276,68 +267,26 @@ int Demuxer::parse_video_frame(int len, int* full) } } // No fall through here -/* if (state_vid_parsed) - { - // We have already parsed the whole frame - if (seeking) // Still not found a sync point. Throw this frame away. - { - if (len >= bytes_remaining) - { - inbuf += bytes_remaining; - ret += bytes_remaining; - state_frametype = state_framepos = 0; - return ret; - } - else - { - inbuf += len; ret += len; return ret; - } - } // No fall through is allowed here - // Send frame header to stream - if (state_stream_fill < 6) - { - state_stream_fill += videostream.put(local_frame, - 6 - state_stream_fill); - if (state_stream_fill < 6) // stream is full! - { - *full = 1; return ret; - } - } - // Send all frame data we have to stream - if (len >= bytes_remaining) len = bytes_remaining; - stream_sent = videostream.put(inbuf, len); - inbuf += stream_sent; ret += stream_sent; - state_framepos += stream_sent; - state_stream_fill += stream_sent; - if (stream_sent != len) // stream is full! - { - *full = 1; return ret; - } - if (state_framepos == frame_length + 2) // frame done - { - state_frametype = state_framepos = 0; - } - 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 { - if (len >= bytes_remaining) len = bytes_remaining; + if (len > bytes_remaining) len = bytes_remaining; memcpy(local_frame + state_framepos + 4, inbuf, len); inbuf += len; ret += len; state_framepos += len; if (len < bytes_remaining) // Not all arrived yet return ret; parse_video_details(local_frame+6, frame_length); - if (seeking) // Still not found a sync point. Ignore this frame. - return ret; } - // We have the whole frame in local_frame. Send it to the stream. - state_stream_fill += videostream.put(local_frame, - 6 + frame_length - state_stream_fill); - if (state_stream_fill < frame_length + 6) // stream is full! + + if (!seeking) { - *full = 1; return ret; + // We have the whole frame in local_frame. Send it to the stream. + // We still support streams that might not consume all the data. + state_stream_fill += videostream.put(local_frame, + 6 + frame_length - state_stream_fill); + if (state_stream_fill < frame_length + 6) // stream is full! + { + *full = 1; return ret; + } } state_frametype = state_framepos = 0; return ret; @@ -346,7 +295,7 @@ int Demuxer::parse_video_frame(int len, int* full) int Demuxer::parse_audio_frame(int len, int* full) { int ret = 0; // return number of bytes consumed - int stream_sent, bytes_remaining; + int bytes_remaining; switch(state_framepos) { @@ -389,30 +338,24 @@ int Demuxer::parse_audio_frame(int len, int* full) } } // No fall through is allowed here - // Send frame header to stream - if (state_stream_fill < 6) + if (bytes_remaining) // There is data yet to copy to local_frame { - state_stream_fill += audiostream.put(local_frame, - 6 - state_stream_fill); - if (state_stream_fill < 6) // stream is full! - { - *full = 1; return ret; - } + if (len > bytes_remaining) len = bytes_remaining; + memcpy(local_frame + state_framepos + 4, inbuf, len); + inbuf += len; ret += len; state_framepos += len; + if (len < bytes_remaining) // Not all arrived yet + return ret; } - // Send all frame data we have to stream - if (len >= bytes_remaining) len = bytes_remaining; - stream_sent = audiostream.put(inbuf, len); - inbuf += stream_sent; ret += stream_sent; - state_framepos += stream_sent; - state_stream_fill += stream_sent; - if (stream_sent != len) // stream is full! + + // We have the whole frame in local_frame. Send it to the stream. + // We still support streams that might not consume all the data. + state_stream_fill += audiostream.put(local_frame, + 6 + frame_length - state_stream_fill); + if (state_stream_fill < frame_length + 6) // stream is full! { *full = 1; return ret; } - if (state_framepos == frame_length + 2) // frame done - { - state_frametype = state_framepos = 0; - } + state_frametype = state_framepos = 0; return ret; } -- 2.39.5