comparison stream/stream_cue.c @ 30763:08a3814981a2

Avoid fd_bin and fd_cue global variables.
author reimar
date Mon, 01 Mar 2010 19:35:18 +0000
parents e5c32d429e3a
children 0987402cd276
comparison
equal deleted inserted replaced
30762:e5c32d429e3a 30763:08a3814981a2
70 sizeof(struct stream_priv_s), 70 sizeof(struct stream_priv_s),
71 &stream_priv_dflts, 71 &stream_priv_dflts,
72 stream_opts_fields 72 stream_opts_fields
73 }; 73 };
74 74
75 static FILE* fd_cue;
76 static int fd_bin = 0;
77
78 static char cue_filename[256]; 75 static char cue_filename[256];
79 static char bincue_path[256]; 76 static char bincue_path[256];
80 77
81 78
82 typedef struct track 79 typedef struct track
118 return errval; 115 return errval;
119 return a * 10 + b; 116 return a * 10 + b;
120 } 117 }
121 118
122 /* presumes Line is preloaded with the "current" line of the file */ 119 /* presumes Line is preloaded with the "current" line of the file */
123 static int cue_getTrackinfo(char *Line, tTrack *track) 120 static int cue_getTrackinfo(FILE *fd_cue, char *Line, tTrack *track)
124 { 121 {
125 int already_set = 0; 122 int already_set = 0;
126 123
127 /* Get the 'mode' */ 124 /* Get the 'mode' */
128 if (strncmp(&Line[2], "TRACK ", 6)==0) 125 if (strncmp(&Line[2], "TRACK ", 6)==0)
179 const char *cur_name; 176 const char *cur_name;
180 int i,j; 177 int i,j;
181 char bin_filename[256]; 178 char bin_filename[256];
182 char s[256]; 179 char s[256];
183 char t[256]; 180 char t[256];
181 int fd_bin;
184 182
185 /* get the filename out of that */ 183 /* get the filename out of that */
186 /* 12345 6 */ 184 /* 12345 6 */
187 mp_msg (MSGT_OPEN,MSGL_INFO, "[bincue] cue_find_bin(%s)\n", firstline); 185 mp_msg (MSGT_OPEN,MSGL_INFO, "[bincue] cue_find_bin(%s)\n", firstline);
188 if (strncmp(firstline, "FILE \"",6)==0) 186 if (strncmp(firstline, "FILE \"",6)==0)
266 return -1; 264 return -1;
267 } 265 }
268 266
269 mp_msg(MSGT_OPEN,MSGL_INFO, 267 mp_msg(MSGT_OPEN,MSGL_INFO,
270 MSGTR_MPDEMUX_CUEREAD_UsingBinFile, cur_name); 268 MSGTR_MPDEMUX_CUEREAD_UsingBinFile, cur_name);
271 return 0; 269 return fd_bin;
272 } 270 }
273 271
274 static inline int cue_msf_2_sector(int minute, int second, int frame) { 272 static inline int cue_msf_2_sector(int minute, int second, int frame) {
275 return frame + (second + minute * 60 ) * 75; 273 return frame + (second + minute * 60 ) * 75;
276 } 274 }
313 struct stat filestat; 311 struct stat filestat;
314 char sLine[256]; 312 char sLine[256];
315 unsigned int sect; 313 unsigned int sect;
316 char *s,*t; 314 char *s,*t;
317 int i; 315 int i;
316 int fd_bin;
317 FILE *fd_cue;
318 318
319 /* we have no tracks at the beginning */ 319 /* we have no tracks at the beginning */
320 nTracks = 0; 320 nTracks = 0;
321
322 fd_bin = 0;
323 321
324 /* split the filename into a path and filename part */ 322 /* split the filename into a path and filename part */
325 s = strdup(in_cue_filename); 323 s = strdup(in_cue_filename);
326 t = strrchr(s, '/'); 324 t = strrchr(s, '/');
327 if (t == (char *)NULL) 325 if (t == (char *)NULL)
365 MSGTR_MPDEMUX_CUEREAD_ErrReadingFromCueFile, in_cue_filename); 363 MSGTR_MPDEMUX_CUEREAD_ErrReadingFromCueFile, in_cue_filename);
366 fclose (fd_cue); 364 fclose (fd_cue);
367 return -1; 365 return -1;
368 } 366 }
369 367
370 if (cue_find_bin(sLine)) { 368 fd_bin = cue_find_bin(sLine);
369 if (fd_bin == -1) {
371 fclose (fd_cue); 370 fclose (fd_cue);
372 return -1; 371 return -1;
373 } 372 }
374 373
375 374
383 return -1; 382 return -1;
384 } 383 }
385 384
386 while(!feof(fd_cue)) 385 while(!feof(fd_cue))
387 { 386 {
388 if (cue_getTrackinfo(sLine, &tracks[nTracks++]) != 0) 387 if (cue_getTrackinfo(fd_cue, sLine, &tracks[nTracks++]) != 0)
389 { 388 {
390 mp_msg(MSGT_OPEN,MSGL_ERR, 389 mp_msg(MSGT_OPEN,MSGL_ERR,
391 MSGTR_MPDEMUX_CUEREAD_ErrReadingFromCueFile, in_cue_filename); 390 MSGTR_MPDEMUX_CUEREAD_ErrReadingFromCueFile, in_cue_filename);
392 fclose (fd_cue); 391 fclose (fd_cue);
393 return -1; 392 return -1;
502 } 501 }
503 } 502 }
504 503
505 static int cue_vcd_read(stream_t *stream, char *mem, int size) { 504 static int cue_vcd_read(stream_t *stream, char *mem, int size) {
506 unsigned long position; 505 unsigned long position;
506 int fd_bin = stream->fd;
507 int track = cue_current_pos.track - 1; 507 int track = cue_current_pos.track - 1;
508 508
509 position = tracks[track].start_offset + 509 position = tracks[track].start_offset +
510 (cue_msf_2_sector(cue_current_pos.minute, 510 (cue_msf_2_sector(cue_current_pos.minute,
511 cue_current_pos.second, 511 cue_current_pos.second,