[1816] | 1 | //light.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include "roard.h" |
---|
| 26 | |
---|
[1818] | 27 | int light_init (unsigned int channels) { |
---|
| 28 | |
---|
[1819] | 29 | g_light_state.channels = 0; |
---|
| 30 | |
---|
[1922] | 31 | if ( channels == 0 || channels > (512*512) ) /* unrealstic values */ |
---|
| 32 | return -1; |
---|
| 33 | |
---|
[1818] | 34 | if ( (g_light_state.state = malloc(channels)) == NULL ) { |
---|
| 35 | return -1; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | g_light_state.channels = channels; |
---|
| 39 | |
---|
| 40 | return light_reset(); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | int light_free (void) { |
---|
| 44 | if ( g_light_state.state != NULL ) { |
---|
| 45 | free(g_light_state.state); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | g_light_state.channels = 0; |
---|
| 49 | |
---|
| 50 | return 0; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | int light_reset (void) { |
---|
| 54 | if ( g_light_state.channels == 0 ) |
---|
| 55 | return 0; |
---|
| 56 | |
---|
| 57 | if ( g_light_state.state == NULL ) |
---|
| 58 | return -1; |
---|
| 59 | |
---|
| 60 | memset(g_light_state.state, 0, g_light_state.channels); |
---|
| 61 | |
---|
| 62 | return 0; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | int light_update(void) { |
---|
| 66 | return 0; |
---|
| 67 | } |
---|
| 68 | |
---|
[1821] | 69 | int light_check_stream (int id) { |
---|
[1822] | 70 | struct roar_stream * s; |
---|
| 71 | struct roar_stream_server * ss; |
---|
[1823] | 72 | char buf[512]; |
---|
[1838] | 73 | int i; |
---|
[1822] | 74 | |
---|
| 75 | if ( g_streams[id] == NULL ) |
---|
| 76 | return -1; |
---|
| 77 | |
---|
| 78 | ROAR_DBG("light_check_stream(id=%i) = ?", id); |
---|
| 79 | |
---|
| 80 | s = ROAR_STREAM(ss = g_streams[id]); |
---|
| 81 | |
---|
[1823] | 82 | switch (s->info.codec) { |
---|
| 83 | case ROAR_CODEC_DMX512: |
---|
| 84 | if ( stream_vio_s_read(ss, buf, 512) != 512 ) { |
---|
| 85 | streams_delete(id); |
---|
| 86 | return -1; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | memcpy(g_light_state.state, buf, g_light_state.channels < 512 ? g_light_state.channels : 512); |
---|
| 90 | |
---|
[1838] | 91 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 92 | if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == id ) { |
---|
| 93 | if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) { |
---|
| 94 | if ( stream_vio_write(i, buf, 512) != 512 ) { |
---|
| 95 | streams_delete(i); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
[1823] | 101 | return 0; |
---|
| 102 | break; |
---|
| 103 | default: |
---|
| 104 | streams_delete(id); |
---|
| 105 | return -1; |
---|
| 106 | } |
---|
| 107 | |
---|
[1821] | 108 | return 0; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | int light_send_stream (int id) { |
---|
[1822] | 112 | int chans; |
---|
| 113 | struct roar_stream * s; |
---|
| 114 | struct roar_stream_server * ss; |
---|
| 115 | char buf[512]; |
---|
[1844] | 116 | register char * bufptr; |
---|
[1822] | 117 | |
---|
| 118 | if ( g_streams[id] == NULL ) |
---|
| 119 | return -1; |
---|
| 120 | |
---|
[1823] | 121 | ROAR_DBG("light_send_stream(id=%i) = ?", id); |
---|
[1822] | 122 | |
---|
| 123 | s = ROAR_STREAM(ss = g_streams[id]); |
---|
| 124 | |
---|
| 125 | switch (s->info.codec) { |
---|
| 126 | case ROAR_CODEC_DMX512: |
---|
| 127 | chans = g_light_state.channels; |
---|
| 128 | |
---|
| 129 | if ( chans > 512 ) |
---|
| 130 | chans = 512; |
---|
| 131 | |
---|
[1844] | 132 | if ( chans == 512 ) { |
---|
| 133 | bufptr = g_light_state.state; |
---|
| 134 | } else { |
---|
| 135 | memset(buf, 0, 512); |
---|
| 136 | memcpy(buf, g_light_state.state, chans); |
---|
| 137 | bufptr = buf; |
---|
[1822] | 138 | } |
---|
| 139 | |
---|
[1844] | 140 | if ( stream_vio_s_write(ss, bufptr, 512) != 512 ) { |
---|
| 141 | streams_delete(id); |
---|
| 142 | return -1; |
---|
[1822] | 143 | } |
---|
| 144 | |
---|
| 145 | return 0; |
---|
| 146 | break; |
---|
| 147 | default: |
---|
| 148 | streams_delete(id); |
---|
| 149 | return -1; |
---|
| 150 | } |
---|
| 151 | |
---|
[1821] | 152 | return 0; |
---|
| 153 | } |
---|
| 154 | |
---|
[1816] | 155 | //ll |
---|