1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
diff --git a/apps/hosted/notification.c b/apps/hosted/notification.c
index faa1247..733ca50 100644
--- a/apps/hosted/notification.c
+++ b/apps/hosted/notification.c
@@ -21,6 +21,7 @@

 #include <jni.h>
 #include <stdio.h>
+#include <sys/mman.h>
 #include "notification.h"
 #include "appevents.h"
 #include "metadata.h"
@@ -66,8 +67,35 @@ static void track_changed_callback(void *param)
         album = e->NewStringUTF(env_ptr, id3->album ?: "");

         albumart = NULL;
-        if (find_albumart(id3, buf, sizeof(buf), &dim))
+        if (id3->embed_albumart && id3->albumart.type == AA_TYPE_JPG)
+        {
+            strlcpy(buf, "/sdcard/rockbox/.temp_albumart.jpg", sizeof(buf));
+            int dst_fd = open(buf, O_CREAT|O_TRUNC|O_WRONLY);
+            if (dst_fd >= 0)
+            {
+                int src_fd = open(id3->path, O_RDONLY);
+                off_t o_pos = id3->albumart.pos;
+                off_t pa_pos = o_pos & ~(sysconf(_SC_PAGE_SIZE) - 1);
+                if (src_fd >= 0)
+                {
+                    int pos_diff = o_pos - pa_pos;
+                    void * p = mmap(NULL, id3->albumart.size + pos_diff,
+                                    PROT_READ, MAP_SHARED, src_fd, pa_pos);
+                    if (p != MAP_FAILED)
+                    {
+                        write(dst_fd, p + pos_diff, id3->albumart.size);
+                        munmap(p, id3->albumart.size + pos_diff);
+                        albumart = e->NewStringUTF(env_ptr, buf);
+                    }
+                    close(src_fd);
+                }
+                close(dst_fd);
+            }
+        }
+        else if (find_albumart(id3, buf, sizeof(buf), &dim))
+        {
             albumart = e->NewStringUTF(env_ptr, buf);
+        }

         e->CallVoidMethod(env_ptr, NotificationManager_instance,
                       updateNotification, title, artist, album, albumart);