prerecord.h
typedef structjoseph_prerecord
{
char *ipnc_frame_buf[25];
int ipnc_frame_buf_size[25];
}JOSEPH_RECORD;
typedef structnode
{
JOSEPH_RECORD joseph_prerecord_ipnc;
struct node *next;
struct node *pione;
}NODE;
prerecord.c
#include "avserver.h"
NODE * prerecord_node_create(void)
{
NODE *head = (NODE*)malloc(sizeof(NODE));
memset(head,0,sizeof(NODE));
head->next = NULL;
head->pione = NULL;
returnhead;
}
void init_joseph_prerecord_ipnc(JOSEPH_RECORD *in)
{
static int i_temp =0;
for(i_temp = 0; i_temp< 25 ; i_temp++)
{
in->ipnc_frame_buf[i_temp] =NULL;
in->ipnc_frame_buf_size[i_temp]= 0;
}
}
void prerecord_node_fill(NODE *head,JOSEPH_RECORD *in)
{
static int i_temp = 0;
for(i_temp = 0; i_temp < 25; i_temp++)
{
head->joseph_prerecord_ipnc.ipnc_frame_buf[i_temp]= (char*)malloc((in->ipnc_frame_buf_size[i_temp])*sizeof(char));
memcpy(head->joseph_prerecord_ipnc.ipnc_frame_buf[i_temp],in->ipnc_frame_buf[i_temp],in->ipnc_frame_buf_size[i_temp]);
head->joseph_prerecord_ipnc.ipnc_frame_buf_size[i_temp]= in->ipnc_frame_buf_size[i_temp];
}
}
NODE * prerecord_node_insert(NODE *head,JOSEPH_RECORD*joseph_prerecord_in)
{
NODE *p = NULL;
if(head->joseph_prerecord_ipnc.ipnc_frame_buf[0]== NULL)
{
prerecord_node_fill(head,joseph_prerecord_in);
return head;
}
else
{
p = (NODE *)malloc(sizeof(NODE));
memset(p,0,sizeof(p));
prerecord_node_fill(p,joseph_prerecord_in);
head->pione = p;
p->next = head;
p->pione = NULL;
}
returnp;
}
void ipnc_frame_print(NODE *head)
{
NODE *q = NULL;
q = head;
static int frame_count = 0;
static int node_count = 1;
while(q != NULL)
{
printf("\n%s %d The %dth node :\n\n",__FUNCTION__,__LINE__,node_count++);
for(frame_count = 0; frame_count < 25; frame_count++)
{
printf("%s %d The contnet of the %dth is %s\n",__FUNCTION__,__LINE__,frame_count,q->joseph_prerecord_ipnc.ipnc_frame_buf[frame_count]);
}
q = q->next;
printf("\n");
}
}
void ipnc_frame_save(NODE * head)
{
FILE *fp_video;
NODE *q = NULL;
q = head;
static int frame_count = 0;
static int node_count = 1;
fp_video =fopen(JOSEPH_PRERECORD_FILE_NAME, "wb");
while(q->next != NULL)
{
q = q->next;
}
#if 1
while(q != NULL)
{
///save one node
for(frame_count = 0; frame_count < 25;frame_count++)
{
fwrite(q->joseph_prerecord_ipnc.ipnc_frame_buf[frame_count],q->joseph_prerecord_ipnc.ipnc_frame_buf_size[frame_count],1,fp_video);
fflush(fp_video);
}
q = q->pione;
node_count++;
}
fclose(fp_video);
#endif
}
NODE * ipnc_frame_free_node(NODE *head)
{
NODE *q = NULL;
NODE *p = NULL;
NODE *p_head = NULL;
q = head;
p_head = head;
static int frame_count = 0;
while(q->next != NULL)
{
q = q->next;
p = q->pione;
}
if(q->next == NULL)
{
p->next = NULL;
for(frame_count = 0;frame_count < 25; frame_count++)
{
free(q->joseph_prerecord_ipnc.ipnc_frame_buf[frame_count]);
q->joseph_prerecord_ipnc.ipnc_frame_buf[frame_count]= NULL;
if(q->joseph_prerecord_ipnc.ipnc_frame_buf[frame_count] == NULL)
{
//printf("%s%d free %dth frame buf succeed!\n",__FUNCTION__,__LINE__,frame_count);
}
}
free(q);
q = NULL;
}
return p_head;
}
void ipnc_frame_free(NODE *head)
{
NODE *q = NULL;
static int frame_count = 0;
while(head != NULL)
{
q = head;
head = head->next;
for(frame_count = 0; frame_count < 25; frame_count++)
{
free(q->joseph_prerecord_ipnc.ipnc_frame_buf[frame_count]);
q->joseph_prerecord_ipnc.ipnc_frame_buf[frame_count]= NULL;
if(q->joseph_prerecord_ipnc.ipnc_frame_buf[frame_count] == NULL)
{
//printf("%s%d free %dth frame buf succeed!\n",__FUNCTION__,__LINE__,frame_count);
}
}
free(q);
q = NULL;
}
}
#if 0
int joseph_prerecord_video()
{
static int frame_count = 0;
char buf[64] = {0};
NODE *joseph_prerecord_head = (NODE*)malloc(sizeof(NODE));
JOSEPH_RECORD *joseph_prerecord_frame =(JOSEPH_RECORD *)malloc(sizeof(JOSEPH_RECORD));
memset(joseph_prerecord_head,0,sizeof(NODE));
memset(joseph_prerecord_frame,0,sizeof(JOSEPH_RECORD));
init_joseph_prerecord_ipnc(&joseph_prerecord_head->joseph_prerecord_ipnc);
init_joseph_prerecord_ipnc(joseph_prerecord_frame);
joseph_prerecord_head =prerecord_node_create();
if ( joseph_prerecord_head != NULL)
{
printf("%s %d Create the listsucceed !\n",__FUNCTION__,__LINE__);
}
//init joseph_prerecord_head
//creat next node
for(frame_count = 0; frame_count < 25;frame_count++)
{
memset(buf,0,64);
sprintf(buf,"%d",(frame_count*frame_count));
joseph_prerecord_frame->ipnc_frame_buf[frame_count]= (char *)malloc((strlen(buf))*sizeof(char));
memset(joseph_prerecord_frame->ipnc_frame_buf[frame_count],0,strlen(joseph_prerecord_frame->ipnc_frame_buf[frame_count]));
memcpy(joseph_prerecord_frame->ipnc_frame_buf[frame_count],buf,strlen(buf));
//printf("%s %d The content of the buf is %s, thelength is%d\n",__FUNCTION__,__LINE__,buf,strlen(joseph_prerecord_frame->ipnc_frame_buf[frame_count]));
printf("%s %d The content of%dth frame is is%s\n",__FUNCTION__,__LINE__,frame_count,joseph_prerecord_frame->ipnc_frame_buf[frame_count]);
}
joseph_prerecord_head =prerecord_node_insert(joseph_prerecord_head,joseph_prerecord_frame);
for(frame_count = 0; frame_count < 25;frame_count++)
{
memset(buf,0,64);
sprintf(buf,"%d",(frame_count*frame_count*frame_count));
joseph_prerecord_frame->ipnc_frame_buf[frame_count]= (char *)malloc((strlen(buf))*sizeof(char));
memset(joseph_prerecord_frame->ipnc_frame_buf[frame_count],0,strlen(joseph_prerecord_frame->ipnc_frame_buf[frame_count]));
memcpy(joseph_prerecord_frame->ipnc_frame_buf[frame_count],buf,strlen(buf));
printf("%s %d The content of the buf is %s, thelength is%d\n",__FUNCTION__,__LINE__,buf,strlen(joseph_prerecord_frame->ipnc_frame_buf[frame_count]));
printf("%s %d The content of%dth frame is is%s\n",__FUNCTION__,__LINE__,frame_count,joseph_prerecord_frame->ipnc_frame_buf[frame_count]);
}
joseph_prerecord_head =prerecord_node_insert(joseph_prerecord_head,joseph_prerecord_frame);
for(frame_count = 0; frame_count < 25;frame_count++)
{
memset(buf,0,64);
sprintf(buf,"%d",(frame_count*frame_count*frame_count*frame_count));
joseph_prerecord_frame->ipnc_frame_buf[frame_count]= (char *)malloc((strlen(buf))*sizeof(char));
memset(joseph_prerecord_frame->ipnc_frame_buf[frame_count],0,strlen(joseph_prerecord_frame->ipnc_frame_buf[frame_count]));
memcpy(joseph_prerecord_frame->ipnc_frame_buf[frame_count],buf,strlen(buf));
printf("%s %d The content of the buf is %s, thelength is%d\n",__FUNCTION__,__LINE__,buf,strlen(joseph_prerecord_frame->ipnc_frame_buf[frame_count]));
printf("%s %d The content of%dth frame is is%s\n",__FUNCTION__,__LINE__,frame_count,joseph_prerecord_frame->ipnc_frame_buf[frame_count]);
}
joseph_prerecord_head =prerecord_node_insert(joseph_prerecord_head,joseph_prerecord_frame);
for(frame_count = 0; frame_count < 25;frame_count++)
{
free(joseph_prerecord_frame->ipnc_frame_buf[frame_count]);
joseph_prerecord_frame->ipnc_frame_buf[frame_count]= NULL;
}
ipnc_frame_print(joseph_prerecord_head);
ipnc_frame_free(joseph_prerecord_head);
return 0;
}
#endif