Mercurial > hg > pulseaudio
changeset 49:bdc766c0c2ae
added PulseAudioStreamVolumeControl.java
author | iivan@town.yyz.redhat.com |
---|---|
date | Fri, 08 Aug 2008 14:54:18 -0400 |
parents | f27fbf96d5aa |
children | 61cf6f811619 |
files | src/org/classpath/icedtea/pulseaudio/PulseAudioStreamVolumeControl.java src/org_classpath_icedtea_pulseaudio_PulseAudioVolumeMuteControl.c |
diffstat | 2 files changed, 66 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/classpath/icedtea/pulseaudio/PulseAudioStreamVolumeControl.java Fri Aug 08 14:54:18 2008 -0400 @@ -0,0 +1,66 @@ +package org.classpath.icedtea.pulseaudio; + +import java.io.IOException; + +import org.classpath.icedtea.pulseaudio.EventLoop; +import org.classpath.icedtea.pulseaudio.PulseAudioVolumeControl; + +public class PulseAudioStreamVolumeControl extends PulseAudioVolumeControl { + private long streamPointer; + private EventLoop eventLoop; + private PulseAudioSourceDataLine line; + + + static { + try { + String library = new java.io.File(".").getCanonicalPath() + + java.io.File.separatorChar + "lib" + + java.io.File.separatorChar + + System.mapLibraryName("pulse-java"); + System.out.println(library); + System.load(library); + } catch (IOException e) { + assert ("Loading failed".endsWith("library")); + } + } + + protected PulseAudioStreamVolumeControl(PulseAudioSourceDataLine line) { + super(line); + this.streamPointer = line.getStreamPointer(); + this.eventLoop = line.getEventLoop(); + this.line = line; + } + + public synchronized void setValue(float newValue) { + if(!line.isMuted()) { + setStreamVolume(newValue); + } + + line.setVolume(newValue); + } + + protected synchronized void setStreamVolume(float newValue) { + int operationPointer; + int operationState; + synchronized(eventLoop.threadLock) { + operationPointer = native_setValue(newValue); + operationState = native_getOperationState(operationPointer); + } + while(operationState != 1) { + synchronized (eventLoop.threadLock) { + operationState = native_getOperationState(operationPointer); + } + } + + } + + public synchronized float getValue() { + return line.getVolume(); + } + + + private native int native_getOperationState(int operationState); + public native int native_setValue(float newValue); +} + +
--- a/src/org_classpath_icedtea_pulseaudio_PulseAudioVolumeMuteControl.c Fri Aug 08 14:40:11 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* PulseAudioStreamVolumeControl.java - Copyright (C) 2008 Red Hat, Inc. - -This file is part of IcedTea. - -IcedTea is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 2. - -IcedTea is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with IcedTea; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. -*/ - - -#include "jni-common.h" - -static void sink_input_change_volume(pa_context* context, - const pa_sink_input_info* input_info, int eol, void* userdata) { - assert(context); - if (eol) { - return; - } - assert(i); - userdata = i->volume; -} - -JNIEXPORT jint JNICALL Java_org_openjdk_sound_PulseAudioStreamVolumeControl_getValue(JNIEnv env*, jobject obj) { - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - int stream_id pa_stream_get_index(stream); - pa_cvolume *volume; - pa_context_get_sink_input_info((pa_context*) contextPointer ,stream_id,sink_input_change_volume, volume); - printf("%d\n", volume->values[0]); -}