stereoplay

changeset 6:8fc045d33d62 tip

updated the code to work with more recent ffmpeg versions
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 26 Sep 2020 14:26:39 +0300
parents ba7d221f6725
children
files .hgignore Makefile src/stereoplay.c src/vid.c
diffstat 4 files changed, 23 insertions(+), 17 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Sat Sep 26 14:26:39 2020 +0300
     1.3 @@ -0,0 +1,3 @@
     1.4 +\.o
     1.5 +\.swp
     1.6 +^stereoplay$
     2.1 --- a/Makefile	Thu Nov 03 22:01:01 2011 +0200
     2.2 +++ b/Makefile	Sat Sep 26 14:26:39 2020 +0300
     2.3 @@ -8,7 +8,7 @@
     2.4  
     2.5  CC = gcc
     2.6  CFLAGS = -pedantic -Wall -g -O2
     2.7 -LDFLAGS = $(gllibs_$(shell uname -s)) -lavformat -lavcodec -lswscale
     2.8 +LDFLAGS = $(gllibs_$(shell uname -s)) -lavformat -lavcodec -lavutil -lswscale
     2.9  
    2.10  gllibs_Linux = -lGL -lGLU -lglut -lGLEW
    2.11  gllibs_Darwin = -framework OpenGL -framework GLUT -lGLEW
     3.1 --- a/src/stereoplay.c	Thu Nov 03 22:01:01 2011 +0200
     3.2 +++ b/src/stereoplay.c	Sat Sep 26 14:26:39 2020 +0300
     3.3 @@ -146,11 +146,13 @@
     3.4  		_exit(0);
     3.5  	}
     3.6  
     3.7 +	fcntl(pfd[0], F_SETFL, fcntl(pfd[0], F_GETFL) | O_NONBLOCK);
     3.8 +
     3.9  	dpy = glXGetCurrentDisplay();
    3.10  	xsock = ConnectionNumber(dpy);
    3.11  
    3.12  	for(;;) {
    3.13 -		int res;
    3.14 +		/*int res;
    3.15  		fd_set rdset;
    3.16  
    3.17  		FD_ZERO(&rdset);
    3.18 @@ -171,8 +173,9 @@
    3.19  				upd_frame = 1;
    3.20  				glutPostRedisplay();
    3.21  			}
    3.22 -		}
    3.23 +		}*/
    3.24  
    3.25 +		upd_frame = 1;
    3.26  		glutMainLoopEvent();
    3.27  		if(busy_loop) {
    3.28  			glutPostRedisplay();
     4.1 --- a/src/vid.c	Thu Nov 03 22:01:01 2011 +0200
     4.2 +++ b/src/vid.c	Sat Sep 26 14:26:39 2020 +0300
     4.3 @@ -1,6 +1,6 @@
     4.4  /*
     4.5  Stereoplay - an OpenGL stereoscopic video player.
     4.6 -Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
     4.7 +Copyright (C) 2011-2020  John Tsiombikas <nuclear@member.fsf.org>
     4.8  
     4.9  This program is free software: you can redistribute it and/or modify
    4.10  it under the terms of the GNU General Public License as published by
    4.11 @@ -15,11 +15,11 @@
    4.12  You should have received a copy of the GNU General Public License
    4.13  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    4.14  */
    4.15 -
    4.16  #include <stdio.h>
    4.17  #include <libavcodec/avcodec.h>
    4.18  #include <libavformat/avformat.h>
    4.19  #include <libswscale/swscale.h>
    4.20 +#include <libavutil/imgutils.h>
    4.21  #include "vid.h"
    4.22  
    4.23  struct video_file {
    4.24 @@ -49,13 +49,13 @@
    4.25  	}
    4.26  	memset(vf, 0, sizeof *vf);
    4.27  
    4.28 -	if(av_open_input_file(&vf->avctx, fname, 0, 0, 0) != 0) {
    4.29 +	if(avformat_open_input(&vf->avctx, fname, 0, 0) != 0) {
    4.30  		fprintf(stderr, "open_video(%s): failed to open file\n", fname);
    4.31  		vid_close(vf);
    4.32  		return 0;
    4.33  	}
    4.34  
    4.35 -	if(av_find_stream_info(vf->avctx) < 0) {
    4.36 +	if(avformat_find_stream_info(vf->avctx, 0) < 0) {
    4.37  		fprintf(stderr, "open_video(%s): failed to find stream info\n", fname);
    4.38  		vid_close(vf);
    4.39  		return 0;
    4.40 @@ -81,20 +81,20 @@
    4.41  		return 0;
    4.42  	}
    4.43  
    4.44 -	if(avcodec_open(vf->cctx, vf->codec) < 0) {
    4.45 +	if(avcodec_open2(vf->cctx, vf->codec, 0) < 0) {
    4.46  		fprintf(stderr, "open_video(%s): failed to open codec\n", fname);
    4.47  		vid_close(vf);
    4.48  		return 0;
    4.49  	}
    4.50  
    4.51 -	if(!(vf->frm = avcodec_alloc_frame()) || !(vf->rgbfrm = avcodec_alloc_frame())) {
    4.52 +	if(!(vf->frm = av_frame_alloc()) || !(vf->rgbfrm = av_frame_alloc())) {
    4.53  		fprintf(stderr, "open_video(%s): failed to allocate frame\n", fname);
    4.54  		vid_close(vf);
    4.55  		return 0;
    4.56  	}
    4.57  
    4.58  	vf->sws = sws_getContext(vf->cctx->width, vf->cctx->height, vf->cctx->pix_fmt,
    4.59 -			vf->cctx->width, vf->cctx->height, PIX_FMT_RGB32, SWS_POINT, 0, 0, 0);
    4.60 +			vf->cctx->width, vf->cctx->height, AV_PIX_FMT_RGB32, SWS_POINT, 0, 0, 0);
    4.61  	if(!vf->sws) {
    4.62  		fprintf(stderr, "open_video(%s): failed to allocate sws context\n", fname);
    4.63  		vid_close(vf);
    4.64 @@ -117,7 +117,7 @@
    4.65  	if(vf->rgbfrm) av_free(vf->rgbfrm);
    4.66  	if(vf->frm) av_free(vf->frm);
    4.67  	if(vf->cctx) avcodec_close(vf->cctx);
    4.68 -	if(vf->avctx) av_close_input_file(vf->avctx);
    4.69 +	if(vf->avctx) avformat_close_input(&vf->avctx);
    4.70  	free(vf);
    4.71  }
    4.72  
    4.73 @@ -153,22 +153,22 @@
    4.74  {
    4.75  	AVPacket packet;
    4.76  	int frame_done = 0;
    4.77 -	AVPicture *rgbfrm = (AVPicture*)vf->rgbfrm;
    4.78 -	AVPicture *frm = (AVPicture*)vf->frm;
    4.79  
    4.80 -	avpicture_fill((AVPicture*)vf->rgbfrm, (uint8_t*)img, PIX_FMT_RGB32, vf->cctx->width, vf->cctx->height);
    4.81 +	av_image_fill_arrays(vf->rgbfrm->data, vf->rgbfrm->linesize, (unsigned char*)img,
    4.82 +			AV_PIX_FMT_RGB32, vf->cctx->width, vf->cctx->height, 1);
    4.83  
    4.84  	while(av_read_frame(vf->avctx, &packet) >= 0) {
    4.85  		if(packet.stream_index == vf->vstream) {
    4.86  			avcodec_decode_video2(vf->cctx, vf->frm, &frame_done, &packet);
    4.87  
    4.88  			if(frame_done) {
    4.89 -				sws_scale(vf->sws, frm->data, frm->linesize, 0, vf->cctx->height, rgbfrm->data, rgbfrm->linesize);
    4.90 -				av_free_packet(&packet);
    4.91 +				sws_scale(vf->sws, vf->frm->data, vf->frm->linesize, 0, vf->cctx->height,
    4.92 +						vf->rgbfrm->data, vf->rgbfrm->linesize);
    4.93 +				av_packet_unref(&packet);
    4.94  				return 0;
    4.95  			}
    4.96  		}
    4.97 -		av_free_packet(&packet);
    4.98 +		av_packet_unref(&packet);
    4.99  	}
   4.100  
   4.101  	return -1;