mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
ffmpeg: kill per-ncviusal subtitle context memory leak
This commit is contained in:
parent
fe50c8ba29
commit
740093fbb3
@ -213,7 +213,7 @@ animate(struct notcurses* nc, struct ncprogbar* left, struct ncprogbar* right){
|
||||
struct timespec expected;
|
||||
clock_gettime(CLOCK_MONOTONIC, &expected);
|
||||
uint64_t expect_ns = timespec_to_ns(&expected);
|
||||
uint64_t channels;
|
||||
uint64_t channels = 0;
|
||||
int length = 1;
|
||||
do{
|
||||
get_next_head(std, ncprogbar_plane(left), ncprogbar_plane(right),
|
||||
|
@ -1060,21 +1060,21 @@ int drop_signals(void* nc);
|
||||
void ncvisual_printbanner(const notcurses* nc);
|
||||
|
||||
typedef struct ncvisual_implementation {
|
||||
int (*ncvisual_init)(int loglevel);
|
||||
void (*ncvisual_printbanner)(const struct notcurses* nc);
|
||||
int (*ncvisual_blit)(struct ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
const struct blitset* bset, int placey, int placex,
|
||||
int begy, int begx, int leny, int lenx,
|
||||
bool blendcolors);
|
||||
struct ncvisual* (*ncvisual_create)(void);
|
||||
struct ncvisual* (*ncvisual_from_file)(const char* fname);
|
||||
int (*visual_init)(int loglevel);
|
||||
void (*visual_printbanner)(const struct notcurses* nc);
|
||||
int (*visual_blit)(struct ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
const struct blitset* bset, int placey, int placex,
|
||||
int begy, int begx, int leny, int lenx,
|
||||
bool blendcolors);
|
||||
struct ncvisual* (*visual_create)(void);
|
||||
struct ncvisual* (*visual_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);
|
||||
void (*visual_details_seed)(struct ncvisual* ncv);
|
||||
void (*visual_details_destroy)(struct ncvisual_details* deets);
|
||||
int (*visual_decode)(struct ncvisual* nc);
|
||||
char* (*visual_subtitle)(const struct ncvisual* ncv);
|
||||
bool canopen_images;
|
||||
bool canopen_videos;
|
||||
} ncvisual_implementation;
|
||||
|
@ -631,6 +631,27 @@ int ncplane_destroy(ncplane* ncp){
|
||||
return -1;
|
||||
}
|
||||
//notcurses_debug(ncplane_notcurses(ncp), stderr);
|
||||
int ret = 0;
|
||||
// dissolve our binding from behind (->bprev is either NULL, or its
|
||||
// predecessor on the bound list's ->bnext, or &ncp->boundto->blist)
|
||||
if(ncp->bprev){
|
||||
if( (*ncp->bprev = ncp->bnext) ){
|
||||
ncp->bnext->bprev = ncp->bprev;
|
||||
}
|
||||
}
|
||||
// recursively reparent our children to the plane to which we are bound.
|
||||
// this will extract each one from the sibling list.
|
||||
struct ncplane* bound = ncp->blist;
|
||||
while(bound){
|
||||
struct ncplane* tmp = bound->bnext;
|
||||
if(ncplane_reparent_family(bound, ncp->boundto) == NULL){
|
||||
ret = -1;
|
||||
}
|
||||
bound = tmp;
|
||||
}
|
||||
// extract ourselves from the z-axis. do this *after* reparenting, in case
|
||||
// reparenting shifts up the z-axis somehow (though i don't think it can,
|
||||
// at least not within a pile?).
|
||||
if(ncp->above){
|
||||
ncp->above->below = ncp->below;
|
||||
}else{
|
||||
@ -641,20 +662,7 @@ int ncplane_destroy(ncplane* ncp){
|
||||
}else{
|
||||
ncplane_pile(ncp)->bottom = ncp->above;
|
||||
}
|
||||
if(ncp->bprev){
|
||||
if( (*ncp->bprev = ncp->bnext) ){
|
||||
ncp->bnext->bprev = ncp->bprev;
|
||||
}
|
||||
}
|
||||
int ret = 0;
|
||||
struct ncplane* bound = ncp->blist;
|
||||
while(bound){
|
||||
struct ncplane* tmp = bound->bnext;
|
||||
if(ncplane_reparent_family(bound, ncp->boundto) == NULL){
|
||||
ret = -1;
|
||||
}
|
||||
bound = tmp;
|
||||
}
|
||||
// no need to NULL out our ->boundto, as we are about to die (and unlinked)
|
||||
free_plane(ncp);
|
||||
return ret;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ auto ncvisual_decode(ncvisual* nc) -> int {
|
||||
if(!visual_implementation){
|
||||
return -1;
|
||||
}
|
||||
return visual_implementation->ncvisual_decode(nc);
|
||||
return visual_implementation->visual_decode(nc);
|
||||
}
|
||||
|
||||
auto ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
@ -19,7 +19,7 @@ auto ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
bool blendcolors) -> int {
|
||||
int ret = -1;
|
||||
if(visual_implementation){
|
||||
if(visual_implementation->ncvisual_blit(ncv, rows, cols, n, bset, placey, placex,
|
||||
if(visual_implementation->visual_blit(ncv, rows, cols, n, bset, placey, placex,
|
||||
begy, begx, leny, lenx, blendcolors) >= 0){
|
||||
ret = 0;
|
||||
}
|
||||
@ -37,13 +37,13 @@ auto ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
// have been prepared already in 'ncv'.
|
||||
auto ncvisual_details_seed(struct ncvisual* ncv) -> void {
|
||||
if(visual_implementation){
|
||||
visual_implementation->ncvisual_details_seed(ncv);
|
||||
visual_implementation->visual_details_seed(ncv);
|
||||
}
|
||||
}
|
||||
|
||||
auto ncvisual_init(int loglevel) -> int {
|
||||
if(visual_implementation){
|
||||
return visual_implementation->ncvisual_init(loglevel);
|
||||
return visual_implementation->visual_init(loglevel);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -52,19 +52,19 @@ auto ncvisual_from_file(const char* filename) -> ncvisual* {
|
||||
if(!visual_implementation){
|
||||
return nullptr;
|
||||
}
|
||||
return visual_implementation->ncvisual_from_file(filename);
|
||||
return visual_implementation->visual_from_file(filename);
|
||||
}
|
||||
|
||||
auto ncvisual_create(void) -> ncvisual* {
|
||||
if(visual_implementation){
|
||||
return visual_implementation->ncvisual_create();
|
||||
return visual_implementation->visual_create();
|
||||
}
|
||||
return new ncvisual{};
|
||||
}
|
||||
|
||||
auto ncvisual_printbanner(const notcurses* nc) -> void {
|
||||
if(visual_implementation){
|
||||
visual_implementation->ncvisual_printbanner(nc);
|
||||
visual_implementation->visual_printbanner(nc);
|
||||
}else{
|
||||
term_fg_palindex(nc, stderr, nc->tcache.colors <= 88 ? 1 % nc->tcache.colors : 0xcb);
|
||||
fprintf(stderr, "\n Warning! Notcurses was built without multimedia support.\n");
|
||||
@ -546,7 +546,7 @@ auto ncvisual_from_plane(const ncplane* n, ncblitter_e blit, int begy, int begx,
|
||||
|
||||
auto ncvisual_details_destroy(ncvisual_details* deets){
|
||||
if(visual_implementation){
|
||||
visual_implementation->ncvisual_details_destroy(deets);
|
||||
visual_implementation->visual_details_destroy(deets);
|
||||
}
|
||||
}
|
||||
|
||||
@ -670,7 +670,7 @@ auto ncvisual_subtitle(const ncvisual* ncv) -> char* {
|
||||
if(!visual_implementation){
|
||||
return nullptr;
|
||||
}
|
||||
return visual_implementation->ncvisual_subtitle(ncv);
|
||||
return visual_implementation->visual_subtitle(ncv);
|
||||
}
|
||||
|
||||
auto ncvisual_resize(ncvisual* nc, int rows, int cols) -> int {
|
||||
|
@ -530,7 +530,7 @@ int ffmpeg_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto ncvisual_details_seed(ncvisual* ncv) -> void {
|
||||
auto ffmpeg_details_seed(ncvisual* ncv) -> void {
|
||||
assert(nullptr == ncv->details->oframe);
|
||||
ncv->details->frame->data[0] = reinterpret_cast<uint8_t*>(ncv->data);
|
||||
ncv->details->frame->data[1] = nullptr;
|
||||
@ -571,8 +571,9 @@ void ncvisual_printbanner(const notcurses* nc __attribute__ ((unused))){
|
||||
LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR, LIBSWSCALE_VERSION_MICRO);
|
||||
}
|
||||
|
||||
auto ncvisual_details_destroy(ncvisual_details* deets) -> void {
|
||||
auto ffmpeg_details_destroy(ncvisual_details* deets) -> void {
|
||||
avcodec_close(deets->codecctx);
|
||||
avcodec_free_context(&deets->subtcodecctx);
|
||||
avcodec_free_context(&deets->codecctx);
|
||||
av_frame_free(&deets->frame);
|
||||
av_freep(&deets->oframe);
|
||||
@ -585,15 +586,15 @@ auto ncvisual_details_destroy(ncvisual_details* deets) -> void {
|
||||
}
|
||||
|
||||
static const ncvisual_implementation ffmpeg_impl = {
|
||||
.ncvisual_init = ffmpeg_init,
|
||||
.ncvisual_printbanner = ncvisual_printbanner,
|
||||
.ncvisual_blit = ffmpeg_blit,
|
||||
.ncvisual_create = ffmpeg_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,
|
||||
.visual_init = ffmpeg_init,
|
||||
.visual_printbanner = ncvisual_printbanner,
|
||||
.visual_blit = ffmpeg_blit,
|
||||
.visual_create = ffmpeg_create,
|
||||
.visual_from_file = ffmpeg_from_file,
|
||||
.visual_details_seed = ffmpeg_details_seed,
|
||||
.visual_details_destroy = ffmpeg_details_destroy,
|
||||
.visual_decode = ffmpeg_decode,
|
||||
.visual_subtitle = ffmpeg_subtitle,
|
||||
.canopen_images = true,
|
||||
.canopen_videos = true,
|
||||
};
|
||||
|
@ -269,15 +269,15 @@ void oiio_printbanner(const notcurses* nc __attribute__ ((unused))){
|
||||
}
|
||||
|
||||
const static ncvisual_implementation oiio_impl = {
|
||||
.ncvisual_init = oiio_init,
|
||||
.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,
|
||||
.visual_init = oiio_init,
|
||||
.visual_printbanner = oiio_printbanner,
|
||||
.visual_blit = oiio_blit,
|
||||
.visual_create = oiio_create,
|
||||
.visual_from_file = oiio_from_file,
|
||||
.visual_details_seed = oiio_details_seed,
|
||||
.visual_details_destroy = oiio_details_destroy,
|
||||
.visual_decode = oiio_decode,
|
||||
.visual_subtitle = oiio_subtitle,
|
||||
.canopen_images = true,
|
||||
.canopen_videos = false,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user