diff options
author | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2007-10-28 15:54:10 +0000 |
---|---|---|
committer | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2007-10-28 15:54:10 +0000 |
commit | 7807279eaf698474e2eabde440b73a1f587ea7ef (patch) | |
tree | 07d972da2a7251d134a0a5d74ce5d8be5ca42838 | |
parent | 9f6719ec56f2a6b5ae164f6be7dcd7fc3f072d75 (diff) | |
download | rockbox-7807279eaf698474e2eabde440b73a1f587ea7ef.tar.gz rockbox-7807279eaf698474e2eabde440b73a1f587ea7ef.zip |
Add #defines for error values. Makes the code easier to read.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15348 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/buffering.c | 36 | ||||
-rw-r--r-- | apps/buffering.h | 7 | ||||
-rw-r--r-- | apps/playback.c | 12 |
3 files changed, 31 insertions, 24 deletions
diff --git a/apps/buffering.c b/apps/buffering.c index 347ad611f3..0fd0c4c520 100644 --- a/apps/buffering.c +++ b/apps/buffering.c | |||
@@ -253,7 +253,7 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, | |||
253 | 253 | ||
254 | /* This is how far we shifted buf_widx to align things */ | 254 | /* This is how far we shifted buf_widx to align things */ |
255 | shift = RINGBUF_SUB(new_widx, buf_widx); | 255 | shift = RINGBUF_SUB(new_widx, buf_widx); |
256 | 256 | ||
257 | /* How much space are we short in the actual ring buffer? */ | 257 | /* How much space are we short in the actual ring buffer? */ |
258 | overlap = RINGBUF_ADD_CROSS(buf_widx, shift + len, buf_ridx); | 258 | overlap = RINGBUF_ADD_CROSS(buf_widx, shift + len, buf_ridx); |
259 | if (overlap >= 0 && (alloc_all || (unsigned)overlap > data_size)) { | 259 | if (overlap >= 0 && (alloc_all || (unsigned)overlap > data_size)) { |
@@ -426,7 +426,7 @@ static struct memory_handle *move_handle(const struct memory_handle *h, | |||
426 | overlap -= correction; | 426 | overlap -= correction; |
427 | *delta -= correction; | 427 | *delta -= correction; |
428 | } | 428 | } |
429 | 429 | ||
430 | dest = (struct memory_handle *)(&buffer[newpos]); | 430 | dest = (struct memory_handle *)(&buffer[newpos]); |
431 | 431 | ||
432 | if (h == first_handle) { | 432 | if (h == first_handle) { |
@@ -784,11 +784,11 @@ management functions for all the actual handle management work. | |||
784 | int bufopen(const char *file, size_t offset, enum data_type type) | 784 | int bufopen(const char *file, size_t offset, enum data_type type) |
785 | { | 785 | { |
786 | if (!can_add_handle()) | 786 | if (!can_add_handle()) |
787 | return -2; | 787 | return BUFFER_FULL; |
788 | 788 | ||
789 | int fd = open(file, O_RDONLY); | 789 | int fd = open(file, O_RDONLY); |
790 | if (fd < 0) | 790 | if (fd < 0) |
791 | return -1; | 791 | return FILE_ERROR; |
792 | 792 | ||
793 | size_t size = filesize(fd); | 793 | size_t size = filesize(fd); |
794 | 794 | ||
@@ -797,7 +797,7 @@ int bufopen(const char *file, size_t offset, enum data_type type) | |||
797 | { | 797 | { |
798 | DEBUGF("bufopen: failed to add handle\n"); | 798 | DEBUGF("bufopen: failed to add handle\n"); |
799 | close(fd); | 799 | close(fd); |
800 | return -2; | 800 | return BUFFER_FULL; |
801 | } | 801 | } |
802 | 802 | ||
803 | strncpy(h->path, file, MAX_PATH); | 803 | strncpy(h->path, file, MAX_PATH); |
@@ -835,12 +835,12 @@ int bufopen(const char *file, size_t offset, enum data_type type) | |||
835 | int bufalloc(const void *src, size_t size, enum data_type type) | 835 | int bufalloc(const void *src, size_t size, enum data_type type) |
836 | { | 836 | { |
837 | if (!can_add_handle()) | 837 | if (!can_add_handle()) |
838 | return -2; | 838 | return BUFFER_FULL; |
839 | 839 | ||
840 | struct memory_handle *h = add_handle(size, false, true); | 840 | struct memory_handle *h = add_handle(size, false, true); |
841 | 841 | ||
842 | if (!h) | 842 | if (!h) |
843 | return -2; | 843 | return BUFFER_FULL; |
844 | 844 | ||
845 | if (src) { | 845 | if (src) { |
846 | if (type == TYPE_ID3 && size == sizeof(struct mp3entry)) { | 846 | if (type == TYPE_ID3 && size == sizeof(struct mp3entry)) { |
@@ -888,11 +888,11 @@ int bufseek(int handle_id, size_t newpos) | |||
888 | { | 888 | { |
889 | struct memory_handle *h = find_handle(handle_id); | 889 | struct memory_handle *h = find_handle(handle_id); |
890 | if (!h) | 890 | if (!h) |
891 | return -1; | 891 | return HANDLE_NOT_FOUND; |
892 | 892 | ||
893 | if (newpos > h->filesize) { | 893 | if (newpos > h->filesize) { |
894 | /* access beyond the end of the file */ | 894 | /* access beyond the end of the file */ |
895 | return -3; | 895 | return INVALID_VALUE; |
896 | } | 896 | } |
897 | else if (newpos < h->offset || h->offset + h->available < newpos) { | 897 | else if (newpos < h->offset || h->offset + h->available < newpos) { |
898 | /* access before or after buffered data. A rebuffer is needed. */ | 898 | /* access before or after buffered data. A rebuffer is needed. */ |
@@ -910,7 +910,7 @@ int bufadvance(int handle_id, off_t offset) | |||
910 | { | 910 | { |
911 | const struct memory_handle *h = find_handle(handle_id); | 911 | const struct memory_handle *h = find_handle(handle_id); |
912 | if (!h) | 912 | if (!h) |
913 | return -1; | 913 | return HANDLE_NOT_FOUND; |
914 | 914 | ||
915 | size_t newpos = h->offset + RINGBUF_SUB(h->ridx, h->data) + offset; | 915 | size_t newpos = h->offset + RINGBUF_SUB(h->ridx, h->data) + offset; |
916 | return bufseek(handle_id, newpos); | 916 | return bufseek(handle_id, newpos); |
@@ -922,18 +922,18 @@ ssize_t bufread(int handle_id, size_t size, void *dest) | |||
922 | { | 922 | { |
923 | const struct memory_handle *h = find_handle(handle_id); | 923 | const struct memory_handle *h = find_handle(handle_id); |
924 | if (!h) | 924 | if (!h) |
925 | return -1; | 925 | return HANDLE_NOT_FOUND; |
926 | 926 | ||
927 | size_t ret; | 927 | size_t ret; |
928 | size_t copy_n = RINGBUF_SUB(h->widx, h->ridx); | 928 | size_t copy_n = RINGBUF_SUB(h->widx, h->ridx); |
929 | 929 | ||
930 | if (size == 0 && h->filerem > 0 && copy_n == 0) | 930 | if (size == 0 && h->filerem > 0 && copy_n == 0) |
931 | /* Data isn't ready */ | 931 | /* Data isn't ready */ |
932 | return -2; | 932 | return DATA_NOT_READY; |
933 | 933 | ||
934 | if (copy_n < size && h->filerem > 0) | 934 | if (copy_n < size && h->filerem > 0) |
935 | /* Data isn't ready */ | 935 | /* Data isn't ready */ |
936 | return -2; | 936 | return DATA_NOT_READY; |
937 | 937 | ||
938 | if (copy_n == 0 && h->filerem == 0) | 938 | if (copy_n == 0 && h->filerem == 0) |
939 | /* File is finished reading */ | 939 | /* File is finished reading */ |
@@ -965,18 +965,18 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data) | |||
965 | { | 965 | { |
966 | const struct memory_handle *h = find_handle(handle_id); | 966 | const struct memory_handle *h = find_handle(handle_id); |
967 | if (!h) | 967 | if (!h) |
968 | return -1; | 968 | return HANDLE_NOT_FOUND; |
969 | 969 | ||
970 | ssize_t ret; | 970 | ssize_t ret; |
971 | size_t copy_n = RINGBUF_SUB(h->widx, h->ridx); | 971 | size_t copy_n = RINGBUF_SUB(h->widx, h->ridx); |
972 | 972 | ||
973 | if (size == 0 && h->filerem > 0 && copy_n == 0) | 973 | if (size == 0 && h->filerem > 0 && copy_n == 0) |
974 | /* Data isn't ready */ | 974 | /* Data isn't ready */ |
975 | return -2; | 975 | return DATA_NOT_READY; |
976 | 976 | ||
977 | if (copy_n < size && h->filerem > 0) | 977 | if (copy_n < size && h->filerem > 0) |
978 | /* Data isn't ready */ | 978 | /* Data isn't ready */ |
979 | return -2; | 979 | return DATA_NOT_READY; |
980 | 980 | ||
981 | if (copy_n == 0 && h->filerem == 0) | 981 | if (copy_n == 0 && h->filerem == 0) |
982 | /* File is finished reading */ | 982 | /* File is finished reading */ |
@@ -1021,7 +1021,7 @@ ssize_t buf_get_offset(int handle_id, void *ptr) | |||
1021 | { | 1021 | { |
1022 | const struct memory_handle *h = find_handle(handle_id); | 1022 | const struct memory_handle *h = find_handle(handle_id); |
1023 | if (!h) | 1023 | if (!h) |
1024 | return -1; | 1024 | return HANDLE_NOT_FOUND; |
1025 | 1025 | ||
1026 | return (size_t)ptr - (size_t)&buffer[h->ridx]; | 1026 | return (size_t)ptr - (size_t)&buffer[h->ridx]; |
1027 | } | 1027 | } |
@@ -1030,7 +1030,7 @@ ssize_t buf_handle_offset(int handle_id) | |||
1030 | { | 1030 | { |
1031 | const struct memory_handle *h = find_handle(handle_id); | 1031 | const struct memory_handle *h = find_handle(handle_id); |
1032 | if (!h) | 1032 | if (!h) |
1033 | return -1; | 1033 | return HANDLE_NOT_FOUND; |
1034 | return h->offset; | 1034 | return h->offset; |
1035 | } | 1035 | } |
1036 | 1036 | ||
diff --git a/apps/buffering.h b/apps/buffering.h index 29771adc1a..7dc07f5881 100644 --- a/apps/buffering.h +++ b/apps/buffering.h | |||
@@ -35,6 +35,13 @@ enum data_type { | |||
35 | TYPE_UNKNOWN, | 35 | TYPE_UNKNOWN, |
36 | }; | 36 | }; |
37 | 37 | ||
38 | /* Error return values */ | ||
39 | #define HANDLE_NOT_FOUND -1 | ||
40 | #define BUFFER_FULL -2 | ||
41 | #define INVALID_VALUE -3 | ||
42 | #define FILE_ERROR -4 | ||
43 | #define DATA_NOT_READY -5 | ||
44 | |||
38 | 45 | ||
39 | /* Initialise the buffering subsystem */ | 46 | /* Initialise the buffering subsystem */ |
40 | void buffering_init(void); | 47 | void buffering_init(void); |
diff --git a/apps/playback.c b/apps/playback.c index 3c1dd37d3f..2fae4d34ea 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -366,11 +366,11 @@ static void *bufgetcodec(struct track_info *track) | |||
366 | void *ptr; | 366 | void *ptr; |
367 | ssize_t ret = bufgetdata(track->codec_hid, track->codecsize, &ptr); | 367 | ssize_t ret = bufgetdata(track->codec_hid, track->codecsize, &ptr); |
368 | 368 | ||
369 | if (ret == -2) { | 369 | if (ret == DATA_NOT_READY) { |
370 | buf_request_buffer_handle(track->codec_hid); | 370 | buf_request_buffer_handle(track->codec_hid); |
371 | } | 371 | } |
372 | 372 | ||
373 | while (ret == -2) { | 373 | while (ret == DATA_NOT_READY) { |
374 | sleep(1); | 374 | sleep(1); |
375 | ret = bufgetdata(track->codec_hid, track->codecsize, &ptr); | 375 | ret = bufgetdata(track->codec_hid, track->codecsize, &ptr); |
376 | } | 376 | } |
@@ -1516,13 +1516,13 @@ static size_t codec_filebuf_callback(void *ptr, size_t size) | |||
1516 | return 0; | 1516 | return 0; |
1517 | 1517 | ||
1518 | 1518 | ||
1519 | if (copy_n == -2) | 1519 | if (copy_n == DATA_NOT_READY) |
1520 | { | 1520 | { |
1521 | buf_request_buffer_handle(CUR_TI->audio_hid); | 1521 | buf_request_buffer_handle(CUR_TI->audio_hid); |
1522 | } | 1522 | } |
1523 | 1523 | ||
1524 | /* Let the disk buffer catch fill until enough data is available */ | 1524 | /* Let the disk buffer catch fill until enough data is available */ |
1525 | while (copy_n == -2) | 1525 | while (copy_n == DATA_NOT_READY) |
1526 | { | 1526 | { |
1527 | sleep(1); | 1527 | sleep(1); |
1528 | 1528 | ||
@@ -1561,13 +1561,13 @@ static void* codec_request_buffer_callback(size_t *realsize, size_t reqsize) | |||
1561 | return NULL; | 1561 | return NULL; |
1562 | } | 1562 | } |
1563 | 1563 | ||
1564 | if (ret == -2) | 1564 | if (ret == DATA_NOT_READY) |
1565 | { | 1565 | { |
1566 | buf_request_buffer_handle(CUR_TI->audio_hid); | 1566 | buf_request_buffer_handle(CUR_TI->audio_hid); |
1567 | } | 1567 | } |
1568 | 1568 | ||
1569 | /* Let the disk buffer catch fill until enough data is available */ | 1569 | /* Let the disk buffer catch fill until enough data is available */ |
1570 | while (ret == -2) | 1570 | while (ret == DATA_NOT_READY) |
1571 | { | 1571 | { |
1572 | sleep(1); | 1572 | sleep(1); |
1573 | 1573 | ||