move libav.c to nc_err_e #532

This commit is contained in:
nick black 2020-04-24 01:03:02 -04:00 committed by Nick Black
parent 6ffbef3d74
commit 2037cdfacb
12 changed files with 116 additions and 100 deletions

View File

@ -263,20 +263,25 @@ int ncdirect_cursor_up(struct ncdirect* nc, int num);
int ncdirect_cursor_left(struct ncdirect* nc, int num);
int ncdirect_cursor_right(struct ncdirect* nc, int num);
int ncdirect_cursor_down(struct ncdirect* nc, int num);
struct ncvisual* ncplane_visual_open(struct ncplane* nc, const char* file, int* averr);
typedef enum {
NCERR_SUCCESS,
NCERR_NOMEM,
NCERR_EOF,
} nc_err_e;
struct ncvisual* ncplane_visual_open(struct ncplane* nc, const char* file, nc_err_e* err);
typedef enum {
NCSCALE_NONE,
NCSCALE_SCALE,
NCSCALE_STRETCH,
} ncscale_e;
struct ncvisual* ncvisual_open_plane(struct notcurses* nc, const char* file, int* averr, int y, int x, ncscale_e style);
struct ncvisual* ncvisual_open_plane(struct notcurses* nc, const char* file, nc_err_e* err, int y, int x, ncscale_e style);
struct ncplane* ncvisual_plane(struct ncvisual* ncv);
void ncvisual_destroy(struct ncvisual* ncv);
struct AVFrame* ncvisual_decode(struct ncvisual* nc, int* averr);
struct AVFrame* ncvisual_decode(struct ncvisual* nc, nc_err_e* err);
int ncvisual_render(const struct ncvisual* ncv, int begy, int begx, int leny, int lenx);
char* ncvisual_subtitle(const struct ncvisual* ncv);
typedef int (*streamcb)(struct notcurses* nc, struct ncvisual* ncv, void*);
int ncvisual_stream(struct notcurses* nc, struct ncvisual* ncv, int* averr, float timescale, streamcb streamer, void* curry);
int ncvisual_stream(struct notcurses* nc, struct ncvisual* ncv, nc_err_e* err, float timescale, streamcb streamer, void* curry);
int ncblit_bgrx(struct ncplane* nc, int placey, int placex, int linesize, const unsigned char* data, int begy, int begx, int leny, int lenx);
int ncblit_rgba(struct ncplane* nc, int placey, int placex, int linesize, const unsigned char* data, int begy, int begx, int leny, int lenx);
struct selector_item {

View File

@ -16,15 +16,15 @@ chunli_draw(struct notcurses* nc, const char* ext, int count, const cell* b){
struct timespec iterdelay;
timespec_div(&demodelay, 10, &iterdelay);
for(int i = 0 ; i < count ; ++i){
int averr;
nc_err_e err;
notcurses_refresh(nc, &dimy, &dimx);
snprintf(file, sizeof(file), "chunli%d.%s", i + 1, ext);
chuns[i].path = find_data(file);
chuns[i].ncv = ncvisual_open_plane(nc, chuns[i].path, &averr, 0, 0, NCSCALE_NONE);
chuns[i].ncv = ncvisual_open_plane(nc, chuns[i].path, &err, 0, 0, NCSCALE_NONE);
if(chuns[i].ncv == NULL){
return -1;
}
if(ncvisual_decode(chuns[i].ncv, &averr) == NULL){
if(ncvisual_decode(chuns[i].ncv, &err) == NULL){
return -1;
}
if(ncvisual_render(chuns[i].ncv, 0, 0, -1, -1) <= 0){
@ -53,25 +53,26 @@ int chunli_demo(struct notcurses* nc){
}
struct timespec iterdelay;
timespec_div(&demodelay, 10, &iterdelay);
int averr, dimx, dimy;
int ret, dimx, dimy;
notcurses_refresh(nc, &dimy, &dimx);
cell b = CELL_TRIVIAL_INITIALIZER;
cell_set_fg_alpha(&b, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(&b, CELL_ALPHA_TRANSPARENT);
if( (averr = chunli_draw(nc, "bmp", CHUNS, &b)) ){
return averr;
if( (ret = chunli_draw(nc, "bmp", CHUNS, &b)) ){
return ret;
}
char file[20];
for(int i = 1 ; i < 100 ; ++i){
snprintf(file, sizeof(file), "chunli%02d.png", i);
char* path = find_data(file);
struct ncvisual* ncv = ncvisual_open_plane(nc, path, &averr, 0, 0, NCSCALE_NONE);
nc_err_e err;
struct ncvisual* ncv = ncvisual_open_plane(nc, path, &err, 0, 0, NCSCALE_NONE);
if(ncv == NULL){
free(path);
break;
}
free(path);
if(ncvisual_decode(ncv, &averr) == NULL){
if(ncvisual_decode(ncv, &err) == NULL){
return -1;
}
struct ncplane* ncp = ncvisual_plane(ncv);

View File

@ -44,7 +44,7 @@ outzoomed_map(struct notcurses* nc, const char* map){
static struct ncplane*
zoom_map(struct notcurses* nc, const char* map){
int ncerr;
nc_err_e ncerr;
// determine size that will be represented on screen at once, and how
// large that section has been rendered in the outzoomed map. take the map
// and begin opening it on larger and larger planes that fit on the screen

View File

@ -175,16 +175,16 @@ int fallin_demo(struct notcurses* nc){
}
free(usemap);
ncplane_erase(stdn);
#ifdef USE_FFMPEG
#ifdef USE_MULTIMEDIA
#ifndef DFSG_BUILD
int averr = 0;
nc_err_e err = 0;
char* path = find_data("lamepatents.jpg");
struct ncvisual* ncv = ncplane_visual_open(stdn, path, &averr);
struct ncvisual* ncv = ncplane_visual_open(stdn, path, &err);
free(path);
if(ncv == NULL){
return -1;
}
if(ncvisual_decode(ncv, &averr) == NULL){
if(ncvisual_decode(ncv, &err) == NULL){
ncvisual_destroy(ncv);
return -1;
}
@ -192,8 +192,8 @@ int fallin_demo(struct notcurses* nc){
ncvisual_destroy(ncv);
return -1;
}
assert(ncvisual_decode(ncv, &averr) == NULL);
assert(averr == AVERROR_EOF);
assert(ncvisual_decode(ncv, &err) == NULL);
assert(NCERR_EOF == err);
ncvisual_destroy(ncv);
#endif
#endif

View File

@ -31,9 +31,9 @@ fadethread(void* vnc){
timespec_mul(&demodelay, 2, &fade);
ncplane_fadeout(ncp, &fade, demo_fader, NULL);
ncvisual_destroy(chncv);
int averr;
nc_err_e err;
char* path = find_data("samoa.avi");
struct ncvisual* ncv = ncplane_visual_open(ncp, path, &averr);
struct ncvisual* ncv = ncplane_visual_open(ncp, path, &err);
free(path);
if(ncv == NULL){
return NULL;
@ -44,7 +44,7 @@ fadethread(void* vnc){
ncplane_putstr_aligned(apiap, 0, NCALIGN_CENTER,
"Apia 🡺 Atlanta. Samoa, tula'i ma sisi ia lau fu'a, lou pale lea!");
int three = 3;
int canceled = ncvisual_stream(nc, ncv, &averr, delaymultiplier, perframe, &three);
int canceled = ncvisual_stream(nc, ncv, &err, delaymultiplier, perframe, &three);
ncvisual_destroy(ncv);
ncplane_erase(ncp);
ncplane_destroy(apiap);
@ -126,14 +126,14 @@ int outro(struct notcurses* nc){
int rows, cols;
struct ncplane* ncp = notcurses_stddim_yx(nc, &rows, &cols);
ncplane_erase(ncp);
int averr = 0;
nc_err_e err = 0;
char* path = find_data("changes.jpg");
chncv = ncplane_visual_open(ncp, path, &averr);
chncv = ncplane_visual_open(ncp, path, &err);
free(path);
if(chncv == NULL){
return -1;
}
if(ncvisual_decode(chncv, &averr) == NULL){
if(ncvisual_decode(chncv, &err) == NULL){
ncvisual_destroy(chncv);
return -1;
}

View File

@ -18,16 +18,16 @@ static int
view_video_demo(struct notcurses* nc){
int dimy, dimx;
struct ncplane* ncp = notcurses_stddim_yx(nc, &dimy, &dimx);
int averr;
nc_err_e err;
struct ncvisual* ncv;
char* fm6 = find_data("fm6.mkv");
ncv = ncplane_visual_open(ncp, fm6, &averr);
ncv = ncplane_visual_open(ncp, fm6, &err);
if(!ncv){
free(fm6);
return -1;
}
free(fm6);
int ret = ncvisual_stream(nc, ncv, &averr, 2.0/3.0 * delaymultiplier, watch_for_keystroke, NULL);
int ret = ncvisual_stream(nc, ncv, &err, 2.0/3.0 * delaymultiplier, watch_for_keystroke, NULL);
ncvisual_destroy(ncv);
return ret;
}
@ -70,10 +70,10 @@ int view_demo(struct notcurses* nc){
}
int dimy, dimx;
struct ncplane* ncp = notcurses_stddim_yx(nc, &dimy, &dimx);
int averr = 0;
nc_err_e err = 0;
char* pic = find_data("PurpleDrank.jpg");
ncplane_erase(ncp);
struct ncvisual* ncv = ncplane_visual_open(ncp, pic, &averr);
struct ncvisual* ncv = ncplane_visual_open(ncp, pic, &err);
if(ncv == NULL){
free(pic);
return -1;
@ -84,7 +84,7 @@ int view_demo(struct notcurses* nc){
return -1;
}
pic = find_data("dsscaw-purp.png");
struct ncvisual* ncv2 = ncplane_visual_open(dsplane, pic, &averr);
struct ncvisual* ncv2 = ncplane_visual_open(dsplane, pic, &err);
if(ncv2 == NULL){
free(pic);
ncvisual_destroy(ncv);
@ -92,13 +92,13 @@ int view_demo(struct notcurses* nc){
return -1;
}
free(pic);
if(ncvisual_decode(ncv, &averr) == NULL){
if(ncvisual_decode(ncv, &err) == NULL){
ncvisual_destroy(ncv);
ncvisual_destroy(ncv2);
ncplane_destroy(dsplane);
return -1;
}
if(ncvisual_decode(ncv2, &averr) == NULL){
if(ncvisual_decode(ncv2, &err) == NULL){
ncvisual_destroy(ncv);
ncvisual_destroy(ncv2);
ncplane_destroy(dsplane);

View File

@ -106,14 +106,14 @@ int xray_demo(struct notcurses* nc){
return -1;
}
char* path = find_data("notcursesI.avi");
int averr;
struct ncvisual* ncv = ncplane_visual_open(n, path, &averr);
nc_err_e err;
struct ncvisual* ncv = ncplane_visual_open(n, path, &err);
free(path);
if(ncv == NULL){
return -1;
}
struct ncplane* newpanel = NULL;
int ret = ncvisual_stream(nc, ncv, &averr, 0.5 * delaymultiplier, perframecb, &newpanel);
int ret = ncvisual_stream(nc, ncv, &err, 0.5 * delaymultiplier, perframecb, &newpanel);
ncvisual_destroy(ncv);
ncplane_destroy(n);
ncplane_destroy(newpanel);

View File

@ -160,7 +160,13 @@ char* ncvisual_subtitle(const ncvisual* ncv){
return NULL;
}
AVFrame* ncvisual_decode(ncvisual* nc, int* averr){
static nc_err_e
averr2ncerr(int averr){
// FIXME need to map averror codes to ncerrors
return -averr;
}
AVFrame* ncvisual_decode(ncvisual* nc, nc_err_e* ncerr){
bool have_frame = false;
bool unref = false;
av_freep(&nc->oframe->data[0]);
@ -172,10 +178,12 @@ AVFrame* ncvisual_decode(ncvisual* nc, int* averr){
if(unref){
av_packet_unref(nc->packet);
}
if((*averr = av_read_frame(nc->fmtctx, nc->packet)) < 0){
int averr;
if((averr = av_read_frame(nc->fmtctx, nc->packet)) < 0){
/*if(averr != AVERROR_EOF){
fprintf(stderr, "Error reading frame info (%s)\n", av_err2str(*averr));
}*/
*ncerr = averr2ncerr(averr);
return NULL;
}
unref = true;
@ -187,20 +195,20 @@ AVFrame* ncvisual_decode(ncvisual* nc, int* averr){
}
}while(nc->packet->stream_index != nc->stream_index);
++nc->packet_outstanding;
*averr = avcodec_send_packet(nc->codecctx, nc->packet);
if(*averr < 0){
//fprintf(stderr, "Error processing AVPacket (%s)\n", av_err2str(*averr));
return ncvisual_decode(nc, averr);
*ncerr = avcodec_send_packet(nc->codecctx, nc->packet);
if(*ncerr < 0){
//fprintf(stderr, "Error processing AVPacket (%s)\n", av_err2str(*ncerr));
return ncvisual_decode(nc, ncerr);
}
--nc->packet_outstanding;
av_packet_unref(nc->packet);
*averr = avcodec_receive_frame(nc->codecctx, nc->frame);
if(*averr >= 0){
int averr = avcodec_receive_frame(nc->codecctx, nc->frame);
if(averr >= 0){
have_frame = true;
}else if(*averr == AVERROR(EAGAIN) || *averr == AVERROR_EOF){
}else if(averr == AVERROR(EAGAIN) || averr == AVERROR_EOF){
have_frame = false;
}else if(*averr < 0){
//fprintf(stderr, "Error decoding AVPacket (%s)\n", av_err2str(*averr));
}else if(averr < 0){
//fprintf(stderr, "Error decoding AVPacket (%s)\n", av_err2str(averr));
return NULL;
}
}while(!have_frame);
@ -225,7 +233,7 @@ AVFrame* ncvisual_decode(ncvisual* nc, int* averr){
nc->placey = 0;
nc->placex = 0;
if(nc->ncp == NULL){
*averr = AVERROR(ENOMEM);
*ncerr = NCERR_NOMEM;
return NULL;
}
}else{ // check for resize
@ -276,35 +284,39 @@ AVFrame* ncvisual_decode(ncvisual* nc, int* averr){
}
static ncvisual*
ncvisual_open(const char* filename, int* averr){
ncvisual_open(const char* filename, nc_err_e* ncerr){
ncvisual* ncv = ncvisual_create(1);
if(ncv == NULL){
// fprintf(stderr, "Couldn't create %s (%s)\n", filename, strerror(errno));
*averr = AVERROR(ENOMEM);
*ncerr = NCERR_NOMEM;
return NULL;
}
memset(ncv, 0, sizeof(*ncv));
*averr = avformat_open_input(&ncv->fmtctx, filename, NULL, NULL);
if(*averr < 0){
int averr = avformat_open_input(&ncv->fmtctx, filename, NULL, NULL);
if(averr < 0){
// fprintf(stderr, "Couldn't open %s (%s)\n", filename, av_err2str(*averr));
*ncerr = averr2ncerr(averr);
goto err;
}
if((*averr = avformat_find_stream_info(ncv->fmtctx, NULL)) < 0){
averr = avformat_find_stream_info(ncv->fmtctx, NULL);
if(averr < 0){
/*fprintf(stderr, "Error extracting stream info from %s (%s)\n", filename,
av_err2str(*averr));*/
*ncerr = averr2ncerr(averr);
goto err;
}
//av_dump_format(ncv->fmtctx, 0, filename, false);
if((*averr = av_find_best_stream(ncv->fmtctx, AVMEDIA_TYPE_SUBTITLE, -1, -1, &ncv->subtcodec, 0)) >= 0){
ncv->sub_stream_index = *averr;
if((averr = av_find_best_stream(ncv->fmtctx, AVMEDIA_TYPE_SUBTITLE, -1, -1, &ncv->subtcodec, 0)) >= 0){
ncv->sub_stream_index = averr;
if((ncv->subtcodecctx = avcodec_alloc_context3(ncv->subtcodec)) == NULL){
//fprintf(stderr, "Couldn't allocate decoder for %s\n", filename);
*averr = AVERROR(ENOMEM);
*ncerr = NCERR_NOMEM;
goto err;
}
// FIXME do we need avcodec_parameters_to_context() here?
if((*averr = avcodec_open2(ncv->subtcodecctx, ncv->subtcodec, NULL)) < 0){
if((averr = avcodec_open2(ncv->subtcodecctx, ncv->subtcodec, NULL)) < 0){
//fprintf(stderr, "Couldn't open codec for %s (%s)\n", filename, av_err2str(*averr));
*ncerr = averr2ncerr(averr);
goto err;
}
}else{
@ -312,14 +324,15 @@ ncvisual_open(const char* filename, int* averr){
}
if((ncv->packet = av_packet_alloc()) == NULL){
// fprintf(stderr, "Couldn't allocate packet for %s\n", filename);
*averr = AVERROR(ENOMEM);
*ncerr = NCERR_NOMEM;
goto err;
}
if((*averr = av_find_best_stream(ncv->fmtctx, AVMEDIA_TYPE_VIDEO, -1, -1, &ncv->codec, 0)) < 0){
if((averr = av_find_best_stream(ncv->fmtctx, AVMEDIA_TYPE_VIDEO, -1, -1, &ncv->codec, 0)) < 0){
// fprintf(stderr, "Couldn't find visuals in %s (%s)\n", filename, av_err2str(*averr));
*ncerr = averr2ncerr(averr);
goto err;
}
ncv->stream_index = *averr;
ncv->stream_index = averr;
if(ncv->codec == NULL){
//fprintf(stderr, "Couldn't find decoder for %s\n", filename);
goto err;
@ -327,19 +340,20 @@ ncvisual_open(const char* filename, int* averr){
AVStream* st = ncv->fmtctx->streams[ncv->stream_index];
if((ncv->codecctx = avcodec_alloc_context3(ncv->codec)) == NULL){
//fprintf(stderr, "Couldn't allocate decoder for %s\n", filename);
*averr = AVERROR(ENOMEM);
*ncerr = NCERR_NOMEM;
goto err;
}
if(avcodec_parameters_to_context(ncv->codecctx, st->codecpar) < 0){
goto err;
}
if((*averr = avcodec_open2(ncv->codecctx, ncv->codec, NULL)) < 0){
if((averr = avcodec_open2(ncv->codecctx, ncv->codec, NULL)) < 0){
//fprintf(stderr, "Couldn't open codec for %s (%s)\n", filename, av_err2str(*averr));
*ncerr = averr2ncerr(averr);
goto err;
}
/*if((ncv->cparams = avcodec_parameters_alloc()) == NULL){
//fprintf(stderr, "Couldn't allocate codec params for %s\n", filename);
*averr = AVERROR(ENOMEM);
*averr = NCERR_NOMEM;
goto err;
}
if((*averr = avcodec_parameters_from_context(ncv->cparams, ncv->codecctx)) < 0){
@ -348,12 +362,12 @@ ncvisual_open(const char* filename, int* averr){
}*/
if((ncv->frame = av_frame_alloc()) == NULL){
// fprintf(stderr, "Couldn't allocate frame for %s\n", filename);
*averr = AVERROR(ENOMEM);
*ncerr = NCERR_NOMEM;
goto err;
}
if((ncv->oframe = av_frame_alloc()) == NULL){
// fprintf(stderr, "Couldn't allocate output frame for %s\n", filename);
*averr = AVERROR(ENOMEM);
*ncerr = NCERR_NOMEM;
goto err;
}
return ncv;
@ -363,8 +377,8 @@ err:
return NULL;
}
ncvisual* ncplane_visual_open(ncplane* nc, const char* filename, int* averr){
ncvisual* ncv = ncvisual_open(filename, averr);
ncvisual* ncplane_visual_open(ncplane* nc, const char* filename, nc_err_e* ncerr){
ncvisual* ncv = ncvisual_open(filename, ncerr);
if(ncv == NULL){
return NULL;
}
@ -376,8 +390,8 @@ ncvisual* ncplane_visual_open(ncplane* nc, const char* filename, int* averr){
}
ncvisual* ncvisual_open_plane(notcurses* nc, const char* filename,
int* averr, int y, int x, ncscale_e style){
ncvisual* ncv = ncvisual_open(filename, averr);
nc_err_e* ncerr, int y, int x, ncscale_e style){
ncvisual* ncv = ncvisual_open(filename, ncerr);
if(ncv == NULL){
return NULL;
}
@ -437,7 +451,7 @@ int ncvisual_render(const ncvisual* ncv, int begy, int begx, int leny, int lenx)
// frames carry a presentation time relative to the beginning, so we get an
// initial timestamp, and check each frame against the elapsed time to sync
// up playback.
int ncvisual_stream(notcurses* nc, ncvisual* ncv, int* averr,
int ncvisual_stream(notcurses* nc, ncvisual* ncv, nc_err_e* ncerr,
float timescale, streamcb streamer, void* curry){
int frame = 1;
ncv->timescale = timescale;
@ -449,7 +463,7 @@ int ncvisual_stream(notcurses* nc, ncvisual* ncv, int* averr,
// each frame has a pkt_duration in milliseconds. keep the aggregate, in case
// we don't have PTS available.
uint64_t sum_duration = 0;
while( (avf = ncvisual_decode(ncv, averr)) ){
while( (avf = ncvisual_decode(ncv, ncerr)) ){
// codecctx seems to be off by a factor of 2 regularly. instead, go with
// the time_base from the avformatctx.
double tbase = av_q2d(ncv->fmtctx->streams[ncv->stream_index]->time_base);
@ -488,7 +502,7 @@ int ncvisual_stream(notcurses* nc, ncvisual* ncv, int* averr,
nanosleep(&interval, NULL);
}
}
if(*averr == AVERROR_EOF){
if(*ncerr == NCERR_EOF){
return 0;
}
return -1;
@ -505,9 +519,9 @@ bool notcurses_canopen(const notcurses* nc __attribute__ ((unused))){
return false;
}
struct AVFrame* ncvisual_decode(ncvisual* nc, int* averr){
struct AVFrame* ncvisual_decode(ncvisual* nc, nc_err_e* ncerr){
(void)nc;
(void)averr;
(void)ncerr;
return NULL;
}
@ -520,29 +534,29 @@ int ncvisual_render(const ncvisual* ncv, int begy, int begx, int leny, int lenx)
return -1;
}
int ncvisual_stream(struct notcurses* nc, struct ncvisual* ncv, int* averr,
int ncvisual_stream(struct notcurses* nc, struct ncvisual* ncv, nc_err_e* ncerr,
float timespec, streamcb streamer, void* curry){
(void)nc;
(void)ncv;
(void)averr;
(void)ncerr;
(void)timespec;
(void)streamer;
(void)curry;
return -1;
}
ncvisual* ncplane_visual_open(ncplane* nc, const char* filename, int* averr){
ncvisual* ncplane_visual_open(ncplane* nc, const char* filename, nc_err_e* ncerr){
(void)nc;
(void)filename;
(void)averr;
(void)ncerr;
return NULL;
}
ncvisual* ncvisual_open_plane(notcurses* nc, const char* filename,
int* averr, int y, int x, ncscale_e style){
nc_err_e* ncerr, int y, int x, ncscale_e style){
(void)nc;
(void)filename;
(void)averr;
(void)ncerr;
(void)y;
(void)x;
(void)style;

View File

@ -82,13 +82,13 @@ int main(void){
channels_set_bg_alpha(&sopts.bgchannels, CELL_ALPHA_BLEND);
struct ncplane* n = notcurses_stdplane(nc);
#ifdef USE_FFMPEG
int averr;
struct ncvisual* ncv = ncplane_visual_open(n, "../data/covid19.jpg", &averr);
#ifdef USE_MULTIMEDIA
nc_err_e err;
struct ncvisual* ncv = ncplane_visual_open(n, "../data/covid19.jpg", &err);
if(!ncv){
goto err;
}
if(!ncvisual_decode(ncv, &averr)){
if(!ncvisual_decode(ncv, &err)){
goto err;
}
if(ncvisual_render(ncv, 0, 0, -1, -1) <= 0){
@ -127,9 +127,7 @@ int main(void){
}
return EXIT_SUCCESS;
#ifdef USE_FFMPEG
err:
notcurses_stop(nc);
return EXIT_FAILURE;
#endif
}

View File

@ -81,13 +81,13 @@ int main(void){
channels_set_bg_alpha(&sopts.bgchannels, CELL_ALPHA_BLEND);
struct ncplane* n = notcurses_stdplane(nc);
#ifdef USE_FFMPEG
int averr;
struct ncvisual* ncv = ncplane_visual_open(n, "../data/changes.jpg", &averr);
#ifdef USE_MULTIMEDIA
nc_err_e err;
struct ncvisual* ncv = ncplane_visual_open(n, "../data/changes.jpg", &err);
if(!ncv){
goto err;
}
if(!ncvisual_decode(ncv, &averr)){
if(!ncvisual_decode(ncv, &err)){
goto err;
}
if(ncvisual_render(ncv, 0, 0, -1, -1) <= 0){
@ -126,9 +126,7 @@ int main(void){
}
return EXIT_SUCCESS;
#ifdef USE_FFMPEG
err:
notcurses_stop(nc);
return EXIT_FAILURE;
#endif
}

View File

@ -1,12 +1,12 @@
void DrawBackground(const std::string& s) { // drawn to the standard plane
#ifdef USE_FFMPEG
int averr;
#ifdef USE_MULTIMEDIA
nc_err_e err;
try{
backg_ = std::make_unique<ncpp::Visual>(s.c_str(), &averr, 0, 0, ncpp::NCScale::Stretch);
backg_ = std::make_unique<ncpp::Visual>(s.c_str(), &err, 0, 0, ncpp::NCScale::Stretch);
}catch(std::exception& e){
throw TetrisNotcursesErr("visual(): " + s + ": " + e.what());
}
if(!backg_->decode(&averr)){
if(!backg_->decode(&err)){
throw TetrisNotcursesErr("decode(): " + s);
}
if(backg_->render(0, 0, -1, -1) <= 0){

View File

@ -172,18 +172,18 @@ int main(int argc, char** argv){
for(auto i = nonopt ; i < argc ; ++i){
std::array<char, 128> errbuf;
int frames = 0;
int averr;
nc_err_e err;
std::unique_ptr<Visual> ncv;
try{
ncv = std::make_unique<Visual>(argv[i], &averr, 1, 0, stretchmode);
ncv = std::make_unique<Visual>(argv[i], &err, 1, 0, stretchmode);
}catch(std::exception& e){
nc.stop();
std::cerr << argv[i] << ": " << e.what() << "\n";
return EXIT_FAILURE;
}
int r = ncv->stream(&averr, timescale, perframe, &frames);
int r = ncv->stream(&err, timescale, perframe, &frames);
if(r < 0){ // positive is intentional abort
av_make_error_string(errbuf.data(), errbuf.size(), averr);
av_make_error_string(errbuf.data(), errbuf.size(), err);
nc.stop();
std::cerr << "Error decoding " << argv[i] << ": " << errbuf.data() << std::endl;
return EXIT_FAILURE;