view pulseaudio/src/native/org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c @ 1080:8b85ec866923

2008-10-10 Ioana Ivan <iivan@redhat.com> Omair Majid <omajid@redhat.com> * INSTALL: Updated to reflect requirements for pulse-java. * Makefile.am (distclean-local): Clean up pulse-java. (EXTRA_DIST): Add pulseaudio folder. (stamps/icedtea.stamp): Added dependency on stamps/pulse-java.stamp. Also copy generated .jar and .so files to the jre images. (stamps/icedtea-debug.stamp): Likewise. (stamps/pulse-java.stamp): New target. (stamps/pulse-java-jar.stamp): Likewise. (stamps/pulse-java-class.stamp): Likewise. (stamps/pulse-java-headers.stamp): Likewise. (clean-pulse-java): Likewise. * README: Added note for PulseAudio based mixer. * acinclude.m4 (FIND_PULSEAUDIO): Find the pulseaudio binary. * configure.ac: Check for pulseaudio server and header files being installed. * patches/icedtea-pulse-soundproperties.patch: Dont use pulse-java as the default Mixer. * pulseaudio/: Copied over sources from pulseaudio repository.
author Omair Majid <omajid@redhat.com>
date Fri, 10 Oct 2008 16:03:12 -0400
parents
children
line wrap: on
line source

#include "org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.h"
#include "jni-common.h"
#include <pulse/pulseaudio.h>
#include <string.h>

typedef struct java_context {
	JNIEnv* env;
	jobject obj;
} java_context;

extern JNIEnv* pulse_thread_env;

void source_callback(pa_context *context, int success, void *userdata) {
	assert(context);
	assert(pulse_thread_env);
	notifyWaitingOperations(pulse_thread_env);
}

void get_source_volume_callback(pa_context *context, const pa_source_info *i,
		int eol, void *userdata) {
	assert(context);
	assert(pulse_thread_env);
	
	if (eol == 0) {
		// printf("%s\n", i->name); 
		jobject obj = (jobject) userdata;
		assert(obj);
		jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, obj);
		assert(cls);
		jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls,
				"update_channels_and_volume", "(IF)V");
		assert(mid1);
		(*pulse_thread_env)->CallVoidMethod(pulse_thread_env, obj, mid1,
				(int) (i->volume).channels, (float) (i->volume).values[0]) ;
	} else {
		notifyWaitingOperations(pulse_thread_env);
	}
}

/*
 * Class:     org_classpath_icedtea_pulseaudio_PulseAudioSourcePort
 * Method:    native_updateVolumeInfo
 * Signature: ()[B
 */
JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioSourcePort_native_1updateVolumeInfo
(JNIEnv *env, jobject obj) {
	jclass cls = (*env)->GetObjectClass(env, obj);
	assert(cls);
	jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;");
	assert(fid);
	jstring jstr = (*env)->GetObjectField(env, obj, fid);
	assert(jstr);
	const char *name = (*env)->GetStringUTFChars(env, jstr, NULL);
	if (name == NULL) {
		return NULL;    // oome
	}
	
	pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer");
	assert(context);
	obj = (*env)->NewGlobalRef(env, obj);
	pa_operation *o = pa_context_get_source_info_by_name (context, (char*) name, get_source_volume_callback, obj);
	assert(o);
	return convertNativePointerToJava(env, o);
}

/*
 * Class:     org_classpath_icedtea_pulseaudio_PulseAudioSourcePort
 * Method:    native_setVolume
 * Signature: (F)[B
 */
JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioSourcePort_native_1setVolume
(JNIEnv *env, jobject obj, jfloat value) {
	jclass cls = (*env)->GetObjectClass(env, obj);
	assert(cls);
	
	jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;");
	assert(fid);
	
	jstring jstr = (*env)->GetObjectField(env, obj, fid);
	assert(jstr);
	
	const char *name = (*env)->GetStringUTFChars(env, jstr, NULL);
	if (name == NULL) {
		return NULL; 	// oome
	}
	
	pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer");
	assert(context);
	
	obj = (*env)->NewGlobalRef(env, obj);
	fid = (*env)->GetFieldID(env, cls, "channels", "I");
	assert(fid);
	
	jint channels = (*env)->GetIntField(env, obj, fid);
	pa_cvolume cv;
	
	pa_operation *o = pa_context_set_source_volume_by_name (context, (char*) name,pa_cvolume_set(&cv, channels, value), source_callback, obj);
	assert(o);
	
	return convertNativePointerToJava(env, o);
}