Skip to content

Commit

Permalink
ptz: Move backend-specific properties to each backend code
Browse files Browse the repository at this point in the history
  • Loading branch information
norihiro committed Jul 28, 2024
1 parent 8692319 commit 15182f6
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 28 deletions.
43 changes: 18 additions & 25 deletions src/face-tracker-ptz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct ptz_backend_type_s
{
const char *backend_name;
class ptz_backend *(*make_device)(obs_data_t *data);
bool (*ptz_type_modified)(obs_properties_t *group_output, obs_data_t *settings);
};

template <class backend_class>
Expand All @@ -97,25 +98,20 @@ static class ptz_backend *make_device_template(obs_data_t *data)

static const struct ptz_backend_type_s backends[] =
{
{
.backend_name = "obsptz",
.make_device = make_device_template<obsptz_backend>,
},
#define BACKEND(name, cls) \
{ \
.backend_name = name, \
.make_device = make_device_template<cls>, \
.ptz_type_modified = cls::ptz_type_modified, \
}
BACKEND("obsptz", obsptz_backend),
#ifdef WITH_PTZ_TCP
{
.backend_name = "visca-over-tcp",
.make_device = make_device_template<libvisca_thread>,
},
BACKEND("visca-over-tcp", libvisca_thread),
#endif // WITH_PTZ_TCP
{
.backend_name = "http",
.make_device = make_device_template<ptz_http_backend>,
},
{
.backend_name = "dummy",
.make_device = make_device_template<dummy_backend>,
},
{NULL, NULL}
BACKEND("http", ptz_http_backend),
BACKEND("dummy", dummy_backend),
{NULL, NULL, NULL}
#undef BACKEND
};

static const struct ptz_backend_type_s *get_backend(const char *ptz_type)
Expand Down Expand Up @@ -365,10 +361,11 @@ static bool ptz_type_modified(obs_properties_t *props, obs_property_t *, obs_dat
obs_property_set_visible(prop, sel);
}

if (strcmp(ptz_type, "http") == 0) {
obs_property_t *prop = obs_properties_get(props, "ptz.http.id");
if (obs_property_list_item_count(prop) == 0)
ptz_http_backend::init_ptz_http_id(props, prop, settings);
auto *b = get_backend(ptz_type);
if (b && b->ptz_type_modified) {
obs_properties_t *group = obs_property_group_content(obs_properties_get(props, "output"));

b->ptz_type_modified(group, settings);
}

return true;
Expand Down Expand Up @@ -460,10 +457,6 @@ static obs_properties_t *ftptz_properties(void *data)
#endif // WITH_PTZ_TCP
obs_property_list_add_string(p, obs_module_text("HTTP"), "http");
obs_property_set_modified_callback(p, ptz_type_modified);
obs_properties_add_int(pp, "ptz.obsptz.device_id", obs_module_text("Device ID"), 0, 99, 1);
obs_properties_add_text(pp, "ptz.visca-over-tcp.address", obs_module_text("IP address"), OBS_TEXT_DEFAULT);
obs_properties_add_int(pp, "ptz.visca-over-tcp.port", obs_module_text("Port"), 1, 65535, 1);
obs_properties_add_list(pp, "ptz.http.id", obs_module_text("Camera Model"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);

obs_properties_add_int_slider(pp, "ptz_max_x", "Max control (pan)", 0, PTZ_MAX_X, 1);
obs_properties_add_int_slider(pp, "ptz_max_y", "Max control (tilt)", 0, PTZ_MAX_Y, 1);
Expand Down
11 changes: 11 additions & 0 deletions src/libvisca-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,14 @@ float libvisca_thread::raw2zoomfactor(int zoom)
// TODO: configurable
return expf((float)zoom * (logf(20.0f) / 16384.f));
}

bool libvisca_thread::ptz_type_modified(obs_properties_t *pp, obs_data_t *settings)
{
(void)settings;
if (obs_properties_get(pp, "ptz.visca-over-tcp.address"))
return false;

obs_properties_add_text(pp, "ptz.visca-over-tcp.address", obs_module_text("IP address"), OBS_TEXT_DEFAULT);
obs_properties_add_int(pp, "ptz.visca-over-tcp.port", obs_module_text("Port"), 1, 65535, 1);
return true;
}
1 change: 1 addition & 0 deletions src/libvisca-thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ class libvisca_thread : public ptz_backend
return false;
return true;
}
static bool ptz_type_modified(obs_properties_t *group_output, obs_data_t *settings);
};
9 changes: 9 additions & 0 deletions src/obsptz-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,12 @@ float obsptz_backend::get_zoom()
// TODO: implement
return 1.0f;
}

bool obsptz_backend::ptz_type_modified(obs_properties_t *pp, obs_data_t *)
{
if (obs_properties_get(pp, "ptz.obsptz.device_id"))
return false;

obs_properties_add_int(pp, "ptz.obsptz.device_id", obs_module_text("Device ID"), 0, 99, 1);
return true;
}
2 changes: 2 additions & 0 deletions src/obsptz-backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ class obsptz_backend : public ptz_backend
void set_zoom_speed(int zoom) override;
void recall_preset(int preset) override;
float get_zoom() override;

static bool ptz_type_modified(obs_properties_t *group_output, obs_data_t *settings);
};
6 changes: 6 additions & 0 deletions src/ptz-backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ class ptz_backend
virtual void set_pantiltzoom_speed(float pan, float tilt, float zoom) { (void)pan; (void)tilt; (void)zoom; }

inline static bool check_data(obs_data_t *) { return true; }
inline static bool ptz_type_modified(obs_properties_t *group_output, obs_data_t *settings)
{
(void)group_output;
(void)settings;
return false;
}
};
16 changes: 14 additions & 2 deletions src/ptz-http-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static bool id_modified(obs_properties_t *props, obs_property_t *, obs_data_t *s
return true;
}

void ptz_http_backend::init_ptz_http_id(obs_properties_t *props, obs_property_t *prop, obs_data_t *settings)
static void init_ptz_http_id(obs_properties_t *group_output, obs_property_t *prop, obs_data_t *settings)
{
obs_property_set_modified_callback(prop, id_modified);

Expand All @@ -172,5 +172,17 @@ void ptz_http_backend::init_ptz_http_id(obs_properties_t *props, obs_property_t
}

if (obs_data_has_user_value(settings, "ptz.http.id"))
id_modified(props, prop, settings);
id_modified(obs_properties_get_parent(group_output), prop, settings);
}

bool ptz_http_backend::ptz_type_modified(obs_properties_t *group_output, obs_data_t *settings)
{
if (obs_properties_get(group_output, "ptz.visca-over-tcp.address"))
return false;

obs_property_t *prop = obs_properties_add_list(group_output, "ptz.http.id", obs_module_text("Camera Model"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
init_ptz_http_id(group_output, prop, settings);

return true;
}
2 changes: 1 addition & 1 deletion src/ptz-http-backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ class ptz_http_backend : public ptz_backend
}

public:
static void init_ptz_http_id(obs_properties_t *props, obs_property_t *prop, obs_data_t *settings);
static bool ptz_type_modified(obs_properties_t *group_output, obs_data_t *settings);
};

0 comments on commit 15182f6

Please sign in to comment.