1/*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26//#define USE_TRACE
27
28
29#include <jni.h>
30#include <jni_util.h>
31#include "SoundDefs.h"
32#include "Ports.h"
33#include "Utilities.h"
34#include "com_sun_media_sound_PortMixerProvider.h"
35
36
37//////////////////////////////////////////// PortMixerProvider ////////////////////////////////////////////
38
39int getPortMixerDescription(int mixerIndex, PortMixerDescription* desc) {
40 strcpy(desc->name, "Unknown Name");
41 strcpy(desc->vendor, "Unknown Vendor");
42 strcpy(desc->description, "Port Mixer");
43 strcpy(desc->version, "Unknown Version");
44#if USE_PORTS == TRUE
45 PORT_GetPortMixerDescription(mixerIndex, desc);
46#endif // USE_PORTS
47 return TRUE;
48}
49
50JNIEXPORT jint JNICALL Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices(JNIEnv *env, jclass cls) {
51 INT32 numDevices = 0;
52
53 TRACE0("Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices.\n");
54
55#if USE_PORTS == TRUE
56 numDevices = PORT_GetPortMixerCount();
57#endif // USE_PORTS
58
59 TRACE1("Java_com_sun_media_sound_PortMixerProvider_nGetNumDevices returning %d.\n", (int) numDevices);
60
61 return (jint)numDevices;
62}
63
64JNIEXPORT jobject JNICALL Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo(JNIEnv *env, jclass cls, jint mixerIndex) {
65 jclass portMixerInfoClass;
66 jmethodID portMixerInfoConstructor;
67 PortMixerDescription desc;
68 jobject info = NULL;
69 jstring name;
70 jstring vendor;
71 jstring description;
72 jstring version;
73
74 TRACE1("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo(%d).\n", mixerIndex);
75
76 // retrieve class and constructor of PortMixerProvider.PortMixerInfo
77 portMixerInfoClass = (*env)->FindClass(env, IMPLEMENTATION_PACKAGE_NAME"/PortMixerProvider$PortMixerInfo");
78 if (portMixerInfoClass == NULL) {
79 ERROR0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo: portMixerInfoClass is NULL\n");
80 return NULL;
81 }
82 portMixerInfoConstructor = (*env)->GetMethodID(env, portMixerInfoClass, "<init>",
83 "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
84 if (portMixerInfoConstructor == NULL) {
85 ERROR0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo: portMixerInfoConstructor is NULL\n");
86 return NULL;
87 }
88
89 if (getPortMixerDescription(mixerIndex, &desc)) {
90 // create a new PortMixerInfo object and return it
91 name = (*env)->NewStringUTF(env, desc.name);
92 CHECK_NULL_RETURN(name, info);
93 vendor = (*env)->NewStringUTF(env, desc.vendor);
94 CHECK_NULL_RETURN(vendor, info);
95 description = (*env)->NewStringUTF(env, desc.description);
96 CHECK_NULL_RETURN(description, info);
97 version = (*env)->NewStringUTF(env, desc.version);
98 CHECK_NULL_RETURN(version, info);
99 info = (*env)->NewObject(env, portMixerInfoClass,
100 portMixerInfoConstructor, mixerIndex,
101 name, vendor, description, version);
102 }
103
104 TRACE0("Java_com_sun_media_sound_PortMixerProvider_nNewPortMixerInfo succeeded.\n");
105 return info;
106}
107