From 17e05c6fd59b4d8777788aea5907ac3fbd8f89f0 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 13 Jan 2020 19:30:49 +1100 Subject: [PATCH] [all] expose the FrameBuffer struct for correct sizeof calculations --- VERSION | 2 +- c-host/include/interface/capture.h | 4 ++-- .../platform/Windows/capture/DXGI/src/dxgi.c | 2 +- .../platform/Windows/capture/NVFBC/src/nvfbc.c | 2 +- c-host/src/app.c | 2 +- client/include/interface/renderer.h | 2 +- client/renderers/EGL/desktop.c | 4 ++-- client/renderers/EGL/desktop.h | 2 +- client/renderers/EGL/egl.c | 2 +- client/renderers/EGL/texture.c | 2 +- client/renderers/EGL/texture.h | 2 +- client/renderers/OpenGL/opengl.c | 18 +++++++++--------- client/src/main.c | 2 +- common/include/common/framebuffer.h | 17 ++++++++++++----- common/src/framebuffer.c | 14 ++++---------- obs/lg.c | 2 +- 16 files changed, 40 insertions(+), 39 deletions(-) diff --git a/VERSION b/VERSION index 2fde6818..9cf9a2b8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B1-94-g17df1ebc6b+1 \ No newline at end of file +B1-95-g9846762991+1 \ No newline at end of file diff --git a/c-host/include/interface/capture.h b/c-host/include/interface/capture.h index 9be8a712..330b2870 100644 --- a/c-host/include/interface/capture.h +++ b/c-host/include/interface/capture.h @@ -91,7 +91,7 @@ typedef struct CaptureInterface unsigned int (*getMaxFrameSize)(); CaptureResult (*capture )(); - CaptureResult (*waitFrame )(CaptureFrame * frame); - CaptureResult (*getFrame )(FrameBuffer frame); + CaptureResult (*waitFrame )(CaptureFrame * frame); + CaptureResult (*getFrame )(FrameBuffer * frame); } CaptureInterface; \ No newline at end of file diff --git a/c-host/platform/Windows/capture/DXGI/src/dxgi.c b/c-host/platform/Windows/capture/DXGI/src/dxgi.c index 08c055fe..6301b2be 100644 --- a/c-host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/c-host/platform/Windows/capture/DXGI/src/dxgi.c @@ -805,7 +805,7 @@ static CaptureResult dxgi_waitFrame(CaptureFrame * frame) return CAPTURE_RESULT_OK; } -static CaptureResult dxgi_getFrame(FrameBuffer frame) +static CaptureResult dxgi_getFrame(FrameBuffer * frame) { assert(this); assert(this->initialized); diff --git a/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c b/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c index b88755b9..7cb09938 100644 --- a/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -294,7 +294,7 @@ static CaptureResult nvfbc_waitFrame(CaptureFrame * frame) return CAPTURE_RESULT_OK; } -static CaptureResult nvfbc_getFrame(FrameBuffer frame) +static CaptureResult nvfbc_getFrame(FrameBuffer * frame) { framebuffer_write( frame, diff --git a/c-host/src/app.c b/c-host/src/app.c index 2147792f..5f4275cc 100644 --- a/c-host/src/app.c +++ b/c-host/src/app.c @@ -188,7 +188,7 @@ static int frameThread(void * opaque) // put the framebuffer on the border of the next page // this is to allow for aligned DMA transfers by the receiver - FrameBuffer fb = (FrameBuffer)(((uint8_t*)fi) + fi->offset); + FrameBuffer * fb = (FrameBuffer *)(((uint8_t*)fi) + fi->offset); framebuffer_prepare(fb); /* we post and then get the frame, this is intentional! */ diff --git a/client/include/interface/renderer.h b/client/include/interface/renderer.h index f5e80e4c..ca50cb07 100644 --- a/client/include/interface/renderer.h +++ b/client/include/interface/renderer.h @@ -90,7 +90,7 @@ typedef void (* LG_RendererDeInitialize)(void * opaque); typedef void (* LG_RendererOnResize )(void * opaque, const int width, const int height, const LG_RendererRect destRect); typedef bool (* LG_RendererOnMouseShape)(void * opaque, const LG_RendererCursor cursor, const int width, const int height, const int pitch, const uint8_t * data); typedef bool (* LG_RendererOnMouseEvent)(void * opaque, const bool visible , const int x, const int y); -typedef bool (* LG_RendererOnFrameEvent)(void * opaque, const LG_RendererFormat format, const FrameBuffer frame); +typedef bool (* LG_RendererOnFrameEvent)(void * opaque, const LG_RendererFormat format, const FrameBuffer * frame); typedef void (* LG_RendererOnAlert )(void * opaque, const LG_MsgAlert alert, const char * message, bool ** closeFlag); typedef bool (* LG_RendererRender )(void * opaque, SDL_Window *window); typedef void (* LG_RendererUpdateFPS )(void * opaque, const float avgUPS, const float avgFPS); diff --git a/client/renderers/EGL/desktop.c b/client/renderers/EGL/desktop.c index 8821705b..b741df65 100644 --- a/client/renderers/EGL/desktop.c +++ b/client/renderers/EGL/desktop.c @@ -60,7 +60,7 @@ struct EGL_Desktop enum EGL_PixelFormat pixFmt; unsigned int width, height; unsigned int pitch; - FrameBuffer frame; + const FrameBuffer * frame; bool update; // night vision @@ -181,7 +181,7 @@ void egl_desktop_free(EGL_Desktop ** desktop) *desktop = NULL; } -bool egl_desktop_prepare_update(EGL_Desktop * desktop, const bool sourceChanged, const LG_RendererFormat format, const FrameBuffer frame) +bool egl_desktop_prepare_update(EGL_Desktop * desktop, const bool sourceChanged, const LG_RendererFormat format, const FrameBuffer * frame) { if (sourceChanged) { diff --git a/client/renderers/EGL/desktop.h b/client/renderers/EGL/desktop.h index 09de74ef..a1b6a0f5 100644 --- a/client/renderers/EGL/desktop.h +++ b/client/renderers/EGL/desktop.h @@ -28,6 +28,6 @@ typedef struct EGL_Desktop EGL_Desktop; bool egl_desktop_init(EGL_Desktop ** desktop); void egl_desktop_free(EGL_Desktop ** desktop); -bool egl_desktop_prepare_update(EGL_Desktop * desktop, const bool sourceChanged, const LG_RendererFormat format, const FrameBuffer frame); +bool egl_desktop_prepare_update(EGL_Desktop * desktop, const bool sourceChanged, const LG_RendererFormat format, const FrameBuffer * frame); void egl_desktop_perform_update(EGL_Desktop * desktop, const bool sourceChanged); bool egl_desktop_render(EGL_Desktop * desktop, const float x, const float y, const float scaleX, const float scaleY, const bool nearest); \ No newline at end of file diff --git a/client/renderers/EGL/egl.c b/client/renderers/EGL/egl.c index 28d1260f..607073e3 100644 --- a/client/renderers/EGL/egl.c +++ b/client/renderers/EGL/egl.c @@ -295,7 +295,7 @@ bool egl_on_mouse_event(void * opaque, const bool visible, const int x, const in return true; } -bool egl_on_frame_event(void * opaque, const LG_RendererFormat format, const FrameBuffer frame) +bool egl_on_frame_event(void * opaque, const LG_RendererFormat format, const FrameBuffer * frame) { struct Inst * this = (struct Inst *)opaque; this->sourceChanged = ( diff --git a/client/renderers/EGL/texture.c b/client/renderers/EGL/texture.c index 98897631..4f04af5f 100644 --- a/client/renderers/EGL/texture.c +++ b/client/renderers/EGL/texture.c @@ -279,7 +279,7 @@ bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer) return true; } -bool egl_texture_update_from_frame(EGL_Texture * texture, const FrameBuffer frame) +bool egl_texture_update_from_frame(EGL_Texture * texture, const FrameBuffer * frame) { if (!texture->streaming) return false; diff --git a/client/renderers/EGL/texture.h b/client/renderers/EGL/texture.h index b8ee49e0..eb6e9ec2 100644 --- a/client/renderers/EGL/texture.h +++ b/client/renderers/EGL/texture.h @@ -47,7 +47,7 @@ void egl_texture_free(EGL_Texture ** tex); bool egl_texture_setup (EGL_Texture * texture, enum EGL_PixelFormat pixfmt, size_t width, size_t height, size_t stride, bool streaming); bool egl_texture_update (EGL_Texture * texture, const uint8_t * buffer); -bool egl_texture_update_from_frame(EGL_Texture * texture, const FrameBuffer frame); +bool egl_texture_update_from_frame(EGL_Texture * texture, const FrameBuffer * frame); enum EGL_TexStatus egl_texture_process(EGL_Texture * texture); enum EGL_TexStatus egl_texture_bind (EGL_Texture * texture); int egl_texture_count (EGL_Texture * texture); \ No newline at end of file diff --git a/client/renderers/OpenGL/opengl.c b/client/renderers/OpenGL/opengl.c index fb40971c..0ca439c4 100644 --- a/client/renderers/OpenGL/opengl.c +++ b/client/renderers/OpenGL/opengl.c @@ -116,14 +116,14 @@ struct Inst const LG_Font * font; LG_FontObj fontObj, alertFontObj; - LG_Lock formatLock; - LG_RendererFormat format; - GLuint intFormat; - GLuint vboFormat; - GLuint dataFormat; - size_t texSize; - size_t texPos; - FrameBuffer frame; + LG_Lock formatLock; + LG_RendererFormat format; + GLuint intFormat; + GLuint vboFormat; + GLuint dataFormat; + size_t texSize; + size_t texPos; + const FrameBuffer * frame; uint64_t drawStart; bool hasBuffers; @@ -368,7 +368,7 @@ bool opengl_on_mouse_event(void * opaque, const bool visible, const int x, const return false; } -bool opengl_on_frame_event(void * opaque, const LG_RendererFormat format, const FrameBuffer frame) +bool opengl_on_frame_event(void * opaque, const LG_RendererFormat format, const FrameBuffer * frame) { struct Inst * this = (struct Inst *)opaque; if (!this) diff --git a/client/src/main.c b/client/src/main.c index e3afe4c3..d43fa606 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -440,7 +440,7 @@ static int frameThread(void * unused) updatePositionInfo(); } - FrameBuffer fb = (FrameBuffer)(((uint8_t*)frame) + frame->offset); + FrameBuffer * fb = (FrameBuffer *)(((uint8_t*)frame) + frame->offset); if (!state.lgr->on_frame_event(state.lgrData, lgrFormat, fb)) { DEBUG_ERROR("renderer on frame event returned failure"); diff --git a/common/include/common/framebuffer.h b/common/include/common/framebuffer.h index 9dcf15f6..c8614fae 100644 --- a/common/include/common/framebuffer.h +++ b/common/include/common/framebuffer.h @@ -23,26 +23,33 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include -typedef struct stFrameBuffer * FrameBuffer; + +typedef struct stFrameBuffer +{ + uint64_t wp; + uint8_t data[0]; +} +FrameBuffer; + typedef bool (*FrameBufferReadFn)(void * opaque, const void * src, size_t size); /** * Read data from the KVMFRFrame into the dst buffer */ -bool framebuffer_read(const FrameBuffer frame, void * dst, size_t size); +bool framebuffer_read(const FrameBuffer * frame, void * dst, size_t size); /** * Read data from the KVMFRFrame using a callback */ -bool framebuffer_read_fn(const FrameBuffer frame, FrameBufferReadFn fn, size_t size, void * opaque); +bool framebuffer_read_fn(const FrameBuffer * frame, FrameBufferReadFn fn, size_t size, void * opaque); /** * Prepare the framebuffer for writing */ -void framebuffer_prepare(const FrameBuffer frame); +void framebuffer_prepare(FrameBuffer * frame); /** * Write data from the src buffer into the KVMFRFrame */ -bool framebuffer_write(const FrameBuffer frame, const void * src, size_t size); \ No newline at end of file +bool framebuffer_write(FrameBuffer * frame, const void * src, size_t size); \ No newline at end of file diff --git a/common/src/framebuffer.c b/common/src/framebuffer.c index d25f6930..4e2f7e06 100644 --- a/common/src/framebuffer.c +++ b/common/src/framebuffer.c @@ -23,13 +23,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #define FB_CHUNK_SIZE 1024 -struct stFrameBuffer -{ - uint64_t wp; - uint8_t data[0]; -}; - -bool framebuffer_read(const FrameBuffer frame, void * dst, size_t size) +bool framebuffer_read(const FrameBuffer * frame, void * dst, size_t size) { uint8_t *d = (uint8_t*)dst; uint64_t rp = 0; @@ -51,7 +45,7 @@ bool framebuffer_read(const FrameBuffer frame, void * dst, size_t size) return true; } -bool framebuffer_read_fn(const FrameBuffer frame, FrameBufferReadFn fn, size_t size, void * opaque) +bool framebuffer_read_fn(const FrameBuffer * frame, FrameBufferReadFn fn, size_t size, void * opaque) { uint64_t rp = 0; while(rp < size) @@ -76,12 +70,12 @@ bool framebuffer_read_fn(const FrameBuffer frame, FrameBufferReadFn fn, size_t s /** * Prepare the framebuffer for writing */ -void framebuffer_prepare(const FrameBuffer frame) +void framebuffer_prepare(FrameBuffer * frame) { frame->wp = 0; } -bool framebuffer_write(FrameBuffer frame, const void * src, size_t size) +bool framebuffer_write(FrameBuffer * frame, const void * src, size_t size) { /* copy in chunks */ while(size) diff --git a/obs/lg.c b/obs/lg.c index edd87068..38099e64 100644 --- a/obs/lg.c +++ b/obs/lg.c @@ -164,7 +164,7 @@ static void lgVideoTick(void * data, float seconds) } } - FrameBuffer fb = (FrameBuffer)(((uint8_t*)frame) + frame->offset); + FrameBuffer * fb = (FrameBuffer *)(((uint8_t*)frame) + frame->offset); uint8_t *texData; uint32_t linesize;