Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Start Session After Failure #408

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/app_session.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "app_session.h"
#include "app.h"
#include "stream/session.h"
#include "logging.h"

int app_session_begin(app_t *app, const uuidstr_t *uuid, const APP_LIST *gs_app) {
if (app->session != NULL) {
commons_log_error("App", "Session already exists");
return -1;
}
const pclist_t *node = pcmanager_node(pcmanager, uuid);
if (node == NULL) {
commons_log_error("App", "Failed to find node %s", (const char *) uuid);
return -1;
}
app->session = session_create(app, app_configuration, node->server, gs_app);
Expand Down
4 changes: 4 additions & 0 deletions src/app/stream/audio/session_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ static OpusMSDecoder *decoder = NULL;
static unsigned char *buffer = NULL;
static int frame_size = 0, unit_size = 0;

AUDIO_INFO audio_stream_info;

static size_t opus_head_serialize(const OPUS_MULTISTREAM_CONFIGURATION *config, unsigned char *data);

static int aud_init(int audioConfiguration, const POPUS_MULTISTREAM_CONFIGURATION opusConfig, void *context,
int arFlags) {
(void) audioConfiguration;
(void) arFlags;
memset(&audio_stream_info, 0, sizeof(audio_stream_info));
session = context;
player = session->player;
SS4S_AudioCodec codec = SS4S_AUDIO_PCM_S16LE;
Expand All @@ -43,6 +46,7 @@ static int aud_init(int audioConfiguration, const POPUS_MULTISTREAM_CONFIGURATIO
unit_size = (int) (opusConfig->channelCount * sizeof(int16_t));
buffer = calloc(unit_size, frame_size);
}
audio_stream_info.format = SS4S_AudioCodecName(codec);
SS4S_AudioInfo info = {
.numOfChannels = opusConfig->channelCount,
.codec = codec,
Expand Down
19 changes: 16 additions & 3 deletions src/app/stream/input/session_evmouse.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "session_evmouse.h"
#include "evmouse.h"
#include "stream/session_priv.h"

#include <errno.h>
#include <assert.h>

#include "logging.h"

Expand All @@ -14,6 +16,7 @@ static void set_evmouse(session_evmouse_t *mouse, evmouse_t *dev);
void session_evmouse_init(session_evmouse_t *mouse, session_t *session) {
mouse->session = session;
mouse->lock = SDL_CreateMutex();
mouse->cond = SDL_CreateCond();
mouse->thread = SDL_CreateThread((SDL_ThreadFunction) mouse_worker, "sessinput", mouse);
}

Expand All @@ -24,16 +27,25 @@ void session_evmouse_deinit(session_evmouse_t *mouse) {
}
SDL_DestroyMutex(mouse->lock);
mouse->lock = NULL;
SDL_DestroyCond(mouse->cond);
mouse->cond = NULL;
}

void session_evmouse_interrupt(session_evmouse_t *mouse) {
void session_evmouse_wait_ready(session_evmouse_t *mouse) {
SDL_LockMutex(mouse->lock);
if (mouse->dev != NULL) {
evmouse_interrupt(mouse->dev);
while (mouse->dev == NULL) {
SDL_CondWait(mouse->cond, mouse->lock);
}
SDL_UnlockMutex(mouse->lock);
}

void session_evmouse_interrupt(session_evmouse_t *mouse) {
SDL_LockMutex(mouse->lock);
assert (mouse->dev != NULL);
evmouse_interrupt(mouse->dev);
SDL_UnlockMutex(mouse->lock);
}

static int mouse_worker(session_evmouse_t *mouse) {
evmouse_t *dev = evmouse_open_default();
if (dev == NULL) {
Expand All @@ -52,6 +64,7 @@ static int mouse_worker(session_evmouse_t *mouse) {
static void set_evmouse(session_evmouse_t *mouse, evmouse_t *dev) {
SDL_LockMutex(mouse->lock);
mouse->dev = dev;
SDL_CondSignal(mouse->cond);
SDL_UnlockMutex(mouse->lock);
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/stream/input/session_evmouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ typedef struct session_t session_t;
typedef struct session_evmouse_t {
session_t *session;
SDL_mutex *lock;
SDL_cond *cond;
SDL_Thread *thread;
struct evmouse_t *dev;
} session_evmouse_t;
Expand All @@ -15,4 +16,6 @@ void session_evmouse_init(session_evmouse_t *mouse, session_t *session);

void session_evmouse_deinit(session_evmouse_t *mouse);

void session_evmouse_wait_ready(session_evmouse_t *mouse);

void session_evmouse_interrupt(session_evmouse_t *mouse);
6 changes: 3 additions & 3 deletions src/app/stream/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ typedef struct VIDEO_INFO {
bool has_decoder_latency;
} VIDEO_INFO;

typedef struct AUDIO_STATS {
uint32_t avgBufferTime;
} AUDIO_STATS;
typedef struct AUDIO_INFO {
const char *format;
} AUDIO_INFO;

typedef struct session_config_t {
STREAM_CONFIGURATION stream;
Expand Down
7 changes: 4 additions & 3 deletions src/app/stream/session_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ int session_worker(session_t *session) {
int appId = session->app_id;
session->player = NULL;

#if FEATURE_INPUT_EVMOUSE
session_evmouse_wait_ready(&session->input.evmouse);
#endif

commons_log_info("Session", "Launch app %d...", appId);
GS_CLIENT client = app_gs_client_new(app);
gs_set_timeout(client, 30);
Expand Down Expand Up @@ -110,9 +114,6 @@ int session_worker(session_t *session) {
}
gs_destroy(client);
bus_pushevent(USER_STREAM_FINISHED, NULL, NULL);
#if FEATURE_INPUT_EVMOUSE
session_evmouse_deinit(&session->input.evmouse);
#endif
app_bus_post(app, (bus_actionfunc) app_session_destroy, app);
return 0;
}
5 changes: 4 additions & 1 deletion src/app/stream/video/session_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,17 @@ void vdec_stat_submit(const struct VIDEO_STATS *src, unsigned long now) {
dst->totalFps = (float) dst->totalFrames / ((float) delta / 1000);
dst->receivedFps = (float) dst->receivedFrames / ((float) delta / 1000);
dst->decodedFps = (float) dst->submittedFrames / ((float) delta / 1000);
LiGetEstimatedRttInfo(&dst->rtt, &dst->rttVariance);
if (!streaming_overlay_shown()) {
return;
}
int latencyUs = 0;
if (SS4S_PlayerGetVideoLatency(player, 0, &latencyUs)) {
dst->avgDecoderLatency = (float) latencyUs / 1000.0f;
vdec_stream_info.has_decoder_latency = true;
} else {
dst->avgDecoderLatency = 0;
}
LiGetEstimatedRttInfo(&dst->rtt, &dst->rttVariance);
app_bus_post(session->app, (bus_actionfunc) streaming_refresh_stats, NULL);
}

Expand Down
1 change: 1 addition & 0 deletions src/app/stream/video/session_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

extern struct VIDEO_STATS vdec_summary_stats;
extern struct VIDEO_INFO vdec_stream_info;
extern struct AUDIO_INFO audio_stream_info;

extern DECODER_RENDERER_CALLBACKS ss4s_dec_callbacks;

12 changes: 11 additions & 1 deletion src/app/ui/streaming/streaming.controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static void on_view_created(lv_fragment_t *self, lv_obj_t *view);

static void on_delete_obj(lv_fragment_t *self, lv_obj_t *view);

static void on_obj_deleted(lv_fragment_t *self, lv_obj_t *view);

static bool on_event(lv_fragment_t *self, int code, void *userdata);

static void constructor(lv_fragment_t *self, void *args);
Expand All @@ -44,6 +46,7 @@ const lv_fragment_class_t streaming_controller_class = {
.create_obj_cb = streaming_scene_create,
.obj_created_cb = on_view_created,
.obj_will_delete_cb = on_delete_obj,
.obj_deleted_cb = on_obj_deleted,
.event_cb = on_event,
.instance_size = sizeof(streaming_controller_t),
};
Expand Down Expand Up @@ -75,7 +78,8 @@ bool streaming_refresh_stats() {
}
lv_label_set_text_fmt(controller->stats_items.decoder, "%s (%s)",
SS4S_ModuleInfoGetId(app->ss4s.selection.video_module), vdec_stream_info.format);
lv_label_set_text_static(controller->stats_items.audio, SS4S_ModuleInfoGetId(app->ss4s.selection.audio_module));
lv_label_set_text_fmt(controller->stats_items.audio, "%s (%s)",
SS4S_ModuleInfoGetId(app->ss4s.selection.audio_module), audio_stream_info.format);
lv_label_set_text_fmt(controller->stats_items.rtt, "%d ms (var. %d ms)", dst->rtt, dst->rttVariance);
lv_label_set_text_fmt(controller->stats_items.net_fps, "%.2f FPS", dst->receivedFps);

Expand Down Expand Up @@ -232,6 +236,12 @@ static void on_delete_obj(lv_fragment_t *self, lv_obj_t *view) {
lv_group_del(controller->group);
}

static void on_obj_deleted(lv_fragment_t *self, lv_obj_t *view) {
LV_UNUSED(view);
streaming_controller_t *controller = (streaming_controller_t *) self;
lv_obj_del(controller->detached_root);
}

static void exit_streaming(lv_event_t *event) {
streaming_controller_t *self = lv_event_get_user_data(event);
session_interrupt(self->global->session, true, STREAMING_INTERRUPT_USER);
Expand Down
3 changes: 2 additions & 1 deletion src/app/ui/streaming/streaming.controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ typedef struct app_t app_t;
typedef struct {
lv_fragment_t base;
app_t *global;
lv_obj_t *detached_root;
lv_obj_t *hint;
lv_obj_t *overlay;
lv_group_t *group;
lv_obj_t *hint;
lv_obj_t *progress;
lv_obj_t *video;
lv_obj_t *actions;
Expand Down
2 changes: 2 additions & 0 deletions src/app/ui/streaming/streaming.view.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lv_obj_t *streaming_scene_create(lv_fragment_t *self, lv_obj_t *parent) {
lv_obj_remove_style_all(obj);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100));
controller->detached_root = obj;

lv_obj_t *hint = lv_label_create(obj);
lv_obj_set_style_pad_all(hint, LV_DPX(20), 0);
Expand Down Expand Up @@ -143,6 +144,7 @@ lv_obj_t *streaming_scene_create(lv_fragment_t *self, lv_obj_t *parent) {

streaming_overlay_resized(controller);

// We return overlay instead of obj, and will delete the obj manually
return overlay;
}

Expand Down