RetroArch/command.h

574 lines
18 KiB
C
Raw Normal View History

2012-07-27 22:47:35 -07:00
/* RetroArch - A frontend for libretro.
2013-12-31 16:50:59 -08:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2016-01-09 19:06:50 -08:00
* Copyright (C) 2011-2016 - Daniel De Matteis
2021-04-05 10:58:18 -07:00
* Copyright (C) 2021 - David G.F.
*
2012-07-27 22:47:35 -07:00
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
2015-04-13 02:39:40 -07:00
#ifndef COMMAND_H__
#define COMMAND_H__
2012-07-27 22:47:35 -07:00
#include <stdint.h>
2016-09-11 09:05:39 -07:00
#include <boolean.h>
#include <retro_common_api.h>
2012-07-27 22:47:35 -07:00
2016-09-11 09:05:39 -07:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2021-09-09 07:55:14 -07:00
#include <streams/interface_stream.h>
#include "retroarch_types.h"
2021-09-09 07:55:14 -07:00
#include "input/input_defines.h"
#include "configuration.h"
2021-09-09 07:55:14 -07:00
#define MAX_CMD_DRIVERS 3
#define DEFAULT_NETWORK_CMD_PORT 55355
RETRO_BEGIN_DECLS
2016-05-09 11:30:47 -07:00
enum event_command
{
2016-05-09 11:51:53 -07:00
CMD_EVENT_NONE = 0,
2016-05-09 11:30:47 -07:00
/* Resets RetroArch. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_RESET,
CMD_EVENT_SET_PER_GAME_RESOLUTION,
CMD_EVENT_SET_FRAME_LIMIT,
2016-05-09 11:30:47 -07:00
/* Loads core. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_LOAD_CORE,
CMD_EVENT_LOAD_CORE_PERSIST,
#if defined(HAVE_RUNAHEAD) && (defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB))
CMD_EVENT_LOAD_SECOND_CORE,
#endif
2016-05-09 11:51:53 -07:00
CMD_EVENT_UNLOAD_CORE,
2022-11-22 05:45:30 -08:00
/* Closes content. */
2020-09-03 09:40:07 -07:00
CMD_EVENT_CLOSE_CONTENT,
2022-11-22 05:45:30 -08:00
/* Swaps the current state with what's on the undo load buffer. */
CMD_EVENT_UNDO_LOAD_STATE,
2022-11-22 05:45:30 -08:00
/* Rewrites a savestate on disk. */
2016-06-04 12:34:06 -07:00
CMD_EVENT_UNDO_SAVE_STATE,
2022-11-22 05:45:30 -08:00
/* Save state hotkeys. */
CMD_EVENT_LOAD_STATE,
2016-05-09 11:51:53 -07:00
CMD_EVENT_SAVE_STATE,
CMD_EVENT_SAVE_STATE_DECREMENT,
CMD_EVENT_SAVE_STATE_INCREMENT,
/* Replay hotkeys. */
CMD_EVENT_PLAY_REPLAY,
CMD_EVENT_RECORD_REPLAY,
CMD_EVENT_HALT_REPLAY,
CMD_EVENT_REPLAY_DECREMENT,
CMD_EVENT_REPLAY_INCREMENT,
2022-11-22 05:45:30 -08:00
/* Save state actions. */
CMD_EVENT_SAVE_STATE_TO_RAM,
CMD_EVENT_LOAD_STATE_FROM_RAM,
CMD_EVENT_RAM_STATE_TO_FILE,
2016-05-09 11:30:47 -07:00
/* Takes screenshot. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_TAKE_SCREENSHOT,
2016-05-09 11:30:47 -07:00
/* Quits RetroArch. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_QUIT,
2016-05-09 11:30:47 -07:00
/* Reinitialize all drivers. */
2017-12-17 09:56:26 -08:00
CMD_EVENT_REINIT_FROM_TOGGLE,
/* Reinitialize all drivers. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_REINIT,
2016-05-09 11:30:47 -07:00
/* Toggles cheevos hardcore mode. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_CHEEVOS_HARDCORE_MODE_TOGGLE,
2016-05-09 11:30:47 -07:00
/* Deinitialize rewind. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_REWIND_DEINIT,
2016-05-09 11:30:47 -07:00
/* Initializes rewind. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_REWIND_INIT,
/* Reinitializes rewind (primarily if the state size changes). */
CMD_EVENT_REWIND_REINIT,
2016-05-09 11:30:47 -07:00
/* Toggles rewind. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_REWIND_TOGGLE,
2016-05-09 11:30:47 -07:00
/* Initializes autosave. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_AUTOSAVE_INIT,
2016-05-09 11:30:47 -07:00
/* Stops audio. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_AUDIO_STOP,
2016-05-09 11:30:47 -07:00
/* Starts audio. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_AUDIO_START,
2016-05-09 11:30:47 -07:00
/* Mutes audio. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_AUDIO_MUTE_TOGGLE,
2022-11-22 05:45:30 -08:00
/* Volume adjustments. */
CMD_EVENT_VOLUME_UP,
CMD_EVENT_VOLUME_DOWN,
CMD_EVENT_MIXER_VOLUME_UP,
CMD_EVENT_MIXER_VOLUME_DOWN,
2018-11-29 04:12:11 -08:00
/* Toggles FPS counter. */
CMD_EVENT_FPS_TOGGLE,
/* Toggles statistics display. */
CMD_EVENT_STATISTICS_TOGGLE,
2016-05-09 11:30:47 -07:00
/* Initializes overlay. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_OVERLAY_INIT,
/* Frees or caches overlay. */
CMD_EVENT_OVERLAY_UNLOAD,
2016-05-09 11:30:47 -07:00
/* Sets current scale factor for overlay. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_OVERLAY_SET_SCALE_FACTOR,
2016-05-09 11:30:47 -07:00
/* Sets current alpha modulation for overlay. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_OVERLAY_SET_ALPHA_MOD,
/* Sets diagonal sensitivities of overlay eightway areas. */
CMD_EVENT_OVERLAY_SET_EIGHTWAY_DIAGONAL_SENSITIVITY,
2016-05-09 11:30:47 -07:00
/* Deinitializes overlay. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_DSP_FILTER_INIT,
2016-05-09 11:30:47 -07:00
/* Initializes recording system. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_RECORD_INIT,
2016-05-09 11:30:47 -07:00
/* Deinitializes recording system. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_RECORD_DEINIT,
2016-05-09 11:30:47 -07:00
/* Deinitializes history playlist. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_HISTORY_DEINIT,
2016-05-09 11:30:47 -07:00
/* Initializes history playlist. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_HISTORY_INIT,
2016-05-09 11:30:47 -07:00
/* Deinitializes core information. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_CORE_INFO_DEINIT,
2016-05-09 11:30:47 -07:00
/* Initializes core information. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_CORE_INFO_INIT,
2016-05-09 11:30:47 -07:00
/* Deinitializes core. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_CORE_DEINIT,
2016-05-09 11:30:47 -07:00
/* Initializes core. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_CORE_INIT,
2016-05-09 11:30:47 -07:00
/* Apply video state changes. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_VIDEO_APPLY_STATE_CHANGES,
2016-05-09 11:30:47 -07:00
/* Set video blocking state. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_VIDEO_SET_BLOCKING_STATE,
2016-05-09 11:30:47 -07:00
/* Sets current aspect ratio index. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_VIDEO_SET_ASPECT_RATIO,
2016-05-09 11:30:47 -07:00
/* Restarts RetroArch. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_RESTART_RETROARCH,
2016-05-09 11:30:47 -07:00
/* Shutdown the OS */
2016-05-09 11:51:53 -07:00
CMD_EVENT_SHUTDOWN,
2016-05-09 11:30:47 -07:00
/* Reboot the OS */
2016-05-09 11:51:53 -07:00
CMD_EVENT_REBOOT,
2016-05-09 11:30:47 -07:00
/* Resume RetroArch when in menu. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_RESUME,
/* Add a playlist entry to favorites. */
CMD_EVENT_ADD_TO_FAVORITES,
/* Reset playlist entry associated core to DETECT */
2018-04-30 11:33:05 -07:00
CMD_EVENT_RESET_CORE_ASSOCIATION,
2016-05-09 11:30:47 -07:00
/* Toggles pause. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_PAUSE_TOGGLE,
2016-05-09 11:30:47 -07:00
/* Pauses RetroArch. */
2022-11-22 05:45:30 -08:00
CMD_EVENT_MENU_PAUSE_LIBRETRO,
2016-05-09 11:51:53 -07:00
CMD_EVENT_PAUSE,
2022-11-22 05:45:30 -08:00
/* Unpauses RetroArch. */
CMD_EVENT_UNPAUSE,
/* Toggles menu on/off. */
CMD_EVENT_MENU_TOGGLE,
/* Configuration saving. */
2018-09-30 17:13:53 -07:00
CMD_EVENT_MENU_RESET_TO_DEFAULT_CONFIG,
CMD_EVENT_MENU_SAVE_CONFIG,
2016-05-09 11:51:53 -07:00
CMD_EVENT_MENU_SAVE_CURRENT_CONFIG,
2016-08-26 07:43:29 -07:00
CMD_EVENT_MENU_SAVE_CURRENT_CONFIG_OVERRIDE_CORE,
2018-05-13 20:33:06 -07:00
CMD_EVENT_MENU_SAVE_CURRENT_CONFIG_OVERRIDE_CONTENT_DIR,
2016-08-26 07:43:29 -07:00
CMD_EVENT_MENU_SAVE_CURRENT_CONFIG_OVERRIDE_GAME,
CMD_EVENT_MENU_REMOVE_CURRENT_CONFIG_OVERRIDE_CORE,
CMD_EVENT_MENU_REMOVE_CURRENT_CONFIG_OVERRIDE_CONTENT_DIR,
CMD_EVENT_MENU_REMOVE_CURRENT_CONFIG_OVERRIDE_GAME,
2016-05-09 11:30:47 -07:00
/* Applies shader changes. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_SHADERS_APPLY_CHANGES,
/* A new shader preset has been loaded */
CMD_EVENT_SHADER_PRESET_LOADED,
2022-11-22 05:45:30 -08:00
/* Shader hotkeys. */
CMD_EVENT_SHADER_NEXT,
CMD_EVENT_SHADER_PREV,
CMD_EVENT_SHADER_TOGGLE,
2016-05-09 11:30:47 -07:00
/* Apply cheats. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_CHEATS_APPLY,
2022-11-22 05:45:30 -08:00
/* Cheat hotkeys. */
CMD_EVENT_CHEAT_TOGGLE,
CMD_EVENT_CHEAT_INDEX_PLUS,
CMD_EVENT_CHEAT_INDEX_MINUS,
2016-05-09 11:30:47 -07:00
/* Initializes network system. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_NETWORK_INIT,
/* Initializes netplay system with a string or no host specified. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_NETPLAY_INIT,
/* Initializes netplay system with a direct host specified. */
CMD_EVENT_NETPLAY_INIT_DIRECT,
/* Initializes netplay system with a direct host specified after loading content. */
CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED,
2016-05-09 11:30:47 -07:00
/* Deinitializes netplay system. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_NETPLAY_DEINIT,
/* Switch between netplay gaming and watching. */
CMD_EVENT_NETPLAY_GAME_WATCH,
Netplay Stuff (#13375) * Netplay Stuff ## PROTOCOL FALLBACK In order to support older clients a protocol fallback system was introduced. The host will no longer send its header automatically after a TCP connection is established, instead, it awaits for the client to send his before determining which protocol this connection is going to operate on. Netplay has now two protocols, a low protocol and a high protocol; the low protocol is the minimum protocol it supports, while the high protocol is the highest protocol it can operate on. To fully support older clients, a hack was necessary: sending the high protocol in the unused client's header salt field, while keeping the protocol field to the low protocol. Without this hack we would only be able to support older clients if a newer client was the host. Any future system can make use of this system by checking connection->netplay_protocol, which is available for both the client and host. ## NETPLAY CHAT Starting with protocol 6, netplay chat is available through the new NETPLAY_CMD_PLAYER_CHAT command. Limitations of the command code, which causes a disconnection on unknown commands, makes this system not possible on protocol 5. Protocol 5 connections can neither send nor receive chat, but other netplay operations are unaffected. Clients send chat as a string to the server, and it's the server's sole responsability to relay chat messages. As of now, sending chat uses RetroArch's input menu, while the display of on-screen chat uses a widget overlay and RetroArch's notifications as a fallback. If a new overlay and/or input system is desired, no backwards compatibility changes need to be made. Only clients in playing mode (as opposed to spectating mode) can send and receive chat. ## SETTINGS SHARING Some settings are better used when both host and clients share the same configuration. As of protocol 6, the following settings will be shared from host to clients (without altering a client's configuration file): input latency frames and allow pausing. ## NETPLAY TUNNEL/MITM With the current MITM system being defunct (at least as of 1.9.X), a new system was in order to solve most if not all of the problems with the current system. This new system uses a tunneling approach, which is similar to most VPN and tunneling services around. Tunnel commands: RATS[unique id] (RetroArch Tunnel Session) - 16 bytes -> When this command is sent with a zeroed unique id, the tunnel server interprets this as a netplay host wanting to create a new session, in this case, the same command is returned to the host, but now with its unique session id. When a client needs to connect to a host, this command is sent with the unique session id of the host, causing the tunnel server to send a RATL command to the host. RATL[unique id] (RetroArch Tunnel Link) - 16 bytes -> The tunnel server sends this command to the host when a client wants to connect to the host. Once the host receives this command, it establishes a new connection to the tunnel server, sending this command together with the client's unique id through this new connection, causing the tunnel server to link this connection to the connection of the client. RATP (RetroArch Tunnel Ping) - 4 bytes -> The tunnel server sends this command to verify that the host, whom the session belongs to, is still around. The host replies with the same command. A session is closed if the tunnel server can not verify that the host is alive. Operations: Host -> Instead of listening and accepting connections, it connects to the tunnel server, requests a new session and then monitor this connection for new linking requests. Once a request is received, it establishes a new connection to the tunnel server for linking with a client. The tunnel server's address and port are obtained by querying the lobby server. The host will publish its session id together with the rest of its info to the lobby server. Client -> It connects to the tunnel server and then sends the session id of the host it wants to connect to. A host's session id is obtained from the json data sent by the lobby server. Improvements (from current MITM system): No longer a risk of TCP port exhaustion; we only use one port now at the tunnel server. Very little cpu usage. About 95% net I/O bound now. Future backwards compatible with any and all changes to netplay as it no longer runs any netplay logic at MITM servers. No longer operates the host in client mode, which was a source of many of the current problems. Cleaner and more maintainable system and code. Notable functions: netplay_mitm_query -> Grabs the tunnel's address and port from the lobby server. init_tcp_socket -> Handles the creation and operation mode of the TCP socket based on whether it's host, host+MITM or client. handle_mitm_connection -> Creates and completes linking connections and replies to ping commands (only 1 of each per call to not affect performance). ## MISC Ping Limiter: If a client's estimated latency to the server is higher than this value, connection will be dropped just before finishing the netplay handshake. Ping Counter: A ping counter (similar to the FPS one) can be shown in the bottom right corner of the screen, if you are connected to a host. LAN Discovery: Refactored and moved to its own "Refresh Netplay LAN List" button. ## FIXES Many minor fixes to the current netplay implementation are also included. * Remove NETPLAY_TEST_BUILD
2021-12-19 07:58:01 -08:00
/* Open a netplay chat input menu. */
CMD_EVENT_NETPLAY_PLAYER_CHAT,
/* Toggle chat fading. */
CMD_EVENT_NETPLAY_FADE_CHAT_TOGGLE,
2019-03-09 14:48:03 -08:00
/* Start hosting netplay. */
CMD_EVENT_NETPLAY_ENABLE_HOST,
/* Disconnect from the netplay host. */
CMD_EVENT_NETPLAY_DISCONNECT,
2022-11-22 05:45:30 -08:00
/* Toggle ping counter. */
CMD_EVENT_NETPLAY_PING_TOGGLE,
/* Toggles netplay hosting. */
CMD_EVENT_NETPLAY_HOST_TOGGLE,
2016-05-09 11:30:47 -07:00
/* Reinitializes audio driver. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_AUDIO_REINIT,
2016-05-09 11:30:47 -07:00
/* Resizes windowed scale. Will reinitialize video driver. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_RESIZE_WINDOWED_SCALE,
2016-05-09 11:30:47 -07:00
/* Toggles disk eject. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_DISK_EJECT_TOGGLE,
2016-05-09 11:30:47 -07:00
/* Cycle to next disk. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_DISK_NEXT,
2016-05-09 11:30:47 -07:00
/* Cycle to previous disk. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_DISK_PREV,
2020-01-14 04:28:10 -08:00
/* Switch to specified disk index */
CMD_EVENT_DISK_INDEX,
2016-05-09 11:30:47 -07:00
/* Appends disk image to disk image list. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_DISK_APPEND_IMAGE,
2016-05-09 11:30:47 -07:00
/* Stops rumbling. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_RUMBLE_STOP,
2016-05-09 11:30:47 -07:00
/* Toggles mouse grab. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_GRAB_MOUSE_TOGGLE,
/* Toggles game focus. */
CMD_EVENT_GAME_FOCUS_TOGGLE,
2018-04-30 11:33:05 -07:00
/* Toggles desktop menu. */
CMD_EVENT_UI_COMPANION_TOGGLE,
2016-05-09 11:30:47 -07:00
/* Toggles fullscreen mode. */
2016-05-09 11:51:53 -07:00
CMD_EVENT_FULLSCREEN_TOGGLE,
2022-11-22 05:45:30 -08:00
/* Toggle recording. */
2019-06-08 06:19:15 -07:00
CMD_EVENT_RECORDING_TOGGLE,
2022-11-22 05:45:30 -08:00
/* Toggle streaming. */
2019-06-08 06:19:15 -07:00
CMD_EVENT_STREAMING_TOGGLE,
2022-11-22 05:45:30 -08:00
/* Toggle Run-Ahead. */
CMD_EVENT_RUNAHEAD_TOGGLE,
/* Toggle Preemtive Frames. */
CMD_EVENT_PREEMPT_TOGGLE,
/* Deinitialize or Reinitialize Preemptive Frames. */
CMD_EVENT_PREEMPT_UPDATE,
/* Force Preemptive Frames to refill its state buffer. */
CMD_EVENT_PREEMPT_RESET_BUFFER,
2022-11-22 05:45:30 -08:00
/* Toggle VRR runloop. */
CMD_EVENT_VRR_RUNLOOP_TOGGLE,
/* AI service. */
2019-06-08 06:19:15 -07:00
CMD_EVENT_AI_SERVICE_TOGGLE,
2020-01-31 18:27:58 -08:00
CMD_EVENT_AI_SERVICE_CALL,
2022-11-22 05:45:30 -08:00
/* Misc. */
CMD_EVENT_SAVE_FILES,
2022-11-22 05:45:30 -08:00
CMD_EVENT_CONTROLLER_INIT,
CMD_EVENT_DISCORD_INIT,
CMD_EVENT_PRESENCE_UPDATE,
CMD_EVENT_OVERLAY_NEXT,
CMD_EVENT_OSK_TOGGLE,
Add microphone support via a new driver (#14731) * Some slight fixes * Update libretro.h * Log calls to RETRO_ENVIRONMENT_GET_MICROPHONE_INTERFACE * Finish proof-of-concept for mic support - It works, but doesn't support floating-point audio yet - It may need to be resampled, too * Add macros that aren't available in SDL 2 * Comment out a variable definition for now - For C89 compliance * Add some comments for clarity * Let ALSA tolerate a null new_rate * Partial ALSA microphone support - Not yet tested - Mic is created and destroyed - Mic can also be paused or unpaused - Mic is paused or unpaused with the rest of the driver - Microphone is not yet read * Install error logging in the ALSA driver - It defers to RARCH_ERR * Free the ALSA microphone in alsa_free * Fix an indent * First draft of alsa_read_microphone * Deinitialize SDL Audio in sdl_audio_free * Save and restore the ALSA error logger - You should always practice safe global state * Add newlines to some RARCH_ERRs * Add some logging * Check for the mic being active via settings instead of via flags * Adjusted a log entry to be less misleading - A frequency of 0Hz looks weird to the uninformed - In reality, it means the driver used the requested frequency * Fix an incorrect format string * Tidy up logging in alsa.c * Rename audio_enable_microphone to audio_enable_input * Rename microphone_device to audio_input_device * Add audio_input_latency and audio_input_block_frames settings * Add all mic-related settings to the options menu * Adjust logging for alsa.c - Log the ALSA library version - Add errno details * Refer to the microphone in logs by name * Use %u instead of %d for some log items * Add input_samples_buf * Remove an inaccurate comment * Change type of input_samples_buf * Clean up audio_driver_flush_microphone_input * Comment convert_float_to_s16 - It helped me understand what it's doing - Turns out it'll work just fine on mono audio * Don't use the resampler for mic input * Fix crash in the ALSA driver when reading from a mic * Update some logging messages * ALSA support now works for mics * Reuse some common functions in alsa.c * Add alsa_thread_microphone_t * Refactor alsa.c - Introduce alsa_init_pcm to init any PCM that we're using - Vastly simplifies the implementation of alsa_init and alsa_init_microphone - Will be used for the read-based versions next * Make ALSA logging a little more consistent * Clean up the mic with alsa_free_microphone if alsa_init_microphone fails * Remove an unused function * Move some cleanup in alsa.c to a common function * First crack at mic support for alsathread - Refactor some duplicate code into functions - Use functions introduced in alsa.c - Create and destroy the mic * Slight cleanups for clarity * Implement alsa_thread_set/get_microphone_state * More work on alsathread - No more crashing, but the mic just returns silence * Slight cleanups for clarity * Add alsa_set_mic_enabled_internal - For setting the state of a microphone while considering its current state * Use alsa_set_mic_enabled_internal * Log a little more info * Log when the audio driver is started/stopped * Move base microphone driver code into a new directory - Add microphone_driver.c to Makefile.common - Rename functions as needed * Initialize and deinitialize the microphone driver * Implement sdl_microphone.c * Un-const an argument - In case the driver context needs to do any locking * Revise comments for microphone_driver.h * Remove an unimplemented function * Remove some functions from the mic driver * Remove mic functions from audio_thread_wrapper * Remove mic functions from sdl_audio * Fix microphone_null * Split the mic code for the alsa audio drivers into microphone drivers * Fix an extra struct member * Add a setting for the mic driver * Add a command to reinitialize the microphone driver * Rename mic-related settings * Add DRIVER_MICROPHONE_MASK to DRIVERS_CMD_ALL * Rename audio_enable_input to microphone_enable * Remove some labels from qt_options * Search for microphone_driver within find_driver_nonempty * Clean up some mic driver code * Pending mics now return silence * Adjust some logging and comments * Some cleanup in the microphone driver * Invert a flag check - Oops * Fix a log message * Fix the wrong flags being checked * Slight refactor of wasapi_init_device - Add a data_flow parameter - Declare it in a header - In preparation for WASAPI mic support * Add some WASAPI macros for _IAudioCaptureClient * Move some common WASAPI functions to audio/common/wasapi.c - They'll be used by the mic and the audio drivers * Add wasapi_log_hr * Generalize mmdevice_list_new to look for capture devices, too * Fix a function declaration * Move driver-specific device_list_new functions into their respective files * Clean up some declarations * First draft of wasapi microphone driver * Add wasapi_microphone_device_list_free * Change function parameter names to be consistent with microphone_driver * Partially implement wasapi_microphone_read - Mostly copied from the audio driver so far - It doesn't compile yet - But it'll be beautiful when I'm done with it * Refactor the mic driver's functions - Rename get_mic_active to mic_alive - Split set_mic_active into start_mic and stop_mic - Refactor the SDL mic driver accordingly * Edit some WASAPI functions for logging and clarity * Implement more of the WASAPI mic driver * Rename write_event to read_event * Pass the WASAPI driver context to the various read functions * Mostly implement the read function for the WASAPI mic driver * Fix a crash in microphone_driver - Forgot to move the position of the name of null_driver * Reduce some logging in wasapi common functions - Only log the chosen audio client format, not all attempted ones * Add some macro wrappers for IAudioClient methods * Update mic driver configuration - Make the mic driver configurable in the menu - Add config items for WASAPI-related options similar to the audio driver * Fix a menu entry scrolling through audio devices instead of mic devices * Add some utility functions * Expose the new utility functions in wasapi.h * Add extra logging in the WASAPI common functions * Add sharemode_name * Use _IAudioClient_Initialize macro in some places * Pass channels to wasapi_init_client - Remember, mics are in mono * Use _IAudioClient_Initialize macro some more * Forgot to pass channels in some places * Add some utility functions * Forgot an #include * Add wasapi_select_device_format * Simplify the format selection logic in wasapi_init_client_sh * Unset the microphone in wasapi_microphone_close_mic - Ought to prevent a potential segfault * Simplify some logging * Fix incorrect value being passed to _IAudioCaptureClient_ReleaseBuffer * Remove some unneeded logging * Add some values to hresult_name * Polish up wasapi_select_device_format - Test for formats manually when Windows can't - Add some debug logging - Check for channels * Compute the fields of WAVEFORMATEXTENSIBLE correctly - As per the doc's stated requirements * Simplify logic for WASAPI client creation * Fix a potential hang in wasapi_microphone_read_shared_buffered * Stop the microphone if the driver is stopped * Don't name the microphone event * Ensure that wasapi_init_client reports the correct format and rate * Implement exclusive microphone read access for WASAPI * Add _IAudioCaptureClient_GetNextPacketSize macro * Organize cases in hresult_name * Clear some extra fields if wasapi_set_format is setting a Pcm format * Adjust some logs * Adjust some logs * Remove unneeded local vars * Add a log * Update wasapi.c * Update wasapi.c * Fix shared-mode mic support in WASAPI producing broken input - Turns out it had nothing to do with shared mode * Reuse a common function - Remove wasapi_microphone_read_shared_buffered - Rename wasapi_microphone_read_exclusive to wasapi_microphone_read_buffered * Remove some code I was using for test purposes * Clarify some language * Double the default shared-mode mic buffer length * Split getting a device's name into a separate function, then use it * Fix the ALSA mic drivers - To comply with changes I previously made to the mic driver interface * Remove unused synchronization primitives from the SDL microphone driver * Add sdl_microphone_mic_use_float * Document audio_driver_state_flags - I needed to understand these to see if similar flags were required for the mic driver * Remove an unused function in wasapi.c * Add and document flags in microphone_driver.h * Remove driver-specific mic start/stop functions - The mic driver itself doesn't do much processing - That honor goes to individual mics * Remove some unused fields in microphone_driver.h * Add CMD_EVENT_MICROPHONE_STOP/START * Remove unused functions from microphone_null * Change how the mic driver state is referenced in some places * Simplify the SDL microphone driver - The driver backend no longer keeps a reference to the mic (the frontend does that) - Remove functions that are no longer needed - Don't track paused state, just query the mic itself * Simplify the WASAPI microphone driver - Don't track the driver running state or the microphone handle, the frontend does that now - Remove support for unbuffered input (hunterk suggested that it wasn't necessary) * Make microphone_wasapi_sh_buffer_length a uint, not an int - It won't be negative anymore - 0 now represents the default value * Make the microphone frontend more robust - Improve documentation for how various functions should be implemented - Closes all microphones before freeing the driver (so backends don't have to) - Tracks the enabled state of each microphone, so backends don't have to (but they still can) * Stop the mic driver in core_unload_game * Ensure mic support is compatible with the revised menu code * Move alsa.h into audio/common * Remove RETRO_ENVIRONMENT_GET_MICROPHONE_ENABLED - It was never really needed * Refactor the ALSA microphone driver - Move common ALSA functions to audio/common/alsa.c - Replace alsa_set_mic_enabled_internal with alsa_start/stop_pcm - Don't track the microphone handle in the ALSA driver context - Remove unneeded fields * Move some common alsathread code into audio/common/alsathread.c * Change return type of mic_driver_open_mic_internal to bool * First crack at resampling mic input * Remove an extraneous check - I think something distracted me when I was writing this line * Add stereo/mono conversion functions * Make alsa_start_pcm and alsa_stop_pcm more robust - They now return success if the stream is already running and stopped, respectively * Revise some mic-related comments in libretro.h * First crack at resampling mic input * Simplify an expression * Simplify an expression * Fix a log tag * Allow mic resampler to be configured separately from audio resampler * Add some comments * Set the source ratio to something sensible * Stop deadlock in `alsathread` mic driver * Allow mics to be initialized even when core is loaded from CLI - When loading content from CLI, the drivers are initialized a little differently - That threw off the mic initialization code * Rename the functions in retro_microphone_interface * Revise some mic-related comments in libretro.h * Update retro_microphone_interface - Add get_mic_rate - Add a parameter to open_mic - The modifications don't do anything yet * Use parameter objects in the microphone handle * Replace get_mic_rate with get_params * Add a microphone interface version * Remove part of a comment * Set the effective params in mic_driver_microphone_handle_init * Drop a stray newline * Change where the mic interface is zeroed - I was accidentally throwing out the version that the core was asking for * Reduce logspam for wasapi_set_nonblock_state - Now it only logs when the sync mode is changed * Change DEFAULT_WASAPI_SH_BUFFER_LENGTH to 0 - -16 is no longer a valid value * Set the new_rate in wasapi_init * Change description of microphone sample rate in the settings * First attempt at resampling configured mic input * Forgot a section * Fix some input samples being skipped * Rename a variable for clarity * Add microphone.outgoing_samples * Update the mic driver - Processed samples are now buffered - The resampler is skipped if the ratio is (very close to) 1 * Remove part of a comment * Update some comments in audio_resampler.h * Slightly refactor the SDL microphone driver - Move SDL_AudioSpec to a field of sdl_microphone_handle_t - Allow SDL to change the requested format and sample rate - Request floating-point input - Implement sdl_microphone_mic_use_float * Fix a non-C89-compliant declaration * Add new files to griffin.c * Remove a C++-style comment * Add two more files to griffin.c * Remove some unneeded declarations in microphone_driver.h * Remove a stray comma in configuration.c - For C89 compliance * Fix compilation on some platforms * Change some function signatures * Make the ALSA drivers always set the audio rate * Fix the alsathread mic driver * Make state_manager_frame_is_reversed return false if HAVE_REWIND isn't defined * Mute the microphone if the core is running in fast-forward, slow-mo, or rewind * Clarify a comment * Clarify a comment * Add a comment * Don't allocate memory for slowmo samples in the mic driver - We're not supporting slowmo for mics, so it's not needed * Fix a { * Add my name to AUTHORS.h * Add driver_lifetime_flags - For drivers that have special setup/teardown needs * Ensure that resetting the mic driver maintains active mic handles - Prevents fullscreen toggle from stopping all mic input * Update CHANGES.md * Move some default microphone settings to a new part of the config file * Ensure that RetroArch can use the audio format that Windows suggests * Remove references to mic support in the SDL audio driver * Remove unused WASAPI functions * Return failure if RetroArch couldn't select a WASAPI format * Ensure that Windows uses the WASAPI mic driver by default * Treat disabled mic support as a warning, not an error * Clarify some WASAPI-related microphone settings * Remove some unused variables * Add or revise microphone-related comments * Rearrange doc comments for microphone types in libretro.h * Remove a space * Remove some unused flags * Remove ALSA error logger - It was never used anyway * Remove unneeded microphone-related arguments * Document a parameter * Remove a logging call * Add a constant for the microphone's shared buffer length for WASAPI * Fix stylistic inconsistencies * Make mic_driver_get_sample_size a macro instead of a function * Move the microphone implementation to the audio directory * Make microphone support optional (but enabled by default) * Fix the griffin build
2023-06-06 12:55:06 -07:00
#ifdef HAVE_MICROPHONE
/* Stops all enabled microphones. */
CMD_EVENT_MICROPHONE_STOP,
/* Starts all enabled microphones */
CMD_EVENT_MICROPHONE_START,
/* Reinitializes microphone driver. */
CMD_EVENT_MICROPHONE_REINIT,
#endif
2022-11-22 05:45:30 -08:00
/* Deprecated */
CMD_EVENT_SEND_DEBUG_INFO,
/* Add a playlist entry to another playlist. */
CMD_EVENT_ADD_TO_PLAYLIST
2016-05-09 11:30:47 -07:00
};
enum cmd_source_t
{
CMD_NONE = 0,
CMD_STDIN,
CMD_NETWORK
};
struct cmd_map
{
const char *str;
unsigned id;
};
struct command_handler;
typedef void (*command_poller_t)(struct command_handler *cmd);
typedef void (*command_replier_t)(struct command_handler *cmd, const char * data, size_t len);
typedef void (*command_destructor_t)(struct command_handler *cmd);
struct command_handler
{
/* Interface to poll the driver */
command_poller_t poll;
/* Interface to reply */
command_replier_t replier;
/* Interface to delete the underlying command */
command_destructor_t destroy;
/* Underlying command storage */
void *userptr;
/* State received */
bool state[RARCH_BIND_LIST_END];
};
typedef struct command_handler command_t;
typedef struct command_handle
{
command_t *handle;
unsigned id;
} command_handle_t;
struct rarch_state;
2016-05-09 11:30:47 -07:00
/**
2016-05-09 11:51:53 -07:00
* command_event:
2016-05-09 11:30:47 -07:00
* @cmd : Command index.
*
* Performs RetroArch command with index @cmd.
*
* Returns: true (1) on success, otherwise false (0).
**/
bool command_event(enum event_command action, void *data);
2016-02-12 22:19:21 -08:00
/* Constructors for the supported drivers */
command_t* command_network_new(uint16_t port);
command_t* command_stdin_new(void);
command_t* command_uds_new(void);
bool command_network_send(const char *cmd_);
#ifdef HAVE_CONFIGFILE
bool command_event_save_config(
const char *config_path,
char *s, size_t len);
#endif
void command_event_undo_save_state(char *s, size_t len);
void command_event_undo_load_state(char *s, size_t len);
void command_event_set_mixer_volume(
settings_t *settings,
float gain);
bool command_event_resize_windowed_scale(settings_t *settings,
unsigned window_scale);
bool command_event_save_auto_state(void);
/**
* event_set_volume:
* @gain : amount of gain to be applied to current volume level.
*
* Adjusts the current audio volume level.
*
**/
void command_event_set_volume(
settings_t *settings,
float gain,
bool widgets_active,
bool audio_driver_mute_enable);
/**
* command_event_init_controllers:
*
* Initialize libretro controllers.
**/
void command_event_init_controllers(rarch_system_info_t *info,
settings_t *settings, unsigned num_active_users);
bool command_event_load_entry_state(settings_t *settings);
2021-11-08 21:03:00 -08:00
void command_event_load_auto_state(void);
2021-09-09 07:55:14 -07:00
void command_event_set_savestate_auto_index(
2021-11-08 21:03:00 -08:00
settings_t *settings);
2021-09-09 07:55:14 -07:00
void command_event_set_savestate_garbage_collect(
unsigned max_to_keep,
bool show_hidden_files
);
void command_event_set_replay_auto_index(
settings_t *settings);
void command_event_set_replay_garbage_collect(
unsigned max_to_keep,
bool show_hidden_files
);
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
bool command_set_shader(command_t *cmd, const char *arg);
#endif
2021-09-09 07:55:14 -07:00
#ifdef HAVE_CHEATS
void command_event_init_cheats(
bool apply_cheats_after_load,
const char *path_cheat_db,
void *bsv_movie_data);
2021-09-09 07:55:14 -07:00
#endif
#if defined(HAVE_COMMAND)
struct cmd_action_map
{
const char *str;
bool (*action)(command_t* cmd, const char *arg);
const char *arg_desc;
};
bool command_version(command_t *cmd, const char* arg);
bool command_get_status(command_t *cmd, const char* arg);
bool command_get_config_param(command_t *cmd, const char* arg);
bool command_show_osd_msg(command_t *cmd, const char* arg);
bool command_load_state_slot(command_t *cmd, const char* arg);
bool command_play_replay_slot(command_t *cmd, const char* arg);
#ifdef HAVE_CHEEVOS
bool command_read_ram(command_t *cmd, const char *arg);
bool command_write_ram(command_t *cmd, const char *arg);
#endif
bool command_read_memory(command_t *cmd, const char *arg);
bool command_write_memory(command_t *cmd, const char *arg);
static const struct cmd_action_map action_map[] = {
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
{ "SET_SHADER", command_set_shader, "<shader path>" },
#endif
{ "VERSION", command_version, "No argument"},
{ "GET_STATUS", command_get_status, "No argument" },
{ "GET_CONFIG_PARAM", command_get_config_param, "<param name>" },
{ "SHOW_MSG", command_show_osd_msg, "No argument" },
#if defined(HAVE_CHEEVOS)
/* These functions use achievement addresses and only work if a game with achievements is
* loaded. READ_CORE_MEMORY and WRITE_CORE_MEMORY are preferred and use system addresses. */
{ "READ_CORE_RAM", command_read_ram, "<address> <number of bytes>" },
{ "WRITE_CORE_RAM", command_write_ram, "<address> <byte1> <byte2> ..." },
#endif
{ "READ_CORE_MEMORY", command_read_memory, "<address> <number of bytes>" },
{ "WRITE_CORE_MEMORY",command_write_memory, "<address> <byte1> <byte2> ..." },
{ "LOAD_STATE_SLOT",command_load_state_slot, "<slot number>"},
{ "PLAY_REPLAY_SLOT",command_play_replay_slot, "<slot number>"},
};
static const struct cmd_map map[] = {
{ "MENU_TOGGLE", RARCH_MENU_TOGGLE },
{ "QUIT", RARCH_QUIT_KEY },
{ "CLOSE_CONTENT", RARCH_CLOSE_CONTENT_KEY },
{ "RESET", RARCH_RESET },
2022-11-22 05:45:30 -08:00
{ "FAST_FORWARD", RARCH_FAST_FORWARD_KEY },
{ "FAST_FORWARD_HOLD", RARCH_FAST_FORWARD_HOLD_KEY },
{ "SLOWMOTION", RARCH_SLOWMOTION_KEY },
{ "SLOWMOTION_HOLD", RARCH_SLOWMOTION_HOLD_KEY },
{ "REWIND", RARCH_REWIND },
{ "PAUSE_TOGGLE", RARCH_PAUSE_TOGGLE },
{ "FRAMEADVANCE", RARCH_FRAMEADVANCE },
{ "MUTE", RARCH_MUTE },
{ "VOLUME_UP", RARCH_VOLUME_UP },
{ "VOLUME_DOWN", RARCH_VOLUME_DOWN },
{ "LOAD_STATE", RARCH_LOAD_STATE_KEY },
{ "SAVE_STATE", RARCH_SAVE_STATE_KEY },
{ "STATE_SLOT_PLUS", RARCH_STATE_SLOT_PLUS },
{ "STATE_SLOT_MINUS", RARCH_STATE_SLOT_MINUS },
{ "PLAY_REPLAY", RARCH_PLAY_REPLAY_KEY },
{ "RECORD_REPLAY", RARCH_RECORD_REPLAY_KEY },
{ "HALT_REPLAY", RARCH_HALT_REPLAY_KEY },
{ "REPLAY_SLOT_PLUS", RARCH_REPLAY_SLOT_PLUS },
{ "REPLAY_SLOT_MINUS", RARCH_REPLAY_SLOT_MINUS },
{ "DISK_EJECT_TOGGLE", RARCH_DISK_EJECT_TOGGLE },
{ "DISK_NEXT", RARCH_DISK_NEXT },
{ "DISK_PREV", RARCH_DISK_PREV },
{ "SHADER_TOGGLE", RARCH_SHADER_TOGGLE },
{ "SHADER_NEXT", RARCH_SHADER_NEXT },
{ "SHADER_PREV", RARCH_SHADER_PREV },
{ "CHEAT_TOGGLE", RARCH_CHEAT_TOGGLE },
{ "CHEAT_INDEX_PLUS", RARCH_CHEAT_INDEX_PLUS },
{ "CHEAT_INDEX_MINUS", RARCH_CHEAT_INDEX_MINUS },
{ "SCREENSHOT", RARCH_SCREENSHOT },
{ "RECORDING_TOGGLE", RARCH_RECORDING_TOGGLE },
{ "STREAMING_TOGGLE", RARCH_STREAMING_TOGGLE },
{ "GRAB_MOUSE_TOGGLE", RARCH_GRAB_MOUSE_TOGGLE },
{ "GAME_FOCUS_TOGGLE", RARCH_GAME_FOCUS_TOGGLE },
{ "FULLSCREEN_TOGGLE", RARCH_FULLSCREEN_TOGGLE_KEY },
{ "UI_COMPANION_TOGGLE", RARCH_UI_COMPANION_TOGGLE },
{ "VRR_RUNLOOP_TOGGLE", RARCH_VRR_RUNLOOP_TOGGLE },
{ "RUNAHEAD_TOGGLE", RARCH_RUNAHEAD_TOGGLE },
{ "PREEMPT_TOGGLE", RARCH_PREEMPT_TOGGLE },
{ "FPS_TOGGLE", RARCH_FPS_TOGGLE },
{ "STATISTICS_TOGGLE", RARCH_STATISTICS_TOGGLE },
{ "AI_SERVICE", RARCH_AI_SERVICE },
{ "NETPLAY_PING_TOGGLE", RARCH_NETPLAY_PING_TOGGLE },
{ "NETPLAY_HOST_TOGGLE", RARCH_NETPLAY_HOST_TOGGLE },
{ "NETPLAY_GAME_WATCH", RARCH_NETPLAY_GAME_WATCH },
{ "NETPLAY_PLAYER_CHAT", RARCH_NETPLAY_PLAYER_CHAT },
{ "NETPLAY_FADE_CHAT_TOGGLE", RARCH_NETPLAY_FADE_CHAT_TOGGLE },
{ "MENU_UP", RETRO_DEVICE_ID_JOYPAD_UP },
{ "MENU_DOWN", RETRO_DEVICE_ID_JOYPAD_DOWN },
{ "MENU_LEFT", RETRO_DEVICE_ID_JOYPAD_LEFT },
{ "MENU_RIGHT", RETRO_DEVICE_ID_JOYPAD_RIGHT },
{ "MENU_A", RETRO_DEVICE_ID_JOYPAD_A },
{ "MENU_B", RETRO_DEVICE_ID_JOYPAD_B },
2022-11-22 05:45:30 -08:00
{ "OVERLAY_NEXT", RARCH_OVERLAY_NEXT },
{ "OSK", RARCH_OSK },
#if 0
/* Deprecated */
{ "SEND_DEBUG_INFO", RARCH_SEND_DEBUG_INFO },
#endif
};
#endif
#ifdef HAVE_CONFIGFILE
/**
* command_event_save_core_config:
*
* Saves a new (core) configuration to a file. Filename is based
* on heuristics to avoid typing.
*
* Returns: true (1) on success, otherwise false (0).
**/
bool command_event_save_core_config(
const char *dir_menu_config,
const char *rarch_path_config);
/**
* command_event_save_current_config:
*
* Saves current configuration file to disk, and (optionally)
* autosave state.
**/
void command_event_save_current_config(enum override_type type);
/**
* command_event_remove_current_config:
*
* Removes current configuration file from disk.
**/
void command_event_remove_current_config(enum override_type type);
#endif
/**
* command_event_disk_control_append_image:
* @path : Path to disk image.
*
* Appends disk image to disk image list.
**/
bool command_event_disk_control_append_image(const char *path);
2021-11-03 16:38:18 -07:00
void command_event_reinit(const int flags);
bool command_event_main_state(unsigned cmd);
RETRO_END_DECLS
2013-04-21 01:05:12 -07:00
2012-07-27 22:47:35 -07:00
#endif