static int
set_pos_rel_callback(void *id, int32_t delta, int mode)
{
	assert(nullptr != id);
	
	WavPackDecoder *decoder = static_cast<WavPackDecoder *>(id);
	InputSource *inputSource = decoder->GetInputSource();

	if(!inputSource->SupportsSeeking())
		return -1;
	
	// Adjust offset as required
	SInt64 offset = delta;
	switch(mode) {
		case SEEK_SET:
			// offset remains unchanged
			break;
		case SEEK_CUR:
			offset += inputSource->GetOffset();
			break;
		case SEEK_END:
			offset += inputSource->GetLength();
			break;
	}
	
	return (!inputSource->SeekToOffset(offset));
}
static int
set_pos_abs_callback(void *id, uint32_t pos)
{
	assert(nullptr != id);
	
	WavPackDecoder *decoder = static_cast<WavPackDecoder *>(id);
	return !decoder->GetInputSource()->SeekToOffset(pos);
}
static uint32_t
get_pos_callback(void *id)
{
	assert(nullptr != id);
	
	WavPackDecoder *decoder = static_cast<WavPackDecoder *>(id);
	return static_cast<uint32_t>(decoder->GetInputSource()->GetOffset());
}
static int32_t
read_bytes_callback(void *id, void *data, int32_t bcount)
{
	assert(nullptr != id);

	WavPackDecoder *decoder = static_cast<WavPackDecoder *>(id);
	return static_cast<int32_t>(decoder->GetInputSource()->Read(data, bcount));
}
static int
can_seek_callback(void *id)
{
	assert(nullptr != id);
	
	WavPackDecoder *decoder = static_cast<WavPackDecoder *>(id);
	return static_cast<uint32_t>(decoder->GetInputSource()->SupportsSeeking());
}
Beispiel #6
0
static uint32_t
get_length_callback(void *id)
{
	assert(NULL != id);
	
	WavPackDecoder *decoder = static_cast<WavPackDecoder *>(id);
	return static_cast<uint32_t>(decoder->GetInputSource()->GetLength());
}
// FIXME: How does one emulate ungetc when the data is non-seekable?
static int
push_back_byte_callback(void *id, int c)
{
	assert(nullptr != id);
	
	WavPackDecoder *decoder = static_cast<WavPackDecoder *>(id);
	InputSource *inputSource = decoder->GetInputSource();
	
	if(!inputSource->SupportsSeeking())
		return EOF;
	
	if(!inputSource->SeekToOffset(inputSource->GetOffset() - 1))
		return EOF;
	
	return c;
}
	uint32_t wpd_get_length_shim(void *id)
	{
		WavPackDecoder* d = (WavPackDecoder*)id;
		return d->getLength();
	}
	int wpd_push_back_byte_shim(void *id, int c)
	{
		WavPackDecoder* d = (WavPackDecoder*)id;
		return d->pushBackByte(c);
	}
	uint32_t wpd_get_pos_shim(void *id)
	{
		WavPackDecoder* d = (WavPackDecoder*)id;
		return d->getPos();
	}
	int32_t wpd_read_bytes_shim(void *id, void *data, int32_t bcount)
	{
		WavPackDecoder* d = (WavPackDecoder*)id;
		return d->readBytes(data, bcount);
	}