openMSX
LaserdiscPlayer.hh
Go to the documentation of this file.
1 #ifndef LASERDISCPLAYER_HH
2 #define LASERDISCPLAYER_HH
3 
5 #include "BooleanSetting.hh"
6 #include "RecordedCommand.hh"
7 #include "EmuTime.hh"
8 #include "Schedulable.hh"
9 #include "DynamicClock.hh"
10 #include "Filename.hh"
12 #include "EventListener.hh"
13 #include "ThrottleManager.hh"
14 #include "outer.hh"
15 
16 namespace openmsx {
17 
18 class PioneerLDControl;
19 class HardwareConfig;
20 class MSXMotherBoard;
21 class OggReader;
22 class LDRenderer;
23 class RawFrame;
24 
26  , private EventListener
28 {
29 public:
30  LaserdiscPlayer(const HardwareConfig& hwConf,
31  PioneerLDControl& ldcontrol);
33 
34  // Called from CassettePort
35  int16_t readSample(EmuTime::param time);
36 
37  // Called from PioneerLDControl
38  void setMuting(bool left, bool right, EmuTime::param time);
39  bool extAck(EmuTime::param /*time*/) const { return ack; }
40  void extControl(bool bit, EmuTime::param time);
41  const RawFrame* getRawFrame() const;
42 
43  template<typename Archive>
44  void serialize(Archive& ar, unsigned version);
45 
46  // video interface
47  MSXMotherBoard& getMotherBoard() { return motherBoard; }
48 
49  enum RemoteState {
55  };
56 
57  enum PlayerState {
63  };
64 
65  enum SeekState {
70  };
71 
72  enum StereoMode {
76  };
77 
81  };
82 private:
83  void setImageName(std::string newImage, EmuTime::param time);
84  const Filename& getImageName() const { return oggImage; }
85  void autoRun();
86 
89  void play(EmuTime::param time);
90  void pause(EmuTime::param time);
91  void stop(EmuTime::param time);
92  void eject(EmuTime::param time);
93  void seekFrame(size_t frame, EmuTime::param time);
94  void stepFrame(bool forwards);
95  void seekChapter(int chapter, EmuTime::param time);
96 
97  // Control from MSX
98 
101  void scheduleDisplayStart(EmuTime::param time);
102  bool isVideoOutputAvailable(EmuTime::param time);
103  void remoteButtonNEC(unsigned code, EmuTime::param time);
104  void submitRemote(RemoteProtocol protocol, unsigned code);
105  void setAck(EmuTime::param time, int wait);
106  size_t getCurrentSample(EmuTime::param time);
107  void createRenderer();
108 
109  // SoundDevice
110  void generateChannels(float** buffers, unsigned num) override;
111  bool updateBuffer(unsigned length, float* buffer,
112  EmuTime::param time) override;
113  float getAmplificationFactorImpl() const override;
114 
115  // Schedulable
116  struct SyncAck final : public Schedulable {
117  friend class LaserdiscPlayer;
118  explicit SyncAck(Scheduler& s) : Schedulable(s) {}
119  void executeUntil(EmuTime::param time) override {
120  auto& player = OUTER(LaserdiscPlayer, syncAck);
121  player.execSyncAck(time);
122  }
123  } syncAck;
124  struct SyncOdd final : public Schedulable {
125  friend class LaserdiscPlayer;
126  explicit SyncOdd(Scheduler& s) : Schedulable(s) {}
127  void executeUntil(EmuTime::param time) override {
128  auto& player = OUTER(LaserdiscPlayer, syncOdd);
129  player.execSyncFrame(time, true);
130  }
131  } syncOdd;
132  struct SyncEven final : public Schedulable {
133  friend class LaserdiscPlayer;
134  explicit SyncEven(Scheduler& s) : Schedulable(s) {}
135  void executeUntil(EmuTime::param time) override {
136  auto& player = OUTER(LaserdiscPlayer, syncEven);
137  player.execSyncFrame(time, false);
138  }
139  } syncEven;
140 
141  void execSyncAck(EmuTime::param time);
142  void execSyncFrame(EmuTime::param time, bool odd);
143  EmuTime::param getCurrentTime() const { return syncAck.getCurrentTime(); }
144 
145  // EventListener
146  int signalEvent(const std::shared_ptr<const Event>& event) override;
147 
148  // VideoSystemChangeListener interface:
149  void preVideoSystemChange() override;
150  void postVideoSystemChange() override;
151 
152  MSXMotherBoard& motherBoard;
153  PioneerLDControl& ldcontrol;
154 
155  struct Command final : RecordedCommand {
156  Command(CommandController& commandController,
157  StateChangeDistributor& stateChangeDistributor,
158  Scheduler& scheduler);
159  void execute(span<const TclObject> tokens, TclObject& result,
160  EmuTime::param time) override;
161  std::string help(const std::vector<std::string>& tokens) const override;
162  void tabCompletion(std::vector<std::string>& tokens) const override;
163  } laserdiscCommand;
164 
165  std::unique_ptr<OggReader> video;
166  Filename oggImage;
167  std::unique_ptr<LDRenderer> renderer;
168 
169  void nextFrame(EmuTime::param time);
170  void setFrameStep();
171  size_t currentFrame;
172  int frameStep;
173 
174  // Audio state
175  DynamicClock sampleClock;
176  EmuTime start;
177  size_t playingFromSample;
178  size_t lastPlayedSample;
179  bool muteLeft, muteRight;
180  StereoMode stereoMode;
181 
182  // Ext Control
183  RemoteState remoteState;
184  EmuTime remoteLastEdge;
185  unsigned remoteBitNr;
186  unsigned remoteBits;
187  bool remoteLastBit;
188  RemoteProtocol remoteProtocol;
189  unsigned remoteCode;
190  bool remoteExecuteDelayed;
191  // Number of v-blank since code was sent
192  int remoteVblanksBack;
193 
194  /* We need to maintain some state for seeking */
195  SeekState seekState;
196 
197  /* frame the MSX has requested to wait for */
198  size_t waitFrame;
199 
200  // pause playing back on reaching wait frame
201  bool stillOnWaitFrame;
202 
203  /* The specific frame or chapter we are seeking to */
204  int seekNum;
205 
206  // For ack
207  bool ack;
208 
209  // State of the video itself
210  bool seeking;
211 
212  PlayerState playerState;
213 
214  enum PlayingSpeed {
215  SPEED_STEP3 = -5, // Each frame is repeated 90 times
216  SPEED_STEP1 = -4, // Each frame is repeated 30 times
217  SPEED_1IN16 = -3, // Each frame is repeated 16 times
218  SPEED_1IN8 = -2, // Each frame is repeated 8 times
219  SPEED_1IN4 = -1, // Each frame is repeated 4 times
220  SPEED_1IN2 = 0,
221  SPEED_X1 = 1,
222  SPEED_X2 = 2,
223  SPEED_X3 = 3
224  };
225  int playingSpeed;
226 
227  // Loading indicator
228  BooleanSetting autoRunSetting;
229  LoadingIndicator loadingIndicator;
230  int sampleReads;
231 };
232 
234 
235 } // namespace openmsx
236 
237 #endif
T length(const vecN< N, T > &x)
Definition: gl_vec.hh:343
bool extAck(EmuTime::param) const
MSXMotherBoard & getMotherBoard()
Definition: span.hh:34
Commands that directly influence the MSX state should send and events so that they can be recorded by...
void extControl(bool bit, EmuTime::param time)
LaserdiscPlayer(const HardwareConfig &hwConf, PioneerLDControl &ldcontrol)
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
A video frame as output by the VDP scanline conversion unit, before any postprocessing filters are ap...
Definition: RawFrame.hh:25
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:15
void setMuting(bool left, bool right, EmuTime::param time)
This class represents a filename.
Definition: Filename.hh:17
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
int16_t readSample(EmuTime::param time)
void serialize(Archive &ar, unsigned version)
Used by a device to indicate when it is loading.
const RawFrame * getRawFrame() const
#define OUTER(type, member)
Definition: outer.hh:38