[343] | 1 | //audiocd.c: |
---|
| 2 | |
---|
[688] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - August 2008 |
---|
| 5 | * |
---|
| 6 | * This file is part of libroaryiff a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * libroaryiff is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
[343] | 25 | #include <libroaryiff.h> |
---|
| 26 | |
---|
[806] | 27 | struct { |
---|
| 28 | int fh; |
---|
| 29 | int stream; |
---|
| 30 | char * device; |
---|
| 31 | } _g_roaryiff_cdrom = {-1, -1, NULL}; |
---|
| 32 | |
---|
[343] | 33 | int YEjectAudioCD(YConnection *con) { |
---|
[806] | 34 | YStopAudioCD(con); |
---|
[343] | 35 | return system("eject") == 0 ? 0 : -1; |
---|
| 36 | } |
---|
| 37 | |
---|
[806] | 38 | int YPlayAudioCDTrack(YConnection *con, int track_number) { |
---|
| 39 | struct roar_connection rcon; |
---|
| 40 | int flags; |
---|
| 41 | |
---|
| 42 | if ( con == NULL ) |
---|
| 43 | return -1; |
---|
| 44 | |
---|
| 45 | rcon.fh = con->fd; |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | if ( _g_roaryiff_cdrom.fh == -1 ) { |
---|
| 49 | // ok, we need to open the cdrom device |
---|
| 50 | if ( _g_roaryiff_cdrom.device == NULL ) { |
---|
| 51 | _g_roaryiff_cdrom.device = roar_cdromdevice(); |
---|
| 52 | if ( _g_roaryiff_cdrom.device == NULL ) |
---|
| 53 | return -1; |
---|
| 54 | } |
---|
| 55 | if ( (_g_roaryiff_cdrom.fh = open(_g_roaryiff_cdrom.device, O_RDONLY, 0644)) == -1 ) |
---|
| 56 | return -1; |
---|
| 57 | |
---|
| 58 | if ( (flags = fcntl(_g_roaryiff_cdrom.fh, F_GETFL, 0)) == -1 ) { |
---|
| 59 | close(_g_roaryiff_cdrom.fh); |
---|
| 60 | _g_roaryiff_cdrom.fh = -1; |
---|
| 61 | return -1; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | flags |= FD_CLOEXEC; |
---|
| 65 | |
---|
| 66 | if ( fcntl(_g_roaryiff_cdrom.fh, F_SETFL, flags) == -1 ) { |
---|
| 67 | close(_g_roaryiff_cdrom.fh); |
---|
| 68 | _g_roaryiff_cdrom.fh = -1; |
---|
| 69 | return -1; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | return -1; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | int YStopAudioCD(YConnection *con) { |
---|
| 77 | struct roar_connection rcon; |
---|
| 78 | |
---|
| 79 | if ( con == NULL ) |
---|
| 80 | return -1; |
---|
| 81 | |
---|
| 82 | rcon.fh = con->fd; |
---|
| 83 | |
---|
| 84 | if ( _g_roaryiff_cdrom.fh != -1 ) { |
---|
| 85 | close(_g_roaryiff_cdrom.fh); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if ( _g_roaryiff_cdrom.stream != -1 ) { |
---|
| 89 | roar_kick(&rcon, ROAR_OT_STREAM, _g_roaryiff_cdrom.stream); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | return 0; |
---|
| 93 | } |
---|
| 94 | |
---|
[343] | 95 | //ll |
---|