Skip to content

Commit

Permalink
Use stack for call-data
Browse files Browse the repository at this point in the history
  • Loading branch information
norihiro committed Aug 7, 2022
1 parent 3a120b3 commit 303c0e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
23 changes: 8 additions & 15 deletions src/face-tracker-monitor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <obs-module.h>
#include <obs.hpp>
#include "plugin-macros.generated.h"
#include "helper.hpp"


#define MAX_ERROR 2
Expand Down Expand Up @@ -205,15 +206,12 @@ static uint32_t ftmon_get_width(void *data)
if (!ph)
return 0;

calldata_t cd = {0};
CALLDATA_FIXED_DECL(cd, 128);
if (proc_handler_call(ph, "get_target_size", &cd)) {
long long ret;
if (calldata_get_int(&cd, "width", &ret)) {
calldata_free(&cd);
return (int32_t)ret;
}
if (calldata_get_int(&cd, "width", &ret))
return (uint32_t)ret;
}
calldata_free(&cd);
}

OBSSource source(get_source(s));
Expand All @@ -235,15 +233,12 @@ static uint32_t ftmon_get_height(void *data)
if (!ph)
return 0;

calldata_t cd = {0};
CALLDATA_FIXED_DECL(cd, 128);
if (proc_handler_call(ph, "get_target_size", &cd)) {
long long ret;
if (calldata_get_int(&cd, "height", &ret)) {
calldata_free(&cd);
return (int32_t)ret;
}
if (calldata_get_int(&cd, "height", &ret))
return (uint32_t)ret;
}
calldata_free(&cd);
}

OBSSource source(get_source(s));
Expand All @@ -266,7 +261,7 @@ static void ftmon_video_render(void *data, gs_effect_t *)
if (!ph)
return;

calldata_t cd = {0};
CALLDATA_FIXED_DECL(cd, 128);
calldata_set_bool(&cd, "notrack", s->notrack);

if (!s->nosource) {
Expand All @@ -281,8 +276,6 @@ static void ftmon_video_render(void *data, gs_effect_t *)
calldata_set_bool(&cd, "landmark_only", true);

proc_handler_call(ph, "render_info", &cd);

calldata_free(&cd);
}

extern "C"
Expand Down
2 changes: 2 additions & 0 deletions src/helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define DEBUG_DATA_PATH_FILTER "Data Files (*.dat);;TSV Files (*.tsv);;All Files (*.*)"
#endif

#define CALLDATA_FIXED_DECL(cd, size) calldata_t cd; uint8_t calldata_##cd##_stack[128]; calldata_init_fixed(&cd, calldata_##cd##_stack, sizeof(calldata_##cd##_stack));

struct pointf_s
{
float x;
Expand Down
10 changes: 4 additions & 6 deletions src/obsptz-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <algorithm>
#include "plugin-macros.generated.h"
#include "obsptz-backend.hpp"
#include "helper.hpp"

#define debug(...) blog(LOG_INFO, __VA_ARGS__)

Expand Down Expand Up @@ -43,10 +44,9 @@ proc_handler_t *obsptz_backend::get_ptz_ph()
if (!ph)
return NULL;

calldata_t cd = {0};
CALLDATA_FIXED_DECL(cd, 128);
proc_handler_call(ph, "ptz_get_proc_handler", &cd);
calldata_get_ptr(&cd, "return", &ptz_ph);
calldata_free(&cd);

return ptz_ph;
}
Expand All @@ -62,7 +62,7 @@ void obsptz_backend::set_pantilt_speed(int pan, int tilt)
same_pantilt_cnt = 0;
}

calldata_t cd = {0};
CALLDATA_FIXED_DECL(cd, 128);
calldata_set_int(&cd, "device_id", device_id);
calldata_set_float(&cd, "pan", pan / 24.0f);
calldata_set_float(&cd, "tilt", -tilt / 20.0f);
Expand All @@ -74,7 +74,6 @@ void obsptz_backend::set_pantilt_speed(int pan, int tilt)
ph = obs_get_proc_handler();
proc_handler_call(ph, "ptz_pantilt", &cd);
}
calldata_free(&cd);
uint64_t ns = os_gettime_ns();
available_ns = std::max(available_ns, ns) + (60*1000*1000);
prev_pan = pan;
Expand All @@ -96,12 +95,11 @@ void obsptz_backend::set_zoom_speed(int zoom)
if (!ph)
return;

calldata_t cd = {0};
CALLDATA_FIXED_DECL(cd, 128);
calldata_set_int(&cd, "device_id", device_id);
calldata_set_float(&cd, "zoom", -zoom / 7.0f);
proc_handler_call(ph, "ptz_move_continuous", &cd);

calldata_free(&cd);
uint64_t ns = os_gettime_ns();
available_ns = std::max(available_ns, ns) + (60*1000*1000);
prev_zoom = zoom;
Expand Down

0 comments on commit 303c0e3

Please sign in to comment.