Path: blob/master/src/java.desktop/share/native/libjsound/PortMixerProvider.c
41152 views
/*1* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425//#define USE_TRACE262728#include <jni.h>29#include <jni_util.h>30#include "SoundDefs.h"31#include "Ports.h"32#include "Utilities.h"33#include "com_sun_media_sound_PortMixerProvider.h"343536//////////////////////////////////////////// PortMixerProvider ////////////////////////////////////////////3738int getPortMixerDescription(int mixerIndex, PortMixerDescription* desc) {39strcpy(desc->name, "Unknown Name");40strcpy(desc->vendor, "Unknown Vendor");41strcpy(desc->description, "Port Mixer");42strcpy(desc->version, "Unknown Version");43#if USE_PORTS == TRUE44PORT_GetPortMixerDescription(mixerIndex, desc);45#endif // USE_PORTS46return TRUE;47}4849JNIEXPORT jint JNICALL Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices(JNIEnv *env, jclass cls) {50INT32 numDevices = 0;5152TRACE0("Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices.\n");5354#if USE_PORTS == TRUE55numDevices = PORT_GetPortMixerCount();56#endif // USE_PORTS5758TRACE1("Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices returning %d.\n", (int) numDevices);5960return (jint)numDevices;61}6263JNIEXPORT jobject JNICALL Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo(JNIEnv *env, jclass cls, jint mixerIndex) {64jclass portMixerInfoClass;65jmethodID portMixerInfoConstructor;66PortMixerDescription desc;67jobject info = NULL;68jstring name;69jstring vendor;70jstring description;71jstring version;7273TRACE1("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo(%d).\n", mixerIndex);7475// retrieve class and constructor of PortMixerProvider.PortMixerInfo76portMixerInfoClass = (*env)->FindClass(env, IMPLEMENTATION_PACKAGE_NAME"/PortMixerProvider$PortMixerInfo");77if (portMixerInfoClass == NULL) {78ERROR0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo: portMixerInfoClass is NULL\n");79return NULL;80}81portMixerInfoConstructor = (*env)->GetMethodID(env, portMixerInfoClass, "<init>",82"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");83if (portMixerInfoConstructor == NULL) {84ERROR0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo: portMixerInfoConstructor is NULL\n");85return NULL;86}8788if (getPortMixerDescription(mixerIndex, &desc)) {89// create a new PortMixerInfo object and return it90name = (*env)->NewStringUTF(env, desc.name);91CHECK_NULL_RETURN(name, info);92vendor = (*env)->NewStringUTF(env, desc.vendor);93CHECK_NULL_RETURN(vendor, info);94description = (*env)->NewStringUTF(env, desc.description);95CHECK_NULL_RETURN(description, info);96version = (*env)->NewStringUTF(env, desc.version);97CHECK_NULL_RETURN(version, info);98info = (*env)->NewObject(env, portMixerInfoClass,99portMixerInfoConstructor, mixerIndex,100name, vendor, description, version);101}102103TRACE0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo succeeded.\n");104return info;105}106107108