inline static void debug_style(lua_State *L, const char *path, const char *key) { if (!IS_LOG_PRIORITY(log_ui_draw, LOG_PRIORITY_DEBUG)) { return; } lua_getglobal(L, "tostring"); lua_pushvalue(L, -2); lua_call(L, 1, 1); lua_getglobal(L, "tostring"); lua_pushvalue(L, 1); lua_call(L, 1, 1); LOG_DEBUG(log_ui_draw, "style: [%s] %s : %s = %s", lua_tostring(L, -1), path, key, lua_tostring(L, -2)); lua_pop(L, 2); }
static pid_t decode_alsa_fork(const char *device, const char *capture, unsigned int buffer_time, unsigned int period_count, unsigned int sample_size, u32_t flags) { char *path, b[10], p[10], f[10], s[10]; char *cmd[20]; pid_t pid; int i, idx = 0, ret; path = alloca(PATH_MAX); /* jive_alsa [-v] -d <device> -b <buffer_time> -p <period_count> -f <flags> */ cmd[idx++] = "jive_alsa"; if (IS_LOG_PRIORITY(log_audio_output, LOG_PRIORITY_DEBUG)) { cmd[idx++] = "-v"; } cmd[idx++] = "-d"; cmd[idx++] = (char *)device; if (capture) { cmd[idx++] = "-c"; cmd[idx++] = (char *)capture; } snprintf(b, sizeof(b), "%d", buffer_time); cmd[idx++] = "-b"; cmd[idx++] = b; snprintf(p, sizeof(p), "%d", period_count); cmd[idx++] = "-p"; cmd[idx++] = p; snprintf(s, sizeof(s), "%d", sample_size); cmd[idx++] = "-s"; cmd[idx++] = s; snprintf(f, sizeof(f), "%d", flags); cmd[idx++] = "-f"; cmd[idx++] = f; cmd[idx] = '\0'; if (IS_LOG_PRIORITY(log_audio_output, LOG_PRIORITY_DEBUG)) { path[0] = '\0'; for (i=0; i<idx; i++) { strncat(path, cmd[i], PATH_MAX); strncat(path, " ", PATH_MAX); } LOG_DEBUG(log_audio_output, "fork %s", path); } /* command path */ getcwd(path, PATH_MAX); strncat(path, "/jive_alsa", PATH_MAX); decode_audio_lock(); decode_audio->running = false; /* fork + exec */ pid = vfork(); if (pid < 0) { LOG_ERROR(log_audio_output, "fork failed %d", errno); return -1; } if (pid == 0) { /* child */ ret = execv(path, cmd); LOG_ERROR(log_audio_output, "execv failed %d", errno); _exit(-1); } /* wait for backend process to start */ while (1) { fifo_wait_timeout(&decode_audio->fifo, 500); if (decode_audio->running) { break; } if (waitpid(pid, NULL, WNOHANG) == pid) { decode_audio_unlock(); LOG_ERROR(log_audio_output, "%s failed to start", cmd[0]); return -1; } } decode_audio_unlock(); return pid; }