Path: blob/master/src/java.desktop/share/native/libjsound/DirectAudioDeviceProvider.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_TRACE26//#define USE_ERROR272829#include <jni.h>30#include <jni_util.h>31#include "SoundDefs.h"32#include "DirectAudio.h"33#include "Utilities.h"34#include "com_sun_media_sound_DirectAudioDeviceProvider.h"353637//////////////////////////////////////////// DirectAudioDeviceProvider ////////////////////////////////////////////3839int getDirectAudioDeviceDescription(int mixerIndex, DirectAudioDeviceDescription* desc) {40desc->deviceID = 0;41desc->maxSimulLines = 0;42strcpy(desc->name, "Unknown Name");43strcpy(desc->vendor, "Unknown Vendor");44strcpy(desc->description, "Unknown Description");45strcpy(desc->version, "Unknown Version");46#if USE_DAUDIO == TRUE47DAUDIO_GetDirectAudioDeviceDescription(mixerIndex, desc);48#endif // USE_DAUDIO49return TRUE;50}5152JNIEXPORT jint JNICALL Java_com_sun_media_sound_DirectAudioDeviceProvider_nGetNumDevices(JNIEnv *env, jclass cls) {53INT32 numDevices = 0;5455TRACE0("Java_com_sun_media_sound_DirectAudioDeviceProvider_nGetNumDevices.\n");5657#if USE_DAUDIO == TRUE58numDevices = DAUDIO_GetDirectAudioDeviceCount();59#endif // USE_DAUDIO6061TRACE1("Java_com_sun_media_sound_DirectAudioDeviceProvider_nGetNumDevices returning %d.\n", (int) numDevices);6263return (jint)numDevices;64}6566JNIEXPORT jobject JNICALL Java_com_sun_media_sound_DirectAudioDeviceProvider_nNewDirectAudioDeviceInfo67(JNIEnv *env, jclass cls, jint mixerIndex) {6869jclass directAudioDeviceInfoClass;70jmethodID directAudioDeviceInfoConstructor;71DirectAudioDeviceDescription desc;72jobject info = NULL;73jstring name;74jstring vendor;75jstring description;76jstring version;7778TRACE1("Java_com_sun_media_sound_DirectAudioDeviceProvider_nNewDirectAudioDeviceInfo(%d).\n", mixerIndex);7980// retrieve class and constructor of DirectAudioDeviceProvider.DirectAudioDeviceInfo81directAudioDeviceInfoClass = (*env)->FindClass(env, IMPLEMENTATION_PACKAGE_NAME"/DirectAudioDeviceProvider$DirectAudioDeviceInfo");82if (directAudioDeviceInfoClass == NULL) {83ERROR0("Java_com_sun_media_sound_DirectAudioDeviceProvider_nNewDirectAudioDeviceInfo: directAudioDeviceInfoClass is NULL\n");84return NULL;85}86directAudioDeviceInfoConstructor = (*env)->GetMethodID(env, directAudioDeviceInfoClass, "<init>",87"(IIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");88if (directAudioDeviceInfoConstructor == NULL) {89ERROR0("Java_com_sun_media_sound_DirectAudioDeviceProvider_nNewDirectAudioDeviceInfo: directAudioDeviceInfoConstructor is NULL\n");90return NULL;91}9293TRACE1("Get description for device %d\n", mixerIndex);9495if (getDirectAudioDeviceDescription(mixerIndex, &desc)) {96// create a new DirectAudioDeviceInfo object and return it97name = (*env)->NewStringUTF(env, desc.name);98CHECK_NULL_RETURN(name, info);99vendor = (*env)->NewStringUTF(env, desc.vendor);100CHECK_NULL_RETURN(vendor, info);101description = (*env)->NewStringUTF(env, desc.description);102CHECK_NULL_RETURN(description, info);103version = (*env)->NewStringUTF(env, desc.version);104CHECK_NULL_RETURN(version, info);105info = (*env)->NewObject(env, directAudioDeviceInfoClass,106directAudioDeviceInfoConstructor, mixerIndex,107desc.deviceID, desc.maxSimulLines,108name, vendor, description, version);109} else {110ERROR1("ERROR: getDirectAudioDeviceDescription(%d, desc) returned FALSE!\n", mixerIndex);111}112113TRACE0("Java_com_sun_media_sound_DirectAudioDeviceProvider_nNewDirectAudioDeviceInfo succeeded.\n");114return info;115}116117118