Mercurial > mplayer.hg
annotate vcd_read.h @ 954:db20b90dd34d
audio out drivers
author | arpi_esp |
---|---|
date | Sat, 02 Jun 2001 23:25:43 +0000 |
parents | c7117e17e20b |
children | 72cacd3b8f30 |
rev | line source |
---|---|
1 | 1 //=================== VideoCD ========================== |
2 static struct cdrom_tocentry vcd_entry; | |
3 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
4 static inline void vcd_set_msf(unsigned int sect){ |
1 | 5 vcd_entry.cdte_addr.msf.frame=sect%75; |
6 sect=sect/75; | |
7 vcd_entry.cdte_addr.msf.second=sect%60; | |
8 sect=sect/60; | |
9 vcd_entry.cdte_addr.msf.minute=sect; | |
10 } | |
11 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
12 static inline unsigned int vcd_get_msf(){ |
1 | 13 return vcd_entry.cdte_addr.msf.frame + |
14 (vcd_entry.cdte_addr.msf.second+ | |
15 vcd_entry.cdte_addr.msf.minute*60)*75; | |
16 } | |
17 | |
18 int vcd_seek_to_track(int fd,int track){ | |
19 vcd_entry.cdte_format = CDROM_MSF; | |
20 vcd_entry.cdte_track = track; | |
21 if (ioctl(fd, CDROMREADTOCENTRY, &vcd_entry)) { | |
22 perror("ioctl dif1"); | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
23 return -1; |
1 | 24 } |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
25 return VCD_SECTOR_DATA*vcd_get_msf(); |
1 | 26 } |
27 | |
598 | 28 int vcd_get_track_end(int fd,int track){ |
29 struct cdrom_tochdr tochdr; | |
30 if (ioctl(fd,CDROMREADTOCHDR,&tochdr)==-1) | |
31 { perror("read CDROM toc header: "); return -1; } | |
32 vcd_entry.cdte_format = CDROM_MSF; | |
33 vcd_entry.cdte_track = track<tochdr.cdth_trk1?(track+1):CDROM_LEADOUT; | |
34 if (ioctl(fd, CDROMREADTOCENTRY, &vcd_entry)) { | |
35 perror("ioctl dif2"); | |
36 return -1; | |
37 } | |
38 return VCD_SECTOR_DATA*vcd_get_msf(); | |
39 } | |
40 | |
1 | 41 void vcd_read_toc(int fd){ |
42 struct cdrom_tochdr tochdr; | |
43 int i; | |
44 if (ioctl(fd,CDROMREADTOCHDR,&tochdr)==-1) | |
45 { perror("read CDROM toc header: "); return; } | |
46 for (i=tochdr.cdth_trk0 ; i<=tochdr.cdth_trk1 ; i++){ | |
47 struct cdrom_tocentry tocentry; | |
48 | |
49 tocentry.cdte_track = i; | |
50 tocentry.cdte_format = CDROM_MSF; | |
51 | |
52 if (ioctl(fd,CDROMREADTOCENTRY,&tocentry)==-1) | |
53 { perror("read CDROM toc entry: "); return; } | |
54 | |
55 printf("track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d mode: %d\n", | |
56 (int)tocentry.cdte_track, | |
57 (int)tocentry.cdte_adr, | |
58 (int)tocentry.cdte_ctrl, | |
59 (int)tocentry.cdte_format, | |
60 (int)tocentry.cdte_addr.msf.minute, | |
61 (int)tocentry.cdte_addr.msf.second, | |
62 (int)tocentry.cdte_addr.msf.frame, | |
63 (int)tocentry.cdte_datamode | |
64 ); | |
65 } | |
66 } | |
67 | |
68 static char vcd_buf[VCD_SECTOR_SIZE]; | |
69 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
70 static int vcd_read(int fd,char *mem){ |
1 | 71 memcpy(vcd_buf,&vcd_entry.cdte_addr.msf,sizeof(struct cdrom_msf)); |
72 if(ioctl(fd,CDROMREADRAW,vcd_buf)==-1) return 0; // EOF? | |
73 | |
74 vcd_entry.cdte_addr.msf.frame++; | |
75 if (vcd_entry.cdte_addr.msf.frame==75){ | |
76 vcd_entry.cdte_addr.msf.frame=0; | |
77 vcd_entry.cdte_addr.msf.second++; | |
78 if (vcd_entry.cdte_addr.msf.second==60){ | |
79 vcd_entry.cdte_addr.msf.second=0; | |
80 vcd_entry.cdte_addr.msf.minute++; | |
81 } | |
82 } | |
83 | |
84 memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA); | |
85 return VCD_SECTOR_DATA; | |
86 } | |
87 | |
88 //================== VCD CACHE ======================= | |
89 #ifdef VCD_CACHE | |
90 | |
91 static int vcd_cache_size=0; | |
92 static char *vcd_cache_data=NULL; | |
93 static int *vcd_cache_sectors=NULL; | |
94 static int vcd_cache_index=0; // index to first free (or oldest) cache sector | |
95 static int vcd_cache_current=-1; | |
96 | |
97 void vcd_cache_init(int s){ | |
98 vcd_cache_size=s; | |
99 vcd_cache_sectors=malloc(s*sizeof(int)); | |
100 vcd_cache_data=malloc(s*VCD_SECTOR_SIZE); | |
101 memset(vcd_cache_sectors,255,s*sizeof(int)); | |
102 } | |
103 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
1
diff
changeset
|
104 static inline void vcd_cache_seek(int sect){ |
1 | 105 vcd_cache_current=sect; |
106 } | |
107 | |
108 int vcd_cache_read(int fd,char* mem){ | |
109 int i; | |
110 char* vcd_buf; | |
111 for(i=0;i<vcd_cache_size;i++) | |
112 if(vcd_cache_sectors[i]==vcd_cache_current){ | |
113 // found in the cache! :) | |
114 vcd_buf=&vcd_cache_data[i*VCD_SECTOR_SIZE]; | |
115 ++vcd_cache_current; | |
116 memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA); | |
117 return VCD_SECTOR_DATA; | |
118 } | |
119 // NEW cache entry: | |
120 vcd_buf=&vcd_cache_data[vcd_cache_index*VCD_SECTOR_SIZE]; | |
121 vcd_cache_sectors[vcd_cache_index]=vcd_cache_current; | |
122 ++vcd_cache_index;if(vcd_cache_index>=vcd_cache_size)vcd_cache_index=0; | |
123 // read data! | |
124 vcd_set_msf(vcd_cache_current); | |
125 memcpy(vcd_buf,&vcd_entry.cdte_addr.msf,sizeof(struct cdrom_msf)); | |
126 if(ioctl(fd,CDROMREADRAW,vcd_buf)==-1) return 0; // EOF? | |
127 ++vcd_cache_current; | |
128 memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA); | |
129 return VCD_SECTOR_DATA; | |
130 } | |
131 | |
132 #endif |