wavpack: wrapper for converting void* to struct wavpack_input*
A new function has been added to do a cast and a little check in the wavpack-mpd input stream wrapper.
This commit is contained in:

committed by
Max Kellermann

parent
2b4a410bb0
commit
cfd55b29bd
@@ -346,16 +346,25 @@ struct wavpack_input {
|
|||||||
int last_byte;
|
int last_byte;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Little wrapper for struct wavpack_input to cast from void *.
|
||||||
|
*/
|
||||||
|
static struct wavpack_input *
|
||||||
|
wpin(void *id)
|
||||||
|
{
|
||||||
|
assert(id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t
|
static int32_t
|
||||||
wavpack_input_read_bytes(void *id, void *data, int32_t bcount)
|
wavpack_input_read_bytes(void *id, void *data, int32_t bcount)
|
||||||
{
|
{
|
||||||
struct wavpack_input *isp = (struct wavpack_input *)id;
|
|
||||||
uint8_t *buf = (uint8_t *)data;
|
uint8_t *buf = (uint8_t *)data;
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
|
|
||||||
if (isp->last_byte != EOF) {
|
if (wpin(id)->last_byte != EOF) {
|
||||||
*buf++ = isp->last_byte;
|
*buf++ = wpin(id)->last_byte;
|
||||||
isp->last_byte = EOF;
|
wpin(id)->last_byte = EOF;
|
||||||
--bcount;
|
--bcount;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
@@ -363,7 +372,7 @@ wavpack_input_read_bytes(void *id, void *data, int32_t bcount)
|
|||||||
/* wavpack fails if we return a partial read, so we just wait
|
/* wavpack fails if we return a partial read, so we just wait
|
||||||
until the buffer is full */
|
until the buffer is full */
|
||||||
while (bcount > 0) {
|
while (bcount > 0) {
|
||||||
size_t nbytes = decoder_read(isp->decoder, isp->is,
|
size_t nbytes = decoder_read(wpin(id)->decoder, wpin(id)->is,
|
||||||
buf, bcount);
|
buf, bcount);
|
||||||
if (nbytes == 0) {
|
if (nbytes == 0) {
|
||||||
/* EOF, error or a decoder command */
|
/* EOF, error or a decoder command */
|
||||||
@@ -381,40 +390,38 @@ wavpack_input_read_bytes(void *id, void *data, int32_t bcount)
|
|||||||
static uint32_t
|
static uint32_t
|
||||||
wavpack_input_get_pos(void *id)
|
wavpack_input_get_pos(void *id)
|
||||||
{
|
{
|
||||||
return ((struct wavpack_input *)id)->is->offset;
|
return wpin(id)->is->offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
wavpack_input_set_pos_abs(void *id, uint32_t pos)
|
wavpack_input_set_pos_abs(void *id, uint32_t pos)
|
||||||
{
|
{
|
||||||
return input_stream_seek(((struct wavpack_input *)id)->is, pos, SEEK_SET)
|
return input_stream_seek(wpin(id)->is, pos, SEEK_SET) ? 0 : -1;
|
||||||
? 0 : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
wavpack_input_set_pos_rel(void *id, int32_t delta, int mode)
|
wavpack_input_set_pos_rel(void *id, int32_t delta, int mode)
|
||||||
{
|
{
|
||||||
return input_stream_seek(((struct wavpack_input *)id)->is, delta, mode)
|
return input_stream_seek(wpin(id)->is, delta, mode) ? 0 : -1;
|
||||||
? 0 : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
wavpack_input_push_back_byte(void *id, int c)
|
wavpack_input_push_back_byte(void *id, int c)
|
||||||
{
|
{
|
||||||
((struct wavpack_input *)id)->last_byte = c;
|
wpin(id)->last_byte = c;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t
|
||||||
wavpack_input_get_length(void *id)
|
wavpack_input_get_length(void *id)
|
||||||
{
|
{
|
||||||
return ((struct wavpack_input *)id)->is->size;
|
return wpin(id)->is->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
wavpack_input_can_seek(void *id)
|
wavpack_input_can_seek(void *id)
|
||||||
{
|
{
|
||||||
return ((struct wavpack_input *)id)->is->seekable;
|
return wpin(id)->is->seekable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WavpackStreamReader mpd_is_reader = {
|
static WavpackStreamReader mpd_is_reader = {
|
||||||
|
Reference in New Issue
Block a user