From 76bf41188aa3357f085f3e213e1097eb27e5edf1 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 16 Feb 2013 12:30:26 +0100 Subject: [PATCH] Add video_threaded option to Android. --- android/native/jni/Android.mk | 3 +-- android/phoenix/res/xml/prefs.xml | 6 +++++- .../src/org/retroarch/browser/RetroArch.java | 1 + audio/resampler.h | 6 ++---- audio/sinc.c | 19 ++++++++++--------- console/griffin/griffin.c | 5 ++++- driver.c | 2 +- driver_funcs.h | 2 +- general.h | 2 +- gfx/context/androidegl_ctx.c | 6 ++++++ gfx/thread_wrapper.c | 11 ++++++++--- record/ffemu.c | 2 +- retroarch.c | 2 +- 13 files changed, 42 insertions(+), 25 deletions(-) diff --git a/android/native/jni/Android.mk b/android/native/jni/Android.mk index 25b1a45b9e..d14440b85f 100644 --- a/android/native/jni/Android.mk +++ b/android/native/jni/Android.mk @@ -6,7 +6,6 @@ HAVE_SINC := 1 HAVE_LOGGER := 1 include $(CLEAR_VARS) - ifeq ($(TARGET_ARCH),arm) LOCAL_CFLAGS += -DANDROID_ARM -marm LOCAL_ARM_MODE := arm @@ -52,7 +51,7 @@ ifeq ($(PERF_TEST), 1) LOCAL_CFLAGS += -DPERF_TEST endif -LOCAL_CFLAGS += -Wall -Wno-unused-function -O3 -fno-stack-protector -funroll-loops -DNDEBUG -DHAVE_GRIFFIN -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_FBO -DHAVE_OVERLAY -DHAVE_OPENGLES -DHAVE_VID_CONTEXT -DHAVE_OPENGLES2 -DGLSL_DEBUG -DHAVE_GLSL -DWANT_RZLIB -DHAVE_ZLIB -DINLINE=inline -DLSB_FIRST -DHAVE_THREAD -D__LIBRETRO__ -DRARCH_PERFORMANCE_MODE -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -std=gnu99 -I../../../deps/rzlib +LOCAL_CFLAGS += -Wall -pthread -Wno-unused-function -O3 -fno-stack-protector -funroll-loops -DNDEBUG -DHAVE_GRIFFIN -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_FBO -DHAVE_OVERLAY -DHAVE_OPENGLES -DHAVE_VID_CONTEXT -DHAVE_OPENGLES2 -DGLSL_DEBUG -DHAVE_GLSL -DWANT_RZLIB -DHAVE_ZLIB -DINLINE=inline -DLSB_FIRST -DHAVE_THREADS -D__LIBRETRO__ -DRARCH_PERFORMANCE_MODE -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -std=gnu99 -I../../../deps/rzlib LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -landroid -lEGL -lGLESv2 $(LOGGER_LDLIBS) -ldl diff --git a/android/phoenix/res/xml/prefs.xml b/android/phoenix/res/xml/prefs.xml index 8908a94155..521745440a 100644 --- a/android/phoenix/res/xml/prefs.xml +++ b/android/phoenix/res/xml/prefs.xml @@ -81,12 +81,16 @@ android:title="Aspect ratio" /> + - diff --git a/android/phoenix/src/org/retroarch/browser/RetroArch.java b/android/phoenix/src/org/retroarch/browser/RetroArch.java index de137fba09..83475fe87b 100644 --- a/android/phoenix/src/org/retroarch/browser/RetroArch.java +++ b/android/phoenix/src/org/retroarch/browser/RetroArch.java @@ -371,6 +371,7 @@ public class RetroArch extends Activity implements config.setInt("input_autodetect_icade_profile_pad4", prefs.getInt("input_autodetect_icade_profile_pad4", 0)); config.setDouble("video_refresh_rate", getRefreshRate()); + config.setBoolean("video_threaded", prefs.getBoolean("video_threaded", true)); String aspect = prefs.getString("video_aspect_ratio", "auto"); if (aspect.equals("full")) { diff --git a/audio/resampler.h b/audio/resampler.h index 981c44f541..c5f803e8d7 100644 --- a/audio/resampler.h +++ b/audio/resampler.h @@ -31,12 +31,10 @@ #define M_PI 3.14159265358979323846264338327 #endif -typedef float sample_t; - struct resampler_data { - const sample_t *data_in; - sample_t *data_out; + const float *data_in; + float *data_out; size_t input_frames; size_t output_frames; diff --git a/audio/sinc.c b/audio/sinc.c index 483e148a73..937f985ca9 100644 --- a/audio/sinc.c +++ b/audio/sinc.c @@ -104,9 +104,9 @@ typedef struct rarch_sinc_resampler { - sample_t *phase_table; - sample_t *buffer_l; - sample_t *buffer_r; + float *phase_table; + float *buffer_l; + float *buffer_r; unsigned taps; @@ -115,7 +115,7 @@ typedef struct rarch_sinc_resampler // A buffer for phase_table, buffer_l and buffer_r are created in a single calloc(). // Ensure that we get as good cache locality as we can hope for. - sample_t *main_buffer; + float *main_buffer; } rarch_sinc_resampler_t; static inline double sinc(double val) @@ -389,9 +389,10 @@ static void process_sinc_neon(rarch_sinc_resampler_t *resamp, float *out_buffer) const float *buffer_r = resamp->buffer_r + resamp->ptr; unsigned phase = resamp->time >> SUBPHASE_BITS; - const float *phase_table = resamp->phase_table[phase]; + unsigned taps = resamp->taps; + const float *phase_table = resamp->phase_table + phase * taps; - process_sinc_neon_asm(out_buffer, buffer_l, buffer_r, phase_table, resamp->taps); + process_sinc_neon_asm(out_buffer, buffer_l, buffer_r, phase_table, taps); } #else // Plain ol' C99 #define process_sinc_func process_sinc_C @@ -403,8 +404,8 @@ static void resampler_sinc_process(void *re_, struct resampler_data *data) uint32_t ratio = PHASES / data->ratio; - const sample_t *input = data->data_in; - sample_t *output = data->data_out; + const float *input = data->data_in; + float *output = data->data_out; size_t frames = data->input_frames; size_t out_frames = 0; @@ -475,7 +476,7 @@ static void *resampler_sinc_new(double bandwidth_mod) #endif size_t elems = phase_elems + 4 * re->taps; - re->main_buffer = (sample_t*)aligned_alloc__(128, sizeof(sample_t) * elems); + re->main_buffer = (float*)aligned_alloc__(128, sizeof(float) * elems); if (!re->main_buffer) goto error; diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 950d609075..c75823d96b 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -377,15 +377,18 @@ RETROARCH /*============================================================ THREAD ============================================================ */ +// This is supposed to be HAVE_THREADS. #if defined(HAVE_THREAD) && defined(XENON) #include "../../thread/xenon_sdl_threads.c" -#elif defined(HAVE_THREAD) +#elif defined(HAVE_THREADS) #include "../../thread.c" +#include "../../gfx/thread_wrapper.c" #ifdef ANDROID #include "../../autosave.c" #endif #endif + /*============================================================ NETPLAY ============================================================ */ diff --git a/driver.c b/driver.c index 5db2e09af8..083b7a86e8 100644 --- a/driver.c +++ b/driver.c @@ -424,7 +424,7 @@ void init_audio(void) g_extern.audio_data.data_ptr = 0; rarch_assert(g_settings.audio.out_rate < g_settings.audio.in_rate * AUDIO_MAX_RATIO); - rarch_assert(g_extern.audio_data.outsamples = (sample_t*)malloc(outsamples_max * sizeof(sample_t))); + rarch_assert(g_extern.audio_data.outsamples = (float*)malloc(outsamples_max * sizeof(float))); if (g_extern.audio_active && g_settings.audio.rate_control) { diff --git a/driver_funcs.h b/driver_funcs.h index dd2461e31f..d6f776e679 100644 --- a/driver_funcs.h +++ b/driver_funcs.h @@ -18,7 +18,7 @@ #ifndef _RARCH_DRIVER_FUNCS_H #define _RARCH_DRIVER_FUNCS_H -#if !defined(HAVE_GRIFFIN) /* Normal */ +#if !defined(HAVE_GRIFFIN) || defined(ANDROID) /* Normal */ #define audio_init_func(device, rate, latency) driver.audio->init(device, rate, latency) #define audio_write_func(buf, size) driver.audio->write(driver.audio_data, buf, size) diff --git a/general.h b/general.h index 4398447637..ac621b62b0 100644 --- a/general.h +++ b/general.h @@ -397,7 +397,7 @@ struct global bool use_float; bool mute; - sample_t *outsamples; + float *outsamples; int16_t *conv_outsamples; int16_t *rewind_buf; diff --git a/gfx/context/androidegl_ctx.c b/gfx/context/androidegl_ctx.c index ba775cff8c..ce0e76633d 100644 --- a/gfx/context/androidegl_ctx.c +++ b/gfx/context/androidegl_ctx.c @@ -15,10 +15,12 @@ */ #include "../../driver.h" +#include "../../general.h" #include "../gfx_common.h" #include "../gl_common.h" #include /* Requires NDK r5 or newer */ +#include #include "../../frontend/frontend_android.h" #include "../image.h" @@ -148,6 +150,10 @@ static bool gfx_ctx_init(void) goto error; } + ALooper *looper = ALooper_forThread(); + if (!looper) + ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); + return true; error: diff --git a/gfx/thread_wrapper.c b/gfx/thread_wrapper.c index 67efe230b3..33845b8171 100644 --- a/gfx/thread_wrapper.c +++ b/gfx/thread_wrapper.c @@ -340,7 +340,6 @@ static bool thread_frame(void *data, const void *frame_, for (unsigned h = 0; h < height; h++, src += pitch, dst += copy_stride) memcpy(dst, src, copy_stride); thr->frame.updated = true; - scond_signal(thr->cond_thread); thr->frame.width = width; thr->frame.height = height; thr->frame.pitch = copy_stride; @@ -350,6 +349,7 @@ static bool thread_frame(void *data, const void *frame_, else *thr->frame.msg = '\0'; + scond_signal(thr->cond_thread); slock_unlock(thr->frame.lock); } slock_unlock(thr->lock); @@ -380,16 +380,21 @@ static bool thread_init(thread_video_t *thr, const video_info_t *info, const inp thr->alive = true; thr->focus = true; - thr->frame.buffer = (uint8_t*)malloc((info->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t)) * - info->input_scale * info->input_scale * RARCH_SCALE_BASE * RARCH_SCALE_BASE); + size_t max_size = info->input_scale * RARCH_SCALE_BASE; + max_size *= max_size; + max_size *= info->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); + thr->frame.buffer = (uint8_t*)malloc(max_size); if (!thr->frame.buffer) return false; + memset(thr->frame.buffer, 0x80, max_size); + thr->thread = sthread_create(thread_loop, thr); if (!thr->thread) return false; thread_send_cmd(thr, CMD_INIT); thread_wait_reply(thr, CMD_INIT); + return thr->cmd_data.b; } diff --git a/record/ffemu.c b/record/ffemu.c index a7ffffe4ff..3b81a33410 100644 --- a/record/ffemu.c +++ b/record/ffemu.c @@ -1023,7 +1023,7 @@ static void ffemu_audio_resample(ffemu_t *handle, struct ffemu_audio_data *data) { // It's always two channels ... struct resampler_data info = {0}; - info.data_in = (const sample_t*)data->data; + info.data_in = (const float*)data->data; info.data_out = handle->audio.resample_out; info.input_frames = data->frames; info.ratio = handle->audio.ratio; diff --git a/retroarch.c b/retroarch.c index 01e52328d5..333513e76a 100644 --- a/retroarch.c +++ b/retroarch.c @@ -366,7 +366,7 @@ static bool audio_flush(const int16_t *data, size_t samples) if (!g_extern.audio_active) return false; - const sample_t *output_data = NULL; + const float *output_data = NULL; unsigned output_frames = 0; struct resampler_data src_data = {0};