[1827] | 1 | //driver_dmx.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5823] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2013 |
---|
[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; |
---|
[5754] | 34 | const char * dev = device; |
---|
[5242] | 35 | |
---|
| 36 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY, 0644) == -1 ) |
---|
| 37 | return -1; |
---|
[1827] | 38 | |
---|
[5708] | 39 | vio = roar_mm_malloc(sizeof(struct roar_vio_calls)); |
---|
| 40 | if ( vio == NULL ) |
---|
| 41 | return -1; |
---|
| 42 | roar_vio_clear_calls(vio); |
---|
| 43 | |
---|
[1830] | 44 | if ( fh == -1 ) { |
---|
[5754] | 45 | if ( dev == NULL ) |
---|
| 46 | dev = roar_env_get("DMX"); |
---|
[1827] | 47 | |
---|
[5754] | 48 | if ( dev == NULL ) |
---|
[5832] | 49 | dev = roar_libroar_get_path_static("dev-default-dmx4linux"); |
---|
[1830] | 50 | |
---|
[5754] | 51 | if ( roar_vio_open_dstr(vio, dev, &def, 1) == -1 ) { |
---|
[5708] | 52 | err = roar_error; |
---|
| 53 | roar_mm_free(vio); |
---|
| 54 | roar_error = err; |
---|
[1827] | 55 | return -1; |
---|
[5708] | 56 | } |
---|
[1827] | 57 | } else { |
---|
[5708] | 58 | if ( roar_vio_open_fh(vio, fh) == -1 ) { |
---|
| 59 | err = roar_error; |
---|
| 60 | roar_mm_free(vio); |
---|
| 61 | roar_error = err; |
---|
[1827] | 62 | return -1; |
---|
[5708] | 63 | } |
---|
[1827] | 64 | } |
---|
| 65 | |
---|
[5708] | 66 | vio->flags |= ROAR_VIO_FLAGS_FREESELF; |
---|
| 67 | |
---|
| 68 | roar_vio_open_pass(inst, vio); |
---|
[1827] | 69 | inst->write = driver_dmx_write; |
---|
[1828] | 70 | inst->ctl = driver_dmx_ctl; |
---|
| 71 | |
---|
| 72 | info->codec = ROAR_CODEC_DMX512; |
---|
[1827] | 73 | |
---|
[2368] | 74 | if ( sstream != NULL ) |
---|
| 75 | driver_dmx_ctl(inst, ROAR_VIO_CTL_SET_SSTREAM, sstream); |
---|
| 76 | |
---|
[1827] | 77 | return 0; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | ssize_t driver_dmx_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 81 | if ( vio == NULL || buf == NULL ) |
---|
| 82 | return -1; |
---|
| 83 | |
---|
| 84 | if ( count != 512 ) |
---|
| 85 | return -1; |
---|
| 86 | |
---|
[5708] | 87 | if ( roar_vio_lseek(vio->inst, 0, SEEK_SET) == (roar_off_t)-1 ) |
---|
[1827] | 88 | return -1; |
---|
| 89 | |
---|
[5708] | 90 | return roar_vio_write(vio->inst, buf, count); |
---|
[1827] | 91 | } |
---|
| 92 | |
---|
[5278] | 93 | int driver_dmx_ctl(struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) { |
---|
[1828] | 94 | |
---|
| 95 | if ( vio == NULL ) |
---|
| 96 | return -1; |
---|
| 97 | |
---|
| 98 | switch (cmd) { |
---|
| 99 | case ROAR_VIO_CTL_SET_SSTREAM: |
---|
| 100 | ROAR_STREAM(data)->dir = ROAR_DIR_LIGHT_OUT; |
---|
[1829] | 101 | ROAR_STREAM_SERVER(data)->codec_orgi = ROAR_CODEC_DMX512; |
---|
[1828] | 102 | break; |
---|
| 103 | default: |
---|
[5708] | 104 | roar_err_set(ROAR_ERROR_BADRQC); |
---|
[1828] | 105 | return -1; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | return 0; |
---|
| 109 | } |
---|
| 110 | |
---|
[2503] | 111 | #endif |
---|
| 112 | |
---|
[1827] | 113 | //ll |
---|