diff --git a/src/lib/internal.h b/src/lib/internal.h index bf9ebe650..39c4edcf4 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -1067,11 +1067,13 @@ typedef struct ncvisual_implementation { int begy, int begx, int leny, int lenx, bool blendcolors); struct ncvisual* (*ncvisual_create)(void); + struct ncvisual* (*ncvisual_from_file)(const char* fname); // ncv constructors other than ncvisual_from_file() need to set up the // AVFrame* 'frame' according to their own data, which is assumed to // have been prepared already in 'ncv'. void (*ncvisual_details_seed)(struct ncvisual* ncv); void (*ncvisual_details_destroy)(struct ncvisual_details* deets); + int (*ncvisual_decode)(struct ncvisual* nc); char* (*ncvisual_subtitle)(const struct ncvisual* ncv); bool canopen_images; bool canopen_videos; @@ -1081,12 +1083,6 @@ typedef struct ncvisual_implementation { extern const ncvisual_implementation* visual_implementation __attribute__ ((visibility("default"))); -struct ncvisual* ncvisual_from_file(const char* filename) - __attribute__ ((visibility("default"))); - -struct ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags) - __attribute__ ((visibility("default"))); - #ifdef __cplusplus } #endif diff --git a/src/lib/visual.cpp b/src/lib/visual.cpp index ad94fb284..279473c40 100644 --- a/src/lib/visual.cpp +++ b/src/lib/visual.cpp @@ -6,9 +6,11 @@ const ncvisual_implementation* visual_implementation = nullptr; -auto __attribute__ ((weak)) -ncvisual_decode(ncvisual* nc __attribute__ ((unused))) -> int { - return -1; +auto ncvisual_decode(ncvisual* nc) -> int { + if(!visual_implementation){ + return -1; + } + return visual_implementation->ncvisual_decode(nc); } auto ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n, @@ -46,9 +48,11 @@ auto ncvisual_init(int loglevel) -> int { return 0; } -auto __attribute__ ((weak)) -ncvisual_from_file(const char* filename __attribute__ ((unused))) -> ncvisual* { - return nullptr; +auto ncvisual_from_file(const char* filename) -> ncvisual* { + if(!visual_implementation){ + return nullptr; + } + return visual_implementation->ncvisual_from_file(filename); } auto ncvisual_create(void) -> ncvisual* { diff --git a/src/media/ffmpeg.cpp b/src/media/ffmpeg.cpp index 2a41bf559..e8acb275e 100644 --- a/src/media/ffmpeg.cpp +++ b/src/media/ffmpeg.cpp @@ -134,7 +134,7 @@ averr2ncerr(int averr){ return -1; } -int ncvisual_decode(ncvisual* nc){ +int ffmpeg_decode(ncvisual* nc){ if(nc->details->fmtctx == nullptr){ // not a file-backed ncvisual return -1; } @@ -288,7 +288,7 @@ auto ncvisual_create() -> ncvisual* { return nc; } -ncvisual* ncvisual_from_file(const char* filename) { +ncvisual* ffmpeg_from_file(const char* filename) { AVStream* st; ncvisual* ncv = ncvisual_create(); if(ncv == nullptr){ @@ -359,7 +359,7 @@ ncvisual* ncvisual_from_file(const char* filename) { // frame is set up in prep_details(), so that format can be set there, as // is necessary when it is prepared from inputs other than files. oframe // is set up whenever we convert to RGBA. - if(ncvisual_decode(ncv)){ + if(ffmpeg_decode(ncv)){ goto err; } return ncv; @@ -435,7 +435,7 @@ int ncvisual_stream(notcurses* nc, ncvisual* ncv, float timescale, } return r; } - }while((ncerr = ncvisual_decode(ncv)) == 0); + }while((ncerr = ffmpeg_decode(ncv)) == 0); if(activevopts.n != vopts->n){ ncplane_destroy(activevopts.n); } @@ -446,13 +446,13 @@ int ncvisual_stream(notcurses* nc, ncvisual* ncv, float timescale, } int ncvisual_decode_loop(ncvisual* ncv){ - int r = ncvisual_decode(ncv); + int r = ffmpeg_decode(ncv); if(r == 1){ if(av_seek_frame(ncv->details->fmtctx, ncv->details->stream_index, 0, AVSEEK_FLAG_FRAME) < 0){ // FIXME log error return -1; } - if(ncvisual_decode(ncv) < 0){ + if(ffmpeg_decode(ncv) < 0){ return -1; } } @@ -589,8 +589,10 @@ static const ncvisual_implementation ffmpeg_impl = { .ncvisual_printbanner = ncvisual_printbanner, .ncvisual_blit = ffmpeg_blit, .ncvisual_create = ncvisual_create, + .ncvisual_from_file = ffmpeg_from_file, .ncvisual_details_seed = ncvisual_details_seed, .ncvisual_details_destroy = ncvisual_details_destroy, + .ncvisual_decode = ffmpeg_decode, .ncvisual_subtitle = ffmpeg_subtitle, .canopen_images = true, .canopen_videos = true, diff --git a/src/media/oiio.cpp b/src/media/oiio.cpp index ba117ff59..ac3f9f3a6 100644 --- a/src/media/oiio.cpp +++ b/src/media/oiio.cpp @@ -44,7 +44,7 @@ auto oiio_create() -> ncvisual* { return nc; } -ncvisual* ncvisual_from_file(const char* filename) { +ncvisual* oiio_from_file(const char* filename) { ncvisual* ncv = oiio_create(); if(ncv == nullptr){ return nullptr; @@ -58,14 +58,14 @@ ncvisual* ncvisual_from_file(const char* filename) { /*const auto &spec = ncv->details->image->spec_dimensions(0); std::cout << "Opened " << filename << ": " << spec.height << "x" << spec.width << "@" << spec.nchannels << " (" << spec.format << ")" << std::endl;*/ - if(ncvisual_decode(ncv)){ + if(oiio_decode(ncv)){ ncvisual_destroy(ncv); return nullptr; } return ncv; } -int ncvisual_decode(ncvisual* nc) { +int oiio_decode(ncvisual* nc) { //fprintf(stderr, "current subimage: %d frame: %p\n", nc->details->image->current_subimage(), nc->details->frame.get()); const auto &spec = nc->details->image->spec_dimensions(nc->details->framenum); if(nc->details->frame){ @@ -112,14 +112,14 @@ int ncvisual_decode(ncvisual* nc) { } int ncvisual_decode_loop(ncvisual* ncv){ - int r = ncvisual_decode(ncv); + int r = oiio_decode(ncv); if(r == 1){ OIIO::ImageSpec newspec; if(ncv->details->image->seek_subimage(0, 0, newspec)){ return -1; } ncv->details->framenum = 0; - if(ncvisual_decode(ncv) < 0){ + if(oiio_decode(ncv) < 0){ return -1; } } @@ -217,7 +217,7 @@ auto ncvisual_stream(notcurses* nc, ncvisual* ncv, float timescale, return r; } ++frame; - }while((ncerr = ncvisual_decode(ncv)) == 0); + }while((ncerr = oiio_decode(ncv)) == 0); if(activevopts.n != vopts->n){ ncplane_destroy(activevopts.n); } @@ -273,8 +273,10 @@ const static ncvisual_implementation oiio_impl = { .ncvisual_printbanner = oiio_printbanner, .ncvisual_blit = oiio_blit, .ncvisual_create = oiio_create, + .ncvisual_from_file = oiio_from_file, .ncvisual_details_seed = oiio_details_seed, .ncvisual_details_destroy = oiio_details_destroy, + .ncvisual_decode = oiio_decode, .ncvisual_subtitle = oiio_subtitle, .canopen_images = true, .canopen_videos = false,