这篇教程C++ switch_clear_flag函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中switch_clear_flag函数的典型用法代码示例。如果您正苦于以下问题:C++ switch_clear_flag函数的具体用法?C++ switch_clear_flag怎么用?C++ switch_clear_flag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了switch_clear_flag函数的22个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: pocketsphinx_asr_close/*! function to close the asr interface */static switch_status_t pocketsphinx_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags){ pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>>pocketsphinx_asr_close<<<<<<<<</n"); switch_mutex_lock(ps->flag_mutex); if (switch_test_flag(ps, PSFLAG_ALLOCATED)) { if (switch_test_flag(ps, PSFLAG_READY)) { ps_end_utt(ps->ps); } ps_free(ps->ps); ps->ps = NULL; } switch_safe_free(ps->grammar); switch_mutex_unlock(ps->flag_mutex); switch_clear_flag(ps, PSFLAG_HAS_TEXT); switch_clear_flag(ps, PSFLAG_READY); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Port Closed./n"); switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED); /* ifly end session */ QISRSessionEnd(ps->ifly_session_id, ps->ifly_hints); return SWITCH_STATUS_SUCCESS;}
开发者ID:dgkae,项目名称:unicallasr,代码行数:28,
示例2: SWITCH_DECLARESWITCH_DECLARE(uint32_t) switch_core_media_bug_set_flag(switch_media_bug_t *bug, uint32_t flag){ if ((flag & SMBF_PRUNE)) { switch_clear_flag(bug, SMBF_LOCK); } return switch_set_flag(bug, flag);}
开发者ID:benlangfeld,项目名称:FreeSWITCH,代码行数:7,
示例3: handle_node_api_commandstatic switch_status_t handle_node_api_command(ei_node_t *ei_node, switch_stream_handle_t *stream, uint32_t command) { unsigned int year, day, hour, min, sec, delta; switch (command) { case API_COMMAND_DISCONNECT: stream->write_function(stream, "Disconnecting erlang node %s at managers request/n", ei_node->peer_nodename); switch_clear_flag(ei_node, LFLAG_RUNNING); break; case API_COMMAND_REMOTE_IP: delta = (switch_micro_time_now() - ei_node->created_time) / 1000000; sec = delta % 60; min = delta / 60 % 60; hour = delta / 3600 % 24; day = delta / 86400 % 7; year = delta / 31556926 % 12; stream->write_function(stream, "Uptime %d years, %d days, %d hours, %d minutes, %d seconds/n", year, day, hour, min, sec); stream->write_function(stream, "Local Address %s:%d/n", ei_node->local_ip, ei_node->local_port); stream->write_function(stream, "Remote Address %s:%d/n", ei_node->remote_ip, ei_node->remote_port); break; case API_COMMAND_STREAMS: handle_node_api_event_streams(ei_node, stream); break; case API_COMMAND_BINDINGS: handle_api_command_streams(ei_node, stream); break; default: break; } return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:32,
示例4: pocketsphinx_asr_get_results/*! function to read results from the ASR */static switch_status_t pocketsphinx_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags){ pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; switch_status_t status = SWITCH_STATUS_SUCCESS; if (switch_test_flag(ps, PSFLAG_BARGE)) { switch_clear_flag_locked(ps, PSFLAG_BARGE); status = SWITCH_STATUS_BREAK; } if (switch_test_flag(ps, PSFLAG_HAS_TEXT)) { switch_mutex_lock(ps->flag_mutex); switch_clear_flag(ps, PSFLAG_HAS_TEXT); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Recognized: %s, Confidence: %d, Confidence-Threshold: %d/n", ps->hyp, ps->confidence, ps->confidence_threshold); switch_mutex_unlock(ps->flag_mutex); *xmlstr = switch_mprintf("<?xml version=/"1.0/"?>/n" "<result grammar=/"%s/">/n" " <interpretation grammar=/"%s/" confidence=/"%d/">/n" " <input mode=/"speech/">%s</input>/n" " </interpretation>/n" "</result>/n", ps->grammar, ps->grammar, ps->confidence, ps->hyp); if (!switch_test_flag(ps, PSFLAG_INPUT_TIMERS) && switch_test_flag(ah, SWITCH_ASR_FLAG_AUTO_RESUME)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto Resuming/n"); switch_set_flag(ps, PSFLAG_READY); ps_start_utt(ps->ps, NULL); } status = SWITCH_STATUS_SUCCESS; } else if (switch_test_flag(ps, PSFLAG_NOINPUT)) { switch_clear_flag_locked(ps, PSFLAG_NOINPUT); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO INPUT/n"); *xmlstr = switch_mprintf("<?xml version=/"1.0/"?>/n" "<result grammar=/"%s/">/n" " <interpretation>/n" " <input mode=/"speech/"><noinput/></input>/n" " </interpretation>/n" "</result>/n", ps->grammar); status = SWITCH_STATUS_SUCCESS; } else if (switch_test_flag(ps, PSFLAG_NOMATCH)) { switch_clear_flag_locked(ps, PSFLAG_NOMATCH); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO MATCH/n"); *xmlstr = switch_mprintf("<?xml version=/"1.0/"?>/n" "<result grammar=/"%s/">/n" " <interpretation>/n" " <input mode=/"speech/"><nomatch/></input>/n" " </interpretation>/n" "</result>/n", ps->grammar); status = SWITCH_STATUS_SUCCESS; } return status;}
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:60,
示例5: channel_read_framestatic switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id){ switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; //switch_time_t started = switch_time_now(); //unsigned int elapsed; switch_byte_t *data; channel = switch_core_session_get_channel(session); assert(channel != NULL); tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); tech_pvt->read_frame.flags = SFF_NONE; *frame = NULL; while (switch_test_flag(tech_pvt, TFLAG_IO)) { if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { switch_clear_flag(tech_pvt, TFLAG_BREAK); goto cng; } if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) { switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); if (!tech_pvt->read_frame.datalen) { continue; } *frame = &tech_pvt->read_frame;#if SWITCH_BYTE_ORDER == __BIG_ENDIAN if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) { switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2); }#endif return SWITCH_STATUS_SUCCESS; } switch_cond_next(); } return SWITCH_STATUS_FALSE;cng: data = (switch_byte_t *) tech_pvt->read_frame.data; data[0] = 65; data[1] = 0; tech_pvt->read_frame.datalen = 2; tech_pvt->read_frame.flags = SFF_CNG; *frame = &tech_pvt->read_frame; return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:57,
示例6: channel_on_routingstatic switch_status_t channel_on_routing(switch_core_session_t *session){ switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; const char *app, *arg; channel = switch_core_session_get_channel(session); assert(channel != NULL); tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); do_reset(tech_pvt); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING/n", switch_channel_get_name(channel)); if (switch_test_flag(tech_pvt, TFLAG_RUNNING_APP)) { switch_clear_flag(tech_pvt, TFLAG_RUNNING_APP); } if (switch_test_flag(tech_pvt, TFLAG_APP) && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && (app = switch_channel_get_variable(channel, "loopback_app"))) { switch_caller_extension_t *extension = NULL; switch_clear_flag(tech_pvt, TFLAG_APP); switch_set_flag(tech_pvt, TFLAG_RUNNING_APP); arg = switch_channel_get_variable(channel, "loopback_app_arg"); extension = switch_caller_extension_new(session, app, app); switch_caller_extension_add_application(session, extension, "pre_answer", NULL); switch_caller_extension_add_application(session, extension, app, arg); switch_channel_set_caller_extension(channel, extension); switch_channel_set_state(channel, CS_EXECUTE); return SWITCH_STATUS_FALSE; } return SWITCH_STATUS_SUCCESS;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:41,
示例7: switch_speex_encodestatic switch_status_t switch_speex_encode(switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data, uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag){ struct speex_context *context = codec->private_info; short *buf; int is_speech = 1; if (!context) { return SWITCH_STATUS_FALSE; } buf = decoded_data; if (context->pp) { is_speech = speex_preprocess(context->pp, buf, NULL); } if (is_speech) { is_speech = speex_encode_int(context->encoder_state, buf, &context->encoder_bits) || !context->codec_settings.dtx; } else { speex_bits_pack(&context->encoder_bits, 0, 5); } if (is_speech) { switch_clear_flag(context, SWITCH_CODEC_FLAG_SILENCE); *flag |= SWITCH_CODEC_FLAG_SILENCE_STOP; } else { if (switch_test_flag(context, SWITCH_CODEC_FLAG_SILENCE)) { *encoded_data_len = 0; *flag |= SWITCH_CODEC_FLAG_SILENCE; return SWITCH_STATUS_SUCCESS; } switch_set_flag(context, SWITCH_CODEC_FLAG_SILENCE); *flag |= SWITCH_CODEC_FLAG_SILENCE_START; } speex_bits_pack(&context->encoder_bits, 15, 5); *encoded_data_len = speex_bits_write(&context->encoder_bits, (char *) encoded_data, context->encoder_frame_size); speex_bits_reset(&context->encoder_bits); (*encoded_data_len)--; return SWITCH_STATUS_SUCCESS;}
开发者ID:kgrofelnik,项目名称:mod_portaudio-endpoints,代码行数:51,
示例8: SWITCH_DECLARESWITCH_DECLARE(int) CoreSession::setAutoHangup(bool val) { this_check(-1); sanity_check(-1); if (!session) { return SWITCH_STATUS_FALSE; } if (val) { switch_set_flag(this, S_HUP); } else { switch_clear_flag(this, S_HUP); } return SWITCH_STATUS_SUCCESS;}
开发者ID:gujun,项目名称:sscore,代码行数:15,
示例9: pocketsphinx_asr_pause/*! function to pause recognizer */static switch_status_t pocketsphinx_asr_pause(switch_asr_handle_t *ah){ pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; switch_status_t status = SWITCH_STATUS_FALSE; switch_mutex_lock(ps->flag_mutex); if (switch_test_flag(ps, PSFLAG_READY)) { ps_end_utt(ps->ps); switch_clear_flag(ps, PSFLAG_READY); status = SWITCH_STATUS_SUCCESS; } switch_mutex_unlock(ps->flag_mutex); return status;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:16,
示例10: pocketsphinx_asr_get_results/*! function to read results from the ASR */static switch_status_t pocketsphinx_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags){ pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; switch_status_t status = SWITCH_STATUS_SUCCESS; //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>>pocketsphinx_asr_get_results<<<<<<<<</n"); if (switch_test_flag(ps, PSFLAG_BARGE)) { switch_clear_flag_locked(ps, PSFLAG_BARGE); status = SWITCH_STATUS_BREAK; } if (switch_test_flag(ps, PSFLAG_HAS_TEXT)) { switch_mutex_lock(ps->flag_mutex); switch_clear_flag(ps, PSFLAG_HAS_TEXT); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Recognized: %s, Confidence: %d, Confidence-Threshold: %d/n", ps->hyp, ps->confidence, ps->confidence_threshold); switch_mutex_unlock(ps->flag_mutex); *xmlstr = switch_mprintf("%s", ps->hyp); if (!switch_test_flag(ps, PSFLAG_INPUT_TIMERS) && switch_test_flag(ah, SWITCH_ASR_FLAG_AUTO_RESUME)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto Resuming/n"); switch_set_flag(ps, PSFLAG_READY); ps_start_utt(ps->ps, NULL); } status = SWITCH_STATUS_SUCCESS; } else if (switch_test_flag(ps, PSFLAG_NOINPUT)) { switch_clear_flag_locked(ps, PSFLAG_NOINPUT); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO INPUT/n"); *xmlstr = switch_mprintf(""); status = SWITCH_STATUS_SUCCESS; } else if (switch_test_flag(ps, PSFLAG_NOMATCH)) { switch_clear_flag_locked(ps, PSFLAG_NOMATCH); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO MATCH/n"); *xmlstr = switch_mprintf(""); status = SWITCH_STATUS_SUCCESS; } return status;}
开发者ID:dgkae,项目名称:unicallasr,代码行数:49,
示例11: pocketsphinx_asr_feed/*! function to feed audio to the ASR */static switch_status_t pocketsphinx_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags){ pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; int rv = 0; if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) return SWITCH_STATUS_BREAK; if (!switch_test_flag(ps, PSFLAG_HAS_TEXT) && switch_test_flag(ps, PSFLAG_READY)) { if (stop_detect(ps, (int16_t *) data, len / 2)) { char const *hyp; switch_mutex_lock(ps->flag_mutex); if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) { if (!zstr(hyp)) { ps_end_utt(ps->ps); switch_clear_flag(ps, PSFLAG_READY); if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) { if (zstr(hyp)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Lost the text, never mind..../n"); ps_start_utt(ps->ps, NULL); switch_set_flag(ps, PSFLAG_READY); } else { ps->hyp = switch_core_strdup(ah->memory_pool, hyp); switch_set_flag(ps, PSFLAG_HAS_TEXT); } } } } switch_mutex_unlock(ps->flag_mutex); } /* only feed ps_process_raw when we are listening */ if (ps->listening) { switch_mutex_lock(ps->flag_mutex); rv = ps_process_raw(ps->ps, (int16 *) data, len / 2, FALSE, FALSE); switch_mutex_unlock(ps->flag_mutex); } if (rv < 0) { return SWITCH_STATUS_FALSE; } } return SWITCH_STATUS_SUCCESS;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:47,
示例12: next_file/** * open next file for reading * @param handle the file handle */static switch_status_t next_file(switch_file_handle_t *handle){ struct ssml_context *context = handle->private_info; const char *file; top: context->index++; if (switch_test_flag((&context->fh), SWITCH_FILE_OPEN)) { switch_core_file_close(&context->fh); } if (context->index >= context->num_files) { return SWITCH_STATUS_FALSE; } file = context->files[context->index].name; context->fh.prefix = context->files[context->index].prefix; if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { /* unsupported */ return SWITCH_STATUS_FALSE; } if (switch_core_file_open(&context->fh, file, handle->channels, handle->samplerate, handle->flags, NULL) != SWITCH_STATUS_SUCCESS) { goto top; } handle->samples = context->fh.samples; handle->format = context->fh.format; handle->sections = context->fh.sections; handle->seekable = context->fh.seekable; handle->speed = context->fh.speed; handle->interval = context->fh.interval; if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) { switch_set_flag(handle, SWITCH_FILE_NATIVE); } else { switch_clear_flag(handle, SWITCH_FILE_NATIVE); } return SWITCH_STATUS_SUCCESS;}
开发者ID:alleywind,项目名称:FreeSWITCH,代码行数:49,
示例13: pocketsphinx_asr_get_results/*! function to read results from the ASR*/static switch_status_t pocketsphinx_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags){ pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; switch_status_t status = SWITCH_STATUS_SUCCESS; int32_t conf; if (switch_test_flag(ps, PSFLAG_BARGE)) { switch_clear_flag_locked(ps, PSFLAG_BARGE); status = SWITCH_STATUS_BREAK; } if (switch_test_flag(ps, PSFLAG_HAS_TEXT)) { switch_mutex_lock(ps->flag_mutex); switch_clear_flag(ps, PSFLAG_HAS_TEXT); conf = ps_get_prob(ps->ps, &ps->uttid); ps->confidence = (conf + 20000) / 200; if (ps->confidence < 0) { ps->confidence = 0; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Recognized: %s, Confidence: %d/n", ps->hyp, ps->confidence); switch_mutex_unlock(ps->flag_mutex); *xmlstr = switch_mprintf("<?xml version=/"1.0/"?>/n" "<result grammar=/"%s/">/n" " <interpretation grammar=/"%s/" confidence=/"%d/">/n" " <input mode=/"speech/">%s</input>/n" " </interpretation>/n" "</result>/n", ps->grammar, ps->grammar, ps->confidence, ps->hyp); if (switch_test_flag(ps, SWITCH_ASR_FLAG_AUTO_RESUME)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto Resuming/n"); switch_set_flag(ps, PSFLAG_READY); ps_start_utt(ps->ps, NULL); } status = SWITCH_STATUS_SUCCESS; } return status;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:44,
示例14: pocketsphinx_asr_resume/*! function to resume recognizer */static switch_status_t pocketsphinx_asr_resume(switch_asr_handle_t *ah){ pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; switch_status_t status = SWITCH_STATUS_FALSE; switch_mutex_lock(ps->flag_mutex); switch_clear_flag(ps, PSFLAG_HAS_TEXT); if (!switch_test_flag(ps, PSFLAG_READY)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Manually Resuming/n"); if (ps_start_utt(ps->ps, NULL)) { status = SWITCH_STATUS_GENERR; } else { switch_set_flag(ps, PSFLAG_READY); } } switch_mutex_unlock(ps->flag_mutex); return status;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:21,
示例15: SWITCH_DECLARESWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec){ switch_mutex_t *mutex; switch_memory_pool_t *pool; int free_pool = 0; switch_assert(codec != NULL); if (!codec->implementation || !switch_core_codec_ready(codec)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!/n"); return SWITCH_STATUS_NOT_INITALIZED; } if (switch_test_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL)) { free_pool = 1; } pool = codec->memory_pool; mutex = codec->mutex; if (mutex) switch_mutex_lock(mutex); codec->implementation->destroy(codec); switch_clear_flag(codec, SWITCH_CODEC_FLAG_READY); UNPROTECT_INTERFACE(codec->codec_interface); if (mutex) switch_mutex_unlock(mutex); if (free_pool) { switch_core_destroy_memory_pool(&pool); } return SWITCH_STATUS_SUCCESS;}
开发者ID:sl33nyc,项目名称:freeswitch,代码行数:37,
示例16: SWITCH_DECLARESWITCH_DECLARE(switch_status_t) switch_core_speech_close(switch_speech_handle_t *sh, switch_speech_flag_t *flags){ switch_status_t status = sh->speech_interface->speech_close(sh, flags); if (!switch_test_flag(sh, SWITCH_SPEECH_FLAG_OPEN)) { return SWITCH_STATUS_FALSE; } if (sh->buffer) { switch_buffer_destroy(&sh->buffer); } switch_resample_destroy(&sh->resampler); UNPROTECT_INTERFACE(sh->speech_interface); if (switch_test_flag(sh, SWITCH_SPEECH_FLAG_FREE_POOL)) { switch_core_destroy_memory_pool(&sh->memory_pool); } switch_clear_flag(sh, SWITCH_SPEECH_FLAG_OPEN); return status;}
开发者ID:bodji,项目名称:freeswitch,代码行数:24,
示例17: fileman_file_read//.........这里部分代码省略......... } o_len = FILE_STARTBYTES / 2; if (switch_core_file_read(fh, context->abuf, &o_len) != SWITCH_STATUS_SUCCESS) { context->eof++; /* at end of file... need to clear buffers before giving up */ continue; } //switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Read file %"SWITCH_SIZE_T_FMT" bytes/n", o_len * 2); /* add file data to audio bufer */ read_bytes = switch_buffer_write(fh->audio_buffer, context->abuf, o_len * 2); //switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Write audio frame %"SWITCH_SIZE_T_FMT" bytes/n", read_bytes); read_bytes = switch_buffer_read(fh->audio_buffer, context->abuf, *len * 2); o_len = read_bytes / 2; fh->offset_pos += o_len; //switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Read audio frame %"SWITCH_SIZE_T_FMT" bytes/n", read_bytes); //switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "file pos = %i/n", fh->offset_pos); } if (o_len <= 0) { //switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "o_len <= 0 (%"SWITCH_SIZE_T_FMT")/n", o_len); status = SWITCH_STATUS_FALSE; goto done; } /* limit speed... there is a .25 factor change in packet size relative to original packet size for each increment. Too many increments and we cause badness when (factor * speed * o_len) > o_len */ if (handle->speed > 2) { handle->speed = 2; } else if (handle->speed < -2) { handle->speed = -2; } if (switch_test_flag(fh, SWITCH_FILE_SEEK)) { /* file position has changed flush the buffer */ switch_buffer_zero(fh->audio_buffer); switch_clear_flag(fh, SWITCH_FILE_SEEK); } /* generate speed frames */ if (handle->speed && do_speed) { float factor = 0.25f * abs(handle->speed); switch_size_t new_len, supplement_len, step_len; short *bp = context->abuf; switch_size_t wrote_len = 0; //switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Generate speed frame (%i)/n", handle->speed); supplement_len = (int) (factor * o_len); if (!supplement_len) { supplement_len = 1; } new_len = (handle->speed > 0) ? o_len - supplement_len : o_len + supplement_len; step_len = (handle->speed > 0) ? (new_len / supplement_len) : (o_len / supplement_len); if (!fh->sp_audio_buffer) { switch_buffer_create_dynamic(&fh->sp_audio_buffer, 1024, 1024, 0); } while ((wrote_len + step_len) < new_len) { switch_buffer_write(fh->sp_audio_buffer, bp, step_len * 2); wrote_len += step_len; bp += step_len; if (handle->speed > 0) { bp++; } else { float f; short s; f = (float) (*bp + *(bp + 1) + *(bp - 1)); f /= 3; s = (short) f; switch_buffer_write(fh->sp_audio_buffer, &s, 2); wrote_len++; } } if (wrote_len < new_len) { switch_size_t r_len = new_len - wrote_len; switch_buffer_write(fh->sp_audio_buffer, bp, r_len * 2); wrote_len += r_len; } continue; } /* adjust volume on frame */ if (handle->vol) { //switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Adjust volume to = %i/n", handle->vol); switch_change_sln_volume(context->abuf, *len, handle->vol); } break; }done: /* copy frame over to return to caller */ memcpy(data, context->abuf, *len * 2); handle->offset_pos = context->fh.offset_pos; return status;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例18: fileman_file_open/** * Wraps file with interface that can be controlled by fileman flags * @param handle * @param path the file to play * @return SWITCH_STATUS_SUCCESS if opened */static switch_status_t fileman_file_open(switch_file_handle_t *handle, const char *path){ int start_offset_ms = 0; switch_status_t status = SWITCH_STATUS_FALSE; struct fileman_file_context *context = switch_core_alloc(handle->memory_pool, sizeof(*context)); handle->private_info = context; if (handle->params) { const char *id = switch_event_get_header(handle->params, "id"); const char *uuid = switch_event_get_header(handle->params, "session"); const char *start_offset_ms_str = switch_event_get_header(handle->params, "start_offset_ms"); if (!zstr(id)) { context->id = switch_core_strdup(handle->memory_pool, id); } if (!zstr(uuid)) { context->uuid = switch_core_strdup(handle->memory_pool, uuid); } if (!zstr(start_offset_ms_str) && switch_is_number(start_offset_ms_str)) { start_offset_ms = atoi(start_offset_ms_str); if (start_offset_ms < 0) { start_offset_ms = 0; } } } switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Got path %s/n", path); if ((status = switch_core_file_open(&context->fh, path, handle->channels, handle->samplerate, handle->flags, NULL)) != SWITCH_STATUS_SUCCESS) { return status; } /* set up handle for external control */ if (!context->id) { /* use filename as ID */ context->id = switch_core_strdup(handle->memory_pool, path); } switch_mutex_lock(fileman_globals.mutex); if (!switch_core_hash_find(fileman_globals.hash, context->id)) { switch_core_hash_insert(fileman_globals.hash, context->id, handle); } else { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_WARNING, "Duplicate fileman ID: %s/n", context->id); return SWITCH_STATUS_FALSE; } switch_mutex_unlock(fileman_globals.mutex); context->max_frame_len = (handle->samplerate / 1000 * SWITCH_MAX_INTERVAL); switch_zmalloc(context->abuf, FILE_STARTBYTES * sizeof(*context->abuf)); if (!context->fh.audio_buffer) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "Create audio buffer/n"); switch_buffer_create_dynamic(&context->fh.audio_buffer, FILE_BLOCKSIZE, FILE_BUFSIZE, 0); switch_assert(context->fh.audio_buffer); } handle->samples = context->fh.samples; handle->format = context->fh.format; handle->sections = context->fh.sections; handle->seekable = context->fh.seekable; handle->speed = context->fh.speed; handle->vol = context->fh.vol; handle->offset_pos = context->fh.offset_pos; handle->interval = context->fh.interval; if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) { switch_set_flag(handle, SWITCH_FILE_NATIVE); } else { switch_clear_flag(handle, SWITCH_FILE_NATIVE); } if (handle->params && switch_true(switch_event_get_header(handle->params, "pause"))) { switch_set_flag(handle, SWITCH_FILE_PAUSE); } if (handle->seekable && start_offset_ms) { unsigned int pos = 0; int32_t target = start_offset_ms * (handle->samplerate / 1000); switch_log_printf(SWITCH_CHANNEL_UUID_LOG(context->uuid), SWITCH_LOG_DEBUG, "seek to position %d/n", target); switch_core_file_seek(&context->fh, &pos, target, SEEK_SET); } return status;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:88,
示例19: next_file//.........这里部分代码省略......... switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Missing <document>/n"); return SWITCH_STATUS_FALSE; } } else { context->cur_doc = iks_next_tag(context->cur_doc); } /* done? */ if (!context->cur_doc) { if (context->could_open && ++loops < 2 && (output->repeat_times == 0 || ++context->play_count < output->repeat_times)) { /* repeat all document(s) */ if (!output->repeat_interval_ms) { goto top; } } else { /* no more files to play */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Done playing/n"); return SWITCH_STATUS_FALSE; } } if (!context->cur_doc) { /* play silence between repeats */ switch_safe_free(context->ssml); context->ssml = switch_mprintf("silence_stream://%i", output->repeat_interval_ms); } else { /* play next document */ iks *speak = NULL; switch_safe_free(context->ssml); context->ssml = NULL; speak = iks_find(context->cur_doc, "speak"); if (speak) { /* <speak> is child node */ char *ssml_str = iks_string(NULL, speak); if (zstr(output->renderer)) { /* FS must parse the SSML */ context->ssml = switch_mprintf("ssml://%s", ssml_str); } else { /* renderer will parse the SSML */ if (!zstr(output->headers) && !strncmp("unimrcp", output->renderer, 7)) { /* pass MRCP headers */ context->ssml = switch_mprintf("tts://%s||%s%s", output->renderer, output->headers, ssml_str); } else { context->ssml = switch_mprintf("tts://%s||%s", output->renderer, ssml_str); } } iks_free(ssml_str); } else if (iks_has_children(context->cur_doc)) { /* check if <speak> is in CDATA */ const char *ssml_str = NULL; iks *ssml = iks_child(context->cur_doc); if (ssml && iks_type(ssml) == IKS_CDATA) { ssml_str = iks_cdata(ssml); } if (zstr(ssml_str)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Missing <document> CDATA/n"); return SWITCH_STATUS_FALSE; } if (zstr(output->renderer)) { /* FS must parse the SSML */ context->ssml = switch_mprintf("ssml://%s", ssml_str); } else { /* renderer will parse the SSML */ if (!zstr(output->headers) && !strncmp("unimrcp", output->renderer, 7)) { /* pass MRCP headers */ context->ssml = switch_mprintf("tts://%s||%s%s", output->renderer, output->headers, ssml_str); } else { context->ssml = switch_mprintf("tts://%s||%s", output->renderer, ssml_str); } } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Missing <speak>/n"); return SWITCH_STATUS_FALSE; } } if (switch_core_file_open(&context->fh, context->ssml, handle->channels, handle->samplerate, handle->flags, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Failed to open %s/n", context->ssml); goto top; } else { context->could_open = 1; } handle->samples = context->fh.samples; handle->format = context->fh.format; handle->sections = context->fh.sections; handle->seekable = context->fh.seekable; handle->speed = context->fh.speed; handle->vol = context->fh.vol; handle->offset_pos = context->fh.offset_pos; handle->interval = context->fh.interval; if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) { switch_set_flag(handle, SWITCH_FILE_NATIVE); } else { switch_clear_flag(handle, SWITCH_FILE_NATIVE); } return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例20: fileman_process_cmd/** * Process fileman command */static switch_status_t fileman_process_cmd(const char *cmd, switch_file_handle_t *fhp){ if (zstr(cmd)) { return SWITCH_STATUS_SUCCESS; } if (fhp) { struct fileman_file_context *context = (struct fileman_file_context *)fhp->private_info; if (!switch_test_flag(fhp, SWITCH_FILE_OPEN)) { return SWITCH_STATUS_FALSE; } if (!strncasecmp(cmd, "speed", 5)) { char *p; if ((p = strchr(cmd, ':'))) { p++; if (*p == '+' || *p == '-') { int step; if (!(step = atoi(p))) { if (*p == '+') { step = 1; } else { step = -1; } } fhp->speed += step; } else { int speed = atoi(p); fhp->speed = speed; } return SWITCH_STATUS_SUCCESS; } return SWITCH_STATUS_FALSE; } else if (!strncasecmp(cmd, "volume", 6)) { char *p; if ((p = strchr(cmd, ':'))) { p++; if (*p == '+' || *p == '-') { int step; if (!(step = atoi(p))) { if (*p == '+') { step = 1; } else { step = -1; } } fhp->vol += step; } else { int vol = atoi(p); fhp->vol = vol; } return SWITCH_STATUS_SUCCESS; } if (fhp->vol) { switch_normalize_volume(fhp->vol); } return SWITCH_STATUS_FALSE; } else if (!strcasecmp(cmd, "pause")) { switch_set_flag(fhp, SWITCH_FILE_PAUSE); return SWITCH_STATUS_SUCCESS; } else if (!strcasecmp(cmd, "resume")) { switch_clear_flag(fhp, SWITCH_FILE_PAUSE); return SWITCH_STATUS_SUCCESS; } else if (!strcasecmp(cmd, "stop")) { switch_set_flag(fhp, SWITCH_FILE_DONE); return SWITCH_STATUS_FALSE; } else if (!strcasecmp(cmd, "truncate")) { switch_core_file_truncate(fhp, 0); } else if (!strcasecmp(cmd, "restart")) { unsigned int pos = 0; fhp->speed = 0; switch_core_file_seek(fhp, &pos, 0, SEEK_SET); return SWITCH_STATUS_SUCCESS; } else if (!strncasecmp(cmd, "seek", 4)) { unsigned int samps = 0; unsigned int pos = 0; char *p; if ((p = strchr(cmd, ':'))) { p++; if (*p == '+' || *p == '-') { int step; int32_t target; if (!(step = atoi(p))) { if (*p == '+') { step = 1000; } else { step = -1000; } }//.........这里部分代码省略.........
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例21: channel_read_framestatic switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id){ switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; switch_status_t status = SWITCH_STATUS_FALSE; switch_mutex_t *mutex = NULL; void *pop = NULL; channel = switch_core_session_get_channel(session); switch_assert(channel != NULL); tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); if (!switch_test_flag(tech_pvt, TFLAG_LINKED)) { goto end; } *frame = NULL; if (!switch_channel_ready(channel)) { goto end; } switch_core_timer_next(&tech_pvt->timer); mutex = tech_pvt->mutex; switch_mutex_lock(mutex); if (switch_test_flag(tech_pvt, TFLAG_CLEAR)) { clear_queue(tech_pvt); switch_clear_flag(tech_pvt, TFLAG_CLEAR); } if (switch_queue_trypop(tech_pvt->frame_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) { if (tech_pvt->write_frame) { switch_frame_free(&tech_pvt->write_frame); } tech_pvt->write_frame = (switch_frame_t *) pop; tech_pvt->write_frame->codec = &tech_pvt->read_codec; *frame = tech_pvt->write_frame; tech_pvt->packet_count++; switch_clear_flag(tech_pvt->write_frame, SFF_CNG); tech_pvt->first_cng = 0; } else { *frame = &tech_pvt->cng_frame; tech_pvt->cng_frame.codec = &tech_pvt->read_codec; tech_pvt->cng_frame.datalen = tech_pvt->read_codec.implementation->decoded_bytes_per_packet; switch_set_flag((&tech_pvt->cng_frame), SFF_CNG); if (!tech_pvt->first_cng) { switch_yield(tech_pvt->read_codec.implementation->samples_per_packet); tech_pvt->first_cng = 1; } } if (*frame) { status = SWITCH_STATUS_SUCCESS; } else { status = SWITCH_STATUS_FALSE; } end: if (mutex) { switch_mutex_unlock(mutex); } return status;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:72,
示例22: SWITCH_DECLARE//.........这里部分代码省略......... } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "switch_ivr_menu_execute todo=[%d]/n", todo); switch (todo) { case SWITCH_IVR_ACTION_DIE: status = SWITCH_STATUS_FALSE; break; case SWITCH_IVR_ACTION_PLAYSOUND: status = switch_ivr_play_file(session, NULL, aptr, NULL); break; case SWITCH_IVR_ACTION_EXECMENU: if (!strcmp(aptr, menu->name)) { status = SWITCH_STATUS_SUCCESS; } else { reps = -1; status = switch_ivr_menu_execute(session, stack, aptr, obj); } break; case SWITCH_IVR_ACTION_EXECAPP: { switch_application_interface_t *application_interface; char *app_name; char *app_arg = NULL; status = SWITCH_STATUS_FALSE; if (!zstr(aptr)) { app_name = switch_core_session_strdup(session, aptr); if ((app_arg = strchr(app_name, ' '))) { *app_arg++ = '/0'; } if ((application_interface = switch_loadable_module_get_application_interface(app_name))) { switch_core_session_exec(session, application_interface, app_arg); UNPROTECT_INTERFACE(application_interface); status = SWITCH_STATUS_SUCCESS; } } } break; case SWITCH_IVR_ACTION_BACK: running = 0; status = SWITCH_STATUS_SUCCESS; break; case SWITCH_IVR_ACTION_TOMAIN: switch_set_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN); status = SWITCH_STATUS_BREAK; break; case SWITCH_IVR_ACTION_NOOP: status = SWITCH_STATUS_SUCCESS; break; default: switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Invalid TODO!/n"); break; } } } if (switch_test_flag(menu, SWITCH_IVR_MENU_FLAG_STACK)) { /* top level */ if (switch_test_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN)) { /* catch the fallback and recover */ switch_clear_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN); status = SWITCH_STATUS_SUCCESS; running = 1; continue; } } } if (!match) { if (*menu->buf) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "IVR menu '%s' caught invalid input '%s'/n", menu->name, menu->buf); if (menu->invalid_sound) { play_and_collect(session, menu, menu->invalid_sound, 0); } } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "IVR menu '%s' no input detected/n", menu->name); } errs++; /* breaks are ok too */ if (SWITCH_STATUS_IS_BREAK(status)) { status = SWITCH_STATUS_SUCCESS; } } } if (stack->stack_count == 1) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "exit-sound '%s'/n", menu->exit_sound); if (!zstr(menu->exit_sound)) { status = play_and_collect(session, menu, menu->exit_sound, 0); } } end: stack->stack_count--; return status;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:101,
注:本文中的switch_clear_flag函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ switch_core_codec_ready函数代码示例 C++ switch_channel_test_flag函数代码示例 |