Mercurial > mplayer.hg
annotate stream/stream_cdda.c @ 22188:b9fa8b0ddab9
strncat() misuses, may have been exploitable.
Reported by Sascha Sommer.
author | rtogni |
---|---|
date | Sun, 11 Feb 2007 18:00:06 +0000 |
parents | fa99b3d31d13 |
children | d261f5109660 |
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 |
21418
cc5b0c53b263
Move system headers before libavutil headers to work around build issues on
diego
parents:
21372
diff
changeset
|
3 #include <stdio.h> |
cc5b0c53b263
Move system headers before libavutil headers to work around build issues on
diego
parents:
21372
diff
changeset
|
4 #include <stdlib.h> |
cc5b0c53b263
Move system headers before libavutil headers to work around build issues on
diego
parents:
21372
diff
changeset
|
5 |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
6 #include "stream.h" |
17012 | 7 #include "m_option.h" |
8 #include "m_struct.h" | |
21372 | 9 #include "libavutil/common.h" |
21507
fa99b3d31d13
Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents:
21479
diff
changeset
|
10 #include "mpbswap.h" |
19312
ab8d6b6deb63
proper inclusion of demuxer.h (including libmpdemux in Makefile only was to make previous split easier)
ben
parents:
19272
diff
changeset
|
11 #include "libmpdemux/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 |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16940
diff
changeset
|
15 #include "mp_msg.h" |
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16940
diff
changeset
|
16 #include "help_mp.h" |
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16940
diff
changeset
|
17 |
16940 | 18 #ifndef CD_FRAMESIZE_RAW |
19 #define CD_FRAMESIZE_RAW CDIO_CD_FRAMESIZE_RAW | |
20 #endif | |
21 | |
22 | |
10591 | 23 extern char *cdrom_device; |
24 | |
9801 | 25 static struct cdda_params { |
26 int speed; | |
27 int paranoia_mode; | |
28 char* generic_dev; | |
29 int sector_size; | |
30 int search_overlap; | |
31 int toc_bias; | |
32 int toc_offset; | |
33 int no_skip; | |
34 char* device; | |
35 m_span_t span; | |
36 } cdda_dflts = { | |
37 -1, | |
16914
701af802aee7
set cdda paranoia default to 0 since e.g. cdda://2 breaks otherwise.
reimar
parents:
16635
diff
changeset
|
38 0, |
9801 | 39 NULL, |
40 0, | |
41 -1, | |
42 0, | |
43 0, | |
44 0, | |
10591 | 45 NULL, |
9801 | 46 { 0, 0 } |
47 }; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
48 |
9801 | 49 #define ST_OFF(f) M_ST_OFF(struct cdda_params,f) |
50 m_option_t cdda_params_fields[] = { | |
51 { "speed", ST_OFF(speed), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
52 { "paranoia", ST_OFF(paranoia_mode), CONF_TYPE_INT,M_OPT_RANGE, 0, 2, NULL }, | |
53 { "generic-dev", ST_OFF(generic_dev), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
54 { "sector-size", ST_OFF(sector_size), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
55 { "overlap", ST_OFF(search_overlap), CONF_TYPE_INT, M_OPT_RANGE,0,75, NULL }, | |
56 { "toc-bias", ST_OFF(toc_bias), CONF_TYPE_INT, 0, 0, 0, NULL }, | |
57 { "toc-offset", ST_OFF(toc_offset), CONF_TYPE_INT, 0, 0, 0, NULL }, | |
58 { "noskip", ST_OFF(no_skip), CONF_TYPE_FLAG, 0 , 0, 1, NULL }, | |
59 { "skip", ST_OFF(no_skip), CONF_TYPE_FLAG, 0 , 1, 0, NULL }, | |
60 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
61 { "span", ST_OFF(span), CONF_TYPE_OBJ_PARAMS, 0, 0, 0, &m_span_params_def }, | |
62 /// For url parsing | |
63 { "hostname", ST_OFF(span), CONF_TYPE_OBJ_PARAMS, 0, 0, 0, &m_span_params_def }, | |
64 { "port", ST_OFF(speed), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
65 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
66 {NULL, NULL, 0, 0, 0, 0, NULL} | |
67 }; | |
68 static struct m_struct_st stream_opts = { | |
69 "cdda", | |
70 sizeof(struct cdda_params), | |
71 &cdda_dflts, | |
72 cdda_params_fields | |
73 }; | |
74 | |
75 /// We keep these options but now they set the defaults | |
76 m_option_t cdda_opts[] = { | |
77 { "speed", &cdda_dflts.speed, CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
78 { "paranoia", &cdda_dflts.paranoia_mode, CONF_TYPE_INT,M_OPT_RANGE, 0, 2, NULL }, | |
79 { "generic-dev", &cdda_dflts.generic_dev, CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
80 { "sector-size", &cdda_dflts.sector_size, CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL }, | |
81 { "overlap", &cdda_dflts.search_overlap, CONF_TYPE_INT, M_OPT_RANGE,0,75, NULL }, | |
82 { "toc-bias", &cdda_dflts.toc_bias, CONF_TYPE_INT, 0, 0, 0, NULL }, | |
83 { "toc-offset", &cdda_dflts.toc_offset, CONF_TYPE_INT, 0, 0, 0, NULL }, | |
84 { "noskip", &cdda_dflts.no_skip, CONF_TYPE_FLAG, 0 , 0, 1, NULL }, | |
85 { "skip", &cdda_dflts.no_skip, CONF_TYPE_FLAG, 0 , 1, 0, NULL }, | |
86 { "device", &cdda_dflts.device, CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
87 { "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
|
88 {NULL, NULL, 0, 0, 0, 0, NULL} |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
89 }; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
90 |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
11652
diff
changeset
|
91 extern int cdd_identify(const char *dev); |
9801 | 92 extern int cddb_resolve(const char *dev, char **xmcd_file); |
93 extern cd_info_t* cddb_parse_xmcd(char *xmcd_file); | |
94 | |
95 static int seek(stream_t* s,off_t pos); | |
96 static int fill_buffer(stream_t* s, char* buffer, int max_len); | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
97 static void close_cdda(stream_t* s); |
9801 | 98 |
99 static int open_cdda(stream_t *st,int m, void* opts, int* file_format) { | |
100 struct cdda_params* p = (struct cdda_params*)opts; | |
101 int mode = p->paranoia_mode; | |
102 int offset = p->toc_offset; | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
103 #ifndef HAVE_LIBCDIO |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
104 cdrom_drive* cdd = NULL; |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
105 #else |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
106 cdrom_drive_t* cdd = NULL; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
107 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
108 cdda_priv* priv; |
9801 | 109 cd_info_t *cd_info,*cddb_info = NULL; |
6696 | 110 unsigned int audiolen=0; |
16926
24c52f2c3aa9
fix cdda://n syntax: do not hang when n > nr_tracks and play only track n,
reimar
parents:
16914
diff
changeset
|
111 int last_track; |
6696 | 112 int i; |
9801 | 113 char *xmcd_file = NULL; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
114 |
9801 | 115 if(m != STREAM_READ) { |
116 m_struct_free(&stream_opts,opts); | |
117 return STREAM_UNSUPORTED; | |
118 } | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
119 |
10591 | 120 if(!p->device) { |
121 if (cdrom_device) | |
122 p->device = strdup(cdrom_device); | |
123 else | |
124 p->device = strdup(DEFAULT_CDROM_DEVICE); | |
125 } | |
126 | |
21479 | 127 #ifdef HAVE_CDDB |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
11652
diff
changeset
|
128 // 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
|
129 // 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
|
130 if(cdd_identify(p->device) >= 0 && strncmp(st->url,"cddb",4) == 0) { |
9801 | 131 i = cddb_resolve(p->device, &xmcd_file); |
132 if(i == 0) { | |
133 cddb_info = cddb_parse_xmcd(xmcd_file); | |
134 free(xmcd_file); | |
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 } |
9801 | 137 #endif |
138 | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
139 #ifndef HAVE_LIBCDIO |
9801 | 140 if(p->generic_dev) |
141 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
|
142 else |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
143 #endif |
8958
56bf90cefb10
Removed the hardcoded /dev/cdrom for NetBSD and added an work around
bertrand
parents:
8609
diff
changeset
|
144 #if defined(__NetBSD__) |
9801 | 145 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
|
146 #else |
9801 | 147 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
|
148 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
149 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
150 if(!cdd) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16940
diff
changeset
|
151 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_MPDEMUX_CDDA_CantOpenCDDADevice); |
9801 | 152 m_struct_free(&stream_opts,opts); |
18225 | 153 free(cddb_info); |
9801 | 154 return STREAM_ERROR; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
155 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
156 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
157 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
|
158 |
9801 | 159 if(p->sector_size) { |
160 cdd->nsectors = p->sector_size; | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
161 #ifndef HAVE_LIBCDIO |
9801 | 162 cdd->bigbuff = p->sector_size * CD_FRAMESIZE_RAW; |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
163 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
164 } |
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(cdda_open(cdd) != 0) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16940
diff
changeset
|
167 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_MPDEMUX_CDDA_CantOpenDisc); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
168 cdda_close(cdd); |
9801 | 169 m_struct_free(&stream_opts,opts); |
18225 | 170 free(cddb_info); |
9801 | 171 return STREAM_ERROR; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
172 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
173 |
6696 | 174 cd_info = cd_info_new(); |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16940
diff
changeset
|
175 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_MPDEMUX_CDDA_AudioCDFoundWithNTracks,cdda_tracks(cdd)); |
6696 | 176 for(i=0;i<cdd->tracks;i++) { |
177 char track_name[80]; | |
178 long sec=cdda_track_firstsector(cdd,i+1); | |
179 long off=cdda_track_lastsector(cdd,i+1)-sec+1; | |
180 | |
181 sprintf(track_name, "Track %d", i+1); | |
182 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 ); | |
183 audiolen += off; | |
184 } | |
185 cd_info->min = (unsigned int)(audiolen/(60*75)); | |
186 cd_info->sec = (unsigned int)((audiolen/75)%60); | |
187 cd_info->msec = (unsigned int)(audiolen%75); | |
188 | |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18922
diff
changeset
|
189 priv = malloc(sizeof(cdda_priv)); |
6696 | 190 memset(priv, 0, sizeof(cdda_priv)); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
191 priv->cd = cdd; |
6696 | 192 priv->cd_info = cd_info; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
193 |
9801 | 194 if(p->toc_bias) |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
195 offset -= cdda_track_firstsector(cdd,1); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
196 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
197 if(offset) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
198 int i; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
199 for(i = 0 ; i < cdd->tracks + 1 ; i++) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
200 cdd->disc_toc[i].dwStartSector += offset; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
201 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
202 |
9801 | 203 if(p->speed) |
204 cdda_speed_set(cdd,p->speed); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
205 |
16926
24c52f2c3aa9
fix cdda://n syntax: do not hang when n > nr_tracks and play only track n,
reimar
parents:
16914
diff
changeset
|
206 last_track = cdda_tracks(cdd); |
24c52f2c3aa9
fix cdda://n syntax: do not hang when n > nr_tracks and play only track n,
reimar
parents:
16914
diff
changeset
|
207 if (p->span.start > last_track) p->span.start = last_track; |
24c52f2c3aa9
fix cdda://n syntax: do not hang when n > nr_tracks and play only track n,
reimar
parents:
16914
diff
changeset
|
208 if (p->span.end < p->span.start) p->span.end = p->span.start; |
24c52f2c3aa9
fix cdda://n syntax: do not hang when n > nr_tracks and play only track n,
reimar
parents:
16914
diff
changeset
|
209 if (p->span.end > last_track) p->span.end = last_track; |
9801 | 210 if(p->span.start) |
211 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
|
212 else |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
213 priv->start_sector = cdda_disc_firstsector(cdd); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
214 |
9801 | 215 if(p->span.end) { |
216 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
|
217 } else |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
218 priv->end_sector = cdda_disc_lastsector(cdd); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
219 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
220 priv->cdp = paranoia_init(cdd); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
221 if(priv->cdp == NULL) { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
222 cdda_close(cdd); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
223 free(priv); |
9801 | 224 cd_info_free(cd_info); |
225 m_struct_free(&stream_opts,opts); | |
18225 | 226 free(cddb_info); |
9801 | 227 return STREAM_ERROR; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
228 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
229 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
230 if(mode == 0) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
231 mode = PARANOIA_MODE_DISABLE; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
232 else if(mode == 1) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
233 mode = PARANOIA_MODE_OVERLAP; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
234 else |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
235 mode = PARANOIA_MODE_FULL; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
236 |
9801 | 237 if(p->no_skip) |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
238 mode |= PARANOIA_MODE_NEVERSKIP; |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
239 #ifndef HAVE_LIBCDIO |
16635
8fd80915d2a2
10l, forgotten call to paranoia_modeset to actually set the desired mode.
reimar
parents:
16524
diff
changeset
|
240 paranoia_modeset(cdd, mode); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
241 |
9801 | 242 if(p->search_overlap >= 0) |
243 paranoia_overlapset(cdd,p->search_overlap); | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
244 #else |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
245 paranoia_modeset(priv->cdp, mode); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
246 |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
247 if(p->search_overlap >= 0) |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
248 paranoia_overlapset(priv->cdp,p->search_overlap); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
249 #endif |
6384
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 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
|
252 priv->sector = priv->start_sector; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
253 |
21479 | 254 #ifdef HAVE_CDDB |
9801 | 255 if(cddb_info) { |
256 cd_info_free(cd_info); | |
257 priv->cd_info = cddb_info; | |
258 cd_info_debug( cddb_info ); | |
259 } | |
260 #endif | |
261 | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
262 st->priv = priv; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
263 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
|
264 st->end_pos = priv->end_sector*CD_FRAMESIZE_RAW; |
9801 | 265 st->type = STREAMTYPE_CDDA; |
266 st->sector_size = CD_FRAMESIZE_RAW; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
267 |
9801 | 268 st->fill_buffer = fill_buffer; |
269 st->seek = seek; | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
270 st->close = close_cdda; |
9801 | 271 |
272 *file_format = DEMUXER_TYPE_RAWAUDIO; | |
273 | |
274 m_struct_free(&stream_opts,opts); | |
275 | |
276 return STREAM_OK; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
277 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
278 |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
279 #ifndef HAVE_LIBCDIO |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
280 static void cdparanoia_callback(long inpos, int function) { |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
281 #else |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
282 static void cdparanoia_callback(long int inpos, paranoia_cb_mode_t function) { |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
283 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
284 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
285 |
9801 | 286 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
|
287 cdda_priv* p = (cdda_priv*)s->priv; |
6696 | 288 cd_track_t *cd_track; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
289 int16_t * buf; |
9801 | 290 int i; |
6384
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 buf = paranoia_read(p->cdp,cdparanoia_callback); |
20195 | 293 if (!buf) |
294 return 0; | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
295 |
11652 | 296 #ifdef WORDS_BIGENDIAN |
297 for(i=0;i<CD_FRAMESIZE_RAW/2;i++) | |
298 buf[i]=le2me_16(buf[i]); | |
299 #endif | |
300 | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
301 p->sector++; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
302 s->pos = p->sector*CD_FRAMESIZE_RAW; |
9801 | 303 memcpy(buffer,buf,CD_FRAMESIZE_RAW); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
304 |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
305 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
|
306 s->eof = 1; |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
307 return 0; |
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
308 } |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
309 |
6696 | 310 for(i=0;i<p->cd->tracks;i++){ |
311 if(p->cd->disc_toc[i].dwStartSector==p->sector-1) { | |
312 cd_track = cd_info_get_track(p->cd_info, i+1); | |
313 //printf("Track %d, sector=%d\n", i, p->sector-1); | |
314 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
|
315 mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name); |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
18225
diff
changeset
|
316 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK=%d\n", cd_track->track_nb); |
6696 | 317 } |
318 break; | |
319 } | |
320 } | |
321 | |
322 | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
323 return CD_FRAMESIZE_RAW; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
324 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
325 |
9801 | 326 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
|
327 cdda_priv* p = (cdda_priv*)s->priv; |
6696 | 328 cd_track_t *cd_track; |
329 int sec; | |
330 int current_track=0, seeked_track=0; | |
331 int i; | |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
332 |
9801 | 333 s->pos = newpos; |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
334 if(s->pos < 0) { |
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
335 s->eof = 1; |
9801 | 336 return 0; |
9656
ef5ae9f9c6e6
fixed trivial seeking bugs, patch by Krister Lagerstrom <krister@kmlager.com>
alex
parents:
8958
diff
changeset
|
337 } |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
338 |
6696 | 339 sec = s->pos/CD_FRAMESIZE_RAW; |
8524 | 340 //printf("pos: %d, sec: %d ## %d\n", (int)s->pos, (int)sec, CD_FRAMESIZE_RAW); |
341 //printf("sector: %d new: %d\n", p->sector, sec ); | |
6696 | 342 |
343 for(i=0;i<p->cd->tracks;i++){ | |
8559 | 344 // printf("trk #%d: %d .. %d\n",i,p->cd->disc_toc[i].dwStartSector,p->cd->disc_toc[i+1].dwStartSector); |
8524 | 345 if( p->sector>=p->cd->disc_toc[i].dwStartSector && p->sector<p->cd->disc_toc[i+1].dwStartSector ) { |
6696 | 346 current_track = i; |
347 } | |
8524 | 348 if( sec>=p->cd->disc_toc[i].dwStartSector && sec<p->cd->disc_toc[i+1].dwStartSector ) { |
6696 | 349 seeked_track = i; |
350 } | |
351 } | |
352 //printf("current: %d, seeked: %d\n", current_track, seeked_track); | |
353 if( current_track!=seeked_track ) { | |
354 //printf("Track %d, sector=%d\n", seeked_track, sec); | |
355 cd_track = cd_info_get_track(p->cd_info, seeked_track+1); | |
356 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
|
357 mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name); |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
18225
diff
changeset
|
358 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK=%d\n", cd_track->track_nb); |
6696 | 359 } |
360 | |
361 } | |
8524 | 362 #if 0 |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
363 if(sec < p->start_sector) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
364 sec = p->start_sector; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
365 else if(sec > p->end_sector) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
366 sec = p->end_sector; |
8524 | 367 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
368 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
369 p->sector = sec; |
6696 | 370 // s->pos = sec*CD_FRAMESIZE_RAW; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
371 |
8524 | 372 //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
|
373 paranoia_seek(p->cdp,sec,SEEK_SET); |
9801 | 374 return 1; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
375 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
376 |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16926
diff
changeset
|
377 static void close_cdda(stream_t* s) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
378 cdda_priv* p = (cdda_priv*)s->priv; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
379 paranoia_free(p->cdp); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
380 cdda_close(p->cd); |
9801 | 381 cd_info_free(p->cd_info); |
382 free(p); | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
383 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
384 |
9801 | 385 stream_info_t stream_info_cdda = { |
386 "CDDA", | |
387 "cdda", | |
388 "Albeu", | |
389 "", | |
390 open_cdda, | |
21479 | 391 { "cdda", |
392 #ifdef HAVE_CDDB | |
393 "cddb", | |
394 #endif | |
395 NULL }, | |
9801 | 396 &stream_opts, |
397 1 // Urls are an option string | |
398 }; |