diff options
author | Torbjörn Andersson | 2018-06-19 07:06:41 +0200 |
---|---|---|
committer | Thierry Crozat | 2018-11-04 22:33:22 +0100 |
commit | 1d69564876ad0048d49b968a5fbc01564dd74dba (patch) | |
tree | d7ec5da5a739bf5e03c8c5e5cf4ba5b7af0e6fb6 /video | |
parent | ac40828ed24ff3d42ac68f2d45f36a03c34dc54d (diff) | |
download | scummvm-rg350-1d69564876ad0048d49b968a5fbc01564dd74dba.tar.gz scummvm-rg350-1d69564876ad0048d49b968a5fbc01564dd74dba.tar.bz2 scummvm-rg350-1d69564876ad0048d49b968a5fbc01564dd74dba.zip |
VIDEO: Moved MPEGStream creation out of readNextPacket()
I think it makes things easier to read, and I have some ideas
that I want to try which should be easier this way...
Diffstat (limited to 'video')
-rw-r--r-- | video/mpegps_decoder.cpp | 148 | ||||
-rw-r--r-- | video/mpegps_decoder.h | 1 |
2 files changed, 78 insertions, 71 deletions
diff --git a/video/mpegps_decoder.cpp b/video/mpegps_decoder.cpp index 81c1765475..5d86e3f500 100644 --- a/video/mpegps_decoder.cpp +++ b/video/mpegps_decoder.cpp @@ -79,6 +79,82 @@ void MPEGPSDecoder::close() { memset(_psmESType, 0, 256); } +MPEGPSDecoder::MPEGStream *MPEGPSDecoder::getStream(uint32 startCode, Common::SeekableReadStream *packet) { + MPEGStream *stream = 0; + + if (_streamMap.contains(startCode)) { + // We already found the stream + stream = _streamMap[startCode]; + } else { + // We haven't seen this before + + if (startCode == kStartCodePrivateStream1) { + PrivateStreamType streamType = detectPrivateStreamType(packet); + packet->seek(0); + + // TODO: Handling of these types (as needed) + bool handled = false; + const char *typeName; + + switch (streamType) { + case kPrivateStreamAC3: { + typeName = "AC-3"; + +#ifdef USE_A52 + handled = true; + AC3AudioTrack *ac3Track = new AC3AudioTrack(*packet, getSoundType()); + stream = ac3Track; + _streamMap[startCode] = ac3Track; + addTrack(ac3Track); +#endif + break; + } + case kPrivateStreamDTS: + typeName = "DTS"; + break; + case kPrivateStreamDVDPCM: + typeName = "DVD PCM"; + break; + case kPrivateStreamPS2Audio: + typeName = "PS2 Audio"; + break; + default: + typeName = "Unknown"; + break; + } + + if (!handled) { + warning("Unhandled DVD private stream: %s", typeName); + + // Make it 0 so we don't get the warning twice + _streamMap[startCode] = 0; + } + } else if (startCode >= 0x1E0 && startCode <= 0x1EF) { + // Video stream + // TODO: Multiple video streams + warning("Found extra video stream 0x%04X", startCode); + _streamMap[startCode] = 0; + } else if (startCode >= 0x1C0 && startCode <= 0x1DF) { +#ifdef USE_MAD + // MPEG Audio stream + MPEGAudioTrack *audioTrack = new MPEGAudioTrack(*packet, getSoundType()); + stream = audioTrack; + _streamMap[startCode] = audioTrack; + addTrack(audioTrack); +#else + warning("Found audio stream 0x%04X, but no MAD support compiled in", startCode); + _streamMap[startCode] = 0; +#endif + } else { + // Probably not relevant + debug(0, "Found unhandled MPEG-PS stream type 0x%04x", startCode); + _streamMap[startCode] = 0; + } + } + + return stream; +} + void MPEGPSDecoder::readNextPacket() { if (_stream->eos()) return; @@ -96,78 +172,8 @@ void MPEGPSDecoder::readNextPacket() { return; } - MPEGStream *stream = 0; Common::SeekableReadStream *packet = _stream->readStream(size); - - if (_streamMap.contains(startCode)) { - // We already found the stream - stream = _streamMap[startCode]; - } else { - // We haven't seen this before - - if (startCode == kStartCodePrivateStream1) { - PrivateStreamType streamType = detectPrivateStreamType(packet); - packet->seek(0); - - // TODO: Handling of these types (as needed) - bool handled = false; - const char *typeName; - - switch (streamType) { - case kPrivateStreamAC3: { - typeName = "AC-3"; - -#ifdef USE_A52 - handled = true; - AC3AudioTrack *ac3Track = new AC3AudioTrack(*packet, getSoundType()); - stream = ac3Track; - _streamMap[startCode] = ac3Track; - addTrack(ac3Track); -#endif - break; - } - case kPrivateStreamDTS: - typeName = "DTS"; - break; - case kPrivateStreamDVDPCM: - typeName = "DVD PCM"; - break; - case kPrivateStreamPS2Audio: - typeName = "PS2 Audio"; - break; - default: - typeName = "Unknown"; - break; - } - - if (!handled) { - warning("Unhandled DVD private stream: %s", typeName); - - // Make it 0 so we don't get the warning twice - _streamMap[startCode] = 0; - } - } else if (startCode >= 0x1E0 && startCode <= 0x1EF) { - // Video stream - // TODO: Multiple video streams - warning("Found extra video stream 0x%04X", startCode); - _streamMap[startCode] = 0; - } else if (startCode >= 0x1C0 && startCode <= 0x1DF) { -#ifdef USE_MAD - // MPEG Audio stream - MPEGAudioTrack *audioTrack = new MPEGAudioTrack(*packet, getSoundType()); - stream = audioTrack; - _streamMap[startCode] = audioTrack; - addTrack(audioTrack); -#else - warning("Found audio stream 0x%04X, but no MAD support compiled in", startCode); - _streamMap[startCode] = 0; -#endif - } else { - // Probably not relevant - debug(0, "Found unhandled MPEG-PS stream type 0x%04x", startCode); - _streamMap[startCode] = 0; - } - } + MPEGStream *stream = getStream(startCode, packet); if (stream) { packet->seek(0); diff --git a/video/mpegps_decoder.h b/video/mpegps_decoder.h index cc11416f72..15a9443f2f 100644 --- a/video/mpegps_decoder.h +++ b/video/mpegps_decoder.h @@ -160,6 +160,7 @@ private: int readNextPacketHeader(int32 &startCode, uint32 &pts, uint32 &dts); int findNextStartCode(uint32 &size); + MPEGStream *getStream(uint32 startCode, Common::SeekableReadStream *packet); uint32 readPTS(int c); void parseProgramStreamMap(int length); |