From 931b538300d1d86dfa5d74ef16845be52f4e165f Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Tue, 7 Aug 2007 00:14:15 +0200 Subject: [PATCH] bufopen: Add support for data types that can't wrap. Added a new data type: TYPE_STREAM, for stream audio that can't wrap. The only data type allowed to wrap is audio. Now bufopen returns -2 for all cases where adding the handle failed because of a lack of memory space. --- testplugin.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/testplugin.c b/testplugin.c index 5348c50..d641b7a 100644 --- a/testplugin.c +++ b/testplugin.c @@ -57,6 +57,7 @@ static void graph_view(int width); enum data_type { TYPE_CODEC, TYPE_AUDIO, + TYPE_STREAM, TYPE_ID3, TYPE_CUESHEET, TYPE_IMAGE, @@ -495,7 +496,7 @@ int bufopen(char *file, size_t offset, enum data_type type) current one to finish buffering its data. */ buf_widx = RINGBUF_ADD(buf_widx, cur_handle->filerem); } else { - return -1; + return -2; } } @@ -505,6 +506,13 @@ int bufopen(char *file, size_t offset, enum data_type type) size_t size = rb->filesize(fd) - offset; + if (type != TYPE_AUDIO && + size + sizeof(struct memory_handle) > buffer_len - buf_widx) + { + /* for types other than audio, the data can't wrap */ + return -2; + } + DEBUGF("bufopen: %s (offset: %ld) (%ld bytes needed)...\n", file, offset, size); @@ -513,7 +521,7 @@ int bufopen(char *file, size_t offset, enum data_type type) { DEBUGF("failed to add handle\n"); rb->close(fd); - return -1; + return -2; } if (offset) rb->lseek(fd, offset, SEEK_SET); -- 2.11.4.GIT