File: device.c

package info (click to toggle)
xwax 0.7-5
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 312 kB
  • ctags: 524
  • sloc: ansic: 3,921; makefile: 104; sh: 101
file content (100 lines) | stat: -rw-r--r-- 2,405 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright (C) 2010 Mark Hills <mark@pogo.org.uk>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 2 for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * version 2 along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 */

#include "device.h"


void device_connect_timecoder(struct device_t *dv, struct timecoder_t *tc)
{
    dv->timecoder = tc;
}


void device_connect_player(struct device_t *dv, struct player_t *pl)
{
    dv->player = pl;
}


/* Return the sample rate of the device in Hz */

unsigned int device_sample_rate(struct device_t *dv)
{
    return dv->type->sample_rate(dv);
}


/* Start the device inputting and outputting audio */

int device_start(struct device_t *dv)
{
    if(dv->type->start)
        return dv->type->start(dv);
    else
        return 0;
}


/* Stop the device */

int device_stop(struct device_t *dv)
{
    if(dv->type->stop)
        return dv->type->stop(dv);
    else
        return 0;
}


/* Clear (destruct) the device. The corresponding constructor is
 * specific to each particular audio system. */

void device_clear(struct device_t *dv)
{
    dv->type->clear(dv);
}


/* Return file descriptors which should be watched for this device.
 * Do not return anything for callback-based audio systems. If this
 * function returns any file descriptors, there must be a handle()
 * function available.
 *
 * Returns the number of pollfd filled, or -1 on error. */

ssize_t device_pollfds(struct device_t *dv, struct pollfd *pe, size_t z)
{
    if(dv->type->pollfds)
        return dv->type->pollfds(dv, pe, z);
    else
        return 0;
}


/* Handle any available input or output on the device. This function
 * is called when there is activity on any fd given by pollfds() for
 * any devices in the system. */

int device_handle(struct device_t *dv)
{
    if(dv->type->handle)
        return dv->type->handle(dv);
    else
        return 0;
}