Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

add thread for the api server

+586 -16
+342
Cargo.lock
··· 584 584 ] 585 585 586 586 [[package]] 587 + name = "bumpalo" 588 + version = "3.16.0" 589 + source = "registry+https://github.com/rust-lang/crates.io-index" 590 + checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" 591 + 592 + [[package]] 587 593 name = "byteorder" 588 594 version = "1.5.0" 589 595 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 865 871 checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" 866 872 dependencies = [ 867 873 "futures-core", 874 + "futures-sink", 868 875 ] 869 876 870 877 [[package]] ··· 1107 1114 ] 1108 1115 1109 1116 [[package]] 1117 + name = "hyper-rustls" 1118 + version = "0.27.3" 1119 + source = "registry+https://github.com/rust-lang/crates.io-index" 1120 + checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" 1121 + dependencies = [ 1122 + "futures-util", 1123 + "http 1.1.0", 1124 + "hyper", 1125 + "hyper-util", 1126 + "rustls", 1127 + "rustls-pki-types", 1128 + "tokio", 1129 + "tokio-rustls", 1130 + "tower-service", 1131 + "webpki-roots", 1132 + ] 1133 + 1134 + [[package]] 1110 1135 name = "hyper-timeout" 1111 1136 version = "0.5.1" 1112 1137 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1183 1208 ] 1184 1209 1185 1210 [[package]] 1211 + name = "ipnet" 1212 + version = "2.10.0" 1213 + source = "registry+https://github.com/rust-lang/crates.io-index" 1214 + checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" 1215 + 1216 + [[package]] 1186 1217 name = "itertools" 1187 1218 version = "0.13.0" 1188 1219 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1204 1235 checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" 1205 1236 dependencies = [ 1206 1237 "libc", 1238 + ] 1239 + 1240 + [[package]] 1241 + name = "js-sys" 1242 + version = "0.3.70" 1243 + source = "registry+https://github.com/rust-lang/crates.io-index" 1244 + checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" 1245 + dependencies = [ 1246 + "wasm-bindgen", 1207 1247 ] 1208 1248 1209 1249 [[package]] ··· 1599 1639 ] 1600 1640 1601 1641 [[package]] 1642 + name = "quinn" 1643 + version = "0.11.3" 1644 + source = "registry+https://github.com/rust-lang/crates.io-index" 1645 + checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" 1646 + dependencies = [ 1647 + "bytes", 1648 + "pin-project-lite", 1649 + "quinn-proto", 1650 + "quinn-udp", 1651 + "rustc-hash", 1652 + "rustls", 1653 + "socket2", 1654 + "thiserror", 1655 + "tokio", 1656 + "tracing", 1657 + ] 1658 + 1659 + [[package]] 1660 + name = "quinn-proto" 1661 + version = "0.11.6" 1662 + source = "registry+https://github.com/rust-lang/crates.io-index" 1663 + checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" 1664 + dependencies = [ 1665 + "bytes", 1666 + "rand", 1667 + "ring", 1668 + "rustc-hash", 1669 + "rustls", 1670 + "slab", 1671 + "thiserror", 1672 + "tinyvec", 1673 + "tracing", 1674 + ] 1675 + 1676 + [[package]] 1677 + name = "quinn-udp" 1678 + version = "0.5.4" 1679 + source = "registry+https://github.com/rust-lang/crates.io-index" 1680 + checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" 1681 + dependencies = [ 1682 + "libc", 1683 + "once_cell", 1684 + "socket2", 1685 + "tracing", 1686 + "windows-sys 0.52.0", 1687 + ] 1688 + 1689 + [[package]] 1602 1690 name = "quote" 1603 1691 version = "1.0.37" 1604 1692 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1682 1770 checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" 1683 1771 1684 1772 [[package]] 1773 + name = "reqwest" 1774 + version = "0.12.7" 1775 + source = "registry+https://github.com/rust-lang/crates.io-index" 1776 + checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" 1777 + dependencies = [ 1778 + "base64", 1779 + "bytes", 1780 + "futures-channel", 1781 + "futures-core", 1782 + "futures-util", 1783 + "http 1.1.0", 1784 + "http-body", 1785 + "http-body-util", 1786 + "hyper", 1787 + "hyper-rustls", 1788 + "hyper-util", 1789 + "ipnet", 1790 + "js-sys", 1791 + "log", 1792 + "mime", 1793 + "once_cell", 1794 + "percent-encoding", 1795 + "pin-project-lite", 1796 + "quinn", 1797 + "rustls", 1798 + "rustls-pemfile", 1799 + "rustls-pki-types", 1800 + "serde", 1801 + "serde_json", 1802 + "serde_urlencoded", 1803 + "sync_wrapper 1.0.1", 1804 + "tokio", 1805 + "tokio-rustls", 1806 + "tower-service", 1807 + "url", 1808 + "wasm-bindgen", 1809 + "wasm-bindgen-futures", 1810 + "web-sys", 1811 + "webpki-roots", 1812 + "windows-registry", 1813 + ] 1814 + 1815 + [[package]] 1816 + name = "ring" 1817 + version = "0.17.8" 1818 + source = "registry+https://github.com/rust-lang/crates.io-index" 1819 + checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" 1820 + dependencies = [ 1821 + "cc", 1822 + "cfg-if", 1823 + "getrandom", 1824 + "libc", 1825 + "spin", 1826 + "untrusted", 1827 + "windows-sys 0.52.0", 1828 + ] 1829 + 1830 + [[package]] 1685 1831 name = "rockbox-graphql" 1686 1832 version = "0.1.0" 1687 1833 dependencies = [ ··· 1716 1862 version = "0.1.0" 1717 1863 dependencies = [ 1718 1864 "owo-colors 4.1.0", 1865 + "reqwest", 1719 1866 "rockbox-graphql", 1720 1867 "rockbox-rpc", 1721 1868 "rockbox-sys", ··· 1733 1880 checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" 1734 1881 1735 1882 [[package]] 1883 + name = "rustc-hash" 1884 + version = "2.0.0" 1885 + source = "registry+https://github.com/rust-lang/crates.io-index" 1886 + checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" 1887 + 1888 + [[package]] 1736 1889 name = "rustc_version" 1737 1890 version = "0.4.1" 1738 1891 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1755 1908 ] 1756 1909 1757 1910 [[package]] 1911 + name = "rustls" 1912 + version = "0.23.13" 1913 + source = "registry+https://github.com/rust-lang/crates.io-index" 1914 + checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" 1915 + dependencies = [ 1916 + "once_cell", 1917 + "ring", 1918 + "rustls-pki-types", 1919 + "rustls-webpki", 1920 + "subtle", 1921 + "zeroize", 1922 + ] 1923 + 1924 + [[package]] 1925 + name = "rustls-pemfile" 1926 + version = "2.1.3" 1927 + source = "registry+https://github.com/rust-lang/crates.io-index" 1928 + checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" 1929 + dependencies = [ 1930 + "base64", 1931 + "rustls-pki-types", 1932 + ] 1933 + 1934 + [[package]] 1935 + name = "rustls-pki-types" 1936 + version = "1.8.0" 1937 + source = "registry+https://github.com/rust-lang/crates.io-index" 1938 + checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" 1939 + 1940 + [[package]] 1941 + name = "rustls-webpki" 1942 + version = "0.102.8" 1943 + source = "registry+https://github.com/rust-lang/crates.io-index" 1944 + checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" 1945 + dependencies = [ 1946 + "ring", 1947 + "rustls-pki-types", 1948 + "untrusted", 1949 + ] 1950 + 1951 + [[package]] 1758 1952 name = "rustversion" 1759 1953 version = "1.0.17" 1760 1954 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1925 2119 ] 1926 2120 1927 2121 [[package]] 2122 + name = "subtle" 2123 + version = "2.6.1" 2124 + source = "registry+https://github.com/rust-lang/crates.io-index" 2125 + checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" 2126 + 2127 + [[package]] 1928 2128 name = "syn" 1929 2129 version = "2.0.77" 1930 2130 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1946 2146 version = "1.0.1" 1947 2147 source = "registry+https://github.com/rust-lang/crates.io-index" 1948 2148 checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" 2149 + dependencies = [ 2150 + "futures-core", 2151 + ] 1949 2152 1950 2153 [[package]] 1951 2154 name = "tempfile" ··· 2053 2256 "proc-macro2", 2054 2257 "quote", 2055 2258 "syn", 2259 + ] 2260 + 2261 + [[package]] 2262 + name = "tokio-rustls" 2263 + version = "0.26.0" 2264 + source = "registry+https://github.com/rust-lang/crates.io-index" 2265 + checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" 2266 + dependencies = [ 2267 + "rustls", 2268 + "rustls-pki-types", 2269 + "tokio", 2056 2270 ] 2057 2271 2058 2272 [[package]] ··· 2292 2506 ] 2293 2507 2294 2508 [[package]] 2509 + name = "untrusted" 2510 + version = "0.9.0" 2511 + source = "registry+https://github.com/rust-lang/crates.io-index" 2512 + checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" 2513 + 2514 + [[package]] 2295 2515 name = "url" 2296 2516 version = "2.5.2" 2297 2517 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2324 2544 checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 2325 2545 2326 2546 [[package]] 2547 + name = "wasm-bindgen" 2548 + version = "0.2.93" 2549 + source = "registry+https://github.com/rust-lang/crates.io-index" 2550 + checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" 2551 + dependencies = [ 2552 + "cfg-if", 2553 + "once_cell", 2554 + "wasm-bindgen-macro", 2555 + ] 2556 + 2557 + [[package]] 2558 + name = "wasm-bindgen-backend" 2559 + version = "0.2.93" 2560 + source = "registry+https://github.com/rust-lang/crates.io-index" 2561 + checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" 2562 + dependencies = [ 2563 + "bumpalo", 2564 + "log", 2565 + "once_cell", 2566 + "proc-macro2", 2567 + "quote", 2568 + "syn", 2569 + "wasm-bindgen-shared", 2570 + ] 2571 + 2572 + [[package]] 2573 + name = "wasm-bindgen-futures" 2574 + version = "0.4.43" 2575 + source = "registry+https://github.com/rust-lang/crates.io-index" 2576 + checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" 2577 + dependencies = [ 2578 + "cfg-if", 2579 + "js-sys", 2580 + "wasm-bindgen", 2581 + "web-sys", 2582 + ] 2583 + 2584 + [[package]] 2585 + name = "wasm-bindgen-macro" 2586 + version = "0.2.93" 2587 + source = "registry+https://github.com/rust-lang/crates.io-index" 2588 + checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" 2589 + dependencies = [ 2590 + "quote", 2591 + "wasm-bindgen-macro-support", 2592 + ] 2593 + 2594 + [[package]] 2595 + name = "wasm-bindgen-macro-support" 2596 + version = "0.2.93" 2597 + source = "registry+https://github.com/rust-lang/crates.io-index" 2598 + checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" 2599 + dependencies = [ 2600 + "proc-macro2", 2601 + "quote", 2602 + "syn", 2603 + "wasm-bindgen-backend", 2604 + "wasm-bindgen-shared", 2605 + ] 2606 + 2607 + [[package]] 2608 + name = "wasm-bindgen-shared" 2609 + version = "0.2.93" 2610 + source = "registry+https://github.com/rust-lang/crates.io-index" 2611 + checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" 2612 + 2613 + [[package]] 2614 + name = "web-sys" 2615 + version = "0.3.70" 2616 + source = "registry+https://github.com/rust-lang/crates.io-index" 2617 + checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" 2618 + dependencies = [ 2619 + "js-sys", 2620 + "wasm-bindgen", 2621 + ] 2622 + 2623 + [[package]] 2624 + name = "webpki-roots" 2625 + version = "0.26.3" 2626 + source = "registry+https://github.com/rust-lang/crates.io-index" 2627 + checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" 2628 + dependencies = [ 2629 + "rustls-pki-types", 2630 + ] 2631 + 2632 + [[package]] 2633 + name = "windows-registry" 2634 + version = "0.2.0" 2635 + source = "registry+https://github.com/rust-lang/crates.io-index" 2636 + checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" 2637 + dependencies = [ 2638 + "windows-result", 2639 + "windows-strings", 2640 + "windows-targets", 2641 + ] 2642 + 2643 + [[package]] 2644 + name = "windows-result" 2645 + version = "0.2.0" 2646 + source = "registry+https://github.com/rust-lang/crates.io-index" 2647 + checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" 2648 + dependencies = [ 2649 + "windows-targets", 2650 + ] 2651 + 2652 + [[package]] 2653 + name = "windows-strings" 2654 + version = "0.1.0" 2655 + source = "registry+https://github.com/rust-lang/crates.io-index" 2656 + checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" 2657 + dependencies = [ 2658 + "windows-result", 2659 + "windows-targets", 2660 + ] 2661 + 2662 + [[package]] 2327 2663 name = "windows-sys" 2328 2664 version = "0.52.0" 2329 2665 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2434 2770 "quote", 2435 2771 "syn", 2436 2772 ] 2773 + 2774 + [[package]] 2775 + name = "zeroize" 2776 + version = "1.8.1" 2777 + source = "registry+https://github.com/rust-lang/crates.io-index" 2778 + checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" 2437 2779 2438 2780 [[package]] 2439 2781 name = "zstd"
+3 -4
apps/main.c
··· 94 94 #include "audio_thread.h" 95 95 #include "playback.h" 96 96 #include "tdspeed.h" 97 + #include "server_thread.h" 97 98 #if defined(HAVE_RECORDING) && !defined(SIMULATOR) 98 99 #include "pcm_record.h" 99 100 #endif ··· 155 156 156 157 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */ 157 158 158 - extern void start_server(void); 159 - 160 159 static void init(void); 161 160 /* main(), and various functions called by main() and init() may be 162 161 * be INIT_ATTR. These functions must not be called after the final call ··· 195 194 /* All threads should be created and public queues registered by now */ 196 195 usb_start_monitoring(); 197 196 #endif 198 - 199 - start_server(); 200 197 201 198 #if !defined(DISABLE_ACTION_REMAP) && defined(CORE_KEYREMAP_FILE) 202 199 if (file_exists(CORE_KEYREMAP_FILE)) ··· 454 451 usb_init(); 455 452 usb_start_monitoring(); 456 453 #endif 454 + 455 + server_init(); 457 456 } 458 457 459 458 #else /* ! (CONFIG_PLATFORM & PLATFORM_HOSTED) */
+80
apps/server_thread.c
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id$ 9 + * 10 + * Copyright (C) 2005-2007 Miika Pekkarinen 11 + * Copyright (C) 2007-2008 Nicolas Pennequin 12 + * Copyright (C) 2011-2013 Michael Sevakis 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 + #include "config.h" 24 + #include "system.h" 25 + #include "kernel.h" 26 + #include "logf.h" 27 + #include "appevents.h" 28 + 29 + bool server_is_initialized = false; 30 + 31 + /* Event queues */ 32 + // struct event_queue server_queue SHAREDBSS_ATTR; 33 + // static struct queue_sender_list server_queue_sender_list SHAREDBSS_ATTR; 34 + 35 + /* Server thread */ 36 + static long server_stack[(DEFAULT_STACK_SIZE + 0x1000)/sizeof(long)]; 37 + static const char server_thread_name[] = "server"; 38 + unsigned int server_thread_id = 0; 39 + 40 + extern void start_server(void); 41 + extern void start_servers(void); 42 + 43 + extern void debugfn(const char *fmt); 44 + 45 + static void server_thread(void) { 46 + start_server(); 47 + } 48 + 49 + /** -- Startup -- **/ 50 + 51 + /* Initialize the server - called from init() in main.c */ 52 + void INIT_ATTR server_init(void) 53 + { 54 + /* Can never do this twice */ 55 + if (server_is_initialized) 56 + { 57 + logf("server: already initialized"); 58 + return; 59 + } 60 + 61 + logf("server: initializing"); 62 + 63 + /* Initialize queues before giving control elsewhere in case it likes 64 + to send messages. Thread creation will be delayed however so nothing 65 + starts running until ready if something yields such as talk_init. */ 66 + // queue_init(&server_queue, true); 67 + 68 + /* This thread does buffer, so match its priority */ 69 + server_thread_id = create_thread(server_thread, server_stack, 70 + sizeof(server_stack), 0, server_thread_name 71 + IF_PRIO(, PRIORITY_USER_INTERFACE) 72 + IF_COP(, CPU)); 73 + 74 + sleep(HZ); 75 + 76 + start_servers(); 77 + 78 + /* Probably safe to say */ 79 + server_is_initialized = true; 80 + }
+32
apps/server_thread.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id$ 9 + * 10 + * Copyright (C) 2005-2007 Miika Pekkarinen 11 + * Copyright (C) 2007-2008 Nicolas Pennequin 12 + * Copyright (C) 2011-2013 Michael Sevakis 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 + #ifndef SERVER_THREAD_H 24 + #define SERVER_THREAD_H 25 + 26 + 27 + /* (*) If you change these, you must check audio_clear_track_notifications 28 + in playback.c for correctness */ 29 + 30 + void server_init(void); 31 + 32 + #endif /* SERVER_THREAD_H */
+1
build.zig
··· 4226 4226 "apps/tagcache.c", 4227 4227 "apps/keymaps/keymap-touchscreen.c", 4228 4228 "apps/keymaps/keymap-sdl.c", 4229 + "apps/server_thread.c", 4229 4230 "build/lang/lang_core.c", 4230 4231 }; 4231 4232
+1
crates/server/Cargo.toml
··· 8 8 9 9 [dependencies] 10 10 owo-colors = "4.0.0" 11 + reqwest = {version = "0.12.7", features = ["blocking", "rustls-tls"], default-features = false} 11 12 rockbox-graphql = {path = "../graphql"} 12 13 rockbox-rpc = {path = "../rpc"} 13 14 rockbox-sys = {path = "../sys"}
+123 -9
crates/server/src/lib.rs
··· 1 1 use owo_colors::OwoColorize; 2 2 use rockbox_sys::{self as rb, events::RockboxCommand}; 3 3 use std::{ 4 + ffi::c_char, 5 + io::{BufRead, BufReader, Write}, 6 + net::{TcpListener, TcpStream}, 4 7 sync::{Arc, Mutex}, 5 8 thread, 6 9 }; 7 10 8 11 #[no_mangle] 12 + pub extern "C" fn debugfn(args: *const c_char) { 13 + let c_str = unsafe { std::ffi::CStr::from_ptr(args) }; 14 + let str_slice = c_str.to_str().unwrap(); 15 + println!("{}", str_slice); 16 + } 17 + 18 + #[no_mangle] 9 19 pub extern "C" fn start_server() { 10 20 const BANNER: &str = r#" 11 21 __________ __ ___. ··· 16 26 \/ \/ \/ \/ \/ 17 27 "#; 18 28 19 - // Start the server 20 29 println!("{}", BANNER.yellow()); 21 30 31 + let port = std::env::var("ROCKBOX_TCP_PORT").unwrap_or_else(|_| "6063".to_string()); 32 + let addr = format!("127.0.0.1:{}", port); 33 + let listener = TcpListener::bind(&addr).unwrap(); 34 + listener.set_nonblocking(true).unwrap(); 35 + 36 + println!( 37 + "{} server is listening on {}", 38 + "Rockbox TCP".bright_purple(), 39 + addr.bright_green() 40 + ); 41 + 42 + loop { 43 + match listener.accept() { 44 + Ok((stream, _)) => { 45 + handle_connection(stream); 46 + } 47 + Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => { 48 + // No incoming connection, just sleep and retry 49 + rb::system::sleep(rb::HZ / 2 as f32); 50 + } 51 + Err(e) => { 52 + eprintln!("Error accepting connection: {}", e); 53 + break; 54 + } 55 + } 56 + } 57 + } 58 + 59 + fn handle_connection(mut stream: TcpStream) { 60 + let buf_reader = BufReader::new(&mut stream); 61 + let http_request: Vec<_> = buf_reader 62 + .lines() 63 + .map(|result| result.unwrap()) 64 + .take_while(|line| !line.is_empty()) 65 + .collect(); 66 + 67 + // parse request 68 + let request = http_request[0].split_whitespace().collect::<Vec<_>>(); 69 + let method = request[0]; 70 + let path = request[1]; 71 + 72 + if method != "GET" { 73 + let response = "HTTP/1.1 405 Method Not Allowed\r\n\r\n"; 74 + stream.write_all(response.as_bytes()).unwrap(); 75 + return; 76 + } 77 + 78 + match path { 79 + "/pause" => { 80 + rb::playback::pause(); 81 + } 82 + "/resume" => { 83 + rb::playback::resume(); 84 + } 85 + "/next" => { 86 + rb::playback::next(); 87 + } 88 + "/prev" => { 89 + rb::playback::prev(); 90 + } 91 + "/stop" => { 92 + rb::playback::hard_stop(); 93 + } 94 + _ => { 95 + if path.starts_with("/play") { 96 + let params: Vec<_> = path.split('?').collect(); 97 + let params: Vec<_> = params[1].split('&').collect(); 98 + let elapsed = params[0].split('=').collect::<Vec<_>>()[1].parse().unwrap(); 99 + let offset = params[1].split('=').collect::<Vec<_>>()[1].parse().unwrap(); 100 + rb::playback::play(elapsed, offset); 101 + let response = "HTTP/1.1 200 OK\r\n\r\n"; 102 + stream.write_all(response.as_bytes()).unwrap(); 103 + return; 104 + } 105 + 106 + if path.starts_with("/ff_rewind") { 107 + let params: Vec<_> = path.split('?').collect(); 108 + let newtime = params[1].split('=').collect::<Vec<_>>()[1].parse().unwrap(); 109 + rb::playback::ff_rewind(newtime); 110 + let response = "HTTP/1.1 200 OK\r\n\r\n"; 111 + stream.write_all(response.as_bytes()).unwrap(); 112 + return; 113 + } 114 + 115 + let response = "HTTP/1.1 404 Not Found\r\n\r\n"; 116 + stream.write_all(response.as_bytes()).unwrap(); 117 + return; 118 + } 119 + } 120 + 121 + let response = "HTTP/1.1 200 OK\r\n\r\n"; 122 + 123 + stream.write_all(response.as_bytes()).unwrap(); 124 + } 125 + 126 + #[no_mangle] 127 + pub extern "C" fn start_servers() { 22 128 let (cmd_tx, cmd_rx) = std::sync::mpsc::channel::<RockboxCommand>(); 23 129 let cmd_tx = Arc::new(Mutex::new(cmd_tx)); 24 130 25 131 thread::spawn(move || { 132 + let port = std::env::var("ROCKBOX_TCP_PORT").unwrap_or_else(|_| "6063".to_string()); 133 + let url = format!("http://127.0.0.1:{}", port); 134 + 26 135 while let Ok(event) = cmd_rx.recv() { 27 136 match event { 28 137 RockboxCommand::Play(elapsed, offset) => { 29 - rb::playback::play(elapsed, offset); 138 + reqwest::blocking::get(&format!( 139 + "{}/play?elapsed={}&offset={}", 140 + url, elapsed, offset 141 + )) 142 + .unwrap(); 30 143 } 31 144 RockboxCommand::Pause => { 32 - rb::playback::pause(); 145 + reqwest::blocking::get(&format!("{}/pause", url)).unwrap(); 33 146 } 34 147 RockboxCommand::Resume => { 35 - rb::playback::resume(); 148 + reqwest::blocking::get(&format!("{}/resume", url)).unwrap(); 36 149 } 37 150 RockboxCommand::Next => { 38 - rb::playback::next(); 151 + reqwest::blocking::get(&format!("{}/next", url)).unwrap(); 39 152 } 40 153 RockboxCommand::Prev => { 41 - rb::playback::prev(); 154 + reqwest::blocking::get(&format!("{}/prev", url)).unwrap(); 42 155 } 43 156 RockboxCommand::FfRewind(newtime) => { 44 - rb::playback::ff_rewind(newtime); 157 + reqwest::blocking::get(&format!("{}/ff_rewind?newtime={}", url, newtime)) 158 + .unwrap(); 45 159 } 46 160 RockboxCommand::FlushAndReloadTracks => { 47 - rb::playback::flush_and_reload_tracks(); 161 + reqwest::blocking::get(&format!("{}/flush_and_reload_tracks", url)).unwrap(); 48 162 } 49 163 RockboxCommand::Stop => { 50 - rb::playback::hard_stop(); 164 + reqwest::blocking::get(&format!("{}/stop", url)).unwrap(); 51 165 } 52 166 } 53 167 }
+3 -2
crates/sys/src/lib.rs
··· 1 - use std::ffi::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void}; 1 + use std::ffi::{c_char, c_float, c_int, c_long, c_uchar, c_uint, c_ulong, c_void}; 2 2 3 3 pub mod browse; 4 4 pub mod dir; ··· 19 19 const ID3V2_BUF_SIZE: usize = 1800; 20 20 const MAX_PATHNAME: usize = 80; 21 21 const NB_SCREENS: usize = 2; 22 + pub const HZ: f32 = 100.0; 22 23 23 24 #[repr(C)] 24 25 #[derive(Debug, Copy, Clone)] ··· 811 812 ) -> c_uchar; 812 813 813 814 // Kernel / System 814 - fn sleep(ticks: c_uint); 815 + fn sleep(ticks: c_float); 815 816 fn r#yield(); 816 817 fn current_tick(); 817 818 fn default_event_handler(event: c_long);
+1 -1
crates/sys/src/system.rs
··· 1 - pub fn sleep(ticks: u32) { 1 + pub fn sleep(ticks: f32) { 2 2 unsafe { 3 3 crate::sleep(ticks); 4 4 }