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