source: roaraudio/roard/driver_dmx.c @ 6056:8d4468a24909

Last change on this file since 6056:8d4468a24909 was 6052:d48765b2475e, checked in by phi, 9 years ago

updated copyright headers

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