Пример #1
0
int audio_capture_data(audio_capture_t audio_capture,
		       void *data, size_t size)
{
	glc_message_header_t msg_hdr;
	glc_audio_data_header_t audio_hdr;

	int ret;
	if (!(audio_capture->flags & AUDIO_CAPTURE_CAPTURING))
		return 0;

	if (audio_capture->flags & AUDIO_CAPTURE_CFG_CHANGED) {
		if ((ret = audio_capture_write_cfg(audio_capture)))
			return ret;
		audio_capture->flags &= ~AUDIO_CAPTURE_CFG_CHANGED;
	}

	if (!(audio_capture->flags & AUDIO_CAPTURE_IGNORE_TIME))
		audio_capture->time = glc_state_time(audio_capture->glc);

	msg_hdr.type = GLC_MESSAGE_AUDIO_DATA;
	audio_hdr.id = audio_capture->id; /* should be set to valid one */
	audio_hdr.size = size;
	audio_hdr.time = audio_capture->time;

	if (audio_capture->flags & AUDIO_CAPTURE_IGNORE_TIME)
		audio_capture->time += ((glc_utime_t) size * (glc_utime_t) 1000000) /
					(glc_utime_t) (audio_capture_frames_to_bytes(audio_capture, 1) *
						       audio_capture->rate);

	if ((ret = ps_packet_open(&audio_capture->packet, PS_PACKET_WRITE)))
		goto err;
	if ((ret = ps_packet_write(&audio_capture->packet,
				   &msg_hdr, sizeof(glc_message_header_t))))
		goto err;
	if ((ret = ps_packet_write(&audio_capture->packet,
				   &audio_hdr, sizeof(glc_audio_data_header_t))))
		goto err;
	if ((ret = ps_packet_write(&audio_capture->packet,
				   data, size)))
		goto err;
	if ((ret = ps_packet_close(&audio_capture->packet)))
		goto err;

	return 0;
err:
	ps_buffer_cancel(audio_capture->target);
	glc_state_set(audio_capture->glc, GLC_STATE_CANCEL);
	glc_log(audio_capture->glc, GLC_ERROR, "audio_capture",
		"can't write audio data to buffer");
	glc_log(audio_capture->glc, GLC_ERROR, "audio_capture",
		"%s (%d)", strerror(ret), ret);
	return ret;
}
Пример #2
0
void gl_capture_error(gl_capture_t gl_capture, int err)
{
	glc_log(gl_capture->glc, GLC_ERROR, "gl_capture",
		"%s (%d)", strerror(err), err);

	/* stop capturing */
	if (gl_capture->flags & GL_CAPTURE_CAPTURING)
		gl_capture_stop(gl_capture);

	/* cancel glc */
	glc_state_set(gl_capture->glc, GLC_STATE_CANCEL);
	if (gl_capture->to)
		ps_buffer_cancel(gl_capture->to);
}
Пример #3
0
int audio_capture_write_cfg(audio_capture_t audio_capture)
{
	glc_message_header_t hdr;
	glc_audio_format_message_t fmt_msg;
	int ret = 0;

	if (!audio_capture->id)
		glc_state_audio_new(audio_capture->glc, &audio_capture->id,
				    &audio_capture->state_audio);

	hdr.type = GLC_MESSAGE_AUDIO_FORMAT;
	fmt_msg.id = audio_capture->id;
	fmt_msg.flags = audio_capture->format_flags;
	fmt_msg.rate = audio_capture->rate;
	fmt_msg.channels = audio_capture->channels;
	fmt_msg.format = audio_capture->format;

	if ((ret = ps_packet_open(&audio_capture->packet, PS_PACKET_WRITE)))
		goto err;
	if ((ret = ps_packet_write(&audio_capture->packet,
				   &hdr, sizeof(glc_message_header_t))))
		goto err;
	if ((ret = ps_packet_write(&audio_capture->packet,
				   &fmt_msg, sizeof(glc_audio_format_message_t))))
		goto err;
	if ((ret = ps_packet_close(&audio_capture->packet)))
		goto err;

	return 0;
err:
	glc_state_set(audio_capture->glc, GLC_STATE_CANCEL);
	ps_buffer_cancel(audio_capture->target);
	glc_log(audio_capture->glc, GLC_ERROR, "audio_capture",
		"can't write audio stream configuration to buffer");
	glc_log(audio_capture->glc, GLC_ERROR, "audio_capture",
		"%s (%d)", strerror(ret), ret);
	return ret;
}