/* * List resolutions for device and format */ static void v4l2_resolution_list(int dev, uint_fast32_t pixelformat, obs_property_t *prop) { struct v4l2_frmsizeenum frmsize; frmsize.pixel_format = pixelformat; frmsize.index = 0; struct dstr buffer; dstr_init(&buffer); obs_property_list_clear(prop); obs_property_list_add_int(prop, obs_module_text("LeaveUnchanged"), -1); v4l2_ioctl(dev, VIDIOC_ENUM_FRAMESIZES, &frmsize); switch(frmsize.type) { case V4L2_FRMSIZE_TYPE_DISCRETE: while (v4l2_ioctl(dev, VIDIOC_ENUM_FRAMESIZES, &frmsize) == 0) { dstr_printf(&buffer, "%dx%d", frmsize.discrete.width, frmsize.discrete.height); obs_property_list_add_int(prop, buffer.array, v4l2_pack_tuple(frmsize.discrete.width, frmsize.discrete.height)); frmsize.index++; } break; default: blog(LOG_INFO, "Stepwise and Continuous framesizes " "are currently hardcoded"); for (const int *packed = v4l2_framesizes; *packed; ++packed) { int width; int height; v4l2_unpack_tuple(&width, &height, *packed); dstr_printf(&buffer, "%dx%d", width, height); obs_property_list_add_int(prop, buffer.array, *packed); } break; } dstr_free(&buffer); }
static void add_audio_encoder_params(struct dstr *cmd, obs_encoder_t *aencoder) { obs_data_t *settings = obs_encoder_get_settings(aencoder); int bitrate = (int)obs_data_get_int(settings, "bitrate"); audio_t *audio = obs_get_audio(); struct dstr name = {0}; obs_data_release(settings); dstr_copy(&name, obs_encoder_get_name(aencoder)); dstr_replace(&name, "\"", "\"\""); dstr_catf(cmd, "\"%s\" %d %d %d ", name.array, bitrate, (int)obs_encoder_get_sample_rate(aencoder), (int)audio_output_get_channels(audio)); dstr_free(&name); }
void *os_dlopen(const char *path) { struct dstr dll_name; wchar_t *wpath; HMODULE h_library = NULL; dstr_init_copy(&dll_name, path); dstr_cat(&dll_name, ".dll"); os_utf8_to_wcs(dll_name.array, 0, &wpath); h_library = LoadLibraryW(wpath); bfree(wpath); dstr_free(&dll_name); if (!h_library) blog(LOG_INFO, "LoadLibrary failed for '%s', error: %u", path, GetLastError()); return h_library; }
/* unwraps a structure that's used for input/output */ static void gl_unwrap_storage_struct(struct gl_shader_parser *glsp, struct shader_struct *st, const char *name, bool input, const char *prefix) { struct dstr prefix_str; size_t i; dstr_init(&prefix_str); if (prefix) dstr_copy(&prefix_str, prefix); dstr_cat(&prefix_str, name); dstr_cat(&prefix_str, "_"); for (i = 0; i < st->vars.num; i++) { struct shader_var *st_var = st->vars.array+i; gl_write_storage_var(glsp, st_var, input, prefix_str.array); } dstr_free(&prefix_str); }
static void cf_addew(struct cf_preprocessor *pp, const struct cf_token *token, const char *message, int error_level, const char *val1, const char *val2, const char *val3) { uint32_t row, col; cf_gettokenoffset(pp, token, &row, &col); if (!val1 && !val2 && !val3) { error_data_add(pp->ed, token->lex->file, row, col, message, error_level); } else { struct dstr formatted; dstr_init(&formatted); dstr_safe_printf(&formatted, message, val1, val2, val3, NULL); error_data_add(pp->ed, token->lex->file, row, col, formatted.array, error_level); dstr_free(&formatted); } }
void dstr_vcatf(struct dstr *dst, const char *format, va_list args) { va_list args_cp; va_copy(args_cp, args); int len = vsnprintf(NULL, 0, format, args_cp); va_end(args_cp); if (len < 0) len = 4095; dstr_ensure_capacity(dst, dst->len + ((size_t)len) + 1); len = vsnprintf(dst->array + dst->len, ((size_t)len) + 1, format, args); if (!*dst->array) { dstr_free(dst); return; } dst->len += len < 0 ? strlen(dst->array + dst->len) : (size_t)len; }
static void text_node_destroy(struct text_node *node) { struct text_node *subnode; if (!node) return; subnode = node->first_subnode; while (subnode) { struct text_node *destroy_node = subnode; subnode = subnode->next; text_node_destroy(destroy_node); } dstr_free(&node->str); if (node->leaf) text_leaf_destroy(node->leaf); bfree(node); }
static void obs_source_destroy(obs_source_t source) { size_t i; obs_source_dosignal(source, "source-destroy"); if (source->filter_parent) obs_source_filter_remove(source->filter_parent, source); for (i = 0; i < source->filters.num; i++) obs_source_release(source->filters.array[i]); for (i = 0; i < source->audio_wait_buffer.num; i++) audiobuf_free(source->audio_wait_buffer.array+i); for (i = 0; i < source->video_frames.num; i++) source_frame_destroy(source->video_frames.array[i]); gs_entercontext(obs->video.graphics); texture_destroy(source->output_texture); gs_leavecontext(); if (source->data) source->callbacks.destroy(source->data); bfree(source->audio_data.data); audio_line_destroy(source->audio_line); audio_resampler_destroy(source->resampler); proc_handler_destroy(source->procs); signal_handler_destroy(source->signals); da_free(source->video_frames); da_free(source->audio_wait_buffer); da_free(source->filters); pthread_mutex_destroy(&source->filter_mutex); pthread_mutex_destroy(&source->audio_mutex); pthread_mutex_destroy(&source->video_mutex); dstr_free(&source->settings); bfree(source->name); bfree(source); }
static void ep_makeshaderstring(struct effect_parser *ep, struct dstr *shader, struct darray *shader_call, struct darray *used_params) { struct cf_token *token = shader_call->array; struct cf_token *func_name; struct ep_func *func; struct dstr call_str; dstr_init(&call_str); while (token->type != CFTOKEN_NONE && is_whitespace(*token->str.array)) token++; if (token->type == CFTOKEN_NONE || strref_cmp(&token->str, "NULL") == 0) return; func_name = token; while (token->type != CFTOKEN_NONE) { struct ep_param *param = ep_getparam_strref(ep, &token->str); if (param) ep_write_param(shader, param, used_params); dstr_cat_strref(&call_str, &token->str); token++; } func = ep_getfunc_strref(ep, &func_name->str); if (!func) return; ep_write_func(ep, shader, func, used_params); ep_write_main(ep, shader, func, &call_str); dstr_free(&call_str); ep_reset_written(ep); }
const char *os_get_path_extension(const char *path) { struct dstr temp; size_t pos = 0; char *period; char *slash; dstr_init_copy(&temp, path); dstr_replace(&temp, "\\", "/"); slash = strrchr(temp.array, '/'); period = strrchr(temp.array, '.'); if (period) pos = (size_t)(period - temp.array); dstr_free(&temp); if (!period || slash > period) return NULL; return path + pos; }
/* on windows, plugin files are located in [base directory]/plugins/[bit] */ char *find_plugin(const char *plugin) { struct dstr path; dstr_init(&path); #ifdef _WIN64 if (check_lib_path(plugin, "obs-plugins/64bit/", &path)) #else if (check_lib_path(plugin, "obs-plugins/32bit/", &path)) #endif return path.array; #ifdef _WIN64 if (check_lib_path(plugin, "../../obs-plugins/64bit/", &path)) #else if (check_lib_path(plugin, "../../obs-plugins/32bit/", &path)) #endif return path.array; dstr_free(&path); return NULL; }
static void rtmp_stream_destroy(void *data) { struct rtmp_stream *stream = data; if (stopping(stream) && !connecting(stream)) { pthread_join(stream->send_thread, NULL); } else if (connecting(stream) || active(stream)) { if (stream->connecting) pthread_join(stream->connect_thread, NULL); stream->stop_ts = 0; os_event_signal(stream->stop_event); if (active(stream)) { os_sem_post(stream->send_sem); obs_output_end_data_capture(stream->output); pthread_join(stream->send_thread, NULL); } } free_packets(stream); dstr_free(&stream->path); dstr_free(&stream->key); dstr_free(&stream->username); dstr_free(&stream->password); dstr_free(&stream->encoder_name); dstr_free(&stream->bind_ip); os_event_destroy(stream->stop_event); os_sem_destroy(stream->send_sem); pthread_mutex_destroy(&stream->packets_mutex); circlebuf_free(&stream->packets); #ifdef TEST_FRAMEDROPS circlebuf_free(&stream->droptest_info); #endif os_event_destroy(stream->buffer_space_available_event); os_event_destroy(stream->buffer_has_data_event); os_event_destroy(stream->socket_available_event); os_event_destroy(stream->send_thread_signaled_exit); pthread_mutex_destroy(&stream->write_buf_mutex); if (stream->write_buf) bfree(stream->write_buf); bfree(stream); }
static bool init_update(struct update_info *info) { struct dstr user_agent = {0}; info->curl = curl_easy_init(); if (!info->curl) { warn("Could not initialize Curl"); return false; } info->local_package = get_package(info->local, "package.json"); info->cache_package = get_package(info->cache, "package.json"); obs_data_t *metadata = get_package(info->cache, "meta.json"); if (metadata) { const char *etag = obs_data_get_string(metadata, "etag"); if (etag) { struct dstr if_none_match = { 0 }; dstr_copy(&if_none_match, "If-None-Match: "); dstr_cat(&if_none_match, etag); info->etag_local = bstrdup(etag); info->header = curl_slist_append(info->header, if_none_match.array); } obs_data_release(metadata); } dstr_copy(&user_agent, "User-Agent: "); dstr_cat(&user_agent, info->user_agent); info->header = curl_slist_append(info->header, user_agent.array); dstr_free(&user_agent); return true; }
static int ep_parse_sampler_state_item(struct effect_parser *ep, struct ep_sampler *eps) { int ret; char *state = NULL; struct dstr value = {0}; ret = cf_next_name(&ep->cfp, &state, "state name", ";"); if (ret != PARSE_SUCCESS) goto fail; ret = cf_next_token_should_be(&ep->cfp, "=", ";", NULL); if (ret != PARSE_SUCCESS) goto fail; for (;;) { const char *cur_str; if (!cf_next_valid_token(&ep->cfp)) return PARSE_EOF; cur_str = ep->cfp.cur_token->str.array; if (*cur_str == ';') break; dstr_ncat(&value, cur_str, ep->cfp.cur_token->str.len); } if (value.len) { da_push_back(eps->states, &state); da_push_back(eps->values, &value.array); } return ret; fail: bfree(state); dstr_free(&value); return ret; }
static void find_modules_in_path(struct obs_module_path *omp, obs_find_module_callback_t callback, void *param) { struct dstr search_path = {0}; char *module_start; bool search_directories = false; os_glob_t *gi; dstr_copy(&search_path, omp->bin); module_start = strstr(search_path.array, "%module%"); if (module_start) { dstr_resize(&search_path, module_start - search_path.array); search_directories = true; } if (!dstr_is_empty(&search_path) && dstr_end(&search_path) != '/') dstr_cat_ch(&search_path, '/'); dstr_cat_ch(&search_path, '*'); if (!search_directories) dstr_cat(&search_path, get_module_extension()); if (os_glob(search_path.array, 0, &gi) == 0) { for (size_t i = 0; i < gi->gl_pathc; i++) { if (search_directories == gi->gl_pathv[i].directory) process_found_module(omp, gi->gl_pathv[i].path, search_directories, callback, param); } os_globfree(gi); } dstr_free(&search_path); }
static void rtmp_stream_destroy(void *data) { struct rtmp_stream *stream = data; if (stopping(stream) && !connecting(stream)) { pthread_join(stream->send_thread, NULL); } else if (connecting(stream) || active(stream)) { if (stream->connecting) pthread_join(stream->connect_thread, NULL); stream->stop_ts = 0; os_event_signal(stream->stop_event); if (active(stream)) { os_sem_post(stream->send_sem); obs_output_end_data_capture(stream->output); pthread_join(stream->send_thread, NULL); } } if (stream) { free_packets(stream); dstr_free(&stream->path); dstr_free(&stream->key); dstr_free(&stream->username); dstr_free(&stream->password); dstr_free(&stream->encoder_name); dstr_free(&stream->bind_ip); os_event_destroy(stream->stop_event); os_sem_destroy(stream->send_sem); pthread_mutex_destroy(&stream->packets_mutex); circlebuf_free(&stream->packets); bfree(stream); } }
void obs_hotkeys_set_translations_s( struct obs_hotkeys_translations *translations, size_t size) { #define ADD_TRANSLATION(key_name, var_name) \ if (t.var_name) \ obs_set_key_translation(key_name, t.var_name); struct obs_hotkeys_translations t = {0}; struct dstr numpad = {0}; struct dstr mouse = {0}; struct dstr button = {0}; if (!translations) { return; } memcpy(&t, translations, (size < sizeof(t)) ? size : sizeof(t)); ADD_TRANSLATION(OBS_KEY_INSERT, insert); ADD_TRANSLATION(OBS_KEY_DELETE, del); ADD_TRANSLATION(OBS_KEY_HOME, home); ADD_TRANSLATION(OBS_KEY_END, end); ADD_TRANSLATION(OBS_KEY_PAGEUP, page_up); ADD_TRANSLATION(OBS_KEY_PAGEDOWN, page_down); ADD_TRANSLATION(OBS_KEY_NUMLOCK, num_lock); ADD_TRANSLATION(OBS_KEY_SCROLLLOCK, scroll_lock); ADD_TRANSLATION(OBS_KEY_CAPSLOCK, caps_lock); ADD_TRANSLATION(OBS_KEY_BACKSPACE, backspace); ADD_TRANSLATION(OBS_KEY_TAB, tab); ADD_TRANSLATION(OBS_KEY_PRINT, print); ADD_TRANSLATION(OBS_KEY_PAUSE, pause); ADD_TRANSLATION(OBS_KEY_SHIFT, shift); ADD_TRANSLATION(OBS_KEY_ALT, alt); ADD_TRANSLATION(OBS_KEY_CONTROL, control); ADD_TRANSLATION(OBS_KEY_META, meta); ADD_TRANSLATION(OBS_KEY_MENU, menu); ADD_TRANSLATION(OBS_KEY_SPACE, space); #ifdef __APPLE__ const char *numpad_str = t.apple_keypad_num; ADD_TRANSLATION(OBS_KEY_NUMSLASH, apple_keypad_divide); ADD_TRANSLATION(OBS_KEY_NUMASTERISK, apple_keypad_multiply); ADD_TRANSLATION(OBS_KEY_NUMMINUS, apple_keypad_minus); ADD_TRANSLATION(OBS_KEY_NUMPLUS, apple_keypad_plus); ADD_TRANSLATION(OBS_KEY_NUMPERIOD, apple_keypad_decimal); ADD_TRANSLATION(OBS_KEY_NUMEQUAL, apple_keypad_equal); #else const char *numpad_str = t.numpad_num; ADD_TRANSLATION(OBS_KEY_NUMSLASH, numpad_divide); ADD_TRANSLATION(OBS_KEY_NUMASTERISK, numpad_multiply); ADD_TRANSLATION(OBS_KEY_NUMMINUS, numpad_minus); ADD_TRANSLATION(OBS_KEY_NUMPLUS, numpad_plus); ADD_TRANSLATION(OBS_KEY_NUMPERIOD, numpad_decimal); #endif if (numpad_str) { dstr_copy(&numpad, numpad_str); dstr_depad(&numpad); if (dstr_find(&numpad, "%1") == NULL) { dstr_cat(&numpad, " %1"); } #define ADD_NUMPAD_NUM(idx) \ dstr_copy_dstr(&button, &numpad); \ dstr_replace(&button, "%1", #idx); \ obs_set_key_translation(OBS_KEY_NUM ## idx, button.array) ADD_NUMPAD_NUM(0); ADD_NUMPAD_NUM(1); ADD_NUMPAD_NUM(2); ADD_NUMPAD_NUM(3); ADD_NUMPAD_NUM(4); ADD_NUMPAD_NUM(5); ADD_NUMPAD_NUM(6); ADD_NUMPAD_NUM(7); ADD_NUMPAD_NUM(8); ADD_NUMPAD_NUM(9); } if (t.mouse_num) { dstr_copy(&mouse, t.mouse_num); dstr_depad(&mouse); if (dstr_find(&mouse, "%1") == NULL) { dstr_cat(&mouse, " %1"); } #define ADD_MOUSE_NUM(idx) \ dstr_copy_dstr(&button, &mouse); \ dstr_replace(&button, "%1", #idx); \ obs_set_key_translation(OBS_KEY_MOUSE ## idx, button.array) ADD_MOUSE_NUM(1); ADD_MOUSE_NUM(2); ADD_MOUSE_NUM(3); ADD_MOUSE_NUM(4); ADD_MOUSE_NUM(5); ADD_MOUSE_NUM(6); ADD_MOUSE_NUM(7); ADD_MOUSE_NUM(8); ADD_MOUSE_NUM(9); ADD_MOUSE_NUM(10); ADD_MOUSE_NUM(11); ADD_MOUSE_NUM(12); ADD_MOUSE_NUM(13); ADD_MOUSE_NUM(14); ADD_MOUSE_NUM(15); ADD_MOUSE_NUM(16); ADD_MOUSE_NUM(17); ADD_MOUSE_NUM(18); ADD_MOUSE_NUM(19); ADD_MOUSE_NUM(20); ADD_MOUSE_NUM(21); ADD_MOUSE_NUM(22); ADD_MOUSE_NUM(23); ADD_MOUSE_NUM(24); ADD_MOUSE_NUM(25); ADD_MOUSE_NUM(26); ADD_MOUSE_NUM(27); ADD_MOUSE_NUM(28); ADD_MOUSE_NUM(29); } dstr_free(&numpad); dstr_free(&mouse); dstr_free(&button); }
void process_quote(void *data) { Quote *quote; struct msg *msg; quote = (Quote *)data; if (quote->thyquote.m_nLen == sizeof (tHYQuote)) { dlist_iter_t iter; dlist_node_t node; int tlen; quote->thyquote.m_cJYS[sizeof quote->thyquote.m_cJYS - 1] = '\0'; quote->thyquote.m_cHYDM[sizeof quote->thyquote.m_cHYDM - 1] = '\0'; quote->m_nMSec = 0; /* in case of multiple monitors */ dlist_rwlock_rdlock(monitors); if (dlist_length(monitors) > 0) { char res[512]; snprintf(res, sizeof res, "RX '%d,%s,%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f," "%.2f,%.2f,%d,%.2f,%d,%d,%.2f,%d,%.2f,%d'\r\n", quote->thyquote.m_nTime, quote->thyquote.m_cHYDM, quote->thyquote.m_cJYS, quote->thyquote.m_dZXJ, quote->thyquote.m_dJKP, quote->thyquote.m_dZGJ, quote->thyquote.m_dZDJ, quote->thyquote.m_dZSP, quote->thyquote.m_dJSP, quote->thyquote.m_dZJSJ, quote->thyquote.m_dJJSJ, quote->thyquote.m_nCJSL, quote->thyquote.m_dCJJE, quote->thyquote.m_nZCCL, quote->thyquote.m_nCCL, quote->thyquote.m_dMRJG1, quote->thyquote.m_nMRSL1, quote->thyquote.m_dMCJG1, quote->thyquote.m_nMCSL1); iter = dlist_iter_new(monitors, DLIST_START_HEAD); while ((node = dlist_next(iter))) { client c = (client)dlist_node_value(node); pthread_spin_lock(&c->lock); if (!(c->flags & CLIENT_CLOSE_ASAP)) { if (net_try_write(c->fd, res, strlen(res), 10, NET_NONBLOCK) == -1) { xcb_log(XCB_LOG_WARNING, "Writing to client '%p': %s", c, strerror(errno)); if (++c->eagcount >= 3) client_free_async(c); } else if (c->eagcount) c->eagcount = 0; } pthread_spin_unlock(&c->lock); } dlist_iter_free(&iter); } dlist_rwlock_unlock(monitors); /* FIXME */ if (quote->thyquote.m_nTime == 999999999) { FREE(data); return; /* idiosyncrasy of different timestamps */ } else if ((tlen = intlen(quote->thyquote.m_nTime)) < 10) { int hour; struct tm lt; hour = quote->thyquote.m_nTime / 10000000; if (tv.tv_sec == 0 || hour == 9 || hour == 21) gettimeofday(&tv, NULL); if (prev_hour == 23 && hour == 0) tv.tv_sec += 24 * 60 * 60; prev_hour = hour; localtime_r(&tv.tv_sec, <); if (quote->thyquote.m_cHYDM[0] == 'S' && quote->thyquote.m_cHYDM[1] == 'P') quote->thyquote.m_nTime *= 1000; else if (tlen == 6 || tlen == 7) quote->thyquote.m_nTime *= 100; lt.tm_sec = quote->thyquote.m_nTime % 100000 / 1000; lt.tm_min = quote->thyquote.m_nTime % 10000000 / 100000; lt.tm_hour = hour; quote->m_nMSec = quote->thyquote.m_nTime % 1000; quote->thyquote.m_nTime = mktime(<); } /* FIXME: no millisecond field in some exchanges' quotes */ if (addms) { struct timeval tv; dstr contract = dstr_new(quote->thyquote.m_cHYDM); struct sms *sms; gettimeofday(&tv, NULL); if ((sms = table_get_value(times, contract)) == NULL) { if (NEW(sms)) { sms->qsec = quote->thyquote.m_nTime; sms->sec = tv.tv_sec; sms->msec = tv.tv_usec / 1000; table_insert(times, contract, sms); } } else if (sms->qsec != quote->thyquote.m_nTime) { sms->qsec = quote->thyquote.m_nTime; sms->sec = tv.tv_sec; sms->msec = tv.tv_usec / 1000; dstr_free(contract); } else { int32_t offset; if ((offset = (tv.tv_sec - sms->sec) * 1000 + tv.tv_usec / 1000 - sms->msec) > 999) offset = 999; quote->m_nMSec = offset; dstr_free(contract); } } if (get_logger_level() == __LOG_DEBUG) { time_t t = (time_t)quote->thyquote.m_nTime; char datestr[64]; strftime(datestr, sizeof datestr, "%F %T", localtime(&t)); xcb_log(XCB_LOG_DEBUG, "%s.%03d,%s,%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f," "%d,%.2f,%d,%d,%.2f,%d,%.2f,%d", datestr, quote->m_nMSec, quote->thyquote.m_cHYDM, quote->thyquote.m_cJYS, quote->thyquote.m_dZXJ, quote->thyquote.m_dJKP, quote->thyquote.m_dZGJ, quote->thyquote.m_dZDJ, quote->thyquote.m_dZSP, quote->thyquote.m_dJSP, quote->thyquote.m_dZJSJ, quote->thyquote.m_dJJSJ, quote->thyquote.m_nCJSL, quote->thyquote.m_dCJJE, quote->thyquote.m_nZCCL, quote->thyquote.m_nCCL, quote->thyquote.m_dMRJG1, quote->thyquote.m_nMRSL1, quote->thyquote.m_dMCJG1, quote->thyquote.m_nMCSL1); } } else xcb_log(XCB_LOG_DEBUG, "Data '%s' received", data); if (NEW0(msg) == NULL) { FREE(data); return; } msg->data = data; msg->refcount = 1; thrpool_queue(tp, send_quote, msg, NULL, msgfree, NULL); }
/* FIXME */ static void kfree(const void *key) { dstr_free((dstr)key); }
static void read_quote(event_loop el, int fd, int mask, void *data) { char *buf; struct sockaddr_in si; socklen_t slen = sizeof si; int nread; NOT_USED(el); NOT_USED(mask); NOT_USED(data); if ((buf = CALLOC(1, sizeof (Quote))) == NULL) return; /* FIXME */ if ((nread = recvfrom(fd, buf, sizeof (Quote), 0, (struct sockaddr *)&si, &slen)) > 0) { Quote *quote; struct msg *msg; quote = (Quote *)buf; if (quote->thyquote.m_nLen == sizeof (THYQuote)) { int tlen; quote->thyquote.m_cJYS[sizeof quote->thyquote.m_cJYS - 1] = '\0'; quote->thyquote.m_cHYDM[sizeof quote->thyquote.m_cHYDM - 1] = '\0'; quote->m_nMSec = 0; /* for testing */ dlist_rwlock_rdlock(monitors); if (dlist_length(monitors) > 0) { char res[512]; dlist_iter_t iter = dlist_iter_new(monitors, DLIST_START_HEAD); dlist_node_t node; snprintf(res, sizeof res, "RX '%d,%s,%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f," "%.2f,%.2f,%d,%.2f,%d,%d,%.2f,%d,%.2f,%d'\r\n", quote->thyquote.m_nTime, quote->thyquote.m_cHYDM, quote->thyquote.m_cJYS, quote->thyquote.m_dZXJ, quote->thyquote.m_dJKP, quote->thyquote.m_dZGJ, quote->thyquote.m_dZDJ, quote->thyquote.m_dZSP, quote->thyquote.m_dJSP, quote->thyquote.m_dZJSJ, quote->thyquote.m_dJJSJ, quote->thyquote.m_nCJSL, quote->thyquote.m_dCJJE, quote->thyquote.m_nZCCL, quote->thyquote.m_nCCL, quote->thyquote.m_dMRJG1, quote->thyquote.m_nMRSL1, quote->thyquote.m_dMCJG1, quote->thyquote.m_nMCSL1); while ((node = dlist_next(iter))) { client c = (client)dlist_node_value(node); pthread_spin_lock(&c->lock); if (c->flags & CLIENT_CLOSE_ASAP) { pthread_spin_unlock(&c->lock); continue; } if (net_try_write(c->fd, res, strlen(res), 10, NET_NONBLOCK) == -1) { xcb_log(XCB_LOG_WARNING, "Writing to client '%p': %s", c, strerror(errno)); if (++c->eagcount >= 10) client_free_async(c); } else if (c->eagcount) c->eagcount = 0; pthread_spin_unlock(&c->lock); } dlist_iter_free(&iter); } dlist_rwlock_unlock(monitors); /* FIXME */ if (quote->thyquote.m_nTime == 999999999) { FREE(buf); return; } else if ((tlen = intlen(quote->thyquote.m_nTime)) < 10) { struct timeval tv; struct tm lt; gettimeofday(&tv, NULL); localtime_r(&tv.tv_sec, <); if (quote->thyquote.m_cHYDM[0] == 'S' && quote->thyquote.m_cHYDM[1] == 'P') quote->thyquote.m_nTime *= 1000; else if (tlen == 6 || tlen == 7) quote->thyquote.m_nTime *= 100; lt.tm_hour = quote->thyquote.m_nTime / 10000000; lt.tm_min = quote->thyquote.m_nTime % 10000000 / 100000; lt.tm_sec = quote->thyquote.m_nTime % 100000 / 1000; quote->m_nMSec = quote->thyquote.m_nTime % 1000; quote->thyquote.m_nTime = mktime(<); } /* FIXME */ if (addms) { struct timeval tv; dstr contract = dstr_new(quote->thyquote.m_cHYDM); struct sms *sms; gettimeofday(&tv, NULL); if ((sms = table_get_value(times, contract)) == NULL) { if (NEW(sms)) { sms->qsec = quote->thyquote.m_nTime; sms->sec = tv.tv_sec; sms->msec = tv.tv_usec / 1000; table_insert(times, contract, sms); } } else if (sms->qsec != quote->thyquote.m_nTime) { sms->qsec = quote->thyquote.m_nTime; sms->sec = tv.tv_sec; sms->msec = tv.tv_usec / 1000; dstr_free(contract); } else { int32_t offset; if ((offset = (tv.tv_sec - sms->sec) * 1000 + tv.tv_usec / 1000 - sms->msec) > 999) offset = 999; quote->m_nMSec = offset; dstr_free(contract); } } } if (NEW0(msg) == NULL) { FREE(buf); return; } msg->data = buf; msg->refcount = 1; thrpool_queue(tp, send_quote, msg, NULL, msgfree, NULL); } else FREE(buf); }
static obs_properties_t *ffmpeg_source_getproperties(void *data) { struct dstr filter = {0}; UNUSED_PARAMETER(data); obs_properties_t *props = obs_properties_create(); obs_properties_set_flags(props, OBS_PROPERTIES_DEFER_UPDATE); obs_property_t *prop; // use this when obs allows non-readonly paths prop = obs_properties_add_bool(props, "is_local_file", obs_module_text("LocalFile")); obs_property_set_modified_callback(prop, is_local_file_modified); dstr_copy(&filter, obs_module_text("MediaFileFilter.AllMediaFiles")); dstr_cat(&filter, media_filter); dstr_cat(&filter, obs_module_text("MediaFileFilter.VideoFiles")); dstr_cat(&filter, video_filter); dstr_cat(&filter, obs_module_text("MediaFileFilter.AudioFiles")); dstr_cat(&filter, audio_filter); dstr_cat(&filter, obs_module_text("MediaFileFilter.AllFiles")); dstr_cat(&filter, " (*.*)"); obs_properties_add_path(props, "local_file", obs_module_text("LocalFile"), OBS_PATH_FILE, filter.array, NULL); dstr_free(&filter); obs_properties_add_bool(props, "looping", obs_module_text("Looping")); obs_properties_add_bool(props, "restart_on_activate", obs_module_text("RestartWhenActivated")); obs_properties_add_text(props, "input", obs_module_text("Input"), OBS_TEXT_DEFAULT); obs_properties_add_text(props, "input_format", obs_module_text("InputFormat"), OBS_TEXT_DEFAULT); obs_properties_add_bool(props, "hw_decode", obs_module_text("HardwareDecode")); obs_properties_add_bool(props, "clear_on_media_end", obs_module_text("ClearOnMediaEnd")); prop = obs_properties_add_bool(props, "advanced", obs_module_text("Advanced")); obs_property_set_modified_callback(prop, is_advanced_modified); obs_properties_add_bool(props, "force_scale", obs_module_text("ForceFormat")); prop = obs_properties_add_int(props, "audio_buffer_size", obs_module_text("AudioBufferSize"), 1, 9999, 1); obs_property_set_visible(prop, false); prop = obs_properties_add_int(props, "video_buffer_size", obs_module_text("VideoBufferSize"), 1, 9999, 1); obs_property_set_visible(prop, false); prop = obs_properties_add_list(props, "frame_drop", obs_module_text("FrameDropping"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_list_add_int(prop, obs_module_text("DiscardNone"), AVDISCARD_NONE); obs_property_list_add_int(prop, obs_module_text("DiscardDefault"), AVDISCARD_DEFAULT); obs_property_list_add_int(prop, obs_module_text("DiscardNonRef"), AVDISCARD_NONREF); obs_property_list_add_int(prop, obs_module_text("DiscardBiDir"), AVDISCARD_BIDIR); #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 67, 100) obs_property_list_add_int(prop, obs_module_text("DiscardNonIntra"), AVDISCARD_NONINTRA); #endif obs_property_list_add_int(prop, obs_module_text("DiscardNonKey"), AVDISCARD_NONKEY); obs_property_list_add_int(prop, obs_module_text("DiscardAll"), AVDISCARD_ALL); obs_property_set_visible(prop, false); return props; }
dstr *dstr_split_args(const char *line, int *argc) { const char *p = line; dstr current = NULL; dstr *argv = NULL; *argc = 0; for (;;) { while (*p && isspace(*p)) ++p; if (*p) { int inq = 0; /* 1 if in quotes */ int insq = 0; /* 1 if in single quotes */ int done = 0; if (current == NULL) current = dstr_new_len("", 0); while (!done) { /* FIXME */ if (inq) { if (*p == '\\' && *(p + 1) == 'x' && is_hex_digit(*(p + 2)) && is_hex_digit(*(p + 3))) { unsigned char byte = 16 * hex_digit_to_int(*(p + 2)) + hex_digit_to_int(*(p + 3)); p += 3; current = dstr_cat_len(current, (char *)&byte, 1); } else if (*p == '\\' && *(p + 1)) { char c; ++p; switch (*p) { case 'a': c = '\a'; break; case 'b': c = '\b'; break; case 'n': c = '\n'; break; case 'r': c = '\r'; break; case 't': c = '\t'; break; default: c = *p; break; } current = dstr_cat_len(current, &c, 1); } else if (*p == '"') { /* closing quote must be followed by a space or not at all */ if (*(p + 1) && !isspace(*(p + 1))) goto err; done = 1; /* unterminated quotes */ } else if (*p == '\0') goto err; else current = dstr_cat_len(current, p, 1); } else if (insq) { if (*p == '\\' && *(p + 1) == '\'') { ++p; current = dstr_cat_len(current, "'", 1); } else if (*p == '\'') { /* closing quote must be followed by a space or not at all */ if (*(p + 1) && !isspace(*(p + 1))) goto err; done = 1; /* unterminated quotes */ } else if (*p == '\0') goto err; else current = dstr_cat_len(current, p, 1); } else switch (*p) { case ' ': case '\0': case '\n': case '\r': case '\t': done = 1; break; case '"': inq = 1; break; case '\'': insq = 1; break; default: current = dstr_cat_len(current, p, 1); break; } if (*p) ++p; } if (RESIZE(argv, (*argc + 1) * sizeof (char *)) == NULL) goto err; argv[*argc] = current; ++*argc; current = NULL; } else return argv; } err: { int i; for (i = 0; i < *argc; ++i) dstr_free(argv[i]); FREE(argv); if (current) dstr_free(current); return NULL; } }
static obs_properties_t *ffmpeg_source_getproperties(void *data) { struct ffmpeg_source *s = data; struct dstr filter = {0}; struct dstr path = {0}; UNUSED_PARAMETER(data); obs_properties_t *props = obs_properties_create(); obs_properties_set_flags(props, OBS_PROPERTIES_DEFER_UPDATE); obs_property_t *prop; // use this when obs allows non-readonly paths prop = obs_properties_add_bool(props, "is_local_file", obs_module_text("LocalFile")); obs_property_set_modified_callback(prop, is_local_file_modified); dstr_copy(&filter, obs_module_text("MediaFileFilter.AllMediaFiles")); dstr_cat(&filter, media_filter); dstr_cat(&filter, obs_module_text("MediaFileFilter.VideoFiles")); dstr_cat(&filter, video_filter); dstr_cat(&filter, obs_module_text("MediaFileFilter.AudioFiles")); dstr_cat(&filter, audio_filter); dstr_cat(&filter, obs_module_text("MediaFileFilter.AllFiles")); dstr_cat(&filter, " (*.*)"); if (s && s->input && *s->input) { const char *slash; dstr_copy(&path, s->input); dstr_replace(&path, "\\", "/"); slash = strrchr(path.array, '/'); if (slash) dstr_resize(&path, slash - path.array + 1); } obs_properties_add_path(props, "local_file", obs_module_text("LocalFile"), OBS_PATH_FILE, filter.array, path.array); dstr_free(&filter); dstr_free(&path); prop = obs_properties_add_bool(props, "looping", obs_module_text("Looping")); obs_properties_add_bool(props, "restart_on_activate", obs_module_text("RestartWhenActivated")); obs_properties_add_text(props, "input", obs_module_text("Input"), OBS_TEXT_DEFAULT); obs_properties_add_text(props, "input_format", obs_module_text("InputFormat"), OBS_TEXT_DEFAULT); #ifndef __APPLE__ obs_properties_add_bool(props, "hw_decode", obs_module_text("HardwareDecode")); #endif obs_properties_add_bool(props, "clear_on_media_end", obs_module_text("ClearOnMediaEnd")); prop = obs_properties_add_bool(props, "close_when_inactive", obs_module_text("CloseFileWhenInactive")); obs_property_set_long_description(prop, obs_module_text("CloseFileWhenInactive.ToolTip")); prop = obs_properties_add_list(props, "color_range", obs_module_text("ColorRange"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_list_add_int(prop, obs_module_text("ColorRange.Auto"), VIDEO_RANGE_DEFAULT); obs_property_list_add_int(prop, obs_module_text("ColorRange.Partial"), VIDEO_RANGE_PARTIAL); obs_property_list_add_int(prop, obs_module_text("ColorRange.Full"), VIDEO_RANGE_FULL); return props; }
void dstr_from_mbs(struct dstr *dst, const char *mbstr) { dstr_free(dst); dst->len = os_mbs_to_utf8_ptr(mbstr, 0, &dst->array); }
static inline void device_item_free(struct device_item *item) { dstr_free(&item->name); dstr_free(&item->value); }
static inline bool ep_compile_pass_shader(struct effect_parser *ep, struct gs_effect_technique *tech, struct gs_effect_pass *pass, struct ep_pass *pass_in, size_t pass_idx, enum gs_shader_type type) { struct dstr shader_str; struct dstr location; struct darray used_params; /* struct dstr */ struct darray *pass_params = NULL; /* struct pass_shaderparam */ gs_shader_t *shader = NULL; bool success = true; dstr_init(&shader_str); darray_init(&used_params); dstr_init(&location); dstr_copy(&location, ep->cfp.lex.file); if (type == GS_SHADER_VERTEX) dstr_cat(&location, " (Vertex "); else if (type == GS_SHADER_PIXEL) dstr_cat(&location, " (Pixel "); /*else if (type == SHADER_GEOMETRY) dstr_cat(&location, " (Geometry ");*/ assert(pass_idx <= UINT_MAX); dstr_catf(&location, "shader, technique %s, pass %u)", tech->name, (unsigned)pass_idx); if (type == GS_SHADER_VERTEX) { ep_makeshaderstring(ep, &shader_str, &pass_in->vertex_program.da, &used_params); pass->vertshader = gs_vertexshader_create(shader_str.array, location.array, NULL); shader = pass->vertshader; pass_params = &pass->vertshader_params.da; } else if (type == GS_SHADER_PIXEL) { ep_makeshaderstring(ep, &shader_str, &pass_in->fragment_program.da, &used_params); pass->pixelshader = gs_pixelshader_create(shader_str.array, location.array, NULL); shader = pass->pixelshader; pass_params = &pass->pixelshader_params.da; } #if 0 blog(LOG_DEBUG, "+++++++++++++++++++++++++++++++++++"); blog(LOG_DEBUG, " %s", location.array); blog(LOG_DEBUG, "-----------------------------------"); blog(LOG_DEBUG, "%s", shader_str.array); blog(LOG_DEBUG, "+++++++++++++++++++++++++++++++++++"); #endif if (shader) success = ep_compile_pass_shaderparams(ep, pass_params, &used_params, shader); else success = false; dstr_free(&location); dstr_array_free(used_params.array, used_params.num); darray_free(&used_params); dstr_free(&shader_str); return success; }
static int server_cron(event_loop el, unsigned long id, void *data) { dlist_iter_t iter; dlist_node_t node; NOT_USED(el); NOT_USED(id); NOT_USED(data); if (log_reload) { close_logger(); if (init_logger("/var/log/xcb/xcb-dp2.log", __LOG_DEBUG) == 0) { const char *tmp; pthread_mutex_lock(&cfg_lock); if ((tmp = variable_retrieve(cfg, "general", "log_level"))) { if (!strcasecmp(tmp, "debug")) set_logger_level(__LOG_DEBUG); else if (!strcasecmp(tmp, "info")) set_logger_level(__LOG_INFO); else if (!strcasecmp(tmp, "notice")) set_logger_level(__LOG_NOTICE); else if (!strcasecmp(tmp, "warning")) set_logger_level(__LOG_WARNING); } pthread_mutex_unlock(&cfg_lock); log_reload = 0; } /* FIXME */ if (addms) table_clear(times); } if (shut_down) { if (prepare_for_shutdown() == 0) exit(0); xcb_log(XCB_LOG_WARNING, "SIGTERM received, but errors trying to shutdown the server"); } /* FIXME */ iter = dlist_iter_new(clients_to_close, DLIST_START_HEAD); while ((node = dlist_next(iter))) { client c = (client)dlist_node_value(node); if (c->refcount == 0) client_free(c); } dlist_iter_free(&iter); /* FIXME */ if (cronloops % 200 == 0) { char meme[] = "SU OT GNOLEB ERA ESAB RUOY LLA"; int status; /* heartbeat */ dlist_lock(clients); if (dlist_length(clients) > 0) { dstr res = dstr_new("HEARTBEAT|"); dstr ip = getipv4(); res = dstr_cat(res, ip); res = dstr_cat(res, "\r\n"); iter = dlist_iter_new(clients, DLIST_START_HEAD); while ((node = dlist_next(iter))) { client c = (client)dlist_node_value(node); pthread_spin_lock(&c->lock); if (net_try_write(c->fd, res, dstr_length(res), 100, NET_NONBLOCK) == -1) xcb_log(XCB_LOG_WARNING, "Writing to client '%p': %s", c, strerror(errno)); pthread_spin_unlock(&c->lock); } dlist_iter_free(&iter); dstr_free(ip); dstr_free(res); } dlist_unlock(clients); /* FIXME: trying to lower the high CPU load while idle */ if ((status = pgm_send(pgm_sender, meme, sizeof meme, NULL)) != PGM_IO_STATUS_NORMAL) xcb_log(XCB_LOG_WARNING, "Communication test failed"); } ++cronloops; return 100; }
/** * The x server was changed */ static bool xshm_server_changed(obs_properties_t *props, obs_property_t *p, obs_data_t *settings) { UNUSED_PARAMETER(p); bool advanced = obs_data_get_bool(settings, "advanced"); int_fast32_t old_screen = obs_data_get_int(settings, "screen"); const char *server = obs_data_get_string(settings, "server"); obs_property_t *screens = obs_properties_get(props, "screen"); /* we want a real NULL here in case there is no string here */ server = (advanced && *server) ? server : NULL; obs_property_list_clear(screens); xcb_connection_t *xcb = xcb_connect(server, NULL); if (!xcb || xcb_connection_has_error(xcb)) { obs_property_set_enabled(screens, false); return true; } struct dstr screen_info; dstr_init(&screen_info); bool xinerama = xinerama_is_active(xcb); int_fast32_t count = (xinerama) ? xinerama_screen_count(xcb) : xcb_setup_roots_length(xcb_get_setup(xcb)); for (int_fast32_t i = 0; i < count; ++i) { int_fast32_t x, y, w, h; x = y = w = h = 0; if (xinerama) xinerama_screen_geo(xcb, i, &x, &y, &w, &h); else x11_screen_geo(xcb, i, &w, &h); dstr_printf(&screen_info, "Screen %"PRIuFAST32" (%"PRIuFAST32 "x%"PRIuFAST32" @ %"PRIuFAST32 ",%"PRIuFAST32")", i, w, h, x, y); obs_property_list_add_int(screens, screen_info.array, i); } /* handle missing screen */ if (old_screen + 1 > count) { dstr_printf(&screen_info, "Screen %"PRIuFAST32" (not found)", old_screen); size_t index = obs_property_list_add_int(screens, screen_info.array, old_screen); obs_property_list_item_disable(screens, index, true); } dstr_free(&screen_info); xcb_disconnect(xcb); obs_property_set_enabled(screens, true); return true; }
/* * List available devices */ static void v4l2_device_list(obs_property_t *prop, obs_data_t *settings) { DIR *dirp; struct dirent *dp; struct dstr device; bool cur_device_found; size_t cur_device_index; const char *cur_device_name; #ifdef __FreeBSD__ dirp = opendir("/dev"); #else dirp = opendir("/sys/class/video4linux"); #endif if (!dirp) return; cur_device_found = false; cur_device_name = obs_data_get_string(settings, "device_id"); obs_property_list_clear(prop); dstr_init_copy(&device, "/dev/"); while ((dp = readdir(dirp)) != NULL) { int fd; uint32_t caps; struct v4l2_capability video_cap; #ifdef __FreeBSD__ if (strstr(dp->d_name, "video") == NULL) continue; #endif if (dp->d_type == DT_DIR) continue; dstr_resize(&device, 5); dstr_cat(&device, dp->d_name); if ((fd = v4l2_open(device.array, O_RDWR | O_NONBLOCK)) == -1) { blog(LOG_INFO, "Unable to open %s", device.array); continue; } if (v4l2_ioctl(fd, VIDIOC_QUERYCAP, &video_cap) == -1) { blog(LOG_INFO, "Failed to query capabilities for %s", device.array); v4l2_close(fd); continue; } #ifndef V4L2_CAP_DEVICE_CAPS caps = video_cap.capabilities; #else /* ... since Linux 3.3 */ caps = (video_cap.capabilities & V4L2_CAP_DEVICE_CAPS) ? video_cap.device_caps : video_cap.capabilities; #endif if (!(caps & V4L2_CAP_VIDEO_CAPTURE)) { blog(LOG_INFO, "%s seems to not support video capture", device.array); v4l2_close(fd); continue; } obs_property_list_add_string(prop, (char *) video_cap.card, device.array); blog(LOG_INFO, "Found device '%s' at %s", video_cap.card, device.array); /* check if this is the currently used device */ if (cur_device_name && !strcmp(cur_device_name, device.array)) cur_device_found = true; v4l2_close(fd); } /* add currently selected device if not present, but disable it ... */ if (!cur_device_found && cur_device_name && strlen(cur_device_name)) { cur_device_index = obs_property_list_add_string(prop, cur_device_name, cur_device_name); obs_property_list_item_disable(prop, cur_device_index, true); } closedir(dirp); dstr_free(&device); }
int main(int argc, char **argv) { int opt, i = 1, fd, sock; struct stat sb; char *addr, *p, *q; char neterr[256]; int pfd[2]; /* FIXME */ ip = dstr_new("127.0.0.1"); port = 33330; while ((opt = getopt(argc, argv, "h:p:?")) != -1) switch (opt) { case 'h': dstr_free(ip); ip = dstr_new(optarg); i += 2; break; case 'p': port = atoi(optarg); i += 2; break; case '?': default: usage(); } if ((fd = open(argv[i], O_RDONLY)) == -1) { fprintf(stderr, "Error opening file: %s\n", strerror(errno)); exit(1); } fstat(fd, &sb); if ((addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) { fprintf(stderr, "Error mmaping file: %s\n", strerror(errno)); exit(1); } close(fd); if ((sock = net_udp_nonblock_connect(ip, port, neterr, sizeof neterr)) == -1) { fprintf(stderr, "Connecting %s:%d: %s\n", ip, port, neterr); exit(1); } if (pipe(pfd) != 0) { fprintf(stderr, "Error creating pipe: %s\n", strerror(errno)); exit(1); } p = addr; q = memchr(p, '\n', sb.st_size); while (q) { int len = PAGEALIGN(q - p + 1); char *line; if ((line = POSIXALIGN(sysconf(_SC_PAGESIZE), len))) { struct iovec iov; memset(line, '\0', len); strncpy(line, p, q - p); iov.iov_base = line; iov.iov_len = len; /* zero copy */ if (vmsplice(pfd[1], &iov, 1, SPLICE_F_GIFT) == -1) { fprintf(stderr, "Error vmsplicing: %s\n", strerror(errno)); exit(1); } again: if (splice(pfd[0], NULL, sock, NULL, len, SPLICE_F_MOVE) == -1) { if (errno == EAGAIN) goto again; else { fprintf(stderr, "Error splicing: %s\n", strerror(errno)); exit(1); } } FREE(line); } else fprintf(stderr, "Error allocating memory for line\n"); p = q + 1; q = memchr(p, '\n', sb.st_size - (q - addr)); } close(pfd[0]); close(pfd[1]); close(sock); munmap(addr, sb.st_size); return 0; }