gs_ffmpeg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README

commit 22f1abf7d39f112579a6c44acbef06a2870acdd9
parent 35c8ec02fa548b6ec4c4b37ffc7a5e00cbfd26c5
Author: Samdal <samdal@protonmail.com>
Date:   Sun,  8 Jan 2023 23:28:40 +0100

move thread_t into struct

Diffstat:
Msource/gs_avdecode.h | 11++++++-----
Msource/main.c | 5++---
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/source/gs_avdecode.h b/source/gs_avdecode.h @@ -70,6 +70,7 @@ extern void gs_avdecode_destroy(gs_avdecode_ctx_t* ctx, gs_asset_texture_t* tex) // // when the decoder thread exits it sets done to 1 typedef struct gs_avdecode_pthread_s { + pthread_t thread; pthread_attr_t attr; gs_avdecode_ctx_t video; @@ -78,9 +79,9 @@ typedef struct gs_avdecode_pthread_s { _Atomic int loop; // TODO... _Atomic int done; } gs_avdecode_pthread_t; -extern int gs_avdecode_pthread_play_video(gs_avdecode_pthread_t* ctxp, pthread_t* thread, const char* path, +extern int gs_avdecode_pthread_play_video(gs_avdecode_pthread_t* ctxp, const char* path, const gs_graphics_texture_desc_t* desc, gs_asset_texture_t* out); -extern void gs_avdecode_pthread_destroy(gs_avdecode_pthread_t* ctxp, pthread_t* thread, gs_asset_texture_t* tex); +extern void gs_avdecode_pthread_destroy(gs_avdecode_pthread_t* ctxp, gs_asset_texture_t* tex); #define gs_avdecode_aquire_m(_ctxp, ...) \ do { \ @@ -424,7 +425,7 @@ _gs_avdecode_pthread_player(void* data) } int -gs_avdecode_pthread_play_video(gs_avdecode_pthread_t* ctxp, pthread_t* thread, const char* path, +gs_avdecode_pthread_play_video(gs_avdecode_pthread_t* ctxp, const char* path, const gs_graphics_texture_desc_t* desc, gs_asset_texture_t* out) { if (!ctxp) return 2; @@ -435,14 +436,14 @@ gs_avdecode_pthread_play_video(gs_avdecode_pthread_t* ctxp, pthread_t* thread, c int res = gs_avdecode_init(path, &ctxp->video, desc, out); if (res) return res; - pthread_create(thread, &ctxp->attr, &_gs_avdecode_pthread_player, ctxp); + pthread_create(&ctxp->thread, &ctxp->attr, &_gs_avdecode_pthread_player, ctxp); // TODO: error code from pthread functions as well return res; } void -gs_avdecode_pthread_destroy(gs_avdecode_pthread_t* ctxp, pthread_t* thread, gs_asset_texture_t* tex) +gs_avdecode_pthread_destroy(gs_avdecode_pthread_t* ctxp, gs_asset_texture_t* tex) { pthread_attr_destroy(&ctxp->attr); diff --git a/source/main.c b/source/main.c @@ -12,7 +12,6 @@ static gs_asset_texture_t tex; static gs_asset_texture_t ptex; static gs_avdecode_ctx_t video; static gs_avdecode_pthread_t pvideo; -static pthread_t video_thread; void app_update() { @@ -45,7 +44,7 @@ void app_update() gsi_texture(&gsi, ptex.hndl); gsi_rectvd(&gsi, gs_v2(fb.x/2, fb.y/2), gs_v2(fb.x/2, fb.y/2), gs_v2s(0.f), gs_v2s(1.f), GS_COLOR_WHITE, GS_GRAPHICS_PRIMITIVE_TRIANGLES); } else if (pvideo.done > 0) { - gs_avdecode_pthread_destroy(&pvideo, &video_thread, &ptex); + gs_avdecode_pthread_destroy(&pvideo, &ptex); pvideo.done = -1; } @@ -60,7 +59,7 @@ void app_init() int res = gs_avdecode_init(filename, &video, NULL, &tex); - int res2 = gs_avdecode_pthread_play_video(&pvideo, &video_thread, filename, NULL, &ptex); + int res2 = gs_avdecode_pthread_play_video(&pvideo, filename, NULL, &ptex); if (res) { gs_println("Unable to initialize video '%s' (error code %d)", filename, res);