annotate vcd_read.h @ 891:ceb1ae196e3a

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