From 15182f6d531b61d2d2961ceb19511fea50b86fb5 Mon Sep 17 00:00:00 2001 From: Norihiro Kamae Date: Sun, 28 Jul 2024 21:45:18 +0900 Subject: [PATCH] ptz: Move backend-specific properties to each backend code --- src/face-tracker-ptz.cpp | 43 +++++++++++++++++----------------------- src/libvisca-thread.cpp | 11 ++++++++++ src/libvisca-thread.hpp | 1 + src/obsptz-backend.cpp | 9 +++++++++ src/obsptz-backend.hpp | 2 ++ src/ptz-backend.hpp | 6 ++++++ src/ptz-http-backend.cpp | 16 +++++++++++++-- src/ptz-http-backend.hpp | 2 +- 8 files changed, 62 insertions(+), 28 deletions(-) diff --git a/src/face-tracker-ptz.cpp b/src/face-tracker-ptz.cpp index 4938eca..415141b 100644 --- a/src/face-tracker-ptz.cpp +++ b/src/face-tracker-ptz.cpp @@ -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 @@ -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, - }, +#define BACKEND(name, cls) \ + { \ + .backend_name = name, \ + .make_device = make_device_template, \ + .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, - }, + BACKEND("visca-over-tcp", libvisca_thread), #endif // WITH_PTZ_TCP - { - .backend_name = "http", - .make_device = make_device_template, - }, - { - .backend_name = "dummy", - .make_device = make_device_template, - }, - {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) @@ -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; @@ -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); diff --git a/src/libvisca-thread.cpp b/src/libvisca-thread.cpp index a58b782..af1a0b3 100644 --- a/src/libvisca-thread.cpp +++ b/src/libvisca-thread.cpp @@ -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; +} diff --git a/src/libvisca-thread.hpp b/src/libvisca-thread.hpp index 66b90ed..d7aced9 100644 --- a/src/libvisca-thread.hpp +++ b/src/libvisca-thread.hpp @@ -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); }; diff --git a/src/obsptz-backend.cpp b/src/obsptz-backend.cpp index dcda9d0..3c0cd90 100644 --- a/src/obsptz-backend.cpp +++ b/src/obsptz-backend.cpp @@ -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; +} diff --git a/src/obsptz-backend.hpp b/src/obsptz-backend.hpp index 5c9c827..811cc32 100644 --- a/src/obsptz-backend.hpp +++ b/src/obsptz-backend.hpp @@ -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); }; diff --git a/src/ptz-backend.hpp b/src/ptz-backend.hpp index d5a648c..49a2181 100644 --- a/src/ptz-backend.hpp +++ b/src/ptz-backend.hpp @@ -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; + } }; diff --git a/src/ptz-http-backend.cpp b/src/ptz-http-backend.cpp index c84cb40..b9fff62 100644 --- a/src/ptz-http-backend.cpp +++ b/src/ptz-http-backend.cpp @@ -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); @@ -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; } diff --git a/src/ptz-http-backend.hpp b/src/ptz-http-backend.hpp index da983e5..5c07a7b 100644 --- a/src/ptz-http-backend.hpp +++ b/src/ptz-http-backend.hpp @@ -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); };