source: roaraudio/plugins/ao/ao_roar.c @ 3232:cd6b1b93bc03

Last change on this file since 3232:cd6b1b93bc03 was 3232:cd6b1b93bc03, checked in by phi, 14 years ago

update (C)

File size: 3.7 KB
Line 
1/*
2 *
3 *  ao_roar.c
4 *
5 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
6 *      based on ao_esd.c of libao by Stan Seibert - July 2000, July 2001
7 *
8 *  This file is part of RoarAudio, a cross-platform sound server. See
9 *  README for a history of this source code.
10 *
11 *  This file is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2, or (at your option)
14 *  any later version.
15 *
16 *  RoarAudio is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with GNU Make; see the file COPYING.  If not, write to
23 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 */
26
27#include <stdio.h>
28#include <unistd.h>
29#include <stdlib.h>
30#include <string.h>
31
32#include <roaraudio.h>
33#include <ao/ao.h>
34#include <ao/plugin.h>
35
36static char * ao_roar_options[] = {"host"};
37
38/*
39typedef struct ao_info {
40        int  type; // live output or file output?
41        char *name; // full name of driver
42        char *short_name; // short name of driver
43        char *author; // driver author
44        char *comment; // driver comment
45        int  preferred_byte_format;
46        int  priority;
47        char **options;
48        int  option_count;
49} ao_info;
50*/
51
52static ao_info ao_roar_info =
53{
54 AO_TYPE_LIVE,
55 "RoarAudio output",
56 "roar",
57 "Philipp 'ph3-der-loewe' Schafft, Based on code by: Stan Seibert <volsung@asu.edu>",
58 "Outputs to the RoarAudio Sound Daemon.",
59 AO_FMT_NATIVE,
60 50,
61 ao_roar_options,
62 1
63};
64
65
66typedef struct ao_roar_internal {
67 struct roar_vio_calls svio;
68 char * host;
69} ao_roar_internal;
70
71
72int ao_plugin_test(void) {
73 struct roar_connection con;
74
75 if ( roar_simple_connect(&con, NULL, "libao client") == -1 )
76  return 0;
77
78 if (roar_get_standby(&con)) {
79  roar_disconnect(&con);
80  return 0;
81 }
82
83 roar_disconnect(&con);
84 return 1;
85}
86
87
88ao_info * ao_plugin_driver_info(void) {
89 return &ao_roar_info;
90}
91
92
93int ao_plugin_device_init(ao_device * device) {
94 ao_roar_internal * internal;
95
96 internal = (ao_roar_internal *) malloc(sizeof(ao_roar_internal));
97
98 if (internal == NULL) 
99  return 0;
100
101 internal->host = NULL;
102
103 device->internal = internal;
104
105 return 1;
106}
107
108int ao_plugin_set_option(ao_device * device, const char * key, const char * value) {
109 ao_roar_internal * internal = (ao_roar_internal *) device->internal;
110
111 if ( strcmp(key, "host") == 0 ) {
112  if(internal->host) free(internal->host);
113   internal->host = strdup(value);
114 }
115
116 return 1;
117}
118
119int ao_plugin_open(ao_device * device, ao_sample_format * format) {
120 ao_roar_internal * internal = (ao_roar_internal *) device->internal;
121
122 if ( roar_vio_simple_stream(&(internal->svio), format->rate, format->channels, format->bits,
123                             ROAR_CODEC_DEFAULT, internal->host, ROAR_DIR_PLAY, "libao client") == -1 )
124  return 0;
125
126 device->driver_byte_format = AO_FMT_NATIVE;
127
128 return 1;
129}
130
131int ao_plugin_play(ao_device * device, const char * output_samples, uint_32 num_bytes) {
132 ao_roar_internal * internal = (ao_roar_internal *) device->internal;
133
134 if (roar_vio_write(&(internal->svio), (char*)output_samples, num_bytes) == -1) {
135  return 0;
136 } else {
137  return 1;
138 }
139}
140
141
142int ao_plugin_close(ao_device * device) {
143 ao_roar_internal * internal = (ao_roar_internal *) device->internal;
144
145 roar_vio_close(&(internal->svio));
146
147 return 1;
148}
149
150
151void ao_plugin_device_clear(ao_device * device) {
152 ao_roar_internal * internal = (ao_roar_internal *) device->internal;
153
154 if( internal->host != NULL )
155  free(internal->host);
156
157 free(internal);
158}
Note: See TracBrowser for help on using the repository browser.