src/java.desktop/solaris/native/libjsound/PLATFORM_API_SolarisOS_Ports.c
author jlaskey
Thu, 14 Nov 2019 12:39:56 -0400
branchJDK-8193209-branch
changeset 59087 effb66aab08b
parent 49289 148e29df1644
permissions -rw-r--r--
[mq]: other
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
42938
c0b3077af726 8170798: Fix minor issues in java2d and sound coding.
goetz
parents: 25859
diff changeset
     2
 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#define USE_ERROR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
//#define USE_TRACE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "Ports.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "PLATFORM_API_SolarisOS_Utils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#define MONITOR_GAIN_STRING "Monitor Gain"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#define ALL_TARGET_PORT_COUNT 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// define the following to not use audio_prinfo_t.mod_ports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#define SOLARIS7_COMPATIBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
// Solaris audio defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
static int targetPorts[ALL_TARGET_PORT_COUNT] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    AUDIO_SPEAKER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    AUDIO_HEADPHONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    AUDIO_LINE_OUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    AUDIO_AUX1_OUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    AUDIO_AUX2_OUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    AUDIO_SPDIF_OUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static char* targetPortNames[ALL_TARGET_PORT_COUNT] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    "Speaker",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    "Headphone",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    "Line Out",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    "AUX1 Out",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    "AUX2 Out",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    "SPDIF Out"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
// defined in Ports.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static int targetPortJavaSoundMapping[ALL_TARGET_PORT_COUNT] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    PORT_DST_SPEAKER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    PORT_DST_HEADPHONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    PORT_DST_LINE_OUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    PORT_DST_UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    PORT_DST_UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    PORT_DST_UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#define ALL_SOURCE_PORT_COUNT 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
// Solaris audio defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
static int sourcePorts[ALL_SOURCE_PORT_COUNT] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    AUDIO_MICROPHONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    AUDIO_LINE_IN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    AUDIO_CD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    AUDIO_AUX1_IN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    AUDIO_AUX2_IN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    AUDIO_SPDIF_IN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    AUDIO_CODEC_LOOPB_IN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
static char* sourcePortNames[ALL_SOURCE_PORT_COUNT] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    "Microphone In",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    "Line In",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    "Compact Disc In",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    "AUX1 In",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    "AUX2 In",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    "SPDIF In",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    "Internal Loopback"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
// Ports.h defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
static int sourcePortJavaSoundMapping[ALL_SOURCE_PORT_COUNT] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    PORT_SRC_MICROPHONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    PORT_SRC_LINE_IN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    PORT_SRC_COMPACT_DISC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    PORT_SRC_UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    PORT_SRC_UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    PORT_SRC_UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    PORT_SRC_UNKNOWN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
struct tag_PortControlID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
typedef struct tag_PortInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    int fd;                    // file descriptor of the pseudo device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    audio_info_t audioInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // ports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    int targetPortCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    int sourcePortCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    // indexes to sourcePorts/targetPorts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // contains first target ports, then source ports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    int ports[ALL_TARGET_PORT_COUNT + ALL_SOURCE_PORT_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    int maxControlCount;       // upper bound of number of controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    int usedControlIDs;        // number of items already filled in controlIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    struct tag_PortControlID* controlIDs; // the control IDs themselves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
} PortInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#define PORT_CONTROL_TYPE_PLAY          0x4000000
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
#define PORT_CONTROL_TYPE_RECORD        0x8000000
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#define PORT_CONTROL_TYPE_SELECT_PORT   1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
#define PORT_CONTROL_TYPE_GAIN          2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#define PORT_CONTROL_TYPE_BALANCE       3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#define PORT_CONTROL_TYPE_MONITOR_GAIN  10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
#define PORT_CONTROL_TYPE_OUTPUT_MUTED  11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
#define PORT_CONTROL_TYPE_PLAYRECORD_MASK PORT_CONTROL_TYPE_PLAY | PORT_CONTROL_TYPE_RECORD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
#define PORT_CONTROL_TYPE_MASK 0xFFFFFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
typedef struct tag_PortControlID {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    PortInfo*  portInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    INT32                 controlType;  // PORT_CONTROL_TYPE_XX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    uint_t                port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
} PortControlID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
///// implemented functions of Ports.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
INT32 PORT_GetPortMixerCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    return (INT32) getAudioDeviceCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
INT32 PORT_GetPortMixerDescription(INT32 mixerIndex, PortMixerDescription* description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    AudioDeviceDescription desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    if (getAudioDeviceDescriptionByIndex(mixerIndex, &desc, TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        strncpy(description->name, desc.name, PORT_STRING_LENGTH-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        description->name[PORT_STRING_LENGTH-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        strncpy(description->vendor, desc.vendor, PORT_STRING_LENGTH-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        description->vendor[PORT_STRING_LENGTH-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        strncpy(description->version, desc.version, PORT_STRING_LENGTH-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        description->version[PORT_STRING_LENGTH-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        /*strncpy(description->description, desc.description, PORT_STRING_LENGTH-1);*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        strncpy(description->description, "Solaris Ports", PORT_STRING_LENGTH-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        description->description[PORT_STRING_LENGTH-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
void* PORT_Open(INT32 mixerIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    PortInfo* info = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    int fd = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    AudioDeviceDescription desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    int success = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    TRACE0("PORT_Open\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    if (getAudioDeviceDescriptionByIndex(mixerIndex, &desc, FALSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        fd = open(desc.pathctl, O_RDWR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    if (fd < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        ERROR1("Couldn't open audio device ctl for device %d!\n", mixerIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    info = (PortInfo*) malloc(sizeof(PortInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    if (info != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        memset(info, 0, sizeof(PortInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        info->fd = fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        success = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    if (!success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (fd >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            close(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        PORT_Close((void*) info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        info = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
void PORT_Close(void* id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    TRACE0("PORT_Close\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    if (id != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        PortInfo* info = (PortInfo*) id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (info->fd >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            close(info->fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            info->fd = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (info->controlIDs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            free(info->controlIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            info->controlIDs = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        free(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
INT32 PORT_GetPortCount(void* id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    int ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    PortInfo* info = (PortInfo*) id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    if (info != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (!info->targetPortCount && !info->sourcePortCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            AUDIO_INITINFO(&info->audioInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (ioctl(info->fd, AUDIO_GETINFO, &info->audioInfo) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                for (i = 0; i < ALL_TARGET_PORT_COUNT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    if (info->audioInfo.play.avail_ports & targetPorts[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        info->ports[info->targetPortCount] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                        info->targetPortCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
#ifdef SOLARIS7_COMPATIBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    TRACE3("Target %d %s: avail=%d\n", i, targetPortNames[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                           info->audioInfo.play.avail_ports & targetPorts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    TRACE4("Target %d %s: avail=%d  mod=%d\n", i, targetPortNames[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                           info->audioInfo.play.avail_ports & targetPorts[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                           info->audioInfo.play.mod_ports & targetPorts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                for (i = 0; i < ALL_SOURCE_PORT_COUNT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    if (info->audioInfo.record.avail_ports & sourcePorts[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        info->ports[info->targetPortCount + info->sourcePortCount] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        info->sourcePortCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
#ifdef SOLARIS7_COMPATIBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    TRACE3("Source %d %s: avail=%d\n", i, sourcePortNames[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                           info->audioInfo.record.avail_ports & sourcePorts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    TRACE4("Source %d %s: avail=%d  mod=%d\n", i, sourcePortNames[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                           info->audioInfo.record.avail_ports & sourcePorts[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                           info->audioInfo.record.mod_ports & sourcePorts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        ret = info->targetPortCount + info->sourcePortCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
int isSourcePort(PortInfo* info, INT32 portIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    return (portIndex >= info->targetPortCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
INT32 PORT_GetPortType(void* id, INT32 portIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    PortInfo* info = (PortInfo*) id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    if ((portIndex >= 0) && (portIndex < PORT_GetPortCount(id))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (isSourcePort(info, portIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return sourcePortJavaSoundMapping[info->ports[portIndex]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return targetPortJavaSoundMapping[info->ports[portIndex]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
// pre-condition: portIndex must have been verified!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
char* getPortName(PortInfo* info, INT32 portIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    char* ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    if (isSourcePort(info, portIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        ret = sourcePortNames[info->ports[portIndex]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        ret = targetPortNames[info->ports[portIndex]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
INT32 PORT_GetPortName(void* id, INT32 portIndex, char* name, INT32 len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    PortInfo* info = (PortInfo*) id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    char* n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    if ((portIndex >= 0) && (portIndex < PORT_GetPortCount(id))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        n = getPortName(info, portIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            strncpy(name, n, len-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            name[len-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
void createPortControl(PortInfo* info, PortControlCreator* creator, INT32 portIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                       INT32 type, void** controlObjects, int* controlCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    PortControlID* controlID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    void* newControl = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    int controlIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    char* jsType = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    int isBoolean = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    TRACE0(">createPortControl\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    // fill the ControlID structure and add this control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    if (info->usedControlIDs >= info->maxControlCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        ERROR1("not enough free controlIDs !! maxControlIDs = %d\n", info->maxControlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    controlID = &(info->controlIDs[info->usedControlIDs]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    controlID->portInfo = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    controlID->controlType = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    controlIndex = info->ports[portIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    if (isSourcePort(info, portIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        controlID->port = sourcePorts[controlIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        controlID->port = targetPorts[controlIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    switch (type & PORT_CONTROL_TYPE_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    case PORT_CONTROL_TYPE_SELECT_PORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        jsType = CONTROL_TYPE_SELECT; isBoolean = TRUE; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    case PORT_CONTROL_TYPE_GAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        jsType = CONTROL_TYPE_VOLUME;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    case PORT_CONTROL_TYPE_BALANCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        jsType = CONTROL_TYPE_BALANCE; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    case PORT_CONTROL_TYPE_MONITOR_GAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        jsType = CONTROL_TYPE_VOLUME; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    case PORT_CONTROL_TYPE_OUTPUT_MUTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        jsType = CONTROL_TYPE_MUTE; isBoolean = TRUE; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    if (isBoolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        TRACE0(" PORT_CONTROL_TYPE_BOOLEAN\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        newControl = (creator->newBooleanControl)(creator, controlID, jsType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    else if (jsType == CONTROL_TYPE_BALANCE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        TRACE0(" PORT_CONTROL_TYPE_BALANCE\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        newControl = (creator->newFloatControl)(creator, controlID, jsType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                                -1.0f, 1.0f, 2.0f / 65.0f, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        TRACE0(" PORT_CONTROL_TYPE_FLOAT\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        newControl = (creator->newFloatControl)(creator, controlID, jsType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                                0.0f, 1.0f, 1.0f / 256.0f, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    if (newControl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        controlObjects[*controlCount] = newControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        (*controlCount)++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        info->usedControlIDs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    TRACE0("<createPortControl\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
void addCompoundControl(PortInfo* info, PortControlCreator* creator, char* name, void** controlObjects, int* controlCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    void* compControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    TRACE1(">addCompoundControl %d controls\n", *controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    if (*controlCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // create compound control and add it to the vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        compControl = (creator->newCompoundControl)(creator, name, controlObjects, *controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        if (compControl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            TRACE1(" addCompoundControl: calling addControl %p\n", compControl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            (creator->addControl)(creator, compControl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        *controlCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    TRACE0("<addCompoundControl\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
void addAllControls(PortInfo* info, PortControlCreator* creator, void** controlObjects, int* controlCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    TRACE0(">addAllControl\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    // go through all controls and add them to the vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    for (i = 0; i < *controlCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        (creator->addControl)(creator, controlObjects[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    *controlCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    TRACE0("<addAllControl\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    PortInfo* info = (PortInfo*) id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    int portCount = PORT_GetPortCount(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    void* controls[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    int controlCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    INT32 type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    int selectable = 1;
42938
c0b3077af726 8170798: Fix minor issues in java2d and sound coding.
goetz
parents: 25859
diff changeset
   393
    memset(controls, 0, sizeof(controls));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    TRACE4(">PORT_GetControls(id=%p, portIndex=%d). controlIDs=%p, maxControlCount=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
           id, portIndex, info->controlIDs, info->maxControlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    if ((portIndex >= 0) && (portIndex < portCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        // if the memory isn't reserved for the control structures, allocate it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (!info->controlIDs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            int maxCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            TRACE0("getControl: allocate mem\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            // get a maximum number of controls:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            // each port has a select, balance, and volume control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            maxCount = 3 * portCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            // then there is monitorGain and outputMuted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            maxCount += (2 * info->targetPortCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            info->maxControlCount = maxCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            info->controlIDs = (PortControlID*) malloc(sizeof(PortControlID) * maxCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (!isSourcePort(info, portIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            type = PORT_CONTROL_TYPE_PLAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            // add master mute control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            createPortControl(info, creator, portIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                              type | PORT_CONTROL_TYPE_OUTPUT_MUTED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                              controls, &controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            addAllControls(info, creator, controls, &controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
#ifdef SOLARIS7_COMPATIBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            selectable = info->audioInfo.play.avail_ports & targetPorts[info->ports[portIndex]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            selectable = info->audioInfo.play.mod_ports & targetPorts[info->ports[portIndex]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            type = PORT_CONTROL_TYPE_RECORD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
#ifdef SOLARIS7_COMPATIBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            selectable = info->audioInfo.record.avail_ports & sourcePorts[info->ports[portIndex]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            selectable = info->audioInfo.record.mod_ports & sourcePorts[info->ports[portIndex]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        // add a mixer strip with volume, ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        createPortControl(info, creator, portIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                          type | PORT_CONTROL_TYPE_GAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                          controls, &controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // ... balance, ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        createPortControl(info, creator, portIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                          type | PORT_CONTROL_TYPE_BALANCE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                          controls, &controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        // ... and select control (if not always on)...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if (selectable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            createPortControl(info, creator, portIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                              type | PORT_CONTROL_TYPE_SELECT_PORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                              controls, &controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        // ... packaged in a compound control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        addCompoundControl(info, creator, getPortName(info, portIndex), controls, &controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (type == PORT_CONTROL_TYPE_PLAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            // add a single strip for source ports with monitor gain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            createPortControl(info, creator, portIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                              type | PORT_CONTROL_TYPE_MONITOR_GAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                              controls, &controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            // also in a compound control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            addCompoundControl(info, creator, MONITOR_GAIN_STRING, controls, &controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    TRACE0("< PORT_getControls\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
INT32 PORT_GetIntValue(void* controlIDV) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    PortControlID* controlID = (PortControlID*) controlIDV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    audio_info_t audioInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    audio_prinfo_t* prinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    AUDIO_INITINFO(&audioInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    if (ioctl(controlID->portInfo->fd, AUDIO_GETINFO, &audioInfo) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if (controlID->controlType & PORT_CONTROL_TYPE_PLAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            prinfo = &(audioInfo.play);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            prinfo = &(audioInfo.record);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        switch (controlID->controlType & PORT_CONTROL_TYPE_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        case PORT_CONTROL_TYPE_SELECT_PORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            return (prinfo->port & controlID->port)?TRUE:FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        case PORT_CONTROL_TYPE_OUTPUT_MUTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return (audioInfo.output_muted)?TRUE:FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            ERROR1("PORT_GetIntValue: Wrong type %d !\n", controlID->controlType & PORT_CONTROL_TYPE_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    ERROR0("PORT_GetIntValue: Could not ioctl!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
void PORT_SetIntValue(void* controlIDV, INT32 value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    PortControlID* controlID = (PortControlID*) controlIDV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    audio_info_t audioInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    audio_prinfo_t* prinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    int setPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    if (controlID->controlType & PORT_CONTROL_TYPE_PLAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        prinfo = &(audioInfo.play);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        prinfo = &(audioInfo.record);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    switch (controlID->controlType & PORT_CONTROL_TYPE_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    case PORT_CONTROL_TYPE_SELECT_PORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        // first try to just add this port. if that fails, set ONLY to this port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        AUDIO_INITINFO(&audioInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if (ioctl(controlID->portInfo->fd, AUDIO_GETINFO, &audioInfo) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if (value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                setPort = (prinfo->port | controlID->port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                setPort = (prinfo->port - controlID->port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            AUDIO_INITINFO(&audioInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            prinfo->port = setPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if (ioctl(controlID->portInfo->fd, AUDIO_SETINFO, &audioInfo) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                // didn't work. Either this line doesn't support to select several
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                // ports at once (e.g. record), or a real error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                if (value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    // set to ONLY this port (and disable any other currently selected ports)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    AUDIO_INITINFO(&audioInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    prinfo->port = controlID->port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    if (ioctl(controlID->portInfo->fd, AUDIO_SETINFO, &audioInfo) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        ERROR2("Error setting output select port %d to port %d!\n", controlID->port, controlID->port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                    // assume it's an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                    ERROR2("Error setting output select port %d to port %d!\n", controlID->port, setPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        case PORT_CONTROL_TYPE_OUTPUT_MUTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            AUDIO_INITINFO(&audioInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            audioInfo.output_muted = (value?TRUE:FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            if (ioctl(controlID->portInfo->fd, AUDIO_SETINFO, &audioInfo) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                ERROR2("Error setting output muted on port %d to %d!\n", controlID->port, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            ERROR1("PORT_SetIntValue: Wrong type %d !\n", controlID->controlType & PORT_CONTROL_TYPE_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
float PORT_GetFloatValue(void* controlIDV) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    PortControlID* controlID = (PortControlID*) controlIDV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    audio_info_t audioInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    audio_prinfo_t* prinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    AUDIO_INITINFO(&audioInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    if (ioctl(controlID->portInfo->fd, AUDIO_GETINFO, &audioInfo) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (controlID->controlType & PORT_CONTROL_TYPE_PLAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            prinfo = &(audioInfo.play);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            prinfo = &(audioInfo.record);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        switch (controlID->controlType & PORT_CONTROL_TYPE_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        case PORT_CONTROL_TYPE_GAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            return ((float) (prinfo->gain - AUDIO_MIN_GAIN))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                / ((float) (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        case PORT_CONTROL_TYPE_BALANCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            return ((float) ((prinfo->balance - AUDIO_LEFT_BALANCE - AUDIO_MID_BALANCE) << 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                / ((float) (AUDIO_RIGHT_BALANCE - AUDIO_LEFT_BALANCE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        case PORT_CONTROL_TYPE_MONITOR_GAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            return ((float) (audioInfo.monitor_gain - AUDIO_MIN_GAIN))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                / ((float) (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            ERROR1("PORT_GetFloatValue: Wrong type %d !\n", controlID->controlType & PORT_CONTROL_TYPE_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    ERROR0("PORT_GetFloatValue: Could not ioctl!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    return 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
void PORT_SetFloatValue(void* controlIDV, float value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    PortControlID* controlID = (PortControlID*) controlIDV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    audio_info_t audioInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    audio_prinfo_t* prinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    AUDIO_INITINFO(&audioInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    if (controlID->controlType & PORT_CONTROL_TYPE_PLAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        prinfo = &(audioInfo.play);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        prinfo = &(audioInfo.record);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    switch (controlID->controlType & PORT_CONTROL_TYPE_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    case PORT_CONTROL_TYPE_GAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        prinfo->gain = AUDIO_MIN_GAIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            + (int) ((value * ((float) (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN))) + 0.5f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    case PORT_CONTROL_TYPE_BALANCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        prinfo->balance =  AUDIO_LEFT_BALANCE + AUDIO_MID_BALANCE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            + ((int) (value * ((float) ((AUDIO_RIGHT_BALANCE - AUDIO_LEFT_BALANCE) >> 1))) + 0.5f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    case PORT_CONTROL_TYPE_MONITOR_GAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        audioInfo.monitor_gain = AUDIO_MIN_GAIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            + (int) ((value * ((float) (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN))) + 0.5f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        ERROR1("PORT_SetFloatValue: Wrong type %d !\n", controlID->controlType & PORT_CONTROL_TYPE_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    if (ioctl(controlID->portInfo->fd, AUDIO_SETINFO, &audioInfo) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        ERROR0("PORT_SetFloatValue: Could not ioctl!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
#endif // USE_PORTS