jdk/src/java.desktop/share/native/libjsound/PortMixer.c
author serb
Sat, 18 Jul 2015 15:12:08 +0300
changeset 32110 733062f75808
parent 25859 3317bb8137f4
permissions -rw-r--r--
8074831: Resolve disabled warnings for libjsound Reviewed-by: amenkov, azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2014, 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_TRACE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define USE_ERROR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <jni.h>
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
    31
#include <jni_util.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "SoundDefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "Ports.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "Utilities.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "com_sun_media_sound_PortMixer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
//////////////////////////////////////////// PortMixer ////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
JNIEXPORT jlong JNICALL Java_com_sun_media_sound_PortMixer_nOpen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  (JNIEnv *env, jclass cls, jint mixerIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    jlong ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    ret = (jlong) (INT_PTR) PORT_Open(mixerIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
JNIEXPORT void JNICALL Java_com_sun_media_sound_PortMixer_nClose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  (JNIEnv *env, jclass cls, jlong id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    if (id != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        PORT_Close((void*) (INT_PTR) id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
JNIEXPORT jint JNICALL Java_com_sun_media_sound_PortMixer_nGetPortCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  (JNIEnv *env, jclass cls, jlong id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    jint ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    if (id != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        ret = (jint) PORT_GetPortCount((void*) (INT_PTR) id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
JNIEXPORT jint JNICALL Java_com_sun_media_sound_PortMixer_nGetPortType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  (JNIEnv *env, jclass cls, jlong id, jint portIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    jint ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    TRACE1("Java_com_sun_media_sound_PortMixer_nGetPortType(%d).\n", portIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    if (id != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        ret = (jint) PORT_GetPortType((void*) (INT_PTR) id, portIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    TRACE1("Java_com_sun_media_sound_PortMixerProvider_nGetPortType returning %d.\n", ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
JNIEXPORT jstring JNICALL Java_com_sun_media_sound_PortMixer_nGetPortName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  (JNIEnv *env, jclass cls, jlong id, jint portIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    char str[PORT_STRING_LENGTH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    jstring jString = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    TRACE1("Java_com_sun_media_sound_PortMixer_nGetPortName(%d).\n", portIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    str[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if (id != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        PORT_GetPortName((void*) (INT_PTR) id, portIndex, str, PORT_STRING_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    jString = (*env)->NewStringUTF(env, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    TRACE1("Java_com_sun_media_sound_PortMixerProvider_nGetName returning \"%s\".\n", str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    return jString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
JNIEXPORT void JNICALL Java_com_sun_media_sound_PortMixer_nControlSetIntValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  (JNIEnv *env, jclass cls, jlong controlID, jint value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    if (controlID != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        PORT_SetIntValue((void*) (UINT_PTR) controlID, (INT32) value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
JNIEXPORT jint JNICALL Java_com_sun_media_sound_PortMixer_nControlGetIntValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  (JNIEnv *env, jclass cls, jlong controlID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    INT32 ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    if (controlID != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        ret = PORT_GetIntValue((void*) (UINT_PTR) controlID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    return (jint) ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
JNIEXPORT void JNICALL Java_com_sun_media_sound_PortMixer_nControlSetFloatValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  (JNIEnv *env, jclass cls, jlong controlID, jfloat value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    if (controlID != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        PORT_SetFloatValue((void*) (UINT_PTR) controlID, (float) value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
JNIEXPORT jfloat JNICALL Java_com_sun_media_sound_PortMixer_nControlGetFloatValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  (JNIEnv *env, jclass cls, jlong controlID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    float ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    if (controlID != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        ret = PORT_GetFloatValue((void*) (UINT_PTR) controlID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    return (jfloat) ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
/* ************************************** native control creation support ********************* */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
// contains all the needed references so that the platform dependent code can call JNI wrapper functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
typedef struct tag_ControlCreatorJNI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // this member is seen by the platform dependent code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    PortControlCreator creator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    // general JNI variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    // the vector to be filled with controls (initialized before usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    jobject vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    jmethodID vectorAddElement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    // control specific constructors (initialized on demand)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    jclass boolCtrlClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    jmethodID boolCtrlConstructor;   // signature (JLjava/lang/String;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    jclass controlClass;             // class of javax.sound.sampled.Control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    jclass compCtrlClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    jmethodID compCtrlConstructor;   // signature (Ljava/lang/String;[Ljavax/sound/sampled/Control;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    jclass floatCtrlClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    jmethodID floatCtrlConstructor1; // signature (JLjava/lang/String;FFFLjava/lang/String;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    jmethodID floatCtrlConstructor2; // signature (JIFFFLjava/lang/String;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
} ControlCreatorJNI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
void* PORT_NewBooleanControl(void* creatorV, void* controlID, char* type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    ControlCreatorJNI* creator = (ControlCreatorJNI*) creatorV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    jobject ctrl = NULL;
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   174
    jstring typeString;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
#ifdef USE_TRACE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    if (((UINT_PTR) type) <= CONTROL_TYPE_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        TRACE1("PORT_NewBooleanControl: creating '%d'\n", (int) (UINT_PTR) type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        TRACE1("PORT_NewBooleanControl: creating '%s'\n", type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    if (!creator->boolCtrlClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // retrieve class and constructor of PortMixer.BoolCtrl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        creator->boolCtrlClass = (*creator->env)->FindClass(creator->env, IMPLEMENTATION_PACKAGE_NAME"/PortMixer$BoolCtrl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (!creator->boolCtrlClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            ERROR0("PORT_NewBooleanControl: boolCtrlClass is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        creator->boolCtrlConstructor = (*creator->env)->GetMethodID(creator->env, creator->boolCtrlClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                 "<init>", "(JLjava/lang/String;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (!creator->boolCtrlConstructor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            ERROR0("PORT_NewBooleanControl: boolCtrlConstructor is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    if (type == CONTROL_TYPE_MUTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        type = "Mute";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    else if (type == CONTROL_TYPE_SELECT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        type = "Select";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   204
    typeString = (*creator->env)->NewStringUTF(creator->env, type);
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   205
    CHECK_NULL_RETURN(typeString, (void*) ctrl);
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   206
    ctrl = (*creator->env)->NewObject(creator->env, creator->boolCtrlClass,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   207
                                      creator->boolCtrlConstructor,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   208
                                      (jlong) (UINT_PTR) controlID, typeString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    if (!ctrl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        ERROR0("PORT_NewBooleanControl: ctrl is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    if ((*creator->env)->ExceptionOccurred(creator->env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        ERROR0("PORT_NewBooleanControl: ExceptionOccurred!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    TRACE0("PORT_NewBooleanControl succeeded\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    return (void*) ctrl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
void* PORT_NewCompoundControl(void* creatorV, char* type, void** controls, int controlCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    ControlCreatorJNI* creator = (ControlCreatorJNI*) creatorV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    jobject ctrl = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jobjectArray controlArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    int i;
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   224
    jstring typeString;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    TRACE2("PORT_NewCompoundControl: creating '%s' with %d controls\n", type, controlCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    if (!creator->compCtrlClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        TRACE0("PORT_NewCompoundControl: retrieve method ids\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // retrieve class and constructor of PortMixer.BoolCtrl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        creator->compCtrlClass = (*creator->env)->FindClass(creator->env, IMPLEMENTATION_PACKAGE_NAME"/PortMixer$CompCtrl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (!creator->compCtrlClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            ERROR0("PORT_NewCompoundControl: compCtrlClass is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        creator->compCtrlConstructor = (*creator->env)->GetMethodID(creator->env, creator->compCtrlClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                 "<init>", "(Ljava/lang/String;[Ljavax/sound/sampled/Control;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (!creator->compCtrlConstructor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            ERROR0("PORT_NewCompoundControl: compCtrlConstructor is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        creator->controlClass = (*creator->env)->FindClass(creator->env, JAVA_SAMPLED_PACKAGE_NAME"/Control");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (!creator->controlClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            ERROR0("PORT_NewCompoundControl: controlClass is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    TRACE0("PORT_NewCompoundControl: creating array\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    // create new array for the controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    controlArray = (*creator->env)->NewObjectArray(creator->env, controlCount, creator->controlClass, (jobject) NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    if (!controlArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        ERROR0("PORT_NewCompoundControl: controlArray is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    TRACE0("PORT_NewCompoundControl: setting array values\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    for (i = 0; i < controlCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        (*creator->env)->SetObjectArrayElement(creator->env, controlArray, i, (jobject) controls[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    TRACE0("PORT_NewCompoundControl: creating compound control\n");
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   259
    typeString = (*creator->env)->NewStringUTF(creator->env, type);
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   260
    CHECK_NULL_RETURN(typeString, (void*) ctrl);
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   261
    ctrl = (*creator->env)->NewObject(creator->env, creator->compCtrlClass,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   262
                                      creator->compCtrlConstructor,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   263
                                      typeString, controlArray);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    if (!ctrl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        ERROR0("PORT_NewCompoundControl: ctrl is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    if ((*creator->env)->ExceptionOccurred(creator->env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        ERROR0("PORT_NewCompoundControl: ExceptionOccurred!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    TRACE0("PORT_NewCompoundControl succeeded\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    return (void*) ctrl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
void* PORT_NewFloatControl(void* creatorV, void* controlID, char* type,
32110
733062f75808 8074831: Resolve disabled warnings for libjsound
serb
parents: 25859
diff changeset
   275
                           float min, float max, float precision, const char* units) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    ControlCreatorJNI* creator = (ControlCreatorJNI*) creatorV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    jobject ctrl = NULL;
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   278
    jstring unitsString;
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   279
    jstring typeString;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
#ifdef USE_TRACE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    if (((UINT_PTR) type) <= CONTROL_TYPE_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        TRACE1("PORT_NewFloatControl: creating '%d'\n", (int) (UINT_PTR) type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        TRACE1("PORT_NewFloatControl: creating '%s'\n", type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    if (!creator->floatCtrlClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // retrieve class and constructor of PortMixer.BoolCtrl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        creator->floatCtrlClass = (*creator->env)->FindClass(creator->env, IMPLEMENTATION_PACKAGE_NAME"/PortMixer$FloatCtrl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (!creator->floatCtrlClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            ERROR0("PORT_NewFloatControl: floatCtrlClass is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        creator->floatCtrlConstructor1 = (*creator->env)->GetMethodID(creator->env, creator->floatCtrlClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                 "<init>", "(JLjava/lang/String;FFFLjava/lang/String;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if (!creator->floatCtrlConstructor1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            ERROR0("PORT_NewFloatControl: floatCtrlConstructor1 is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        creator->floatCtrlConstructor2 = (*creator->env)->GetMethodID(creator->env, creator->floatCtrlClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                 "<init>", "(JIFFFLjava/lang/String;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (!creator->floatCtrlConstructor2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            ERROR0("PORT_NewFloatControl: floatCtrlConstructor2 is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   308
    unitsString = (*creator->env)->NewStringUTF(creator->env, units);
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   309
    CHECK_NULL_RETURN(unitsString, (void*) ctrl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    if (((UINT_PTR) type) <= CONTROL_TYPE_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        // constructor with int parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        TRACE1("PORT_NewFloatControl: calling constructor2 with type %d\n", (int) (UINT_PTR) type);
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   313
        ctrl = (*creator->env)->NewObject(creator->env, creator->floatCtrlClass,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   314
                                          creator->floatCtrlConstructor2,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   315
                                          (jlong) (UINT_PTR) controlID, (jint) (UINT_PTR) type,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   316
                                          min, max, precision, unitsString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        TRACE0("PORT_NewFloatControl: calling constructor1\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        // constructor with string parameter
23659
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   320
        typeString = (*creator->env)->NewStringUTF(creator->env, type);
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   321
        CHECK_NULL_RETURN(typeString, (void*) ctrl);
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   322
        ctrl = (*creator->env)->NewObject(creator->env, creator->floatCtrlClass,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   323
                                          creator->floatCtrlConstructor1,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   324
                                          (jlong) (UINT_PTR) controlID, typeString,
ac5179bc5c63 8029362: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.media.sound: JNI exception pending
serb
parents: 5506
diff changeset
   325
                                          min, max, precision, unitsString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    if (!ctrl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        ERROR0("PORT_NewFloatControl: ctrl is NULL!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    if ((*creator->env)->ExceptionOccurred(creator->env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        ERROR0("PORT_NewFloatControl: ExceptionOccurred!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    TRACE1("PORT_NewFloatControl succeeded %p\n", (void*) ctrl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    return (void*) ctrl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
int PORT_AddControl(void* creatorV, void* control) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    ControlCreatorJNI* creator = (ControlCreatorJNI*) creatorV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    TRACE1("PORT_AddControl %p\n", (void*) control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    (*creator->env)->CallVoidMethod(creator->env, creator->vector, creator->vectorAddElement, (jobject) control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    if ((*creator->env)->ExceptionOccurred(creator->env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        ERROR0("PORT_AddControl: ExceptionOccurred!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    TRACE0("PORT_AddControl succeeded\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
JNIEXPORT void JNICALL Java_com_sun_media_sound_PortMixer_nGetControls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
  (JNIEnv *env, jclass cls, jlong id, jint portIndex, jobject vector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    ControlCreatorJNI creator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    jclass vectorClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
#if USE_PORTS == TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    if (id != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        memset(&creator, 0, sizeof(ControlCreatorJNI));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        creator.creator.newBooleanControl  = &PORT_NewBooleanControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        creator.creator.newCompoundControl = &PORT_NewCompoundControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        creator.creator.newFloatControl    = &PORT_NewFloatControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        creator.creator.addControl         = &PORT_AddControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        creator.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        vectorClass = (*env)->GetObjectClass(env, vector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (vectorClass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            ERROR0("Java_com_sun_media_sound_PortMixer_nGetControls: vectorClass is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        creator.vector = vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        creator.vectorAddElement = (*env)->GetMethodID(env, vectorClass, "addElement", "(Ljava/lang/Object;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (creator.vectorAddElement == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            ERROR0("Java_com_sun_media_sound_PortMixer_nGetControls: addElementMethodID is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        PORT_GetControls((void*) (UINT_PTR) id, (INT32) portIndex, (PortControlCreator*) &creator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}