这篇教程C++ switch_mutex_init函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中switch_mutex_init函数的典型用法代码示例。如果您正苦于以下问题:C++ switch_mutex_init函数的具体用法?C++ switch_mutex_init怎么用?C++ switch_mutex_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了switch_mutex_init函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: spool_cdrstatic void spool_cdr(const char *path, const char *log_line){ cdr_fd_t *fd = NULL; char *log_line_lf = NULL; unsigned int bytes_in, bytes_out; int loops = 0; if (!(fd = switch_core_hash_find(globals.fd_hash, path))) { fd = switch_core_alloc(globals.pool, sizeof(*fd)); switch_assert(fd); memset(fd, 0, sizeof(*fd)); fd->fd = -1; switch_mutex_init(&fd->mutex, SWITCH_MUTEX_NESTED, globals.pool); fd->path = switch_core_strdup(globals.pool, path); switch_core_hash_insert(globals.fd_hash, path, fd); } if (end_of(log_line) != '/n') { log_line_lf = switch_mprintf("%s/n", log_line); } else { switch_strdup(log_line_lf, log_line); } assert(log_line_lf); switch_mutex_lock(fd->mutex); bytes_out = (unsigned) strlen(log_line_lf); if (fd->fd < 0) { do_reopen(fd); if (fd->fd < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s/n", path); goto end; } } if (fd->bytes + bytes_out > UINT_MAX) { do_rotate(fd); } while ((bytes_in = write(fd->fd, log_line_lf, bytes_out)) != bytes_out && ++loops < 10) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write error to file %s %d/%d/n", path, (int) bytes_in, (int) bytes_out); do_rotate(fd); switch_yield(250000); } if (bytes_in > 0) { fd->bytes += bytes_in; }end: switch_mutex_unlock(fd->mutex); switch_safe_free(log_line_lf);}
开发者ID:publicreading,项目名称:FreeSWITCH,代码行数:54,
示例2: switch_log_printfstatic dir_profile_t *load_profile(const char *profile_name){ dir_profile_t *profile = NULL; switch_xml_t x_profiles, x_profile, cfg, xml = NULL; switch_event_t *event = NULL; if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed/n", global_cf); return profile; } if (!(x_profiles = switch_xml_child(cfg, "profiles"))) { goto end; } if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile_name))) { switch_memory_pool_t *pool; int count; if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure/n"); goto end; } if (!(profile = switch_core_alloc(pool, sizeof(dir_profile_t)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure/n"); switch_core_destroy_memory_pool(&pool); goto end; } profile->pool = pool; profile_set_config(profile); /* Add the params to the event structure */ count = (int)switch_event_import_xml(switch_xml_child(x_profile, "param"), "name", "value", &event); if (switch_xml_config_parse_event(event, count, SWITCH_FALSE, profile->config) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to process configuration/n"); switch_core_destroy_memory_pool(&pool); goto end; } switch_thread_rwlock_create(&profile->rwlock, pool); profile->name = switch_core_strdup(pool, profile_name); switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, profile->pool); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s/n", profile->name); switch_core_hash_insert(globals.profile_hash, profile->name, profile); }end: switch_xml_free(xml); return profile;}
开发者ID:jasonbourneh0810,项目名称:FreeSWITCH,代码行数:54,
示例3: rayo_cpa_component_load/** * Load input CPA * @param module_interface * @param pool memory pool * @param config_file * @return SWITCH_STATUS_SUCCESS if successfully loaded */switch_status_t rayo_cpa_component_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool, const char *config_file){ rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "cpa", "set:"RAYO_EXT_NS":stop", stop_cpa_component); switch_event_bind("rayo_cpa_component", SWITCH_EVENT_CUSTOM, "rayo::cpa", on_rayo_cpa_detector_event, NULL); switch_event_bind("rayo_cpa_component", SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE, NULL, on_channel_hangup_complete_event, NULL); globals.pool = pool; switch_core_hash_init(&globals.subscribers); switch_mutex_init(&globals.subscribers_mutex, SWITCH_MUTEX_NESTED, pool); return rayo_cpa_detector_load(module_interface, pool, config_file);}
开发者ID:bodji,项目名称:freeswitch,代码行数:19,
示例4: bind_fetch_agentstatic switch_status_t bind_fetch_agent(switch_xml_section_t section, switch_xml_binding_t **binding) { switch_memory_pool_t *pool = NULL; ei_xml_agent_t *agent; /* create memory pool for this xml search binging (lives for duration of mod_kazoo runtime) */ if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory: They're not people; they're hippies!/n"); return SWITCH_STATUS_MEMERR; } /* allocate some memory to store the fetch bindings for this section */ if (!(agent = switch_core_alloc(pool, sizeof (*agent)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory: Oh, Jesus tap-dancing Christ!/n"); return SWITCH_STATUS_MEMERR; } /* try to bind to the switch */ if (switch_xml_bind_search_function_ret(fetch_handler, section, agent, binding) != SWITCH_STATUS_SUCCESS) { switch_core_destroy_memory_pool(&pool); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not bind to FreeSWITCH %s XML requests/n" ,xml_section_to_string(section)); return SWITCH_STATUS_GENERR; } agent->pool = pool; agent->section = section; switch_thread_rwlock_create(&agent->lock, pool); agent->clients = NULL; switch_mutex_init(&agent->current_client_mutex, SWITCH_MUTEX_DEFAULT, pool); agent->current_client = NULL; switch_mutex_init(&agent->replies_mutex, SWITCH_MUTEX_DEFAULT, pool); switch_thread_cond_create(&agent->new_reply, pool); agent->replies = NULL; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Bound to %s XML requests/n" ,xml_section_to_string(section)); return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:39,
示例5: eventpipe_events_loadint eventpipe_events_load(const char *modname, switch_memory_pool_t *pool) { memset(&globals, 0, sizeof(globals)); head = NULL; switch_mutex_init(&globals.eventpipe_call_list_mutex, SWITCH_MUTEX_NESTED, pool); if (switch_event_bind_removable(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, eventpipe_events_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!/n"); return SWITCH_STATUS_GENERR; } return SWITCH_STATUS_SUCCESS;}
开发者ID:tamiel,项目名称:mod_eventpipe,代码行数:13,
示例6: SavedCondition SavedCondition(switch_memory_pool_t *pool=NULL): _pool(pool), _can_delete_pool(false) { if(!_pool) { switch_core_new_memory_pool(&_pool); _can_delete_pool = true; } switch_thread_cond_create(&_condition, _pool); switch_mutex_init(&_mutex, SWITCH_MUTEX_DEFAULT, _pool); }
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:13,
示例7: load_configstatic switch_status_t load_config(void){ char *cf = "reference.conf"; switch_xml_t cfg, xml, settings, param; memset(&globals, 0, sizeof(globals)); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed/n", cf); return SWITCH_STATUS_TERM; } if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcmp(var, "debug")) { globals.debug = atoi(val); } else if (!strcmp(var, "port")) { globals.port = atoi(val); } else if (!strcmp(var, "ip")) { set_global_ip(val); } else if (!strcmp(var, "codec-master")) { if (!strcasecmp(val, "us")) { switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS); } } else if (!strcmp(var, "dialplan")) { set_global_dialplan(val); } else if (!strcmp(var, "codec-prefs")) { set_global_codec_string(val); globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS); } else if (!strcmp(var, "codec-rates")) { set_global_codec_rates_string(val); globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS); } } } if (!globals.dialplan) { set_global_dialplan("default"); } if (!globals.port) { globals.port = 4569; } switch_xml_free(xml); return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:51,
示例8: mongo_connection_pool_createswitch_status_t mongo_connection_pool_create(mongo_connection_pool_t **conn_pool, switch_size_t min_connections, switch_size_t max_connections, const char *conn_str){ switch_memory_pool_t *pool = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; mongo_connection_pool_t *cpool = NULL; DBClientBase *conn = NULL; if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) { return status; } if (!(cpool = (mongo_connection_pool_t *)switch_core_alloc(pool, sizeof(mongo_connection_pool_t)))) { switch_goto_status(SWITCH_STATUS_MEMERR, done); } if ((status = switch_mutex_init(&cpool->mutex, SWITCH_MUTEX_NESTED, pool)) != SWITCH_STATUS_SUCCESS) { goto done; } if ((status = switch_queue_create(&cpool->connections, max_connections, pool)) != SWITCH_STATUS_SUCCESS) { goto done; } cpool->min_connections = min_connections; cpool->max_connections = max_connections; cpool->conn_str = switch_core_strdup(pool, conn_str); cpool->pool = pool; for (cpool->size = 0; cpool->size < min_connections; cpool->size++) { if (mongo_connection_create(&conn, conn_str) == SWITCH_STATUS_SUCCESS) { mongo_connection_pool_put(cpool, conn); } else { break; } } done: if (status == SWITCH_STATUS_SUCCESS) { *conn_pool = cpool; } else { switch_core_destroy_memory_pool(&pool); } return status;}
开发者ID:moises-silva,项目名称:mod_conference-admin,代码行数:50,
示例9: rayo_output_component_load/** * Initialize output component * @param module_interface * @param pool memory pool to allocate from * @param config_file to use * @return SWITCH_STATUS_SUCCESS if successful */switch_status_t rayo_output_component_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool, const char *config_file){ switch_api_interface_t *api_interface; switch_file_interface_t *file_interface; rayo_actor_command_handler_add(RAT_CALL, "", "set:"RAYO_OUTPUT_NS":output", start_call_output_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "output", "set:"RAYO_EXT_NS":stop", stop_output_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":pause", pause_output_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":resume", resume_output_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":speed-up", speed_up_output_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":speed-down", speed_down_output_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":volume-up", volume_up_output_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":volume-down", volume_down_output_component); rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":seek", seek_output_component); rayo_actor_command_handler_add(RAT_MIXER, "", "set:"RAYO_OUTPUT_NS":output", start_mixer_output_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "output", "set:"RAYO_EXT_NS":stop", stop_output_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":pause", pause_output_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":resume", resume_output_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":speed-up", speed_up_output_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":speed-down", speed_down_output_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":volume-up", volume_up_output_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":volume-down", volume_down_output_component); rayo_actor_command_handler_add(RAT_MIXER_COMPONENT, "output", "set:"RAYO_OUTPUT_NS":seek", seek_output_component); file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE); file_interface->interface_name = "mod_rayo"; file_interface->extens = rayo_supported_formats; file_interface->file_open = rayo_file_open; file_interface->file_close = rayo_file_close; file_interface->file_read = rayo_file_read; file_interface->file_seek = rayo_file_seek; switch_mutex_init(&fileman_globals.mutex, SWITCH_MUTEX_NESTED, pool); switch_core_hash_init(&fileman_globals.hash); file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE); file_interface->interface_name = "mod_rayo"; file_interface->extens = fileman_supported_formats; file_interface->file_open = fileman_file_open; file_interface->file_close = fileman_file_close; file_interface->file_write = fileman_file_write; file_interface->file_read = fileman_file_read; file_interface->file_seek = fileman_file_seek; SWITCH_ADD_API(api_interface, "fileman", "Manage file audio", fileman_api, FILEMAN_SYNTAX); return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:56,
示例10: switch_core_new_memory_poolblacklist_t *blacklist_create(const char *name) { switch_memory_pool_t *pool = NULL; blacklist_t *bl = NULL; switch_core_new_memory_pool(&pool); bl = switch_core_alloc(pool, sizeof(*bl)); switch_assert(bl); bl->pool = pool; switch_core_hash_init(&bl->list); switch_mutex_init(&bl->list_mutex, SWITCH_MUTEX_NESTED, pool); return bl;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:15,
示例11: start_capturestatic switch_status_t start_capture(switch_core_session_t *session, unsigned int seconds, switch_media_bug_flag_t flags, const char *base){ switch_channel_t *channel = switch_core_session_get_channel(session); switch_media_bug_t *bug; switch_status_t status; switch_codec_implementation_t read_impl = { 0 }; struct cap_cb *cb; switch_size_t bytes; switch_bind_flag_t bind_flags = 0; if (switch_channel_get_private(channel, "snapshot")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Already Running./n"); return SWITCH_STATUS_FALSE; } if (seconds < 5) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Must be at least 5 seconds!/n"); return SWITCH_STATUS_FALSE; } switch_core_session_get_read_impl(session, &read_impl); if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_FALSE; } cb = switch_core_session_alloc(session, sizeof(*cb)); cb->base = switch_core_session_strdup(session, base); bytes = read_impl.samples_per_second * seconds * 2; switch_buffer_create_dynamic(&cb->buffer, bytes, bytes, bytes); switch_mutex_init(&cb->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); if ((status = switch_core_media_bug_add(session, "snapshot", NULL, capture_callback, cb, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) { return status; } bind_flags = SBF_DIAL_ALEG | SBF_EXEC_ALEG | SBF_EXEC_SAME; switch_ivr_bind_dtmf_meta_session(session, 7, bind_flags, "snapshot::snap"); switch_channel_set_private(channel, "snapshot", bug); return SWITCH_STATUS_SUCCESS;}
开发者ID:DrumTechnologiesLtd,项目名称:FreeSWITCH,代码行数:45,
示例12: modem_global_initswitch_status_t modem_global_init(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool){ memset(&globals, 0, sizeof(globals)); globals.pool = pool; globals.SOFT_MAX_MODEMS = spandsp_globals.modem_count; switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, pool); modem_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); modem_endpoint_interface->interface_name = "modem"; modem_endpoint_interface->io_routines = &channel_io_routines; modem_endpoint_interface->state_handler = &channel_event_handlers; activate_modems(); return SWITCH_STATUS_SUCCESS; }
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:19,
示例13: write_cdrstatic void write_cdr(const char *path, const char *log_line){ cdr_fd_t *fd = NULL; unsigned int bytes_in, bytes_out; if (!(fd = switch_core_hash_find(globals.fd_hash, path))) { fd = switch_core_alloc(globals.pool, sizeof(*fd)); switch_assert(fd); memset(fd, 0, sizeof(*fd)); fd->fd = -1; switch_mutex_init(&fd->mutex, SWITCH_MUTEX_NESTED, globals.pool); fd->path = switch_core_strdup(globals.pool, path); switch_core_hash_insert(globals.fd_hash, path, fd); } switch_mutex_lock(fd->mutex); bytes_out = (unsigned) strlen(log_line); if (fd->fd < 0) { do_reopen(fd); if (fd->fd < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s/n", path); goto end; } } if (fd->bytes + bytes_out > UINT_MAX) { do_rotate(fd); } if ((bytes_in = write(fd->fd, log_line, bytes_out)) != bytes_out) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write error to file %s %d/%d/n", path, (int) bytes_in, (int) bytes_out); } fd->bytes += bytes_in; end: switch_mutex_unlock(fd->mutex);}
开发者ID:gujun,项目名称:sscore,代码行数:40,
示例14: SWITCH_DECLARESWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool, switch_bool_t colorize){ switch_threadattr_t *thd_attr;; switch_assert(pool != NULL); LOG_POOL = pool; switch_threadattr_create(&thd_attr, LOG_POOL); switch_threadattr_detach_set(thd_attr, 1); switch_queue_create(&LOG_QUEUE, SWITCH_CORE_QUEUE_LEN, LOG_POOL);#ifdef SWITCH_LOG_RECYCLE switch_queue_create(&LOG_RECYCLE_QUEUE, SWITCH_CORE_QUEUE_LEN, LOG_POOL);#endif switch_mutex_init(&BINDLOCK, SWITCH_MUTEX_NESTED, LOG_POOL); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_thread_create(&thread, thd_attr, log_thread, NULL, LOG_POOL); while (!THREAD_RUNNING) { switch_cond_next(); } if (colorize) {#ifdef WIN32 hStdout = GetStdHandle(STD_OUTPUT_HANDLE); if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) { wOldColorAttrs = csbiInfo.wAttributes; COLORIZE = SWITCH_TRUE; }#else COLORIZE = SWITCH_TRUE;#endif } return SWITCH_STATUS_SUCCESS;}
开发者ID:konradwyr,项目名称:FreeSwitch,代码行数:39,
示例15: timerfd_start_intervalstatic switch_status_t timerfd_start_interval(interval_timer_t *it, int interval){ struct itimerspec val; struct epoll_event e; int fd; it->users++; if (it->users > 1) return SWITCH_STATUS_SUCCESS; it->tick = 0; switch_mutex_init(&it->mutex, SWITCH_MUTEX_NESTED, module_pool); switch_thread_cond_create(&it->cond, module_pool); fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); if (fd < 0) return SWITCH_STATUS_GENERR; val.it_interval.tv_sec = interval / 1000; val.it_interval.tv_nsec = (interval % 1000) * 1000000; val.it_value.tv_sec = 0; val.it_value.tv_nsec = 100000; if (timerfd_settime(fd, 0, &val, NULL) < 0) { close(fd); return SWITCH_STATUS_GENERR; } e.events = EPOLLIN | EPOLLERR; e.data.ptr = it; if (epoll_ctl(interval_poll_fd, EPOLL_CTL_ADD, fd, &e) < 0) { close(fd); return SWITCH_STATUS_GENERR; } it->fd = fd; return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:38,
示例16: memsetWSClientParser::WSClientParser() { // TODO Auto-generated constructor stub mState = WSClientState_UnKnow; mpCallback = NULL; mpClient = NULL; mpUser = NULL; mpDomain = NULL; mpDestNumber = NULL; mpSite = NULL; mpCustom = NULL; mpChannel = NULL; memset(mWebSocketKey, '/0', sizeof(mWebSocketKey)); // 创建内存池 switch_core_new_memory_pool(&mpPool); switch_mutex_init(&clientMutex, SWITCH_MUTEX_NESTED, mpPool); // 生成唯一标识 switch_uuid_t uuid; switch_uuid_get(&uuid); switch_uuid_format(this->uuid, &uuid);}
开发者ID:KingsleyYau,项目名称:CamShareMiddleware,代码行数:23,
示例17: SWITCH_DECLARESWITCH_DECLARE(void) switch_ssl_init_ssl_locks(void){ int i, num; if (ssl_count == 0) { num = CRYPTO_num_locks(); ssl_mutexes = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(switch_mutex_t*)); switch_assert(ssl_mutexes != NULL); switch_core_new_memory_pool(&ssl_pool); for (i = 0; i < num; i++) { switch_mutex_init(&(ssl_mutexes[i]), SWITCH_MUTEX_NESTED, ssl_pool); switch_assert(ssl_mutexes[i] != NULL); } CRYPTO_set_id_callback(switch_ssl_ssl_thread_id); CRYPTO_set_locking_callback((void (*)(int, int, const char*, int))switch_ssl_ssl_lock_callback); } ssl_count++;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:24,
示例18: tech_initstatic switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *session, switch_codec_t *codec){ const char *iananame = "L16"; int rate = 8000; int interval = 20; switch_status_t status = SWITCH_STATUS_SUCCESS; switch_channel_t *channel = switch_core_session_get_channel(session); const switch_codec_implementation_t *read_impl; if (codec) { iananame = codec->implementation->iananame; rate = codec->implementation->samples_per_second; interval = codec->implementation->microseconds_per_packet / 1000; } if (switch_core_codec_ready(&tech_pvt->read_codec)) { switch_core_codec_destroy(&tech_pvt->read_codec); } if (switch_core_codec_ready(&tech_pvt->write_codec)) { switch_core_codec_destroy(&tech_pvt->write_codec); } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s setup codec %s/%d/%d/n", switch_channel_get_name(channel), iananame, rate, interval); status = switch_core_codec_init(&tech_pvt->read_codec, iananame, NULL, rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)); if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) { goto end; } status = switch_core_codec_init(&tech_pvt->write_codec, iananame, NULL, rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)); if (status != SWITCH_STATUS_SUCCESS) { switch_core_codec_destroy(&tech_pvt->read_codec); goto end; } tech_pvt->read_frame.data = tech_pvt->databuf; tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); tech_pvt->read_frame.codec = &tech_pvt->read_codec; tech_pvt->cng_frame.data = tech_pvt->cng_databuf; tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf); //switch_set_flag((&tech_pvt->cng_frame), SFF_CNG); tech_pvt->cng_frame.datalen = 2; tech_pvt->bowout_frame_count = (tech_pvt->read_codec.implementation->actual_samples_per_second / tech_pvt->read_codec.implementation->samples_per_packet) * 3; switch_core_session_set_read_codec(session, &tech_pvt->read_codec); switch_core_session_set_write_codec(session, &tech_pvt->write_codec); if (tech_pvt->flag_mutex) { switch_core_timer_destroy(&tech_pvt->timer); } read_impl = tech_pvt->read_codec.implementation; switch_core_timer_init(&tech_pvt->timer, "soft", read_impl->microseconds_per_packet / 1000, read_impl->samples_per_packet * 4, switch_core_session_get_pool(session)); if (!tech_pvt->flag_mutex) { switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_core_session_set_private(session, tech_pvt); switch_queue_create(&tech_pvt->frame_queue, FRAME_QUEUE_LEN, switch_core_session_get_pool(session)); tech_pvt->session = session; tech_pvt->channel = switch_core_session_get_channel(session); } end: return status;}
开发者ID:gujun,项目名称:sscore,代码行数:85,
示例19: SWITCH_DECLARE//.........这里部分代码省略......... if (flags & SMBF_READ_REPLACE) { switch_thread_rwlock_wrlock(session->bug_rwlock); for (bp = session->bugs; bp; bp = bp->next) { if (switch_test_flag(bp, SMBF_READ_REPLACE)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Only one bug of this type allowed!/n"); switch_thread_rwlock_unlock(session->bug_rwlock); return SWITCH_STATUS_GENERR; } } switch_thread_rwlock_unlock(session->bug_rwlock); }#endif if (!(bug = switch_core_session_alloc(session, sizeof(*bug)))) { return SWITCH_STATUS_MEMERR; } bug->callback = callback; bug->user_data = user_data; bug->session = session; bug->flags = flags; bug->function = "N/A"; bug->target = "N/A"; switch_core_session_get_read_impl(session, &bug->read_impl); switch_core_session_get_write_impl(session, &bug->write_impl); if (function) { bug->function = switch_core_session_strdup(session, function); } if (target) { bug->target = switch_core_session_strdup(session, target); } bug->stop_time = stop_time; bytes = bug->read_impl.decoded_bytes_per_packet; if (!bug->flags) { bug->flags = (SMBF_READ_STREAM | SMBF_WRITE_STREAM); } if (switch_test_flag(bug, SMBF_READ_STREAM) || switch_test_flag(bug, SMBF_READ_PING)) { switch_buffer_create_dynamic(&bug->raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, MAX_BUG_BUFFER); switch_mutex_init(&bug->read_mutex, SWITCH_MUTEX_NESTED, session->pool); } bytes = bug->write_impl.decoded_bytes_per_packet; if (switch_test_flag(bug, SMBF_WRITE_STREAM)) { switch_buffer_create_dynamic(&bug->raw_write_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, MAX_BUG_BUFFER); switch_mutex_init(&bug->write_mutex, SWITCH_MUTEX_NESTED, session->pool); } if ((bug->flags & SMBF_THREAD_LOCK)) { bug->thread_id = switch_thread_self(); } if (bug->callback) { switch_bool_t result = bug->callback(bug, bug->user_data, SWITCH_ABC_TYPE_INIT); if (result == SWITCH_FALSE) { switch_core_media_bug_destroy(bug); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error attaching BUG to %s/n", switch_channel_get_name(session->channel)); return SWITCH_STATUS_GENERR; } } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Attaching BUG to %s/n", switch_channel_get_name(session->channel)); bug->ready = 1; switch_thread_rwlock_wrlock(session->bug_rwlock); bug->next = session->bugs; session->bugs = bug; for(bp = session->bugs; bp; bp = bp->next) { if (bp->ready && !switch_test_flag(bp, SMBF_TAP_NATIVE_READ) && !switch_test_flag(bp, SMBF_TAP_NATIVE_WRITE)) { tap_only = 0; } } switch_thread_rwlock_unlock(session->bug_rwlock); *new_bug = bug; if (tap_only) { switch_set_flag(session, SSF_MEDIA_BUG_TAP_ONLY); } else { switch_clear_flag(session, SSF_MEDIA_BUG_TAP_ONLY); } if (switch_event_create(&event, SWITCH_EVENT_MEDIA_BUG_START) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Function", "%s", bug->function); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Target", "%s", bug->target); switch_channel_event_set_data(session->channel, event); switch_event_fire(&event); } return SWITCH_STATUS_SUCCESS;}
开发者ID:benlangfeld,项目名称:FreeSWITCH,代码行数:101,
示例20: SWITCH_DECLARESWITCH_DECLARE(switch_status_t) switch_core_codec_init_with_bitrate(switch_codec_t *codec, const char *codec_name, const char *fmtp, uint32_t rate, int ms, int channels, uint32_t bitrate, uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool){ switch_codec_interface_t *codec_interface; const switch_codec_implementation_t *iptr, *implementation = NULL; switch_assert(codec != NULL); switch_assert(codec_name != NULL); memset(codec, 0, sizeof(*codec)); if (channels == 2) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stereo is currently unsupported. please downsample audio source to mono./n"); return SWITCH_STATUS_GENERR; } if ((codec_interface = switch_loadable_module_get_codec_interface(codec_name)) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid codec %s!/n", codec_name); return SWITCH_STATUS_GENERR; } /* If no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */ if (!ms) { for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) { if ((!rate || rate == iptr->samples_per_second) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) && (20 == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) { implementation = iptr; goto found; } } } /* Either looking for a specific interval or there was no interval specified and there wasn't one @20ms available */ for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) { if ((!rate || rate == iptr->samples_per_second) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) && (!ms || ms == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) { implementation = iptr; break; } } found: if (implementation) { switch_status_t status; codec->codec_interface = codec_interface; codec->implementation = implementation; codec->flags = flags; if (pool) { codec->memory_pool = pool; } else { if ((status = switch_core_new_memory_pool(&codec->memory_pool)) != SWITCH_STATUS_SUCCESS) { return status; } switch_set_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL); } if (fmtp) { codec->fmtp_in = switch_core_strdup(codec->memory_pool, fmtp); } implementation->init(codec, flags, codec_settings); switch_mutex_init(&codec->mutex, SWITCH_MUTEX_NESTED, codec->memory_pool); switch_set_flag(codec, SWITCH_CODEC_FLAG_READY); return SWITCH_STATUS_SUCCESS; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec %s Exists but not at the desired implementation. %dhz %dms/n", codec_name, rate, ms); } UNPROTECT_INTERFACE(codec_interface); return SWITCH_STATUS_NOTIMPL;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:76,
示例21: SWITCH_DECLARESWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t start, switch_port_t end, switch_port_flag_t flags, switch_core_port_allocator_t **new_allocator){ switch_status_t status; switch_memory_pool_t *pool; switch_core_port_allocator_t *alloc; int even, odd; if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) { return status; } if (!(alloc = switch_core_alloc(pool, sizeof(*alloc)))) { switch_core_destroy_memory_pool(&pool); return SWITCH_STATUS_MEMERR; } alloc->flags = flags; even = switch_test_flag(alloc, SPF_EVEN); odd = switch_test_flag(alloc, SPF_ODD); if (!(even && odd)) { if (even) { if ((start % 2) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Rounding odd start port %d to %d/n", start, start + 1); start++; } if ((end % 2) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Rounding odd end port %d to %d/n", end, end - 1); end--; } } else if (odd) { if ((start % 2) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Rounding even start port %d to %d/n", start, start + 1); start++; } if ((end % 2) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Rounding even end port %d to %d/n", end, end - 1); end--; } } } alloc->track_len = (end - start) + 2; if (!(even && odd)) { alloc->track_len /= 2; } alloc->track = switch_core_alloc(pool, (alloc->track_len + 2) * sizeof(switch_byte_t)); alloc->start = start; alloc->next = start; alloc->end = end; switch_mutex_init(&alloc->mutex, SWITCH_MUTEX_NESTED, pool); alloc->pool = pool; *new_allocator = alloc; return SWITCH_STATUS_SUCCESS;}
开发者ID:RodrigoNieves,项目名称:FreeSWITCH,代码行数:62,
示例22: switch_core_session_get_channel//.........这里部分代码省略......... SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "" "WSClientParser::InitChannel( " "[Fail, Can't initialize write codec], " "this : %p, " "wsChannel : %p " ")/n", this, wsChannel ); return false; } switch_core_session_set_read_codec(session, &wsChannel->read_codec); switch_core_session_set_write_codec(session, &wsChannel->write_codec); //static inline uint8_t rtmp_audio_codec(int channels, int bits, int rate, rtmp_audio_format_t format) { wsChannel->audio_codec = 0xB2; //rtmp_audio_codec(1, 16, 0 /* speex is always 8000 */, RTMP_AUDIO_SPEEX); // 初始化视频 switch_codec_settings_t codec_settings = {{ 0 }}; wsChannel->video_read_frame.data = wsChannel->video_databuf; wsChannel->video_read_frame.buflen = sizeof(wsChannel->video_databuf); /* Initialize video read & write codecs */ if (switch_core_codec_init( &wsChannel->video_read_codec, /* name */ "H264", /* modname */ NULL, /* fmtp */ NULL, /* rate */ 90000, /* ms */ 0, /* channels */ 1, /* flags */ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, /* codec settings */ NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS ) { switch_log_printf( SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "WSClientParser::InitChannel( " "[Fail, Can't initialize video read codec], " "this : %p, " "wsChannel : %p " ") /n", this, wsChannel ); return false; } codec_settings.video.bandwidth = switch_parse_bandwidth_string("1mb"); if (switch_core_codec_init( &wsChannel->video_write_codec, /* name */ "H264", /* modname */ NULL, /* fmtp */ NULL, /* rate */ 90000, /* ms */ 0, /* channels */ 1, /* flags */ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, /* codec settings */ &codec_settings, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS ) { switch_log_printf( SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "WSClientParser::InitChannel( " "[Fail, Can't initialize write codec], " "this : %p, " "wsChannel : %p " ") /n", this, wsChannel ); return false; } switch_core_session_set_video_read_codec(session, &wsChannel->video_read_codec); switch_core_session_set_video_write_codec(session, &wsChannel->video_write_codec); switch_channel_set_flag(channel, CF_VIDEO); wsChannel->mparams.external_video_source = SWITCH_TRUE; switch_media_handle_create(&wsChannel->media_handle, session, &wsChannel->mparams); wsChannel->video_read_frame.packet = wsChannel->video_databuf; wsChannel->video_read_frame.data = wsChannel->video_databuf + 12; wsChannel->video_read_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE - 12; switch_mutex_init(&wsChannel->video_readbuf_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_buffer_create_dynamic(&wsChannel->video_readbuf, 1024, 1024, 2048000); wsChannel->video_codec = 0xB2; return true;}
开发者ID:KingsleyYau,项目名称:CamShareMiddleware,代码行数:101,
示例23: do_telecastvoid do_telecast(switch_stream_handle_t *stream){ char *path_info = switch_event_get_header(stream->param_event, "http-path-info"); char *uuid = strdup(path_info + 4); switch_core_session_t *tsession; char *fname = "stream.mp3"; if ((fname = strchr(uuid, '/'))) { *fname++ = '/0'; } if (!(tsession = switch_core_session_locate(uuid))) { char *ref = switch_event_get_header(stream->param_event, "http-referer"); stream->write_function(stream, "Content-type: text/html/r/n/r/n<h2>Not Found!</h2>/n" "<META http-equiv=/"refresh/" content=/"1;URL=%s/">", ref); } else { switch_media_bug_t *bug = NULL; switch_buffer_t *buffer = NULL; switch_mutex_t *mutex; switch_channel_t *channel = switch_core_session_get_channel(tsession); lame_global_flags *gfp = NULL; switch_codec_implementation_t read_impl = { 0 }; switch_core_session_get_read_impl(tsession, &read_impl); if (switch_channel_test_flag(channel, CF_PROXY_MODE)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stepping into media path so this will work!/n"); switch_ivr_media(uuid, SMF_REBRIDGE); } if (!(gfp = lame_init())) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate lame/n"); goto end; } lame_set_num_channels(gfp, read_impl.number_of_channels); lame_set_in_samplerate(gfp, read_impl.actual_samples_per_second); lame_set_brate(gfp, 16 * (read_impl.actual_samples_per_second / 8000) * read_impl.number_of_channels); lame_set_mode(gfp, 3); lame_set_quality(gfp, 2); lame_set_errorf(gfp, log_error); lame_set_debugf(gfp, log_debug); lame_set_msgf(gfp, log_msg); lame_set_bWriteVbrTag(gfp, 0); lame_mp3_tags_fid(gfp, NULL); lame_init_params(gfp); lame_print_config(gfp); switch_mutex_init(&mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession)); switch_buffer_create_dynamic(&buffer, 1024, 2048, 0); switch_buffer_add_mutex(buffer, mutex); if (switch_core_media_bug_add(tsession, "telecast", NULL, telecast_callback, buffer, 0, SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_PING, &bug) != SWITCH_STATUS_SUCCESS) { goto end; } stream->write_function(stream, "Content-type: audio/mpeg/r/n" "Content-Disposition: inline; filename=/"%s/"/r/n/r/n", fname); while (switch_channel_ready(channel)) { unsigned char mp3buf[TC_BUFFER_SIZE] = ""; int rlen; uint8_t buf[1024]; switch_size_t bytes = 0; if (switch_buffer_inuse(buffer) >= 1024) { switch_buffer_lock(buffer); bytes = switch_buffer_read(buffer, buf, sizeof(buf)); switch_buffer_unlock(buffer); } else { if (!bytes) { switch_cond_next(); continue; } memset(buf, 0, bytes); } if ((rlen = lame_encode_buffer(gfp, (void *) buf, NULL, bytes / 2, mp3buf, sizeof(mp3buf))) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!/n", rlen); goto end; } if (rlen) { if (stream->raw_write_function(stream, mp3buf, rlen)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected/n"); goto end; } } } end: switch_safe_free(uuid); if (gfp) { lame_close(gfp); gfp = NULL; } if (bug) { switch_core_media_bug_remove(tsession, &bug); }//.........这里部分代码省略.........
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:101,
示例24: mp4_file_openstatic switch_status_t mp4_file_open(switch_file_handle_t *handle, const char *path){ mp4_file_context_t *context; char *ext; unsigned int flags = 0; const char *tmp = NULL; if ((ext = strrchr(path, '.')) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Format/n"); return SWITCH_STATUS_GENERR; } ext++; if ((context = switch_core_alloc(handle->memory_pool, sizeof(mp4_file_context_t))) == 0) { return SWITCH_STATUS_MEMERR; } memset(context, 0, sizeof(mp4_file_context_t)); context->offset = -100; if (handle->params && (tmp = switch_event_get_header(handle->params, "mp4v2_video_offset"))) { context->offset = atoi(tmp); } context->audio_type = MP4_ULAW_AUDIO_TYPE; // default if (handle->params && (tmp = switch_event_get_header(handle->params, "mp4v2_audio_codec"))) { if (!strcasecmp(tmp, "PCMU")) { context->audio_type = MP4_ULAW_AUDIO_TYPE; } else if (!strcasecmp(tmp, "MP3")) { context->audio_type = MP4_MP3_AUDIO_TYPE; } else if (!strcasecmp(tmp, "AAC")) { context->audio_type = MP4_MPEG4_AUDIO_TYPE; } else if (!strcasecmp(tmp, "L16")) { context->audio_type = MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE; } } switch_mutex_init(&context->mutex, SWITCH_MUTEX_NESTED, handle->memory_pool); if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { flags |= SWITCH_FOPEN_WRITE | SWITCH_FOPEN_CREATE; if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND) || switch_test_flag(handle, SWITCH_FILE_WRITE_OVER)) { flags |= SWITCH_FOPEN_READ; } else { flags |= SWITCH_FOPEN_TRUNCATE; } } if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) { flags |= SWITCH_FOPEN_READ; } if ((context->fd = MP4CreateEx(path, 0, 1, 1, NULL, 0, NULL, 0)) == MP4_INVALID_FILE_HANDLE) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening file %s/n", path); return SWITCH_STATUS_GENERR; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sample rate: %d, channels: %d/n", handle->samplerate, handle->channels); if (context->audio_type == MP4_ULAW_AUDIO_TYPE) { context->audio = MP4AddULawAudioTrack(context->fd, handle->samplerate); MP4SetTrackIntegerProperty(context->fd, context->audio, "mdia.minf.stbl.stsd.ulaw.channels", handle->channels); MP4SetTrackIntegerProperty(context->fd, context->audio, "mdia.minf.stbl.stsd.ulaw.sampleSize", 8); } else if (context->audio_type == MP4_MP3_AUDIO_TYPE) { // handle->samplerate = 44100; context->audio = MP4AddAudioTrack(context->fd, handle->samplerate, handle->samplerate, MP4_MP3_AUDIO_TYPE); MP4SetTrackName(context->fd, context->audio, ".mp3"); MP4SetTrackIntegerProperty(context->fd, context->audio, "mdia.minf.stbl.stsd.mp4a.channels", handle->channels); // MP4SetTrackIntegerProperty(context->fd, context->audio, "mdia.minf.stbl.stsd..mp3.channels", handle->channels); } else if (context->audio_type == MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE) { context->audio = MP4AddAudioTrack(context->fd, handle->samplerate, handle->samplerate, MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE); MP4SetTrackName(context->fd, context->audio, "lpcm"); MP4SetTrackIntegerProperty(context->fd, context->audio, "mdia.minf.stbl.stsd.mp4a.channels", handle->channels); MP4SetTrackIntegerProperty(context->fd, context->audio, "mdia.minf.stbl.stsd.lpcm.channels", handle->channels); MP4SetTrackIntegerProperty(context->fd, context->audio, "mdia.minf.stbl.stsd.lpcm.sampleSize", 16); } else if (context->audio_type == MP4_MPEG4_AUDIO_TYPE) { /* AAC object types */ #define AAC_MAIN 1 #define AAC_LOW 2 #define AAC_SSR 3 #define AAC_LTP 4 uint16_t info = 0; info |= AAC_LOW << 11; // aacObjectType (5bit) info |= get_aac_sample_rate_index(handle->samplerate) << 7; //(4bit) info |= handle->channels << 3; //(4bit) info = htons(info); context->audio = MP4AddAudioTrack(context->fd, handle->samplerate, handle->samplerate, MP4_MPEG4_AUDIO_TYPE); MP4SetTrackESConfiguration(context->fd, context->audio, (uint8_t *)&info, sizeof(info)); MP4SetTrackIntegerProperty(context->fd, context->audio, "mdia.minf.stbl.stsd.mp4a.channels", handle->channels); } handle->format = 0; handle->sections = 0; handle->seekable = 0; handle->speed = 0; handle->pos = 0;//.........这里部分代码省略.........
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例25: shout_file_openstatic switch_status_t shout_file_open(switch_file_handle_t *handle, const char *path){ shout_context_t *context; char *host, *file; char *username, *password, *port; char *err = NULL; const char *mpg123err = NULL; int portno = 0; if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) { return SWITCH_STATUS_MEMERR; } if (!handle->samplerate) { handle->samplerate = 8000; } context->memory_pool = handle->memory_pool; context->samplerate = handle->samplerate; context->handle = handle; switch_thread_rwlock_create(&(context->rwlock), context->memory_pool); switch_thread_rwlock_rdlock(context->rwlock); switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, context->memory_pool); if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) { if (switch_buffer_create_dynamic(&context->audio_buffer, TC_BUFFER_SIZE, TC_BUFFER_SIZE * 2, 0) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!/n"); goto error; } context->mh = our_mpg123_new(NULL, NULL); if (mpg123_format_all(context->mh) != MPG123_OK) { MPGERROR(); } if (mpg123_param(context->mh, MPG123_FORCE_RATE, context->samplerate, 0) != MPG123_OK) { MPGERROR(); } if (handle->handler) { if (mpg123_param(context->mh, MPG123_FLAGS, MPG123_SEEKBUFFER | MPG123_MONO_MIX, 0) != MPG123_OK) { MPGERROR(); } if (mpg123_open_feed(context->mh) != MPG123_OK) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening mpg feed/n"); mpg123err = mpg123_strerror(context->mh); goto error; } context->stream_url = switch_core_sprintf(context->memory_pool, "http://%s", path); context->prebuf = handle->prebuf; launch_read_stream_thread(context); } else { handle->seekable = 1; if (mpg123_param(context->mh, MPG123_FLAGS, MPG123_MONO_MIX, 0) != MPG123_OK) { MPGERROR(); } if (mpg123_open(context->mh, path) != MPG123_OK) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s/n", path); mpg123err = mpg123_strerror(context->mh); goto error; } } } else if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Appending to MP3 not supported./n"); } if (!(context->gfp = lame_init())) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate lame/n"); goto error; } if (!handle->handler) { id3tag_init(context->gfp); id3tag_v2_only(context->gfp); id3tag_pad_v2(context->gfp); } context->channels = handle->channels; lame_set_brate(context->gfp, 16 * (handle->samplerate / 8000) * handle->channels); lame_set_num_channels(context->gfp, handle->channels); lame_set_in_samplerate(context->gfp, handle->samplerate); lame_set_out_samplerate(context->gfp, handle->samplerate); if (handle->channels == 2) { lame_set_mode(context->gfp, STEREO); } else { lame_set_mode(context->gfp, MONO); } lame_set_quality(context->gfp, 2); /* 2=high 5 = medium 7=low */ lame_set_errorf(context->gfp, log_error); lame_set_debugf(context->gfp, log_debug); lame_set_msgf(context->gfp, log_msg); if (handle->handler) { if (switch_buffer_create_dynamic(&context->audio_buffer, MY_BLOCK_SIZE, MY_BUF_LEN, 0) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!/n");//.........这里部分代码省略.........
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:101,
注:本文中的switch_mutex_init函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ switch_mutex_lock函数代码示例 C++ switch_log_printf函数代码示例 |