[FFmpeg-devel] [PATCH 05/11] ffserver: allow skip setting defaults

Lukasz Marek lukasz.m.luki2 at gmail.com
Mon Nov 17 02:46:52 CET 2014


Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
---
 doc/ffserver.texi | 10 ++++++++++
 ffserver.c        |  1 +
 ffserver_config.c | 30 ++++++++++++++++++++++++++++++
 ffserver_config.h |  2 ++
 4 files changed, 43 insertions(+)

diff --git a/doc/ffserver.texi b/doc/ffserver.texi
index b7c5b6a..d3ff13e 100644
--- a/doc/ffserver.texi
+++ b/doc/ffserver.texi
@@ -408,6 +408,11 @@ ignored, and the log is written to standard output.
 Set no-daemon mode. This option is currently ignored since now
 @command{ffserver} will always work in no-daemon mode, and is
 deprecated.
+
+ at item UseDefaults
+ at item NoDefaults
+Control whether default codec options are used for the all streams or not.
+Each stream may overwrite this setting for its own. Default is @var{UseDefaults}.
 @end table
 
 @section Feed section
@@ -571,6 +576,11 @@ deprecated in favor of @option{Metadata}.
 @item Metadata @var{key} @var{value}
 Set metadata value on the output stream.
 
+ at item UseDefaults
+ at item NoDefaults
+Control whether default codec options are used for the stream or not.
+Default is @var{UseDefaults} unless disabled globally.
+
 @item NoAudio
 @item NoVideo
 Suppress audio/video.
diff --git a/ffserver.c b/ffserver.c
index 933eb0e..e24243d 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -201,6 +201,7 @@ static FFServerConfig config = {
     .nb_max_http_connections = 2000,
     .nb_max_connections = 5,
     .max_bandwidth = 1000,
+    .use_defaults = 1,
 };
 
 static void new_connection(int server_fd, int is_rtsp);
diff --git a/ffserver_config.c b/ffserver_config.c
index b372e4a..355111c 100644
--- a/ffserver_config.c
+++ b/ffserver_config.c
@@ -188,6 +188,8 @@ static void add_codec(FFServerStream *stream, AVCodecContext *av, FFServerConfig
     if (av_dict_count(*opts))
         av_log(NULL, AV_LOG_ERROR, "Something went wrong, %d options not set!!!\n", av_dict_count(*opts));
 
+    if (config->stream_use_defaults) {
+    //TODO: reident
     /* compute default parameters */
     switch(av->codec_type) {
     case AVMEDIA_TYPE_AUDIO:
@@ -252,6 +254,25 @@ static void add_codec(FFServerStream *stream, AVCodecContext *av, FFServerConfig
     default:
         abort();
     }
+    } else {
+        switch(av->codec_type) {
+        case AVMEDIA_TYPE_AUDIO:
+            if (av->bit_rate == 0)
+                report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
+                                    &config->errors, "audio bit rate is not set\n");
+            if (av->sample_rate == 0)
+                report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
+                                    &config->errors, "audio sample rate is not set\n");
+            break;
+        case AVMEDIA_TYPE_VIDEO:
+            if (av->width == 0 || av->height == 0)
+                report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
+                                    &config->errors, "video size is not set\n");
+            break;
+        default:
+            av_assert0(0);
+        }
+    }
 
     st = av_mallocz(sizeof(AVStream));
     if (!st)
@@ -579,6 +600,10 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
             ffserver_get_arg(config->logfilename, sizeof(config->logfilename), p);
     } else if (!av_strcasecmp(cmd, "LoadModule")) {
         ERROR("Loadable modules are no longer supported\n");
+    } else if (!av_strcasecmp(cmd, "NoDefaults")) {
+        config->use_defaults = 0;
+    } else if (!av_strcasecmp(cmd, "UseDefaults")) {
+        config->use_defaults = 1;
     } else
         ERROR("Incorrect keyword: '%s'\n", cmd);
     return 0;
@@ -734,6 +759,7 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
             config->guessed_audio_codec_id = AV_CODEC_ID_NONE;
             config->guessed_video_codec_id = AV_CODEC_ID_NONE;
         }
+        config->stream_use_defaults = config->use_defaults;
         *pstream = stream;
         return 0;
     }
@@ -1028,6 +1054,10 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
     } else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, "ReadOnlyFile")) {
         ffserver_get_arg(stream->feed_filename, sizeof(stream->feed_filename),
                 p);
+    } else if (!av_strcasecmp(cmd, "UseDefaults")) {
+        config->stream_use_defaults = 1;
+    } else if (!av_strcasecmp(cmd, "NoDefaults")) {
+        config->stream_use_defaults = 0;
     } else {
         ERROR("Invalid entry '%s' inside <Stream></Stream>\n", cmd);
     }
diff --git a/ffserver_config.h b/ffserver_config.h
index 60e88ec..4e1e0e0 100644
--- a/ffserver_config.h
+++ b/ffserver_config.h
@@ -106,6 +106,7 @@ typedef struct FFServerConfig {
     struct sockaddr_in rtsp_addr;
     int errors;
     int warnings;
+    int use_defaults;
     // Following variables MUST NOT be used outside configuration parsing code.
     enum AVCodecID guessed_audio_codec_id;
     enum AVCodecID guessed_video_codec_id;
@@ -116,6 +117,7 @@ typedef struct FFServerConfig {
     int no_audio;
     int no_video;
     int line_num;
+    int stream_use_defaults;
 } FFServerConfig;
 
 void ffserver_get_arg(char *buf, int buf_size, const char **pp);
-- 
1.9.1



More information about the ffmpeg-devel mailing list