aboutsummaryrefslogtreecommitdiff
path: root/backends/audiocd/linux
diff options
context:
space:
mode:
authorMatthew Hoops2015-10-06 22:10:34 -0400
committerJohannes Schickel2016-03-13 13:57:19 +0100
commitaa6ff444408bfd17bcca1d8364e86ce62da327ef (patch)
tree5990ede855749a13faeaa8b381320cb4e0b4cfa1 /backends/audiocd/linux
parentdc0d4fcf303458e9044866dd05a30c317e07eef0 (diff)
downloadscummvm-rg350-aa6ff444408bfd17bcca1d8364e86ce62da327ef.tar.gz
scummvm-rg350-aa6ff444408bfd17bcca1d8364e86ce62da327ef.tar.bz2
scummvm-rg350-aa6ff444408bfd17bcca1d8364e86ce62da327ef.zip
BACKENDS: Only expose one set of functions for AudioCDManager
Engines should only have to call one set of functions and not decide between the two. In fact, the 'emulation' API was documented to just call the 'real CD' API.
Diffstat (limited to 'backends/audiocd/linux')
-rw-r--r--backends/audiocd/linux/linux-audiocd.cpp68
1 files changed, 42 insertions, 26 deletions
diff --git a/backends/audiocd/linux/linux-audiocd.cpp b/backends/audiocd/linux/linux-audiocd.cpp
index fe3ae1e58b..a835ade218 100644
--- a/backends/audiocd/linux/linux-audiocd.cpp
+++ b/backends/audiocd/linux/linux-audiocd.cpp
@@ -252,11 +252,12 @@ public:
LinuxAudioCDManager();
~LinuxAudioCDManager();
- bool openCD(int drive);
- void closeCD();
- void playCD(int track, int numLoops, int startFrame, int duration);
+ bool open();
+ void close();
+ bool play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate = false);
protected:
+ bool openCD(int drive);
bool openCD(const Common::String &drive);
private:
@@ -301,22 +302,40 @@ LinuxAudioCDManager::LinuxAudioCDManager() {
}
LinuxAudioCDManager::~LinuxAudioCDManager() {
- closeCD();
+ close();
}
-bool LinuxAudioCDManager::openCD(int drive) {
- closeCD();
+bool LinuxAudioCDManager::open() {
+ close();
+
+ if (openRealCD())
+ return true;
+
+ return DefaultAudioCDManager::open();
+}
+
+void LinuxAudioCDManager::close() {
+ DefaultAudioCDManager::close();
+
+ if (_fd < 0)
+ return;
+
+ ::close(_fd);
+ memset(&_tocHeader, 0, sizeof(_tocHeader));
+ _tocEntries.clear();
+}
+bool LinuxAudioCDManager::openCD(int drive) {
DeviceList devices = scanDevices();
if (drive >= (int)devices.size())
return false;
- _fd = open(devices[drive].name.c_str(), O_RDONLY | O_NONBLOCK, 0);
+ _fd = ::open(devices[drive].name.c_str(), O_RDONLY | O_NONBLOCK, 0);
if (_fd < 0)
return false;
if (!loadTOC()) {
- closeCD();
+ close();
return false;
}
@@ -328,44 +347,39 @@ bool LinuxAudioCDManager::openCD(const Common::String &drive) {
if (!tryAddDrive(devices, drive) && !tryAddPath(devices, drive))
return false;
- _fd = open(devices[0].name.c_str(), O_RDONLY | O_NONBLOCK, 0);
+ _fd = ::open(devices[0].name.c_str(), O_RDONLY | O_NONBLOCK, 0);
if (_fd < 0)
return false;
if (!loadTOC()) {
- closeCD();
+ close();
return false;
}
return true;
}
-void LinuxAudioCDManager::closeCD() {
- if (_fd < 0)
- return;
-
- stop();
- close(_fd);
- memset(&_tocHeader, 0, sizeof(_tocHeader));
- _tocEntries.clear();
-}
+bool LinuxAudioCDManager::play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate) {
+ // Prefer emulation
+ if (DefaultAudioCDManager::play(track, numLoops, startFrame, duration, onlyEmulate))
+ return true;
-void LinuxAudioCDManager::playCD(int track, int numLoops, int startFrame, int duration) {
- // Stop any previous track
- stop();
+ // If we're set to only emulate, or have no CD drive, return here
+ if (onlyEmulate || _fd < 0)
+ return false;
// HACK: For now, just assume that track number is right
// That only works because ScummVM uses the wrong track number anyway
if (track >= (int)_tocEntries.size() - 1) {
warning("No such track %d", track);
- return;
+ return false;
}
// Bail if the track isn't an audio track
if ((_tocEntries[track].cdte_ctrl & 0x04) != 0) {
warning("Track %d is not audio", track);
- return;
+ return false;
}
// Create the AudioStream and play it
@@ -388,6 +402,8 @@ void LinuxAudioCDManager::playCD(int track, int numLoops, int startFrame, int du
_cd.balance,
DisposeAfterUse::YES,
true);
+
+ return true;
}
LinuxAudioCDManager::DeviceList LinuxAudioCDManager::scanDevices() {
@@ -421,13 +437,13 @@ bool LinuxAudioCDManager::tryAddDrive(DeviceList &devices, const Common::String
return true;
// Try opening the device and seeing if it is a CD-ROM drve
- int fd = open(drive.c_str(), O_RDONLY | O_NONBLOCK, 0);
+ int fd = ::open(drive.c_str(), O_RDONLY | O_NONBLOCK, 0);
if (fd >= 0) {
cdrom_subchnl info;
info.cdsc_format = CDROM_MSF;
bool isCD = ioctl(fd, CDROMSUBCHNL, &info) == 0 || isTrayEmpty(errno);
- close(fd);
+ ::close(fd);
if (isCD) {
devices.push_back(Device(drive, device));
return true;