[FFmpeg-devel,v2] avfilter/f_sidedata: try to fix warning: comparison of constant -1 with expression of type 'enum AVFrameSideDataType'

Submitted by lance.lmwang@gmail.com on Sept. 19, 2019, 1:53 a.m.

Details

Message ID 20190919015304.32321-1-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com Sept. 19, 2019, 1:53 a.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/f_sidedata.c | 10 +++++-----
 libavutil/frame.h        | 10 ++++++++++
 libavutil/version.h      |  2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavfilter/f_sidedata.c b/libavfilter/f_sidedata.c
index 381da5a052..3082aa65ea 100644
--- a/libavfilter/f_sidedata.c
+++ b/libavfilter/f_sidedata.c
@@ -49,7 +49,7 @@  static const AVOption filt_name##_options[] = { \
     { "mode", "set a mode of operation", OFFSET(mode),   AV_OPT_TYPE_INT,    {.i64 = 0 }, 0, SIDEDATA_NB-1, FLAGS, "mode" }, \
     {   "select", "select frame",        0,              AV_OPT_TYPE_CONST,  {.i64 = SIDEDATA_SELECT }, 0, 0, FLAGS, "mode" }, \
     {   "delete", "delete side data",    0,              AV_OPT_TYPE_CONST,  {.i64 = SIDEDATA_DELETE }, 0, 0, FLAGS, "mode" }, \
-    { "type",   "set side data type",    OFFSET(type),   AV_OPT_TYPE_INT,    {.i64 = -1 }, -1, INT_MAX, FLAGS, "type" }, \
+    { "type",   "set side data type",    OFFSET(type),   AV_OPT_TYPE_INT,    {.i64 = AV_FRAME_DATA_NB }, 0, AV_FRAME_DATA_NB, FLAGS, "type" }, \
     {   "PANSCAN",                    "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_PANSCAN                    }, 0, 0, FLAGS, "type" }, \
     {   "A53_CC",                     "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_A53_CC                     }, 0, 0, FLAGS, "type" }, \
     {   "STEREO3D",                   "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_STEREO3D                   }, 0, 0, FLAGS, "type" }, \
@@ -79,7 +79,7 @@  static const AVOption filt_name##_options[] = { \
     { "mode", "set a mode of operation", OFFSET(mode),   AV_OPT_TYPE_INT,    {.i64 = 0 }, 0, SIDEDATA_NB-1, FLAGS, "mode" }, \
     {   "select", "select frame",        0,              AV_OPT_TYPE_CONST,  {.i64 = SIDEDATA_SELECT }, 0, 0, FLAGS, "mode" }, \
     {   "delete", "delete side data",    0,              AV_OPT_TYPE_CONST,  {.i64 = SIDEDATA_DELETE }, 0, 0, FLAGS, "mode" }, \
-    { "type",   "set side data type",    OFFSET(type),   AV_OPT_TYPE_INT,    {.i64 = -1 }, -1, INT_MAX, FLAGS, "type" }, \
+    { "type",   "set side data type",    OFFSET(type),   AV_OPT_TYPE_INT,    {.i64 = AV_FRAME_DATA_NB }, 0, AV_FRAME_DATA_NB, FLAGS, "type" }, \
     {   "PANSCAN",                    "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_PANSCAN                    }, 0, 0, FLAGS, "type" }, \
     {   "A53_CC",                     "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_A53_CC                     }, 0, 0, FLAGS, "type" }, \
     {   "STEREO3D",                   "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_STEREO3D                   }, 0, 0, FLAGS, "type" }, \
@@ -107,7 +107,7 @@  static av_cold int init(AVFilterContext *ctx)
 {
     SideDataContext *s = ctx->priv;
 
-    if (s->type == -1 && s->mode != SIDEDATA_DELETE) {
+    if (s->type == AV_FRAME_DATA_NB && s->mode != SIDEDATA_DELETE) {
         av_log(ctx, AV_LOG_ERROR, "Side data type must be set\n");
         return AVERROR(EINVAL);
     }
@@ -122,7 +122,7 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     SideDataContext *s = ctx->priv;
     AVFrameSideData *sd = NULL;
 
-    if (s->type != -1)
+    if (s->type != AV_FRAME_DATA_NB)
        sd = av_frame_get_side_data(frame, s->type);
 
     switch (s->mode) {
@@ -132,7 +132,7 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         }
         break;
     case SIDEDATA_DELETE:
-        if (s->type == -1) {
+        if (s->type == AV_FRAME_DATA_NB) {
             while (frame->nb_side_data)
                 av_frame_remove_side_data(frame, frame->side_data[0]->type);
         } else if (sd) {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..4b83125be1 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -179,6 +179,16 @@  enum AVFrameSideDataType {
      * array element is implied by AVFrameSideData.size / AVRegionOfInterest.self_size.
      */
     AV_FRAME_DATA_REGIONS_OF_INTEREST,
+
+    /**
+     * The number of side data types.
+     * This is not part of the public API/ABI in the sense that it may
+     * change when new side data types are added.
+     * This must stay the last enum value.
+     * If its value becomes huge, some code using it
+     * needs to be updated as it assumes it to be smaller than other limits.
+     */
+    AV_FRAME_DATA_NB
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/version.h b/libavutil/version.h
index 3395769857..27d663baf1 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@ 
 
 #define LIBAVUTIL_VERSION_MAJOR  56
 #define LIBAVUTIL_VERSION_MINOR  35
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \