Merge pull request #7220 from reswitched/master
[NSW] SDK Compat Fixups
This commit is contained in:
commit
13c22c47b9
|
@ -836,7 +836,9 @@ ifeq ($(TARGET), retroarch_switch)
|
||||||
OBJ += gfx/drivers/switch_gfx.o \
|
OBJ += gfx/drivers/switch_gfx.o \
|
||||||
input/drivers/switch_input.o \
|
input/drivers/switch_input.o \
|
||||||
input/drivers_joypad/switch_joypad.o \
|
input/drivers_joypad/switch_joypad.o \
|
||||||
audio/drivers/switch_audio.o
|
audio/drivers/switch_audio.o \
|
||||||
|
audio/drivers/switch_nx_thread_audio.o \
|
||||||
|
frontend/drivers/platform_switch.o
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ endif
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(strip $(LIBTRANSISTOR_HOME)),)
|
ifeq ($(strip $(LIBTRANSISTOR_HOME)),)
|
||||||
$(error "Please set LIBTRANSISTOR_HOME in your environment. export LIBTRANSISTOR_HOME=<path t>o libtransistor")
|
$(error "Please set LIBTRANSISTOR_HOME in your environment. export LIBTRANSISTOR_HOME=<path/to/libtransistor/dist/>")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
include $(LIBTRANSISTOR_HOME)/libtransistor.mk
|
include $(LIBTRANSISTOR_HOME)/libtransistor.mk
|
||||||
|
@ -52,7 +52,7 @@ LIBDIRS := -L.
|
||||||
|
|
||||||
TARGETS := $(TARGET).nro
|
TARGETS := $(TARGET).nro
|
||||||
|
|
||||||
CFLAGS += $(INCDIRS) $(DEFINES) -Wunused-command-line-argument
|
CFLAGS += $(INCDIRS) $(DEFINES) -Wno-unused-command-line-argument -Werror-implicit-function-declaration
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
|
|
|
@ -125,9 +125,7 @@ static const audio_driver_t *audio_drivers[] = {
|
||||||
#endif
|
#endif
|
||||||
#ifdef SWITCH
|
#ifdef SWITCH
|
||||||
&audio_switch,
|
&audio_switch,
|
||||||
#ifdef HAVE_LIBNX
|
|
||||||
&audio_switch_thread,
|
&audio_switch_thread,
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
&audio_null,
|
&audio_null,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* RetroArch - A frontend for libretro.
|
/* RetroArch - A frontend for libretro.
|
||||||
* Copyright (C) 2018 - misson2000
|
* Copyright (C) 2018 - misson20000
|
||||||
* Copyright (C) 2018 - m4xw
|
* Copyright (C) 2018 - m4xw
|
||||||
*
|
*
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
@ -19,13 +19,7 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef HAVE_LIBNX
|
#include "switch_audio_compat.h"
|
||||||
#include <switch.h>
|
|
||||||
#else
|
|
||||||
#include <libtransistor/nx.h>
|
|
||||||
#include <libtransistor/alloc_pages.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../audio_driver.h"
|
#include "../audio_driver.h"
|
||||||
#include "../../verbosity.h"
|
#include "../../verbosity.h"
|
||||||
|
|
||||||
|
@ -35,22 +29,6 @@
|
||||||
#define BUFFER_COUNT 3
|
#define BUFFER_COUNT 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBNX
|
|
||||||
#define switch_audio_ipc_init audoutInitialize
|
|
||||||
#define switch_audio_ipc_output_get_released_buffer(a, b) audoutGetReleasedAudioOutBuffer(&a->current_buffer, &b)
|
|
||||||
#define switch_audio_ipc_output_append_buffer(a, b) audoutAppendAudioOutBuffer(&b)
|
|
||||||
#define switch_audio_ipc_output_stop(a) audoutStopAudioOut()
|
|
||||||
#define switch_audio_ipc_output_start(a) audoutStartAudioOut()
|
|
||||||
#define audio_output_buffer_t AudioOutBuffer
|
|
||||||
#else
|
|
||||||
#define switch_audio_ipc_init audio_ipc_init
|
|
||||||
#define switch_audio_ipc_output_get_released_buffer(a, b) audio_ipc_output_get_released_buffer(&a->output, &b, &a->current_buffer)
|
|
||||||
#define switch_audio_ipc_output_append_buffer(a, b) audio_ipc_output_append_buffer(&a->output, &b)
|
|
||||||
#define switch_audio_ipc_output_stop(a) audio_ipc_output_stop(&a->output)
|
|
||||||
#define switch_audio_ipc_output_start(a) audio_ipc_output_start(&a->output)
|
|
||||||
#define audio_output_buffer_t audio_output_buffer_t
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const int sample_rate = 48000;
|
static const int sample_rate = 48000;
|
||||||
static const int max_num_samples = sample_rate;
|
static const int max_num_samples = sample_rate;
|
||||||
static const int num_channels = 2;
|
static const int num_channels = 2;
|
||||||
|
@ -62,8 +40,8 @@ typedef struct
|
||||||
bool is_paused;
|
bool is_paused;
|
||||||
uint64_t last_append;
|
uint64_t last_append;
|
||||||
unsigned latency;
|
unsigned latency;
|
||||||
audio_output_buffer_t buffers[BUFFER_COUNT];
|
compat_audio_out_buffer buffers[BUFFER_COUNT];
|
||||||
audio_output_buffer_t *current_buffer;
|
compat_audio_out_buffer *current_buffer;
|
||||||
|
|
||||||
#ifndef HAVE_LIBNX
|
#ifndef HAVE_LIBNX
|
||||||
audio_output_t output;
|
audio_output_t output;
|
||||||
|
@ -155,13 +133,8 @@ static ssize_t switch_audio_write(void *data, const void *buf, size_t size)
|
||||||
|
|
||||||
if (swa->current_buffer->data_size > (48000 * swa->latency) / 1000)
|
if (swa->current_buffer->data_size > (48000 * swa->latency) / 1000)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBNX
|
|
||||||
if (switch_audio_ipc_output_append_buffer(swa, *swa->current_buffer) != 0)
|
|
||||||
return -1;
|
|
||||||
#else
|
|
||||||
if (switch_audio_ipc_output_append_buffer(swa, swa->current_buffer) != 0)
|
if (switch_audio_ipc_output_append_buffer(swa, swa->current_buffer) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
|
||||||
swa->current_buffer = NULL;
|
swa->current_buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +312,7 @@ static void *switch_audio_init(const char *device,
|
||||||
goto fail_audio_output;
|
goto fail_audio_output;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (switch_audio_ipc_output_append_buffer(swa, swa->buffers[i]) != 0)
|
if (switch_audio_ipc_output_append_buffer(swa, &swa->buffers[i]) != 0)
|
||||||
goto fail_audio_output;
|
goto fail_audio_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBNX
|
||||||
|
#include <switch.h>
|
||||||
|
#else
|
||||||
|
#include <libtransistor/nx.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBNX
|
||||||
|
|
||||||
|
// libnx definitions
|
||||||
|
|
||||||
|
// threading
|
||||||
|
typedef Mutex compat_mutex;
|
||||||
|
typedef Thread compat_thread;
|
||||||
|
typedef CondVar compat_condvar;
|
||||||
|
|
||||||
|
#define compat_thread_create(thread, func, data, stack_size, prio, cpu) \
|
||||||
|
threadCreate(thread, func, data, stack_size, prio, cpu)
|
||||||
|
#define compat_thread_start(thread) \
|
||||||
|
threadStart(thread)
|
||||||
|
#define compat_thread_join(thread) \
|
||||||
|
threadWaitForExit(thread)
|
||||||
|
#define compat_thread_close(thread) \
|
||||||
|
threadClose(thread)
|
||||||
|
#define compat_mutex_create(mutex) \
|
||||||
|
mutexInit(mutex)
|
||||||
|
#define compat_mutex_lock(mutex) \
|
||||||
|
mutexLock(mutex)
|
||||||
|
#define compat_mutex_unlock(mutex) \
|
||||||
|
mutexUnlock(mutex)
|
||||||
|
#define compat_condvar_create(condvar) \
|
||||||
|
condvarInit(condvar)
|
||||||
|
#define compat_condvar_wait(condvar, mutex) \
|
||||||
|
condvarWait(condvar, mutex)
|
||||||
|
#define compat_condvar_wake_all(condvar) \
|
||||||
|
condvarWakeAll(condvar)
|
||||||
|
|
||||||
|
// audio
|
||||||
|
typedef AudioOutBuffer compat_audio_out_buffer;
|
||||||
|
#define switch_audio_ipc_init audoutInitialize
|
||||||
|
#define switch_audio_ipc_finalize audoutExit
|
||||||
|
#define switch_audio_ipc_output_get_released_buffer(a, b) audoutGetReleasedAudioOutBuffer(&a->current_buffer, &b)
|
||||||
|
#define switch_audio_ipc_output_append_buffer(a, b) audoutAppendAudioOutBuffer(b)
|
||||||
|
#define switch_audio_ipc_output_stop(a) audoutStopAudioOut()
|
||||||
|
#define switch_audio_ipc_output_start(a) audoutStartAudioOut()
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// libtransistor definitions
|
||||||
|
|
||||||
|
typedef result_t Result;
|
||||||
|
#define R_FAILED(r) ((r) != RESULT_OK)
|
||||||
|
|
||||||
|
// threading
|
||||||
|
typedef trn_mutex_t compat_mutex;
|
||||||
|
typedef trn_thread_t compat_thread;
|
||||||
|
typedef trn_condvar_t compat_condvar;
|
||||||
|
|
||||||
|
#define compat_thread_create(thread, func, data, stack_size, prio, cpu) \
|
||||||
|
trn_thread_create(thread, func, data, prio, cpu, stack_size, NULL)
|
||||||
|
#define compat_thread_start(thread) \
|
||||||
|
trn_thread_start(thread)
|
||||||
|
#define compat_thread_join(thread) \
|
||||||
|
trn_thread_join(thread, -1)
|
||||||
|
#define compat_thread_close(thread) \
|
||||||
|
trn_thread_destroy(thread)
|
||||||
|
#define compat_mutex_create(mutex) \
|
||||||
|
trn_mutex_create(mutex)
|
||||||
|
#define compat_mutex_lock(mutex) \
|
||||||
|
trn_mutex_lock(mutex)
|
||||||
|
#define compat_mutex_unlock(mutex) \
|
||||||
|
trn_mutex_unlock(mutex)
|
||||||
|
#define compat_condvar_create(condvar) \
|
||||||
|
trn_condvar_create(condvar)
|
||||||
|
#define compat_condvar_wait(condvar, mutex) \
|
||||||
|
trn_condvar_wait(condvar, mutex, -1)
|
||||||
|
#define compat_condvar_wake_all(condvar) \
|
||||||
|
trn_condvar_signal(condvar, -1)
|
||||||
|
|
||||||
|
// audio
|
||||||
|
typedef audio_output_buffer_t compat_audio_out_buffer;
|
||||||
|
#define switch_audio_ipc_init audio_ipc_init
|
||||||
|
#define switch_audio_ipc_finalize audio_ipc_finalize
|
||||||
|
#define switch_audio_ipc_output_get_released_buffer(a, b) audio_ipc_output_get_released_buffer(&a->output, &b, &a->current_buffer)
|
||||||
|
#define switch_audio_ipc_output_append_buffer(a, b) audio_ipc_output_append_buffer(&a->output, b)
|
||||||
|
#define switch_audio_ipc_output_stop(a) audio_ipc_output_stop(&a->output)
|
||||||
|
#define switch_audio_ipc_output_start(a) audio_ipc_output_start(&a->output)
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,358 +1,448 @@
|
||||||
/* RetroArch - A frontend for libretro.
|
/* RetroArch - A frontend for libretro.
|
||||||
* Copyright (C) 2018 - misson2000
|
* Copyright (C) 2018 - misson20000
|
||||||
* Copyright (C) 2018 - m4xw
|
* Copyright (C) 2018 - m4xw
|
||||||
* Copyright (C) 2018 - lifajucejo
|
* Copyright (C) 2018 - lifajucejo
|
||||||
*
|
*
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
* 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-
|
* 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.
|
* 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;
|
* 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
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE. See the GNU General Public License for more details.
|
* 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.
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/unistd.h>
|
#include <sys/unistd.h>
|
||||||
|
|
||||||
#include <switch.h>
|
#ifdef HAVE_LIBNX
|
||||||
|
#include <switch.h>
|
||||||
#include <queues/fifo_queue.h>
|
#else
|
||||||
#include "../audio_driver.h"
|
#include <libtransistor/nx.h>
|
||||||
#include "../../verbosity.h"
|
#endif
|
||||||
|
|
||||||
#include "../../tasks/tasks_internal.h"
|
#include <queues/fifo_queue.h>
|
||||||
|
#include "../audio_driver.h"
|
||||||
#define THREAD_STACK_SIZE (1024 * 8)
|
#include "../../verbosity.h"
|
||||||
|
|
||||||
#define AUDIO_THREAD_CPU 2
|
#include "../../tasks/tasks_internal.h"
|
||||||
|
|
||||||
#define CHANNELCOUNT 2
|
#include "switch_audio_compat.h"
|
||||||
#define BYTESPERSAMPLE sizeof(uint16_t)
|
|
||||||
#define SAMPLE_SIZE (CHANNELCOUNT * BYTESPERSAMPLE)
|
static const size_t thread_stack_size = 1024 * 8;
|
||||||
|
static const int thread_preferred_cpu = 2;
|
||||||
#define AUDIO_BUFFER_COUNT 2
|
static const int channel_count = 2;
|
||||||
|
static const size_t sample_size = sizeof(uint16_t);
|
||||||
static inline void lockMutex(Mutex* mtx)
|
static const size_t frame_size = channel_count * sample_size;
|
||||||
{
|
|
||||||
mutexLock(mtx);
|
#define AUDIO_BUFFER_COUNT 2
|
||||||
}
|
|
||||||
|
typedef struct
|
||||||
typedef struct
|
{
|
||||||
{
|
fifo_buffer_t* fifo;
|
||||||
fifo_buffer_t* fifo;
|
compat_mutex fifoLock;
|
||||||
Mutex fifoLock;
|
compat_condvar cond;
|
||||||
CondVar cond;
|
compat_mutex condLock;
|
||||||
Mutex condLock;
|
|
||||||
|
size_t fifoSize;
|
||||||
size_t fifoSize;
|
|
||||||
|
volatile bool running;
|
||||||
volatile bool running;
|
bool nonblocking;
|
||||||
bool nonblocking;
|
bool is_paused;
|
||||||
bool is_paused;
|
|
||||||
|
compat_audio_out_buffer buffers[AUDIO_BUFFER_COUNT];
|
||||||
AudioOutBuffer buffer[AUDIO_BUFFER_COUNT];
|
compat_thread thread;
|
||||||
Thread thread;
|
|
||||||
|
unsigned latency;
|
||||||
unsigned latency;
|
uint32_t sampleRate;
|
||||||
uint32_t sampleRate;
|
|
||||||
} switch_thread_audio_t;
|
#ifndef HAVE_LIBNX
|
||||||
|
audio_output_t output;
|
||||||
static void mainLoop(void* data)
|
handle_t event;
|
||||||
{
|
#endif
|
||||||
switch_thread_audio_t* swa = (switch_thread_audio_t*)data;
|
} switch_thread_audio_t;
|
||||||
|
|
||||||
if (!swa)
|
static void mainLoop(void* data)
|
||||||
return;
|
{
|
||||||
|
switch_thread_audio_t* swa = (switch_thread_audio_t*)data;
|
||||||
RARCH_LOG("[Audio]: start mainLoop cpu %u tid %u\n", svcGetCurrentProcessorNumber(), swa->thread.handle);
|
|
||||||
|
if (!swa)
|
||||||
for (int i = 0; i < AUDIO_BUFFER_COUNT; i++)
|
return;
|
||||||
{
|
|
||||||
swa->buffer[i].next = NULL; /* Unused */
|
RARCH_LOG("[Audio]: start mainLoop cpu %u tid %u\n", svcGetCurrentProcessorNumber(), swa->thread.handle);
|
||||||
swa->buffer[i].buffer_size = swa->fifoSize;
|
|
||||||
swa->buffer[i].buffer = memalign(0x1000, swa->buffer[i].buffer_size);
|
compat_audio_out_buffer* released_out_buffer = NULL;
|
||||||
swa->buffer[i].data_size = swa->buffer[i].buffer_size;
|
uint32_t released_out_count;
|
||||||
swa->buffer[i].data_offset = 0;
|
Result rc;
|
||||||
|
|
||||||
memset(swa->buffer[i].buffer, 0, swa->buffer[i].buffer_size);
|
while (swa->running)
|
||||||
audoutAppendAudioOutBuffer(&swa->buffer[i]);
|
{
|
||||||
}
|
if (!released_out_buffer)
|
||||||
|
{
|
||||||
AudioOutBuffer* released_out_buffer = NULL;
|
#ifdef HAVE_LIBNX
|
||||||
u32 released_out_count;
|
rc = audoutWaitPlayFinish(&released_out_buffer, &released_out_count, U64_MAX);
|
||||||
Result rc;
|
#else
|
||||||
|
uint32_t handle_idx = 0;
|
||||||
while (swa->running)
|
svcWaitSynchronization(&handle_idx, &swa->event, 1, 33333333);
|
||||||
{
|
svcResetSignal(swa->event);
|
||||||
if (!released_out_buffer)
|
|
||||||
{
|
rc = audio_ipc_output_get_released_buffer(&swa->output, &released_out_count, &released_out_buffer);
|
||||||
rc = audoutWaitPlayFinish(&released_out_buffer, &released_out_count, U64_MAX);
|
#endif
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
{
|
{
|
||||||
swa->running = false;
|
swa->running = false;
|
||||||
RARCH_LOG("[Audio]: audoutGetReleasedAudioOutBuffer failed: %d\n", (int)rc);
|
RARCH_LOG("[Audio]: audoutGetReleasedAudioOutBuffer failed: %d\n", (int)rc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
released_out_buffer->data_size = 0;
|
released_out_buffer->data_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bufAvail = released_out_buffer->buffer_size - released_out_buffer->data_size;
|
size_t bufAvail = released_out_buffer->buffer_size - released_out_buffer->data_size;
|
||||||
|
|
||||||
lockMutex(&swa->fifoLock);
|
compat_mutex_lock(&swa->fifoLock);
|
||||||
|
|
||||||
size_t avail = fifo_read_avail(swa->fifo);
|
size_t avail = fifo_read_avail(swa->fifo);
|
||||||
size_t to_write = MIN(avail, bufAvail);
|
size_t to_write = MIN(avail, bufAvail);
|
||||||
if (to_write > 0)
|
if (to_write > 0) {
|
||||||
fifo_read(swa->fifo, ((u8*)released_out_buffer->buffer) + released_out_buffer->data_size, to_write);
|
uint8_t *base;
|
||||||
|
#ifdef HAVE_LIBNX
|
||||||
mutexUnlock(&swa->fifoLock);
|
base = (uint8_t*) released_out_buffer->buffer;
|
||||||
condvarWakeAll(&swa->cond);
|
#else
|
||||||
|
base = (uint8_t*) released_out_buffer->sample_data;
|
||||||
released_out_buffer->data_size += to_write;
|
#endif
|
||||||
if (released_out_buffer->data_size >= released_out_buffer->buffer_size / 2)
|
fifo_read(swa->fifo, base + released_out_buffer->data_size, to_write);
|
||||||
{
|
}
|
||||||
rc = audoutAppendAudioOutBuffer(released_out_buffer);
|
|
||||||
if (R_FAILED(rc))
|
compat_mutex_unlock(&swa->fifoLock);
|
||||||
{
|
compat_condvar_wake_all(&swa->cond);
|
||||||
RARCH_LOG("[Audio]: audoutAppendAudioOutBuffer failed: %d\n", (int)rc);
|
|
||||||
}
|
released_out_buffer->data_size += to_write;
|
||||||
released_out_buffer = NULL;
|
if (released_out_buffer->data_size >= released_out_buffer->buffer_size / 2)
|
||||||
}
|
{
|
||||||
else
|
rc = switch_audio_ipc_output_append_buffer(swa, released_out_buffer);
|
||||||
svcSleepThread(16000000); /* 16ms */
|
if (R_FAILED(rc))
|
||||||
}
|
{
|
||||||
}
|
RARCH_LOG("[Audio]: audoutAppendAudioOutBuffer failed: %d\n", (int)rc);
|
||||||
|
}
|
||||||
static void *switch_thread_audio_init(const char *device, unsigned rate, unsigned latency, unsigned block_frames, unsigned *new_rate)
|
released_out_buffer = NULL;
|
||||||
{
|
}
|
||||||
(void)device;
|
else
|
||||||
|
svcSleepThread(16000000); /* 16ms */
|
||||||
switch_thread_audio_t *swa = (switch_thread_audio_t *)calloc(1, sizeof(switch_thread_audio_t));
|
}
|
||||||
|
}
|
||||||
if (!swa)
|
|
||||||
return NULL;
|
static void *switch_thread_audio_init(const char *device, unsigned rate, unsigned latency, unsigned block_frames, unsigned *new_rate)
|
||||||
|
{
|
||||||
swa->running = true;
|
(void)device;
|
||||||
swa->nonblocking = true;
|
|
||||||
swa->is_paused = true;
|
char names[8][0x20];
|
||||||
swa->latency = MAX(latency, 8);
|
uint32_t num_names = 0;
|
||||||
|
switch_thread_audio_t *swa = (switch_thread_audio_t *)calloc(1, sizeof(*swa));
|
||||||
Result rc = audoutInitialize();
|
|
||||||
if (R_FAILED(rc))
|
if (!swa)
|
||||||
{
|
return NULL;
|
||||||
RARCH_LOG("[Audio]: audio init failed %d\n", (int)rc);
|
|
||||||
return NULL;
|
swa->running = true;
|
||||||
}
|
swa->nonblocking = true;
|
||||||
|
swa->is_paused = true;
|
||||||
rc = audoutStartAudioOut();
|
swa->latency = MAX(latency, 8);
|
||||||
if (R_FAILED(rc))
|
|
||||||
{
|
Result rc = switch_audio_ipc_init();
|
||||||
RARCH_LOG("[Audio]: audio start init failed: %d\n", (int)rc);
|
if (R_FAILED(rc))
|
||||||
return NULL;
|
{
|
||||||
}
|
RARCH_LOG("[Audio]: audio init failed %d\n", (int)rc);
|
||||||
|
free(swa);
|
||||||
swa->sampleRate = audoutGetSampleRate();
|
return NULL;
|
||||||
*new_rate = swa->sampleRate;
|
}
|
||||||
|
|
||||||
mutexInit(&swa->fifoLock);
|
#ifdef HAVE_LIBNX
|
||||||
swa->fifoSize = (swa->sampleRate * SAMPLE_SIZE * swa->latency) / 1000;
|
rc = audoutStartAudioOut();
|
||||||
swa->fifo = fifo_new(swa->fifoSize);
|
if (R_FAILED(rc))
|
||||||
|
{
|
||||||
condvarInit(&swa->cond);
|
RARCH_LOG("[Audio]: audio start init failed: %d\n", (int)rc);
|
||||||
|
goto fail_audio_ipc;
|
||||||
RARCH_LOG("[Audio]: switch_thread_audio_init device %s requested rate %hu rate %hu latency %hu block_frames %hu fifoSize %lu\n",
|
}
|
||||||
device, rate, swa->sampleRate, swa->latency, block_frames, swa->fifoSize);
|
|
||||||
|
swa->sampleRate = audoutGetSampleRate();
|
||||||
u32 prio;
|
#else
|
||||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
if (audio_ipc_list_outputs(&names[0], 8, &num_names) != RESULT_OK) {
|
||||||
rc = threadCreate(&swa->thread, &mainLoop, (void*)swa, THREAD_STACK_SIZE, prio + 1, AUDIO_THREAD_CPU);
|
goto fail_audio_ipc;
|
||||||
|
}
|
||||||
if (R_FAILED(rc))
|
|
||||||
{
|
if (num_names != 1) {
|
||||||
RARCH_LOG("[Audio]: thread creation failed create %u\n", swa->thread.handle);
|
RARCH_ERR("[Audio]: got back more than one AudioOut\n");
|
||||||
swa->running = false;
|
goto fail_audio_ipc;
|
||||||
return NULL;
|
}
|
||||||
}
|
|
||||||
|
if (audio_ipc_open_output(names[0], &swa->output) != RESULT_OK) {
|
||||||
if (R_FAILED(threadStart(&swa->thread)))
|
goto fail_audio_ipc;
|
||||||
{
|
}
|
||||||
RARCH_LOG("[Audio]: thread creation failed start %u\n", swa->thread.handle);
|
|
||||||
threadClose(&swa->thread);
|
swa->sampleRate = swa->output.sample_rate;
|
||||||
swa->running = false;
|
|
||||||
return NULL;
|
if (swa->output.num_channels != 2)
|
||||||
}
|
{
|
||||||
|
RARCH_ERR("expected %d channels, got %d\n", 2,
|
||||||
return swa;
|
swa->output.num_channels);
|
||||||
}
|
goto fail_audio_output;
|
||||||
|
}
|
||||||
static bool switch_thread_audio_start(void *data, bool is_shutdown)
|
|
||||||
{
|
if (swa->output.sample_format != PCM_INT16)
|
||||||
/* RARCH_LOG("[Audio]: switch_thread_audio_start\n"); */
|
{
|
||||||
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
RARCH_ERR("expected PCM_INT16, got %d\n", swa->output.sample_format);
|
||||||
|
goto fail_audio_output;
|
||||||
if (!swa)
|
}
|
||||||
return false;
|
|
||||||
|
if (audio_ipc_output_register_buffer_event(&swa->output, &swa->event) != 0)
|
||||||
swa->is_paused = false;
|
goto fail_audio_output;
|
||||||
return true;
|
#endif
|
||||||
}
|
|
||||||
|
*new_rate = swa->sampleRate;
|
||||||
static bool switch_thread_audio_stop(void *data)
|
|
||||||
{
|
|
||||||
switch_thread_audio_t* swa = (switch_thread_audio_t*)data;
|
for (int i = 0; i < AUDIO_BUFFER_COUNT; i++)
|
||||||
|
{
|
||||||
if (!swa)
|
#ifdef HAVE_LIBNX
|
||||||
return false;
|
swa->buffers[i].next = NULL; /* Unused */
|
||||||
|
swa->buffers[i].data_offset = 0;
|
||||||
swa->is_paused = true;
|
swa->buffers[i].buffer_size = swa->fifoSize;
|
||||||
return true;
|
swa->buffers[i].data_size = swa->buffers[i].buffer_size;
|
||||||
}
|
swa->buffers[i].buffer = memalign(0x1000, swa->buffers[i].buffer_size);
|
||||||
|
|
||||||
static void switch_thread_audio_free(void *data)
|
if (swa->buffers[i].buffer == NULL)
|
||||||
{
|
goto fail;
|
||||||
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
|
||||||
|
memset(swa->buffers[i].buffer, 0, swa->buffers[i].buffer_size);
|
||||||
if (!swa)
|
#else
|
||||||
return;
|
swa->buffers[i].ptr = &swa->buffers[i].sample_data;
|
||||||
|
swa->buffers[i].unknown = 0;
|
||||||
if (swa->running)
|
swa->buffers[i].buffer_size = swa->fifoSize;
|
||||||
{
|
swa->buffers[i].data_size = swa->buffers[i].buffer_size;
|
||||||
swa->running = false;
|
swa->buffers[i].sample_data = alloc_pages(swa->buffers[i].buffer_size, swa->buffers[i].buffer_size, NULL);
|
||||||
threadWaitForExit(&swa->thread);
|
|
||||||
threadClose(&swa->thread);
|
if (swa->buffers[i].sample_data == NULL)
|
||||||
}
|
goto fail_audio_output;
|
||||||
|
|
||||||
audoutStopAudioOut();
|
memset(swa->buffers[i].sample_data, 0, swa->buffers[i].buffer_size);
|
||||||
audoutExit();
|
#endif
|
||||||
|
|
||||||
if (swa->fifo)
|
if (switch_audio_ipc_output_append_buffer(swa, &swa->buffers[i]) != 0)
|
||||||
{
|
goto fail_audio_output;
|
||||||
fifo_free(swa->fifo);
|
}
|
||||||
swa->fifo = NULL;
|
|
||||||
}
|
compat_mutex_create(&swa->fifoLock);
|
||||||
|
swa->fifoSize = (swa->sampleRate * sample_size * swa->latency) / 1000;
|
||||||
for (int i = 0; i < AUDIO_BUFFER_COUNT; i++)
|
swa->fifo = fifo_new(swa->fifoSize);
|
||||||
free(swa->buffer[i].buffer);
|
|
||||||
|
compat_condvar_create(&swa->cond);
|
||||||
free(swa);
|
|
||||||
swa = NULL;
|
RARCH_LOG("[Audio]: switch_thread_audio_init device %s requested rate %hu rate %hu latency %hu block_frames %hu fifoSize %lu\n",
|
||||||
}
|
device, rate, swa->sampleRate, swa->latency, block_frames, swa->fifoSize);
|
||||||
|
|
||||||
static ssize_t switch_thread_audio_write(void *data, const void *buf, size_t size)
|
uint32_t prio;
|
||||||
{
|
svcGetThreadPriority(&prio, 0xffff8000);
|
||||||
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
rc = compat_thread_create(&swa->thread, &mainLoop, (void*)swa, thread_stack_size, prio + 1, thread_preferred_cpu);
|
||||||
|
|
||||||
if (!swa || !swa->running)
|
if (R_FAILED(rc))
|
||||||
return 0;
|
{
|
||||||
|
RARCH_LOG("[Audio]: thread creation failed create %u\n", swa->thread.handle);
|
||||||
size_t avail;
|
swa->running = false;
|
||||||
size_t written;
|
return NULL;
|
||||||
|
}
|
||||||
if (swa->nonblocking)
|
|
||||||
{
|
if (R_FAILED(compat_thread_start(&swa->thread)))
|
||||||
lockMutex(&swa->fifoLock);
|
{
|
||||||
avail = fifo_write_avail(swa->fifo);
|
RARCH_LOG("[Audio]: thread creation failed start %u\n", swa->thread.handle);
|
||||||
written = MIN(avail, size);
|
compat_thread_close(&swa->thread);
|
||||||
if (written > 0)
|
swa->running = false;
|
||||||
{
|
return NULL;
|
||||||
fifo_write(swa->fifo, buf, written);
|
}
|
||||||
}
|
|
||||||
mutexUnlock(&swa->fifoLock);
|
return swa;
|
||||||
}
|
|
||||||
else
|
fail_audio_output:
|
||||||
{
|
#ifndef HAVE_LIBNX
|
||||||
written = 0;
|
audio_ipc_output_close(&swa->output);
|
||||||
while (written < size && swa->running)
|
#endif
|
||||||
{
|
fail_audio_ipc:
|
||||||
lockMutex(&swa->fifoLock);
|
switch_audio_ipc_finalize();
|
||||||
avail = fifo_write_avail(swa->fifo);
|
fail:
|
||||||
if (avail == 0)
|
free(swa); // freeing a null ptr is valid
|
||||||
{
|
return NULL;
|
||||||
mutexUnlock(&swa->fifoLock);
|
}
|
||||||
lockMutex(&swa->condLock);
|
|
||||||
if (swa->running)
|
static bool switch_thread_audio_start(void *data, bool is_shutdown)
|
||||||
condvarWait(&swa->cond, &swa->condLock);
|
{
|
||||||
mutexUnlock(&swa->condLock);
|
/* RARCH_LOG("[Audio]: switch_thread_audio_start\n"); */
|
||||||
}
|
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
||||||
else
|
|
||||||
{
|
if (!swa)
|
||||||
size_t write_amt = MIN(size - written, avail);
|
return false;
|
||||||
fifo_write(swa->fifo, (const char*)buf + written, write_amt);
|
|
||||||
mutexUnlock(&swa->fifoLock);
|
swa->is_paused = false;
|
||||||
written += write_amt;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
static bool switch_thread_audio_stop(void *data)
|
||||||
|
{
|
||||||
return written;
|
switch_thread_audio_t* swa = (switch_thread_audio_t*)data;
|
||||||
}
|
|
||||||
|
if (!swa)
|
||||||
static bool switch_thread_audio_alive(void *data)
|
return false;
|
||||||
{
|
|
||||||
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
swa->is_paused = true;
|
||||||
|
return true;
|
||||||
if (!swa)
|
}
|
||||||
return false;
|
|
||||||
|
static void switch_thread_audio_free(void *data)
|
||||||
return !swa->is_paused;
|
{
|
||||||
}
|
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
||||||
|
|
||||||
static void switch_thread_audio_set_nonblock_state(void *data, bool state)
|
if (!swa)
|
||||||
{
|
return;
|
||||||
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
|
||||||
|
if (swa->running)
|
||||||
if (swa)
|
{
|
||||||
swa->nonblocking = state;
|
swa->running = false;
|
||||||
}
|
compat_thread_join(&swa->thread);
|
||||||
|
compat_thread_close(&swa->thread);
|
||||||
static bool switch_thread_audio_use_float(void *data)
|
}
|
||||||
{
|
|
||||||
(void)data;
|
switch_audio_ipc_output_stop(swa);
|
||||||
return false;
|
switch_audio_ipc_finalize();
|
||||||
}
|
|
||||||
|
if (swa->fifo)
|
||||||
static size_t switch_thread_audio_write_avail(void *data)
|
{
|
||||||
{
|
fifo_free(swa->fifo);
|
||||||
switch_thread_audio_t* swa = (switch_thread_audio_t*)data;
|
swa->fifo = NULL;
|
||||||
|
}
|
||||||
lockMutex(&swa->fifoLock);
|
|
||||||
size_t val = fifo_write_avail(swa->fifo);
|
for (int i = 0; i < sizeof(swa->buffers)/sizeof(swa->buffers[0]); i++) {
|
||||||
mutexUnlock(&swa->fifoLock);
|
#ifdef HAVE_LIBNX
|
||||||
|
free(swa->buffers[i].buffer);
|
||||||
return val;
|
#else
|
||||||
}
|
free_pages(swa->buffers[i].sample_data);
|
||||||
|
#endif
|
||||||
size_t switch_thread_audio_buffer_size(void *data)
|
}
|
||||||
{
|
|
||||||
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
free(swa);
|
||||||
|
swa = NULL;
|
||||||
if (!swa)
|
}
|
||||||
return 0;
|
|
||||||
|
static ssize_t switch_thread_audio_write(void *data, const void *buf, size_t size)
|
||||||
return swa->fifoSize;
|
{
|
||||||
}
|
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
||||||
|
|
||||||
audio_driver_t audio_switch_thread = {
|
if (!swa || !swa->running)
|
||||||
switch_thread_audio_init,
|
return 0;
|
||||||
switch_thread_audio_write,
|
|
||||||
switch_thread_audio_stop,
|
size_t avail;
|
||||||
switch_thread_audio_start,
|
size_t written;
|
||||||
switch_thread_audio_alive,
|
|
||||||
switch_thread_audio_set_nonblock_state,
|
if (swa->nonblocking)
|
||||||
switch_thread_audio_free,
|
{
|
||||||
switch_thread_audio_use_float,
|
compat_mutex_lock(&swa->fifoLock);
|
||||||
"switch_thread",
|
avail = fifo_write_avail(swa->fifo);
|
||||||
NULL, /* device_list_new */
|
written = MIN(avail, size);
|
||||||
NULL, /* device_list_free */
|
if (written > 0)
|
||||||
switch_thread_audio_write_avail,
|
{
|
||||||
switch_thread_audio_buffer_size
|
fifo_write(swa->fifo, buf, written);
|
||||||
};
|
}
|
||||||
|
compat_mutex_unlock(&swa->fifoLock);
|
||||||
/* vim: set ts=6 sw=6 sts=6: */
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
written = 0;
|
||||||
|
while (written < size && swa->running)
|
||||||
|
{
|
||||||
|
compat_mutex_lock(&swa->fifoLock);
|
||||||
|
avail = fifo_write_avail(swa->fifo);
|
||||||
|
if (avail == 0)
|
||||||
|
{
|
||||||
|
compat_mutex_unlock(&swa->fifoLock);
|
||||||
|
compat_mutex_lock(&swa->condLock);
|
||||||
|
if (swa->running)
|
||||||
|
compat_condvar_wait(&swa->cond, &swa->condLock);
|
||||||
|
compat_mutex_unlock(&swa->condLock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t write_amt = MIN(size - written, avail);
|
||||||
|
fifo_write(swa->fifo, (const char*)buf + written, write_amt);
|
||||||
|
compat_mutex_unlock(&swa->fifoLock);
|
||||||
|
written += write_amt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool switch_thread_audio_alive(void *data)
|
||||||
|
{
|
||||||
|
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
||||||
|
|
||||||
|
if (!swa)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return !swa->is_paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void switch_thread_audio_set_nonblock_state(void *data, bool state)
|
||||||
|
{
|
||||||
|
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
||||||
|
|
||||||
|
if (swa)
|
||||||
|
swa->nonblocking = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool switch_thread_audio_use_float(void *data)
|
||||||
|
{
|
||||||
|
(void)data;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t switch_thread_audio_write_avail(void *data)
|
||||||
|
{
|
||||||
|
switch_thread_audio_t* swa = (switch_thread_audio_t*)data;
|
||||||
|
|
||||||
|
compat_mutex_lock(&swa->fifoLock);
|
||||||
|
size_t val = fifo_write_avail(swa->fifo);
|
||||||
|
compat_mutex_unlock(&swa->fifoLock);
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t switch_thread_audio_buffer_size(void *data)
|
||||||
|
{
|
||||||
|
switch_thread_audio_t *swa = (switch_thread_audio_t *)data;
|
||||||
|
|
||||||
|
if (!swa)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return swa->fifoSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
audio_driver_t audio_switch_thread = {
|
||||||
|
switch_thread_audio_init,
|
||||||
|
switch_thread_audio_write,
|
||||||
|
switch_thread_audio_stop,
|
||||||
|
switch_thread_audio_start,
|
||||||
|
switch_thread_audio_alive,
|
||||||
|
switch_thread_audio_set_nonblock_state,
|
||||||
|
switch_thread_audio_free,
|
||||||
|
switch_thread_audio_use_float,
|
||||||
|
"switch_thread",
|
||||||
|
NULL, /* device_list_new */
|
||||||
|
NULL, /* device_list_free */
|
||||||
|
switch_thread_audio_write_avail,
|
||||||
|
switch_thread_audio_buffer_size
|
||||||
|
};
|
||||||
|
|
||||||
|
/* vim: set ts=6 sw=6 sts=6: */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -70,6 +70,9 @@ static frontend_ctx_driver_t *frontend_ctx_drivers[] = {
|
||||||
#endif
|
#endif
|
||||||
#ifdef DJGPP
|
#ifdef DJGPP
|
||||||
&frontend_ctx_dos,
|
&frontend_ctx_dos,
|
||||||
|
#endif
|
||||||
|
#ifdef SWITCH
|
||||||
|
&frontend_ctx_switch,
|
||||||
#endif
|
#endif
|
||||||
&frontend_ctx_null,
|
&frontend_ctx_null,
|
||||||
NULL
|
NULL
|
||||||
|
|
|
@ -126,6 +126,7 @@ extern frontend_ctx_driver_t frontend_ctx_win32;
|
||||||
extern frontend_ctx_driver_t frontend_ctx_xenon;
|
extern frontend_ctx_driver_t frontend_ctx_xenon;
|
||||||
extern frontend_ctx_driver_t frontend_ctx_emscripten;
|
extern frontend_ctx_driver_t frontend_ctx_emscripten;
|
||||||
extern frontend_ctx_driver_t frontend_ctx_dos;
|
extern frontend_ctx_driver_t frontend_ctx_dos;
|
||||||
|
extern frontend_ctx_driver_t frontend_ctx_switch;
|
||||||
extern frontend_ctx_driver_t frontend_ctx_null;
|
extern frontend_ctx_driver_t frontend_ctx_null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,59 +1,59 @@
|
||||||
#ifndef SWITCH_COMMON_H__
|
#ifndef SWITCH_COMMON_H__
|
||||||
#define SWITCH_COMMON_H__
|
#define SWITCH_COMMON_H__
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <gfx/scaler/scaler.h>
|
#include <gfx/scaler/scaler.h>
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool vsync;
|
bool vsync;
|
||||||
bool rgb32;
|
bool rgb32;
|
||||||
bool smooth; // bilinear
|
bool smooth; // bilinear
|
||||||
unsigned width, height;
|
unsigned width, height;
|
||||||
unsigned rotation;
|
unsigned rotation;
|
||||||
struct video_viewport vp;
|
struct video_viewport vp;
|
||||||
struct texture_image *overlay;
|
struct texture_image *overlay;
|
||||||
bool overlay_enabled;
|
bool overlay_enabled;
|
||||||
bool in_menu;
|
bool in_menu;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
bool enable;
|
bool enable;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
|
|
||||||
uint32_t *pixels;
|
uint32_t *pixels;
|
||||||
|
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
|
||||||
unsigned tgtw;
|
unsigned tgtw;
|
||||||
unsigned tgth;
|
unsigned tgth;
|
||||||
|
|
||||||
struct scaler_ctx scaler;
|
struct scaler_ctx scaler;
|
||||||
} menu_texture;
|
} menu_texture;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint32_t x_offset;
|
uint32_t x_offset;
|
||||||
} hw_scale;
|
} hw_scale;
|
||||||
|
|
||||||
uint32_t image[1280 * 720];
|
uint32_t image[1280 * 720];
|
||||||
uint32_t tmp_image[1280 * 720];
|
uint32_t tmp_image[1280 * 720];
|
||||||
u32 cnt;
|
u32 cnt;
|
||||||
struct scaler_ctx scaler;
|
struct scaler_ctx scaler;
|
||||||
uint32_t last_width;
|
uint32_t last_width;
|
||||||
uint32_t last_height;
|
uint32_t last_height;
|
||||||
bool keep_aspect;
|
bool keep_aspect;
|
||||||
bool should_resize;
|
bool should_resize;
|
||||||
bool need_clear;
|
bool need_clear;
|
||||||
bool is_threaded;
|
bool is_threaded;
|
||||||
|
|
||||||
bool o_size;
|
bool o_size;
|
||||||
uint32_t o_height;
|
uint32_t o_height;
|
||||||
uint32_t o_width;
|
uint32_t o_width;
|
||||||
} switch_video_t;
|
} switch_video_t;
|
||||||
|
|
||||||
void gfx_slow_swizzling_blit(uint32_t *buffer, uint32_t *image, int w, int h, int tx, int ty, bool blend);
|
void gfx_slow_swizzling_blit(uint32_t *buffer, uint32_t *image, int w, int h, int tx, int ty, bool blend);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* RetroArch - A frontend for libretro.
|
/* RetroArch - A frontend for libretro.
|
||||||
* Copyright (C) 2018 - misson2000
|
* Copyright (C) 2018 - misson20000
|
||||||
* Copyright (C) 2018 - m4xw
|
* Copyright (C) 2018 - m4xw
|
||||||
*
|
*
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,207 +1,207 @@
|
||||||
/* Copyright (C) 2018 - M4xw <m4x@m4xw.net>, RetroArch Team
|
/* Copyright (C) 2018 - M4xw <m4x@m4xw.net>, RetroArch Team
|
||||||
*
|
*
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
* The following license statement only applies to this file (switch_pthread.h).
|
* The following license statement only applies to this file (switch_pthread.h).
|
||||||
* ---------------------------------------------------------------------------------------
|
* ---------------------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge,
|
* Permission is hereby granted, free of charge,
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||||
* to deal in the Software without restriction, including without limitation the rights to
|
* to deal in the Software without restriction, including without limitation the rights to
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _SWITCH_PTHREAD_WRAP_
|
#ifndef _SWITCH_PTHREAD_WRAP_
|
||||||
#define _SWITCH_PTHREAD_WRAP_
|
#define _SWITCH_PTHREAD_WRAP_
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "../include/retro_inline.h"
|
#include "../include/retro_inline.h"
|
||||||
#include "../../verbosity.h"
|
#include "../../verbosity.h"
|
||||||
|
|
||||||
#define THREADVARS_MAGIC 0x21545624 // !TV$
|
#define THREADVARS_MAGIC 0x21545624 // !TV$
|
||||||
|
|
||||||
// This structure is exactly 0x20 bytes, if more is needed modify getThreadVars() below
|
// This structure is exactly 0x20 bytes, if more is needed modify getThreadVars() below
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
// Magic value used to check if the struct is initialized
|
// Magic value used to check if the struct is initialized
|
||||||
u32 magic;
|
u32 magic;
|
||||||
|
|
||||||
// Thread handle, for mutexes
|
// Thread handle, for mutexes
|
||||||
Handle handle;
|
Handle handle;
|
||||||
|
|
||||||
// Pointer to the current thread (if exists)
|
// Pointer to the current thread (if exists)
|
||||||
Thread *thread_ptr;
|
Thread *thread_ptr;
|
||||||
|
|
||||||
// Pointer to this thread's newlib state
|
// Pointer to this thread's newlib state
|
||||||
struct _reent *reent;
|
struct _reent *reent;
|
||||||
|
|
||||||
// Pointer to this thread's thread-local segment
|
// Pointer to this thread's thread-local segment
|
||||||
void *tls_tp; // !! Offset needs to be TLS+0x1F8 for __aarch64_read_tp !!
|
void *tls_tp; // !! Offset needs to be TLS+0x1F8 for __aarch64_read_tp !!
|
||||||
} ThreadVars;
|
} ThreadVars;
|
||||||
|
|
||||||
static INLINE ThreadVars *getThreadVars(void)
|
static INLINE ThreadVars *getThreadVars(void)
|
||||||
{
|
{
|
||||||
return (ThreadVars *)((u8 *)armGetTls() + 0x1E0);
|
return (ThreadVars *)((u8 *)armGetTls() + 0x1E0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STACKSIZE (8 * 1024)
|
#define STACKSIZE (8 * 1024)
|
||||||
|
|
||||||
/* libnx threads return void but pthreads return void pointer */
|
/* libnx threads return void but pthreads return void pointer */
|
||||||
|
|
||||||
static uint32_t threadCounter = 1;
|
static uint32_t threadCounter = 1;
|
||||||
|
|
||||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
|
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
|
||||||
{
|
{
|
||||||
u32 prio = 0;
|
u32 prio = 0;
|
||||||
Thread new_switch_thread;
|
Thread new_switch_thread;
|
||||||
|
|
||||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||||
|
|
||||||
// Launch threads on Core 1
|
// Launch threads on Core 1
|
||||||
int rc = threadCreate(&new_switch_thread, (void (*)(void *))start_routine, arg, STACKSIZE, prio - 1, 1);
|
int rc = threadCreate(&new_switch_thread, (void (*)(void *))start_routine, arg, STACKSIZE, prio - 1, 1);
|
||||||
|
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
{
|
{
|
||||||
return EAGAIN;
|
return EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("[Threading]: Starting Thread(#%i)\n", threadCounter);
|
printf("[Threading]: Starting Thread(#%i)\n", threadCounter);
|
||||||
if (R_FAILED(threadStart(&new_switch_thread)))
|
if (R_FAILED(threadStart(&new_switch_thread)))
|
||||||
{
|
{
|
||||||
threadClose(&new_switch_thread);
|
threadClose(&new_switch_thread);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*thread = new_switch_thread;
|
*thread = new_switch_thread;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pthread_exit(void *retval)
|
void pthread_exit(void *retval)
|
||||||
{
|
{
|
||||||
(void)retval;
|
(void)retval;
|
||||||
printf("[Threading]: Exiting Thread\n");
|
printf("[Threading]: Exiting Thread\n");
|
||||||
svcExitThread();
|
svcExitThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE Thread threadGetCurrent(void)
|
static INLINE Thread threadGetCurrent(void)
|
||||||
{
|
{
|
||||||
ThreadVars *tv = getThreadVars();
|
ThreadVars *tv = getThreadVars();
|
||||||
return *tv->thread_ptr;
|
return *tv->thread_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE pthread_t pthread_self(void)
|
static INLINE pthread_t pthread_self(void)
|
||||||
{
|
{
|
||||||
return threadGetCurrent();
|
return threadGetCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
|
static INLINE int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
|
||||||
{
|
{
|
||||||
mutexInit(mutex);
|
mutexInit(mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE int pthread_mutex_destroy(pthread_mutex_t *mutex)
|
INLINE int pthread_mutex_destroy(pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
// Nothing
|
// Nothing
|
||||||
*mutex = 0;
|
*mutex = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_mutex_lock(pthread_mutex_t *mutex)
|
static INLINE int pthread_mutex_lock(pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
mutexLock(mutex);
|
mutexLock(mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_mutex_unlock(pthread_mutex_t *mutex)
|
static INLINE int pthread_mutex_unlock(pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
mutexUnlock(mutex);
|
mutexUnlock(mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE int pthread_detach(pthread_t thread)
|
INLINE int pthread_detach(pthread_t thread)
|
||||||
{
|
{
|
||||||
(void)thread;
|
(void)thread;
|
||||||
// Nothing for now
|
// Nothing for now
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_join(pthread_t thread, void **retval)
|
static INLINE int pthread_join(pthread_t thread, void **retval)
|
||||||
{
|
{
|
||||||
printf("[Threading]: Waiting for Thread Exit\n");
|
printf("[Threading]: Waiting for Thread Exit\n");
|
||||||
threadWaitForExit(&thread);
|
threadWaitForExit(&thread);
|
||||||
threadClose(&thread);
|
threadClose(&thread);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_mutex_trylock(pthread_mutex_t *mutex)
|
static INLINE int pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
return mutexTryLock(mutex) ? 0 : 1;
|
return mutexTryLock(mutex) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
static INLINE int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
condvarWait(cond, mutex);
|
condvarWait(cond, mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
|
static INLINE int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
|
||||||
{
|
{
|
||||||
condvarWaitTimeout(cond, mutex, abstime->tv_nsec);
|
condvarWaitTimeout(cond, mutex, abstime->tv_nsec);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
|
static INLINE int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
|
||||||
{
|
{
|
||||||
condvarInit(cond);
|
condvarInit(cond);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_cond_signal(pthread_cond_t *cond)
|
static INLINE int pthread_cond_signal(pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
condvarWakeOne(cond);
|
condvarWakeOne(cond);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE int pthread_cond_broadcast(pthread_cond_t *cond)
|
static INLINE int pthread_cond_broadcast(pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
condvarWakeAll(cond);
|
condvarWakeAll(cond);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE int pthread_cond_destroy(pthread_cond_t *cond)
|
INLINE int pthread_cond_destroy(pthread_cond_t *cond)
|
||||||
{
|
{
|
||||||
// Nothing
|
// Nothing
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE int pthread_equal(pthread_t t1, pthread_t t2)
|
INLINE int pthread_equal(pthread_t t1, pthread_t t2)
|
||||||
{
|
{
|
||||||
if (t1.handle == t2.handle)
|
if (t1.handle == t2.handle)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -391,7 +391,7 @@ int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, i
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if(_chsize(_fileno(stream->fp), length) != 0)
|
if(_chsize(_fileno(stream->fp), length) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
#elif !defined(VITA) && !defined(PSP)
|
#elif !defined(VITA) && !defined(PSP) && (!defined(SWITCH) || defined(HAVE_LIBNX))
|
||||||
if(ftruncate(fileno(stream->fp), length) != 0)
|
if(ftruncate(fileno(stream->fp), length) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue