00001 #include <cdaudio.h>
00002 #include "audiere.h"
00003 #include "debug.h"
00004 #include "internal.h"
00005 #include "utility.h"
00006
00007
00008 namespace audiere {
00009
00010 class CDDeviceUnix : public RefImplementation<CDDevice> {
00011 public:
00012 CDDeviceUnix(int device, const char* name) {
00013 m_device = device;
00014 m_name = name;
00015 }
00016
00017 ~CDDeviceUnix() {
00018 stop();
00019 cd_finish(m_device);
00020 }
00021
00022 const char* ADR_CALL getName() {
00023 return m_name.c_str();
00024 }
00025
00026 int ADR_CALL getTrackCount() {
00027 disc_info disc;
00028 if (cd_stat(m_device, &disc) == -1) {
00029 return 0;
00030 }
00031
00032 if (containsCD()) {
00033 return disc.disc_total_tracks;
00034 } else {
00035 return 0;
00036 }
00037 }
00038
00039 void ADR_CALL play(int track) {
00040 cd_play_track(m_device, track + 1, track + 1);
00041 }
00042
00043 void ADR_CALL stop() {
00044 cd_stop(m_device);
00045 }
00046
00047 void ADR_CALL pause() {
00048 cd_pause(m_device);
00049 }
00050
00051 void ADR_CALL resume() {
00052 cd_resume(m_device);
00053 }
00054
00055 bool ADR_CALL isPlaying() {
00056 disc_info disc;
00057 if (cd_stat(m_device, &disc) == -1) {
00058 return false;
00059 }
00060
00061 return disc.disc_mode == CDAUDIO_PLAYING;
00062 }
00063
00064 bool ADR_CALL containsCD() {
00065 disc_info disc;
00066 if (cd_stat(m_device, &disc) == -1) {
00067 return false;
00068 }
00069
00070 return disc.disc_present != 0;
00071 }
00072
00073 bool ADR_CALL isDoorOpen() {
00074 ADR_LOG("Warning: libcdaudio does not allow checking the door status.");
00075 return false;
00076 }
00077
00078 void ADR_CALL openDoor() {
00079 cd_eject(m_device);
00080 }
00081
00082 void ADR_CALL closeDoor() {
00083 cd_close(m_device);
00084 }
00085
00086 private:
00087 int m_device;
00088 std::string m_name;
00089 };
00090
00091
00092 ADR_EXPORT(const char*) AdrEnumerateCDDevices() {
00093
00094 return "";
00095 }
00096
00097 ADR_EXPORT(CDDevice*) AdrOpenCDDevice(const char* name) {
00098
00099 int device = cd_init_device(const_cast<char*>(name));
00100 if (device == -1) {
00101 return 0;
00102 } else {
00103 return new CDDeviceUnix(device, name);
00104 }
00105 }
00106
00107 }