Beispiel #1
0
Datei: opengl.c Projekt: 7max/glc
int opengl_push_message(glc_message_header_t *hdr, void *message, size_t message_size)
{
	ps_packet_t packet;
	int ret = 0;
	ps_buffer_t *to;
	if (!lib.running)
		return EAGAIN;

	if (opengl.unscaled)
		to = opengl.unscaled;
	else
		to = opengl.buffer;

	if ((ret = ps_packet_init(&packet, to)))
		goto finish;
	if ((ret = ps_packet_open(&packet, PS_PACKET_WRITE)))
		goto finish;
	if ((ret = ps_packet_write(&packet, hdr, sizeof(glc_message_header_t))))
		goto finish;
	if ((ret = ps_packet_write(&packet, message, message_size)))
		goto finish;
	if ((ret = ps_packet_close(&packet)))
		goto finish;
	if ((ret = ps_packet_destroy(&packet)))
		goto finish;

finish:
	return ret;
}
Beispiel #2
0
int audio_capture_set_buffer(audio_capture_t audio_capture, ps_buffer_t *buffer)
{
	if (audio_capture->target)
		return EAGAIN;

	audio_capture->target = buffer;
	ps_packet_init(&audio_capture->packet, audio_capture->target);

	return 0;
}
Beispiel #3
0
int alsa_hook_stream_init(alsa_hook_t alsa_hook,
			struct alsa_hook_stream_s *stream)
{
	int ret;
	glc_message_header_t msg_hdr;
	glc_audio_format_message_t fmt_msg;

	if (unlikely(!stream->fmt))
		return EINVAL;

	/* we need proper id for the stream */
	if (stream->id < 1)
		glc_state_audio_new(alsa_hook->glc, &stream->id,
					&stream->state_audio);

	glc_log(alsa_hook->glc, GLC_INFO, "alsa_hook",
		 "%p: initializing stream %d", stream->pcm, stream->id);

	/* init packet */
	if (stream->initialized)
		ps_packet_destroy(&stream->packet);
	ps_packet_init(&stream->packet, alsa_hook->to);

	/* prepare audio format message */
	msg_hdr.type = GLC_MESSAGE_AUDIO_FORMAT;
	fmt_msg.id = stream->id;
	fmt_msg.flags = stream->flags;
	fmt_msg.rate = stream->rate;
	fmt_msg.channels = stream->channels;
	fmt_msg.format = stream->format;
	ps_packet_open(&stream->packet, PS_PACKET_WRITE);
	ps_packet_write(&stream->packet, &msg_hdr,
			sizeof(glc_message_header_t));
	ps_packet_write(&stream->packet, &fmt_msg,
			sizeof(glc_audio_format_message_t));
	ps_packet_close(&stream->packet);

	alsa_hook_stream_wait(stream);

	ret = glc_simple_thread_create(alsa_hook->glc, &stream->thread,
				alsa_hook_thread, stream);

	stream->initialized = 1;
	return ret;
}
Beispiel #4
0
int gl_capture_get_video_stream(gl_capture_t gl_capture,
				struct gl_capture_video_stream_s **video,
				Display *dpy, GLXDrawable drawable)
{
	struct gl_capture_video_stream_s *fvideo;

	pthread_rwlock_rdlock(&gl_capture->videolist_lock);
	fvideo = gl_capture->video;
	while (fvideo != NULL) {
		if ((fvideo->drawable == drawable) && (fvideo->dpy == dpy))
			break;

		fvideo = fvideo->next;
	}
	pthread_rwlock_unlock(&gl_capture->videolist_lock);

	if (fvideo == NULL) {
		fvideo = (struct gl_capture_video_stream_s *)
			calloc(1, sizeof(struct gl_capture_video_stream_s));

		fvideo->dpy          = dpy;
		fvideo->drawable     = drawable;
		fvideo->gather_stats = glc_log_get_level(gl_capture->glc) >= GLC_PERF;
		ps_packet_init(&fvideo->packet, gl_capture->to);

		glc_state_video_new(gl_capture->glc, &fvideo->id, &fvideo->state_video);

		/* these functions need to be thread-safe */
		pthread_rwlock_wrlock(&gl_capture->videolist_lock);

		fvideo->next      = gl_capture->video;
		gl_capture->video = fvideo;

		pthread_rwlock_unlock(&gl_capture->videolist_lock);
	}
	
	*video = fvideo;
	return 0;
}
Beispiel #5
0
int glc_util_write_end_of_stream(glc_t *glc, ps_buffer_t *to)
{
	int ret = 0;
	ps_packet_t packet;
	glc_message_header_t header;
	header.type = GLC_MESSAGE_CLOSE;

	if (unlikely((ret = ps_packet_init(&packet, to))))
		goto finish;
	if (unlikely((ret = ps_packet_open(&packet, PS_PACKET_WRITE))))
		goto finish;
	if (unlikely((ret = ps_packet_write(&packet,
			&header, sizeof(glc_message_header_t)))))
		goto finish;
	if (unlikely((ret = ps_packet_close(&packet))))
		goto finish;
	if (unlikely((ret = ps_packet_destroy(&packet))))
		goto finish;

finish:
	return ret;
}