/***********************************************************************
* 包含头文件
************************************************************************/
// 依次为标准库头文件、平台头文件、自定义头文件
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <dirent.h>
#include <time.h>
#include "flvx264.h"
#include "mem_pool.h"
//#include "librtmp/rtmpdump.h"
/***********************************************************************
* 常量定义
***********************************************************************/
int find_video_flag=0;
int find_audio_flag=0;
/***********************************************************************
* 本地使用宏定义
***********************************************************************/
/***********************************************************************
* 本地使用数据结构定义
***********************************************************************/
/***********************************************************************
* 全局变量
***********************************************************************/
/***********************************************************************
* 局部变量
***********************************************************************/
#define MAXLISTNO 256
static Audio_Packet_list Audio_list[MAXLISTNO];
static Video_Packet_list Video_list[MAXLISTNO];
static Rtmpinfo *rtmpheader[MAXLISTNO] ;
//changed by simon 2012-11-13
#define mutex_flag 0
/***********************************************************************
* 局部函数原型
***********************************************************************/
/***********************************************************************
* 全局函数实现
***********************************************************************/
//D_INT32 audio_packet_list_init(void)
D_INT32 audio_packet_list_init(D_INT32 listindex)
{
if(listindex >= MAXLISTNO ||listindex <0)
return D_FAILURE;
Audio_list[listindex].pfirst = NULL;
Audio_list[listindex].plast = NULL;
Audio_list[listindex].count = 0;
Audio_list[listindex].cur = 0;
//changed by simon 2012-11-11
#if mutex_flag
pthread_mutex_init(&Audio_list[listindex].mutex, NULL);
#endif
//end
return D_SUCCESS;
}
D_INT32 audio_packet_list_index_packet_get(D_INT32 listindex,D_INT32 index,Audio_packet **ptmp_packet)
{
Audio_packet *ptemp_file=NULL;
D_INT32 count=0;
//printf("######total packet:%d,cur:%d\n", Audio_list.count, index);
if(listindex >= MAXLISTNO ||listindex <0)
return D_FAILURE;
if ((index >= Audio_list[listindex].count) || (NULL == ptmp_packet))
{
return D_FAILURE;
}
ptemp_file = Audio_list[listindex].pfirst;
while ((count != index) && (NULL != ptemp_file))
{
ptemp_file = ptemp_file->pnext_file;
count++;
}
if (NULL == ptemp_file)
{
printf("can not find file ! %s \n",__func__);
return D_FAILURE;
}
*ptmp_packet = ptemp_file;
return D_SUCCESS;
}
D_INT32 audio_packet_list_cur_packet_get(D_INT32 listindex,Audio_packet **ptmp_packet)
{
if(listindex >= MAXLISTNO ||listindex <0)
return D_FAILURE;
Audio_packet *ptemp_file = NULL;
D_INT32 count = 0;
if (NULL == ptmp_packet)
{
return D_FAILURE;
}
ptemp_file = Audio_list[listindex].pfirst;
while ((count != Audio_list[listindex].cur) && (NULL != ptemp_file))
{
ptemp_file = ptemp_file->pnext_file;
count++;
}
if (NULL == ptemp_file)
{
printf("can not find file ! %s \n",__func__);
return D_FAILURE;
}
*ptmp_packet = ptemp_file;
return D_SUCCESS;
}
D_INT32 audio_packet_list_prve_packet_get(D_INT32 listindex,Audio_packet **ptmp_packet)
{
if(listindex >= MAXLISTNO ||listindex <0)
return D_FAILURE;
Audio_packet *ptemp_file = NULL;
D_INT32 count = 0;
if (NULL == ptmp_packet)
{
return D_FAILURE;
}
Audio_list[listindex].cur--;
if (Audio_list[listindex].cur >= Audio_list[listindex].count)
{
Audio_list[listindex].cur = Audio_list[listindex].count -1;
}
ptemp_file = Audio_list[listindex].pfirst;
while ((count != Audio_list[listindex].cur) && (NULL != ptemp_file))
{
ptemp_file = ptemp_file->pnext_file;
count++;
}
if (NULL == ptemp_file)
{
printf("can not find file ! %s \n",__func__);
return D_FAILURE;
}
*ptmp_packet = ptemp_file;
return D_SUCCESS;
}
D_INT32 audio_packet_list_next_packet_get(D_INT32 listindex,Audio_packet **ptmp_packet)
{
if(listindex >= MAXLISTNO ||listindex <0)
return D_FAILURE;
Audio_packet *ptemp_file = NULL;
D_INT32 count = 0;
if (NULL == ptmp_packet)
{
return D_FAILURE;
}
Audio_list[listindex].cur++;
if (Audio_list[listindex].cur >= Audio_list[listindex].count)
{
Audio_list[listindex].cur = 0;
}
ptemp_file = Audio_list[listindex].pfirst;
while ((count != Audio_list[listindex].cur) && (NULL != ptemp_file))
{
ptemp_file = ptemp_file->pnext_file;
count++;
}
if (NULL == ptemp_file)
{
printf("can not find file ! %s \n",__func__);
return D_FAILURE;
}
*ptmp_packet = ptemp_file;
return D_SUCCESS;
}
//D_INT32 audio_packet_list_clean(void)
D_INT32 audio_packet_list_clean(D_INT32 listindex)
{
if(listindex >= MAXLISTNO ||listindex <0)
return D_FAILURE;
//changed by simon 2012-11-11
#if mutex_flag
while(pthread_mutex_lock(&Audio_list[listindex].mutex))
{
//lock fail
printf("<<%s %d-------lock fail-------->>\n",__func__,__LINE__);
perror ("[%s]pthread_mutex_lock");
usleep(10);
}
#endif
//end
Audio_packet *player_file = NULL;
Audio_packet *pfile_next = NULL;
player_file = Audio_list[listindex].pfirst;
while (NULL != player_file)
{
pfile_next = player_file->pnext_file;
audio_packet_free(player_file);
player_file = pfile_next;
}
Audio_list[listindex].pfirst = NULL;
Audio_list[listindex].plast = NULL;
Audio_list[listindex].count = 0;
Audio_list[listindex].cur = 0;
//changed by simon 2012-11-11
#if mutex_flag
pthread_mutex_unlock(&Audio_list[listindex].mutex);
#endif
//end
return D_SUCCESS;
}
D_INT32 audio_packet_list_add(D_INT32 listindex,Audio_packet *packet)
{
if(listindex >= MAXLISTNO ||listindex <0)
return D_FAILURE;
#if mutex_flag
//changed by simon 2012-11-11
while(pthread_mutex_lock(&Audio_list[listindex].mutex))
{
//lock fail
printf("<<%s %d-------lock fail-------->>\n",__func__,__LINE__);
perror ("[%s]pthread_mutex_lock");
usleep(10);
}
#endif
//end
Audio_packet *ptemp_file = NULL;
D_INT32 ret = 0;
if(NULL == packet)
{
printf("%s:parameter is NULL ! \n",__func__);
#if mutex_flag
//changed by simon 2012-11-11
pthread_mutex_unlock(&Audio_list[listindex].mutex);
//end
#endif
return D_FAILURE;
}
ret = audio_packet_malloc(listindex,&ptemp_file);
if ((D_SUCCESS != ret) || (NULL == ptemp_file))
{
#if mutex_flag
//changed by simon 2012-11-11
pthread_mutex_unlock(&Audio_list[listindex].mutex);
//end
#endif
return D_FAILURE;
}
//changed by simon 2012-11-11
memset(ptemp_file,0x00,sizeof(Audio_packet));
ptemp_file->packet_size=0;
ptemp_file->channel=0;
ptemp_file->time_stamp=0;
ptemp_file->packet_data = NULL;
ptemp_file->index = 0;
ptemp_file->pnext_file = NULL;
ptemp_file->ppre_file= NULL;
if(packet->packet_size <=0 || packet->packet_data ==NULL)
{
printf("<<-----%s-----%d-----add fail---->>\n",__func__,__LINE__);
#if mutex_flag
//changed by simon 2012-11-11
pthread_mutex_unlock(&Audio_list[listindex].mutex);
//end
#endif
return D_FAILURE;
}
ptemp_file->packet_size=packet->packet_size;
ptemp_file->channel=packet->channel;
ptemp_file->time_stamp=packet->time_stamp;
ptemp_file->packet_receive_time=packet->packet_receive_time;
#if mem_flag
ptemp_file->packet_data = (char *)TPool_Alloc(listindex,pac
- 1
- 2
- 3
- 4
- 5
- 6
前往页