static size_t pipe_output_play(struct audio_output *ao, const void *chunk, size_t size, GError **error) { struct pipe_output *pd = (struct pipe_output *)ao; size_t ret; ret = fwrite(chunk, 1, size, pd->fh); if (ret == 0) g_set_error(error, pipe_output_quark(), errno, "Write error on pipe: %s", g_strerror(errno)); return ret; }
static bool pipe_output_open(void *data, G_GNUC_UNUSED struct audio_format *audio_format, G_GNUC_UNUSED GError **error) { struct pipe_output *pd = data; pd->fh = popen(pd->cmd, "w"); if (pd->fh == NULL) { g_set_error(error, pipe_output_quark(), errno, "Error opening pipe \"%s\": %s", pd->cmd, g_strerror(errno)); return false; } return true; }
static void * pipe_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, const struct config_param *param, GError **error) { struct pipe_output *pd = g_new(struct pipe_output, 1); pd->cmd = config_dup_block_string(param, "command", NULL); if (pd->cmd == NULL) { g_set_error(error, pipe_output_quark(), 0, "No \"command\" parameter specified"); return NULL; } return pd; }
static struct audio_output * pipe_output_init(const struct config_param *param, GError **error) { struct pipe_output *pd = g_new(struct pipe_output, 1); if (!ao_base_init(&pd->base, &pipe_output_plugin, param, error)) { g_free(pd); return NULL; } pd->cmd = config_dup_block_string(param, "command", NULL); if (pd->cmd == NULL) { g_set_error(error, pipe_output_quark(), 0, "No \"command\" parameter specified"); return NULL; } return &pd->base; }