devctl for cdrom!!!!!!!!

Dear All,

I have problem with working cdrom programming. I can get cdrom (cd audio) data toc but I can’t get the track raw data. I using devctl to access the cdrom. Detail below is my code.

int main(int argc, char** argv)
{
struct _cdrom_read_toc cdtoc;
strcut _cdrom_raw_data rawdata;
int error, fd;

 if(fd = open("/dev/cd0", O_RDONLY)== -1)
 {
     fprintf(stderr,"Error with open device file: %s\n", strerror(errno));
     exit(-1);
 }

 if(error = devctl(fd, DCMD_CAM_CDROMREADTOC, &cdtoc, sizeof(cdtoc), NULL))
 {
     fprintf(stderr,"Get cd toc failure: %s\n", strerror(error));
     exit(-1);
 }

  rawdata.lba  = 0;
  rawdata.nsectors = 14494;      //the second track start at 3:13:19
  rawdata.mode = CDDA;
  if(error = devctl(fd, CDMD_CAM_CDROMREAD, &rawdata, sizeof(rawdata), NULL))
  {
       fprintf(stderr,"Get cd raw data failure: %s\n", strerror(error));
       exit(-1);
  }
  .......
  ......

}

The output srceen show:
Get cd raw data failure: Invalid argument

Or I use read function to get data but the result still the same


char buf[2352];
int addr;


//after get cd toc

addr = 150; // The frist track start at 0:2:0
lseek(fd, addr * 2352, SEEK_SET);
error = read(fd, buf, sizeof(buf));
if(error != 2352)
{
fprintf(stderr,“Reading cd raw data failure: %s\n”, strerror(errno));
exit(-1);
}

Output show:
Reading cd raw data failure: Invalid argument

I don’t what worng in here. Please help me solve this problem. Thank you very much.

Can I using ioctl in here? I have searched long time on internet but don’t have guide for this issue. ioctl only using on Linux version right?

Please help me. Thank you.
James

Dear All,

I have problem with working cdrom programming. I can get cdrom (cd audio) data toc but I can’t get the track raw data. I using devctl to access the cdrom. Detail below is my code.

int main(int argc, char** argv)
{
struct _cdrom_read_toc cdtoc;
strcut _cdrom_raw_data rawdata;
int error, fd;

 if(fd = open("/dev/cd0", O_RDONLY)== -1)
 {
     fprintf(stderr,"Error with open device file: %s\n", strerror(errno));
     exit(-1);
 }

 if(error = devctl(fd, DCMD_CAM_CDROMREADTOC, &cdtoc, sizeof(cdtoc), NULL))
 {
     fprintf(stderr,"Get cd toc failure: %s\n", strerror(error));
     exit(-1);
 }

  rawdata.lba  = 0;
  rawdata.nsectors = 14494;      //the second track start at 3:13:19
  rawdata.mode = CDDA;
  if(error = devctl(fd, CDMD_CAM_CDROMREAD, &rawdata, sizeof(rawdata), NULL))
  {
       fprintf(stderr,"Get cd raw data failure: %s\n", strerror(error));
       exit(-1);
  }
  .......
  ......

}

The output srceen show:
Get cd raw data failure: Invalid argument

Or I use read function to get data but the result still the same


char buf[2352];
int addr;


//after get cd toc

addr = 150; // The frist track start at 0:2:0
lseek(fd, addr * 2352, SEEK_SET);
error = read(fd, buf, sizeof(buf));
if(error != 2352)
{
fprintf(stderr,“Reading cd raw data failure: %s\n”, strerror(errno));
exit(-1);
}

Output show:
Reading cd raw data failure: Invalid argument

I don’t what worng in here. Please help me solve this problem. Thank you very much.

Can I using ioctl in here? I have searched long time on internet but don’t have guide for this issue. ioctl only using on Linux version right?

Please help me. Thank you.
James

The problem is your CDROM drive doesn’t support the feature that the QNX CDROMREAD command uses for raw data extraction. You will need to use tools like cdda2wav or paranoia.

Thank you for your reply.

But my problem is I want to get data by coding(Programming API function) not using tool to get it. I mean is : now iam developing a tool like cdda2wav.

Do you know can I access(read) cdrom data by using ioctl or read function. If done. Please let me know where (???.h file )I can find the command for cdrom of ioctl define.

Thank you so much.
James

Unless you use a different cdrom drive, you will need to use the same methods that cdda2wav uses (sending SCSI messages to the drive?).

I think this is not cdrom drive wrong! Because this can get data and play cd audio nomally.

Have you attemp using (open(),read()) function to access the cd device file. Because if I can get the start position for a track then I can get data by read() function right?

Ex: if first track start at 0:2:0 mean at 2 seconds so I can caculate the
start offset for read() at addr = 2752352 = 352800.

And then I can using read function begin to get each time 2352 bytes data from it right?

lseek(fd,addr, SEEK_SET); //fd=open("/dev/cd0", O_RDONLY);
read(fd, data, sizeof(data)); //char data[2532];

Why this also un-implementable by return a error code : Invalid argument?
If could please let me know more detial.

Thank you very much.
James

There is a particular cd drive feature for extracting audio data which the CDROMREAD command uses. and not all drives support it. A read() will most likely end up using that command so you get the same error as when using devctl directly.

When playing a CD, the drive just sends the analog/digital audio data straight to the soundcard, unless the software reads the raw data so it can apply an equaliser, draw a scope, whatever. I think QNX 6.3 does digital extraction by default now, without using the CDROMREAD command, so you may be able to use the audiocdda.so plugin (or whatever it’s called). Otherwise you’ll need to skip that devctl command and find out how to use the lower level access methods.