testcdrom.c
资源名称:NETVIDEO.rar [点击查看]
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:5k
源码类别:
流媒体/Mpeg4/MP4
开发平台:
Visual C++
- /* Test the SDL CD-ROM audio functions */
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h>
- #include "SDL.h"
- static void PrintStatus(int driveindex, SDL_CD *cdrom)
- {
- CDstatus status;
- char *status_str;
- status = SDL_CDStatus(cdrom);
- switch (status) {
- case CD_TRAYEMPTY:
- status_str = "tray empty";
- break;
- case CD_STOPPED:
- status_str = "stopped";
- break;
- case CD_PLAYING:
- status_str = "playing";
- break;
- case CD_PAUSED:
- status_str = "paused";
- break;
- case CD_ERROR:
- status_str = "error state";
- break;
- }
- printf("Drive %d status: %sn", driveindex, status_str);
- if ( status >= CD_PLAYING ) {
- int m, s, f;
- FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f);
- printf("Currently playing track %d, %d:%2.2dn",
- cdrom->track[cdrom->cur_track].id, m, s);
- }
- }
- static void ListTracks(SDL_CD *cdrom)
- {
- int i;
- int m, s, f;
- SDL_CDStatus(cdrom);
- printf("Drive tracks: %dn", cdrom->numtracks);
- for ( i=0; i<cdrom->numtracks; ++i ) {
- FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f);
- if ( f > 0 )
- ++s;
- printf("tTrack (index %d) %d: %d:%2.2dn", i,
- cdrom->track[i].id, m, s);
- }
- }
- static void PrintUsage(char *argv0)
- {
- fprintf(stderr, "Usage: %s [drive#] [command] [command] ...n", argv0);
- fprintf(stderr, "Where 'command' is one of:n");
- fprintf(stderr, " -statusn");
- fprintf(stderr, " -listn");
- fprintf(stderr, " -play [first_track] [first_frame] [num_tracks] [num_frames]n");
- fprintf(stderr, " -pausen");
- fprintf(stderr, " -resumen");
- fprintf(stderr, " -stopn");
- fprintf(stderr, " -ejectn");
- fprintf(stderr, " -sleep <milliseconds>n");
- }
- int main(int argc, char *argv[])
- {
- int drive;
- int i;
- SDL_CD *cdrom;
- /* Initialize SDL first */
- if ( SDL_Init(SDL_INIT_CDROM) < 0 ) {
- fprintf(stderr, "Couldn't initialize SDL: %sn",SDL_GetError());
- exit(1);
- }
- atexit(SDL_Quit);
- /* Find out how many CD-ROM drives are connected to the system */
- if ( SDL_CDNumDrives() == 0 ) {
- printf("No CD-ROM devices detectedn");
- exit(0);
- }
- printf("Drives available: %dn", SDL_CDNumDrives());
- for ( i=0; i<SDL_CDNumDrives(); ++i ) {
- printf("Drive %d: "%s"n", i, SDL_CDName(i));
- }
- /* Open the CD-ROM */
- drive = 0;
- i=1;
- if ( argv[i] && isdigit(argv[i][0]) ) {
- drive = atoi(argv[i++]);
- }
- cdrom = SDL_CDOpen(drive);
- if ( cdrom == NULL ) {
- fprintf(stderr, "Couldn't open drive %d: %sn", drive,
- SDL_GetError());
- exit(2);
- }
- #ifdef TEST_NULLCD
- cdrom = NULL;
- #endif
- /* Find out which function to perform */
- for ( ; argv[i]; ++i ) {
- if ( strcmp(argv[i], "-status") == 0 ) {
- /* PrintStatus(drive, cdrom); */
- } else
- if ( strcmp(argv[i], "-list") == 0 ) {
- ListTracks(cdrom);
- } else
- if ( strcmp(argv[i], "-play") == 0 ) {
- int strack, sframe;
- int ntrack, nframe;
- strack = 0;
- if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
- strack = atoi(argv[++i]);
- }
- sframe = 0;
- if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
- sframe = atoi(argv[++i]);
- }
- ntrack = 0;
- if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
- ntrack = atoi(argv[++i]);
- }
- nframe = 0;
- if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
- nframe = atoi(argv[++i]);
- }
- if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
- if ( SDL_CDPlayTracks(cdrom, strack, sframe,
- ntrack, nframe) < 0 ) {
- fprintf(stderr,
- "Couldn't play tracks %d/%d for %d/%d: %sn",
- strack, sframe, ntrack, nframe, SDL_GetError());
- }
- } else {
- fprintf(stderr, "No CD in drive!n");
- }
- } else
- if ( strcmp(argv[i], "-pause") == 0 ) {
- if ( SDL_CDPause(cdrom) < 0 ) {
- fprintf(stderr, "Couldn't pause CD: %sn",
- SDL_GetError());
- }
- } else
- if ( strcmp(argv[i], "-resume") == 0 ) {
- if ( SDL_CDResume(cdrom) < 0 ) {
- fprintf(stderr, "Couldn't resume CD: %sn",
- SDL_GetError());
- }
- } else
- if ( strcmp(argv[i], "-stop") == 0 ) {
- if ( SDL_CDStop(cdrom) < 0 ) {
- fprintf(stderr, "Couldn't eject CD: %sn",
- SDL_GetError());
- }
- } else
- if ( strcmp(argv[i], "-eject") == 0 ) {
- if ( SDL_CDEject(cdrom) < 0 ) {
- fprintf(stderr, "Couldn't eject CD: %sn",
- SDL_GetError());
- }
- } else
- if ( (strcmp(argv[i], "-sleep") == 0) &&
- (argv[i+1] && isdigit(argv[i+1][0])) ) {
- SDL_Delay(atoi(argv[++i]));
- printf("Delayed %d millisecondsn", atoi(argv[i]));
- } else {
- PrintUsage(argv[0]);
- SDL_CDClose(cdrom);
- exit(1);
- }
- }
- PrintStatus(drive, cdrom);
- SDL_CDClose(cdrom);
- return(0);
- }