示例#1
0
struct ast_frame* convert_frame( struct ast_trans_pvt* trans, struct ast_frame* fr )
{
    if ( trans == NULL )
    {
        ast_log( LOG_WARNING, "unable to convert frame with null translator\n" ) ;
        return NULL ;
    }

    if ( fr == NULL )
    {
        ast_log( LOG_WARNING, "unable to convert null frame\n" ) ;
        return NULL ;
    }

    // convert the frame
    struct ast_frame* translated_frame = ast_translate( trans, fr, 1 ) ;

    // check for errors
    if ( translated_frame == NULL )
    {
        ast_log( LOG_ERROR, "unable to translate frame\n" ) ;
        return NULL ;
    }

    // return the translated frame
    return translated_frame ;
}
示例#2
0
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
{
	struct ast_frame *begin_frame = f, *duped_frame = NULL, *frame_ptr;
	unsigned int x;

	/* In some cases, we can be passed a frame which has no data in it, but
	 * which has a positive number of samples defined. Once such situation is
	 * when a jitter buffer is in use and the jitter buffer interpolates a frame.
	 * The frame it produces has data set to NULL, datalen set to 0, and samples
	 * set to either 160 or 240.
	 */
	if (!f->data) {
		return 0;
	}

	if (f->subclass != AST_FORMAT_SLINEAR) {
		if (sf->trans && f->subclass != sf->format) {
			ast_translator_free_path(sf->trans);
			sf->trans = NULL;
		}

		if (!sf->trans) {
			if ((sf->trans = ast_translator_build_path(AST_FORMAT_SLINEAR, f->subclass)) == NULL) {
				ast_log(LOG_WARNING, "Cannot build a path from %s to slin\n", ast_getformatname(f->subclass));
				return 0;
			} else {
				sf->format = f->subclass;
			}
		}

		if (!(begin_frame = ast_translate(sf->trans, f, 0))) 
			return 0;
		
		duped_frame = ast_frdup(begin_frame);

		ast_frfree(begin_frame);

		if (!duped_frame)
			return 0;
	} else {
		if (!(duped_frame = ast_frdup(f)))
			return 0;
	}

	x = 0;
	AST_LIST_TRAVERSE(&sf->queue, frame_ptr, frame_list)
		x++;

	AST_LIST_INSERT_TAIL(&sf->queue, duped_frame, frame_list);

	sf->size += duped_frame->samples;

	return x;
}
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
{
	struct ast_frame *frame, *frame_ptr;

	if (!f) {
		return 0;
	}

	if (f->subclass != AST_FORMAT_SLINEAR) {
		if (sf->trans && f->subclass != sf->format) {
			ast_translator_free_path(sf->trans);
			sf->trans = NULL;
		}
		if (!sf->trans) {
			if ((sf->trans = ast_translator_build_path(AST_FORMAT_SLINEAR, f->subclass)) == NULL) {
				ast_log(LOG_WARNING, "Cannot build a path from %s to slin\n", ast_getformatname(f->subclass));
				return 0;
			} else {
				sf->format = f->subclass;
			}
		}
	}

	if (sf->trans) {
		frame = ast_translate(sf->trans, f, 0);
	} else {
		frame = ast_frdup(f);
	}

	if (frame) {
		int x = 0;
		for (frame_ptr = sf->queue; frame_ptr && frame_ptr->next; frame_ptr=frame_ptr->next) {
			x++;
		}
		if (frame_ptr) {
			frame_ptr->next = frame;
		} else {
			sf->queue = frame;
		}
		frame->next = NULL;
		sf->size += frame->datalen;	
		return x;
	}

	return 0;
	
}
示例#4
0
文件: pcl.c 项目: vmezhang/sometest
/* 编译 */
static void Compile (char *file) 
{
    AstTranslationUnit transUnit;

    Initialize ();

    if ( test_lex ) {

        LexTest (file);
        goto exit;
    }

    /* 处理C文件,产生语法树所需的节点 */
    transUnit = ParseTranslationUnit (file);

    /* 检查节点的语义 */
    CheckTranslationUnit (transUnit);

    if ( ErrorCount ) 
        goto exit;

    if ( DumpAST ) {
        /* 生成语法树 */
        DumpTranslationUnit (transUnit);
    }

    /* 语句翻译 */
    ast_translate (transUnit);

#if 0
    if (DumpIR) {
        
        /* 中间代码输出 */
        DAssemTranslationUnit (transUnit);
    }

    /* 目标代码生成 */
    //EmitTranslationUnit (transUnit);

#endif

exit:
    Finalize ();
}