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
37namespace Graphics {
38struct Surface;
39}
40
41namespace Video {
42class VideoDecoder;
43}
44
45namespace Nancy {
46
47class 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.
57public:
60
61 // Load <name> + ".avf"/".bik" and create the matching decoder. videoPlaytype
62 // picks the container, falling back to the other one if its file is missing.
63 // bidirectionalCache enables fast bidirectional scrubbing; pass it only for
64 // scrubbed panorama scenes. screenFormat decodes Bink frames in the screen
65 // format instead of the input format; only for opaque videos, since the
66 // transparent color is defined in the input format.
67 bool loadFile(const Common::Path &name, byte videoPlaytype = kVideoPlaytypeAuto, bool bidirectionalCache = false, bool screenFormat = false);
68 bool isVideoLoaded() const;
69 void close();
70 Video::VideoDecoder *getDecoder() { return _decoder.get(); }
71
72 // Playback control - forwarded to the decoder.
73 void start();
74 void stop();
75 void pauseVideo(bool pause);
76 bool isPlaying() const;
77 bool needsUpdate() const;
78 bool endOfVideo() const; // AVF uses AVFDecoder::atEnd()
79
80 void seekToFrame(uint frame);
81 void seek(const Audio::Timestamp &time);
82 void rewind();
83 void setRate(const Common::Rational &rate);
84 Common::Rational getRate() const;
85 void setReverse(bool reverse);
86
87 int getCurFrame() const;
88 int getFrameCount() const;
89 Audio::Timestamp getDuration() const;
90 uint16 getWidth() const;
91 uint16 getHeight() const;
92 void addFrameTime(uint16 timeToAdd); // AVF only, no-op otherwise
93
94 // Sets the volume of the movie's audio track, as a percentage (0 - 100).
95 void setVolume(byte percent);
96
97 // Loaded movies are registered under their filename, so SetMovieVolume
98 // (Nancy14 AR 150) can address one that is already playing by name.
99 static MoviePlayer *findLoadedMovie(const Common::Path &name);
100
101 // Decode a frame: frameNr < 0 returns the next frame; otherwise that
102 // specific frame via the format-appropriate cached path (AVF decodeFrame;
103 // Bink decodes forward when possible and caches frames, see _frameCache).
104 const Graphics::Surface *decodeNextFrame(int frameNr = -1);
105
106 // --- Optional simple frame-range player, built on the above. Handy for
107 // consumers (e.g. BoardGamePuzzle) that just want to show a still frame or
108 // play [first, last] over time. Uses its own, no-skip timing so it starts
109 // immediately and stays smooth, and decodes into an internal surface.
110 void goToFrame(int frameNr); // show a single still frame
111 void playRange(int first, int last); // begin timed playback (reverse if last < first)
112 bool update(); // advance; true if the shown frame changed
113 bool isRangePlaying() const { return _rangePlaying; }
114 int getCurrentFrame() const { return getCurFrame(); }
115 void drawFrame(Graphics::ManagedSurface &dst, const Common::Point &pos) const;
116 void drawFrame(Graphics::ManagedSurface &dst, const Common::Rect &source, const Common::Point &pos) const; // a part of it
117
118private:
119 friend class BinkCacheLoader;
120
121 static byte resolvePlaytype(byte videoPlaytype); // resolves kVideoPlaytypeAuto
122
123 void storeCurrentFrame();
124 void freeFrameCache();
125 void unregisterMovie();
126 bool fillNextCacheFrame(); // decode one uncached frame; true when the cache is full
127
129 byte _videoType = kVideoPlaytypeAVF;
130
131 // Name this movie was loaded with; used by findLoadedMovie().
132 Common::Path _loadedName;
133
134 // Decoded-frame cache for the Bink path (AVF caches internally). Bink seeking
135 // re-decodes from the previous keyframe, so caching keeps panorama scrubbing
136 // fast. Enabled only when loadFile() is asked for a bidirectional cache; the
137 // whole cache is then filled forward (the fast direction) in spare time by a
138 // deferred loader, so even the first turn is smooth.
139 bool _useFrameCache = false;
142 uint _cacheFillNext = 0;
143
144 // Simple frame-range player state. _currentSurface points at the decoder's
145 // last-decoded frame (owned by it, valid until the next decode).
146 const Graphics::Surface *_currentSurface = nullptr;
147 int _rangeLast = 0;
148 int _step = 1;
149 bool _rangePlaying = false;
150 uint32 _lastFrameTime = 0;
151 uint32 _frameDelayMs = 66;
152};
153
154} // End of namespace Nancy
155
156#endif // NANCY_MOVIEPLAYER_H
Definition: timestamp.h:83
Definition: path.h:52
Definition: rational.h:40
PointerType get() const
Definition: ptr.h:637
Definition: ptr.h:159
Definition: managed_surface.h:51
Definition: movieplayer.h:56
Definition: video_decoder.h:53
Definition: formatinfo.h:28
Definition: actionmanager.h:32
Definition: rect.h:144
Definition: rect.h:536
Definition: surface.h:67