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 * Overlay loader
11 *
12 * Copyright (C) 2006 Jens Arnold
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 "overlay.h"
26
27/* load and run a plugin linked as an overlay.
28
29 arguments:
30 parameter = plugin parameter, passed on to the overlay
31 filename = overlay file name, absolute path as usual
32 name = overlay display name
33
34 result:
35 return value from the overlay
36
37 As long as a large plugin to be overlayed doesn't use the audiobuffer
38 itself, no adjustments in the plugin source code are necessary to make
39 it work as an overlay, it only needs an adapted linker script.
40
41 If the overlayed plugin *does* use the audiobuffer itself, it needs
42 to make sure not to overwrite itself.
43
44 The linker script for the overlay should use a base address towards the
45 end of the audiobuffer, just low enough to make the overlay fit. */
46
47enum plugin_status run_overlay(const void* parameter,
48 unsigned char *filename, unsigned char *name)
49{
50 size_t audiobuf_size;
51 unsigned char *audiobuf;
52 void *handle;
53 struct plugin_header *p_hdr;
54 struct lc_header *hdr;
55 enum plugin_status retval = PLUGIN_ERROR;
56
57 audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size);
58 if (!audiobuf)
59 {
60 rb->splash(2*HZ, "Can't obtain memory");
61 goto error;
62 }
63
64 handle = rb->lc_open(filename, audiobuf, audiobuf_size);
65 if (!handle)
66 {
67 rb->splashf(2*HZ, "Can't open %s", filename);
68 goto error;
69 }
70
71 p_hdr = rb->lc_get_header(handle);
72 if (!p_hdr)
73 {
74 rb->splash(2*HZ, "Can't get header");
75 goto error_close;
76 }
77 else
78 hdr = &p_hdr->lc_hdr;
79
80 if (hdr->magic != PLUGIN_MAGIC || hdr->target_id != TARGET_ID)
81 {
82 rb->splashf(2*HZ, "%s overlay: Incompatible model.", name);
83 goto error_close;
84 }
85
86 if (hdr->api_version != PLUGIN_API_VERSION ||
87 p_hdr->api_size > sizeof(struct plugin_api))
88 {
89 rb->splashf(2*HZ, "%s overlay: Incompatible version.", name);
90 goto error_close;
91 }
92
93 *(p_hdr->api) = rb;
94 retval = p_hdr->entry_point(parameter);
95 /* fall through */
96error_close:
97 rb->lc_close(handle);
98error:
99 return retval;
100}