avcodec_parameters_to_context() #215

This commit is contained in:
nick black 2020-01-07 09:30:50 -05:00
parent 75f0ea6ca0
commit acef43c759
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 18 additions and 4 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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.