From 4edd9ca95507a012c6f77660b4717cf071df8dc5 Mon Sep 17 00:00:00 2001 From: Liam Waldron Date: Mon, 30 Oct 2023 15:02:43 -0400 Subject: [PATCH] init --- common.h | 37 ++++++++++++++++++++++++++ mp3fw.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ mp3fw.h | 27 +++++++++++++++++++ player.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 216 insertions(+) create mode 100644 common.h create mode 100644 mp3fw.c create mode 100644 mp3fw.h create mode 100644 player.c diff --git a/common.h b/common.h new file mode 100644 index 0000000..4fc4b6f --- /dev/null +++ b/common.h @@ -0,0 +1,37 @@ +/* + common.h - includes common headers + + This file is part of mp3fw. + + mp3fw is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + mp3fw is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with mp3fw. If not, see . +*/ + +#ifndef INCLUDE_H_ +#define INCLUDE_H_ + +/* Common headers */ +#include +#include +#include +#include +#include +#include + +/* mpv libraries */ +#include + +/* Program headers */ +#include "mp3fw.h" + +#endif diff --git a/mp3fw.c b/mp3fw.c new file mode 100644 index 0000000..bb826a8 --- /dev/null +++ b/mp3fw.c @@ -0,0 +1,73 @@ +/* + mp3fw.c - mp3 player firmware + + This file is part of mp3fw. + + mp3fw is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + mp3fw is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with mp3fw. If not, see . +*/ + +#include "common.h" + +static void +usage(int argc, char *argv[]) +{ + printf("%s - play audio files\n", argv[0]); + printf("usage: %s [-h] [-v] [-p] FILE\n", argv[0]); + printf("\n"); + printf("%s {-h} Show this message\n", argv[0]); + printf("%s {-v} Show the current version\n", argv[0]); + printf("%s {-p} FILE Play an audio file\n", argv[0]); + printf("\n"); + printf("mp3fw is free software.\n"); + printf("See the GNU GPL version 3 for details.\n"); +} + +static void +usage_small(int argc, char *argv[]) +{ + printf("usage: %s [-h] [-v] [-p] FILE\n", argv[0]); +} + +int +main(int argc, char *argv[]) +{ + + if (argc < 2) { + usage_small(argc, argv); + exit(1); + } + + int opt; + + while ((opt = getopt(argc, argv, ":if:hvp")) != -1) { + switch(opt) { + case 'h': + usage(argc, argv); + exit(0); + break; + case 'v': + printf(MP3FW_VERSION "\n"); + exit(0); + break; + case 'p': + mp3fw_playfile(argc, argv); + exit(0); + break; + case '?': + usage_small(argc, argv); + exit(1); + break; + } + } +} diff --git a/mp3fw.h b/mp3fw.h new file mode 100644 index 0000000..e55ad3b --- /dev/null +++ b/mp3fw.h @@ -0,0 +1,27 @@ +/* + mp3fw.h - mp3 player firmware + + This file is part of mp3fw. + + mp3fw is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + mp3fw is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with mp3fw. If not, see . +*/ + +#ifndef MP3FW_H_ +#define MP3FW_H_ + +#define MP3FW_VERSION "0.0.1rc" + +int mp3fw_playfile(int argc, char *argv[]); + +#endif diff --git a/player.c b/player.c new file mode 100644 index 0000000..86d8f8c --- /dev/null +++ b/player.c @@ -0,0 +1,79 @@ +/* + player.c - backend player functions + + This file is part of mp3fw. + + mp3fw is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + mp3fw is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with mp3fw. If not, see . +*/ + +#include "common.h" + +/* + Positional Parameters + + (user)$ mp3fw -p FILE + 0 1 2 +*/ + + +static inline void +check_error(int status) +{ + if (status < 0) { + printf("mpv API error: %s\n", mpv_error_string(status)); + } +} + +int +mp3fw_playfile(int argc, char *argv[]) +{ + + /* struct EXTRACTOR_PluginList *plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY); + EXTRACTOR_extract(plugins, argv[2], NULL, 0, &EXTRACTOR_meta_data_print, stdout); + EXTRACTOR_plugin_remove_all(plugins); */ + + if (argc != 3) { + printf("no audio file was passed into player\n"); + return 1; + } + + mpv_handle *ctx = mpv_create(); + if (!ctx) { + printf("failed creating context\n"); + return 1; + } + + check_error(mpv_set_option_string(ctx, "input-default-bindings", "yes")); + mpv_set_option_string(ctx, "input-vo-keyboard", "yes"); + int val = 1; + check_error(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &val)); + + check_error(mpv_initialize(ctx)); + + printf("loading file %s\n", argv[2]); + + const char *cmd[] = {"loadfile", argv[2], NULL}; + check_error(mpv_command(ctx, cmd)); + + do { + mpv_event *event = mpv_wait_event(ctx, 10000); + printf("event: %s\n", mpv_event_name(event->event_id)); + if (event->event_id == MPV_EVENT_SHUTDOWN) + break; + } + + while (1); + mpv_terminate_destroy(ctx); + return 0; +}