blob: 114d598f8a0710ff64e2e219682099ebac5a5787 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26//#define USE_TRACE
27
28
29#include <jni.h>
30#include "SoundDefs.h"
31#include "Ports.h"
32#include "Utilities.h"
33#include "com_sun_media_sound_PortMixerProvider.h"
34
35
36//////////////////////////////////////////// PortMixerProvider ////////////////////////////////////////////
37
38int getPortMixerDescription(int mixerIndex, PortMixerDescription* desc) {
39 strcpy(desc->name, "Unknown Name");
40 strcpy(desc->vendor, "Unknown Vendor");
41 strcpy(desc->description, "Port Mixer");
42 strcpy(desc->version, "Unknown Version");
43#if USE_PORTS == TRUE
44 PORT_GetPortMixerDescription(mixerIndex, desc);
45#endif // USE_PORTS
46 return TRUE;
47}
48
49JNIEXPORT jint JNICALL Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices(JNIEnv *env, jclass cls) {
50 INT32 numDevices = 0;
51
52 TRACE0("Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices.\n");
53
54#if USE_PORTS == TRUE
55 numDevices = PORT_GetPortMixerCount();
56#endif // USE_PORTS
57
58 TRACE1("Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices returning %d.\n", (int) numDevices);
59
60 return (jint)numDevices;
61}
62
63JNIEXPORT jobject JNICALL Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo(JNIEnv *env, jclass cls, jint mixerIndex) {
64 jclass portMixerInfoClass;
65 jmethodID portMixerInfoConstructor;
66 PortMixerDescription desc;
67 jobject info = NULL;
68 TRACE1("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo(%d).\n", mixerIndex);
69
70 // retrieve class and constructor of PortMixerProvider.PortMixerInfo
71 portMixerInfoClass = (*env)->FindClass(env, IMPLEMENTATION_PACKAGE_NAME"/PortMixerProvider$PortMixerInfo");
72 if (portMixerInfoClass == NULL) {
73 ERROR0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo: portMixerInfoClass is NULL\n");
74 return NULL;
75 }
76 portMixerInfoConstructor = (*env)->GetMethodID(env, portMixerInfoClass, "<init>",
77 "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
78 if (portMixerInfoConstructor == NULL) {
79 ERROR0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo: portMixerInfoConstructor is NULL\n");
80 return NULL;
81 }
82
83 if (getPortMixerDescription(mixerIndex, &desc)) {
84 // create a new PortMixerInfo object and return it
85 info = (*env)->NewObject(env, portMixerInfoClass, portMixerInfoConstructor, mixerIndex,
86 (*env)->NewStringUTF(env, desc.name),
87 (*env)->NewStringUTF(env, desc.vendor),
88 (*env)->NewStringUTF(env, desc.description),
89 (*env)->NewStringUTF(env, desc.version));
90 }
91
92 TRACE0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo succeeded.\n");
93 return info;
94}