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