clock.c

来自「h263解码程序.。。。。。。。。。。。」· C语言 代码 · 共 43 行

C
43
字号
/*
********************************************************************************
*                       linux213x
*                 linux213x timer module for decoder
*                                                                         
*                (c) Copyright 2002-2003, Actions Co,Ld.                       
*                        All Right Reserved                               
*
* File   : dec_timer.c 
* By     : styao
* Version: 1> v1.00     first version    02.27.2006
********************************************************************************
*/
#include <sys/time.h>#include <stdio.h>#include <stdlib.h>
struct timeval time_start;
int start_clock(){		gettimeofday(&time_start,NULL);				
		return 0;}unsigned int get_clock_time(){
		struct timeval cur_tv,last_tv;
		unsigned int current_time;

		/*calculate the current time*/
		gettimeofday(&cur_tv,NULL);
		last_tv=time_start;
		if(cur_tv.tv_usec<last_tv.tv_usec){
			cur_tv.tv_sec--;
			current_time=1000000+cur_tv.tv_usec-last_tv.tv_usec;			
		}else	
			current_time=cur_tv.tv_usec-last_tv.tv_usec;		
		current_time=current_time/1000;		
		current_time+=(cur_tv.tv_sec-last_tv.tv_sec)*1000;

		/*adjust time if possible*/
		return current_time;	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?