The page writes: "if we're in the middle of decoding a video frame and the buffer doesn't have any more bytes yet (e.g. because it's streaming from the net) we would need to pause the decoder, save its exact state and later, when enough bytes are available, resume it again. Of course this isn't particularly difficult to achieve using threads, but if we want to stay single threaded it gets very hairy."
But I'm pretty sure the MPEG people would just say, "look, this is not that hard and was a solved problem 20 years ago. We're not going to introduce a 1-frame delay at the encoder (which is what you want us to do by putting a frame length in the PES header) but we're also not making you introduce a 1-frame delay at the decoder. Just do what libmpeg2 has been doing since 1999: make a state object that represents the byte-by-byte evolving state of the decoder. Update the state object as you go. If you run out of bytes in the buffer, return STATE_BUFFER to the caller. When the caller gives you more bytes later, use the state object to resume from where you left off."
"Here's what that object looks like for MPEG-2: https://github.com/cisco-open-source/libmpeg2/blob/master/li...
Yes, it's not beautiful, and yes, it would be more elegant if these variables were broken out into different scopes (current block, current slice, current picture, current sequence), but this is basically what you're in for and it's not that hard. And it avoids a 1-frame delay at either end. (And no, you don't need a 1-frame delay just because you're demuxing from a transport stream either -- just throw each TS packet into the video ES decoder as soon as you get it.)"