From 49214de125c9143b1387e4b0fdf977697f190d54 Mon Sep 17 00:00:00 2001 From: radius Date: Sat, 15 Sep 2018 17:44:46 -0500 Subject: [PATCH] [record] start whipping some sense into this feature --- .vscode/settings.json | 3 ++- command.c | 9 ++++++--- config.def.h | 4 ++++ configuration.c | 12 ++++++++++++ configuration.h | 5 ++++- paths.c | 9 +++++++++ record/record_driver.c | 37 +++++++++++++++++++++++++++++-------- record/record_driver.h | 2 +- retroarch.c | 7 ++++++- 9 files changed, 73 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3b105d2389..1fde8c11fd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,7 +18,8 @@ "driver.h": "c", "iosfwd": "c", "xlocbuf": "c", - "xmemory0": "c" + "xmemory0": "c", + "ios": "c" }, "C_Cpp.dimInactiveRegions": false, } \ No newline at end of file diff --git a/command.c b/command.c index 1179f6151a..325c533b39 100644 --- a/command.c +++ b/command.c @@ -2176,9 +2176,12 @@ TODO: Add a setting for these tweaks */ return false; break; case CMD_EVENT_RECORD_INIT: - command_event(CMD_EVENT_HISTORY_DEINIT, NULL); - if (!recording_init()) - return false; + { + bool *recording_enabled = recording_is_enabled(); + *recording_enabled = true; + if (!recording_init(false)) + return false; + } break; case CMD_EVENT_HISTORY_DEINIT: if (g_defaults.content_history) diff --git a/config.def.h b/config.def.h index 8ecacdc99d..dd3bceda2e 100644 --- a/config.def.h +++ b/config.def.h @@ -654,6 +654,10 @@ static const unsigned libretro_log_level = 1; #define RARCH_DEFAULT_PORT 55435 #endif +#ifndef RARCH_STREAM_DEFAULT_PORT +#define RARCH_STREAM_DEFAULT_PORT 56400 +#endif + /* KEYBINDS, JOYPAD */ /* Axis threshold (between 0.0 and 1.0) diff --git a/configuration.c b/configuration.c index 4c8b373ff3..8cb0b1c9c3 100644 --- a/configuration.c +++ b/configuration.c @@ -1159,6 +1159,14 @@ static struct config_path_setting *populate_settings_path(settings_t *settings, #ifdef HAVE_OVERLAY SETTING_PATH("input_overlay", settings->paths.path_overlay, false, NULL, true); +#endif +#ifdef HAVE_FFMPEG + SETTING_PATH("video_record_config", + settings->paths.path_record_config, false, NULL, true); + SETTING_PATH("video_stream_config", + settings->paths.path_stream_config, false, NULL, true); + SETTING_PATH("video_stream_url", + settings->paths.path_stream_url, false, NULL, true); #endif SETTING_PATH("video_font_path", settings->paths.path_font, false, NULL, true); @@ -1580,6 +1588,7 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings, SETTING_UINT("aspect_ratio_index", &settings->uints.video_aspect_ratio_idx, true, aspect_ratio_idx, false); #ifdef HAVE_NETWORKING SETTING_UINT("netplay_ip_port", &settings->uints.netplay_port, true, RARCH_DEFAULT_PORT, false); + SETTING_UINT("video_stream_port", &settings->uints.video_stream_port, true, RARCH_STREAM_DEFAULT_PORT, false); SETTING_OVERRIDE(RARCH_OVERRIDE_SETTING_NETPLAY_IP_PORT); SETTING_UINT("netplay_input_latency_frames_min",&settings->uints.netplay_input_latency_frames_min, true, 0, false); SETTING_UINT("netplay_input_latency_frames_range",&settings->uints.netplay_input_latency_frames_range, true, 0, false); @@ -1921,6 +1930,9 @@ static void config_set_defaults(void) *settings->paths.path_menu_wallpaper = '\0'; *settings->paths.path_content_database = '\0'; *settings->paths.path_overlay = '\0'; + *settings->paths.path_record_config = '\0'; + *settings->paths.path_stream_config = '\0'; + *settings->paths.path_stream_url = '\0'; *settings->paths.path_softfilter_plugin = '\0'; *settings->arrays.playlist_names = '\0'; diff --git a/configuration.h b/configuration.h index c3a4c9c539..f4d40743e6 100644 --- a/configuration.h +++ b/configuration.h @@ -374,6 +374,7 @@ typedef struct settings unsigned video_msg_bgcolor_red; unsigned video_msg_bgcolor_green; unsigned video_msg_bgcolor_blue; + unsigned video_stream_port; unsigned menu_thumbnails; unsigned menu_left_thumbnails; @@ -478,6 +479,9 @@ typedef struct settings char path_cheat_database[PATH_MAX_LENGTH]; char path_content_database[PATH_MAX_LENGTH]; char path_overlay[PATH_MAX_LENGTH]; + char path_record_config[PATH_MAX_LENGTH]; + char path_stream_config[PATH_MAX_LENGTH]; + char path_stream_url[PATH_MAX_LENGTH]; char path_menu_wallpaper[PATH_MAX_LENGTH]; char path_audio_dsp_plugin[PATH_MAX_LENGTH]; char path_softfilter_plugin[PATH_MAX_LENGTH]; @@ -492,7 +496,6 @@ typedef struct settings char path_shader[PATH_MAX_LENGTH]; char path_font[PATH_MAX_LENGTH]; - char directory_audio_filter[PATH_MAX_LENGTH]; char directory_autoconfig[PATH_MAX_LENGTH]; char directory_video_filter[PATH_MAX_LENGTH]; diff --git a/paths.c b/paths.c index fc08a119be..7ad604b80b 100644 --- a/paths.c +++ b/paths.c @@ -721,6 +721,15 @@ enum rarch_content_type path_is_media_type(const char *path) string_to_lower(ext_lower); + /* hack, to detect livestreams so the ffmpeg core can be started */ + if ( + strstr(path, "udp://") || + strstr(path, "tcp://") || + strstr(path, "rtmp://") || + strstr(path, "rtp://") + ) + return RARCH_CONTENT_MOVIE; + switch (msg_hash_to_file_type(msg_hash_calculate(ext_lower))) { #if defined(HAVE_FFMPEG) || defined(HAVE_MPV) diff --git a/record/record_driver.c b/record/record_driver.c index 2426a36dac..ce82e54eec 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -35,6 +35,7 @@ #include "../verbosity.h" #include "../msg_hash.h" #include "../list_special.h" +#include "paths.h" static const record_driver_t *record_drivers[] = { @@ -309,9 +310,10 @@ void recording_push_audio(const int16_t *data, size_t samples) * * Returns: true (1) if successful, otherwise false (0). **/ -bool recording_init(void) +bool recording_init(bool stream) { - char recording_file[PATH_MAX_LENGTH]; + char output[PATH_MAX_LENGTH]; + char buf[PATH_MAX_LENGTH]; struct ffemu_params params = {0}; struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); bool *recording_enabled = recording_is_enabled(); @@ -321,7 +323,7 @@ bool recording_init(void) if (!*recording_enabled) return false; - recording_file[0] = '\0'; + output[0] = '\0'; if (rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) { @@ -343,19 +345,36 @@ bool recording_init(void) (float)av_info->timing.fps, (float)av_info->timing.sample_rate); - strlcpy(recording_file, global->record.path, sizeof(recording_file)); + if (!string_is_empty(global->record.path)) + strlcpy(output, global->record.path, sizeof(output)); + else + { + if(stream) + if (!string_is_empty(settings->paths.path_stream_url)) + strlcpy(output, settings->paths.path_stream_url, sizeof(output)); + else + /* to-do determine the local interface, this won't work for connecting over the internet*/ + snprintf(output, sizeof(output), "udp://127.0.0.1:%u", settings->uints.video_stream_port); + else + { + const char *game_name = path_basename(path_get(RARCH_PATH_BASENAME)); + fill_str_dated_filename(buf, game_name, + "mkv", sizeof(buf)); + fill_pathname_join(output, global->record.output_dir, buf, sizeof(output)); + } + } if (recording_use_output_dir) - fill_pathname_join(recording_file, + fill_pathname_join(output, global->record.output_dir, - global->record.path, sizeof(recording_file)); + global->record.path, sizeof(output)); params.out_width = av_info->geometry.base_width; params.out_height = av_info->geometry.base_height; params.fb_width = av_info->geometry.max_width; params.fb_height = av_info->geometry.max_height; params.channels = 2; - params.filename = recording_file; + params.filename = output; params.fps = av_info->timing.fps; params.samplerate = av_info->timing.sample_rate; params.pix_fmt = (video_driver_get_pixel_format() == RETRO_PIXEL_FORMAT_XRGB8888) ? @@ -364,6 +383,8 @@ bool recording_init(void) if (!string_is_empty(global->record.config)) params.config = global->record.config; + else if (!string_is_empty(settings->paths.path_record_config)) + params.config = settings->paths.path_record_config; if (video_driver_supports_recording()) { @@ -443,7 +464,7 @@ bool recording_init(void) RARCH_LOG("%s %s @ %ux%u. (FB size: %ux%u pix_fmt: %u)\n", msg_hash_to_str(MSG_RECORDING_TO), - global->record.path, + output, params.out_width, params.out_height, params.fb_width, params.fb_height, (unsigned)params.pix_fmt); diff --git a/record/record_driver.h b/record/record_driver.h index a8b087163a..582ca9c65b 100644 --- a/record/record_driver.h +++ b/record/record_driver.h @@ -158,7 +158,7 @@ void find_record_driver(void); * * Returns: true (1) if successful, otherwise false (0). **/ -bool recording_init(void); +bool recording_init(bool stream); bool *recording_is_enabled(void); diff --git a/retroarch.c b/retroarch.c index 183025e772..3be095f63b 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1320,6 +1320,7 @@ static void retroarch_main_init_media(void) bool retroarch_main_init(int argc, char *argv[]) { bool init_failed = false; + global_t *global = global_get_ptr(); retroarch_init_state(); @@ -1398,7 +1399,8 @@ bool retroarch_main_init(int argc, char *argv[]) command_event(CMD_EVENT_MAPPER_INIT, NULL); command_event(CMD_EVENT_REWIND_INIT, NULL); command_event(CMD_EVENT_CONTROLLERS_INIT, NULL); - command_event(CMD_EVENT_RECORD_INIT, NULL); + if (!string_is_empty(global->record.path)) + command_event(CMD_EVENT_RECORD_INIT, NULL); path_init_savefile(); @@ -3191,7 +3193,10 @@ static enum runloop_state runloop_check_state( current_input, RARCH_MOVIE_RECORD_TOGGLE); if (pressed && !old_pressed) + { + command_event(CMD_EVENT_RECORD_INIT, NULL); bsv_movie_check(); + } old_pressed = pressed; }