ScummVM API documentation
movieplayer.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_MOVIEPLAYER_H
23 #define NANCY_MOVIEPLAYER_H
24 
25 #include "common/array.h"
26 #include "common/ptr.h"
27 #include "common/path.h"
28 #include "common/rational.h"
29 #include "common/rect.h"
30 
31 #include "audio/timestamp.h"
32 
33 #include "graphics/managed_surface.h"
34 
35 #include "engines/nancy/commontypes.h"
36 
37 namespace Graphics {
38 struct Surface;
39 }
40 
41 namespace Video {
42 class VideoDecoder;
43 }
44 
45 namespace Nancy {
46 
47 class DeferredLoader;
48 
49 // The single low-level interface to the AVF/Bink video decoders. Every consumer
50 // (PlaySecondaryMovie, PlaySecondaryVideo, Conversation, Viewport, Map,
51 // BoardGamePuzzle, ...) owns one of these instead of a raw Video::VideoDecoder,
52 // so the AVF-vs-Bink specifics (decoder creation, .avf/.bik file selection, and
53 // the AVF-only behaviour of decodeFrame/addFrameTime/endOfVideo) live in one
54 // place. All other methods forward 1:1 to the underlying decoder, so playback
55 // behaviour is unchanged; higher-level playback/timing logic stays per consumer.
56 class MoviePlayer {
57 public:
58  MoviePlayer();
59  ~MoviePlayer();
60 
61  // Load <name> + ".avf"/".bik", auto-detecting the format from which file
62  // exists (AVF preferred if both do) and creating the matching decoder.
63  // bidirectionalCache enables fast bidirectional scrubbing; pass it only for
64  // scrubbed panorama scenes.
65  bool loadFile(const Common::Path &name, bool bidirectionalCache = false);
66  bool isVideoLoaded() const;
67  void close();
68  Video::VideoDecoder *getDecoder() { return _decoder.get(); }
69 
70  // Playback control - forwarded to the decoder.
71  void start();
72  void stop();
73  void pauseVideo(bool pause);
74  bool isPlaying() const;
75  bool needsUpdate() const;
76  bool endOfVideo() const; // AVF uses AVFDecoder::atEnd()
77 
78  void seekToFrame(uint frame);
79  void seek(const Audio::Timestamp &time);
80  void rewind();
81  void setRate(const Common::Rational &rate);
82  Common::Rational getRate() const;
83  void setReverse(bool reverse);
84 
85  int getCurFrame() const;
86  int getFrameCount() const;
87  Audio::Timestamp getDuration() const;
88  uint16 getWidth() const;
89  uint16 getHeight() const;
90  void addFrameTime(uint16 timeToAdd); // AVF only, no-op otherwise
91 
92  // Decode a frame: frameNr < 0 returns the next frame; otherwise that
93  // specific frame via the format-appropriate cached path (AVF decodeFrame;
94  // Bink decodes forward when possible and caches frames, see _frameCache).
95  const Graphics::Surface *decodeNextFrame(int frameNr = -1);
96 
97  // --- Optional simple frame-range player, built on the above. Handy for
98  // consumers (e.g. BoardGamePuzzle) that just want to show a still frame or
99  // play [first, last] over time. Uses its own, no-skip timing so it starts
100  // immediately and stays smooth, and decodes into an internal surface.
101  void goToFrame(int frameNr); // show a single still frame
102  void playRange(int first, int last); // begin timed playback (reverse if last < first)
103  bool update(); // advance; true if the shown frame changed
104  bool isRangePlaying() const { return _rangePlaying; }
105  int getCurrentFrame() const { return getCurFrame(); }
106  void drawFrame(Graphics::ManagedSurface &dst, const Common::Point &pos) const;
107 
108 private:
109  friend class BinkCacheLoader;
110 
111  void storeCurrentFrame();
112  void freeFrameCache();
113  bool fillNextCacheFrame(); // decode one uncached frame; true when the cache is full
114 
116  byte _videoType = kVideoPlaytypeAVF;
117 
118  // Decoded-frame cache for the Bink path (AVF caches internally). Bink seeking
119  // re-decodes from the previous keyframe, so caching keeps panorama scrubbing
120  // fast. Enabled only when loadFile() is asked for a bidirectional cache; the
121  // whole cache is then filled forward (the fast direction) in spare time by a
122  // deferred loader, so even the first turn is smooth.
123  bool _useFrameCache = false;
126  uint _cacheFillNext = 0;
127 
128  // Simple frame-range player state. _currentSurface points at the decoder's
129  // last-decoded frame (owned by it, valid until the next decode).
130  const Graphics::Surface *_currentSurface = nullptr;
131  int _rangeLast = 0;
132  int _step = 1;
133  bool _rangePlaying = false;
134  uint32 _lastFrameTime = 0;
135  uint32 _frameDelayMs = 66;
136 };
137 
138 } // End of namespace Nancy
139 
140 #endif // NANCY_MOVIEPLAYER_H
Definition: managed_surface.h:51
Definition: surface.h:67
Definition: movieplayer.h:56
Definition: path.h:52
Definition: timestamp.h:83
Definition: rational.h:40
Definition: video_decoder.h:53
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: ptr.h:159
Definition: animation.h:37
Definition: actionmanager.h:32