From acef43c75928816ddbd387dd933e6580cccb52f6 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 7 Jan 2020 09:30:50 -0500 Subject: [PATCH] avcodec_parameters_to_context() #215 --- include/notcurses.h | 3 +++ src/lib/libav.c | 10 +++++++--- src/view/view.cpp | 9 ++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/notcurses.h b/include/notcurses.h index 2efc79b3c..f9a1e84fd 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -1618,6 +1618,9 @@ ncvisual_simple_streamer(struct notcurses* nc, struct ncvisual* ncv __attribute_ // Stream the entirety of the media, according to its own timing. Blocking, // obviously. streamer may be NULL; it is otherwise called for each frame, and // its return value handled as outlined for stream cb. Pretty raw; beware. +// If streamer() returns non-zero, the stream is aborted, and that value is +// returned. By convention, return a positive number to indicate intentional +// abort from within streamer(). API int ncvisual_stream(struct notcurses* nc, struct ncvisual* ncv, int* averr, streamcb streamer, void* curry); diff --git a/src/lib/libav.c b/src/lib/libav.c index e33ffc633..a75a6438f 100644 --- a/src/lib/libav.c +++ b/src/lib/libav.c @@ -20,7 +20,7 @@ void ncvisual_destroy(ncvisual* ncv){ avcodec_free_context(&ncv->codecctx); av_frame_free(&ncv->frame); av_freep(&ncv->oframe); - avcodec_parameters_free(&ncv->cparams); + //avcodec_parameters_free(&ncv->cparams); sws_freeContext(ncv->swsctx); av_packet_free(&ncv->packet); av_packet_free(&ncv->subtitle); @@ -234,16 +234,20 @@ ncvisual_open(const char* filename, int* averr){ //fprintf(stderr, "Couldn't find decoder for %s\n", filename); goto err; } + 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); goto err; } + if(avcodec_parameters_to_context(ncv->codecctx, st->codecpar) < 0){ + goto err; + } if((*averr = avcodec_open2(ncv->codecctx, ncv->codec, NULL)) < 0){ //fprintf(stderr, "Couldn't open codec for %s (%s)\n", filename, av_err2str(*averr)); goto err; } - if((ncv->cparams = avcodec_parameters_alloc()) == NULL){ + /*if((ncv->cparams = avcodec_parameters_alloc()) == NULL){ //fprintf(stderr, "Couldn't allocate codec params for %s\n", filename); *averr = AVERROR(ENOMEM); goto err; @@ -251,7 +255,7 @@ ncvisual_open(const char* filename, int* averr){ if((*averr = avcodec_parameters_from_context(ncv->cparams, ncv->codecctx)) < 0){ //fprintf(stderr, "Couldn't get codec params for %s (%s)\n", filename, av_err2str(*averr)); goto err; - } + }*/ if((ncv->frame = av_frame_alloc()) == NULL){ // fprintf(stderr, "Couldn't allocate frame for %s\n", filename); *averr = AVERROR(ENOMEM); diff --git a/src/view/view.cpp b/src/view/view.cpp index 8de81df17..97d6b1682 100644 --- a/src/view/view.cpp +++ b/src/view/view.cpp @@ -57,7 +57,14 @@ int perframe(struct notcurses* nc, struct ncvisual* ncv, void* vframecount){ ncplane_dim_yx(ncvisual_plane(ncv), &oldy, &oldx); keepy = oldy > dimy ? dimy : oldy; keepx = oldx > dimx ? dimx : oldx; - return ncplane_resize(ncvisual_plane(ncv), 0, 0, keepy, keepx, 0, 0, dimy, dimx); + char32_t keyp; + while((keyp = notcurses_getc_nblock(nc, nullptr)) != (char32_t)-1){ + if(keyp == NCKEY_RESIZE){ + return ncplane_resize(ncvisual_plane(ncv), 0, 0, keepy, keepx, 0, 0, dimy, dimx); + } + return 1; + } + return 0; } // can exit() directly. returns index in argv of first non-option param.