Commit graph

113 commits

Author SHA1 Message Date
Sergey Stepanov
62fc68e88b
Add optional static linking with vpx, x264, opus 2023-04-24 00:16:00 +03:00
Sergey Stepanov
ece1efad16
Add optional static linking with vpx, x264, opus 2023-04-23 23:51:38 +03:00
Sergey Stepanov
8893e1e5bf Update config manager 2023-04-22 17:05:28 +03:00
Sergey Stepanov
eda90d74e6
Rename C.stop (it crashes PCSX on Ubuntu) wtf omegalol 2023-04-21 00:26:41 +03:00
Sergey Stepanov
ee58af488d
Advance 1 frame only with Mupen 2023-04-20 22:54:35 +03:00
Sergey Stepanov
c8eb672ecd
Fix missing return 2023-04-20 22:54:12 +03:00
Sergey Stepanov
f00c27a226
Clean nanoarch 2023-04-20 14:18:57 +03:00
Sergey Stepanov
853c7a6f81 Fix save/load for Mupen64
By passing function arguments into the synchronized un-libco loop, we can now save and restore Mupen game states without segfaults.
2023-04-16 13:24:28 +03:00
Sergey Stepanov
b48a6c92f6 Refactor nanoarch names 2023-04-16 13:24:28 +03:00
Sergey Stepanov
5034f86667 Save/Load without malloc 2023-04-16 13:24:28 +03:00
Sergey Stepanov
d830821ceb Move last frame time init fn to the end 2023-04-16 13:24:28 +03:00
Sergey Stepanov
137397dbc1 Update Libretro env handlers 2023-04-16 13:24:28 +03:00
Sergey Stepanov
66dbdba863 Use explicit Libretro log levels instead of magic numbers 2023-04-16 13:24:28 +03:00
Sergey Stepanov
33099d098f Use new page-segmentation friendly unsafe.Slice for mem restore 2023-04-16 13:24:28 +03:00
Sergey Stepanov
43cb05e088 Remove unused OS signal handlers in C
The idea is that we make just one OS signals handler on the C (CGO) side instead of Go and handle everything there from both, which is needed for proper termination process of multithreaded Libretro cores. But it leads to strange segfaults.
2023-04-16 13:24:28 +03:00
Sergey Stepanov
a1b24b0a85 Handle faster most called Libretro env getters 2023-04-16 13:24:28 +03:00
Sergey Stepanov
7c2b88716b Update libretro.h 2023-04-16 13:24:28 +03:00
Sergey Stepanov
9325fddc1f Make RETRO_ENVIRONMENT_GET_SAVESTATE_CONTEXT return RETRO_SAVESTATE_CONTEXT_NORMAL explicitly for NeoGEO 2023-04-16 13:24:28 +03:00
Sergey Stepanov
5920af5a36
Add RETRO_ENVIRONMENT_GET_SAVESTATE_CONTEXT for NeoGEO 2023-04-08 01:18:41 +03:00
Sergey Stepanov
7b0d212fc0
Simplify core options passing 2023-04-06 20:40:58 +03:00
Sergey Stepanov
e3ecd8fef0
Remove not needed rand seeding 2023-04-06 20:39:41 +03:00
sergystepanov
cfd5b1ae8d
Libretro cores config in yaml (#392)
Removes separate config files for Libretro cores stored in the cores folder and replaces them with options in the main config.yaml file.
2023-04-06 11:25:49 +03:00
Sergey Stepanov
b5cb33812b
Add dummy CLEAR_ALL_THREAD_WAITS_CB for Mupen64 core in order to support the threaded renderer 2023-04-04 17:59:24 +03:00
Sergey Stepanov
9178dab7dd
Fix N64 overlapping frame draw 2023-04-03 20:39:49 +03:00
Sergey Stepanov
0f66f35673
Add the initial RETRO_ENVIRONMENT_SET_MESSAGE support 2023-03-31 18:50:42 +03:00
Sergey Stepanov
b24e82c145
Fix disabled cloud save downloads 2023-03-26 00:14:19 +03:00
Sergey Stepanov
b6366e7b88
Update room tests 2023-03-18 23:50:05 +03:00
sergystepanov
3bb54fdad4
Clean API (#391)
Remove hard coupling between api (all the API data structures) and com (app clients communication protocol and logic).
2023-03-18 20:24:06 +03:00
Sergey Stepanov
cd056ee976
Bump to v3 2023-03-16 23:46:53 +03:00
Sergey Stepanov
faf347a44a
Make rand.Seed not deprecated 2023-02-17 18:12:38 +03:00
Sergey Stepanov
d27d819821
Add variable frame rate (VFR) option for cores.
It is enabled only for N64.
Disabling it for everything else may lead to a much smoother video playback (less stuttering).
2023-02-10 18:03:50 +03:00
Sergey Stepanov
beaf862dec
Don't cache nil frames 2023-02-10 17:47:58 +03:00
sergystepanov
c7b5d1afc3
Fix possible infinite loop on Mupen close (#389)
For some reason the Libretro Mupen core breaks the pseudo-random order of channel selection leading to constant skip of the done channel on ticker aka an infinite loop.
2023-02-04 22:47:53 +03:00
Sergey Stepanov
0d7467048a
Log abnormal WebRTC sample writes 2023-02-04 20:30:37 +03:00
sergystepanov
2b81c3fb87
Some optimizations (#387)
- Fixed broken image cache for the first stage RGBA frames. It was not a thread-safe one, which led to image tearing (parts of old images in multiple consecutive frames).
- 180 flip function for the OpenGL coordinate system has been moved into the rotation part.
- Optimized YUV converter.
- Optimized color converters:
  - Use __restrict pointers.
  - Draw image pixels with the faster bitwise operators and pointer arithmetic as 32/16bit LE numbers (may break on ARM devices like RPi). 
  - Pass uints for less num conversions.
  - Much faster XRGB -> RGBA conversion with Go's stdlib 32bit flip.
- Wrapped RGBA images into a custom struct in order to bypass opacity tests for the standard Go png functions, which needed for the PNG file export. Before that we set RGBx opacity byte explicitly during the pixel format conversions (much slower).
- Made Libretro core shutdown more deterministic. When we run a C core separately from the main Go process we have to make sure that the C core is not doing anything in its syscall while we stopping the emulator. Basically, a blocking call may be suspended on the Go's side while the other goroutines have no knowledge of that.
- Less info level logs.
- Added recording user label.
- Enabled RTCP sender reports by default, which may help with A/V sync.
- Check onMessage webrtc handler if it's set. May crash the program if not.
- Fixed some make dirs permissions.
- Enabled console colors (since MS has finally fixed their bloody Terminal).
- Disable log in some tests.
- Updated deps.
2023-01-31 22:22:03 +03:00
Sergey Stepanov
07bc3d3a39
Remove broken image cache for now 2023-01-11 17:08:55 +03:00
sergystepanov
3bd959b4ef
Refactored v3 (#350)
This PR contains refactored code.

**Changelog**
- Added new net code (the communication architecture was left intact).
- All network client IDs now have custom type `network.Uid` backed by github.com/rs/xid lib.
  ```
  The string representation of a UUID takes 32 bytes, and the new type will take just 16.
  Because of Golang JSON serialization problems with omitting zero-length empty slices (it can't) 
  and the need to use UID values as map keys (maps don't support slices as keys), 
  IDs are stored as strings (for now).
  ```
- A whole new WebSocket client/server implementation was added, as well as a new communication layer with synchronous and async call handlers.
  - WebSocket connections now support dedicated Ping/Pong frames as opposed to original ping text messages.
  - Used Gorilla WebSocket library doesn't allow concurrent (simultaneous) reads and writes, so this part was handled via send channel synchronization.
- New API structures can be found in the `pkg/api` folder.
- New communication protocol can be found in the `pkg/com/*` folder.
- Updated communication protocol is based on JSON-encoded messaging through WebSocket and has the following structure:
  ```
  Packet
    [id] string — a globally unique identification tag for the packet to track it trough a chain of requests.
    t uint8 — contains packet type information (i.e. INIT_PACKET, SDP_OFFER_PACKET, ...).
    [p] any — contains packet data (any type).

  Each packet is a text message in JSON-serialized form (WebSocket control frames obviously not).
  ```
  ```
  The main principle of this protocol and the duplex data exchange is:
  the one who initializes connection is called a client, and 
  the one who is being connected to is called a server. 
  With the current architecture, the coordinator is the server, the user browsers and workers are the clients.

            ____           ____
           ↓    ↑         ↑    ↓
     browser ⟶ coordinator ⟵ worker
       (c)          (s)         (c)

  One of the most crucial performance vise parts of these interactions is that 
  all the server-initiated calls to clients should be asynchronous!
  ```
  - In order to track synchronous calls (packets) with an asynchronous protocol, such as WebSocket, each packet may have an `id` that should be copied in all subsequent requests/responses.
  - The old `sessionID` param was replaced by `id` that should be stored inside the `p` (payload) part of the packet.
- It is possible to skip the default ping check for all connected workers on every user connection and just pick the first available with the new roundRobin param in the coordinator config file `coordinator.roundRobin: true/false`.
- Added a dedicated package for the system API (pkg/api/*).
- Added structured logging system (zerolog) for better logging and cloud services integration.
- Added a visual representation of the network message exchange in logs:
  ```
  ...
  01:00:01.1078 3f98 INF w → c Handshake ws://localhost:8000/wso
  01:00:01.1138  994 INF c ← w Handshake localhost:8000
  01:00:01.1148  994 INF c ← w Connect cid=cep.hrg
  01:00:01.1158  994 DBG c     connection id has been changed to cepl7obdrc3jv66kp2ug cid=cep.hrg
  01:00:01.1158 3f98 INF w → c Connect cid=cep.2ug
  01:00:01.1158  994 INF c     New worker / addr: localhost, ...
  01:00:01.1158 3f98 INF w     Connected to the coordinator localhost:8000 cid=cep.2ug
  01:00:02.5834  994 INF c ← u Handshake localhost:8000
  01:00:02.6175  994 INF c ← u Connect cid=cep.hs0
  01:00:02.6209  994 INF c     Search available workers cid=cep.hs0
  01:00:02.6214  994 INF c     Found next free worker cid=cep.hs0
  01:00:02.6220  994 INF c → u InitSession cid=cep.hs0
  01:00:02.6527  994 INF c ← u WebrtcInit cid=cep.hs0
  01:00:02.6527  994 INF c → w ᵇWebrtcInit cid=cep.hrg
  01:00:02.6537 3f98 INF w ← c WebrtcInit cid=cep.2ug
  01:00:02.6537 3f98 INF w     WebRTC start cid=cep.2ug
  ...
  ```
- Replaced a monstrous Prometheus metrics lib.
- Removed spflag dependency.
- Added new `version` config file param/constant for compatibility reasons.
- Bump the minimum required version for Go to 1.18 due to use of generics.
- Opus encoder now is cached and the default config is 96Kbps, complexity 5 (was 196Kbps, 8).
- Changed the default x264 quality parameters to `crf 23 / superfast / baseline` instead of `crf 17 / veryfast / main`.
- Added a separate WebRTC logging config param `webrtc.logLevel`.
- Worker now allocates much less memory.
- Optimized and fixed RGB to YUV converter.
- `--v=5` logging cmd flag was removed and replaced with the `debug` config parameter.


**Breaking changes (migration to v3)**
- Coordinator server API changes, see web/js/api/api.js.
- Coordinator client event API changes:
  - c `GAME_PLAYER_IDX_CHANGE` (string) -> `GAME_PLAYER_IDX` (number)
  - c `GAME_PLAYER_IDX` -> `GAME_PLAYER_IDX_SET`
  - c `MEDIA_STREAM_INITIALIZED` -> `WEBRTC_NEW_CONNECTION`
  - c `MEDIA_STREAM_SDP_AVAILABLE` -> `WEBRTC_SDP_OFFER`
  - c `MEDIA_STREAM_CANDIDATE_ADD` -> `WEBRTC_ICE_CANDIDATE_RECEIVED`
  - c `MEDIA_STREAM_CANDIDATE_FLUSH` -> `WEBRTC_ICE_CANDIDATES_FLUSH`
  - x `MEDIA_STREAM_READY` -> **removed**
  - c `CONNECTION_READY` -> `WEBRTC_CONNECTION_READY`
  - c `CONNECTION_CLOSED` -> `WEBRTC_CONNECTION_CLOSED`
  - c `GET_SERVER_LIST` -> `WORKER_LIST_FETCHED`
  - x `KEY_STATE_UPDATED` -> **removed**
  - n `WEBRTC_ICE_CANDIDATE_FOUND`
  - n `WEBRTC_SDP_ANSWER`
  - n `MESSAGE`
- `rtcp` module renamed to `webrtc`.
- Controller state equals Libretro controller state (changed order of bits), see: web/js/input/input.js.
- Added new `coordintaor.selector` config param that changes the selection algorithm for workers. By default it will select any free worker. Set this param to `ping` for the old behavior.
- Changed the name of the `webrtc.iceServers.url` config param to `webrtc.iceServers.urls`.
2023-01-09 23:20:22 +03:00
sergystepanov
6b6c391f81
Faster image processing (#382)
* Calculate frame duration in ns

* Reuse single OpenGL byte buffer

* Add threaded a/v processing

* Check min threads in opts

* Return missing audio sample
2022-11-24 13:44:00 +03:00
sergystepanov
54ee9a7af3
Savestate compression (#374)
Added the optional saveCompression configuration parameter which enables ZIP compression of the emulator states, reducing files sizes by the factor of 10x (most of these state files store zeroes).
2022-08-05 22:44:40 +03:00
Sergey Stepanov
e214025bef
Disable excessive autosave logging 2022-07-26 12:28:02 +03:00
Valniae
1750d48b89
Timely auto save (#373)
Add autosave for the emulator states. Controlled with the autosaveSec param.
2022-07-26 12:25:36 +03:00
sergystepanov
e53cf45fa7
Main thread lock refactoring (#367)
Use slim main thread locking function for macOS instead of a lib.
2022-06-12 13:39:23 +03:00
Sergey Stepanov
0665c3e607
Remove heavy Google Cloud Storage lib 2022-04-11 09:22:06 +03:00
Sergey Stepanov
fac6cc4495
Generate xIds on the worker's side 2022-04-09 10:27:04 +03:00
sergystepanov
9ad3c98a7d
Rework worker selection feature (#365)
We add a new option for manual worker or machine (server with multiple workers) select, depending on the new coordinator option `coordinator.debug` which by default allows machine selection.
2022-04-07 21:04:30 +03:00
Sergey Stepanov
02a061a580
Extract audio buffer and resampler 2021-12-25 21:50:33 +03:00
sergystepanov
1271aa8438
Game recording support (#356)
This feature adds the ability to record game sessions as raw a/v media files.
2021-12-04 14:20:38 +03:00
Sergey Stepanov
339750a978
Calculate emulation frames duration directly 2021-11-22 20:01:46 +03:00
sergystepanov
9acbecb813
WebRTC single port support (#354)
Add the new `webrtc.singlePort` config option which forces the WebRTC server to listen on this port only.
2021-11-02 17:05:31 +03:00
Sergey Stepanov
a73c0e8c5f
Update re-time interceptor.
Update re-time video frame interceptor to the latest pion WebRTC changes and keep it shared between all RTC peer connections.
2021-10-14 19:47:08 +03:00