ScummVM API documentation
video.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 #ifndef NANCY_VIDEO_H
23 #define NANCY_VIDEO_H
24 
25 #include "video/video_decoder.h"
26 
27 namespace Common {
28 class ReadStream;
29 class SeekableReadStream;
30 }
31 
32 namespace Graphics {
33 struct Surface;
34 }
35 
36 namespace Nancy {
37 
38 class Decompressor;
39 class VideoCacheLoader;
40 
42  friend class VideoCacheLoader;
43 public:
44  enum CacheHint { kLoadForward, kLoadBidirectional };
45 
46  AVFDecoder(CacheHint cacheHint = kLoadForward) : _cacheHint(cacheHint) {}
47  virtual ~AVFDecoder();
48 
49  bool loadStream(Common::SeekableReadStream *stream) override;
50  const Graphics::Surface *decodeFrame(uint frameNr);
51  void addFrameTime(const uint16 timeToAdd);
52  bool atEnd() const;
53 
54 private:
55  CacheHint _cacheHint;
56  class AVFVideoTrack : public FixedRateVideoTrack {
57  public:
58  AVFVideoTrack(Common::SeekableReadStream *stream, uint32 chunkFileFormat, CacheHint cacheHint);
59  virtual ~AVFVideoTrack();
60 
61  uint16 getWidth() const override { return _width; }
62  uint16 getHeight() const override { return _height; }
63  Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
64  int getCurFrame() const override { return _curFrame; }
65  int getFrameCount() const override { return _frameCount; }
66  bool isSeekable() const override { return true; }
67  bool seek(const Audio::Timestamp &time) override;
68  bool setReverse(bool reverse) override;
69  bool isReversed() const override { return _reversed; }
70  bool endOfTrack() const override;
71  const Graphics::Surface *decodeNextFrame() override;
72  const Graphics::Surface *decodeFrame(uint frameNr);
73  const Graphics::Surface *getSurfaceForFrame(uint frameNr) { return &_frameCache[frameNr]; }
74  void addFrameTime(const uint16 timeToAdd) { _frameTime += timeToAdd; }
75  CacheHint getCacheHint() const { return _cacheHint; }
76 
77  protected:
78  Common::Rational getFrameRate() const override { return Common::Rational(1000, _frameTime); }
79 
80  private:
81  struct ChunkInfo {
82  Common::String name;
83  uint16 index;
84  uint32 offset;
85  uint32 compressedSize;
86  uint32 size;
87  byte type;
88  };
89 
90  bool decode(byte *outBuf, uint32 frameSize, Common::ReadStream &inBuf) const;
91 
92  Common::SeekableReadStream *_fileStream;
93  Graphics::PixelFormat _pixelFormat;
94  uint _width, _height, _depth, _frameSize;
95  int _curFrame;
96  uint _frameCount;
97  uint32 _frameTime;
98  Common::Array<ChunkInfo> _chunkInfo;
99  Decompressor *_dec;
100  bool _reversed;
101  bool _compressed;
102 
105  CacheHint _cacheHint;
106  };
107 };
108 
109 } // End of namespace Nancy
110 
111 #endif // NANCY_VIDEO_H
Definition: str.h:59
Definition: surface.h:67
Definition: video_decoder.h:713
Definition: pixelformat.h:138
Definition: timestamp.h:83
Definition: stream.h:745
Definition: rational.h:40
Definition: video_decoder.h:53
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: video.h:41
Definition: decompress.h:35
Definition: stream.h:385
Definition: actionmanager.h:32