This commit is contained in:
Liam Waldron 2023-10-30 15:02:43 -04:00
commit 4edd9ca955
4 changed files with 216 additions and 0 deletions

37
common.h Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#ifndef INCLUDE_H_
#define INCLUDE_H_
/* Common headers */
#include <color.h>
#include <extractor.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/* mpv libraries */
#include <mpv/client.h>
/* Program headers */
#include "mp3fw.h"
#endif

73
mp3fw.c Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#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;
}
}
}

27
mp3fw.h Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#ifndef MP3FW_H_
#define MP3FW_H_
#define MP3FW_VERSION "0.0.1rc"
int mp3fw_playfile(int argc, char *argv[]);
#endif

79
player.c Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#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;
}