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

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

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

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

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

示例1: while

static void *torture_thread(switch_thread_t *thread, void *obj){	int y = 0;	int z = 0;	switch_core_thread_session_t *ts = obj;	switch_event_t *event;	z = THREADS++;	while (THREADS > 0) {		int x;		for (x = 0; x < 1; x++) {			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_COOL) == SWITCH_STATUS_SUCCESS) {				switch_event_add_header(event, "event_info", "hello world %d %d", z, y++);				switch_event_fire(&event);			}		}		switch_yield(100000);	}	if (ts->pool) {		switch_memory_pool_t *pool = ts->pool;		switch_core_destroy_memory_pool(&pool);	}	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Thread Ended/n");}
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:27,


示例2: launch_read_stream_thread

static void launch_read_stream_thread(shout_context_t *context){	switch_thread_t *thread;	switch_threadattr_t *thd_attr = NULL;	int sanity = 10;	size_t used;	context->thread_running = 1;	switch_threadattr_create(&thd_attr, context->memory_pool);	switch_threadattr_detach_set(thd_attr, 1);	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);	switch_thread_create(&thread, thd_attr, read_stream_thread, context, context->memory_pool);	while (context->thread_running && --sanity) {		/* at least 1s of audio and up to 5s initialize */		switch_mutex_lock(context->audio_mutex);		used = switch_buffer_inuse(context->audio_buffer);		switch_mutex_unlock(context->audio_mutex);		if (used >= (2 * context->samplerate)) {			break;		}		switch_yield(500000);	}}
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:26,


示例3: SWITCH_DECLARE

SWITCH_DECLARE(void) switch_nat_thread_stop(void){	/* don't do anything if no thread ptr */	if (!nat_thread_p) {		return;	}	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping NAT Task Thread/n");	if (nat_globals_perm.running == 1) {		int sanity = 0;		switch_status_t st;		nat_globals_perm.running = -1;		switch_thread_join(&st, nat_thread_p);		while (nat_globals_perm.running) {			switch_yield(1000000);	/* can take up to 5s for the thread to terminate, so wait for 10 */			if (++sanity > 10) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out waiting for NAT Task Thread to stop/n");				break;			}		}	}	nat_thread_p = NULL;}
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:26,


示例4: spool_cdr

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


示例5: vlc_file_close

static switch_status_t vlc_file_close(switch_file_handle_t *handle){	vlc_file_context_t *context = handle->private_info;	int sanity = 0;			context->playing = 0;		/* The clients need to empty the last of the audio buffer */	while ( switch_buffer_inuse(context->audio_buffer) > 0 ) {		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VLC waiting to close the files: %d /n", (int) switch_buffer_inuse(context->audio_buffer));		switch_yield(500000);		if (++sanity > 10) {			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Giving up waiting for client to empty the audio buffer/n");			break;		}	}	/* Let the clients get the last of the audio stream */	sanity = 0;	while ( 3 == libvlc_media_get_state(context->m) ) {		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VLC waiting for clients: %d /n", libvlc_media_get_state(context->m));		switch_yield(500000);                 if (++sanity > 10) {                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Giving up waiting for client to get the last of the audio stream/n");                        break;		}	}	if( context->mp ) 		libvlc_media_player_stop(context->mp);		if( context->m ) 		libvlc_media_release(context->m);		if ( context->inst_out != NULL )		libvlc_release(context->inst_out);	return SWITCH_STATUS_SUCCESS;}
开发者ID:utkarsh301994,项目名称:localhost,代码行数:39,


示例6: SWITCH_DECLARE

SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock_timeout(switch_thread_rwlock_t *rwlock, int timeout){	int sanity = timeout * 2;	while (sanity) {		if (switch_thread_rwlock_trywrlock(rwlock) == SWITCH_STATUS_SUCCESS) {			return SWITCH_STATUS_SUCCESS;		}		sanity--;		switch_yield(500000);	}	return SWITCH_STATUS_FALSE;}
开发者ID:gujun,项目名称:sscore,代码行数:14,


示例7: do_reopen

static void do_reopen(cdr_fd_t *fd){	int x = 0;	if (fd->fd > -1) {		close(fd->fd);		fd->fd = -1;	}	for (x = 0; x < 10; x++) {		if ((fd->fd = open(fd->path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) > -1) {			fd->bytes = fd_size(fd->fd);			break;		}		switch_yield(100000);	}}
开发者ID:kgrofelnik,项目名称:mod_portaudio-endpoints,代码行数:17,


示例8: switch_core_standard_on_reset

static void switch_core_standard_on_reset(switch_core_session_t *session){	switch_channel_set_variable(session->channel, "call_uuid", switch_core_session_get_uuid(session));	switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard RESET/n", switch_channel_get_name(session->channel));	if (switch_channel_test_flag(session->channel, CF_RECOVERING_BRIDGE)) {		switch_core_session_t *other_session = NULL;		const char *uuid = switch_core_session_get_uuid(session);		if (switch_channel_test_flag(session->channel, CF_BRIDGE_ORIGINATOR)) {			const char *other_uuid = switch_channel_get_partner_uuid(session->channel);			int x = 0;			if (other_uuid) {				for (x = 0; other_session == NULL && x < 20; x++) {					if (!switch_channel_up(session->channel)) {						break;					}					other_session = switch_core_session_locate(other_uuid);					switch_yield(100000);				}			}			if (other_session) {				switch_channel_t *other_channel = switch_core_session_get_channel(other_session);				switch_channel_clear_flag(session->channel, CF_BRIDGE_ORIGINATOR);				switch_channel_wait_for_state_timeout(other_channel, CS_RESET, 5000);				switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 2000, NULL);				if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) && switch_channel_test_flag(other_channel, CF_PROXY_MODE)) {					switch_ivr_signal_bridge(session, other_session);				} else {					switch_ivr_uuid_bridge(uuid, other_uuid);				}				switch_core_session_rwunlock(other_session);			}		}		switch_channel_clear_flag(session->channel, CF_RECOVERING_BRIDGE);	}}
开发者ID:odmanV2,项目名称:freecenter,代码行数:43,


示例9: SWITCH_DECLARE

SWITCH_DECLARE(void) switch_scheduler_task_thread_stop(void){	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping Task Thread/n");	if (globals.task_thread_running == 1) {		int sanity = 0;		switch_status_t st;		globals.task_thread_running = -1;		switch_thread_join(&st, task_thread_p);		while (globals.task_thread_running) {			switch_yield(100000);			if (++sanity > 10) {				break;			}		}	}}
开发者ID:bodji,项目名称:freeswitch,代码行数:19,


示例10: deactivate_modems

static void deactivate_modems(void){	int max = globals.SOFT_MAX_MODEMS;    int x;		switch_mutex_lock(globals.mutex);    for(x = 0; x < max; x++) {		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,   "Stopping Modem SLOT %d/n", x);		modem_close(&globals.MODEM_POOL[x]);    }	switch_mutex_unlock(globals.mutex);	/* Wait for Threads to die */	while (globals.THREADCOUNT) {		switch_yield(100000);	}}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:19,


示例11: channel_read_frame

static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id){    crtp_private_t *tech_pvt;    switch_channel_t *channel;    switch_status_t status;        channel = switch_core_session_get_channel(session);	assert(channel != NULL);		tech_pvt = switch_core_session_get_private(session);	assert(tech_pvt != NULL);        if (!tech_pvt->rtp_session || tech_pvt->mode == RTP_SENDONLY) {	switch_yield(20000); /* replace by local timer XXX */        goto cng;    }            if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {        switch_dtmf_t dtmf = { 0 };        switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, &dtmf);        switch_channel_queue_dtmf(channel, &dtmf);    }        tech_pvt->read_frame.flags = SFF_NONE;    tech_pvt->read_frame.codec = &tech_pvt->read_codec;    status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame, flags);    if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {        goto cng;    }        *frame = &tech_pvt->read_frame;    return SWITCH_STATUS_SUCCESS;    cng:    *frame = &tech_pvt->read_frame;    tech_pvt->read_frame.codec = &tech_pvt->read_codec;    tech_pvt->read_frame.flags |= SFF_CNG;    tech_pvt->read_frame.datalen = 0;        return SWITCH_STATUS_SUCCESS;}
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:42,


示例12: monitor_thread_run

void *SWITCH_THREAD_FUNC monitor_thread_run(switch_thread_t *thread, void *obj){	xml_binding_t *binding = (xml_binding_t *) obj;	time_t st;	int diff;	while(globals.running) {		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Running server command: %s/n", binding->server);		st = switch_epoch_time_now(NULL);		switch_system(binding->server, SWITCH_TRUE);		diff = (int) switch_epoch_time_now(NULL) - st;		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Server command complete: %s/n", binding->server);		if (globals.running && diff < 5) {			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Server command had short run duration, sleeping: %s/n", binding->server);			switch_yield(10000000);		}	}		return NULL;}
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:21,


示例13: launch_write_stream_thread

static void launch_write_stream_thread(shout_context_t *context){	switch_thread_t *thread;	switch_threadattr_t *thd_attr = NULL;	int sanity = 10;	if (context->err) {		return;	}	context->thread_running = 1;	switch_threadattr_create(&thd_attr, context->memory_pool);	switch_threadattr_detach_set(thd_attr, 1);	switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);	switch_thread_create(&thread, thd_attr, write_stream_thread, context, context->memory_pool);	while (context->thread_running && context->thread_running != 2) {		switch_yield(100000);		if (!--sanity)			break;	}}
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:22,


示例14: do_reopen

static switch_status_t do_reopen(cdr_fd_t *fd){	int x = 0;	switch_status_t status = SWITCH_STATUS_FALSE;	if(fd == NULL || fd->path == NULL){		return SWITCH_STATUS_FALSE;	}	//if (fd->fd > -1) {	do_close(fd);	fd->fd = NULL;	for (x = 0; x < 10; x++) {		//if ((fd->fd = open(fd->path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) > -1) {		if(do_open(fd) == SWITCH_STATUS_SUCCESS && fd->fd != NULL){			fd->bytes = switch_file_get_size(fd->fd);//fd_size(fd->fd);			status = SWITCH_STATUS_SUCCESS;			break;		}		switch_yield(100000);	}	return status;}
开发者ID:gujun,项目名称:sscore,代码行数:24,


示例15: db_is_up

//.........这里部分代码省略.........            max_tries = DEFAULT_PGSQL_RETRIES;    }top:    if (!handle) {        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Handle/n");        goto done;    }    if (!handle->con) {        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Connection/n");        goto done;    }    /* Try a non-blocking read on the connection to gobble up any EOF from a closed connection and mark the connection BAD if it is closed. */    PQconsumeInput(handle->con);    if (PQstatus(handle->con) == CONNECTION_BAD) {        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "PQstatus returned bad connection; reconnecting.../n");        handle->state = SWITCH_PGSQL_STATE_ERROR;        PQreset(handle->con);        if (PQstatus(handle->con) == CONNECTION_BAD) {            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "PQstatus returned bad connection -- reconnection failed!/n");            goto error;        }        handle->state = SWITCH_PGSQL_STATE_CONNECTED;        handle->sock = PQsocket(handle->con);    }    /*	if (!PQsendQuery(handle->con, "SELECT 1")) {    		code = __LINE__;    		goto error;    	}    	if(switch_pgsql_next_result(handle, &result) == SWITCH_PGSQL_FAIL) {    		code = __LINE__;    		goto error;    	}    	if (!result || result->status != PGRES_COMMAND_OK) {    		code = __LINE__;    		goto error;    	}    	switch_pgsql_free_result(&result);    	switch_pgsql_finish_results(handle);    */    ret = 1;    goto done;error:    err_str = switch_pgsql_handle_get_error(handle);    if (PQstatus(handle->con) == CONNECTION_BAD) {        handle->state = SWITCH_PGSQL_STATE_ERROR;        PQreset(handle->con);        if (PQstatus(handle->con) == CONNECTION_OK) {            handle->state = SWITCH_PGSQL_STATE_CONNECTED;            recon = SWITCH_PGSQL_SUCCESS;            handle->sock = PQsocket(handle->con);        }    }    max_tries--;    if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Failure-Message", "The sql server is not responding for DSN %s [%s][%d]",                                switch_str_nil(handle->dsn), switch_str_nil(err_str), code);        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The sql server is not responding for DSN %s [%s][%d]/n",                          switch_str_nil(handle->dsn), switch_str_nil(err_str), code);        if (recon == SWITCH_PGSQL_SUCCESS) {            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection has been re-established");            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "The connection has been re-established/n");        } else {            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection could not be re-established");            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The connection could not be re-established/n");        }        if (!max_tries) {            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "Giving up!");            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Giving up!/n");        }        switch_event_fire(&event);    }    if (!max_tries) {        goto done;    }    switch_safe_free(err_str);    switch_yield(1000000);    goto top;done:    switch_safe_free(err_str);    return ret;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,


示例16: write_stream_thread

static void *SWITCH_THREAD_FUNC write_stream_thread(switch_thread_t *thread, void *obj){	shout_context_t *context = (shout_context_t *) obj;	switch_thread_rwlock_rdlock(context->rwlock);	if (context->thread_running) {		context->thread_running++;	} else {		switch_thread_rwlock_unlock(context->rwlock);		return NULL;	}	if (!context->lame_ready) {		lame_init_params(context->gfp);		lame_print_config(context->gfp);		context->lame_ready = 1;	}	while (!context->err && context->thread_running) {		unsigned char mp3buf[8192] = "";		int16_t audio[9600] = { 0 };		switch_size_t audio_read = 0;		int rlen = 0;		long ret = 0;		switch_mutex_lock(context->audio_mutex);		if (context->audio_buffer) {			audio_read = switch_buffer_read(context->audio_buffer, audio, sizeof(audio));		} else {			context->err++;		}		switch_mutex_unlock(context->audio_mutex);		error_check();		if (!audio_read) {			audio_read = sizeof(audio);			memset(audio, 255, sizeof(audio));		}		if (context->channels == 2) {			int16_t l[4800] = { 0 };			int16_t r[4800] = { 0 };			int j = 0;			switch_size_t i;			for (i = 0; i < audio_read / 4; i++) {				l[i] = audio[j++];				r[i] = audio[j++];			}			if ((rlen = lame_encode_buffer(context->gfp, l, r, audio_read / 4, mp3buf, sizeof(mp3buf))) < 0) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!/n", rlen);				goto error;			}		} else if (context->channels == 1) {			if ((rlen = lame_encode_buffer(context->gfp, (void *) audio, NULL, audio_read / sizeof(int16_t), mp3buf, sizeof(mp3buf))) < 0) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!/n", rlen);				goto error;			}		}		if (rlen) {			ret = shout_send(context->shout, mp3buf, rlen);			if (ret != SHOUTERR_SUCCESS) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Send error: %s/n", shout_get_error(context->shout));				goto error;			}		} else {			memset(mp3buf, 0, 128);			ret = shout_send(context->shout, mp3buf, 128);		}		shout_sync(context->shout);		switch_yield(100000);	}  error:	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write Thread Done/n");	switch_thread_rwlock_unlock(context->rwlock);	context->thread_running = 0;	return NULL;}
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:85,


示例17: free_context

static inline void free_context(shout_context_t *context){	int ret;	if (context) {		switch_mutex_lock(context->audio_mutex);		context->err++;		switch_mutex_unlock(context->audio_mutex);		if (context->stream_url) {			int sanity = 0;			while (context->thread_running) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for stream to terminate: %s/n", context->stream_url);				switch_yield(500000);				if (++sanity > 10) {					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up waiting for stream to terminate: %s/n", context->stream_url);					break;				}			}		}		switch_thread_rwlock_wrlock(context->rwlock);		if (context->mh) {			mpg123_close(context->mh);			mpg123_delete(context->mh);		}		if (context->fp) {			unsigned char mp3buffer[8192];			int len;			int16_t blank[2048] = { 0 }, *r = NULL;			if (context->channels == 2) {				r = blank;			}			len = lame_encode_buffer(context->gfp, blank, r, sizeof(blank) / 2, mp3buffer, sizeof(mp3buffer));			if (len) {				ret = fwrite(mp3buffer, 1, len, context->fp);			}			while ((len = lame_encode_flush(context->gfp, mp3buffer, sizeof(mp3buffer))) > 0) {				ret = fwrite(mp3buffer, 1, len, context->fp);				if (ret < 0) {					break;				}			}			lame_mp3_tags_fid(context->gfp, context->fp);			fclose(context->fp);			context->fp = NULL;		}		if (context->shout) {			shout_close(context->shout);			context->shout = NULL;		}		if (context->gfp) {			lame_close(context->gfp);			context->gfp = NULL;		}		if (context->audio_buffer) {			switch_buffer_destroy(&context->audio_buffer);		}		switch_mutex_destroy(context->audio_mutex);		switch_thread_rwlock_unlock(context->rwlock);		switch_thread_rwlock_destroy(context->rwlock);	}}
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:78,


示例18: stream_callback

static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data){	register unsigned int realsize = (unsigned int) (size * nmemb);	shout_context_t *context = data;	int decode_status = 0;	size_t usedlen;	uint32_t used, buf_size = 1024 * 128;	/* do not make this 64 or less, stutter will ensue after 											   first 64k buffer is dry */	if (context->prebuf) {		buf_size = context->prebuf;	}	/* make sure we aren't over zealous by slowing down the stream when the buffer is too full */	while (!context->err) {		switch_mutex_lock(context->audio_mutex);		used = switch_buffer_inuse(context->audio_buffer);		switch_mutex_unlock(context->audio_mutex);		if (used < buf_size) {			/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Buffered %u/%u!/n", used, buf_size); */			break;		}		switch_yield(500000);	}	if (mpg123_feed(context->mh, ptr, realsize) != MPG123_OK) {		goto error;	}	do {		usedlen = 0;		decode_status = mpg123_read(context->mh, context->decode_buf, sizeof(context->decode_buf), &usedlen);		if (decode_status == MPG123_NEW_FORMAT) {			continue;		} else if (decode_status == MPG123_OK || decode_status == MPG123_NEED_MORE) {			;		} else if (decode_status == MPG123_DONE) {			context->eof++;		} else if (decode_status == MPG123_ERR || decode_status > 0) {			if (++context->mp3err >= 5) {				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decoder Error! %s/n", context->stream_url);				context->eof++;				goto error;			}			continue;		}		context->mp3err = 0;		switch_mutex_lock(context->audio_mutex);		switch_buffer_write(context->audio_buffer, context->decode_buf, usedlen);		switch_mutex_unlock(context->audio_mutex);	} while (!context->err && !context->eof && decode_status != MPG123_NEED_MORE);	if (context->err) {		goto error;	}	return realsize;  error:	switch_mutex_lock(context->audio_mutex);	context->err++;	switch_mutex_unlock(context->audio_mutex);	return 0;}
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:70,


示例19: do_broadcast

void do_broadcast(switch_stream_handle_t *stream){	char *path_info = switch_event_get_header(stream->param_event, "http-path-info");	char *file;	lame_global_flags *gfp = NULL;	switch_file_handle_t fh = { 0 };	unsigned char mp3buf[TC_BUFFER_SIZE] = "";	uint8_t buf[1024];	int rlen;	int is_local = 0;	uint32_t interval = 20000;	if (strstr(path_info + 7, "://")) {		file = strdup(path_info + 7);		is_local++;	} else {		file = switch_mprintf("%s/streamfiles/%s", SWITCH_GLOBAL_dirs.base_dir, path_info + 7);	}	assert(file);	if (switch_core_file_open(&fh, file, 0, 0, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {		memset(&fh, 0, sizeof(fh));		stream->write_function(stream, "Content-type: text/html/r/n/r/n<h2>File not found</h2>/n");		goto end;	}	if (switch_test_flag((&fh), SWITCH_FILE_NATIVE)) {		stream->write_function(stream, "Content-type: text/html/r/n/r/n<h2>File format not supported</h2>/n");		goto end;	}	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, fh.channels);	lame_set_in_samplerate(gfp, fh.samplerate);	lame_set_brate(gfp, 16 * (fh.samplerate / 8000) * fh.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);	stream->write_function(stream, "Content-type: audio/mpeg/r/n" "Content-Disposition: inline; filename=/"%s.mp3/"/r/n/r/n", path_info + 7);	if (fh.interval) {		interval = fh.interval * 1000;	}	for (;;) {		switch_size_t samples = sizeof(buf) / 2;		switch_core_file_read(&fh, buf, &samples);		if (is_local) {			switch_yield(interval);		}		if (!samples) {			break;		}		if ((rlen = lame_encode_buffer(gfp, (void *) buf, NULL, samples, 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;			}		}	}	while ((rlen = lame_encode_flush(gfp, mp3buf, sizeof(mp3buf))) > 0) {		if (stream->raw_write_function(stream, mp3buf, rlen)) {			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected/n");			goto end;		}	}  end:	if (fh.channels) {		switch_core_file_close(&fh);	}	switch_safe_free(file);	if (gfp) {		lame_close(gfp);		gfp = NULL;	}//.........这里部分代码省略.........
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:101,


示例20: SWITCH_MOD_DECLARE

SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void){	THREADS = -1;	switch_yield(100000);	return SWITCH_STATUS_SUCCESS;}
开发者ID:moises-silva,项目名称:mod_handsfree,代码行数:6,



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


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