annotate stream/vcd_read_fbsd.h @ 19883:4e43ba6844d8

Fix stupid use of multiplication to check signs which fails because of overflow. Negative values do not seem to be used so just remove the failing test.
author uau
date Mon, 18 Sep 2006 14:04:50 +0000
parents 64d82a45a05d
children 773e6c50d1b8
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
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
15 typedef struct mp_vcd_priv_st {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
16 int fd;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
17 struct ioc_read_toc_single_entry entry;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
18 cdsector_t buf;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
19 } mp_vcd_priv_t;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
20
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
21 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect){
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
22 vcd->entry.entry.addr.msf.frame=sect%75;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
23 sect=sect/75;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
24 vcd->entry.entry.addr.msf.second=sect%60;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
25 sect=sect/60;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
26 vcd->entry.entry.addr.msf.minute=sect;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
27 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
28
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
29 static inline unsigned int vcd_get_msf(mp_vcd_priv_t* vcd){
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
30 return vcd->entry.entry.addr.msf.frame +
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
31 (vcd->entry.entry.addr.msf.second+
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
32 vcd->entry.entry.addr.msf.minute*60)*75;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
33 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
34
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
35 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track){
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
36 vcd->entry.address_format = CD_MSF_FORMAT;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
37 vcd->entry.track = track;
9899
248c478a0699 typo fix
nexus
parents: 9887
diff changeset
38 if (ioctl(vcd->fd, CDIOREADTOCENTRY, &vcd->entry)) {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
39 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno));
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
40 return -1;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
41 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
42 return VCD_SECTOR_DATA*vcd_get_msf(vcd);
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
43 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
44
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
45 int vcd_get_track_end(mp_vcd_priv_t* vcd, int track){
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
46 struct ioc_toc_header tochdr;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
47 if (ioctl(vcd->fd,CDIOREADTOCHEADER,&tochdr)==-1) {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
48 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
49 return -1;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
50 }
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
51 vcd->entry.address_format = CD_MSF_FORMAT;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
52 vcd->entry.track = track<tochdr.ending_track?(track+1):CDROM_LEADOUT;
9899
248c478a0699 typo fix
nexus
parents: 9887
diff changeset
53 if (ioctl(vcd->fd, CDIOREADTOCENTRY, &vcd->entry)) {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
54 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno));
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
55 return -1;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
56 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
57 return VCD_SECTOR_DATA*vcd_get_msf(vcd);
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
58 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
59
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
60 mp_vcd_priv_t* vcd_read_toc(int fd){
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
61 struct ioc_toc_header tochdr;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
62 mp_vcd_priv_t* vcd;
16547
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
63 int i, min = 0, sec = 0, frame = 0;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
64 if (ioctl(fd,CDIOREADTOCHEADER,&tochdr)==-1) {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
65 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
66 return NULL;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
67 }
18237
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 16547
diff changeset
68 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.starting_track);
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 16547
diff changeset
69 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track);
16547
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
70 for (i=tochdr.starting_track ; i<=tochdr.ending_track + 1; i++){
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
71 struct ioc_read_toc_single_entry tocentry;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
72
16547
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
73 tocentry.track = i<=tochdr.ending_track ? i : CDROM_LEADOUT;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
74 tocentry.address_format = CD_MSF_FORMAT;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
75
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
76 if (ioctl(fd,CDIOREADTOCENTRY,&tocentry)==-1) {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
77 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
78 return NULL;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
79 }
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
80
16547
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
81 if (i<=tochdr.ending_track)
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
82 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
83 (int)tocentry.track,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
84 (int)tocentry.entry.addr_type,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
85 (int)tocentry.entry.control,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
86 (int)tocentry.address_format,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
87 (int)tocentry.entry.addr.msf.minute,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
88 (int)tocentry.entry.addr.msf.second,
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
89 (int)tocentry.entry.addr.msf.frame
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
90 );
16547
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
91
18237
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 16547
diff changeset
92 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
16547
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
93 {
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
94 if (i > tochdr.starting_track)
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
95 {
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
96 min = tocentry.entry.addr.msf.minute - min;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
97 sec = tocentry.entry.addr.msf.second - sec;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
98 frame = tocentry.entry.addr.msf.frame - frame;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
99 if ( frame < 0 )
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
100 {
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
101 frame += 75;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
102 sec --;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
103 }
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
104 if ( sec < 0 )
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
105 {
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
106 sec += 60;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
107 min --;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
108 }
18237
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 16547
diff changeset
109 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame);
16547
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
110 }
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
111 min = tocentry.entry.addr.msf.minute;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
112 sec = tocentry.entry.addr.msf.second;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
113 frame = tocentry.entry.addr.msf.frame;
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
114 }
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
115 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
116 vcd = malloc(sizeof(mp_vcd_priv_t));
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
117 vcd->fd = fd;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
118 return vcd;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
119 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
120
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
121 static int vcd_read(mp_vcd_priv_t* vcd,char *mem){
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
122
9899
248c478a0699 typo fix
nexus
parents: 9887
diff changeset
123 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE)
1177
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
124 != VCD_SECTOR_SIZE) return 0; // EOF?
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
125
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
126 vcd->entry.entry.addr.msf.frame++;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
127 if (vcd->entry.entry.addr.msf.frame==75){
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
128 vcd->entry.entry.addr.msf.frame=0;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
129 vcd->entry.entry.addr.msf.second++;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
130 if (vcd->entry.entry.addr.msf.second==60){
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
131 vcd->entry.entry.addr.msf.second=0;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
132 vcd->entry.entry.addr.msf.minute++;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
133 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
134 }
9899
248c478a0699 typo fix
nexus
parents: 9887
diff changeset
135 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA);
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
136 return VCD_SECTOR_DATA;
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
137 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
138