~ubuntu-branches/ubuntu/trusty/libao/trusty

« back to all changes in this revision

Viewing changes to src/plugins/roar/ao_roar.c

  • Committer: Bazaar Package Importer
  • Author(s): John Francesco Ferlito
  • Date: 2010-04-11 11:04:30 UTC
  • mfrom: (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100411110430-wldc1w7ll1j6c4yc
Tags: 1.0.0-4
Actually depend on libao.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
36
static char *ao_roar_options[] = {"host","verbose","quiet","matrix","debug"};
 
37
 
 
38
/*
 
39
typedef 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
 
 
52
static ao_info ao_roar_info ={
 
53
  AO_TYPE_LIVE,
 
54
  "RoarAudio output",
 
55
  "roar",
 
56
  "Philipp 'ph3-der-loewe' Schafft, Based on code by: Stan Seibert <volsung@asu.edu>",
 
57
  "Outputs to the RoarAudio Sound Daemon.",
 
58
  AO_FMT_NATIVE,
 
59
  50,
 
60
  ao_roar_options,
 
61
  5
 
62
};
 
63
 
 
64
 
 
65
typedef struct ao_roar_internal {
 
66
  struct roar_vio_calls svio;
 
67
  char * host;
 
68
} ao_roar_internal;
 
69
 
 
70
 
 
71
int ao_plugin_test(void) {
 
72
  struct roar_connection con;
 
73
 
 
74
  if ( roar_simple_connect(&con, NULL, "libao client") == -1 )
 
75
    return 0;
 
76
 
 
77
  if (roar_get_standby(&con)) {
 
78
    roar_disconnect(&con);
 
79
    return 0;
 
80
  }
 
81
 
 
82
  roar_disconnect(&con);
 
83
  return 1;
 
84
}
 
85
 
 
86
 
 
87
ao_info * ao_plugin_driver_info(void) {
 
88
  return &ao_roar_info;
 
89
}
 
90
 
 
91
 
 
92
int ao_plugin_device_init(ao_device * device) {
 
93
  ao_roar_internal * internal;
 
94
 
 
95
  internal = (ao_roar_internal *) calloc(1,sizeof(ao_roar_internal));
 
96
 
 
97
  if (internal == NULL)
 
98
    return 0;
 
99
 
 
100
  internal->host = NULL;
 
101
 
 
102
  device->internal = internal;
 
103
  device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED;
 
104
 
 
105
  return 1;
 
106
}
 
107
 
 
108
int 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
 
 
119
int ao_plugin_open(ao_device * device, ao_sample_format * format) {
 
120
  ao_roar_internal * internal = (ao_roar_internal *) device->internal;
 
121
  char * map = NULL;
 
122
 
 
123
  if ( roar_vio_simple_stream(&(internal->svio), format->rate, format->channels, format->bits,
 
124
                             ROAR_CODEC_DEFAULT, internal->host, ROAR_DIR_PLAY, "libao client") == -1 )
 
125
    return 0;
 
126
 
 
127
  device->driver_byte_format = AO_FMT_NATIVE;
 
128
 
 
129
  if(!device->inter_matrix){ /* It would be set if an app or user force-sets the mapping; don't overwrite! */
 
130
    switch (format->channels) {
 
131
    case  1: map = "M";               break;
 
132
    case  2: map = "L,R";             break;
 
133
    case  3: map = "L,R,C";           break;
 
134
    case  4: map = "L,R,BL,BR";       break;
 
135
    case  5: map = "L,R,C,BL,BR";     break;
 
136
    case  6: map = "L,R,C,LFE,BL,BR"; break;
 
137
    }
 
138
    /* >6 channels will warn about inability to map */
 
139
 
 
140
    if ( map )
 
141
      device->inter_matrix = strdup(map);
 
142
  }
 
143
 
 
144
  return 1;
 
145
}
 
146
 
 
147
int ao_plugin_play(ao_device * device, const char * output_samples, uint_32 num_bytes) {
 
148
  ao_roar_internal * internal = (ao_roar_internal *) device->internal;
 
149
 
 
150
  if (roar_vio_write(&(internal->svio), (char*)output_samples, num_bytes) == -1) {
 
151
    return 0;
 
152
  } else {
 
153
    return 1;
 
154
  }
 
155
}
 
156
 
 
157
 
 
158
int ao_plugin_close(ao_device * device) {
 
159
  ao_roar_internal * internal = (ao_roar_internal *) device->internal;
 
160
 
 
161
  roar_vio_close(&(internal->svio));
 
162
 
 
163
  return 1;
 
164
}
 
165
 
 
166
 
 
167
void ao_plugin_device_clear(ao_device * device) {
 
168
  ao_roar_internal * internal = (ao_roar_internal *) device->internal;
 
169
 
 
170
  if( internal->host != NULL )
 
171
    free(internal->host);
 
172
 
 
173
  free(internal);
 
174
}