[1827] | 1 | //driver_dmx.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012 |
---|
[1827] | 5 | * |
---|
| 6 | * This file is part of roard 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 | * RoarAudio 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[1827] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "roard.h" |
---|
| 27 | |
---|
[2503] | 28 | #ifndef ROAR_WITHOUT_DCOMP_DMX |
---|
| 29 | |
---|
[2367] | 30 | int driver_dmx_open_vio (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
[5242] | 31 | struct roar_vio_defaults def; |
---|
[5708] | 32 | struct roar_vio_calls * vio; |
---|
| 33 | int err; |
---|
[5242] | 34 | |
---|
| 35 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY, 0644) == -1 ) |
---|
| 36 | return -1; |
---|
[1827] | 37 | |
---|
[5708] | 38 | vio = roar_mm_malloc(sizeof(struct roar_vio_calls)); |
---|
| 39 | if ( vio == NULL ) |
---|
| 40 | return -1; |
---|
| 41 | roar_vio_clear_calls(vio); |
---|
| 42 | |
---|
[1830] | 43 | if ( fh == -1 ) { |
---|
| 44 | if ( device == NULL ) |
---|
| 45 | device = getenv("DMX"); |
---|
[1827] | 46 | |
---|
[1830] | 47 | if ( device == NULL ) |
---|
| 48 | device = "/dev/dmx"; |
---|
| 49 | |
---|
[5708] | 50 | if ( roar_vio_open_dstr(vio, device, &def, 1) == -1 ) { |
---|
| 51 | err = roar_error; |
---|
| 52 | roar_mm_free(vio); |
---|
| 53 | roar_error = err; |
---|
[1827] | 54 | return -1; |
---|
[5708] | 55 | } |
---|
[1827] | 56 | } else { |
---|
[5708] | 57 | if ( roar_vio_open_fh(vio, fh) == -1 ) { |
---|
| 58 | err = roar_error; |
---|
| 59 | roar_mm_free(vio); |
---|
| 60 | roar_error = err; |
---|
[1827] | 61 | return -1; |
---|
[5708] | 62 | } |
---|
[1827] | 63 | } |
---|
| 64 | |
---|
[5708] | 65 | vio->flags |= ROAR_VIO_FLAGS_FREESELF; |
---|
| 66 | |
---|
| 67 | roar_vio_open_pass(inst, vio); |
---|
[1827] | 68 | inst->write = driver_dmx_write; |
---|
[1828] | 69 | inst->ctl = driver_dmx_ctl; |
---|
| 70 | |
---|
| 71 | info->codec = ROAR_CODEC_DMX512; |
---|
[1827] | 72 | |
---|
[2368] | 73 | if ( sstream != NULL ) |
---|
| 74 | driver_dmx_ctl(inst, ROAR_VIO_CTL_SET_SSTREAM, sstream); |
---|
| 75 | |
---|
[1827] | 76 | return 0; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | ssize_t driver_dmx_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 80 | if ( vio == NULL || buf == NULL ) |
---|
| 81 | return -1; |
---|
| 82 | |
---|
| 83 | if ( count != 512 ) |
---|
| 84 | return -1; |
---|
| 85 | |
---|
[5708] | 86 | if ( roar_vio_lseek(vio->inst, 0, SEEK_SET) == (roar_off_t)-1 ) |
---|
[1827] | 87 | return -1; |
---|
| 88 | |
---|
[5708] | 89 | return roar_vio_write(vio->inst, buf, count); |
---|
[1827] | 90 | } |
---|
| 91 | |
---|
[5278] | 92 | int driver_dmx_ctl(struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) { |
---|
[1828] | 93 | |
---|
| 94 | if ( vio == NULL ) |
---|
| 95 | return -1; |
---|
| 96 | |
---|
| 97 | switch (cmd) { |
---|
| 98 | case ROAR_VIO_CTL_SET_SSTREAM: |
---|
| 99 | ROAR_STREAM(data)->dir = ROAR_DIR_LIGHT_OUT; |
---|
[1829] | 100 | ROAR_STREAM_SERVER(data)->codec_orgi = ROAR_CODEC_DMX512; |
---|
[1828] | 101 | break; |
---|
| 102 | default: |
---|
[5708] | 103 | roar_err_set(ROAR_ERROR_BADRQC); |
---|
[1828] | 104 | return -1; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | return 0; |
---|
| 108 | } |
---|
| 109 | |
---|
[2503] | 110 | #endif |
---|
| 111 | |
---|
[1827] | 112 | //ll |
---|