[FFmpeg-devel] [PATCH] lavu/log: use const objs

Lukasz Marek lukasz.m.luki2 at gmail.com
Sun Nov 30 18:37:26 CET 2014


Logging system must not change state of passed objects.
Missing consts also blocks many other places where functions
should have const arguments, but it would cause a warning.

Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
---
 cmdutils.c                |  4 ++--
 cmdutils.h                |  2 +-
 ffmpeg.c                  |  2 +-
 ffprobe.c                 |  6 +++---
 ffserver.c                |  2 +-
 libavcodec/options.c      |  9 +++++----
 libavcodec/resample.c     |  2 +-
 libavfilter/avfilter.c    |  4 ++--
 libavfilter/framesync.c   |  2 +-
 libavformat/avio.c        |  4 ++--
 libavformat/options.c     |  8 ++++----
 libavutil/log.c           | 34 +++++++++++++++++-----------------
 libavutil/log.h           | 18 +++++++++---------
 libpostproc/postprocess.c |  2 +-
 libswresample/options.c   |  2 +-
 libswscale/options.c      |  2 +-
 16 files changed, 52 insertions(+), 51 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index b68dae9..3623d65 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -90,12 +90,12 @@ void uninit_opts(void)
     av_dict_free(&resample_opts);
 }
 
-void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
+void log_callback_help(FF_CONST_AVUTIL55 void *ptr, int level, const char *fmt, va_list vl)
 {
     vfprintf(stdout, fmt, vl);
 }
 
-static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl)
+static void log_callback_report(FF_CONST_AVUTIL55 void *ptr, int level, const char *fmt, va_list vl)
 {
     va_list vl2;
     char line[1024];
diff --git a/cmdutils.h b/cmdutils.h
index f6ad44c..5043e4c 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -76,7 +76,7 @@ void uninit_opts(void);
  * Trivial log callback.
  * Only suitable for opt_help and similar since it lacks prefix handling.
  */
-void log_callback_help(void* ptr, int level, const char* fmt, va_list vl);
+void log_callback_help(FF_CONST_AVUTIL55 void* ptr, int level, const char* fmt, va_list vl);
 
 /**
  * Override the cpuflags.
diff --git a/ffmpeg.c b/ffmpeg.c
index b44401f..803bb76 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3882,7 +3882,7 @@ static int64_t getmaxrss(void)
 #endif
 }
 
-static void log_callback_null(void *ptr, int level, const char *fmt, va_list vl)
+static void log_callback_null(FF_CONST_AVUTIL55 void *ptr, int level, const char *fmt, va_list vl)
 {
 }
 
diff --git a/ffprobe.c b/ffprobe.c
index 24ecafd..9f9f0e3 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -343,9 +343,9 @@ struct WriterContext {
     unsigned int string_validation_utf8_flags;
 };
 
-static const char *writer_get_name(void *p)
+static const char *writer_get_name(FF_CONST_AVUTIL55 void *p)
 {
-    WriterContext *wctx = p;
+    const WriterContext *wctx = p;
     return wctx->writer->name;
 }
 
@@ -748,7 +748,7 @@ static const Writer *writer_get_by_name(const char *name)
 /* WRITERS */
 
 #define DEFINE_WRITER_CLASS(name)                   \
-static const char *name##_get_name(void *ctx)       \
+static const char *name##_get_name(FF_CONST_AVUTIL55 void *ctx) \
 {                                                   \
     return #name ;                                  \
 }                                                   \
diff --git a/ffserver.c b/ffserver.c
index 8ef51a1..ae40b96 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -333,7 +333,7 @@ static void http_log(const char *fmt, ...)
     va_end(vargs);
 }
 
-static void http_av_log(void *ptr, int level, const char *fmt, va_list vargs)
+static void http_av_log(FF_CONST_AVUTIL55 void *ptr, int level, const char *fmt, va_list vargs)
 {
     static int print_prefix = 1;
     AVClass *avc = ptr ? *(AVClass**)ptr : NULL;
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 7f9fb07..957a12d 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -35,8 +35,9 @@
 
 #include "options_table.h"
 
-static const char* context_to_name(void* ptr) {
-    AVCodecContext *avc= ptr;
+static const char* context_to_name(FF_CONST_AVUTIL55 void* ptr)
+{
+    const AVCodecContext *avc= ptr;
 
     if(avc && avc->codec && avc->codec->name)
         return avc->codec->name;
@@ -68,9 +69,9 @@ static const AVClass *codec_child_class_next(const AVClass *prev)
     return NULL;
 }
 
-static AVClassCategory get_category(void *ptr)
+static AVClassCategory get_category(FF_CONST_AVUTIL55 void *ptr)
 {
-    AVCodecContext* avctx = ptr;
+    const AVCodecContext* avctx = ptr;
     if(avctx->codec && avctx->codec->decode) return AV_CLASS_CATEGORY_DECODER;
     else                                     return AV_CLASS_CATEGORY_ENCODER;
 }
diff --git a/libavcodec/resample.c b/libavcodec/resample.c
index c45aa16..18fb86d 100644
--- a/libavcodec/resample.c
+++ b/libavcodec/resample.c
@@ -38,7 +38,7 @@
 
 struct AVResampleContext;
 
-static const char *context_to_name(void *ptr)
+static const char *context_to_name(FF_CONST_AVUTIL55 void *ptr)
 {
     return "audioresample";
 }
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 963f5e6..7f0ce37 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -546,9 +546,9 @@ int avfilter_pad_count(const AVFilterPad *pads)
     return count;
 }
 
-static const char *default_filter_name(void *filter_ctx)
+static const char *default_filter_name(FF_CONST_AVUTIL55 void *filter_ctx)
 {
-    AVFilterContext *ctx = filter_ctx;
+    const AVFilterContext *ctx = filter_ctx;
     return ctx->name ? ctx->name : ctx->filter->name;
 }
 
diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c
index 12db50c..fdc48fc 100644
--- a/libavfilter/framesync.c
+++ b/libavfilter/framesync.c
@@ -26,7 +26,7 @@
 
 #define OFFSET(member) offsetof(FFFrameSync, member)
 
-static const char *framesync_name(void *ptr)
+static const char *framesync_name(FF_CONST_AVUTIL55 void *ptr)
 {
     return "framesync";
 }
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 326bb0a..1ddbaa9 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -39,9 +39,9 @@ URLProtocol *ffurl_protocol_next(const URLProtocol *prev)
 
 /** @name Logging context. */
 /*@{*/
-static const char *urlcontext_to_name(void *ptr)
+static const char *urlcontext_to_name(FF_CONST_AVUTIL55 void *ptr)
 {
-    URLContext *h = (URLContext *)ptr;
+    const URLContext *h = (URLContext *)ptr;
     if (h->prot)
         return h->prot->name;
     else
diff --git a/libavformat/options.c b/libavformat/options.c
index 5044043..ce45ac1 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -29,9 +29,9 @@
 
 #include "options_table.h"
 
-static const char* format_to_name(void* ptr)
+static const char* format_to_name(FF_CONST_AVUTIL55 void* ptr)
 {
-    AVFormatContext* fc = (AVFormatContext*) ptr;
+    const AVFormatContext* fc = (AVFormatContext*) ptr;
     if(fc->iformat) return fc->iformat->name;
     else if(fc->oformat) return fc->oformat->name;
     else return "NULL";
@@ -77,9 +77,9 @@ static const AVClass *format_child_class_next(const AVClass *prev)
     return NULL;
 }
 
-static AVClassCategory get_category(void *ptr)
+static AVClassCategory get_category(FF_CONST_AVUTIL55 void *ptr)
 {
-    AVFormatContext* s = ptr;
+    const AVFormatContext* s = ptr;
     if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
     else           return AV_CLASS_CATEGORY_MUXER;
 }
diff --git a/libavutil/log.c b/libavutil/log.c
index 2091316..3f734ab 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -181,14 +181,14 @@ static void colored_fputs(int level, int tint, const char *str)
 
 }
 
-const char *av_default_item_name(void *ptr)
+const char *av_default_item_name(FF_CONST_AVUTIL55 void *ptr)
 {
-    return (*(AVClass **) ptr)->class_name;
+    return (*(const AVClass **) ptr)->class_name;
 }
 
-AVClassCategory av_default_get_category(void *ptr)
+AVClassCategory av_default_get_category(FF_CONST_AVUTIL55 void *ptr)
 {
-    return (*(AVClass **) ptr)->category;
+    return (*(const AVClass **) ptr)->category;
 }
 
 static void sanitize(uint8_t *line){
@@ -199,8 +199,8 @@ static void sanitize(uint8_t *line){
     }
 }
 
-static int get_category(void *ptr){
-    AVClass *avc = *(AVClass **) ptr;
+static int get_category(FF_CONST_AVUTIL55 void *ptr){
+    const AVClass *avc = *(const AVClass **) ptr;
     if(    !avc
         || (avc->version&0xFF)<100
         ||  avc->version < (51 << 16 | 59 << 8)
@@ -236,10 +236,10 @@ static const char *get_level_str(int level)
     }
 }
 
-static void format_line(void *avcl, int level, const char *fmt, va_list vl,
+static void format_line(FF_CONST_AVUTIL55 void *avcl, int level, const char *fmt, va_list vl,
                         AVBPrint part[4], int *print_prefix, int type[2])
 {
-    AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
+    const AVClass* avc = avcl ? *(const AVClass **) avcl : NULL;
     av_bprint_init(part+0, 0, 1);
     av_bprint_init(part+1, 0, 1);
     av_bprint_init(part+2, 0, 1);
@@ -248,7 +248,7 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
     if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
     if (*print_prefix && avc) {
         if (avc->parent_log_context_offset) {
-            AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
+            const AVClass** parent = *(const AVClass ***) (((uint8_t *) avcl) +
                                    avc->parent_log_context_offset);
             if (parent && *parent) {
                 av_bprintf(part+0, "[%s @ %p] ",
@@ -272,7 +272,7 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
     }
 }
 
-void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
+void av_log_format_line(FF_CONST_AVUTIL55 void *ptr, int level, const char *fmt, va_list vl,
                         char *line, int line_size, int *print_prefix)
 {
     AVBPrint part[4];
@@ -281,7 +281,7 @@ void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
     av_bprint_finalize(part+3, NULL);
 }
 
-void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
+void av_log_default_callback(FF_CONST_AVUTIL55 void* ptr, int level, const char* fmt, va_list vl)
 {
     static int print_prefix = 1;
     static int count;
@@ -338,12 +338,12 @@ end:
 #endif
 }
 
-static void (*av_log_callback)(void*, int, const char*, va_list) =
+static void (*av_log_callback)(FF_CONST_AVUTIL55 void*, int, const char*, va_list) =
     av_log_default_callback;
 
-void av_log(void* avcl, int level, const char *fmt, ...)
+void av_log(FF_CONST_AVUTIL55 void* avcl, int level, const char *fmt, ...)
 {
-    AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
+    const AVClass* avc = avcl ? *(const AVClass **) avcl : NULL;
     va_list vl;
     va_start(vl, fmt);
     if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
@@ -353,9 +353,9 @@ void av_log(void* avcl, int level, const char *fmt, ...)
     va_end(vl);
 }
 
-void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
+void av_vlog(FF_CONST_AVUTIL55 void* avcl, int level, const char *fmt, va_list vl)
 {
-    void (*log_callback)(void*, int, const char*, va_list) = av_log_callback;
+    void (*log_callback)(FF_CONST_AVUTIL55 void*, int, const char*, va_list) = av_log_callback;
     if (log_callback)
         log_callback(avcl, level, fmt, vl);
 }
@@ -380,7 +380,7 @@ int av_log_get_flags(void)
     return flags;
 }
 
-void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
+void av_log_set_callback(void (*callback)(FF_CONST_AVUTIL55 void*, int, const char*, va_list))
 {
     av_log_callback = callback;
 }
diff --git a/libavutil/log.h b/libavutil/log.h
index e1ff09b..ae8bf0c 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -74,7 +74,7 @@ typedef struct AVClass {
      * A pointer to a function which returns the name of a context
      * instance ctx associated with the class.
      */
-    const char* (*item_name)(void* ctx);
+    const char* (*item_name)(FF_CONST_AVUTIL55 void* ctx);
 
     /**
      * a pointer to the first option specified in the class if any or NULL
@@ -132,7 +132,7 @@ typedef struct AVClass {
      * Callback to return the category.
      * available since version (51 << 16 | 59 << 8 | 100)
      */
-    AVClassCategory (*get_category)(void* ctx);
+    AVClassCategory (*get_category)(FF_CONST_AVUTIL55 void* ctx);
 
     /**
      * Callback to return the supported/allowed ranges.
@@ -225,7 +225,7 @@ typedef struct AVClass {
  * @param fmt The format string (printf-compatible) that specifies how
  *        subsequent arguments are converted to output.
  */
-void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
+void av_log(FF_CONST_AVUTIL55 void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
 
 
 /**
@@ -243,7 +243,7 @@ void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
  *        subsequent arguments are converted to output.
  * @param vl The arguments referenced by the format string.
  */
-void av_vlog(void *avcl, int level, const char *fmt, va_list vl);
+void av_vlog(FF_CONST_AVUTIL55 void *avcl, int level, const char *fmt, va_list vl);
 
 /**
  * Get the current log level
@@ -273,7 +273,7 @@ void av_log_set_level(int level);
  *
  * @param callback A logging function with a compatible signature.
  */
-void av_log_set_callback(void (*callback)(void*, int, const char*, va_list));
+void av_log_set_callback(void (*callback)(FF_CONST_AVUTIL55 void*, int, const char*, va_list));
 
 /**
  * Default logging callback
@@ -288,7 +288,7 @@ void av_log_set_callback(void (*callback)(void*, int, const char*, va_list));
  *        subsequent arguments are converted to output.
  * @param vl The arguments referenced by the format string.
  */
-void av_log_default_callback(void *avcl, int level, const char *fmt,
+void av_log_default_callback(FF_CONST_AVUTIL55 void *avcl, int level, const char *fmt,
                              va_list vl);
 
 /**
@@ -298,8 +298,8 @@ void av_log_default_callback(void *avcl, int level, const char *fmt,
  *
  * @return The AVClass class_name
  */
-const char* av_default_item_name(void* ctx);
-AVClassCategory av_default_get_category(void *ptr);
+const char* av_default_item_name(FF_CONST_AVUTIL55 void* ctx);
+AVClassCategory av_default_get_category(FF_CONST_AVUTIL55 void *ptr);
 
 /**
  * Format a line of log the same way as the default callback.
@@ -308,7 +308,7 @@ AVClassCategory av_default_get_category(void *ptr);
  * @param print_prefix  used to store whether the prefix must be printed;
  *                      must point to a persistent integer initially set to 1
  */
-void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
+void av_log_format_line(FF_CONST_AVUTIL55 void *ptr, int level, const char *fmt, va_list vl,
                         char *line, int line_size, int *print_prefix);
 
 /**
diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c
index f8fb356..677d3ac 100644
--- a/libpostproc/postprocess.c
+++ b/libpostproc/postprocess.c
@@ -903,7 +903,7 @@ static void reallocBuffers(PPContext *c, int width, int height, int stride, int
     reallocAlign((void **)&c->forcedQPTable, mbWidth*sizeof(QP_STORE_T));
 }
 
-static const char * context_to_name(void * ptr) {
+static const char * context_to_name(FF_CONST_AVUTIL55 void * ptr) {
     return "postproc";
 }
 
diff --git a/libswresample/options.c b/libswresample/options.c
index 01cdb1e..16ad3c9 100644
--- a/libswresample/options.c
+++ b/libswresample/options.c
@@ -126,7 +126,7 @@ static const AVOption options[]={
 {0}
 };
 
-static const char* context_to_name(void* ptr) {
+static const char* context_to_name(FF_CONST_AVUTIL55 void* ptr) {
     return "SWR";
 }
 
diff --git a/libswscale/options.c b/libswscale/options.c
index 4d49c3e..4b11934 100644
--- a/libswscale/options.c
+++ b/libswscale/options.c
@@ -24,7 +24,7 @@
 #include "swscale.h"
 #include "swscale_internal.h"
 
-static const char *sws_context_to_name(void *ptr)
+static const char *sws_context_to_name(FF_CONST_AVUTIL55 void *ptr)
 {
     return "swscaler";
 }
-- 
1.9.1



More information about the ffmpeg-devel mailing list