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