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

« back to all changes in this revision

Viewing changes to src/plugins/sndio/ao_sndio.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
 * Copyright (c) 2008 Alexandre Ratchov <alex at caoua.org>
 
3
 *
 
4
 * Permission to use, copy, modify, and distribute this software for any
 
5
 * purpose with or without fee is hereby granted, provided that the above
 
6
 * copyright notice and this permission notice appear in all copies.
 
7
 *
 
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
15
 */
 
16
#include <sndio.h>
 
17
#include <ao/ao.h>
 
18
#include <ao/plugin.h>
 
19
 
 
20
static char * ao_sndio_options[] = {
 
21
  "verbose",
 
22
  "quiet",
 
23
  "matrix",
 
24
  "debug",
 
25
  "dev"
 
26
};
 
27
 
 
28
ao_info ao_sndio_info = {
 
29
  AO_TYPE_LIVE,
 
30
  "sndio audio output",
 
31
  "sndio",
 
32
  "Alexandre Ratchov <alex at caoua.org>",
 
33
  "Outputs to the sndio library",
 
34
  AO_FMT_NATIVE,
 
35
  30,
 
36
  ao_sndio_options,
 
37
  4
 
38
};
 
39
 
 
40
typedef struct ao_alsa_internal
 
41
{
 
42
  struct sio_hdl *hdl;
 
43
  char *dev;
 
44
} ao_sndio_internal;
 
45
 
 
46
int ao_plugin_test()
 
47
{
 
48
  struct sio_hdl *hdl;
 
49
 
 
50
  hdl = sio_open(NULL, SIO_PLAY, 0);
 
51
  if (hdl == NULL)
 
52
    return 0;
 
53
  sio_close(hdl);
 
54
  return 1;
 
55
}
 
56
 
 
57
ao_info *ao_plugin_driver_info(void)
 
58
{
 
59
  return &ao_sndio_info;
 
60
}
 
61
 
 
62
int ao_plugin_device_init(ao_device *device)
 
63
{
 
64
  ao_sndio_internal *internal;
 
65
  internal = (ao_sndio_internal *) calloc(1,sizeof(*internal));
 
66
  device->internal = internal;
 
67
  device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED;
 
68
  return 1;
 
69
}
 
70
 
 
71
int ao_plugin_set_option(ao_device *device, const char *key, const char *value)
 
72
{
 
73
  ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
 
74
 
 
75
  if (!strcmp(key, "dev")) {
 
76
    if (internal->dev)
 
77
      free (internal->dev);
 
78
    if(!value){
 
79
      internal->dev=NULL;
 
80
    }else{
 
81
      if (!(internal->dev = strdup(value)))
 
82
        return 0;
 
83
    }
 
84
  }
 
85
  return 1;
 
86
}
 
87
 
 
88
int ao_plugin_open(ao_device *device, ao_sample_format *format)
 
89
{
 
90
  ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
 
91
  struct sio_par par;
 
92
 
 
93
  internal->hdl = sio_open(internal->dev, SIO_PLAY, 0);
 
94
  if (internal->hdl == NULL)
 
95
    return 0;
 
96
 
 
97
  sio_initpar(&par);
 
98
  par.sig = 1;
 
99
  par.le = SIO_LE_NATIVE;
 
100
  par.bits = format->bits;
 
101
  par.rate = format->rate;
 
102
  par.pchan = device->output_channels;
 
103
  if (!sio_setpar(hdl, &par))
 
104
    return 0;
 
105
  device->driver_byte_format = AO_FMT_NATIVE;
 
106
  if (!sio_start(hdl))
 
107
    return 0;
 
108
 
 
109
  if(!device->inter_matrix){
 
110
    /* set up matrix such that users are warned about > stereo playback */
 
111
    if(device->output_channels<=2)
 
112
      device->inter_matrix=strdup("L,R");
 
113
    //else no matrix, which results in a warning
 
114
  }
 
115
 
 
116
  return 1;
 
117
}
 
118
 
 
119
int ao_plugin_play(ao_device *device, const char *output_samples, uint_32 num_bytes)
 
120
{
 
121
  ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
 
122
  struct sio_hdl *hdl = internal->hdl;
 
123
 
 
124
  if (!sio_write(hdl, output_samples, num_bytes))
 
125
    return 0;
 
126
  return 1;
 
127
}
 
128
 
 
129
int ao_plugin_close(ao_device *device)
 
130
{
 
131
  ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
 
132
  struct sio_hdl *hdl = internal->hdl;
 
133
 
 
134
  if (!sio_stop(hdl))
 
135
    return 0;
 
136
  return 1;
 
137
}
 
138
 
 
139
void ao_plugin_device_clear(ao_device *device)
 
140
{
 
141
  ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
 
142
  struct sio_hdl *hdl = internal->hdl;
 
143
 
 
144
  sio_close(hdl);
 
145
  if(internal->dev)
 
146
    free(internal->dev);
 
147
  internal->dev=NULL;
 
148
}