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
openmsx::HardwareConfig
HardwareConfig
Definition: HardwareConfig.cc:459
openmsx::LaserdiscPlayer::setMuting
void setMuting(bool left, bool right, EmuTime::param time)
Definition: LaserdiscPlayer.cc:754
openmsx::Command::Command
Command(CommandController &controller, std::string_view name)
Definition: Command.cc:53
openmsx::LaserdiscPlayer::RemoteProtocol
RemoteProtocol
Definition: LaserdiscPlayer.hh:78
openmsx::LaserdiscPlayer::SEEK_FRAME
Definition: LaserdiscPlayer.hh:68
openmsx::ResampledSoundDevice
Definition: ResampledSoundDevice.hh:15
openmsx::LaserdiscPlayer::SEEK_NONE
Definition: LaserdiscPlayer.hh:66
openmsx::LaserdiscPlayer::extAck
bool extAck(EmuTime::param) const
Definition: LaserdiscPlayer.hh:39
openmsx::LaserdiscPlayer::PLAYER_PAUSED
Definition: LaserdiscPlayer.hh:61
openmsx::PioneerLDControl
Definition: PioneerLDControl.hh:16
openmsx::LaserdiscPlayer::STEREO
Definition: LaserdiscPlayer.hh:75
openmsx::LaserdiscPlayer::~LaserdiscPlayer
~LaserdiscPlayer()
Definition: LaserdiscPlayer.cc:148
openmsx::LaserdiscPlayer::SeekState
SeekState
Definition: LaserdiscPlayer.hh:65
openmsx::LaserdiscPlayer::serialize
void serialize(Archive &ar, unsigned version)
Definition: LaserdiscPlayer.cc:1032
EventListener.hh
gl::length
T length(const vecN< N, T > &x)
Definition: gl_vec.hh:348
openmsx::LaserdiscPlayer::StereoMode
StereoMode
Definition: LaserdiscPlayer.hh:72
Schedulable.hh
Filename.hh
openmsx::LaserdiscPlayer
Definition: LaserdiscPlayer.hh:25
VideoSystemChangeListener.hh
BooleanSetting.hh
openmsx::LaserdiscPlayer::NEC_BITS_SPACE
Definition: LaserdiscPlayer.hh:54
openmsx::LaserdiscPlayer::RIGHT
Definition: LaserdiscPlayer.hh:74
span
Definition: span.hh:34
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::LaserdiscPlayer::PLAYER_STOPPED
Definition: LaserdiscPlayer.hh:58
openmsx::LaserdiscPlayer::PlayerState
PlayerState
Definition: LaserdiscPlayer.hh:57
OUTER
#define OUTER(type, member)
Definition: outer.hh:38
RecordedCommand.hh
openmsx::LaserdiscPlayer::NEC_BITS_PULSE
Definition: LaserdiscPlayer.hh:53
openmsx::LaserdiscPlayer::extControl
void extControl(bool bit, EmuTime::param time)
Definition: LaserdiscPlayer.cc:176
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:59
openmsx::LaserdiscPlayer
LaserdiscPlayer
Definition: LaserdiscPlayer.cc:1133
openmsx::LaserdiscPlayer::RemoteState
RemoteState
Definition: LaserdiscPlayer.hh:49
openmsx::LaserdiscPlayer::IR_NONE
Definition: LaserdiscPlayer.hh:79
openmsx::LaserdiscPlayer::LEFT
Definition: LaserdiscPlayer.hh:73
openmsx::RawFrame
A video frame as output by the VDP scanline conversion unit, before any postprocessing filters are ap...
Definition: RawFrame.hh:25
openmsx::EventListener
Definition: EventListener.hh:10
ThrottleManager.hh
outer.hh
openmsx::Schedulable
Schedulable
Definition: Schedulable.cc:69
openmsx::LaserdiscPlayer::IR_NEC
Definition: LaserdiscPlayer.hh:80
EmuTime.hh
openmsx::Filename
Filename
Definition: Filename.cc:50
openmsx::LaserdiscPlayer::PLAYER_PLAYING
Definition: LaserdiscPlayer.hh:59
openmsx::LaserdiscPlayer::NEC_HEADER_SPACE
Definition: LaserdiscPlayer.hh:52
openmsx::LaserdiscPlayer::SEEK_WAIT
Definition: LaserdiscPlayer.hh:69
openmsx::HardwareConfig
Definition: HardwareConfig.hh:21
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:133
openmsx::LaserdiscPlayer::REMOTE_HEADER_PULSE
Definition: LaserdiscPlayer.hh:51
openmsx::LaserdiscPlayer::readSample
int16_t readSample(EmuTime::param time)
Definition: LaserdiscPlayer.cc:934
DynamicClock.hh
openmsx::LaserdiscPlayer::REMOTE_IDLE
Definition: LaserdiscPlayer.hh:50
openmsx::Filename
This class represents a filename.
Definition: Filename.hh:17
openmsx::LaserdiscPlayer::SEEK_CHAPTER
Definition: LaserdiscPlayer.hh:67
openmsx::LaserdiscPlayer::getMotherBoard
MSXMotherBoard & getMotherBoard()
Definition: LaserdiscPlayer.hh:47
openmsx::LaserdiscPlayer::getRawFrame
const RawFrame * getRawFrame() const
Definition: LaserdiscPlayer.cc:263
openmsx::VideoSystemChangeListener
Definition: VideoSystemChangeListener.hh:6
openmsx::LaserdiscPlayer::PLAYER_MULTISPEED
Definition: LaserdiscPlayer.hh:60
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::DynamicClock
DynamicClock
Definition: DynamicClock.cc:14
openmsx::PioneerLDControl
PioneerLDControl
Definition: PioneerLDControl.cc:197
openmsx::LaserdiscPlayer::PLAYER_STILL
Definition: LaserdiscPlayer.hh:62
openmsx::LaserdiscPlayer::LaserdiscPlayer
LaserdiscPlayer(const HardwareConfig &hwConf, PioneerLDControl &ldcontrol)
Definition: LaserdiscPlayer.cc:105
ResampledSoundDevice.hh