Esempio n. 1
0
int Play_Seek(int _iPlayId, int _iPos, int _iTm)
{
	int iPlayId;
	S_FileHeader *ptFileHeader;

	if(td_failure == (iPlayId = Play_FindFromId(_iPlayId)))
	{
		return td_failure;
	}
	
	pthread_mutex_lock(&gtPlayback[iPlayId].m_tLock);
	td_printf(0, "%s, %d, _iPos = %d, _iTm = %d\n", __func__, __LINE__, _iPos, _iTm);
	if(td_success == playfile_seek(gtPlayback[iPlayId].m_tFileList, _iPos, _iTm, NULL, &ptFileHeader))
	{
		if(PLAYBACK_STAT_STOP == gtPlayback[iPlayId].m_tStat)
		{
			gtPlayback[iPlayId].m_tStat = PLAYBACK_STAT_PLAY;
		}
		play_getData(gtPlayback + iPlayId, 1);
		play_setStd(gtPlayback + iPlayId);
		play_SendToDec(gtPlayback + iPlayId, play_GetSysTime());
	}

	pthread_mutex_unlock(&gtPlayback[iPlayId].m_tLock);
	play_waken(0);
	td_printf(0,"%s, %d\n", __func__, __LINE__);
	return td_success;
}
Esempio n. 2
0
int X_API STDCALL adt_dlist_delete(DList* dlist, DListNode* node)
{
    if (dlist == NULL)
	{
		td_printf(0,"dlist is null");
		return TD_FALSE;
	}

	if (node == NULL)
	{
		td_printf(0,"node is null");
		return TD_FALSE;
	}

	if (dlist->head == node)
	{
		dlist->head = dlist->head->next;
		if (dlist->head != NULL)
		{
			dlist->head->prev = NULL;
		}

		free(node);
	}
	else if (dlist->end == node)
	{
		dlist->end = dlist->end->prev;
		if (dlist->end != NULL)
		{
			dlist->end->next = NULL;
		}

		free(node);
	}
	else
	{
		node->prev->next = node->next;
		if (node->next != NULL)
		{
			node->next->prev = node->prev;
		}
		free(node);
	}

	--dlist->len;
	return TD_TRUE;

}
Esempio n. 3
0
static int play_SendToDec(Tplayback *_ptPlayback, long long _LForkTime)
{
	S_FrameHeader *pFrameHeader;
	if(PLAYBACK_STAT_STOP == _ptPlayback->m_tStat)
	{
		return td_failure;
	}
	if(1 == _ptPlayback->m_iChgStd || _ptPlayback->m_lStdFrameTime > _ptPlayback->m_lCurFrameTime)
	{
		_ptPlayback->m_iChgStd = 0;
		_ptPlayback->m_lStdFrameTime = _ptPlayback->m_lCurFrameTime;
		_ptPlayback->m_lStdForkTime = _LForkTime;
	}

	if(_ptPlayback->m_lCurFrameTime - _ptPlayback->m_lStdFrameTime > _LForkTime - _ptPlayback->m_lStdForkTime)
	{	
		return td_failure;
	}

	//发送数据
	#ifndef SELF_DEC
	TPushData PushData;
	pFrameHeader = (S_FrameHeader *)(_ptPlayback->m_pcBuf);
	PushData.m_pBuf = _ptPlayback->m_pcBuf;
	PushData.m_iBufLen = _ptPlayback->m_iDataLen;
	td_printf(0,"_ptPlayback->m_pcBuf = %p, _ptPlayback->m_iDataLen = %d, pFrameHeader = %d", _ptPlayback->m_pcBuf, _ptPlayback->m_iDataLen, pFrameHeader->u8FrameType);
	chnmnt_ChannelIpChannelPushData(PLAYBACKCHNNO, &PushData);
	#else
	//pFrameHeader
	playdec_SendFileVStream(_ptPlayback->m_ptVdec, _ptPlayback->m_pcBuf + sizeof(S_FrameHeader), _ptPlayback->m_iDataLen);
	#endif
	_ptPlayback->m_iBufFull = 0;
	return td_success;
}
Esempio n. 4
0
DListNode* X_API STDCALL adt_dlist_add(DList* dlist, DListNode* node, void* data)
{
	if (dlist == NULL)
	{
		td_printf(0,"dlist is null");
		return NULL;
	}

	DListNode* new_node = (DListNode*)malloc(sizeof(DListNode) + dlist->node_size);
	if(NULL == new_node)
	{
		//my_perror("adt_dlist_add, malloc node failed");
		td_printf(0,"adt_dlist_add, malloc node failed");
		return NULL;
	}
	memcpy(new_node->data, data, dlist->node_size);
	new_node->next = new_node->prev = NULL;

	if(dlist->head == NULL)
	{
		dlist->head = new_node;
		dlist->end = new_node;
	}
	else
	{
		if(node == NULL || node == dlist->end)
		{
			dlist->end->next = new_node;
			new_node->prev = dlist->end;
			dlist->end = new_node;
		}
		else
		{
			new_node->prev = node;
			if(node->next != NULL)
			{
				node->next->prev = new_node;
			}
			new_node->next = node->next;
			node->next = new_node;
		}
	}

	++dlist->len;
	return new_node;
}
Esempio n. 5
0
int X_API STDCALL adt_dlist_empty(DList* dlist)
{
	if (dlist == NULL)
	{
		td_printf(0,"dlist is null");
		return TD_TRUE;//FALSE;
	}

    return (dlist->head == NULL);
}
Esempio n. 6
0
unsigned int X_API STDCALL adt_dlist_size(DList* dlist)
{
	if (dlist == NULL)
	{
		td_printf(0,"dlist is null");
		return TD_FALSE;
	}

	return dlist->len;
}
Esempio n. 7
0
DListNode* X_API STDCALL adt_dlist_end(DList* dlist)
{
    if (dlist == NULL)
	{
		td_printf(0,"dlist is null");
		return TD_FALSE;
	}

	return dlist->end;
}
Esempio n. 8
0
int X_API STDCALL adt_dlist_unlock(DList* dlist)
{
    if (dlist == NULL) {
		td_printf(0,"dlist is null");
		return TD_FALSE;
	}

	//return os_mutex_unlock(&dlist->mutex);
	pthread_mutex_unlock(&dlist->mutex.mutex);
	return 0;
}
Esempio n. 9
0
int X_API STDCALL adt_dlist_lock_uninit(DList* dlist)
{
    if (dlist == NULL)
    {
		td_printf(0,"dlist is null");
		return TD_FALSE;
	}

	//return os_mutex_lock(&dlist->mutex);
	return pthread_mutex_destroy(&dlist->mutex.mutex);
}
Esempio n. 10
0
void UUSee_Printf_Hex(const  char *fragment, unsigned short length, const unsigned char *name)
{
	
    const unsigned char *s;
    const unsigned short data_per_line=16;
    int i, j;
    unsigned char *c1, *c2, buf[256];
	
    if (fragment==NULL)
		return;
	
    td_printf("  %s at 0x%x.",name, (unsigned int)fragment);
    td_printf("      length: %d byte%s\r\n", length, (length>0)?"s":"");
	
    s=fragment;
    j=length;
    while (j>0) {
		memset(buf, ' ',256);
		/* c1+=sprintf(c1=buf, "    data: "); */
		memcpy(buf, "    data: ", 11);
		c1=(buf+10);
		c2=c1+(3*data_per_line)+1;
		for (i=((j>data_per_line)?data_per_line:j); i>0; i--, j--) {
			*c1=(*s>>4); *(c1)+=(*c1<0x0a)?'0':('a'-0x0a); c1++;
			*c1=(*s&0x0f); *(c1)+=(*c1<0x0a)?'0':('a'-0x0a); c1++;
			*c1++=' ';
			if (isprint(*s))
				*c2++=*s;
			else
				*c2++='.';
			s++;
		}
		*c2=0;
		td_printf("%s\r\n",buf);
    }
}
Esempio n. 11
0
DList* X_API STDCALL adt_dlist_create(unsigned int node_size)
{
    DList* dlist = (DList*)malloc(sizeof(DList));
	if (dlist == NULL)
	{
		td_printf(0,"malloc fail");
        return NULL;
	}
	dlist->node_size = node_size;
	dlist->head = NULL;
	dlist->end = NULL;
	dlist->len = 0;
//	os_mutex_init(&dlist->mutex, TRUE);
	adt_dlist_lock_init(dlist);

	return dlist;
}
Esempio n. 12
0
DListNode* X_API STDCALL adt_dlist_insert(DList* dlist, DListNode* node, void* data)
{
    if (dlist == NULL)
	{
		td_printf(0,"dlist is null");
		return TD_FALSE;
	}

	DListNode* new_node = (DListNode*)malloc(sizeof(DListNode) + dlist->node_size);
	memcpy(new_node->data, data, dlist->node_size);
	new_node->next = new_node->prev = NULL;

	if (dlist->head == NULL)
	{
		dlist->head = new_node;
		dlist->end = new_node;
	}
	else
	{
		if (node == NULL || node == dlist->head)
		{
			dlist->head->prev = new_node;
			new_node->next = dlist->head;
			dlist->head = new_node;
		}
		else
		{
			new_node->prev = node->prev;
			if (node->prev != NULL)
			{
				node->prev->next = new_node;
			}
			new_node->next = node;
			node->prev = new_node;
		}
	}

	++dlist->len;
	return new_node;
}
Esempio n. 13
0
int  X_API STDCALL adt_dlist_destroy(DList* dlist)
{
    if (dlist == NULL)
    {
		td_printf(0,"dlist is null");
		return TD_FALSE;
	}

	void* ptr;
	DListNode* node = dlist->head;
	while (node != NULL)
	{
		ptr = node;
		node = node->next;
		free(ptr);
	}

//	os_mutex_destroy(&dlist->mutex);
	adt_dlist_lock_uninit(dlist);

	free(dlist);
	return TD_TRUE;
}
Esempio n. 14
0
int Play_GetStat(int _iPlayId, TplyStat *_ptStat)
{
//	S_FileHeader *ptFileHeader;
	int iPlayId;

	if(NULL == _ptStat)
	{
		return td_failure;
	}
	if(td_failure == (iPlayId = Play_FindFromId(_iPlayId)))
	{
		return td_failure;
	}
	pthread_mutex_lock(&gtPlayback[iPlayId].m_tLock);
	playfile_GetCmd(gtPlayback[iPlayId].m_tFileList, 0, &_ptStat->m_iSchedule);
	playfile_GetCmd(gtPlayback[iPlayId].m_tFileList, 1, &_ptStat->m_iCurTime);
	playfile_GetCmd(gtPlayback[iPlayId].m_tFileList, 2, &_ptStat->m_iPassword);
	_ptStat->m_iStat = gtPlayback[iPlayId].m_tStat;
	_ptStat->m_iSpeed = gtPlayback[iPlayId].m_iSpeed;
	td_printf(0,"_ptStat->m_iSchedule = %d, gtPlayback[iPlayId].m_tStat = %d, _ptStat->m_iCurTime = %d\n", _ptStat->m_iSchedule, gtPlayback[iPlayId].m_tStat, _ptStat->m_iCurTime);
	pthread_mutex_unlock(&gtPlayback[iPlayId].m_tLock);
	return td_success;
}
Esempio n. 15
0
td_s32 ringbuf_Write(td_s32 _iSize, const void *_ptSrc, TRingBuf *_ptBuf)
{
	TRingBuffer *ptBuf = (TRingBuffer *)_ptBuf;
	const char *ptSrc = (const char *)_ptSrc;
	td_s32 iSize = 0;
	td_s32 iDataSize = 0;
	td_s32 iCap = 0;

	if (NULL == _ptSrc || NULL == _ptBuf)
	{
		return -1;
	}

	if (_iSize < 1)
	{
		return _iSize;
	}

	// do safe check 20110715 
	if (ptBuf->m_iBufSize < 1 || ptBuf->m_iReadPos < 0 || ptBuf->m_iWritePos < 0)
	{
		return -1;
	}
	
	pthread_mutex_lock(&ptBuf->m_Mutex);

	//td_printf(0, "ring buf %p write pos = %d, read pos = %d\n", _ptBuf, ptBuf->m_iWritePos, ptBuf->m_iReadPos);

	if(ptBuf->m_iWritePos <= ptBuf->m_iReadPos /*&& ptBuf->m_iWritePos != 2147466720*/)
	{
		RingBufClear(ptBuf);
	}
	else if (ptBuf->m_iWritePos > 0x1FFFFFFF) //解决读写指针无限制递增溢出变负 20110713 dxl
	{
		int iIndx1 = ptBuf->m_iWritePos / ptBuf->m_iBufSize;
		int iIndx2 = ptBuf->m_iReadPos / ptBuf->m_iBufSize;
		int iIndx = iIndx1 < iIndx2 ? iIndx1 : iIndx2;
		int iDec = iIndx * ptBuf->m_iBufSize;

		ptBuf->m_iWritePos -= iDec;
		ptBuf->m_iReadPos -= iDec;
	}

	iSize = ptBuf->m_iBufSize;
	iDataSize = ptBuf->m_iWritePos - ptBuf->m_iReadPos;
	iCap = iSize - iDataSize;

	if (_iSize <= iCap)
	{
		ringbuf_WriteData(_iSize, ptSrc, ptBuf);
	}
	else if (RINGBUF_WRITE_BLOCK == ptBuf->m_iType)
	{
		td_s32 iLeft = _iSize;
		while (iLeft > 0)
		{
			iCap = iSize - (ptBuf->m_iWritePos - ptBuf->m_iReadPos);

			if (iCap > 0)
			{
				// zty 20120331
				iCap = min(iLeft, iCap);
				
				ringbuf_WriteData(iCap, ptSrc, ptBuf);

				td_printf(0, "ringbuf_Write ringbuf_Write ringbuf_Write iCap err:%d" , iCap);
				
				// zty 20120308
				//ptBuf += iCap;
				ptSrc += iCap;
				iLeft -= iCap;
			}
			else
			{
				pthread_mutex_unlock(&ptBuf->m_Mutex); //解锁让对方去处理
				usleep(1000);
				pthread_mutex_lock(&ptBuf->m_Mutex);
			}
		}
	}
	else
	{
		if (_iSize < iSize)
		{
			ringbuf_WriteData(_iSize, ptSrc, ptBuf);
		}
		else
		{
			RingBufClear(ptBuf);
			ringbuf_WriteData(iSize, ptSrc + (_iSize - iSize), ptBuf);
		}

		ptBuf->m_iReadPos = ptBuf->m_iWritePos - iSize;
	}
	
	pthread_mutex_unlock(&ptBuf->m_Mutex);
	
	return iSize;
}