diff options
Diffstat (limited to 'apps/buffering.c')
-rw-r--r-- | apps/buffering.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/apps/buffering.c b/apps/buffering.c index edfb8e758a..3a412680ea 100644 --- a/apps/buffering.c +++ b/apps/buffering.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include "playback.h" | 48 | #include "playback.h" |
49 | #include "pcmbuf.h" | 49 | #include "pcmbuf.h" |
50 | #include "buffer.h" | 50 | #include "buffer.h" |
51 | #include "bmp.h" | ||
51 | 52 | ||
52 | #ifdef SIMULATOR | 53 | #ifdef SIMULATOR |
53 | #define ata_disk_is_active() 1 | 54 | #define ata_disk_is_active() 1 |
@@ -745,7 +746,7 @@ static void shrink_handle(struct memory_handle *h) | |||
745 | 746 | ||
746 | if (h->next && h->filerem == 0 && | 747 | if (h->next && h->filerem == 0 && |
747 | (h->type == TYPE_ID3 || h->type == TYPE_CUESHEET || | 748 | (h->type == TYPE_ID3 || h->type == TYPE_CUESHEET || |
748 | h->type == TYPE_IMAGE || h->type == TYPE_CODEC || | 749 | h->type == TYPE_BITMAP || h->type == TYPE_CODEC || |
749 | h->type == TYPE_ATOMIC_AUDIO)) | 750 | h->type == TYPE_ATOMIC_AUDIO)) |
750 | { | 751 | { |
751 | /* metadata handle: we can move all of it */ | 752 | /* metadata handle: we can move all of it */ |
@@ -762,11 +763,15 @@ static void shrink_handle(struct memory_handle *h) | |||
762 | h->ridx = RINGBUF_ADD(h->ridx, delta); | 763 | h->ridx = RINGBUF_ADD(h->ridx, delta); |
763 | h->widx = RINGBUF_ADD(h->widx, delta); | 764 | h->widx = RINGBUF_ADD(h->widx, delta); |
764 | 765 | ||
765 | /* when moving a struct mp3entry we need to readjust its pointers. */ | ||
766 | if (h->type == TYPE_ID3 && h->filesize == sizeof(struct mp3entry)) { | 766 | if (h->type == TYPE_ID3 && h->filesize == sizeof(struct mp3entry)) { |
767 | /* when moving an mp3entry we need to readjust its pointers. */ | ||
767 | adjust_mp3entry((struct mp3entry *)&buffer[h->data], | 768 | adjust_mp3entry((struct mp3entry *)&buffer[h->data], |
768 | (void *)&buffer[h->data], | 769 | (void *)&buffer[h->data], |
769 | (void *)&buffer[olddata]); | 770 | (void *)&buffer[olddata]); |
771 | } else if (h->type == TYPE_BITMAP) { | ||
772 | /* adjust the bitmap's pointer */ | ||
773 | struct bitmap *bmp = (struct bitmap *)&buffer[h->data]; | ||
774 | bmp->data = &buffer[h->data + sizeof(struct bitmap)]; | ||
770 | } | 775 | } |
771 | } | 776 | } |
772 | else | 777 | else |
@@ -814,6 +819,23 @@ static bool fill_buffer(void) | |||
814 | } | 819 | } |
815 | } | 820 | } |
816 | 821 | ||
822 | #ifdef HAVE_LCD_BITMAP | ||
823 | /* Given a file descriptor to a bitmap file, write the bitmap data to the | ||
824 | buffer, with a struct bitmap and the actual data immediately following. | ||
825 | Return value is the total size (struct + data). */ | ||
826 | static int load_bitmap(const int fd) | ||
827 | { | ||
828 | int rc; | ||
829 | struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx]; | ||
830 | /* FIXME: alignment may be needed for the data buffer. */ | ||
831 | bmp->data = &buffer[buf_widx + sizeof(struct bitmap)]; | ||
832 | bmp->maskdata = NULL; | ||
833 | int free = (int)MIN(buffer_len - BUF_USED, buffer_len - buf_widx); | ||
834 | rc = read_bmp_fd(fd, bmp, free, FORMAT_ANY|FORMAT_DITHER); | ||
835 | return rc + (rc > 0 ? sizeof(struct bitmap) : 0); | ||
836 | } | ||
837 | #endif | ||
838 | |||
817 | 839 | ||
818 | /* | 840 | /* |
819 | MAIN BUFFERING API CALLS | 841 | MAIN BUFFERING API CALLS |
@@ -858,7 +880,6 @@ int bufopen(const char *file, size_t offset, enum data_type type) | |||
858 | } | 880 | } |
859 | 881 | ||
860 | strncpy(h->path, file, MAX_PATH); | 882 | strncpy(h->path, file, MAX_PATH); |
861 | h->filesize = size; | ||
862 | h->filerem = size - offset; | 883 | h->filerem = size - offset; |
863 | h->offset = offset; | 884 | h->offset = offset; |
864 | h->ridx = buf_widx; | 885 | h->ridx = buf_widx; |
@@ -867,7 +888,25 @@ int bufopen(const char *file, size_t offset, enum data_type type) | |||
867 | h->available = 0; | 888 | h->available = 0; |
868 | h->type = type; | 889 | h->type = type; |
869 | 890 | ||
870 | if (type == TYPE_CUESHEET || type == TYPE_IMAGE) { | 891 | #ifdef HAVE_LCD_BITMAP |
892 | if (type == TYPE_BITMAP) { | ||
893 | /* Bitmap file: we load the data instead of the file */ | ||
894 | mutex_lock(&llist_mutex); /* Lock because load_bitmap yields */ | ||
895 | size = load_bitmap(fd); | ||
896 | if (size <= 0) | ||
897 | return ERR_FILE_ERROR; | ||
898 | |||
899 | h->filerem = 0; | ||
900 | h->available = size; | ||
901 | h->widx = buf_widx + size; /* safe because the data doesn't wrap */ | ||
902 | buf_widx += size; /* safe too */ | ||
903 | mutex_unlock(&llist_mutex); | ||
904 | } | ||
905 | #endif | ||
906 | |||
907 | h->filesize = size; | ||
908 | |||
909 | if (type == TYPE_CUESHEET) { | ||
871 | h->fd = fd; | 910 | h->fd = fd; |
872 | /* Immediately start buffering those */ | 911 | /* Immediately start buffering those */ |
873 | LOGFQUEUE("buffering >| Q_BUFFER_HANDLE"); | 912 | LOGFQUEUE("buffering >| Q_BUFFER_HANDLE"); |