PDA

View Full Version : How to read a CD



skepticalgeek
21st March 2010, 10:40
I am developing a Qt application that needs to read from the CD drive, specifically audio CDs. I have included libkcompactdisc and have created a KCompactDisc object. It sees the drive and identifies the drive name, manufacturer, etc. but cannot see the disc in the drive. The OS knows there is a disc in the drive. Every other application on the system sees the CD. But the KCompactDisc object tells me there is no disc. In the rather sparse documentation for this library, I noticed there were functions for Disc Title, Disc Length, and others, as well as commands for play, stop, etc. But there does not seem to be a read or load command. SO HOW DO I GET THE OBJECT TO READ THE FREAKING DISC??? Sorry for shouting but I am going crazy here. Here is the code snippet I am using.



Disc = new KCompactDisc(KCompactDisc::Synchronous);
Disc->setAutoMetadataLookup(true);
x = Disc->setDevice(Disc->defaultCdromDeviceName(),50,true,Disc->audioSystems().at(0));
QObject::connect(Disc,SIGNAL(discInformation(KComp actDisc::DiscInfo)),this,SLOT(DisplayDiscInfo(KCom pactDisc::DiscInfo)));
ui->txtCDInfo->setText(Disc->defaultCdromDeviceName() + "\n"
+ Disc->discArtist() + "\n" +
Disc->discTitle() + "\n" +
"Disc ID: " + QString::number(Disc->discId()) + "\n"
+ "Disc Length: " + QString::number(Disc->discLength()));

The text box shows the name of the drive, blank lines for the artist and title, and zeroes for Disc ID and Length. When I set a breakpoint at the last line and look at the object, the Disc Status is no disc. Any insight you guys can provide would be appreciated. Thanks.

wysota
21st March 2010, 11:03
What is the device name returned by defaultCdromDeviceName()? By the way, the method is static. Please also check that deviceName(), deviceModel(), deviceVendor() and deviceRevision() match what you would expect. Maybe you are just reading the wrong drive.

Calling refreshListOfCdromDevices() prior to doing all that might help too.

skepticalgeek
21st March 2010, 18:52
Thanks. I should have included more information about the system and the drive. This is a netbook running Ubuntu Netbook Remix. It has one CD drive, an external dvd-rw from Gear Head. The information provided by the KCompactDisc calls is this:

Device Name: [DVDRW - Slimtype - DVD A DS8A4S]
Device Model: DVD A DS8A4S
Device Vendor: Slimtype
Device Revision:

Also, where is the refreshListOfCdromDevices() call located. It doesn't seem to be in KCompactDisc.

squidge
21st March 2010, 20:41
Last time I needed to read a cdrom I never bothered with any library. I used the 'proc' fs to figure out the device name and then read that device directly (eg. open("/dev/sdc",O_RDONLY)).

wysota
21st March 2010, 21:06
Thanks. I should have included more information about the system and the drive. This is a netbook running Ubuntu Netbook Remix. It has one CD drive, an external dvd-rw from Gear Head. The information provided by the KCompactDisc calls is this:

Device Name: [DVDRW - Slimtype - DVD A DS8A4S]
Device Model: DVD A DS8A4S
Device Vendor: Slimtype
Device Revision:
What about the UDI/URI?


Also, where is the refreshListOfCdromDevices() call located. It doesn't seem to be in KCompactDisc.
Hmm... I can't find it now. Maybe it was a private function/method...

skepticalgeek
21st March 2010, 22:13
Device UDI: /org/freedesktop/Hal/devices/storage_serial_Slimtype_DVD_A_DS8A4S_FFFFFFFE0D912 150372883_0_0
Device URL: file:///dev/sr0

Thanks for the feedback. Basically, I want to read the artist information, trqack offsets, and other information I need to get the CD information from freedb. This project is a jukebox program with an integrated CD ripper, or at least it will be once I figure out how to read the CD.

wysota
21st March 2010, 23:24
The data seems fine. Solid seems to be working and returning proper data. If I had to guess, I would say the problem is the data arrives asynchronously and you have to wait for the discInformation() or discChanged() signal. If you get them (you might have to reinsert the disc into the drive) then you know you get proper information and can try to read them.

You can also try calling metadataLookup() after setting the device. Just bouncing off ideas... I'm running out of them anyway, the class is quite simple, there is hardly anything that could fail here. Could you try preparing a minimal compilable example reproducing the problem? Just please keep it minimal and compilable ;)

By the way, I found the refreshListOfCdromDevices() function. It's a static function in libkcompactdisc.cpp.

skepticalgeek
22nd March 2010, 08:27
Solved it. Turns out I trued when I should have falsed. In the line:
x = Disc->setDevice(Disc->defaultCdromDeviceName(),50,true,Disc->audioSystems().at(0));

the parameter true should be false. Once I changeThanks for all the help.