summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/hosted/notification.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/apps/hosted/notification.c b/apps/hosted/notification.c
index faa1247860..443200698c 100644
--- a/apps/hosted/notification.c
+++ b/apps/hosted/notification.c
@@ -21,11 +21,13 @@
21 21
22#include <jni.h> 22#include <jni.h>
23#include <stdio.h> 23#include <stdio.h>
24#include <sys/mman.h>
24#include "notification.h" 25#include "notification.h"
25#include "appevents.h" 26#include "appevents.h"
26#include "metadata.h" 27#include "metadata.h"
27#include "albumart.h" 28#include "albumart.h"
28#include "misc.h" 29#include "misc.h"
30#include "thread.h"
29#include "debug.h" 31#include "debug.h"
30 32
31extern JNIEnv *env_ptr; 33extern JNIEnv *env_ptr;
@@ -66,8 +68,36 @@ static void track_changed_callback(void *param)
66 album = e->NewStringUTF(env_ptr, id3->album ?: ""); 68 album = e->NewStringUTF(env_ptr, id3->album ?: "");
67 69
68 albumart = NULL; 70 albumart = NULL;
69 if (find_albumart(id3, buf, sizeof(buf), &dim)) 71 if (id3->embed_albumart && id3->albumart.type == AA_TYPE_JPG)
72 { /* extract albumart to a temporary file using mmap() */
73 snprintf(buf, sizeof(buf), "/sdcard/rockbox/.temp_albumart_%d.jpg",
74 thread_self());
75 int dst_fd = creat(buf, 0666);
76 if (dst_fd >= 0)
77 {
78 int src_fd = open(id3->path, O_RDONLY);
79 off_t o_pos = id3->albumart.pos;
80 off_t pa_pos = o_pos & ~(sysconf(_SC_PAGE_SIZE) - 1);
81 if (src_fd >= 0)
82 { /* align to page boundary */
83 int pos_diff = o_pos - pa_pos;
84 unsigned char* p = mmap(NULL, id3->albumart.size + pos_diff,
85 PROT_READ, MAP_SHARED, src_fd, pa_pos);
86 if (p != MAP_FAILED)
87 {
88 write(dst_fd, p + pos_diff, id3->albumart.size);
89 munmap(p, id3->albumart.size + pos_diff);
90 albumart = e->NewStringUTF(env_ptr, buf);
91 }
92 close(src_fd);
93 }
94 close(dst_fd);
95 }
96 }
97 else if (find_albumart(id3, buf, sizeof(buf), &dim))
98 {
70 albumart = e->NewStringUTF(env_ptr, buf); 99 albumart = e->NewStringUTF(env_ptr, buf);
100 }
71 101
72 e->CallVoidMethod(env_ptr, NotificationManager_instance, 102 e->CallVoidMethod(env_ptr, NotificationManager_instance,
73 updateNotification, title, artist, album, albumart); 103 updateNotification, title, artist, album, albumart);
@@ -82,6 +112,12 @@ static void track_finished_callback(void *param)
82 JNIEnv e = *env_ptr; 112 JNIEnv e = *env_ptr;
83 e->CallVoidMethod(env_ptr, NotificationManager_instance, 113 e->CallVoidMethod(env_ptr, NotificationManager_instance,
84 finishNotification); 114 finishNotification);
115
116 /* delete temporary albumart file */
117 char buf[MAX_PATH];
118 snprintf(buf, sizeof(buf), "/sdcard/rockbox/.temp_albumart_%d.jpg",
119 thread_self());
120 unlink(buf);
85} 121}
86 122
87void notification_init(void) 123void notification_init(void)