Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions libvmaf/src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <locale.h>

#include "feature/alias.h"
#include "feature/feature_collector.h"
Expand Down Expand Up @@ -72,6 +73,12 @@ int vmaf_write_output_xml(VmafContext *vmaf, VmafFeatureCollector *fc,
if (!fc) return -EINVAL;
if (!outfile) return -EINVAL;

locale_t c_locale = newlocale(LC_ALL_MASK, "C", NULL);
locale_t old_locale = (locale_t)0;
if (c_locale != (locale_t)0) {
old_locale = uselocale(c_locale);
}

fprintf(outfile, "<VMAF version=\"%s\">\n", vmaf_version());
fprintf(outfile, " <params qualityWidth=\"%d\" qualityHeight=\"%d\" />\n",
width, height);
Expand Down Expand Up @@ -154,13 +161,24 @@ int vmaf_write_output_xml(VmafContext *vmaf, VmafFeatureCollector *fc,

fprintf(outfile, "</VMAF>\n");

if (c_locale != (locale_t)0) {
uselocale(old_locale);
freelocale(c_locale);
}

return 0;
}

int vmaf_write_output_json(VmafContext *vmaf, VmafFeatureCollector *fc,
FILE *outfile, unsigned subsample, double fps,
unsigned pic_cnt)
{
locale_t c_locale = newlocale(LC_ALL_MASK, "C", NULL);
locale_t old_locale = (locale_t)0;
if (c_locale != (locale_t)0) {
old_locale = uselocale(c_locale);
}

int leading_zeros_count;
fprintf(outfile, "{\n");
fprintf(outfile, " \"version\": \"%s\",\n", vmaf_version());
Expand Down Expand Up @@ -299,12 +317,23 @@ int vmaf_write_output_json(VmafContext *vmaf, VmafFeatureCollector *fc,
fprintf(outfile, "\n }\n");
fprintf(outfile, "}\n");

if (c_locale != (locale_t)0) {
uselocale(old_locale);
freelocale(c_locale);
}

return 0;
}

int vmaf_write_output_csv(VmafFeatureCollector *fc, FILE *outfile,
unsigned subsample)
{
locale_t c_locale = newlocale(LC_ALL_MASK, "C", NULL);
locale_t old_locale = (locale_t)0;
if (c_locale != (locale_t)0) {
old_locale = uselocale(c_locale);
}

int leading_zeros_count;
fprintf(outfile, "Frame,");
for (unsigned i = 0; i < fc->cnt; i++) {
Expand Down Expand Up @@ -342,12 +371,23 @@ int vmaf_write_output_csv(VmafFeatureCollector *fc, FILE *outfile,
fprintf(outfile, "\n");
}

if (c_locale != (locale_t)0) {
uselocale(old_locale);
freelocale(c_locale);
}

return 0;
}

int vmaf_write_output_sub(VmafFeatureCollector *fc, FILE *outfile,
unsigned subsample)
{
locale_t c_locale = newlocale(LC_ALL_MASK, "C", NULL);
locale_t old_locale = (locale_t)0;
if (c_locale != (locale_t)0) {
old_locale = uselocale(c_locale);
}

int leading_zeros_count;
for (unsigned i = 0 ; i < max_capacity(fc); i++) {
if ((subsample > 1) && (i % subsample))
Expand Down Expand Up @@ -381,5 +421,10 @@ int vmaf_write_output_sub(VmafFeatureCollector *fc, FILE *outfile,
fprintf(outfile, "\n");
}

if (c_locale != (locale_t)0) {
uselocale(old_locale);
freelocale(c_locale);
}

return 0;
}
17 changes: 16 additions & 1 deletion libvmaf/src/read_json_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>

#define MAX_FEATURE_COUNT 64 //FIXME
#define MAX_KNOT_COUNT 10 //FIXME
Expand Down Expand Up @@ -432,6 +433,7 @@ static int model_parse(json_stream *s, VmafModel *model,
static int vmaf_read_json_model(VmafModel **model, VmafModelConfig *cfg,
json_stream *s)
{
int err = -EINVAL;
VmafModel *const m = *model = malloc(sizeof(*m));
if (!m) return -ENOMEM;
memset(m, 0, sizeof(*m));
Expand All @@ -449,7 +451,20 @@ static int vmaf_read_json_model(VmafModel **model, VmafModelConfig *cfg,
if (!m->score_transform.knots.list) return -ENOMEM;
memset(m->score_transform.knots.list, 0, knots_sz);

return model_parse(s, m, cfg->flags);
locale_t c_locale = newlocale(LC_ALL_MASK, "C", NULL);
locale_t old_locale = (locale_t)0;
if (c_locale != (locale_t)0) {
old_locale = uselocale(c_locale);
}

err = model_parse(s, m, cfg->flags);

if (c_locale != (locale_t)0) {
uselocale(old_locale);
freelocale(c_locale);
}

return err;
}

int vmaf_read_json_model_from_buffer(VmafModel **model, VmafModelConfig *cfg,
Expand Down
14 changes: 8 additions & 6 deletions libvmaf/src/svm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2653,11 +2653,11 @@ int svm_save_model(const char *model_file_name, const svm_model *model)
FILE *fp = fopen(model_file_name,"w");
if(fp==NULL) return -1;

char *old_locale = setlocale(LC_ALL, NULL);
if (old_locale) {
old_locale = strdup(old_locale);
locale_t c_locale = newlocale(LC_ALL_MASK, "C", NULL);
locale_t old_locale = (locale_t)0;
if (c_locale != (locale_t)0) {
old_locale = uselocale(c_locale);
}
setlocale(LC_ALL, "C");

const svm_parameter& param = model->param;

Expand Down Expand Up @@ -2738,8 +2738,10 @@ int svm_save_model(const char *model_file_name, const svm_model *model)
fprintf(fp, "\n");
}

setlocale(LC_ALL, old_locale);
free(old_locale);
if (c_locale != (locale_t)0) {
uselocale(old_locale);
freelocale(c_locale);
}

if (ferror(fp) != 0 || fclose(fp) != 0) return -1;
else return 0;
Expand Down