~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kscd/libwm/plat_news.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: plat_news.c,v 1.8 2001/04/10 17:34:52 dfoerste Exp $
 
3
 *
 
4
 * This file is part of WorkMan, the civilized CD player library
 
5
 * (c) 1991-1997 by Steven Grimm (original author)
 
6
 * (c) by Dirk Fļæ½rsterling (current 'author' = maintainer)
 
7
 * The maintainer can be contacted by his e-mail address:
 
8
 * milliByte@DeathsDoor.com 
 
9
 *
 
10
 * This library is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU Library General Public
 
12
 * License as published by the Free Software Foundation; either
 
13
 * version 2 of the License, or (at your option) any later version.
 
14
 *
 
15
 * This library is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
18
 * Library General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU Library General Public
 
21
 * License along with this library; if not, write to the Free
 
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 *
 
24
 *
 
25
 * Sony NEWS-specific drive control routines.
 
26
 */
 
27
 
 
28
static char plat_news_id[] = "$Id: plat_news.c,v 1.8 2001/04/10 17:34:52 dfoerste Exp $";
 
29
 
 
30
#if defined( __sony_news) || defined(sony_news)
 
31
 
 
32
#include <errno.h>
 
33
#include <stdio.h>
 
34
#include <fcntl.h>
 
35
#include <ustat.h>
 
36
#include <CD.h>
 
37
#include <sys/types.h>
 
38
#include <sys/param.h>
 
39
#include <sys/stat.h>
 
40
#include <sys/time.h>
 
41
 
 
42
#include "include/wm_config.h"
 
43
#include "include/wm_struct.h"
 
44
#include "include/wm_cdtext.h"
 
45
 
 
46
#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
 
47
 
 
48
void *malloc();
 
49
char *strchr();
 
50
 
 
51
extern char     *cd_device;
 
52
extern int      intermittent_dev;
 
53
 
 
54
int     min_volume = 128;
 
55
int     max_volume = 255;
 
56
 
 
57
/*
 
58
 * Initialize the drive.  A no-op for the generic driver.
 
59
 */
 
60
int
 
61
gen_init( struct wm_drive *d )
 
62
{
 
63
  return (0);
 
64
} /* gen_init() */
 
65
 
 
66
/*
 
67
 * Open the CD device and figure out what kind of drive is attached.
 
68
 */
 
69
int
 
70
wmcd_open( struct wm_drive *d )
 
71
{
 
72
  int           fd;
 
73
  static int    warned = 0;
 
74
  char  vendor[32] = WM_STR_GENVENDOR;
 
75
  char   model[32] = WM_STR_GENMODEL;
 
76
  char     rev[32] = WM_STR_GENREV;
 
77
  
 
78
  if (d->fd >= 0)               /* Device already open? */
 
79
    {
 
80
      wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_open(): [device is open (fd=%d)]\n", d->fd);
 
81
      return (0);
 
82
    }
 
83
  
 
84
  intermittent_dev = 1;
 
85
  if (cd_device == NULL)
 
86
    cd_device = DEFAULT_CD_DEVICE;
 
87
  
 
88
  if ((d->fd = CD_Open(cd_device, 0)) < 0)
 
89
    {
 
90
      /* Solaris 2.2 volume manager moves links around */
 
91
      if (errno == ENOENT && intermittent_dev)
 
92
        return (0);
 
93
      
 
94
      if (errno == EACCES)
 
95
        {
 
96
          if (!warned)
 
97
            {
 
98
              /*
 
99
              char      realname[MAXPATHLEN];
 
100
              
 
101
              if (realpath(cd_device, realname) == NULL)
 
102
                {
 
103
                  perror("realpath");
 
104
                  return 1;
 
105
                }
 
106
                */
 
107
              return -EACCES;
 
108
            }
 
109
        }
 
110
      else if (errno != EIO)    /* defined at top */
 
111
        {
 
112
          return (-6);
 
113
        }
 
114
      
 
115
      /* No CD in drive. */
 
116
      return (1);
 
117
    }
 
118
  
 
119
  /* Now fill in the relevant parts of the wm_drive structure. */
 
120
  fd = d->fd;
 
121
  
 
122
  /* Figure out the drive type, if possible */
 
123
  wm_scsi_get_drive_type(d, vendor, model, rev);
 
124
  *d = *(find_drive_struct(vendor, model, rev));
 
125
  wm_drive_settype(vendor, model, rev);
 
126
  
 
127
  d->fd = fd;
 
128
  
 
129
  (d->init)(d);
 
130
  
 
131
  return (0);
 
132
} /* wmcd_open() */
 
133
 
 
134
/*
 
135
 * Close the CD device.
 
136
 */
 
137
int
 
138
wmcd_close(int fd)
 
139
{
 
140
  int   ret;
 
141
  
 
142
  ret = CD_Close(fd);
 
143
  wm_susleep(3000000);
 
144
  return (ret);
 
145
} /* wmcd_close */
 
146
 
 
147
/*
 
148
 * Re-Open the device if it is open.
 
149
 */
 
150
int
 
151
wmcd_reopen( struct wm_drive *d )
 
152
{
 
153
  int status;
 
154
  
 
155
  do {
 
156
    wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_reopen\n");
 
157
    if (d->fd >= 0)             /* Device really open? */
 
158
      {
 
159
        wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device.\n");
 
160
        status = wmcd_close( d->fd );   /* close it! */
 
161
        /* we know, that the file is closed, do we? */
 
162
        d->fd = -1;
 
163
      }
 
164
    wm_susleep( 1000 );
 
165
    wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calling wmcd_open()\n");
 
166
    status = wmcd_open( d ); /* open it as usual */
 
167
    wm_susleep( 1000 );
 
168
  } while ( status != 0 );
 
169
  return status;
 
170
} /* wmcd_reopen() */
 
171
 
 
172
/*
 
173
 * Pass SCSI commands to the device.
 
174
 */
 
175
int
 
176
wm_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen, 
 
177
        unsigned char *buf, int buflen, int getreply)
 
178
{
 
179
        /* NEWS can't do SCSI passthrough... or can it? */
 
180
        return (-1);
 
181
} /* wm_scsi() */
 
182
 
 
183
 
 
184
/*
 
185
 * Get the current status of the drive: the current play mode, the absolute
 
186
 * position from start of disc (in frames), and the current track and index
 
187
 * numbers if the CD is playing or paused.
 
188
 */
 
189
int
 
190
gen_get_drive_status( struct wm_drive *d, enum wm_cd_modes oldmode, 
 
191
                      enum wm_cd_modes *mode, int *pos, int *track, int *index)
 
192
{
 
193
  struct CD_Status              sc;
 
194
 
 
195
  /* If we can't get status, the CD is ejected, so default to that. */
 
196
  *mode = WM_CDM_EJECTED;
 
197
  
 
198
  /* Is the device open? */
 
199
  if (d->fd < 0)
 
200
    {
 
201
      switch (wmcd_open(d)) {
 
202
      case -1:  /* error */
 
203
        return (-1);
 
204
        
 
205
      case 1:           /* retry */
 
206
        return (0);
 
207
      }
 
208
    }
 
209
  
 
210
  /* Disc is ejected.  Close the device. */
 
211
  if (CD_GetStatus(d->fd, &sc))
 
212
    {
 
213
      wmcd_close(d->fd);
 
214
      d->fd = -1;
 
215
      return (0);
 
216
    }
 
217
  
 
218
  switch (sc.status) {
 
219
  case CDSTAT_PLAY:
 
220
    *mode = PLAYING;
 
221
    *track = sc.tno;
 
222
    *index = sc.index;
 
223
    *pos = sc.baddr;
 
224
    break;
 
225
    
 
226
  case CDSTAT_PAUSE:
 
227
    if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED)
 
228
      {
 
229
        *mode = WM_CDM_PAUSED;
 
230
        *track = sc.tno;
 
231
        *index = sc.index;
 
232
        *pos = sc.baddr;
 
233
      }
 
234
    else
 
235
      *mode = WM_CDM_STOPPED;
 
236
    break;
 
237
    
 
238
  case CDSTAT_STOP:
 
239
    if (oldmode == WM_CDM_PLAYING)
 
240
      {
 
241
        *mode = WM_CDM_TRACK_DONE;      /* waiting for next track. */
 
242
        break;
 
243
      }
 
244
    /* fall through */
 
245
    
 
246
  default:
 
247
    *mode = WM_CDM_STOPPED;
 
248
    break;
 
249
  }
 
250
  
 
251
  return (0);
 
252
} /* gen_get_drive_status() */
 
253
 
 
254
/*
 
255
 * Get the number of tracks on the CD.
 
256
 */
 
257
int
 
258
gen_get_trackcount(struct wm_drive *d, int *tracks)
 
259
{
 
260
  struct CD_Capacity    cc;
 
261
  
 
262
  if (CD_GetCapacity(d->fd, &cc))
 
263
    return (-1);
 
264
  
 
265
  *tracks = cc.etrack - 1;
 
266
  return (0);
 
267
} /* gen_get_trackcount() */
 
268
 
 
269
/*
 
270
 * Get the start time and mode (data or audio) of a track.
 
271
 */
 
272
int
 
273
gen_get_trackinfo( struct wm_drive *d, int track, int *data, int *startframe )
 
274
{
 
275
  struct CD_TOCinfo     hdr;
 
276
  struct CD_TOCdata     ent;
 
277
  
 
278
  hdr.strack = track;
 
279
  hdr.ntrack = 1;
 
280
  hdr.data = &ent;
 
281
  if (CD_ReadTOC(d->fd, &hdr))
 
282
    return (-1);
 
283
  
 
284
  *data = (ent.control & 4) ? 1 : 0;
 
285
  *startframe = ent.baddr;
 
286
  
 
287
  return (0);
 
288
} /* gen_get_trackinfo */
 
289
 
 
290
/*
 
291
 * Get the number of frames on the CD.
 
292
 */
 
293
int
 
294
gen_get_cdlen( struct wm_drive *d, int *frames )
 
295
{
 
296
  int           tmp;
 
297
  
 
298
  if ((d->get_trackcount)(d, &tmp))
 
299
    return (-1);
 
300
  
 
301
  return (gen_get_trackinfo(d, tmp + 1, &tmp, frames));
 
302
} /* gen_get_cdlen() */
 
303
 
 
304
 
 
305
/*
 
306
 * Play the CD from one position to another (both in frames.)
 
307
 */
 
308
int
 
309
gen_play( struct wm_drive *d, int start, int end )
 
310
{
 
311
  struct CD_PlayAddr            msf;
 
312
  
 
313
  msf.addrmode                  = CD_MSF;
 
314
  msf.addr.msf.startmsf.min     = start / (60*75);
 
315
  msf.addr.msf.startmsf.sec     = (start % (60*75)) / 75;
 
316
  msf.addr.msf.startmsf.frame   = start % 75;
 
317
  msf.addr.msf.endmsf.min               = end / (60*75);
 
318
  msf.addr.msf.endmsf.sec               = (end % (60*75)) / 75;
 
319
  msf.addr.msf.endmsf.frame     = end % 75;
 
320
  
 
321
  if (CD_Play(d->fd, &msf))
 
322
    {
 
323
      printf("wm_cd_play_chunk(%d,%d)\n",start,end);
 
324
      printf("msf = %d:%d:%d %d:%d:%d\n",
 
325
             msf.addr.msf.startmsf.min,
 
326
             msf.addr.msf.startmsf.sec,
 
327
             msf.addr.msf.startmsf.frame,
 
328
             msf.addr.msf.endmsf.min,
 
329
             msf.addr.msf.endmsf.sec,
 
330
             msf.addr.msf.endmsf.frame);
 
331
      perror("CD_Play");
 
332
      return (-1);
 
333
    }
 
334
  
 
335
  return (0);
 
336
} /* gen_play() */
 
337
 
 
338
/*
 
339
 * Pause the CD.
 
340
 */
 
341
int
 
342
gen_pause( struct wm_drive *d )
 
343
{
 
344
  CD_Pause(d->fd);
 
345
  return (0);
 
346
} /* gen_pause() */
 
347
 
 
348
/*
 
349
 * Resume playing the CD (assuming it was paused.)
 
350
 */
 
351
int
 
352
gen_resume( struct wm_drive *d )
 
353
{
 
354
        CD_Restart(d->fd);
 
355
        return (0);
 
356
} /* gen_resume() */
 
357
 
 
358
/*
 
359
 * Stop the CD.
 
360
 */
 
361
int
 
362
gen_stop( struct wm_drive *d )
 
363
{
 
364
        CD_Stop(d->fd);
 
365
        return (0);
 
366
} /* gen_stop() */
 
367
 
 
368
/*
 
369
 * Eject the current CD, if there is one.
 
370
 */
 
371
int
 
372
gen_eject( struct wm_drive *d )
 
373
{
 
374
  struct stat   stbuf;
 
375
  struct ustat  ust;
 
376
  
 
377
  if (fstat(d->fd, &stbuf) != 0)
 
378
    return (-2);
 
379
  
 
380
  /* Is this a mounted filesystem? */
 
381
  if (ustat(stbuf.st_rdev, &ust) == 0)
 
382
    return (-3);
 
383
  
 
384
  if (CD_AutoEject(d->fd))
 
385
    return (-1);
 
386
  
 
387
  /* Close the device if it needs to vanish. */
 
388
  if (intermittent_dev)
 
389
    {
 
390
      wmcd_close(d->fd);
 
391
      d->fd = -1;
 
392
    }
 
393
  
 
394
  return (0);
 
395
} /* gen_eject() */
 
396
 
 
397
/*----------------------------------------*
 
398
 * Close the CD tray
 
399
 *
 
400
 * Please edit and send changes to
 
401
 * milliByte@DeathsDoor.com
 
402
 *----------------------------------------*/
 
403
int 
 
404
gen_closetray(struct wm_drive *d)
 
405
{
 
406
#ifdef CAN_CLOSE
 
407
  if(!wmcd_close(d->fd))
 
408
    {
 
409
      d->fd=-1;
 
410
      return(wmcd_reopen(d));
 
411
    } else {
 
412
      return(-1);
 
413
    }
 
414
#else
 
415
  /* Always succeed if the drive can't close */
 
416
  return(0);
 
417
#endif /* CAN_CLOSE */
 
418
} /* gen_closetray() */
 
419
 
 
420
 
 
421
/*
 
422
 * Set the volume level for the left and right channels.  Their values
 
423
 * range from 0 to 100.
 
424
 */
 
425
int
 
426
gen_set_volume( struct wm_drive *d, int left, int right)
 
427
{
 
428
  /* NEWS can't adjust volume! */
 
429
  return (0);
 
430
}
 
431
 
 
432
/*
 
433
 * Read the initial volume from the drive, if available.  Each channel
 
434
 * ranges from 0 to 100, with -1 indicating data not available.
 
435
 */
 
436
int
 
437
gen_get_volume( struct wm_drive *d, omt *left, int *right)
 
438
{
 
439
  /* Suns, HPs, Linux, NEWS can't read the volume; oh well */
 
440
  *left = *right = -1;
 
441
  return (0);
 
442
} /* gen_get_volume() */
 
443
 
 
444
/*------------------------------------------------------------------------*
 
445
 * gen_get_cdtext(drive, buffer, lenght)
 
446
 *------------------------------------------------------------------------*/
 
447
 
 
448
int
 
449
gen_get_cdtext(struct wm_drive *d, unsigned char **pp_buffer, int *p_buffer_lenght)
 
450
{
 
451
  return -1; /* no SCSI, no CDTEXT */
 
452
} /* gen_get_cdtext() */
 
453
 
 
454
#endif