Re: [FFmpeg-devel] [PATCH 01/11] ffserver_config: cosmetic: simplify functions calls.

2014-11-17 Thread Reynaldo H. Verdejo Pinochet
Looks Good. Feel free to push.

Bests,

-- 
Reynaldo H. Verdejo Pinochet
Open Source Group
Samsung Research America / Silicon Valley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 01/11] ffserver_config: cosmetic: simplify functions calls.

2014-11-16 Thread Lukasz Marek
ffserver_save_avoption() and ffserver_opt_preset() have
redundant arguments. They can be obtained basing on media type.
This simplifies uses and reduce chance for a mistake.

Signed-off-by: Lukasz Marek 
---
 ffserver_config.c | 91 +++
 1 file changed, 45 insertions(+), 46 deletions(-)

diff --git a/ffserver_config.c b/ffserver_config.c
index 02c8431..6b80f02 100644
--- a/ffserver_config.c
+++ b/ffserver_config.c
@@ -31,8 +31,8 @@
 #include "cmdutils.h"
 #include "ffserver_config.h"
 
-static int ffserver_save_avoption(AVCodecContext *ctx, const char *opt, const 
char *arg,
-  AVDictionary **dict, int type, 
FFServerConfig *config, int line_num);
+static int ffserver_save_avoption(const char *opt, const char *arg, int type,
+  FFServerConfig *config, int line_num);
 static void vreport_config_error(const char *filename, int line_num, int 
log_level,
  int *errors, const char *fmt, va_list vl);
 static void report_config_error(const char *filename, int line_num, int 
log_level,
@@ -274,12 +274,25 @@ static int ffserver_set_codec(AVCodecContext *ctx, const 
char *codec_name, FFSer
 return 0;
 }
 
-static int ffserver_opt_preset(const char *arg, AVCodecContext *avctx, 
FFServerConfig *config, int line_num)
+static int ffserver_opt_preset(const char *arg, int type, FFServerConfig 
*config, int line_num)
 {
 FILE *f=NULL;
 char filename[1000], tmp[1000], tmp2[1000], line[1000];
 int ret = 0;
-AVCodec *codec = avcodec_find_encoder(avctx->codec_id);
+AVCodecContext *avctx;
+const AVCodec *codec;
+
+switch(type) {
+case AV_OPT_FLAG_AUDIO_PARAM:
+avctx = config->dummy_actx;
+break;
+case AV_OPT_FLAG_VIDEO_PARAM:
+avctx = config->dummy_vctx;
+break;
+default:
+av_assert0(0);
+}
+codec = avcodec_find_encoder(avctx->codec_id);
 
 if (!(f = get_preset_file(filename, sizeof(filename), arg, 0,
   codec ? codec->name : NULL))) {
@@ -306,29 +319,10 @@ static int ffserver_opt_preset(const char *arg, 
AVCodecContext *avctx, FFServerC
 av_log(NULL, AV_LOG_ERROR, "Subtitles preset found.\n");
 ret = AVERROR(EINVAL);
 break;
-} else {
-int type;
-AVDictionary **opts;
-
-switch(avctx->codec_type) {
-case AVMEDIA_TYPE_AUDIO:
-type = AV_OPT_FLAG_AUDIO_PARAM;
-opts = &config->audio_opts;
-break;
-case AVMEDIA_TYPE_VIDEO:
-type = AV_OPT_FLAG_VIDEO_PARAM;
-opts = &config->video_opts;
-break;
-default:
-ret = AVERROR(EINVAL);
-goto exit;
-}
-if (ffserver_save_avoption(avctx, tmp, tmp2, opts, type, config, 
line_num) < 0)
-break;
-}
+} else if (ffserver_save_avoption(tmp, tmp2, type, config, line_num) < 
0)
+break;
 }
 
-  exit:
 fclose(f);
 
 return ret;
@@ -430,8 +424,7 @@ static int ffserver_set_float_param(float *dest, const char 
*value, float factor
 return AVERROR(EINVAL);
 }
 
-static int ffserver_save_avoption(AVCodecContext *ctx, const char *opt, const 
char *arg, AVDictionary **dict,
-  int type, FFServerConfig *config, int 
line_num)
+static int ffserver_save_avoption(const char *opt, const char *arg, int type, 
FFServerConfig *config, int line_num)
 {
 static int hinted = 0;
 int ret = 0;
@@ -440,6 +433,26 @@ static int ffserver_save_avoption(AVCodecContext *ctx, 
const char *opt, const ch
 const char *option = NULL;
 const char *codec_name = NULL;
 char buff[1024];
+AVCodecContext *ctx;
+AVDictionary **dict;
+enum AVCodecID guessed_codec_id;
+
+switch (type) {
+case AV_OPT_FLAG_VIDEO_PARAM:
+ctx = config->dummy_vctx;
+dict = &config->video_opts;
+guessed_codec_id = config->guessed_video_codec_id != AV_CODEC_ID_NONE ?
+   config->guessed_video_codec_id : AV_CODEC_ID_H264;
+break;
+case AV_OPT_FLAG_AUDIO_PARAM:
+ctx = config->dummy_actx;
+dict = &config->audio_opts;
+guessed_codec_id = config->guessed_audio_codec_id != AV_CODEC_ID_NONE ?
+   config->guessed_audio_codec_id : AV_CODEC_ID_AAC;
+break;
+default:
+av_assert0(0);
+}
 
 if (strchr(opt, ':')) {
 //explicit private option
@@ -461,23 +474,11 @@ static int ffserver_save_avoption(AVCodecContext *ctx, 
const char *opt, const ch
 report_config_error(config->filename, line_num, AV_LOG_ERROR,
 &config->errors, "Option not found: %s\n", opt);
 if (!hinted && ctx->codec_id == AV_CODEC_ID_NONE) {
-enum AVCodecID id;