Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#124 change compute_vmaf() interface to return an error code instead …
…of throw an error. (#126)
  • Loading branch information
li-zhi committed Dec 3, 2017
1 parent 7964274 commit 96b99b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -489,7 +489,7 @@ make install
This copies the library header `libvmaf.h` under `usr/local/include`, library `libvmaf.a `under `user/local/lib` and all the model files under `usr/local/share`. You can use the header `libvmaf.h` in your program. It contains an API which can be called from any C/C++ program:

```
double compute_vmaf(char* fmt, int width, int height, int (*read_frame)(float *ref_data, float *main_data, float *temp_data,
int compute_vmaf(double* vmaf_score, char* fmt, int width, int height, int (*read_frame)(float *ref_data, float *main_data, float *temp_data,
int stride, void *user_data), void *user_data, char *model_path, char *log_path, char *log_fmt, int disable_clip,
int disable_avx, int enable_transform, int phone_model, int do_psnr, int do_ssim, int do_ms_ssim, char *pool_method);
```
Expand Down
23 changes: 17 additions & 6 deletions wrapper/src/libvmaf.cpp
Expand Up @@ -25,7 +25,7 @@ extern "C" {

enum vmaf_cpu cpu; // global

double compute_vmaf(char* fmt, int width, int height, int (*read_frame)(float *ref_data, float *main_data, float *temp_data, int stride_byte, void *user_data), void *user_data, char *model_path, char *log_path, char *log_fmt, int disable_clip, int disable_avx, int enable_transform, int phone_model, int do_psnr, int do_ssim, int do_ms_ssim, char *pool_method)
int compute_vmaf(double* vmaf_score, char* fmt, int width, int height, int (*read_frame)(float *ref_data, float *main_data, float *temp_data, int stride_byte, void *user_data), void *user_data, char *model_path, char *log_path, char *log_fmt, int disable_clip, int disable_avx, int enable_transform, int phone_model, int do_psnr, int do_ssim, int do_ms_ssim, char *pool_method)
{
bool d_c = false;
bool d_a = false;
Expand Down Expand Up @@ -60,10 +60,21 @@ double compute_vmaf(char* fmt, int width, int height, int (*read_frame)(float *r
cpu = VMAF_CPU_NONE;
}

double score = RunVmaf(fmt, width, height, read_frame, user_data, model_path, log_path, log_fmt, d_c, e_t, d_p, d_s, d_m_s, pool_method);

return score;

}
try {
double score = RunVmaf(fmt, width, height, read_frame, user_data, model_path, log_path, log_fmt, d_c, e_t, d_p, d_s, d_m_s, pool_method);
*vmaf_score = score;
return 0;
}
catch (VmafException& e)
{
printf("Caught VmafException: %s\n", e.what());
return 1;
}
catch (std::runtime_error& e)
{
printf("Caught runtime_error: %s\n", e.what());
return 1;
}
}

}
2 changes: 1 addition & 1 deletion wrapper/src/libvmaf.h
Expand Up @@ -23,7 +23,7 @@
extern "C" {
#endif

double compute_vmaf(char* fmt, int width, int height, int (*read_frame)(float *ref_data, float *main_data, float *temp_data, int stride_byte, void *user_data), void *user_data, char *model_path, char *log_path, char *log_fmt, int disable_clip, int disable_avx, int enable_transform, int phone_model, int do_psnr, int do_ssim, int do_ms_ssim, char *pool_method);
int compute_vmaf(double* vmaf_score, char* fmt, int width, int height, int (*read_frame)(float *ref_data, float *main_data, float *temp_data, int stride_byte, void *user_data), void *user_data, char *model_path, char *log_path, char *log_fmt, int disable_clip, int disable_avx, int enable_transform, int phone_model, int do_psnr, int do_ssim, int do_ms_ssim, char *pool_method);


#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion wrapper/src/main.cpp
Expand Up @@ -106,7 +106,7 @@ int run_wrapper(char *fmt, int width, int height, char *ref_path, char *dis_path
}

/* Run VMAF */
score = compute_vmaf(fmt, width, height, read_frame, s, model_path, log_path, log_fmt, disable_clip, disable_avx, enable_transform, phone_model, do_psnr, do_ssim, do_ms_ssim, pool_method);
ret = compute_vmaf(&score, fmt, width, height, read_frame, s, model_path, log_path, log_fmt, disable_clip, disable_avx, enable_transform, phone_model, do_psnr, do_ssim, do_ms_ssim, pool_method);

fail_or_end:
if (s->ref_rfile)
Expand Down

4 comments on commit 96b99b9

@rcunning
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also update ffmpeg source (libavfilter/vf_libvmaf.c) for this change?

@li-zhi
Copy link
Contributor Author

@li-zhi li-zhi commented on 96b99b9 Dec 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbultje
Copy link

@rbultje rbultje commented on 96b99b9 Dec 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still getting exceptions when the file failed to parse (as opposed to not existing):

libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: array: attempting to access element:18446744073709551613 in array of length:0

@rbultje
Copy link

@rbultje rbultje commented on 96b99b9 Dec 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've send a patch that fixes the compile and works if the model file is missing. It doesn't deal with corrupt model files yet because of the above issue.

http://ffmpeg.org/pipermail/ffmpeg-devel/2017-December/221967.html

Please sign in to comment.