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; }
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; }