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 status_t err; 67 CALLED(); 68 69 if (!info) 70 return EINVAL; 71 72 // XXX: we should probably cache them as they might change on the fly 73 74 info->dev = Info()->dev; // this mixer 75 info->ctrl = index; 76 if (ioctl(fFD, SNDCTL_MIX_EXTINFO, info, sizeof(*info)) < 0) { 77 PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_EXTINFO(%d): %s\n", __FUNCTION__, index, strerror(errno))); 78 return errno; 79 } 80 81 return B_OK; 82 } 83 84 85 status_t OpenSoundDeviceMixer::GetMixerValue(oss_mixer_value *value) 86 { 87 status_t err; 88 CALLED(); 89 90 if (!value) 91 return EINVAL; 92 93 value->dev = Info()->dev; // this mixer 94 // should be set before calling 95 //value->ctrl = index; 96 //value->timestamp = 97 if (ioctl(fFD, SNDCTL_MIX_READ, value, sizeof(*value)) < 0) { 98 PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_READ(%d): %s\n", __FUNCTION__, value->ctrl, strerror(errno))); 99 return errno; 100 } 101 102 return B_OK; 103 } 104 105 106 status_t OpenSoundDeviceMixer::SetMixerValue(oss_mixer_value *value) 107 { 108 status_t err; 109 CALLED(); 110 111 if (!value) 112 return EINVAL; 113 114 value->dev = Info()->dev; // this mixer 115 // should be set before calling 116 //value->ctrl = index; 117 //value->timestamp = 118 if (ioctl(fFD, SNDCTL_MIX_WRITE, value, sizeof(*value)) < 0) { 119 PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_WRITE(%d): %s\n", __FUNCTION__, value->ctrl, strerror(errno))); 120 return errno; 121 } 122 123 return B_OK; 124 } 125 126 127 status_t OpenSoundDeviceMixer::GetEnumInfo(int index, oss_mixer_enuminfo *info) 128 { 129 status_t err; 130 CALLED(); 131 132 if (!info) 133 return EINVAL; 134 135 info->dev = Info()->dev; // this mixer 136 info->ctrl = index; 137 if (ioctl(fFD, SNDCTL_MIX_ENUMINFO, info, sizeof(*info)) < 0) { 138 PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_ENUMINFO(%d): %s\n", __FUNCTION__, index, strerror(errno))); 139 return errno; 140 } 141 142 return B_OK; 143 } 144 145 146 //update_counter 147 148 149