From 6e872935db95638edd73093d299608076eed7d9c Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 4 Nov 2010 23:07:04 +0000 Subject: Implement get_preset_file() in cmdutils.h and use it to factorize code from ffmpeg.c and ffserver.c. Originally committed as revision 25679 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffserver.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'ffserver.c') diff --git a/ffserver.c b/ffserver.c index 63bd267..fcc3359 100644 --- a/ffserver.c +++ b/ffserver.c @@ -3972,27 +3972,11 @@ static int ffserver_opt_preset(const char *arg, { FILE *f=NULL; char filename[1000], tmp[1000], tmp2[1000], line[1000]; - int i, ret = 0; - const char *base[3]= { getenv("FFMPEG_DATADIR"), - getenv("HOME"), - FFMPEG_DATADIR, - }; - - for(i=0; i<3 && !f; i++){ - if(!base[i]) - continue; - snprintf(filename, sizeof(filename), "%s%s/%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", arg); - f= fopen(filename, "r"); - if(!f){ - AVCodec *codec = avcodec_find_encoder(avctx->codec_id); - if (codec) { - snprintf(filename, sizeof(filename), "%s%s/%s-%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", codec->name, arg); - f= fopen(filename, "r"); - } - } - } + int ret = 0; + AVCodec *codec = avcodec_find_encoder(avctx->codec_id); - if(!f){ + if (!(f = get_preset_file(filename, sizeof(filename), arg, 0, + codec ? codec->name : NULL))) { fprintf(stderr, "File for preset '%s' not found\n", arg); return 1; } -- cgit v1.1