diff options
author | andrew-elder <andrew_elder@pobox.com> | 2021-06-22 11:02:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-22 11:02:29 -0400 |
commit | 90065dc56717761008c357b57407ee591faad9e8 (patch) | |
tree | 301179b5769d300a2a5bbee17d58a2da78d3f358 | |
parent | b4b986082f06f5b9882e18710c8638246eb98cf5 (diff) | |
parent | 12d5c8317c398f7fc7fccf85f35b5673a99f77cb (diff) | |
download | Open-AVB-open-avb-next.tar.gz |
Merge pull request #915 from MarcinMiklas/configuration_options_can_be_changed_at_runtimeopen-avb-next
Configuration options can be changed at runtime
-rw-r--r-- | lib/avtp_pipeline/platform/Linux/avb_host/CMakeLists.txt | 2 | ||||
-rw-r--r-- | lib/avtp_pipeline/platform/Linux/avb_host/openavb_harness.c | 52 | ||||
-rwxr-xr-x | lib/avtp_pipeline/tl/openavb_tl.c | 59 | ||||
-rwxr-xr-x | lib/avtp_pipeline/tl/openavb_tl_pub.h | 13 |
4 files changed, 101 insertions, 25 deletions
diff --git a/lib/avtp_pipeline/platform/Linux/avb_host/CMakeLists.txt b/lib/avtp_pipeline/platform/Linux/avb_host/CMakeLists.txt index f11837c4..0ac3c845 100644 --- a/lib/avtp_pipeline/platform/Linux/avb_host/CMakeLists.txt +++ b/lib/avtp_pipeline/platform/Linux/avb_host/CMakeLists.txt @@ -29,7 +29,6 @@ target_link_libraries( openavb_host avbTl ${PLATFORM_LINK_LIBRARIES} ${ALSA_LIBRARIES} - ${GLIB_PKG_LIBRARIES} pthread rt dl ) @@ -58,7 +57,6 @@ target_link_libraries( openavb_harness avbTl ${PLATFORM_LINK_LIBRARIES} ${ALSA_LIBRARIES} - ${GLIB_PKG_LIBRARIES} pthread rt dl ) diff --git a/lib/avtp_pipeline/platform/Linux/avb_host/openavb_harness.c b/lib/avtp_pipeline/platform/Linux/avb_host/openavb_harness.c index 6802c447..98535ab4 100644 --- a/lib/avtp_pipeline/platform/Linux/avb_host/openavb_harness.c +++ b/lib/avtp_pipeline/platform/Linux/avb_host/openavb_harness.c @@ -150,6 +150,7 @@ void openavbTlHarnessMenu() " t Stop all streams\n" " l List streams\n" " 0-99 Toggle the state of the numbered stream\n" + " c N NAME VAL Change config option for stream N\n" " m Display this menu\n" " z Stats\n" " x Exit\n" @@ -157,6 +158,39 @@ void openavbTlHarnessMenu() ); } +// manually matches following regular expression: +// +// /(\d+)\s+([^\s]+)\s+(.*)\s*/ +// +// where: +// $1 - idx +// $2 - name +// $3 - value +int parse_idx_name_value(char* line, int* pIdx, char** pName, char** pValue) +{ + char *token = NULL; + + int tmp = strtol(line, &token, 10); + if (token == line) return 0; + *pIdx = tmp; + + while (isspace(*token)) ++token; + if (*token == '\0') return 1; + + *pName = token; + while (!isspace(*++token) && *token != '\0') ; + if (*token == '\0') return 2; + *token = '\0'; + + while (isspace(*++token)) ; + if (*token == '\0') return 2; + *pValue = token; + + token += strlen(token); + while (isspace(*--token) && *token != '\0') *token = '\0'; + + return 3; +} /********************************************** * main @@ -403,7 +437,7 @@ int main(int argc, char *argv[]) openavbTlHarnessMenu(); while (bRunning) { - char buf[16]; + char buf[512]; printf("> "); if (fgets(buf, sizeof(buf), stdin) == NULL) { openavbTlHarnessMenu(); @@ -449,10 +483,26 @@ int main(int argc, char *argv[]) } } break; + case 'c': + { + int i1 = -1; + char *name = NULL; + char *value = NULL; + + if (parse_idx_name_value(&buf[1], &i1, &name, &value) == 3 && i1 < tlCount) { + openavb_tl_cfg_name_value_t NVCfg = {{name}, {value}, 1}; + openavbTlChangeConfig(tlHandleList[i1], &NVCfg); + } else { + openavbTlHarnessMenu(); + } + + } + break; case 'm': // Display menu openavbTlHarnessMenu(); break; + case 'z': // Stats { diff --git a/lib/avtp_pipeline/tl/openavb_tl.c b/lib/avtp_pipeline/tl/openavb_tl.c index 4a4396ed..b01b4e9b 100755 --- a/lib/avtp_pipeline/tl/openavb_tl.c +++ b/lib/avtp_pipeline/tl/openavb_tl.c @@ -401,6 +401,42 @@ EXTERN_DLL_EXPORT void openavbTLInitCfg(openavb_tl_cfg_t *pCfg) AVB_TRACE_EXIT(AVB_TRACE_TL); } +void openavbTlChangeConfig(tl_handle_t handle, openavb_tl_cfg_name_value_t *pNVCfg) +{ + tl_state_t *pTLState = (tl_state_t *)handle; + + if (!pTLState) { + AVB_LOG_ERROR("Invalid handle."); + AVB_TRACE_EXIT(AVB_TRACE_TL); + return; + } + + openavb_tl_cfg_t *pCfg = &pTLState->cfg; + + int i; + for (i = 0; i < pNVCfg->nLibCfgItems; i++) { + if (MATCH_LEFT(pNVCfg->libCfgNames[i], "intf_nv_", 8)) { + if (pCfg->intf_cb.intf_cfg_cb) { + pCfg->intf_cb.intf_cfg_cb(pTLState->pMediaQ, pNVCfg->libCfgNames[i], pNVCfg->libCfgValues[i]); + } + else { + AVB_LOGF_ERROR("No interface module cfg function; ignoring %s", pNVCfg->libCfgNames[i]); + } + } + else if (MATCH_LEFT(pNVCfg->libCfgNames[i], "map_nv_", 7)) { + if (pCfg->map_cb.map_cfg_cb) { + pCfg->map_cb.map_cfg_cb(pTLState->pMediaQ, pNVCfg->libCfgNames[i], pNVCfg->libCfgValues[i]); + } + else { + AVB_LOGF_ERROR("No mapping module cfg function; ignoring %s", pNVCfg->libCfgNames[i]); + } + } + else { + AVB_LOG_ERROR("Only intf_nv_ and map_nv_ names are supported"); + } + } +} + EXTERN_DLL_EXPORT bool openavbTLConfigure(tl_handle_t handle, openavb_tl_cfg_t *pCfgIn, openavb_tl_cfg_name_value_t *pNVCfg) { AVB_TRACE_ENTRY(AVB_TRACE_TL); @@ -464,28 +500,7 @@ EXTERN_DLL_EXPORT bool openavbTLConfigure(tl_handle_t handle, openavb_tl_cfg_t * } // Submit configuration values to mapping and interface modules - int i; - for (i = 0; i < pNVCfg->nLibCfgItems; i++) { - if (MATCH_LEFT(pNVCfg->libCfgNames[i], "intf_nv_", 8)) { - if (pCfg->intf_cb.intf_cfg_cb) { - pCfg->intf_cb.intf_cfg_cb(pTLState->pMediaQ, pNVCfg->libCfgNames[i], pNVCfg->libCfgValues[i]); - } - else { - AVB_LOGF_ERROR("No interface module cfg function; ignoring %s", pNVCfg->libCfgNames[i]); - } - } - else if (MATCH_LEFT(pNVCfg->libCfgNames[i], "map_nv_", 7)) { - if (pCfg->map_cb.map_cfg_cb) { - pCfg->map_cb.map_cfg_cb(pTLState->pMediaQ, pNVCfg->libCfgNames[i], pNVCfg->libCfgValues[i]); - } - else { - AVB_LOGF_ERROR("No mapping module cfg function; ignoring %s", pNVCfg->libCfgNames[i]); - } - } - else { - assert(0); - } - } // for loop ends + openavbTlChangeConfig(pTLState, pNVCfg); // for loop ends pTLState->cfg.map_cb.map_gen_init_cb(pTLState->pMediaQ); pTLState->cfg.intf_cb.intf_gen_init_cb(pTLState->pMediaQ); diff --git a/lib/avtp_pipeline/tl/openavb_tl_pub.h b/lib/avtp_pipeline/tl/openavb_tl_pub.h index 3b708b88..a95aedaf 100755 --- a/lib/avtp_pipeline/tl/openavb_tl_pub.h +++ b/lib/avtp_pipeline/tl/openavb_tl_pub.h @@ -241,6 +241,19 @@ tl_handle_t openavbTLOpen(void); */ void openavbTLInitCfg(openavb_tl_cfg_t *pCfg); + +/** Change talker's / listener's configuration item + * + * Changes one configuration option of talker / listener from name value pair. + * Only intf_nv_ and map_nv_ names are supported. + * Can be called while stream is running, assuming that map and intf modules + * are prepared for runtime changes of particular configration item. + * + * @param handle Handle of talker/listener + * @param pNVCfg Pointer to name value pair configuration structure + */ +void openavbTlChangeConfig(tl_handle_t handle, openavb_tl_cfg_name_value_t* pNVCfg); + /** Configure the talker / listener. * * Configures talker/listener with configuration values from configuration |