请大家帮忙分析下,这样的存储设置,正确吗。
static void* __SM_channel_simulater(void* arg)
{
int ret,efn=0,I_siz,P_siz,frame_len,flagment;
int bitrate = (1<<20),IfI = 25, fnum = (1<<30);
xesap_task_frame_t tf = {.ChaID=(int)arg};
struct timeval tick_lastsec;
struct frame_signature *fsig_p;
const xesap_task_statistic_t *tstat_p;
struct frame_flag *add_frame_flag;
tf.data = malloc(bitrate);
I_siz = bitrate/10;
P_siz = (bitrate-I_siz)/24;
gettimeofday(&tf.timestamp,NULL);
gettimeofday(&tick_lastsec,NULL);
bitrate = 0;
int num=0;
do{
if((efn%IfI)==0)
{
tf.frame_type = XESAP_FRAME_TYPE_I_FRAME;
if(efn%2)
{
frame_len = I_siz + (random()%(20<<10));
}
else
{
frame_len = I_siz - (random()%(20<<10));
}
}
else
{
tf.frame_type = XESAP_FRAME_TYPE_P_FRAME;
if(efn%2)
{
frame_len = P_siz + (random()%(10<<10));
}
else
{
frame_len = P_siz - (random()%(10<<10));
}
}
gettimeofday(&tf.timestamp,NULL);
if(tick_lastsec.tv_sec != tf.timestamp.tv_sec)
{
tick_lastsec.tv_sec= tf.timestamp.tv_sec;
bitrate = 0;
tstat_p = xesap_task_get_statistic(tf.ChaID);
if(tstat_p)
{
/*printf("ChaID(%d):\ttotal(%d)\tflushed(%d/%d)\tdiscard(%d)\tshrink(%d)\tFB(%d/%d)\tMEM(%02d%%-%d/%d)\n", \
tf.ChaID,tstat_p->fn_total,tstat_p->fn_flush_success,tstat_p->fn_flush_fail, \
tstat_p->fn_discard,tstat_p->fn_shrink,tstat_p->fn_buf,tstat_p->fn_size, \
tstat_p->buf_len*100/tstat_p->buf_size,tstat_p->buf_len,tstat_p->buf_size);*/
}
}
flagment = 0;
do
{
if(frame_len<16)
frame_len=16;
if(frame_len > (64<<10))
{
tf.data_len = 64<<10;
}
else
{
tf.data_len = frame_len;
}
if(flagment)
tf.frame_type = XESAP_FRAME_TYPE_P_FRAME;
/*
* 此段为每帧标记头部分
*/
add_frame_flag = (struct frame_flag *)calloc(1,sizeof(struct frame_flag));
add_frame_flag->date = malloc(tf.data_len);
add_frame_flag->byte_flag = 0X20100921;
add_frame_flag->frame_type = tf.frame_type;
add_frame_flag->frame_seq = num++;
add_frame_flag->frame_time.tv_sec = tf.timestamp.tv_sec;
add_frame_flag->frame_date_len = tf.data_len;
add_frame_flag->date = tf.data;
tf.data = &add_frame_flag;
flagment++;
frame_len -= tf.data_len;
fsig_p = (struct frame_signature*)tf.data;
fsig_p->magiK = FSIG_MAGIK;
fsig_p->frame_type = tf.frame_type;
fsig_p->data_len = tf.data_len;
fsig_p->tv_sec = tf.timestamp.tv_sec;
/*printf("ChaID(%d): deliver flagment(%d) magiK(0x%08x) frame_type(%d) data_len(%d)\n", \
tf.ChaID,flagment,fsig_p->magiK,fsig_p->frame_type,fsig_p->data_len);
*/
ret = xesap_task_deliver_stream_frame(&tf);
if(ret!=0)
{
if(tf.error==XESAP_ERR_NO_MEM)
{
printf("file write fail,XESAP_ERR_NO_MEM\n");
}
else
{
printf("file write fail, errno=%d\n",tf.error);
break;
}
}
bitrate += tf.data_len;
}while(frame_len);
efn++;
usleep(40000);
}while(efn<fnum);
return NULL;
} |