1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
int main(int argc, char *argv[]) {
/** Programme who should play the first track from an CD with ioctl(...) calls */
int fd ;
struct cdrom_tochdr table_of_content_headers ; // First && Last Track infos.
struct cdrom_tocentry table_of_content_entries ; // Offsets every track on the CD.
struct cdrom_msf msf_playing_data_structur ; // Used by CDROMPLAYMSF to set the Start and playing End.
struct cdrom_subchnl playing_data_informations ; // Keep status, current position min,sec,frame infos...
if ((fd=open("/dev/cdrom",O_RDONLY)) == -1) {
perror("Error open device") ;
exit(EXIT_FAILURE) ;
}
fprintf(stdout,"Press any key to initialise the CD...\n") ;
getchar() ;
if ( ioctl(fd, CDROMREADTOCHDR, &table_of_content_headers) == -1) {
perror("ioctl read cdrom T.O.C headers error") ;
exit(EXIT_FAILURE) ;
}
uint8_t first = table_of_content_headers.cdth_trk0 ; // First track from the CD number.
uint8_t last = table_of_content_headers.cdth_trk1 ; // Last track from the CD number.
table_of_content_entries.cdte_track = first ; // We set the first track to get Table of Content offset for playing starting offset.
table_of_content_entries.cdte_format = CDROM_MSF ; // Set the format.
if ( ioctl(fd, CDROMREADTOCENTRY, &table_of_content_entries) == -1) {
perror("ioctl read cdrom T.O.C entries error") ;
exit(EXIT_FAILURE) ;
}
msf_playing_data_structur.cdmsf_min0=table_of_content_entries.cdte_addr.msf.minute ; // Set playing the start offset.
msf_playing_data_structur.cdmsf_sec0=table_of_content_entries.cdte_addr.msf.second ; // Set playing the start offset.
msf_playing_data_structur.cdmsf_frame0=table_of_content_entries.cdte_addr.msf.frame ; // Set playing the start offset.
table_of_content_entries.cdte_track = first+1 ; // We set the second track to get Table of Content offset for playing end offset. /** Alternative: CD end definition CDROM_LEADOUT */
table_of_content_entries.cdte_format = CDROM_MSF ; // Playing management format.
if ( ioctl(fd, CDROMREADTOCENTRY, &table_of_content_entries) == -1) {
perror("ioctl read cdrom T.O.C entries error") ;
exit(EXIT_FAILURE) ;
}
msf_playing_data_structur.cdmsf_min1=table_of_content_entries.cdte_addr.msf.minute ; // Set playing the end offset.
msf_playing_data_structur.cdmsf_sec1=table_of_content_entries.cdte_addr.msf.second ; // Set playing the end offset.
msf_playing_data_structur.cdmsf_frame1=table_of_content_entries.cdte_addr.msf.frame ; // Set playing the end offset.
fprintf(stdout,"Press any key to ear the first track...\n") ;
getchar() ;
if ( ioctl(fd, CDROMPLAYMSF, &msf_playing_data_structur) == -1) {
perror("ioctl cdrom playing error") ;
exit(EXIT_FAILURE) ;
}
playing_data_informations.cdsc_format=CDROM_MSF ;
if ( ioctl(fd, CDROMSUBCHNL, &playing_data_informations) == -1) {
perror("ioctl cdrom get informations error") ;
exit(EXIT_FAILURE) ;
}
while (playing_data_informations.cdsc_audiostatus != CDROM_AUDIO_COMPLETED ) {
/* This part is experimental because i cannot play the CD from this programme actually */
/** Get
*
* playing_data_informations.cdsc_audiostatus
*
* values with command:
*
* $ grep AUDIO_ /usr/include/linux/cdrom.h
* ******************************************/
fprintf(stdout,"Press any key to pause the CD...\n") ;
getchar() ;
if ( ioctl(fd, CDROMPAUSE) == -1) {
perror("ioctl cdrom pause error") ;
exit(EXIT_FAILURE) ;
}
fprintf(stdout,"Press any key to resume the CD...\n") ;
getchar() ;
if ( ioctl(fd, CDROMRESUME) == -1) {
perror("ioctl cdrom resume error") ;
exit(EXIT_FAILURE) ;
}
/** Update the informations struct to display progressbar per example. */
if ( ioctl(fd, CDROMSUBCHNL, &playing_data_informations) == -1) {
perror("ioctl cdrom get informations error") ;
exit(EXIT_FAILURE) ;
}
}
close(fd) ;
} |
Partager