示例#1
0
int IndexBlocks_GetTrackCount(IndexBlocks blocks)
{
    int result = -1;
    struct _IndexBlocks* instance = (struct _IndexBlocks*)blocks;
    if(instance != NULL)
    {
        if(
#if defined(_POSIX)
            instance->_sem_ret == -1
#else
            instance->_sync == NULL
#endif
          )
        {
            return result;
        }
        lock_wait(&instance->_sync);
        if(instance->_firstNode == NULL)
        {
            result = 0;
        }
        else
        {
            struct _IndexBlockNode* lastNode = _GetLastNode(instance->_firstNode);
            result = (int)lastNode->FirstTrackNumber + (int)lastNode->TrackCount;
        }
        lock_post(&instance->_sync);
    }
    return result;
}
示例#2
0
int IndexBlocks_AddBlock(IndexBlocks blocks, int streamOffset, int length, int trackCount)
{
	int trackOffset = 0;
	struct _IndexBlocks* instance = (struct _IndexBlocks*)blocks;
	struct _IndexBlockNode* node = NULL;
	struct _IndexBlockNode* lastNode = NULL;
	if(instance == NULL || blocks == NULL || length >= 65536 || trackCount >= 256)
	{
		return 0;
	}
	sem_wait(&instance->_sync);

	lastNode = _GetLastNode(instance->_firstNode);
	if(lastNode != NULL)
	{
		trackOffset = (int)lastNode->FirstTrackNumber + (int)lastNode->TrackCount;
	}
	if((trackOffset + trackCount) >= 65536)
	{
		sem_post(&instance->_sync);
		return 0;
	}

	node = (struct _IndexBlockNode*)malloc(sizeof(struct _IndexBlockNode));
	if(node == NULL)
	{
		sem_post(&instance->_sync);
		return 0;
	}

	node->Next = NULL;
	node->ByteOffset = streamOffset;
	node->ByteLength = (unsigned short)length;
	node->FirstTrackNumber = (unsigned short)trackOffset;
	node->TrackCount = (unsigned char)trackCount;

	if(lastNode == NULL)
	{
		instance->_firstNode = node;
	}
	else
	{
		lastNode->Next = node;
	}

	instance->_blockCount++;

	sem_post(&instance->_sync);

	return 1;
}
示例#3
0
int IndexBlocks_GetTrackCount(IndexBlocks blocks)
{
	int result = -1;
	struct _IndexBlocks* instance = (struct _IndexBlocks*)blocks;
	if(instance != NULL)
	{
		sem_wait(&instance->_sync);
		if(instance->_firstNode == NULL)
		{
			result = 0;
		}
		else
		{
			struct _IndexBlockNode* lastNode = _GetLastNode(instance->_firstNode);
			result = (int)lastNode->FirstTrackNumber + (int)lastNode->TrackCount;
		}
		sem_post(&instance->_sync);
	}
	return result;
}