From 1a178752515620b2a40a8f251ef499255a3c8766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=20Pi=C3=B1a?= Date: Sat, 26 Apr 2025 16:32:49 +0000 Subject: [PATCH 1/5] implementation --- libvmaf/include/libvmaf/model.h | 6 ++++++ libvmaf/src/model.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/libvmaf/include/libvmaf/model.h b/libvmaf/include/libvmaf/model.h index 98211466f..8ff269b04 100644 --- a/libvmaf/include/libvmaf/model.h +++ b/libvmaf/include/libvmaf/model.h @@ -87,6 +87,12 @@ int vmaf_model_collection_feature_overload(VmafModel *model, void vmaf_model_collection_destroy(VmafModelCollection *model_collection); +/// @brief Iterate through all built in vmaf model versions +/// @param prev previous model. NULL to get the first model +/// @param name OUT var - name of next model. If last model, this function does not modify name +/// @return next model or NULL after the last model +const void* vmaf_version_next(const void* prev, char** name); + #ifdef __cplusplus } #endif diff --git a/libvmaf/src/model.c b/libvmaf/src/model.c index ab623a9fd..9ee911ece 100644 --- a/libvmaf/src/model.c +++ b/libvmaf/src/model.c @@ -322,3 +322,17 @@ int vmaf_model_collection_feature_overload(VmafModel *model, return err; } +const void* vmaf_version_next(const void* prev, char** name){ + VmafBuiltInModel* prev_model = prev; + VmafBuiltInModel* out_model = NULL; + if (!prev_model){ + out_model = &built_in_models[0]; + } + if(prev_model - built_in_models < BUILT_IN_MODEL_CNT){ + out_model = prev_model + 1; + } + if (name && out_model){ + *name = out_model->version; + } + return out_model; +} \ No newline at end of file From 3b796a00154e82c9eca29ca4dd9fa67d9c2336c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=20Pi=C3=B1a?= Date: Sat, 26 Apr 2025 16:49:37 +0000 Subject: [PATCH 2/5] add test --- libvmaf/include/libvmaf/model.h | 2 +- libvmaf/src/model.c | 2 +- libvmaf/test/test_model.c | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libvmaf/include/libvmaf/model.h b/libvmaf/include/libvmaf/model.h index 8ff269b04..8f3475d61 100644 --- a/libvmaf/include/libvmaf/model.h +++ b/libvmaf/include/libvmaf/model.h @@ -91,7 +91,7 @@ void vmaf_model_collection_destroy(VmafModelCollection *model_collection); /// @param prev previous model. NULL to get the first model /// @param name OUT var - name of next model. If last model, this function does not modify name /// @return next model or NULL after the last model -const void* vmaf_version_next(const void* prev, char** name); +const void* vmaf_version_next(const void* prev, const char** name); #ifdef __cplusplus } diff --git a/libvmaf/src/model.c b/libvmaf/src/model.c index 9ee911ece..b5def2dda 100644 --- a/libvmaf/src/model.c +++ b/libvmaf/src/model.c @@ -322,7 +322,7 @@ int vmaf_model_collection_feature_overload(VmafModel *model, return err; } -const void* vmaf_version_next(const void* prev, char** name){ +const void* vmaf_version_next(const void* prev, const char** name){ VmafBuiltInModel* prev_model = prev; VmafBuiltInModel* out_model = NULL; if (!prev_model){ diff --git a/libvmaf/test/test_model.c b/libvmaf/test/test_model.c index ff965cd38..290410bb4 100644 --- a/libvmaf/test/test_model.c +++ b/libvmaf/test/test_model.c @@ -371,6 +371,17 @@ static char *test_model_set_flags() return NULL; } + +static char* test_version_next(){ + void* next = NULL; + char* version = NULL; + while(next = vmaf_version_next(next, &version)){ + VmafBuiltInModel* m = next; + mu_assert("Model versions must match",m->version == version); + } + return NULL; +} + char *run_tests() { mu_run_test(test_json_model); @@ -382,5 +393,6 @@ char *run_tests() mu_run_test(test_model_check_default_behavior_set_flags); mu_run_test(test_model_set_flags); mu_run_test(test_model_feature); + mu_run_test(test_version_next); return NULL; } From 74f54864abc0e649bd5addf95dbfa95e5448f9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=20Pi=C3=B1a?= Date: Sat, 26 Apr 2025 16:56:14 +0000 Subject: [PATCH 3/5] update function name --- libvmaf/src/model.c | 2 +- libvmaf/test/test_model.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libvmaf/src/model.c b/libvmaf/src/model.c index b5def2dda..1d98153e9 100644 --- a/libvmaf/src/model.c +++ b/libvmaf/src/model.c @@ -322,7 +322,7 @@ int vmaf_model_collection_feature_overload(VmafModel *model, return err; } -const void* vmaf_version_next(const void* prev, const char** name){ +const void* vmaf_model_version_next(const void* prev, const char** name){ VmafBuiltInModel* prev_model = prev; VmafBuiltInModel* out_model = NULL; if (!prev_model){ diff --git a/libvmaf/test/test_model.c b/libvmaf/test/test_model.c index 290410bb4..f3fb62513 100644 --- a/libvmaf/test/test_model.c +++ b/libvmaf/test/test_model.c @@ -375,7 +375,7 @@ static char *test_model_set_flags() static char* test_version_next(){ void* next = NULL; char* version = NULL; - while(next = vmaf_version_next(next, &version)){ + while(next = vmaf_model_version_next(next, &version)){ VmafBuiltInModel* m = next; mu_assert("Model versions must match",m->version == version); } From 6554f156a0c6297bac36f14969081076521fc040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=20Pi=C3=B1a?= Date: Sat, 26 Apr 2025 16:59:21 +0000 Subject: [PATCH 4/5] update include --- libvmaf/include/libvmaf/model.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvmaf/include/libvmaf/model.h b/libvmaf/include/libvmaf/model.h index 8f3475d61..0e374fe05 100644 --- a/libvmaf/include/libvmaf/model.h +++ b/libvmaf/include/libvmaf/model.h @@ -91,7 +91,7 @@ void vmaf_model_collection_destroy(VmafModelCollection *model_collection); /// @param prev previous model. NULL to get the first model /// @param name OUT var - name of next model. If last model, this function does not modify name /// @return next model or NULL after the last model -const void* vmaf_version_next(const void* prev, const char** name); +const void* vmaf_model_version_next(const void* prev, const char** name); #ifdef __cplusplus } From 6f8b07c7978fde9aeba0ba6e9af93f4b1b568a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=20Pi=C3=B1a?= Date: Sat, 26 Apr 2025 19:43:41 +0000 Subject: [PATCH 5/5] change arg name --- libvmaf/include/libvmaf/model.h | 2 +- libvmaf/src/model.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libvmaf/include/libvmaf/model.h b/libvmaf/include/libvmaf/model.h index 0e374fe05..5aab1622a 100644 --- a/libvmaf/include/libvmaf/model.h +++ b/libvmaf/include/libvmaf/model.h @@ -91,7 +91,7 @@ void vmaf_model_collection_destroy(VmafModelCollection *model_collection); /// @param prev previous model. NULL to get the first model /// @param name OUT var - name of next model. If last model, this function does not modify name /// @return next model or NULL after the last model -const void* vmaf_model_version_next(const void* prev, const char** name); +const void* vmaf_model_version_next(const void* prev, const char** version); #ifdef __cplusplus } diff --git a/libvmaf/src/model.c b/libvmaf/src/model.c index 1d98153e9..8746eb741 100644 --- a/libvmaf/src/model.c +++ b/libvmaf/src/model.c @@ -322,7 +322,7 @@ int vmaf_model_collection_feature_overload(VmafModel *model, return err; } -const void* vmaf_model_version_next(const void* prev, const char** name){ +const void* vmaf_model_version_next(const void* prev, const char** version){ VmafBuiltInModel* prev_model = prev; VmafBuiltInModel* out_model = NULL; if (!prev_model){ @@ -331,8 +331,8 @@ const void* vmaf_model_version_next(const void* prev, const char** name){ if(prev_model - built_in_models < BUILT_IN_MODEL_CNT){ out_model = prev_model + 1; } - if (name && out_model){ - *name = out_model->version; + if (version && out_model){ + *version = out_model->version; } return out_model; } \ No newline at end of file