Mercurial > mplayer.hg
annotate libmpdemux/cdda.c @ 10393:122564a2df38
-overlapsub clarified (thanks, Rich), -nooverlapsub removed (redundant)
author | diego |
---|---|
date | Mon, 07 Jul 2003 23:02:25 +0000 |
parents | d42177a0da2a |
children | 0d381b648b51 |
rev | line source |
---|---|
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
1 #include "config.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
2 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
3 #ifdef HAVE_CDDA |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
4 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
5 #include "stream.h" |
9801 | 6 #include "../m_option.h" |
7 #include "../m_struct.h" | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
8 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
9 #include <stdio.h> |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
10 #include <stdlib.h> |
9801 | 11 #include "demuxer.h" |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
12 |
6696 | 13 #include "cdd.h" |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
14 |
9801 | 15 static struct cdda_params { |
16 int speed; | |
17 int paranoia_mode; | |
18 char* generic_dev; | |
19 int sector_size; | |
20 int search_overlap; | |
21 int toc_bias; | |
22 int toc_offset; | |
23 int no_skip; | |
24 char* device; | |
25 m_span_t span; | |
26 } cdda_dflts = { | |
27 -1, | |
28 1, | |
29 NULL, | |
30 0, | |
31 -1, | |
32 0, | |
33 0, | |
34 0, | |
35 DEFAULT_CDROM_DEVICE, | |
36 { 0, 0 } | |
37 }; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
38 |
9801 | 39 #define ST_OFF(f) M_ST_OFF(struct cdda_params,f) |
40 m_option_t cdda_params_fields[] = { | |
41 { "speed", ST_OFF(speed), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
42 { "paranoia", ST_OFF(paranoia_mode), CONF_TYPE_INT,M_OPT_RANGE, 0, 2, NULL }, | |
43 { "generic-dev", ST_OFF(generic_dev), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
44 { "sector-size", ST_OFF(sector_size), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
45 { "overlap", ST_OFF(search_overlap), CONF_TYPE_INT, M_OPT_RANGE,0,75, NULL }, | |
46 { "toc-bias", ST_OFF(toc_bias), CONF_TYPE_INT, 0, 0, 0, NULL }, | |
47 { "toc-offset", ST_OFF(toc_offset), CONF_TYPE_INT, 0, 0, 0, NULL }, | |
48 { "noskip", ST_OFF(no_skip), CONF_TYPE_FLAG, 0 , 0, 1, NULL }, | |
49 { "skip", ST_OFF(no_skip), CONF_TYPE_FLAG, 0 , 1, 0, NULL }, | |
50 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
51 { "span", ST_OFF(span), CONF_TYPE_OBJ_PARAMS, 0, 0, 0, &m_span_params_def }, | |
52 /// For url parsing | |
53 { "hostname", ST_OFF(span), CONF_TYPE_OBJ_PARAMS, 0, 0, 0, &m_span_params_def }, | |
54 { "port", ST_OFF(speed), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
55 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
56 {NULL, NULL, 0, 0, 0, 0, NULL} | |
57 }; | |
58 static struct m_struct_st stream_opts = { | |
59 "cdda", | |
60 sizeof(struct cdda_params), | |
61 &cdda_dflts, | |
62 cdda_params_fields | |
63 }; | |
64 | |
65 /// We keep these options but now they set the defaults | |
66 m_option_t cdda_opts[] = { | |
67 { "speed", &cdda_dflts.speed, CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
68 { "paranoia", &cdda_dflts.paranoia_mode, CONF_TYPE_INT,M_OPT_RANGE, 0, 2, NULL }, | |
69 { "generic-dev", &cdda_dflts.generic_dev, CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
70 { "sector-size", &cdda_dflts.sector_size, CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
71 { "overlap", &cdda_dflts.search_overlap, CONF_TYPE_INT, M_OPT_RANGE,0,75, NULL }, | |
72 { "toc-bias", &cdda_dflts.toc_bias, CONF_TYPE_INT, 0, 0, 0, NULL }, | |
73 { "toc-offset", &cdda_dflts.toc_offset, CONF_TYPE_INT, 0, 0, 0, NULL }, | |
74 { "noskip", &cdda_dflts.no_skip, CONF_TYPE_FLAG, 0 , 0, 1, NULL }, | |
75 { "skip", &cdda_dflts.no_skip, CONF_TYPE_FLAG, 0 , 1, 0, NULL }, | |
76 { "device", &cdda_dflts.device, CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
77 { "span", &cdda_dflts.span, CONF_TYPE_OBJ_PARAMS, 0, 0, 0, &m_span_params_def }, | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
78 {NULL, NULL, 0, 0, 0, 0, NULL} |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
79 }; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
80 |
9801 | 81 extern int cddb_resolve(const char *dev, char **xmcd_file); |
82 extern cd_info_t* cddb_parse_xmcd(char *xmcd_file); | |
83 | |
84 static int seek(stream_t* s,off_t pos); | |
85 static int fill_buffer(stream_t* s, char* buffer, int max_len); | |
86 static void close(stream_t* s); | |
87 | |
88 static int open_cdda(stream_t *st,int m, void* opts, int* file_format) { | |
89 struct cdda_params* p = (struct cdda_params*)opts; | |
90 int mode = p->paranoia_mode; | |
91 int offset = p->toc_offset; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
92 cdrom_drive* cdd = NULL; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
93 cdda_priv* priv; |
9801 | 94 cd_info_t *cd_info,*cddb_info = NULL; |
6696 | 95 unsigned int audiolen=0; |
96 int i; | |
9801 | 97 char *xmcd_file = NULL; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
98 |
9801 | 99 if(m != STREAM_READ) { |
100 m_struct_free(&stream_opts,opts); | |
101 return STREAM_UNSUPORTED; | |
102 } | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
103 |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9801
diff
changeset
|
104 #ifdef MPLAYER_NETWORK |
9801 | 105 if(strncmp(st->url,"cddb",4) == 0) { |
106 i = cddb_resolve(p->device, &xmcd_file); | |
107 if(i == 0) { | |
108 cddb_info = cddb_parse_xmcd(xmcd_file); | |
109 free(xmcd_file); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
110 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
111 } |
9801 | 112 #endif |
113 | |
114 if(p->generic_dev) | |
115 cdd = cdda_identify_scsi(p->generic_dev,p->device,0,NULL); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
116 else |
8958
56bf90cefb10
Removed the hardcoded /dev/cdrom for NetBSD and added an work around
bertrand
parents:
8609
diff
changeset
|
117 #if defined(__NetBSD__) |
9801 | 118 cdd = cdda_identify_scsi(p->device,p->device,0,NULL); |
8958
56bf90cefb10
Removed the hardcoded /dev/cdrom for NetBSD and added an work around
bertrand
parents:
8609
diff
changeset
|
119 #else |
9801 | 120 cdd = cdda_identify(p->device,0,NULL); |
8958
56bf90cefb10
Removed the hardcoded /dev/cdrom for NetBSD and added an work around
bertrand
parents:
8609
diff
changeset
|
121 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
122 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
123 if(!cdd) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
124 mp_msg(MSGT_OPEN,MSGL_ERR,"Can't open cdda device\n"); |
9801 | 125 m_struct_free(&stream_opts,opts); |
126 return STREAM_ERROR; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
127 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
128 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
129 cdda_verbose_set(cdd, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
130 |
9801 | 131 if(p->sector_size) { |
132 cdd->nsectors = p->sector_size; | |
133 cdd->bigbuff = p->sector_size * CD_FRAMESIZE_RAW; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
134 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
135 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
136 if(cdda_open(cdd) != 0) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
137 mp_msg(MSGT_OPEN,MSGL_ERR,"Can't open disc\n"); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
138 cdda_close(cdd); |
9801 | 139 m_struct_free(&stream_opts,opts); |
140 return STREAM_ERROR; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
141 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
142 |
6696 | 143 cd_info = cd_info_new(); |
144 mp_msg(MSGT_OPEN,MSGL_INFO,"Found Audio CD with %d tracks\n",cdda_tracks(cdd)); | |
145 for(i=0;i<cdd->tracks;i++) { | |
146 char track_name[80]; | |
147 long sec=cdda_track_firstsector(cdd,i+1); | |
148 long off=cdda_track_lastsector(cdd,i+1)-sec+1; | |
149 | |
150 sprintf(track_name, "Track %d", i+1); | |
151 cd_info_add_track(cd_info, track_name, i+1, (unsigned int)(off/(60*75)), (unsigned int)((off/75)%60), (unsigned int)(off%75), sec, off ); | |
152 audiolen += off; | |
153 } | |
154 cd_info->min = (unsigned int)(audiolen/(60*75)); | |
155 cd_info->sec = (unsigned int)((audiolen/75)%60); | |
156 cd_info->msec = (unsigned int)(audiolen%75); | |
157 | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
158 priv = (cdda_priv*)malloc(sizeof(cdda_priv)); |
6696 | 159 memset(priv, 0, sizeof(cdda_priv)); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
160 priv->cd = cdd; |
6696 | 161 priv->cd_info = cd_info; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
162 |
9801 | 163 if(p->toc_bias) |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
164 offset -= cdda_track_firstsector(cdd,1); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
165 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
166 if(offset) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
167 int i; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
168 for(i = 0 ; i < cdd->tracks + 1 ; i++) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
169 cdd->disc_toc[i].dwStartSector += offset; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
170 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
171 |
9801 | 172 if(p->speed) |
173 cdda_speed_set(cdd,p->speed); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
174 |
9801 | 175 if(p->span.start) |
176 priv->start_sector = cdda_track_firstsector(cdd,p->span.start); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
177 else |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
178 priv->start_sector = cdda_disc_firstsector(cdd); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
179 |
9801 | 180 if(p->span.end) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
181 int last = cdda_tracks(cdd); |
9801 | 182 if(p->span.end > last) p->span.end = last; |
183 priv->end_sector = cdda_track_lastsector(cdd,p->span.end); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
184 } else |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
185 priv->end_sector = cdda_disc_lastsector(cdd); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
186 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
187 priv->cdp = paranoia_init(cdd); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
188 if(priv->cdp == NULL) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
189 cdda_close(cdd); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
190 free(priv); |
9801 | 191 cd_info_free(cd_info); |
192 m_struct_free(&stream_opts,opts); | |
193 return STREAM_ERROR; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
194 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
195 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
196 if(mode == 0) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
197 mode = PARANOIA_MODE_DISABLE; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
198 else if(mode == 1) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
199 mode = PARANOIA_MODE_OVERLAP; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
200 else |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
201 mode = PARANOIA_MODE_FULL; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
202 |
9801 | 203 if(p->no_skip) |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
204 mode |= PARANOIA_MODE_NEVERSKIP; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
205 |
9801 | 206 if(p->search_overlap >= 0) |
207 paranoia_overlapset(cdd,p->search_overlap); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
208 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
209 paranoia_seek(priv->cdp,priv->start_sector,SEEK_SET); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
210 priv->sector = priv->start_sector; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
211 |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9801
diff
changeset
|
212 #ifdef MPLAYER_NETWORK |
9801 | 213 if(cddb_info) { |
214 cd_info_free(cd_info); | |
215 priv->cd_info = cddb_info; | |
216 cd_info_debug( cddb_info ); | |
217 } | |
218 #endif | |
219 | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
220 st->priv = priv; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
221 st->start_pos = priv->start_sector*CD_FRAMESIZE_RAW; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
222 st->end_pos = priv->end_sector*CD_FRAMESIZE_RAW; |
9801 | 223 st->type = STREAMTYPE_CDDA; |
224 st->sector_size = CD_FRAMESIZE_RAW; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
225 |
9801 | 226 st->fill_buffer = fill_buffer; |
227 st->seek = seek; | |
228 st->close = close; | |
229 | |
230 *file_format = DEMUXER_TYPE_RAWAUDIO; | |
231 | |
232 m_struct_free(&stream_opts,opts); | |
233 | |
234 return STREAM_OK; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
235 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
236 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
237 static void cdparanoia_callback(long inpos, int function) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
238 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
239 |
9801 | 240 static int fill_buffer(stream_t* s, char* buffer, int max_len) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
241 cdda_priv* p = (cdda_priv*)s->priv; |
6696 | 242 cd_track_t *cd_track; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
243 int16_t * buf; |
9801 | 244 int i; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
245 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
246 buf = paranoia_read(p->cdp,cdparanoia_callback); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
247 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
248 p->sector++; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
249 s->pos = p->sector*CD_FRAMESIZE_RAW; |
9801 | 250 memcpy(buffer,buf,CD_FRAMESIZE_RAW); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
251 |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
252 if((p->sector < p->start_sector) || (p->sector >= p->end_sector)) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
253 s->eof = 1; |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
254 return 0; |
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
255 } |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
256 |
6696 | 257 for(i=0;i<p->cd->tracks;i++){ |
258 if(p->cd->disc_toc[i].dwStartSector==p->sector-1) { | |
259 cd_track = cd_info_get_track(p->cd_info, i+1); | |
260 //printf("Track %d, sector=%d\n", i, p->sector-1); | |
261 if( cd_track!=NULL ) { | |
8558 | 262 printf("\n%s\n", cd_track->name ); |
6696 | 263 } |
264 break; | |
265 } | |
266 } | |
267 | |
268 | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
269 return CD_FRAMESIZE_RAW; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
270 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
271 |
9801 | 272 static int seek(stream_t* s,off_t newpos) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
273 cdda_priv* p = (cdda_priv*)s->priv; |
6696 | 274 cd_track_t *cd_track; |
275 int sec; | |
276 int current_track=0, seeked_track=0; | |
277 int i; | |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
278 |
9801 | 279 s->pos = newpos; |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
280 if(s->pos < 0) { |
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
281 s->eof = 1; |
9801 | 282 return 0; |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
283 } |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
284 |
6696 | 285 sec = s->pos/CD_FRAMESIZE_RAW; |
8524 | 286 //printf("pos: %d, sec: %d ## %d\n", (int)s->pos, (int)sec, CD_FRAMESIZE_RAW); |
287 //printf("sector: %d new: %d\n", p->sector, sec ); | |
6696 | 288 |
289 for(i=0;i<p->cd->tracks;i++){ | |
8559 | 290 // printf("trk #%d: %d .. %d\n",i,p->cd->disc_toc[i].dwStartSector,p->cd->disc_toc[i+1].dwStartSector); |
8524 | 291 if( p->sector>=p->cd->disc_toc[i].dwStartSector && p->sector<p->cd->disc_toc[i+1].dwStartSector ) { |
6696 | 292 current_track = i; |
293 } | |
8524 | 294 if( sec>=p->cd->disc_toc[i].dwStartSector && sec<p->cd->disc_toc[i+1].dwStartSector ) { |
6696 | 295 seeked_track = i; |
296 } | |
297 } | |
298 //printf("current: %d, seeked: %d\n", current_track, seeked_track); | |
299 if( current_track!=seeked_track ) { | |
300 //printf("Track %d, sector=%d\n", seeked_track, sec); | |
301 cd_track = cd_info_get_track(p->cd_info, seeked_track+1); | |
302 if( cd_track!=NULL ) { | |
8558 | 303 printf("\n%s\n", cd_track->name ); |
6696 | 304 } |
305 | |
306 } | |
8524 | 307 #if 0 |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
308 if(sec < p->start_sector) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
309 sec = p->start_sector; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
310 else if(sec > p->end_sector) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
311 sec = p->end_sector; |
8524 | 312 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
313 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
314 p->sector = sec; |
6696 | 315 // s->pos = sec*CD_FRAMESIZE_RAW; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
316 |
8524 | 317 //printf("seek: %d, sec: %d\n", (int)s->pos, sec); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
318 paranoia_seek(p->cdp,sec,SEEK_SET); |
9801 | 319 return 1; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
320 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
321 |
9801 | 322 static void close(stream_t* s) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
323 cdda_priv* p = (cdda_priv*)s->priv; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
324 paranoia_free(p->cdp); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
325 cdda_close(p->cd); |
9801 | 326 cd_info_free(p->cd_info); |
327 free(p); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
328 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
329 |
9801 | 330 stream_info_t stream_info_cdda = { |
331 "CDDA", | |
332 "cdda", | |
333 "Albeu", | |
334 "", | |
335 open_cdda, | |
336 { "cdda", "cddb", NULL }, | |
337 &stream_opts, | |
338 1 // Urls are an option string | |
339 }; | |
340 | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
341 #endif |