annotate libmpdemux/vcd_read_fbsd.h @ 8417:15e3d9c2c0ac

allocate the video buffer on the fly, instead of one big chunk at startup
author henry
date Tue, 10 Dec 2002 09:11:42 +0000
parents 1394aebaa838
children d862231858d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 958
diff changeset
1 #include <sys/cdio.h>
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 958
diff changeset
2 #include <sys/cdrio.h>
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 958
diff changeset
3
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
4 //=================== VideoCD ==========================
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
5 #define CDROM_LEADOUT 0xAA
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
6
1177
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
7 typedef struct {
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
8 uint8_t sync [12];
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
9 uint8_t header [4];
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
10 uint8_t subheader [8];
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
11 uint8_t data [2324];
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
12 uint8_t spare [4];
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
13 } cdsector_t;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
14
1311
e116beb1ac7b Minor code cleanup from Vladimir Kushnir
jkeil
parents: 1177
diff changeset
15 static cdsector_t vcd_buf;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
16 static struct ioc_read_toc_single_entry vcd_entry;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
17
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
18 static inline void vcd_set_msf(unsigned int sect){
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
19 vcd_entry.entry.addr.msf.frame=sect%75;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
20 sect=sect/75;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
21 vcd_entry.entry.addr.msf.second=sect%60;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
22 sect=sect/60;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
23 vcd_entry.entry.addr.msf.minute=sect;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
24 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
25
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
26 static inline unsigned int vcd_get_msf(){
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
27 return vcd_entry.entry.addr.msf.frame +
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
28 (vcd_entry.entry.addr.msf.second+
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
29 vcd_entry.entry.addr.msf.minute*60)*75;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
30 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
31
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
32 int vcd_seek_to_track(int fd,int track){
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
33 vcd_entry.address_format = CD_MSF_FORMAT;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
34 vcd_entry.track = track;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
35 if (ioctl(fd, CDIOREADTOCENTRY, &vcd_entry)) {
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
36 perror("ioctl dif1");
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
37 return -1;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
38 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
39 return VCD_SECTOR_DATA*vcd_get_msf();
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
40 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
41
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
42 int vcd_get_track_end(int fd,int track){
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
43 struct ioc_toc_header tochdr;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
44 if (ioctl(fd,CDIOREADTOCHEADER,&tochdr)==-1)
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
45 { perror("read CDROM toc header: "); return -1; }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
46 vcd_entry.address_format = CD_MSF_FORMAT;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
47 vcd_entry.track = track<tochdr.ending_track?(track+1):CDROM_LEADOUT;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
48 if (ioctl(fd, CDIOREADTOCENTRY, &vcd_entry)) {
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
49 perror("ioctl dif2");
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
50 return -1;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
51 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
52 return VCD_SECTOR_DATA*vcd_get_msf();
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
53 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
54
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
55 void vcd_read_toc(int fd){
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
56 struct ioc_toc_header tochdr;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
57 int i;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
58 if (ioctl(fd,CDIOREADTOCHEADER,&tochdr)==-1)
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
59 { perror("read CDROM toc header: "); return; }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
60 for (i=tochdr.starting_track ; i<=tochdr.ending_track ; i++){
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
61 struct ioc_read_toc_single_entry tocentry;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
62
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
63 tocentry.track = i;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
64 tocentry.address_format = CD_MSF_FORMAT;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
65
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
66 if (ioctl(fd,CDIOREADTOCENTRY,&tocentry)==-1)
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
67 { perror("read CDROM toc entry: "); return; }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
68
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
69 printf("track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
70 (int)tocentry.track,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
71 (int)tocentry.entry.addr_type,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
72 (int)tocentry.entry.control,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
73 (int)tocentry.address_format,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
74 (int)tocentry.entry.addr.msf.minute,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
75 (int)tocentry.entry.addr.msf.second,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
76 (int)tocentry.entry.addr.msf.frame
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
77 );
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
78 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
79 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
80
1311
e116beb1ac7b Minor code cleanup from Vladimir Kushnir
jkeil
parents: 1177
diff changeset
81 static int vcd_read(int fd,char *mem){
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
82
1177
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
83 if (pread(fd,&vcd_buf,VCD_SECTOR_SIZE,vcd_get_msf()*VCD_SECTOR_SIZE)
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
84 != VCD_SECTOR_SIZE) return 0; // EOF?
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
85
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
86 vcd_entry.entry.addr.msf.frame++;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
87 if (vcd_entry.entry.addr.msf.frame==75){
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
88 vcd_entry.entry.addr.msf.frame=0;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
89 vcd_entry.entry.addr.msf.second++;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
90 if (vcd_entry.entry.addr.msf.second==60){
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
91 vcd_entry.entry.addr.msf.second=0;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
92 vcd_entry.entry.addr.msf.minute++;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
93 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
94 }
1177
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
95 memcpy(mem,vcd_buf.data,VCD_SECTOR_DATA);
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
96 return VCD_SECTOR_DATA;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
97 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
98