Skip to content

Commit

Permalink
refactoring: update feature_collector to support multiple configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiğithan Yiğit authored and Yiğithan Yiğit committed Jan 31, 2025
1 parent 4e21c82 commit ffb6067
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
77 changes: 42 additions & 35 deletions libvmaf/src/feature/feature_collector.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ int vmaf_feature_collector_append(VmafFeatureCollector *feature_collector,

VmafPredictModel *model_iter = feature_collector->models;

while (model_iter) {
while(model_iter) {
VmafModel *model = model_iter->model;
bool needs_computation = false;

Expand All @@ -370,44 +370,51 @@ int vmaf_feature_collector_append(VmafFeatureCollector *feature_collector,
pthread_mutex_unlock(&(feature_collector->lock));
res = vmaf_predict_score_at_index(model, feature_collector, picture_index, &score, true, true, 0);
pthread_mutex_lock(&(feature_collector->lock));
}
model_iter = model_iter->next;
}

VmafCallbackItem *metadata_iter = feature_collector->metadata ?
feature_collector->metadata->head : NULL;

if (!res) {
// Process all pending frames up to current index in order
unsigned process_index = feature_collector->metadata->last_seen_lowest_index;
feature_collector->metadata->last_seen_highest_index = MAX(picture_index, feature_collector->metadata->last_seen_highest_index);

while (process_index <= feature_collector->metadata->last_seen_highest_index) {
bool frame_ready = true;

// First check if this frame's score is ready
pthread_mutex_unlock(&(feature_collector->lock));
if (vmaf_feature_collector_get_score(feature_collector, model->name, &score, process_index) != 0) {
frame_ready = false;
}
pthread_mutex_lock(&(feature_collector->lock));

if (!frame_ready) break; // Stop at first unready frame

// Frame is ready, trigger callbacks for all features
for (unsigned j = 0; j < feature_collector->cnt; j++) {
VmafMetadata data = {
.feature_name = feature_collector->feature_vector[j]->name,
.picture_index = process_index,
.score = feature_collector->feature_vector[j]->score[process_index].value,
};

// Call all metadata callbacks
feature_collector->metadata->head->metadata_cfg.callback(
feature_collector->metadata->head->metadata_cfg.data, &data);
}

process_index++;
feature_collector->metadata->last_seen_lowest_index = process_index;
while(metadata_iter) {
// Process all pending frames up to current index in order
unsigned process_index = metadata_iter->last_seen_lowest_index;
metadata_iter->last_seen_highest_index = MAX(picture_index, metadata_iter->last_seen_highest_index);

while (process_index <= metadata_iter->last_seen_highest_index) {
bool frame_ready = true;

VmafPredictModel *model_iter = feature_collector->models;
while(model_iter && frame_ready) {
// First check if this frame's score is ready
pthread_mutex_unlock(&(feature_collector->lock));
if (vmaf_feature_collector_get_score(feature_collector, model_iter->model->name, &score, process_index) != 0) {
frame_ready = false;
}
pthread_mutex_lock(&(feature_collector->lock));
model_iter = model_iter->next;
}
}

model_iter = model_iter->next;
if (!frame_ready) break; // Stop at first unready frame

// Frame is ready, trigger callbacks for all features
for (unsigned j = 0; j < feature_collector->cnt; j++) {
VmafMetadata data = {
.feature_name = feature_collector->feature_vector[j]->name,
.picture_index = process_index,
.score = feature_collector->feature_vector[j]->score[process_index].value,
};

// Call all metadata callbacks
metadata_iter->metadata_cfg.callback(
metadata_iter->metadata_cfg.data, &data);
}

process_index++;
metadata_iter->last_seen_lowest_index = process_index;
}
metadata_iter = metadata_iter->next;
}

unlock:
Expand Down
2 changes: 0 additions & 2 deletions libvmaf/src/metadata_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ int vmaf_metadata_init(VmafCallbackList **const metadata)
if (!metadata_s) goto fail;

metadata_s->head = NULL;
metadata_s->last_seen_highest_index = 0;
metadata_s->last_seen_lowest_index = 0;

return 0;

Expand Down
4 changes: 2 additions & 2 deletions libvmaf/src/metadata_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

typedef struct VmafCallbackItem {
VmafMetadataConfiguration metadata_cfg;
unsigned last_seen_highest_index;
unsigned last_seen_lowest_index;
struct VmafCallbackItem *next;
} VmafCallbackItem;

typedef struct VmafCallbackList{
VmafCallbackItem *head;
unsigned last_seen_highest_index;
unsigned last_seen_lowest_index;
} VmafCallbackList;

int vmaf_metadata_init(VmafCallbackList **const metadata);
Expand Down

0 comments on commit ffb6067

Please sign in to comment.