fate/libavcodec: add codec_desc test

Remove runtime check at codec_desc.c

Reviewed-by: wm4 <nfxjfg@googlemail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
This commit is contained in:
Muhammad Faiz 2018-02-10 16:30:14 +07:00
parent dced1f6cdf
commit b7d476b138
4 changed files with 51 additions and 24 deletions

View File

@ -1090,6 +1090,7 @@ SKIPHEADERS-$(CONFIG_V4L2_M2M) += v4l2_buffers.h v4l2_context.h v4l2_m2m
TESTPROGS = avpacket \ TESTPROGS = avpacket \
celp_math \ celp_math \
codec_desc \
htmlsubtitles \ htmlsubtitles \
imgconvert \ imgconvert \
jpeg2000dwt \ jpeg2000dwt \

View File

@ -21,10 +21,8 @@
#include <string.h> #include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/internal.h" #include "libavutil/internal.h"
#include "libavutil/thread.h"
#include "avcodec.h" #include "avcodec.h"
#include "profiles.h" #include "profiles.h"
#include "version.h" #include "version.h"
@ -3111,26 +3109,6 @@ static const AVCodecDescriptor codec_descriptors[] = {
}, },
}; };
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
static void check_validity(void)
{
int i;
for (i = 0; i < FF_ARRAY_ELEMS(codec_descriptors) - 1; i++) {
if (codec_descriptors[i].id >= codec_descriptors[i+1].id) {
av_log(NULL, AV_LOG_FATAL, "unsorted codec_id '%s' and '%s'.\n",
codec_descriptors[i].name, codec_descriptors[i+1].name);
av_assert0(0);
}
}
}
static AVOnce check_validity_once = AV_ONCE_INIT;
#define CHECK_VALIDITY() ff_thread_once(&check_validity_once, check_validity);
#else
#define CHECK_VALIDITY() ((void)0)
#endif
static int descriptor_compare(const void *key, const void *member) static int descriptor_compare(const void *key, const void *member)
{ {
enum AVCodecID id = *(const enum AVCodecID *) key; enum AVCodecID id = *(const enum AVCodecID *) key;
@ -3141,8 +3119,6 @@ static int descriptor_compare(const void *key, const void *member)
const AVCodecDescriptor *avcodec_descriptor_get(enum AVCodecID id) const AVCodecDescriptor *avcodec_descriptor_get(enum AVCodecID id)
{ {
CHECK_VALIDITY();
return bsearch(&id, codec_descriptors, FF_ARRAY_ELEMS(codec_descriptors), return bsearch(&id, codec_descriptors, FF_ARRAY_ELEMS(codec_descriptors),
sizeof(codec_descriptors[0]), descriptor_compare); sizeof(codec_descriptors[0]), descriptor_compare);
} }

View File

@ -0,0 +1,45 @@
/*
* 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/avcodec.h"
int main(int argc, char **argv)
{
const AVCodecDescriptor *old_desc = NULL, *desc;
while (desc = avcodec_descriptor_next(old_desc)) {
if (old_desc && old_desc->id >= desc->id) {
av_log(NULL, AV_LOG_FATAL, "Unsorted codec_descriptors '%s' and '%s'.\n", old_desc->name, desc->name);
return 1;
}
if (avcodec_descriptor_get(desc->id) != desc) {
av_log(NULL, AV_LOG_FATAL, "avcodec_descriptor_get() failed with '%s'.\n", desc->name);
return 1;
}
if (avcodec_descriptor_get_by_name(desc->name) != desc) {
av_log(NULL, AV_LOG_FATAL, "avcodec_descriptor_get_by_name() failed with '%s'.\n", desc->name);
return 1;
}
old_desc = desc;
}
return 0;
}

View File

@ -13,6 +13,11 @@ fate-celp_math: libavcodec/tests/celp_math$(EXESUF)
fate-celp_math: CMD = run libavcodec/tests/celp_math fate-celp_math: CMD = run libavcodec/tests/celp_math
fate-celp_math: CMP = null fate-celp_math: CMP = null
FATE_LIBAVCODEC-yes += fate-codec_desc
fate-codec_desc: libavcodec/tests/codec_desc$(EXESUF)
fate-codec_desc: CMD = run libavcodec/tests/codec_desc
fate-codec_desc: CMP = null
FATE_LIBAVCODEC-$(CONFIG_GOLOMB) += fate-golomb FATE_LIBAVCODEC-$(CONFIG_GOLOMB) += fate-golomb
fate-golomb: libavcodec/tests/golomb$(EXESUF) fate-golomb: libavcodec/tests/golomb$(EXESUF)
fate-golomb: CMD = run libavcodec/tests/golomb fate-golomb: CMD = run libavcodec/tests/golomb