您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ switch_core_session_get_channel函数代码示例

51自学网 2021-06-03 08:35:15
  C++
这篇教程C++ switch_core_session_get_channel函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中switch_core_session_get_channel函数的典型用法代码示例。如果您正苦于以下问题:C++ switch_core_session_get_channel函数的具体用法?C++ switch_core_session_get_channel怎么用?C++ switch_core_session_get_channel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了switch_core_session_get_channel函数的22个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: channel_receive_message

static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg){	switch_channel_t *channel;	private_t *tech_pvt;	channel = switch_core_session_get_channel(session);	switch_assert(channel != NULL);	tech_pvt = switch_core_session_get_private(session);	switch_assert(tech_pvt != NULL);	switch (msg->message_id) {	case SWITCH_MESSAGE_INDICATE_ANSWER:		t31_call_event(tech_pvt->modem->t31_state, AT_CALL_EVENT_CONNECTED);		modem_set_state(tech_pvt->modem, MODEM_STATE_CONNECTED);		mod_spandsp_indicate_data(session, SWITCH_FALSE, SWITCH_TRUE);		break;	case SWITCH_MESSAGE_INDICATE_PROGRESS:		t31_call_event(tech_pvt->modem->t31_state, AT_CALL_EVENT_CONNECTED);		modem_set_state(tech_pvt->modem, MODEM_STATE_CONNECTED);		mod_spandsp_indicate_data(session, SWITCH_FALSE, SWITCH_TRUE);		break;	case SWITCH_MESSAGE_INDICATE_RINGING:		break;	case SWITCH_MESSAGE_INDICATE_BRIDGE:		mod_spandsp_indicate_data(session, SWITCH_FALSE, SWITCH_TRUE);						break;	case SWITCH_MESSAGE_INDICATE_UNBRIDGE:		mod_spandsp_indicate_data(session, SWITCH_FALSE, SWITCH_TRUE);		break;	default:		break;	}	return SWITCH_STATUS_SUCCESS;}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:39,


示例2: channel_on_destroy

static switch_status_t channel_on_destroy(switch_core_session_t *session){    switch_channel_t *channel = NULL;    private_t *tech_pvt = NULL;    channel = switch_core_session_get_channel(session);    assert(channel != NULL);    tech_pvt = switch_core_session_get_private(session);    if (tech_pvt) {        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);        }    }    return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:22,


示例3: rayo_component_send_start

/** * Start execution of call output component * @param component to start * @param session the session to output to * @param output the output request * @param iq the original request */static iks *start_call_output(struct rayo_component *component, switch_core_session_t *session, iks *output, iks *iq){	switch_stream_handle_t stream = { 0 };	/* acknowledge command */	rayo_component_send_start(component, iq);	/* build playback command */	SWITCH_STANDARD_STREAM(stream);	stream.write_function(&stream, "{id=%s,session=%s,pause=%s",		RAYO_JID(component), switch_core_session_get_uuid(session),		OUTPUT_COMPONENT(component)->start_paused ? "true" : "false");	if (OUTPUT_COMPONENT(component)->max_time > 0) {		stream.write_function(&stream, ",timeout=%i", OUTPUT_COMPONENT(component)->max_time * 1000);	}	stream.write_function(&stream, "}fileman://rayo://%s", RAYO_JID(component));	if (switch_ivr_displace_session(session, stream.data, 0, "m") == SWITCH_STATUS_SUCCESS) {		RAYO_UNLOCK(component);	} else {		if (component->complete) {			/* component is already destroyed */			RAYO_UNLOCK(component);		} else {			/* need to destroy component */			if (OUTPUT_COMPONENT(component)->document) {				iks_delete(OUTPUT_COMPONENT(component)->document);			}			if (switch_channel_get_state(switch_core_session_get_channel(session)) >= CS_HANGUP) {				rayo_component_send_complete(component, COMPONENT_COMPLETE_HANGUP);			} else {				rayo_component_send_complete(component, COMPONENT_COMPLETE_ERROR);			}		}	}	switch_safe_free(stream.data);	return NULL;}
开发者ID:lzcykevin,项目名称:FreeSWITCH,代码行数:45,


示例4: SWITCH_DECLARE

SWITCH_DECLARE(switch_status_t) switch_limit_incr(const char *backend, switch_core_session_t *session, const char *realm, const char *resource, const int max, const int interval) {	switch_limit_interface_t *limit = NULL;	switch_channel_t *channel = NULL;	int status = SWITCH_STATUS_SUCCESS;		if (session) {		channel = switch_core_session_get_channel(session);	}	/* locate impl, call appropriate func */	if (!(limit = get_backend(backend))) {		switch_limit_log(session, SWITCH_LOG_ERROR, "Limit subsystem %s not found!/n", backend);		switch_goto_status(SWITCH_STATUS_GENERR, end);	}	switch_limit_log(session, SWITCH_LOG_INFO, "incr called: %s_%s max:%d, interval:%d/n",					  realm, resource, max, interval);		if ((status = limit->incr(session, realm, resource, max, interval)) == SWITCH_STATUS_SUCCESS) {		if (session) {			/* race condition? what if another leg is doing the same thing? */			const char *existing = switch_channel_get_variable(channel, LIMIT_BACKEND_VARIABLE);			if (existing) {				if (!strstr(existing, backend)) {					switch_channel_set_variable_printf(channel, LIMIT_BACKEND_VARIABLE, "%s,%s", existing, backend);				}			} else {				switch_channel_set_variable(channel, LIMIT_BACKEND_VARIABLE, backend);				switch_core_event_hook_add_state_change(session, limit_state_handler);			}		}	}		release_backend(limit);	end:	return status;}
开发者ID:moises-silva,项目名称:freeswitch,代码行数:38,


示例5: channel_receive_message

static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg){    switch_channel_t *channel;    private_t *tech_pvt;    channel = switch_core_session_get_channel(session);    assert(channel != NULL);    tech_pvt = (private_t *) switch_core_session_get_private(session);    assert(tech_pvt != NULL);    switch (msg->message_id) {    case SWITCH_MESSAGE_INDICATE_ANSWER:    {        channel_answer_channel(session);    }    break;    default:        break;    }    return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:23,


示例6: run_callback

static switch_status_t run_callback(switch_new_say_callback_t say_cb, char *tosay, switch_say_args_t *say_args, switch_core_session_t *session, char **rstr){	switch_say_file_handle_t *sh;	switch_status_t status = SWITCH_STATUS_FALSE;	switch_event_t *var_event = NULL;		if (session) {		switch_channel_t *channel = switch_core_session_get_channel(session);		switch_channel_get_variables(channel, &var_event);	}	switch_say_file_handle_create(&sh, say_args->ext, &var_event);		status = say_cb(sh, tosay, say_args);	if ((*rstr = switch_say_file_handle_detach_path(sh))) {		status = SWITCH_STATUS_SUCCESS;	}	switch_say_file_handle_destroy(&sh);	return status;}
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:23,


示例7: channel_on_init

/*    State methods they get called when the state changes to the specific state    returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next   so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.*/static switch_status_t channel_on_init(switch_core_session_t *session){	switch_channel_t *channel;	private_t *tech_pvt = NULL;	tech_pvt = switch_core_session_get_private(session);	assert(tech_pvt != NULL);	channel = switch_core_session_get_channel(session);	assert(channel != NULL);	switch_set_flag_locked(tech_pvt, TFLAG_IO);	/* Move channel's state machine to ROUTING. This means the call is trying	   to get from the initial start where the call because, to the point	   where a destination has been identified. If the channel is simply	   left in the initial state, nothing will happen. */	switch_channel_set_state(channel, CS_ROUTING);	switch_mutex_lock(globals.mutex);	globals.calls++;	switch_mutex_unlock(globals.mutex);	return SWITCH_STATUS_SUCCESS;}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:28,


示例8: channel_on_destroy

static switch_status_t channel_on_destroy(switch_core_session_t *session){	switch_channel_t *channel = NULL;	loopback_private_t *tech_pvt = NULL;	switch_event_t *vars;	channel = switch_core_session_get_channel(session);	switch_assert(channel != NULL);	tech_pvt = switch_core_session_get_private(session);	if ((vars = (switch_event_t *) switch_channel_get_private(channel, "__loopback_vars__"))) {		switch_channel_set_private(channel, "__loopback_vars__", NULL);		switch_event_destroy(&vars);	}		if (tech_pvt) {		switch_core_timer_destroy(&tech_pvt->timer);		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);		}		if (tech_pvt->write_frame) {			switch_frame_free(&tech_pvt->write_frame);		}		clear_queue(tech_pvt);	}	return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:37,


示例9: channel_kill_channel

static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig){	switch_channel_t *channel = NULL;	private_t *tech_pvt = 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);	switch (sig) {	case SWITCH_SIG_BREAK:		switch_set_flag_locked(tech_pvt, TFLAG_CNG);		switch_mutex_lock(tech_pvt->mutex);		if (tech_pvt->other_tech_pvt) {			switch_set_flag_locked(tech_pvt->other_tech_pvt, TFLAG_CNG);		}		switch_mutex_unlock(tech_pvt->mutex);		break;	case SWITCH_SIG_KILL:		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);		switch_clear_flag_locked(tech_pvt, TFLAG_LINKED);		switch_mutex_lock(tech_pvt->mutex);		if (tech_pvt->other_tech_pvt) {			switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_LINKED);		}		switch_mutex_unlock(tech_pvt->mutex);		break;	default:		break;	}	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL KILL/n", switch_channel_get_name(channel));	return SWITCH_STATUS_SUCCESS;}
开发者ID:gujun,项目名称:sscore,代码行数:37,


示例10: SWITCH_DECLARE

SWITCH_DECLARE(void) CoreSession::destroy(void){	this_check_void();		if (!allocated) {		return;	}	allocated = 0;	switch_safe_free(xml_cdr_text);	switch_safe_free(uuid);		switch_safe_free(tts_name);	switch_safe_free(voice_name);	if (session) {		if (!channel) {			channel = switch_core_session_get_channel(session);		}		if (channel) {			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, 							  "%s destroy/unlink session from object/n", switch_channel_get_name(channel));			switch_channel_set_private(channel, "CoreSession", NULL);			if (switch_channel_up(channel) && switch_test_flag(this, S_HUP) && !switch_channel_test_flag(channel, CF_TRANSFER)) {				switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);			}		}        switch_core_session_rwunlock(session);		session = NULL;		channel = NULL;    }	init_vars();	}
开发者ID:gujun,项目名称:sscore,代码行数:37,


示例11: channel_on_hangup

static switch_status_t channel_on_hangup(switch_core_session_t *session){	switch_channel_t *channel = NULL;	loopback_private_t *tech_pvt = NULL;	channel = switch_core_session_get_channel(session);	switch_assert(channel != NULL);	switch_channel_set_variable(channel, "is_loopback", "1");	tech_pvt = switch_core_session_get_private(session);	switch_assert(tech_pvt != NULL);	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP/n", switch_channel_get_name(channel));	switch_clear_flag_locked(tech_pvt, TFLAG_LINKED);	switch_mutex_lock(tech_pvt->mutex);	if (tech_pvt->other_tech_pvt) {		switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_LINKED);		if (tech_pvt->other_tech_pvt->session && tech_pvt->other_tech_pvt->session != tech_pvt->other_session) {			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "OTHER SESSION MISMATCH????/n");			tech_pvt->other_session = tech_pvt->other_tech_pvt->session;		}		tech_pvt->other_tech_pvt = NULL;	}	if (tech_pvt->other_session) {		switch_channel_hangup(tech_pvt->other_channel, switch_channel_get_cause(channel));		switch_core_session_rwunlock(tech_pvt->other_session);		tech_pvt->other_channel = NULL;		tech_pvt->other_session = NULL;	}	switch_mutex_unlock(tech_pvt->mutex);	return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:36,


示例12: switch_core_session_get_channel

static switch_event_t *get_extra_headers(oreka_session_t *oreka, oreka_recording_status_t status){	switch_event_t *extra_headers = NULL;	switch_channel_t *channel = NULL;	switch_core_session_t *session = oreka->session;	channel = switch_core_session_get_channel(session);	if (status == FS_OREKA_START) {		if (!oreka->invite_extra_headers) {			switch_event_create_subclass(&oreka->invite_extra_headers, SWITCH_EVENT_CLONE, NULL);			switch_assert(oreka->invite_extra_headers);			save_extra_headers(oreka->invite_extra_headers, channel);		}		extra_headers = oreka->invite_extra_headers;	} else if (status == FS_OREKA_STOP) {		if (!oreka->bye_extra_headers) {			switch_event_create_subclass(&oreka->bye_extra_headers, SWITCH_EVENT_CLONE, NULL);			switch_assert(oreka->bye_extra_headers);			save_extra_headers(oreka->bye_extra_headers, channel);		}		extra_headers = oreka->bye_extra_headers;	}	return extra_headers;}
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:24,


示例13: channel_receive_event

static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event){    const char *command = switch_event_get_header(event, "command");    switch_channel_t *channel = switch_core_session_get_channel(session);    crtp_private_t *tech_pvt = switch_core_session_get_private(session);    char *codec  = switch_event_get_header_nil(event, kCODEC);    char *szptime  = switch_event_get_header_nil(event, kPTIME);    char *szrate = switch_event_get_header_nil(event, kRATE);    char *szpt = switch_event_get_header_nil(event, kPT);    int ptime  = !zstr(szptime) ? atoi(szptime) : 0,		rate = !zstr(szrate) ? atoi(szrate) : 8000,		pt = !zstr(szpt) ? atoi(szpt) : 0;    if (!zstr(command) && !strcasecmp(command, "media_modify")) {        /* Compare parameters */        if (compare_var(event, channel, kREMOTEADDR) ||            compare_var(event, channel, kREMOTEPORT)) {		char *remote_addr = switch_event_get_header(event, kREMOTEADDR);		char *szremote_port = switch_event_get_header(event, kREMOTEPORT);		switch_port_t remote_port = !zstr(szremote_port) ? atoi(szremote_port) : 0;		const char *err;            switch_channel_set_variable(channel, kREMOTEADDR, remote_addr);            switch_channel_set_variable(channel, kREMOTEPORT, szremote_port);                        if (switch_rtp_set_remote_address(tech_pvt->rtp_session, remote_addr, remote_port, 0, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error setting RTP remote address: %s/n", err);            } else {                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set RTP remote: %s:%d/n", remote_addr, (int)remote_port);                tech_pvt->mode = RTP_SENDRECV;            }        }                if (compare_var(event, channel, kCODEC) ||            compare_var(event, channel, kPTIME) ||            compare_var(event, channel, kPT) ||	    compare_var(event, channel, kRATE)) {		/* Reset codec */		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Switching codec updating /n");		if (switch_core_codec_init(&tech_pvt->read_codec,					codec,					NULL,					rate,					ptime,					1,					/*SWITCH_CODEC_FLAG_ENCODE |*/ SWITCH_CODEC_FLAG_DECODE,					NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?/n");			goto fail;		} else {			if (switch_core_codec_init(&tech_pvt->write_codec,						codec,						NULL,						rate,						ptime,						1,						SWITCH_CODEC_FLAG_ENCODE /*| SWITCH_CODEC_FLAG_DECODE*/, 						NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?/n");				goto fail;			}		}		if (switch_core_session_set_read_codec(session, &tech_pvt->read_codec) != SWITCH_STATUS_SUCCESS) {			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't set read codec?/n");			goto fail;		}		if (switch_core_session_set_write_codec(session, &tech_pvt->write_codec) != SWITCH_STATUS_SUCCESS) {			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't set write codec?/n");			goto fail;		}		switch_rtp_set_default_payload(tech_pvt->rtp_session, pt);		//switch_rtp_set_recv_pt(tech_pvt->rtp_session, pt);	}                if (compare_var(event, channel, kRFC2833PT)) {            const char *szpt = switch_channel_get_variable(channel, kRFC2833PT);            int pt = !zstr(szpt) ? atoi(szpt) : 0;                        switch_channel_set_variable(channel, kRFC2833PT, szpt);            switch_rtp_set_telephony_event(tech_pvt->rtp_session, pt);        }        } else {        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Received unknown command [%s] in event./n", !command ? "null" : command);    }    return SWITCH_STATUS_SUCCESS;fail:     if (tech_pvt) {        if (tech_pvt->read_codec.implementation) {			switch_core_codec_destroy(&tech_pvt->read_codec);		}		//.........这里部分代码省略.........
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:101,


示例14: channel_outgoing_channel

static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,													switch_caller_profile_t *outbound_profile,													switch_core_session_t **new_session, 													switch_memory_pool_t **pool,													switch_originate_flag_t flags, switch_call_cause_t *cancel_cause){    switch_channel_t *channel;    char name[128];    crtp_private_t *tech_pvt = NULL;        switch_caller_profile_t *caller_profile;    switch_rtp_flag_t rtp_flags[SWITCH_RTP_FLAG_INVALID] = {0};        const char *err;        const char  *local_addr = switch_event_get_header_nil(var_event, kLOCALADDR),                *szlocal_port = switch_event_get_header_nil(var_event, kLOCALPORT),                *remote_addr = switch_event_get_header_nil(var_event, kREMOTEADDR),                *szremote_port = switch_event_get_header_nil(var_event, kREMOTEPORT),                *codec  = switch_event_get_header_nil(var_event, kCODEC),                *szptime  = switch_event_get_header_nil(var_event, kPTIME),                //*mode  = switch_event_get_header_nil(var_event, kMODE),                //*szrfc2833_pt = switch_event_get_header_nil(var_event, kRFC2833PT),                *szrate = switch_event_get_header_nil(var_event, kRATE),                *szpt = switch_event_get_header_nil(var_event, kPT);            switch_port_t local_port = !zstr(szlocal_port) ? atoi(szlocal_port) : 0,                 remote_port = !zstr(szremote_port) ? atoi(szremote_port) : 0;        int ptime  = !zstr(szptime) ? atoi(szptime) : 0,        //rfc2833_pt = !zstr(szrfc2833_pt) ? atoi(szrfc2833_pt) : 0,        rate = !zstr(szrate) ? atoi(szrate) : 8000,        pt = !zstr(szpt) ? atoi(szpt) : 0;            if (            ((zstr(remote_addr) || remote_port == 0) && (zstr(local_addr) || local_port == 0)) ||            zstr(codec) ||            zstr(szpt)) {                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required arguments/n");        goto fail;    }            if (!(*new_session = switch_core_session_request(crtp.endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, 0, pool))) {        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't request session./n");        goto fail;    }        channel = switch_core_session_get_channel(*new_session);        tech_pvt = switch_core_session_alloc(*new_session, sizeof *tech_pvt);    tech_pvt->session = *new_session;    tech_pvt->channel = channel;    tech_pvt->local_address = switch_core_session_strdup(*new_session, local_addr);    tech_pvt->local_port = local_port;    tech_pvt->remote_address = switch_core_session_strdup(*new_session, remote_addr);    tech_pvt->remote_port = remote_port;    tech_pvt->ptime = ptime;    tech_pvt->agreed_pt = pt;    tech_pvt->dtmf_type = DTMF_2833; /* XXX */        if (zstr(local_addr) || local_port == 0) {        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "The local address and port must be set/n");        goto fail;    } else if (zstr(remote_addr) || remote_port == 0) {        tech_pvt->mode = RTP_RECVONLY;    } else {        tech_pvt->mode = RTP_SENDRECV;    }        switch_core_session_set_private(*new_session, tech_pvt);        caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);    switch_channel_set_caller_profile(channel, caller_profile);            snprintf(name, sizeof(name), "rtp/%s", outbound_profile->destination_number);	switch_channel_set_name(channel, name);        switch_channel_set_state(channel, CS_INIT);	if (switch_core_codec_init(&tech_pvt->read_codec,							   codec,							   NULL,							   rate,							   ptime,							   1,							   /*SWITCH_CODEC_FLAG_ENCODE |*/ SWITCH_CODEC_FLAG_DECODE,							   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?/n");        goto fail;	} else {		if (switch_core_codec_init(&tech_pvt->write_codec,								   codec,								   NULL,								   rate,								   ptime,								   1,//.........这里部分代码省略.........
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:101,


示例15: SWITCH_DECLARE

SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(switch_core_session_t *session, switch_codec_t *codec){	switch_event_t *event;	switch_channel_t *channel = switch_core_session_get_channel(session);	char tmp[30];	switch_status_t status = SWITCH_STATUS_SUCCESS;	int changed_read_codec = 0;	switch_mutex_lock(session->codec_read_mutex);	if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {		codec = NULL;	}	if (codec) {		/* set real_read_codec and read_codec */		if (!session->real_read_codec) {			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec set to %s:%d/n",							  switch_channel_get_name(session->channel), codec->implementation->iananame, codec->implementation->ianacode);			session->read_codec = session->real_read_codec = codec;			changed_read_codec = 1;			if (codec->implementation) {				session->read_impl = *codec->implementation;				session->real_read_impl = *codec->implementation;			} else {				memset(&session->read_impl, 0, sizeof(session->read_impl));			}		} else { /* replace real_read_codec */			switch_codec_t *cur_codec;			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec replaced with %s:%d/n",							  switch_channel_get_name(session->channel), codec->implementation->iananame, codec->implementation->ianacode);			/* Set real_read_codec to front of the list of read_codecs */			cur_codec = session->read_codec;			while (cur_codec != NULL) {				if (cur_codec->next == session->real_read_codec) {					cur_codec->next = codec;					break;				}				cur_codec = cur_codec->next;			}			session->real_read_codec = codec;			/* set read_codec with real_read_codec if it no longer is ready */			if (!switch_core_codec_ready(session->read_codec)) {				session->read_codec = codec;				changed_read_codec = 1;				if (codec->implementation) {					session->read_impl = *codec->implementation;					session->real_read_impl = *codec->implementation;				} else {					memset(&session->read_impl, 0, sizeof(session->read_impl));				}			}		}		/* force media bugs to copy the read codec from the next frame */		switch_thread_rwlock_wrlock(session->bug_rwlock);		if (switch_core_codec_ready(&session->bug_codec)) {			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Destroying BUG Codec %s:%d/n",				session->bug_codec.implementation->iananame, session->bug_codec.implementation->ianacode);			switch_core_codec_destroy(&session->bug_codec);		}		switch_thread_rwlock_unlock(session->bug_rwlock);	} else {		status = SWITCH_STATUS_FALSE;		goto end;	}	if (changed_read_codec && session->read_codec && session->read_impl.decoded_bytes_per_packet) {		if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {			switch_channel_event_set_data(session->channel, event);			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_impl.actual_samples_per_second);			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-bit-rate", "%d", session->read_impl.bits_per_second);			if (session->read_impl.actual_samples_per_second != session->read_impl.samples_per_second) {				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);			}			switch_event_fire(&event);		}		switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);		switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);		switch_channel_set_variable(channel, "read_rate", tmp);		session->raw_read_frame.codec = session->read_codec;		session->raw_write_frame.codec = session->read_codec;		session->enc_read_frame.codec = session->read_codec;		session->enc_write_frame.codec = session->read_codec;	}  end:	if (session->read_codec) {		switch_channel_set_flag(channel, CF_MEDIA_SET);	}	switch_mutex_unlock(session->codec_read_mutex);	return status;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:98,


示例16: hu_say_time

static switch_status_t hu_say_time(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args){	int32_t t;	switch_time_t target = 0, target_now = 0;	switch_time_exp_t tm, tm_now;	uint8_t say_date = 0, say_time = 0, say_year = 0, say_month = 0, say_dow = 0, say_day = 0, say_yesterday = 0, say_today = 0;	switch_channel_t *channel = switch_core_session_get_channel(session);	const char *tz = switch_channel_get_variable(channel, "timezone");	if (say_args->type == SST_TIME_MEASUREMENT) {		int64_t hours = 0;		int64_t minutes = 0;		int64_t seconds = 0;		int64_t r = 0;		if (strchr(tosay, ':')) {			char *tme = switch_core_session_strdup(session, tosay);			char *p;			if ((p = strrchr(tme, ':'))) {				*p++ = '/0';				seconds = atoi(p);				if ((p = strchr(tme, ':'))) {					*p++ = '/0';					minutes = atoi(p);					if (tme) {						hours = atoi(tme);					}				} else {					minutes = atoi(tme);				}			}		} else {			if ((seconds = atol(tosay)) <= 0) {				seconds = (int64_t) switch_epoch_time_now(NULL);			}			if (seconds >= 60) {				minutes = seconds / 60;				r = seconds % 60;				seconds = r;			}			if (minutes >= 60) {				hours = minutes / 60;				r = minutes % 60;				minutes = r;			}		}		if (hours) {			say_num(hours, SSM_PRONOUNCED);			say_file("time/hour.wav");		} else {			say_file("digits/0.wav");			say_file("time/hour.wav");		}		if (minutes) {			say_num(minutes, SSM_PRONOUNCED);			say_file("time/minute.wav");		} else {			say_file("digits/0.wav");			say_file("time/minute.wav");		}		if (seconds) {			say_num(seconds, SSM_PRONOUNCED);			say_file("time/second.wav");		} else {			say_file("digits/0.wav");			say_file("time/second.wav");		}		return SWITCH_STATUS_SUCCESS;	}	if ((t = atol(tosay)) > 0) {		target = switch_time_make(t, 0);		target_now = switch_micro_time_now();	} else {		target = switch_micro_time_now();		target_now = switch_micro_time_now();	}	if (tz) {		int check = atoi(tz);		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Timezone is [%s]/n", tz);		if (check) {			switch_time_exp_tz(&tm, target, check);			switch_time_exp_tz(&tm_now, target_now, check);		} else {			switch_time_exp_tz_name(tz, &tm, target);			switch_time_exp_tz_name(tz, &tm_now, target_now);		}	} else {		switch_time_exp_lt(&tm, target);		switch_time_exp_lt(&tm_now, target_now);	}//.........这里部分代码省略.........
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:101,


示例17: my_on_reporting

static switch_status_t my_on_reporting(switch_core_session_t *session){	switch_status_t status = SWITCH_STATUS_SUCCESS;	switch_channel_t *channel = switch_core_session_get_channel(session);	switch_event_header_t *hi;	switch_caller_profile_t *caller_profile;	switch_app_log_t *app_log;	bson cdr;	int is_b;	char *tmp;	if (globals.shutdown) {		return SWITCH_STATUS_SUCCESS;	}	is_b = channel && switch_channel_get_originator_caller_profile(channel);	if (!globals.log_b && is_b) {		const char *force_cdr = switch_channel_get_variable(channel, SWITCH_FORCE_PROCESS_CDR_VARIABLE);		if (!switch_true(force_cdr)) {			return SWITCH_STATUS_SUCCESS;		}	}	bson_init(&cdr);	/* Channel data */	bson_append_start_object(&cdr, "channel_data");	bson_append_string(&cdr, "state", switch_channel_state_name(switch_channel_get_state(channel)));	bson_append_string(&cdr, "direction", switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");	bson_append_int(&cdr, "state_number", switch_channel_get_state(channel));	if ((tmp = switch_channel_get_flag_string(channel))) {		bson_append_string(&cdr, "flags", tmp);		free(tmp);	}	if ((tmp = switch_channel_get_cap_string(channel))) {		bson_append_string(&cdr, "caps", tmp);		free(tmp);	}	bson_append_finish_object(&cdr);				/* channel_data */	/* Channel variables */	bson_append_start_object(&cdr, "variables");	if ((hi = switch_channel_variable_first(channel))) {		for (; hi; hi = hi->next) {			if (!zstr(hi->name) && !zstr(hi->value)) {				bson_append_string(&cdr, hi->name, hi->value);			}		}		switch_channel_variable_last(channel);	}	bson_append_finish_object(&cdr);				/* variables */	/* App log */	if ((app_log = switch_core_session_get_app_log(session))) {		switch_app_log_t *ap;		bson_append_start_object(&cdr, "app_log");		for (ap = app_log; ap; ap = ap->next) {			bson_append_start_object(&cdr, "application");			bson_append_string(&cdr, "app_name", ap->app);			bson_append_string(&cdr, "app_data", ap->arg);			bson_append_long(&cdr, "app_stamp", ap->stamp);			bson_append_finish_object(&cdr);		/* application */		}		bson_append_finish_object(&cdr);			/* app_log */	}	/* Callflow */	caller_profile = switch_channel_get_caller_profile(channel);	while (caller_profile) {		bson_append_start_object(&cdr, "callflow");		if (!zstr(caller_profile->dialplan)) {			bson_append_string(&cdr, "dialplan", caller_profile->dialplan);		}		if (!zstr(caller_profile->profile_index)) {			bson_append_string(&cdr, "profile_index", caller_profile->profile_index);		}		if (caller_profile->caller_extension) {			switch_caller_application_t *ap;			bson_append_start_object(&cdr, "extension");			bson_append_string(&cdr, "name", caller_profile->caller_extension->extension_name);			bson_append_string(&cdr, "number", caller_profile->caller_extension->extension_number);			if (caller_profile->caller_extension->current_application) {				bson_append_string(&cdr, "current_app", caller_profile->caller_extension->current_application->application_name);			}//.........这里部分代码省略.........
开发者ID:vkrikun,项目名称:freeswitch,代码行数:101,


示例18: my_on_reporting

static switch_status_t my_on_reporting(switch_core_session_t *session){	switch_channel_t *channel = switch_core_session_get_channel(session);	switch_status_t status = SWITCH_STATUS_SUCCESS;	const char *log_dir = NULL, *accountcode = NULL, *a_template_str = NULL, *g_template_str = NULL;	char *log_line, *path = NULL;	if (globals.shutdown) {		return SWITCH_STATUS_SUCCESS;	}	if (!((globals.legs & CDR_LEG_A) && (globals.legs & CDR_LEG_B))) {		if ((globals.legs & CDR_LEG_A)) {			if (switch_channel_get_originator_caller_profile(channel)) {				return SWITCH_STATUS_SUCCESS;			}		} else {			if (switch_channel_get_originatee_caller_profile(channel)) {				return SWITCH_STATUS_SUCCESS;			}		}	}	if (!(log_dir = switch_channel_get_variable(channel, "cdr_csv_base"))) {		log_dir = globals.log_dir;	}	if (switch_dir_make_recursive(log_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s/n", log_dir);		return SWITCH_STATUS_FALSE;	}	if (globals.debug) {		switch_event_t *event;		if (switch_event_create_plain(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {			char *buf;			switch_channel_event_set_data(channel, event);			switch_event_serialize(event, &buf, SWITCH_FALSE);			switch_assert(buf);			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "CHANNEL_DATA:/n%s/n", buf);			switch_event_destroy(&event);			free(buf);		}	}	g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template);	if ((accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) {		a_template_str = (const char *) switch_core_hash_find(globals.template_hash, accountcode);	}	if (!g_template_str) {		g_template_str =			"/"${accountcode}/",/"${caller_id_number}/",/"${destination_number}/",/"${context}/",/"${caller_id}/",/"${channel_name}/",/"${bridge_channel}/",/"${last_app}/",/"${last_arg}/",/"${start_stamp}/",/"${answer_stamp}/",/"${end_stamp}/",/"${duration}/",/"${billsec}/",/"${hangup_cause}/",/"${amaflags}/",/"${uuid}/",/"${userfield}/";";	}	if (!a_template_str) {		a_template_str = g_template_str;	}	log_line = switch_channel_expand_variables(channel, a_template_str);	if ((accountcode) && (!globals.masterfileonly)) {		path = switch_mprintf("%s%s%s.csv", log_dir, SWITCH_PATH_SEPARATOR, accountcode);		assert(path);		write_cdr(path, log_line);		free(path);	}	if (g_template_str != a_template_str) {		if (log_line != a_template_str) {			switch_safe_free(log_line);		}		log_line = switch_channel_expand_variables(channel, g_template_str);	}	if (!log_line) {		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating cdr/n");		return SWITCH_STATUS_FALSE;	}	path = switch_mprintf("%s%sMaster.csv", log_dir, SWITCH_PATH_SEPARATOR);	assert(path);	write_cdr(path, log_line);	free(path);	if (log_line != g_template_str) {		free(log_line);	}	return status;}
开发者ID:kgrofelnik,项目名称:mod_portaudio-endpoints,代码行数:93,


示例19: run_callback

static switch_status_t run_callback(switch_new_say_callback_ru_t say_cb, char *tosay, switch_say_args_t *say_args, switch_core_session_t *session, char **rstr){        switch_say_file_handle_t *sh;        switch_status_t status = SWITCH_STATUS_FALSE;        switch_event_t *var_event = NULL;        const char *cases=NULL;        const char *gender=NULL;        const char *currency=NULL;	say_opt_t say_opt;	say_opt.cases=0;	say_opt.gender=0;	say_opt.currency=0;        if (session) {                switch_channel_t *channel = switch_core_session_get_channel(session);                switch_channel_get_variables(channel, &var_event);// проверяем не заданы ли канальные переменные род, падеж, валюта                gender = switch_channel_get_variable(channel, "gender");                cases = switch_channel_get_variable(channel, "cases");                currency = switch_channel_get_variable(channel, "currency");                //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say!!!  %s  %s   %s !/n",gender, cases,currency);                if (cases) {		    //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say!!!  %s!/n", cases);                		    if ((strcmp(cases,"nominativus")==0) || (strcmp(cases,"именительный")==0)) {			say_opt.cases=(cases_t)0;		    }		    if ((strcmp(cases,"genitivus")==0) || (strcmp(cases,"родительный")==0)) {			say_opt.cases=(cases_t)1;		    }		    if ((strcmp(cases,"dativus")==0) || (strcmp(cases,"дательный")==0)) {			say_opt.cases=(cases_t)2;		    }		    if ((strcmp(cases,"accusativus_a")==0) || (strcmp(cases,"винительный_о")==0)) {			say_opt.cases=(cases_t)3;		    }		    if ((strcmp(cases,"accusativus_i")==0) || (strcmp(cases,"винительный_н")==0)) {			say_opt.cases=(cases_t)4;		    }		    if ((strcmp(cases,"instrumentalis")==0) || (strcmp(cases,"творительный")==0)) {			say_opt.cases=(cases_t)5;		    }		    if ((strcmp(cases,"prepositive")==0) || (strcmp(cases,"предложный")==0)) {			say_opt.cases=(cases_t)6;		    }		}                if (gender) {		    //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say!!!  %s!/n", gender);                		    if ((strcmp(gender,"male")==0) || (strcmp(gender,"мужской")==0)) {			say_opt.gender=(say_gender_t)0;		    }		    if ((strcmp(gender,"it")==0) || (strcmp(gender,"средний")==0)) {			say_opt.gender=(say_gender_t)1;		    }		    if ((strcmp(gender,"female")==0) || (strcmp(gender,"женский")==0)) {			say_opt.gender=(say_gender_t)2;		    }		    if ((strcmp(gender,"plural")==0) || (strcmp(gender,"множественное")==0)) {			say_opt.gender=(say_gender_t)3;		    }		    if ((strcmp(gender,"male_h")==0) || (strcmp(gender,"мужской_порядковый")==0)) {			say_opt.gender=(say_gender_t)4;		    }		    if ((strcmp(gender,"it_h")==0) || (strcmp(gender,"средний_порядковый")==0)) {			say_opt.gender=(say_gender_t)5;		    }		    if ((strcmp(gender,"female_h")==0) || (strcmp(gender,"женский_порядковый")==0)) {			say_opt.gender=(say_gender_t)6;		    }		    if ((strcmp(gender,"plural_h")==0) || (strcmp(gender,"множественное_порядковый")==0)) {			say_opt.gender=(say_gender_t)7;		    }                		}                if (currency) {		    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say!!!  %s!/n", currency);                		    if ((strcmp(currency,"ruble")==0) || (strcmp(currency,"рубль")==0)) {			say_opt.currency=(currency_t)0;//			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "rul!!!  /n");					    }		    if ((strcmp(currency,"dollar")==0) || (strcmp(currency,"доллар")==0)) {//			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "dollar!!!  !/n");			say_opt.currency=(currency_t)1;		    }		}		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say!!!  %s!   say_opt.gender=%d   say_opt.cases=%d/n", tosay,say_opt.gender,say_opt.cases);                                                                                	}        switch_say_file_handle_create(&sh, say_args->ext, &var_event);//запуск ru_ip,ru_say_money ...        status = say_cb(sh, tosay, say_args,&say_opt);        if ((*rstr = switch_say_file_handle_detach_path(sh))) {                status = SWITCH_STATUS_SUCCESS;        }        switch_say_file_handle_destroy(&sh);//.........这里部分代码省略.........
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:101,


示例20: teletone_generate

static JSBool teletone_generate(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval){	struct teletone_obj *tto = JS_GetPrivate(cx, obj);	int32 loops = 0;	if (argc > 0) {		char *script;		switch_core_session_t *session;		switch_frame_t write_frame = { 0 };		unsigned char *fdata[1024];		switch_frame_t *read_frame;		switch_channel_t *channel;		if (argc > 1) {			if (!JS_ValueToInt32(cx, argv[1], &loops)) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Convert to INT/n");				return JS_FALSE;			}			loops--;		}		if (tto->audio_buffer) {			switch_buffer_zero(tto->audio_buffer);		}		tto->ts.debug = 1;		tto->ts.debug_stream = switch_core_get_console();		script = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));		teletone_run(&tto->ts, script);		session = tto->session;		write_frame.codec = &tto->codec;		write_frame.data = fdata;		write_frame.buflen = sizeof(fdata);		channel = switch_core_session_get_channel(session);		if (tto->timer) {			switch_core_service_session(session);		}		if (loops) {			switch_buffer_set_loops(tto->audio_buffer, loops);		}		for (;;) {			if (switch_test_flag(tto, TTF_DTMF)) {				char dtmf[128];				char *ret;				if (switch_channel_has_dtmf(channel)) {					uintN aargc = 0;					jsval aargv[4];					switch_channel_dequeue_dtmf_string(channel, dtmf, sizeof(dtmf));					aargv[aargc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dtmf));					JS_CallFunction(cx, obj, tto->function, aargc, aargv, &tto->ret);					ret = JS_GetStringBytes(JS_ValueToString(cx, tto->ret));					if (strcmp(ret, "true") && strcmp(ret, "undefined")) {						*rval = tto->ret;						return JS_TRUE;					}				}			}			if (tto->timer) {				if (switch_core_timer_next(tto->timer) != SWITCH_STATUS_SUCCESS) {					break;				}			} else {				switch_status_t status;				status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);				if (!SWITCH_READ_ACCEPTABLE(status)) {					break;				}			}			if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(tto->audio_buffer,																		  fdata, write_frame.codec->implementation->decoded_bytes_per_packet)) <= 0) {				break;			}			write_frame.samples = write_frame.datalen / 2;			if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bad Write/n");				break;			}		}		if (tto->timer) {			switch_core_thread_session_end(session);		}		return JS_TRUE;	}	return JS_FALSE;}
开发者ID:PauloFer1,项目名称:FreeSWITCH,代码行数:100,


示例21: start_call_record

/** * Start recording call * @param session the session to record * @param record the record component */static int start_call_record(switch_core_session_t *session, struct rayo_component *component){	struct record_component *record_component = RECORD_COMPONENT(component);	switch_channel_t *channel = switch_core_session_get_channel(session);	int max_duration_sec = 0;	switch_channel_set_variable(channel, "RECORD_HANGUP_ON_ERROR", "false");	switch_channel_set_variable(channel, "RECORD_TOGGLE_ON_REPEAT", "");	switch_channel_set_variable(channel, "RECORD_CHECK_BRIDGE", "");	switch_channel_set_variable(channel, "RECORD_MIN_SEC", "0");	switch_channel_set_variable(channel, "RECORD_STEREO", "");	switch_channel_set_variable(channel, "RECORD_READ_ONLY", "");	switch_channel_set_variable(channel, "RECORD_WRITE_ONLY", "");	switch_channel_set_variable(channel, "RECORD_APPEND", "");	switch_channel_set_variable(channel, "RECORD_WRITE_OVER", "true");	switch_channel_set_variable(channel, "RECORD_ANSWER_REQ", "");	switch_channel_set_variable(channel, "RECORD_SILENCE_THRESHOLD", "200");	if (record_component->initial_timeout > 0) {		switch_channel_set_variable_printf(channel, "RECORD_INITIAL_TIMEOUT_MS", "%i", record_component->initial_timeout);	} else {		switch_channel_set_variable(channel, "RECORD_INITIAL_TIMEOUT_MS", "");	}	if (record_component->final_timeout > 0) {		switch_channel_set_variable_printf(channel, "RECORD_FINAL_TIMEOUT_MS", "%i", record_component->final_timeout);	} else {		switch_channel_set_variable(channel, "RECORD_FINAL_TIMEOUT_MS", "");	}	/* allow dialplan override for these variables */	//switch_channel_set_variable(channel, "RECORD_PRE_BUFFER_FRAMES", "");	//switch_channel_set_variable(channel, "record_sample_rate", "");	//switch_channel_set_variable(channel, "enable_file_write_buffering", "");	/* max duration attribute is in milliseconds- convert to seconds */	if (record_component->max_duration > 0) {		max_duration_sec = ceil((double)(record_component->max_duration - record_component->duration_ms) / 1000.0);	}	if (!strcmp(record_component->direction, "duplex")) {		if (!record_component->mix) {			/* STEREO */			switch_channel_set_variable(channel, "RECORD_STEREO", "true");		} /* else MONO (default) */	} else if (!strcmp(record_component->direction, "send")) {		/* record audio sent from the caller */		switch_channel_set_variable(channel, "RECORD_READ_ONLY", "true");	} else if (!strcmp(record_component->direction, "recv")) {		/* record audio received by the caller */		switch_channel_set_variable(channel, "RECORD_WRITE_ONLY", "true");	};	if (record_component->start_beep) {		switch_ivr_displace_session(session, RECORD_BEEP, 0, "");		record_component->start_time = switch_micro_time_now();	}	if (switch_ivr_record_session(session, (char *)RAYO_ID(component), max_duration_sec, NULL) == SWITCH_STATUS_SUCCESS) {		switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Recording started: file = %s/n", RAYO_ID(component));		return 1;	}	return 0;}
开发者ID:benlangfeld,项目名称:FreeSWITCH,代码行数:67,


示例22: do_telecast

void 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,



注:本文中的switch_core_session_get_channel函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ switch_core_session_get_private函数代码示例
C++ switch_core_new_memory_pool函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。