wmcbrine / tivodecode-ng

The "next generation" of tivodecode, to handle transport streams. Not fully working yet.
Other
32 stars 10 forks source link

payloadOffset is larger than TS_FRAME_SIZE?! #4

Open a1291762 opened 7 years ago

a1291762 commented 7 years ago

Hi,

I've been using tivodecode 0.4.4 for a while now so that I can download TS files from my TiVo. TS is how they come OTA (I'm in Australia, if that's relevant) and having the TiVo convert them to PS does not always work (particularly for certain channels). I originally used ffmpeg to convert to PS (for better seeking) but these days I do a quick mpeg4 re-encode for faster seeking and better handling of the occasional invalid video chunk.

Anyway, I have a show I just recorded that crashes tivodecode. After looking at a stack trace, I made the below change to reject the packets that are bad. The end result is that I get all the video but audio stops about 10 minute in. The file plays just fine on the TiVo itself.

The things is, I'm not really sure about what's going on with the internals of tivodecode so I don't know if this really is a bad packet (ie. the TiVo has given me crap) or if there's just some kind of decode issue.

I was pointed to this project, which continues from tivodecode 0.4.4 and it has the same issue.

diff --git a/tivo_decoder_ts_stream.cxx b/tivo_decoder_ts_stream.cxx
index 78e85cc..28a1b1e 100644
--- a/tivo_decoder_ts_stream.cxx
+++ b/tivo_decoder_ts_stream.cxx
@@ -74,6 +74,10 @@ bool TiVoDecoderTsStream::addPkt(TiVoDecoderTsPacket *pPkt)
             VVERBOSE("DEQUE : PktID %d from PID 0x%04x\n", pPkt2->packetId,
                     stream_pid);

+            int size = (TS_FRAME_SIZE - pPkt2->payloadOffset);
+            if (size <= 0)
+                return false;
+
             std::memcpy(&pesDecodeBuffer[pesDecodeBufferLen],
                         &pPkt2->buffer[pPkt2->payloadOffset],
                         TS_FRAME_SIZE - pPkt2->payloadOffset);

I was also pointed to tivolibre, a Java version of the tivodecode logic. Out of curiosity, I ran the same video through it and it completed successfuly, keeping the audio intact. Interesting... I might take a look at what it's doing and see if I can bring the changes/improvements over to C++.