annotate vcd_read.h @ 132:642d64c1cc33

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