{
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()
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)
{
++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;
}
} // 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.
}
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
{
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()
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