From d106ebf0d397c0df376db9ef6d20236f9685363e Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 1 Dec 2019 12:56:28 -0500 Subject: [PATCH] libav: check for AVERROR_EOF #86 --- include/notcurses.h | 9 ++++++--- src/view/view.cpp | 12 ++++-------- tests/libav.cpp | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/notcurses.h b/include/notcurses.h index 74c7607b4..5093bf567 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -10,6 +10,9 @@ #ifdef __cplusplus extern "C" { #define RESTRICT +#include +#include +#include // ffmpeg doesn't reliably "C"-guard itself #else #define RESTRICT restrict #endif @@ -598,9 +601,9 @@ API struct ncvisual* ncplane_visual_open(struct ncplane* nc, const char* file, API void ncvisual_destroy(struct ncvisual* ncv); // extract the next frame from an ncvisual. returns NULL on end of file, writing -// 0 to 'averr'. returns NULL on a decoding or allocation error, placing the -// AVError in 'averr'. this frame is invalidated by a subsequent call to -// ncvisual_decode(), and should not be freed by the caller. +// AVERROR_EOF to 'averr'. returns NULL on a decoding or allocation error, +// placing the AVError in 'averr'. this frame is invalidated by a subsequent +// call to ncvisual_decode(), and should not be freed by the caller. API struct AVFrame* ncvisual_decode(struct ncvisual* nc, int* averr); // render the next frame to the associated ncplane at the current cursor diff --git a/src/view/view.cpp b/src/view/view.cpp index 218b67579..c627b6722 100644 --- a/src/view/view.cpp +++ b/src/view/view.cpp @@ -2,13 +2,6 @@ #include #include #include - -extern "C" { -#include -#include -#include -} - #include "notcurses.h" static void usage(std::ostream& os, const char* name, int exitcode) @@ -28,7 +21,10 @@ int ncview(struct notcurses* nc, struct ncvisual* ncv, int* averr){ ncplane_printf(n, "Got frame %05d\u2026", frame); ++frame; } - return *averr; + if(*averr == AVERROR_EOF){ + return 0; + } + return -1; } int main(int argc, char** argv){ diff --git a/tests/libav.cpp b/tests/libav.cpp index a64553390..a3c7458f9 100644 --- a/tests/libav.cpp +++ b/tests/libav.cpp @@ -35,7 +35,7 @@ TEST_F(LibavTest, LoadImage) { EXPECT_EQ(0, averr); ASSERT_NE(nullptr, ncv); ASSERT_NE(nullptr, ncvisual_decode(ncv, &averr)); - EXPECT_EQ(0, averr); + EXPECT_EQ(AVERROR_EOF, averr); ncvisual_destroy(ncv); }