Skip to content

Commit

Permalink
Detect supported resolutions
Browse files Browse the repository at this point in the history
Add some more resolutions and predetect resolutions from it.
`sceVideodecInitLibrary` would return the negative value if input the
invalid param (most time it would be invalid resolution)

also it prevent to change the resolution after starting the streaming.

resolve #160
  • Loading branch information
d3m3vilurr committed Oct 29, 2020
1 parent a37923f commit ede3ce8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 21 deletions.
62 changes: 51 additions & 11 deletions src/gui/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "../config.h"
#include "../input/vita.h"
#include "../video/vita.h"

#include <assert.h>
#include <stdarg.h>
Expand All @@ -18,6 +19,7 @@
#include <psp2/ctrl.h>
#include <psp2/rtc.h>
#include <psp2/touch.h>
#include <psp2/videodec.h>
#include <vita2d.h>
#include <Limelight.h>

Expand Down Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 5 additions & 9 deletions src/video/vita.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "../config.h"
#include "../debug.h"
#include "../gui/guilib.h"
#include "vita.h"
#include "sps.h"

#include <Limelight.h>
Expand All @@ -34,7 +35,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include <stdarg.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/video/vita.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@
* You should have received a copy of the GNU General Public License
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
*/
#include <math.h>

// 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();
2 changes: 1 addition & 1 deletion third_party/moonlight-common-c

0 comments on commit ede3ce8

Please sign in to comment.