ScummVM API documentation
qt_decoder.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //
23 // Partially based on ffmpeg code.
24 //
25 // Copyright (c) 2001 Fabrice Bellard.
26 // First version by Francois Revol revol@free.fr
27 // Seek function by Gael Chardon gael.dev@4now.net
28 //
29 
30 #ifndef VIDEO_QT_DECODER_H
31 #define VIDEO_QT_DECODER_H
32 
33 #include "audio/decoders/quicktime_intern.h"
34 #include "common/scummsys.h"
35 
36 #include "video/video_decoder.h"
37 
38 namespace Common {
39 class Rational;
40 }
41 
42 namespace Graphics {
43 struct PixelFormat;
44 }
45 
46 namespace Image {
47 class Codec;
48 }
49 
50 namespace Video {
51 
61 public:
63  virtual ~QuickTimeDecoder();
64 
65  bool loadFile(const Common::Path &filename);
66  bool loadStream(Common::SeekableReadStream *stream);
67  void close();
68  uint16 getWidth() const { return _width; }
69  uint16 getHeight() const { return _height; }
70  const Graphics::Surface *decodeNextFrame();
71  Audio::Timestamp getDuration() const { return Audio::Timestamp(0, _duration, _timeScale); }
72 
73  void enableEditListBoundsCheckQuirk(bool enable) { _enableEditListBoundsCheckQuirk = enable; }
74  Common::String getAliasPath();
75 
76  void handleMouseMove(int16 x, int16 y);
77  void handleMouseButton(bool isDown, int16 x = -1, int16 y = -1);
78 
79  float getPanAngle() const { return ((VideoTrackHandler *)_nextVideoTrack)->getPanAngle(); }
80  void setPanAngle(float panAngle) { ((VideoTrackHandler *)_nextVideoTrack)->setPanAngle(panAngle); }
81  float getTiltAngle() const { return ((VideoTrackHandler *)_nextVideoTrack)->getTiltAngle(); }
82  void setTiltAngle(float tiltAngle) { ((VideoTrackHandler *)_nextVideoTrack)->setTiltAngle(tiltAngle); }
83  float getFOV() const { return ((VideoTrackHandler *)_nextVideoTrack)->getFOV(); }
84  void setFOV(float fov) { ((VideoTrackHandler *)_nextVideoTrack)->setFOV(fov); }
85 
86  int getCurrentRow() { return _nextVideoTrack->getCurFrame() / _nav.columns; }
87  void setCurrentRow(int row);
88  int getCurrentColumn() { return _nextVideoTrack->getCurFrame() % _nav.columns; }
89  void setCurrentColumn(int column);
90 
91  void nudge(const Common::String &direction);
92 
93  bool isVR() const { return _isVR; }
94  QTVRType getQTVRType() const { return _qtvrType; }
95 
96  uint8 getWarpMode() const { return _warpMode; }
97  void setWarpMode(uint8 warpMode) { _warpMode = warpMode; }
98 
99  struct NodeData {
100  uint32 nodeID;
101 
102  float defHPan;
103  float defVPan;
104  float defZoom;
105 
106  float minHPan;
107  float minVPan;
108  float maxHPan;
109  float maxVPan;
110  float minZoom;
111 
112  Common::String name;
113  };
114 
115  NodeData getNodeData(uint32 nodeID);
116 
117 protected:
118  Common::QuickTimeParser::SampleDesc *readSampleDesc(Common::QuickTimeParser::Track *track, uint32 format, uint32 descSize);
119 
120 private:
121  void init();
122 
123  void updateAudioBuffer();
124 
125  uint16 _width, _height;
126 
127  uint16 _prevMouseX, _prevMouseY;
128  bool _isMouseButtonDown;
129 
130  bool _isVR;
131 
132  uint8 _warpMode; // (2 | 1 | 0) for 2-d, 1-d or no warping
133 
134  Graphics::Surface *_scaledSurface;
135  void scaleSurface(const Graphics::Surface *src, Graphics::Surface *dst,
136  const Common::Rational &scaleFactorX, const Common::Rational &scaleFactorY);
137 
138  bool _enableEditListBoundsCheckQuirk;
139 
140  class VideoSampleDesc : public Common::QuickTimeParser::SampleDesc {
141  public:
142  VideoSampleDesc(Common::QuickTimeParser::Track *parentTrack, uint32 codecTag);
143  ~VideoSampleDesc();
144 
145  void initCodec();
146 
147  // TODO: Make private in the long run
148  uint16 _bitsPerSample;
149  char _codecName[32];
150  uint16 _colorTableId;
151  byte *_palette;
152  Image::Codec *_videoCodec;
153  };
154 
155  // The AudioTrackHandler is currently just a wrapper around some
156  // QuickTimeDecoder functions.
157  class AudioTrackHandler : public SeekableAudioTrack {
158  public:
159  AudioTrackHandler(QuickTimeDecoder *decoder, QuickTimeAudioTrack *audioTrack);
160 
161  void updateBuffer();
162 
163  protected:
164  Audio::SeekableAudioStream *getSeekableAudioStream() const;
165 
166  private:
167  QuickTimeDecoder *_decoder;
168  QuickTimeAudioTrack *_audioTrack;
169  };
170 
171  // The VideoTrackHandler is the bridge between the time of playback
172  // and the media for the given track. It calculates when to start
173  // tracks and at what rate to play the media using the edit list.
174  class VideoTrackHandler : public VideoTrack {
175  public:
176  VideoTrackHandler(QuickTimeDecoder *decoder, Common::QuickTimeParser::Track *parent);
177  ~VideoTrackHandler();
178 
179  bool endOfTrack() const;
180  bool isSeekable() const { return true; }
181  bool seek(const Audio::Timestamp &time);
182  Audio::Timestamp getDuration() const;
183 
184  uint16 getWidth() const;
185  uint16 getHeight() const;
186  Graphics::PixelFormat getPixelFormat() const;
187  bool setOutputPixelFormat(const Graphics::PixelFormat &format);
188  int getCurFrame() const { return _curFrame; }
189  void setCurFrame(int32 curFrame) { _curFrame = curFrame; }
190  int getFrameCount() const;
191  uint32 getNextFrameStartTime() const; // milliseconds
192  const Graphics::Surface *decodeNextFrame();
193  Audio::Timestamp getFrameTime(uint frame) const;
194  const byte *getPalette() const;
195  bool hasDirtyPalette() const { return _curPalette; }
196  bool setReverse(bool reverse);
197  bool isReversed() const { return _reversed; }
198  bool canDither() const;
199  void setDither(const byte *palette);
200 
201  Common::Rational getScaledWidth() const;
202  Common::Rational getScaledHeight() const;
203 
204  float getPanAngle() const { return _panAngle; }
205  void setPanAngle(float panAngle) { _panAngle = panAngle; }
206  float getTiltAngle() const { return _tiltAngle; }
207  void setTiltAngle(float tiltAngle) { _tiltAngle = tiltAngle; }
208  float getFOV() const { return _fov; }
209  void setFOV(float fov) { _fov = fov; }
210 
211  private:
212  QuickTimeDecoder *_decoder;
214  uint32 _curEdit;
215  int32 _curFrame;
216  int32 _delayedFrameToBufferTo;
217  uint32 _nextFrameStartTime; // media time
218  Graphics::Surface *_scaledSurface;
219  int32 _durationOverride; // media time
220  const byte *_curPalette;
221  mutable bool _dirtyPalette;
222  bool _reversed;
223 
224  float _panAngle;
225  float _tiltAngle;
226  float _fov;
227 
228  void constructPanorama();
229  void projectPanorama();
230 
231  Graphics::Surface *_constructedPano;
232  Graphics::Surface *_projectedPano;
233 
234  bool _isPanoConstructed;
235 
236  // Forced dithering of frames
237  byte *_forcedDitherPalette;
238  byte *_ditherTable;
239  Graphics::Surface *_ditherFrame;
240  const Graphics::Surface *forceDither(const Graphics::Surface &frame);
241 
242  Common::SeekableReadStream *getNextFramePacket(uint32 &descId);
243  uint32 getCurFrameDuration(); // media time
244  uint32 findKeyFrame(uint32 frame) const;
245  bool isEmptyEdit() const;
246  void enterNewEditListEntry(bool bufferFrames, bool intializingTrack = false);
247  const Graphics::Surface *bufferNextFrame();
248  uint32 getRateAdjustedFrameTime() const; // media time
249  uint32 getCurEditTimeOffset() const; // media time
250  uint32 getCurEditTrackDuration() const; // media time
251  bool atLastEdit() const;
252  bool endOfCurEdit() const;
253  void checkEditListBounds();
254  };
255 };
256 
257 } // End of namespace Video
258 
259 #endif
Definition: quicktime_intern.h:65
Definition: str.h:59
Definition: surface.h:67
Definition: qt_decoder.h:60
Definition: pixelformat.h:138
Definition: quicktime.h:132
Definition: path.h:52
Definition: timestamp.h:83
Definition: stream.h:745
Definition: rational.h:40
Definition: quicktime.h:276
Definition: audiostream.h:212
Definition: codec.h:57
Definition: quicktime_intern.h:47
Definition: video_decoder.h:53
Audio::Timestamp getDuration() const
Definition: qt_decoder.h:71
Definition: algorithm.h:29
Definition: formatinfo.h:28
uint16 getWidth() const
Definition: qt_decoder.h:68
Definition: qt_decoder.h:99
Definition: avi_frames.h:36
Definition: video_decoder.h:832
Definition: movie_decoder.h:32
uint16 getHeight() const
Definition: qt_decoder.h:69
Definition: video_decoder.h:577