Mercurial > mplayer.hg
annotate libmpdemux/vcd_read_fbsd.h @ 17960:ec93436dc52d
Fix a/v desync for real some files
author | rtognimp |
---|---|
date | Sun, 26 Mar 2006 14:10:52 +0000 |
parents | aa15d627a00b |
children | 4231482179b6 |
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 | 15 typedef struct mp_vcd_priv_st { |
16 int fd; | |
17 struct ioc_read_toc_single_entry entry; | |
18 cdsector_t buf; | |
19 } mp_vcd_priv_t; | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
20 |
9887 | 21 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect){ |
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 | 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 | 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 | 29 static inline unsigned int vcd_get_msf(mp_vcd_priv_t* vcd){ |
30 return vcd->entry.entry.addr.msf.frame + | |
31 (vcd->entry.entry.addr.msf.second+ | |
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 | 35 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track){ |
36 vcd->entry.address_format = CD_MSF_FORMAT; | |
37 vcd->entry.track = track; | |
9899 | 38 if (ioctl(vcd->fd, CDIOREADTOCENTRY, &vcd->entry)) { |
9887 | 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 | 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 | 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 | 47 if (ioctl(vcd->fd,CDIOREADTOCHEADER,&tochdr)==-1) { |
48 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
49 return -1; | |
50 } | |
51 vcd->entry.address_format = CD_MSF_FORMAT; | |
52 vcd->entry.track = track<tochdr.ending_track?(track+1):CDROM_LEADOUT; | |
9899 | 53 if (ioctl(vcd->fd, CDIOREADTOCENTRY, &vcd->entry)) { |
9887 | 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 | 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 | 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 | 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 | 64 if (ioctl(fd,CDIOREADTOCHEADER,&tochdr)==-1) { |
65 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
66 return NULL; | |
67 } | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
68 if (identify) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
69 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
70 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.starting_track); |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
71 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track); |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
72 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
73 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
|
74 struct ioc_read_toc_single_entry tocentry; |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
75 |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
76 tocentry.track = i<=tochdr.ending_track ? i : CDROM_LEADOUT; |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
77 tocentry.address_format = CD_MSF_FORMAT; |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
78 |
9887 | 79 if (ioctl(fd,CDIOREADTOCENTRY,&tocentry)==-1) { |
80 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno)); | |
81 return NULL; | |
82 } | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
83 |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
84 if (i<=tochdr.ending_track) |
9887 | 85 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
|
86 (int)tocentry.track, |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
87 (int)tocentry.entry.addr_type, |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
88 (int)tocentry.entry.control, |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
89 (int)tocentry.address_format, |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
90 (int)tocentry.entry.addr.msf.minute, |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
91 (int)tocentry.entry.addr.msf.second, |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
92 (int)tocentry.entry.addr.msf.frame |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
93 ); |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
94 |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
95 if (identify) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
96 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
97 if (i > tochdr.starting_track) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
98 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 if ( frame < 0 ) |
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 frame += 75; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
105 sec --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
106 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
107 if ( sec < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
108 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
109 sec += 60; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
110 min --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
111 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
112 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame); |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
113 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 } |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
118 } |
9887 | 119 vcd = malloc(sizeof(mp_vcd_priv_t)); |
120 vcd->fd = fd; | |
121 return vcd; | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
122 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
123 |
9887 | 124 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
|
125 |
9899 | 126 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
|
127 != VCD_SECTOR_SIZE) return 0; // EOF? |
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
128 |
9887 | 129 vcd->entry.entry.addr.msf.frame++; |
130 if (vcd->entry.entry.addr.msf.frame==75){ | |
131 vcd->entry.entry.addr.msf.frame=0; | |
132 vcd->entry.entry.addr.msf.second++; | |
133 if (vcd->entry.entry.addr.msf.second==60){ | |
134 vcd->entry.entry.addr.msf.second=0; | |
135 vcd->entry.entry.addr.msf.minute++; | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
136 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
137 } |
9899 | 138 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA); |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
139 return VCD_SECTOR_DATA; |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
140 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
141 |