A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/*****************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Andrew Mahone
11 *
12 * In-memory JPEG decode benchmark.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include "plugin.h"
25#include "lib/jpeg_mem.h"
26
27
28/* a null output plugin to save memory and better isolate decode cost */
29static unsigned int get_size_null(struct bitmap *bm)
30{
31 (void) bm;
32 return 1;
33}
34
35static void output_row_null(uint32_t row, void * row_in,
36 struct scaler_context *ctx)
37{
38 (void) row;
39 (void) row_in;
40 (void) ctx;
41 return;
42}
43
44const struct custom_format format_null = {
45 .output_row_8 = output_row_null,
46#ifdef HAVE_LCD_COLOR
47 .output_row_32 = {
48 output_row_null,
49 output_row_null
50 },
51#else
52 .output_row_32 = output_row_null,
53#endif
54 .get_size = get_size_null
55};
56
57static int output_y = 0;
58static int font_h;
59
60#define lcd_printf(...) \
61do { \
62 rb->lcd_putsxyf(0, output_y, __VA_ARGS__); \
63 rb->lcd_update_rect(0, output_y, LCD_WIDTH, font_h); \
64 output_y += font_h; \
65} while (0)
66
67/* this is the plugin entry point */
68enum plugin_status plugin_start(const void* parameter)
69{
70 size_t plugin_buf_len;
71 unsigned char * plugin_buf =
72 (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len);
73 static char filename[MAX_PATH];
74 struct bitmap bm = {
75 .width = LCD_WIDTH,
76 .height = LCD_HEIGHT,
77 };
78 int ret;
79
80 if(!parameter) return PLUGIN_ERROR;
81
82 rb->strcpy(filename, parameter);
83 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
84 rb->lcd_fillrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
85 rb->lcd_set_drawmode(DRMODE_SOLID);
86 rb->lcd_getstringsize("A", NULL, &font_h);
87 int fd = rb->open(filename, O_RDONLY);
88 if (fd < 0)
89 {
90 lcd_printf("file open failed: %d", fd);
91 goto wait;
92 }
93 unsigned long filesize = rb->filesize(fd);
94 if (filesize > plugin_buf_len)
95 {
96 lcd_printf("file too large");
97 goto wait;
98 }
99 plugin_buf_len -= filesize;
100 unsigned char *jpeg_buf = plugin_buf;
101 plugin_buf += filesize;
102 rb->read(fd, jpeg_buf, filesize);
103 rb->close(fd);
104 bm.data = plugin_buf;
105 struct dim jpeg_size;
106 get_jpeg_dim_mem(jpeg_buf, filesize, &jpeg_size);
107 lcd_printf("jpeg file size: %dx%d",jpeg_size.width, jpeg_size.height);
108 bm.width = jpeg_size.width;
109 bm.height = jpeg_size.height;
110 char *size_str[] = { "1/1", "1/2", "1/4", "1/8" };
111 int i;
112 for (i = 0; i < 4; i++)
113 {
114 lcd_printf("timing %s decode", size_str[i]);
115 ret = decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len,
116 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
117 &format_null);
118 if (ret == 1)
119 {
120 long t1, t2, t_end;
121 int count = 0;
122 t2 = *(rb->current_tick);
123 while (t2 != (t1 = *(rb->current_tick)));
124 t_end = t1 + 10 * HZ;
125 do {
126 decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len,
127 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
128 &format_null);
129 count++;
130 t2 = *(rb->current_tick);
131 } while (TIME_BEFORE(t2, t_end) || count < 10);
132 t2 -= t1;
133 t2 *= 10;
134 t2 += count >> 1;
135 t2 /= count;
136 t1 = t2 / 1000;
137 t2 -= t1 * 1000;
138 lcd_printf("%01d.%03d secs/decode", (int)t1, (int)t2);
139 bm.width >>= 1;
140 bm.height >>= 1;
141 if (!(bm.width && bm.height))
142 break;
143 } else
144 lcd_printf("insufficient memory");
145 }
146
147wait:
148 while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield();
149 return PLUGIN_OK;
150}