diff --git a/src/gui/ui_settings.c b/src/gui/ui_settings.c index 5c600559..53263179 100644 --- a/src/gui/ui_settings.c +++ b/src/gui/ui_settings.c @@ -5,6 +5,7 @@ #include "../config.h" #include "../input/vita.h" +#include "../video/vita.h" #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include #include @@ -69,6 +71,25 @@ static char *settings_special_names[] = {"None", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12" }; +#define MAX_RESOLUTION 9 +static int RESOLUTIONS[MAX_RESOLUTION][2] = { + {960, 540}, // 16:9, QHD + {960, 544}, // VITA original + {1024, 576}, // 16:9 + {1152, 648}, // 16:9 + {1280, 540}, // 21:9 + {1280, 720}, // 16:9, 720p HD + {1366, 768}, // 16:9, WXGA + {1600, 900}, // 16:9, 900p HD+ + //{1720, 720}, // 21:9 + {1920, 1080}, // 16:9, FHD + //{1920, 1200}, // 16:10 +}; + +int support_resolution_idx[MAX_RESOLUTION] = {-1}; +char *support_resolutions[MAX_RESOLUTION] = {0}; +int support_resolution_count = 0; + static bool settings_loop_setup = 1; /* @@ -446,23 +467,42 @@ static int settings_loop(int id, void *context, const input_data *input) { char current[256]; int new_idx; + if (!vitavideo_initialized() && !support_resolution_count) { + for (int i = 0; i < MAX_RESOLUTION; i++) { + SceVideodecQueryInitInfoHwAvcdec dec; + dec.size = sizeof(SceVideodecQueryInitInfoHwAvcdec); + dec.horizontal = VITA_DECODER_RESOLUTION(RESOLUTIONS[i][0]); + dec.vertical = VITA_DECODER_RESOLUTION(RESOLUTIONS[i][1]); + dec.numOfRefFrames = 5; + dec.numOfStreams = 1; + int ret = sceVideodecInitLibrary(SCE_VIDEODEC_TYPE_HW_AVCDEC, &dec); + sceVideodecTermLibrary(SCE_VIDEODEC_TYPE_HW_AVCDEC); + if (ret < 0) { + // unsupported resolution + continue; + } + support_resolutions[support_resolution_count] = calloc(10, sizeof(char)); + snprintf(support_resolutions[support_resolution_count], 10, "%dx%d", RESOLUTIONS[i][0], RESOLUTIONS[i][1]); + vita_debug_log("res: %d\n", support_resolution_count); + vita_debug_log("%s\n", support_resolutions[support_resolution_count]); + support_resolution_idx[support_resolution_count++] = i; + } + } + switch (id) { case SETTINGS_RESOLUTION: if (!left && !right) { - break; + break; + } + if (vitavideo_initialized()) { + break; } - char *resolutions[] = {"960x540", "960x544", "1280x540", "1280x720", "1920x1080"}; + //char *resolutions[] = {"960x540", "960x544", "1280x540", "1280x720", "1920x1080"}; sprintf(current, "%dx%d", config.stream.width, config.stream.height); - new_idx = _move_idx_in_array(resolutions, current, left ? -1 : +1); - - switch (new_idx) { - case 0: config.stream.width = 960; config.stream.height = 540; break; - case 1: config.stream.width = 960; config.stream.height = 544; break; - case 2: config.stream.width = 1280; config.stream.height = 540; break; - case 3: config.stream.width = 1280; config.stream.height = 720; break; - case 4: config.stream.width = 1920; config.stream.height = 1080; break; - } + new_idx = move_idx_in_array(support_resolutions, support_resolution_count, current, left ? -1 : +1); + config.stream.width = RESOLUTIONS[support_resolution_idx[new_idx]][0]; + config.stream.height = RESOLUTIONS[support_resolution_idx[new_idx]][1]; did_change = 1; break; diff --git a/src/video/vita.c b/src/video/vita.c index 95d0bd2d..ea3b4161 100644 --- a/src/video/vita.c +++ b/src/video/vita.c @@ -21,6 +21,7 @@ #include "../config.h" #include "../debug.h" #include "../gui/guilib.h" +#include "vita.h" #include "sps.h" #include @@ -34,7 +35,6 @@ #include #include #include -#include #include @@ -118,14 +118,6 @@ typedef struct { static image_scaling_settings image_scaling = {0}; -// Vita's sceVideodecInitLibrary only accept resolution that is multiple of 16 on either dimension, -// and the smallest resolution is 64 -// Full supported resolution list can be found at: -// https://github.com/MakiseKurisu/vita-sceVideodecInitLibrary-test/ -#define ROUND_NEAREST_16(x) (round(((double) (x)) / 16) * 16) -#define VITA_DECODER_RESOLUTION_LOWER_BOUND(x) ((x) < 64 ? 64 : (x)) -#define VITA_DECODER_RESOLUTION(x) (VITA_DECODER_RESOLUTION_LOWER_BOUND(ROUND_NEAREST_16(x))) - void update_scaling_settings(int width, int height) { image_scaling.texture_width = SCREEN_WIDTH; image_scaling.texture_height = SCREEN_HEIGHT; @@ -563,6 +555,10 @@ void vitavideo_hide_poor_net_indicator() { memset(&poor_net_indicator, 0, sizeof(indicator_status)); } +int vitavideo_initialized() { + return video_status != NOT_INIT; +} + DECODER_RENDERER_CALLBACKS decoder_callbacks_vita = { .setup = vita_setup, .cleanup = vita_cleanup, diff --git a/src/video/vita.h b/src/video/vita.h index 447e007b..b1ab176d 100644 --- a/src/video/vita.h +++ b/src/video/vita.h @@ -16,9 +16,18 @@ * You should have received a copy of the GNU General Public License * along with Moonlight; if not, see . */ +#include +// Vita's sceVideodecInitLibrary only accept resolution that is multiple of 16 on either dimension, +// and the smallest resolution is 64 +// Full supported resolution list can be found at: +// https://github.com/MakiseKurisu/vita-sceVideodecInitLibrary-test/ +#define ROUND_NEAREST_16(x) (round(((double) (x)) / 16) * 16) +#define VITA_DECODER_RESOLUTION_LOWER_BOUND(x) ((x) < 64 ? 64 : (x)) +#define VITA_DECODER_RESOLUTION(x) (VITA_DECODER_RESOLUTION_LOWER_BOUND(ROUND_NEAREST_16(x))) void vitavideo_start(); void vitavideo_stop(); void vitavideo_show_poor_net_indicator(); void vitavideo_hide_poor_net_indicator(); +int vitavideo_initialized(); diff --git a/third_party/moonlight-common-c b/third_party/moonlight-common-c index edf08d0a..8dfc96ee 160000 --- a/third_party/moonlight-common-c +++ b/third_party/moonlight-common-c @@ -1 +1 @@ -Subproject commit edf08d0a60ae6594cbd897a4746f2d2e8d2b1c04 +Subproject commit 8dfc96eecfdc6791547b4a67220dbbf01ecc2f65