Mercurial > mplayer.hg
annotate libmpdemux/cddb.c @ 8710:ba369c754b36
motion estimation pre pass
author | michael |
---|---|
date | Thu, 02 Jan 2003 01:38:35 +0000 |
parents | 1d98280b9ad1 |
children | f1fc23f6203b |
rev | line source |
---|---|
6474 | 1 /* |
2 * CDDB HTTP protocol | |
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com> | |
4 * (C) 2002, MPlayer team. | |
5 * | |
6 * Implementation follow the freedb.howto1.06.txt specification | |
7 * from http://freedb.freedb.org | |
8 * | |
9 * discid computation by Jeremy D. Zawodny | |
10 * Copyright (c) 1998-2000 Jeremy D. Zawodny <Jeremy@Zawodny.com> | |
11 * Code release under GPL | |
12 * | |
13 */ | |
14 | |
15 #include "config.h" | |
16 | |
17 #if defined(HAVE_CDDA) && defined(STREAMING) | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <fcntl.h> | |
22 #include <stdarg.h> | |
23 #include <errno.h> | |
24 #include <netdb.h> | |
25 #include <unistd.h> | |
26 #include <string.h> | |
27 #include <sys/ioctl.h> | |
28 #include <sys/types.h> | |
29 #include <sys/stat.h> | |
30 | |
8609
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
31 #if defined(__FreeBSD__) || defined(__bsdi__) |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
32 #define SYS_BSD 1 |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
33 #endif |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
34 |
8609
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
35 #if defined(__NetBSD__) |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
36 #define SYS_NBSD 1 |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
37 #endif |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
38 |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
39 #if defined(__OpenBSD__) |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
40 #define SYS_OBSD 1 |
6474 | 41 #endif |
42 | |
43 #if defined(__linux__) | |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
44 #include <linux/cdrom.h> |
6474 | 45 #elif defined(SYS_BSD) |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
46 #include <sys/cdio.h> |
8609
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
47 #elif defined(SYS_NBSD) |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
48 #include <sys/cdio.h> |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
49 #elif defined(SYS_OBSD) |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
50 #include <util.h> |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
51 #include <sys/cdio.h> |
6474 | 52 #endif |
53 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
54 #include "cdd.h" |
6474 | 55 #include "../version.h" |
56 #include "stream.h" | |
57 #include "network.h" | |
58 | |
59 #define DEFAULT_FREEDB_SERVER "freedb.freedb.org" | |
60 #define DEFAULT_CACHE_DIR "/.cddb/" | |
61 | |
62 stream_t* open_cdda(char *dev, char *track); | |
63 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
64 static cd_toc_t cdtoc[100]; |
6474 | 65 |
66 #if defined(__linux__) | |
67 int | |
68 read_toc(void) { | |
69 int drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK); | |
70 struct cdrom_tochdr tochdr; | |
71 struct cdrom_tocentry tocentry; | |
72 int i; | |
73 | |
74 ioctl(drive, CDROMREADTOCHDR, &tochdr); | |
75 for (i = tochdr.cdth_trk0; i <= tochdr.cdth_trk1; i++) { | |
76 tocentry.cdte_track = i; | |
77 tocentry.cdte_format = CDROM_MSF; | |
78 ioctl(drive, CDROMREADTOCENTRY, &tocentry); | |
79 cdtoc[i-1].min = tocentry.cdte_addr.msf.minute; | |
80 cdtoc[i-1].sec = tocentry.cdte_addr.msf.second; | |
81 cdtoc[i-1].frame = tocentry.cdte_addr.msf.frame; | |
82 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; | |
83 cdtoc[i-1].frame += cdtoc[i-1].sec*75; | |
84 } | |
85 tocentry.cdte_track = 0xAA; | |
86 tocentry.cdte_format = CDROM_MSF; | |
87 ioctl(drive, CDROMREADTOCENTRY, &tocentry); | |
88 cdtoc[tochdr.cdth_trk1].min = tocentry.cdte_addr.msf.minute; | |
89 cdtoc[tochdr.cdth_trk1].sec = tocentry.cdte_addr.msf.second; | |
90 cdtoc[tochdr.cdth_trk1].frame = tocentry.cdte_addr.msf.frame; | |
91 cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].min*60*75; | |
92 cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].sec*75; | |
93 close(drive); | |
94 return tochdr.cdth_trk1; | |
95 } | |
96 | |
97 #elif defined(SYS_BSD) | |
98 int | |
99 read_toc(void) { | |
100 int drive = open("/dev/acd0c", O_RDONLY | O_NONBLOCK); | |
101 struct ioc_toc_header tochdr; | |
102 struct ioc_read_toc_single_entry tocentry; | |
103 int i; | |
104 | |
105 ioctl(drive, CDIOREADTOCHEADER, &tochdr); | |
106 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { | |
107 tocentry.track = i; | |
108 tocentry.address_format = CD_MSF_FORMAT; | |
109 ioctl(drive, CDIOREADTOCENTRY, &tocentry); | |
110 cdtoc[i-1].min = tocentry.entry.addr.msf.minute; | |
111 cdtoc[i-1].sec = tocentry.entry.addr.msf.second; | |
112 cdtoc[i-1].frame = tocentry.entry.addr.msf.frame; | |
113 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; | |
114 cdtoc[i-1].frame += cdtoc[i-1].sec*75; | |
115 } | |
116 tocentry.track = 0xAA; | |
117 tocentry.address_format = CD_MSF_FORMAT; | |
118 ioctl(drive, CDIOREADTOCENTRY, &tocentry); | |
119 cdtoc[tochdr.ending_track].min = tocentry.entry.addr.msf.minute; | |
120 cdtoc[tochdr.ending_track].sec = tocentry.entry.addr.msf.second; | |
121 cdtoc[tochdr.ending_track].frame = tocentry.entry.addr.msf.frame; | |
122 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].min*60*75; | |
123 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].sec*75; | |
124 close(drive); | |
125 return tochdr.ending_track; | |
126 } | |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
127 |
8609
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
128 #elif defined(SYS_NBSD) |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
129 int |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
130 read_toc(void) { |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
131 int drive; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
132 struct ioc_toc_header tochdr; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
133 struct ioc_read_toc_entry tocentry; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
134 int i; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
135 struct cd_toc_entry toc_buffer; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
136 |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
137 drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK); |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
138 if (!drive) |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
139 return -1; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
140 |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
141 ioctl(drive, CDIOREADTOCHEADER, &tochdr); |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
142 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
143 tocentry.starting_track = i; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
144 tocentry.address_format = CD_MSF_FORMAT; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
145 tocentry.data = &toc_buffer; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
146 tocentry.data_len = sizeof(toc_buffer); |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
147 ioctl(drive, CDIOREADTOCENTRYS, &tocentry); |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
148 cdtoc[i-1].min = toc_buffer.addr.msf.minute; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
149 cdtoc[i-1].sec = toc_buffer.addr.msf.second; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
150 cdtoc[i-1].frame = toc_buffer.addr.msf.frame; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
151 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
152 cdtoc[i-1].frame += cdtoc[i-1].sec*75; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
153 } |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
154 tocentry.starting_track = 0xAA; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
155 tocentry.address_format = CD_MSF_FORMAT; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
156 ioctl(drive, CDIOREADTOCENTRYS, &tocentry); |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
157 cdtoc[tochdr.ending_track].min = toc_buffer.addr.msf.minute; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
158 cdtoc[tochdr.ending_track].sec = toc_buffer.addr.msf.second; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
159 cdtoc[tochdr.ending_track].frame = toc_buffer.addr.msf.frame; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
160 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].min*60*75; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
161 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].sec*75; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
162 close(drive); |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
163 return tochdr.ending_track; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
164 } |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
165 |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
166 #elif defined(SYS_OBSD) |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
167 int |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
168 read_toc(void) { |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
169 int drive; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
170 struct ioc_toc_header tochdr; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
171 struct ioc_read_toc_entry tocentry; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
172 int i; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
173 char *drivename; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
174 char *realdev; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
175 struct cd_toc_entry toc_buffer; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
176 |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
177 drivename = getenv("CDROM"); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
178 if (!drivename) |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
179 drivename = "cd0"; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
180 drive = opendev(drivename, O_RDONLY, OPENDEV_PART, &realdev); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
181 if (!drive) |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
182 return -1; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
183 |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
184 ioctl(drive, CDIOREADTOCHEADER, &tochdr); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
185 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
186 tocentry.starting_track = i; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
187 tocentry.address_format = CD_MSF_FORMAT; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
188 tocentry.data = &toc_buffer; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
189 tocentry.data_len = sizeof(toc_buffer); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
190 ioctl(drive, CDIOREADTOCENTRYS, &tocentry); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
191 cdtoc[i-1].min = toc_buffer.addr.msf.minute; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
192 cdtoc[i-1].sec = toc_buffer.addr.msf.second; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
193 cdtoc[i-1].frame = toc_buffer.addr.msf.frame; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
194 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
195 cdtoc[i-1].frame += cdtoc[i-1].sec*75; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
196 } |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
197 tocentry.starting_track = 0xAA; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
198 tocentry.address_format = CD_MSF_FORMAT; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
199 ioctl(drive, CDIOREADTOCENTRYS, &tocentry); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
200 cdtoc[tochdr.ending_track].min = toc_buffer.addr.msf.minute; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
201 cdtoc[tochdr.ending_track].sec = toc_buffer.addr.msf.second; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
202 cdtoc[tochdr.ending_track].frame = toc_buffer.addr.msf.frame; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
203 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].min*60*75; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
204 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].sec*75; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
205 close(drive); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
206 return tochdr.ending_track; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
207 } |
6474 | 208 #endif |
209 | |
210 unsigned int | |
211 cddb_sum(int n) { | |
212 unsigned int ret; | |
213 | |
214 ret = 0; | |
215 while (n > 0) { | |
216 ret += (n % 10); | |
217 n /= 10; | |
218 } | |
219 return ret; | |
220 } | |
221 | |
222 unsigned long | |
223 cddb_discid(int tot_trks) { | |
224 unsigned int i, t = 0, n = 0; | |
225 | |
226 i = 0; | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
227 while (i < (unsigned int)tot_trks) { |
6474 | 228 n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec); |
229 i++; | |
230 } | |
231 t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) - | |
232 ((cdtoc[0].min * 60) + cdtoc[0].sec); | |
233 return ((n % 0xff) << 24 | t << 8 | tot_trks); | |
234 } | |
235 | |
236 | |
237 | |
238 int | |
239 cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*), cddb_data_t *cddb_data) { | |
240 char request[4096]; | |
241 int fd, ret = 0; | |
242 URL_t *url; | |
243 HTTP_header_t *http_hdr; | |
244 | |
245 if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1; | |
246 | |
247 sprintf( request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d", cddb_data->freedb_server, command, cddb_data->cddb_hello, cddb_data->freedb_proto_level ); | |
248 printf("Request[%s]\n", request ); | |
249 | |
250 url = url_new(request); | |
251 if( url==NULL ) { | |
252 printf("Not a valid URL\n"); | |
253 return -1; | |
254 } | |
255 | |
256 fd = http_send_request(url); | |
257 if( fd<0 ) { | |
258 printf("failed to send the http request\n"); | |
259 return -1; | |
260 } | |
261 | |
262 http_hdr = http_read_response( fd ); | |
263 if( http_hdr==NULL ) { | |
264 printf("Failed to read the http response\n"); | |
265 return -1; | |
266 } | |
267 | |
268 http_debug_hdr(http_hdr); | |
269 printf("body=[%s]\n", http_hdr->body ); | |
270 | |
271 switch(http_hdr->status_code) { | |
272 case 200: | |
273 ret = reply_parser(http_hdr, cddb_data); | |
274 break; | |
275 case 400: | |
276 printf("Not Found\n"); | |
277 break; | |
278 default: | |
279 printf("Unknown Error code\n"); | |
280 } | |
281 | |
282 http_free( http_hdr ); | |
283 url_free( url ); | |
284 | |
285 return ret; | |
286 } | |
287 | |
288 int | |
289 cddb_read_cache(cddb_data_t *cddb_data) { | |
290 char file_name[100]; | |
291 struct stat stats; | |
292 int file_fd, ret; | |
293 size_t file_size; | |
294 | |
295 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1; | |
296 | |
297 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id); | |
298 | |
299 file_fd = open(file_name, O_RDONLY); | |
300 if( file_fd<0 ) { | |
301 printf("No cache found\n"); | |
302 return -1; | |
303 } | |
304 | |
305 ret = fstat( file_fd, &stats ); | |
306 if( ret<0 ) { | |
307 perror("fstat"); | |
308 file_size = 4096; | |
309 } else { | |
310 file_size = stats.st_size; | |
311 } | |
312 | |
313 cddb_data->xmcd_file = (char*)malloc(file_size); | |
314 if( cddb_data->xmcd_file==NULL ) { | |
315 printf("Memory allocation failed\n"); | |
316 close(file_fd); | |
317 return -1; | |
318 } | |
319 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size); | |
320 if( cddb_data->xmcd_file_size!=file_size ) { | |
321 printf("Not all the xmcd file has been read\n"); | |
322 close(file_fd); | |
323 return -1; | |
324 } | |
325 | |
326 close(file_fd); | |
327 | |
328 return 0; | |
329 } | |
330 | |
331 int | |
332 cddb_write_cache(cddb_data_t *cddb_data) { | |
333 // We have the file, save it for cache. | |
7721 | 334 struct stat file_stat; |
6474 | 335 char file_name[100]; |
7721 | 336 int file_fd, ret; |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
337 int wrote=0; |
6474 | 338 |
339 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1; | |
340 | |
7721 | 341 // Check if the CDDB cache dir exist |
342 ret = stat( cddb_data->cache_dir, &file_stat ); | |
343 if( ret<0 ) { | |
344 // Directory not present, create it. | |
345 ret = mkdir( cddb_data->cache_dir, 0755 ); | |
346 if( ret<0 ) { | |
347 perror("mkdir"); | |
348 printf("Failed to create directory %s\n", cddb_data->cache_dir ); | |
349 return -1; | |
350 } | |
351 } | |
352 | |
353 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id ); | |
6474 | 354 |
355 file_fd = creat(file_name, S_IREAD|S_IWRITE); | |
356 if( file_fd<0 ) { | |
7721 | 357 perror("create"); |
6474 | 358 return -1; |
359 } | |
360 | |
361 wrote = write(file_fd, cddb_data->xmcd_file, cddb_data->xmcd_file_size); | |
362 if( wrote<0 ) { | |
363 perror("write"); | |
364 close(file_fd); | |
365 return -1; | |
366 } | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
367 if( (unsigned int)wrote!=cddb_data->xmcd_file_size ) { |
6474 | 368 printf("Not all the xmcd file has been written\n"); |
369 close(file_fd); | |
370 return -1; | |
371 } | |
372 | |
373 close(file_fd); | |
374 | |
375 return 0; | |
376 } | |
377 | |
378 int | |
379 cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
380 unsigned long disc_id; | |
381 char category[100]; | |
382 char *ptr=NULL, *ptr2=NULL; | |
383 int ret, status; | |
384 | |
385 if( http_hdr==NULL || cddb_data==NULL ) return -1; | |
386 | |
387 ret = sscanf( http_hdr->body, "%d ", &status); | |
388 if( ret!=1 ) { | |
389 printf("Parse error\n"); | |
390 return -1; | |
391 } | |
392 | |
393 switch(status) { | |
394 case 210: | |
395 ret = sscanf( http_hdr->body, "%d %s %08lx", &status, category, &disc_id); | |
396 if( ret!=3 ) { | |
397 printf("Parse error\n"); | |
398 return -1; | |
399 } | |
400 // Check if it's a xmcd database file | |
401 ptr = strstr(http_hdr->body, "# xmcd"); | |
402 if( ptr==NULL ) { | |
403 printf("Invalid xmcd database file returned\n"); | |
404 return -1; | |
405 } | |
406 // Ok found the beginning of the file | |
407 // look for the end | |
408 ptr2 = strstr(ptr, "\r\n.\r\n"); | |
409 if( ptr2==NULL ) { | |
410 ptr2 = strstr(ptr, "\n.\n"); | |
411 if( ptr2==NULL ) { | |
412 printf("Unable to find '.'\n"); | |
8557 | 413 ptr2=ptr+strlen(ptr); //return -1; |
6474 | 414 } |
415 } | |
416 // Ok found the end | |
417 // do a sanity check | |
7953 | 418 if( http_hdr->body_size<(unsigned int)(ptr2-ptr) ) { |
6474 | 419 printf("Unexpected fix me\n"); |
420 return -1; | |
421 } | |
422 cddb_data->xmcd_file = ptr; | |
423 cddb_data->xmcd_file_size = ptr2-ptr+2; | |
424 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0'; | |
425 // Avoid the http_free function to free the xmcd file...save a mempcy... | |
426 http_hdr->body = NULL; | |
427 http_hdr->body_size = 0; | |
428 return cddb_write_cache(cddb_data); | |
429 default: | |
430 printf("Unhandled code\n"); | |
431 } | |
432 return 0; | |
433 } | |
434 | |
435 int | |
436 cddb_request_titles(cddb_data_t *cddb_data) { | |
437 char command[1024]; | |
438 sprintf( command, "cddb+read+%s+%08lx", cddb_data->category, cddb_data->disc_id); | |
439 return cddb_http_request(command, cddb_read_parse, cddb_data); | |
440 } | |
441 | |
442 int | |
443 cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
444 char album_title[100]; | |
445 char *ptr = NULL; | |
446 int ret, status; | |
447 | |
448 ret = sscanf( http_hdr->body, "%d ", &status); | |
449 if( ret!=1 ) { | |
450 printf("Parse error\n"); | |
451 return -1; | |
452 } | |
453 | |
454 switch(status) { | |
455 case 200: | |
456 // Found exact match | |
457 ret = sscanf(http_hdr->body, "%d %s %08lx %s", &status, cddb_data->category, &(cddb_data->disc_id), album_title); | |
458 if( ret!=4 ) { | |
459 printf("Parse error\n"); | |
460 return -1; | |
461 } | |
462 ptr = strstr(http_hdr->body, album_title); | |
463 if( ptr!=NULL ) { | |
464 char *ptr2; | |
465 int len; | |
466 ptr2 = strstr(ptr, "\n"); | |
467 if( ptr2==NULL ) { | |
468 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); | |
469 } else { | |
470 len = ptr2-ptr+1; | |
471 } | |
472 strncpy(album_title, ptr, len); | |
473 album_title[len-2]='\0'; | |
474 } | |
475 printf("Parse OK, found: %s\n", album_title); | |
476 return cddb_request_titles(cddb_data); | |
477 case 202: | |
478 // No match found | |
479 printf("Album not found\n"); | |
480 break; | |
481 case 210: | |
482 // Found exact matches, list follows | |
483 ptr = strstr(http_hdr->body, "\n"); | |
484 if( ptr==NULL ) { | |
485 printf("Unable to find end of line\n"); | |
486 return -1; | |
487 } | |
488 ptr++; | |
489 // We have a list of exact matches, so which one do | |
490 // we use? So let's take the first one. | |
491 ret = sscanf(ptr, "%s %08lx %s", cddb_data->category, &(cddb_data->disc_id), album_title); | |
492 if( ret!=3 ) { | |
493 printf("Parse error\n"); | |
494 return -1; | |
495 } | |
496 ptr = strstr(http_hdr->body, album_title); | |
497 if( ptr!=NULL ) { | |
498 char *ptr2; | |
499 int len; | |
500 ptr2 = strstr(ptr, "\n"); | |
501 if( ptr2==NULL ) { | |
502 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); | |
503 } else { | |
504 len = ptr2-ptr+1; | |
505 } | |
506 strncpy(album_title, ptr, len); | |
507 album_title[len-2]='\0'; | |
508 } | |
509 printf("Parse OK, found: %s\n", album_title); | |
510 return cddb_request_titles(cddb_data); | |
511 /* | |
512 body=[210 Found exact matches, list follows (until terminating `.') | |
513 misc c711930d Santana / Supernatural | |
514 rock c711930d Santana / Supernatural | |
515 blues c711930d Santana / Supernatural | |
516 .] | |
517 */ | |
518 case 211: | |
519 // Found inexact matches, list follows | |
520 printf("No exact matches found, list follows\n"); | |
521 break; | |
522 default: | |
523 printf("Unhandled code\n"); | |
524 } | |
525 return -1; | |
526 } | |
527 | |
528 int | |
529 cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
530 int max; | |
531 int ret, status; | |
532 char *ptr; | |
533 | |
534 ret = sscanf( http_hdr->body, "%d ", &status); | |
535 if( ret!=1 ) { | |
536 printf("Parse error\n"); | |
537 return -1; | |
538 } | |
539 | |
540 switch(status) { | |
541 case 210: | |
542 ptr = strstr(http_hdr->body, "max proto:"); | |
543 if( ptr==NULL ) { | |
544 printf("Parse error\n"); | |
545 return -1; | |
546 } | |
547 ret = sscanf(ptr, "max proto: %d", &max); | |
548 if( ret!=1 ) { | |
549 printf("Parse error\n"); | |
550 return -1; | |
551 } | |
552 cddb_data->freedb_proto_level = max; | |
553 return 0; | |
554 default: | |
555 printf("Unhandled code\n"); | |
556 } | |
557 return -1; | |
558 } | |
559 | |
560 int | |
561 cddb_get_proto_level(cddb_data_t *cddb_data) { | |
562 return cddb_http_request("stat", cddb_proto_level_parse, cddb_data); | |
563 } | |
564 | |
565 int | |
566 cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
567 int ret, status; | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
568 |
6474 | 569 ret = sscanf( http_hdr->body, "%d ", &status); |
570 if( ret!=1 ) { | |
571 printf("Parse error\n"); | |
572 return -1; | |
573 } | |
574 | |
575 switch(status) { | |
576 case 210: | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
577 // TODO: Parse the sites |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
578 ret = cddb_data->anonymous; // For gcc complaining about unused parameter. |
6474 | 579 return 0; |
580 case 401: | |
581 printf("No sites information available\n"); | |
582 break; | |
583 default: | |
584 printf("Unhandled code\n"); | |
585 } | |
586 return -1; | |
587 } | |
588 | |
589 int | |
590 cddb_get_freedb_sites(cddb_data_t *cddb_data) { | |
591 return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data); | |
592 } | |
593 | |
594 void | |
595 cddb_create_hello(cddb_data_t *cddb_data) { | |
596 char host_name[51]; | |
597 char *user_name; | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
598 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
599 if( cddb_data->anonymous ) { // Default is anonymous |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
600 /* Note from Eduardo Pérez Ureta <eperez@it.uc3m.es> : |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
601 * We don't send current user/host name in hello to prevent spam. |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
602 * Software that sends this is considered spyware |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
603 * that most people don't like. |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
604 */ |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
605 user_name = "anonymous"; |
6474 | 606 strcpy(host_name, "localhost"); |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
607 } else { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
608 if( gethostname(host_name, 50)<0 ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
609 strcpy(host_name, "localhost"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
610 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
611 user_name = getenv("LOGNAME"); |
6474 | 612 } |
613 sprintf( cddb_data->cddb_hello, "&hello=%s+%s+%s+%s", user_name, host_name, "MPlayer", VERSION ); | |
614 } | |
615 | |
616 int | |
617 cddb_retrieve(cddb_data_t *cddb_data) { | |
618 char offsets[1024], command[1024]; | |
619 char *ptr; | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
620 unsigned int i, time_len; |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
621 int ret; |
6474 | 622 |
623 ptr = offsets; | |
624 for( i=0; i<cddb_data->tracks ; i++ ) { | |
625 ptr += sprintf(ptr, "%d+", cdtoc[i].frame ); | |
626 } | |
8557 | 627 ptr[0]=0; |
6474 | 628 time_len = (cdtoc[cddb_data->tracks].frame)/75; |
8557 | 629 |
6474 | 630 cddb_data->freedb_server = DEFAULT_FREEDB_SERVER; |
631 cddb_data->freedb_proto_level = 1; | |
632 cddb_data->xmcd_file = NULL; | |
633 | |
634 cddb_create_hello(cddb_data); | |
6475
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
635 if( cddb_get_proto_level(cddb_data)<0 ) { |
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
636 printf("Failed to get the protocol level\n"); |
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
637 return -1; |
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
638 } |
6474 | 639 |
640 //cddb_get_freedb_sites(&cddb_data); | |
641 | |
642 sprintf(command, "cddb+query+%08lx+%d+%s%d", cddb_data->disc_id, cddb_data->tracks, offsets, time_len ); | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
643 ret = cddb_http_request(command, cddb_query_parse, cddb_data); |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
644 if( ret<0 ) return -1; |
6474 | 645 |
646 if( cddb_data->cache_dir!=NULL ) { | |
647 free(cddb_data->cache_dir); | |
648 } | |
649 return 0; | |
650 } | |
651 | |
652 int | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
653 cddb_resolve(char **xmcd_file) { |
6474 | 654 char cddb_cache_dir[] = DEFAULT_CACHE_DIR; |
655 char *home_dir = NULL; | |
656 cddb_data_t cddb_data; | |
657 | |
658 cddb_data.tracks = read_toc(); | |
659 cddb_data.disc_id = cddb_discid(cddb_data.tracks); | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
660 cddb_data.anonymous = 1; // Don't send user info by default |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
661 |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
662 // Check if there is a CD in the drive |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
663 // FIXME: That's not really a good way to check |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
664 if( cddb_data.disc_id==8256 ) { |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
665 printf("No CD in the drive\n"); |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
666 return -1; |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
667 } |
6474 | 668 |
669 home_dir = getenv("HOME"); | |
670 if( home_dir==NULL ) { | |
671 cddb_data.cache_dir = NULL; | |
672 } else { | |
673 cddb_data.cache_dir = (char*)malloc(strlen(home_dir)+strlen(cddb_cache_dir)+1); | |
674 if( cddb_data.cache_dir==NULL ) { | |
675 printf("Memory allocation failed\n"); | |
676 return -1; | |
677 } | |
678 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir ); | |
679 } | |
680 | |
681 // Check for a cached file | |
682 if( cddb_read_cache(&cddb_data)<0 ) { | |
683 // No Cache found | |
684 if( cddb_retrieve(&cddb_data)<0 ) { | |
685 return -1; | |
686 } | |
687 } | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
688 |
6474 | 689 if( cddb_data.xmcd_file!=NULL ) { |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
690 // printf("%s\n", cddb_data.xmcd_file ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
691 *xmcd_file = cddb_data.xmcd_file; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
692 return 0; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
693 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
694 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
695 return -1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
696 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
697 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
698 /******************************************************************************************************************* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
699 * |
7431
e46eeafcd4df
Moved all the cdinfo specific from cddb to a standalone file(cdinfo.c), so
bertrand
parents:
7269
diff
changeset
|
700 * xmcd parser |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
701 * |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
702 *******************************************************************************************************************/ |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
703 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
704 xmcd_parse_dtitle(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
705 char *ptr, *album; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
706 ptr = strstr(line, "DTITLE="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
707 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
708 ptr += 7; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
709 album = strstr(ptr, "/"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
710 if( album==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
711 cd_info->album = (char*)malloc(strlen(album+2)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
712 if( cd_info->album==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
713 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
714 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
715 strcpy( cd_info->album, album+2 ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
716 album--; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
717 album[0] = '\0'; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
718 cd_info->artist = (char*)malloc(strlen(ptr)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
719 if( cd_info->artist==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
720 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
721 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
722 strcpy( cd_info->artist, ptr ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
723 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
724 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
725 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
726 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
727 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
728 xmcd_parse_dgenre(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
729 char *ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
730 ptr = strstr(line, "DGENRE="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
731 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
732 ptr += 7; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
733 cd_info->genre = (char*)malloc(strlen(ptr)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
734 if( cd_info->genre==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
735 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
736 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
737 strcpy( cd_info->genre, ptr ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
738 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
739 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
740 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
741 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
742 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
743 xmcd_parse_ttitle(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
744 unsigned int track_nb; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
745 unsigned long sec, off; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
746 char *ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
747 ptr = strstr(line, "TTITLE"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
748 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
749 ptr += 6; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
750 // Here we point to the track number |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
751 track_nb = atoi(ptr); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
752 ptr = strstr(ptr, "="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
753 if( ptr==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
754 ptr++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
755 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
756 sec = cdtoc[track_nb].frame; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
757 off = cdtoc[track_nb+1].frame-sec+1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
758 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
759 cd_info_add_track( cd_info, ptr, track_nb+1, (unsigned int)(off/(60*75)), (unsigned int)((off/75)%60), (unsigned int)(off%75), sec, off ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
760 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
761 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
762 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
763 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
764 cd_info_t* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
765 cddb_parse_xmcd(char *xmcd_file) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
766 cd_info_t *cd_info = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
767 int length, pos = 0; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
768 char *ptr, *ptr2; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
769 unsigned int audiolen; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
770 if( xmcd_file==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
771 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
772 cd_info = cd_info_new(); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
773 if( cd_info==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
774 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
775 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
776 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
777 length = strlen(xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
778 ptr = xmcd_file; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
779 while( ptr!=NULL && pos<length ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
780 // Read a line |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
781 ptr2 = ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
782 while( ptr2[0]!='\0' && ptr2[0]!='\r' && ptr2[0]!='\n' ) ptr2++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
783 if( ptr2[0]=='\0' ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
784 break; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
785 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
786 ptr2[0] = '\0'; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
787 // Ignore comments |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
788 if( ptr[0]!='#' ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
789 // Search for the album title |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
790 if( xmcd_parse_dtitle(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
791 // Search for the genre |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
792 else if( xmcd_parse_dgenre(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
793 // Search for a track title |
7953 | 794 else if( xmcd_parse_ttitle(cd_info, ptr) ) audiolen++; // <-- audiolen++ to shut up gcc warning |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
795 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
796 if( ptr2[1]=='\n' ) ptr2++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
797 pos = (ptr2+1)-ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
798 ptr = ptr2+1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
799 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
800 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
801 audiolen = cdtoc[cd_info->nb_tracks].frame-cdtoc[0].frame; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
802 cd_info->min = (unsigned int)(audiolen/(60*75)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
803 cd_info->sec = (unsigned int)((audiolen/75)%60); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
804 cd_info->msec = (unsigned int)(audiolen%75); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
805 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
806 return cd_info; |
6474 | 807 } |
808 | |
809 stream_t* | |
810 cddb_open(char *dev, char *track) { | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
811 stream_t *stream; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
812 cd_info_t *cd_info = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
813 cdda_priv *priv; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
814 char *xmcd_file = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
815 int ret; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
816 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
817 ret = cddb_resolve(&xmcd_file); |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
818 if( ret<0 ) { |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
819 return NULL; |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
820 } |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
821 if( ret==0 ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
822 cd_info = cddb_parse_xmcd(xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
823 free(xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
824 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
825 stream = open_cdda(dev, track); |
6474 | 826 |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
827 priv = ((cdda_priv*)(stream->priv)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
828 if( cd_info!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
829 cd_info_free(priv->cd_info); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
830 priv->cd_info = cd_info; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
831 } |
7721 | 832 cd_info_debug( cd_info ); |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
833 return stream; |
6474 | 834 } |
835 #endif |