[Scummvm-git-logs] scummvm master -> 73afe02f141b05d4ab4548df264216dedd7c9219

bluegr noreply at scummvm.org
Sun Mar 23 15:14:03 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
73afe02f14 VIDEO: Correctly handle raw Elementary Stream MPEG Videos


Commit: 73afe02f141b05d4ab4548df264216dedd7c9219
    https://github.com/scummvm/scummvm/commit/73afe02f141b05d4ab4548df264216dedd7c9219
Author: Malharbdv (149364452+Malharbdv at users.noreply.github.com)
Date: 2025-03-23T17:14:00+02:00

Commit Message:
VIDEO: Correctly handle raw Elementary Stream MPEG Videos

Recognize the type of the stream in .mpg files (ES or PS)
In case of ES (Elementary Streams) bypass the PES header
parsing process and directly feed the MPEG decoder the raw data.
Remove warning that appears when opening the ND
logo when opening the game 3mice1-pl

Changed paths:
    video/mpegps_decoder.cpp
    video/mpegps_decoder.h


diff --git a/video/mpegps_decoder.cpp b/video/mpegps_decoder.cpp
index 9c32c980bd3..626a551abd2 100644
--- a/video/mpegps_decoder.cpp
+++ b/video/mpegps_decoder.cpp
@@ -43,6 +43,7 @@ namespace Video {
 // --------------------------------------------------------------------------
 
 enum {
+	kStartCodeSequenceHeader = 0x1B3,
 	kStartCodePack = 0x1BA,
 	kStartCodeSystemHeader = 0x1BB,
 	kStartCodeProgramStreamMap = 0x1BC,
@@ -261,6 +262,27 @@ MPEGPSDecoder::MPEGPSDemuxer::~MPEGPSDemuxer() {
 bool MPEGPSDecoder::MPEGPSDemuxer::loadStream(Common::SeekableReadStream *stream) {
 	close();
 
+	// Check if the videostream being loaded is an elementary stream (ES) or a program stream (PS)
+	// PS streams start with the Pack Header which has a start code of 0x1ba
+	// ES streams start with the Sequence Header which has a start code of 0x1b3
+	uint32 header = stream->readUint32BE();
+	stream->seek(-4, SEEK_CUR);
+
+	// If it is a Sequence Header (ES Stream), pass the stream to a Elementary Stream handler.
+	// If it is a Pack Header (PS stream), pass the stream to PS demuxer for demuxing into video and audio packets
+	// Currently not handling other stream types like ES audio stream
+	// Throwing a warning, so that decoding of further streams isn't affected
+	// Unknown stream header types are "handled" (ignored) in the readNextPacketHeader function 
+
+	if (header == kStartCodeSequenceHeader) {
+		_isESStream = true;
+	} else if (header == kStartCodePack) {
+		_isESStream = false;
+	} else {
+		warning("Unknown Start Code in the MPEG stream, %d", header);
+		_isESStream = false;
+	}
+	
 	_stream = stream;
 
 	int queuedPackets = 0;
@@ -351,6 +373,21 @@ bool MPEGPSDecoder::MPEGPSDemuxer::queueNextPacket() {
 	if (_stream->eos())
 		return false;
 
+	// Program Streams are nothing but a wrapping around Elementary Stream data, this wrapping or header has 
+	// length, pts, dts and other information embedded in it which we parse in the readNextPacketHeader function
+	// Elementary stream doesn't have pts and dts, but our sendPacket() function handles that well
+	// TODO: Only handling video ES streams for now, audio ES streams are bit more complicated
+	if (_isESStream) {
+		const uint16 kESPacketSize = 1024;	// FFmpeg uses 1024 to packetize ES streams into PES packets
+	  
+		Common::SeekableReadStream *stream = _stream->readStream(kESPacketSize);
+
+		int32 startCode = 0x1E0;
+		uint32 pts = 0xFFFFFFFF, dts = 0xFFFFFFFF;
+		_videoQueue.push(Packet(stream, startCode, pts, dts));
+		return true;
+	}
+
 	for (;;) {
 		int32 startCode;
 		uint32 pts, dts;
diff --git a/video/mpegps_decoder.h b/video/mpegps_decoder.h
index 1f93b094927..fcbb3b47166 100644
--- a/video/mpegps_decoder.h
+++ b/video/mpegps_decoder.h
@@ -96,6 +96,8 @@ private:
 		Common::SeekableReadStream *_stream;
 		Common::Queue<Packet> _videoQueue;
 		Common::Queue<Packet> _audioQueue;
+		// If we come across a non-packetized elementary stream
+		bool _isESStream;
 	};
 
 	// Base class for handling MPEG streams




More information about the Scummvm-git-logs mailing list