diff mbox series

[FFmpeg-devel,5/5] lavc: remove tests/options

Message ID 20210224100402.22300-5-anton@khirnov.net
State Accepted
Headers show
Series [FFmpeg-devel,1/5] tests/api-band-test: simplify code | expand

Checks

Context Check Description
andriy/configure warning Failed to apply patch

Commit Message

Anton Khirnov Feb. 24, 2021, 10:04 a.m. UTC
It tests deprecated avcodec_copy_context().
---
 libavcodec/Makefile        |   1 -
 libavcodec/tests/options.c | 194 -------------------------------------
 tests/fate/libavcodec.mak  |   4 -
 3 files changed, 199 deletions(-)
 delete mode 100644 libavcodec/tests/options.c

Comments

Andreas Rheinhardt Feb. 26, 2021, 1:55 p.m. UTC | #1
Anton Khirnov:
> It tests deprecated avcodec_copy_context().
> ---
>  libavcodec/Makefile        |   1 -
>  libavcodec/tests/options.c | 194 -------------------------------------
>  tests/fate/libavcodec.mak  |   4 -
>  3 files changed, 199 deletions(-)
>  delete mode 100644 libavcodec/tests/options.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index b46c1688cc..097e7ecd5a 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1220,7 +1220,6 @@ TESTPROGS = avpacket                                                    \
>              imgconvert                                                  \
>              jpeg2000dwt                                                 \
>              mathops                                                    \
> -            options                                                     \
>              mjpegenc_huffman                                            \
>              utils                                                       \
>  
> diff --git a/libavcodec/tests/options.c b/libavcodec/tests/options.c
> deleted file mode 100644
> index 010e3c0145..0000000000
> --- a/libavcodec/tests/options.c
> +++ /dev/null
> @@ -1,194 +0,0 @@
> -/*
> - * Copyright (c) 2001 Fabrice Bellard
> - * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
> - *
> - * This file is part of FFmpeg.
> - *
> - * FFmpeg is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 of the License, or (at your option) any later version.
> - *
> - * FFmpeg is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with FFmpeg; if not, write to the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> - */
> -
> -#include "libavcodec/options.c"
> -
> -static int dummy_init(AVCodecContext *ctx)
> -{
> -    //TODO: this code should set every possible pointer that could be set by codec and is not an option;
> -    ctx->extradata_size = 8;
> -    ctx->extradata = av_malloc(ctx->extradata_size);
> -    return 0;
> -}
> -
> -static int dummy_close(AVCodecContext *ctx)
> -{
> -    av_freep(&ctx->extradata);
> -    ctx->extradata_size = 0;
> -    return 0;
> -}
> -
> -static int dummy_encode(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
> -{
> -    return AVERROR(ENOSYS);
> -}
> -
> -typedef struct Dummy12Context {
> -    AVClass  *av_class;
> -    int      num;
> -    char*    str;
> -} Dummy12Context;
> -
> -typedef struct Dummy3Context {
> -    void     *fake_av_class;
> -    int      num;
> -    char*    str;
> -} Dummy3Context;
> -
> -#define OFFSET(x) offsetof(Dummy12Context, x)
> -#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> -static const AVOption dummy_options[] = {
> -    { "str", "set str", OFFSET(str), AV_OPT_TYPE_STRING, { .str = "i'm src default value" }, 0, 0, VE},
> -    { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT,    { .i64 = 1500100900 },    0, INT_MAX, VE},
> -    { NULL },
> -};
> -
> -static const AVClass dummy_v1_class = {
> -    .class_name = "dummy_v1_class",
> -    .item_name  = av_default_item_name,
> -    .option     = dummy_options,
> -    .version    = LIBAVUTIL_VERSION_INT,
> -};
> -
> -static const AVClass dummy_v2_class = {
> -    .class_name = "dummy_v2_class",
> -    .item_name  = av_default_item_name,
> -    .option     = dummy_options,
> -    .version    = LIBAVUTIL_VERSION_INT,
> -};
> -
> -/* codec with options */
> -static AVCodec dummy_v1_encoder = {
> -    .name             = "dummy_v1_codec",
> -    .type             = AVMEDIA_TYPE_VIDEO,
> -    .id               = AV_CODEC_ID_NONE - 1,
> -    .encode2          = dummy_encode,
> -    .init             = dummy_init,
> -    .close            = dummy_close,
> -    .priv_class       = &dummy_v1_class,
> -    .priv_data_size   = sizeof(Dummy12Context),
> -};
> -
> -/* codec with options, different class */
> -static AVCodec dummy_v2_encoder = {
> -    .name             = "dummy_v2_codec",
> -    .type             = AVMEDIA_TYPE_VIDEO,
> -    .id               = AV_CODEC_ID_NONE - 2,
> -    .encode2          = dummy_encode,
> -    .init             = dummy_init,
> -    .close            = dummy_close,
> -    .priv_class       = &dummy_v2_class,
> -    .priv_data_size   = sizeof(Dummy12Context),
> -};
> -
> -/* codec with priv data, but no class */
> -static AVCodec dummy_v3_encoder = {
> -    .name             = "dummy_v3_codec",
> -    .type             = AVMEDIA_TYPE_VIDEO,
> -    .id               = AV_CODEC_ID_NONE - 3,
> -    .encode2          = dummy_encode,
> -    .init             = dummy_init,
> -    .close            = dummy_close,
> -    .priv_data_size   = sizeof(Dummy3Context),
> -};
> -
> -/* codec without priv data */
> -static AVCodec dummy_v4_encoder = {
> -    .name             = "dummy_v4_codec",
> -    .type             = AVMEDIA_TYPE_VIDEO,
> -    .id               = AV_CODEC_ID_NONE - 4,
> -    .encode2          = dummy_encode,
> -    .init             = dummy_init,
> -    .close            = dummy_close,
> -};
> -
> -static void test_copy_print_codec(const AVCodecContext *ctx)
> -{
> -    printf("%-14s: %dx%d prv: %s",
> -           ctx->codec ? ctx->codec->name : "NULL",
> -           ctx->width, ctx->height,
> -           ctx->priv_data ? "set" : "null");
> -    if (ctx->codec && ctx->codec->priv_class && ctx->codec->priv_data_size) {
> -        int64_t i64;
> -        char *str = NULL;
> -        av_opt_get_int(ctx->priv_data, "num", 0, &i64);
> -        av_opt_get(ctx->priv_data, "str", 0, (uint8_t**)&str);
> -        printf(" opts: %"PRId64" %s", i64, str);
> -        av_free(str);
> -    }
> -    printf("\n");
> -}
> -
> -static void test_copy(const AVCodec *c1, const AVCodec *c2)
> -{
> -    AVCodecContext *ctx1, *ctx2;
> -    printf("%s -> %s\nclosed:\n", c1 ? c1->name : "NULL", c2 ? c2->name : "NULL");
> -    ctx1 = avcodec_alloc_context3(c1);
> -    ctx2 = avcodec_alloc_context3(c2);
> -    ctx1->width = ctx1->height = 128;
> -    ctx1->time_base = (AVRational){12,34};
> -    if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
> -        av_opt_set(ctx2->priv_data, "num", "667", 0);
> -        av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
> -    }
> -    avcodec_copy_context(ctx2, ctx1);
> -    test_copy_print_codec(ctx1);
> -    test_copy_print_codec(ctx2);
> -    if (ctx1->codec) {
> -        int ret;
> -        printf("opened:\n");
> -        ret = avcodec_open2(ctx1, ctx1->codec, NULL);
> -        if (ret < 0) {
> -            fprintf(stderr, "avcodec_open2 failed\n");
> -            exit(1);
> -        }
> -        if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
> -            av_opt_set(ctx2->priv_data, "num", "667", 0);
> -            av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
> -        }
> -        avcodec_copy_context(ctx2, ctx1);
> -        test_copy_print_codec(ctx1);
> -        test_copy_print_codec(ctx2);
> -    }
> -    avcodec_free_context(&ctx1);
> -    avcodec_free_context(&ctx2);
> -}
> -
> -int main(void)
> -{
> -    AVCodec *dummy_codec[] = {
> -        &dummy_v1_encoder,
> -        &dummy_v2_encoder,
> -        &dummy_v3_encoder,
> -        &dummy_v4_encoder,
> -        NULL,
> -    };
> -    int i, j;
> -
> -    for (i = 0; dummy_codec[i]; i++)
> -        avcodec_register(dummy_codec[i]);
> -
> -    printf("testing avcodec_copy_context()\n");
> -    for (i = 0; i < FF_ARRAY_ELEMS(dummy_codec); i++)
> -        for (j = 0; j < FF_ARRAY_ELEMS(dummy_codec); j++)
> -            test_copy(dummy_codec[i], dummy_codec[j]);
> -    return 0;
> -}
> diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak
> index 747dae3704..682296914a 100644
> --- a/tests/fate/libavcodec.mak
> +++ b/tests/fate/libavcodec.mak
> @@ -65,10 +65,6 @@ fate-mpeg12framerate: libavcodec/tests/mpeg12framerate$(EXESUF)
>  fate-mpeg12framerate: CMD = run libavcodec/tests/mpeg12framerate$(EXESUF)
>  fate-mpeg12framerate: REF = /dev/null
>  
> -FATE_LIBAVCODEC-yes += fate-libavcodec-options
> -fate-libavcodec-options: libavcodec/tests/options$(EXESUF)
> -fate-libavcodec-options: CMD = run libavcodec/tests/options$(EXESUF)
> -
>  FATE_LIBAVCODEC-$(CONFIG_RANGECODER) += fate-rangecoder
>  fate-rangecoder: libavcodec/tests/rangecoder$(EXESUF)
>  fate-rangecoder: CMD = run libavcodec/tests/rangecoder$(EXESUF)
> 
You forgot to remove the corresponding entry in .gitignore. LGTM otherwise.

- Andreas
Anton Khirnov March 1, 2021, 3:06 p.m. UTC | #2
Quoting Andreas Rheinhardt (2021-02-26 14:55:26)
> You forgot to remove the corresponding entry in .gitignore. LGTM otherwise.

And the test output as well.
Both removed locally.
diff mbox series

Patch

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b46c1688cc..097e7ecd5a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1220,7 +1220,6 @@  TESTPROGS = avpacket                                                    \
             imgconvert                                                  \
             jpeg2000dwt                                                 \
             mathops                                                    \
-            options                                                     \
             mjpegenc_huffman                                            \
             utils                                                       \
 
diff --git a/libavcodec/tests/options.c b/libavcodec/tests/options.c
deleted file mode 100644
index 010e3c0145..0000000000
--- a/libavcodec/tests/options.c
+++ /dev/null
@@ -1,194 +0,0 @@ 
-/*
- * Copyright (c) 2001 Fabrice Bellard
- * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "libavcodec/options.c"
-
-static int dummy_init(AVCodecContext *ctx)
-{
-    //TODO: this code should set every possible pointer that could be set by codec and is not an option;
-    ctx->extradata_size = 8;
-    ctx->extradata = av_malloc(ctx->extradata_size);
-    return 0;
-}
-
-static int dummy_close(AVCodecContext *ctx)
-{
-    av_freep(&ctx->extradata);
-    ctx->extradata_size = 0;
-    return 0;
-}
-
-static int dummy_encode(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
-{
-    return AVERROR(ENOSYS);
-}
-
-typedef struct Dummy12Context {
-    AVClass  *av_class;
-    int      num;
-    char*    str;
-} Dummy12Context;
-
-typedef struct Dummy3Context {
-    void     *fake_av_class;
-    int      num;
-    char*    str;
-} Dummy3Context;
-
-#define OFFSET(x) offsetof(Dummy12Context, x)
-#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
-static const AVOption dummy_options[] = {
-    { "str", "set str", OFFSET(str), AV_OPT_TYPE_STRING, { .str = "i'm src default value" }, 0, 0, VE},
-    { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT,    { .i64 = 1500100900 },    0, INT_MAX, VE},
-    { NULL },
-};
-
-static const AVClass dummy_v1_class = {
-    .class_name = "dummy_v1_class",
-    .item_name  = av_default_item_name,
-    .option     = dummy_options,
-    .version    = LIBAVUTIL_VERSION_INT,
-};
-
-static const AVClass dummy_v2_class = {
-    .class_name = "dummy_v2_class",
-    .item_name  = av_default_item_name,
-    .option     = dummy_options,
-    .version    = LIBAVUTIL_VERSION_INT,
-};
-
-/* codec with options */
-static AVCodec dummy_v1_encoder = {
-    .name             = "dummy_v1_codec",
-    .type             = AVMEDIA_TYPE_VIDEO,
-    .id               = AV_CODEC_ID_NONE - 1,
-    .encode2          = dummy_encode,
-    .init             = dummy_init,
-    .close            = dummy_close,
-    .priv_class       = &dummy_v1_class,
-    .priv_data_size   = sizeof(Dummy12Context),
-};
-
-/* codec with options, different class */
-static AVCodec dummy_v2_encoder = {
-    .name             = "dummy_v2_codec",
-    .type             = AVMEDIA_TYPE_VIDEO,
-    .id               = AV_CODEC_ID_NONE - 2,
-    .encode2          = dummy_encode,
-    .init             = dummy_init,
-    .close            = dummy_close,
-    .priv_class       = &dummy_v2_class,
-    .priv_data_size   = sizeof(Dummy12Context),
-};
-
-/* codec with priv data, but no class */
-static AVCodec dummy_v3_encoder = {
-    .name             = "dummy_v3_codec",
-    .type             = AVMEDIA_TYPE_VIDEO,
-    .id               = AV_CODEC_ID_NONE - 3,
-    .encode2          = dummy_encode,
-    .init             = dummy_init,
-    .close            = dummy_close,
-    .priv_data_size   = sizeof(Dummy3Context),
-};
-
-/* codec without priv data */
-static AVCodec dummy_v4_encoder = {
-    .name             = "dummy_v4_codec",
-    .type             = AVMEDIA_TYPE_VIDEO,
-    .id               = AV_CODEC_ID_NONE - 4,
-    .encode2          = dummy_encode,
-    .init             = dummy_init,
-    .close            = dummy_close,
-};
-
-static void test_copy_print_codec(const AVCodecContext *ctx)
-{
-    printf("%-14s: %dx%d prv: %s",
-           ctx->codec ? ctx->codec->name : "NULL",
-           ctx->width, ctx->height,
-           ctx->priv_data ? "set" : "null");
-    if (ctx->codec && ctx->codec->priv_class && ctx->codec->priv_data_size) {
-        int64_t i64;
-        char *str = NULL;
-        av_opt_get_int(ctx->priv_data, "num", 0, &i64);
-        av_opt_get(ctx->priv_data, "str", 0, (uint8_t**)&str);
-        printf(" opts: %"PRId64" %s", i64, str);
-        av_free(str);
-    }
-    printf("\n");
-}
-
-static void test_copy(const AVCodec *c1, const AVCodec *c2)
-{
-    AVCodecContext *ctx1, *ctx2;
-    printf("%s -> %s\nclosed:\n", c1 ? c1->name : "NULL", c2 ? c2->name : "NULL");
-    ctx1 = avcodec_alloc_context3(c1);
-    ctx2 = avcodec_alloc_context3(c2);
-    ctx1->width = ctx1->height = 128;
-    ctx1->time_base = (AVRational){12,34};
-    if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
-        av_opt_set(ctx2->priv_data, "num", "667", 0);
-        av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
-    }
-    avcodec_copy_context(ctx2, ctx1);
-    test_copy_print_codec(ctx1);
-    test_copy_print_codec(ctx2);
-    if (ctx1->codec) {
-        int ret;
-        printf("opened:\n");
-        ret = avcodec_open2(ctx1, ctx1->codec, NULL);
-        if (ret < 0) {
-            fprintf(stderr, "avcodec_open2 failed\n");
-            exit(1);
-        }
-        if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
-            av_opt_set(ctx2->priv_data, "num", "667", 0);
-            av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
-        }
-        avcodec_copy_context(ctx2, ctx1);
-        test_copy_print_codec(ctx1);
-        test_copy_print_codec(ctx2);
-    }
-    avcodec_free_context(&ctx1);
-    avcodec_free_context(&ctx2);
-}
-
-int main(void)
-{
-    AVCodec *dummy_codec[] = {
-        &dummy_v1_encoder,
-        &dummy_v2_encoder,
-        &dummy_v3_encoder,
-        &dummy_v4_encoder,
-        NULL,
-    };
-    int i, j;
-
-    for (i = 0; dummy_codec[i]; i++)
-        avcodec_register(dummy_codec[i]);
-
-    printf("testing avcodec_copy_context()\n");
-    for (i = 0; i < FF_ARRAY_ELEMS(dummy_codec); i++)
-        for (j = 0; j < FF_ARRAY_ELEMS(dummy_codec); j++)
-            test_copy(dummy_codec[i], dummy_codec[j]);
-    return 0;
-}
diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak
index 747dae3704..682296914a 100644
--- a/tests/fate/libavcodec.mak
+++ b/tests/fate/libavcodec.mak
@@ -65,10 +65,6 @@  fate-mpeg12framerate: libavcodec/tests/mpeg12framerate$(EXESUF)
 fate-mpeg12framerate: CMD = run libavcodec/tests/mpeg12framerate$(EXESUF)
 fate-mpeg12framerate: REF = /dev/null
 
-FATE_LIBAVCODEC-yes += fate-libavcodec-options
-fate-libavcodec-options: libavcodec/tests/options$(EXESUF)
-fate-libavcodec-options: CMD = run libavcodec/tests/options$(EXESUF)
-
 FATE_LIBAVCODEC-$(CONFIG_RANGECODER) += fate-rangecoder
 fate-rangecoder: libavcodec/tests/rangecoder$(EXESUF)
 fate-rangecoder: CMD = run libavcodec/tests/rangecoder$(EXESUF)