[Scummvm-git-logs] scummvm master -> 598581c32b309372d355f3b0b7a19ebc5117b52a

bluegr noreply at scummvm.org
Sat Nov 29 03:47:32 UTC 2025


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

Summary:
598581c32b VIDEO: Don't hardcode expected channels in PSX decoder


Commit: 598581c32b309372d355f3b0b7a19ebc5117b52a
    https://github.com/scummvm/scummvm/commit/598581c32b309372d355f3b0b7a19ebc5117b52a
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2025-11-29T11:47:27+08:00

Commit Message:
VIDEO: Don't hardcode expected channels in PSX decoder

Still allow only one channel, but the channel number doesn't matter.
Also rename track to channel to follow the specifications.

Fixes Trac#15476.

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


diff --git a/video/psx_decoder.cpp b/video/psx_decoder.cpp
index 7b1c21d3665..eadcf7e2dcd 100644
--- a/video/psx_decoder.cpp
+++ b/video/psx_decoder.cpp
@@ -200,9 +200,9 @@ void PSXStreamDecoder::readNextPacket() {
 			error("Corrupt PSX stream sector");
 
 		sector->seek(0x11);
-		byte track = sector->readByte();
-		if (track >= 32) {
-			warning("Bad PSX stream track");
+		byte channel = sector->readByte();
+		if (channel >= 32) {
+			warning("Bad PSX stream channel");
 			return;
 		}
 
@@ -210,60 +210,64 @@ void PSXStreamDecoder::readNextPacket() {
 
 		switch (sectorType) {
 		case CDXA_TYPE_DATA:
-		case CDXA_TYPE_VIDEO:
-			if (track == 1) {
-				if (!_videoTrack) {
-					_videoTrack = new PSXVideoTrack(sector, _speed, _frameCount);
-					addTrack(_videoTrack);
-
-					// If no video track is initialized, we are called
-					// by loadStream(). Stop here, and start rendering
-					// the track from the next call.
-					_stream->seek(prevPos);
-					return;
-				}
-
-				sector->seek(28);
-				uint16 curSector = sector->readUint16LE();
-				uint16 sectorCount = sector->readUint16LE();
-				sector->readUint32LE();
-				uint16 frameSize = sector->readUint32LE();
-
-				if (curSector >= sectorCount)
-					error("Bad sector");
-
-				if (!partialFrame)
-					partialFrame = (byte *)malloc(sectorCount * VIDEO_DATA_CHUNK_SIZE);
-
-				sector->seek(VIDEO_DATA_HEADER_SIZE);
-				sector->read(partialFrame + curSector * VIDEO_DATA_CHUNK_SIZE, VIDEO_DATA_CHUNK_SIZE);
-
-				if (curSector == sectorCount - 1) {
-					// Done assembling the frame
-					Common::BitStreamMemoryStream *frame = new Common::BitStreamMemoryStream(partialFrame, frameSize, DisposeAfterUse::YES);
-
-					_videoTrack->decodeFrame(frame, sectorsRead);
-
-					delete frame;
-					delete sector;
-					return;
-				}
-			} else
-				error("Unhandled multi-track video");
+		case CDXA_TYPE_VIDEO: {
+			if (!_videoTrack) {
+				_videoTrack = new PSXVideoTrack(sector, _speed, _frameCount, channel);
+				addTrack(_videoTrack);
+
+				// If no video track is initialized, we are called
+				// by loadStream(). Stop here, and start rendering
+				// the track from the next call.
+				_stream->seek(prevPos);
+				return;
+			}
+
+			if (_videoTrack->getChannel() != channel) {
+				warning("Unhandled multi-channel video");
+				return;
+			}
+
+			sector->seek(28);
+			uint16 curSector = sector->readUint16LE();
+			uint16 sectorCount = sector->readUint16LE();
+			sector->readUint32LE();
+			uint16 frameSize = sector->readUint32LE();
+
+			if (curSector >= sectorCount)
+				error("Bad sector");
+
+			if (!partialFrame)
+				partialFrame = (byte *)malloc(sectorCount * VIDEO_DATA_CHUNK_SIZE);
+
+			sector->seek(VIDEO_DATA_HEADER_SIZE);
+			sector->read(partialFrame + curSector * VIDEO_DATA_CHUNK_SIZE, VIDEO_DATA_CHUNK_SIZE);
+
+			if (curSector == sectorCount - 1) {
+				// Done assembling the frame
+				Common::BitStreamMemoryStream *frame = new Common::BitStreamMemoryStream(partialFrame, frameSize, DisposeAfterUse::YES);
+
+				_videoTrack->decodeFrame(frame, sectorsRead);
+
+				delete frame;
+				delete sector;
+				return;
+			}
 			break;
-		case CDXA_TYPE_AUDIO:
+		}
+		case CDXA_TYPE_AUDIO: {
 			// We only handle one audio channel so far
-			if (track == 1) {
-				if (!_audioTrack) {
-					_audioTrack = new PSXAudioTrack(sector, getSoundType());
-					addTrack(_audioTrack);
-				}
-
-				_audioTrack->queueAudioFromSector(sector);
-			} else {
-				warning("Unhandled multi-track audio");
+			if (!_audioTrack) {
+				_audioTrack = new PSXAudioTrack(sector, getSoundType(), channel);
+				addTrack(_audioTrack);
 			}
+
+			if (_audioTrack->getChannel() != channel) {
+				warning("Unhandled multi-channel audio");
+			}
+
+			_audioTrack->queueAudioFromSector(sector);
 			break;
+		}
 		default:
 			// This shows up way too often, but the other sectors
 			// are safe to ignore
@@ -308,8 +312,8 @@ Common::SeekableReadStream *PSXStreamDecoder::readSector() {
 #define AUDIO_DATA_CHUNK_SIZE   2304
 #define AUDIO_DATA_SAMPLE_COUNT 4032
 
-PSXStreamDecoder::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType) :
-		AudioTrack(soundType) {
+PSXStreamDecoder::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType, byte channel) :
+		AudioTrack(soundType), _channel(channel) {
 	assert(sector);
 	_endOfTrack = false;
 
@@ -350,7 +354,8 @@ Audio::AudioStream *PSXStreamDecoder::PSXAudioTrack::getAudioStream() const {
 }
 
 
-PSXStreamDecoder::PSXVideoTrack::PSXVideoTrack(Common::SeekableReadStream *firstSector, CDSpeed speed, int frameCount) : _nextFrameStartTime(0, speed), _frameCount(frameCount), _surface(nullptr) {
+PSXStreamDecoder::PSXVideoTrack::PSXVideoTrack(Common::SeekableReadStream *firstSector, CDSpeed speed, int frameCount, byte channel) :
+	_nextFrameStartTime(0, speed), _frameCount(frameCount), _channel(channel), _surface(nullptr) {
 	assert(firstSector);
 
 	firstSector->seek(40);
diff --git a/video/psx_decoder.h b/video/psx_decoder.h
index b29b4c3f19c..d789e87ac30 100644
--- a/video/psx_decoder.h
+++ b/video/psx_decoder.h
@@ -77,9 +77,10 @@ protected:
 private:
 	class PSXVideoTrack : public VideoTrack {
 	public:
-		PSXVideoTrack(Common::SeekableReadStream *firstSector, CDSpeed speed, int frameCount);
+		PSXVideoTrack(Common::SeekableReadStream *firstSector, CDSpeed speed, int frameCount, byte channel);
 		~PSXVideoTrack() override;
 
+		byte getChannel() const { return _channel; }
 		uint16 getWidth() const override { return _width; }
 		uint16 getHeight() const override { return _height; }
 		Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
@@ -105,6 +106,7 @@ private:
 		uint16 _height;
 		uint32 _frameCount;
 		Audio::Timestamp _nextFrameStartTime;
+		byte _channel;
 		bool _endOfTrack;
 		int _curFrame;
 
@@ -135,9 +137,10 @@ private:
 
 	class PSXAudioTrack : public AudioTrack {
 	public:
-		PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
+		PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType, byte channel);
 		~PSXAudioTrack() override;
 
+		byte getChannel() const { return _channel; }
 		bool endOfTrack() const override;
 
 		void setEndOfTrack() { _endOfTrack = true; }
@@ -148,6 +151,7 @@ private:
 
 		Audio::QueuingAudioStream *_audStream;
 
+		byte _channel;
 		bool _endOfTrack;
 		bool _stereo;
 		uint _rate;




More information about the Scummvm-git-logs mailing list