1*de6be214SFrançois Revol /*
2*de6be214SFrançois Revol * OpenSound media addon for BeOS and Haiku
3*de6be214SFrançois Revol *
4*de6be214SFrançois Revol * Copyright (c) 2007, François Revol (revol@free.fr)
5*de6be214SFrançois Revol * Distributed under the terms of the MIT License.
6*de6be214SFrançois Revol */
7*de6be214SFrançois Revol
8*de6be214SFrançois Revol #include "OpenSoundDeviceMixer.h"
9*de6be214SFrançois Revol #include "debug.h"
10*de6be214SFrançois Revol #include "driver_io.h"
11*de6be214SFrançois Revol #include <MediaDefs.h>
12*de6be214SFrançois Revol #include <Debug.h>
13*de6be214SFrançois Revol #include <errno.h>
14*de6be214SFrançois Revol #include <string.h>
15*de6be214SFrançois Revol
~OpenSoundDeviceMixer()16*de6be214SFrançois Revol OpenSoundDeviceMixer::~OpenSoundDeviceMixer()
17*de6be214SFrançois Revol {
18*de6be214SFrançois Revol CALLED();
19*de6be214SFrançois Revol if (fFD != 0) {
20*de6be214SFrançois Revol close(fFD);
21*de6be214SFrançois Revol }
22*de6be214SFrançois Revol }
23*de6be214SFrançois Revol
OpenSoundDeviceMixer(oss_mixerinfo * info)24*de6be214SFrançois Revol OpenSoundDeviceMixer::OpenSoundDeviceMixer(oss_mixerinfo *info)
25*de6be214SFrançois Revol {
26*de6be214SFrançois Revol CALLED();
27*de6be214SFrançois Revol fInitCheckStatus = B_NO_INIT;
28*de6be214SFrançois Revol memcpy(&fMixerInfo, info, sizeof(oss_mixerinfo));
29*de6be214SFrançois Revol fFD = open(info->devnode, O_RDWR);
30*de6be214SFrançois Revol if (fFD < 0) {
31*de6be214SFrançois Revol fInitCheckStatus = errno;
32*de6be214SFrançois Revol return;
33*de6be214SFrançois Revol }
34*de6be214SFrançois Revol fInitCheckStatus = B_OK;
35*de6be214SFrançois Revol }
36*de6be214SFrançois Revol
37*de6be214SFrançois Revol
InitCheck(void) const38*de6be214SFrançois Revol status_t OpenSoundDeviceMixer::InitCheck(void) const
39*de6be214SFrançois Revol {
40*de6be214SFrançois Revol CALLED();
41*de6be214SFrançois Revol return fInitCheckStatus;
42*de6be214SFrançois Revol }
43*de6be214SFrançois Revol
CountExtInfos()44*de6be214SFrançois Revol int OpenSoundDeviceMixer::CountExtInfos()
45*de6be214SFrançois Revol {
46*de6be214SFrançois Revol int n;
47*de6be214SFrançois Revol CALLED();
48*de6be214SFrançois Revol
49*de6be214SFrançois Revol // faster way!
50*de6be214SFrançois Revol return Info()->nrext;
51*de6be214SFrançois Revol
52*de6be214SFrançois Revol // -1 doesn't work here (!?)
53*de6be214SFrançois Revol n = Info()->dev;
54*de6be214SFrançois Revol if (ioctl(fFD, SNDCTL_MIX_NREXT, &n, sizeof(int)) < 0) {
55*de6be214SFrançois Revol PRINT(("OpenSoundDeviceMixer::CountExtInfos: SNDCTL_MIX_NREXT: %s\n", strerror(errno)));
56*de6be214SFrançois Revol return 0;
57*de6be214SFrançois Revol }
58*de6be214SFrançois Revol
59*de6be214SFrançois Revol return n;
60*de6be214SFrançois Revol }
61*de6be214SFrançois Revol
62*de6be214SFrançois Revol
63*de6be214SFrançois Revol
GetExtInfo(int index,oss_mixext * info)64*de6be214SFrançois Revol status_t OpenSoundDeviceMixer::GetExtInfo(int index, oss_mixext *info)
65*de6be214SFrançois Revol {
66*de6be214SFrançois Revol CALLED();
67*de6be214SFrançois Revol
68*de6be214SFrançois Revol if (!info)
69*de6be214SFrançois Revol return EINVAL;
70*de6be214SFrançois Revol
71*de6be214SFrançois Revol // XXX: we should probably cache them as they might change on the fly
72*de6be214SFrançois Revol
73*de6be214SFrançois Revol info->dev = Info()->dev; // this mixer
74*de6be214SFrançois Revol info->ctrl = index;
75*de6be214SFrançois Revol if (ioctl(fFD, SNDCTL_MIX_EXTINFO, info, sizeof(*info)) < 0) {
76*de6be214SFrançois Revol PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_EXTINFO(%d): %s\n", __FUNCTION__, index, strerror(errno)));
77*de6be214SFrançois Revol return errno;
78*de6be214SFrançois Revol }
79*de6be214SFrançois Revol
80*de6be214SFrançois Revol return B_OK;
81*de6be214SFrançois Revol }
82*de6be214SFrançois Revol
83*de6be214SFrançois Revol
GetMixerValue(oss_mixer_value * value)84*de6be214SFrançois Revol status_t OpenSoundDeviceMixer::GetMixerValue(oss_mixer_value *value)
85*de6be214SFrançois Revol {
86*de6be214SFrançois Revol CALLED();
87*de6be214SFrançois Revol
88*de6be214SFrançois Revol if (!value)
89*de6be214SFrançois Revol return EINVAL;
90*de6be214SFrançois Revol
91*de6be214SFrançois Revol value->dev = Info()->dev; // this mixer
92*de6be214SFrançois Revol // should be set before calling
93*de6be214SFrançois Revol //value->ctrl = index;
94*de6be214SFrançois Revol //value->timestamp =
95*de6be214SFrançois Revol if (ioctl(fFD, SNDCTL_MIX_READ, value, sizeof(*value)) < 0) {
96*de6be214SFrançois Revol PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_READ(%d): %s\n", __FUNCTION__, value->ctrl, strerror(errno)));
97*de6be214SFrançois Revol return errno;
98*de6be214SFrançois Revol }
99*de6be214SFrançois Revol
100*de6be214SFrançois Revol return B_OK;
101*de6be214SFrançois Revol }
102*de6be214SFrançois Revol
103*de6be214SFrançois Revol
SetMixerValue(oss_mixer_value * value)104*de6be214SFrançois Revol status_t OpenSoundDeviceMixer::SetMixerValue(oss_mixer_value *value)
105*de6be214SFrançois Revol {
106*de6be214SFrançois Revol CALLED();
107*de6be214SFrançois Revol
108*de6be214SFrançois Revol if (!value)
109*de6be214SFrançois Revol return EINVAL;
110*de6be214SFrançois Revol
111*de6be214SFrançois Revol value->dev = Info()->dev; // this mixer
112*de6be214SFrançois Revol // should be set before calling
113*de6be214SFrançois Revol //value->ctrl = index;
114*de6be214SFrançois Revol //value->timestamp =
115*de6be214SFrançois Revol if (ioctl(fFD, SNDCTL_MIX_WRITE, value, sizeof(*value)) < 0) {
116*de6be214SFrançois Revol PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_WRITE(%d): %s\n", __FUNCTION__, value->ctrl, strerror(errno)));
117*de6be214SFrançois Revol return errno;
118*de6be214SFrançois Revol }
119*de6be214SFrançois Revol
120*de6be214SFrançois Revol return B_OK;
121*de6be214SFrançois Revol }
122*de6be214SFrançois Revol
123*de6be214SFrançois Revol
GetEnumInfo(int index,oss_mixer_enuminfo * info)124*de6be214SFrançois Revol status_t OpenSoundDeviceMixer::GetEnumInfo(int index, oss_mixer_enuminfo *info)
125*de6be214SFrançois Revol {
126*de6be214SFrançois Revol CALLED();
127*de6be214SFrançois Revol
128*de6be214SFrançois Revol if (!info)
129*de6be214SFrançois Revol return EINVAL;
130*de6be214SFrançois Revol
131*de6be214SFrançois Revol info->dev = Info()->dev; // this mixer
132*de6be214SFrançois Revol info->ctrl = index;
133*de6be214SFrançois Revol if (ioctl(fFD, SNDCTL_MIX_ENUMINFO, info, sizeof(*info)) < 0) {
134*de6be214SFrançois Revol PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_ENUMINFO(%d): %s\n", __FUNCTION__, index, strerror(errno)));
135*de6be214SFrançois Revol return errno;
136*de6be214SFrançois Revol }
137*de6be214SFrançois Revol
138*de6be214SFrançois Revol return B_OK;
139*de6be214SFrançois Revol }
140*de6be214SFrançois Revol
141*de6be214SFrançois Revol
142*de6be214SFrançois Revol //update_counter
143*de6be214SFrançois Revol
144*de6be214SFrançois Revol
145