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/keyboard.h"
35 #include "common/scummsys.h"
36 
37 #include "graphics/palette.h"
38 #include "graphics/transform_tools.h"
39 
40 #include "video/video_decoder.h"
41 
42 namespace Common {
43 class Archive;
44 class Rational;
45 }
46 
47 namespace Graphics {
48 class Cursor;
49 struct PixelFormat;
50 }
51 
52 namespace Image {
53 class Codec;
54 }
55 
56 namespace Video {
57 
67 public:
69  virtual ~QuickTimeDecoder();
70 
71  bool loadFile(const Common::Path &filename);
72  bool loadStream(Common::SeekableReadStream *stream);
73  void close();
74  uint16 getWidth() const { return _width; }
75  uint16 getHeight() const { return _height; }
76  const Graphics::Surface *decodeNextFrame();
77  Audio::Timestamp getDuration() const { return Audio::Timestamp(0, _duration, _timeScale); }
78 
79  void enableEditListBoundsCheckQuirk(bool enable) { _enableEditListBoundsCheckQuirk = enable; }
80  Common::String getAliasPath();
81 
83  // QTVR stuff
85  void setTargetSize(uint16 w, uint16 h);
86  void setOrigin(int left, int top) { _origin = Common::Point(left, top); }
87 
88  void handleMouseMove(int16 x, int16 y);
89  void handleMouseButton(bool isDown, int16 x = -1, int16 y = -1, bool repeat = false);
90  void handleKey(Common::KeyState &state, bool down, bool repeat = false);
91  void handleQuit();
92 
93  Common::Point getLastClick() { return _mouseDrag; }
94 
95  float getPanAngle() const { return _panAngle; }
96  void setPanAngle(float panAngle);
97  float getTiltAngle() const { return _tiltAngle; }
98  void setTiltAngle(float tiltAngle);
99  float getFOV() const { return _fov; }
100  float getHFOV() const { return _hfov; }
101  bool setFOV(float fov);
102  int getCurrentNodeID() { return _currentSample == -1 ? 0 : _panoTrack->panoSamples[_currentSample].hdr.nodeID; }
103  Common::String getCurrentNodeName();
104 
105  int getCurrentRow() { return _nextVideoTrack->getCurFrame() / _nav.columns; }
106  void setCurrentRow(int row);
107  int getCurrentColumn() { return _nextVideoTrack->getCurFrame() % _nav.columns; }
108  void setCurrentColumn(int column);
109 
110  int getZoomState() { return _zoomState; }
111 
112  const PanoHotSpot *getRolloverHotspot() { return _rolloverHotspot; }
113  int getRolloverHotspotID() { return _rolloverHotspotID; }
114  const PanoHotSpot *getClickedHotspot() { return _clickedHotspot; }
115  int getClickedHotspotID() { return _clickedHotspotID; }
116  Common::Point getPanLoc(int16 x, int16 y);
117  Graphics::FloatPoint getPanAngles(int16 x, int16 y);
118 
119  Common::String getHotSpotName(int id);
120  void setClickedHotSpot(int id);
121  const PanoHotSpot *getHotSpotByID(int id);
122  const PanoNavigation *getHotSpotNavByID(int id);
123 
124  void nudge(const Common::String &direction);
125 
126  bool isVR() const { return _isVR; }
127  QTVRType getQTVRType() const { return _qtvrType; }
128 
129  int getWarpMode() const { return _warpMode; }
130  void setWarpMode(int warpMode);
131  float getQuality() const { return _quality; }
132  void setQuality(float quality);
133  Common::String getTransitionMode() const { return _transitionMode == kTransitionModeNormal ? "normal" : "swing"; }
134  void setTransitionMode(Common::String mode);
135  float getTransitionSpeed() const { return _transitionSpeed; }
136  void setTransitionSpeed(float speed);
137  Common::String getUpdateMode() const;
138  void setUpdateMode(Common::String mode);
139 
140  void renderHotspots(bool mode);
141 
142  struct NodeData {
143  uint32 nodeID;
144 
145  float defHPan;
146  float defVPan;
147  float defZoom;
148 
149  float minHPan;
150  float minVPan;
151  float maxHPan;
152  float maxVPan;
153  float minZoom;
154 
155  Common::String name;
156  };
157 
158  NodeData getNodeData(uint32 nodeID);
159  void goToNode(uint32 nodeID);
160 
161 protected:
162  Common::QuickTimeParser::SampleDesc *readSampleDesc(Common::QuickTimeParser::Track *track, uint32 format, uint32 descSize);
163  Common::QuickTimeParser::SampleDesc *readPanoSampleDesc(Common::QuickTimeParser::Track *track, uint32 format, uint32 descSize);
164 
165 private:
166  void init();
167 
168  void updateAudioBuffer();
169 
170  void handleObjectMouseMove(int16 x, int16 y);
171  void handleObjectMouseButton(bool isDown, int16 x, int16 y, bool repeat);
172  void handlePanoMouseMove(int16 x, int16 y);
173  void handlePanoMouseButton(bool isDown, int16 x, int16 y, bool repeat);
174 
175  void handleObjectKey(Common::KeyState &state, bool down, bool repeat);
176  void handlePanoKey(Common::KeyState &state, bool down, bool repeat);
177 
178  void closeQTVR();
179  void updateAngles();
180  void lookupHotspot(int16 x, int16 y);
181  void updateQTVRCursor(int16 x, int16 y);
182  void setCursor(int curId);
183  void cleanupCursors();
184  void computeInteractivityZones();
185 
186  uint16 _width, _height;
187  // _origin is the top left corner point of the panorama video being played
188  // by director engine or whichever engine is using QTVR decoder currently
189  // decoder handles swing transitions (in QTVR xtra) internally
190  // Hence, it needs to know where to blit the projected panorama during transition
191  Common::Point _origin;
192 
193 public:
194  int _currentSample = -1;
195  Common::Point _prevMouse;
196  bool _isMouseButtonDown = false;
197  Common::Point _mouseDrag;
198 
199  bool _isKeyDown = false;
200  Common::KeyState _lastKey;
201 
202  enum {
203  kZoomNone,
204  kZoomQuestion,
205  kZoomIn,
206  kZoomOut,
207  kZoomLimit,
208 
209  kTransitionModeNormal,
210  kTransitionModeSwing,
211 
212  kUpdateModeNormal,
213  kUpdateModeUpdateBoth,
214  kUpdateModeOffscreenOnly,
215  kUpdateModeFromOffscreen,
216  kUpdateModeDirectToScreen,
217  };
218 
219 private:
220  Common::Rect _curBbox;
221 
222  int _currentQTVRCursor = -1;
223  Common::Archive *_dataBundle = nullptr;
224  Graphics::Cursor **_cursorCache = nullptr;
225  int _cursorDirMap[256];
226 
227  bool _isVR = false;
228 
229  uint8 _warpMode = 2; // (2 | 1 | 0) for 2-d, 1-d or no warping
230  float _quality = 0.0f;
231  int _transitionMode = kTransitionModeNormal;
232  float _transitionSpeed = 1.0f;
233  int _updateMode = kUpdateModeNormal;
234 
235  float _panAngle = 0.0f;
236  float _tiltAngle = 0.0f;
237  float _fov = 56.0f;
238  float _hfov = 56.0f;
239  int _zoomState = kZoomNone;
240  bool _repeatTimerActive = false;
241 
242  const PanoHotSpot *_rolloverHotspot = nullptr;
243  int _rolloverHotspotID = 0;
244  const PanoHotSpot *_clickedHotspot = nullptr;
245  int _clickedHotspotID = 0;
246  bool _renderHotspots = false;
247 
248  Graphics::Surface *_scaledSurface;
249  void scaleSurface(const Graphics::Surface *src, Graphics::Surface *dst,
250  const Common::Rational &scaleFactorX, const Common::Rational &scaleFactorY);
251 
252  bool _enableEditListBoundsCheckQuirk;
253 
254  class VideoSampleDesc : public Common::QuickTimeParser::SampleDesc {
255  public:
256  VideoSampleDesc(Common::QuickTimeParser::Track *parentTrack, uint32 codecTag);
257  ~VideoSampleDesc();
258 
259  void initCodec();
260 
261  // TODO: Make private in the long run
262  uint16 _bitsPerSample;
263  char _codecName[32];
264  uint16 _colorTableId;
265  Graphics::Palette _palette;
266  Image::Codec *_videoCodec;
267  };
268 
269  // The AudioTrackHandler is currently just a wrapper around some
270  // QuickTimeDecoder functions.
271  class AudioTrackHandler : public SeekableAudioTrack {
272  public:
273  AudioTrackHandler(QuickTimeDecoder *decoder, QuickTimeAudioTrack *audioTrack);
274 
275  void updateBuffer();
276 
277  protected:
278  Audio::SeekableAudioStream *getSeekableAudioStream() const;
279 
280  private:
281  QuickTimeDecoder *_decoder;
282  QuickTimeAudioTrack *_audioTrack;
283  };
284 
285  class PanoSampleDesc : public Common::QuickTimeParser::SampleDesc {
286  public:
287  PanoSampleDesc(Common::QuickTimeParser::Track *parentTrack, uint32 codecTag);
288  ~PanoSampleDesc();
289 
290  int16 _majorVersion; // must be zero, also observed to be 1
291  int16 _minorVersion; // must be zero, also observed to be 1
292 
293  int32 _sceneTrackID; // ID of video track that contains panoramic scene
294  int32 _loResSceneTrackID; // ID of video track that contains low res panoramic scene
295  byte _reserved3[4 * 6]; // must be zero
296  int32 _hotSpotTrackID; // ID of video track that contains hotspot image
297  byte _reserved4[4 * 9]; // must be zero
298 
299  float _hPanStart; // horizontal pan range start angle (e.g. 0)
300  float _hPanEnd; // horizontal pan range end angle (e.g. 360)
301  float _vPanTop; // vertical pan range top angle (e.g. 42.5)
302  float _vPanBottom; // vertical pan range bottom angle (e.g. -42.5)
303  float _minimumZoom; // minimum zoom angle (e.g. 5; use 0 for default)
304  float _maximumZoom; // maximum zoom angle (e.g. 65; use 0 for default)
305 
306  // info for the highest res version of scene track
307  uint32 _sceneSizeX; // pixel width of the panorama (e.g. 768)
308  uint32 _sceneSizeY; // pixel height of the panorama (e.g. 2496)
309  uint32 _numFrames; // number of diced frames (e.g. 24)
310  int16 _reserved5; // must be zero
311  int16 _sceneNumFramesX; // diced frames wide (e.g. 1)
312  int16 _sceneNumFramesY; // diced frames high (e.g. 24)
313  int16 _sceneColorDepth; // bit depth of the scene track (e.g. 32)
314 
315  // info for the highest rest version of hotSpot track
316  int32 _hotSpotSizeX; // pixel width of the hot spot panorama (e.g. 768)
317  int32 _hotSpotSizeY; // pixel height of the hot spot panorama (e.g. 2496)
318  int16 _reserved6; // must be zero
319  int16 _hotSpotNumFramesX; // diced frames wide (e.g. 1)
320  int16 _hotSpotNumFramesY; // diced frames high (e.g. 24)
321  int16 _hotSpotColorDepth; // must be 8
322  };
323 
324  // The VideoTrackHandler is the bridge between the time of playback
325  // and the media for the given track. It calculates when to start
326  // tracks and at what rate to play the media using the edit list.
327  class VideoTrackHandler : public VideoTrack {
328  public:
329  VideoTrackHandler(QuickTimeDecoder *decoder, Common::QuickTimeParser::Track *parent);
330  ~VideoTrackHandler();
331 
332  bool endOfTrack() const;
333  bool isSeekable() const { return true; }
334  bool seek(const Audio::Timestamp &time);
335  Audio::Timestamp getDuration() const;
336 
337  uint16 getWidth() const;
338  uint16 getHeight() const;
339  Graphics::PixelFormat getPixelFormat() const;
340  bool setOutputPixelFormat(const Graphics::PixelFormat &format);
341  int getCurFrame() const { return _curFrame; }
342  void setCurFrame(int32 curFrame) { _curFrame = curFrame; }
343  int getFrameCount() const;
344  uint32 getNextFrameStartTime() const; // milliseconds
345  const Graphics::Surface *decodeNextFrame();
346  Audio::Timestamp getFrameTime(uint frame) const;
347  const byte *getPalette() const;
348  bool hasDirtyPalette() const { return _dirtyPalette; }
349  bool setReverse(bool reverse);
350  bool isReversed() const { return _reversed; }
351  bool canDither() const;
352  void setDither(const byte *palette);
353 
354  Common::Rational getScaledWidth() const;
355  Common::Rational getScaledHeight() const;
356 
357  const Graphics::Surface *bufferNextFrame();
358 
359  private:
360  QuickTimeDecoder *_decoder;
362  uint32 _curEdit;
363  int32 _curFrame;
364  int32 _delayedFrameToBufferTo;
365  uint32 _nextFrameStartTime; // media time
366  Graphics::Surface *_scaledSurface;
367  int32 _durationOverride; // media time
368  const byte *_curPalette;
369  mutable bool _dirtyPalette;
370  bool _reversed;
371 
372  Common::SeekableReadStream *getNextFramePacket(uint32 &descId);
373  uint32 getCurFrameDuration(); // media time
374  uint32 findKeyFrame(uint32 frame) const;
375  bool isEmptyEdit() const;
376  void enterNewEditListEntry(bool bufferFrames, bool intializingTrack = false);
377  uint32 getRateAdjustedFrameTime() const; // media time
378  uint32 getCurEditTimeOffset() const; // media time
379  uint32 getCurEditTrackDuration() const; // media time
380  bool atLastEdit() const;
381  bool endOfCurEdit() const;
382  void checkEditListBounds();
383  };
384 
385  class PanoTrackHandler : public VideoTrack {
386  public:
387  PanoTrackHandler(QuickTimeDecoder *decoder, Common::QuickTimeParser::Track *parent);
388  ~PanoTrackHandler();
389 
390  bool endOfTrack() const { return false; }
391  uint16 getWidth() const;
392  uint16 getHeight() const;
393  int getCurFrame() const { return 1; }
394  uint32 getNextFrameStartTime() const { return 0; }
395  Graphics::PixelFormat getPixelFormat() const;
396  const Graphics::Surface *decodeNextFrame();
397 
398  Common::Rational getScaledWidth() const;
399  Common::Rational getScaledHeight() const;
400 
401  void initPanorama();
402  void constructPanorama();
403  Graphics::Surface *constructMosaic(VideoTrackHandler *track, uint w, uint h, Common::String fname);
404 
405  Common::Point projectPoint(int16 x, int16 y);
406 
407  void setDirty() { _dirty = true; }
408 
409  private:
410  QuickTimeDecoder *_decoder;
412 
413  void projectPanorama(uint8 scaleFactor, float fov, float hfov, float panAngle, float tiltAngle);
414  void swingTransitionHandler();
415  void boxAverage(Graphics::Surface *sourceSurface, uint8 scaleFactor);
416  Graphics::Surface* upscalePanorama(Graphics::Surface *sourceSurface, int8 level);
417 
418  const Graphics::Surface *bufferNextFrame();
419 
420  public:
421  Graphics::Surface *_constructedPano;
422  Graphics::Surface *_upscaledConstructedPano;
423  Graphics::Surface *_constructedHotspots;
424  Graphics::Surface *_projectedPano;
425  Graphics::Surface *_planarProjection;
426 
427  // Current upscale level (0 or 1 or 2) of _upscaledConstructedPanorama compared to _constructedPano
428  // level 0 means that constructedPano was just contructed and hasn't been upscaled yet
429  // level 1 means only upscaled height (2x pixels)
430  // level 2 means upscaled height and width (4x pixels)
431  uint8 _upscaleLevel = 0;
432 
433  // Defining these to make the swing transition happen
434  // which requires storing the previous point during every change in FOV, Pan Angle and Tilt Angle
435  // If swing transition is called, this will be the start point of the transition
436  float _currentFOV = 0;
437  float _currentHFOV = 0;
438  float _currentPanAngle = 0;
439  float _currentTiltAngle = 0;
440 
441  private:
442  bool _isPanoConstructed;
443  bool _dirty;
444  };
445 };
446 
447 } // End of namespace Video
448 
449 #endif
Definition: quicktime_intern.h:65
Definition: str.h:59
Definition: surface.h:67
Definition: quicktime.h:265
Definition: qt_decoder.h:66
Definition: pixelformat.h:138
Definition: quicktime.h:134
Definition: rect.h:524
Definition: path.h:52
Definition: timestamp.h:83
Definition: stream.h:745
Definition: rational.h:40
Definition: quicktime.h:201
Definition: quicktime.h:300
Definition: audiostream.h:212
Definition: archive.h:141
Definition: codec.h:57
Definition: quicktime_intern.h:47
Definition: atari-cursor.h:35
Definition: video_decoder.h:53
Definition: cursor.h:42
Audio::Timestamp getDuration() const
Definition: qt_decoder.h:77
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: rect.h:144
uint16 getWidth() const
Definition: qt_decoder.h:74
Definition: transform_tools.h:32
Definition: qt_decoder.h:142
Definition: keyboard.h:294
Simple class for handling a palette data.
Definition: palette.h:55
Definition: avi_frames.h:36
Definition: video_decoder.h:844
Definition: movie_decoder.h:32
uint16 getHeight() const
Definition: qt_decoder.h:75
Definition: video_decoder.h:589