1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef SHERLOCK_SCALPEL_3DO_MOVIE_DECODER_H
24 #define SHERLOCK_SCALPEL_3DO_MOVIE_DECODER_H
25 
26 #include "common/rect.h"
27 #include "video/video_decoder.h"
28 #include "audio/decoders/3do.h"
29 
30 namespace Audio {
31 class QueuingAudioStream;
32 }
33 
34 namespace Common {
35 class SeekableReadStream;
36 }
37 
38 namespace Image {
39 class Codec;
40 }
41 
42 namespace Sherlock {
43 
44 class Scalpel3DOMovieDecoder : public Video::VideoDecoder {
45 public:
46 	Scalpel3DOMovieDecoder();
47 	~Scalpel3DOMovieDecoder();
48 
49 	bool loadStream(Common::SeekableReadStream *stream);
50 	void close();
51 
52 protected:
53 	void readNextPacket();
54 
55 private:
56 	int32 _streamVideoOffset; /* current stream offset for video decoding */
57 	int32 _streamAudioOffset; /* current stream offset for audio decoding */
58 
59 private:
60 	class StreamVideoTrack : public VideoTrack  {
61 	public:
62 		StreamVideoTrack(uint32 width, uint32 height, uint32 codecTag, uint32 frameCount);
63 		~StreamVideoTrack();
64 
65 		bool endOfTrack() const;
66 
getWidth()67 		uint16 getWidth() const { return _width; }
getHeight()68 		uint16 getHeight() const { return _height; }
69 		Graphics::PixelFormat getPixelFormat() const;
getCurFrame()70 		int getCurFrame() const { return _curFrame; }
getFrameCount()71 		int getFrameCount() const { return _frameCount; }
setNextFrameStartTime(uint32 nextFrameStartTime)72 		void setNextFrameStartTime(uint32 nextFrameStartTime) { _nextFrameStartTime = nextFrameStartTime; }
getNextFrameStartTime()73 		uint32 getNextFrameStartTime() const { return _nextFrameStartTime; }
decodeNextFrame()74 		const Graphics::Surface *decodeNextFrame() { return _surface; }
75 
76 		void decodeFrame(Common::SeekableReadStream *stream, uint32 videoTimeStamp);
77 
78 	private:
79 		const Graphics::Surface *_surface;
80 
81 		int _curFrame;
82 		uint32 _frameCount;
83 		uint32 _nextFrameStartTime;
84 
85 		Image::Codec *_codec;
86 		uint16 _width, _height;
87 	};
88 
89 	class StreamAudioTrack : public AudioTrack {
90 	public:
91 		StreamAudioTrack(uint32 codecTag, uint32 sampleRate, uint32 channels, Audio::Mixer::SoundType soundType);
92 		~StreamAudioTrack();
93 
94 		void queueAudio(Common::SeekableReadStream *stream, uint32 size);
95 
96 	protected:
97 		Audio::AudioStream *getAudioStream() const;
98 
99 	private:
100 		Audio::QueuingAudioStream *_audioStream;
101 		uint32 _totalAudioQueued; /* total amount of milliseconds of audio, that we queued up already */
102 
103 	public:
getTotalAudioQueued()104 		uint32 getTotalAudioQueued() const { return _totalAudioQueued; }
105 
106 	private:
107 		int16 decodeSample(uint8 dataNibble);
108 
109 		uint32 _codecTag;
110 		uint16 _sampleRate;
111 		bool   _stereo;
112 
113 		Audio::audio_3DO_ADP4_PersistentSpace _ADP4_PersistentSpace;
114 		Audio::audio_3DO_SDX2_PersistentSpace _SDX2_PersistentSpace;
115 	};
116 
117 	Common::SeekableReadStream *_stream;
118 	StreamVideoTrack *_videoTrack;
119 	StreamAudioTrack *_audioTrack;
120 };
121 
122 } // End of namespace Sherlock
123 
124 #endif
125