From d0a283621df3ceeaffab5599edeb7c3bc032a1be Mon Sep 17 00:00:00 2001 From: Yessiest Date: Sat, 20 May 2023 03:37:57 +0400 Subject: [PATCH] Added playlists and config loading --- Makefile | 2 +- mpv-libretro.c | 82 +++++++++++++++++++++++++++++++++-------------- mpv_libretro.info | 19 +++++++++++ 3 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 mpv_libretro.info diff --git a/Makefile b/Makefile index 5c15763..eb2ae84 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ STATIC_LINKING := 0 AR := ar -DEBUG := 0 +DEBUG := 1 TARGET_NAME := mpv PREFIX := /usr LIBDIR := $(PREFIX)/lib diff --git a/mpv-libretro.c b/mpv-libretro.c index e663878..f80c2e6 100644 --- a/mpv-libretro.c +++ b/mpv-libretro.c @@ -97,20 +97,23 @@ static void process_mpv_events(mpv_event_id event_block) { struct mpv_event_end_file *eof = (struct mpv_event_end_file *)mp_event->data; - - if(eof->reason == MPV_END_FILE_REASON_EOF) - environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, NULL); -#if 0 - /* The following could be done instead if the file was not - * closed once the end was reached - allowing the user to seek - * back without reopening the file. - */ - struct retro_message ra_msg = { - "Finished playing file", 60 * 5, /* 5 seconds */ - }; - - environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &ra_msg);RETRO_ENVIRONMENT_SHUTDOWN -#endif + int *playlist_current_id = malloc(sizeof(int)); + int ret = 0; + if ((ret = mpv_get_property(mpv, "playlist-pos", MPV_FORMAT_INT64, playlist_current_id)) < 0) + { + *playlist_current_id = -1; + } + log_cb(RETRO_LOG_INFO,"[testing shit] %d, %d\n", + ret,*playlist_current_id); + if(eof->reason == MPV_END_FILE_REASON_EOF) { + if (*playlist_current_id == -1) { + free(playlist_current_id); + environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, NULL); + } else { + free(playlist_current_id); + continue; + } + } } else if(mp_event->event_id == MPV_EVENT_NONE) continue; @@ -236,9 +239,25 @@ void retro_set_environment(retro_environment_t cb) log_cb = fallback_log; } +const char *get_filename_ext(const char *filename) { + const char *dot = strrchr(filename, '.'); + if(!dot || dot == filename) return ""; + return dot + 1; +} + +const char *get_mpv_config() { + char *fullpath = malloc(64); + memset(fullpath, 0, 64); + const char* homepath = getenv("HOME"); + strcat(fullpath, homepath); + strcat(fullpath, "/.config/mpv/mpv.conf"); + return (const char*)fullpath; +} + static void context_reset(void) { - const char *cmd[] = {"loadfile", filepath, NULL}; + const char *cmd[] = {(strcmp(get_filename_ext(filepath),"txt") == 0) ? "loadlist" : "loadfile", filepath, NULL}; + const char *config_path = get_mpv_config(); int ret; #ifdef HAVE_LOCALE @@ -252,6 +271,19 @@ static void context_reset(void) log_cb(RETRO_LOG_ERROR, "failed creating context\n"); exit(EXIT_FAILURE); } + + if((ret = mpv_set_property_string(mpv,"osc","yes")) < 0) + { + log_cb(RETRO_LOG_ERROR, "unable to enable OSC: %s\n", + mpv_error_string(ret)); + } + + + if((ret = mpv_load_config_file(mpv,config_path)) < 0) + { + log_cb(RETRO_LOG_ERROR, "unable to load config file %s: %s\n", + config_path,mpv_error_string(ret)); + } if((ret = mpv_initialize(mpv)) < 0) { @@ -287,19 +319,21 @@ static void context_reset(void) /* Attempt to enable hardware acceleration. MPV will fallback to software * decoding on failure. */ + /* hardware decoding enabled by default breaks on bcm2835. + * enable at your own risk via config file + if((ret = mpv_set_option_string(mpv, "hwdec", "auto")) < 0) { log_cb(RETRO_LOG_ERROR, "failed to set hwdec option: %s\n", mpv_error_string(ret)); } - + */ if((ret = mpv_command(mpv, cmd)) != 0) { log_cb(RETRO_LOG_ERROR, "mpv_command failed to load input file: %s\n", mpv_error_string(ret)); goto err; } - /* TODO #2: Check for the highest samplerate in audio stream, and use that. * Fall back to 48kHz otherwise. * We currently force the audio to be sampled at 48KHz. @@ -444,30 +478,30 @@ static void retropad_update_input(void) 0, RETRO_DEVICE_ID_JOYPAD_A) != 0 ? 1 : 0; if(current.l == 1 && last.l == 0) - mpv_command_string(mpv, "cycle audio"); + mpv_command_string(mpv, "osd-msg cycle audio"); if(current.r == 1 && last.r == 0) - mpv_command_string(mpv, "cycle sub"); + mpv_command_string(mpv, "osd-msg cycle sub"); if(current.a == 1 && last.a == 0) - mpv_command_string(mpv, "cycle pause"); + mpv_command_string(mpv, "osd-msg cycle pause"); /* TODO #3: Press and hold commands with small delay */ if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT)) - mpv_command_string(mpv, "seek -5"); + mpv_command_string(mpv, "osd-msg-bar seek -5"); if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT)) - mpv_command_string(mpv, "seek 5"); + mpv_command_string(mpv, "osd-msg-bar seek 5"); if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP)) - mpv_command_string(mpv, "seek 60"); + mpv_command_string(mpv, "osg-msg-bar seek 60"); if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN)) - mpv_command_string(mpv, "seek -60"); + mpv_command_string(mpv, "osg-msg-bar seek -60"); /* Press and hold commands */ if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, diff --git a/mpv_libretro.info b/mpv_libretro.info new file mode 100644 index 0000000..f6221f6 --- /dev/null +++ b/mpv_libretro.info @@ -0,0 +1,19 @@ +# Software Information +display_name = "MPV" +authors = "MPV team|FFmpeg team" +supported_extensions = "mkv|avi|f4v|f4f|3gp|ogm|flv|mp4|mp3|flac|ogg|m4a|webm|3g2|mov|wmv|mpg|mpeg|vob|asf|divx|m2p|m2ts|ps|ts|mxf|wma|wav|txt" +corename = "MPV" +categories = "Media player" +license = "LGPLv2, GPLv2" +permissions = "" +display_version = "Git" + +# Hardware Information +systemname = "MPV" +systemid = "movie" + +# Libretro Features +supports_no_game = "false" +is_experimental = "true" + +description = "An experimental media player ported to libretro. This core is similar in function to the ffmpeg-libretro core but using the powerful and modern MPV backend instead. Most users will be better-served by the ffmpeg core, but this one may yield a better user experience with improved controls and capabilities."