comparison libmpdemux/vcd_read_fbsd.h @ 2310:9e059416eea6

libdemuxer...
author arpi
date Sat, 20 Oct 2001 18:49:08 +0000
parents vcd_read_fbsd.h@e116beb1ac7b
children 1394aebaa838
comparison
equal deleted inserted replaced
2309:3128b9d8b4ea 2310:9e059416eea6
1 #include <sys/cdio.h>
2 #include <sys/cdrio.h>
3
4 //=================== VideoCD ==========================
5 #define CDROM_LEADOUT 0xAA
6
7 typedef struct {
8 uint8_t sync [12];
9 uint8_t header [4];
10 uint8_t subheader [8];
11 uint8_t data [2324];
12 uint8_t spare [4];
13 } cdsector_t;
14
15 static cdsector_t vcd_buf;
16 static struct ioc_read_toc_single_entry vcd_entry;
17
18 static inline void vcd_set_msf(unsigned int sect){
19 vcd_entry.entry.addr.msf.frame=sect%75;
20 sect=sect/75;
21 vcd_entry.entry.addr.msf.second=sect%60;
22 sect=sect/60;
23 vcd_entry.entry.addr.msf.minute=sect;
24 }
25
26 static inline unsigned int vcd_get_msf(){
27 return vcd_entry.entry.addr.msf.frame +
28 (vcd_entry.entry.addr.msf.second+
29 vcd_entry.entry.addr.msf.minute*60)*75;
30 }
31
32 int vcd_seek_to_track(int fd,int track){
33 vcd_entry.address_format = CD_MSF_FORMAT;
34 vcd_entry.track = track;
35 if (ioctl(fd, CDIOREADTOCENTRY, &vcd_entry)) {
36 perror("ioctl dif1");
37 return -1;
38 }
39 return VCD_SECTOR_DATA*vcd_get_msf();
40 }
41
42 int vcd_get_track_end(int fd,int track){
43 struct ioc_toc_header tochdr;
44 if (ioctl(fd,CDIOREADTOCHEADER,&tochdr)==-1)
45 { perror("read CDROM toc header: "); return -1; }
46 vcd_entry.address_format = CD_MSF_FORMAT;
47 vcd_entry.track = track<tochdr.ending_track?(track+1):CDROM_LEADOUT;
48 if (ioctl(fd, CDIOREADTOCENTRY, &vcd_entry)) {
49 perror("ioctl dif2");
50 return -1;
51 }
52 return VCD_SECTOR_DATA*vcd_get_msf();
53 }
54
55 void vcd_read_toc(int fd){
56 struct ioc_toc_header tochdr;
57 int i;
58 if (ioctl(fd,CDIOREADTOCHEADER,&tochdr)==-1)
59 { perror("read CDROM toc header: "); return; }
60 for (i=tochdr.starting_track ; i<=tochdr.ending_track ; i++){
61 struct ioc_read_toc_single_entry tocentry;
62
63 tocentry.track = i;
64 tocentry.address_format = CD_MSF_FORMAT;
65
66 if (ioctl(fd,CDIOREADTOCENTRY,&tocentry)==-1)
67 { perror("read CDROM toc entry: "); return; }
68
69 printf("track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
70 (int)tocentry.track,
71 (int)tocentry.entry.addr_type,
72 (int)tocentry.entry.control,
73 (int)tocentry.address_format,
74 (int)tocentry.entry.addr.msf.minute,
75 (int)tocentry.entry.addr.msf.second,
76 (int)tocentry.entry.addr.msf.frame
77 );
78 }
79 }
80
81 static int vcd_read(int fd,char *mem){
82
83 if (pread(fd,&vcd_buf,VCD_SECTOR_SIZE,vcd_get_msf()*VCD_SECTOR_SIZE)
84 != VCD_SECTOR_SIZE) return 0; // EOF?
85
86 vcd_entry.entry.addr.msf.frame++;
87 if (vcd_entry.entry.addr.msf.frame==75){
88 vcd_entry.entry.addr.msf.frame=0;
89 vcd_entry.entry.addr.msf.second++;
90 if (vcd_entry.entry.addr.msf.second==60){
91 vcd_entry.entry.addr.msf.second=0;
92 vcd_entry.entry.addr.msf.minute++;
93 }
94 }
95 memcpy(mem,vcd_buf.data,VCD_SECTOR_DATA);
96 return VCD_SECTOR_DATA;
97 }
98
99 //================== VCD CACHE =======================
100 #ifdef VCD_CACHE
101
102 static int vcd_cache_size=0;
103 static char *vcd_cache_data=NULL;
104 static int *vcd_cache_sectors=NULL;
105 static int vcd_cache_index=0; // index to first free (or oldest) cache sector
106 static int vcd_cache_current=-1;
107
108 void vcd_cache_init(int s){
109 vcd_cache_size=s;
110 vcd_cache_sectors=malloc(s*sizeof(int));
111 vcd_cache_data=malloc(s*VCD_SECTOR_SIZE);
112 memset(vcd_cache_sectors,255,s*sizeof(int));
113 }
114
115 static inline void vcd_cache_seek(int sect){
116 vcd_cache_current=sect;
117 }
118
119 int vcd_cache_read(int fd,char* mem){
120 int i;
121 char* vcd_buf;
122 for(i=0;i<vcd_cache_size;i++)
123 if(vcd_cache_sectors[i]==vcd_cache_current){
124 // found in the cache! :)
125 vcd_buf=&vcd_cache_data[i*VCD_SECTOR_SIZE];
126 ++vcd_cache_current;
127 memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA);
128 return VCD_SECTOR_DATA;
129 }
130 // NEW cache entry:
131 vcd_buf=&vcd_cache_data[vcd_cache_index*VCD_SECTOR_SIZE];
132 vcd_cache_sectors[vcd_cache_index]=vcd_cache_current;
133 ++vcd_cache_index;if(vcd_cache_index>=vcd_cache_size)vcd_cache_index=0;
134 // read data!
135 vcd_set_msf(vcd_cache_current);
136 memcpy(vcd_buf,&vcd_entry.entry.addr.msf,sizeof(struct cdrom_msf));
137 /* if(ioctl(fd,CDROMREADRAW,vcd_buf)==-1) return 0; */ // EOF?
138 ++vcd_cache_current;
139 memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA);
140 return VCD_SECTOR_DATA;
141 }
142
143 #endif