Skip to content

Commit

Permalink
[all] expose the FrameBuffer struct for correct sizeof calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Jan 13, 2020
1 parent 9846762 commit 17e05c6
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Original file line Diff line number Diff line change
@@ -1 +1 @@
B1-94-g17df1ebc6b+1 B1-95-g9846762991+1
4 changes: 2 additions & 2 deletions c-host/include/interface/capture.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ typedef struct CaptureInterface
unsigned int (*getMaxFrameSize)(); unsigned int (*getMaxFrameSize)();


CaptureResult (*capture )(); CaptureResult (*capture )();
CaptureResult (*waitFrame )(CaptureFrame * frame); CaptureResult (*waitFrame )(CaptureFrame * frame);
CaptureResult (*getFrame )(FrameBuffer frame); CaptureResult (*getFrame )(FrameBuffer * frame);
} }
CaptureInterface; CaptureInterface;
2 changes: 1 addition & 1 deletion c-host/platform/Windows/capture/DXGI/src/dxgi.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ static CaptureResult dxgi_waitFrame(CaptureFrame * frame)
return CAPTURE_RESULT_OK; return CAPTURE_RESULT_OK;
} }


static CaptureResult dxgi_getFrame(FrameBuffer frame) static CaptureResult dxgi_getFrame(FrameBuffer * frame)
{ {
assert(this); assert(this);
assert(this->initialized); assert(this->initialized);
Expand Down
2 changes: 1 addition & 1 deletion c-host/platform/Windows/capture/NVFBC/src/nvfbc.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static CaptureResult nvfbc_waitFrame(CaptureFrame * frame)
return CAPTURE_RESULT_OK; return CAPTURE_RESULT_OK;
} }


static CaptureResult nvfbc_getFrame(FrameBuffer frame) static CaptureResult nvfbc_getFrame(FrameBuffer * frame)
{ {
framebuffer_write( framebuffer_write(
frame, frame,
Expand Down
2 changes: 1 addition & 1 deletion c-host/src/app.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static int frameThread(void * opaque)


// put the framebuffer on the border of the next page // put the framebuffer on the border of the next page
// this is to allow for aligned DMA transfers by the receiver // 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); framebuffer_prepare(fb);


/* we post and then get the frame, this is intentional! */ /* we post and then get the frame, this is intentional! */
Expand Down
2 changes: 1 addition & 1 deletion client/include/interface/renderer.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 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_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_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 void (* LG_RendererOnAlert )(void * opaque, const LG_MsgAlert alert, const char * message, bool ** closeFlag);
typedef bool (* LG_RendererRender )(void * opaque, SDL_Window *window); typedef bool (* LG_RendererRender )(void * opaque, SDL_Window *window);
typedef void (* LG_RendererUpdateFPS )(void * opaque, const float avgUPS, const float avgFPS); typedef void (* LG_RendererUpdateFPS )(void * opaque, const float avgUPS, const float avgFPS);
Expand Down
4 changes: 2 additions & 2 deletions client/renderers/EGL/desktop.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct EGL_Desktop
enum EGL_PixelFormat pixFmt; enum EGL_PixelFormat pixFmt;
unsigned int width, height; unsigned int width, height;
unsigned int pitch; unsigned int pitch;
FrameBuffer frame; const FrameBuffer * frame;
bool update; bool update;


// night vision // night vision
Expand Down Expand Up @@ -181,7 +181,7 @@ void egl_desktop_free(EGL_Desktop ** desktop)
*desktop = NULL; *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) if (sourceChanged)
{ {
Expand Down
2 changes: 1 addition & 1 deletion client/renderers/EGL/desktop.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ typedef struct EGL_Desktop EGL_Desktop;
bool egl_desktop_init(EGL_Desktop ** desktop); bool egl_desktop_init(EGL_Desktop ** desktop);
void egl_desktop_free(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); 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); bool egl_desktop_render(EGL_Desktop * desktop, const float x, const float y, const float scaleX, const float scaleY, const bool nearest);
2 changes: 1 addition & 1 deletion client/renderers/EGL/egl.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ bool egl_on_mouse_event(void * opaque, const bool visible, const int x, const in
return true; 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; struct Inst * this = (struct Inst *)opaque;
this->sourceChanged = ( this->sourceChanged = (
Expand Down
2 changes: 1 addition & 1 deletion client/renderers/EGL/texture.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer)
return true; 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) if (!texture->streaming)
return false; return false;
Expand Down
2 changes: 1 addition & 1 deletion client/renderers/EGL/texture.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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_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 (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_process(EGL_Texture * texture);
enum EGL_TexStatus egl_texture_bind (EGL_Texture * texture); enum EGL_TexStatus egl_texture_bind (EGL_Texture * texture);
int egl_texture_count (EGL_Texture * texture); int egl_texture_count (EGL_Texture * texture);
18 changes: 9 additions & 9 deletions client/renderers/OpenGL/opengl.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ struct Inst
const LG_Font * font; const LG_Font * font;
LG_FontObj fontObj, alertFontObj; LG_FontObj fontObj, alertFontObj;


LG_Lock formatLock; LG_Lock formatLock;
LG_RendererFormat format; LG_RendererFormat format;
GLuint intFormat; GLuint intFormat;
GLuint vboFormat; GLuint vboFormat;
GLuint dataFormat; GLuint dataFormat;
size_t texSize; size_t texSize;
size_t texPos; size_t texPos;
FrameBuffer frame; const FrameBuffer * frame;


uint64_t drawStart; uint64_t drawStart;
bool hasBuffers; bool hasBuffers;
Expand Down Expand Up @@ -368,7 +368,7 @@ bool opengl_on_mouse_event(void * opaque, const bool visible, const int x, const
return false; 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; struct Inst * this = (struct Inst *)opaque;
if (!this) if (!this)
Expand Down
2 changes: 1 addition & 1 deletion client/src/main.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ static int frameThread(void * unused)
updatePositionInfo(); 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)) if (!state.lgr->on_frame_event(state.lgrData, lgrFormat, fb))
{ {
DEBUG_ERROR("renderer on frame event returned failure"); DEBUG_ERROR("renderer on frame event returned failure");
Expand Down
17 changes: 12 additions & 5 deletions common/include/common/framebuffer.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,26 +23,33 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>


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); typedef bool (*FrameBufferReadFn)(void * opaque, const void * src, size_t size);


/** /**
* Read data from the KVMFRFrame into the dst buffer * 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 * 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 * 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 * Write data from the src buffer into the KVMFRFrame
*/ */
bool framebuffer_write(const FrameBuffer frame, const void * src, size_t size); bool framebuffer_write(FrameBuffer * frame, const void * src, size_t size);
14 changes: 4 additions & 10 deletions common/src/framebuffer.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <string.h> #include <string.h>
#define FB_CHUNK_SIZE 1024 #define FB_CHUNK_SIZE 1024


struct stFrameBuffer bool framebuffer_read(const FrameBuffer * frame, void * dst, size_t size)
{
uint64_t wp;
uint8_t data[0];
};

bool framebuffer_read(const FrameBuffer frame, void * dst, size_t size)
{ {
uint8_t *d = (uint8_t*)dst; uint8_t *d = (uint8_t*)dst;
uint64_t rp = 0; uint64_t rp = 0;
Expand All @@ -51,7 +45,7 @@ bool framebuffer_read(const FrameBuffer frame, void * dst, size_t size)
return true; 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; uint64_t rp = 0;
while(rp < size) while(rp < size)
Expand All @@ -76,12 +70,12 @@ bool framebuffer_read_fn(const FrameBuffer frame, FrameBufferReadFn fn, size_t s
/** /**
* Prepare the framebuffer for writing * Prepare the framebuffer for writing
*/ */
void framebuffer_prepare(const FrameBuffer frame) void framebuffer_prepare(FrameBuffer * frame)
{ {
frame->wp = 0; 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 */ /* copy in chunks */
while(size) while(size)
Expand Down
2 changes: 1 addition & 1 deletion obs/lg.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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; uint8_t *texData;
uint32_t linesize; uint32_t linesize;
Expand Down

0 comments on commit 17e05c6

Please sign in to comment.