ScummVM API documentation
vqa_player.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 BLADERUNNER_VQA_PLAYER_H
23#define BLADERUNNER_VQA_PLAYER_H
24
25#include "bladerunner/vqa_decoder.h"
26
27#include "audio/audiostream.h"
28#include "audio/mixer.h"
29
30#include "graphics/surface.h"
31
32namespace BladeRunner {
33
34enum LoopSetModes {
35 kLoopSetModeJustStart = 0, // sets _frameBeginNext, _repeatsCount, _frameEnd
36 kLoopSetModeEnqueue = 1, // sets _frameBeginNext, _repeatsCountQueued, _frameEndQueued
37 kLoopSetModeImmediate = 2 // like ModeJustStart, but also sets _frameNext to _frameBeginNext and updates _frameNextTime to current
38};
39
40class BladeRunnerEngine;
41class View;
42class Lights;
43class ZBuffer;
44
45class VQAPlayer {
46 friend class Debugger;
47 friend class OuttakePlayer;
48
50 Common::String _name;
52 VQADecoder _decoder;
53 Audio::QueuingAudioStream *_audioStream;
54 Graphics::Surface *_surface;
55
56 static const uint32 kVqaFrameTimeDiff = 4000; // 60 * 1000 / 15
57 static const int kMaxAudioPreloadedFrames = 15;
58 // Use speech sound type as in original engine
60
61 int _frame;
62 int _frameNext;
63 int _frameBeginNext; // The frame to begin from, after current playing loop ends.
64 // Does not necessarily reflect current playing loop's start frame
65 int _frameEnd; // The frame to end at for current playing loop
66 int _loopIdTarget; // Does not necessarily reflect current playing loop's id (for a queue of loops this will have the id of the last one in the queue)
67 // Used: - as param for _callbackLoopEnded() (which typically is loopEnded()), but never actually used in there)
68 // - for the MA05 inshot glitch workaround
69 // It is set at every setLoop call except for the _loopInitial case (when no video stream is loaded)
70 int _repeatsCount; // -1 loop forever
71 // 0 final repetition (or don't repeat after playing)
72 // When that repetition is completeed VQAPlayer::update() returns -3 value
73 // See Scene::advanceFrame() and OuttakePlayer::play() for checks for -3 result
74 // Value is decreased per completed loop of current playing videoloop until it reaches 0
75
76 int _repeatsCountQueued;
77 int _frameEndQueued;
78
79 int _lastAudioFrameSuccessfullyQueued;
80
81 int _loopIdInitial;
82 int _repeatsCountInitial;
83
84 uint32 _frameNextTime;
85 bool _hasAudio;
86 bool _audioStarted;
87 Audio::SoundHandle _soundHandle;
88
89 bool _specialPS15GlitchFix;
90 bool _specialUG18DoNotRepeatLastLoop;
91
92 void (*_callbackLoopEnded)(void *, int frame, int loopId);
93 void *_callbackData;
94
95public:
96
98 : _vm(vm),
99 _name(name),
100 _s(nullptr),
101 _surface(surface),
102 _decoder(),
103 _audioStream(nullptr),
104 _frame(-1),
105 _frameNext(-1),
106 _frameBeginNext(-1),
107 _frameEnd(-1),
108 _loopIdTarget(-1),
109 _repeatsCount(-1),
110 _repeatsCountQueued(-1),
111 _frameEndQueued(-1),
112 _lastAudioFrameSuccessfullyQueued(-1),
113 _loopIdInitial(-1),
114 _repeatsCountInitial(-1),
115 _frameNextTime(0),
116 _hasAudio(false),
117 _audioStarted(false),
118 _specialPS15GlitchFix(false),
119 _specialUG18DoNotRepeatLastLoop(false),
120 _callbackLoopEnded(nullptr),
121 _callbackData(nullptr) { }
122
123 ~VQAPlayer() {
124 close();
125 }
126
127 bool open();
128 void close();
129
130 bool loadVQPTable(const Common::String& vqpResName);
131
132 int update(bool forceDraw = false, bool advanceFrame = true, bool useTime = true, Graphics::Surface *customSurface = nullptr);
133 void updateZBuffer(ZBuffer *zbuffer);
134 void updateView(View *view);
135 void updateScreenEffects(ScreenEffects *screenEffects);
136 void updateLights(Lights *lights);
137
138 bool setBeginAndEndFrame(int begin, int end, int repeatsCount, int loopSetMode, void(*callback)(void *, int, int), void *callbackData);
139 bool setLoop(int loopId, int repeatsCount, int loopSetMode, void(*callback)(void*, int, int), void *callbackData);
140
141 bool seekToFrame(int frame);
142
143 bool getCurrentBeginAndEndFrame(int frame, int *begin, int *end);
144 int getLoopBeginFrame(int loopId);
145 int getLoopEndFrame(int loopId);
146
147 int getLoopIdTarget() const { return _loopIdTarget; };
148
149 int getFrameCount() const;
150
151 int getQueuedAudioFrames() const;
152
153private:
154 void queueAudioFrame(Audio::AudioStream *audioStream);
155};
156
157} // End of namespace BladeRunner
158
159#endif
Definition: audiostream.h:50
SoundType
Definition: mixer.h:73
@ kSpeechSoundType
Definition: mixer.h:78
Definition: audiostream.h:370
Definition: mixer.h:49
Definition: bladerunner.h:113
Definition: debugger.h:56
Definition: lights.h:33
Definition: outtake.h:33
Definition: screen_effects.h:39
Definition: vqa_decoder.h:56
Definition: vqa_player.h:45
Definition: view.h:33
Definition: zbuffer.h:49
Definition: stream.h:745
Definition: str.h:59
Definition: surface.h:67