Beispiel #1
0
gint oss_open(AFormat fmt, gint rate, gint nch)
{
	if (oss_cfg.use_alt_audio_device && oss_cfg.alt_audio_device)
		device_name = g_strdup(oss_cfg.alt_audio_device);
	else
	{
		if (oss_cfg.audio_device > 0)
			device_name = g_strdup_printf("%s%d", DEV_DSP, oss_cfg.audio_device);
		else
			device_name = g_strdup(DEV_DSP);
	}
	fd = open(device_name, O_WRONLY);
	if (fd == -1)
	{
		g_warning("oss_open(): Failed to open audio device (%s): %s",
			  device_name, strerror(errno));
		g_free(device_name);
		return 0;
	}

	input.format.xmms = fmt;
	input.frequency = rate;
	input.channels = nch;
	input.bps = oss_calc_bitrate(oss_get_format(fmt), rate, nch);

	oss_setup_format(fmt, rate, nch);
	
	realtime = xmms_check_realtime_priority();
	
	if(!realtime)
	{
		buffer_size = (oss_cfg.buffer_size * input.bps) / 1000;
		if (buffer_size < 8192)
			buffer_size = 8192;
		prebuffer_size = (buffer_size * oss_cfg.prebuffer) / 100;
		if (buffer_size - prebuffer_size < 4096)
			prebuffer_size = buffer_size - 4096;

		buffer_size += device_buffer_size;
		buffer = g_malloc0(buffer_size);
	}
	flush = -1;
	prebuffer = TRUE;
	wr_index = rd_index = output_time_offset = written = output_bytes = 0;
	paused = FALSE;
	do_pause = FALSE;
	unpause = FALSE;
	remove_prebuffer = FALSE;

	going = 1;
	if (!realtime)
		pthread_create(&buffer_thread, NULL, oss_loop, NULL);
	return 1;
}
Beispiel #2
0
static gint playerout_open(AFormat fmt, gint rate, gint nch)
{
	gint pos;

	written = 0;
	afmt = fmt;
	sampleRate = rate;
	numChannels = nch;
	startTime = 0.0f;
	pausedTime = 0.0f;

	if (xmms_check_realtime_priority())
	{
		xmms_show_message("Error",
				  "You cannot use the Player Output plugin\n"
				    "when you're running in realtime mode.",
				  "Ok", FALSE, NULL, NULL);
		return 0;
	}

	/* do player server connection here */
	// Create a client object and connect to the server; the server must
	// be running on "localhost" at port 6665
	client = playerc_client_create(NULL, server_address, server_port);
	if (playerc_client_connect(client) != 0)
	{
		fprintf(stderr, "error: %s\n", playerc_error_str());
		client = NULL;
		return 0;
	}

	// Create a audio proxy susbscribe
	audio_proxy = playerc_audio_create(client, server_index);
	if (playerc_audio_subscribe(audio_proxy, PLAYERC_OPEN_MODE) != 0)
	{
		fprintf(stderr, "error: %s\n", playerc_error_str());
		return 0;
	}

	// Set to PULL data mode
	if (playerc_client_datamode (client, PLAYERC_DATAMODE_PULL) != 0)
	{
		fprintf(stderr, "error: %s\n", playerc_error_str());
		return 0;
	}
	if (playerc_client_set_replace_rule (client, -1, -1, PLAYER_MSGTYPE_DATA, -1, 1) != 0)
	{
		fprintf(stderr, "error: %s\n", playerc_error_str());
		return 0;
	}

	bytesPerSecond = rate * nch;
	if (fmt == FMT_S16_LE || fmt == FMT_S16_BE || fmt == FMT_S16_NE ||
		   fmt == FMT_U16_LE || fmt == FMT_U16_BE || fmt == FMT_U16_NE)
		bytesPerSecond *= 2;

	// Allocate a buffer
	bufferLength = (int) (((float) bufferTime / 1000.0f) * bytesPerSecond);
	if (buffer != NULL)
		free (buffer);
	buffer = malloc (bufferLength);
	bufferPos = 0;

	return 1;
}
Beispiel #3
0
void *draw_thread_func(void *arg)
{
	Bool configured = FALSE;

	if ((window = create_window(640, 480)) == 0)
	{
		g_log(NULL, G_LOG_LEVEL_CRITICAL, __FILE__ ": unable to create window");
		pthread_exit(NULL);
	}
	
	XMapWindow(dpy, window);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-1, 1, -1, 1, 1.5, 10);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

#ifdef HAVE_SCHED_SETSCHEDULER
	if(xmms_check_realtime_priority())
	{
		struct sched_param sparam;
		sparam.sched_priority = sched_get_priority_max(SCHED_OTHER);
		pthread_setschedparam(pthread_self(), SCHED_OTHER, &sparam);		
	}
#endif
	
	while(going)
	{
		while(XPending(dpy))
		{
			XEvent event;
			KeySym keysym;
			char buf[16];
			
			XNextEvent(dpy, &event);
			switch(event.type)
			{
			case ConfigureNotify:
				glViewport(0,0,event.xconfigure.width, event.xconfigure.height);
				if(oglspectrum_cfg.tdfx_mode && !grabbed_pointer)
				{
					
					XGrabPointer(dpy, window,
						     True, ButtonPressMask,
						     GrabModeAsync,
						     GrabModeAsync,
						     window, None, CurrentTime);
					grabbed_pointer = TRUE;
				}
				configured = TRUE;
				break;
			case KeyPress:

				
				XLookupString (&event.xkey, buf, 16, &keysym, NULL);
				switch(keysym)
				{
				case XK_Escape:
					
					/* Ugly hack to get the disable_plugin call in the main thread. */
					GDK_THREADS_ENTER();
					gtk_idle_add(disable_func, NULL);
					GDK_THREADS_LEAVE();
					break;
				case XK_z:
					xmms_remote_playlist_prev(oglspectrum_vp.xmms_session);
					break;
				case XK_x:
					xmms_remote_play(oglspectrum_vp.xmms_session);
					break;
				case XK_c:
					xmms_remote_pause(oglspectrum_vp.xmms_session);
					break;
				case XK_v:
					xmms_remote_stop(oglspectrum_vp.xmms_session);
					break;
				case XK_b:
					xmms_remote_playlist_next(oglspectrum_vp.xmms_session);
					break;
				case XK_Up:					
					x_speed -= 0.1;
					if(x_speed < -3.0)
						x_speed = -3.0;
					break;
				case XK_Down:					
					x_speed += 0.1;
					if(x_speed > 3.0)
						x_speed = 3.0;
					break;
				case XK_Left:
					y_speed -= 0.1;
					if(y_speed < -3.0)
						y_speed = -3.0;
					
					break;
				case XK_Right:
					y_speed += 0.1;
					if(y_speed > 3.0)
						y_speed = 3.0;
					break;
				case XK_w:
					z_speed -= 0.1;
					if(z_speed < -3.0)
						z_speed = -3.0;
					break;
				case XK_q:
					z_speed += 0.1;
					if(z_speed > 3.0)
						z_speed = 3.0;
					break;
				case XK_Return:
					x_speed = 0.0;
					y_speed = 0.5;
					z_speed = 0.0;
					x_angle = 20.0;
					y_angle = 45.0;
					z_angle = 0.0;
					break;					
				}
				
				break;
			case ClientMessage:
				if ((Atom)event.xclient.data.l[0] == wm_delete_window_atom)
				{
					GDK_THREADS_ENTER();
					gtk_idle_add(disable_func, NULL);
					GDK_THREADS_LEAVE();
				}
				break;
			}
		}
		if(configured)
		{
			x_angle += x_speed;
			if(x_angle >= 360.0)
				x_angle -= 360.0;
			
			y_angle += y_speed;
			if(y_angle >= 360.0)
				y_angle -= 360.0;

			z_angle += z_speed;
			if(z_angle >= 360.0)
				z_angle -= 360.0;

			draw_bars();
		}
	}

	if (glxcontext)
	{
		glXMakeCurrent(dpy, 0, NULL);
		glXDestroyContext(dpy, glxcontext);
		glxcontext = NULL;
	}
	if (window)
	{
		if (grabbed_pointer)
		{
			XUngrabPointer(dpy, CurrentTime);
			grabbed_pointer = FALSE;
		}

		XDestroyWindow(dpy, window);
		window = 0;
	}

	pthread_exit(NULL);
}