上传完整项目文件

This commit is contained in:
xhgit committed 2026-06-21 14:26:15 +08:00
1 parent e63d58df8d
commit aa0dd45839
8663 files changed
+2393125

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
/audiogen
/audiomatch
/base64
/data/
/pixfmts.mak
/rotozoom
/test_copy.ffmeta
/tiny_psnr
/tiny_ssim
/videogen
/vsynth1/
+345
View File
@@ -0,0 +1,345 @@
ifneq ($(strip $(KEEP)),)
ifneq ($(strip $(KEEP)),0)
# KEEP_FILES is normally undefined; it is set to 2 # if the user requested
# to keep all intermediate FATE-files by setting KEEP.
# For some tests it is also set to 1 if it is unset; this indicates
# that only some intermediate files (namely only non-raw files)
# are to be kept. This allows reusing these intermediate files as input
# files for other tests (mostly the seek-tests).
KEEP_FILES = 2
endif
endif
THREADS = 1
VREF = tests/vsynth1/00.pgm
AREF = tests/data/asynth1.sw
FATEW = 34
FATEH = 34
FFMPEG=ffmpeg$(PROGSSUF)$(EXESUF)
$(AREF): CMP=
APITESTSDIR := tests/api
FATE_OUTDIRS = tests/data tests/data/fate tests/data/filtergraphs tests/data/maps tests/data/streamgroups tests/data/lavf tests/data/lavf-fate tests/data/pixfmt tests/vsynth1 $(APITESTSDIR)
OUTDIRS += $(FATE_OUTDIRS)
$(VREF): tests/videogen$(HOSTEXESUF) | tests/vsynth1
$(M)./$< 'tests/vsynth1/'
$(AREF): tests/audiogen$(HOSTEXESUF) | tests/data
$(M)./$< $@
tests/data/asynth-%.wav: tests/audiogen$(HOSTEXESUF) | tests/data
$(M)./$< $@ $(subst -, ,$*)
tests/data/vsynth1.yuv: tests/videogen$(HOSTEXESUF) | tests/data
$(M)$< $@
tests/data/vsynth2.yuv: tests/rotozoom$(HOSTEXESUF) | tests/data
$(M)$< $(SRC_PATH)/tests/reference.pnm $@
tests/data/vsynth_lena.yuv: tests/rotozoom$(HOSTEXESUF) | tests/data
$(M)$< $(SAMPLES)/lena.pnm $@
tests/data/vsynth3.yuv: tests/videogen$(HOSTEXESUF) | tests/data
$(M)$< $@ $(FATEW) $(FATEH)
tests/test_copy.ffmeta: TAG = COPY
tests/test_copy.ffmeta: tests/data
$(M)cp -f $(SRC_PATH)/tests/test.ffmeta tests/test_copy.ffmeta
tests/data/%.sw tests/data/asynth% tests/data/vsynth%.yuv tests/vsynth%/00.pgm tests/data/%.nut: TAG = GEN
tests/data/filtergraphs/%: TAG = COPY
tests/data/filtergraphs/%: $(SRC_PATH)/tests/filtergraphs/% | tests/data/filtergraphs
$(M)cp $< $@
tests/data/maps/%: TAG = COPY
tests/data/maps/%: $(SRC_PATH)/tests/maps/% | tests/data/maps
$(M)cp $< $@
tests/data/streamgroups/%: TAG = COPY
tests/data/streamgroups/%: $(SRC_PATH)/tests/streamgroups/% | tests/data/streamgroups
$(M)cp $< $@
RUNNING_FATE := $(filter check fate%,$(filter-out fate-rsync,$(MAKECMDGOALS)))
# Check sanity of dependencies when running FATE tests.
ifneq (,$(RUNNING_FATE))
CHKCFG = $(if $($(1))$(!$(1)),$($(1)), $(error No such config: $(1)))
endif
ALLYES = $(strip $(call XYES, $(1)))
XYES = $(if $(strip $(1)), \
$(if $(call CHKCFG,CONFIG_$(firstword $(1))), \
$(call XYES, $(wordlist 2, $(words $(1)), $(1)))), \
yes)
ENCDEC = $(call ALLYES, $(firstword $(1))_ENCODER $(lastword $(1))_DECODER \
$(firstword $(2))_MUXER $(lastword $(2))_DEMUXER \
$(3) FILE_PROTOCOL)
ENCDEC2 = $(call ALLYES, $(firstword $(1))_ENCODER $(lastword $(1))_DECODER \
$(firstword $(2))_ENCODER $(lastword $(2))_DECODER \
$(firstword $(3))_MUXER $(lastword $(3))_DEMUXER \
$(4) FILE_PROTOCOL)
# RAWVIDEO_ENCODER and PCM_S16LE_ENCODER corresponds to the default codecs
# for framecrc. These requirements are not always necessary.
TRANSCODE = $(call ALLYES, $(firstword $(1))_ENCODER $(lastword $(1))_DECODER \
$(firstword $(2))_MUXER $(lastword $(2))_DEMUXER \
$(3) FILE_PROTOCOL PIPE_PROTOCOL RAWVIDEO_ENCODER \
PCM_S16LE_ENCODER FRAMECRC_MUXER)
REMUX = $(call ALLYES, $(firstword $(1))_MUXER $(lastword $(1))_DEMUXER \
$(2) FILE_PROTOCOL PIPE_PROTOCOL FRAMECRC_MUXER)
DEMDEC = $(call ALLYES, $(1)_DEMUXER $(2:%=%_DECODER) $(3) FILE_PROTOCOL)
ENCMUX = $(call ALLYES, $(1:%=%_ENCODER) $(2)_MUXER $(3))
FRAMEMD5 = $(call ALLYES, $(1)_DEMUXER $(2:%=%_DECODER) $(3) \
PCM_S16LE_ENCODER RAWVIDEO_ENCODER FRAMEMD5_MUXER \
PIPE_PROTOCOL FILE_PROTOCOL)
FRAMECRC = $(call ALLYES, $(1)_DEMUXER $(2:%=%_DECODER) $(3) \
PCM_S16LE_ENCODER RAWVIDEO_ENCODER FRAMECRC_MUXER \
PIPE_PROTOCOL FILE_PROTOCOL)
# Variant of DEMDEC for use with the "pcm" command.
PCM = $(call ALLYES, $(1)_DEMUXER $(2)_DECODER $(3) FILE_PROTOCOL \
PCM_S16LE_ENCODER PCM_S16LE_MUXER PIPE_PROTOCOL)
DEMMUX = $(call ALLYES, $(1)_DEMUXER $(2)_MUXER $(3) FILE_PROTOCOL)
# Variant of FRAMECRC for the cases with -lavfi where no demuxer is involved.
FILTERFRAMECRC = $(call ALLYES, $(1:%=%_FILTER) $(2) PCM_S16LE_ENCODER \
RAWVIDEO_ENCODER FRAMECRC_MUXER PIPE_PROTOCOL)
# Specialization of FRAMECRC to be used when filtering is involved.
FILTERDEMDEC = $(call ALLYES, $(1:%=%_FILTER) $(2:%=%_DEMUXER) $(3:%=%_DECODER) \
$(4) PCM_S16LE_ENCODER RAWVIDEO_ENCODER \
FRAMECRC_MUXER FILE_PROTOCOL PIPE_PROTOCOL)
FILTERDEMDECENCMUX = $(call ALLYES, $(1:%=%_FILTER) $(2)_DEMUXER $(3)_DECODER $(4)_ENCODER $(5)_MUXER $(6) FILE_PROTOCOL)
PARSERDEMDEC = $(call ALLYES, $(1)_PARSER $(2)_DEMUXER $(3)_DECODER $(4) FILE_PROTOCOL)
# Allow overriding CONFIG_LARGE_TESTS via LARGE_TESTS, if set on the
# make command line.
ifeq ($(LARGE_TESTS), yes)
CONFIG_LARGE_TESTS:=yes
!CONFIG_LARGE_TESTS:=
else ifeq ($(LARGE_TESTS), no)
CONFIG_LARGE_TESTS:=
!CONFIG_LARGE_TESTS:=yes
endif
include $(SRC_PATH)/$(APITESTSDIR)/Makefile
include $(SRC_PATH)/tests/fate/acodec.mak
include $(SRC_PATH)/tests/fate/vcodec.mak
include $(SRC_PATH)/tests/fate/lavf-audio.mak
include $(SRC_PATH)/tests/fate/lavf-container.mak
include $(SRC_PATH)/tests/fate/lavf-image.mak
include $(SRC_PATH)/tests/fate/lavf-image2pipe.mak
include $(SRC_PATH)/tests/fate/lavf-video.mak
# Must be included after acodec.mak, vcodec.mak and lavf-*.mak
include $(SRC_PATH)/tests/fate/seek.mak
include $(SRC_PATH)/tests/fate/aac.mak
include $(SRC_PATH)/tests/fate/ac3.mak
include $(SRC_PATH)/tests/fate/adpcm.mak
include $(SRC_PATH)/tests/fate/alac.mak
include $(SRC_PATH)/tests/fate/als.mak
include $(SRC_PATH)/tests/fate/amrnb.mak
include $(SRC_PATH)/tests/fate/amrwb.mak
include $(SRC_PATH)/tests/fate/api.mak
include $(SRC_PATH)/tests/fate/apng.mak
include $(SRC_PATH)/tests/fate/atrac.mak
include $(SRC_PATH)/tests/fate/audio.mak
include $(SRC_PATH)/tests/fate/bmp.mak
include $(SRC_PATH)/tests/fate/build.mak
include $(SRC_PATH)/tests/fate/caf.mak
include $(SRC_PATH)/tests/fate/canopus.mak
include $(SRC_PATH)/tests/fate/cbs.mak
include $(SRC_PATH)/tests/fate/cdxl.mak
include $(SRC_PATH)/tests/fate/checkasm.mak
# Must be included after lavf-container.mak
include $(SRC_PATH)/tests/fate/concatdec.mak
include $(SRC_PATH)/tests/fate/cover-art.mak
include $(SRC_PATH)/tests/fate/dca.mak
include $(SRC_PATH)/tests/fate/demux.mak
include $(SRC_PATH)/tests/fate/dfa.mak
include $(SRC_PATH)/tests/fate/dnxhd.mak
include $(SRC_PATH)/tests/fate/dpcm.mak
include $(SRC_PATH)/tests/fate/dvvideo.mak
include $(SRC_PATH)/tests/fate/ea.mak
include $(SRC_PATH)/tests/fate/exif.mak
include $(SRC_PATH)/tests/fate/enc_external.mak
# Must be included after lavf-video.mak
include $(SRC_PATH)/tests/fate/ffmpeg.mak
include $(SRC_PATH)/tests/fate/ffprobe.mak
include $(SRC_PATH)/tests/fate/fifo-muxer.mak
include $(SRC_PATH)/tests/fate/filter-audio.mak
# Must be included after vcodec.mak
include $(SRC_PATH)/tests/fate/filter-video.mak
include $(SRC_PATH)/tests/fate/fits.mak
include $(SRC_PATH)/tests/fate/flac.mak
include $(SRC_PATH)/tests/fate/flvenc.mak
include $(SRC_PATH)/tests/fate/gapless.mak
include $(SRC_PATH)/tests/fate/gif.mak
include $(SRC_PATH)/tests/fate/h264.mak
include $(SRC_PATH)/tests/fate/hap.mak
include $(SRC_PATH)/tests/fate/hevc.mak
include $(SRC_PATH)/tests/fate/hlsenc.mak
include $(SRC_PATH)/tests/fate/hw.mak
include $(SRC_PATH)/tests/fate/iamf.mak
include $(SRC_PATH)/tests/fate/id3v2.mak
include $(SRC_PATH)/tests/fate/image.mak
include $(SRC_PATH)/tests/fate/imf.mak
include $(SRC_PATH)/tests/fate/indeo.mak
include $(SRC_PATH)/tests/fate/jpeg2000.mak
include $(SRC_PATH)/tests/fate/jxl.mak
include $(SRC_PATH)/tests/fate/libavcodec.mak
include $(SRC_PATH)/tests/fate/libavdevice.mak
include $(SRC_PATH)/tests/fate/libavformat.mak
include $(SRC_PATH)/tests/fate/libavutil.mak
include $(SRC_PATH)/tests/fate/libswresample.mak
include $(SRC_PATH)/tests/fate/libswscale.mak
include $(SRC_PATH)/tests/fate/lossless-audio.mak
include $(SRC_PATH)/tests/fate/lossless-video.mak
include $(SRC_PATH)/tests/fate/matroska.mak
include $(SRC_PATH)/tests/fate/microsoft.mak
include $(SRC_PATH)/tests/fate/monkeysaudio.mak
include $(SRC_PATH)/tests/fate/mov.mak
include $(SRC_PATH)/tests/fate/mp3.mak
include $(SRC_PATH)/tests/fate/mpc.mak
include $(SRC_PATH)/tests/fate/mpeg4.mak
include $(SRC_PATH)/tests/fate/mpegps.mak
include $(SRC_PATH)/tests/fate/mpegts.mak
include $(SRC_PATH)/tests/fate/mxf.mak
include $(SRC_PATH)/tests/fate/oma.mak
include $(SRC_PATH)/tests/fate/opus.mak
include $(SRC_PATH)/tests/fate/pcm.mak
include $(SRC_PATH)/tests/fate/pixfmt.mak
include $(SRC_PATH)/tests/fate/pixlet.mak
include $(SRC_PATH)/tests/fate/probe.mak
include $(SRC_PATH)/tests/fate/prores.mak
include $(SRC_PATH)/tests/fate/qoa.mak
include $(SRC_PATH)/tests/fate/qt.mak
include $(SRC_PATH)/tests/fate/qtrle.mak
include $(SRC_PATH)/tests/fate/real.mak
include $(SRC_PATH)/tests/fate/screen.mak
include $(SRC_PATH)/tests/fate/segafilm.mak
include $(SRC_PATH)/tests/fate/segment.mak
include $(SRC_PATH)/tests/fate/source.mak
include $(SRC_PATH)/tests/fate/spdif.mak
include $(SRC_PATH)/tests/fate/speedhq.mak
include $(SRC_PATH)/tests/fate/subtitles.mak
include $(SRC_PATH)/tests/fate/truehd.mak
include $(SRC_PATH)/tests/fate/utvideo.mak
include $(SRC_PATH)/tests/fate/vbn.mak
include $(SRC_PATH)/tests/fate/video.mak
include $(SRC_PATH)/tests/fate/voice.mak
include $(SRC_PATH)/tests/fate/vorbis.mak
include $(SRC_PATH)/tests/fate/vpx.mak
include $(SRC_PATH)/tests/fate/vqf.mak
include $(SRC_PATH)/tests/fate/vvc.mak
include $(SRC_PATH)/tests/fate/wavpack.mak
include $(SRC_PATH)/tests/fate/webm-dash-manifest.mak
include $(SRC_PATH)/tests/fate/wma.mak
include $(SRC_PATH)/tests/fate/xvid.mak
FATE_FFMPEG += $(FATE_FFMPEG-yes) $(FATE_AVCONV) $(FATE_AVCONV-yes)
FATE-$(CONFIG_FFMPEG) += $(FATE_FFMPEG)
FATE_FFPROBE += $(FATE_FFPROBE-yes)
FATE-$(CONFIG_FFPROBE) += $(FATE_FFPROBE)
FATE-$(call ALLYES, FFMPEG FFPROBE) += $(FATE_FFMPEG_FFPROBE)
FATE_SAMPLES_AVCONV += $(FATE_SAMPLES_AVCONV-yes)
FATE_SAMPLES_FFMPEG += $(FATE_SAMPLES_FFMPEG-yes)
FATE_EXTERN-$(CONFIG_FFMPEG) += $(FATE_SAMPLES_AVCONV) $(FATE_SAMPLES_FFMPEG)
FATE_EXTERN-$(CONFIG_FFPROBE) += $(FATE_SAMPLES_FFPROBE)
FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_SAMPLES_FFMPEG_FFPROBE-yes)
FATE_EXTERN-$(call ALLYES, FFMPEG FFPROBE) += $(FATE_SAMPLES_FFMPEG_FFPROBE)
FATE_EXTERN += $(FATE_EXTERN-yes) $(FATE_SAMPLES_FASTSTART)
FATE += $(FATE-yes)
RSYNC_OPTIONS-$(HAVE_RSYNC_CONTIMEOUT) += --contimeout=60
RSYNC_OPTIONS = -vrltLW --timeout=60 $(RSYNC_OPTIONS-yes)
$(FATE_FFMPEG) $(FATE_FFMPEG_FFPROBE) $(FATE_SAMPLES_AVCONV) $(FATE_SAMPLES_FFMPEG) $(FATE_SAMPLES_FFMPEG_FFPROBE): ffmpeg$(PROGSSUF)$(EXESUF)
$(FATE_FFPROBE) $(FATE_FFMPEG_FFPROBE) $(FATE_SAMPLES_FFPROBE) $(FATE_SAMPLES_FFMPEG_FFPROBE): ffprobe$(PROGSSUF)$(EXESUF)
$(FATE_SAMPLES_FASTSTART): tools/qt-faststart$(EXESUF)
$(FATE_SAMPLES_DUMP_DATA) $(FATE_SAMPLES_DUMP_DATA-yes): tools/venc_data_dump$(EXESUF)
$(FATE_SAMPLES_SCALE_SLICE): tools/scale_slice_test$(EXESUF)
ifdef SAMPLES
FATE += $(FATE_EXTERN)
fate-rsync:
rsync $(RSYNC_OPTIONS) rsync://fate-suite.ffmpeg.org/fate-suite/ $(SAMPLES)
else
fate::
@echo "warning: only a subset of the fate tests will be run because SAMPLES is not specified"
fate-rsync:
@echo "use 'make fate-rsync SAMPLES=/path/to/samples' to sync the fate suite"
$(FATE_EXTERN):
@echo "$@ requires external samples and SAMPLES not specified"; false
endif
FATE_UTILS = base64 tiny_psnr tiny_ssim audiomatch
TOOL = ffmpeg
$(addprefix fate-, $(IGNORE_TESTS)): REPORT=ignore
fate:: $(FATE)
# Tests requiring hardware support are not included in a default fate run.
fate-hw: $(FATE_HW-yes)
FATE += $(FATE_HW-yes)
$(FATE): export PROGSUF = $(PROGSSUF)
$(FATE): export EXECSUF = $(EXESUF)
$(FATE): export HOSTEXECSUF = $(HOSTEXESUF)
$(FATE): $(FATE_UTILS:%=tests/%$(HOSTEXESUF)) | $(FATE_OUTDIRS)
@echo "TEST $(@:fate-%=%)$(FATE_SUFFIX)"
$(Q)$(SRC_PATH)/tests/fate-run.sh $@$(FATE_SUFFIX) "$(TARGET_SAMPLES)" "$(TARGET_EXEC)" "$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' '$(THREADS)' '$(THREAD_TYPE)' '$(CPUFLAGS)' '$(CMP_SHIFT)' '$(CMP_TARGET)' '$(SIZE_TOLERANCE)' '$(CMP_UNIT)' '$(GEN)' '$(HWACCEL)' '$(REPORT)' '$(KEEP_FILES)'
fate-list:
@printf '%s\n' $(sort $(FATE))
coverage.info: TAG = LCOV
coverage.info:
$(M)lcov -q -d $(CURDIR) -b $(patsubst src%,./,$(SRC_LINK)) --capture | \
sed "s,$(CURDIR)/\./,$(CURDIR)/," > $@.in
$(M)lcov -q --remove $@.in "/usr*" > $@
$(Q)$(RM) $@.in
lcov: TAG = GENHTML
lcov: coverage.info
$(M)genhtml -q -o $(CURDIR)/lcov $<
lcov-reset: TAG = LCOV
lcov-reset:
$(M)lcov -q -d $(CURDIR) --zerocounters
$(Q)$(RM) -f coverage.info
clean:: testclean
testclean::
$(RM) -r tests/vsynth1 tests/data tools/lavfi-showfiltfmts$(PROGSSUF)$(EXESUF)
$(RM) $(CLEANSUFFIXES:%=tests/%)
$(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF))
$(RM) tests/pixfmts.mak tests/test_copy.ffmeta
-include $(wildcard tests/*.d)
include $(SRC_PATH)/tests/checkasm/Makefile
.PHONY: fate* lcov lcov-reset
.INTERMEDIATE: coverage.info
+1
View File
@@ -0,0 +1 @@
/*-test
+21
View File
@@ -0,0 +1,21 @@
APITESTPROGS-$(call ENCDEC, FLAC, FLAC) += api-flac
APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264
APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264-slice
APITESTPROGS-yes += api-seek
APITESTPROGS-$(call DEMDEC, H263, H263) += api-band
APITESTPROGS-$(HAVE_THREADS) += api-threadmessage
APITESTPROGS += $(APITESTPROGS-yes)
APITESTOBJS := $(APITESTOBJS:%=$(APITESTSDIR)%) $(APITESTPROGS:%=$(APITESTSDIR)/%-test.o)
APITESTPROGS := $(APITESTPROGS:%=$(APITESTSDIR)/%-test$(EXESUF))
-include $(wildcard $(APITESTOBJS:.o=.d))
$(APITESTOBJS): | $(sort $(dir $(APITESTOBJS)))
$(APITESTOBJS) $(APITESTOBJS:.o=.i): CPPFLAGS += -DTEST
$(APITESTOBJS) $(APITESTOBJS:.o=.i): CFLAGS += -Umain
$(APITESTPROGS): %$(EXESUF): %.o $(FF_DEP_LIBS)
$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(filter %.o,$^) $(FF_EXTRALIBS) $(ELIBS)
testclean::
$(RM) $(addprefix $(APITESTSDIR)/,$(CLEANSUFFIXES) *-test$(EXESUF))
+233
View File
@@ -0,0 +1,233 @@
/*
* Copyright (c) 2015 Ludmila Glinskih
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* draw_horiz_band test.
*/
#include "libavutil/adler32.h"
#include "libavutil/mem.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
uint8_t *slice_byte_buffer;
int draw_horiz_band_called;
static void draw_horiz_band(AVCodecContext *ctx, const AVFrame *fr, int offset[4],
int slice_position, int type, int height)
{
int i;
const AVPixFmtDescriptor *pix_fmt_desc;
int chroma_w, chroma_h;
int shift_slice_position;
int shift_height;
draw_horiz_band_called = 1;
pix_fmt_desc = av_pix_fmt_desc_get(ctx->pix_fmt);
chroma_w = -((-ctx->width) >> pix_fmt_desc->log2_chroma_w);
chroma_h = -((-height) >> pix_fmt_desc->log2_chroma_h);
shift_slice_position = -((-slice_position) >> pix_fmt_desc->log2_chroma_h);
shift_height = -((-ctx->height) >> pix_fmt_desc->log2_chroma_h);
for (i = 0; i < height; i++) {
memcpy(slice_byte_buffer + ctx->width * slice_position + i * ctx->width,
fr->data[0] + offset[0] + i * fr->linesize[0], ctx->width);
}
for (i = 0; i < chroma_h; i++) {
memcpy(slice_byte_buffer + ctx->width * ctx->height + chroma_w * shift_slice_position + i * chroma_w,
fr->data[1] + offset[1] + i * fr->linesize[1], chroma_w);
}
for (i = 0; i < chroma_h; i++) {
memcpy(slice_byte_buffer + ctx->width * ctx->height + chroma_w * shift_height + chroma_w * shift_slice_position + i * chroma_w,
fr->data[2] + offset[2] + i * fr->linesize[2], chroma_w);
}
}
static int video_decode(const char *input_filename)
{
const AVCodec *codec = NULL;
AVCodecContext *ctx= NULL;
AVCodecParameters *origin_par = NULL;
uint8_t *byte_buffer = NULL;
AVFrame *fr = NULL;
AVPacket *pkt;
AVFormatContext *fmt_ctx = NULL;
int number_of_written_bytes;
int video_stream;
int byte_buffer_size;
int result;
draw_horiz_band_called = 0;
result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't open file\n");
return result;
}
result = avformat_find_stream_info(fmt_ctx, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
return result;
}
video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
if (video_stream < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");
return -1;
}
origin_par = fmt_ctx->streams[video_stream]->codecpar;
codec = avcodec_find_decoder(origin_par->codec_id);
if (!codec) {
av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
return -1;
}
if (!(codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)) {
av_log(NULL, AV_LOG_ERROR, "Codec does not support draw_horiz_band\n");
return -1;
}
ctx = avcodec_alloc_context3(codec);
if (!ctx) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");
return AVERROR(ENOMEM);
}
result = avcodec_parameters_to_context(ctx, origin_par);
if (result) {
av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");
return result;
}
ctx->draw_horiz_band = draw_horiz_band;
ctx->thread_count = 1;
result = avcodec_open2(ctx, codec, NULL);
if (result < 0) {
av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");
return result;
}
fr = av_frame_alloc();
if (!fr) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n");
return AVERROR(ENOMEM);
}
pkt = av_packet_alloc();
if (!pkt) {
av_log(NULL, AV_LOG_ERROR, "Cannot allocate packet\n");
return AVERROR(ENOMEM);
}
byte_buffer_size = av_image_get_buffer_size(ctx->pix_fmt, ctx->width, ctx->height, 32);
byte_buffer = av_malloc(byte_buffer_size);
if (!byte_buffer) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate buffer\n");
return AVERROR(ENOMEM);
}
slice_byte_buffer = av_malloc(byte_buffer_size);
if (!slice_byte_buffer) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate buffer\n");
return AVERROR(ENOMEM);
}
memset(slice_byte_buffer, 0, byte_buffer_size);
result = 0;
while (result >= 0) {
result = av_read_frame(fmt_ctx, pkt);
if (result >= 0 && pkt->stream_index != video_stream) {
av_packet_unref(pkt);
continue;
}
// pkt will be empty on read error/EOF
result = avcodec_send_packet(ctx, pkt);
av_packet_unref(pkt);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
return result;
}
while (result >= 0) {
result = avcodec_receive_frame(ctx, fr);
if (result == AVERROR_EOF)
goto finish;
else if (result == AVERROR(EAGAIN)) {
result = 0;
break;
} else if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error decoding frame\n");
return result;
}
number_of_written_bytes = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
(const uint8_t* const *)fr->data, (const int*) fr->linesize,
ctx->pix_fmt, ctx->width, ctx->height, 1);
if (number_of_written_bytes < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't copy image to buffer\n");
return number_of_written_bytes;
}
if (draw_horiz_band_called == 0) {
av_log(NULL, AV_LOG_ERROR, "draw_horiz_band haven't been called!\n");
return -1;
}
if (av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes) !=
av_adler32_update(0, (const uint8_t*)slice_byte_buffer, number_of_written_bytes)) {
av_log(NULL, AV_LOG_ERROR, "Decoded frames with and without draw_horiz_band are not the same!\n");
return -1;
}
av_frame_unref(fr);
}
}
finish:
av_packet_free(&pkt);
av_frame_free(&fr);
avformat_close_input(&fmt_ctx);
avcodec_free_context(&ctx);
av_freep(&byte_buffer);
av_freep(&slice_byte_buffer);
return 0;
}
int main(int argc, char **argv)
{
if (argc < 2)
{
av_log(NULL, AV_LOG_ERROR, "Incorrect input: expected %s <name of a video file>\n", argv[0]);
return 1;
}
if (video_decode(argv[1]) != 0)
return 1;
return 0;
}
+284
View File
@@ -0,0 +1,284 @@
/*
* Copyright (c) 2015 Ludmila Glinskih
* Copyright (c) 2001 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* FLAC codec test.
* Encodes raw data to FLAC format and decodes it back to raw. Compares raw-data
* after that.
*/
#include "libavcodec/avcodec.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/mem.h"
#include "libavutil/samplefmt.h"
#define NUMBER_OF_AUDIO_FRAMES 200
#define NAME_BUFF_SIZE 100
/* generate i-th frame of test audio */
static int generate_raw_frame(uint16_t *frame_data, int i, int sample_rate,
int channels, int frame_size)
{
int j, k;
for (j = 0; j < frame_size; j++) {
frame_data[channels * j] = 10000 * ((j / 10 * i) % 2);
for (k = 1; k < channels; k++)
frame_data[channels * j + k] = frame_data[channels * j] * (k + 1);
}
return 0;
}
static int init_encoder(const AVCodec *enc, AVCodecContext **enc_ctx,
const AVChannelLayout *ch_layout, int sample_rate)
{
AVCodecContext *ctx;
int result;
char name_buff[NAME_BUFF_SIZE];
av_channel_layout_describe(ch_layout, name_buff, NAME_BUFF_SIZE);
av_log(NULL, AV_LOG_INFO, "channel layout: %s, sample rate: %i\n", name_buff, sample_rate);
ctx = avcodec_alloc_context3(enc);
if (!ctx) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate encoder context\n");
return AVERROR(ENOMEM);
}
ctx->sample_fmt = AV_SAMPLE_FMT_S16;
ctx->sample_rate = sample_rate;
av_channel_layout_copy(&ctx->ch_layout, ch_layout);
result = avcodec_open2(ctx, enc, NULL);
if (result < 0) {
av_log(ctx, AV_LOG_ERROR, "Can't open encoder\n");
return result;
}
*enc_ctx = ctx;
return 0;
}
static int init_decoder(const AVCodec *dec, AVCodecContext **dec_ctx,
const AVChannelLayout *ch_layout)
{
AVCodecContext *ctx;
int result;
ctx = avcodec_alloc_context3(dec);
if (!ctx) {
av_log(NULL, AV_LOG_ERROR , "Can't allocate decoder context\n");
return AVERROR(ENOMEM);
}
ctx->request_sample_fmt = AV_SAMPLE_FMT_S16;
av_channel_layout_copy(&ctx->ch_layout, ch_layout);
result = avcodec_open2(ctx, dec, NULL);
if (result < 0) {
av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");
return result;
}
*dec_ctx = ctx;
return 0;
}
static int run_test(const AVCodec *enc, const AVCodec *dec,
AVCodecContext *enc_ctx, AVCodecContext *dec_ctx)
{
AVPacket *enc_pkt;
AVFrame *in_frame, *out_frame;
uint8_t *raw_in = NULL, *raw_out = NULL;
int in_offset = 0, out_offset = 0;
int result = 0;
int i = 0;
int in_frame_bytes, out_frame_bytes;
enc_pkt = av_packet_alloc();
if (!enc_pkt) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate output packet\n");
return AVERROR(ENOMEM);
}
in_frame = av_frame_alloc();
if (!in_frame) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate input frame\n");
return AVERROR(ENOMEM);
}
in_frame->nb_samples = enc_ctx->frame_size;
in_frame->format = enc_ctx->sample_fmt;
result = av_channel_layout_copy(&in_frame->ch_layout, &enc_ctx->ch_layout);
if (result < 0)
return result;
if (av_frame_get_buffer(in_frame, 0) != 0) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate a buffer for input frame\n");
return AVERROR(ENOMEM);
}
out_frame = av_frame_alloc();
if (!out_frame) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate output frame\n");
return AVERROR(ENOMEM);
}
raw_in = av_malloc(in_frame->linesize[0] * NUMBER_OF_AUDIO_FRAMES);
if (!raw_in) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate memory for raw_in\n");
return AVERROR(ENOMEM);
}
raw_out = av_malloc(in_frame->linesize[0] * NUMBER_OF_AUDIO_FRAMES);
if (!raw_out) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate memory for raw_out\n");
return AVERROR(ENOMEM);
}
for (i = 0; i < NUMBER_OF_AUDIO_FRAMES; i++) {
result = av_frame_make_writable(in_frame);
if (result < 0)
return result;
generate_raw_frame((uint16_t*)(in_frame->data[0]), i, enc_ctx->sample_rate,
enc_ctx->ch_layout.nb_channels, enc_ctx->frame_size);
in_frame_bytes = in_frame->nb_samples * in_frame->ch_layout.nb_channels * sizeof(uint16_t);
if (in_frame_bytes > in_frame->linesize[0]) {
av_log(NULL, AV_LOG_ERROR, "Incorrect value of input frame linesize\n");
return 1;
}
memcpy(raw_in + in_offset, in_frame->data[0], in_frame_bytes);
in_offset += in_frame_bytes;
result = avcodec_send_frame(enc_ctx, in_frame);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error submitting a frame for encoding\n");
return result;
}
while (result >= 0) {
result = avcodec_receive_packet(enc_ctx, enc_pkt);
if (result == AVERROR(EAGAIN))
break;
else if (result < 0 && result != AVERROR_EOF) {
av_log(NULL, AV_LOG_ERROR, "Error encoding audio frame\n");
return result;
}
/* if we get an encoded packet, feed it straight to the decoder */
result = avcodec_send_packet(dec_ctx, enc_pkt);
av_packet_unref(enc_pkt);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
return result;
}
result = avcodec_receive_frame(dec_ctx, out_frame);
if (result == AVERROR(EAGAIN)) {
result = 0;
continue;
} else if (result == AVERROR(EOF)) {
result = 0;
break;
} else if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error decoding audio packet\n");
return result;
}
if (in_frame->nb_samples != out_frame->nb_samples) {
av_log(NULL, AV_LOG_ERROR, "Error frames before and after decoding has different number of samples\n");
return AVERROR_UNKNOWN;
}
if (av_channel_layout_compare(&in_frame->ch_layout, &out_frame->ch_layout)) {
av_log(NULL, AV_LOG_ERROR, "Error frames before and after decoding has different channel layout\n");
return AVERROR_UNKNOWN;
}
if (in_frame->format != out_frame->format) {
av_log(NULL, AV_LOG_ERROR, "Error frames before and after decoding has different sample format\n");
return AVERROR_UNKNOWN;
}
out_frame_bytes = out_frame->nb_samples * out_frame->ch_layout.nb_channels * sizeof(uint16_t);
if (out_frame_bytes > out_frame->linesize[0]) {
av_log(NULL, AV_LOG_ERROR, "Incorrect value of output frame linesize\n");
return 1;
}
memcpy(raw_out + out_offset, out_frame->data[0], out_frame_bytes);
out_offset += out_frame_bytes;
}
}
if (memcmp(raw_in, raw_out, out_frame_bytes * NUMBER_OF_AUDIO_FRAMES) != 0) {
av_log(NULL, AV_LOG_ERROR, "Output differs\n");
return 1;
}
av_log(NULL, AV_LOG_INFO, "OK\n");
av_freep(&raw_in);
av_freep(&raw_out);
av_packet_free(&enc_pkt);
av_frame_free(&in_frame);
av_frame_free(&out_frame);
return 0;
}
int main(void)
{
const AVCodec *enc = NULL, *dec = NULL;
AVCodecContext *enc_ctx = NULL, *dec_ctx = NULL;
const AVChannelLayout channel_layouts[] = { AV_CHANNEL_LAYOUT_STEREO,
AV_CHANNEL_LAYOUT_5POINT1_BACK,
AV_CHANNEL_LAYOUT_SURROUND,
AV_CHANNEL_LAYOUT_STEREO_DOWNMIX };
int sample_rates[] = {8000, 44100, 48000, 192000};
int cl, sr;
enc = avcodec_find_encoder(AV_CODEC_ID_FLAC);
if (!enc) {
av_log(NULL, AV_LOG_ERROR, "Can't find encoder\n");
return 1;
}
dec = avcodec_find_decoder(AV_CODEC_ID_FLAC);
if (!dec) {
av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
return 1;
}
for (cl = 0; cl < FF_ARRAY_ELEMS(channel_layouts); cl++) {
for (sr = 0; sr < FF_ARRAY_ELEMS(sample_rates); sr++) {
if (init_encoder(enc, &enc_ctx, &channel_layouts[cl], sample_rates[sr]) != 0)
return 1;
if (init_decoder(dec, &dec_ctx, &channel_layouts[cl]) != 0)
return 1;
if (run_test(enc, dec, enc_ctx, dec_ctx) != 0)
return 1;
avcodec_free_context(&enc_ctx);
avcodec_free_context(&dec_ctx);
}
}
return 0;
}
+238
View File
@@ -0,0 +1,238 @@
/*
* Copyright (c) 2001 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define MAX_SLICES 8
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_IO_H
#include <io.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "libavcodec/avcodec.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "libavutil/hash.h"
#include "libavutil/bswap.h"
static int header = 0;
static int decode(AVCodecContext *dec_ctx, AVFrame *frame,
AVPacket *pkt)
{
static uint64_t frame_cnt = 0;
int ret;
ret = avcodec_send_packet(dec_ctx, pkt);
if (ret < 0) {
fprintf(stderr, "Error sending a packet for decoding: %s\n", av_err2str(ret));
return ret;
}
while (ret >= 0) {
const AVPixFmtDescriptor *desc;
char sum[AV_HASH_MAX_SIZE * 2 + 1];
struct AVHashContext *hash;
ret = avcodec_receive_frame(dec_ctx, frame);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
return 0;
} else if (ret < 0) {
fprintf(stderr, "Error during decoding: %s\n", av_err2str(ret));
return ret;
}
if (!header) {
printf(
"#format: frame checksums\n"
"#version: 2\n"
"#hash: MD5\n"
"#tb 0: 1/30\n"
"#media_type 0: video\n"
"#codec_id 0: rawvideo\n"
"#dimensions 0: 352x288\n"
"#sar 0: 128/117\n"
"#stream#, dts, pts, duration, size, hash\n");
header = 1;
}
desc = av_pix_fmt_desc_get(dec_ctx->pix_fmt);
if ((ret = av_hash_alloc(&hash, "md5")) < 0) {
return ret;
}
av_hash_init(hash);
for (int i = 0; i < frame->height; i++)
av_hash_update(hash, &frame->data[0][i * frame->linesize[0]], frame->width);
for (int i = 0; i < frame->height >> desc->log2_chroma_h; i++)
av_hash_update(hash, &frame->data[1][i * frame->linesize[1]], frame->width >> desc->log2_chroma_w);
for (int i = 0; i < frame->height >> desc->log2_chroma_h; i++)
av_hash_update(hash, &frame->data[2][i * frame->linesize[2]], frame->width >> desc->log2_chroma_w);
av_hash_final_hex(hash, sum, av_hash_get_size(hash) * 2 + 1);
printf("0, %10"PRId64", %10"PRId64", 1, %8d, %s\n",
frame_cnt, frame_cnt,
(frame->width * frame->height + 2 * (frame->height >> desc->log2_chroma_h) * (frame->width >> desc->log2_chroma_w)), sum);
frame_cnt += 1;
av_hash_freep(&hash);
}
return 0;
}
int main(int argc, char **argv)
{
const AVCodec *codec = NULL;
AVCodecContext *c = NULL;
AVFrame *frame = NULL;
unsigned int threads;
AVPacket *pkt;
FILE *file = NULL;
char * nal = NULL;
int nals = 0, ret = 0;
char *p;
if (argc < 3) {
fprintf(stderr, "Usage: %s <threads> <input file>\n", argv[0]);
return -1;
}
if (!(threads = strtoul(argv[1], NULL, 0)))
threads = 1;
else if (threads > MAX_SLICES)
threads = MAX_SLICES;
#ifdef _WIN32
setmode(fileno(stdout), O_BINARY);
#endif
if (!(pkt = av_packet_alloc())) {
return -1;
}
nal = av_malloc(MAX_SLICES * UINT16_MAX + AV_INPUT_BUFFER_PADDING_SIZE);
if (!nal)
goto err;
p = nal;
if (!(codec = avcodec_find_decoder(AV_CODEC_ID_H264))) {
fprintf(stderr, "Codec not found\n");
ret = -1;
goto err;
}
if (!(c = avcodec_alloc_context3(codec))) {
fprintf(stderr, "Could not allocate video codec context\n");
ret = -1;
goto err;
}
c->width = 352;
c->height = 288;
c->flags2 |= AV_CODEC_FLAG2_CHUNKS;
c->thread_type = FF_THREAD_SLICE;
c->thread_count = threads;
if ((ret = avcodec_open2(c, codec, NULL)) < 0) {
fprintf(stderr, "Could not open codec\n");
goto err;
}
#if HAVE_THREADS
if (c->active_thread_type != FF_THREAD_SLICE) {
fprintf(stderr, "Couldn't activate slice threading: %d\n", c->active_thread_type);
ret = -1;
goto err;
}
#else
fprintf(stderr, "WARN: not using threads, only checking decoding slice NALUs\n");
#endif
if (!(frame = av_frame_alloc())) {
fprintf(stderr, "Could not allocate video frame\n");
ret = -1;
goto err;
}
if (!(file = fopen(argv[2], "rb"))) {
fprintf(stderr, "Couldn't open NALU file: %s\n", argv[2]);
ret = -1;
goto err;
}
while(1) {
uint16_t size = 0;
size_t ret = fread(&size, 1, sizeof(uint16_t), file);
if (ret != sizeof(uint16_t))
break;
size = av_be2ne16(size);
ret = fread(p, 1, size, file);
if (ret != size) {
perror("Couldn't read data");
goto err;
}
p += ret;
if (++nals >= threads) {
int decret = 0;
pkt->data = nal;
pkt->size = p - nal;
if ((decret = decode(c, frame, pkt)) < 0) {
goto err;
}
memset(nal, 0, MAX_SLICES * UINT16_MAX + AV_INPUT_BUFFER_PADDING_SIZE);
nals = 0;
p = nal;
}
}
if (nals) {
pkt->data = nal;
pkt->size = p - nal;
if ((ret = decode(c, frame, pkt)) < 0) {
goto err;
}
}
ret = decode(c, frame, NULL);
err:
if (nal)
av_free(nal);
if (file)
fclose(file);
av_frame_free(&frame);
avcodec_free_context(&c);
av_packet_free(&pkt);
return ret;
}
+187
View File
@@ -0,0 +1,187 @@
/*
* Copyright (c) 2015 Ludmila Glinskih
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* H264 codec test.
*/
#include "libavutil/adler32.h"
#include "libavutil/mem.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
#include "libavutil/timestamp.h"
static int video_decode_example(const char *input_filename)
{
const AVCodec *codec = NULL;
AVCodecContext *ctx= NULL;
AVCodecParameters *origin_par = NULL;
AVFrame *fr = NULL;
uint8_t *byte_buffer = NULL;
AVPacket *pkt;
AVFormatContext *fmt_ctx = NULL;
int number_of_written_bytes;
int video_stream;
int byte_buffer_size;
int i = 0;
int result;
result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't open file\n");
return result;
}
result = avformat_find_stream_info(fmt_ctx, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
return result;
}
video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
if (video_stream < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");
return -1;
}
origin_par = fmt_ctx->streams[video_stream]->codecpar;
codec = avcodec_find_decoder(origin_par->codec_id);
if (!codec) {
av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
return -1;
}
ctx = avcodec_alloc_context3(codec);
if (!ctx) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");
return AVERROR(ENOMEM);
}
result = avcodec_parameters_to_context(ctx, origin_par);
if (result) {
av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");
return result;
}
result = avcodec_open2(ctx, codec, NULL);
if (result < 0) {
av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");
return result;
}
fr = av_frame_alloc();
if (!fr) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n");
return AVERROR(ENOMEM);
}
pkt = av_packet_alloc();
if (!pkt) {
av_log(NULL, AV_LOG_ERROR, "Cannot allocate packet\n");
return AVERROR(ENOMEM);
}
byte_buffer_size = av_image_get_buffer_size(ctx->pix_fmt, ctx->width, ctx->height, 16);
byte_buffer = av_malloc(byte_buffer_size);
if (!byte_buffer) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate buffer\n");
return AVERROR(ENOMEM);
}
printf("#tb %d: %d/%d\n", video_stream, fmt_ctx->streams[video_stream]->time_base.num, fmt_ctx->streams[video_stream]->time_base.den);
i = 0;
result = 0;
while (result >= 0) {
result = av_read_frame(fmt_ctx, pkt);
if (result >= 0 && pkt->stream_index != video_stream) {
av_packet_unref(pkt);
continue;
}
if (result < 0)
result = avcodec_send_packet(ctx, NULL);
else {
if (pkt->pts == AV_NOPTS_VALUE)
pkt->pts = pkt->dts = i;
result = avcodec_send_packet(ctx, pkt);
}
av_packet_unref(pkt);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
return result;
}
while (result >= 0) {
result = avcodec_receive_frame(ctx, fr);
if (result == AVERROR_EOF)
goto finish;
else if (result == AVERROR(EAGAIN)) {
result = 0;
break;
} else if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error decoding frame\n");
return result;
}
number_of_written_bytes = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
(const uint8_t* const *)fr->data, (const int*) fr->linesize,
ctx->pix_fmt, ctx->width, ctx->height, 1);
if (number_of_written_bytes < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't copy image to buffer\n");
av_frame_unref(fr);
return number_of_written_bytes;
}
printf("%d, %s, %s, %8"PRId64", %8d, 0x%08"PRIx32"\n", video_stream,
av_ts2str(fr->pts), av_ts2str(fr->pkt_dts), fr->duration,
number_of_written_bytes, av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes));
av_frame_unref(fr);
}
i++;
}
finish:
av_packet_free(&pkt);
av_frame_free(&fr);
avformat_close_input(&fmt_ctx);
avcodec_free_context(&ctx);
av_freep(&byte_buffer);
return 0;
}
int main(int argc, char **argv)
{
if (argc < 2)
{
av_log(NULL, AV_LOG_ERROR, "Incorrect input\n");
return 1;
}
if (video_decode_example(argv[1]) != 0)
return 1;
return 0;
}
+306
View File
@@ -0,0 +1,306 @@
/*
* Copyright (c) 2015 Ludmila Glinskih
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Seek test.
*/
#include "libavutil/adler32.h"
#include "libavutil/mem.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
int64_t *pts_array;
uint32_t *crc_array;
int size_of_array;
int number_of_elements;
static int add_crc_to_array(uint32_t crc, int64_t pts)
{
if (size_of_array <= number_of_elements) {
if (size_of_array == 0)
size_of_array = 10;
size_of_array *= 2;
crc_array = av_realloc_f(crc_array, size_of_array, sizeof(uint32_t));
pts_array = av_realloc_f(pts_array, size_of_array, sizeof(int64_t));
if ((crc_array == NULL) || (pts_array == NULL)) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate array to store crcs\n");
return AVERROR(ENOMEM);
}
}
crc_array[number_of_elements] = crc;
pts_array[number_of_elements] = pts;
number_of_elements++;
return 0;
}
static int compare_crc_in_array(uint32_t crc, int64_t pts)
{
int i;
for (i = 0; i < number_of_elements; i++) {
if (pts_array[i] == pts) {
if (crc_array[i] == crc) {
printf("Comparing 0x%08"PRIx32" %"PRId64" %d is OK\n", crc, pts, i);
return 0;
}
else {
av_log(NULL, AV_LOG_ERROR, "Incorrect crc of a frame after seeking\n");
return -1;
}
}
}
av_log(NULL, AV_LOG_ERROR, "Incorrect pts of a frame after seeking\n");
return -1;
}
static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
AVCodecContext *ctx, AVPacket *pkt, AVFrame *fr,
uint64_t ts_start, uint64_t ts_end, int no_seeking)
{
int number_of_written_bytes;
int result;
int byte_buffer_size;
uint8_t *byte_buffer;
uint32_t crc;
byte_buffer_size = av_image_get_buffer_size(ctx->pix_fmt, ctx->width, ctx->height, 16);
byte_buffer = av_malloc(byte_buffer_size);
if (!byte_buffer) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate buffer\n");
return AVERROR(ENOMEM);
}
if (!no_seeking) {
result = av_seek_frame(fmt_ctx, video_stream, ts_start, AVSEEK_FLAG_ANY);
printf("Seeking to %"PRId64", computing crc for frames with pts < %"PRId64"\n", ts_start, ts_end);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error in seeking\n");
return result;
}
avcodec_flush_buffers(ctx);
}
do {
result = av_read_frame(fmt_ctx, pkt);
if (result >= 0 && pkt->stream_index != video_stream) {
av_packet_unref(pkt);
continue;
}
if (result < 0)
result = avcodec_send_packet(ctx, NULL);
else {
if (pkt->pts == AV_NOPTS_VALUE) {
av_log(NULL, AV_LOG_ERROR, "Error: frames doesn't have pts values\n");
return -1;
}
result = avcodec_send_packet(ctx, pkt);
}
av_packet_unref(pkt);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
return result;
}
while (result >= 0) {
result = avcodec_receive_frame(ctx, fr);
if (result == AVERROR_EOF)
goto finish;
else if (result == AVERROR(EAGAIN)) {
result = 0;
break;
} else if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Error decoding frame\n");
return result;
}
number_of_written_bytes = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
(const uint8_t* const *)fr->data, (const int*) fr->linesize,
ctx->pix_fmt, ctx->width, ctx->height, 1);
if (number_of_written_bytes < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't copy image to buffer\n");
return number_of_written_bytes;
}
if ((!no_seeking) && (fr->pts > ts_end))
break;
crc = av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes);
printf("%10"PRId64", 0x%08"PRIx32"\n", fr->pts, crc);
if (no_seeking) {
if (add_crc_to_array(crc, fr->pts) < 0)
return -1;
}
else {
if (compare_crc_in_array(crc, fr->pts) < 0)
return -1;
}
av_frame_unref(fr);
}
} while (result >= 0 && (no_seeking || (fr->pts + fr->duration <= ts_end)));
finish:
av_freep(&byte_buffer);
return 0;
}
static long int read_seek_range(const char *string_with_number)
{
long int number;
char *end_of_string = NULL;
number = strtol(string_with_number, &end_of_string, 10);
if ((strlen(string_with_number) != end_of_string - string_with_number) || (number < 0)) {
av_log(NULL, AV_LOG_ERROR, "Incorrect input ranges of seeking\n");
return -1;
}
else if ((number == LONG_MAX) || (number == LONG_MIN)) {
if (errno == ERANGE) {
av_log(NULL, AV_LOG_ERROR, "Incorrect input ranges of seeking\n");
return -1;
}
}
return number;
}
static int seek_test(const char *input_filename, const char *start, const char *end)
{
const AVCodec *codec = NULL;
AVCodecContext *ctx= NULL;
AVCodecParameters *origin_par = NULL;
AVPacket *pkt = NULL;
AVFrame *fr = NULL;
AVFormatContext *fmt_ctx = NULL;
int video_stream;
int result;
int i, j;
long int start_ts, end_ts;
size_of_array = 0;
number_of_elements = 0;
crc_array = NULL;
pts_array = NULL;
result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't open file\n");
return result;
}
result = avformat_find_stream_info(fmt_ctx, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
goto end;
}
start_ts = read_seek_range(start);
end_ts = read_seek_range(end);
if ((start_ts < 0) || (end_ts < 0)) {
result = -1;
goto end;
}
//TODO: add ability to work with audio format
video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
if (video_stream < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");
result = video_stream;
goto end;
}
origin_par = fmt_ctx->streams[video_stream]->codecpar;
codec = avcodec_find_decoder(origin_par->codec_id);
if (!codec) {
av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
result = AVERROR_DECODER_NOT_FOUND;
goto end;
}
ctx = avcodec_alloc_context3(codec);
if (!ctx) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");
result = AVERROR(ENOMEM);
goto end;
}
result = avcodec_parameters_to_context(ctx, origin_par);
if (result) {
av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");
goto end;
}
result = avcodec_open2(ctx, codec, NULL);
if (result < 0) {
av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");
goto end;
}
fr = av_frame_alloc();
if (!fr) {
av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n");
result = AVERROR(ENOMEM);
goto end;
}
pkt = av_packet_alloc();
if (!pkt) {
av_log(NULL, AV_LOG_ERROR, "Cannot allocate packet\n");
result = AVERROR(ENOMEM);
goto end;
}
result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, pkt, fr, 0, 0, 1);
if (result != 0)
goto end;
for (i = start_ts; i < end_ts; i += 100) {
for (j = i + 100; j < end_ts; j += 100) {
result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, pkt, fr, i, j, 0);
if (result != 0)
break;
}
}
end:
av_freep(&crc_array);
av_freep(&pts_array);
av_packet_free(&pkt);
av_frame_free(&fr);
avformat_close_input(&fmt_ctx);
avcodec_free_context(&ctx);
return result;
}
int main(int argc, char **argv)
{
if (argc < 4) {
av_log(NULL, AV_LOG_ERROR, "Incorrect input\n");
return 1;
}
if (seek_test(argv[1], argv[2], argv[3]) != 0)
return 1;
return 0;
}
+263
View File
@@ -0,0 +1,263 @@
/*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Thread message API test
*/
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/frame.h"
#include "libavutil/mem.h"
#include "libavutil/threadmessage.h"
#include "libavutil/thread.h" // not public
struct sender_data {
int id;
pthread_t tid;
int workload;
AVThreadMessageQueue *queue;
};
/* same as sender_data but shuffled for testing purpose */
struct receiver_data {
pthread_t tid;
int workload;
int id;
AVThreadMessageQueue *queue;
};
struct message {
AVFrame *frame;
// we add some junk in the message to make sure the message size is >
// sizeof(void*)
int magic;
};
#define MAGIC 0xdeadc0de
static void free_frame(void *arg)
{
struct message *msg = arg;
av_assert0(msg->magic == MAGIC);
av_frame_free(&msg->frame);
}
static void *sender_thread(void *arg)
{
int i, ret = 0;
struct sender_data *wd = arg;
av_log(NULL, AV_LOG_INFO, "sender #%d: workload=%d\n", wd->id, wd->workload);
for (i = 0; i < wd->workload; i++) {
if (rand() % wd->workload < wd->workload / 10) {
av_log(NULL, AV_LOG_INFO, "sender #%d: flushing the queue\n", wd->id);
av_thread_message_flush(wd->queue);
} else {
char *val;
AVDictionary *meta = NULL;
struct message msg = {
.magic = MAGIC,
.frame = av_frame_alloc(),
};
if (!msg.frame) {
ret = AVERROR(ENOMEM);
break;
}
/* we add some metadata to identify the frames */
val = av_asprintf("frame %d/%d from sender %d",
i + 1, wd->workload, wd->id);
if (!val) {
av_frame_free(&msg.frame);
ret = AVERROR(ENOMEM);
break;
}
ret = av_dict_set(&meta, "sig", val, AV_DICT_DONT_STRDUP_VAL);
if (ret < 0) {
av_frame_free(&msg.frame);
break;
}
msg.frame->metadata = meta;
/* allocate a real frame in order to simulate "real" work */
msg.frame->format = AV_PIX_FMT_RGBA;
msg.frame->width = 320;
msg.frame->height = 240;
ret = av_frame_get_buffer(msg.frame, 0);
if (ret < 0) {
av_frame_free(&msg.frame);
break;
}
/* push the frame in the common queue */
av_log(NULL, AV_LOG_INFO, "sender #%d: sending my work (%d/%d frame:%p)\n",
wd->id, i + 1, wd->workload, msg.frame);
ret = av_thread_message_queue_send(wd->queue, &msg, 0);
if (ret < 0) {
av_frame_free(&msg.frame);
break;
}
}
}
av_log(NULL, AV_LOG_INFO, "sender #%d: my work is done here (%s)\n",
wd->id, av_err2str(ret));
av_thread_message_queue_set_err_recv(wd->queue, ret < 0 ? ret : AVERROR_EOF);
return NULL;
}
static void *receiver_thread(void *arg)
{
int i, ret = 0;
struct receiver_data *rd = arg;
for (i = 0; i < rd->workload; i++) {
if (rand() % rd->workload < rd->workload / 10) {
av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue, "
"discarding %d message(s)\n", rd->id,
av_thread_message_queue_nb_elems(rd->queue));
av_thread_message_flush(rd->queue);
} else {
struct message msg;
AVDictionary *meta;
AVDictionaryEntry *e;
ret = av_thread_message_queue_recv(rd->queue, &msg, 0);
if (ret < 0)
break;
av_assert0(msg.magic == MAGIC);
meta = msg.frame->metadata;
e = av_dict_get(meta, "sig", NULL, 0);
av_log(NULL, AV_LOG_INFO, "got \"%s\" (%p)\n", e->value, msg.frame);
av_frame_free(&msg.frame);
}
}
av_log(NULL, AV_LOG_INFO, "consumed enough (%d), stop\n", i);
av_thread_message_queue_set_err_send(rd->queue, ret < 0 ? ret : AVERROR_EOF);
return NULL;
}
static int get_workload(int minv, int maxv)
{
return maxv == minv ? maxv : rand() % (maxv - minv) + minv;
}
int main(int ac, char **av)
{
int i, ret = 0;
int max_queue_size;
int nb_senders, sender_min_load, sender_max_load;
int nb_receivers, receiver_min_load, receiver_max_load;
struct sender_data *senders;
struct receiver_data *receivers;
AVThreadMessageQueue *queue = NULL;
if (ac != 8) {
av_log(NULL, AV_LOG_ERROR, "%s <max_queue_size> "
"<nb_senders> <sender_min_send> <sender_max_send> "
"<nb_receivers> <receiver_min_recv> <receiver_max_recv>\n", av[0]);
return 1;
}
max_queue_size = atoi(av[1]);
nb_senders = atoi(av[2]);
sender_min_load = atoi(av[3]);
sender_max_load = atoi(av[4]);
nb_receivers = atoi(av[5]);
receiver_min_load = atoi(av[6]);
receiver_max_load = atoi(av[7]);
if (max_queue_size <= 0 ||
nb_senders <= 0 || sender_min_load <= 0 || sender_max_load <= 0 ||
nb_receivers <= 0 || receiver_min_load <= 0 || receiver_max_load <= 0) {
av_log(NULL, AV_LOG_ERROR, "negative values not allowed\n");
return 1;
}
av_log(NULL, AV_LOG_INFO, "qsize:%d / %d senders sending [%d-%d] / "
"%d receivers receiving [%d-%d]\n", max_queue_size,
nb_senders, sender_min_load, sender_max_load,
nb_receivers, receiver_min_load, receiver_max_load);
senders = av_calloc(nb_senders, sizeof(*senders));
receivers = av_calloc(nb_receivers, sizeof(*receivers));
if (!senders || !receivers) {
ret = AVERROR(ENOMEM);
goto end;
}
ret = av_thread_message_queue_alloc(&queue, max_queue_size, sizeof(struct message));
if (ret < 0)
goto end;
av_thread_message_queue_set_free_func(queue, free_frame);
#define SPAWN_THREADS(type) do { \
for (i = 0; i < nb_##type##s; i++) { \
struct type##_data *td = &type##s[i]; \
\
td->id = i; \
td->queue = queue; \
td->workload = get_workload(type##_min_load, type##_max_load); \
\
ret = pthread_create(&td->tid, NULL, type##_thread, td); \
if (ret) { \
const int err = AVERROR(ret); \
av_log(NULL, AV_LOG_ERROR, "Unable to start " AV_STRINGIFY(type) \
" thread: %s\n", av_err2str(err)); \
goto end; \
} \
} \
} while (0)
#define WAIT_THREADS(type) do { \
for (i = 0; i < nb_##type##s; i++) { \
struct type##_data *td = &type##s[i]; \
\
ret = pthread_join(td->tid, NULL); \
if (ret) { \
const int err = AVERROR(ret); \
av_log(NULL, AV_LOG_ERROR, "Unable to join " AV_STRINGIFY(type) \
" thread: %s\n", av_err2str(err)); \
goto end; \
} \
} \
} while (0)
SPAWN_THREADS(receiver);
SPAWN_THREADS(sender);
WAIT_THREADS(sender);
WAIT_THREADS(receiver);
end:
av_thread_message_queue_free(&queue);
av_freep(&senders);
av_freep(&receivers);
if (ret < 0 && ret != AVERROR_EOF) {
av_log(NULL, AV_LOG_ERROR, "Error: %s\n", av_err2str(ret));
return 1;
}
return 0;
}
+248
View File
@@ -0,0 +1,248 @@
/*
* Generate a synthetic stereo sound.
* NOTE: No floats are used to guarantee bitexact output.
*
* Copyright (c) 2002 Fabrice Bellard
*
* 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 <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define MAX_CHANNELS 12
static unsigned int myrnd(unsigned int *seed_ptr, int n)
{
unsigned int seed, val;
seed = *seed_ptr;
seed = (seed * 314159) + 1;
if (n == 256) {
val = seed >> 24;
} else {
val = seed % n;
}
*seed_ptr = seed;
return val;
}
#define FRAC_BITS 16
#define FRAC_ONE (1 << FRAC_BITS)
#define COS_TABLE_BITS 7
/* integer cosine */
static const unsigned short cos_table[(1 << COS_TABLE_BITS) + 2] = {
0x8000, 0x7ffe, 0x7ff6, 0x7fea, 0x7fd9, 0x7fc2, 0x7fa7, 0x7f87,
0x7f62, 0x7f38, 0x7f0a, 0x7ed6, 0x7e9d, 0x7e60, 0x7e1e, 0x7dd6,
0x7d8a, 0x7d3a, 0x7ce4, 0x7c89, 0x7c2a, 0x7bc6, 0x7b5d, 0x7aef,
0x7a7d, 0x7a06, 0x798a, 0x790a, 0x7885, 0x77fb, 0x776c, 0x76d9,
0x7642, 0x75a6, 0x7505, 0x7460, 0x73b6, 0x7308, 0x7255, 0x719e,
0x70e3, 0x7023, 0x6f5f, 0x6e97, 0x6dca, 0x6cf9, 0x6c24, 0x6b4b,
0x6a6e, 0x698c, 0x68a7, 0x67bd, 0x66d0, 0x65de, 0x64e9, 0x63ef,
0x62f2, 0x61f1, 0x60ec, 0x5fe4, 0x5ed7, 0x5dc8, 0x5cb4, 0x5b9d,
0x5a82, 0x5964, 0x5843, 0x571e, 0x55f6, 0x54ca, 0x539b, 0x5269,
0x5134, 0x4ffb, 0x4ec0, 0x4d81, 0x4c40, 0x4afb, 0x49b4, 0x486a,
0x471d, 0x45cd, 0x447b, 0x4326, 0x41ce, 0x4074, 0x3f17, 0x3db8,
0x3c57, 0x3af3, 0x398d, 0x3825, 0x36ba, 0x354e, 0x33df, 0x326e,
0x30fc, 0x2f87, 0x2e11, 0x2c99, 0x2b1f, 0x29a4, 0x2827, 0x26a8,
0x2528, 0x23a7, 0x2224, 0x209f, 0x1f1a, 0x1d93, 0x1c0c, 0x1a83,
0x18f9, 0x176e, 0x15e2, 0x1455, 0x12c8, 0x113a, 0x0fab, 0x0e1c,
0x0c8c, 0x0afb, 0x096b, 0x07d9, 0x0648, 0x04b6, 0x0324, 0x0192,
0x0000, 0x0000,
};
#define CSHIFT (FRAC_BITS - COS_TABLE_BITS - 2)
static int int_cos(int a)
{
int neg, v, f;
const unsigned short *p;
a = a & (FRAC_ONE - 1); /* modulo 2 * pi */
if (a >= (FRAC_ONE / 2))
a = FRAC_ONE - a;
neg = 0;
if (a > (FRAC_ONE / 4)) {
neg = -1;
a = (FRAC_ONE / 2) - a;
}
p = cos_table + (a >> CSHIFT);
/* linear interpolation */
f = a & ((1 << CSHIFT) - 1);
v = p[0] + (((p[1] - p[0]) * f + (1 << (CSHIFT - 1))) >> CSHIFT);
v = (v ^ neg) - neg;
v = v << (FRAC_BITS - 15);
return v;
}
FILE *outfile;
static void put16(int16_t v)
{
fputc( v & 0xff, outfile);
fputc((v >> 8) & 0xff, outfile);
}
static void put32(uint32_t v)
{
fputc( v & 0xff, outfile);
fputc((v >> 8) & 0xff, outfile);
fputc((v >> 16) & 0xff, outfile);
fputc((v >> 24) & 0xff, outfile);
}
#define HEADER_SIZE 38
#define FMT_SIZE 18
#define SAMPLE_SIZE 2
#define WFORMAT_PCM 0x0001
static void put_wav_header(int sample_rate, int channels, int nb_samples)
{
int block_align = SAMPLE_SIZE * channels;
int data_size = block_align * nb_samples;
fputs("RIFF", outfile);
put32(HEADER_SIZE + data_size);
fputs("WAVEfmt ", outfile);
put32(FMT_SIZE);
put16(WFORMAT_PCM);
put16(channels);
put32(sample_rate);
put32(block_align * sample_rate);
put16(block_align);
put16(SAMPLE_SIZE * 8);
put16(0);
fputs("data", outfile);
put32(data_size);
}
int main(int argc, char **argv)
{
int i, a, v, j, f, amp, ampa;
unsigned int seed = 1;
int tabf1[MAX_CHANNELS], tabf2[MAX_CHANNELS];
int taba[MAX_CHANNELS];
int sample_rate = 44100;
int nb_channels = 2;
char *ext;
if (argc < 2 || argc > 5) {
printf("usage: %s file [<sample rate> [<channels>] [<random seed>]]\n"
"generate a test raw 16 bit audio stream\n"
"If the file extension is .wav a WAVE header will be added.\n"
"default: 44100 Hz stereo\n", argv[0]);
exit(1);
}
if (argc > 2) {
sample_rate = atoi(argv[2]);
if (sample_rate <= 0) {
fprintf(stderr, "invalid sample rate: %d\n", sample_rate);
return 1;
}
}
if (argc > 3) {
nb_channels = atoi(argv[3]);
if (nb_channels < 1 || nb_channels > MAX_CHANNELS) {
fprintf(stderr, "invalid number of channels: %d\n", nb_channels);
return 1;
}
}
if (argc > 4)
seed = atoi(argv[4]);
outfile = fopen(argv[1], "wb");
if (!outfile) {
perror(argv[1]);
return 1;
}
if ((ext = strrchr(argv[1], '.')) && !strcmp(ext, ".wav"))
put_wav_header(sample_rate, nb_channels, 6 * sample_rate);
/* 1 second of single freq sine at 1000 Hz */
a = 0;
for (i = 0; i < 1 * sample_rate; i++) {
v = (int_cos(a) * 10000) >> FRAC_BITS;
for (j = 0; j < nb_channels; j++)
put16(v);
a += (1000 * FRAC_ONE) / sample_rate;
}
/* 1 second of varying frequency between 100 and 10000 Hz */
a = 0;
for (i = 0; i < 1 * sample_rate; i++) {
v = (int_cos(a) * 10000) >> FRAC_BITS;
for (j = 0; j < nb_channels; j++)
put16(v);
f = 100 + (((10000 - 100) * i) / sample_rate);
a += (f * FRAC_ONE) / sample_rate;
}
/* 0.5 second of low amplitude white noise */
for (i = 0; i < sample_rate / 2; i++) {
v = myrnd(&seed, 20000) - 10000;
for (j = 0; j < nb_channels; j++)
put16(v);
}
/* 0.5 second of high amplitude white noise */
for (i = 0; i < sample_rate / 2; i++) {
v = myrnd(&seed, 65535) - 32768;
for (j = 0; j < nb_channels; j++)
put16(v);
}
/* 1 second of unrelated ramps for each channel */
for (j = 0; j < nb_channels; j++) {
taba[j] = 0;
tabf1[j] = 100 + myrnd(&seed, 5000);
tabf2[j] = 100 + myrnd(&seed, 5000);
}
for (i = 0; i < 1 * sample_rate; i++) {
for (j = 0; j < nb_channels; j++) {
v = (int_cos(taba[j]) * 10000) >> FRAC_BITS;
put16(v);
f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / sample_rate);
taba[j] += (f * FRAC_ONE) / sample_rate;
}
}
/* 2 seconds of 500 Hz with varying volume */
a = 0;
ampa = 0;
for (i = 0; i < 2 * sample_rate; i++) {
for (j = 0; j < nb_channels; j++) {
amp = ((FRAC_ONE + int_cos(ampa)) * 5000) >> FRAC_BITS;
if (j & 1)
amp = 10000 - amp;
v = (int_cos(a) * amp) >> FRAC_BITS;
put16(v);
a += (500 * FRAC_ONE) / sample_rate;
ampa += (2 * FRAC_ONE) / sample_rate;
}
}
fclose(outfile);
return 0;
}
+122
View File
@@ -0,0 +1,122 @@
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <inttypes.h>
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
static int64_t fsize(FILE *f) {
int64_t end, pos = ftell(f);
fseek(f, 0, SEEK_END);
end = ftell(f);
fseek(f, pos, SEEK_SET);
return end;
}
int main(int argc, char **argv) {
FILE *f[2];
int i, pos;
int siglen, datlen;
int bestpos = 0;
double bestc = 0;
double sigamp = 0;
int16_t *signal, *data;
int maxshift = 16384;
if (argc < 3) {
printf("audiomatch <testfile> <reffile>\n");
printf("WAV headers are skipped automatically.\n");
return 1;
}
f[0] = fopen(argv[1], "rb");
f[1] = fopen(argv[2], "rb");
if (!f[0] || !f[1]) {
fprintf(stderr, "Could not open input files.\n");
return 1;
}
for (i = 0; i < 2; i++) {
uint8_t p[100];
if (fread(p, 1, 12, f[i]) != 12)
return 1;
if (!memcmp(p, "RIFF", 4) &&
!memcmp(p + 8, "WAVE", 4)) {
if (fread(p, 1, 8, f[i]) != 8)
return 1;
while (memcmp(p, "data", 4)) {
int s = p[4] | p[5] << 8 | p[6] << 16 | p[7] << 24;
fseek(f[i], s, SEEK_CUR);
if (fread(p, 1, 8, f[i]) != 8)
return 1;
}
} else {
fseek(f[i], -12, SEEK_CUR);
}
}
datlen = fsize(f[0]) - ftell(f[0]);
siglen = fsize(f[1]) - ftell(f[1]);
data = malloc(datlen * sizeof(*data));
signal = malloc(siglen * sizeof(*signal));
if (fread(data , 1, datlen, f[0]) != datlen)
goto read_fail;
if (fread(signal, 1, siglen, f[1]) != siglen)
goto read_fail;
datlen /= 2;
siglen /= 2;
for (i = 0; i < siglen; i++) {
signal[i] = ((uint8_t*)(signal + i))[0] + 256*((uint8_t*)(signal + i))[1];
sigamp += signal[i] * signal[i];
}
for (i = 0; i < datlen; i++)
data[i] = ((uint8_t*)(data + i))[0] + 256*((uint8_t*)(data + i))[1];
for (pos = 0; pos < maxshift; pos = pos < 0 ? -pos: -pos-1) {
int64_t c = 0;
int testlen = FFMIN(siglen, datlen-pos);
for (i = FFMAX(0, -pos); i < testlen; i++) {
int j = pos + i;
c += signal[i] * data[j];
}
if (FFABS(c) > sigamp * 0.94)
maxshift = FFMIN(maxshift, FFABS(pos)+32);
if (FFABS(c) > FFABS(bestc)) {
bestc = c;
bestpos = pos;
}
}
printf("presig: %d postsig:%d c:%7.4f lenerr:%d\n", bestpos, datlen - siglen - bestpos, bestc / sigamp, datlen - siglen);
free(data);
free(signal);
return 0;
read_fail:
free(data);
free(signal);
return 1;
}
+54
View File
@@ -0,0 +1,54 @@
/*
* 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
*/
/*
* Based on libavutil/base64.c
*/
#include <stdio.h>
int main(void)
{
static const char b64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
unsigned i_bits = 0;
int i_shift = 0;
int out_len = 0;
int in;
#define putb64() \
do { \
putchar(b64[(i_bits << 6 >> i_shift) & 0x3f]); \
out_len++; \
i_shift -= 6; \
} while (0)
while ((in = getchar()) != EOF) {
i_bits = (i_bits << 8) + in;
i_shift += 8;
while (i_shift > 6)
putb64();
}
while (i_shift > 0)
putb64();
while (out_len++ & 3)
putchar('=');
putchar('\n');
return 0;
}
+1
View File
@@ -0,0 +1 @@
/checkasm
+111
View File
@@ -0,0 +1,111 @@
# libavcodec tests
# subsystems
AVCODECOBJS-$(CONFIG_AC3DSP) += ac3dsp.o
AVCODECOBJS-$(CONFIG_AUDIODSP) += audiodsp.o
AVCODECOBJS-$(CONFIG_BLOCKDSP) += blockdsp.o
AVCODECOBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o
AVCODECOBJS-$(CONFIG_FDCTDSP) += fdctdsp.o
AVCODECOBJS-$(CONFIG_FMTCONVERT) += fmtconvert.o
AVCODECOBJS-$(CONFIG_G722DSP) += g722dsp.o
AVCODECOBJS-$(CONFIG_H263DSP) += h263dsp.o
AVCODECOBJS-$(CONFIG_H264CHROMA) += h264chroma.o
AVCODECOBJS-$(CONFIG_H264DSP) += h264dsp.o
AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
AVCODECOBJS-$(CONFIG_H264QPEL) += h264qpel.o
AVCODECOBJS-$(CONFIG_IDCTDSP) += idctdsp.o
AVCODECOBJS-$(CONFIG_LLAUDDSP) += llauddsp.o
AVCODECOBJS-$(CONFIG_LLVIDDSP) += llviddsp.o
AVCODECOBJS-$(CONFIG_LLVIDENCDSP) += llviddspenc.o
AVCODECOBJS-$(CONFIG_LPC) += lpc.o
AVCODECOBJS-$(CONFIG_ME_CMP) += motion.o
AVCODECOBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideoencdsp.o
AVCODECOBJS-$(CONFIG_VC1DSP) += vc1dsp.o
AVCODECOBJS-$(CONFIG_VP8DSP) += vp8dsp.o
AVCODECOBJS-$(CONFIG_VIDEODSP) += videodsp.o
# decoders/encoders
AVCODECOBJS-$(CONFIG_AAC_DECODER) += aacpsdsp.o \
sbrdsp.o
AVCODECOBJS-$(CONFIG_AAC_ENCODER) += aacencdsp.o
AVCODECOBJS-$(CONFIG_ALAC_DECODER) += alacdsp.o
AVCODECOBJS-$(CONFIG_DCA_DECODER) += synth_filter.o
AVCODECOBJS-$(CONFIG_EXR_DECODER) += exrdsp.o
AVCODECOBJS-$(CONFIG_FLAC_DECODER) += flacdsp.o
AVCODECOBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuvdsp.o
AVCODECOBJS-$(CONFIG_JPEG2000_DECODER) += jpeg2000dsp.o
AVCODECOBJS-$(CONFIG_OPUS_DECODER) += opusdsp.o
AVCODECOBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o
AVCODECOBJS-$(CONFIG_HEVC_DECODER) += hevc_add_res.o hevc_deblock.o hevc_idct.o hevc_sao.o hevc_pel.o
AVCODECOBJS-$(CONFIG_RV34DSP) += rv34dsp.o
AVCODECOBJS-$(CONFIG_RV40_DECODER) += rv40dsp.o
AVCODECOBJS-$(CONFIG_SVQ1_ENCODER) += svq1enc.o
AVCODECOBJS-$(CONFIG_TAK_DECODER) += takdsp.o
AVCODECOBJS-$(CONFIG_UTVIDEO_DECODER) += utvideodsp.o
AVCODECOBJS-$(CONFIG_V210_DECODER) += v210dec.o
AVCODECOBJS-$(CONFIG_V210_ENCODER) += v210enc.o
AVCODECOBJS-$(CONFIG_VORBIS_DECODER) += vorbisdsp.o
AVCODECOBJS-$(CONFIG_VP9_DECODER) += vp9dsp.o
AVCODECOBJS-$(CONFIG_VVC_DECODER) += vvc_alf.o vvc_mc.o
CHECKASMOBJS-$(CONFIG_AVCODEC) += $(AVCODECOBJS-yes)
# libavfilter tests
AVFILTEROBJS-$(CONFIG_AFIR_FILTER) += af_afir.o
AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o
AVFILTEROBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o
AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o
AVFILTEROBJS-$(CONFIG_EQ_FILTER) += vf_eq.o
AVFILTEROBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o
AVFILTEROBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o
AVFILTEROBJS-$(CONFIG_THRESHOLD_FILTER) += vf_threshold.o
AVFILTEROBJS-$(CONFIG_NLMEANS_FILTER) += vf_nlmeans.o
AVFILTEROBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o
CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes)
# swscale tests
SWSCALEOBJS += sw_gbrp.o sw_range_convert.o sw_rgb.o sw_scale.o sw_yuv2rgb.o sw_yuv2yuv.o
CHECKASMOBJS-$(CONFIG_SWSCALE) += $(SWSCALEOBJS)
# libavutil tests
AVUTILOBJS += av_tx.o
AVUTILOBJS += fixed_dsp.o
AVUTILOBJS += float_dsp.o
AVUTILOBJS += lls.o
CHECKASMOBJS-$(CONFIG_AVUTIL) += $(AVUTILOBJS)
CHECKASMOBJS-$(ARCH_AARCH64) += aarch64/checkasm.o
CHECKASMOBJS-$(HAVE_ARMV5TE_EXTERNAL) += arm/checkasm.o
CHECKASMOBJS-$(HAVE_RV) += riscv/checkasm.o
CHECKASMOBJS-$(HAVE_X86ASM) += x86/checkasm.o
CHECKASMOBJS += $(CHECKASMOBJS-yes) checkasm.o
CHECKASMOBJS := $(sort $(CHECKASMOBJS:%=tests/checkasm/%))
-include $(CHECKASMOBJS:.o=.d)
CHECKASMDIRS := $(sort $(dir $(CHECKASMOBJS)))
$(CHECKASMOBJS): | $(CHECKASMDIRS)
OUTDIRS += $(CHECKASMDIRS)
tests/checkasm/checkasm.o: CFLAGS += -Umain
CHECKASM := tests/checkasm/checkasm$(EXESUF)
$(CHECKASM): $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS)
$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS-avcodec) $(EXTRALIBS-avfilter) $(EXTRALIBS-avformat) $(EXTRALIBS-avutil) $(EXTRALIBS-swresample) $(EXTRALIBS)
run-checkasm: $(CHECKASM)
run-checkasm:
$(Q)$(TARGET_EXEC) $(TARGET_PATH)/$(CHECKASM)
checkasm: $(CHECKASM)
testclean:: checkasmclean
checkasmclean:
$(RM) $(CHECKASM) $(CLEANSUFFIXES:%=tests/checkasm/%) $(CLEANSUFFIXES:%=tests/checkasm/$(ARCH)/%)
.PHONY: checkasm
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/mem_internal.h"
#include "libavcodec/aacenc_utils.h"
#include "libavcodec/aacencdsp.h"
#include "libavcodec/aactab.h"
#include "checkasm.h"
#define randomize_float(buf, len) \
do { \
int i; \
for (i = 0; i < len; i++) { \
float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
buf[i] = f; \
} \
} while (0)
#define randomize_elem(tab) (tab[rnd() % FF_ARRAY_ELEMS(tab)])
static void test_abs_pow34(AACEncDSPContext *s)
{
#define BUF_SIZE 1024
LOCAL_ALIGNED_32(float, in, [BUF_SIZE]);
declare_func(void, float *, const float *, int);
randomize_float(in, BUF_SIZE);
if (check_func(s->abs_pow34, "abs_pow34")) {
LOCAL_ALIGNED_32(float, out, [BUF_SIZE]);
LOCAL_ALIGNED_32(float, out2, [BUF_SIZE]);
call_ref(out, in, BUF_SIZE);
call_new(out2, in, BUF_SIZE);
if (!float_near_ulp_array(out, out2, 1, BUF_SIZE))
fail();
bench_new(out, in, BUF_SIZE);
}
report("abs_pow34");
}
static void test_quant_bands(AACEncDSPContext *s)
{
int maxval = randomize_elem(aac_cb_maxval);
float q34 = (float)rnd() / (UINT_MAX / 1024);
float rounding = (rnd() & 1) ? ROUND_TO_ZERO : ROUND_STANDARD;
LOCAL_ALIGNED_16(float, in, [BUF_SIZE]);
LOCAL_ALIGNED_16(float, scaled, [BUF_SIZE]);
declare_func(void, int *, const float *, const float *, int, int, int,
const float, const float);
randomize_float(in, BUF_SIZE);
randomize_float(scaled, BUF_SIZE);
for (int sign = 0; sign <= 1; sign++) {
if (check_func(s->quant_bands, "quant_bands_%s",
sign ? "signed" : "unsigned")) {
LOCAL_ALIGNED_32(int, out, [BUF_SIZE]);
LOCAL_ALIGNED_32(int, out2, [BUF_SIZE]);
call_ref(out, in, scaled, BUF_SIZE, sign, maxval, q34, rounding);
call_new(out2, in, scaled, BUF_SIZE, sign, maxval, q34, rounding);
if (memcmp(out, out2, BUF_SIZE * sizeof (int)))
fail();
bench_new(out, in, scaled, BUF_SIZE, sign, maxval, q34, rounding);
}
}
report("quant_bands");
}
void checkasm_check_aacencdsp(void)
{
AACEncDSPContext s = { 0 };
ff_aacenc_dsp_init(&s);
test_abs_pow34(&s);
test_quant_bands(&s);
}
+262
View File
@@ -0,0 +1,262 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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/aacpsdsp.h"
#include "libavutil/intfloat.h"
#include "libavutil/mem_internal.h"
#include "checkasm.h"
#define N 32
#define STRIDE 128
#define BUF_SIZE (N * STRIDE)
#define randomize(buf, len) do { \
int i; \
for (i = 0; i < len; i++) { \
const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \
(buf)[i] = f; \
} \
} while (0)
#define EPS 0.005
static void clear_less_significant_bits(INTFLOAT *buf, int len, int bits)
{
int i;
for (i = 0; i < len; i++) {
union av_intfloat32 u = { .f = buf[i] };
u.i &= (0xffffffff << bits);
buf[i] = u.f;
}
}
static void test_add_squares(void)
{
LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_16(INTFLOAT, src, [BUF_SIZE], [2]);
declare_func(void, INTFLOAT *dst,
const INTFLOAT (*src)[2], int n);
randomize((INTFLOAT *)src, BUF_SIZE * 2);
randomize(dst0, BUF_SIZE);
memcpy(dst1, dst0, BUF_SIZE * sizeof(INTFLOAT));
call_ref(dst0, src, BUF_SIZE);
call_new(dst1, src, BUF_SIZE);
if (!float_near_abs_eps_array(dst0, dst1, EPS, BUF_SIZE))
fail();
bench_new(dst1, src, BUF_SIZE);
}
static void test_mul_pair_single(void)
{
LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, src0, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, src1, [BUF_SIZE]);
declare_func(void, INTFLOAT (*dst)[2],
INTFLOAT (*src0)[2], INTFLOAT *src1, int n);
randomize((INTFLOAT *)src0, BUF_SIZE * 2);
randomize(src1, BUF_SIZE);
call_ref(dst0, src0, src1, BUF_SIZE);
call_new(dst1, src0, src1, BUF_SIZE);
if (!float_near_abs_eps_array((float *)dst0, (float *)dst1, EPS, BUF_SIZE * 2))
fail();
bench_new(dst1, src0, src1, BUF_SIZE);
}
static void test_hybrid_analysis(void)
{
LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, in, [13], [2]);
LOCAL_ALIGNED_16(INTFLOAT, filter, [N], [8][2]);
declare_func(void, INTFLOAT (*out)[2], INTFLOAT (*in)[2],
const INTFLOAT (*filter)[8][2],
ptrdiff_t stride, int n);
randomize((INTFLOAT *)in, 13 * 2);
randomize((INTFLOAT *)filter, N * 8 * 2);
randomize((INTFLOAT *)dst0, BUF_SIZE * 2);
memcpy(dst1, dst0, BUF_SIZE * 2 * sizeof(INTFLOAT));
call_ref(dst0, in, filter, STRIDE, N);
call_new(dst1, in, filter, STRIDE, N);
if (!float_near_abs_eps_array((float *)dst0, (float *)dst1, EPS, BUF_SIZE * 2))
fail();
bench_new(dst1, in, filter, STRIDE, N);
}
static void test_hybrid_analysis_ileave(void)
{
LOCAL_ALIGNED_16(INTFLOAT, in, [2], [38][64]);
LOCAL_ALIGNED_16(INTFLOAT, out0, [91], [32][2]);
LOCAL_ALIGNED_16(INTFLOAT, out1, [91], [32][2]);
declare_func(void, INTFLOAT (*out)[32][2], INTFLOAT L[2][38][64],
int i, int len);
randomize((INTFLOAT *)out0, 91 * 32 * 2);
randomize((INTFLOAT *)in, 2 * 38 * 64);
memcpy(out1, out0, 91 * 32 * 2 * sizeof(INTFLOAT));
/* len is hardcoded to 32 as that's the only value used in
libavcodec. asm functions are likely to be optimized
hardcoding this value in their loops and could fail with
anything else.
i is hardcoded to the two values currently used by the
aac decoder because the arm neon implementation is
micro-optimized for them and will fail for almost every
other value. */
call_ref(out0, in, 3, 32);
call_new(out1, in, 3, 32);
/* the function just moves data around, so memcmp is enough */
if (memcmp(out0, out1, 91 * 32 * 2 * sizeof(INTFLOAT)))
fail();
call_ref(out0, in, 5, 32);
call_new(out1, in, 5, 32);
if (memcmp(out0, out1, 91 * 32 * 2 * sizeof(INTFLOAT)))
fail();
bench_new(out1, in, 3, 32);
}
static void test_hybrid_synthesis_deint(void)
{
LOCAL_ALIGNED_16(INTFLOAT, out0, [2], [38][64]);
LOCAL_ALIGNED_16(INTFLOAT, out1, [2], [38][64]);
LOCAL_ALIGNED_16(INTFLOAT, in, [91], [32][2]);
declare_func(void, INTFLOAT out[2][38][64], INTFLOAT (*in)[32][2],
int i, int len);
randomize((INTFLOAT *)in, 91 * 32 * 2);
randomize((INTFLOAT *)out0, 2 * 38 * 64);
memcpy(out1, out0, 2 * 38 * 64 * sizeof(INTFLOAT));
/* len is hardcoded to 32 as that's the only value used in
libavcodec. asm functions are likely to be optimized
hardcoding this value in their loops and could fail with
anything else.
i is hardcoded to the two values currently used by the
aac decoder because the arm neon implementation is
micro-optimized for them and will fail for almost every
other value. */
call_ref(out0, in, 3, 32);
call_new(out1, in, 3, 32);
/* the function just moves data around, so memcmp is enough */
if (memcmp(out0, out1, 2 * 38 * 64 * sizeof(INTFLOAT)))
fail();
call_ref(out0, in, 5, 32);
call_new(out1, in, 5, 32);
if (memcmp(out0, out1, 2 * 38 * 64 * sizeof(INTFLOAT)))
fail();
bench_new(out1, in, 3, 32);
}
static void test_stereo_interpolate(PSDSPContext *psdsp)
{
int i;
LOCAL_ALIGNED_16(INTFLOAT, l, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, r, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, l0, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, r0, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, l1, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, r1, [BUF_SIZE], [2]);
LOCAL_ALIGNED_16(INTFLOAT, h, [2], [4]);
LOCAL_ALIGNED_16(INTFLOAT, h_step, [2], [4]);
declare_func(void, INTFLOAT (*l)[2], INTFLOAT (*r)[2],
INTFLOAT h[2][4], INTFLOAT h_step[2][4], int len);
randomize((INTFLOAT *)l, BUF_SIZE * 2);
randomize((INTFLOAT *)r, BUF_SIZE * 2);
for (i = 0; i < 2; i++) {
if (check_func(psdsp->stereo_interpolate[i], "ps_stereo_interpolate%s", i ? "_ipdopd" : "")) {
memcpy(l0, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
memcpy(l1, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
memcpy(r0, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
memcpy(r1, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
randomize((INTFLOAT *)h, 2 * 4);
randomize((INTFLOAT *)h_step, 2 * 4);
// Clear the least significant 14 bits of h_step, to avoid
// divergence when accumulating h_step BUF_SIZE times into
// a float variable which may or may not have extra intermediate
// precision. Therefore clear roughly log2(BUF_SIZE) less
// significant bits, to get the same result regardless of any
// extra precision in the accumulator.
clear_less_significant_bits((INTFLOAT *)h_step, 2 * 4, 14);
call_ref(l0, r0, h, h_step, BUF_SIZE);
call_new(l1, r1, h, h_step, BUF_SIZE);
if (!float_near_abs_eps_array((float *)l0, (float *)l1, EPS, BUF_SIZE * 2) ||
!float_near_abs_eps_array((float *)r0, (float *)r1, EPS, BUF_SIZE * 2))
fail();
memcpy(l1, l, BUF_SIZE * 2 * sizeof(INTFLOAT));
memcpy(r1, r, BUF_SIZE * 2 * sizeof(INTFLOAT));
bench_new(l1, r1, h, h_step, BUF_SIZE);
}
}
}
void checkasm_check_aacpsdsp(void)
{
PSDSPContext psdsp;
ff_psdsp_init(&psdsp);
if (check_func(psdsp.add_squares, "ps_add_squares"))
test_add_squares();
report("add_squares");
if (check_func(psdsp.mul_pair_single, "ps_mul_pair_single"))
test_mul_pair_single();
report("mul_pair_single");
if (check_func(psdsp.hybrid_analysis, "ps_hybrid_analysis"))
test_hybrid_analysis();
report("hybrid_analysis");
if (check_func(psdsp.hybrid_analysis_ileave, "ps_hybrid_analysis_ileave"))
test_hybrid_analysis_ileave();
report("hybrid_analysis_ileave");
if (check_func(psdsp.hybrid_synthesis_deint, "ps_hybrid_synthesis_deint"))
test_hybrid_synthesis_deint();
report("hybrid_synthesis_deint");
test_stereo_interpolate(&psdsp);
report("stereo_interpolate");
}
+198
View File
@@ -0,0 +1,198 @@
/****************************************************************************
* Assembly testing and benchmarking tool
* Copyright (c) 2015 Martin Storsjo
* Copyright (c) 2015 Janne Grunau
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/
#include "libavutil/aarch64/asm.S"
const register_init, align=4
.quad 0x21f86d66c8ca00ce
.quad 0x75b6ba21077c48ad
.quad 0xed56bb2dcb3c7736
.quad 0x8bda43d3fd1a7e06
.quad 0xb64a9c9e5d318408
.quad 0xdf9a54b303f1d3a3
.quad 0x4a75479abd64e097
.quad 0x249214109d5d1c88
.quad 0x1a1b2550a612b48c
.quad 0x79445c159ce79064
.quad 0x2eed899d5a28ddcd
.quad 0x86b2536fcd8cf636
.quad 0xb0856806085e7943
.quad 0x3f2bf84fc0fcca4e
.quad 0xacbd382dcf5b8de2
.quad 0xd229e1f5b281303f
.quad 0x71aeaff20b095fd9
.quad 0xab63e2e11fa38ed9
endconst
const error_message_register
.asciz "failed to preserve register"
error_message_stack:
.asciz "stack clobbered"
endconst
// max number of args used by any asm function.
#define MAX_ARGS 15
#define CLOBBER_STACK ((8*MAX_ARGS + 15) & ~15)
function checkasm_stack_clobber, export=1
mov x3, sp
mov x2, #CLOBBER_STACK
1:
stp x0, x1, [sp, #-16]!
subs x2, x2, #16
b.gt 1b
mov sp, x3
ret
endfunc
// + 16 for stack canary reference
#define ARG_STACK ((8*(MAX_ARGS - 8) + 15) & ~15 + 16)
function checkasm_checked_call, export=1
stp x29, x30, [sp, #-16]!
mov x29, sp
stp x19, x20, [sp, #-16]!
stp x21, x22, [sp, #-16]!
stp x23, x24, [sp, #-16]!
stp x25, x26, [sp, #-16]!
stp x27, x28, [sp, #-16]!
stp d8, d9, [sp, #-16]!
stp d10, d11, [sp, #-16]!
stp d12, d13, [sp, #-16]!
stp d14, d15, [sp, #-16]!
movrel x9, register_init
ldp d8, d9, [x9], #16
ldp d10, d11, [x9], #16
ldp d12, d13, [x9], #16
ldp d14, d15, [x9], #16
ldp x19, x20, [x9], #16
ldp x21, x22, [x9], #16
ldp x23, x24, [x9], #16
ldp x25, x26, [x9], #16
ldp x27, x28, [x9], #16
sub sp, sp, #ARG_STACK
.equ pos, 0
.rept MAX_ARGS-8
// Skip the first 8 args, that are loaded into registers
ldr x9, [x29, #16 + 8*8 + pos]
str x9, [sp, #pos]
.equ pos, pos + 8
.endr
// Fill x8-x17 with garbage. This doesn't have to be preserved,
// but avoids relying on them having any particular value.
movrel x9, register_init
ldp x10, x11, [x9], #32
ldp x12, x13, [x9], #32
ldp x14, x15, [x9], #32
ldp x16, x17, [x9], #32
ldp x8, x9, [x9]
// For stack overflows, the callee is free to overwrite the parameters
// that were passed on the stack (if any), so we can only check after
// that point. First figure out how many parameters the function
// really took on the stack:
ldr w2, [x29, #16 + 8*8 + (MAX_ARGS-8)*8]
// Load the first non-parameter value from the stack, that should be
// left untouched by the function. Store a copy of it inverted, so that
// e.g. overwriting everything with zero would be noticed.
ldr x2, [sp, x2, lsl #3]
mvn x2, x2
str x2, [sp, #ARG_STACK-8]
// Load the in-register arguments
mov x12, x0
ldp x0, x1, [x29, #16]
ldp x2, x3, [x29, #32]
ldp x4, x5, [x29, #48]
ldp x6, x7, [x29, #64]
// Call the target function
blr x12
// Load the number of stack parameters, stack canary and its reference
ldr w2, [x29, #16 + 8*8 + (MAX_ARGS-8)*8]
ldr x2, [sp, x2, lsl #3]
ldr x3, [sp, #ARG_STACK-8]
add sp, sp, #ARG_STACK
stp x0, x1, [sp, #-16]!
mvn x3, x3
cmp x2, x3
b.ne 2f
movrel x9, register_init
movi v3.8h, #0
.macro check_reg_neon reg1, reg2
ldr q1, [x9], #16
uzp1 v2.2d, v\reg1\().2d, v\reg2\().2d
eor v1.16b, v1.16b, v2.16b
orr v3.16b, v3.16b, v1.16b
.endm
check_reg_neon 8, 9
check_reg_neon 10, 11
check_reg_neon 12, 13
check_reg_neon 14, 15
uqxtn v3.8b, v3.8h
umov x3, v3.d[0]
.macro check_reg reg1, reg2
ldp x0, x1, [x9], #16
eor x0, x0, \reg1
eor x1, x1, \reg2
orr x3, x3, x0
orr x3, x3, x1
.endm
check_reg x19, x20
check_reg x21, x22
check_reg x23, x24
check_reg x25, x26
check_reg x27, x28
cbz x3, 0f
movrel x0, error_message_register
b 1f
2:
movrel x0, error_message_stack
1:
bl X(checkasm_fail_func)
0:
ldp x0, x1, [sp], #16
ldp d14, d15, [sp], #16
ldp d12, d13, [sp], #16
ldp d10, d11, [sp], #16
ldp d8, d9, [sp], #16
ldp x27, x28, [sp], #16
ldp x25, x26, [sp], #16
ldp x23, x24, [sp], #16
ldp x21, x22, [sp], #16
ldp x19, x20, [sp], #16
ldp x29, x30, [sp], #16
ret
endfunc
+203
View File
@@ -0,0 +1,203 @@
/*
* Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
* Copyright (c) 2024 Geoff Hill <geoff@geoffhill.org>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <stdint.h>
#include <string.h>
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/ac3dsp.h"
#include "checkasm.h"
#define randomize_exp(buf, len) \
do { \
int i; \
for (i = 0; i < len; i++) { \
buf[i] = (uint8_t)rnd(); \
} \
} while (0)
#define randomize_i24(buf, len) \
do { \
int i; \
for (i = 0; i < len; i++) { \
int32_t v = (int32_t)rnd(); \
int32_t u = (v & 0xFFFFFF); \
buf[i] = (v < 0) ? -u : u; \
} \
} while (0)
#define randomize_float(buf, len) \
do { \
int i; \
for (i = 0; i < len; i++) { \
float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
buf[i] = f; \
} \
} while (0)
static void check_ac3_exponent_min(AC3DSPContext *c) {
#define MAX_COEFS 256
#define MAX_CTXT 6
#define EXP_SIZE (MAX_CTXT * MAX_COEFS)
LOCAL_ALIGNED_16(uint8_t, src, [EXP_SIZE]);
LOCAL_ALIGNED_16(uint8_t, v1, [EXP_SIZE]);
LOCAL_ALIGNED_16(uint8_t, v2, [EXP_SIZE]);
int n;
declare_func(void, uint8_t *, int, int);
for (n = 0; n < MAX_CTXT; ++n) {
if (check_func(c->ac3_exponent_min, "ac3_exponent_min_reuse%d", n)) {
randomize_exp(src, EXP_SIZE);
memcpy(v1, src, EXP_SIZE);
memcpy(v2, src, EXP_SIZE);
call_ref(v1, n, MAX_COEFS);
call_new(v2, n, MAX_COEFS);
if (memcmp(v1, v2, EXP_SIZE) != 0)
fail();
bench_new(v2, n, MAX_COEFS);
}
}
report("ac3_exponent_min");
}
static void check_ac3_extract_exponents(AC3DSPContext *c) {
#define MAX_EXPS 3072
LOCAL_ALIGNED_16(int32_t, src, [MAX_EXPS]);
LOCAL_ALIGNED_16(uint8_t, v1, [MAX_EXPS]);
LOCAL_ALIGNED_16(uint8_t, v2, [MAX_EXPS]);
int n;
declare_func(void, uint8_t *, int32_t *, int);
for (n = 512; n <= MAX_EXPS; n += 256) {
if (check_func(c->extract_exponents, "ac3_extract_exponents_n%d", n)) {
randomize_i24(src, n);
call_ref(v1, src, n);
call_new(v2, src, n);
if (memcmp(v1, v2, n) != 0)
fail();
bench_new(v1, src, n);
}
}
report("ac3_extract_exponents");
}
static void check_float_to_fixed24(AC3DSPContext *c) {
#define BUF_SIZE 1024
LOCAL_ALIGNED_32(float, src, [BUF_SIZE]);
declare_func(void, int32_t *, const float *, size_t);
randomize_float(src, BUF_SIZE);
if (check_func(c->float_to_fixed24, "float_to_fixed24")) {
LOCAL_ALIGNED_32(int32_t, dst, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, dst2, [BUF_SIZE]);
call_ref(dst, src, BUF_SIZE);
call_new(dst2, src, BUF_SIZE);
if (memcmp(dst, dst2, BUF_SIZE) != 0)
fail();
bench_new(dst, src, BUF_SIZE);
}
report("float_to_fixed24");
}
static void check_ac3_sum_square_butterfly_int32(AC3DSPContext *c) {
#define ELEMS 240
LOCAL_ALIGNED_16(int32_t, lt, [ELEMS]);
LOCAL_ALIGNED_16(int32_t, rt, [ELEMS]);
LOCAL_ALIGNED_16(uint64_t, v1, [4]);
LOCAL_ALIGNED_16(uint64_t, v2, [4]);
declare_func(void, int64_t[4], const int32_t *, const int32_t *, int);
randomize_i24(lt, ELEMS);
randomize_i24(rt, ELEMS);
if (check_func(c->sum_square_butterfly_int32,
"ac3_sum_square_bufferfly_int32")) {
call_ref(v1, lt, rt, ELEMS);
call_new(v2, lt, rt, ELEMS);
if (memcmp(v1, v2, sizeof(int64_t[4])) != 0)
fail();
bench_new(v2, lt, rt, ELEMS);
}
report("ac3_sum_square_butterfly_int32");
}
static void check_ac3_sum_square_butterfly_float(AC3DSPContext *c) {
LOCAL_ALIGNED_32(float, lt, [ELEMS]);
LOCAL_ALIGNED_32(float, rt, [ELEMS]);
LOCAL_ALIGNED_16(float, v1, [4]);
LOCAL_ALIGNED_16(float, v2, [4]);
declare_func(void, float[4], const float *, const float *, int);
randomize_float(lt, ELEMS);
randomize_float(rt, ELEMS);
if (check_func(c->sum_square_butterfly_float,
"ac3_sum_square_bufferfly_float")) {
call_ref(v1, lt, rt, ELEMS);
call_new(v2, lt, rt, ELEMS);
if (!float_near_ulp_array(v1, v2, 11, 4))
fail();
bench_new(v2, lt, rt, ELEMS);
}
report("ac3_sum_square_butterfly_float");
}
void checkasm_check_ac3dsp(void)
{
AC3DSPContext c;
ff_ac3dsp_init(&c);
check_ac3_exponent_min(&c);
check_ac3_extract_exponents(&c);
check_float_to_fixed24(&c);
check_ac3_sum_square_butterfly_int32(&c);
check_ac3_sum_square_butterfly_float(&c);
}
+151
View File
@@ -0,0 +1,151 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "config.h"
#include <float.h>
#include <stdint.h>
#include "libavfilter/af_afirdsp.h"
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
#include "checkasm.h"
#define LEN 256
#define randomize_buffer(buf) \
do { \
int i; \
double bmg[2], stddev = 10.0, mean = 0.0; \
\
for (i = 0; i < BUF_SIZE; i += 2) { \
av_bmg_get(&checkasm_lfg, bmg); \
buf[i] = bmg[0] * stddev + mean; \
buf[i + 1] = bmg[1] * stddev + mean; \
} \
} while(0);
static void test_fcmul_add(AudioFIRDSPContext *fir)
{
#define BUF_SIZE LEN*2+8
LOCAL_ALIGNED_32(float, src0, [BUF_SIZE]);
LOCAL_ALIGNED_32(float, src1, [BUF_SIZE]);
LOCAL_ALIGNED_32(float, src2, [BUF_SIZE]);
randomize_buffer(src0);
randomize_buffer(src1);
randomize_buffer(src2);
if (check_func(fir->fcmul_add, "fcmul_add")) {
LOCAL_ALIGNED_32(float, cdst, [BUF_SIZE]);
LOCAL_ALIGNED_32(float, odst, [BUF_SIZE]);
int i;
declare_func(void, float *sum, const float *t, const float *c,
ptrdiff_t len);
memcpy(cdst, src0, (BUF_SIZE) * sizeof(float));
memcpy(odst, src0, (BUF_SIZE) * sizeof(float));
call_ref(cdst, src1, src2, LEN);
call_new(odst, src1, src2, LEN);
for (i = 0; i <= LEN*2; i++) {
int idx = i & ~1;
float cre = src2[idx];
float cim = src2[idx + 1];
float tre = src1[idx];
float tim = src1[idx + 1];
double t = fabs(src0[i]) +
fabs(tre) + fabs(tim) + fabs(cre) + fabs(cim) +
fabs(tre * cre) + fabs(tim * cim) +
fabs(tre * cim) + fabs(tim * cre) +
fabs(tre * cre - tim * cim) +
fabs(tre * cim + tim * cre) +
fabs(cdst[i]) + 1.0;
if (!float_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
memcpy(odst, src0, (BUF_SIZE) * sizeof(float));
bench_new(odst, src1, src2, LEN);
}
report("fcmul_add");
}
static void test_dcmul_add(AudioFIRDSPContext *fir)
{
#define BUF_SIZE LEN*2+8
LOCAL_ALIGNED_32(double, src0, [BUF_SIZE]);
LOCAL_ALIGNED_32(double, src1, [BUF_SIZE]);
LOCAL_ALIGNED_32(double, src2, [BUF_SIZE]);
randomize_buffer(src0);
randomize_buffer(src1);
randomize_buffer(src2);
if (check_func(fir->dcmul_add, "dcmul_add")) {
LOCAL_ALIGNED_32(double, cdst, [BUF_SIZE]);
LOCAL_ALIGNED_32(double, odst, [BUF_SIZE]);
int i;
declare_func(void, double *sum, const double *t, const double *c,
ptrdiff_t len);
memcpy(cdst, src0, (BUF_SIZE) * sizeof(double));
memcpy(odst, src0, (BUF_SIZE) * sizeof(double));
call_ref(cdst, src1, src2, LEN);
call_new(odst, src1, src2, LEN);
for (i = 0; i <= LEN*2; i++) {
int idx = i & ~1;
double cre = src2[idx];
double cim = src2[idx + 1];
double tre = src1[idx];
double tim = src1[idx + 1];
double t = fabs(src0[i]) +
fabs(tre) + fabs(tim) + fabs(cre) + fabs(cim) +
fabs(tre * cre) + fabs(tim * cim) +
fabs(tre * cim) + fabs(tim * cre) +
fabs(tre * cre - tim * cim) +
fabs(tre * cim + tim * cre) +
fabs(cdst[i]) + 1.0;
if (!double_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
memcpy(odst, src0, (BUF_SIZE) * sizeof(double));
bench_new(odst, src1, src2, LEN);
}
report("dcmul_add");
}
void checkasm_check_afir(void)
{
AudioFIRDSPContext fir = { 0 };
ff_afir_init(&fir);
test_fcmul_add(&fir);
test_dcmul_add(&fir);
}
+120
View File
@@ -0,0 +1,120 @@
/*
* Copyright (c) 2015 James Almer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/alacdsp.h"
#include "libavcodec/mathops.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
#define BUF_SIZE 256
#define MAX_CHANNELS 2
#define randomize_buffers() \
do { \
int i; \
for (i = 0; i < BUF_SIZE*MAX_CHANNELS; i++) { \
int32_t r = sign_extend(rnd(), 24); \
ref_buf[i] = r; \
new_buf[i] = r; \
} \
} while (0)
static void check_decorrelate_stereo(void)
{
LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]);
LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS]);
int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] };
int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] };
ALACDSPContext c;
ff_alacdsp_init(&c);
if (check_func(c.decorrelate_stereo, "alac_decorrelate_stereo")) {
int len = (rnd() & 0xFF) + 1;
int shift = rnd() & 0x1F;
int weight = rnd() & 0xFF;
declare_func(void, int32_t *buf[2], int len, int shift, int weight);
randomize_buffers();
call_ref(ref, len, shift, weight);
call_new(new, len, shift, weight);
if (memcmp(ref[0], new[0], len * sizeof(int32_t)) ||
memcmp(ref[1], new[1], len * sizeof(int32_t)))
fail();
bench_new(new, BUF_SIZE, shift, weight);
}
report("decorrelate_stereo");
}
#undef randomize_buffers
#define randomize_buffers() \
do { \
int i, j; \
for (i = 0; i < BUF_SIZE; i++) { \
for (j = 0; j < ch; j++) { \
int32_t r = sign_extend(rnd(), 24); \
ref[j][i] = r; \
new[j][i] = r; \
r = rnd() & 0xFF; \
ref_ebb[j][i] = r; \
new_ebb[j][i] = r; \
} \
} \
} while (0)
static void check_append_extra_bits(void)
{
LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS*2]);
LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS*2]);
int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] };
int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] };
int32_t *ref_ebb[2] = { &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3] };
int32_t *new_ebb[2] = { &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3] };
ALACDSPContext c;
static const char * const channels[2] = { "mono", "stereo" };
int ch;
ff_alacdsp_init(&c);
for (ch = 1; ch <= 2; ch++) {
if (check_func(c.append_extra_bits[ch-1], "alac_append_extra_bits_%s", channels[ch-1])) {
int len = (rnd() & 0xFF) + 1;
declare_func(void, int32_t *buf[2], int32_t *ebb[2], int ebits, int ch, int len);
randomize_buffers();
call_ref(ref, ref_ebb, 8, ch, len);
call_new(new, new_ebb, 8, ch, len);
if ( memcmp(ref[0], new[0], len * sizeof(int32_t)) ||
(ch == 2 && memcmp(ref[1], new[1], len * sizeof(int32_t))))
fail();
bench_new(new, new_ebb, 8, ch, BUF_SIZE);
}
}
report("append_extra_bits");
}
void checkasm_check_alacdsp(void)
{
check_decorrelate_stereo();
check_append_extra_bits();
}
+197
View File
@@ -0,0 +1,197 @@
/****************************************************************************
* Assembly testing and benchmarking tool
* Copyright (c) 2015 Martin Storsjo
* Copyright (c) 2015 Janne Grunau
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/
#include "libavutil/arm/asm.S"
/* override fpu so that NEON instructions are rejected */
#if HAVE_VFP
FPU .fpu vfp
ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
#endif
const register_init, align=3
.quad 0x21f86d66c8ca00ce
.quad 0x75b6ba21077c48ad
.quad 0xed56bb2dcb3c7736
.quad 0x8bda43d3fd1a7e06
.quad 0xb64a9c9e5d318408
.quad 0xdf9a54b303f1d3a3
.quad 0x4a75479abd64e097
.quad 0x249214109d5d1c88
endconst
const error_message_fpscr
.asciz "failed to preserve register FPSCR, changed bits: %x"
error_message_gpr:
.asciz "failed to preserve register r%d"
error_message_vfp:
.asciz "failed to preserve register d%d"
error_message_stack:
.asciz "failed to preserve stack"
endconst
@ max number of args used by any asm function.
#define MAX_ARGS 15
#define ARG_STACK 4*(MAX_ARGS - 4)
@ Align the used stack space to 8 to preserve the stack alignment.
@ +8 for stack canary reference.
#define ARG_STACK_A (((ARG_STACK + pushed + 7) & ~7) - pushed + 8)
.macro clobbercheck variant
.equ pushed, 4*9
function checkasm_checked_call_\variant, export=1
push {r4-r11, lr}
.ifc \variant, vfp
vpush {d8-d15}
fmrx r4, FPSCR
push {r4}
.equ pushed, pushed + 16*4 + 4
.endif
movrel r12, register_init
.ifc \variant, vfp
vldm r12, {d8-d15}
.endif
ldm r12, {r4-r11}
sub sp, sp, #ARG_STACK_A
.equ pos, 0
.rept MAX_ARGS-4
ldr r12, [sp, #ARG_STACK_A + pushed + 8 + pos]
str r12, [sp, #pos]
.equ pos, pos + 4
.endr
@ For stack overflows, the callee is free to overwrite the parameters
@ that were passed on the stack (if any), so we can only check after
@ that point. First figure out how many parameters the function
@ really took on the stack:
ldr r12, [sp, #ARG_STACK_A + pushed + 8 + 4*(MAX_ARGS-4)]
@ Load the first non-parameter value from the stack, that should be
@ left untouched by the function. Store a copy of it inverted, so that
@ e.g. overwriting everything with zero would be noticed.
ldr r12, [sp, r12, lsl #2]
mvn r12, r12
str r12, [sp, #ARG_STACK_A - 4]
mov r12, r0
mov r0, r2
mov r1, r3
ldrd r2, r3, [sp, #ARG_STACK_A + pushed]
@ Call the target function
blx r12
@ Load the number of stack parameters, stack canary and its reference
ldr r12, [sp, #ARG_STACK_A + pushed + 8 + 4*(MAX_ARGS-4)]
ldr r2, [sp, r12, lsl #2]
ldr r3, [sp, #ARG_STACK_A - 4]
add sp, sp, #ARG_STACK_A
push {r0, r1}
mvn r3, r3
cmp r2, r3
bne 5f
movrel r12, register_init
.ifc \variant, vfp
.macro check_reg_vfp, dreg, offset
ldrd r2, r3, [r12, #8 * (\offset)]
vmov r0, lr, \dreg
eor r2, r2, r0
eor r3, r3, lr
orrs r2, r2, r3
bne 4f
.endm
.irp n, 8, 9, 10, 11, 12, 13, 14, 15
@ keep track of the checked double/SIMD register
mov r1, #\n
check_reg_vfp d\n, \n-8
.endr
.purgem check_reg_vfp
fmrx r1, FPSCR
ldr r3, [sp, #8]
eor r1, r1, r3
@ Ignore changes in bits 0-4 and 7
bic r1, r1, #0x9f
@ Ignore changes in the topmost 5 bits
bics r1, r1, #0xf8000000
bne 3f
.endif
@ keep track of the checked GPR
mov r1, #4
.macro check_reg reg1, reg2=
ldrd r2, r3, [r12], #8
eors r2, r2, \reg1
bne 2f
add r1, r1, #1
.ifnb \reg2
eors r3, r3, \reg2
bne 2f
.endif
add r1, r1, #1
.endm
check_reg r4, r5
check_reg r6, r7
@ r9 is a volatile register in the ios ABI
#ifdef __APPLE__
check_reg r8
#else
check_reg r8, r9
#endif
check_reg r10, r11
.purgem check_reg
b 0f
5:
movrel r0, error_message_stack
b 1f
4:
movrel r0, error_message_vfp
b 1f
3:
movrel r0, error_message_fpscr
b 1f
2:
movrel r0, error_message_gpr
1:
bl X(checkasm_fail_func)
0:
pop {r0, r1}
.ifc \variant, vfp
pop {r2}
fmxr FPSCR, r2
vpop {d8-d15}
.endif
pop {r4-r11, pc}
endfunc
.endm
#if HAVE_VFP || HAVE_NEON
clobbercheck vfp
#endif
clobbercheck novfp
+147
View File
@@ -0,0 +1,147 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "libavcodec/audiodsp.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "checkasm.h"
#define MAX_SIZE (32 * 128)
#define randomize_float(buf, len) \
do { \
int i; \
for (i = 0; i < len; i++) { \
float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
buf[i] = f; \
} \
} while (0)
#define randomize_int(buf, len, size, bits) \
do { \
int i; \
for (i = 0; i < len; i++) { \
uint ## size ## _t r = rnd() & ((1LL << bits) - 1); \
AV_WN ## size ## A(buf + i, -(1LL << (bits - 1)) + r); \
} \
} while (0)
void checkasm_check_audiodsp(void)
{
AudioDSPContext adsp;
ff_audiodsp_init(&adsp);
if (check_func(adsp.scalarproduct_int16, "audiodsp.scalarproduct_int16")) {
LOCAL_ALIGNED(32, int16_t, v1, [MAX_SIZE]);
LOCAL_ALIGNED(32, int16_t, v2, [MAX_SIZE]);
unsigned int len_bits_minus4, v1_bits, v2_bits, len;
int32_t res0, res1;
declare_func(int32_t, const int16_t *v1, const int16_t *v2, int len);
// generate random 5-12bit vector length
len_bits_minus4 = rnd() % 8;
len = rnd() & ((1 << len_bits_minus4) - 1);
len = 16 * FFMAX(len, 1);
// generate the bit counts for each of the vectors such that the result
// fits into int32
v1_bits = 1 + rnd() % 15;
v2_bits = FFMIN(32 - (len_bits_minus4 + 4) - v1_bits - 1, 15);
randomize_int(v1, MAX_SIZE, 16, v1_bits + 1);
randomize_int(v2, MAX_SIZE, 16, v2_bits + 1);
res0 = call_ref(v1, v2, len);
res1 = call_new(v1, v2, len);
if (res0 != res1)
fail();
bench_new(v1, v2, MAX_SIZE);
}
if (check_func(adsp.vector_clip_int32, "audiodsp.vector_clip_int32")) {
LOCAL_ALIGNED(32, int32_t, src, [MAX_SIZE]);
LOCAL_ALIGNED(32, int32_t, dst0, [MAX_SIZE]);
LOCAL_ALIGNED(32, int32_t, dst1, [MAX_SIZE]);
int32_t val1, val2, min, max;
int len;
declare_func(void, int32_t *dst, const int32_t *src,
int32_t min, int32_t max, unsigned int len);
val1 = ((int32_t)rnd());
val1 = FFSIGN(val1) * (val1 & ((1 << 24) - 1));
val2 = ((int32_t)rnd());
val2 = FFSIGN(val2) * (val2 & ((1 << 24) - 1));
min = FFMIN(val1, val2);
max = FFMAX(val1, val2);
randomize_int(src, MAX_SIZE, 32, 32);
len = rnd() % 128;
len = 32 * FFMAX(len, 1);
call_ref(dst0, src, min, max, len);
call_new(dst1, src, min, max, len);
if (memcmp(dst0, dst1, len * sizeof(*dst0)))
fail();
bench_new(dst1, src, min, max, MAX_SIZE);
}
if (check_func(adsp.vector_clipf, "audiodsp.vector_clipf")) {
LOCAL_ALIGNED(32, float, src, [MAX_SIZE]);
LOCAL_ALIGNED(32, float, dst0, [MAX_SIZE]);
LOCAL_ALIGNED(32, float, dst1, [MAX_SIZE]);
float val1, val2, min, max;
int i, len;
declare_func(void, float *dst, const float *src,
int len, float min, float max);
val1 = (float)rnd() / (UINT_MAX >> 1) - 1.0f;
val2 = (float)rnd() / (UINT_MAX >> 1) - 1.0f;
min = FFMIN(val1, val2);
max = FFMAX(val1, val2);
randomize_float(src, MAX_SIZE);
len = rnd() % 128;
len = 16 * FFMAX(len, 1);
call_ref(dst0, src, len, min, max);
call_new(dst1, src, len, min, max);
for (i = 0; i < len; i++) {
if (!float_near_ulp_array(dst0, dst1, 3, len))
fail();
}
bench_new(dst1, src, MAX_SIZE, min, max);
}
report("audiodsp");
}
+129
View File
@@ -0,0 +1,129 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavutil/tx.h"
#include "libavutil/error.h"
#include "checkasm.h"
#include <stdlib.h>
#define EPS 0.0005
#define SCALE_NOOP(x) (x)
#define SCALE_INT20(x) (av_clip64(lrintf((x) * 2147483648.0), INT32_MIN, INT32_MAX) >> 12)
#define randomize_complex(BUF, LEN, TYPE, SCALE) \
do { \
TYPE *buf = (TYPE *)BUF; \
for (int i = 0; i < LEN; i++) { \
double fre = (double)rnd() / UINT_MAX; \
double fim = (double)rnd() / UINT_MAX; \
buf[i] = (TYPE){ SCALE(fre), SCALE(fim) }; \
} \
} while (0)
static const int check_lens[] = {
2, 4, 8, 16, 32, 64, 120, 960, 1024, 1920, 16384,
};
static AVTXContext *tx_refs[AV_TX_NB][2 /* Direction */][FF_ARRAY_ELEMS(check_lens)] = { 0 };
static int init = 0;
static void free_tx_refs(void)
{
for (int i = 0; i < FF_ARRAY_ELEMS(tx_refs); i++)
for (int j = 0; j < FF_ARRAY_ELEMS(*tx_refs); j++)
for (int k = 0; k < FF_ARRAY_ELEMS(**tx_refs); k++)
av_tx_uninit(&tx_refs[i][j][k]);
}
#define CHECK_TEMPLATE(PREFIX, TYPE, DIR, DATA_TYPE, SCALE_TYPE, LENGTHS, CHECK_EXPRESSION) \
do { \
int err; \
AVTXContext *tx; \
av_tx_fn fn; \
int num_checks = 0; \
int last_check = 0; \
\
for (int i = 0; i < FF_ARRAY_ELEMS(LENGTHS); i++) { \
int len = LENGTHS[i]; \
const SCALE_TYPE scale = 1.0 / len; \
\
if ((err = av_tx_init(&tx, &fn, TYPE, DIR, len, &scale, 0x0)) < 0) { \
fprintf(stderr, "av_tx: %s\n", av_err2str(err)); \
return; \
} \
\
if (check_func(fn, PREFIX "_%i", len)) { \
AVTXContext *tx_ref = tx_refs[TYPE][DIR][i]; \
if (!tx_ref) \
tx_ref = tx; \
num_checks++; \
last_check = len; \
call_ref(tx_ref, out_ref, in, sizeof(DATA_TYPE)); \
call_new(tx, out_new, in, sizeof(DATA_TYPE)); \
if (CHECK_EXPRESSION) { \
fail(); \
av_tx_uninit(&tx); \
break; \
} \
bench_new(tx, out_new, in, sizeof(DATA_TYPE)); \
av_tx_uninit(&tx_refs[TYPE][DIR][i]); \
tx_refs[TYPE][DIR][i] = tx; \
} else { \
av_tx_uninit(&tx); \
} \
} \
\
if (num_checks == 1) \
report(PREFIX "_%i", last_check); \
else if (num_checks) \
report(PREFIX); \
} while (0)
void checkasm_check_av_tx(void)
{
declare_func(void, AVTXContext *tx, void *out, void *in, ptrdiff_t stride);
void *in = av_malloc(16384*2*8);
void *out_ref = av_malloc(16384*2*8);
void *out_new = av_malloc(16384*2*8);
randomize_complex(in, 16384, AVComplexFloat, SCALE_NOOP);
CHECK_TEMPLATE("float_fft", AV_TX_FLOAT_FFT, 0, AVComplexFloat, float, check_lens,
!float_near_abs_eps_array(out_ref, out_new, EPS, len*2));
CHECK_TEMPLATE("float_imdct", AV_TX_FLOAT_MDCT, 1, float, float, check_lens,
!float_near_abs_eps_array(out_ref, out_new, EPS, len));
randomize_complex(in, 16384, AVComplexDouble, SCALE_NOOP);
CHECK_TEMPLATE("double_fft", AV_TX_DOUBLE_FFT, 0, AVComplexDouble, double, check_lens,
!double_near_abs_eps_array(out_ref, out_new, EPS, len*2));
av_free(in);
av_free(out_ref);
av_free(out_new);
if (!init) {
init = 1;
atexit(free_tx_refs);
}
}
+93
View File
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2015 Henrik Gramner
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/blockdsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define randomize_buffers(size) \
do { \
int i; \
for (i = 0; i < size; i++) { \
uint16_t r = rnd(); \
AV_WN16A(buf0 + i, r); \
AV_WN16A(buf1 + i, r); \
} \
} while (0)
#define check_clear(func, size) \
do { \
if (check_func(h.func, "blockdsp." #func)) { \
declare_func(void, int16_t *block); \
randomize_buffers(size); \
call_ref(buf0); \
call_new(buf1); \
if (memcmp(buf0, buf1, sizeof(*buf0) * size)) \
fail(); \
bench_new(buf0); \
} \
} while (0)
static void check_fill(BlockDSPContext *h){
LOCAL_ALIGNED_16(uint8_t, buf0_16, [16 * 16]);
LOCAL_ALIGNED_16(uint8_t, buf1_16, [16 * 16]);
for (int t = 0; t < 2; ++t) {
uint8_t *buf0 = buf0_16 + t * /* force 8 byte alignment */ 8;
uint8_t *buf1 = buf1_16 + t * /* force 8 byte alignment */ 8;
int n = 16 - 8 * t;
declare_func(void, uint8_t *block, uint8_t value,
ptrdiff_t line_size, int h);
if (check_func(h->fill_block_tab[t], "blockdsp.fill_block_tab[%d]", t)) {
uint8_t value = rnd();
memset(buf0, 0, sizeof(*buf0) * n * n);
memset(buf1, 0, sizeof(*buf1) * n * n);
call_ref(buf0, value, n, n);
call_new(buf1, value, n, n);
if (memcmp(buf0, buf1, sizeof(*buf0) * n * n))
fail();
bench_new(buf0, value, n, n);
}
}
}
void checkasm_check_blockdsp(void)
{
LOCAL_ALIGNED_32(uint16_t, buf0, [6 * 8 * 8]);
LOCAL_ALIGNED_32(uint16_t, buf1, [6 * 8 * 8]);
BlockDSPContext h;
ff_blockdsp_init(&h);
check_clear(clear_block, 8 * 8);
check_clear(clear_blocks, 8 * 8 * 6);
check_fill(&h);
report("blockdsp");
}
+77
View File
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2015 Henrik Gramner
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/bswapdsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define BUF_SIZE 512
#define randomize_buffers() \
do { \
int i; \
for (i = 0; i < BUF_SIZE; i += 4) { \
uint32_t r = rnd(); \
AV_WN32A(src0 + i, r); \
AV_WN32A(src1 + i, r); \
r = rnd(); \
AV_WN32A(dst0 + i, r); \
AV_WN32A(dst1 + i, r); \
} \
} while (0)
#define check_bswap(type) \
do { \
int w; \
declare_func(void, type *dst, const type *src, int w); \
\
for (w = 0; w < BUF_SIZE / sizeof(type); w++) { \
int offset = (BUF_SIZE / sizeof(type) - w) & 15; /* Test various alignments */ \
randomize_buffers(); \
call_ref((type *)dst0 + offset, (type *)src0 + offset, w); \
call_new((type *)dst1 + offset, (type *)src1 + offset, w); \
if (memcmp(src0, src1, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE)) \
fail(); \
bench_new((type *)dst1 + offset, (type *)src1 + offset, w); \
} \
} while (0)
void checkasm_check_bswapdsp(void)
{
LOCAL_ALIGNED_16(uint8_t, src0, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, src1, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE]);
BswapDSPContext h;
ff_bswapdsp_init(&h);
if (check_func(h.bswap_buf, "bswap_buf"))
check_bswap(uint32_t);
if (check_func(h.bswap16_buf, "bswap16_buf"))
check_bswap(uint16_t);
report("bswap");
}
File diff suppressed because it is too large. Load diff
+390
View File
@@ -0,0 +1,390 @@
/*
* Assembly testing and benchmarking tool
* Copyright (c) 2015 Henrik Gramner
* Copyright (c) 2008 Loren Merritt
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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.
*/
#ifndef TESTS_CHECKASM_CHECKASM_H
#define TESTS_CHECKASM_CHECKASM_H
#include <stdint.h>
#include "config.h"
#if CONFIG_LINUX_PERF
#include <unistd.h> // read(3)
#include <sys/ioctl.h>
#include <asm/unistd.h>
#include <linux/perf_event.h>
#elif CONFIG_MACOS_KPERF
#include "libavutil/macos_kperf.h"
#endif
#include "libavutil/avstring.h"
#include "libavutil/cpu.h"
#include "libavutil/emms.h"
#include "libavutil/internal.h"
#include "libavutil/lfg.h"
#include "libavutil/timer.h"
#ifdef _WIN32
#include <windows.h>
#if ARCH_X86_32
#include <setjmp.h>
typedef jmp_buf checkasm_context;
#define checkasm_save_context() checkasm_handle_signal(setjmp(checkasm_context_buf))
#define checkasm_load_context(s) longjmp(checkasm_context_buf, s)
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
/* setjmp/longjmp on Windows on architectures using SEH (all except x86_32)
* will try to use SEH to unwind the stack, which doesn't work for assembly
* functions without unwind information. */
typedef struct { CONTEXT c; int status; } checkasm_context;
#define checkasm_save_context() \
(checkasm_context_buf.status = 0, \
RtlCaptureContext(&checkasm_context_buf.c), \
checkasm_handle_signal(checkasm_context_buf.status))
#define checkasm_load_context(s) \
(checkasm_context_buf.status = s, \
RtlRestoreContext(&checkasm_context_buf.c, NULL))
#else
#define checkasm_context void*
#define checkasm_save_context() 0
#define checkasm_load_context() do {} while (0)
#endif
#else
#include <setjmp.h>
typedef sigjmp_buf checkasm_context;
#define checkasm_save_context() checkasm_handle_signal(sigsetjmp(checkasm_context_buf, 1))
#define checkasm_load_context(s) siglongjmp(checkasm_context_buf, s)
#endif
void checkasm_check_aacencdsp(void);
void checkasm_check_aacpsdsp(void);
void checkasm_check_ac3dsp(void);
void checkasm_check_afir(void);
void checkasm_check_alacdsp(void);
void checkasm_check_audiodsp(void);
void checkasm_check_av_tx(void);
void checkasm_check_blend(void);
void checkasm_check_blockdsp(void);
void checkasm_check_bswapdsp(void);
void checkasm_check_colorspace(void);
void checkasm_check_exrdsp(void);
void checkasm_check_fdctdsp(void);
void checkasm_check_fixed_dsp(void);
void checkasm_check_flacdsp(void);
void checkasm_check_float_dsp(void);
void checkasm_check_fmtconvert(void);
void checkasm_check_g722dsp(void);
void checkasm_check_h263dsp(void);
void checkasm_check_h264chroma(void);
void checkasm_check_h264dsp(void);
void checkasm_check_h264pred(void);
void checkasm_check_h264qpel(void);
void checkasm_check_hevc_add_res(void);
void checkasm_check_hevc_deblock(void);
void checkasm_check_hevc_idct(void);
void checkasm_check_hevc_pel(void);
void checkasm_check_hevc_sao(void);
void checkasm_check_huffyuvdsp(void);
void checkasm_check_idctdsp(void);
void checkasm_check_jpeg2000dsp(void);
void checkasm_check_llauddsp(void);
void checkasm_check_lls(void);
void checkasm_check_llviddsp(void);
void checkasm_check_llviddspenc(void);
void checkasm_check_lpc(void);
void checkasm_check_motion(void);
void checkasm_check_mpegvideoencdsp(void);
void checkasm_check_nlmeans(void);
void checkasm_check_opusdsp(void);
void checkasm_check_pixblockdsp(void);
void checkasm_check_sbrdsp(void);
void checkasm_check_rv34dsp(void);
void checkasm_check_rv40dsp(void);
void checkasm_check_svq1enc(void);
void checkasm_check_synth_filter(void);
void checkasm_check_sw_gbrp(void);
void checkasm_check_sw_range_convert(void);
void checkasm_check_sw_rgb(void);
void checkasm_check_sw_scale(void);
void checkasm_check_sw_yuv2rgb(void);
void checkasm_check_sw_yuv2yuv(void);
void checkasm_check_takdsp(void);
void checkasm_check_utvideodsp(void);
void checkasm_check_v210dec(void);
void checkasm_check_v210enc(void);
void checkasm_check_vc1dsp(void);
void checkasm_check_vf_bwdif(void);
void checkasm_check_vf_eq(void);
void checkasm_check_vf_gblur(void);
void checkasm_check_vf_hflip(void);
void checkasm_check_vf_threshold(void);
void checkasm_check_vf_sobel(void);
void checkasm_check_vp8dsp(void);
void checkasm_check_vp9dsp(void);
void checkasm_check_videodsp(void);
void checkasm_check_vorbisdsp(void);
void checkasm_check_vvc_alf(void);
void checkasm_check_vvc_mc(void);
struct CheckasmPerf;
void *checkasm_check_func(void *func, const char *name, ...) av_printf_format(2, 3);
int checkasm_bench_func(void);
void checkasm_fail_func(const char *msg, ...) av_printf_format(1, 2);
struct CheckasmPerf *checkasm_get_perf_context(void);
void checkasm_report(const char *name, ...) av_printf_format(1, 2);
void checkasm_set_signal_handler_state(int enabled);
int checkasm_handle_signal(int s);
extern checkasm_context checkasm_context_buf;
/* float compare utilities */
int float_near_ulp(float a, float b, unsigned max_ulp);
int float_near_abs_eps(float a, float b, float eps);
int float_near_abs_eps_ulp(float a, float b, float eps, unsigned max_ulp);
int float_near_ulp_array(const float *a, const float *b, unsigned max_ulp,
unsigned len);
int float_near_abs_eps_array(const float *a, const float *b, float eps,
unsigned len);
int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps,
unsigned max_ulp, unsigned len);
int double_near_abs_eps(double a, double b, double eps);
int double_near_abs_eps_array(const double *a, const double *b, double eps,
unsigned len);
extern AVLFG checkasm_lfg;
#define rnd() av_lfg_get(&checkasm_lfg)
static av_unused void *func_ref, *func_new;
extern uint64_t bench_runs;
/* Decide whether or not the specified function needs to be tested */
#define check_func(func, ...) (checkasm_save_context(), func_ref = checkasm_check_func((func_new = func), __VA_ARGS__))
/* Declare the function prototype. The first argument is the return value, the remaining
* arguments are the function parameters. Naming parameters is optional. */
#define declare_func(ret, ...) declare_new(ret, __VA_ARGS__) typedef ret func_type(__VA_ARGS__)
#define declare_func_float(ret, ...) declare_new_float(ret, __VA_ARGS__) typedef ret func_type(__VA_ARGS__)
#define declare_func_emms(cpu_flags, ret, ...) declare_new_emms(cpu_flags, ret, __VA_ARGS__) typedef ret func_type(__VA_ARGS__)
/* Indicate that the current test has failed */
#define fail() checkasm_fail_func("%s:%d", av_basename(__FILE__), __LINE__)
/* Print the test outcome */
#define report checkasm_report
/* Call the reference function */
#define call_ref(...)\
(checkasm_set_signal_handler_state(1),\
((func_type *)func_ref)(__VA_ARGS__));\
checkasm_set_signal_handler_state(0)
#if ARCH_X86 && HAVE_X86ASM
/* Verifies that clobbered callee-saved registers are properly saved and restored
* and that either no MMX registers are touched or emms is issued */
void checkasm_checked_call(void *func, ...);
/* Verifies that clobbered callee-saved registers are properly saved and restored
* and issues emms for asm functions which are not required to do so */
void checkasm_checked_call_emms(void *func, ...);
/* Verifies that clobbered callee-saved registers are properly saved and restored
* but doesn't issue emms. Meant for dsp functions returning float or double */
void checkasm_checked_call_float(void *func, ...);
#if ARCH_X86_64
/* Evil hack: detect incorrect assumptions that 32-bit ints are zero-extended to 64-bit.
* This is done by clobbering the stack with junk around the stack pointer and calling the
* assembly function through checked_call() with added dummy arguments which forces all
* real arguments to be passed on the stack and not in registers. For 32-bit arguments the
* upper half of the 64-bit register locations on the stack will now contain junk which will
* cause misbehaving functions to either produce incorrect output or segfault. Note that
* even though this works extremely well in practice, it's technically not guaranteed
* and false negatives is theoretically possible, but there can never be any false positives.
*/
void checkasm_stack_clobber(uint64_t clobber, ...);
#define declare_new(ret, ...) ret (*checked_call)(void *, int, int, int, int, int, __VA_ARGS__)\
= (void *)checkasm_checked_call;
#define declare_new_float(ret, ...) ret (*checked_call)(void *, int, int, int, int, int, __VA_ARGS__)\
= (void *)checkasm_checked_call_float;
#define declare_new_emms(cpu_flags, ret, ...) \
ret (*checked_call)(void *, int, int, int, int, int, __VA_ARGS__) = \
((cpu_flags) & av_get_cpu_flags()) ? (void *)checkasm_checked_call_emms : \
(void *)checkasm_checked_call;
#define CLOB (UINT64_C(0xdeadbeefdeadbeef))
#define call_new(...) (checkasm_set_signal_handler_state(1),\
checkasm_stack_clobber(CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,\
CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB),\
checked_call(func_new, 0, 0, 0, 0, 0, __VA_ARGS__));\
checkasm_set_signal_handler_state(0)
#elif ARCH_X86_32
#define declare_new(ret, ...) ret (*checked_call)(void *, __VA_ARGS__) = (void *)checkasm_checked_call;
#define declare_new_float(ret, ...) ret (*checked_call)(void *, __VA_ARGS__) = (void *)checkasm_checked_call_float;
#define declare_new_emms(cpu_flags, ret, ...) ret (*checked_call)(void *, __VA_ARGS__) = \
((cpu_flags) & av_get_cpu_flags()) ? (void *)checkasm_checked_call_emms : \
(void *)checkasm_checked_call;
#define call_new(...)\
(checkasm_set_signal_handler_state(1),\
checked_call(func_new, __VA_ARGS__));\
checkasm_set_signal_handler_state(0)
#endif
#elif ARCH_ARM && HAVE_ARMV5TE_EXTERNAL
/* Use a dummy argument, to offset the real parameters by 2, not only 1.
* This makes sure that potential 8-byte-alignment of parameters is kept the same
* even when the extra parameters have been removed. */
void checkasm_checked_call_vfp(void *func, int dummy, ...);
void checkasm_checked_call_novfp(void *func, int dummy, ...);
extern void (*checkasm_checked_call)(void *func, int dummy, ...);
#define declare_new(ret, ...) ret (*checked_call)(void *, int dummy, __VA_ARGS__, \
int, int, int, int, int, int, int, int, \
int, int, int, int, int, int, int) = (void *)checkasm_checked_call;
#define call_new(...) \
(checkasm_set_signal_handler_state(1),\
checked_call(func_new, 0, __VA_ARGS__, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0));\
checkasm_set_signal_handler_state(0)
#elif ARCH_AARCH64 && !defined(__APPLE__)
void checkasm_stack_clobber(uint64_t clobber, ...);
void checkasm_checked_call(void *func, ...);
#define declare_new(ret, ...) ret (*checked_call)(void *, int, int, int, int, int, int, int, __VA_ARGS__,\
int, int, int, int, int, int, int, int,\
int, int, int, int, int, int, int)\
= (void *)checkasm_checked_call;
#define CLOB (UINT64_C(0xdeadbeefdeadbeef))
#define call_new(...) (checkasm_set_signal_handler_state(1),\
checkasm_stack_clobber(CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,\
CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB,CLOB),\
checked_call(func_new, 0, 0, 0, 0, 0, 0, 0, __VA_ARGS__,\
7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0));\
checkasm_set_signal_handler_state(0)
#elif ARCH_RISCV
void checkasm_set_function(void *);
void *checkasm_get_wrapper(void);
#if HAVE_RV && (__riscv_xlen == 64) && defined (__riscv_d)
#define declare_new(ret, ...) \
ret (*checked_call)(__VA_ARGS__) = checkasm_get_wrapper();
#define call_new(...) \
(checkasm_set_signal_handler_state(1),\
checkasm_set_function(func_new), checked_call(__VA_ARGS__));\
checkasm_set_signal_handler_state(0)
#else
#define declare_new(ret, ...)
#define call_new(...)\
(checkasm_set_signal_handler_state(1),\
((func_type *)func_new)(__VA_ARGS__));\
checkasm_set_signal_handler_state(0)
#endif
#else
#define declare_new(ret, ...)
#define declare_new_float(ret, ...)
#define declare_new_emms(cpu_flags, ret, ...)
/* Call the function */
#define call_new(...)\
(checkasm_set_signal_handler_state(1),\
((func_type *)func_new)(__VA_ARGS__));\
checkasm_set_signal_handler_state(0)
#endif
#ifndef declare_new_emms
#define declare_new_emms(cpu_flags, ret, ...) declare_new(ret, __VA_ARGS__)
#endif
#ifndef declare_new_float
#define declare_new_float(ret, ...) declare_new(ret, __VA_ARGS__)
#endif
typedef struct CheckasmPerf {
int sysfd;
uint64_t cycles;
int iterations;
} CheckasmPerf;
#if defined(AV_READ_TIME) || CONFIG_LINUX_PERF || CONFIG_MACOS_KPERF
#if CONFIG_LINUX_PERF
#define PERF_START(t) do { \
ioctl(sysfd, PERF_EVENT_IOC_RESET, 0); \
ioctl(sysfd, PERF_EVENT_IOC_ENABLE, 0); \
} while (0)
#define PERF_STOP(t) do { \
int ret; \
ioctl(sysfd, PERF_EVENT_IOC_DISABLE, 0); \
ret = read(sysfd, &t, sizeof(t)); \
(void)ret; \
} while (0)
#elif CONFIG_MACOS_KPERF
#define PERF_START(t) t = ff_kperf_cycles()
#define PERF_STOP(t) t = ff_kperf_cycles() - t
#else
#define PERF_START(t) t = AV_READ_TIME()
#define PERF_STOP(t) t = AV_READ_TIME() - t
#endif
/* Benchmark the function */
#define bench_new(...)\
do {\
if (checkasm_bench_func()) {\
struct CheckasmPerf *perf = checkasm_get_perf_context();\
av_unused const int sysfd = perf->sysfd;\
func_type *tfunc = func_new;\
uint64_t tsum = 0;\
uint64_t ti, tcount = 0;\
uint64_t t = 0; \
const uint64_t truns = bench_runs;\
checkasm_set_signal_handler_state(1);\
for (ti = 0; ti < truns; ti++) {\
PERF_START(t);\
tfunc(__VA_ARGS__);\
tfunc(__VA_ARGS__);\
tfunc(__VA_ARGS__);\
tfunc(__VA_ARGS__);\
PERF_STOP(t);\
if (t*tcount <= tsum*4 && ti > 0) {\
tsum += t;\
tcount++;\
}\
}\
emms_c();\
perf->cycles += t;\
perf->iterations++;\
checkasm_set_signal_handler_state(0);\
}\
} while (0)
#else
#define bench_new(...) while(0)
#define PERF_START(t) while(0)
#define PERF_STOP(t) while(0)
#endif
#define DECL_CHECKASM_CHECK_FUNC(type) \
int checkasm_check_##type(const char *file, int line, \
const type *buf1, ptrdiff_t stride1, \
const type *buf2, ptrdiff_t stride2, \
int w, int h, const char *name)
DECL_CHECKASM_CHECK_FUNC(uint8_t);
DECL_CHECKASM_CHECK_FUNC(uint16_t);
DECL_CHECKASM_CHECK_FUNC(uint32_t);
DECL_CHECKASM_CHECK_FUNC(int16_t);
DECL_CHECKASM_CHECK_FUNC(int32_t);
#define PASTE(a,b) a ## b
#define CONCAT(a,b) PASTE(a,b)
#define checkasm_check(prefix, ...) CONCAT(checkasm_check_, prefix)(__FILE__, __LINE__, __VA_ARGS__)
#endif /* TESTS_CHECKASM_CHECKASM_H */
+92
View File
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2017 James Almer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/defs.h"
#include "libavcodec/exrdsp.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define BUF_SIZE 5120
#define PADDED_BUF_SIZE BUF_SIZE+AV_INPUT_BUFFER_PADDING_SIZE*2
#define randomize_buffers() \
do { \
int i; \
for (i = 0; i < BUF_SIZE; i += 4) { \
uint32_t r = rnd(); \
AV_WN32A(src + i, r); \
} \
} while (0)
static void check_reorder_pixels(void) {
LOCAL_ALIGNED_32(uint8_t, src, [PADDED_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst_ref, [PADDED_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst_new, [PADDED_BUF_SIZE]);
declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t size);
memset(src, 0, PADDED_BUF_SIZE);
memset(dst_ref, 0, PADDED_BUF_SIZE);
memset(dst_new, 0, PADDED_BUF_SIZE);
randomize_buffers();
call_ref(dst_ref, src, BUF_SIZE);
call_new(dst_new, src, BUF_SIZE);
if (memcmp(dst_ref, dst_new, BUF_SIZE))
fail();
bench_new(dst_new, src, BUF_SIZE);
}
static void check_predictor(void) {
LOCAL_ALIGNED_32(uint8_t, src, [PADDED_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst_ref, [PADDED_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst_new, [PADDED_BUF_SIZE]);
declare_func(void, uint8_t *src, ptrdiff_t size);
memset(src, 0, PADDED_BUF_SIZE);
randomize_buffers();
memcpy(dst_ref, src, PADDED_BUF_SIZE);
memcpy(dst_new, src, PADDED_BUF_SIZE);
call_ref(dst_ref, BUF_SIZE);
call_new(dst_new, BUF_SIZE);
if (memcmp(dst_ref, dst_new, BUF_SIZE))
fail();
bench_new(dst_new, BUF_SIZE);
}
void checkasm_check_exrdsp(void)
{
ExrDSPContext h;
ff_exrdsp_init(&h);
if (check_func(h.reorder_pixels, "reorder_pixels"))
check_reorder_pixels();
report("reorder_pixels");
if (check_func(h.predictor, "predictor"))
check_predictor();
report("predictor");
}
+71
View File
@@ -0,0 +1,71 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/avcodec.h"
#include "libavcodec/fdctdsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
static int int16_cmp_off_by_n(const int16_t *ref, const int16_t *test, size_t n, int accuracy)
{
for (size_t i = 0; i < n; i++) {
if (abs(ref[i] - test[i]) > accuracy)
return 1;
}
return 0;
}
static void check_fdct(void)
{
LOCAL_ALIGNED_16(int16_t, block0, [64]);
LOCAL_ALIGNED_16(int16_t, block1, [64]);
AVCodecContext avctx = {
.bits_per_raw_sample = 8,
.dct_algo = FF_DCT_AUTO,
};
FDCTDSPContext h;
ff_fdctdsp_init(&h, &avctx);
if (check_func(h.fdct, "fdct")) {
declare_func(void, int16_t *);
for (int i = 0; i < 64; i++) {
uint8_t r = rnd();
block0[i] = r;
block1[i] = r;
}
call_ref(block0);
call_new(block1);
if (int16_cmp_off_by_n(block0, block1, 64, 2))
fail();
bench_new(block1);
}
}
void checkasm_check_fdctdsp(void)
{
check_fdct();
report("fdctdsp");
}
+160
View File
@@ -0,0 +1,160 @@
/*
* Copyright (c) 2015 James Almer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "checkasm.h"
#include "libavutil/common.h"
#include "libavutil/fixed_dsp.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#define BUF_SIZE 256
#define randomize_buffers() \
do { \
int i; \
for (i = 0; i < BUF_SIZE; i++) { \
src0[i] = sign_extend(rnd(), 24); \
src1[i] = sign_extend(rnd(), 24); \
src2[i] = sign_extend(rnd(), 24); \
} \
} while (0)
static void check_vector_fmul(const int *src0, const int *src1)
{
LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
declare_func(void, int *dst, const int *src0, const int *src1, int len);
call_ref(ref, src0, src1, BUF_SIZE);
call_new(new, src0, src1, BUF_SIZE);
if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
fail();
bench_new(new, src0, src1, BUF_SIZE);
}
static void check_vector_fmul_add(const int *src0, const int *src1, const int *src2)
{
LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
declare_func(void, int *dst, const int *src0, const int *src1, const int *src2, int len);
call_ref(ref, src0, src1, src2, BUF_SIZE);
call_new(new, src0, src1, src2, BUF_SIZE);
if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
fail();
bench_new(new, src0, src1, src2, BUF_SIZE);
}
static void check_vector_fmul_window(const int32_t *src0, const int32_t *src1, const int32_t *win)
{
LOCAL_ALIGNED_32(int32_t, ref, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, new, [BUF_SIZE]);
declare_func(void, int32_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len);
call_ref(ref, src0, src1, win, BUF_SIZE / 2);
call_new(new, src0, src1, win, BUF_SIZE / 2);
if (memcmp(ref, new, BUF_SIZE * sizeof(int32_t)))
fail();
bench_new(new, src0, src1, win, BUF_SIZE / 2);
}
static void check_vector_fmul_window_scaled(const int32_t *src0, const int32_t *src1, const int32_t *win)
{
LOCAL_ALIGNED_16(int16_t, ref, [BUF_SIZE]);
LOCAL_ALIGNED_16(int16_t, new, [BUF_SIZE]);
declare_func(void, int16_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len, uint8_t bits);
call_ref(ref, src0, src1, win, BUF_SIZE / 2, 2);
call_new(new, src0, src1, win, BUF_SIZE / 2, 2);
if (memcmp(ref, new, BUF_SIZE * sizeof(int16_t)))
fail();
bench_new(new, src0, src1, win, BUF_SIZE / 2, 2);
}
static void check_butterflies(const int *src0, const int *src1)
{
LOCAL_ALIGNED_16(int, ref0, [BUF_SIZE]);
LOCAL_ALIGNED_16(int, ref1, [BUF_SIZE]);
LOCAL_ALIGNED_16(int, new0, [BUF_SIZE]);
LOCAL_ALIGNED_16(int, new1, [BUF_SIZE]);
declare_func(void, int *restrict src0, int *restrict src1, int len);
memcpy(ref0, src0, BUF_SIZE * sizeof(*src0));
memcpy(ref1, src1, BUF_SIZE * sizeof(*src1));
memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
call_ref(ref0, ref1, BUF_SIZE);
call_new(new0, new1, BUF_SIZE);
if (memcmp(ref0, new0, BUF_SIZE * sizeof(*ref0)) ||
memcmp(ref1, new1, BUF_SIZE * sizeof(*ref1)))
fail();
memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
bench_new(new0, new1, BUF_SIZE);
}
static void check_scalarproduct_fixed(const int *src0, const int *src1)
{
int ref, new;
declare_func(int, const int *src0, const int *src1, int len);
ref = call_ref(src0, src1, BUF_SIZE);
new = call_new(src0, src1, BUF_SIZE);
if (ref != new)
fail();
bench_new(src0, src1, BUF_SIZE);
}
void checkasm_check_fixed_dsp(void)
{
LOCAL_ALIGNED_32(int32_t, src0, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, src1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, src2, [BUF_SIZE]);
AVFixedDSPContext *fdsp = avpriv_alloc_fixed_dsp(1);
randomize_buffers();
if (check_func(fdsp->vector_fmul, "vector_fmul_fixed"))
check_vector_fmul(src0, src1);
if (check_func(fdsp->vector_fmul_add, "vector_fmul_add_fixed"))
check_vector_fmul_add(src0, src1, src2);
if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse_fixed"))
check_vector_fmul(src0, src1);
if (check_func(fdsp->vector_fmul_window, "vector_fmul_window_fixed"))
check_vector_fmul_window(src0, src1, src2);
if (check_func(fdsp->vector_fmul_window_scaled, "vector_fmul_window_scaled_fixed"))
check_vector_fmul_window_scaled(src0, src1, src2);
report("vector_fmul");
if (check_func(fdsp->butterflies_fixed, "butterflies_fixed"))
check_butterflies(src0, src1);
report("butterflies_fixed");
if (check_func(fdsp->scalarproduct_fixed, "scalarproduct_fixed"))
check_scalarproduct_fixed(src0, src1);
report("scalarproduct_fixed");
av_freep(&fdsp);
}
+209
View File
@@ -0,0 +1,209 @@
/*
* Copyright (c) 2015 James Almer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/flacdsp.h"
#include "libavcodec/mathops.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define BUF_SIZE 256
#define MAX_CHANNELS 8
#define randomize_buffers() \
do { \
int i, j; \
for (i = 0; i < BUF_SIZE; i += 4) { \
for (j = 0; j < channels; j++) { \
uint32_t r = rnd() & (1 << (bits - 2)) - 1; \
AV_WN32A(ref_src[j] + i, r); \
AV_WN32A(new_src[j] + i, r); \
} \
} \
} while (0)
static void check_decorrelate(uint8_t **ref_dst, uint8_t **ref_src, uint8_t **new_dst, uint8_t **new_src,
int channels, int bits) {
declare_func(void, uint8_t **out, int32_t **in, int channels, int len, int shift);
randomize_buffers();
call_ref(ref_dst, (int32_t **)ref_src, channels, BUF_SIZE / sizeof(int32_t), 8);
call_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
if (memcmp(*ref_dst, *new_dst, bits == 16 ? BUF_SIZE * (channels/2) : BUF_SIZE * channels) ||
memcmp(*ref_src, *new_src, BUF_SIZE * channels))
fail();
bench_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
}
static void check_lpc(int pred_order, int bps)
{
int qlevel = rnd() % 16;
int coeff_prec = (rnd() % 15) + 1;
LOCAL_ALIGNED_16(int32_t, coeffs, [32]);
LOCAL_ALIGNED_16(int32_t, dst, [BUF_SIZE]);
LOCAL_ALIGNED_16(int32_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(int32_t, dst1, [BUF_SIZE]);
declare_func(void, int32_t *, const int[32], int, int, int);
if (bps <= 16)
coeff_prec = av_clip(coeff_prec, 0, 32 - bps - av_log2(pred_order));
for (int i = 0; i < 32; i++)
coeffs[i] = sign_extend(rnd(), coeff_prec);
for (int i = 0; i < BUF_SIZE; i++)
dst[i] = sign_extend(rnd(), bps);
memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t));
memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t));
call_ref(dst0, coeffs, pred_order, qlevel, BUF_SIZE);
call_new(dst1, coeffs, pred_order, qlevel, BUF_SIZE);
if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int32_t)) != 0)
fail();
bench_new(dst, coeffs, pred_order, qlevel, BUF_SIZE);
}
static void check_lpc33(int pred_order)
{
int qlevel = rnd() % 16;
int coeff_prec = (rnd() % 15) + 1;
LOCAL_ALIGNED_16(int64_t, dst, [BUF_SIZE]);
LOCAL_ALIGNED_16(int64_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(int64_t, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_16(int32_t, residuals, [BUF_SIZE]);
LOCAL_ALIGNED_16(int32_t, coeffs, [32]);
declare_func(void, int64_t *, const int32_t *, const int[32], int, int, int);
for (int i = 0; i < 32; i++)
coeffs[i] = sign_extend(rnd(), coeff_prec);
for (int i = 0; i < BUF_SIZE; i++) {
residuals[i] = sign_extend(rnd(), pred_order);
dst[i] = sign_extend64(((int64_t)rnd() << 1) | (rnd() & 1), 33);
}
memcpy(dst0, dst, BUF_SIZE * sizeof (int64_t));
memcpy(dst1, dst, BUF_SIZE * sizeof (int64_t));
call_ref(dst0, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
call_new(dst1, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int64_t)) != 0)
fail();
bench_new(dst, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
}
static void check_wasted32(void)
{
int wasted = rnd() % 32;
LOCAL_ALIGNED_16(int32_t, dst, [BUF_SIZE]);
LOCAL_ALIGNED_16(int32_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(int32_t, dst1, [BUF_SIZE]);
declare_func(void, int32_t *, int, int);
for (int i = 0; i < BUF_SIZE; i++)
dst[i] = rnd();
memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t));
memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t));
call_ref(dst0, wasted, BUF_SIZE);
call_new(dst1, wasted, BUF_SIZE);
if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int32_t)) != 0)
fail();
bench_new(dst, wasted, BUF_SIZE);
}
static void check_wasted33(void)
{
int wasted = rnd() % 33;
LOCAL_ALIGNED_16(int64_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(int64_t, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_16(int32_t, residuals, [BUF_SIZE]);
declare_func(void, int64_t *, const int32_t *, int, int);
for (int i = 0; i < BUF_SIZE; i++)
residuals[i] = rnd();
call_ref(dst0, residuals, wasted, BUF_SIZE);
call_new(dst1, residuals, wasted, BUF_SIZE);
if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int64_t)) != 0)
fail();
bench_new(dst0, residuals, wasted, BUF_SIZE);
}
void checkasm_check_flacdsp(void)
{
LOCAL_ALIGNED_16(uint8_t, ref_dst, [BUF_SIZE*MAX_CHANNELS]);
LOCAL_ALIGNED_16(uint8_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]);
LOCAL_ALIGNED_16(uint8_t, new_dst, [BUF_SIZE*MAX_CHANNELS]);
LOCAL_ALIGNED_16(uint8_t, new_buf, [BUF_SIZE*MAX_CHANNELS]);
uint8_t *ref_src[] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1], &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3],
&ref_buf[BUF_SIZE*4], &ref_buf[BUF_SIZE*5], &ref_buf[BUF_SIZE*6], &ref_buf[BUF_SIZE*7] };
uint8_t *new_src[] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1], &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3],
&new_buf[BUF_SIZE*4], &new_buf[BUF_SIZE*5], &new_buf[BUF_SIZE*6], &new_buf[BUF_SIZE*7] };
static const char * const names[3] = { "ls", "rs", "ms" };
static const struct {
enum AVSampleFormat fmt;
int bits;
} fmts[] = {
{ AV_SAMPLE_FMT_S16, 16 },
{ AV_SAMPLE_FMT_S32, 32 },
};
static const signed char pred_orders[] = { 13, 16, 29, 32 };
FLACDSPContext h;
int i, j;
for (i = 0; i < 2; i++) {
ff_flacdsp_init(&h, fmts[i].fmt, 2);
for (j = 0; j < 3; j++)
if (check_func(h.decorrelate[j + 1], "flac_decorrelate_%s_%d", names[j], fmts[i].bits))
check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, 2, fmts[i].bits);
for (j = 2; j <= MAX_CHANNELS; j += 2) {
ff_flacdsp_init(&h, fmts[i].fmt, j);
if (check_func(h.decorrelate[0], "flac_decorrelate_indep%d_%d", j, fmts[i].bits))
check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, j, fmts[i].bits);
}
}
report("decorrelate");
for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++)
if (check_func(h.lpc16, "flac_lpc_16_%d", pred_orders[i]))
check_lpc(pred_orders[i], 16);
for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++)
if (check_func(h.lpc32, "flac_lpc_32_%d", pred_orders[i]))
check_lpc(pred_orders[i], 32);
for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++)
if (check_func(h.lpc33, "flac_lpc_33_%d", pred_orders[i]))
check_lpc33(pred_orders[i]);
report("lpc");
if (check_func(h.wasted32, "flac_wasted_32"))
check_wasted32();
if (check_func(h.wasted33, "flac_wasted_33"))
check_wasted33();
report("wasted");
}
+358
View File
@@ -0,0 +1,358 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <float.h>
#include <stdint.h>
#include "libavutil/float_dsp.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "checkasm.h"
#define LEN 256
#define randomize_buffer(buf) \
do { \
int i; \
double bmg[2], stddev = 10.0, mean = 0.0; \
\
for (i = 0; i < LEN; i += 2) { \
av_bmg_get(&checkasm_lfg, bmg); \
buf[i] = bmg[0] * stddev + mean; \
buf[i + 1] = bmg[1] * stddev + mean; \
} \
} while(0);
static void test_vector_fmul(const float *src0, const float *src1)
{
LOCAL_ALIGNED_32(float, cdst, [LEN]);
LOCAL_ALIGNED_32(float, odst, [LEN]);
int i;
declare_func(void, float *dst, const float *src0, const float *src1,
int len);
call_ref(cdst, src0, src1, LEN);
call_new(odst, src0, src1, LEN);
for (i = 0; i < LEN; i++) {
double t = fabs(src0[i]) + fabs(src1[i]) + fabs(src0[i] * src1[i]) + 1.0;
if (!float_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
bench_new(odst, src0, src1, LEN);
}
static void test_vector_dmul(const double *src0, const double *src1)
{
LOCAL_ALIGNED_32(double, cdst, [LEN]);
LOCAL_ALIGNED_32(double, odst, [LEN]);
int i;
declare_func(void, double *dst, const double *src0, const double *src1,
int len);
call_ref(cdst, src0, src1, LEN);
call_new(odst, src0, src1, LEN);
for (i = 0; i < LEN; i++) {
double t = fabs(src0[i]) + fabs(src1[i]) + fabs(src0[i] * src1[i]) + 1.0;
if (!double_near_abs_eps(cdst[i], odst[i], t * 2 * DBL_EPSILON)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
bench_new(odst, src0, src1, LEN);
}
#define ARBITRARY_FMUL_ADD_CONST 0.005
static void test_vector_fmul_add(const float *src0, const float *src1, const float *src2)
{
LOCAL_ALIGNED_32(float, cdst, [LEN]);
LOCAL_ALIGNED_32(float, odst, [LEN]);
int i;
declare_func(void, float *dst, const float *src0, const float *src1,
const float *src2, int len);
call_ref(cdst, src0, src1, src2, LEN);
call_new(odst, src0, src1, src2, LEN);
for (i = 0; i < LEN; i++) {
if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMUL_ADD_CONST)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
bench_new(odst, src0, src1, src2, LEN);
}
static void test_vector_fmul_scalar(const float *src0, const float *src1)
{
LOCAL_ALIGNED_16(float, cdst, [LEN]);
LOCAL_ALIGNED_16(float, odst, [LEN]);
int i;
declare_func(void, float *dst, const float *src, float mul, int len);
call_ref(cdst, src0, src1[0], LEN);
call_new(odst, src0, src1[0], LEN);
for (i = 0; i < LEN; i++) {
double t = fabs(src0[i]) + fabs(src1[0]) + fabs(src0[i] * src1[0]) + 1.0;
if (!float_near_abs_eps(cdst[i], odst[i], t * 2 * FLT_EPSILON)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
bench_new(odst, src0, src1[0], LEN);
}
#define ARBITRARY_FMUL_WINDOW_CONST 0.008
static void test_vector_fmul_window(const float *src0, const float *src1, const float *win)
{
LOCAL_ALIGNED_16(float, cdst, [LEN]);
LOCAL_ALIGNED_16(float, odst, [LEN]);
int i;
declare_func(void, float *dst, const float *src0, const float *src1,
const float *win, int len);
call_ref(cdst, src0, src1, win, LEN / 2);
call_new(odst, src0, src1, win, LEN / 2);
for (i = 0; i < LEN; i++) {
if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMUL_WINDOW_CONST)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
bench_new(odst, src0, src1, win, LEN / 2);
}
#define ARBITRARY_FMAC_SCALAR_CONST 0.005
static void test_vector_fmac_scalar(const float *src0, const float *src1, const float *src2)
{
LOCAL_ALIGNED_32(float, cdst, [LEN]);
LOCAL_ALIGNED_32(float, odst, [LEN]);
int i;
declare_func(void, float *dst, const float *src, float mul, int len);
memcpy(cdst, src2, LEN * sizeof(*src2));
memcpy(odst, src2, LEN * sizeof(*src2));
call_ref(cdst, src0, src1[0], LEN);
call_new(odst, src0, src1[0], LEN);
for (i = 0; i < LEN; i++) {
if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMAC_SCALAR_CONST)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
memcpy(odst, src2, LEN * sizeof(*src2));
bench_new(odst, src0, src1[0], LEN);
}
static void test_vector_dmul_scalar(const double *src0, const double *src1)
{
LOCAL_ALIGNED_32(double, cdst, [LEN]);
LOCAL_ALIGNED_32(double, odst, [LEN]);
int i;
declare_func(void, double *dst, const double *src, double mul, int len);
call_ref(cdst, src0, src1[0], LEN);
call_new(odst, src0, src1[0], LEN);
for (i = 0; i < LEN; i++) {
double t = fabs(src1[0]) + fabs(src0[i]) + fabs(src1[0] * src0[i]) + 1.0;
if (!double_near_abs_eps(cdst[i], odst[i], t * 2 * DBL_EPSILON)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", i,
cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
bench_new(odst, src0, src1[0], LEN);
}
#define ARBITRARY_DMAC_SCALAR_CONST 0.005
static void test_vector_dmac_scalar(const double *src0, const double *src1, const double *src2)
{
LOCAL_ALIGNED_32(double, cdst, [LEN]);
LOCAL_ALIGNED_32(double, odst, [LEN]);
int i;
declare_func(void, double *dst, const double *src, double mul, int len);
memcpy(cdst, src2, LEN * sizeof(*src2));
memcpy(odst, src2, LEN * sizeof(*src2));
call_ref(cdst, src0, src1[0], LEN);
call_new(odst, src0, src1[0], LEN);
for (i = 0; i < LEN; i++) {
if (!double_near_abs_eps(cdst[i], odst[i], ARBITRARY_DMAC_SCALAR_CONST)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fail();
break;
}
}
memcpy(odst, src2, LEN * sizeof(*src2));
bench_new(odst, src0, src1[0], LEN);
}
static void test_butterflies_float(const float *src0, const float *src1)
{
LOCAL_ALIGNED_16(float, cdst, [LEN]);
LOCAL_ALIGNED_16(float, odst, [LEN]);
LOCAL_ALIGNED_16(float, cdst1, [LEN]);
LOCAL_ALIGNED_16(float, odst1, [LEN]);
int i;
declare_func(void, float *restrict src0, float *restrict src1,
int len);
memcpy(cdst, src0, LEN * sizeof(*src0));
memcpy(cdst1, src1, LEN * sizeof(*src1));
memcpy(odst, src0, LEN * sizeof(*src0));
memcpy(odst1, src1, LEN * sizeof(*src1));
call_ref(cdst, cdst1, LEN);
call_new(odst, odst1, LEN);
for (i = 0; i < LEN; i++) {
if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON) ||
!float_near_abs_eps(cdst1[i], odst1[i], FLT_EPSILON)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst1[i], odst1[i], cdst1[i] - odst1[i]);
fail();
break;
}
}
memcpy(odst, src0, LEN * sizeof(*src0));
memcpy(odst1, src1, LEN * sizeof(*src1));
bench_new(odst, odst1, LEN);
}
#define ARBITRARY_SCALARPRODUCT_CONST 0.2
static void test_scalarproduct_float(const float *src0, const float *src1)
{
float cprod, oprod;
declare_func_float(float, const float *src0, const float *src1, int len);
cprod = call_ref(src0, src1, LEN);
oprod = call_new(src0, src1, LEN);
if (!float_near_abs_eps(cprod, oprod, ARBITRARY_SCALARPRODUCT_CONST)) {
fprintf(stderr, "%- .12f - %- .12f = % .12g\n",
cprod, oprod, cprod - oprod);
fail();
}
bench_new(src0, src1, LEN);
}
static void test_scalarproduct_double(const double *src0, const double *src1)
{
double cprod, oprod;
declare_func_float(double, const double *, const double *, size_t);
cprod = call_ref(src0, src1, LEN);
oprod = call_new(src0, src1, LEN);
if (!double_near_abs_eps(cprod, oprod, ARBITRARY_SCALARPRODUCT_CONST)) {
fprintf(stderr, "%- .12f - %- .12f = % .12g\n",
cprod, oprod, cprod - oprod);
fail();
}
bench_new(src0, src1, LEN);
}
void checkasm_check_float_dsp(void)
{
LOCAL_ALIGNED_32(float, src0, [LEN]);
LOCAL_ALIGNED_32(float, src1, [LEN]);
LOCAL_ALIGNED_32(float, src2, [LEN]);
LOCAL_ALIGNED_16(float, src3, [LEN]);
LOCAL_ALIGNED_16(float, src4, [LEN]);
LOCAL_ALIGNED_16(float, src5, [LEN]);
LOCAL_ALIGNED_32(double, dbl_src0, [LEN]);
LOCAL_ALIGNED_32(double, dbl_src1, [LEN]);
LOCAL_ALIGNED_32(double, dbl_src2, [LEN]);
AVFloatDSPContext *fdsp = avpriv_float_dsp_alloc(1);
if (!fdsp) {
fprintf(stderr, "floatdsp: Out of memory error\n");
return;
}
randomize_buffer(src0);
randomize_buffer(src1);
randomize_buffer(src2);
randomize_buffer(src3);
randomize_buffer(src4);
randomize_buffer(src5);
randomize_buffer(dbl_src0);
randomize_buffer(dbl_src1);
randomize_buffer(dbl_src2);
if (check_func(fdsp->vector_fmul, "vector_fmul"))
test_vector_fmul(src0, src1);
if (check_func(fdsp->vector_fmul_add, "vector_fmul_add"))
test_vector_fmul_add(src0, src1, src2);
if (check_func(fdsp->vector_fmul_scalar, "vector_fmul_scalar"))
test_vector_fmul_scalar(src3, src4);
if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse"))
test_vector_fmul(src0, src1);
if (check_func(fdsp->vector_fmul_window, "vector_fmul_window"))
test_vector_fmul_window(src3, src4, src5);
report("vector_fmul");
if (check_func(fdsp->vector_fmac_scalar, "vector_fmac_scalar"))
test_vector_fmac_scalar(src0, src1, src2);
report("vector_fmac");
if (check_func(fdsp->vector_dmul, "vector_dmul"))
test_vector_dmul(dbl_src0, dbl_src1);
if (check_func(fdsp->vector_dmul_scalar, "vector_dmul_scalar"))
test_vector_dmul_scalar(dbl_src0, dbl_src1);
report("vector_dmul");
if (check_func(fdsp->vector_dmac_scalar, "vector_dmac_scalar"))
test_vector_dmac_scalar(dbl_src0, dbl_src1, dbl_src2);
report("vector_dmac");
if (check_func(fdsp->butterflies_float, "butterflies_float"))
test_butterflies_float(src3, src4);
report("butterflies_float");
if (check_func(fdsp->scalarproduct_float, "scalarproduct_float"))
test_scalarproduct_float(src3, src4);
report("scalarproduct_float");
if (check_func(fdsp->scalarproduct_double, "scalarproduct_double"))
test_scalarproduct_double(dbl_src0, dbl_src1);
report("scalarproduct_double");
av_freep(&fdsp);
}
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2015 Janne Grunau
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <math.h>
#include <stdint.h>
#include <string.h>
#include "libavutil/internal.h"
#include "libavutil/common.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/fmtconvert.h"
#include "checkasm.h"
#define BUF_SIZE 1024
#define randomize_input(len) \
do { \
int k; \
for (k = 0; k < len; k++) { \
in[k] = rnd() - INT32_MAX; \
} \
for ( ; k < BUF_SIZE; k++) { \
in[k] = INT32_MAX; \
} \
} while (0)
void checkasm_check_fmtconvert(void)
{
FmtConvertContext c;
LOCAL_ALIGNED(32, float, dst0, [BUF_SIZE]);
LOCAL_ALIGNED(32, float, dst1, [BUF_SIZE]);
LOCAL_ALIGNED(32, int32_t, in, [BUF_SIZE]);
float scale_arr[128];
int length[] = {8, 16, 24, 56, 72, 128, 512, 520, 656, 768, 992};
int i, j;
for (i = 0; i < FF_ARRAY_ELEMS(scale_arr); i++)
scale_arr[i] = (FF_ARRAY_ELEMS(scale_arr) - FF_ARRAY_ELEMS(scale_arr) / 2) / 13;
ff_fmt_convert_init(&c);
memset(dst0, 0, sizeof(*dst0) * BUF_SIZE);
memset(dst1, 0, sizeof(*dst1) * BUF_SIZE);
if (check_func(c.int32_to_float_fmul_scalar, "int32_to_float_fmul_scalar")) {
declare_func(void, float *, const int32_t *, float, int);
for (i = 0; i < FF_ARRAY_ELEMS(scale_arr); i++) {
for (j = 0; j < FF_ARRAY_ELEMS(length); j++) {
randomize_input(length[j]);
call_ref(dst0, in, scale_arr[i], length[j]);
call_new(dst1, in, scale_arr[i], length[j]);
if (!float_near_ulp_array(dst0, dst1, 3, length[j])) {
fail();
break;
}
bench_new(dst1, in, scale_arr[i], length[j]);
}
}
}
if (check_func(c.int32_to_float_fmul_array8, "int32_to_float_fmul_array8")) {
declare_func(void, FmtConvertContext *, float *, const int32_t *,
const float *, int);
for (i = 0; i < 4; i++) {
for (j = 0; j < FF_ARRAY_ELEMS(length); j++) {
randomize_input(length[j]);
call_ref(&c, dst0, in, scale_arr, length[j]);
call_new(&c, dst1, in, scale_arr, length[j]);
if (!float_near_ulp_array(dst0, dst1, 3, length[j])) {
fail();
fprintf(stderr, "int32_to_float_fmul_array8: len: %d\n", length[j]);
break;
}
bench_new(&c, dst1, in, scale_arr, length[j]);
}
}
}
report("fmtconvert");
}
+63
View File
@@ -0,0 +1,63 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/g722.h"
#include "libavcodec/g722dsp.h"
#include "libavcodec/mathops.h"
#define randomize_buffers() \
do { \
int i; \
for (i = 0; i < PREV_SAMPLES_BUF_SIZE; i++) { \
src0[i] = src1[i] = sign_extend(rnd(), 16); \
} \
} while (0)
static void check_qmf(void) {
int16_t src0[PREV_SAMPLES_BUF_SIZE];
int16_t src1[PREV_SAMPLES_BUF_SIZE];
const int16_t *tmp0 = src0;
const int16_t *tmp1 = src1;
int dst0[2], dst1[2];
int i;
declare_func(void, const int16_t *prev_samples, int xout[2]);
randomize_buffers();
for (i = 0; i < PREV_SAMPLES_BUF_SIZE - 24; i++) {
call_ref(tmp0++, dst0);
call_new(tmp1++, dst1);
if (memcmp(dst0, dst1, sizeof(dst0)))
fail();
}
bench_new(src1, dst1);
}
void checkasm_check_g722dsp(void)
{
G722DSPContext h;
ff_g722dsp_init(&h);
if (check_func(h.apply_qmf, "g722_apply_qmf"))
check_qmf();
report("apply_qmf");
}
+62
View File
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 Rémi Denis-Courmont
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/h263dsp.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
typedef void (*filter)(uint8_t *src, int stride, int qscale);
static void check_loop_filter(char dim, filter func)
{
LOCAL_ALIGNED_16(uint8_t, buf0, [32 * 32]);
LOCAL_ALIGNED_16(uint8_t, buf1, [32 * 32]);
int qscale = rnd() % 32;
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, int, int);
for (size_t y = 0; y < 32; y++)
for (size_t x = 0; x < 32; x++)
buf0[y * 32 + x] = buf1[y * 32 + x] = rnd();
if (check_func(func, "h263dsp.%c_loop_filter", dim)) {
call_ref(buf0 + 8 * 33, 32, qscale);
call_new(buf1 + 8 * 33, 32, qscale);
if (memcmp(buf0, buf1, 32 * 32))
fail();
bench_new(buf1 + 8 * 33, 32, 1);
}
}
void checkasm_check_h263dsp(void)
{
H263DSPContext ctx;
ff_h263dsp_init(&ctx);
check_loop_filter('h', ctx.h263_h_loop_filter);
check_loop_filter('v', ctx.h263_v_loop_filter);
report("loop_filter");
}
+85
View File
@@ -0,0 +1,85 @@
/*
* Copyright (c) Lynne
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include <stdint.h>
#include "checkasm.h"
#include "libavcodec/h264chroma.h"
#include "libavutil/mem_internal.h"
#include "libavutil/intreadwrite.h"
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define randomize_buffers(bit_depth) \
do { \
if (bit_depth == 8) { \
for (int i = 0; i < 16*18*2; i++) \
src[i] = rnd() & 0x3; \
} else { \
for (int i = 0; i < 16*18; i += 2) \
AV_WN16(&src[i], rnd() & 0xFF); \
} \
} while (0)
static void check_chroma_mc(void)
{
H264ChromaContext h;
LOCAL_ALIGNED_32(uint8_t, src, [16 * 18 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0, [16 * 18 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1, [16 * 18 * 2]);
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const uint8_t *src,
ptrdiff_t stride, int h, int x, int y);
for (int bit_depth = 8; bit_depth <= 10; bit_depth++) {
ff_h264chroma_init(&h, bit_depth);
randomize_buffers(bit_depth);
for (int size = 0; size < 4; size++) {
#define CHECK_CHROMA_MC(name) \
do { \
if (check_func(h.name## _pixels_tab[size], #name "_mc%d_%d", 1 << (3-size), bit_depth)) { \
for (int x = 0; x < 2; x++) { \
for (int y = 0; y < 2; y++) { \
memcpy(dst0, src, 16 * 18 * SIZEOF_PIXEL); \
memcpy(dst1, src, 16 * 18 * SIZEOF_PIXEL); \
call_ref(dst0, src, 16 * SIZEOF_PIXEL, 16, x, y); \
call_new(dst1, src, 16 * SIZEOF_PIXEL, 16, x, y); \
if (memcmp(dst0, dst1, 16 * 16 * SIZEOF_PIXEL)) { \
fprintf(stderr, #name ": x:%i, y:%i\n", x, y); \
fail(); \
} \
bench_new(dst1, src, 16 * SIZEOF_PIXEL, 16, x, y); \
} \
} \
} \
} while (0)
CHECK_CHROMA_MC(put_h264_chroma);
CHECK_CHROMA_MC(avg_h264_chroma);
}
}
}
void checkasm_check_h264chroma(void)
{
check_chroma_mc();
report("chroma_mc");
}
+463
View File
@@ -0,0 +1,463 @@
/*
* Copyright (c) 2016 Martin Storsjo
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/h264dsp.h"
#include "libavcodec/h264data.h"
#include "libavcodec/h264_parse.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
static const uint32_t pixel_mask[5] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff, 0x0fff0fff, 0x3fff3fff };
static const uint32_t pixel_mask_lf[3] = { 0xff0fff0f, 0x01ff000f, 0x03ff000f };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define SIZEOF_COEF (2 * ((bit_depth + 7) / 8))
#define PIXEL_STRIDE 16
#define randomize_buffers(idx) \
do { \
int x, y; \
uint32_t mask = pixel_mask[(idx)]; \
for (y = 0; y < sz; y++) { \
for (x = 0; x < PIXEL_STRIDE; x += 4) { \
AV_WN32A(src + y * PIXEL_STRIDE + x, rnd() & mask); \
AV_WN32A(dst + y * PIXEL_STRIDE + x, rnd() & mask); \
} \
for (x = 0; x < sz; x++) { \
if (bit_depth == 8) { \
coef[y * sz + x] = src[y * PIXEL_STRIDE + x] - \
dst[y * PIXEL_STRIDE + x]; \
} else { \
((int32_t *)coef)[y * sz + x] = \
((uint16_t *)src)[y * (PIXEL_STRIDE/2) + x] - \
((uint16_t *)dst)[y * (PIXEL_STRIDE/2) + x]; \
} \
} \
} \
} while (0)
#define dct4x4_impl(size, dctcoef) \
static void dct4x4_##size(dctcoef *coef) \
{ \
int i, y, x; \
dctcoef tmp[16]; \
for (i = 0; i < 4; i++) { \
const int z0 = coef[i*4 + 0] + coef[i*4 + 3]; \
const int z1 = coef[i*4 + 1] + coef[i*4 + 2]; \
const int z2 = coef[i*4 + 0] - coef[i*4 + 3]; \
const int z3 = coef[i*4 + 1] - coef[i*4 + 2]; \
tmp[i + 4*0] = z0 + z1; \
tmp[i + 4*1] = 2*z2 + z3; \
tmp[i + 4*2] = z0 - z1; \
tmp[i + 4*3] = z2 - 2*z3; \
} \
for (i = 0; i < 4; i++) { \
const int z0 = tmp[i*4 + 0] + tmp[i*4 + 3]; \
const int z1 = tmp[i*4 + 1] + tmp[i*4 + 2]; \
const int z2 = tmp[i*4 + 0] - tmp[i*4 + 3]; \
const int z3 = tmp[i*4 + 1] - tmp[i*4 + 2]; \
coef[i*4 + 0] = z0 + z1; \
coef[i*4 + 1] = 2*z2 + z3; \
coef[i*4 + 2] = z0 - z1; \
coef[i*4 + 3] = z2 - 2*z3; \
} \
for (y = 0; y < 4; y++) { \
for (x = 0; x < 4; x++) { \
const int64_t scale[] = { 13107 * 10, 8066 * 13, 5243 * 16 }; \
const int idx = (y & 1) + (x & 1); \
coef[y*4 + x] = (coef[y*4 + x] * scale[idx] + (1 << 14)) >> 15; \
} \
} \
}
#define DCT8_1D(src, srcstride, dst, dststride) do { \
const int a0 = (src)[srcstride * 0] + (src)[srcstride * 7]; \
const int a1 = (src)[srcstride * 0] - (src)[srcstride * 7]; \
const int a2 = (src)[srcstride * 1] + (src)[srcstride * 6]; \
const int a3 = (src)[srcstride * 1] - (src)[srcstride * 6]; \
const int a4 = (src)[srcstride * 2] + (src)[srcstride * 5]; \
const int a5 = (src)[srcstride * 2] - (src)[srcstride * 5]; \
const int a6 = (src)[srcstride * 3] + (src)[srcstride * 4]; \
const int a7 = (src)[srcstride * 3] - (src)[srcstride * 4]; \
const int b0 = a0 + a6; \
const int b1 = a2 + a4; \
const int b2 = a0 - a6; \
const int b3 = a2 - a4; \
const int b4 = a3 + a5 + (a1 + (a1 >> 1)); \
const int b5 = a1 - a7 - (a5 + (a5 >> 1)); \
const int b6 = a1 + a7 - (a3 + (a3 >> 1)); \
const int b7 = a3 - a5 + (a7 + (a7 >> 1)); \
(dst)[dststride * 0] = b0 + b1; \
(dst)[dststride * 1] = b4 + (b7 >> 2); \
(dst)[dststride * 2] = b2 + (b3 >> 1); \
(dst)[dststride * 3] = b5 + (b6 >> 2); \
(dst)[dststride * 4] = b0 - b1; \
(dst)[dststride * 5] = b6 - (b5 >> 2); \
(dst)[dststride * 6] = (b2 >> 1) - b3; \
(dst)[dststride * 7] = (b4 >> 2) - b7; \
} while (0)
#define dct8x8_impl(size, dctcoef) \
static void dct8x8_##size(dctcoef *coef) \
{ \
int i, x, y; \
dctcoef tmp[64]; \
for (i = 0; i < 8; i++) \
DCT8_1D(coef + i, 8, tmp + i, 8); \
\
for (i = 0; i < 8; i++) \
DCT8_1D(tmp + 8*i, 1, coef + i, 8); \
\
for (y = 0; y < 8; y++) { \
for (x = 0; x < 8; x++) { \
static const int scale[] = { \
13107 * 20, 11428 * 18, 20972 * 32, \
12222 * 19, 16777 * 25, 15481 * 24, \
}; \
static const int idxmap[] = { \
0, 3, 4, 3, \
3, 1, 5, 1, \
4, 5, 2, 5, \
3, 1, 5, 1, \
}; \
const int idx = idxmap[(y & 3) * 4 + (x & 3)]; \
coef[y*8 + x] = ((int64_t)coef[y*8 + x] * \
scale[idx] + (1 << 17)) >> 18; \
} \
} \
}
dct4x4_impl(16, int16_t)
dct4x4_impl(32, int32_t)
dct8x8_impl(16, int16_t)
dct8x8_impl(32, int32_t)
static void dct4x4(int16_t *coef, int bit_depth)
{
if (bit_depth == 8)
dct4x4_16(coef);
else
dct4x4_32((int32_t *) coef);
}
static void dct8x8(int16_t *coef, int bit_depth)
{
if (bit_depth == 8) {
dct8x8_16(coef);
} else {
dct8x8_32((int32_t *) coef);
}
}
static void check_idct(void)
{
static const int depths[5] = { 8, 9, 10, 12, 14 };
LOCAL_ALIGNED_16(uint8_t, src, [8 * 8 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst, [8 * 8 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst0, [8 * 8 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst1_base, [8 * 8 * 2 + 32]);
LOCAL_ALIGNED_16(int16_t, coef, [8 * 8 * 2]);
LOCAL_ALIGNED_16(int16_t, subcoef0, [8 * 8 * 2]);
LOCAL_ALIGNED_16(int16_t, subcoef1, [8 * 8 * 2]);
H264DSPContext h;
int bit_depth, sz, align, dc, i;
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *block, int stride);
for (i = 0; i < FF_ARRAY_ELEMS(depths); i++) {
bit_depth = depths[i];
ff_h264dsp_init(&h, bit_depth, 1);
for (dc = 0; dc <= 2; dc++) {
for (sz = 4; sz <= 8; sz += 4) {
void (*idct)(uint8_t *, int16_t *, int) = NULL;
const char fmts[3][28] = {
"h264_idct%d_add_%dbpp", "h264_idct%d_dc_add_%dbpp",
"h264_add_pixels%d_%dbpp",
};
randomize_buffers(i);
if (sz == 4)
dct4x4(coef, bit_depth);
else
dct8x8(coef, bit_depth);
switch ((sz << 2) | dc) {
case (4 << 2) | 0: idct = h.h264_idct_add; break;
case (4 << 2) | 1: idct = h.h264_idct_dc_add; break;
case (4 << 2) | 2: idct = h.h264_add_pixels4_clear; break;
case (8 << 2) | 0: idct = h.h264_idct8_add; break;
case (8 << 2) | 1: idct = h.h264_idct8_dc_add; break;
case (8 << 2) | 2: idct = h.h264_add_pixels8_clear; break;
}
if (check_func(idct, fmts[dc], sz, bit_depth)) {
for (align = 0; align < 16; align += sz * SIZEOF_PIXEL) {
uint8_t *dst1 = dst1_base + align;
if (dc) {
memset(subcoef0, 0, sz * sz * SIZEOF_COEF);
memcpy(subcoef0, coef, SIZEOF_COEF);
} else {
memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
}
memcpy(dst0, dst, sz * PIXEL_STRIDE);
memcpy(dst1, dst, sz * PIXEL_STRIDE);
memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
call_ref(dst0, subcoef0, PIXEL_STRIDE);
call_new(dst1, subcoef1, PIXEL_STRIDE);
if (memcmp(dst0, dst1, sz * PIXEL_STRIDE) ||
memcmp(subcoef0, subcoef1, sz * sz * SIZEOF_COEF))
fail();
bench_new(dst1, subcoef1, sz * SIZEOF_PIXEL);
}
}
}
}
}
}
static void check_idct_multiple(void)
{
LOCAL_ALIGNED_16(uint8_t, dst_full, [16 * 16 * 2]);
LOCAL_ALIGNED_16(int16_t, coef_full, [16 * 16 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst0, [16 * 16 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst1, [16 * 16 * 2]);
LOCAL_ALIGNED_16(int16_t, coef0, [16 * 16 * 2]);
LOCAL_ALIGNED_16(int16_t, coef1, [16 * 16 * 2]);
LOCAL_ALIGNED_16(uint8_t, nnzc, [15 * 8]);
H264DSPContext h;
int bit_depth, i, y, func;
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const int *block_offset, int16_t *block, int stride, const uint8_t nnzc[15*8]);
for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
ff_h264dsp_init(&h, bit_depth, 1);
for (func = 0; func < 3; func++) {
void (*idct)(uint8_t *, const int *, int16_t *, int, const uint8_t[]) = NULL;
const char *name;
int sz = 4, intra = 0;
int block_offset[16] = { 0 };
switch (func) {
case 0:
idct = h.h264_idct_add16;
name = "h264_idct_add16";
break;
case 1:
idct = h.h264_idct_add16intra;
name = "h264_idct_add16intra";
intra = 1;
break;
case 2:
idct = h.h264_idct8_add4;
name = "h264_idct8_add4";
sz = 8;
break;
}
memset(nnzc, 0, 15 * 8);
memset(coef_full, 0, 16 * 16 * SIZEOF_COEF);
for (i = 0; i < 16 * 16; i += sz * sz) {
uint8_t src[8 * 8 * 2];
uint8_t dst[8 * 8 * 2];
int16_t coef[8 * 8 * 2];
int index = i / sz;
int block_y = (index / 16) * sz;
int block_x = index % 16;
int offset = (block_y * 16 + block_x) * SIZEOF_PIXEL;
int nnz = rnd() % 3;
randomize_buffers(bit_depth - 8);
if (sz == 4)
dct4x4(coef, bit_depth);
else
dct8x8(coef, bit_depth);
for (y = 0; y < sz; y++)
memcpy(&dst_full[offset + y * 16 * SIZEOF_PIXEL],
&dst[PIXEL_STRIDE * y], sz * SIZEOF_PIXEL);
if (nnz > 1)
nnz = sz * sz;
memcpy(&coef_full[i * SIZEOF_COEF/sizeof(coef[0])],
coef, nnz * SIZEOF_COEF);
if (intra && nnz == 1)
nnz = 0;
nnzc[scan8[i / 16]] = nnz;
block_offset[i / 16] = offset;
}
if (check_func(idct, "%s_%dbpp", name, bit_depth)) {
memcpy(coef0, coef_full, 16 * 16 * SIZEOF_COEF);
memcpy(coef1, coef_full, 16 * 16 * SIZEOF_COEF);
memcpy(dst0, dst_full, 16 * 16 * SIZEOF_PIXEL);
memcpy(dst1, dst_full, 16 * 16 * SIZEOF_PIXEL);
call_ref(dst0, block_offset, coef0, 16 * SIZEOF_PIXEL, nnzc);
call_new(dst1, block_offset, coef1, 16 * SIZEOF_PIXEL, nnzc);
if (memcmp(dst0, dst1, 16 * 16 * SIZEOF_PIXEL) ||
memcmp(coef0, coef1, 16 * 16 * SIZEOF_COEF))
fail();
bench_new(dst1, block_offset, coef1, 16 * SIZEOF_PIXEL, nnzc);
}
}
}
}
static void check_loop_filter(void)
{
LOCAL_ALIGNED_16(uint8_t, dst, [32 * 16 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 16 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 16 * 2]);
H264DSPContext h;
int bit_depth;
int alphas[36], betas[36];
int8_t tc0[36][4];
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *pix, ptrdiff_t stride,
int alpha, int beta, int8_t *tc0);
for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
int i, j, a, c;
uint32_t mask = pixel_mask_lf[bit_depth - 8];
ff_h264dsp_init(&h, bit_depth, 1);
for (i = 35, a = 255, c = 250; i >= 0; i--) {
alphas[i] = a << (bit_depth - 8);
betas[i] = (i + 1) / 2 << (bit_depth - 8);
tc0[i][0] = tc0[i][3] = (c + 6) / 10;
tc0[i][1] = (c + 7) / 15;
tc0[i][2] = (c + 9) / 20;
a = a*9/10;
c = c*9/10;
}
#define CHECK_LOOP_FILTER(name, align, idc) \
do { \
if (check_func(h.name, #name #idc "_%dbpp", bit_depth)) { \
for (j = 0; j < 36; j++) { \
intptr_t off = 8 * 32 + (j & 15) * 4 * !align; \
for (i = 0; i < 1024; i+=4) { \
AV_WN32A(dst + i, rnd() & mask); \
} \
memcpy(dst0, dst, 32 * 16 * 2); \
memcpy(dst1, dst, 32 * 16 * 2); \
\
call_ref(dst0 + off, 32, alphas[j], betas[j], tc0[j]); \
call_new(dst1 + off, 32, alphas[j], betas[j], tc0[j]); \
if (memcmp(dst0, dst1, 32 * 16 * SIZEOF_PIXEL)) { \
fprintf(stderr, #name #idc ": j:%d, alpha:%d beta:%d " \
"tc0:{%d,%d,%d,%d}\n", j, alphas[j], betas[j], \
tc0[j][0], tc0[j][1], tc0[j][2], tc0[j][3]); \
fail(); \
} \
bench_new(dst1 + off, 32, alphas[j], betas[j], tc0[j]);\
} \
} \
} while (0)
CHECK_LOOP_FILTER(h264_v_loop_filter_luma, 1,);
CHECK_LOOP_FILTER(h264_h_loop_filter_luma, 0,);
CHECK_LOOP_FILTER(h264_h_loop_filter_luma_mbaff, 0,);
CHECK_LOOP_FILTER(h264_v_loop_filter_chroma, 1,);
CHECK_LOOP_FILTER(h264_h_loop_filter_chroma, 0,);
CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_mbaff, 0,);
ff_h264dsp_init(&h, bit_depth, 2);
CHECK_LOOP_FILTER(h264_h_loop_filter_chroma, 0, 422);
CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_mbaff, 0, 422);
#undef CHECK_LOOP_FILTER
}
}
static void check_loop_filter_intra(void)
{
LOCAL_ALIGNED_16(uint8_t, dst, [32 * 16 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 16 * 2]);
LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 16 * 2]);
H264DSPContext h;
int bit_depth;
int alphas[36], betas[36];
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *pix, ptrdiff_t stride,
int alpha, int beta);
for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
int i, j, a;
uint32_t mask = pixel_mask_lf[bit_depth - 8];
ff_h264dsp_init(&h, bit_depth, 1);
for (i = 35, a = 255; i >= 0; i--) {
alphas[i] = a << (bit_depth - 8);
betas[i] = (i + 1) / 2 << (bit_depth - 8);
a = a*9/10;
}
#define CHECK_LOOP_FILTER(name, align, idc) \
do { \
if (check_func(h.name, #name #idc "_%dbpp", bit_depth)) { \
for (j = 0; j < 36; j++) { \
intptr_t off = 8 * 32 + (j & 15) * 4 * !align; \
for (i = 0; i < 1024; i+=4) { \
AV_WN32A(dst + i, rnd() & mask); \
} \
memcpy(dst0, dst, 32 * 16 * 2); \
memcpy(dst1, dst, 32 * 16 * 2); \
\
call_ref(dst0 + off, 32, alphas[j], betas[j]); \
call_new(dst1 + off, 32, alphas[j], betas[j]); \
if (memcmp(dst0, dst1, 32 * 16 * SIZEOF_PIXEL)) { \
fprintf(stderr, #name #idc ": j:%d, alpha:%d beta:%d\n", \
j, alphas[j], betas[j]); \
fail(); \
} \
bench_new(dst1 + off, 32, alphas[j], betas[j]); \
} \
} \
} while (0)
CHECK_LOOP_FILTER(h264_v_loop_filter_luma_intra, 1,);
CHECK_LOOP_FILTER(h264_h_loop_filter_luma_intra, 0,);
CHECK_LOOP_FILTER(h264_h_loop_filter_luma_mbaff_intra, 0,);
CHECK_LOOP_FILTER(h264_v_loop_filter_chroma_intra, 1,);
CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_intra, 0,);
CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_mbaff_intra, 0,);
ff_h264dsp_init(&h, bit_depth, 2);
CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_intra, 0, 422);
CHECK_LOOP_FILTER(h264_h_loop_filter_chroma_mbaff_intra, 0, 422);
#undef CHECK_LOOP_FILTER
}
}
void checkasm_check_h264dsp(void)
{
check_idct();
check_idct_multiple();
report("idct");
check_loop_filter();
report("loop_filter");
check_loop_filter_intra();
report("loop_filter_intra");
}
+261
View File
@@ -0,0 +1,261 @@
/*
* Copyright (c) 2015 Henrik Gramner
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/codec_id.h"
#include "libavcodec/h264pred.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
static const int codec_ids[4] = { AV_CODEC_ID_H264, AV_CODEC_ID_VP8, AV_CODEC_ID_RV40, AV_CODEC_ID_SVQ3 };
static const char * const pred4x4_modes[4][15] = {
{ /* H.264 */
[VERT_PRED ] = "vertical",
[HOR_PRED ] = "horizontal",
[DC_PRED ] = "dc",
[DIAG_DOWN_LEFT_PRED ] = "down_left",
[DIAG_DOWN_RIGHT_PRED] = "down_right",
[VERT_RIGHT_PRED ] = "vertical_right",
[HOR_DOWN_PRED ] = "horizontal_right",
[VERT_LEFT_PRED ] = "vertical_left",
[HOR_UP_PRED ] = "horizontal_up",
[LEFT_DC_PRED ] = "left_dc",
[TOP_DC_PRED ] = "top_dc",
[DC_128_PRED ] = "dc_128",
},
{ /* VP8 */
[VERT_PRED ] = "vertical_vp8",
[HOR_PRED ] = "horizontal_vp8",
[VERT_LEFT_PRED] = "vertical_left_vp8",
[TM_VP8_PRED ] = "tm_vp8",
[DC_127_PRED ] = "dc_127_vp8",
[DC_129_PRED ] = "dc_129_vp8",
},
{ /* RV40 */
[DIAG_DOWN_LEFT_PRED ] = "down_left_rv40",
[VERT_LEFT_PRED ] = "vertical_left_rv40",
[HOR_UP_PRED ] = "horizontal_up_rv40",
[DIAG_DOWN_LEFT_PRED_RV40_NODOWN] = "down_left_nodown_rv40",
[HOR_UP_PRED_RV40_NODOWN ] = "horizontal_up_nodown_rv40",
[VERT_LEFT_PRED_RV40_NODOWN ] = "vertical_left_nodown_rv40",
},
{ /* SVQ3 */
[DIAG_DOWN_LEFT_PRED] = "down_left_svq3",
},
};
static const char * const pred8x8_modes[4][11] = {
{ /* H.264 */
[DC_PRED8x8 ] = "dc",
[HOR_PRED8x8 ] = "horizontal",
[VERT_PRED8x8 ] = "vertical",
[PLANE_PRED8x8 ] = "plane",
[LEFT_DC_PRED8x8 ] = "left_dc",
[TOP_DC_PRED8x8 ] = "top_dc",
[DC_128_PRED8x8 ] = "dc_128",
[ALZHEIMER_DC_L0T_PRED8x8] = "mad_cow_dc_l0t",
[ALZHEIMER_DC_0LT_PRED8x8] = "mad_cow_dc_0lt",
[ALZHEIMER_DC_L00_PRED8x8] = "mad_cow_dc_l00",
[ALZHEIMER_DC_0L0_PRED8x8] = "mad_cow_dc_0l0",
},
{ /* VP8 */
[PLANE_PRED8x8 ] = "tm_vp8",
[DC_127_PRED8x8] = "dc_127_vp8",
[DC_129_PRED8x8] = "dc_129_vp8",
},
{ /* RV40 */
[DC_PRED8x8 ] = "dc_rv40",
[LEFT_DC_PRED8x8] = "left_dc_rv40",
[TOP_DC_PRED8x8 ] = "top_dc_rv40",
},
/* nothing for SVQ3 */
};
static const char * const pred16x16_modes[4][9] = {
{ /* H.264 */
[DC_PRED8x8 ] = "dc",
[HOR_PRED8x8 ] = "horizontal",
[VERT_PRED8x8 ] = "vertical",
[PLANE_PRED8x8 ] = "plane",
[LEFT_DC_PRED8x8] = "left_dc",
[TOP_DC_PRED8x8 ] = "top_dc",
[DC_128_PRED8x8 ] = "dc_128",
},
{ /* VP8 */
[PLANE_PRED8x8 ] = "tm_vp8",
[DC_127_PRED8x8] = "dc_127_vp8",
[DC_129_PRED8x8] = "dc_129_vp8",
},
{ /* RV40 */
[PLANE_PRED8x8] = "plane_rv40",
},
{ /* SVQ3 */
[PLANE_PRED8x8] = "plane_svq3",
},
};
static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define BUF_SIZE (3 * 16 * 17)
#define check_pred_func(func, name, mode_name) \
(mode_name && ((codec_ids[codec] == AV_CODEC_ID_H264) ? \
check_func(func, "pred%s_%s_%d", name, mode_name, bit_depth) : \
check_func(func, "pred%s_%s", name, mode_name)))
#define randomize_buffers() \
do { \
uint32_t mask = pixel_mask[bit_depth - 8]; \
int i; \
for (i = 0; i < BUF_SIZE; i += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf0 + i, r); \
AV_WN32A(buf1 + i, r); \
} \
} while (0)
#define src0 (buf0 + 4 * 16) /* Offset to allow room for top and left */
#define src1 (buf1 + 4 * 16)
static void check_pred4x4(H264PredContext *h, uint8_t *buf0, uint8_t *buf1,
int codec, int chroma_format, int bit_depth)
{
if (chroma_format == 1) {
uint8_t *topright = buf0 + 2*16;
int pred_mode;
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *src, const uint8_t *topright, ptrdiff_t stride);
for (pred_mode = 0; pred_mode < 15; pred_mode++) {
if (check_pred_func(h->pred4x4[pred_mode], "4x4", pred4x4_modes[codec][pred_mode])) {
randomize_buffers();
call_ref(src0, topright, 12*SIZEOF_PIXEL);
call_new(src1, topright, 12*SIZEOF_PIXEL);
if (memcmp(buf0, buf1, BUF_SIZE))
fail();
bench_new(src1, topright, 12*SIZEOF_PIXEL);
}
}
}
}
static void check_pred8x8(H264PredContext *h, uint8_t *buf0, uint8_t *buf1,
int codec, int chroma_format, int bit_depth)
{
int pred_mode;
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *src, ptrdiff_t stride);
for (pred_mode = 0; pred_mode < 11; pred_mode++) {
if (check_pred_func(h->pred8x8[pred_mode], (chroma_format == 2) ? "8x16" : "8x8",
pred8x8_modes[codec][pred_mode])) {
randomize_buffers();
call_ref(src0, 24*SIZEOF_PIXEL);
call_new(src1, 24*SIZEOF_PIXEL);
if (memcmp(buf0, buf1, BUF_SIZE))
fail();
bench_new(src1, 24*SIZEOF_PIXEL);
}
}
}
static void check_pred16x16(H264PredContext *h, uint8_t *buf0, uint8_t *buf1,
int codec, int chroma_format, int bit_depth)
{
if (chroma_format == 1) {
int pred_mode;
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *src, ptrdiff_t stride);
for (pred_mode = 0; pred_mode < 9; pred_mode++) {
if (check_pred_func(h->pred16x16[pred_mode], "16x16", pred16x16_modes[codec][pred_mode])) {
randomize_buffers();
call_ref(src0, 48);
call_new(src1, 48);
if (memcmp(buf0, buf1, BUF_SIZE))
fail();
bench_new(src1, 48);
}
}
}
}
static void check_pred8x8l(H264PredContext *h, uint8_t *buf0, uint8_t *buf1,
int codec, int chroma_format, int bit_depth)
{
if (chroma_format == 1 && codec_ids[codec] == AV_CODEC_ID_H264) {
int pred_mode;
declare_func_emms(AV_CPU_FLAG_MMXEXT, void, uint8_t *src, int topleft, int topright, ptrdiff_t stride);
for (pred_mode = 0; pred_mode < 12; pred_mode++) {
if (check_pred_func(h->pred8x8l[pred_mode], "8x8l", pred4x4_modes[codec][pred_mode])) {
int neighbors;
for (neighbors = 0; neighbors <= 0xc000; neighbors += 0x4000) {
int has_topleft = neighbors & 0x8000;
int has_topright = neighbors & 0x4000;
if ((pred_mode == DIAG_DOWN_RIGHT_PRED || pred_mode == VERT_RIGHT_PRED) && !has_topleft)
continue; /* Those aren't allowed according to the spec */
randomize_buffers();
call_ref(src0, has_topleft, has_topright, 24*SIZEOF_PIXEL);
call_new(src1, has_topleft, has_topright, 24*SIZEOF_PIXEL);
if (memcmp(buf0, buf1, BUF_SIZE))
fail();
bench_new(src1, has_topleft, has_topright, 24*SIZEOF_PIXEL);
}
}
}
}
}
/* TODO: Add tests for H.264 lossless H/V prediction */
void checkasm_check_h264pred(void)
{
static const struct {
void (*func)(H264PredContext*, uint8_t*, uint8_t*, int, int, int);
const char *name;
} tests[] = {
{ check_pred4x4, "pred4x4" },
{ check_pred8x8, "pred8x8" },
{ check_pred16x16, "pred16x16" },
{ check_pred8x8l, "pred8x8l" },
};
LOCAL_ALIGNED_16(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, buf1, [BUF_SIZE]);
H264PredContext h;
int test, codec, chroma_format, bit_depth;
for (test = 0; test < FF_ARRAY_ELEMS(tests); test++) {
for (codec = 0; codec < 4; codec++) {
int codec_id = codec_ids[codec];
for (bit_depth = 8; bit_depth <= (codec_id == AV_CODEC_ID_H264 ? 10 : 8); bit_depth++)
for (chroma_format = 1; chroma_format <= (codec_id == AV_CODEC_ID_H264 ? 2 : 1); chroma_format++) {
ff_h264_pred_init(&h, codec_id, bit_depth, chroma_format);
tests[test].func(&h, buf0, buf1, codec, chroma_format, bit_depth);
}
}
report("%s", tests[test].name);
}
}
+82
View File
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2015 Henrik Gramner
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/h264qpel.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define BUF_SIZE (2 * 16 * (16 + 3 + 4))
#define randomize_buffers() \
do { \
uint32_t mask = pixel_mask[bit_depth - 8]; \
int k; \
for (k = 0; k < BUF_SIZE; k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf0 + k, r); \
AV_WN32A(buf1 + k, r); \
r = rnd(); \
AV_WN32A(dst0 + k, r); \
AV_WN32A(dst1 + k, r); \
} \
} while (0)
#define src0 (buf0 + 3 * 2 * 16) /* h264qpel functions read data from negative src pointer offsets */
#define src1 (buf1 + 3 * 2 * 16)
void checkasm_check_h264qpel(void)
{
LOCAL_ALIGNED_16(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, buf1, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE]);
H264QpelContext h;
int op, bit_depth, i, j;
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, const uint8_t *src, ptrdiff_t stride);
for (op = 0; op < 2; op++) {
qpel_mc_func (*tab)[16] = op ? h.avg_h264_qpel_pixels_tab : h.put_h264_qpel_pixels_tab;
const char *op_name = op ? "avg" : "put";
for (bit_depth = 8; bit_depth <= 10; bit_depth++) {
ff_h264qpel_init(&h, bit_depth);
for (i = 0; i < (op ? 3 : 4); i++) {
int size = 16 >> i;
for (j = 0; j < 16; j++)
if (check_func(tab[i][j], "%s_h264_qpel_%d_mc%d%d_%d", op_name, size, j & 3, j >> 2, bit_depth)) {
randomize_buffers();
call_ref(dst0, src0, size * SIZEOF_PIXEL);
call_new(dst1, src1, size * SIZEOF_PIXEL);
if (memcmp(buf0, buf1, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE))
fail();
bench_new(dst1, src1, size * SIZEOF_PIXEL);
}
}
}
report("%s", op_name);
}
}
+98
View File
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2016 Alexandra Hájková
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/hevc/dsp.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
int j; \
for (j = 0; j < size; j++) { \
int16_t r = rnd(); \
AV_WN16A(buf + j, r >> 3); \
} \
} while (0)
#define randomize_buffers2(buf, size, mask) \
do { \
int j; \
for (j = 0; j < size; j++) \
AV_WN16A(buf + j * 2, rnd() & mask); \
} while (0)
static void compare_add_res(int size, ptrdiff_t stride, int overflow_test, int mask)
{
LOCAL_ALIGNED_32(int16_t, res0, [32 * 32]);
LOCAL_ALIGNED_32(int16_t, res1, [32 * 32]);
LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const int16_t *res, ptrdiff_t stride);
randomize_buffers(res0, size);
randomize_buffers2(dst0, size, mask);
if (overflow_test)
res0[0] = 0x8000;
memcpy(res1, res0, sizeof(*res0) * size);
memcpy(dst1, dst0, sizeof(int16_t) * size);
call_ref(dst0, res0, stride);
call_new(dst1, res1, stride);
if (memcmp(dst0, dst1, size))
fail();
bench_new(dst1, res1, stride);
}
static void check_add_res(HEVCDSPContext *h, int bit_depth)
{
int i;
int mask = bit_depth == 8 ? 0xFFFF : bit_depth == 10 ? 0x03FF : 0x07FF;
for (i = 2; i <= 5; i++) {
int block_size = 1 << i;
int size = block_size * block_size;
ptrdiff_t stride = block_size << (bit_depth > 8);
if (check_func(h->add_residual[i - 2], "hevc_add_res_%dx%d_%d", block_size, block_size, bit_depth)) {
compare_add_res(size, stride, 0, mask);
// overflow test for res = -32768
compare_add_res(size, stride, 1, mask);
}
}
}
void checkasm_check_hevc_add_res(void)
{
int bit_depth;
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
HEVCDSPContext h;
ff_hevc_dsp_init(&h, bit_depth);
check_add_res(&h, bit_depth);
}
report("add_residual");
}
+288
View File
@@ -0,0 +1,288 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/macros.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/hevc/dsp.h"
#include "checkasm.h"
static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define BUF_STRIDE (16 * 2)
#define BUF_LINES (16)
// large buffer sizes based on high bit depth
#define BUF_OFFSET (2 * BUF_STRIDE * BUF_LINES)
#define BUF_SIZE (2 * BUF_STRIDE * BUF_LINES + BUF_OFFSET * 2)
#define randomize_buffers(buf0, buf1, size) \
do { \
uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
int k; \
for (k = 0; k < size; k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf0 + k, r); \
AV_WN32A(buf1 + k, r); \
} \
} while (0)
static void check_deblock_chroma(HEVCDSPContext *h, int bit_depth, int c)
{
// see tctable[] in hevc_filter.c, we check full range
int32_t tc[2] = { rnd() % 25, rnd() % 25 };
// no_p, no_q can only be { 0,0 } for the simpler assembly (non *_c
// variant) functions, see deblocking_filter_CTB() in hevc_filter.c
uint8_t no_p[2] = { rnd() & c, rnd() & c };
uint8_t no_q[2] = { rnd() & c, rnd() & c };
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE]);
declare_func(void, uint8_t *pix, ptrdiff_t stride,
const int32_t *tc, const uint8_t *no_p, const uint8_t *no_q);
if (check_func(c ? h->hevc_h_loop_filter_chroma_c : h->hevc_h_loop_filter_chroma,
"hevc_h_loop_filter_chroma%d%s", bit_depth, c ? "_full" : ""))
{
randomize_buffers(buf0, buf1, BUF_SIZE);
call_ref(buf0 + BUF_OFFSET, BUF_STRIDE, tc, no_p, no_q);
call_new(buf1 + BUF_OFFSET, BUF_STRIDE, tc, no_p, no_q);
if (memcmp(buf0, buf1, BUF_SIZE))
fail();
bench_new(buf1 + BUF_OFFSET, BUF_STRIDE, tc, no_p, no_q);
}
if (check_func(c ? h->hevc_v_loop_filter_chroma_c : h->hevc_v_loop_filter_chroma,
"hevc_v_loop_filter_chroma%d%s", bit_depth, c ? "_full" : ""))
{
randomize_buffers(buf0, buf1, BUF_SIZE);
call_ref(buf0 + BUF_OFFSET, BUF_STRIDE, tc, no_p, no_q);
call_new(buf1 + BUF_OFFSET, BUF_STRIDE, tc, no_p, no_q);
if (memcmp(buf0, buf1, BUF_SIZE))
fail();
bench_new(buf1 + BUF_OFFSET, BUF_STRIDE, tc, no_p, no_q);
}
}
#define P3 buf[-4 * xstride]
#define P2 buf[-3 * xstride]
#define P1 buf[-2 * xstride]
#define P0 buf[-1 * xstride]
#define Q0 buf[0 * xstride]
#define Q1 buf[1 * xstride]
#define Q2 buf[2 * xstride]
#define Q3 buf[3 * xstride]
#define TC25(x) ((tc[x] * 5 + 1) >> 1)
#define MASK(x) (uint16_t)(x & ((1 << (bit_depth)) - 1))
#define GET(x) ((SIZEOF_PIXEL == 1) ? *(uint8_t*)(&x) : *(uint16_t*)(&x))
#define SET(x, y) do { \
uint16_t z = MASK(y); \
if (SIZEOF_PIXEL == 1) \
*(uint8_t*)(&x) = z; \
else \
*(uint16_t*)(&x) = z; \
} while (0)
#define RANDCLIP(x, diff) av_clip(GET(x) - (diff), 0, \
(1 << (bit_depth)) - 1) + rnd() % FFMAX(2 * (diff), 1)
// NOTE: this function doesn't work 'correctly' in that it won't always choose
// strong/strong or weak/weak, in most cases it tends to but will sometimes mix
// weak/strong or even skip sometimes. This is more useful to test correctness
// for these functions, though it does make benching them difficult. The easiest
// way to bench these functions is to check an overall decode since there are too
// many paths and ways to trigger the deblock: we would have to bench all
// permutations of weak/strong/skip/nd_q/nd_p/no_q/no_p and it quickly becomes
// too much.
static void randomize_luma_buffers(int type, int *beta, int32_t tc[2],
uint8_t *buf, ptrdiff_t xstride, ptrdiff_t ystride, int bit_depth)
{
int i, j, b3, tc25, tc25diff, b3diff;
// both tc & beta are unscaled inputs
// minimum useful value is 1, full range 0-24
tc[0] = (rnd() % 25) + 1;
tc[1] = (rnd() % 25) + 1;
// minimum useful value for 8bit is 8
*beta = (rnd() % 57) + 8;
switch (type) {
case 0: // strong
for (j = 0; j < 2; j++) {
tc25 = TC25(j) << (bit_depth - 8);
tc25diff = FFMAX(tc25 - 1, 0);
// 4 lines per tc
for (i = 0; i < 4; i++) {
b3 = (*beta << (bit_depth - 8)) >> 3;
SET(P0, rnd() % (1 << bit_depth));
SET(Q0, RANDCLIP(P0, tc25diff));
// p3 - p0 up to beta3 budget
b3diff = rnd() % b3;
SET(P3, RANDCLIP(P0, b3diff));
// q3 - q0, reduced budget
b3diff = rnd() % FFMAX(b3 - b3diff, 1);
SET(Q3, RANDCLIP(Q0, b3diff));
// same concept, budget across 4 pixels
b3 -= b3diff = rnd() % FFMAX(b3, 1);
SET(P2, RANDCLIP(P0, b3diff));
b3 -= b3diff = rnd() % FFMAX(b3, 1);
SET(Q2, RANDCLIP(Q0, b3diff));
// extra reduced budget for weighted pixels
b3 -= b3diff = rnd() % FFMAX(b3 - (1 << (bit_depth - 8)), 1);
SET(P1, RANDCLIP(P0, b3diff));
b3 -= b3diff = rnd() % FFMAX(b3 - (1 << (bit_depth - 8)), 1);
SET(Q1, RANDCLIP(Q0, b3diff));
buf += ystride;
}
}
break;
case 1: // weak
for (j = 0; j < 2; j++) {
tc25 = TC25(j) << (bit_depth - 8);
tc25diff = FFMAX(tc25 - 1, 0);
// 4 lines per tc
for (i = 0; i < 4; i++) {
// Weak filtering is signficantly simpler to activate as
// we only need to satisfy d0 + d3 < beta, which
// can be simplified to d0 + d0 < beta. Using the above
// derivations but substiuting b3 for b1 and ensuring
// that P0/Q0 are at least 1/2 tc25diff apart (tending
// towards 1/2 range).
b3 = (*beta << (bit_depth - 8)) >> 1;
SET(P0, rnd() % (1 << bit_depth));
SET(Q0, RANDCLIP(P0, tc25diff >> 1) +
(tc25diff >> 1) * (P0 < (1 << (bit_depth - 1))) ? 1 : -1);
// p3 - p0 up to beta3 budget
b3diff = rnd() % b3;
SET(P3, RANDCLIP(P0, b3diff));
// q3 - q0, reduced budget
b3diff = rnd() % FFMAX(b3 - b3diff, 1);
SET(Q3, RANDCLIP(Q0, b3diff));
// same concept, budget across 4 pixels
b3 -= b3diff = rnd() % FFMAX(b3, 1);
SET(P2, RANDCLIP(P0, b3diff));
b3 -= b3diff = rnd() % FFMAX(b3, 1);
SET(Q2, RANDCLIP(Q0, b3diff));
// extra reduced budget for weighted pixels
b3 -= b3diff = rnd() % FFMAX(b3 - (1 << (bit_depth - 8)), 1);
SET(P1, RANDCLIP(P0, b3diff));
b3 -= b3diff = rnd() % FFMAX(b3 - (1 << (bit_depth - 8)), 1);
SET(Q1, RANDCLIP(Q0, b3diff));
buf += ystride;
}
}
break;
case 2: // none
*beta = 0; // ensure skip
for (i = 0; i < 8; i++) {
// we can just fill with completely random data, nothing should be touched.
SET(P3, rnd()); SET(P2, rnd()); SET(P1, rnd()); SET(P0, rnd());
SET(Q0, rnd()); SET(Q1, rnd()); SET(Q2, rnd()); SET(Q3, rnd());
buf += ystride;
}
break;
}
}
static void check_deblock_luma(HEVCDSPContext *h, int bit_depth, int c)
{
const char *type;
const char *types[3] = { "strong", "weak", "skip" };
int beta;
int32_t tc[2] = {0};
uint8_t no_p[2] = { rnd() & c, rnd() & c };
uint8_t no_q[2] = { rnd() & c, rnd() & c };
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE]);
uint8_t *ptr0 = buf0 + BUF_OFFSET,
*ptr1 = buf1 + BUF_OFFSET;
declare_func(void, uint8_t *pix, ptrdiff_t stride, int beta,
const int32_t *tc, const uint8_t *no_p, const uint8_t *no_q);
memset(buf0, 0, BUF_SIZE);
for (int j = 0; j < 3; j++) {
type = types[j];
if (check_func(c ? h->hevc_h_loop_filter_luma_c : h->hevc_h_loop_filter_luma,
"hevc_h_loop_filter_luma%d_%s%s", bit_depth, type, c ? "_full" : ""))
{
randomize_luma_buffers(j, &beta, tc, buf0 + BUF_OFFSET, 16 * SIZEOF_PIXEL, SIZEOF_PIXEL, bit_depth);
memcpy(buf1, buf0, BUF_SIZE);
call_ref(ptr0, 16 * SIZEOF_PIXEL, beta, tc, no_p, no_q);
call_new(ptr1, 16 * SIZEOF_PIXEL, beta, tc, no_p, no_q);
if (memcmp(buf0, buf1, BUF_SIZE))
fail();
bench_new(ptr1, 16 * SIZEOF_PIXEL, beta, tc, no_p, no_q);
}
if (check_func(c ? h->hevc_v_loop_filter_luma_c : h->hevc_v_loop_filter_luma,
"hevc_v_loop_filter_luma%d_%s%s", bit_depth, type, c ? "_full" : ""))
{
randomize_luma_buffers(j, &beta, tc, buf0 + BUF_OFFSET, SIZEOF_PIXEL, 16 * SIZEOF_PIXEL, bit_depth);
memcpy(buf1, buf0, BUF_SIZE);
call_ref(ptr0, 16 * SIZEOF_PIXEL, beta, tc, no_p, no_q);
call_new(ptr1, 16 * SIZEOF_PIXEL, beta, tc, no_p, no_q);
if (memcmp(buf0, buf1, BUF_SIZE))
fail();
bench_new(ptr1, 16 * SIZEOF_PIXEL, beta, tc, no_p, no_q);
}
}
}
void checkasm_check_hevc_deblock(void)
{
HEVCDSPContext h;
int bit_depth;
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_hevc_dsp_init(&h, bit_depth);
check_deblock_chroma(&h, bit_depth, 0);
}
report("chroma");
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_hevc_dsp_init(&h, bit_depth);
check_deblock_chroma(&h, bit_depth, 1);
}
report("chroma_full");
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_hevc_dsp_init(&h, bit_depth);
check_deblock_luma(&h, bit_depth, 0);
}
report("luma");
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_hevc_dsp_init(&h, bit_depth);
check_deblock_luma(&h, bit_depth, 1);
}
report("luma_full");
}
+135
View File
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2016 Alexandra Hájková
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/hevc/dsp.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
int j; \
for (j = 0; j < size; j++) { \
int16_t r = rnd(); \
AV_WN16A(buf + j, r); \
} \
} while (0)
static void check_idct(HEVCDSPContext *h, int bit_depth)
{
int i;
LOCAL_ALIGNED(32, int16_t, coeffs0, [32 * 32]);
LOCAL_ALIGNED(32, int16_t, coeffs1, [32 * 32]);
for (i = 2; i <= 5; i++) {
int block_size = 1 << i;
int size = block_size * block_size;
int col_limit = block_size;
declare_func(void, int16_t *coeffs, int col_limit);
randomize_buffers(coeffs0, size);
memcpy(coeffs1, coeffs0, sizeof(*coeffs0) * size);
if (check_func(h->idct[i - 2], "hevc_idct_%dx%d_%d", block_size, block_size, bit_depth)) {
call_ref(coeffs0, col_limit);
call_new(coeffs1, col_limit);
if (memcmp(coeffs0, coeffs1, sizeof(*coeffs0) * size))
fail();
bench_new(coeffs1, col_limit);
}
}
}
static void check_idct_dc(HEVCDSPContext *h, int bit_depth)
{
int i;
LOCAL_ALIGNED(32, int16_t, coeffs0, [32 * 32]);
LOCAL_ALIGNED(32, int16_t, coeffs1, [32 * 32]);
for (i = 2; i <= 5; i++) {
int block_size = 1 << i;
int size = block_size * block_size;
declare_func_emms(AV_CPU_FLAG_MMXEXT, void, int16_t *coeffs);
randomize_buffers(coeffs0, size);
memcpy(coeffs1, coeffs0, sizeof(*coeffs0) * size);
if (check_func(h->idct_dc[i - 2], "hevc_idct_%dx%d_dc_%d", block_size, block_size, bit_depth)) {
call_ref(coeffs0);
call_new(coeffs1);
if (memcmp(coeffs0, coeffs1, sizeof(*coeffs0) * size))
fail();
bench_new(coeffs1);
}
}
}
static void check_transform_luma(HEVCDSPContext *h, int bit_depth)
{
LOCAL_ALIGNED(32, int16_t, coeffs0, [32 * 32]);
LOCAL_ALIGNED(32, int16_t, coeffs1, [32 * 32]);
int block_size = 4;
int size = block_size * block_size;
declare_func(void, int16_t *coeffs);
randomize_buffers(coeffs0, size);
memcpy(coeffs1, coeffs0, sizeof(*coeffs0) * size);
if (check_func(h->transform_4x4_luma, "hevc_transform_luma_4x4_%d", bit_depth)) {
call_ref(coeffs0);
call_new(coeffs1);
if (memcmp(coeffs0, coeffs1, sizeof(*coeffs0) * size))
fail();
bench_new(coeffs1);
}
}
void checkasm_check_hevc_idct(void)
{
int bit_depth;
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
HEVCDSPContext h;
ff_hevc_dsp_init(&h, bit_depth);
check_idct_dc(&h, bit_depth);
}
report("idct_dc");
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
HEVCDSPContext h;
ff_hevc_dsp_init(&h, bit_depth);
check_idct(&h, bit_depth);
}
report("idct");
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
HEVCDSPContext h;
ff_hevc_dsp_init(&h, bit_depth);
check_transform_luma(&h, bit_depth);
}
report("transform_luma");
}
+619
View File
@@ -0,0 +1,619 @@
/*
* Copyright (c) 2015 Henrik Gramner
* Copyright (c) 2021 Josh Dekker
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/hevc/dsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
static const uint32_t pixel_mask[] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff, 0x07ff07ff, 0x0fff0fff };
static const uint32_t pixel_mask16[] = { 0x00ff00ff, 0x01ff01ff, 0x03ff03ff, 0x07ff07ff, 0x0fff0fff };
static const int sizes[] = { -1, 4, 6, 8, 12, 16, 24, 32, 48, 64 };
static const int weights[] = { 0, 128, 255, -1 };
static const int denoms[] = {0, 7, 12, -1 };
static const int offsets[] = {0, 255, -1 };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define BUF_SIZE (2 * MAX_PB_SIZE * (2 * 4 + MAX_PB_SIZE))
#define checkasm_check_pixel(buf1, stride1, buf2, stride2, ...) \
((bit_depth > 8) ? \
checkasm_check(uint16_t, (const uint16_t*)buf1, stride1, \
(const uint16_t*)buf2, stride2, \
__VA_ARGS__) : \
checkasm_check(uint8_t, (const uint8_t*) buf1, stride1, \
(const uint8_t*) buf2, stride2, \
__VA_ARGS__))
#define randomize_buffers() \
do { \
uint32_t mask = pixel_mask[bit_depth - 8]; \
int k; \
for (k = 0; k < BUF_SIZE + SRC_EXTRA; k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf0 + k, r); \
AV_WN32A(buf1 + k, r); \
if (k >= BUF_SIZE) \
continue; \
r = rnd(); \
AV_WN32A(dst0 + k, r); \
AV_WN32A(dst1 + k, r); \
} \
} while (0)
#define randomize_buffers_ref() \
randomize_buffers(); \
do { \
uint32_t mask = pixel_mask16[bit_depth - 8]; \
int k; \
for (k = 0; k < BUF_SIZE; k += 2) { \
uint32_t r = rnd() & mask; \
AV_WN32A(ref0 + k, r); \
AV_WN32A(ref1 + k, r); \
} \
} while (0)
#define src0 (buf0 + 2 * 4 * MAX_PB_SIZE) /* hevc qpel functions read data from negative src pointer offsets */
#define src1 (buf1 + 2 * 4 * MAX_PB_SIZE)
/* FIXME: Does the need for SRC_EXTRA for these tests indicate a bug? */
#define SRC_EXTRA 8
static void checkasm_check_hevc_qpel(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
declare_func(void, int16_t *dst, const uint8_t *src, ptrdiff_t srcstride,
int height, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_pixels"; break; // 0 0
case 1: type = "qpel_h"; break; // 0 1
case 2: type = "qpel_v"; break; // 1 0
case 3: type = "qpel_hv"; break; // 1 1
}
if (check_func(h.put_hevc_qpel[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
int16_t *dstw0 = (int16_t *) dst0, *dstw1 = (int16_t *) dst1;
randomize_buffers();
call_ref(dstw0, src0, sizes[size] * SIZEOF_PIXEL, sizes[size], i, j, sizes[size]);
call_new(dstw1, src1, sizes[size] * SIZEOF_PIXEL, sizes[size], i, j, sizes[size]);
checkasm_check(int16_t, dstw0, MAX_PB_SIZE * sizeof(int16_t),
dstw1, MAX_PB_SIZE * sizeof(int16_t),
size[sizes], size[sizes], "dst");
bench_new(dstw1, src1, sizes[size] * SIZEOF_PIXEL, sizes[size], i, j, sizes[size]);
}
}
}
}
}
report("qpel");
}
static void checkasm_check_hevc_qpel_uni(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
declare_func(void, uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride,
int height, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_uni_pixels"; break; // 0 0
case 1: type = "qpel_uni_h"; break; // 0 1
case 2: type = "qpel_uni_v"; break; // 1 0
case 3: type = "qpel_uni_hv"; break; // 1 1
}
if (check_func(h.put_hevc_qpel_uni[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
randomize_buffers();
call_ref(dst0, sizes[size] * SIZEOF_PIXEL,
src0, sizes[size] * SIZEOF_PIXEL,
sizes[size], i, j, sizes[size]);
call_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
sizes[size], i, j, sizes[size]);
checkasm_check_pixel(dst0, sizes[size] * SIZEOF_PIXEL,
dst1, sizes[size] * SIZEOF_PIXEL,
size[sizes], size[sizes], "dst");
bench_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
sizes[size], i, j, sizes[size]);
}
}
}
}
}
report("qpel_uni");
}
static void checkasm_check_hevc_qpel_uni_w(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
const int *denom, *wx, *ox;
declare_func(void, uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride,
int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_uni_w_pixels"; break; // 0 0
case 1: type = "qpel_uni_w_h"; break; // 0 1
case 2: type = "qpel_uni_w_v"; break; // 1 0
case 3: type = "qpel_uni_w_hv"; break; // 1 1
}
if (check_func(h.put_hevc_qpel_uni_w[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
for (denom = denoms; *denom >= 0; denom++) {
for (wx = weights; *wx >= 0; wx++) {
for (ox = offsets; *ox >= 0; ox++) {
randomize_buffers();
call_ref(dst0, sizes[size] * SIZEOF_PIXEL,
src0, sizes[size] * SIZEOF_PIXEL,
sizes[size], *denom, *wx, *ox, i, j, sizes[size]);
call_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
sizes[size], *denom, *wx, *ox, i, j, sizes[size]);
checkasm_check_pixel(dst0, sizes[size] * SIZEOF_PIXEL,
dst1, sizes[size] * SIZEOF_PIXEL,
size[sizes], size[sizes], "dst");
bench_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
sizes[size], *denom, *wx, *ox, i, j, sizes[size]);
}
}
}
}
}
}
}
}
report("qpel_uni_w");
}
static void checkasm_check_hevc_qpel_bi(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, ref0, [BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, ref1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
declare_func(void, uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride,
const int16_t *src2,
int height, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_bi_pixels"; break; // 0 0
case 1: type = "qpel_bi_h"; break; // 0 1
case 2: type = "qpel_bi_v"; break; // 1 0
case 3: type = "qpel_bi_hv"; break; // 1 1
}
if (check_func(h.put_hevc_qpel_bi[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
randomize_buffers_ref();
call_ref(dst0, sizes[size] * SIZEOF_PIXEL,
src0, sizes[size] * SIZEOF_PIXEL,
ref0, sizes[size], i, j, sizes[size]);
call_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
ref1, sizes[size], i, j, sizes[size]);
checkasm_check_pixel(dst0, sizes[size] * SIZEOF_PIXEL,
dst1, sizes[size] * SIZEOF_PIXEL,
size[sizes], size[sizes], "dst");
bench_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
ref1, sizes[size], i, j, sizes[size]);
}
}
}
}
}
report("qpel_bi");
}
static void checkasm_check_hevc_qpel_bi_w(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE + SRC_EXTRA]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, ref0, [BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, ref1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
const int *denom, *wx, *ox;
declare_func(void, uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride,
const int16_t *src2,
int height, int denom, int wx0, int wx1,
int ox0, int ox1, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_bi_w_pixels"; break; // 0 0
case 1: type = "qpel_bi_w_h"; break; // 0 1
case 2: type = "qpel_bi_w_v"; break; // 1 0
case 3: type = "qpel_bi_w_hv"; break; // 1 1
}
if (check_func(h.put_hevc_qpel_bi_w[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
for (denom = denoms; *denom >= 0; denom++) {
for (wx = weights; *wx >= 0; wx++) {
for (ox = offsets; *ox >= 0; ox++) {
randomize_buffers_ref();
call_ref(dst0, sizes[size] * SIZEOF_PIXEL,
src0, sizes[size] * SIZEOF_PIXEL,
ref0, sizes[size], *denom, *wx, *wx, *ox, *ox, i, j, sizes[size]);
call_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
ref1, sizes[size], *denom, *wx, *wx, *ox, *ox, i, j, sizes[size]);
checkasm_check_pixel(dst0, sizes[size] * SIZEOF_PIXEL,
dst1, sizes[size] * SIZEOF_PIXEL,
size[sizes], size[sizes], "dst");
bench_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
ref1, sizes[size], *denom, *wx, *wx, *ox, *ox, i, j, sizes[size]);
}
}
}
}
}
}
}
}
report("qpel_bi_w");
}
#undef SRC_EXTRA
#define SRC_EXTRA 0
static void checkasm_check_hevc_epel(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
declare_func(void, int16_t *dst, const uint8_t *src, ptrdiff_t srcstride,
int height, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_pixels"; break; // 0 0
case 1: type = "epel_h"; break; // 0 1
case 2: type = "epel_v"; break; // 1 0
case 3: type = "epel_hv"; break; // 1 1
}
if (check_func(h.put_hevc_epel[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
int16_t *dstw0 = (int16_t *) dst0, *dstw1 = (int16_t *) dst1;
randomize_buffers();
call_ref(dstw0, src0, sizes[size] * SIZEOF_PIXEL, sizes[size], i, j, sizes[size]);
call_new(dstw1, src1, sizes[size] * SIZEOF_PIXEL, sizes[size], i, j, sizes[size]);
checkasm_check(int16_t, dstw0, MAX_PB_SIZE * sizeof(int16_t),
dstw1, MAX_PB_SIZE * sizeof(int16_t),
size[sizes], size[sizes], "dst");
bench_new(dstw1, src1, sizes[size] * SIZEOF_PIXEL, sizes[size], i, j, sizes[size]);
}
}
}
}
}
report("epel");
}
static void checkasm_check_hevc_epel_uni(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
declare_func(void, uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride,
int height, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_uni_pixels"; break; // 0 0
case 1: type = "epel_uni_h"; break; // 0 1
case 2: type = "epel_uni_v"; break; // 1 0
case 3: type = "epel_uni_hv"; break; // 1 1
}
if (check_func(h.put_hevc_epel_uni[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
randomize_buffers();
call_ref(dst0, sizes[size] * SIZEOF_PIXEL,
src0, sizes[size] * SIZEOF_PIXEL,
sizes[size], i, j, sizes[size]);
call_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
sizes[size], i, j, sizes[size]);
checkasm_check_pixel(dst0, sizes[size] * SIZEOF_PIXEL,
dst1, sizes[size] * SIZEOF_PIXEL,
size[sizes], size[sizes], "dst");
bench_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
sizes[size], i, j, sizes[size]);
}
}
}
}
}
report("epel_uni");
}
static void checkasm_check_hevc_epel_uni_w(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
const int *denom, *wx, *ox;
declare_func(void, uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride,
int height, int denom, int wx, int ox, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_uni_w_pixels"; break; // 0 0
case 1: type = "epel_uni_w_h"; break; // 0 1
case 2: type = "epel_uni_w_v"; break; // 1 0
case 3: type = "epel_uni_w_hv"; break; // 1 1
}
if (check_func(h.put_hevc_epel_uni_w[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
for (denom = denoms; *denom >= 0; denom++) {
for (wx = weights; *wx >= 0; wx++) {
for (ox = offsets; *ox >= 0; ox++) {
randomize_buffers();
call_ref(dst0, sizes[size] * SIZEOF_PIXEL,
src0, sizes[size] * SIZEOF_PIXEL,
sizes[size], *denom, *wx, *ox, i, j, sizes[size]);
call_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
sizes[size], *denom, *wx, *ox, i, j, sizes[size]);
checkasm_check_pixel(dst0, sizes[size] * SIZEOF_PIXEL,
dst1, sizes[size] * SIZEOF_PIXEL,
size[sizes], size[sizes], "dst");
bench_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
sizes[size], *denom, *wx, *ox, i, j, sizes[size]);
}
}
}
}
}
}
}
}
report("epel_uni_w");
}
static void checkasm_check_hevc_epel_bi(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, ref0, [BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, ref1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
declare_func(void, uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride,
const int16_t *src2,
int height, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_bi_pixels"; break; // 0 0
case 1: type = "epel_bi_h"; break; // 0 1
case 2: type = "epel_bi_v"; break; // 1 0
case 3: type = "epel_bi_hv"; break; // 1 1
}
if (check_func(h.put_hevc_epel_bi[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
randomize_buffers_ref();
call_ref(dst0, sizes[size] * SIZEOF_PIXEL,
src0, sizes[size] * SIZEOF_PIXEL,
ref0, sizes[size], i, j, sizes[size]);
call_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
ref1, sizes[size], i, j, sizes[size]);
checkasm_check_pixel(dst0, sizes[size] * SIZEOF_PIXEL,
dst1, sizes[size] * SIZEOF_PIXEL,
size[sizes], size[sizes], "dst");
bench_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
ref1, sizes[size], i, j, sizes[size]);
}
}
}
}
}
report("epel_bi");
}
static void checkasm_check_hevc_epel_bi_w(void)
{
LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, ref0, [BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, ref1, [BUF_SIZE]);
HEVCDSPContext h;
int size, bit_depth, i, j;
const int *denom, *wx, *ox;
declare_func(void, uint8_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride,
const int16_t *src2,
int height, int denom, int wx0, int wx1,
int ox0, int ox1, intptr_t mx, intptr_t my, int width);
for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
ff_hevc_dsp_init(&h, bit_depth);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
for (size = 1; size < 10; size++) {
const char *type;
switch ((j << 1) | i) {
case 0: type = "pel_bi_w_pixels"; break; // 0 0
case 1: type = "epel_bi_w_h"; break; // 0 1
case 2: type = "epel_bi_w_v"; break; // 1 0
case 3: type = "epel_bi_w_hv"; break; // 1 1
}
if (check_func(h.put_hevc_epel_bi_w[size][j][i],
"put_hevc_%s%d_%d", type, sizes[size], bit_depth)) {
for (denom = denoms; *denom >= 0; denom++) {
for (wx = weights; *wx >= 0; wx++) {
for (ox = offsets; *ox >= 0; ox++) {
randomize_buffers_ref();
call_ref(dst0, sizes[size] * SIZEOF_PIXEL,
src0, sizes[size] * SIZEOF_PIXEL,
ref0, sizes[size], *denom, *wx, *wx, *ox, *ox, i, j, sizes[size]);
call_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
ref1, sizes[size], *denom, *wx, *wx, *ox, *ox, i, j, sizes[size]);
checkasm_check_pixel(dst0, sizes[size] * SIZEOF_PIXEL,
dst1, sizes[size] * SIZEOF_PIXEL,
size[sizes], size[sizes], "dst");
bench_new(dst1, sizes[size] * SIZEOF_PIXEL,
src1, sizes[size] * SIZEOF_PIXEL,
ref1, sizes[size], *denom, *wx, *wx, *ox, *ox, i, j, sizes[size]);
}
}
}
}
}
}
}
}
report("epel_bi_w");
}
void checkasm_check_hevc_pel(void)
{
checkasm_check_hevc_qpel();
checkasm_check_hevc_qpel_uni();
checkasm_check_hevc_qpel_uni_w();
checkasm_check_hevc_qpel_bi();
checkasm_check_hevc_qpel_bi_w();
checkasm_check_hevc_epel();
checkasm_check_hevc_epel_uni();
checkasm_check_hevc_epel_uni_w();
checkasm_check_hevc_epel_bi();
checkasm_check_hevc_epel_bi_w();
}
+160
View File
@@ -0,0 +1,160 @@
/*
* Copyright (c) 2018 Yingming Fan <yingmingfan@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/hevc/dsp.h"
#include "checkasm.h"
static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
static const uint32_t sao_size[5] = {8, 16, 32, 48, 64};
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define PIXEL_STRIDE (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) //same with sao_edge src_stride
#define BUF_SIZE (PIXEL_STRIDE * (64+2) * 2) //+2 for top and bottom row, *2 for high bit depth
#define OFFSET_THRESH (1 << (bit_depth - 5))
#define OFFSET_LENGTH 5
#define randomize_buffers(buf0, buf1, size) \
do { \
uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
int k; \
for (k = 0; k < size; k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf0 + k, r); \
AV_WN32A(buf1 + k, r); \
} \
} while (0)
#define randomize_buffers2(buf, size) \
do { \
uint32_t max_offset = OFFSET_THRESH; \
int k; \
if (bit_depth == 8) { \
for (k = 0; k < size; k++) { \
uint8_t r = rnd() % max_offset; \
buf[k] = r; \
} \
} else { \
for (k = 0; k < size; k++) { \
uint16_t r = rnd() % max_offset; \
buf[k] = r; \
} \
} \
} while (0)
static void check_sao_band(HEVCDSPContext *h, int bit_depth)
{
int i;
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [BUF_SIZE]);
int16_t offset_val[OFFSET_LENGTH];
int left_class = rnd()%32;
for (i = 0; i <= 4; i++) {
int block_size = sao_size[i];
int prev_size = i > 0 ? sao_size[i - 1] : 0;
ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t dst_stride, ptrdiff_t src_stride,
const int16_t *sao_offset_val, int sao_left_class, int width, int height);
if (check_func(h->sao_band_filter[i], "hevc_sao_band_%d_%d", block_size, bit_depth)) {
for (int w = prev_size + 4; w <= block_size; w += 4) {
randomize_buffers(src0, src1, BUF_SIZE);
randomize_buffers2(offset_val, OFFSET_LENGTH);
memset(dst0, 0, BUF_SIZE);
memset(dst1, 0, BUF_SIZE);
call_ref(dst0, src0, stride, stride, offset_val, left_class, w, block_size);
call_new(dst1, src1, stride, stride, offset_val, left_class, w, block_size);
for (int j = 0; j < block_size; j++) {
if (memcmp(dst0 + j*stride, dst1 + j*stride, w*SIZEOF_PIXEL))
fail();
}
}
bench_new(dst1, src1, stride, stride, offset_val, left_class, block_size, block_size);
}
}
}
static void check_sao_edge(HEVCDSPContext *h, int bit_depth)
{
int i;
LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [BUF_SIZE]);
int16_t offset_val[OFFSET_LENGTH];
int eo = rnd()%4;
for (i = 0; i <= 4; i++) {
int block_size = sao_size[i];
int prev_size = i > 0 ? sao_size[i - 1] : 0;
ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
int offset = (AV_INPUT_BUFFER_PADDING_SIZE + PIXEL_STRIDE)*SIZEOF_PIXEL;
declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t stride_dst,
const int16_t *sao_offset_val, int eo, int width, int height);
for (int w = prev_size + 4; w <= block_size; w += 4) {
randomize_buffers(src0, src1, BUF_SIZE);
randomize_buffers2(offset_val, OFFSET_LENGTH);
memset(dst0, 0, BUF_SIZE);
memset(dst1, 0, BUF_SIZE);
if (check_func(h->sao_edge_filter[i], "hevc_sao_edge_%d_%d", block_size, bit_depth)) {
call_ref(dst0, src0 + offset, stride, offset_val, eo, w, block_size);
call_new(dst1, src1 + offset, stride, offset_val, eo, w, block_size);
for (int j = 0; j < block_size; j++) {
if (memcmp(dst0 + j*stride, dst1 + j*stride, w*SIZEOF_PIXEL))
fail();
}
bench_new(dst1, src1 + offset, stride, offset_val, eo, block_size, block_size);
}
}
}
}
void checkasm_check_hevc_sao(void)
{
int bit_depth;
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
HEVCDSPContext h;
ff_hevc_dsp_init(&h, bit_depth);
check_sao_band(&h, bit_depth);
}
report("sao_band");
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
HEVCDSPContext h;
ff_hevc_dsp_init(&h, bit_depth);
check_sao_edge(&h, bit_depth);
}
report("sao_edge");
}
+111
View File
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2016 Alexandra Hájková
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavcodec/huffyuvdsp.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
int j; \
for (j = 0; j < size; j++) \
buf[j] = rnd() & 0xFFFF; \
} while (0)
static void check_add_int16(HuffYUVDSPContext *c, unsigned mask, int width, const char * name)
{
uint16_t *src0 = av_mallocz(width * sizeof(uint16_t));
uint16_t *src1 = av_mallocz(width * sizeof(uint16_t));
uint16_t *dst0 = av_mallocz(width * sizeof(uint16_t));
uint16_t *dst1 = av_mallocz(width * sizeof(uint16_t));
declare_func(void, uint16_t *dst, const uint16_t *src, unsigned mask, int w);
if (!src0 || !src1 || !dst0 || !dst1)
fail();
randomize_buffers(src0, width);
memcpy(src1, src0, width * sizeof(uint16_t));
if (check_func(c->add_int16, "%s", name)) {
call_ref(dst0, src0, mask, width);
call_new(dst1, src1, mask, width);
if (memcmp(dst0, dst1, width * sizeof(uint16_t)))
fail();
bench_new(dst1, src1, mask, width);
}
av_free(src0);
av_free(src1);
av_free(dst0);
av_free(dst1);
}
static void check_add_hfyu_left_pred_bgr32(HuffYUVDSPContext *c)
{
#define BUF_SIZE 1080
uint8_t src[4 * BUF_SIZE], dst0[4 * BUF_SIZE], dst1[4 * BUF_SIZE];
uint8_t left[4], left0[4], left1[4];
declare_func(void, uint8_t *d, const uint8_t *s, intptr_t w, uint8_t *l);
randomize_buffers(src, sizeof (src));
randomize_buffers(left, sizeof (left));
memcpy(left0, left, sizeof (left));
memcpy(left1, left, sizeof (left));
if (check_func(c->add_hfyu_left_pred_bgr32, "add_hfyu_left_pred_bgr32")) {
call_ref(dst0, src, BUF_SIZE, left0);
call_new(dst1, src, BUF_SIZE, left1);
if (memcmp(dst0, dst1, sizeof (dst0)) != 0 ||
memcmp(left0, left1, sizeof (left0)) != 0) {
fail();
}
bench_new(dst1, src, BUF_SIZE, left);
}
report("add_hfyu_left_pred_bgr32");
}
void checkasm_check_huffyuvdsp(void)
{
HuffYUVDSPContext c;
int width = 16 * av_clip(rnd(), 16, 128);
ff_huffyuvdsp_init(&c, AV_PIX_FMT_YUV422P);
/*! test width not multiple of mmsize */
check_add_int16(&c, 65535, width, "add_int16_rnd_width");
report("add_int16_rnd_width");
/*! test always with the same size (for perf test) */
check_add_int16(&c, 65535, 16*128, "add_int16_128");
report("add_int16_128");
check_add_hfyu_left_pred_bgr32(&c);
}
+99
View File
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2022 Ben Avison
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/avcodec.h"
#include "libavcodec/idctdsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define IDCTDSP_TEST(func) { #func, offsetof(IDCTDSPContext, func) },
typedef struct {
const char *name;
size_t offset;
} test;
#define RANDOMIZE_BUFFER16(name, size) \
do { \
int i; \
for (i = 0; i < size; ++i) { \
uint16_t r = rnd() % 0x201 - 0x100; \
AV_WN16A(name##0 + i, r); \
AV_WN16A(name##1 + i, r); \
} \
} while (0)
#define RANDOMIZE_BUFFER8(name, size) \
do { \
int i; \
for (i = 0; i < size; ++i) { \
uint8_t r = rnd(); \
name##0[i] = r; \
name##1[i] = r; \
} \
} while (0)
static void check_add_put_clamped(void)
{
/* Source buffers are only as big as needed, since any over-read won't affect results */
LOCAL_ALIGNED_16(int16_t, src0, [64]);
LOCAL_ALIGNED_16(int16_t, src1, [64]);
/* Destination buffers have borders of one row above/below and 8 columns left/right to catch overflows */
LOCAL_ALIGNED_8(uint8_t, dst0, [10 * 24]);
LOCAL_ALIGNED_8(uint8_t, dst1, [10 * 24]);
AVCodecContext avctx = { 0 };
IDCTDSPContext h;
const test tests[] = {
IDCTDSP_TEST(add_pixels_clamped)
IDCTDSP_TEST(put_pixels_clamped)
IDCTDSP_TEST(put_signed_pixels_clamped)
};
ff_idctdsp_init(&h, &avctx);
for (size_t t = 0; t < FF_ARRAY_ELEMS(tests); ++t) {
void (*func)(const int16_t *, uint8_t * ptrdiff_t) = *(void **)((intptr_t) &h + tests[t].offset);
if (check_func(func, "idctdsp.%s", tests[t].name)) {
declare_func(void, const int16_t *, uint8_t *, ptrdiff_t);
RANDOMIZE_BUFFER16(src, 64);
RANDOMIZE_BUFFER8(dst, 10 * 24);
call_ref(src0, dst0 + 24 + 8, 24);
call_new(src1, dst1 + 24 + 8, 24);
if (memcmp(dst0, dst1, 10 * 24))
fail();
bench_new(src1, dst1 + 24 + 8, 24);
}
}
}
void checkasm_check_idctdsp(void)
{
check_add_put_clamped();
report("idctdsp");
}
+104
View File
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2015 James Almer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "checkasm.h"
#include "libavcodec/jpeg2000dsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define BUF_SIZE 512
#define randomize_buffers() \
do { \
int i; \
for (i = 0; i < BUF_SIZE*3; i++) \
src[i] = rnd(); \
} while (0)
#define randomize_buffers_float() \
do { \
int i; \
for (i = 0; i < BUF_SIZE*3; i++) \
src[i] = (float)rnd() / (UINT_MAX >> 5); \
} while (0)
static void check_rct_int(void)
{
LOCAL_ALIGNED_32(int32_t, src, [BUF_SIZE*3]);
LOCAL_ALIGNED_32(int32_t, ref, [BUF_SIZE*3]);
LOCAL_ALIGNED_32(int32_t, new, [BUF_SIZE*3]);
int32_t *ref0 = &ref[BUF_SIZE*0], *new0 = &new[BUF_SIZE*0];
int32_t *ref1 = &ref[BUF_SIZE*1], *new1 = &new[BUF_SIZE*1];
int32_t *ref2 = &ref[BUF_SIZE*2], *new2 = &new[BUF_SIZE*2];
declare_func(void, void *src0, void *src1, void *src2, int csize);
randomize_buffers();
memcpy(ref, src, BUF_SIZE * 3 * sizeof(*src));
memcpy(new, src, BUF_SIZE * 3 * sizeof(*src));
call_ref(ref0, ref1, ref2, BUF_SIZE);
call_new(new0, new1, new2, BUF_SIZE);
if (memcmp(ref0, new0, BUF_SIZE * sizeof(*src)) ||
memcmp(ref1, new1, BUF_SIZE * sizeof(*src)) ||
memcmp(ref2, new2, BUF_SIZE * sizeof(*src)))
fail();
memcpy(new, src, BUF_SIZE * 3 * sizeof(*src));
bench_new(new0, new1, new2, BUF_SIZE);
}
static void check_ict_float(void)
{
LOCAL_ALIGNED_32(float, src, [BUF_SIZE*3]);
LOCAL_ALIGNED_32(float, ref, [BUF_SIZE*3]);
LOCAL_ALIGNED_32(float, new, [BUF_SIZE*3]);
float *ref0 = &ref[BUF_SIZE*0], *new0 = &new[BUF_SIZE*0];
float *ref1 = &ref[BUF_SIZE*1], *new1 = &new[BUF_SIZE*1];
float *ref2 = &ref[BUF_SIZE*2], *new2 = &new[BUF_SIZE*2];
declare_func(void, void *src0, void *src1, void *src2, int csize);
randomize_buffers_float();
memcpy(ref, src, BUF_SIZE * 3 * sizeof(*src));
memcpy(new, src, BUF_SIZE * 3 * sizeof(*src));
call_ref(ref0, ref1, ref2, BUF_SIZE);
call_new(new0, new1, new2, BUF_SIZE);
if (!float_near_abs_eps_array(ref0, new0, 1.0e-5, BUF_SIZE) ||
!float_near_abs_eps_array(ref1, new1, 1.0e-5, BUF_SIZE) ||
!float_near_abs_eps_array(ref2, new2, 1.0e-5, BUF_SIZE))
fail();
memcpy(new, src, BUF_SIZE * 3 * sizeof(*src));
bench_new(new0, new1, new2, BUF_SIZE);
}
void checkasm_check_jpeg2000dsp(void)
{
Jpeg2000DSPContext h;
ff_jpeg2000dsp_init(&h);
if (check_func(h.mct_decode[FF_DWT53], "jpeg2000_rct_int"))
check_rct_int();
if (check_func(h.mct_decode[FF_DWT97], "jpeg2000_ict_float"))
check_ict_float();
report("mct_decode");
}
+115
View File
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2016 Alexandra Hájková
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/lossless_audiodsp.h"
#include "checkasm.h"
#define randomize_buf(buf, len) \
do { \
for (int i = 0; i < len; i++) \
buf[i] = rnd(); \
} while (0)
static void check_scalarproduct_and_madd_int16(LLAudDSPContext *c)
{
#define BUF_SIZE 1088 // multiple of 16
LOCAL_ALIGNED_16(int16_t, v1, [BUF_SIZE]);
LOCAL_ALIGNED_16(int16_t, v2, [BUF_SIZE]);
LOCAL_ALIGNED_16(int16_t, v3, [BUF_SIZE]);
int mul;
declare_func(int32_t, int16_t *, const int16_t *, const int16_t *,
int, int);
randomize_buf(v1, BUF_SIZE);
randomize_buf(v2, BUF_SIZE);
randomize_buf(v3, BUF_SIZE);
mul = (int16_t)rnd();
if (check_func(c->scalarproduct_and_madd_int16,
"scalarproduct_and_madd_int16")) {
LOCAL_ALIGNED_16(int16_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(int16_t, dst1, [BUF_SIZE]);
int ref, val;
memcpy(dst0, v1, sizeof (*dst0) * BUF_SIZE);
memcpy(dst1, v1, sizeof (*dst1) * BUF_SIZE);
ref = call_ref(dst0, v2, v3, BUF_SIZE, mul);
val = call_new(dst1, v2, v3, BUF_SIZE, mul);
if (memcmp(dst0, dst1, sizeof (*dst0) * BUF_SIZE) != 0 || ref != val)
fail();
bench_new(v1, v2, v3, BUF_SIZE, mul);
}
report("scalarproduct_and_madd_int16");
}
static void check_scalarproduct_and_madd_int32(LLAudDSPContext *c)
{
#define BUF_SIZE 1088 // multiple of 16
LOCAL_ALIGNED_16(int16_t, v1, [BUF_SIZE]);
LOCAL_ALIGNED_16(int32_t, v2, [BUF_SIZE]);
LOCAL_ALIGNED_16(int16_t, v3, [BUF_SIZE]);
int mul;
declare_func(int32_t, int16_t *, const int32_t *, const int16_t *,
int, int);
randomize_buf(v1, BUF_SIZE);
randomize_buf(v2, BUF_SIZE);
randomize_buf(v3, BUF_SIZE);
mul = (int16_t)rnd();
if (check_func(c->scalarproduct_and_madd_int32,
"scalarproduct_and_madd_int32")) {
LOCAL_ALIGNED_16(int16_t, dst0, [BUF_SIZE]);
LOCAL_ALIGNED_16(int16_t, dst1, [BUF_SIZE]);
int ref, val;
memcpy(dst0, v1, sizeof (*dst0) * BUF_SIZE);
memcpy(dst1, v1, sizeof (*dst1) * BUF_SIZE);
ref = call_ref(dst0, v2, v3, BUF_SIZE, mul);
val = call_new(dst1, v2, v3, BUF_SIZE, mul);
if (memcmp(dst0, dst1, sizeof (*dst0) * BUF_SIZE) != 0 || ref != val)
fail();
bench_new(v1, v2, v3, BUF_SIZE, mul);
}
report("scalarproduct_and_madd_int32");
}
void checkasm_check_llauddsp(void)
{
LLAudDSPContext c;
ff_llauddsp_init(&c);
check_scalarproduct_and_madd_int16(&c);
check_scalarproduct_and_madd_int32(&c);
}
+105
View File
@@ -0,0 +1,105 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <float.h>
#include "libavutil/lls.h"
#include "checkasm.h"
#define randomize_buffer(buf) \
do { \
double bmg[2], stddev = 10.0; \
\
for (size_t i = 0; i < MAX_VARS_ALIGN; i += 2) { \
av_bmg_get(&checkasm_lfg, bmg); \
buf[i] = bmg[0] * stddev; \
buf[i + 1] = bmg[1] * stddev; \
} \
} while(0);
static void test_update(LLSModel *lls, const double *var)
{
double refcovar[MAX_VARS][MAX_VARS];
declare_func(void, LLSModel *, const double *);
call_ref(lls, var);
for (size_t i = 0; i < MAX_VARS; i++)
for (size_t j = 0; j < MAX_VARS; j++)
refcovar[i][j] = lls->covariance[i][j];
memset(lls->covariance, 0, sizeof (lls->covariance));
call_new(lls, var);
for (size_t i = 0; i < lls->indep_count; i++)
for (size_t j = i; j < lls->indep_count; j++) {
double eps = FFMAX(2 * DBL_EPSILON * fabs(refcovar[i][j]),
8 * DBL_EPSILON);
if (!double_near_abs_eps(refcovar[i][j], lls->covariance[i][j],
eps)) {
fprintf(stderr, "%zu, %zu: %- .12f - %- .12f = % .12g\n", i, j,
refcovar[i][j], lls->covariance[i][j],
refcovar[i][j] - lls->covariance[i][j]);
fail();
}
}
bench_new(lls, var);
}
static void test_evaluate(LLSModel *lls, const double *param, int order)
{
double refprod, newprod, eps;
declare_func_float(double, LLSModel *, const double *, int);
refprod = call_ref(lls, param, order);
newprod = call_new(lls, param, order);
eps = FFMAX(2 * DBL_EPSILON * fabs(refprod), 0.2);
if (!double_near_abs_eps(refprod, newprod, eps)) {
fprintf(stderr, "%- .12f - %- .12f = % .12g\n",
refprod, newprod, refprod - newprod);
fail();
}
if (order == lls->indep_count)
bench_new(lls, param, order);
}
void checkasm_check_lls(void)
{
static const unsigned char counts[] = { 8, 12, MAX_VARS, };
for (size_t i = 0; i < FF_ARRAY_ELEMS(counts); i++) {
LOCAL_ALIGNED_32(double, var, [MAX_VARS_ALIGN]);
LOCAL_ALIGNED_32(double, param, [FFALIGN(MAX_VARS+2,4)]);
LLSModel lls;
avpriv_init_lls(&lls, counts[i]);
randomize_buffer(var);
randomize_buffer(param);
if (check_func(lls.update_lls, "update_lls_%d", counts[i]))
test_update(&lls, var);
for (size_t j = 0; j <= i; j++)
if (check_func(lls.evaluate_lls, "evaluate_lls_%d_%d", counts[i],
counts[j]))
test_evaluate(&lls, param + 1, counts[j]);
}
report("lls");
}
+220
View File
@@ -0,0 +1,220 @@
/*
* Copyright (c) 2016 Alexandra Hájková
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavcodec/lossless_videodsp.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
int j; \
uint8_t *tmp_buf = (uint8_t *)buf;\
for (j = 0; j < size; j++) \
tmp_buf[j] = rnd() & 0xFF; \
} while (0)
#define init_buffer(a0, a1, type, width)\
if (!a0 || !a1)\
fail();\
randomize_buffers(a0, width * sizeof(type));\
memcpy(a1, a0, width*sizeof(type));\
static void check_add_bytes(LLVidDSPContext *c, int width)
{
uint8_t *dst0 = av_mallocz(width);
uint8_t *dst1 = av_mallocz(width);
uint8_t *src0 = av_calloc(width, sizeof(*src0));
uint8_t *src1 = av_calloc(width, sizeof(*src1));
declare_func(void, uint8_t *dst, uint8_t *src, ptrdiff_t w);
init_buffer(src0, src1, uint8_t, width);
if (!dst0 || !dst1)
fail();
if (check_func(c->add_bytes, "add_bytes")) {
call_ref(dst0, src0, width);
call_new(dst1, src1, width);
if (memcmp(dst0, dst1, width))
fail();
bench_new(dst1, src1, width);
}
av_free(src0);
av_free(src1);
av_free(dst0);
av_free(dst1);
}
static void check_add_median_pred(LLVidDSPContext *c, int width) {
int a0, a1, b0, b1;
uint8_t *dst0 = av_mallocz(width);
uint8_t *dst1 = av_mallocz(width);
uint8_t *src0 = av_calloc(width, sizeof(*src0));
uint8_t *src1 = av_calloc(width, sizeof(*src1));
uint8_t *diff0 = av_calloc(width, sizeof(*diff0));
uint8_t *diff1 = av_calloc(width, sizeof(*diff1));
declare_func(void, uint8_t *dst, const uint8_t *src1,
const uint8_t *diff, ptrdiff_t w,
int *left, int *left_top);
init_buffer(src0, src1, uint8_t, width);
init_buffer(diff0, diff1, uint8_t, width);
a0 = rnd() & 0xFF;
b0 = rnd() & 0xFF;
a1 = a0;
b1 = b0;
if (check_func(c->add_median_pred, "add_median_pred")) {
call_ref(dst0, src0, diff0, width, &a0, &b0);
call_new(dst1, src1, diff1, width, &a1, &b1);
if (memcmp(dst0, dst1, width) || (a0 != a1) || (b0 != b1))
fail();
bench_new(dst1, src1, diff1, width, &a1, &b1);
}
av_free(src0);
av_free(src1);
av_free(diff0);
av_free(diff1);
av_free(dst0);
av_free(dst1);
}
static void check_add_left_pred(LLVidDSPContext *c, int width, int acc, const char * report)
{
int res0, res1;
uint8_t *dst0 = av_mallocz(width);
uint8_t *dst1 = av_mallocz(width);
uint8_t *src0 = av_calloc(width, sizeof(*src0));
uint8_t *src1 = av_calloc(width, sizeof(*src1));
declare_func(int, uint8_t *dst, const uint8_t *src, ptrdiff_t w, int acc);
init_buffer(src0, src1, uint8_t, width);
if (!dst0 || !dst1)
fail();
if (check_func(c->add_left_pred, "%s", report)) {
res0 = call_ref(dst0, src0, width, acc);
res1 = call_new(dst1, src1, width, acc);
if ((res0 & 0xFF) != (res1 & 0xFF)||\
memcmp(dst0, dst1, width))
fail();
bench_new(dst1, src1, width, acc);
}
av_free(src0);
av_free(src1);
av_free(dst0);
av_free(dst1);
}
static void check_add_left_pred_16(LLVidDSPContext *c, unsigned mask, int width, unsigned acc, const char * report)
{
int res0, res1;
uint16_t *dst0 = av_calloc(width, sizeof(*dst0));
uint16_t *dst1 = av_calloc(width, sizeof(*dst1));
uint16_t *src0 = av_calloc(width, sizeof(*src0));
uint16_t *src1 = av_calloc(width, sizeof(*src1));
declare_func(int, uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc);
init_buffer(src0, src1, uint16_t, width);
if (!dst0 || !dst1)
fail();
if (check_func(c->add_left_pred_int16, "%s", report)) {
res0 = call_ref(dst0, src0, mask, width, acc);
res1 = call_new(dst1, src1, mask, width, acc);
if ((res0 &0xFFFF) != (res1 &0xFFFF)||\
memcmp(dst0, dst1, width))
fail();
bench_new(dst1, src1, mask, width, acc);
}
av_free(src0);
av_free(src1);
av_free(dst0);
av_free(dst1);
}
static void check_add_gradient_pred(LLVidDSPContext *c, int w) {
int src_size, stride;
uint8_t *src0, *src1;
declare_func(void, uint8_t *src, const ptrdiff_t stride,
const ptrdiff_t width);
stride = w + 32;
src_size = (stride + 32) * 2; /* dsp need previous line, and ignore the start of the line */
src0 = av_mallocz(src_size);
src1 = av_mallocz(src_size);
init_buffer(src0, src1, uint8_t, src_size);
if (check_func(c->add_gradient_pred, "add_gradient_pred")) {
call_ref(src0 + stride + 32, stride, w);
call_new(src1 + stride + 32, stride, w);
if (memcmp(src0, src1, stride)||/* previous line doesn't change */
memcmp(src0+stride, src1 + stride, w + 32)) {
fail();
}
bench_new(src1 + stride + 32, stride, w);
}
av_free(src0);
av_free(src1);
}
void checkasm_check_llviddsp(void)
{
LLVidDSPContext c;
int width = 16 * av_clip(rnd(), 16, 128);
int accRnd = rnd() & 0xFF;
ff_llviddsp_init(&c);
check_add_bytes(&c, width);
report("add_bytes");
check_add_median_pred(&c, width);
report("add_median_pred");
check_add_left_pred(&c, width, 0, "add_left_pred_zero");
report("add_left_pred_zero");
check_add_left_pred(&c, width, accRnd, "add_left_pred_rnd_acc");
report("add_left_pred_rnd_acc");
check_add_left_pred_16(&c, 255, width, accRnd, "add_left_pred_int16");
report("add_left_pred_int16");
check_add_gradient_pred(&c, width);
report("add_gradient_pred");
}
+114
View File
@@ -0,0 +1,114 @@
/*
* Copyright (c) 2016 Alexandra Hájková
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/lossless_videoencdsp.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
int j; \
for (j = 0; j < size; j+=4) \
AV_WN32(buf + j, rnd()); \
} while (0)
static const struct {uint8_t w, h, s;} planes[] = {
{16,16,16}, {21,23,25}, {32,17,48}, {15,128,16}, {128,127,128}
};
#define MAX_STRIDE 128
#define MAX_HEIGHT 127
static void check_diff_bytes(LLVidEncDSPContext *c)
{
int i;
LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE]);
LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE]);
LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE]);
LOCAL_ALIGNED_32(uint8_t, src2, [MAX_STRIDE]);
LOCAL_ALIGNED_32(uint8_t, src3, [MAX_STRIDE]);
declare_func(void, uint8_t *dst, const uint8_t *src1,
const uint8_t *src2, intptr_t w);
memset(dst0, 0, MAX_STRIDE);
memset(dst1, 0, MAX_STRIDE);
randomize_buffers(src0, MAX_STRIDE);
memcpy(src1, src0, MAX_STRIDE);
randomize_buffers(src2, MAX_STRIDE);
memcpy(src3, src2, MAX_STRIDE);
if (check_func(c->diff_bytes, "diff_bytes")) {
for (i = 0; i < 5; i ++) {
call_ref(dst0, src0, src2, planes[i].w);
call_new(dst1, src1, src3, planes[i].w);
if (memcmp(dst0, dst1, planes[i].w))
fail();
}
bench_new(dst1, src0, src2, planes[4].w);
}
}
static void check_sub_left_pred(LLVidEncDSPContext *c)
{
int i;
LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE * MAX_HEIGHT]);
LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE * MAX_HEIGHT]);
LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE * MAX_HEIGHT]);
LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE * MAX_HEIGHT]);
declare_func(void, uint8_t *dst, const uint8_t *src,
ptrdiff_t stride, ptrdiff_t width, int height);
memset(dst0, 0, MAX_STRIDE * MAX_HEIGHT);
memset(dst1, 0, MAX_STRIDE * MAX_HEIGHT);
randomize_buffers(src0, MAX_STRIDE * MAX_HEIGHT);
memcpy(src1, src0, MAX_STRIDE * MAX_HEIGHT);
if (check_func(c->sub_left_predict, "sub_left_predict")) {
for (i = 0; i < 5; i ++) {
call_ref(dst0, src0, planes[i].s, planes[i].w, planes[i].h);
call_new(dst1, src1, planes[i].s, planes[i].w, planes[i].h);
if (memcmp(dst0, dst1, planes[i].w * planes[i].h))
fail();
break;
}
bench_new(dst1, src0, planes[4].s, planes[4].w, planes[4].h);
}
}
void checkasm_check_llviddspenc(void)
{
LLVidEncDSPContext c;
ff_llvidencdsp_init(&c);
check_diff_bytes(&c);
report("diff_bytes");
check_sub_left_pred(&c);
report("sub_left_predict");
}
+126
View File
@@ -0,0 +1,126 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "libavutil/avassert.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/lpc.h"
#include "checkasm.h"
#define randomize_int32(buf, len) \
do { \
for (int i = 0; i < len; i++) { \
int32_t f = ((int)(UINT32_MAX >> 17)) - ((int)(rnd() >> 16)); \
buf[i] = f; \
} \
} while (0)
#define EPS 0.005
static void test_window(int len)
{
LOCAL_ALIGNED(16, int32_t, src, [5000]);
LOCAL_ALIGNED(16, double, dst0, [5000]);
LOCAL_ALIGNED(16, double, dst1, [5000]);
declare_func(void, const int32_t *in, ptrdiff_t len, double *out);
randomize_int32(src, len);
call_ref(src, len, dst0);
call_new(src, len, dst1);
for (int i = 0; i < len; i++) {
if (!double_near_abs_eps(dst0[i], dst1[i], EPS)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, dst0[i], dst1[i], dst0[i] - dst1[i]);
fail();
break;
}
}
bench_new(src, 4608 + (len & 1), dst1);
}
static void test_compute_autocorr(ptrdiff_t len, int lag)
{
const double eps = EPS * (double)len;
LOCAL_ALIGNED(32, double, src, [5000 + 2 + MAX_LPC_ORDER]);
LOCAL_ALIGNED(16, double, dst0, [MAX_LPC_ORDER + 1]);
LOCAL_ALIGNED(16, double, dst1, [MAX_LPC_ORDER + 1]);
declare_func(void, const double *in, ptrdiff_t len, int lag, double *out);
av_assert0(lag >= 0 && lag <= MAX_LPC_ORDER);
for (int i = 0; i < MAX_LPC_ORDER; i++)
src[i] = 0.;
src += MAX_LPC_ORDER;
for (int i = 0; i < 5000 + 2; i++) {
src[i] = (double)rnd() / (double)UINT_MAX;
}
call_ref(src, len, lag, dst0);
call_new(src, len, lag, dst1);
for (size_t i = 0; i <= lag; i++) {
if (!double_near_abs_eps(dst0[i], dst1[i], eps)) {
fprintf(stderr, "%zu: %- .12f - %- .12f = % .12g\n",
i, dst0[i], dst1[i], dst0[i] - dst1[i]);
fail();
break;
}
}
bench_new(src, 4608 + (len & 1), lag, dst1);
}
void checkasm_check_lpc(void)
{
LPCContext ctx;
int len = 2000 + rnd() % 3000;
static const int lags[] = { 8, 12, };
ff_lpc_init(&ctx, 32, 16, FF_LPC_TYPE_DEFAULT);
if (check_func(ctx.lpc_apply_welch_window, "apply_welch_window_even")) {
test_window(len & ~1);
}
report("apply_welch_window_even");
if (check_func(ctx.lpc_apply_welch_window, "apply_welch_window_odd")) {
test_window(len | 1);
}
report("apply_welch_window_odd");
ff_lpc_end(&ctx);
for (size_t i = 0; i < FF_ARRAY_ELEMS(lags); i++) {
ff_lpc_init(&ctx, len, lags[i], FF_LPC_TYPE_DEFAULT);
if (check_func(ctx.lpc_compute_autocorr, "autocorr_%d_even", lags[i]))
test_compute_autocorr(len & ~1, lags[i]);
#if !ARCH_X86
if (check_func(ctx.lpc_compute_autocorr, "autocorr_%d_odd", lags[i]))
test_compute_autocorr(len | 1, lags[i]);
#endif
ff_lpc_end(&ctx);
}
report("compute_autocorr");
}
+141
View File
@@ -0,0 +1,141 @@
/*
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/me_cmp.h"
#include "checkasm.h"
static void fill_random(uint8_t *tab, int size)
{
int i;
for (i = 0; i < size; i++) {
tab[i] = rnd() % 256;
}
}
static void test_motion(const char *name, me_cmp_func test_func)
{
/* test configurarion */
#define ITERATIONS 16
#define WIDTH 64
#define HEIGHT 64
/* motion estimation can look up to 17 bytes ahead */
static const int look_ahead = 17;
int i, x, y, h, d1, d2;
uint8_t *ptr;
LOCAL_ALIGNED_16(uint8_t, img1, [WIDTH * HEIGHT]);
LOCAL_ALIGNED_16(uint8_t, img2, [WIDTH * HEIGHT]);
declare_func_emms(AV_CPU_FLAG_MMX, int, struct MpegEncContext *c,
const uint8_t *blk1 /* align width (8 or 16) */,
const uint8_t *blk2 /* align 1 */, ptrdiff_t stride,
int h);
if (test_func == NULL) {
return;
}
/* test correctness */
fill_random(img1, WIDTH * HEIGHT);
fill_random(img2, WIDTH * HEIGHT);
if (check_func(test_func, "%s", name)) {
for (i = 0; i < ITERATIONS; i++) {
x = rnd() % (WIDTH - look_ahead);
y = rnd() % (HEIGHT - look_ahead);
// Pick a random h between 4 and 16; pick an even value.
h = 4 + ((rnd() % (16 + 1 - 4)) & ~1);
ptr = img2 + y * WIDTH + x;
d2 = call_ref(NULL, img1, ptr, WIDTH, h);
d1 = call_new(NULL, img1, ptr, WIDTH, h);
if (d1 != d2) {
fail();
printf("func: %s, x=%d y=%d h=%d, error: asm=%d c=%d\n", name, x, y, h, d1, d2);
break;
}
}
// Test with a fixed offset, for benchmark stability
ptr = img2 + 3 * WIDTH + 3;
bench_new(NULL, img1, ptr, WIDTH, 8);
}
}
#define ME_CMP_1D_ARRAYS(XX) \
XX(sad) \
XX(sse) \
XX(hadamard8_diff) \
XX(vsad) \
XX(vsse) \
XX(nsse) \
XX(median_sad)
// tests for functions not yet implemented
#if 0
XX(dct_sad) \
XX(quant_psnr) \
XX(bit) \
XX(rd) \
XX(w53) \
XX(w97) \
XX(dct_max) \
XX(dct264_sad) \
#endif
static void check_motion(void)
{
char buf[64];
/* Setup AVCodecContext in a way that does not pull in all of libavcodec */
AVCodecContext av_ctx = { .codec_id = AV_CODEC_ID_NONE, .flags = AV_CODEC_FLAG_BITEXACT };
MECmpContext me_ctx;
ff_me_cmp_init(&me_ctx, &av_ctx);
for (int i = 0; i < FF_ARRAY_ELEMS(me_ctx.pix_abs); i++) {
for (int j = 0; j < FF_ARRAY_ELEMS(me_ctx.pix_abs[0]); j++) {
snprintf(buf, sizeof(buf), "pix_abs_%d_%d", i, j);
test_motion(buf, me_ctx.pix_abs[i][j]);
}
}
#define XX(me_cmp_array) \
for (int i = 0; i < FF_ARRAY_ELEMS(me_ctx.me_cmp_array); i++) { \
snprintf(buf, sizeof(buf), #me_cmp_array "_%d", i); \
test_motion(buf, me_ctx.me_cmp_array[i]); \
}
ME_CMP_1D_ARRAYS(XX)
#undef XX
}
void checkasm_check_motion(void)
{
check_motion();
report("motion");
}
+147
View File
@@ -0,0 +1,147 @@
/*
* 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 "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/mpegvideoencdsp.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
for (int j = 0; j < size; j += 4) \
AV_WN32(buf + j, rnd()); \
} while (0)
static void check_pix_sum(MpegvideoEncDSPContext *c)
{
LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]);
declare_func(int, const uint8_t *pix, ptrdiff_t line_size);
randomize_buffers(src, 16 * 16);
for (int n = 0; n < 2; n++) {
const char *negstride_str = n ? "_negstride" : "";
if (check_func(c->pix_sum, "pix_sum%s", negstride_str)) {
int sum0, sum1;
const uint8_t *pix = src + (n ? (15 * 16) : 0);
ptrdiff_t line_size = 16 * (n ? -1 : 1);
sum0 = call_ref(pix, line_size);
sum1 = call_new(pix, line_size);
if (sum0 != sum1)
fail();
bench_new(pix, line_size);
}
}
}
static void check_pix_norm1(MpegvideoEncDSPContext *c)
{
LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]);
declare_func(int, const uint8_t *pix, ptrdiff_t line_size);
randomize_buffers(src, 16 * 16);
for (int n = 0; n < 2; n++) {
const char *negstride_str = n ? "_negstride" : "";
if (check_func(c->pix_norm1, "pix_norm1%s", negstride_str)) {
int sum0, sum1;
const uint8_t *pix = src + (n ? (15 * 16) : 0);
ptrdiff_t line_size = 16 * (n ? -1 : 1);
sum0 = call_ref(pix, line_size);
sum1 = call_new(pix, line_size);
if (sum0 != sum1)
fail();
bench_new(pix, line_size);
}
}
}
#define NUM_LINES 4
#define MAX_LINE_SIZE 1920
#define EDGE_WIDTH 16
#define LINESIZE (EDGE_WIDTH + MAX_LINE_SIZE + EDGE_WIDTH)
#define BUFSIZE ((EDGE_WIDTH + NUM_LINES + EDGE_WIDTH) * LINESIZE)
static void check_draw_edges(MpegvideoEncDSPContext *c)
{
static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE, -MAX_LINE_SIZE};
LOCAL_ALIGNED_16(uint8_t, buf0, [BUFSIZE]);
LOCAL_ALIGNED_16(uint8_t, buf1, [BUFSIZE]);
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *buf, ptrdiff_t wrap, int width, int height,
int w, int h, int sides);
for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
int input_size = input_sizes[isi];
int negstride = input_size < 0;
const char *negstride_str = negstride ? "_negstride" : "";
int width = FFABS(input_size);
ptrdiff_t linesize = EDGE_WIDTH + width + EDGE_WIDTH;
/* calculate height based on specified width to use the entire buffer. */
int height = (BUFSIZE / linesize) - (2 * EDGE_WIDTH);
uint8_t *dst0 = buf0 + EDGE_WIDTH * linesize + EDGE_WIDTH;
uint8_t *dst1 = buf1 + EDGE_WIDTH * linesize + EDGE_WIDTH;
if (negstride) {
dst0 += (height - 1) * linesize;
dst1 += (height - 1) * linesize;
linesize *= -1;
}
for (int shift = 0; shift < 3; shift++) {
int edge = EDGE_WIDTH >> shift;
if (check_func(c->draw_edges, "draw_edges_%d_%d_%d%s", width, height, edge, negstride_str)) {
randomize_buffers(buf0, BUFSIZE);
memcpy(buf1, buf0, BUFSIZE);
call_ref(dst0, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
call_new(dst1, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
if (memcmp(buf0, buf1, BUFSIZE))
fail();
bench_new(dst1, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
}
}
}
}
#undef NUM_LINES
#undef MAX_LINE_SIZE
#undef EDGE_WIDTH
#undef LINESIZE
#undef BUFSIZE
void checkasm_check_mpegvideoencdsp(void)
{
AVCodecContext avctx = {
.bits_per_raw_sample = 8,
};
MpegvideoEncDSPContext c = { 0 };
ff_mpegvideoencdsp_init(&c, &avctx);
check_pix_sum(&c);
report("pix_sum");
check_pix_norm1(&c);
report("pix_norm1");
check_draw_edges(&c);
report("draw_edges");
}
+106
View File
@@ -0,0 +1,106 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "libavutil/mem_internal.h"
#include "libavcodec/opus/dsp.h"
#include "libavcodec/opus/tab.h"
#include "checkasm.h"
#define randomize_float(buf, len) \
do { \
for (int i = 0; i < len; i++) { \
float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
buf[i] = f; \
} \
} while (0)
#define EPS 0.005
#define MAX_SIZE (960)
/* period is between 15 and 1022, inclusive */
static void test_postfilter(int period)
{
LOCAL_ALIGNED(16, float, data0, [MAX_SIZE + 1024]);
LOCAL_ALIGNED(16, float, data1, [MAX_SIZE + 1024]);
/* This filter can explode very easily, so use a tapset from the codec.
* In the codec these are usually multiplied by at least 0.09375f,
* so its outside the largest filter value, but the filter is still stable
* so use it. */
float gains[3] = { 0.3066406250f, 0.2170410156f, 0.1296386719f };
/* The codec will always call with an offset which is aligned once
* (period + 2) is subtracted, but here we have to align it outselves. */
int offset = FFALIGN(period + 2, 4);
declare_func(void, float *data, int period, float *gains, int len);
randomize_float(data0, MAX_SIZE + 1024);
memcpy(data1, data0, (MAX_SIZE + 1024)*sizeof(float));
call_ref(data0 + offset, period, gains, MAX_SIZE);
call_new(data1 + offset, period, gains, MAX_SIZE);
if (!float_near_abs_eps_array(data0 + offset, data1 + offset, EPS, MAX_SIZE))
fail();
bench_new(data1 + offset, period, gains, MAX_SIZE);
}
static void test_deemphasis(void)
{
LOCAL_ALIGNED(16, float, src, [FFALIGN(MAX_SIZE, 4)]);
LOCAL_ALIGNED(16, float, dst0, [FFALIGN(MAX_SIZE, 4)]);
LOCAL_ALIGNED(16, float, dst1, [FFALIGN(MAX_SIZE, 4)]);
float coeff0 = (float)rnd() / (UINT_MAX >> 5) - 16.0f, coeff1 = coeff0;
declare_func_float(float, float *out, float *in, float coeff, const float *weights, int len);
randomize_float(src, MAX_SIZE);
coeff0 = call_ref(dst0, src, coeff0, ff_opus_deemph_weights, MAX_SIZE);
coeff1 = call_new(dst1, src, coeff1, ff_opus_deemph_weights, MAX_SIZE);
if (!float_near_abs_eps(coeff0, coeff1, EPS) ||
!float_near_abs_eps_array(dst0, dst1, EPS, MAX_SIZE))
fail();
bench_new(dst1, src, coeff1, ff_opus_deemph_weights, MAX_SIZE);
}
void checkasm_check_opusdsp(void)
{
OpusDSP ctx;
ff_opus_dsp_init(&ctx);
if (check_func(ctx.postfilter, "postfilter_15"))
test_postfilter(15);
report("postfilter_15");
if (check_func(ctx.postfilter, "postfilter_512"))
test_postfilter(512);
report("postfilter_512");
if (check_func(ctx.postfilter, "postfilter_1022"))
test_postfilter(1022);
report("postfilter_1022");
if (check_func(ctx.deemphasis, "deemphasis"))
test_deemphasis();
report("deemphasis");
}
+112
View File
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2015 Tiancheng "Timothy" Gu
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/pixblockdsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define BUF_UNITS 8
#define BUF_SIZE (BUF_UNITS * 128 + 8 * BUF_UNITS)
#define randomize_buffers() \
do { \
int i; \
for (i = 0; i < BUF_SIZE; i += 4) { \
uint32_t r = rnd(); \
AV_WN32A(src10 + i, r); \
AV_WN32A(src11 + i, r); \
r = rnd(); \
AV_WN32A(src20 + i, r); \
AV_WN32A(src21 + i, r); \
r = rnd(); \
AV_WN32A(dst0_ + i, r); \
AV_WN32A(dst1_ + i, r); \
} \
} while (0)
#define check_get_pixels(type, aligned) \
do { \
int i; \
declare_func(void, int16_t *block, const uint8_t *pixels, ptrdiff_t line_size); \
\
for (i = 0; i < BUF_UNITS; i++) { \
int src_offset = i * 64 * sizeof(type) + (aligned ? 8 : 1) * i; \
int dst_offset = i * 64; /* dst must be aligned */ \
randomize_buffers(); \
call_ref(dst0 + dst_offset, src10 + src_offset, 8); \
call_new(dst1 + dst_offset, src11 + src_offset, 8); \
if (memcmp(src10, src11, BUF_SIZE)|| memcmp(dst0, dst1, BUF_SIZE)) \
fail(); \
bench_new(dst1 + dst_offset, src11 + src_offset, 8); \
} \
} while (0)
#define check_diff_pixels(type, aligned) \
do { \
int i; \
declare_func(void, int16_t *restrict block, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride); \
\
for (i = 0; i < BUF_UNITS; i++) { \
int src_offset = i * 64 * sizeof(type) + (aligned ? 8 : 1) * i; \
int dst_offset = i * 64; /* dst must be aligned */ \
randomize_buffers(); \
call_ref(dst0 + dst_offset, src10 + src_offset, src20 + src_offset, 8); \
call_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8); \
if (memcmp(src10, src11, BUF_SIZE) || memcmp(src20, src21, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE)) \
fail(); \
bench_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8); \
} \
} while (0)
void checkasm_check_pixblockdsp(void)
{
LOCAL_ALIGNED_16(uint8_t, src10, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, src11, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, src20, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, src21, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst0_, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst1_, [BUF_SIZE]);
uint16_t *dst0 = (uint16_t *)dst0_;
uint16_t *dst1 = (uint16_t *)dst1_;
PixblockDSPContext h;
AVCodecContext avctx = {
.bits_per_raw_sample = 8,
};
ff_pixblockdsp_init(&h, &avctx);
if (check_func(h.get_pixels, "get_pixels"))
check_get_pixels(uint8_t, 1);
if (check_func(h.get_pixels_unaligned, "get_pixels_unaligned"))
check_get_pixels(uint8_t, 0);
report("get_pixels");
if (check_func(h.diff_pixels, "diff_pixels"))
check_diff_pixels(uint8_t, 1);
if (check_func(h.diff_pixels_unaligned, "diff_pixels_unaligned"))
check_diff_pixels(uint8_t, 0);
report("diff_pixels");
}
+185
View File
@@ -0,0 +1,185 @@
/****************************************************************************
* Copyright © 2022 Rémi Denis-Courmont.
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/
#include "libavutil/riscv/asm.S"
#if (__riscv_xlen == 64)
const fail_s_reg
.asciz "callee-saved integer register clobbered"
endconst
const fail_fs_reg
.asciz "callee-saved floating-point register clobbered"
endconst
const fail_rsvd_reg
.asciz "unallocatable register clobbered"
endconst
.section .tbss, "waT"
.align 3
.hidden checked_func
.hidden saved_regs
checked_func:
.quad 0
saved_regs:
/* Space to spill RA, SP, GP, TP, S0-S11 and FS0-FS11 */
.rept 4 + 12 + 12
.quad 0
.endr
func checkasm_set_function
lpad 0
la.tls.ie t0, checked_func
add t0, tp, t0
sd a0, (t0)
ret
endfunc
func checkasm_get_wrapper, v
lpad 0
addi sp, sp, -16
sd fp, (sp)
sd ra, 8(sp)
addi fp, sp, 16
call av_get_cpu_flags
andi t0, a0, 8 /* AV_CPU_FLAG_RVV_I32 */
lla a0, 3f
beqz t0, 1f
lla a0, 2f
1:
ld ra, 8(sp)
ld fp, (sp)
addi sp, sp, 16
ret
.option norvc
.align 2
2: /* <-- Entry point with the Vector extension --> */
lpad 0
/* Clobber the vectors */
vsetvli t0, zero, e32, m8, ta, ma
li t0, 0xdeadbeef
vmv.v.x v0, t0
vmv.v.x v8, t0
vmv.v.x v16, t0
vmv.v.x v24, t0
/* Clobber the vector configuration */
li t0, 0 /* Vector length: zero */
li t2, -4 /* Vector type: illegal */
vsetvl zero, t0, t2
csrwi vxrm, 3 /* Rounding mode: round-to-odd */
csrwi vxsat, 1 /* Saturation: encountered */
.align 2
3: /* <-- Entry point without the Vector extension --> */
lpad 0
/* Save RA, unallocatable and callee-saved registers */
la.tls.ie t0, saved_regs
add t0, tp, t0
sd ra, (t0)
sd sp, 8(t0)
sd gp, 16(t0)
sd tp, 24(t0)
.irp n, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
sd s\n, (32 + (16 * \n))(t0)
fsd fs\n, (40 + (16 * \n))(t0)
.endr
/* Clobber the stack space right below SP */
li t0, 0xdeadbeef1badf00d
.rept 16
addi sp, sp, -16
sd t0, (sp)
sd t0, 8(sp)
.endr
addi sp, sp, 256
/* Clobber the saved and temporary registers */
.irp n, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
.if (\n > 1 && \n < 7)
mv t\n, t0
.endif
fmv.d.x ft\n, t0
mv s\n, t0
fmv.d.x fs\n, t0
.endr
/* Call the tested function */
la.tls.ie t0, checked_func
add t0, tp, t0
ld t3, (t0)
sd zero, (t0)
jalr t3
/* Check special register values */
la.tls.ie t0, saved_regs
add t0, tp, t0
ld t1, 8(t0)
bne t1, sp, 5f
ld t1, 16(t0)
bne t1, gp, 5f
ld t1, 24(t0) // If TP was corrupted, we probably will have...
bne t1, tp, 5f // ...already crashed before we even get here.
/* Check value of saved registers */
li t0, 0xdeadbeef1badf00d
.irp n, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
bne t0, s\n, 6f
#ifdef __riscv_float_abi_double
/* TODO: check float ABI single too */
fmv.x.d t1, fs\n
bne t0, t1, 7f
#endif
.endr
4:
/* Restore RA and saved registers */
la.tls.ie t0, saved_regs
add t0, tp, t0
ld ra, (t0)
.irp n, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
ld s\n, (32 + (16 * \n))(t0)
fld fs\n, (40 + (16 * \n))(t0)
.endr
ret
5:
lla a0, fail_rsvd_reg
call checkasm_fail_func
tail abort /* The test harness would probably crash anyway */
6:
lla a0, fail_s_reg
call checkasm_fail_func
j 4b
7:
lla a0, fail_fs_reg
call checkasm_fail_func
j 4b
endfunc
#endif
+89
View File
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2024 Institue of Software Chinese Academy of Sciences (ISCAS).
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/rv34dsp.h"
#include "checkasm.h"
#define BUF_SIZE 1024
#define randomize(buf, len) \
do { \
for (int i = 0; i < len; i++) \
buf[i] = rnd(); \
} while (0)
static void test_rv34_inv_transform_dc(RV34DSPContext *s) {
declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t *block);
if (check_func(s->rv34_inv_transform_dc, "rv34_inv_transform_dc")) {
LOCAL_ALIGNED_16(int16_t, p1, [BUF_SIZE]);
LOCAL_ALIGNED_16(int16_t, p2, [BUF_SIZE]);
randomize(p1, BUF_SIZE);
memcpy(p2, p1, BUF_SIZE * sizeof(*p1));
call_ref(p1);
call_new(p2);
if (memcmp(p1, p2, BUF_SIZE * sizeof (*p1)) != 0) {
fail();
}
bench_new(p1);
}
report("rv34_inv_transform_dc");
}
static void test_rv34_idct_dc_add(RV34DSPContext *s) {
declare_func(void, uint8_t *dst, ptrdiff_t stride, int dc);
if (check_func(s->rv34_idct_dc_add, "rv34_idct_dc_add")) {
LOCAL_ALIGNED_16(uint8_t, p1, [BUF_SIZE]);
LOCAL_ALIGNED_16(uint8_t, p2, [BUF_SIZE]);
randomize(p1, BUF_SIZE);
memcpy(p2, p1, BUF_SIZE * sizeof(*p1));
call_ref(p1, 4, 5);
call_new(p2, 4, 5);
if (memcmp(p1, p2, BUF_SIZE * sizeof (*p1)) != 0) {
fail();
}
bench_new(p1, 4, 5);
}
report("rv34_idct_dc_add");
}
void checkasm_check_rv34dsp(void)
{
RV34DSPContext s = { 0 };
ff_rv34dsp_init(&s);
test_rv34_inv_transform_dc(&s);
test_rv34_idct_dc_add(&s);
}
+75
View File
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2024 Institue of Software Chinese Academy of Sciences (ISCAS).
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include <stdint.h>
#include "checkasm.h"
#include "libavcodec/rv40dsp.c"
#include "libavutil/mem_internal.h"
#define randomize_buffers() \
do { \
for (int i = 0; i < 16*18*2; i++) \
src[i] = rnd() & 0x3; \
} while (0)
static void check_chroma_mc(void)
{
RV34DSPContext h;
LOCAL_ALIGNED_32(uint8_t, src, [16 * 18 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0, [16 * 18 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1, [16 * 18 * 2]);
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const uint8_t *src,
ptrdiff_t stride, int h, int x, int y);
ff_rv40dsp_init(&h);
randomize_buffers();
for (int size = 0; size < 2; size++) {
#define CHECK_CHROMA_MC(name) \
do { \
if (check_func(h.name## _pixels_tab[size], #name "_mc%d", 1 << (3 - size))) { \
for (int x = 0; x < 2; x++) { \
for (int y = 0; y < 2; y++) { \
memcpy(dst0, src, 16 * 18); \
memcpy(dst1, src, 16 * 18); \
call_ref(dst0, src, 16, 16, x, y); \
call_new(dst1, src, 16, 16, x, y); \
if (memcmp(dst0, dst1, 16 * 16)) { \
fprintf(stderr, #name ": x:%i, y:%i\n", x, y); \
fail(); \
} \
bench_new(dst1, src, 16, 16, x, y); \
} \
} \
} \
} while (0)
CHECK_CHROMA_MC(put_chroma);
CHECK_CHROMA_MC(avg_chroma);
}
}
void checkasm_check_rv40dsp(void)
{
check_chroma_mc();
report("chroma_mc");
}
+305
View File
@@ -0,0 +1,305 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "libavutil/mem_internal.h"
#include "libavcodec/sbrdsp.h"
#include <float.h>
#include "checkasm.h"
#define randomize(buf, len) do { \
int i; \
for (i = 0; i < len; i++) { \
const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \
(buf)[i] = f; \
} \
} while (0)
#define EPS 0.0001
static void test_sum64x5(void)
{
LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]);
declare_func(void, INTFLOAT *z);
randomize((INTFLOAT *)dst0, 64 + 256);
memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT));
call_ref(dst0);
call_new(dst1);
if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256))
fail();
bench_new(dst1);
}
static void test_sum_square(void)
{
INTFLOAT res0;
INTFLOAT res1;
LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]);
double t = 4 * 256;
declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n);
randomize((INTFLOAT *)src, 256 * 2);
res0 = call_ref(src, 256);
res1 = call_new(src, 256);
if (!float_near_abs_eps(res0, res1, t * 2 * FLT_EPSILON))
fail();
bench_new(src, 256);
}
static void test_neg_odd_64(void)
{
LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
declare_func(void, INTFLOAT *x);
randomize((INTFLOAT *)dst0, 64);
memcpy(dst1, dst0, (64) * sizeof(INTFLOAT));
call_ref(dst0);
call_new(dst1);
if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
fail();
bench_new(dst1);
}
static void test_qmf_pre_shuffle(void)
{
LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
declare_func(void, INTFLOAT *z);
randomize((INTFLOAT *)dst0, 128);
memcpy(dst1, dst0, (128) * sizeof(INTFLOAT));
call_ref(dst0);
call_new(dst1);
if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
fail();
bench_new(dst1);
}
static void test_qmf_post_shuffle(void)
{
LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]);
declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z);
randomize((INTFLOAT *)src, 64);
call_ref(dst0, src);
call_new(dst1, src);
if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64))
fail();
bench_new(dst1, src);
}
static void test_qmf_deint_neg(void)
{
LOCAL_ALIGNED_16(INTFLOAT, src, [64]);
LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]);
declare_func(void, INTFLOAT *v, const INTFLOAT *src);
randomize((INTFLOAT *)src, 64);
call_ref(dst0, src);
call_new(dst1, src);
if (!float_near_abs_eps_array(dst0, dst1, EPS, 64))
fail();
bench_new(dst1, src);
}
static void test_qmf_deint_bfly(void)
{
LOCAL_ALIGNED_16(INTFLOAT, src0, [64]);
LOCAL_ALIGNED_16(INTFLOAT, src1, [64]);
LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]);
declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1);
memset(dst0, 0, 128 * sizeof(INTFLOAT));
memset(dst1, 0, 128 * sizeof(INTFLOAT));
randomize((INTFLOAT *)src0, 64);
randomize((INTFLOAT *)src1, 64);
call_ref(dst0, src0, src1);
call_new(dst1, src0, src1);
if (!float_near_abs_eps_array(dst0, dst1, EPS, 128))
fail();
bench_new(dst1, src0, src1);
}
static void test_autocorrelate(void)
{
LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]);
declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]);
memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT));
randomize((INTFLOAT *)src, 80);
call_ref(src, dst0);
call_new(src, dst1);
if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2))
fail();
bench_new(src, dst1);
}
static void test_hf_gen(void)
{
LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]);
LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]);
LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX;
int i;
declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2],
const INTFLOAT alpha0[2], const INTFLOAT alpha1[2],
INTFLOAT bw, int start, int end);
randomize((INTFLOAT *)low, 128 * 2);
randomize((INTFLOAT *)alpha0, 2);
randomize((INTFLOAT *)alpha1, 2);
for (i = 2; i < 64; i += 2) {
memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT));
memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT));
call_ref(dst0, low, alpha0, alpha1, bw, i, 128);
call_new(dst1, low, alpha0, alpha1, bw, i, 128);
if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
fail();
bench_new(dst1, low, alpha0, alpha1, bw, i, 128);
}
}
static void test_hf_g_filt(void)
{
LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]);
LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]);
LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2],
const INTFLOAT *g_filt, int m_max, intptr_t ixh);
randomize((INTFLOAT *)high, 128 * 40 * 2);
randomize((INTFLOAT *)g_filt, 128);
call_ref(dst0, high, g_filt, 128, 20);
call_new(dst1, high, g_filt, 128, 20);
if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
fail();
bench_new(dst1, high, g_filt, 128, 20);
}
static void test_hf_apply_noise(const SBRDSPContext *sbrdsp)
{
LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]);
LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]);
LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]);
LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]);
int noise = 0x2a;
int i, j;
declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m,
const AAC_FLOAT *q_filt, int noise,
int kx, int m_max);
randomize((INTFLOAT *)ref, 128 * 2);
for (int i = 0; i < 128; i++)
s_m[i] = (rnd() & 1) ? ((INTFLOAT)rnd() / UINT_MAX) : (INTFLOAT)0;
randomize((INTFLOAT *)q_filt, 128);
for (i = 0; i < 4; i++) {
if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) {
for (j = 0; j < 2; j++) {
memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT));
memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT));
call_ref(dst0, s_m, q_filt, noise, j, 128);
call_new(dst1, s_m, q_filt, noise, j, 128);
if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2))
fail();
bench_new(dst1, s_m, q_filt, noise, j, 128);
}
}
}
}
void checkasm_check_sbrdsp(void)
{
SBRDSPContext sbrdsp;
ff_sbrdsp_init(&sbrdsp);
if (check_func(sbrdsp.sum64x5, "sum64x5"))
test_sum64x5();
report("sum64x5");
if (check_func(sbrdsp.sum_square, "sum_square"))
test_sum_square();
report("sum_square");
if (check_func(sbrdsp.neg_odd_64, "neg_odd_64"))
test_neg_odd_64();
report("neg_odd_64");
if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle"))
test_qmf_pre_shuffle();
report("qmf_pre_shuffle");
if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle"))
test_qmf_post_shuffle();
report("qmf_post_shuffle");
if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg"))
test_qmf_deint_neg();
report("qmf_deint_neg");
if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly"))
test_qmf_deint_bfly();
report("qmf_deint_bfly");
if (check_func(sbrdsp.autocorrelate, "autocorrelate"))
test_autocorrelate();
report("autocorrelate");
if (check_func(sbrdsp.hf_gen, "hf_gen"))
test_hf_gen();
report("hf_gen");
if (check_func(sbrdsp.hf_g_filt, "hf_g_filt"))
test_hf_g_filt();
report("hf_g_filt");
test_hf_apply_noise(&sbrdsp);
report("hf_apply_noise");
}
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 "libavutil/mem_internal.h"
#include "libavcodec/svq1encdsp.h"
#include "checkasm.h"
#define BUF_SIZE 1024
#define MIN_VAL (-255 - 5 * 127)
#define MAX_VAL ( 255 + 5 * 128)
#define randomize(buf, len) \
do { \
for (int i = 0; i < len; i++) \
buf[i] = ((rnd() % (MAX_VAL - MIN_VAL + 1)) + MIN_VAL); \
} while (0)
static void test_ssd_int8_vs_int16(SVQ1EncDSPContext *s) {
declare_func(int, const int8_t *pix1, const int16_t *pix2, intptr_t size);
int r1, r2;
if (check_func(s->ssd_int8_vs_int16, "ssd_int8_vs_int16")) {
LOCAL_ALIGNED_4(int8_t, p1, [BUF_SIZE]);
LOCAL_ALIGNED_16(int16_t, p2, [BUF_SIZE]);
randomize(p1, BUF_SIZE);
randomize(p2, BUF_SIZE);
r1 = call_ref(p1, p2, BUF_SIZE);
r2 = call_new(p1, p2, BUF_SIZE);
if (r1 != r2) {
fail();
}
bench_new(p1, p2, BUF_SIZE);
}
report("ssd_int8_vs_int16");
}
void checkasm_check_svq1enc(void)
{
SVQ1EncDSPContext s = { 0 };
ff_svq1enc_init(&s);
test_ssd_int8_vs_int16(&s);
}
+410
View File
@@ -0,0 +1,410 @@
/*
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavutil/pixdesc.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
int j; \
for (j = 0; j < size; j+=4) \
AV_WN32(buf + j, rnd()); \
} while (0)
static const int planar_fmts[] = {
AV_PIX_FMT_GBRP,
AV_PIX_FMT_GBRP9BE,
AV_PIX_FMT_GBRP9LE,
AV_PIX_FMT_GBRP10BE,
AV_PIX_FMT_GBRP10LE,
AV_PIX_FMT_GBRP12BE,
AV_PIX_FMT_GBRP12LE,
AV_PIX_FMT_GBRP14BE,
AV_PIX_FMT_GBRP14LE,
AV_PIX_FMT_GBRAP,
AV_PIX_FMT_GBRAP10BE,
AV_PIX_FMT_GBRAP10LE,
AV_PIX_FMT_GBRAP12BE,
AV_PIX_FMT_GBRAP12LE,
AV_PIX_FMT_GBRP16BE,
AV_PIX_FMT_GBRP16LE,
AV_PIX_FMT_GBRAP16BE,
AV_PIX_FMT_GBRAP16LE,
AV_PIX_FMT_GBRPF32BE,
AV_PIX_FMT_GBRPF32LE,
AV_PIX_FMT_GBRAPF32BE,
AV_PIX_FMT_GBRAPF32LE
};
static void check_output_yuv2gbrp(void)
{
struct SwsContext *ctx;
const AVPixFmtDescriptor *desc;
int fmi, fsi, isi, i;
int dstW, byte_size, luma_filter_size, chr_filter_size;
#define LARGEST_FILTER 16
#define FILTER_SIZES 4
static const int filter_sizes[] = {1, 4, 8, 16};
#define LARGEST_INPUT_SIZE 512
#define INPUT_SIZES 6
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
uint8_t *dst0[4];
uint8_t *dst1[4];
declare_func(void, struct SwsContext *c, const int16_t *lumFilter,
const int16_t **lumSrcx, int lumFilterSize,
const int16_t *chrFilter, const int16_t **chrUSrcx,
const int16_t **chrVSrcx, int chrFilterSize,
const int16_t **alpSrcx, uint8_t **dest,
int dstW, int y);
const int16_t *luma[LARGEST_FILTER];
const int16_t *chru[LARGEST_FILTER];
const int16_t *chrv[LARGEST_FILTER];
const int16_t *alpha[LARGEST_FILTER];
LOCAL_ALIGNED_8(int16_t, luma_filter, [LARGEST_FILTER]);
LOCAL_ALIGNED_8(int16_t, chr_filter, [LARGEST_FILTER]);
LOCAL_ALIGNED_8(int32_t, src_y, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_u, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_v, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(uint8_t, dst0_r, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst0_g, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst0_b, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst0_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst1_r, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst1_g, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst1_b, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst1_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
randomize_buffers((uint8_t*)src_y, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_u, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_v, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_a, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)luma_filter, LARGEST_FILTER * sizeof(int16_t));
randomize_buffers((uint8_t*)chr_filter, LARGEST_FILTER * sizeof(int16_t));
dst0[0] = (uint8_t*)dst0_g;
dst0[1] = (uint8_t*)dst0_b;
dst0[2] = (uint8_t*)dst0_r;
dst0[3] = (uint8_t*)dst0_a;
dst1[0] = (uint8_t*)dst1_g;
dst1[1] = (uint8_t*)dst1_b;
dst1[2] = (uint8_t*)dst1_r;
dst1[3] = (uint8_t*)dst1_a;
for (i = 0; i < LARGEST_FILTER; i++) {
luma[i] = (int16_t *)(src_y + i*LARGEST_INPUT_SIZE);
chru[i] = (int16_t *)(src_u + i*LARGEST_INPUT_SIZE);
chrv[i] = (int16_t *)(src_v + i*LARGEST_INPUT_SIZE);
alpha[i] = (int16_t *)(src_a + i*LARGEST_INPUT_SIZE);
}
ctx = sws_alloc_context();
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
ctx->flags |= SWS_FULL_CHR_H_INT;
for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) {
for (fsi = 0; fsi < FILTER_SIZES; fsi++) {
for (isi = 0; isi < INPUT_SIZES; isi++ ) {
desc = av_pix_fmt_desc_get(planar_fmts[fmi]);
ctx->dstFormat = planar_fmts[fmi];
dstW = input_sizes[isi];
luma_filter_size = filter_sizes[fsi];
chr_filter_size = filter_sizes[fsi];
if (desc->comp[0].depth > 16) {
byte_size = 4;
} else if (desc->comp[0].depth > 8) {
byte_size = 2;
} else {
byte_size = 1;
}
ff_sws_init_scale(ctx);
if (check_func(ctx->yuv2anyX, "yuv2%s_full_X_%d_%d", desc->name, luma_filter_size, dstW)) {
for (i = 0; i < 4; i ++) {
memset(dst0[i], 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
memset(dst1[i], 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
}
call_ref(ctx, luma_filter, luma, luma_filter_size,
chr_filter, chru, chrv, chr_filter_size,
alpha, dst0, dstW, 0);
call_new(ctx, luma_filter, luma, luma_filter_size,
chr_filter, chru, chrv, chr_filter_size,
alpha, dst1, dstW, 0);
if (memcmp(dst0[0], dst1[0], dstW * byte_size) ||
memcmp(dst0[1], dst1[1], dstW * byte_size) ||
memcmp(dst0[2], dst1[2], dstW * byte_size) ||
memcmp(dst0[3], dst1[3], dstW * byte_size) )
fail();
bench_new(ctx, luma_filter, luma, luma_filter_size,
chr_filter, chru, chrv, chr_filter_size,
alpha, dst1, dstW, 0);
}
}
}
}
sws_freeContext(ctx);
}
#undef LARGEST_INPUT_SIZE
#undef INPUT_SIZES
static void check_input_planar_rgb_to_y(void)
{
struct SwsContext *ctx;
const AVPixFmtDescriptor *desc;
int fmi, isi;
int dstW, byte_size;
#define LARGEST_INPUT_SIZE 512
#define INPUT_SIZES 6
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
const uint8_t *src[4];
int32_t rgb2yuv[9] = {0};
declare_func(void, uint8_t *dst, const uint8_t *src[4],
int w, int32_t *rgb2yuv, void *opaque);
LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(uint8_t, dst0_y, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst1_y, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t));
src[0] = (uint8_t*)src_g;
src[1] = (uint8_t*)src_b;
src[2] = (uint8_t*)src_r;
src[3] = (uint8_t*)src_a;
ctx = sws_alloc_context();
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) {
for (isi = 0; isi < INPUT_SIZES; isi++ ) {
desc = av_pix_fmt_desc_get(planar_fmts[fmi]);
ctx->srcFormat = planar_fmts[fmi];
ctx->dstFormat = AV_PIX_FMT_YUVA444P16;
byte_size = 2;
dstW = input_sizes[isi];
ff_sws_init_scale(ctx);
if(check_func(ctx->readLumPlanar, "planar_%s_to_y_%d", desc->name, dstW)) {
memset(dst0_y, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
memset(dst1_y, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
call_ref(dst0_y, src, dstW, rgb2yuv, NULL);
call_new(dst1_y, src, dstW, rgb2yuv, NULL);
if (memcmp(dst0_y, dst1_y, dstW * byte_size))
fail();
bench_new(dst1_y, src, dstW, rgb2yuv, NULL);
}
}
}
sws_freeContext(ctx);
}
#undef LARGEST_INPUT_SIZE
#undef INPUT_SIZES
static void check_input_planar_rgb_to_uv(void)
{
struct SwsContext *ctx;
const AVPixFmtDescriptor *desc;
int fmi, isi;
int dstW, byte_size;
#define LARGEST_INPUT_SIZE 512
#define INPUT_SIZES 6
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
const uint8_t *src[4];
int32_t rgb2yuv[9] = {0};
declare_func(void, uint8_t *dstU, uint8_t *dstV,
const uint8_t *src[4], int w, int32_t *rgb2yuv, void *opaque);
LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(uint8_t, dst0_u, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst0_v, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst1_u, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst1_v, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t));
src[0] = (uint8_t*)src_g;
src[1] = (uint8_t*)src_b;
src[2] = (uint8_t*)src_r;
src[3] = (uint8_t*)src_a;
ctx = sws_alloc_context();
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) {
for (isi = 0; isi < INPUT_SIZES; isi++ ) {
desc = av_pix_fmt_desc_get(planar_fmts[fmi]);
ctx->srcFormat = planar_fmts[fmi];
ctx->dstFormat = AV_PIX_FMT_YUVA444P16;
byte_size = 2;
dstW = input_sizes[isi];
ff_sws_init_scale(ctx);
if(check_func(ctx->readChrPlanar, "planar_%s_to_uv_%d", desc->name, dstW)) {
memset(dst0_u, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
memset(dst0_v, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
memset(dst1_u, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
memset(dst1_v, 0xFF, LARGEST_INPUT_SIZE * sizeof(int32_t));
call_ref(dst0_u, dst0_v, src, dstW, rgb2yuv, NULL);
call_new(dst1_u, dst1_v, src, dstW, rgb2yuv, NULL);
if (memcmp(dst0_u, dst1_u, dstW * byte_size) ||
memcmp(dst0_v, dst1_v, dstW * byte_size))
fail();
bench_new(dst1_u, dst1_v, src, dstW, rgb2yuv, NULL);
}
}
}
sws_freeContext(ctx);
}
#undef LARGEST_INPUT_SIZE
#undef INPUT_SIZES
static void check_input_planar_rgb_to_a(void)
{
struct SwsContext *ctx;
const AVPixFmtDescriptor *desc;
int fmi, isi;
int dstW, byte_size;
#define LARGEST_INPUT_SIZE 512
#define INPUT_SIZES 6
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
const uint8_t *src[4];
int32_t rgb2yuv[9] = {0};
declare_func(void, uint8_t *dst, const uint8_t *src[4],
int w, int32_t *rgb2yuv, void *opaque);
LOCAL_ALIGNED_8(int32_t, src_r, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_g, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_b, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(int32_t, src_a, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(uint8_t, dst0_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
LOCAL_ALIGNED_8(uint8_t, dst1_a, [LARGEST_INPUT_SIZE * sizeof(int32_t)]);
randomize_buffers((uint8_t*)src_r, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_g, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_b, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)src_a, LARGEST_INPUT_SIZE * sizeof(int32_t));
randomize_buffers((uint8_t*)rgb2yuv, 9 * sizeof(int32_t));
src[0] = (uint8_t*)src_g;
src[1] = (uint8_t*)src_b;
src[2] = (uint8_t*)src_r;
src[3] = (uint8_t*)src_a;
ctx = sws_alloc_context();
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
for (fmi = 0; fmi < FF_ARRAY_ELEMS(planar_fmts); fmi++) {
for (isi = 0; isi < INPUT_SIZES; isi++ ) {
desc = av_pix_fmt_desc_get(planar_fmts[fmi]);
if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
continue;
ctx->srcFormat = planar_fmts[fmi];
ctx->dstFormat = AV_PIX_FMT_YUVA444P16;
byte_size = 2;
dstW = input_sizes[isi];
ff_sws_init_scale(ctx);
if(check_func(ctx->readAlpPlanar, "planar_%s_to_a_%d", desc->name, dstW)) {
memset(dst0_a, 0x00, LARGEST_INPUT_SIZE * sizeof(int32_t));
memset(dst1_a, 0x00, LARGEST_INPUT_SIZE * sizeof(int32_t));
call_ref(dst0_a, src, dstW, rgb2yuv, NULL);
call_new(dst1_a, src, dstW, rgb2yuv, NULL);
if (memcmp(dst0_a, dst1_a, dstW * byte_size))
fail();
bench_new(dst1_a, src, dstW, rgb2yuv, NULL);
}
}
}
sws_freeContext(ctx);
}
void checkasm_check_sw_gbrp(void)
{
check_output_yuv2gbrp();
report("output_yuv2gbrp");
check_input_planar_rgb_to_y();
report("input_planar_rgb_y");
check_input_planar_rgb_to_uv();
report("input_planar_rgb_uv");
check_input_planar_rgb_to_a();
report("input_planar_rgb_a");
}
+134
View File
@@ -0,0 +1,134 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "checkasm.h"
static void check_lumConvertRange(int from)
{
const char *func_str = from ? "lumRangeFromJpeg" : "lumRangeToJpeg";
#define LARGEST_INPUT_SIZE 512
#define INPUT_SIZES 6
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
struct SwsContext *ctx;
LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE]);
declare_func(void, int16_t *dst, int width);
ctx = sws_alloc_context();
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
ctx->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P;
ctx->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
ctx->srcRange = from;
ctx->dstRange = !from;
for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) {
int width = input_sizes[dstWi];
for (int i = 0; i < width; i++) {
uint8_t r = rnd();
dst0[i] = (int16_t) r << 7;
dst1[i] = (int16_t) r << 7;
}
ff_sws_init_scale(ctx);
if (check_func(ctx->lumConvertRange, "%s_%d", func_str, width)) {
call_ref(dst0, width);
call_new(dst1, width);
if (memcmp(dst0, dst1, width * sizeof(int16_t)))
fail();
bench_new(dst1, width);
}
}
sws_freeContext(ctx);
}
#undef LARGEST_INPUT_SIZE
#undef INPUT_SIZES
static void check_chrConvertRange(int from)
{
const char *func_str = from ? "chrRangeFromJpeg" : "chrRangeToJpeg";
#define LARGEST_INPUT_SIZE 512
#define INPUT_SIZES 6
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
struct SwsContext *ctx;
LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_32(int16_t, dstU1, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_32(int16_t, dstV1, [LARGEST_INPUT_SIZE]);
declare_func(void, int16_t *dstU, int16_t *dstV, int width);
ctx = sws_alloc_context();
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
ctx->srcFormat = from ? AV_PIX_FMT_YUVJ444P : AV_PIX_FMT_YUV444P;
ctx->dstFormat = from ? AV_PIX_FMT_YUV444P : AV_PIX_FMT_YUVJ444P;
ctx->srcRange = from;
ctx->dstRange = !from;
for (int dstWi = 0; dstWi < INPUT_SIZES; dstWi++) {
int width = input_sizes[dstWi];
for (int i = 0; i < width; i++) {
uint8_t r = rnd();
dstU0[i] = (int16_t) r << 7;
dstV0[i] = (int16_t) r << 7;
dstU1[i] = (int16_t) r << 7;
dstV1[i] = (int16_t) r << 7;
}
ff_sws_init_scale(ctx);
if (check_func(ctx->chrConvertRange, "%s_%d", func_str, width)) {
call_ref(dstU0, dstV0, width);
call_new(dstU1, dstV1, width);
if (memcmp(dstU0, dstU1, width * sizeof(int16_t)) ||
memcmp(dstV0, dstV1, width * sizeof(int16_t)))
fail();
bench_new(dstU1, dstV1, width);
}
}
sws_freeContext(ctx);
}
#undef LARGEST_INPUT_SIZE
#undef INPUT_SIZES
void checkasm_check_sw_range_convert(void)
{
check_lumConvertRange(1);
report("lumRangeFromJpeg");
check_chrConvertRange(1);
report("chrRangeFromJpeg");
check_lumConvertRange(0);
report("lumRangeToJpeg");
check_chrConvertRange(0);
report("chrRangeToJpeg");
}
+497
View File
@@ -0,0 +1,497 @@
/*
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavutil/pixdesc.h"
#include "libswscale/rgb2rgb.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
int j; \
for (j = 0; j < size; j+=4) \
AV_WN32(buf + j, rnd()); \
} while (0)
static const uint8_t width[] = {12, 16, 20, 32, 36, 128};
static const struct {uint8_t w, h, s;} planes[] = {
{12,16,12}, {16,16,16}, {20,23,25}, {32,18,48}, {8,128,16}, {128,128,128}
};
#define MAX_STRIDE 128
#define MAX_HEIGHT 128
static void check_shuffle_bytes(void * func, const char * report)
{
int i;
LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE]);
LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE]);
LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE]);
declare_func(void, const uint8_t *src, uint8_t *dst, int src_size);
memset(dst0, 0, MAX_STRIDE);
memset(dst1, 0, MAX_STRIDE);
randomize_buffers(src0, MAX_STRIDE);
memcpy(src1, src0, MAX_STRIDE);
if (check_func(func, "%s", report)) {
for (i = 0; i < 6; i ++) {
call_ref(src0, dst0, width[i]);
call_new(src1, dst1, width[i]);
if (memcmp(dst0, dst1, MAX_STRIDE))
fail();
}
bench_new(src0, dst0, width[5]);
}
}
static void check_uyvy_to_422p(void)
{
int i;
LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE * MAX_HEIGHT * 2]);
LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE * MAX_HEIGHT * 2]);
LOCAL_ALIGNED_32(uint8_t, dst_y_0, [MAX_STRIDE * MAX_HEIGHT]);
LOCAL_ALIGNED_32(uint8_t, dst_y_1, [MAX_STRIDE * MAX_HEIGHT]);
LOCAL_ALIGNED_32(uint8_t, dst_u_0, [(MAX_STRIDE/2) * MAX_HEIGHT]);
LOCAL_ALIGNED_32(uint8_t, dst_u_1, [(MAX_STRIDE/2) * MAX_HEIGHT]);
LOCAL_ALIGNED_32(uint8_t, dst_v_0, [(MAX_STRIDE/2) * MAX_HEIGHT]);
LOCAL_ALIGNED_32(uint8_t, dst_v_1, [(MAX_STRIDE/2) * MAX_HEIGHT]);
declare_func(void, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
const uint8_t *src, int width, int height,
int lumStride, int chromStride, int srcStride);
randomize_buffers(src0, MAX_STRIDE * MAX_HEIGHT * 2);
memcpy(src1, src0, MAX_STRIDE * MAX_HEIGHT * 2);
if (check_func(uyvytoyuv422, "uyvytoyuv422")) {
for (i = 0; i < 6; i ++) {
memset(dst_y_0, 0, MAX_STRIDE * MAX_HEIGHT);
memset(dst_y_1, 0, MAX_STRIDE * MAX_HEIGHT);
memset(dst_u_0, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
memset(dst_u_1, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
memset(dst_v_0, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
memset(dst_v_1, 0, (MAX_STRIDE/2) * MAX_HEIGHT);
call_ref(dst_y_0, dst_u_0, dst_v_0, src0, planes[i].w, planes[i].h,
MAX_STRIDE, MAX_STRIDE / 2, planes[i].s);
call_new(dst_y_1, dst_u_1, dst_v_1, src1, planes[i].w, planes[i].h,
MAX_STRIDE, MAX_STRIDE / 2, planes[i].s);
if (memcmp(dst_y_0, dst_y_1, MAX_STRIDE * MAX_HEIGHT) ||
memcmp(dst_u_0, dst_u_1, (MAX_STRIDE/2) * MAX_HEIGHT) ||
memcmp(dst_v_0, dst_v_1, (MAX_STRIDE/2) * MAX_HEIGHT))
fail();
}
bench_new(dst_y_1, dst_u_1, dst_v_1, src1, planes[5].w, planes[5].h,
MAX_STRIDE, MAX_STRIDE / 2, planes[5].s);
}
}
#define NUM_LINES 5
#define MAX_LINE_SIZE 1920
#define BUFSIZE (NUM_LINES * MAX_LINE_SIZE)
static int cmp_off_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int accuracy)
{
for (size_t i = 0; i < n; i++) {
if (abs(ref[i] - test[i]) > accuracy)
return 1;
}
return 0;
}
static void check_rgb24toyv12(struct SwsContext *ctx)
{
static const int input_sizes[] = {16, 128, 512, MAX_LINE_SIZE, -MAX_LINE_SIZE};
LOCAL_ALIGNED_32(uint8_t, src, [BUFSIZE * 3]);
LOCAL_ALIGNED_32(uint8_t, buf_y_0, [BUFSIZE]);
LOCAL_ALIGNED_32(uint8_t, buf_y_1, [BUFSIZE]);
LOCAL_ALIGNED_32(uint8_t, buf_u_0, [BUFSIZE / 4]);
LOCAL_ALIGNED_32(uint8_t, buf_u_1, [BUFSIZE / 4]);
LOCAL_ALIGNED_32(uint8_t, buf_v_0, [BUFSIZE / 4]);
LOCAL_ALIGNED_32(uint8_t, buf_v_1, [BUFSIZE / 4]);
declare_func(void, const uint8_t *src, uint8_t *ydst, uint8_t *udst,
uint8_t *vdst, int width, int height, int lumStride,
int chromStride, int srcStride, int32_t *rgb2yuv);
randomize_buffers(src, BUFSIZE * 3);
for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
int input_size = input_sizes[isi];
int negstride = input_size < 0;
const char *negstride_str = negstride ? "_negstride" : "";
int width = FFABS(input_size);
int linesize = width + 32;
/* calculate height based on specified width to use the entire buffer. */
int height = (BUFSIZE / linesize) & ~1;
uint8_t *src0 = src;
uint8_t *src1 = src;
uint8_t *dst_y_0 = buf_y_0;
uint8_t *dst_y_1 = buf_y_1;
uint8_t *dst_u_0 = buf_u_0;
uint8_t *dst_u_1 = buf_u_1;
uint8_t *dst_v_0 = buf_v_0;
uint8_t *dst_v_1 = buf_v_1;
if (negstride) {
src0 += (height - 1) * (linesize * 3);
src1 += (height - 1) * (linesize * 3);
dst_y_0 += (height - 1) * linesize;
dst_y_1 += (height - 1) * linesize;
dst_u_0 += ((height / 2) - 1) * (linesize / 2);
dst_u_1 += ((height / 2) - 1) * (linesize / 2);
dst_v_0 += ((height / 2) - 1) * (linesize / 2);
dst_v_1 += ((height / 2) - 1) * (linesize / 2);
linesize *= -1;
}
if (check_func(ff_rgb24toyv12, "rgb24toyv12_%d_%d%s", width, height, negstride_str)) {
memset(buf_y_0, 0xFF, BUFSIZE);
memset(buf_y_1, 0xFF, BUFSIZE);
memset(buf_u_0, 0xFF, BUFSIZE / 4);
memset(buf_u_1, 0xFF, BUFSIZE / 4);
memset(buf_v_0, 0xFF, BUFSIZE / 4);
memset(buf_v_1, 0xFF, BUFSIZE / 4);
call_ref(src0, dst_y_0, dst_u_0, dst_v_0, width, height,
linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
call_new(src1, dst_y_1, dst_u_1, dst_v_1, width, height,
linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
if (cmp_off_by_n(buf_y_0, buf_y_1, BUFSIZE, 1) ||
cmp_off_by_n(buf_u_0, buf_u_1, BUFSIZE / 4, 1) ||
cmp_off_by_n(buf_v_0, buf_v_1, BUFSIZE / 4, 1))
fail();
bench_new(src1, dst_y_1, dst_u_1, dst_v_1, width, height,
linesize, linesize / 2, linesize * 3, ctx->input_rgb2yuv_table);
}
}
}
#undef NUM_LINES
#undef MAX_LINE_SIZE
#undef BUFSIZE
static void check_interleave_bytes(void)
{
LOCAL_ALIGNED_16(uint8_t, src0_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
LOCAL_ALIGNED_16(uint8_t, src1_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
LOCAL_ALIGNED_16(uint8_t, dst0_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
LOCAL_ALIGNED_16(uint8_t, dst1_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
// Intentionally using unaligned buffers, as this function doesn't have
// any alignment requirements.
uint8_t *src0 = src0_buf + 1;
uint8_t *src1 = src1_buf + 1;
uint8_t *dst0 = dst0_buf + 2;
uint8_t *dst1 = dst1_buf + 2;
declare_func(void, const uint8_t *, const uint8_t *,
uint8_t *, int, int, int, int, int);
randomize_buffers(src0, MAX_STRIDE * MAX_HEIGHT);
randomize_buffers(src1, MAX_STRIDE * MAX_HEIGHT);
if (check_func(interleaveBytes, "interleave_bytes")) {
for (int i = 0; i <= 16; i++) {
// Try all widths [1,16], and try one random width.
int w = i > 0 ? i : (1 + (rnd() % (MAX_STRIDE-2)));
int h = 1 + (rnd() % (MAX_HEIGHT-2));
int src0_offset = 0, src0_stride = MAX_STRIDE;
int src1_offset = 0, src1_stride = MAX_STRIDE;
int dst_offset = 0, dst_stride = 2 * MAX_STRIDE;
memset(dst0, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
memset(dst1, 0, 2 * MAX_STRIDE * MAX_HEIGHT);
// Try different combinations of negative strides
if (i & 1) {
src0_offset = (h-1)*src0_stride;
src0_stride = -src0_stride;
}
if (i & 2) {
src1_offset = (h-1)*src1_stride;
src1_stride = -src1_stride;
}
if (i & 4) {
dst_offset = (h-1)*dst_stride;
dst_stride = -dst_stride;
}
call_ref(src0 + src0_offset, src1 + src1_offset, dst0 + dst_offset,
w, h, src0_stride, src1_stride, dst_stride);
call_new(src0 + src0_offset, src1 + src1_offset, dst1 + dst_offset,
w, h, src0_stride, src1_stride, dst_stride);
// Check a one pixel-pair edge around the destination area,
// to catch overwrites past the end.
checkasm_check(uint8_t, dst0, 2*MAX_STRIDE, dst1, 2*MAX_STRIDE,
2 * w + 2, h + 1, "dst");
}
bench_new(src0, src1, dst1, 127, MAX_HEIGHT,
MAX_STRIDE, MAX_STRIDE, 2*MAX_STRIDE);
}
if (check_func(interleaveBytes, "interleave_bytes_aligned")) {
// Bench the function in a more typical case, with aligned
// buffers and widths.
bench_new(src0_buf, src1_buf, dst1_buf, 128, MAX_HEIGHT,
MAX_STRIDE, MAX_STRIDE, 2*MAX_STRIDE);
}
}
static void check_deinterleave_bytes(void)
{
LOCAL_ALIGNED_16(uint8_t, src_buf, [2*MAX_STRIDE*MAX_HEIGHT+2]);
LOCAL_ALIGNED_16(uint8_t, dst0_u_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
LOCAL_ALIGNED_16(uint8_t, dst0_v_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
LOCAL_ALIGNED_16(uint8_t, dst1_u_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
LOCAL_ALIGNED_16(uint8_t, dst1_v_buf, [MAX_STRIDE*MAX_HEIGHT+1]);
// Intentionally using unaligned buffers, as this function doesn't have
// any alignment requirements.
uint8_t *src = src_buf + 2;
uint8_t *dst0_u = dst0_u_buf + 1;
uint8_t *dst0_v = dst0_v_buf + 1;
uint8_t *dst1_u = dst1_u_buf + 1;
uint8_t *dst1_v = dst1_v_buf + 1;
declare_func(void, const uint8_t *src, uint8_t *dst1, uint8_t *dst2,
int width, int height, int srcStride,
int dst1Stride, int dst2Stride);
randomize_buffers(src, 2*MAX_STRIDE*MAX_HEIGHT+2);
if (check_func(deinterleaveBytes, "deinterleave_bytes")) {
for (int i = 0; i <= 16; i++) {
// Try all widths [1,16], and try one random width.
int w = i > 0 ? i : (1 + (rnd() % (MAX_STRIDE-2)));
int h = 1 + (rnd() % (MAX_HEIGHT-2));
int src_offset = 0, src_stride = 2 * MAX_STRIDE;
int dst_u_offset = 0, dst_u_stride = MAX_STRIDE;
int dst_v_offset = 0, dst_v_stride = MAX_STRIDE;
memset(dst0_u, 0, MAX_STRIDE * MAX_HEIGHT);
memset(dst0_v, 0, MAX_STRIDE * MAX_HEIGHT);
memset(dst1_u, 0, MAX_STRIDE * MAX_HEIGHT);
memset(dst1_v, 0, MAX_STRIDE * MAX_HEIGHT);
// Try different combinations of negative strides
if (i & 1) {
src_offset = (h-1)*src_stride;
src_stride = -src_stride;
}
if (i & 2) {
dst_u_offset = (h-1)*dst_u_stride;
dst_u_stride = -dst_u_stride;
}
if (i & 4) {
dst_v_offset = (h-1)*dst_v_stride;
dst_v_stride = -dst_v_stride;
}
call_ref(src + src_offset, dst0_u + dst_u_offset, dst0_v + dst_v_offset,
w, h, src_stride, dst_u_stride, dst_v_stride);
call_new(src + src_offset, dst1_u + dst_u_offset, dst1_v + dst_v_offset,
w, h, src_stride, dst_u_stride, dst_v_stride);
// Check a one pixel-pair edge around the destination area,
// to catch overwrites past the end.
checkasm_check(uint8_t, dst0_u, MAX_STRIDE, dst1_u, MAX_STRIDE,
w + 1, h + 1, "dst_u");
checkasm_check(uint8_t, dst0_v, MAX_STRIDE, dst1_v, MAX_STRIDE,
w + 1, h + 1, "dst_v");
}
bench_new(src, dst1_u, dst1_v, 127, MAX_HEIGHT,
2*MAX_STRIDE, MAX_STRIDE, MAX_STRIDE);
}
if (check_func(deinterleaveBytes, "deinterleave_bytes_aligned")) {
// Bench the function in a more typical case, with aligned
// buffers and widths.
bench_new(src_buf, dst1_u_buf, dst1_v_buf, 128, MAX_HEIGHT,
2*MAX_STRIDE, MAX_STRIDE, MAX_STRIDE);
}
}
#define MAX_LINE_SIZE 1920
static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE};
static const enum AVPixelFormat rgb_formats[] = {
AV_PIX_FMT_RGB24,
AV_PIX_FMT_BGR24,
AV_PIX_FMT_RGBA,
AV_PIX_FMT_BGRA,
AV_PIX_FMT_ABGR,
AV_PIX_FMT_ARGB,
};
static void check_rgb_to_y(struct SwsContext *ctx)
{
LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]);
LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]);
LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]);
declare_func(void, uint8_t *dst, const uint8_t *src,
const uint8_t *unused1, const uint8_t *unused2, int width,
uint32_t *rgb2yuv, void *opq);
randomize_buffers(src24, MAX_LINE_SIZE * 3);
randomize_buffers(src32, MAX_LINE_SIZE * 4);
for (int i = 0; i < FF_ARRAY_ELEMS(rgb_formats); i++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(rgb_formats[i]);
ctx->srcFormat = rgb_formats[i];
ff_sws_init_scale(ctx);
for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
int w = input_sizes[j];
if (check_func(ctx->lumToYV12, "%s_to_y_%d", desc->name, w)) {
const uint8_t *src = desc->nb_components == 3 ? src24 : src32;
memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2);
memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2);
call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
call_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
if (memcmp(dst0_y, dst1_y, w * 2))
fail();
if (desc->nb_components == 3 ||
// only bench native endian formats
(ctx->srcFormat == AV_PIX_FMT_RGB32 || ctx->srcFormat == AV_PIX_FMT_RGB32_1))
bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, NULL);
}
}
}
}
static void check_rgb_to_uv(struct SwsContext *ctx)
{
LOCAL_ALIGNED_16(uint8_t, src24, [MAX_LINE_SIZE * 3]);
LOCAL_ALIGNED_16(uint8_t, src32, [MAX_LINE_SIZE * 4]);
LOCAL_ALIGNED_16(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]);
LOCAL_ALIGNED_16(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]);
LOCAL_ALIGNED_16(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]);
LOCAL_ALIGNED_16(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]);
declare_func(void, uint8_t *dstU, uint8_t *dstV,
const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
int width, uint32_t *pal, void *opq);
randomize_buffers(src24, MAX_LINE_SIZE * 3);
randomize_buffers(src32, MAX_LINE_SIZE * 4);
for (int i = 0; i < 2 * FF_ARRAY_ELEMS(rgb_formats); i++) {
enum AVPixelFormat src_fmt = rgb_formats[i / 2];
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src_fmt);
ctx->chrSrcHSubSample = (i % 2) ? 0 : 1;
ctx->srcFormat = src_fmt;
ctx->dstFormat = ctx->chrSrcHSubSample ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P;
ff_sws_init_scale(ctx);
for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) {
int w = input_sizes[j] >> ctx->chrSrcHSubSample;
if (check_func(ctx->chrToYV12, "%s_to_uv%s_%d", desc->name,
ctx->chrSrcHSubSample ? "_half" : "",
input_sizes[j])) {
const uint8_t *src = desc->nb_components == 3 ? src24 : src32;
memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2);
memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2);
memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2);
memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2);
call_ref(dst0_u, dst0_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
call_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v, w * 2))
fail();
if (desc->nb_components == 3 ||
// only bench native endian formats
(ctx->srcFormat == AV_PIX_FMT_RGB32 || ctx->srcFormat == AV_PIX_FMT_RGB32_1))
bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL);
}
}
}
}
void checkasm_check_sw_rgb(void)
{
struct SwsContext *ctx;
ff_sws_rgb2rgb_init();
check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103");
report("shuffle_bytes_2103");
check_shuffle_bytes(shuffle_bytes_0321, "shuffle_bytes_0321");
report("shuffle_bytes_0321");
check_shuffle_bytes(shuffle_bytes_1230, "shuffle_bytes_1230");
report("shuffle_bytes_1230");
check_shuffle_bytes(shuffle_bytes_3012, "shuffle_bytes_3012");
report("shuffle_bytes_3012");
check_shuffle_bytes(shuffle_bytes_3210, "shuffle_bytes_3210");
report("shuffle_bytes_3210");
check_uyvy_to_422p();
report("uyvytoyuv422");
check_interleave_bytes();
report("interleave_bytes");
check_deinterleave_bytes();
report("deinterleave_bytes");
ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24,
MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P,
SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL);
if (!ctx)
fail();
check_rgb_to_y(ctx);
report("rgb_to_y");
check_rgb_to_uv(ctx);
report("rgb_to_uv");
check_rgb24toyv12(ctx);
report("rgb24toyv12");
sws_freeContext(ctx);
}
+372
View File
@@ -0,0 +1,372 @@
/*
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
int j; \
for (j = 0; j < size; j+=4) \
AV_WN32(buf + j, rnd()); \
} while (0)
static void yuv2planeX_8_ref(const int16_t *filter, int filterSize,
const int16_t **src, uint8_t *dest, int dstW,
const uint8_t *dither, int offset)
{
// This corresponds to the yuv2planeX_8_c function
int i;
for (i = 0; i < dstW; i++) {
int val = dither[(i + offset) & 7] << 12;
int j;
for (j = 0; j < filterSize; j++)
val += src[j][i] * filter[j];
dest[i]= av_clip_uint8(val >> 19);
}
}
static int cmp_off_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int accuracy)
{
for (size_t i = 0; i < n; i++) {
if (abs(ref[i] - test[i]) > accuracy)
return 1;
}
return 0;
}
static void print_data(uint8_t *p, size_t len, size_t offset)
{
size_t i = 0;
for (; i < len; i++) {
if (i % 8 == 0) {
printf("0x%04zx: ", i+offset);
}
printf("0x%02x ", (uint32_t) p[i]);
if (i % 8 == 7) {
printf("\n");
}
}
if (i % 8 != 0) {
printf("\n");
}
}
static size_t show_differences(uint8_t *a, uint8_t *b, size_t len)
{
for (size_t i = 0; i < len; i++) {
if (a[i] != b[i]) {
size_t offset_of_mismatch = i;
size_t offset;
if (i >= 8) i-=8;
offset = i & (~7);
printf("test a:\n");
print_data(&a[offset], 32, offset);
printf("\ntest b:\n");
print_data(&b[offset], 32, offset);
printf("\n");
return offset_of_mismatch;
}
}
return len;
}
static void check_yuv2yuv1(int accurate)
{
struct SwsContext *ctx;
int osi, isi;
int dstW, offset;
size_t fail_offset;
const int input_sizes[] = {8, 24, 128, 144, 256, 512};
const int INPUT_SIZES = sizeof(input_sizes)/sizeof(input_sizes[0]);
#define LARGEST_INPUT_SIZE 512
const int offsets[] = {0, 3, 8, 11, 16, 19};
const int OFFSET_SIZES = sizeof(offsets)/sizeof(offsets[0]);
const char *accurate_str = (accurate) ? "accurate" : "approximate";
declare_func(void,
const int16_t *src, uint8_t *dest,
int dstW, const uint8_t *dither, int offset);
LOCAL_ALIGNED_16(int16_t, src_pixels, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst0, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst1, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_8(uint8_t, dither, [8]);
randomize_buffers((uint8_t*)dither, 8);
randomize_buffers((uint8_t*)src_pixels, LARGEST_INPUT_SIZE * sizeof(int16_t));
ctx = sws_alloc_context();
if (accurate)
ctx->flags |= SWS_ACCURATE_RND;
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
ff_sws_init_scale(ctx);
for (isi = 0; isi < INPUT_SIZES; ++isi) {
dstW = input_sizes[isi];
for (osi = 0; osi < OFFSET_SIZES; osi++) {
offset = offsets[osi];
if (check_func(ctx->yuv2plane1, "yuv2yuv1_%d_%d_%s", offset, dstW, accurate_str)){
memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0]));
memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0]));
call_ref(src_pixels, dst0, dstW, dither, offset);
call_new(src_pixels, dst1, dstW, dither, offset);
if (cmp_off_by_n(dst0, dst1, dstW * sizeof(dst0[0]), accurate ? 0 : 2)) {
fail();
printf("failed: yuv2yuv1_%d_%di_%s\n", offset, dstW, accurate_str);
fail_offset = show_differences(dst0, dst1, LARGEST_INPUT_SIZE * sizeof(dst0[0]));
printf("failing values: src: 0x%04x dither: 0x%02x dst-c: %02x dst-asm: %02x\n",
(int) src_pixels[fail_offset],
(int) dither[(fail_offset + fail_offset) & 7],
(int) dst0[fail_offset],
(int) dst1[fail_offset]);
}
if(dstW == LARGEST_INPUT_SIZE)
bench_new(src_pixels, dst1, dstW, dither, offset);
}
}
}
sws_freeContext(ctx);
}
static void check_yuv2yuvX(int accurate)
{
struct SwsContext *ctx;
int fsi, osi, isi, i, j;
int dstW;
#define LARGEST_FILTER 16
// ff_yuv2planeX_8_sse2 can't handle odd filter sizes
const int filter_sizes[] = {2, 4, 8, 16};
const int FILTER_SIZES = sizeof(filter_sizes)/sizeof(filter_sizes[0]);
#define LARGEST_INPUT_SIZE 512
static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
const int INPUT_SIZES = sizeof(input_sizes)/sizeof(input_sizes[0]);
const char *accurate_str = (accurate) ? "accurate" : "approximate";
declare_func_emms(AV_CPU_FLAG_MMX, void, const int16_t *filter,
int filterSize, const int16_t **src, uint8_t *dest,
int dstW, const uint8_t *dither, int offset);
const int16_t **src;
LOCAL_ALIGNED_16(int16_t, src_pixels, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_16(int16_t, filter_coeff, [LARGEST_FILTER]);
LOCAL_ALIGNED_16(uint8_t, dst0, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dst1, [LARGEST_INPUT_SIZE]);
LOCAL_ALIGNED_16(uint8_t, dither, [LARGEST_INPUT_SIZE]);
union VFilterData{
const int16_t *src;
uint16_t coeff[8];
} *vFilterData;
uint8_t d_val = rnd();
memset(dither, d_val, LARGEST_INPUT_SIZE);
randomize_buffers((uint8_t*)src_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t));
ctx = sws_alloc_context();
if (accurate)
ctx->flags |= SWS_ACCURATE_RND;
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
ff_sws_init_scale(ctx);
for(isi = 0; isi < INPUT_SIZES; ++isi){
dstW = input_sizes[isi];
for(osi = 0; osi < 64; osi += 16){
if (dstW <= osi)
continue;
for (fsi = 0; fsi < FILTER_SIZES; ++fsi) {
// Generate filter coefficients for the given filter size,
// with some properties:
// - The coefficients add up to the intended sum (4096, 1<<12)
// - The coefficients contain negative values
// - The filter intermediates don't overflow for worst case
// inputs (all positive coefficients are coupled with
// input_max and all negative coefficients with input_min,
// or vice versa).
// Produce a filter with all coefficients set to
// -((1<<12)/(filter_size-1)) except for one (randomly chosen)
// which is set to ((1<<13)-1).
for (i = 0; i < filter_sizes[fsi]; ++i)
filter_coeff[i] = -((1 << 12) / (filter_sizes[fsi] - 1));
filter_coeff[rnd() % filter_sizes[fsi]] = (1 << 13) - 1;
src = av_malloc(sizeof(int16_t*) * filter_sizes[fsi]);
vFilterData = av_malloc((filter_sizes[fsi] + 2) * sizeof(union VFilterData));
memset(vFilterData, 0, (filter_sizes[fsi] + 2) * sizeof(union VFilterData));
for (i = 0; i < filter_sizes[fsi]; ++i) {
src[i] = &src_pixels[i * LARGEST_INPUT_SIZE];
vFilterData[i].src = src[i] - osi;
for(j = 0; j < 4; ++j)
vFilterData[i].coeff[j + 4] = filter_coeff[i];
}
if (check_func(ctx->yuv2planeX, "yuv2yuvX_%d_%d_%d_%s", filter_sizes[fsi], osi, dstW, accurate_str)){
// use vFilterData for the mmx function
const int16_t *filter = ctx->use_mmx_vfilter ? (const int16_t*)vFilterData : &filter_coeff[0];
memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0]));
memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0]));
// We can't use call_ref here, because we don't know if use_mmx_vfilter was set for that
// function or not, so we can't pass it the parameters correctly.
yuv2planeX_8_ref(&filter_coeff[0], filter_sizes[fsi], src, dst0, dstW - osi, dither, osi);
call_new(filter, filter_sizes[fsi], src, dst1, dstW - osi, dither, osi);
if (cmp_off_by_n(dst0, dst1, LARGEST_INPUT_SIZE * sizeof(dst0[0]), accurate ? 0 : 2)) {
fail();
printf("failed: yuv2yuvX_%d_%d_%d_%s\n", filter_sizes[fsi], osi, dstW, accurate_str);
show_differences(dst0, dst1, LARGEST_INPUT_SIZE * sizeof(dst0[0]));
}
if(dstW == LARGEST_INPUT_SIZE)
bench_new((const int16_t*)vFilterData, filter_sizes[fsi], src, dst1, dstW - osi, dither, osi);
}
av_freep(&src);
av_freep(&vFilterData);
}
}
}
sws_freeContext(ctx);
#undef FILTER_SIZES
}
#undef SRC_PIXELS
#define SRC_PIXELS 512
static void check_hscale(void)
{
#define MAX_FILTER_WIDTH 40
#define FILTER_SIZES 6
static const int filter_sizes[FILTER_SIZES] = { 4, 8, 12, 16, 32, 40 };
#define HSCALE_PAIRS 2
static const int hscale_pairs[HSCALE_PAIRS][2] = {
{ 8, 14 },
{ 8, 18 },
};
#define LARGEST_INPUT_SIZE 512
#define INPUT_SIZES 6
static const int input_sizes[INPUT_SIZES] = {8, 24, 128, 144, 256, 512};
int i, j, fsi, hpi, width, dstWi;
struct SwsContext *ctx;
// padded
LOCAL_ALIGNED_32(uint8_t, src, [FFALIGN(SRC_PIXELS + MAX_FILTER_WIDTH - 1, 4)]);
LOCAL_ALIGNED_32(uint32_t, dst0, [SRC_PIXELS]);
LOCAL_ALIGNED_32(uint32_t, dst1, [SRC_PIXELS]);
// padded
LOCAL_ALIGNED_32(int16_t, filter, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]);
LOCAL_ALIGNED_32(int32_t, filterPos, [SRC_PIXELS]);
LOCAL_ALIGNED_32(int16_t, filterAvx2, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]);
LOCAL_ALIGNED_32(int32_t, filterPosAvx, [SRC_PIXELS]);
// The dst parameter here is either int16_t or int32_t but we use void* to
// just cover both cases.
declare_func(void, void *c, void *dst, int dstW,
const uint8_t *src, const int16_t *filter,
const int32_t *filterPos, int filterSize);
ctx = sws_alloc_context();
if (sws_init_context(ctx, NULL, NULL) < 0)
fail();
randomize_buffers(src, SRC_PIXELS + MAX_FILTER_WIDTH - 1);
for (hpi = 0; hpi < HSCALE_PAIRS; hpi++) {
for (fsi = 0; fsi < FILTER_SIZES; fsi++) {
for (dstWi = 0; dstWi < INPUT_SIZES; dstWi++) {
width = filter_sizes[fsi];
ctx->srcBpc = hscale_pairs[hpi][0];
ctx->dstBpc = hscale_pairs[hpi][1];
ctx->hLumFilterSize = ctx->hChrFilterSize = width;
for (i = 0; i < SRC_PIXELS; i++) {
filterPos[i] = i;
filterPosAvx[i] = i;
// These filter cofficients are chosen to try break two corner
// cases, namely:
//
// - Negative filter coefficients. The filters output signed
// values, and it should be possible to end up with negative
// output values.
//
// - Positive clipping. The hscale filter function has clipping
// at (1<<15) - 1
//
// The coefficients sum to the 1.0 point for the hscale
// functions (1 << 14).
for (j = 0; j < width; j++) {
filter[i * width + j] = -((1 << 14) / (width - 1));
}
filter[i * width + (rnd() % width)] = ((1 << 15) - 1);
}
for (i = 0; i < MAX_FILTER_WIDTH; i++) {
// These values should be unused in SIMD implementations but
// may still be read, random coefficients here should help show
// issues where they are used in error.
filter[SRC_PIXELS * width + i] = rnd();
}
ctx->dstW = ctx->chrDstW = input_sizes[dstWi];
ff_sws_init_scale(ctx);
memcpy(filterAvx2, filter, sizeof(uint16_t) * (SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH));
ff_shuffle_filter_coefficients(ctx, filterPosAvx, width, filterAvx2, ctx->dstW);
if (check_func(ctx->hcScale, "hscale_%d_to_%d__fs_%d_dstW_%d", ctx->srcBpc, ctx->dstBpc + 1, width, ctx->dstW)) {
memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0]));
memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0]));
call_ref(NULL, dst0, ctx->dstW, src, filter, filterPos, width);
call_new(NULL, dst1, ctx->dstW, src, filterAvx2, filterPosAvx, width);
if (memcmp(dst0, dst1, ctx->dstW * sizeof(dst0[0])))
fail();
bench_new(NULL, dst0, ctx->dstW, src, filter, filterPosAvx, width);
}
}
}
}
sws_freeContext(ctx);
}
void checkasm_check_sw_scale(void)
{
check_hscale();
report("hscale");
check_yuv2yuv1(0);
check_yuv2yuv1(1);
report("yuv2yuv1");
check_yuv2yuvX(0);
check_yuv2yuvX(1);
report("yuv2yuvX");
}
+239
View File
@@ -0,0 +1,239 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavutil/pixdesc.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
for (int j = 0; j < size; j += 4) \
AV_WN32(buf + j, rnd()); \
} while (0)
static const int dst_fmts[] = {
// AV_PIX_FMT_BGR48BE,
// AV_PIX_FMT_BGR48LE,
// AV_PIX_FMT_RGB48BE,
// AV_PIX_FMT_RGB48LE,
AV_PIX_FMT_ARGB,
AV_PIX_FMT_ABGR,
AV_PIX_FMT_RGBA,
AV_PIX_FMT_BGRA,
AV_PIX_FMT_RGB24,
AV_PIX_FMT_BGR24,
AV_PIX_FMT_RGB565,
AV_PIX_FMT_BGR565,
AV_PIX_FMT_RGB555,
AV_PIX_FMT_BGR555,
// AV_PIX_FMT_RGB444,
// AV_PIX_FMT_BGR444,
// AV_PIX_FMT_RGB8,
// AV_PIX_FMT_BGR8,
// AV_PIX_FMT_RGB4,
// AV_PIX_FMT_BGR4,
// AV_PIX_FMT_RGB4_BYTE,
// AV_PIX_FMT_BGR4_BYTE,
// AV_PIX_FMT_MONOBLACK,
AV_PIX_FMT_GBRP,
};
static int cmp_off_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int accuracy)
{
for (size_t i = 0; i < n; i++) {
if (abs(ref[i] - test[i]) > accuracy)
return 1;
}
return 0;
}
static int cmp_555_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int accuracy)
{
const uint16_t *ref16 = (const uint16_t *) ref;
const uint16_t *test16 = (const uint16_t *) test;
for (size_t i = 0; i < n; i++) {
if (abs(( ref16[i] & 0x1f) - ( test16[i] & 0x1f)) > accuracy)
return 1;
if (abs(((ref16[i] >> 5) & 0x1f) - ((test16[i] >> 5) & 0x1f)) > accuracy)
return 1;
if (abs(((ref16[i] >> 10) & 0x1f) - ((test16[i] >> 10) & 0x1f)) > accuracy)
return 1;
}
return 0;
}
static int cmp_565_by_n(const uint8_t *ref, const uint8_t *test, size_t n, int accuracy)
{
const uint16_t *ref16 = (const uint16_t *) ref;
const uint16_t *test16 = (const uint16_t *) test;
for (size_t i = 0; i < n; i++) {
if (abs(( ref16[i] & 0x1f) - ( test16[i] & 0x1f)) > accuracy)
return 1;
if (abs(((ref16[i] >> 5) & 0x3f) - ((test16[i] >> 5) & 0x3f)) > accuracy)
return 1;
if (abs(((ref16[i] >> 11) & 0x1f) - ((test16[i] >> 11) & 0x1f)) > accuracy)
return 1;
}
return 0;
}
static void check_yuv2rgb(int src_pix_fmt)
{
const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
#define MAX_LINE_SIZE 1920
static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE};
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT,
int, SwsContext *c, const uint8_t *src[],
int srcStride[], int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[]);
LOCAL_ALIGNED_8(uint8_t, src_y, [MAX_LINE_SIZE * 2]);
LOCAL_ALIGNED_8(uint8_t, src_u, [MAX_LINE_SIZE]);
LOCAL_ALIGNED_8(uint8_t, src_v, [MAX_LINE_SIZE]);
LOCAL_ALIGNED_8(uint8_t, src_a, [MAX_LINE_SIZE * 2]);
const uint8_t *src[4] = { src_y, src_u, src_v, src_a };
LOCAL_ALIGNED_8(uint8_t, dst0_0, [2 * MAX_LINE_SIZE * 6]);
LOCAL_ALIGNED_8(uint8_t, dst0_1, [2 * MAX_LINE_SIZE]);
LOCAL_ALIGNED_8(uint8_t, dst0_2, [2 * MAX_LINE_SIZE]);
uint8_t *dst0[4] = { dst0_0, dst0_1, dst0_2 };
uint8_t *lines0[4][2] = {
{ dst0_0, dst0_0 + MAX_LINE_SIZE * 6 },
{ dst0_1, dst0_1 + MAX_LINE_SIZE },
{ dst0_2, dst0_2 + MAX_LINE_SIZE }
};
LOCAL_ALIGNED_8(uint8_t, dst1_0, [2 * MAX_LINE_SIZE * 6]);
LOCAL_ALIGNED_8(uint8_t, dst1_1, [2 * MAX_LINE_SIZE]);
LOCAL_ALIGNED_8(uint8_t, dst1_2, [2 * MAX_LINE_SIZE]);
uint8_t *dst1[4] = { dst1_0, dst1_1, dst1_2 };
uint8_t *lines1[4][2] = {
{ dst1_0, dst1_0 + MAX_LINE_SIZE * 6 },
{ dst1_1, dst1_1 + MAX_LINE_SIZE },
{ dst1_2, dst1_2 + MAX_LINE_SIZE }
};
randomize_buffers(src_y, MAX_LINE_SIZE * 2);
randomize_buffers(src_u, MAX_LINE_SIZE);
randomize_buffers(src_v, MAX_LINE_SIZE);
randomize_buffers(src_a, MAX_LINE_SIZE * 2);
for (int dfi = 0; dfi < FF_ARRAY_ELEMS(dst_fmts); dfi++) {
int dst_pix_fmt = dst_fmts[dfi];
const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
int sample_size = av_get_padded_bits_per_pixel(dst_desc) >> 3;
for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
struct SwsContext *ctx;
int log_level;
int width = input_sizes[isi];
int srcSliceY = 0;
int srcSliceH = 2;
int srcStride[4] = {
width,
width >> src_desc->log2_chroma_w,
width >> src_desc->log2_chroma_w,
width,
};
int dstStride[4] = {
MAX_LINE_SIZE * 6,
MAX_LINE_SIZE,
MAX_LINE_SIZE,
};
// override log level to prevent spamming of the message
// "No accelerated colorspace conversion found from %s to %s"
log_level = av_log_get_level();
av_log_set_level(AV_LOG_ERROR);
ctx = sws_getContext(width, srcSliceH, src_pix_fmt,
width, srcSliceH, dst_pix_fmt,
0, NULL, NULL, NULL);
av_log_set_level(log_level);
if (!ctx)
fail();
if (check_func(ctx->convert_unscaled, "%s_%s_%d", src_desc->name, dst_desc->name, width)) {
memset(dst0_0, 0xFF, 2 * MAX_LINE_SIZE * 6);
memset(dst1_0, 0xFF, 2 * MAX_LINE_SIZE * 6);
if (dst_pix_fmt == AV_PIX_FMT_GBRP) {
memset(dst0_1, 0xFF, MAX_LINE_SIZE);
memset(dst0_2, 0xFF, MAX_LINE_SIZE);
memset(dst1_1, 0xFF, MAX_LINE_SIZE);
memset(dst1_2, 0xFF, MAX_LINE_SIZE);
}
call_ref(ctx, src, srcStride, srcSliceY,
srcSliceH, dst0, dstStride);
call_new(ctx, src, srcStride, srcSliceY,
srcSliceH, dst1, dstStride);
if (dst_pix_fmt == AV_PIX_FMT_ARGB ||
dst_pix_fmt == AV_PIX_FMT_ABGR ||
dst_pix_fmt == AV_PIX_FMT_RGBA ||
dst_pix_fmt == AV_PIX_FMT_BGRA ||
dst_pix_fmt == AV_PIX_FMT_RGB24 ||
dst_pix_fmt == AV_PIX_FMT_BGR24) {
if (cmp_off_by_n(lines0[0][0], lines1[0][0], width * sample_size, 3) ||
cmp_off_by_n(lines0[0][1], lines1[0][1], width * sample_size, 3))
fail();
} else if (dst_pix_fmt == AV_PIX_FMT_RGB565 ||
dst_pix_fmt == AV_PIX_FMT_BGR565) {
if (cmp_565_by_n(lines0[0][0], lines1[0][0], width, 2) ||
cmp_565_by_n(lines0[0][1], lines1[0][1], width, 2))
fail();
} else if (dst_pix_fmt == AV_PIX_FMT_RGB555 ||
dst_pix_fmt == AV_PIX_FMT_BGR555) {
if (cmp_555_by_n(lines0[0][0], lines1[0][0], width, 2) ||
cmp_555_by_n(lines0[0][1], lines1[0][1], width, 2))
fail();
} else if (dst_pix_fmt == AV_PIX_FMT_GBRP) {
for (int p = 0; p < 3; p++)
for (int l = 0; l < 2; l++)
if (cmp_off_by_n(lines0[p][l], lines1[p][l], width, 3))
fail();
} else {
fail();
}
bench_new(ctx, src, srcStride, srcSliceY,
srcSliceH, dst0, dstStride);
}
sws_freeContext(ctx);
}
}
}
#undef MAX_LINE_SIZE
void checkasm_check_sw_yuv2rgb(void)
{
check_yuv2rgb(AV_PIX_FMT_YUV420P);
report("yuv420p");
check_yuv2rgb(AV_PIX_FMT_YUV422P);
report("yuv422p");
check_yuv2rgb(AV_PIX_FMT_YUVA420P);
report("yuva420p");
}
+133
View File
@@ -0,0 +1,133 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavutil/pixdesc.h"
#include "libswscale/swscale.h"
#include "libswscale/swscale_internal.h"
#include "checkasm.h"
#define randomize_buffers(buf, size) \
do { \
for (int j = 0; j < size; j += 4) \
AV_WN32(buf + j, rnd()); \
} while (0)
static void check_semiplanar(int dst_pix_fmt)
{
static const int src_fmts[] = {
AV_PIX_FMT_NV24,
AV_PIX_FMT_NV42,
};
const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
#define NUM_LINES 4
#define MAX_LINE_SIZE 1920
static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE};
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT,
int, SwsContext *c, const uint8_t *src[],
int srcStride[], int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[]);
LOCAL_ALIGNED_8(uint8_t, src_y, [MAX_LINE_SIZE * NUM_LINES]);
LOCAL_ALIGNED_8(uint8_t, src_uv, [MAX_LINE_SIZE * NUM_LINES * 2]);
const uint8_t *src[4] = { src_y, src_uv };
LOCAL_ALIGNED_8(uint8_t, dst0_y, [MAX_LINE_SIZE * NUM_LINES]);
LOCAL_ALIGNED_8(uint8_t, dst0_u, [MAX_LINE_SIZE * NUM_LINES / 2]);
LOCAL_ALIGNED_8(uint8_t, dst0_v, [MAX_LINE_SIZE * NUM_LINES / 2]);
uint8_t *dst0[4] = { dst0_y, dst0_u, dst0_v };
LOCAL_ALIGNED_8(uint8_t, dst1_y, [MAX_LINE_SIZE * NUM_LINES]);
LOCAL_ALIGNED_8(uint8_t, dst1_u, [MAX_LINE_SIZE * NUM_LINES / 2]);
LOCAL_ALIGNED_8(uint8_t, dst1_v, [MAX_LINE_SIZE * NUM_LINES / 2]);
uint8_t *dst1[4] = { dst1_y, dst1_u, dst1_v };
randomize_buffers(src_y, MAX_LINE_SIZE * NUM_LINES);
randomize_buffers(src_uv, MAX_LINE_SIZE * NUM_LINES * 2);
for (int sfi = 0; sfi < FF_ARRAY_ELEMS(src_fmts); sfi++) {
int src_pix_fmt = src_fmts[sfi];
const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
struct SwsContext *ctx;
int log_level;
int width = input_sizes[isi];
int srcSliceY = 0;
int srcSliceH = NUM_LINES;
int srcStride[4] = {
MAX_LINE_SIZE,
MAX_LINE_SIZE * 2,
};
int dstStride[4] = {
MAX_LINE_SIZE,
MAX_LINE_SIZE >> dst_desc->log2_chroma_w,
MAX_LINE_SIZE >> dst_desc->log2_chroma_w,
};
// override log level to prevent spamming of the message
// "No accelerated colorspace conversion found from %s to %s"
log_level = av_log_get_level();
av_log_set_level(AV_LOG_ERROR);
ctx = sws_getContext(width, srcSliceH, src_pix_fmt,
width, srcSliceH, dst_pix_fmt,
0, NULL, NULL, NULL);
av_log_set_level(log_level);
if (!ctx)
fail();
if (check_func(ctx->convert_unscaled, "%s_%s_%d", src_desc->name, dst_desc->name, width)) {
memset(dst0_y, 0xFF, MAX_LINE_SIZE * NUM_LINES);
memset(dst0_u, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
memset(dst0_v, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
memset(dst1_y, 0xFF, MAX_LINE_SIZE * NUM_LINES);
memset(dst1_u, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
memset(dst1_v, 0xFF, MAX_LINE_SIZE * NUM_LINES / 2);
call_ref(ctx, src, srcStride, srcSliceY,
srcSliceH, dst0, dstStride);
call_new(ctx, src, srcStride, srcSliceY,
srcSliceH, dst1, dstStride);
if (memcmp(dst0_y, dst1_y, MAX_LINE_SIZE * NUM_LINES) ||
memcmp(dst0_u, dst1_u, MAX_LINE_SIZE * NUM_LINES / 2) ||
memcmp(dst0_v, dst1_v, MAX_LINE_SIZE * NUM_LINES / 2))
fail();
bench_new(ctx, src, srcStride, srcSliceY,
srcSliceH, dst0, dstStride);
}
sws_freeContext(ctx);
}
}
}
#undef NUM_LINES
#undef MAX_LINE_SIZE
void checkasm_check_sw_yuv2yuv(void)
{
check_semiplanar(AV_PIX_FMT_YUV420P);
report("yuv420p");
}
+126
View File
@@ -0,0 +1,126 @@
/*
* Copyright (c) 2015 Janne Grunau
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "libavutil/internal.h"
#include "libavutil/intfloat.h"
#include "libavutil/mem_internal.h"
#include "libavutil/tx.h"
#include "libavcodec/dcadata.h"
#include "libavcodec/synth_filter.h"
#include "checkasm.h"
#define BUF_SIZE 32
#define randomize_input() \
do { \
int i; \
for (i = 0; i < BUF_SIZE; i++) { \
float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
in[i] = f; \
} \
} while (0)
void checkasm_check_synth_filter(void)
{
float scale = 1.0;
AVTXContext *imdct;
av_tx_fn imdct_fn;
SynthFilterContext synth;
av_tx_init(&imdct, &imdct_fn, AV_TX_FLOAT_MDCT, 0, 16, &scale, 0);
ff_synth_filter_init(&synth);
if (check_func(synth.synth_filter_float, "synth_filter_float")) {
LOCAL_ALIGNED(32, float, out0, [BUF_SIZE]);
LOCAL_ALIGNED(32, float, out1, [BUF_SIZE]);
LOCAL_ALIGNED(32, float, out_b, [BUF_SIZE]);
LOCAL_ALIGNED(32, float, in, [BUF_SIZE]);
LOCAL_ALIGNED(32, float, buf2_0, [BUF_SIZE]);
LOCAL_ALIGNED(32, float, buf2_1, [BUF_SIZE]);
LOCAL_ALIGNED(32, float, buf2_b, [BUF_SIZE]);
LOCAL_ALIGNED(32, float, buf0, [512]);
LOCAL_ALIGNED(32, float, buf1, [512]);
LOCAL_ALIGNED(32, float, buf_b, [512]);
float scale = 1.0f;
int i, offset0 = 0, offset1 = 0, offset_b = 0;
declare_func(void, AVTXContext *, float *, int *,
float[32], const float[512], float[32], float[32], float, av_tx_fn);
memset(buf2_0, 0, sizeof(*buf2_0) * BUF_SIZE);
memset(buf2_1, 0, sizeof(*buf2_1) * BUF_SIZE);
memset(buf2_b, 0, sizeof(*buf2_b) * BUF_SIZE);
memset(buf0, 0, sizeof(*buf2_0) * 512);
memset(buf1, 0, sizeof(*buf2_1) * 512);
memset(buf_b, 0, sizeof(*buf2_b) * 512);
/* more than 1 synth_buf_offset wrap-around */
for (i = 0; i < 20; i++) {
int j;
const float * window = (i & 1) ? ff_dca_fir_32bands_perfect : ff_dca_fir_32bands_nonperfect;
memset(out0, 0, sizeof(*out0) * BUF_SIZE);
memset(out1, 0, sizeof(*out1) * BUF_SIZE);
memset(out_b, 0, sizeof(*out_b) * BUF_SIZE);
randomize_input();
call_ref(imdct, buf0, &offset0, buf2_0, window,
out0, in, scale, imdct_fn);
call_new(imdct, buf1, &offset1, buf2_1, window,
out1, in, scale, imdct_fn);
if (offset0 != offset1) {
fail();
fprintf(stderr, "offsets do not match: %d, %d", offset0, offset1);
break;
}
for (j = 0; j < BUF_SIZE; j++) {
if (!float_near_abs_eps_ulp(out0[j], out1[j], 7.0e-7, 16) ||
!float_near_abs_eps_ulp(buf2_0[j], buf2_1[j], 7.0e-7, 16)) {
union av_intfloat32 o0, o1, b0, b1;
fail();
o0.f = out0[j]; o1.f = out1[j];
b0.f = buf2_0[j], b1.f = buf2_1[j];
fprintf(stderr, "out: %11g (0x%08x); %11g (0x%08x); abs diff %11g\n",
o0.f, o0.i, o1.f, o1.i, fabsf(o0.f - o1.f));
fprintf(stderr, "buf2: %11g (0x%08x); %11g (0x%08x); abs diff %11g\n",
b0.f, b0.i, b1.f, b1.i, fabsf(b0.f - b1.f));
break;
}
}
bench_new(imdct, buf_b, &offset_b, buf2_b, window,
out_b, in, scale, imdct_fn);
}
}
av_tx_uninit(&imdct);
report("synth_filter");
}
+154
View File
@@ -0,0 +1,154 @@
/*
* Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/takdsp.h"
#include "libavcodec/mathops.h"
#include "checkasm.h"
#define randomize(buf, len) \
do { \
for (int i = 0; i < len; i++) \
buf[i] = rnd(); \
} while (0)
#define BUF_SIZE 1024
static void test_decorrelate_ls(TAKDSPContext *s) {
declare_func(void, const int32_t *, int32_t *, int);
if (check_func(s->decorrelate_ls, "decorrelate_ls")) {
LOCAL_ALIGNED_32(int32_t, p1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p2, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p2_2, [BUF_SIZE]);
randomize(p1, BUF_SIZE);
randomize(p2, BUF_SIZE);
memcpy(p2_2, p2, BUF_SIZE * sizeof(*p2));
call_ref(p1, p2, BUF_SIZE);
call_new(p1, p2_2, BUF_SIZE);
if (memcmp(p2, p2_2, BUF_SIZE * sizeof(*p2)) != 0) {
fail();
}
bench_new(p1, p2, BUF_SIZE);
}
report("decorrelate_ls");
}
static void test_decorrelate_sr(TAKDSPContext *s) {
declare_func(void, int32_t *, const int32_t *, int);
if (check_func(s->decorrelate_sr, "decorrelate_sr")) {
LOCAL_ALIGNED_32(int32_t, p1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p1_2, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p2, [BUF_SIZE]);
randomize(p1, BUF_SIZE);
memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
randomize(p2, BUF_SIZE);
call_ref(p1, p2, BUF_SIZE);
call_new(p1_2, p2, BUF_SIZE);
if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0) {
fail();
}
bench_new(p1, p2, BUF_SIZE);
}
report("decorrelate_sr");
}
static void test_decorrelate_sm(TAKDSPContext *s) {
declare_func(void, int32_t *, int32_t *, int);
if (check_func(s->decorrelate_sm, "decorrelate_sm")) {
LOCAL_ALIGNED_32(int32_t, p1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p1_2, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p2, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p2_2, [BUF_SIZE]);
randomize(p1, BUF_SIZE);
memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
randomize(p2, BUF_SIZE);
memcpy(p2_2, p2, BUF_SIZE * sizeof(*p2));
call_ref(p1, p2, BUF_SIZE);
call_new(p1_2, p2_2, BUF_SIZE);
if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0 ||
memcmp(p2, p2_2, BUF_SIZE * sizeof(*p2)) != 0) {
fail();
}
bench_new(p1, p2, BUF_SIZE);
}
report("decorrelate_sm");
}
static void test_decorrelate_sf(TAKDSPContext *s) {
declare_func(void, int32_t *, const int32_t *, int, int, int);
if (check_func(s->decorrelate_sf, "decorrelate_sf")) {
LOCAL_ALIGNED_32(int32_t, p1, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p1_2, [BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, p2, [BUF_SIZE]);
int dshift, dfactor;
randomize(p1, BUF_SIZE);
memcpy(p1_2, p1, BUF_SIZE * sizeof(*p1));
randomize(p2, BUF_SIZE);
dshift = (rnd() & 0xF) + 1;
dfactor = sign_extend(rnd(), 10);
call_ref(p1, p2, BUF_SIZE, dshift, dfactor);
call_new(p1_2, p2, BUF_SIZE, dshift, dfactor);
if (memcmp(p1, p1_2, BUF_SIZE * sizeof(*p1)) != 0) {
fail();
}
bench_new(p1, p2, BUF_SIZE, dshift, dfactor);
}
report("decorrelate_sf");
}
void checkasm_check_takdsp(void)
{
TAKDSPContext s = { 0 };
ff_takdsp_init(&s);
test_decorrelate_ls(&s);
test_decorrelate_sr(&s);
test_decorrelate_sm(&s);
test_decorrelate_sf(&s);
}
+105
View File
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2017 Jokyo Images
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/utvideodsp.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define WIDTH 240
#define HEIGHT 120
#define WIDTH_PADDED (WIDTH + 16) /* padded to 32 */
#define BUFFER_SIZE (WIDTH_PADDED * HEIGHT)
#define randomize_plane(buf, type) \
do { \
int w, h; \
type * tmp = buf; \
for (h = 0; h < HEIGHT; h++) { \
for (w = 0; w < WIDTH; w++) \
tmp[w] = rnd() & 0xFF; \
tmp += WIDTH_PADDED; \
} \
} while (0)
#define cmp_plane(buf0, buf1, s) \
do { \
int h; \
for (h = 0; h < HEIGHT; h++) { \
if (memcmp(buf0 + h*WIDTH_PADDED, \
buf1 + h*WIDTH_PADDED, WIDTH *s)) \
fail();\
} \
} while (0)
#define CHECK_RESTORE(type)\
LOCAL_ALIGNED_32(type, src_r0, [BUFFER_SIZE]); \
LOCAL_ALIGNED_32(type, src_g0, [BUFFER_SIZE]); \
LOCAL_ALIGNED_32(type, src_b0, [BUFFER_SIZE]); \
LOCAL_ALIGNED_32(type, src_r1, [BUFFER_SIZE]); \
LOCAL_ALIGNED_32(type, src_g1, [BUFFER_SIZE]); \
LOCAL_ALIGNED_32(type, src_b1, [BUFFER_SIZE]); \
declare_func(void, type *src_r, type *src_g, type *src_b, \
ptrdiff_t linesize_r, ptrdiff_t linesize_g, \
ptrdiff_t linesize_b, int width, int height); \
memset(src_r0, 0, BUFFER_SIZE * sizeof(type)); \
memset(src_g0, 0, BUFFER_SIZE * sizeof(type)); \
memset(src_b0, 0, BUFFER_SIZE * sizeof(type)); \
randomize_plane(src_r0, type); \
randomize_plane(src_g0, type); \
randomize_plane(src_b0, type); \
memcpy(src_r1, src_r0, BUFFER_SIZE * sizeof(type)); \
memcpy(src_g1, src_g0, BUFFER_SIZE * sizeof(type)); \
memcpy(src_b1, src_b0, BUFFER_SIZE * sizeof(type)); \
call_ref(src_r0, src_g0, src_b0, WIDTH_PADDED, WIDTH_PADDED, WIDTH_PADDED, WIDTH, HEIGHT);\
call_new(src_r1, src_g1, src_b1, WIDTH_PADDED, WIDTH_PADDED, WIDTH_PADDED, WIDTH, HEIGHT);\
cmp_plane(src_r0, src_r1, sizeof(type)); \
cmp_plane(src_g0, src_g1, sizeof(type)); \
cmp_plane(src_b0, src_b1, sizeof(type)); \
bench_new(src_r1, src_g1, src_b1, WIDTH_PADDED, WIDTH_PADDED, WIDTH_PADDED, WIDTH, HEIGHT)
static void check_restore_rgb_planes(void) {
CHECK_RESTORE(uint8_t);
}
static void check_restore_rgb_planes10(void) {
CHECK_RESTORE(uint16_t);
}
void checkasm_check_utvideodsp(void)
{
UTVideoDSPContext h;
ff_utvideodsp_init(&h);
if (check_func(h.restore_rgb_planes, "restore_rgb_planes"))
check_restore_rgb_planes();
report("restore_rgb_planes");
if (check_func(h.restore_rgb_planes10, "restore_rgb_planes10"))
check_restore_rgb_planes10();
report("restore_rgb_planes10");
}
+77
View File
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2019 James Darnley
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/v210dec_init.h"
static uint32_t get_v210(void)
{
uint32_t t0 = rnd() & 0x3ff,
t1 = rnd() & 0x3ff,
t2 = rnd() & 0x3ff;
uint32_t value = t0
| (t1 << 10)
| (t2 << 20);
return value;
}
#define NUM_SAMPLES 2048
static void randomize_buffers(uint32_t *src0, uint32_t *src1, int len)
{
for (int i = 0; i < len; i++) {
uint32_t value = get_v210();
src0[i] = value;
src1[i] = value;
}
}
void checkasm_check_v210dec(void)
{
V210DecContext h;
h.aligned_input = 0;
ff_v210dec_init(&h);
if (check_func(h.unpack_frame, "v210_unpack")) {
uint32_t src0[NUM_SAMPLES/3];
uint32_t src1[NUM_SAMPLES/3];
uint16_t y0[NUM_SAMPLES/2 + 26];
uint16_t y1[NUM_SAMPLES/2 + 26];
uint16_t u0[NUM_SAMPLES/4 + 13];
uint16_t u1[NUM_SAMPLES/4 + 13];
uint16_t v0[NUM_SAMPLES/4 + 13];
uint16_t v1[NUM_SAMPLES/4 + 13];
declare_func(void, const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width);
const int pixels = NUM_SAMPLES / 2 / 6 * 6;
randomize_buffers(src0, src1, NUM_SAMPLES/3);
call_ref(src0, y0, u0, v0, pixels);
call_new(src1, y1, u1, v1, pixels);
if (memcmp(src0, src1, NUM_SAMPLES/3 * sizeof src0[0])
|| memcmp(y0, y1, pixels * sizeof y0[0])
|| memcmp(u0, u1, pixels/2 * sizeof u0[0])
|| memcmp(v0, v1, pixels/2 * sizeof v0[0]))
fail();
bench_new(src1, y1, u1, v1, pixels);
}
report("v210_unpack");
}
+97
View File
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2015 Henrik Gramner
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/v210enc_init.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define BUF_SIZE 512
#define randomize_buffers(mask) \
do { \
int i, size = sizeof(*y0); \
for (i = 0; i < BUF_SIZE; i += 4 / size) { \
uint32_t r = rnd() & mask; \
AV_WN32A(y0 + i, r); \
AV_WN32A(y1 + i, r); \
} \
for (i = 0; i < BUF_SIZE / 2; i += 4 / size) { \
uint32_t r = rnd() & mask; \
AV_WN32A(u0 + i, r); \
AV_WN32A(u1 + i, r); \
r = rnd() & mask; \
AV_WN32A(v0 + i, r); \
AV_WN32A(v1 + i, r); \
} \
for (i = 0; i < width * 8 / 3; i += 4) { \
uint32_t r = rnd(); \
AV_WN32A(dst0 + i, r); \
AV_WN32A(dst1 + i, r); \
} \
} while (0)
#define check_pack_line(type, mask) \
do { \
LOCAL_ALIGNED_16(type, y0, [BUF_SIZE]); \
LOCAL_ALIGNED_16(type, y1, [BUF_SIZE]); \
LOCAL_ALIGNED_16(type, u0, [BUF_SIZE / 2]); \
LOCAL_ALIGNED_16(type, u1, [BUF_SIZE / 2]); \
LOCAL_ALIGNED_16(type, v0, [BUF_SIZE / 2]); \
LOCAL_ALIGNED_16(type, v1, [BUF_SIZE / 2]); \
LOCAL_ALIGNED_16(uint8_t, dst0, [BUF_SIZE * 8 / 3]); \
LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE * 8 / 3]); \
\
declare_func(void, const type * y, const type * u, const type * v, \
uint8_t * dst, ptrdiff_t width); \
ptrdiff_t width, step = 12 / sizeof(type); \
\
for (width = step; width < BUF_SIZE - 15; width += step) { \
int y_offset = rnd() & 15; \
int uv_offset = y_offset / 2; \
randomize_buffers(mask); \
call_ref(y0 + y_offset, u0 + uv_offset, v0 + uv_offset, dst0, width); \
call_new(y1 + y_offset, u1 + uv_offset, v1 + uv_offset, dst1, width); \
if (memcmp(y0, y1, BUF_SIZE * sizeof(type)) \
|| memcmp(u0, u1, BUF_SIZE * sizeof(type) / 2) \
|| memcmp(v0, v1, BUF_SIZE * sizeof(type) / 2) \
|| memcmp(dst0, dst1, width * 8 / 3)) \
fail(); \
bench_new(y1 + y_offset, u1 + uv_offset, v1 + uv_offset, dst1, width); \
} \
} while (0)
void checkasm_check_v210enc(void)
{
V210EncContext h;
ff_v210enc_init(&h);
if (check_func(h.pack_line_8, "v210_planar_pack_8"))
check_pack_line(uint8_t, 0xffffffff);
if (check_func(h.pack_line_10, "v210_planar_pack_10"))
check_pack_line(uint16_t, 0x03ff03ff);
report("planar_pack");
}
+490
View File
@@ -0,0 +1,490 @@
/*
* Copyright (c) 2022 Ben Avison
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/vc1dsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#define VC1DSP_TEST(func) { #func, offsetof(VC1DSPContext, func) },
#define VC1DSP_SIZED_TEST(func, width, height) { #func, offsetof(VC1DSPContext, func), width, height },
typedef struct {
const char *name;
size_t offset;
int width;
int height;
} test;
typedef struct matrix {
size_t width;
size_t height;
float d[];
} matrix;
static const matrix T8 = { 8, 8, {
12, 12, 12, 12, 12, 12, 12, 12,
16, 15, 9, 4, -4, -9, -15, -16,
16, 6, -6, -16, -16, -6, 6, 16,
15, -4, -16, -9, 9, 16, 4, -15,
12, -12, -12, 12, 12, -12, -12, 12,
9, -16, 4, 15, -15, -4, 16, -9,
6, -16, 16, -6, -6, 16, -16, 6,
4, -9, 15, -16, 16, -15, 9, -4
} };
static const matrix T4 = { 4, 4, {
17, 17, 17, 17,
22, 10, -10, -22,
17, -17, -17, 17,
10, -22, 22, -10
} };
static const matrix T8t = { 8, 8, {
12, 16, 16, 15, 12, 9, 6, 4,
12, 15, 6, -4, -12, -16, -16, -9,
12, 9, -6, -16, -12, 4, 16, 15,
12, 4, -16, -9, 12, 15, -6, -16,
12, -4, -16, 9, 12, -15, -6, 16,
12, -9, -6, 16, -12, -4, 16, -15,
12, -15, 6, 4, -12, 16, -16, 9,
12, -16, 16, -15, 12, -9, 6, -4
} };
static const matrix T4t = { 4, 4, {
17, 22, 17, 10,
17, 10, -17, -22,
17, -10, -17, 22,
17, -22, 17, -10
} };
static matrix *new_matrix(size_t width, size_t height)
{
matrix *out = av_mallocz(sizeof (matrix) + height * width * sizeof (float));
if (out == NULL) {
fprintf(stderr, "Memory allocation failure\n");
exit(EXIT_FAILURE);
}
out->width = width;
out->height = height;
return out;
}
static matrix *multiply(const matrix *a, const matrix *b)
{
matrix *out;
if (a->width != b->height) {
fprintf(stderr, "Incompatible multiplication\n");
exit(EXIT_FAILURE);
}
out = new_matrix(b->width, a->height);
for (int j = 0; j < out->height; ++j)
for (int i = 0; i < out->width; ++i) {
float sum = 0;
for (int k = 0; k < a->width; ++k)
sum += a->d[j * a->width + k] * b->d[k * b->width + i];
out->d[j * out->width + i] = sum;
}
return out;
}
static void normalise(matrix *a)
{
for (int j = 0; j < a->height; ++j)
for (int i = 0; i < a->width; ++i) {
float *p = a->d + j * a->width + i;
*p *= 64;
if (a->height == 4)
*p /= (const unsigned[]) { 289, 292, 289, 292 } [j];
else
*p /= (const unsigned[]) { 288, 289, 292, 289, 288, 289, 292, 289 } [j];
if (a->width == 4)
*p /= (const unsigned[]) { 289, 292, 289, 292 } [i];
else
*p /= (const unsigned[]) { 288, 289, 292, 289, 288, 289, 292, 289 } [i];
}
}
static void divide_and_round_nearest(matrix *a, float by)
{
for (int j = 0; j < a->height; ++j)
for (int i = 0; i < a->width; ++i) {
float *p = a->d + j * a->width + i;
*p = rintf(*p / by);
}
}
static void tweak(matrix *a)
{
for (int j = 4; j < a->height; ++j)
for (int i = 0; i < a->width; ++i) {
float *p = a->d + j * a->width + i;
*p += 1;
}
}
/* The VC-1 spec places restrictions on the values permitted at three
* different stages:
* - D: the input coefficients in frequency domain
* - E: the intermediate coefficients, inverse-transformed only horizontally
* - R: the fully inverse-transformed coefficients
*
* To fully cater for the ranges specified requires various intermediate
* values to be held to 17-bit precision; yet these conditions do not appear
* to be utilised in real-world streams. At least some assembly
* implementations have chosen to restrict these values to 16-bit precision,
* to accelerate the decoding of real-world streams at the cost of strict
* adherence to the spec. To avoid our test marking these as failures,
* reduce our random inputs.
*/
#define ATTENUATION 4
static matrix *generate_inverse_quantized_transform_coefficients(size_t width, size_t height)
{
matrix *raw, *tmp, *D, *E, *R;
raw = new_matrix(width, height);
for (int i = 0; i < width * height; ++i)
raw->d[i] = (int) (rnd() % (1024/ATTENUATION)) - 512/ATTENUATION;
tmp = multiply(height == 8 ? &T8 : &T4, raw);
D = multiply(tmp, width == 8 ? &T8t : &T4t);
normalise(D);
divide_and_round_nearest(D, 1);
for (int i = 0; i < width * height; ++i) {
if (D->d[i] < -2048/ATTENUATION || D->d[i] > 2048/ATTENUATION-1) {
/* Rare, so simply try again */
av_free(raw);
av_free(tmp);
av_free(D);
return generate_inverse_quantized_transform_coefficients(width, height);
}
}
E = multiply(D, width == 8 ? &T8 : &T4);
divide_and_round_nearest(E, 8);
for (int i = 0; i < width * height; ++i)
if (E->d[i] < -4096/ATTENUATION || E->d[i] > 4096/ATTENUATION-1) {
/* Rare, so simply try again */
av_free(raw);
av_free(tmp);
av_free(D);
av_free(E);
return generate_inverse_quantized_transform_coefficients(width, height);
}
R = multiply(height == 8 ? &T8t : &T4t, E);
tweak(R);
divide_and_round_nearest(R, 128);
for (int i = 0; i < width * height; ++i)
if (R->d[i] < -512/ATTENUATION || R->d[i] > 512/ATTENUATION-1) {
/* Rare, so simply try again */
av_free(raw);
av_free(tmp);
av_free(D);
av_free(E);
av_free(R);
return generate_inverse_quantized_transform_coefficients(width, height);
}
av_free(raw);
av_free(tmp);
av_free(E);
av_free(R);
return D;
}
#define RANDOMIZE_BUFFER16(name, size) \
do { \
int i; \
for (i = 0; i < size; ++i) { \
uint16_t r = rnd(); \
AV_WN16A(name##0 + i, r); \
AV_WN16A(name##1 + i, r); \
} \
} while (0)
#define RANDOMIZE_BUFFER8(name, size) \
do { \
int i; \
for (i = 0; i < size; ++i) { \
uint8_t r = rnd(); \
name##0[i] = r; \
name##1[i] = r; \
} \
} while (0)
#define RANDOMIZE_BUFFER8_MID_WEIGHTED(name, size) \
do { \
uint8_t *p##0 = name##0, *p##1 = name##1; \
int i = (size); \
while (i-- > 0) { \
int x = 0x80 | (rnd() & 0x7F); \
x >>= rnd() % 9; \
if (rnd() & 1) \
x = -x; \
*p##1++ = *p##0++ = 0x80 + x; \
} \
} while (0)
static void check_inv_trans_inplace(void)
{
/* Inverse transform input coefficients are stored in a 16-bit buffer
* with row stride of 8 coefficients irrespective of transform size.
* vc1_inv_trans_8x8 differs from the others in two ways: coefficients
* are stored in column-major order, and the outputs are written back
* to the input buffer, so we oversize it slightly to catch overruns. */
LOCAL_ALIGNED_16(int16_t, inv_trans_in0, [10 * 8]);
LOCAL_ALIGNED_16(int16_t, inv_trans_in1, [10 * 8]);
VC1DSPContext h;
ff_vc1dsp_init(&h);
if (check_func(h.vc1_inv_trans_8x8, "vc1dsp.vc1_inv_trans_8x8")) {
matrix *coeffs;
declare_func(void, int16_t *);
RANDOMIZE_BUFFER16(inv_trans_in, 10 * 8);
coeffs = generate_inverse_quantized_transform_coefficients(8, 8);
for (int j = 0; j < 8; ++j)
for (int i = 0; i < 8; ++i) {
int idx = 8 + i * 8 + j;
inv_trans_in1[idx] = inv_trans_in0[idx] = coeffs->d[j * 8 + i];
}
call_ref(inv_trans_in0 + 8);
call_new(inv_trans_in1 + 8);
if (memcmp(inv_trans_in0, inv_trans_in1, 10 * 8 * sizeof (int16_t)))
fail();
bench_new(inv_trans_in1 + 8);
av_free(coeffs);
}
}
static void check_inv_trans_adding(void)
{
/* Inverse transform input coefficients are stored in a 16-bit buffer
* with row stride of 8 coefficients irrespective of transform size. */
LOCAL_ALIGNED_16(int16_t, inv_trans_in0, [8 * 8]);
LOCAL_ALIGNED_16(int16_t, inv_trans_in1, [8 * 8]);
/* For all but vc1_inv_trans_8x8, the inverse transform is narrowed and
* added with saturation to an array of unsigned 8-bit values. Oversize
* this by 8 samples left and right and one row above and below. */
LOCAL_ALIGNED_8(uint8_t, inv_trans_out0, [10 * 24]);
LOCAL_ALIGNED_8(uint8_t, inv_trans_out1, [10 * 24]);
VC1DSPContext h;
const test tests[] = {
VC1DSP_SIZED_TEST(vc1_inv_trans_8x4, 8, 4)
VC1DSP_SIZED_TEST(vc1_inv_trans_4x8, 4, 8)
VC1DSP_SIZED_TEST(vc1_inv_trans_4x4, 4, 4)
VC1DSP_SIZED_TEST(vc1_inv_trans_8x8_dc, 8, 8)
VC1DSP_SIZED_TEST(vc1_inv_trans_8x4_dc, 8, 4)
VC1DSP_SIZED_TEST(vc1_inv_trans_4x8_dc, 4, 8)
VC1DSP_SIZED_TEST(vc1_inv_trans_4x4_dc, 4, 4)
};
ff_vc1dsp_init(&h);
for (size_t t = 0; t < FF_ARRAY_ELEMS(tests); ++t) {
void (*func)(uint8_t *, ptrdiff_t, int16_t *) = *(void **)((intptr_t) &h + tests[t].offset);
if (check_func(func, "vc1dsp.%s", tests[t].name)) {
matrix *coeffs;
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, ptrdiff_t, int16_t *);
RANDOMIZE_BUFFER16(inv_trans_in, 8 * 8);
RANDOMIZE_BUFFER8(inv_trans_out, 10 * 24);
coeffs = generate_inverse_quantized_transform_coefficients(tests[t].width, tests[t].height);
for (int j = 0; j < tests[t].height; ++j)
for (int i = 0; i < tests[t].width; ++i) {
int idx = j * 8 + i;
inv_trans_in1[idx] = inv_trans_in0[idx] = coeffs->d[j * tests[t].width + i];
}
call_ref(inv_trans_out0 + 24 + 8, 24, inv_trans_in0);
call_new(inv_trans_out1 + 24 + 8, 24, inv_trans_in1);
if (memcmp(inv_trans_out0, inv_trans_out1, 10 * 24))
fail();
bench_new(inv_trans_out1 + 24 + 8, 24, inv_trans_in1 + 8);
av_free(coeffs);
}
}
}
static void check_loop_filter(void)
{
/* Deblocking filter buffers are big enough to hold a 16x16 block,
* plus 16 columns left and 4 rows above to hold filter inputs
* (depending on whether v or h neighbouring block edge, oversized
* horizontally to maintain 16-byte alignment) plus 16 columns and
* 4 rows below to catch write overflows */
LOCAL_ALIGNED_16(uint8_t, filter_buf0, [24 * 48]);
LOCAL_ALIGNED_16(uint8_t, filter_buf1, [24 * 48]);
VC1DSPContext h;
const test tests[] = {
VC1DSP_TEST(vc1_v_loop_filter4)
VC1DSP_TEST(vc1_h_loop_filter4)
VC1DSP_TEST(vc1_v_loop_filter8)
VC1DSP_TEST(vc1_h_loop_filter8)
VC1DSP_TEST(vc1_v_loop_filter16)
VC1DSP_TEST(vc1_h_loop_filter16)
};
ff_vc1dsp_init(&h);
for (size_t t = 0; t < FF_ARRAY_ELEMS(tests); ++t) {
void (*func)(uint8_t *, ptrdiff_t, int) = *(void **)((intptr_t) &h + tests[t].offset);
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, ptrdiff_t, int);
if (check_func(func, "vc1dsp.%s", tests[t].name)) {
for (int count = 1000; count > 0; --count) {
int pq = rnd() % 31 + 1;
RANDOMIZE_BUFFER8_MID_WEIGHTED(filter_buf, 24 * 48);
call_ref(filter_buf0 + 4 * 48 + 16, 48, pq);
call_new(filter_buf1 + 4 * 48 + 16, 48, pq);
if (memcmp(filter_buf0, filter_buf1, 24 * 48))
fail();
}
}
for (int j = 0; j < 24; ++j)
for (int i = 0; i < 48; ++i)
filter_buf1[j * 48 + i] = 0x60 + 0x40 * (i >= 16 && j >= 4);
if (check_func(func, "vc1dsp.%s_bestcase", tests[t].name))
bench_new(filter_buf1 + 4 * 48 + 16, 48, 1);
if (check_func(func, "vc1dsp.%s_worstcase", tests[t].name))
bench_new(filter_buf1 + 4 * 48 + 16, 48, 31);
}
}
#define TEST_UNESCAPE \
do { \
for (int count = 100; count > 0; --count) { \
escaped_offset = rnd() & 7; \
unescaped_offset = rnd() & 7; \
escaped_len = (1u << (rnd() % 8) + 3) - (rnd() & 7); \
RANDOMIZE_BUFFER8(unescaped, UNESCAPE_BUF_SIZE); \
len0 = call_ref(escaped0 + escaped_offset, escaped_len, unescaped0 + unescaped_offset); \
len1 = call_new(escaped1 + escaped_offset, escaped_len, unescaped1 + unescaped_offset); \
if (len0 != len1 || memcmp(unescaped0, unescaped1, UNESCAPE_BUF_SIZE)) \
fail(); \
} \
} while (0)
static void check_unescape(void)
{
/* This appears to be a typical length of buffer in use */
#define LOG2_UNESCAPE_BUF_SIZE 17
#define UNESCAPE_BUF_SIZE (1u<<LOG2_UNESCAPE_BUF_SIZE)
LOCAL_ALIGNED_8(uint8_t, escaped0, [UNESCAPE_BUF_SIZE]);
LOCAL_ALIGNED_8(uint8_t, escaped1, [UNESCAPE_BUF_SIZE]);
LOCAL_ALIGNED_8(uint8_t, unescaped0, [UNESCAPE_BUF_SIZE]);
LOCAL_ALIGNED_8(uint8_t, unescaped1, [UNESCAPE_BUF_SIZE]);
VC1DSPContext h;
ff_vc1dsp_init(&h);
if (check_func(h.vc1_unescape_buffer, "vc1dsp.vc1_unescape_buffer")) {
int len0, len1, escaped_offset, unescaped_offset, escaped_len;
declare_func(int, const uint8_t *, int, uint8_t *);
/* Test data which consists of escapes sequences packed as tightly as possible */
for (int x = 0; x < UNESCAPE_BUF_SIZE; ++x)
escaped1[x] = escaped0[x] = 3 * (x % 3 == 0);
TEST_UNESCAPE;
/* Test random data */
RANDOMIZE_BUFFER8(escaped, UNESCAPE_BUF_SIZE);
TEST_UNESCAPE;
/* Test data with escape sequences at random intervals */
for (int x = 0; x <= UNESCAPE_BUF_SIZE - 4;) {
int gap, gap_msb;
escaped1[x+0] = escaped0[x+0] = 0;
escaped1[x+1] = escaped0[x+1] = 0;
escaped1[x+2] = escaped0[x+2] = 3;
escaped1[x+3] = escaped0[x+3] = rnd() & 3;
gap_msb = 2u << (rnd() % 8);
gap = (rnd() &~ -gap_msb) | gap_msb;
x += gap;
}
TEST_UNESCAPE;
/* Test data which is known to contain no escape sequences */
memset(escaped0, 0xFF, UNESCAPE_BUF_SIZE);
memset(escaped1, 0xFF, UNESCAPE_BUF_SIZE);
TEST_UNESCAPE;
/* Benchmark the no-escape-sequences case */
bench_new(escaped1, UNESCAPE_BUF_SIZE, unescaped1);
}
}
static void check_mspel_pixels(void)
{
LOCAL_ALIGNED_16(uint8_t, src0, [32 * 32]);
LOCAL_ALIGNED_16(uint8_t, src1, [32 * 32]);
LOCAL_ALIGNED_16(uint8_t, dst0, [32 * 32]);
LOCAL_ALIGNED_16(uint8_t, dst1, [32 * 32]);
VC1DSPContext h;
const test tests[] = {
VC1DSP_SIZED_TEST(put_vc1_mspel_pixels_tab[0][0], 16, 16)
VC1DSP_SIZED_TEST(put_vc1_mspel_pixels_tab[1][0], 8, 8)
VC1DSP_SIZED_TEST(avg_vc1_mspel_pixels_tab[0][0], 16, 16)
VC1DSP_SIZED_TEST(avg_vc1_mspel_pixels_tab[1][0], 8, 8)
};
ff_vc1dsp_init(&h);
for (size_t t = 0; t < FF_ARRAY_ELEMS(tests); ++t) {
void (*func)(uint8_t *, const uint8_t*, ptrdiff_t, int) = *(void **)((intptr_t) &h + tests[t].offset);
if (check_func(func, "vc1dsp.%s", tests[t].name)) {
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, const uint8_t*, ptrdiff_t, int);
RANDOMIZE_BUFFER8(dst, 32 * 32);
RANDOMIZE_BUFFER8(src, 32 * 32);
call_ref(dst0, src0, 32, 0);
call_new(dst1, src1, 32, 0);
if (memcmp(dst0, dst1, 32 * 32)) {
fail();
}
bench_new(dst1, src0, 32, 0);
}
}
}
void checkasm_check_vc1dsp(void)
{
check_inv_trans_inplace();
check_inv_trans_adding();
report("inv_trans");
check_loop_filter();
report("loop_filter");
check_unescape();
report("unescape_buffer");
check_mspel_pixels();
report("mspel_pixels");
}
+150
View File
@@ -0,0 +1,150 @@
/*
* Copyright (c) 2016 Tiancheng "Timothy" Gu
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavfilter/vf_blend_init.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#define WIDTH 256
#define HEIGHT 256
#define BUF_UNITS 3
#define SIZE_PER_UNIT (WIDTH * HEIGHT)
#define BUF_SIZE (BUF_UNITS * SIZE_PER_UNIT)
#define randomize_buffers() \
do { \
int i, j; \
for (i = 0; i < HEIGHT; i++) { \
for (j = 0; j < WIDTH; j++) { \
top1[i * WIDTH + j] = \
top2[i * WIDTH + j] = i; \
bot1[i * WIDTH + j] = \
bot2[i * WIDTH + j] = j; \
} \
} \
for (i = 0; i < SIZE_PER_UNIT; i += 4) { \
uint32_t r = rnd(); \
AV_WN32A(dst1 + i, r); \
AV_WN32A(dst2 + i, r); \
} \
for (; i < BUF_SIZE; i += 4) { \
uint32_t r = rnd(); \
AV_WN32A(top1 + i, r); \
AV_WN32A(top2 + i, r); \
r = rnd(); \
AV_WN32A(bot1 + i, r); \
AV_WN32A(bot2 + i, r); \
r = rnd(); \
AV_WN32A(dst1 + i, r); \
AV_WN32A(dst2 + i, r); \
} \
} while (0)
#define check_blend_func(depth) \
do { \
int i, w; \
declare_func(void, const uint8_t *top, ptrdiff_t top_linesize, \
const uint8_t *bottom, ptrdiff_t bottom_linesize, \
uint8_t *dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
struct FilterParams *param, struct SliceParams *sliceparam); \
w = WIDTH / depth; \
\
for (i = 0; i < BUF_UNITS - 1; i++) { \
int src_offset = i * SIZE_PER_UNIT + (BUF_UNITS - 1 - i) * depth; /* Test various alignments */ \
int dst_offset = i * SIZE_PER_UNIT; /* dst must be aligned */ \
randomize_buffers(); \
call_ref(top1 + src_offset, w, bot1 + src_offset, w, \
dst1 + dst_offset, w, w, HEIGHT, &param, NULL); \
call_new(top2 + src_offset, w, bot2 + src_offset, w, \
dst2 + dst_offset, w, w, HEIGHT, &param, NULL); \
if (memcmp(top1, top2, BUF_SIZE) || memcmp(bot1, bot2, BUF_SIZE) || memcmp(dst1, dst2, BUF_SIZE)) \
fail(); \
} \
bench_new(top2, w / 4, bot2, w / 4, dst2, w / 4, \
w / 4, HEIGHT / 4, &param, NULL); \
} while (0)
void checkasm_check_blend(void)
{
uint8_t *top1 = av_malloc(BUF_SIZE);
uint8_t *top2 = av_malloc(BUF_SIZE);
uint8_t *bot1 = av_malloc(BUF_SIZE);
uint8_t *bot2 = av_malloc(BUF_SIZE);
uint8_t *dst1 = av_malloc(BUF_SIZE);
uint8_t *dst2 = av_malloc(BUF_SIZE);
FilterParams param = {
.opacity = 1.0,
};
#define check_and_report(name, val, depth) \
param.mode = val; \
ff_blend_init(&param, depth * 8); \
if (check_func(param.blend, #name)) \
check_blend_func(depth);
check_and_report(addition, BLEND_ADDITION, 1)
check_and_report(grainmerge, BLEND_GRAINMERGE, 1)
check_and_report(and, BLEND_AND, 1)
check_and_report(average, BLEND_AVERAGE, 1)
check_and_report(darken, BLEND_DARKEN, 1)
check_and_report(grainextract, BLEND_GRAINEXTRACT, 1)
check_and_report(hardmix, BLEND_HARDMIX, 1)
check_and_report(lighten, BLEND_LIGHTEN, 1)
check_and_report(multiply, BLEND_MULTIPLY, 1)
check_and_report(or, BLEND_OR, 1)
check_and_report(phoenix, BLEND_PHOENIX, 1)
check_and_report(screen, BLEND_SCREEN, 1)
check_and_report(subtract, BLEND_SUBTRACT, 1)
check_and_report(xor, BLEND_XOR, 1)
check_and_report(difference, BLEND_DIFFERENCE, 1)
check_and_report(extremity, BLEND_EXTREMITY, 1)
check_and_report(negation, BLEND_NEGATION, 1)
report("8bit");
check_and_report(addition_16, BLEND_ADDITION, 2)
check_and_report(grainmerge_16, BLEND_GRAINMERGE, 2)
check_and_report(and_16, BLEND_AND, 2)
check_and_report(average_16, BLEND_AVERAGE, 2)
check_and_report(darken_16, BLEND_DARKEN, 2)
check_and_report(grainextract_16, BLEND_GRAINEXTRACT, 2)
check_and_report(difference_16, BLEND_DIFFERENCE, 2)
check_and_report(extremity_16, BLEND_EXTREMITY, 2)
check_and_report(negation_16, BLEND_NEGATION, 2)
check_and_report(lighten_16, BLEND_LIGHTEN, 2)
check_and_report(or_16, BLEND_OR, 2)
check_and_report(phoenix_16, BLEND_PHOENIX, 2)
check_and_report(subtract_16, BLEND_SUBTRACT, 2)
check_and_report(xor_16, BLEND_SUBTRACT, 2)
report("16bit");
av_freep(&top1);
av_freep(&top2);
av_freep(&bot1);
av_freep(&bot2);
av_freep(&dst1);
av_freep(&dst2);
}
+255
View File
@@ -0,0 +1,255 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavfilter/bwdifdsp.h"
#include "libavutil/mem_internal.h"
#define WIDTH 256
#define randomize_buffers(buf0, buf1, mask, count) \
for (size_t i = 0; i < count; i++) \
buf0[i] = buf1[i] = rnd() & mask
#define randomize_overflow_check(buf0, buf1, mask, count) \
for (size_t i = 0; i < count; i++) \
buf0[i] = buf1[i] = (rnd() & 1) != 0 ? mask : 0;
#define BODY(type, depth) \
do { \
type prev0[9*WIDTH], prev1[9*WIDTH]; \
type next0[9*WIDTH], next1[9*WIDTH]; \
type cur0[9*WIDTH], cur1[9*WIDTH]; \
type dst0[WIDTH], dst1[WIDTH]; \
const int stride = WIDTH; \
const int mask = (1<<depth)-1; \
\
declare_func(void, void *dst, const void *prev, const void *cur, const void *next, \
int w, int prefs, int mrefs, int prefs2, int mrefs2, \
int prefs3, int mrefs3, int prefs4, int mrefs4, \
int parity, int clip_max); \
\
randomize_buffers(prev0, prev1, mask, 9*WIDTH); \
randomize_buffers(next0, next1, mask, 9*WIDTH); \
randomize_buffers( cur0, cur1, mask, 9*WIDTH); \
\
call_ref(dst0, prev0 + 4*WIDTH, cur0 + 4*WIDTH, next0 + 4*WIDTH, \
WIDTH, stride, -stride, 2*stride, -2*stride, \
3*stride, -3*stride, 4*stride, -4*stride, \
0, mask); \
call_new(dst1, prev1 + 4*WIDTH, cur1 + 4*WIDTH, next1 + 4*WIDTH, \
WIDTH, stride, -stride, 2*stride, -2*stride, \
3*stride, -3*stride, 4*stride, -4*stride, \
0, mask); \
\
if (memcmp(dst0, dst1, sizeof dst0) \
|| memcmp(prev0, prev1, sizeof prev0) \
|| memcmp(next0, next1, sizeof next0) \
|| memcmp( cur0, cur1, sizeof cur0)) \
fail(); \
bench_new(dst1, prev1 + 4*WIDTH, cur1 + 4*WIDTH, next1 + 4*WIDTH, \
WIDTH, stride, -stride, 2*stride, -2*stride, \
3*stride, -3*stride, 4*stride, -4*stride, \
0, mask); \
} while (0)
void checkasm_check_vf_bwdif(void)
{
BWDIFDSPContext ctx_8, ctx_10;
ff_bwdif_init_filter_line(&ctx_8, 8);
ff_bwdif_init_filter_line(&ctx_10, 10);
if (check_func(ctx_8.filter_line, "bwdif8")) {
BODY(uint8_t, 8);
report("bwdif8");
}
if (check_func(ctx_10.filter_line, "bwdif10")) {
BODY(uint16_t, 10);
report("bwdif10");
}
if (!ctx_8.filter_line3)
ctx_8.filter_line3 = ff_bwdif_filter_line3_c;
{
LOCAL_ALIGNED_16(uint8_t, prev0, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, prev1, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, next0, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, next1, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, cur0, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, cur1, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, dst0, [WIDTH*3]);
LOCAL_ALIGNED_16(uint8_t, dst1, [WIDTH*3]);
const int stride = WIDTH;
const int mask = (1<<8)-1;
int parity;
for (parity = 0; parity != 2; ++parity) {
if (check_func(ctx_8.filter_line3, "bwdif8.line3.rnd.p%d", parity)) {
declare_func(void, void * dst1, int d_stride,
const void * prev1, const void * cur1, const void * next1, int prefs,
int w, int parity, int clip_max);
randomize_buffers(prev0, prev1, mask, 11*WIDTH);
randomize_buffers(next0, next1, mask, 11*WIDTH);
randomize_buffers( cur0, cur1, mask, 11*WIDTH);
call_ref(dst0, stride,
prev0 + stride * 4, cur0 + stride * 4, next0 + stride * 4, stride,
WIDTH, parity, mask);
call_new(dst1, stride,
prev1 + stride * 4, cur1 + stride * 4, next1 + stride * 4, stride,
WIDTH, parity, mask);
if (memcmp(dst0, dst1, WIDTH*3)
|| memcmp(prev0, prev1, WIDTH*11)
|| memcmp(next0, next1, WIDTH*11)
|| memcmp( cur0, cur1, WIDTH*11))
fail();
bench_new(dst1, stride,
prev1 + stride * 4, cur1 + stride * 4, next1 + stride * 4, stride,
WIDTH, parity, mask);
}
}
// Use just 0s and ~0s to try to provoke bad cropping or overflow
// Parity makes no difference to this test so just test 0
if (check_func(ctx_8.filter_line3, "bwdif8.line3.overflow")) {
declare_func(void, void * dst1, int d_stride,
const void * prev1, const void * cur1, const void * next1, int prefs,
int w, int parity, int clip_max);
randomize_overflow_check(prev0, prev1, mask, 11*WIDTH);
randomize_overflow_check(next0, next1, mask, 11*WIDTH);
randomize_overflow_check( cur0, cur1, mask, 11*WIDTH);
call_ref(dst0, stride,
prev0 + stride * 4, cur0 + stride * 4, next0 + stride * 4, stride,
WIDTH, 0, mask);
call_new(dst1, stride,
prev1 + stride * 4, cur1 + stride * 4, next1 + stride * 4, stride,
WIDTH, 0, mask);
if (memcmp(dst0, dst1, WIDTH*3)
|| memcmp(prev0, prev1, WIDTH*11)
|| memcmp(next0, next1, WIDTH*11)
|| memcmp( cur0, cur1, WIDTH*11))
fail();
// No point to benching
}
report("bwdif8.line3");
}
{
LOCAL_ALIGNED_16(uint8_t, prev0, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, prev1, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, next0, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, next1, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, cur0, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, cur1, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, dst0, [WIDTH*3]);
LOCAL_ALIGNED_16(uint8_t, dst1, [WIDTH*3]);
const int stride = WIDTH;
const int mask = (1<<8)-1;
int spat;
int parity;
for (spat = 0; spat != 2; ++spat) {
for (parity = 0; parity != 2; ++parity) {
if (check_func(ctx_8.filter_edge, "bwdif8.edge.s%d.p%d", spat, parity)) {
declare_func(void, void *dst1, const void *prev1, const void *cur1, const void *next1,
int w, int prefs, int mrefs, int prefs2, int mrefs2,
int parity, int clip_max, int spat);
randomize_buffers(prev0, prev1, mask, 11*WIDTH);
randomize_buffers(next0, next1, mask, 11*WIDTH);
randomize_buffers( cur0, cur1, mask, 11*WIDTH);
memset(dst0, 0xba, WIDTH * 3);
memset(dst1, 0xba, WIDTH * 3);
call_ref(dst0 + stride,
prev0 + stride * 4, cur0 + stride * 4, next0 + stride * 4, WIDTH,
stride, -stride, stride * 2, -stride * 2,
parity, mask, spat);
call_new(dst1 + stride,
prev1 + stride * 4, cur1 + stride * 4, next1 + stride * 4, WIDTH,
stride, -stride, stride * 2, -stride * 2,
parity, mask, spat);
if (memcmp(dst0, dst1, WIDTH*3)
|| memcmp(prev0, prev1, WIDTH*11)
|| memcmp(next0, next1, WIDTH*11)
|| memcmp( cur0, cur1, WIDTH*11))
fail();
bench_new(dst1 + stride,
prev1 + stride * 4, cur1 + stride * 4, next1 + stride * 4, WIDTH,
stride, -stride, stride * 2, -stride * 2,
parity, mask, spat);
}
}
}
report("bwdif8.edge");
}
if (check_func(ctx_8.filter_intra, "bwdif8.intra")) {
LOCAL_ALIGNED_16(uint8_t, cur0, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, cur1, [11*WIDTH]);
LOCAL_ALIGNED_16(uint8_t, dst0, [WIDTH*3]);
LOCAL_ALIGNED_16(uint8_t, dst1, [WIDTH*3]);
const int stride = WIDTH;
const int mask = (1<<8)-1;
declare_func(void, void *dst1, const void *cur1, int w, int prefs, int mrefs,
int prefs3, int mrefs3, int parity, int clip_max);
randomize_buffers( cur0, cur1, mask, 11*WIDTH);
memset(dst0, 0xba, WIDTH * 3);
memset(dst1, 0xba, WIDTH * 3);
call_ref(dst0 + stride,
cur0 + stride * 4, WIDTH,
stride, -stride, stride * 3, -stride * 3,
0, mask);
call_new(dst1 + stride,
cur0 + stride * 4, WIDTH,
stride, -stride, stride * 3, -stride * 3,
0, mask);
if (memcmp(dst0, dst1, WIDTH*3)
|| memcmp( cur0, cur1, WIDTH*11))
fail();
bench_new(dst1 + stride,
cur0 + stride * 4, WIDTH,
stride, -stride, stride * 3, -stride * 3,
0, mask);
report("bwdif8.intra");
}
}
+315
View File
@@ -0,0 +1,315 @@
/*
* Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com>
*
* 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 <string.h>
#include "checkasm.h"
#include "libavfilter/colorspacedsp.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define W 64
#define H 64
#define randomize_buffers() \
do { \
unsigned mask = bpp_mask[idepth]; \
int n, m; \
int bpp = 1 + (!!idepth); \
int buf_size = W * H * bpp; \
for (m = 0; m < 3; m++) { \
int ss = m ? ss_w + ss_h : 0; \
int plane_sz = buf_size >> ss; \
for (n = 0; n < plane_sz; n += 4) { \
unsigned r = rnd() & mask; \
AV_WN32A(&src[m][n], r); \
} \
} \
} while (0)
static const char *format_string[] = {
"444", "422", "420"
};
static const unsigned bpp_mask[] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
static void check_yuv2yuv(void)
{
declare_func(void, uint8_t *dst[3], const ptrdiff_t dst_stride[3],
uint8_t *src[3], const ptrdiff_t src_stride[3],
int w, int h, const int16_t coeff[3][3][8],
const int16_t off[2][8]);
ColorSpaceDSPContext dsp;
int idepth, odepth, fmt, n;
LOCAL_ALIGNED_32(uint8_t, src_y, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, src_u, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, src_v, [W * H * 2]);
uint8_t *src[3] = { src_y, src_u, src_v };
LOCAL_ALIGNED_32(uint8_t, dst0_y, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0_u, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0_v, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1_y, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1_u, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1_v, [W * H * 2]);
uint8_t *dst0[3] = { dst0_y, dst0_u, dst0_v }, *dst1[3] = { dst1_y, dst1_u, dst1_v };
LOCAL_ALIGNED_32(int16_t, offset_buf, [16]);
LOCAL_ALIGNED_32(int16_t, coeff_buf, [3 * 3 * 8]);
int16_t (*offset)[8] = (int16_t(*)[8]) offset_buf;
int16_t (*coeff)[3][8] = (int16_t(*)[3][8]) coeff_buf;
ff_colorspacedsp_init(&dsp);
for (n = 0; n < 8; n++) {
offset[0][n] = offset[1][n] = 16;
coeff[0][0][n] = (1 << 14) + (1 << 7) + 1;
coeff[0][1][n] = (1 << 7) - 1;
coeff[0][2][n] = -(1 << 8);
coeff[1][0][n] = coeff[2][0][n] = 0;
coeff[1][1][n] = (1 << 14) + (1 << 7);
coeff[1][2][n] = -(1 << 7);
coeff[2][2][n] = (1 << 14) - (1 << 6);
coeff[2][1][n] = 1 << 6;
}
for (idepth = 0; idepth < 3; idepth++) {
for (odepth = 0; odepth < 3; odepth++) {
for (fmt = 0; fmt < 3; fmt++) {
if (check_func(dsp.yuv2yuv[idepth][odepth][fmt],
"ff_colorspacedsp_yuv2yuv_%sp%dto%d",
format_string[fmt],
idepth * 2 + 8, odepth * 2 + 8)) {
int ss_w = !!fmt, ss_h = fmt == 2;
int y_src_stride = W << !!idepth, y_dst_stride = W << !!odepth;
int uv_src_stride = y_src_stride >> ss_w, uv_dst_stride = y_dst_stride >> ss_w;
randomize_buffers();
call_ref(dst0, (ptrdiff_t[3]) { y_dst_stride, uv_dst_stride, uv_dst_stride },
src, (ptrdiff_t[3]) { y_src_stride, uv_src_stride, uv_src_stride },
W, H, coeff, offset);
call_new(dst1, (ptrdiff_t[3]) { y_dst_stride, uv_dst_stride, uv_dst_stride },
src, (ptrdiff_t[3]) { y_src_stride, uv_src_stride, uv_src_stride },
W, H, coeff, offset);
if (memcmp(dst0[0], dst1[0], y_dst_stride * H) ||
memcmp(dst0[1], dst1[1], uv_dst_stride * H >> ss_h) ||
memcmp(dst0[2], dst1[2], uv_dst_stride * H >> ss_h)) {
fail();
}
}
}
}
}
report("yuv2yuv");
}
static void check_yuv2rgb(void)
{
declare_func(void, int16_t *dst[3], ptrdiff_t dst_stride,
uint8_t *src[3], const ptrdiff_t src_stride[3],
int w, int h, const int16_t coeff[3][3][8],
const int16_t off[8]);
ColorSpaceDSPContext dsp;
int idepth, fmt, n;
LOCAL_ALIGNED_32(uint8_t, src_y, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, src_u, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, src_v, [W * H * 2]);
uint8_t *src[3] = { src_y, src_u, src_v };
LOCAL_ALIGNED_32(int16_t, dst0_y, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst0_u, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst0_v, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst1_y, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst1_u, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst1_v, [W * H]);
int16_t *dst0[3] = { dst0_y, dst0_u, dst0_v }, *dst1[3] = { dst1_y, dst1_u, dst1_v };
LOCAL_ALIGNED_32(int16_t, offset, [8]);
LOCAL_ALIGNED_32(int16_t, coeff_buf, [3 * 3 * 8]);
int16_t (*coeff)[3][8] = (int16_t(*)[3][8]) coeff_buf;
ff_colorspacedsp_init(&dsp);
for (n = 0; n < 8; n++) {
offset[n] = 16;
coeff[0][0][n] = coeff[1][0][n] = coeff[2][0][n] = (1 << 14) | 1;
coeff[0][1][n] = coeff[2][2][n] = 0;
coeff[0][2][n] = 1 << 13;
coeff[1][1][n] = -(1 << 12);
coeff[1][2][n] = 1 << 12;
coeff[2][1][n] = 1 << 11;
}
for (idepth = 0; idepth < 3; idepth++) {
for (fmt = 0; fmt < 3; fmt++) {
if (check_func(dsp.yuv2rgb[idepth][fmt],
"ff_colorspacedsp_yuv2rgb_%sp%d",
format_string[fmt], idepth * 2 + 8)) {
int ss_w = !!fmt, ss_h = fmt == 2;
int y_src_stride = W << !!idepth;
int uv_src_stride = y_src_stride >> ss_w;
randomize_buffers();
call_ref(dst0, W, src,
(ptrdiff_t[3]) { y_src_stride, uv_src_stride, uv_src_stride },
W, H, coeff, offset);
call_new(dst1, W, src,
(ptrdiff_t[3]) { y_src_stride, uv_src_stride, uv_src_stride },
W, H, coeff, offset);
if (memcmp(dst0[0], dst1[0], W * H * sizeof(int16_t)) ||
memcmp(dst0[1], dst1[1], W * H * sizeof(int16_t)) ||
memcmp(dst0[2], dst1[2], W * H * sizeof(int16_t))) {
fail();
}
}
}
}
report("yuv2rgb");
}
#undef randomize_buffers
#define randomize_buffers() \
do { \
int y, x, p; \
for (p = 0; p < 3; p++) { \
for (y = 0; y < H; y++) { \
for (x = 0; x < W; x++) { \
int r = rnd() & 0x7fff; \
r -= (32768 - 28672) >> 1; \
src[p][y * W + x] = r; \
} \
} \
} \
} while (0)
static void check_rgb2yuv(void)
{
declare_func(void, uint8_t *dst[3], const ptrdiff_t dst_stride[3],
int16_t *src[3], ptrdiff_t src_stride,
int w, int h, const int16_t coeff[3][3][8],
const int16_t off[8]);
ColorSpaceDSPContext dsp;
int odepth, fmt, n;
LOCAL_ALIGNED_32(int16_t, src_y, [W * H * 2]);
LOCAL_ALIGNED_32(int16_t, src_u, [W * H * 2]);
LOCAL_ALIGNED_32(int16_t, src_v, [W * H * 2]);
int16_t *src[3] = { src_y, src_u, src_v };
LOCAL_ALIGNED_32(uint8_t, dst0_y, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0_u, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0_v, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1_y, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1_u, [W * H * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1_v, [W * H * 2]);
uint8_t *dst0[3] = { dst0_y, dst0_u, dst0_v }, *dst1[3] = { dst1_y, dst1_u, dst1_v };
LOCAL_ALIGNED_32(int16_t, offset, [8]);
LOCAL_ALIGNED_32(int16_t, coeff_buf, [3 * 3 * 8]);
int16_t (*coeff)[3][8] = (int16_t(*)[3][8]) coeff_buf;
ff_colorspacedsp_init(&dsp);
for (n = 0; n < 8; n++) {
offset[n] = 16;
// these somewhat resemble bt601/smpte170m coefficients
coeff[0][0][n] = lrint(0.3 * (1 << 14));
coeff[0][1][n] = lrint(0.6 * (1 << 14));
coeff[0][2][n] = lrint(0.1 * (1 << 14));
coeff[1][0][n] = lrint(-0.15 * (1 << 14));
coeff[1][1][n] = lrint(-0.35 * (1 << 14));
coeff[1][2][n] = lrint(0.5 * (1 << 14));
coeff[2][0][n] = lrint(0.5 * (1 << 14));
coeff[2][1][n] = lrint(-0.42 * (1 << 14));
coeff[2][2][n] = lrint(-0.08 * (1 << 14));
}
for (odepth = 0; odepth < 3; odepth++) {
for (fmt = 0; fmt < 3; fmt++) {
if (check_func(dsp.rgb2yuv[odepth][fmt],
"ff_colorspacedsp_rgb2yuv_%sp%d",
format_string[fmt], odepth * 2 + 8)) {
int ss_w = !!fmt, ss_h = fmt == 2;
int y_dst_stride = W << !!odepth;
int uv_dst_stride = y_dst_stride >> ss_w;
randomize_buffers();
call_ref(dst0, (ptrdiff_t[3]) { y_dst_stride, uv_dst_stride, uv_dst_stride },
src, W, W, H, coeff, offset);
call_new(dst1, (ptrdiff_t[3]) { y_dst_stride, uv_dst_stride, uv_dst_stride },
src, W, W, H, coeff, offset);
if (memcmp(dst0[0], dst1[0], H * y_dst_stride) ||
memcmp(dst0[1], dst1[1], H * uv_dst_stride >> ss_h) ||
memcmp(dst0[2], dst1[2], H * uv_dst_stride >> ss_h)) {
fail();
}
}
}
}
report("rgb2yuv");
}
static void check_multiply3x3(void)
{
declare_func(void, int16_t *data[3], ptrdiff_t stride,
int w, int h, const int16_t coeff[3][3][8]);
ColorSpaceDSPContext dsp;
LOCAL_ALIGNED_32(int16_t, dst0_y, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst0_u, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst0_v, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst1_y, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst1_u, [W * H]);
LOCAL_ALIGNED_32(int16_t, dst1_v, [W * H]);
int16_t *dst0[3] = { dst0_y, dst0_u, dst0_v }, *dst1[3] = { dst1_y, dst1_u, dst1_v };
int16_t **src = dst0;
LOCAL_ALIGNED_32(int16_t, coeff_buf, [3 * 3 * 8]);
int16_t (*coeff)[3][8] = (int16_t(*)[3][8]) coeff_buf;
int n;
ff_colorspacedsp_init(&dsp);
for (n = 0; n < 8; n++) {
coeff[0][0][n] = lrint(0.85 * (1 << 14));
coeff[0][1][n] = lrint(0.10 * (1 << 14));
coeff[0][2][n] = lrint(0.05 * (1 << 14));
coeff[1][0][n] = lrint(-0.1 * (1 << 14));
coeff[1][1][n] = lrint(0.95 * (1 << 14));
coeff[1][2][n] = lrint(0.15 * (1 << 14));
coeff[2][0][n] = lrint(-0.2 * (1 << 14));
coeff[2][1][n] = lrint(0.30 * (1 << 14));
coeff[2][2][n] = lrint(0.90 * (1 << 14));
}
if (check_func(dsp.multiply3x3, "ff_colorspacedsp_multiply3x3")) {
randomize_buffers();
memcpy(dst1_y, dst0_y, W * H * sizeof(*dst1_y));
memcpy(dst1_u, dst0_u, W * H * sizeof(*dst1_u));
memcpy(dst1_v, dst0_v, W * H * sizeof(*dst1_v));
call_ref(dst0, W, W, H, coeff);
call_new(dst1, W, W, H, coeff);
if (memcmp(dst0[0], dst1[0], H * W * sizeof(*dst0_y)) ||
memcmp(dst0[1], dst1[1], H * W * sizeof(*dst0_u)) ||
memcmp(dst0[2], dst1[2], H * W * sizeof(*dst0_v))) {
fail();
}
}
report("multiply3x3");
}
void checkasm_check_colorspace(void)
{
check_yuv2yuv();
check_yuv2rgb();
check_rgb2yuv();
check_multiply3x3();
}
+104
View File
@@ -0,0 +1,104 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavfilter/avfilter.h"
#include "libavfilter/convolution.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define WIDTH 512
#define HEIGHT 512
#define SRC_STRIDE 512
#define PIXELS (WIDTH * HEIGHT)
#define randomize_buffers(buf, size) \
do { \
int j; \
uint8_t *tmp_buf = (uint8_t *)buf;\
for (j = 0; j< size; j++) \
tmp_buf[j] = rnd() & 0xFF; \
} while (0)
static void check_sobel(const char * report_name)
{
LOCAL_ALIGNED_32(uint8_t, src, [PIXELS]);
LOCAL_ALIGNED_32(uint8_t, dst_ref, [PIXELS]);
LOCAL_ALIGNED_32(uint8_t, dst_new, [PIXELS]);
const int height = WIDTH;
const int width = HEIGHT;
const int stride = SRC_STRIDE;
const int dstride = SRC_STRIDE;
int mode = 0;
const uint8_t *c[49];
const int radius = 1;
const int bpc = 1;
const int step = mode == MATRIX_COLUMN ? 16 : 1;
const int slice_start = 0;
const int slice_end = height;
int y;
const int sizew = mode == MATRIX_COLUMN ? height : width;
float scale = 2;
float delta = 10;
ConvolutionContext s;
declare_func(void, uint8_t *dst, int width, float scale, float delta, const int *const matrix,
const uint8_t *c[], int peak, int radius, int dstride, int stride, int size);
s.scale = scale;
s.delta = delta;
s.depth = 8;
s.nb_planes = 3;
s.planes = 15;
ff_sobel_init(&s, s.depth, s.nb_planes);
memset(dst_ref, 0, PIXELS);
memset(dst_new, 0, PIXELS);
randomize_buffers(src, PIXELS);
if (check_func(s.filter[0], "%s", report_name)) {
for (y = slice_start; y < slice_end; y += step) {
const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : radius * bpc;
const int yoff = mode == MATRIX_COLUMN ? radius * dstride : 0;
s.setup[0](radius, c, src, stride, radius, width, y, height, bpc);
call_ref(dst_ref + yoff + xoff, sizew - 2 * radius,
scale, delta, NULL, c, 0, radius,
dstride, stride, slice_end - step);
call_new(dst_new + yoff + xoff, sizew - 2 * radius,
scale, delta, NULL, c, 0, radius,
dstride, stride, slice_end - step);
if (memcmp(dst_ref + yoff + xoff, dst_new + yoff + xoff, slice_end - step))
fail();
bench_new(dst_new + yoff + xoff, sizew - 2 * radius,
scale, delta, NULL, c, 0, radius,
dstride, stride, slice_end - step);
if (mode != MATRIX_COLUMN)
dst_ref += dstride;
}
}
}
void checkasm_check_vf_sobel(void)
{
check_sobel("sobel");
report("convolution:sobel");
}
+80
View File
@@ -0,0 +1,80 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavfilter/avfilter.h"
#include "libavfilter/vf_eq.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define WIDTH 256
#define HEIGHT 256
#define SRC_STRIDE 256
#define PIXELS (WIDTH * HEIGHT)
#define RANDOM_RANGE 80000
#define SCALE 10000
#define randomize_buffers(buf, size) \
do { \
int j; \
uint8_t *tmp_buf = (uint8_t *)buf;\
for (j = 0; j< size; j++) \
tmp_buf[j] = rnd() & 0xFF; \
} while (0)
static void check_eq(void)
{
LOCAL_ALIGNED_32(uint8_t, src, [PIXELS]);
LOCAL_ALIGNED_32(uint8_t, dst_ref, [PIXELS]);
LOCAL_ALIGNED_32(uint8_t, dst_new, [PIXELS]);
int w = WIDTH;
int h = HEIGHT;
int src_stride = SRC_STRIDE;
int dst_stride = SRC_STRIDE;
EQParameters pa;
EQContext eq;
declare_func(void, EQParameters *param, uint8_t *dst, int dst_stride,
const uint8_t *src, int src_stride, int w, int h);
double rand_contrast = (int)(rnd() % (RANDOM_RANGE * 2) - RANDOM_RANGE) /
(SCALE * 1.0);
double rand_brightness = (int)(rnd() % (SCALE * 2) - SCALE) /
(SCALE * 1.0);
pa.contrast = rand_contrast;
pa.brightness = rand_brightness;
memset(dst_ref, 0, PIXELS);
memset(dst_new, 0, PIXELS);
randomize_buffers(src, PIXELS);
ff_eq_init(&eq);
if (check_func(eq.process, "process")) {
call_ref(&pa, dst_ref, dst_stride, src, src_stride, w, h);
call_new(&pa, dst_new, dst_stride, src, src_stride, w, h);
if (memcmp(dst_ref, dst_new, PIXELS))
fail();
bench_new(&pa, dst_new, dst_stride, src, src_stride, w, h);
}
}
void checkasm_check_vf_eq(void)
{
check_eq();
report("eq");
}
+119
View File
@@ -0,0 +1,119 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <float.h>
#include <string.h>
#include "checkasm.h"
#include "libavutil/mem.h"
#include "libavfilter/vf_gblur_init.h"
#define WIDTH 256
#define HEIGHT 256
#define PIXELS (WIDTH * HEIGHT)
#define BUF_SIZE (PIXELS * 4)
#define randomize_buffers(buf, size) \
do { \
int j; \
float *tmp_buf = (float *)buf; \
for (j = 0; j < size; j++) \
tmp_buf[j] = (float)(rnd() & 0xFF); \
} while (0)
static void check_horiz_slice(float *dst_ref, float *dst_new, float *localbuf)
{
int steps = 2;
float nu = 0.101f;
float bscale = 1.112f;
declare_func(void, float *dst, int w, int h, int steps, float nu, float bscale, float *localbuf);
call_ref(dst_ref, WIDTH, HEIGHT, steps, nu, bscale, localbuf);
call_new(dst_new, WIDTH, HEIGHT, steps, nu, bscale, localbuf);
if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) {
fail();
}
bench_new(dst_new, WIDTH, HEIGHT, 1, nu, bscale, localbuf);
}
static void check_verti_slice(float *dst_ref, float *dst_new)
{
int steps = 2;
float nu = 0.101f;
float bscale = 1.112f;
declare_func(void, float *buffer, int width, int height, int column_begin,
int column_end, int steps, float nu, float bscale);
call_ref(dst_ref, WIDTH, HEIGHT, 0, WIDTH, steps, nu, bscale);
call_new(dst_new, WIDTH, HEIGHT, 0, WIDTH, steps, nu, bscale);
if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) {
fail();
}
bench_new(dst_new, WIDTH, HEIGHT, 0, WIDTH, 1, nu, bscale);
}
static void check_postscale_slice(float *dst_ref, float *dst_new)
{
float postscale = 0.0603f;
declare_func(void, float *dst, int len, float postscale, float min, float max);
call_ref(dst_ref, PIXELS, postscale, -FLT_MAX, FLT_MAX);
call_new(dst_new, PIXELS, postscale, -FLT_MAX, FLT_MAX);
if (!float_near_abs_eps_array(dst_ref, dst_new, FLT_EPSILON, PIXELS)) {
fail();
}
bench_new(dst_new, PIXELS, postscale, -FLT_MAX, FLT_MAX);
}
void checkasm_check_vf_gblur(void)
{
float *dst_ref = av_malloc(BUF_SIZE);
float *dst_new = av_malloc(BUF_SIZE);
GBlurContext s;
randomize_buffers(dst_ref, PIXELS);
memcpy(dst_new, dst_ref, BUF_SIZE);
s.planewidth[0] = WIDTH;
s.planeheight[0] = HEIGHT;
ff_gblur_init(&s);
if (check_func(s.horiz_slice, "horiz_slice")) {
check_horiz_slice(dst_ref, dst_new, s.localbuf);
}
report("horiz_slice");
randomize_buffers(dst_ref, PIXELS);
memcpy(dst_new, dst_ref, BUF_SIZE);
if (check_func(s.postscale_slice, "postscale_slice")) {
check_postscale_slice(dst_ref, dst_new);
}
report("postscale_slice");
randomize_buffers(dst_ref, PIXELS);
memcpy(dst_new, dst_ref, BUF_SIZE);
if (check_func(s.verti_slice, "verti_slice")) {
check_verti_slice(dst_ref, dst_new);
}
report("verti_slice");
if (s.localbuf)
av_free(s.localbuf);
av_freep(&dst_ref);
av_freep(&dst_new);
}
+79
View File
@@ -0,0 +1,79 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavfilter/hflip.h"
#include "libavfilter/vf_hflip_init.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define WIDTH 256
#define WIDTH_PADDED 256 + 32
#define randomize_buffers(buf, size) \
do { \
int j; \
uint8_t *tmp_buf = (uint8_t *)buf;\
for (j = 0; j < size; j++) \
tmp_buf[j] = rnd() & 0xFF; \
} while (0)
static void check_hflip(int step, const char * report_name){
LOCAL_ALIGNED_32(uint8_t, src, [WIDTH_PADDED]);
LOCAL_ALIGNED_32(uint8_t, dst_ref, [WIDTH_PADDED]);
LOCAL_ALIGNED_32(uint8_t, dst_new, [WIDTH_PADDED]);
int w = WIDTH;
int i;
int step_array[4] = {1, 1, 1, 1};
FlipContext s;
declare_func(void, const uint8_t *src, uint8_t *dst, int w);
s.bayer_plus1 = 1;
memset(src, 0, WIDTH_PADDED);
memset(dst_ref, 0, WIDTH_PADDED);
memset(dst_new, 0, WIDTH_PADDED);
randomize_buffers(src, WIDTH_PADDED);
if (step == 2) {
w /= 2;
for (i = 0; i < 4; i++)
step_array[i] = step;
}
ff_hflip_init(&s, step_array, 4);
if (check_func(s.flip_line[0], "hflip_%s", report_name)) {
for (i = 1; i < w; i++) {
call_ref(src + (w - 1) * step, dst_ref, i);
call_new(src + (w - 1) * step, dst_new, i);
if (memcmp(dst_ref, dst_new, i * step))
fail();
}
bench_new(src + (w - 1) * step, dst_new, w);
}
}
void checkasm_check_vf_hflip(void)
{
check_hflip(1, "byte");
report("hflip_byte");
check_hflip(2, "short");
report("hflip_short");
}
+114
View File
@@ -0,0 +1,114 @@
/*
* Copyright (c) 2018 Clément Bœsch <u pkh me>
*
* 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 "checkasm.h"
#include "libavfilter/vf_nlmeans_init.h"
#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#define randomize_buffer(buf, size) do { \
int i; \
for (i = 0; i < size / 4; i++) \
((uint32_t *)buf)[i] = rnd(); \
} while (0)
void checkasm_check_nlmeans(void)
{
NLMeansDSPContext dsp = {0};
const int w = 123; // source width
const int h = 45; // source height
const int p = 3; // patch half size
const int r = 2; // research window half size
ff_nlmeans_init(&dsp);
/* See the filter's code for the explanations on the variables */
if (check_func(dsp.compute_safe_ssd_integral_image, "ssd_integral_image")) {
int offx, offy;
const int e = p + r;
const int ii_w = w + e*2;
const int ii_h = h + e*2;
const int ii_lz_32 = FFALIGN(ii_w + 1, 4);
uint32_t *ii_orig_ref = av_calloc(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_ref));
uint32_t *ii_ref = ii_orig_ref + ii_lz_32 + 1;
uint32_t *ii_orig_new = av_calloc(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_new));
uint32_t *ii_new = ii_orig_new + ii_lz_32 + 1;
const int src_lz = FFALIGN(w, 16);
uint8_t *src = av_calloc(h, src_lz);
declare_func(void, uint32_t *dst, ptrdiff_t dst_linesize_32,
const uint8_t *s1, ptrdiff_t linesize1,
const uint8_t *s2, ptrdiff_t linesize2,
int w, int h);
randomize_buffer(src, h * src_lz);
for (offy = -r; offy <= r; offy++) {
for (offx = -r; offx <= r; offx++) {
if (offx || offy) {
const int s1x = e;
const int s1y = e;
const int s2x = e + offx;
const int s2y = e + offy;
const int startx_safe = FFMAX(s1x, s2x);
const int starty_safe = FFMAX(s1y, s2y);
const int u_endx_safe = FFMIN(s1x + w, s2x + w);
const int endy_safe = FFMIN(s1y + h, s2y + h);
const int safe_pw = (u_endx_safe - startx_safe) & ~0xf;
const int safe_ph = endy_safe - starty_safe;
av_assert0(safe_pw && safe_ph);
av_assert0(startx_safe - s1x >= 0); av_assert0(startx_safe - s1x < w);
av_assert0(starty_safe - s1y >= 0); av_assert0(starty_safe - s1y < h);
av_assert0(startx_safe - s2x >= 0); av_assert0(startx_safe - s2x < w);
av_assert0(starty_safe - s2y >= 0); av_assert0(starty_safe - s2y < h);
memset(ii_ref, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_ref));
memset(ii_new, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_new));
call_ref(ii_ref + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
safe_pw, safe_ph);
call_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
safe_pw, safe_ph);
if (memcmp(ii_ref, ii_new, (ii_lz_32 * ii_h - 1) * sizeof(*ii_ref)))
fail();
memset(ii_new, 0, (ii_lz_32 * ii_h - 1) * sizeof(*ii_new));
bench_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32,
src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz,
src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz,
safe_pw, safe_ph);
}
}
}
av_freep(&ii_orig_ref);
av_freep(&ii_orig_new);
av_freep(&src);
}
report("dsp");
}
+86
View File
@@ -0,0 +1,86 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavfilter/vf_threshold_init.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define WIDTH 256
#define WIDTH_PADDED 256 + 32
#define randomize_buffers(buf, size) \
do { \
int j; \
uint8_t *tmp_buf = (uint8_t *)buf;\
for (j = 0; j < size; j++) \
tmp_buf[j] = rnd() & 0xFF; \
} while (0)
static void check_threshold(int depth){
LOCAL_ALIGNED_32(uint8_t, in , [WIDTH_PADDED]);
LOCAL_ALIGNED_32(uint8_t, threshold, [WIDTH_PADDED]);
LOCAL_ALIGNED_32(uint8_t, min , [WIDTH_PADDED]);
LOCAL_ALIGNED_32(uint8_t, max , [WIDTH_PADDED]);
LOCAL_ALIGNED_32(uint8_t, out_ref , [WIDTH_PADDED]);
LOCAL_ALIGNED_32(uint8_t, out_new , [WIDTH_PADDED]);
ptrdiff_t line_size = WIDTH_PADDED;
int w = WIDTH;
declare_func(void, const uint8_t *in, const uint8_t *threshold,
const uint8_t *min, const uint8_t *max, uint8_t *out,
ptrdiff_t ilinesize, ptrdiff_t tlinesize,
ptrdiff_t flinesize, ptrdiff_t slinesize,
ptrdiff_t olinesize, int w, int h);
ThresholdContext s;
s.depth = depth;
ff_threshold_init(&s);
memset(in, 0, WIDTH_PADDED);
memset(threshold, 0, WIDTH_PADDED);
memset(min, 0, WIDTH_PADDED);
memset(max, 0, WIDTH_PADDED);
memset(out_ref, 0, WIDTH_PADDED);
memset(out_new, 0, WIDTH_PADDED);
randomize_buffers(in, WIDTH);
randomize_buffers(threshold, WIDTH);
randomize_buffers(min, WIDTH);
randomize_buffers(max, WIDTH);
if (depth == 16)
w /= 2;
if (check_func(s.threshold, "threshold%d", depth)) {
call_ref(in, threshold, min, max, out_ref, line_size, line_size, line_size, line_size, line_size, w, 1);
call_new(in, threshold, min, max, out_new, line_size, line_size, line_size, line_size, line_size, w, 1);
if (memcmp(out_ref, out_new, WIDTH))
fail();
bench_new(in, threshold, min, max, out_new, line_size, line_size, line_size, line_size, line_size, w, 1);
}
}
void checkasm_check_vf_threshold(void)
{
check_threshold(8);
report("threshold8");
check_threshold(16);
report("threshold16");
}
+90
View File
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/videodsp.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#define randomize_buffers(w, h) \
do { \
int i; \
for (i = 0; i < w * h * sizeof(*src0); i += 4) \
AV_WN32A(((uint8_t *) src0) + i, rnd()); \
} while (0)
#define iter_1d(type, fix, fix_val, var, var_start, var_end) \
for (fix = fix_val, var = var_start; var <= var_end; var++) { \
call_ref((type *) dst0, (const type *) (src0 + y * pw + x), \
bw * sizeof(type), pw * sizeof(type), \
bw, bh, x, y, pw, ph); \
call_new((type *) dst1, (const type *) (src1 + y * pw + x), \
bw * sizeof(type), pw * sizeof(type), \
bw, bh, x, y, pw, ph); \
if (memcmp(dst0, dst1, bw * bh * sizeof(type))) \
fail(); \
bench_new((type *) dst1, (const type *) (src1 + y * pw + x),\
bw * sizeof(type), pw * sizeof(type), \
bw, bh, x, y, pw, ph); \
}
#define check_emu_edge_size(type, src_w, src_h, dst_w, dst_h) \
do { \
LOCAL_ALIGNED_16(type, src0, [src_w * src_h]); \
LOCAL_ALIGNED_16(type, src1, [src_w * src_h]); \
int bw = dst_w, bh = dst_h; \
int pw = src_w, ph = src_h; \
int y, x; \
randomize_buffers(src_w, src_h); \
memcpy(src1, src0, pw * ph * sizeof(type)); \
iter_1d(type, y, 0 - src_h, x, 0 - src_w, src_w - 0); \
iter_1d(type, x, src_w - 0, y, 0 - src_h, src_h - 0); \
iter_1d(type, y, src_h - 0, x, 0 - src_w, src_w - 0); \
iter_1d(type, x, 0 - src_w, y, 0 - src_h, src_h - 0); \
} while (0)
#define check_emu_edge(type) \
do { \
LOCAL_ALIGNED_16(type, dst0, [64 * 64]); \
LOCAL_ALIGNED_16(type, dst1, [64 * 64]); \
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, \
void, type *dst, const type *src, \
ptrdiff_t dst_linesize, \
ptrdiff_t src_linesize, \
int block_w, int block_h, \
int src_x, int src_y, \
int src_w, int src_h); \
check_emu_edge_size(type, 16, 1, 64, 64); \
check_emu_edge_size(type, 16, 16, 64, 64); \
check_emu_edge_size(type, 64, 64, 64, 64); \
} while (0)
void checkasm_check_videodsp(void)
{
VideoDSPContext vdsp;
ff_videodsp_init(&vdsp, 8);
if (check_func(vdsp.emulated_edge_mc, "emulated_edge_mc_8"))
check_emu_edge(uint8_t);
report("emulated_edge_mc");
}
+85
View File
@@ -0,0 +1,85 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <float.h>
#include "libavutil/mem_internal.h"
#include "libavcodec/vorbisdsp.h"
#include "checkasm.h"
#define LEN 512
#define randomize_buffer(buf) \
do { \
double bmg[2], stddev = 10.0, mean = 0.0; \
\
for (int i = 0; i < LEN; i += 2) { \
av_bmg_get(&checkasm_lfg, bmg); \
buf[i] = bmg[0] * stddev + mean; \
buf[i + 1] = bmg[1] * stddev + mean; \
} \
} while(0);
static void test_inverse_coupling(void)
{
LOCAL_ALIGNED_16(float, src0, [LEN]);
LOCAL_ALIGNED_16(float, src1, [LEN]);
LOCAL_ALIGNED_16(float, cdst, [LEN]);
LOCAL_ALIGNED_16(float, odst, [LEN]);
LOCAL_ALIGNED_16(float, cdst1, [LEN]);
LOCAL_ALIGNED_16(float, odst1, [LEN]);
declare_func(void, float *restrict mag, float *restrict ang,
ptrdiff_t blocksize);
randomize_buffer(src0);
randomize_buffer(src1);
memcpy(cdst, src0, LEN * sizeof(*src0));
memcpy(cdst1, src1, LEN * sizeof(*src1));
memcpy(odst, src0, LEN * sizeof(*src0));
memcpy(odst1, src1, LEN * sizeof(*src1));
call_ref(cdst, cdst1, LEN);
call_new(odst, odst1, LEN);
for (int i = 0; i < LEN; i++) {
if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON) ||
!float_near_abs_eps(cdst1[i], odst1[i], FLT_EPSILON)) {
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst[i], odst[i], cdst[i] - odst[i]);
fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
i, cdst1[i], odst1[i], cdst1[i] - odst1[i]);
fail();
break;
}
}
bench_new(src0, src1, LEN);
}
void checkasm_check_vorbisdsp(void)
{
VorbisDSPContext dsp;
ff_vorbisdsp_init(&dsp);
if (check_func(dsp.vorbis_inverse_coupling, "inverse_coupling"))
test_inverse_coupling();
report("inverse_coupling");
}
+521
View File
@@ -0,0 +1,521 @@
/*
* Copyright (c) 2016 Martin Storsjo
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <stdbool.h>
#include <string.h>
#include "config_components.h"
#include "libavcodec/vp8dsp.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "checkasm.h"
#define PIXEL_STRIDE 16
#define randomize_buffers(src, dst, stride, coef) \
do { \
int x, y; \
for (y = 0; y < 4; y++) { \
AV_WN32A((src) + y * (stride), rnd()); \
AV_WN32A((dst) + y * (stride), rnd()); \
for (x = 0; x < 4; x++) \
(coef)[y * 4 + x] = (src)[y * (stride) + x] - \
(dst)[y * (stride) + x]; \
} \
} while (0)
static void dct4x4(int16_t *coef)
{
int i;
for (i = 0; i < 4; i++) {
const int a1 = (coef[i*4 + 0] + coef[i*4 + 3]) * 8;
const int b1 = (coef[i*4 + 1] + coef[i*4 + 2]) * 8;
const int c1 = (coef[i*4 + 1] - coef[i*4 + 2]) * 8;
const int d1 = (coef[i*4 + 0] - coef[i*4 + 3]) * 8;
coef[i*4 + 0] = a1 + b1;
coef[i*4 + 1] = (c1 * 2217 + d1 * 5352 + 14500) >> 12;
coef[i*4 + 2] = a1 - b1;
coef[i*4 + 3] = (d1 * 2217 - c1 * 5352 + 7500) >> 12;
}
for (i = 0; i < 4; i++) {
const int a1 = coef[i + 0*4] + coef[i + 3*4];
const int b1 = coef[i + 1*4] + coef[i + 2*4];
const int c1 = coef[i + 1*4] - coef[i + 2*4];
const int d1 = coef[i + 0*4] - coef[i + 3*4];
coef[i + 0*4] = (a1 + b1 + 7) >> 4;
coef[i + 1*4] = ((c1 * 2217 + d1 * 5352 + 12000) >> 16) + !!d1;
coef[i + 2*4] = (a1 - b1 + 7) >> 4;
coef[i + 3*4] = (d1 * 2217 - c1 * 5352 + 51000) >> 16;
}
}
static void wht4x4(int16_t *coef)
{
int i;
for (i = 0; i < 4; i++) {
int a1 = coef[0 * 4 + i];
int b1 = coef[1 * 4 + i];
int c1 = coef[2 * 4 + i];
int d1 = coef[3 * 4 + i];
int e1;
a1 += b1;
d1 -= c1;
e1 = (a1 - d1) >> 1;
b1 = e1 - b1;
c1 = e1 - c1;
a1 -= c1;
d1 += b1;
coef[0 * 4 + i] = a1;
coef[1 * 4 + i] = c1;
coef[2 * 4 + i] = d1;
coef[3 * 4 + i] = b1;
}
for (i = 0; i < 4; i++) {
int a1 = coef[i * 4 + 0];
int b1 = coef[i * 4 + 1];
int c1 = coef[i * 4 + 2];
int d1 = coef[i * 4 + 3];
int e1;
a1 += b1;
d1 -= c1;
e1 = (a1 - d1) >> 1;
b1 = e1 - b1;
c1 = e1 - c1;
a1 -= c1;
d1 += b1;
coef[i * 4 + 0] = a1 * 2;
coef[i * 4 + 1] = c1 * 2;
coef[i * 4 + 2] = d1 * 2;
coef[i * 4 + 3] = b1 * 2;
}
}
static void check_idct(VP8DSPContext *d, bool is_vp7)
{
LOCAL_ALIGNED_16(uint8_t, src, [4 * 4]);
LOCAL_ALIGNED_16(uint8_t, dst, [4 * 4]);
LOCAL_ALIGNED_16(uint8_t, dst0, [4 * 4]);
LOCAL_ALIGNED_16(uint8_t, dst1, [4 * 4]);
LOCAL_ALIGNED_16(int16_t, coef, [4 * 4]);
LOCAL_ALIGNED_16(int16_t, subcoef0, [4 * 4]);
LOCAL_ALIGNED_16(int16_t, subcoef1, [4 * 4]);
int dc;
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *block, ptrdiff_t stride);
randomize_buffers(src, dst, 4, coef);
dct4x4(coef);
for (dc = 0; dc <= 1; dc++) {
void (*idct)(uint8_t *, int16_t *, ptrdiff_t) = dc ? d->vp8_idct_dc_add : d->vp8_idct_add;
if (check_func(idct, "vp%d_idct_%sadd", 8 - is_vp7, dc ? "dc_" : "")) {
if (dc) {
memset(subcoef0, 0, 4 * 4 * sizeof(int16_t));
subcoef0[0] = coef[0];
} else {
memcpy(subcoef0, coef, 4 * 4 * sizeof(int16_t));
}
memcpy(dst0, dst, 4 * 4);
memcpy(dst1, dst, 4 * 4);
memcpy(subcoef1, subcoef0, 4 * 4 * sizeof(int16_t));
// Note, this uses a pixel stride of 4, even though the real decoder uses a stride as a
// multiple of 16. If optimizations want to take advantage of that, this test needs to be
// updated to make it more like the h264dsp tests.
call_ref(dst0, subcoef0, 4);
call_new(dst1, subcoef1, 4);
if (memcmp(dst0, dst1, 4 * 4) ||
memcmp(subcoef0, subcoef1, 4 * 4 * sizeof(int16_t)))
fail();
bench_new(dst1, subcoef1, 4);
}
}
}
static void check_idct_dc4(VP8DSPContext *d, bool is_vp7)
{
LOCAL_ALIGNED_16(uint8_t, src, [4 * 4 * 4]);
LOCAL_ALIGNED_16(uint8_t, dst, [4 * 4 * 4]);
LOCAL_ALIGNED_16(uint8_t, dst0, [4 * 4 * 4]);
LOCAL_ALIGNED_16(uint8_t, dst1, [4 * 4 * 4]);
LOCAL_ALIGNED_16(int16_t, coef, [4], [4 * 4]);
LOCAL_ALIGNED_16(int16_t, subcoef0, [4], [4 * 4]);
LOCAL_ALIGNED_16(int16_t, subcoef1, [4], [4 * 4]);
int i, chroma;
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t block[4][16], ptrdiff_t stride);
for (chroma = 0; chroma <= 1; chroma++) {
void (*idct4dc)(uint8_t *, int16_t[4][16], ptrdiff_t) = chroma ? d->vp8_idct_dc_add4uv : d->vp8_idct_dc_add4y;
if (check_func(idct4dc, "vp%d_idct_dc_add4%s", 8 - is_vp7, chroma ? "uv" : "y")) {
ptrdiff_t stride = chroma ? 8 : 16;
int w = chroma ? 2 : 4;
for (i = 0; i < 4; i++) {
int blockx = 4 * (i % w);
int blocky = 4 * (i / w);
randomize_buffers(src + stride * blocky + blockx, dst + stride * blocky + blockx, stride, coef[i]);
dct4x4(coef[i]);
memset(&coef[i][1], 0, 15 * sizeof(int16_t));
}
memcpy(dst0, dst, 4 * 4 * 4);
memcpy(dst1, dst, 4 * 4 * 4);
memcpy(subcoef0, coef, 4 * 4 * 4 * sizeof(int16_t));
memcpy(subcoef1, coef, 4 * 4 * 4 * sizeof(int16_t));
call_ref(dst0, subcoef0, stride);
call_new(dst1, subcoef1, stride);
if (memcmp(dst0, dst1, 4 * 4 * 4) ||
memcmp(subcoef0, subcoef1, 4 * 4 * 4 * sizeof(int16_t)))
fail();
bench_new(dst1, subcoef1, stride);
}
}
}
static void check_luma_dc_wht(VP8DSPContext *d, bool is_vp7)
{
LOCAL_ALIGNED_16(int16_t, dc, [4 * 4]);
LOCAL_ALIGNED_16(int16_t, dc0, [4 * 4]);
LOCAL_ALIGNED_16(int16_t, dc1, [4 * 4]);
int16_t block[4][4][16];
LOCAL_ALIGNED_16(int16_t, block0, [4], [4][16]);
LOCAL_ALIGNED_16(int16_t, block1, [4], [4][16]);
int dc_only;
int blockx, blocky;
declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t block[4][4][16], int16_t dc[16]);
for (blocky = 0; blocky < 4; blocky++) {
for (blockx = 0; blockx < 4; blockx++) {
uint8_t src[16], dst[16];
randomize_buffers(src, dst, 4, block[blocky][blockx]);
dct4x4(block[blocky][blockx]);
dc[blocky * 4 + blockx] = block[blocky][blockx][0];
block[blocky][blockx][0] = rnd();
}
}
wht4x4(dc);
for (dc_only = 0; dc_only <= 1; dc_only++) {
void (*idct)(int16_t [4][4][16], int16_t [16]) = dc_only ? d->vp8_luma_dc_wht_dc : d->vp8_luma_dc_wht;
if (check_func(idct, "vp%d_luma_dc_wht%s", 8 - is_vp7, dc_only ? "_dc" : "")) {
if (dc_only) {
memset(dc0, 0, 16 * sizeof(int16_t));
dc0[0] = dc[0];
} else {
memcpy(dc0, dc, 16 * sizeof(int16_t));
}
memcpy(dc1, dc0, 16 * sizeof(int16_t));
memcpy(block0, block, 4 * 4 * 16 * sizeof(int16_t));
memcpy(block1, block, 4 * 4 * 16 * sizeof(int16_t));
call_ref(block0, dc0);
call_new(block1, dc1);
if (memcmp(block0, block1, 4 * 4 * 16 * sizeof(int16_t)) ||
memcmp(dc0, dc1, 16 * sizeof(int16_t)))
fail();
bench_new(block1, dc1);
}
}
}
#define SRC_BUF_STRIDE 32
#define SRC_BUF_SIZE (((size << (size < 16)) + 5) * SRC_BUF_STRIDE)
// The mc subpixel interpolation filter needs the 2 previous pixels in either
// direction, the +1 is to make sure the actual load addresses always are
// unaligned.
#define src (buf + 2 * SRC_BUF_STRIDE + 2 + 1)
#undef randomize_buffers
#define randomize_buffers() \
do { \
int k; \
for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
AV_WN32A(buf + k, rnd()); \
} \
} while (0)
static void check_mc(VP8DSPContext *d)
{
LOCAL_ALIGNED_16(uint8_t, buf, [32 * 32]);
LOCAL_ALIGNED_16(uint8_t, dst0, [16 * 16]);
LOCAL_ALIGNED_16(uint8_t, dst1, [16 * 16]);
int type, k, dx, dy;
declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, ptrdiff_t,
const uint8_t *, ptrdiff_t, int, int, int);
for (type = 0; type < 2; type++) {
for (k = 1; k < 8; k++) {
int hsize = k / 3;
int size = 16 >> hsize;
int height = (size << 1) >> (k % 3);
for (dy = 0; dy < 3; dy++) {
for (dx = 0; dx < 3; dx++) {
char str[100];
vp8_mc_func func = (type ? d->put_vp8_bilinear_pixels_tab : d->put_vp8_epel_pixels_tab)[hsize][dy][dx];
if (dx || dy) {
if (type == 0) {
static const char *dx_names[] = { "", "h4", "h6" };
static const char *dy_names[] = { "", "v4", "v6" };
snprintf(str, sizeof(str), "epel%d_%s%s", size, dx_names[dx], dy_names[dy]);
} else {
snprintf(str, sizeof(str), "bilin%d_%s%s", size, dx ? "h" : "", dy ? "v" : "");
}
} else {
snprintf(str, sizeof(str), "pixels%d", size);
}
if (check_func(func, "vp8_put_%s", str)) {
int mx, my;
int i;
if (type == 0) {
mx = dx == 2 ? 2 + 2 * (rnd() % 3) : dx == 1 ? 1 + 2 * (rnd() % 4) : 0;
my = dy == 2 ? 2 + 2 * (rnd() % 3) : dy == 1 ? 1 + 2 * (rnd() % 4) : 0;
} else {
mx = dx ? 1 + (rnd() % 7) : 0;
my = dy ? 1 + (rnd() % 7) : 0;
}
randomize_buffers();
for (i = -2; i <= 3; i++) {
int val = (i == -1 || i == 2) ? 0 : 0xff;
// Set pixels in the first row and column to the maximum pattern,
// to test for potential overflows in the filter.
src[i ] = val;
src[i * SRC_BUF_STRIDE] = val;
}
call_ref(dst0, size, src, SRC_BUF_STRIDE, height, mx, my);
call_new(dst1, size, src, SRC_BUF_STRIDE, height, mx, my);
if (memcmp(dst0, dst1, size * height))
fail();
bench_new(dst1, size, src, SRC_BUF_STRIDE, height, mx, my);
}
}
}
}
}
}
#undef randomize_buffers
#define setpx(a, b, c) buf[(a) + (b) * jstride] = av_clip_uint8(c)
// Set the pixel to c +/- [0,d]
#define setdx(a, b, c, d) setpx(a, b, c - (d) + (rnd() % ((d) * 2 + 1)))
// Set the pixel to c +/- [d,d+e] (making sure it won't be clipped)
#define setdx2(a, b, o, c, d, e) setpx(a, b, o = c + ((d) + (rnd() % (e))) * (c >= 128 ? -1 : 1))
static void randomize_loopfilter_buffers(int lineoff, int str,
int dir, int flim_E, int flim_I,
int hev_thresh, uint8_t *buf,
int force_hev)
{
uint32_t mask = 0xff;
int off = dir ? lineoff : lineoff * str;
int istride = dir ? 1 : str;
int jstride = dir ? str : 1;
int i;
for (i = 0; i < 8; i += 2) {
// Row 0 will trigger hev for q0/q1, row 2 will trigger hev for p0/p1,
// rows 4 and 6 will not trigger hev.
// force_hev 1 will make sure all rows trigger hev, while force_hev -1
// makes none of them trigger it.
int idx = off + i * istride, p2, p1, p0, q0, q1, q2;
setpx(idx, 0, q0 = rnd() & mask);
if (i == 0 && force_hev >= 0 || force_hev > 0)
setdx2(idx, 1, q1, q0, hev_thresh + 1, flim_I - hev_thresh - 1);
else
setdx(idx, 1, q1 = q0, hev_thresh);
setdx(idx, 2, q2 = q1, flim_I);
setdx(idx, 3, q2, flim_I);
setdx(idx, -1, p0 = q0, flim_E >> 2);
if (i == 2 && force_hev >= 0 || force_hev > 0)
setdx2(idx, -2, p1, p0, hev_thresh + 1, flim_I - hev_thresh - 1);
else
setdx(idx, -2, p1 = p0, hev_thresh);
setdx(idx, -3, p2 = p1, flim_I);
setdx(idx, -4, p2, flim_I);
}
}
// Fill the buffer with random pixels
static void fill_loopfilter_buffers(uint8_t *buf, ptrdiff_t stride, int w, int h)
{
int x, y;
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
buf[y * stride + x] = rnd() & 0xff;
}
#define randomize_buffers(buf, lineoff, str, force_hev) \
randomize_loopfilter_buffers(lineoff, str, dir, flim_E, flim_I, hev_thresh, buf, force_hev)
static void check_loopfilter_16y(VP8DSPContext *d, bool is_vp7)
{
LOCAL_ALIGNED_16(uint8_t, base0, [32 + 16 * 16]);
LOCAL_ALIGNED_16(uint8_t, base1, [32 + 16 * 16]);
int dir, edge, force_hev;
int flim_E = 20, flim_I = 10, hev_thresh = 7;
declare_func(void, uint8_t *, ptrdiff_t, int, int, int);
for (dir = 0; dir < 2; dir++) {
int midoff = dir ? 4 * 16 : 4;
int midoff_aligned = dir ? 4 * 16 : 16;
uint8_t *buf0 = base0 + midoff_aligned;
uint8_t *buf1 = base1 + midoff_aligned;
for (edge = 0; edge < 2; edge++) {
void (*func)(uint8_t *, ptrdiff_t, int, int, int) = NULL;
switch (dir << 1 | edge) {
case (0 << 1) | 0: func = d->vp8_h_loop_filter16y; break;
case (1 << 1) | 0: func = d->vp8_v_loop_filter16y; break;
case (0 << 1) | 1: func = d->vp8_h_loop_filter16y_inner; break;
case (1 << 1) | 1: func = d->vp8_v_loop_filter16y_inner; break;
}
if (check_func(func, "vp%d_loop_filter16y%s_%s", 8 - is_vp7, edge ? "_inner" : "", dir ? "v" : "h")) {
for (force_hev = -1; force_hev <= 1; force_hev++) {
fill_loopfilter_buffers(buf0 - midoff, 16, 16, 16);
randomize_buffers(buf0, 0, 16, force_hev);
randomize_buffers(buf0, 8, 16, force_hev);
memcpy(buf1 - midoff, buf0 - midoff, 16 * 16);
call_ref(buf0, 16, flim_E, flim_I, hev_thresh);
call_new(buf1, 16, flim_E, flim_I, hev_thresh);
if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16))
fail();
}
fill_loopfilter_buffers(buf0 - midoff, 16, 16, 16);
randomize_buffers(buf0, 0, 16, 0);
randomize_buffers(buf0, 8, 16, 0);
bench_new(buf0, 16, flim_E, flim_I, hev_thresh);
}
}
}
}
static void check_loopfilter_8uv(VP8DSPContext *d, bool is_vp7)
{
LOCAL_ALIGNED_16(uint8_t, base0u, [32 + 16 * 16]);
LOCAL_ALIGNED_16(uint8_t, base0v, [32 + 16 * 16]);
LOCAL_ALIGNED_16(uint8_t, base1u, [32 + 16 * 16]);
LOCAL_ALIGNED_16(uint8_t, base1v, [32 + 16 * 16]);
int dir, edge, force_hev;
int flim_E = 20, flim_I = 10, hev_thresh = 7;
declare_func(void, uint8_t *, uint8_t *, ptrdiff_t, int, int, int);
for (dir = 0; dir < 2; dir++) {
int midoff = dir ? 4 * 16 : 4;
int midoff_aligned = dir ? 4 * 16 : 16;
uint8_t *buf0u = base0u + midoff_aligned;
uint8_t *buf0v = base0v + midoff_aligned;
uint8_t *buf1u = base1u + midoff_aligned;
uint8_t *buf1v = base1v + midoff_aligned;
for (edge = 0; edge < 2; edge++) {
void (*func)(uint8_t *, uint8_t *, ptrdiff_t, int, int, int) = NULL;
switch (dir << 1 | edge) {
case (0 << 1) | 0: func = d->vp8_h_loop_filter8uv; break;
case (1 << 1) | 0: func = d->vp8_v_loop_filter8uv; break;
case (0 << 1) | 1: func = d->vp8_h_loop_filter8uv_inner; break;
case (1 << 1) | 1: func = d->vp8_v_loop_filter8uv_inner; break;
}
if (check_func(func, "vp%d_loop_filter8uv%s_%s", 8 - is_vp7, edge ? "_inner" : "", dir ? "v" : "h")) {
for (force_hev = -1; force_hev <= 1; force_hev++) {
fill_loopfilter_buffers(buf0u - midoff, 16, 16, 16);
fill_loopfilter_buffers(buf0v - midoff, 16, 16, 16);
randomize_buffers(buf0u, 0, 16, force_hev);
randomize_buffers(buf0v, 0, 16, force_hev);
memcpy(buf1u - midoff, buf0u - midoff, 16 * 16);
memcpy(buf1v - midoff, buf0v - midoff, 16 * 16);
call_ref(buf0u, buf0v, 16, flim_E, flim_I, hev_thresh);
call_new(buf1u, buf1v, 16, flim_E, flim_I, hev_thresh);
if (memcmp(buf0u - midoff, buf1u - midoff, 16 * 16) ||
memcmp(buf0v - midoff, buf1v - midoff, 16 * 16))
fail();
}
fill_loopfilter_buffers(buf0u - midoff, 16, 16, 16);
fill_loopfilter_buffers(buf0v - midoff, 16, 16, 16);
randomize_buffers(buf0u, 0, 16, 0);
randomize_buffers(buf0v, 0, 16, 0);
bench_new(buf0u, buf0v, 16, flim_E, flim_I, hev_thresh);
}
}
}
}
static void check_loopfilter_simple(VP8DSPContext *d, bool is_vp7)
{
LOCAL_ALIGNED_16(uint8_t, base0, [32 + 16 * 16]);
LOCAL_ALIGNED_16(uint8_t, base1, [32 + 16 * 16]);
int dir;
int flim_E = 20, flim_I = 30, hev_thresh = 0;
declare_func(void, uint8_t *, ptrdiff_t, int);
for (dir = 0; dir < 2; dir++) {
int midoff = dir ? 4 * 16 : 4;
int midoff_aligned = dir ? 4 * 16 : 16;
uint8_t *buf0 = base0 + midoff_aligned;
uint8_t *buf1 = base1 + midoff_aligned;
void (*func)(uint8_t *, ptrdiff_t, int) = dir ? d->vp8_v_loop_filter_simple : d->vp8_h_loop_filter_simple;
if (check_func(func, "vp%d_loop_filter_simple_%s", 8 - is_vp7, dir ? "v" : "h")) {
fill_loopfilter_buffers(buf0 - midoff, 16, 16, 16);
randomize_buffers(buf0, 0, 16, -1);
randomize_buffers(buf0, 8, 16, -1);
memcpy(buf1 - midoff, buf0 - midoff, 16 * 16);
call_ref(buf0, 16, flim_E);
call_new(buf1, 16, flim_E);
if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16))
fail();
bench_new(buf0, 16, flim_E);
}
}
}
static void checkasm_check_vp78dsp(VP8DSPContext *d, bool is_vp7)
{
#if CONFIG_VP7_DECODER
if (is_vp7)
ff_vp7dsp_init(d);
else
#endif
ff_vp8dsp_init(d);
check_idct(d, is_vp7);
check_idct_dc4(d, is_vp7);
check_luma_dc_wht(d, is_vp7);
report("idct");
check_loopfilter_16y(d, is_vp7);
check_loopfilter_8uv(d, is_vp7);
check_loopfilter_simple(d, is_vp7);
report("loopfilter");
}
void checkasm_check_vp8dsp(void)
{
VP8DSPContext d;
ff_vp78dsp_init(&d);
check_mc(&d);
report("mc");
checkasm_check_vp78dsp(&d, false);
#if CONFIG_VP7_DECODER
checkasm_check_vp78dsp(&d, true);
#endif
}
+633
View File
@@ -0,0 +1,633 @@
/*
* Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <math.h>
#include <string.h>
#include "checkasm.h"
#include "libavcodec/vp9data.h"
#include "libavcodec/vp9.h"
#include "libavutil/common.h"
#include "libavutil/emms.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem_internal.h"
static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define randomize_buffers() \
do { \
uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
int k; \
for (k = -4; k < SIZEOF_PIXEL * FFMAX(8, size); k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(a + k, r); \
} \
for (k = 0; k < size * SIZEOF_PIXEL; k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(l + k, r); \
} \
} while (0)
static void check_ipred(void)
{
LOCAL_ALIGNED_32(uint8_t, a_buf, [64 * 2]);
uint8_t *a = &a_buf[32 * 2];
LOCAL_ALIGNED_32(uint8_t, l, [32 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
VP9DSPContext dsp;
int tx, mode, bit_depth;
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride,
const uint8_t *left, const uint8_t *top);
static const char *const mode_names[N_INTRA_PRED_MODES] = {
[VERT_PRED] = "vert",
[HOR_PRED] = "hor",
[DC_PRED] = "dc",
[DIAG_DOWN_LEFT_PRED] = "diag_downleft",
[DIAG_DOWN_RIGHT_PRED] = "diag_downright",
[VERT_RIGHT_PRED] = "vert_right",
[HOR_DOWN_PRED] = "hor_down",
[VERT_LEFT_PRED] = "vert_left",
[HOR_UP_PRED] = "hor_up",
[TM_VP8_PRED] = "tm",
[LEFT_DC_PRED] = "dc_left",
[TOP_DC_PRED] = "dc_top",
[DC_128_PRED] = "dc_128",
[DC_127_PRED] = "dc_127",
[DC_129_PRED] = "dc_129",
};
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vp9dsp_init(&dsp, bit_depth, 0);
for (tx = 0; tx < 4; tx++) {
int size = 4 << tx;
for (mode = 0; mode < N_INTRA_PRED_MODES; mode++) {
if (check_func(dsp.intra_pred[tx][mode], "vp9_%s_%dx%d_%dbpp",
mode_names[mode], size, size, bit_depth)) {
randomize_buffers();
call_ref(dst0, size * SIZEOF_PIXEL, l, a);
call_new(dst1, size * SIZEOF_PIXEL, l, a);
if (memcmp(dst0, dst1, size * size * SIZEOF_PIXEL))
fail();
bench_new(dst1, size * SIZEOF_PIXEL,l, a);
}
}
}
}
report("ipred");
}
#undef randomize_buffers
#define randomize_buffers() \
do { \
uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
for (y = 0; y < sz; y++) { \
for (x = 0; x < sz * SIZEOF_PIXEL; x += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(dst + y * sz * SIZEOF_PIXEL + x, r); \
AV_WN32A(src + y * sz * SIZEOF_PIXEL + x, rnd() & mask); \
} \
for (x = 0; x < sz; x++) { \
if (bit_depth == 8) { \
coef[y * sz + x] = src[y * sz + x] - dst[y * sz + x]; \
} else { \
((int32_t *) coef)[y * sz + x] = \
((uint16_t *) src)[y * sz + x] - \
((uint16_t *) dst)[y * sz + x]; \
} \
} \
} \
} while(0)
// wht function copied from libvpx
static void fwht_1d(double *out, const double *in, int sz)
{
double t0 = in[0] + in[1];
double t3 = in[3] - in[2];
double t4 = trunc((t0 - t3) * 0.5);
double t1 = t4 - in[1];
double t2 = t4 - in[2];
out[0] = t0 - t2;
out[1] = t2;
out[2] = t3 + t1;
out[3] = t1;
}
// standard DCT-II
static void fdct_1d(double *out, const double *in, int sz)
{
int k, n;
for (k = 0; k < sz; k++) {
out[k] = 0.0;
for (n = 0; n < sz; n++)
out[k] += in[n] * cos(M_PI * (2 * n + 1) * k / (sz * 2.0));
}
out[0] *= M_SQRT1_2;
}
// see "Towards jointly optimal spatial prediction and adaptive transform in
// video/image coding", by J. Han, A. Saxena, and K. Rose
// IEEE Proc. ICASSP, pp. 726-729, Mar. 2010.
static void fadst4_1d(double *out, const double *in, int sz)
{
int k, n;
for (k = 0; k < sz; k++) {
out[k] = 0.0;
for (n = 0; n < sz; n++)
out[k] += in[n] * sin(M_PI * (n + 1) * (2 * k + 1) / (sz * 2.0 + 1.0));
}
}
// see "A Butterfly Structured Design of The Hybrid Transform Coding Scheme",
// by Jingning Han, Yaowu Xu, and Debargha Mukherjee
// http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41418.pdf
static void fadst_1d(double *out, const double *in, int sz)
{
int k, n;
for (k = 0; k < sz; k++) {
out[k] = 0.0;
for (n = 0; n < sz; n++)
out[k] += in[n] * sin(M_PI * (2 * n + 1) * (2 * k + 1) / (sz * 4.0));
}
}
typedef void (*ftx1d_fn)(double *out, const double *in, int sz);
static void ftx_2d(double *out, const double *in, enum TxfmMode tx,
enum TxfmType txtp, int sz)
{
static const double scaling_factors[5][4] = {
{ 4.0, 16.0 * M_SQRT1_2 / 3.0, 16.0 * M_SQRT1_2 / 3.0, 32.0 / 9.0 },
{ 2.0, 2.0, 2.0, 2.0 },
{ 1.0, 1.0, 1.0, 1.0 },
{ 0.25 },
{ 4.0 }
};
static const ftx1d_fn ftx1d_tbl[5][4][2] = {
{
{ fdct_1d, fdct_1d },
{ fadst4_1d, fdct_1d },
{ fdct_1d, fadst4_1d },
{ fadst4_1d, fadst4_1d },
}, {
{ fdct_1d, fdct_1d },
{ fadst_1d, fdct_1d },
{ fdct_1d, fadst_1d },
{ fadst_1d, fadst_1d },
}, {
{ fdct_1d, fdct_1d },
{ fadst_1d, fdct_1d },
{ fdct_1d, fadst_1d },
{ fadst_1d, fadst_1d },
}, {
{ fdct_1d, fdct_1d },
}, {
{ fwht_1d, fwht_1d },
},
};
double temp[1024];
double scaling_factor = scaling_factors[tx][txtp];
int i, j;
// cols
for (i = 0; i < sz; ++i) {
double temp_out[32];
ftx1d_tbl[tx][txtp][0](temp_out, &in[i * sz], sz);
// scale and transpose
for (j = 0; j < sz; ++j)
temp[j * sz + i] = temp_out[j] * scaling_factor;
}
// rows
for (i = 0; i < sz; i++)
ftx1d_tbl[tx][txtp][1](&out[i * sz], &temp[i * sz], sz);
}
static void ftx(int16_t *buf, enum TxfmMode tx,
enum TxfmType txtp, int sz, int bit_depth)
{
double ind[1024], outd[1024];
int n;
emms_c();
for (n = 0; n < sz * sz; n++) {
if (bit_depth == 8)
ind[n] = buf[n];
else
ind[n] = ((int32_t *) buf)[n];
}
ftx_2d(outd, ind, tx, txtp, sz);
for (n = 0; n < sz * sz; n++) {
if (bit_depth == 8)
buf[n] = lrint(outd[n]);
else
((int32_t *) buf)[n] = lrint(outd[n]);
}
}
static int copy_subcoefs(int16_t *out, const int16_t *in, enum TxfmMode tx,
enum TxfmType txtp, int sz, int sub, int bit_depth)
{
// copy the topleft coefficients such that the return value (being the
// coefficient scantable index for the eob token) guarantees that only
// the topleft $sub out of $sz (where $sz >= $sub) coefficients in both
// dimensions are non-zero. This leads to braching to specific optimized
// simd versions (e.g. dc-only) so that we get full asm coverage in this
// test
int n;
const int16_t *scan = ff_vp9_scans[tx][txtp];
int eob;
for (n = 0; n < sz * sz; n++) {
int rc = scan[n], rcx = rc % sz, rcy = rc / sz;
// find eob for this sub-idct
if (rcx >= sub || rcy >= sub)
break;
// copy coef
if (bit_depth == 8) {
out[rc] = in[rc];
} else {
AV_COPY32(&out[rc * 2], &in[rc * 2]);
}
}
eob = n;
for (; n < sz * sz; n++) {
int rc = scan[n];
// zero
if (bit_depth == 8) {
out[rc] = 0;
} else {
AV_ZERO32(&out[rc * 2]);
}
}
return eob;
}
static int is_zero(const int16_t *c, int sz)
{
int n;
for (n = 0; n < sz / sizeof(int16_t); n += 2)
if (AV_RN32A(&c[n]))
return 0;
return 1;
}
#define SIZEOF_COEF (2 * ((bit_depth + 7) / 8))
static void check_itxfm(void)
{
LOCAL_ALIGNED_32(uint8_t, src, [32 * 32 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst, [32 * 32 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
LOCAL_ALIGNED_32(int16_t, coef, [32 * 32 * 2]);
LOCAL_ALIGNED_32(int16_t, subcoef0, [32 * 32 * 2]);
LOCAL_ALIGNED_32(int16_t, subcoef1, [32 * 32 * 2]);
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob);
VP9DSPContext dsp;
int y, x, tx, txtp, bit_depth, sub;
static const char *const txtp_types[N_TXFM_TYPES] = {
[DCT_DCT] = "dct_dct", [DCT_ADST] = "adst_dct",
[ADST_DCT] = "dct_adst", [ADST_ADST] = "adst_adst"
};
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vp9dsp_init(&dsp, bit_depth, 0);
for (tx = TX_4X4; tx <= N_TXFM_SIZES /* 4 = lossless */; tx++) {
int sz = 4 << (tx & 3);
int n_txtps = tx < TX_32X32 ? N_TXFM_TYPES : 1;
for (txtp = 0; txtp < n_txtps; txtp++) {
// skip testing sub-IDCTs for WHT or ADST since they don't
// implement it in any of the SIMD functions. If they do,
// consider changing this to ensure we have complete test
// coverage. Test sub=1 for dc-only, then 2, 4, 8, 12, etc,
// since the arm version can distinguish them at that level.
for (sub = (txtp == 0 && tx < 4) ? 1 : sz; sub <= sz;
sub < 4 ? (sub <<= 1) : (sub += 4)) {
if (check_func(dsp.itxfm_add[tx][txtp],
"vp9_inv_%s_%dx%d_sub%d_add_%d",
tx == 4 ? "wht_wht" : txtp_types[txtp],
sz, sz, sub, bit_depth)) {
int eob;
randomize_buffers();
ftx(coef, tx, txtp, sz, bit_depth);
if (sub < sz) {
eob = copy_subcoefs(subcoef0, coef, tx, txtp,
sz, sub, bit_depth);
} else {
eob = sz * sz;
memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF);
}
memcpy(dst0, dst, sz * sz * SIZEOF_PIXEL);
memcpy(dst1, dst, sz * sz * SIZEOF_PIXEL);
memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF);
call_ref(dst0, sz * SIZEOF_PIXEL, subcoef0, eob);
call_new(dst1, sz * SIZEOF_PIXEL, subcoef1, eob);
if (memcmp(dst0, dst1, sz * sz * SIZEOF_PIXEL) ||
!is_zero(subcoef0, sz * sz * SIZEOF_COEF) ||
!is_zero(subcoef1, sz * sz * SIZEOF_COEF))
fail();
bench_new(dst, sz * SIZEOF_PIXEL, coef, eob);
}
}
}
}
}
report("itxfm");
}
#undef randomize_buffers
#define setpx(a,b,c) \
do { \
if (SIZEOF_PIXEL == 1) { \
buf0[(a) + (b) * jstride] = av_clip_uint8(c); \
} else { \
((uint16_t *)buf0)[(a) + (b) * jstride] = av_clip_uintp2(c, bit_depth); \
} \
} while (0)
// c can be an assignment and must not be put under ()
#define setdx(a,b,c,d) setpx(a,b,c-(d)+(rnd()%((d)*2+1)))
#define setsx(a,b,c,d) setdx(a,b,c,(d) << (bit_depth - 8))
static void randomize_loopfilter_buffers(int bidx, int lineoff, int str,
int bit_depth, int dir, const int *E,
const int *F, const int *H, const int *I,
uint8_t *buf0, uint8_t *buf1)
{
uint32_t mask = (1 << bit_depth) - 1;
int off = dir ? lineoff : lineoff * 16;
int istride = dir ? 1 : 16;
int jstride = dir ? str : 1;
int i, j;
for (i = 0; i < 2; i++) /* flat16 */ {
int idx = off + i * istride, p0, q0;
setpx(idx, 0, q0 = rnd() & mask);
setsx(idx, -1, p0 = q0, E[bidx] >> 2);
for (j = 1; j < 8; j++) {
setsx(idx, -1 - j, p0, F[bidx]);
setsx(idx, j, q0, F[bidx]);
}
}
for (i = 2; i < 4; i++) /* flat8 */ {
int idx = off + i * istride, p0, q0;
setpx(idx, 0, q0 = rnd() & mask);
setsx(idx, -1, p0 = q0, E[bidx] >> 2);
for (j = 1; j < 4; j++) {
setsx(idx, -1 - j, p0, F[bidx]);
setsx(idx, j, q0, F[bidx]);
}
for (j = 4; j < 8; j++) {
setpx(idx, -1 - j, rnd() & mask);
setpx(idx, j, rnd() & mask);
}
}
for (i = 4; i < 6; i++) /* regular */ {
int idx = off + i * istride, p2, p1, p0, q0, q1, q2;
setpx(idx, 0, q0 = rnd() & mask);
setsx(idx, 1, q1 = q0, I[bidx]);
setsx(idx, 2, q2 = q1, I[bidx]);
setsx(idx, 3, q2, I[bidx]);
setsx(idx, -1, p0 = q0, E[bidx] >> 2);
setsx(idx, -2, p1 = p0, I[bidx]);
setsx(idx, -3, p2 = p1, I[bidx]);
setsx(idx, -4, p2, I[bidx]);
for (j = 4; j < 8; j++) {
setpx(idx, -1 - j, rnd() & mask);
setpx(idx, j, rnd() & mask);
}
}
for (i = 6; i < 8; i++) /* off */ {
int idx = off + i * istride;
for (j = 0; j < 8; j++) {
setpx(idx, -1 - j, rnd() & mask);
setpx(idx, j, rnd() & mask);
}
}
}
#define randomize_buffers(bidx, lineoff, str) \
randomize_loopfilter_buffers(bidx, lineoff, str, bit_depth, dir, \
E, F, H, I, buf0, buf1)
static void check_loopfilter(void)
{
LOCAL_ALIGNED_32(uint8_t, base0, [32 + 16 * 16 * 2]);
LOCAL_ALIGNED_32(uint8_t, base1, [32 + 16 * 16 * 2]);
VP9DSPContext dsp;
int dir, wd, wd2, bit_depth;
static const char *const dir_name[2] = { "h", "v" };
static const int E[2] = { 20, 28 }, I[2] = { 10, 16 };
static const int H[2] = { 7, 11 }, F[2] = { 1, 1 };
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int E, int I, int H);
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vp9dsp_init(&dsp, bit_depth, 0);
for (dir = 0; dir < 2; dir++) {
int midoff = (dir ? 8 * 8 : 8) * SIZEOF_PIXEL;
int midoff_aligned = (dir ? 8 * 8 : 16) * SIZEOF_PIXEL;
uint8_t *buf0 = base0 + midoff_aligned;
uint8_t *buf1 = base1 + midoff_aligned;
for (wd = 0; wd < 3; wd++) {
// 4/8/16wd_8px
if (check_func(dsp.loop_filter_8[wd][dir],
"vp9_loop_filter_%s_%d_8_%dbpp",
dir_name[dir], 4 << wd, bit_depth)) {
randomize_buffers(0, 0, 8);
memcpy(buf1 - midoff, buf0 - midoff,
16 * 8 * SIZEOF_PIXEL);
call_ref(buf0, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
call_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 8 * SIZEOF_PIXEL))
fail();
bench_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]);
}
}
midoff = (dir ? 16 * 8 : 8) * SIZEOF_PIXEL;
midoff_aligned = (dir ? 16 * 8 : 16) * SIZEOF_PIXEL;
buf0 = base0 + midoff_aligned;
buf1 = base1 + midoff_aligned;
// 16wd_16px loopfilter
if (check_func(dsp.loop_filter_16[dir],
"vp9_loop_filter_%s_16_16_%dbpp",
dir_name[dir], bit_depth)) {
randomize_buffers(0, 0, 16);
randomize_buffers(0, 8, 16);
memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL);
call_ref(buf0, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
call_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL))
fail();
bench_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]);
}
for (wd = 0; wd < 2; wd++) {
for (wd2 = 0; wd2 < 2; wd2++) {
// mix2 loopfilter
if (check_func(dsp.loop_filter_mix2[wd][wd2][dir],
"vp9_loop_filter_mix2_%s_%d%d_16_%dbpp",
dir_name[dir], 4 << wd, 4 << wd2, bit_depth)) {
randomize_buffers(0, 0, 16);
randomize_buffers(1, 8, 16);
memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL);
#define M(a) (((a)[1] << 8) | (a)[0])
call_ref(buf0, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
call_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL))
fail();
bench_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H));
#undef M
}
}
}
}
}
report("loopfilter");
}
#undef setsx
#undef setpx
#undef setdx
#undef randomize_buffers
#define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
#define SRC_BUF_STRIDE 72
#define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
#define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
#define randomize_buffers() \
do { \
uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
int k; \
for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf + k, r); \
} \
if (op == 1) { \
for (k = 0; k < DST_BUF_SIZE; k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(dst0 + k, r); \
AV_WN32A(dst1 + k, r); \
} \
} \
} while (0)
static void check_mc(void)
{
LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]);
LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]);
VP9DSPContext dsp;
int op, hsize, bit_depth, filter, dx, dy;
declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t dst_stride,
const uint8_t *ref, ptrdiff_t ref_stride,
int h, int mx, int my);
static const char *const filter_names[4] = {
"8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
};
static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
static const char *const op_names[2] = { "put", "avg" };
char str[256];
for (op = 0; op < 2; op++) {
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vp9dsp_init(&dsp, bit_depth, 0);
for (hsize = 0; hsize < 5; hsize++) {
int size = 64 >> hsize;
for (filter = 0; filter < 4; filter++) {
for (dx = 0; dx < 2; dx++) {
for (dy = 0; dy < 2; dy++) {
if (dx || dy) {
snprintf(str, sizeof(str),
"%s_%s_%d%s", op_names[op],
filter_names[filter], size,
subpel_names[dy][dx]);
} else {
snprintf(str, sizeof(str),
"%s%d", op_names[op], size);
}
if (check_func(dsp.mc[hsize][filter][op][dx][dy],
"vp9_%s_%dbpp", str, bit_depth)) {
int mx = dx ? 1 + (rnd() % 14) : 0;
int my = dy ? 1 + (rnd() % 14) : 0;
randomize_buffers();
call_ref(dst0, size * SIZEOF_PIXEL,
src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
size, mx, my);
call_new(dst1, size * SIZEOF_PIXEL,
src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
size, mx, my);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
// simd implementations for each filter of subpel
// functions are identical
if (filter >= 1 && filter <= 2) continue;
// 10/12 bpp for bilin are identical
if (bit_depth == 12 && filter == 3) continue;
bench_new(dst1, size * SIZEOF_PIXEL,
src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
size, mx, my);
}
}
}
}
}
}
}
report("mc");
}
void checkasm_check_vp9dsp(void)
{
check_ipred();
check_itxfm();
check_loopfilter();
check_mc();
}
+199
View File
@@ -0,0 +1,199 @@
/*
* Copyright (c) 2023-2024 Nuo Mi <nuomi2021@gmail.com>
* Copyright (c) 2023-2024 Wu Jianhua <toqsxw@outlook.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/vvc/ctu.h"
#include "libavcodec/vvc/data.h"
#include "libavcodec/vvc/dsp.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define SRC_PIXEL_STRIDE (MAX_CTU_SIZE + 2 * ALF_PADDING_SIZE)
#define DST_PIXEL_STRIDE (SRC_PIXEL_STRIDE + 4)
#define SRC_BUF_SIZE (SRC_PIXEL_STRIDE * (MAX_CTU_SIZE + 3 * 2) * 2) //+3 * 2 for top and bottom row, *2 for high bit depth
#define DST_BUF_SIZE (DST_PIXEL_STRIDE * (MAX_CTU_SIZE + 3 * 2) * 2)
#define LUMA_PARAMS_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE * ALF_NUM_COEFF_LUMA)
#define randomize_buffers(buf0, buf1, size) \
do { \
uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
int k; \
for (k = 0; k < size; k += 4) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf0 + k, r); \
AV_WN32A(buf1 + k, r); \
} \
} while (0)
#define randomize_buffers2(buf, size, filter) \
do { \
int k; \
if (filter) { \
for (k = 0; k < size; k++) { \
int8_t r = rnd(); \
buf[k] = r; \
} \
} else { \
for (k = 0; k < size; k++) { \
int r = rnd() % FF_ARRAY_ELEMS(clip_set); \
buf[k] = clip_set[r]; \
} \
} \
} while (0)
static int get_alf_vb_pos(const int h, const int vb_pos_above)
{
if (h == MAX_CTU_SIZE)
return MAX_CTU_SIZE - vb_pos_above;
// If h < MAX_CTU_SIZE and picture virtual boundaries are involved, ALF virtual boundaries can either be within or outside this ALF block.
return ((rnd() & 1) ? h : MAX_CTU_SIZE) - vb_pos_above;
}
static void check_alf_filter(VVCDSPContext *c, const int bit_depth)
{
LOCAL_ALIGNED_32(uint8_t, dst0, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
int16_t filter[LUMA_PARAMS_SIZE];
int16_t clip[LUMA_PARAMS_SIZE];
const int16_t clip_set[] = {
1 << bit_depth, 1 << (bit_depth - 3), 1 << (bit_depth - 5), 1 << (bit_depth - 7)
};
ptrdiff_t src_stride = SRC_PIXEL_STRIDE * SIZEOF_PIXEL;
ptrdiff_t dst_stride = DST_PIXEL_STRIDE * SIZEOF_PIXEL;
int offset = (3 * SRC_PIXEL_STRIDE + 3) * SIZEOF_PIXEL;
declare_func(void, uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src, ptrdiff_t src_stride,
int width, int height, const int16_t *filter, const int16_t *clip, const int vb_pos);
randomize_buffers(src0, src1, SRC_BUF_SIZE);
randomize_buffers2(filter, LUMA_PARAMS_SIZE, 1);
randomize_buffers2(clip, LUMA_PARAMS_SIZE, 0);
for (int h = 4; h <= MAX_CTU_SIZE; h += 4) {
for (int w = 4; w <= MAX_CTU_SIZE; w += 4) {
//Both picture size and virtual boundaries are 8-aligned. For luma, we only need to check 8-aligned sizes.
if (!(w % 8) && !(h % 8)) {
if (check_func(c->alf.filter[LUMA], "vvc_alf_filter_luma_%dx%d_%d", w, h, bit_depth)) {
const int vb_pos = get_alf_vb_pos(h, ALF_VB_POS_ABOVE_LUMA);
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, dst_stride, src0 + offset, src_stride, w, h, filter, clip, vb_pos);
call_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos);
for (int i = 0; i < (h + 1); i++) {
if (memcmp(dst0 + i * dst_stride, dst1 + i * dst_stride, (w + 1) * SIZEOF_PIXEL))
fail();
}
// Bench only square sizes, and ones with dimensions being a power of two.
if (w == h && (w & (w - 1)) == 0)
bench_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos);
}
}
//For chroma, once it exceeds 64, it's not a 4:2:0 format, so we only need to check 8-aligned sizes as well.
if ((w <= 64 || !(w % 8)) && (h <= 64 || !(h % 8))) {
if (check_func(c->alf.filter[CHROMA], "vvc_alf_filter_chroma_%dx%d_%d", w, h, bit_depth)) {
const int vb_pos = get_alf_vb_pos(h, ALF_VB_POS_ABOVE_CHROMA);
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, dst_stride, src0 + offset, src_stride, w, h, filter, clip, vb_pos);
call_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos);
for (int i = 0; i < (h + 1); i++) {
if (memcmp(dst0 + i * dst_stride, dst1 + i * dst_stride, (w + 1) * SIZEOF_PIXEL))
fail();
}
if (w == h && (w & (w - 1)) == 0)
bench_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos);
}
}
}
}
}
static void check_alf_classify(VVCDSPContext *c, const int bit_depth)
{
LOCAL_ALIGNED_32(int, class_idx0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int, transpose_idx0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int, class_idx1, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int, transpose_idx1, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int32_t, alf_gradient_tmp, [ALF_GRADIENT_SIZE * ALF_GRADIENT_SIZE * ALF_NUM_DIR]);
ptrdiff_t stride = SRC_PIXEL_STRIDE * SIZEOF_PIXEL;
int offset = (3 * SRC_PIXEL_STRIDE + 3) * SIZEOF_PIXEL;
declare_func(void, int *class_idx, int *transpose_idx,
const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, int *gradient_tmp);
randomize_buffers(src0, src1, SRC_BUF_SIZE);
//Both picture size and virtual boundaries are 8-aligned. Classify is luma only, we only need to check 8-aligned sizes.
for (int h = 8; h <= MAX_CTU_SIZE; h += 8) {
for (int w = 8; w <= MAX_CTU_SIZE; w += 8) {
const int id_size = w * h / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE * sizeof(int);
const int vb_pos = get_alf_vb_pos(h, ALF_VB_POS_ABOVE_LUMA);
if (check_func(c->alf.classify, "vvc_alf_classify_%dx%d_%d", w, h, bit_depth)) {
memset(class_idx0, 0, id_size);
memset(class_idx1, 0, id_size);
memset(transpose_idx0, 0, id_size);
memset(transpose_idx1, 0, id_size);
call_ref(class_idx0, transpose_idx0, src0 + offset, stride, w, h, vb_pos, alf_gradient_tmp);
call_new(class_idx1, transpose_idx1, src1 + offset, stride, w, h, vb_pos, alf_gradient_tmp);
if (memcmp(class_idx0, class_idx1, id_size))
fail();
if (memcmp(transpose_idx0, transpose_idx1, id_size))
fail();
// Bench only square sizes, and ones with dimensions being a power of two.
if (w == h && (w & (w - 1)) == 0)
bench_new(class_idx1, transpose_idx1, src1 + offset, stride, w, h, vb_pos, alf_gradient_tmp);
}
}
}
}
void checkasm_check_vvc_alf(void)
{
int bit_depth;
VVCDSPContext h;
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vvc_dsp_init(&h, bit_depth);
check_alf_filter(&h, bit_depth);
}
report("alf_filter");
for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vvc_dsp_init(&h, bit_depth);
check_alf_classify(&h, bit_depth);
}
report("alf_classify");
}
+481
View File
@@ -0,0 +1,481 @@
/*
* Copyright (c) 2023-2024 Nuo Mi
* Copyright (c) 2023-2024 Wu Jianhua
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <string.h>
#include "checkasm.h"
#include "libavcodec/vvc/ctu.h"
#include "libavcodec/vvc/data.h"
#include "libavcodec/vvc/dsp.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
static const uint32_t pixel_mask[] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff, 0x3fff3fff, 0xffffffff };
static const int sizes[] = { 2, 4, 8, 16, 32, 64, 128 };
#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
#define PIXEL_STRIDE (MAX_CTU_SIZE * 2)
#define EXTRA_BEFORE 3
#define EXTRA_AFTER 4
#define SRC_EXTRA (EXTRA_BEFORE + EXTRA_AFTER) * 2
#define SRC_BUF_SIZE (PIXEL_STRIDE + SRC_EXTRA) * (PIXEL_STRIDE + SRC_EXTRA)
#define DST_BUF_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE * 2)
#define SRC_OFFSET ((PIXEL_STRIDE + EXTRA_BEFORE * 2) * EXTRA_BEFORE)
#define randomize_buffers(buf0, buf1, size, mask) \
do { \
int k; \
for (k = 0; k < size; k += 4 / sizeof(*buf0)) { \
uint32_t r = rnd() & mask; \
AV_WN32A(buf0 + k, r); \
AV_WN32A(buf1 + k, r); \
} \
} while (0)
#define randomize_pixels(buf0, buf1, size) \
do { \
uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
randomize_buffers(buf0, buf1, size, mask); \
} while (0)
#define randomize_avg_src(buf0, buf1, size) \
do { \
uint32_t mask = 0x3fff3fff; \
randomize_buffers(buf0, buf1, size, mask); \
} while (0)
#define randomize_prof_src(buf0, buf1, size) \
do { \
const int shift = 14 - bit_depth; \
const int mask16 = 0x3fff >> shift << shift; \
uint32_t mask = (mask16 << 16) | mask16; \
randomize_buffers(buf0, buf1, size, mask); \
} while (0)
static void check_put_vvc_luma(void)
{
LOCAL_ALIGNED_32(int16_t, dst0, [DST_BUF_SIZE / 2]);
LOCAL_ALIGNED_32(int16_t, dst1, [DST_BUF_SIZE / 2]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
VVCDSPContext c;
declare_func(void, int16_t *dst, const uint8_t *src, const ptrdiff_t src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
randomize_pixels(src0, src1, SRC_BUF_SIZE);
ff_vvc_dsp_init(&c, bit_depth);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 4; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 4; w <= MAX_CTU_SIZE; w *= 2) {
const int idx = av_log2(w) - 1;
const int mx = rnd() % 16;
const int my = rnd() % 16;
const int8_t *hf = ff_vvc_inter_luma_filters[rnd() % 3][mx];
const int8_t *vf = ff_vvc_inter_luma_filters[rnd() % 3][my];
const char *type;
switch ((j << 1) | i) {
case 0: type = "put_luma_pixels"; break; // 0 0
case 1: type = "put_luma_h"; break; // 0 1
case 2: type = "put_luma_v"; break; // 1 0
case 3: type = "put_luma_hv"; break; // 1 1
}
if (check_func(c.inter.put[LUMA][idx][j][i], "%s_%d_%dx%d", type, bit_depth, w, h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, src0 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
call_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
}
}
}
}
}
}
report("put_luma");
}
static void check_put_vvc_luma_uni(void)
{
LOCAL_ALIGNED_32(uint8_t, dst0, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
VVCDSPContext c;
declare_func(void, uint8_t *dst, ptrdiff_t dststride,
const uint8_t *src, ptrdiff_t srcstride, int height,
const int8_t *hf, const int8_t *vf, int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vvc_dsp_init(&c, bit_depth);
randomize_pixels(src0, src1, SRC_BUF_SIZE);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 4; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 4; w <= MAX_CTU_SIZE; w *= 2) {
const int idx = av_log2(w) - 1;
const int mx = rnd() % VVC_INTER_LUMA_FACTS;
const int my = rnd() % VVC_INTER_LUMA_FACTS;
const int8_t *hf = ff_vvc_inter_luma_filters[rnd() % VVC_INTER_LUMA_FILTER_TYPES][mx];
const int8_t *vf = ff_vvc_inter_luma_filters[rnd() % VVC_INTER_LUMA_FILTER_TYPES][my];
const char *type;
switch ((j << 1) | i) {
case 0: type = "put_uni_pixels"; break; // 0 0
case 1: type = "put_uni_h"; break; // 0 1
case 2: type = "put_uni_v"; break; // 1 0
case 3: type = "put_uni_hv"; break; // 1 1
}
if (check_func(c.inter.put_uni[LUMA][idx][j][i], "%s_luma_%d_%dx%d", type, bit_depth, w, h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, PIXEL_STRIDE, src0 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
call_new(dst1, PIXEL_STRIDE, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst1, PIXEL_STRIDE, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
}
}
}
}
}
}
report("put_uni_luma");
}
static void check_put_vvc_chroma(void)
{
LOCAL_ALIGNED_32(int16_t, dst0, [DST_BUF_SIZE / 2]);
LOCAL_ALIGNED_32(int16_t, dst1, [DST_BUF_SIZE / 2]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
VVCDSPContext c;
declare_func(void, int16_t *dst, const uint8_t *src, const ptrdiff_t src_stride,
const int height, const int8_t *hf, const int8_t *vf, const int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
randomize_pixels(src0, src1, SRC_BUF_SIZE);
ff_vvc_dsp_init(&c, bit_depth);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 2; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 2; w <= MAX_CTU_SIZE; w *= 2) {
const int idx = av_log2(w) - 1;
const int mx = rnd() % VVC_INTER_CHROMA_FACTS;
const int my = rnd() % VVC_INTER_CHROMA_FACTS;
const int8_t *hf = ff_vvc_inter_chroma_filters[rnd() % VVC_INTER_CHROMA_FILTER_TYPES][mx];
const int8_t *vf = ff_vvc_inter_chroma_filters[rnd() % VVC_INTER_CHROMA_FILTER_TYPES][my];
const char *type;
switch ((j << 1) | i) {
case 0: type = "put_chroma_pixels"; break; // 0 0
case 1: type = "put_chroma_h"; break; // 0 1
case 2: type = "put_chroma_v"; break; // 1 0
case 3: type = "put_chroma_hv"; break; // 1 1
}
if (check_func(c.inter.put[CHROMA][idx][j][i], "%s_%d_%dx%d", type, bit_depth, w, h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, src0 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
call_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
}
}
}
}
}
}
report("put_chroma");
}
static void check_put_vvc_chroma_uni(void)
{
LOCAL_ALIGNED_32(uint8_t, dst0, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
VVCDSPContext c;
declare_func(void, uint8_t *dst, ptrdiff_t dststride,
const uint8_t *src, ptrdiff_t srcstride, int height,
const int8_t *hf, const int8_t *vf, int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vvc_dsp_init(&c, bit_depth);
randomize_pixels(src0, src1, SRC_BUF_SIZE);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 4; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 4; w <= MAX_CTU_SIZE; w *= 2) {
const int idx = av_log2(w) - 1;
const int mx = rnd() % VVC_INTER_CHROMA_FACTS;
const int my = rnd() % VVC_INTER_CHROMA_FACTS;
const int8_t *hf = ff_vvc_inter_chroma_filters[rnd() % VVC_INTER_CHROMA_FILTER_TYPES][mx];
const int8_t *vf = ff_vvc_inter_chroma_filters[rnd() % VVC_INTER_CHROMA_FILTER_TYPES][my];
const char *type;
switch ((j << 1) | i) {
case 0: type = "put_uni_pixels"; break; // 0 0
case 1: type = "put_uni_h"; break; // 0 1
case 2: type = "put_uni_v"; break; // 1 0
case 3: type = "put_uni_hv"; break; // 1 1
}
if (check_func(c.inter.put_uni[CHROMA][idx][j][i], "%s_chroma_%d_%dx%d", type, bit_depth, w, h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, PIXEL_STRIDE, src0 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
call_new(dst1, PIXEL_STRIDE, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst1, PIXEL_STRIDE, src1 + SRC_OFFSET, PIXEL_STRIDE, h, hf, vf, w);
}
}
}
}
}
}
report("put_uni_chroma");
}
#define AVG_SRC_BUF_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE)
#define AVG_DST_BUF_SIZE (MAX_PB_SIZE * MAX_PB_SIZE * 2)
static void check_avg(void)
{
LOCAL_ALIGNED_32(int16_t, src00, [AVG_SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, src01, [AVG_SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, src10, [AVG_SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(int16_t, src11, [AVG_SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst0, [AVG_DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [AVG_DST_BUF_SIZE]);
VVCDSPContext c;
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
randomize_avg_src((uint8_t*)src00, (uint8_t*)src10, AVG_SRC_BUF_SIZE * sizeof(int16_t));
randomize_avg_src((uint8_t*)src01, (uint8_t*)src11, AVG_SRC_BUF_SIZE * sizeof(int16_t));
ff_vvc_dsp_init(&c, bit_depth);
for (int h = 2; h <= MAX_CTU_SIZE; h *= 2) {
for (int w = 2; w <= MAX_CTU_SIZE; w *= 2) {
{
declare_func(void, uint8_t *dst, ptrdiff_t dst_stride,
const int16_t *src0, const int16_t *src1, int width, int height);
if (check_func(c.inter.avg, "avg_%d_%dx%d", bit_depth, w, h)) {
memset(dst0, 0, AVG_DST_BUF_SIZE);
memset(dst1, 0, AVG_DST_BUF_SIZE);
call_ref(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, src01, w, h);
call_new(dst1, MAX_CTU_SIZE * SIZEOF_PIXEL, src10, src11, w, h);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, src01, w, h);
}
}
{
declare_func(void, uint8_t *dst, ptrdiff_t dst_stride,
const int16_t *src0, const int16_t *src1, int width, int height,
int denom, int w0, int w1, int o0, int o1);
{
const int denom = rnd() % 8;
const int w0 = rnd() % 256 - 128;
const int w1 = rnd() % 256 - 128;
const int o0 = rnd() % 256 - 128;
const int o1 = rnd() % 256 - 128;
if (check_func(c.inter.w_avg, "w_avg_%d_%dx%d", bit_depth, w, h)) {
memset(dst0, 0, AVG_DST_BUF_SIZE);
memset(dst1, 0, AVG_DST_BUF_SIZE);
call_ref(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, src01, w, h, denom, w0, w1, o0, o1);
call_new(dst1, MAX_CTU_SIZE * SIZEOF_PIXEL, src10, src11, w, h, denom, w0, w1, o0, o1);
if (memcmp(dst0, dst1, DST_BUF_SIZE))
fail();
if (w == h)
bench_new(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, src01, w, h, denom, w0, w1, o0, o1);
}
}
}
}
}
}
report("avg");
}
#define SR_RANGE 2
static void check_dmvr(void)
{
LOCAL_ALIGNED_32(uint16_t, dst0, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint16_t, dst1, [DST_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
const int dst_stride = MAX_PB_SIZE * sizeof(int16_t);
VVCDSPContext c;
declare_func(void, int16_t *dst, const uint8_t *src, ptrdiff_t src_stride, int height,
intptr_t mx, intptr_t my, int width);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
ff_vvc_dsp_init(&c, bit_depth);
randomize_pixels(src0, src1, SRC_BUF_SIZE);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int h = 8; h <= 16; h *= 2) {
for (int w = 8; w <= 16; w *= 2) {
const int pred_w = w + 2 * SR_RANGE;
const int pred_h = h + 2 * SR_RANGE;
const int mx = rnd() % VVC_INTER_LUMA_DMVR_FACTS;
const int my = rnd() % VVC_INTER_LUMA_DMVR_FACTS;
const char *type;
if (w * h < 128)
continue;
switch ((j << 1) | i) {
case 0: type = "dmvr"; break; // 0 0
case 1: type = "dmvr_h"; break; // 0 1
case 2: type = "dmvr_v"; break; // 1 0
case 3: type = "dmvr_hv"; break; // 1 1
}
if (check_func(c.inter.dmvr[j][i], "%s_%d_%dx%d", type, bit_depth, pred_w, pred_h)) {
memset(dst0, 0, DST_BUF_SIZE);
memset(dst1, 0, DST_BUF_SIZE);
call_ref(dst0, src0 + SRC_OFFSET, PIXEL_STRIDE, pred_h, mx, my, pred_w);
call_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, pred_h, mx, my, pred_w);
for (int k = 0; k < pred_h; k++) {
if (memcmp(dst0 + k * dst_stride, dst1 + k * dst_stride, pred_w * sizeof(int16_t))) {
fail();
break;
}
}
bench_new(dst1, src1 + SRC_OFFSET, PIXEL_STRIDE, pred_h, mx, my, pred_w);
}
}
}
}
}
}
report("dmvr");
}
#define BDOF_BLOCK_SIZE 16
#define BDOF_SRC_SIZE (MAX_PB_SIZE* (BDOF_BLOCK_SIZE + 2))
#define BDOF_SRC_OFFSET (MAX_PB_SIZE + 1)
#define BDOF_DST_SIZE (BDOF_BLOCK_SIZE * BDOF_BLOCK_SIZE * 2)
static void check_bdof(void)
{
LOCAL_ALIGNED_32(uint8_t, dst0, [BDOF_DST_SIZE]);
LOCAL_ALIGNED_32(uint8_t, dst1, [BDOF_DST_SIZE]);
LOCAL_ALIGNED_32(uint16_t, src00, [BDOF_SRC_SIZE]);
LOCAL_ALIGNED_32(uint16_t, src01, [BDOF_SRC_SIZE]);
LOCAL_ALIGNED_32(uint16_t, src10, [BDOF_SRC_SIZE]);
LOCAL_ALIGNED_32(uint16_t, src11, [BDOF_SRC_SIZE]);
VVCDSPContext c;
declare_func(void, uint8_t *dst, ptrdiff_t dst_stride, const int16_t *src0, const int16_t *src1, int block_w, int block_h);
for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
const int dst_stride = BDOF_BLOCK_SIZE * SIZEOF_PIXEL;
ff_vvc_dsp_init(&c, bit_depth);
randomize_prof_src(src00, src10, BDOF_SRC_SIZE);
randomize_prof_src(src01, src11, BDOF_SRC_SIZE);
for (int h = 8; h <= 16; h *= 2) {
for (int w = 8; w <= 16; w *= 2) {
if (w * h < 128)
continue;
if (check_func(c.inter.apply_bdof, "apply_bdof_%d_%dx%d", bit_depth, w, h)) {
memset(dst0, 0, BDOF_DST_SIZE);
memset(dst1, 0, BDOF_DST_SIZE);
call_ref(dst0, dst_stride, src00 + BDOF_SRC_OFFSET, src01 + BDOF_SRC_OFFSET, w, h);
call_new(dst1, dst_stride, src10 + BDOF_SRC_OFFSET, src11 + BDOF_SRC_OFFSET, w, h);
if (memcmp(dst0, dst1, BDOF_DST_SIZE))
fail();
bench_new(dst0, dst_stride, src00 + BDOF_SRC_OFFSET, src01 + BDOF_SRC_OFFSET, w, h);
}
}
}
}
report("apply_bdof");
}
static void check_vvc_sad(void)
{
const int bit_depth = 10;
VVCDSPContext c;
LOCAL_ALIGNED_32(uint16_t, src0, [MAX_CTU_SIZE * MAX_CTU_SIZE * 4]);
LOCAL_ALIGNED_32(uint16_t, src1, [MAX_CTU_SIZE * MAX_CTU_SIZE * 4]);
declare_func(int, const int16_t *src0, const int16_t *src1, int dx, int dy, int block_w, int block_h);
ff_vvc_dsp_init(&c, bit_depth);
randomize_pixels(src0, src1, MAX_CTU_SIZE * MAX_CTU_SIZE * 4);
for (int h = 8; h <= 16; h *= 2) {
for (int w = 8; w <= 16; w *= 2) {
for(int offy = 0; offy <= 4; offy++) {
for(int offx = 0; offx <= 4; offx++) {
if (w * h < 128)
continue;
if (check_func(c.inter.sad, "sad_%dx%d", w, h)) {
int result0;
int result1;
result0 = call_ref(src0 + PIXEL_STRIDE * 2 + 2, src1 + PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
result1 = call_new(src0 + PIXEL_STRIDE * 2 + 2, src1 + PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
if (result1 != result0)
fail();
if(offx == 0 && offy == 0)
bench_new(src0 + PIXEL_STRIDE * 2 + 2, src1 + PIXEL_STRIDE * 2 + 2, offx, offy, w, h);
}
}
}
}
}
report("sad");
}
void checkasm_check_vvc_mc(void)
{
check_dmvr();
check_bdof();
check_vvc_sad();
check_put_vvc_luma();
check_put_vvc_luma_uni();
check_put_vvc_chroma();
check_put_vvc_chroma_uni();
check_avg();
}
+244
View File
@@ -0,0 +1,244 @@
;*****************************************************************************
;* Assembly testing and benchmarking tool
;* Copyright (c) 2008 Loren Merritt
;* Copyright (c) 2012 Henrik Gramner
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
;* the Free Software Foundation; either version 2 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 General Public License for more details.
;*
;* You should have received a copy of the GNU General Public License
;* along with this program; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
;*****************************************************************************
%define private_prefix checkasm
%include "libavutil/x86/x86inc.asm"
SECTION_RODATA
error_message: db "failed to preserve register", 0
error_message_emms: db "failed to issue emms", 0
%if ARCH_X86_64
; just random numbers to reduce the chance of incidental match
ALIGN 16
x6: dq 0x1a1b2550a612b48c,0x79445c159ce79064
x7: dq 0x2eed899d5a28ddcd,0x86b2536fcd8cf636
x8: dq 0xb0856806085e7943,0x3f2bf84fc0fcca4e
x9: dq 0xacbd382dcf5b8de2,0xd229e1f5b281303f
x10: dq 0x71aeaff20b095fd9,0xab63e2e11fa38ed9
x11: dq 0x89b0c0765892729a,0x77d410d5c42c882d
x12: dq 0xc45ea11a955d8dd5,0x24b3c1d2a024048b
x13: dq 0x2e8ec680de14b47c,0xdd7b8919edd42786
x14: dq 0x135ce6888fa02cbf,0x11e53e2b2ac655ef
x15: dq 0x011ff554472a7a10,0x6de8f4c914c334d5
n7: dq 0x21f86d66c8ca00ce
n8: dq 0x75b6ba21077c48ad
n9: dq 0xed56bb2dcb3c7736
n10: dq 0x8bda43d3fd1a7e06
n11: dq 0xb64a9c9e5d318408
n12: dq 0xdf9a54b303f1d3a3
n13: dq 0x4a75479abd64e097
n14: dq 0x249214109d5d1c88
%endif
SECTION .text
cextern fail_func
; max number of args used by any asm function.
; (max_args % 4) must equal 3 for stack alignment
%define max_args 15
%if ARCH_X86_64
;-----------------------------------------------------------------------------
; int checkasm_stack_clobber(uint64_t clobber, ...)
;-----------------------------------------------------------------------------
cglobal stack_clobber, 1,2
; Clobber the stack with junk below the stack pointer
%define argsize (max_args+6)*8
SUB rsp, argsize
mov r1, argsize-8
.loop:
mov [rsp+r1], r0
sub r1, 8
jge .loop
ADD rsp, argsize
RET
%if WIN64
%assign free_regs 7
DECLARE_REG_TMP 4
%else
%assign free_regs 9
DECLARE_REG_TMP 7
%endif
%macro report_fail 1
mov r9, rax
mov r10, rdx
lea r0, [%1]
xor eax, eax
call fail_func
mov rdx, r10
mov rax, r9
%endmacro
;-----------------------------------------------------------------------------
; void checkasm_checked_call(void *func, ...)
;-----------------------------------------------------------------------------
INIT_XMM
%macro CHECKED_CALL 0-1
cglobal checked_call%1, 2,15,16,max_args*8+8
mov t0, r0
; All arguments have been pushed on the stack instead of registers in order to
; test for incorrect assumptions that 32-bit ints are zero-extended to 64-bit.
mov r0, r6mp
mov r1, r7mp
mov r2, r8mp
mov r3, r9mp
%if UNIX64
mov r4, r10mp
mov r5, r11mp
%assign i 6
%rep max_args-6
mov r9, [rsp+stack_offset+(i+1)*8]
mov [rsp+(i-6)*8], r9
%assign i i+1
%endrep
%else ; WIN64
%assign i 4
%rep max_args-4
mov r9, [rsp+stack_offset+(i+7)*8]
mov [rsp+i*8], r9
%assign i i+1
%endrep
; Move possible floating-point arguments to the correct registers
movq m0, r0
movq m1, r1
movq m2, r2
movq m3, r3
%assign i 6
%rep 16-6
mova m %+ i, [x %+ i]
%assign i i+1
%endrep
%endif
%assign i 14
%rep 15-free_regs
mov r %+ i, [n %+ i]
%assign i i-1
%endrep
call t0
%assign i 14
%rep 15-free_regs
xor r %+ i, [n %+ i]
or r14, r %+ i
%assign i i-1
%endrep
%if WIN64
%assign i 6
%rep 16-6
pxor m %+ i, [x %+ i]
por m6, m %+ i
%assign i i+1
%endrep
packsswb m6, m6
movq r5, m6
or r14, r5
%endif
; Call fail_func() with a descriptive message to mark it as a failure
; if the called function didn't preserve all callee-saved registers.
; Save the return value located in rdx:rax first to prevent clobbering.
jz .clobber_ok
report_fail error_message
.clobber_ok:
%ifidn %1, _emms
emms
%elifnidn %1, _float
fstenv [rsp]
cmp word [rsp + 8], 0xffff
je .emms_ok
report_fail error_message_emms
emms
.emms_ok:
%endif
RET
%endmacro
%else
; just random numbers to reduce the chance of incidental match
%define n3 dword 0x6549315c
%define n4 dword 0xe02f3e23
%define n5 dword 0xb78d0d1d
%define n6 dword 0x33627ba7
%macro report_fail 1
mov r3, eax
mov r4, edx
lea r0, [%1]
mov [esp], r0
call fail_func
mov edx, r4
mov eax, r3
%endmacro
%macro CHECKED_CALL 0-1
;-----------------------------------------------------------------------------
; void checkasm_checked_call(void *func, ...)
;-----------------------------------------------------------------------------
cglobal checked_call%1, 1,7
mov r3, n3
mov r4, n4
mov r5, n5
mov r6, n6
%rep max_args
PUSH dword [esp+20+max_args*4]
%endrep
call r0
xor r3, n3
xor r4, n4
xor r5, n5
xor r6, n6
or r3, r4
or r5, r6
or r3, r5
jz .clobber_ok
report_fail error_message
.clobber_ok:
%ifidn %1, _emms
emms
%elifnidn %1, _float
fstenv [esp]
cmp word [esp + 8], 0xffff
je .emms_ok
report_fail error_message_emms
emms
.emms_ok:
%endif
add esp, max_args*4
RET
%endmacro
%endif ; ARCH_X86_64
CHECKED_CALL
CHECKED_CALL _emms
CHECKED_CALL _float
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
LC_ALL=C
export LC_ALL
datadir="tests/data"
logfile="$datadir/copy.regression"
reffile="$1"
list=$(grep -oh ' ./tests/data/.*' tests/ref/{acodec,lavf,vsynth1}/*| sort)
rm -f $logfile
for i in $list ; do
echo ---------------- >> $logfile
echo $i >> $logfile
./ffmpeg_g -flags +bitexact -i $i -acodec copy -vcodec copy -y first.nut
./ffmpeg_g -flags +bitexact -i first.nut -acodec copy -vcodec copy -y second.nut
cmp first.nut second.nut >> $logfile
md5sum first.nut >> $logfile
done
if diff -u -w "$reffile" "$logfile" ; then
echo
echo copy regression test: success
exit 0
else
echo
echo copy regression test: error
exit 1
fi
+113
View File
@@ -0,0 +1,113 @@
ffconcat version 1.0
file %SRCFILE%
file %SRCFILE%
duration 1
file_packet_meta dummy 1
file %SRCFILE%
inpoint 00:00.00
outpoint 00:00.04
file %SRCFILE%
inpoint 00:00.04
outpoint 00:00.08
file %SRCFILE%
inpoint 00:00.08
outpoint 00:00.12
file %SRCFILE%
inpoint 00:00.12
outpoint 00:00.16
file %SRCFILE%
inpoint 00:00.16
outpoint 00:00.20
file %SRCFILE%
inpoint 00:00.20
outpoint 00:00.24
file %SRCFILE%
inpoint 00:00.24
outpoint 00:00.28
file %SRCFILE%
inpoint 00:00.28
outpoint 00:00.32
file %SRCFILE%
inpoint 00:00.32
outpoint 00:00.36
file %SRCFILE%
inpoint 00:00.36
outpoint 00:00.40
file %SRCFILE%
inpoint 00:00.40
outpoint 00:00.44
file %SRCFILE%
inpoint 00:00.44
outpoint 00:00.48
file %SRCFILE%
inpoint 00:00.48
outpoint 00:00.52
file %SRCFILE%
inpoint 00:00.52
outpoint 00:00.56
file %SRCFILE%
inpoint 00:00.56
outpoint 00:00.60
file %SRCFILE%
inpoint 00:00.60
outpoint 00:00.64
file %SRCFILE%
inpoint 00:00.64
outpoint 00:00.68
file %SRCFILE%
inpoint 00:00.68
outpoint 00:00.72
file %SRCFILE%
inpoint 00:00.72
outpoint 00:00.76
file %SRCFILE%
inpoint 00:00.76
outpoint 00:00.80
file %SRCFILE%
inpoint 00:00.80
outpoint 00:00.84
file %SRCFILE%
inpoint 00:00.84
outpoint 00:00.88
file %SRCFILE%
inpoint 00:00.88
outpoint 00:00.92
file %SRCFILE%
inpoint 00:00.92
outpoint 00:00.96
file %SRCFILE%
inpoint 00:00.96
outpoint 00:01.00
file %SRCFILE%
outpoint 00:00.40
file %SRCFILE%
inpoint 00:00.40
+700
View File
@@ -0,0 +1,700 @@
#!/bin/sh
export LC_ALL=C
base=$(dirname $0)
. "${base}/md5.sh"
base64=tests/base64${HOSTEXECSUF}
test="${1#fate-}"
target_samples=$2
target_exec=$3
target_path=$4
command=$5
cmp=${6:-diff}
ref=${7:-"${base}/ref/fate/${test}"}
fuzz=${8:-1}
threads=${9:-1}
thread_type=${10:-frame+slice}
cpuflags=${11:-all}
cmp_shift=${12:-0}
cmp_target=${13:-0}
size_tolerance=${14:-0}
cmp_unit=${15:-2}
gen=${16:-no}
hwaccel=${17:-none}
report_type=${18:-standard}
keep=${19:-0}
outdir="tests/data/fate"
outfile="${outdir}/${test}"
errfile="${outdir}/${test}.err"
cmpfile="${outdir}/${test}.diff"
repfile="${outdir}/${test}.rep"
case $threads in
random*)
threads_max=${threads#random}
[ -z "$threads_max" ] && threads_max=16
threads=$(awk "BEGIN { srand(); print 1+int(rand() * $threads_max) }" < /dev/null)
;;
esac
target_path(){
case ${1} in
[a-zA-Z]:/*)
echo ${1}
;;
/*)
echo ${1}
;;
*)
echo ${target_path}/${1}
;;
esac
}
# $1=value1, $2=value2, $3=threshold
# prints 0 if absolute difference between value1 and value2 is <= threshold
compare(){
awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
}
do_tiny_psnr(){
psnr=$(tests/tiny_psnr${HOSTEXECSUF} "$1" "$2" $cmp_unit $cmp_shift 0) || return 1
val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
val_cmp=$(compare $val $cmp_target $fuzz)
size_cmp=$(compare $size1 $size2 $size_tolerance)
if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
echo "$psnr"
if [ "$val_cmp" != 0 ]; then
echo "$3: |$val - $cmp_target| >= $fuzz"
fi
if [ "$size_cmp" != 0 ]; then
echo "size: |$size1 - $size2| >= $size_tolerance"
fi
return 1
fi
}
oneoff(){
do_tiny_psnr "$1" "$2" MAXDIFF
}
stddev(){
do_tiny_psnr "$1" "$2" stddev
}
oneline(){
printf '%s\n' "$1" | diff -u -b - "$2"
}
run(){
test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
$target_exec $target_path/"$@"
}
runecho(){
test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
$target_exec $target_path/"$@" >&3
}
probefmt(){
run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_entries format=format_name -print_format default=nw=1:nk=1 "$@"
}
probeaudiostream(){
run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_entries stream=codec_name,codec_time_base,sample_fmt,channels,channel_layout:side_data "$@"
}
probetags(){
run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_entries format_tags "$@"
}
runlocal(){
test "${V:-0}" -gt 0 && echo ${base}/"$@" ${base} >&3
${base}/"$@" ${base}
}
probeframes(){
run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_frames "$@"
}
probechapters(){
run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_chapters "$@"
}
probegaplessinfo(){
filename="$1"
shift
run ffprobe${PROGSUF}${EXECSUF} -bitexact -select_streams a -show_entries format=start_time,duration:stream=index,start_pts,duration_ts "$filename" "$@"
pktfile1="${outdir}/${test}.pkts"
framefile1="${outdir}/${test}.frames"
cleanfiles="$cleanfiles $pktfile1 $framefile1"
run ffprobe${PROGSUF}${EXECSUF} -bitexact -select_streams a -of compact -count_packets -show_entries packet=pts,dts,duration,flags:stream=nb_read_packets "$filename" "$@" > "$pktfile1"
head -n 8 "$pktfile1"
tail -n 9 "$pktfile1"
run ffprobe${PROGSUF}${EXECSUF} -bitexact -select_streams a -of compact -count_frames -show_entries frame=pts,pkt_dts,best_effort_timestamp,pkt_duration,nb_samples:stream=nb_read_frames "$filename" "$@" > "$framefile1"
head -n 8 "$framefile1"
tail -n 9 "$framefile1"
}
ffmpeg(){
dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
ffmpeg_args="-nostdin -nostats -noauto_conversion_filters -cpuflags $cpuflags"
for arg in $@; do
[ x${arg} = x-i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
ffmpeg_args="${ffmpeg_args} ${arg}"
done
run ffmpeg${PROGSUF}${EXECSUF} ${ffmpeg_args}
}
ffprobe_demux(){
filename=$1
shift
print_filename=$(basename "$filename")
run ffprobe${PROGSUF}${EXECSUF} -print_filename "${print_filename}" \
-of compact -bitexact -show_format -show_streams -show_packets \
-show_data_hash CRC32 "$filename" "$@"
}
framecrc(){
ffmpeg "$@" -bitexact -f framecrc -
}
ffmetadata(){
ffmpeg "$@" -bitexact -f ffmetadata -
}
framemd5(){
ffmpeg "$@" -bitexact -f framemd5 -
}
crc(){
ffmpeg "$@" -f crc -
}
md5pipe(){
ffmpeg "$@" md5:
}
md5(){
encfile="${outdir}/${test}.out"
cleanfiles="$cleanfiles $encfile"
ffmpeg -y "$@" $(target_path $encfile) || return
do_md5sum $encfile | awk '{print $1}'
}
pcm(){
ffmpeg -auto_conversion_filters "$@" -vn -f s16le -
}
fmtstdout(){
fmt=$1
shift 1
ffmpeg -bitexact "$@" -bitexact -f $fmt -
}
enc_dec_pcm(){
out_fmt=$1
dec_fmt=$2
pcm_fmt=$3
src_file=$(target_path $4)
shift 4
encfile="${outdir}/${test}.${out_fmt}"
cleanfiles=$encfile
encfile=$(target_path ${encfile})
ffmpeg -auto_conversion_filters -i $src_file "$@" -f $out_fmt -y ${encfile} || return
ffmpeg -auto_conversion_filters -bitexact -i ${encfile} -c:a pcm_${pcm_fmt} -fflags +bitexact -f ${dec_fmt} -
}
FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
DEC_OPTS="-threads $threads -thread_type $thread_type -idct simple $FLAGS"
ENC_OPTS="-threads 1 -idct simple -dct fastint"
enc_dec(){
enc_fmt_in=$1
srcfile=$2
enc_fmt_out=$3
enc_opt_out=$4
dec_fmt_out=$5
dec_opt_out=$6
dec_opt_in=$7
ffprobe_opts=$8
twopass=$9
encfile="${outdir}/${test}.${enc_fmt_out}"
decfile="${outdir}/${test}.out.${dec_fmt_out}"
cleanfiles="$cleanfiles $decfile"
test "$keep" -ge 1 || cleanfiles="$cleanfiles $encfile"
tsrcfile=$(target_path $srcfile)
tencfile=$(target_path $encfile)
tdecfile=$(target_path $decfile)
if [ -n "$twopass" ]; then
logfile_prefix="${outdir}/${test}.pass1"
cleanfiles="$cleanfiles ${logfile_prefix}-0.log"
tlogfile_prefix=$(target_path $logfile_prefix)
ffmpeg -auto_conversion_filters -f $enc_fmt_in $DEC_OPTS -i $tsrcfile \
$ENC_OPTS $enc_opt_out $FLAGS -pass 1 -passlogfile $tlogfile_prefix \
-f $enc_fmt_out -y $tencfile || return
enc_opt_out="$enc_opt_out -pass 2 -passlogfile $tlogfile_prefix"
fi
ffmpeg -auto_conversion_filters -f $enc_fmt_in $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt_out $FLAGS \
-f $enc_fmt_out -y $tencfile || return
do_md5sum $encfile
echo $(wc -c $encfile)
ffmpeg -auto_conversion_filters $dec_opt_in $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt_out $FLAGS \
-f $dec_fmt_out -y $tdecfile || return
do_md5sum $decfile
tests/tiny_psnr${HOSTEXECSUF} $srcfile $decfile $cmp_unit $cmp_shift
test -z "$ffprobe_opts" || \
run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || return
}
transcode(){
src_fmt=$1
srcfile=$2
enc_fmt=$3
enc_opt=$4
final_encode=$5
ffprobe_opts=$6
additional_input=$7
final_decode=$8
enc_opt_in=$9
test -z "$additional_input" || additional_input="$DEC_OPTS $additional_input"
encfile="${outdir}/${test}.${enc_fmt}"
test $keep -ge 1 || cleanfiles="$cleanfiles $encfile"
tsrcfile=$(target_path $srcfile)
tencfile=$(target_path $encfile)
ffmpeg -f $src_fmt $DEC_OPTS $enc_opt_in -i $tsrcfile $additional_input \
$ENC_OPTS $enc_opt $FLAGS -f $enc_fmt -y $tencfile || return
do_md5sum $encfile
echo $(wc -c $encfile)
ffmpeg $DEC_OPTS $final_decode -i $tencfile $ENC_OPTS $FLAGS $final_encode \
-f framecrc - || return
test -z "$ffprobe_opts" || \
run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || return
}
stream_demux(){
src_fmt=$1
srcfile=$2
src_opts=$3
enc_opts=$4
ffprobe_opts=$5
tsrcfile=$(target_path $srcfile)
ffmpeg $DEC_OPTS -f $src_fmt $src_opts -i $tsrcfile $ENC_OPTS $FLAGS $enc_opts \
-f framecrc - || return
test -z "$ffprobe_opts" || \
run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tsrcfile || return
}
stream_remux(){
src_fmt=$1
srcfile=$2
src_opts=$3
enc_fmt=$4
stream_maps=$5
final_decode=$6
final_encode=$7
ffprobe_opts=$8
encfile="${outdir}/${test}.${enc_fmt}"
test $keep -ge 1 || cleanfiles="$cleanfiles $encfile"
tsrcfile=$(target_path $srcfile)
tencfile=$(target_path $encfile)
ffmpeg -f $src_fmt $src_opts -i $tsrcfile $stream_maps -codec copy $FLAGS \
-f $enc_fmt -y $tencfile || return
ffmpeg $DEC_OPTS $final_decode -i $tencfile $ENC_OPTS $FLAGS $final_encode \
-f framecrc - || return
test -z "$ffprobe_opts" || \
run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || return
}
# this function is for testing external encoders,
# where the precise output is not controlled by us
# we can still test e.g. that the output can be decoded correctly
enc_external(){
srcfile=$1
enc_fmt=$2
enc_opt=$3
probe_opt=$4
srcfile=$(target_path $srcfile)
encfile=$(target_path "${outdir}/${test}.${enc_fmt}")
ffmpeg -i $srcfile $enc_opt -f $enc_fmt -y $encfile || return
run ffprobe${PROGSUF}${EXECSUF} -bitexact $probe_opt $encfile || return
}
# FIXME: There is a certain duplication between the avconv-related helper
# functions above and below that should be refactored.
ffmpeg2="$target_exec ${target_path}/ffmpeg${PROGSUF}${EXECSUF}"
raw_src="${target_path}/tests/vsynth1/%02d.pgm"
pcm_src="${target_path}/tests/data/asynth1.sw"
[ "${V-0}" -gt 0 ] && echov=echov || echov=:
echov(){
echo "$@" >&3
}
AVCONV_OPTS="-nostdin -nostats -noauto_conversion_filters -y -cpuflags $cpuflags -filter_threads $threads"
COMMON_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
DEC_OPTS="$COMMON_OPTS -threads $threads"
ENC_OPTS="$COMMON_OPTS -threads 1 -dct fastint"
run_avconv(){
$echov $ffmpeg2 $AVCONV_OPTS $*
$ffmpeg2 $AVCONV_OPTS $*
}
do_avconv(){
f="$1"
shift
set -- $* ${target_path}/$f
run_avconv $* || return
do_md5sum $f
echo $(wc -c $f)
}
do_avconv_crc(){
f="$1"
shift
printf "%s " "$f"
run_avconv $* -f crc -
}
lavf_audio(){
t="${test#lavf-}"
outdir="tests/data/lavf"
file=${outdir}/lavf.$t
test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
do_avconv $file -auto_conversion_filters $DEC_OPTS $1 -ar 44100 -f s16le -i $pcm_src \
"$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10 $2 || return
test "$4" = "disable_crc" ||
do_avconv_crc $file -auto_conversion_filters $DEC_OPTS $3 -i $target_path/$file
}
lavf_container(){
t="${test#lavf-}"
outdir="tests/data/lavf"
file=${outdir}/lavf.$t
test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $DEC_OPTS \
-ar 44100 -f s16le $1 -i $pcm_src "$ENC_OPTS -metadata title=lavftest" -b:a 64k -t 1 -qscale:v 10 $2 || return
test "$3" = "disable_crc" ||
do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $3
}
lavf_container_attach() { lavf_container "" "$1 -attach ${raw_src%/*}/00.pgm -metadata:s:t mimetype=image/x-portable-greymap"; }
lavf_container_timecode_nodrop() { lavf_container "" "$1 -timecode 02:56:14:13"; }
lavf_container_timecode_drop() { lavf_container "" "$1 -timecode 02:56:14.13 -r 30000/1001"; }
lavf_container_timecode()
{
lavf_container_timecode_nodrop "$@"
lavf_container_timecode_drop "$@"
lavf_container "" "$1"
}
lavf_container_fate()
{
t="${test#lavf-fate-}"
outdir="tests/data/lavf-fate"
file=${outdir}/lavf.$t
cleanfiles="$cleanfiles $file"
input="${target_samples}/$1"
do_avconv $file -auto_conversion_filters $DEC_OPTS $2 -i "$input" \
"$ENC_OPTS -metadata title=lavftest" -vcodec copy -acodec copy || return
do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $3
}
lavf_image(){
no_file_checksums="$3"
nb_frames=13
t="${test#lavf-}"
outdir="tests/data/images/$t"
mkdir -p "$outdir"
file=${outdir}/%02d.$t
if [ "$keep" -lt 1 ]; then
for i in `seq $nb_frames`; do
filename=`printf "$file" $i`
cleanfiles="$cleanfiles $filename"
done
fi
run_avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $1 \
"$ENC_OPTS -metadata title=lavftest" -vf scale -frames $nb_frames \
-y -qscale 10 $target_path/$file || return
if [ -z "$no_file_checksums" ]; then
do_md5sum ${outdir}/02.$t
echo $(wc -c ${outdir}/02.$t)
fi
do_avconv_crc $file -auto_conversion_filters $DEC_OPTS $2 -i $target_path/$file $2
}
lavf_image2pipe(){
t="${test#lavf-}"
t="${t%pipe}"
outdir="tests/data/lavf"
file=${outdir}/${t}pipe.$t
do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src \
-f image2pipe "$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10 || return
do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -f image2pipe -i $target_path/$file
}
lavf_video(){
t="${test#lavf-}"
outdir="tests/data/lavf"
file=${outdir}/lavf.$t
test "$keep" -ge 1 || cleanfiles="$cleanfiles $file"
do_avconv $file -auto_conversion_filters $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src \
"$ENC_OPTS -metadata title=lavftest" -t 1 -qscale 10 $1 $2 || return
do_avconv_crc $file -auto_conversion_filters $DEC_OPTS -i $target_path/$file $1
}
refcmp_metadata(){
refcmp=$1
pixfmt=$2
fuzz=${3:-0.001}
ffmpeg -auto_conversion_filters $FLAGS $ENC_OPTS \
-lavfi "testsrc2=size=300x200:rate=1:duration=5,format=${pixfmt},split[ref][tmp];[tmp]avgblur=4[enc];[enc][ref]${refcmp},metadata=print:file=-" \
-f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
}
cmp_metadata(){
refcmp=$1
pixfmt=$2
fuzz=${3:-0.001}
ffmpeg $FLAGS $ENC_OPTS \
-lavfi "testsrc2=size=300x200:rate=1:duration=5,format=${pixfmt},${refcmp},metadata=print:file=-" \
-f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
}
refcmp_metadata_files(){
file1=$1
file2=$2
refcmp=$3
pixfmt=$4
fuzz=${5:-0.001}
ffmpeg -auto_conversion_filters $FLAGS -i $file1 $FLAGS -i $file2 $ENC_OPTS \
-lavfi "[0:v]format=${pixfmt}[v0];[1:v]format=${pixfmt}[v1];[v0][v1]${refcmp},metadata=print:file=-" \
-f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f ${base}/refcmp-metadata.awk -
}
refcmp_metadata_transcode(){
srcfile=$1
enc_opt=$2
enc_fmt=$3
enc_ext=$4
shift 4
encfile="${outdir}/${test}.${enc_ext}"
cleanfiles="$cleanfiles $encfile"
tsrcfile=$(target_path $srcfile)
tencfile=$(target_path $encfile)
ffmpeg $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS -y -f $enc_fmt $tencfile || return
refcmp_metadata_files $tencfile $tsrcfile "$@"
}
pixfmt_conversion(){
conversion="${test#pixfmt-}"
outdir="tests/data/pixfmt"
raw_dst="$outdir/$conversion.out.yuv"
file=${outdir}/${conversion}.yuv
cleanfiles="$cleanfiles $raw_dst $file"
run_avconv $DEC_OPTS -r 1 -f image2 -c:v pgmyuv -i $raw_src \
$ENC_OPTS -f rawvideo -t 1 -s 352x288 -pix_fmt $conversion $target_path/$raw_dst || return
do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $conversion -i $target_path/$raw_dst \
$ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p -color_range mpeg
}
video_filter(){
filters=$1
shift
label=${test#filter-}
raw_src="${target_path}/tests/vsynth1/%02d.pgm"
printf '%-20s' $label
ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \
$FLAGS $ENC_OPTS -vf "$filters" -vcodec rawvideo -frames:v 5 $* -f nut md5:
}
pixfmts(){
filter=${test#filter-pixfmts-}
filter=${filter%_*}
filter_args=$1
prefilter_chain=$2
nframes=${3:-1}
showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts${EXECSUF}"
scale_exclude_fmts=${outfile}_scale_exclude_fmts
scale_in_fmts=${outfile}_scale_in_fmts
scale_out_fmts=${outfile}_scale_out_fmts
in_fmts=${outfile}_in_fmts
# exclude pixel formats which are not supported as input
$showfiltfmts scale | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_in_fmts
$showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort >$scale_out_fmts
comm -12 $scale_in_fmts $scale_out_fmts >$scale_exclude_fmts
$showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort >$in_fmts
pix_fmts=$(comm -12 $scale_exclude_fmts $in_fmts)
outertest=$test
for pix_fmt in $pix_fmts; do
test=$pix_fmt
video_filter "${prefilter_chain}scale,format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v $nframes || return
done
rm $in_fmts $scale_in_fmts $scale_out_fmts $scale_exclude_fmts
test=$outertest
}
gapless(){
sample=$(target_path $1)
extra_args=$2
decfile1="${outdir}/${test}.out-1"
decfile2="${outdir}/${test}.out-2"
decfile3="${outdir}/${test}.out-3"
cleanfiles="$cleanfiles $decfile1 $decfile2 $decfile3"
# test packet data
ffmpeg -auto_conversion_filters $extra_args -i "$sample" \
-bitexact -c:a copy -f framecrc -y $(target_path $decfile1) || return
do_md5sum $decfile1
# test decoded (and cut) data
ffmpeg -auto_conversion_filters $extra_args -i "$sample" -bitexact -f wav md5: || return
# the same as above again, with seeking to the start
ffmpeg -auto_conversion_filters $extra_args -ss 0 -seek_timestamp 1 -i "$sample" \
-bitexact -c:a copy -f framecrc -y $(target_path $decfile2) || return
do_md5sum $decfile2
ffmpeg -auto_conversion_filters $extra_args -ss 0 -seek_timestamp 1 -i "$sample" \
-bitexact -f wav md5: || return
# test packet data, with seeking to a specific position
ffmpeg -auto_conversion_filters $extra_args -ss 5 -seek_timestamp 1 -i "$sample" \
-bitexact -c:a copy -f framecrc -y $(target_path $decfile3) || return
do_md5sum $decfile3
}
gaplessenc(){
sample=$(target_path $1)
format=$2
codec=$3
file1="${outdir}/${test}.out-1"
cleanfiles="$cleanfiles $file1"
# test data after reencoding
ffmpeg -i "$sample" -bitexact -map 0:a -c:a $codec -af aresample \
-f $format -y "$(target_path "$file1")" || return
probegaplessinfo "$(target_path "$file1")"
}
audio_match(){
sample=$(target_path $1)
trefile=$2
extra_args=$3
decfile="${outdir}/${test}.wav"
cleanfiles="$cleanfiles $decfile"
ffmpeg -auto_conversion_filters -i "$sample" -bitexact $extra_args -y $(target_path $decfile) || return
tests/audiomatch${HOSTEXECSUF} $decfile $trefile
}
concat(){
template=$1
sample=$2
mode=$3
extra_args=$4
concatfile="${outdir}/${test}.ffconcat"
packetfile="${outdir}/${test}.ffprobe"
cleanfiles="$concatfile $packetfile"
awk "{gsub(/%SRCFILE%/, \"$sample\"); print}" $template > $concatfile
if [ "$mode" = "md5" ]; then
run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_streams -show_packets -safe 0 $extra_args $(target_path $concatfile) | tr -d '\r' > $packetfile
do_md5sum $packetfile
else
run ffprobe${PROGSUF}${EXECSUF} -bitexact -show_streams -show_packets -of compact=p=0:nk=1 -safe 0 $extra_args $(target_path $concatfile)
fi
}
venc_data(){
file=$1
stream=$2
frames=$3
run tools/venc_data_dump${EXECSUF} ${file} ${stream} ${frames} ${threads} ${thread_type}
}
null(){
:
}
# Disable globbing: command arguments may contain globbing characters and
# must be kept verbatim
set -f
exec 3>&2
eval $command >"$outfile" 2>$errfile
err=$?
if [ $err -gt 128 ]; then
sig=$(kill -l $err 2>/dev/null)
test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
fi
if test -e "$ref" || test $cmp = "oneline" || test $cmp = "null" || test $cmp = "grep" ; then
case $cmp in
diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
rawdiff)diff -u "$ref" "$outfile" >$cmpfile ;;
oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
stddev) stddev "$ref" "$outfile" >$cmpfile ;;
oneline)oneline "$ref" "$outfile" >$cmpfile ;;
grep) grep "$ref" "$errfile" >$cmpfile ;;
null) cat "$outfile" >$cmpfile ;;
esac
cmperr=$?
test $err = 0 && err=$cmperr
if [ "$report_type" = "ignore" ]; then
test $err = 0 || echo "IGNORE\t${test}" && err=0 && unset sig
else
test $err = 0 || cat $cmpfile
fi
else
echo "reference file '$ref' not found"
err=1
fi
if [ $err -eq 0 ] && test $report_type = "standard" ; then
unset cmpo erro
else
echo "threads=$threads" >> "$errfile"
cmpo="$($base64 <$cmpfile)"
erro="$($base64 <$errfile)"
fi
echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
if test $err != 0 && test $gen != "no" && test "${ref#tests/data/}" = "$ref" ; then
echo "GEN $ref"
cp -f "$outfile" "$ref"
err=$?
fi
if test $err = 0; then
if test $keep -lt 2; then
rm -f $outfile $errfile $cmpfile $cleanfiles
fi
elif test $gen = "no"; then
echo "Test $test failed. Look at $errfile for details."
test "${V:-0}" -gt 0 && cat $errfile
else
echo "Updating reference failed, possibly no output file was generated."
fi
exit $err
+31
View File
@@ -0,0 +1,31 @@
# seems fixed in newer versions
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=577135
{
zlib-inflate
Memcheck:Cond
fun:inflateReset2
fun:inflateInit2_
}
# libc overreads on purpose
# http://sourceware.org/bugzilla/show_bug.cgi?id=12424
{
eval-strtod
Memcheck:Addr8
fun:__GI___strncasecmp_l
fun:____strtod_l_internal
fun:av_strtod
}
{
eval-strtod
Memcheck:Value8
fun:__GI___strncasecmp_l
fun:____strtod_l_internal
fun:av_strtod
}
{
eval-strtod
Memcheck:Cond
fun:__GI___strncasecmp_l
fun:____strtod_l_internal
fun:av_strtod
}
+135
View File
@@ -0,0 +1,135 @@
#!/bin/sh
config=$1
die(){
echo "$@"
exit 1
}
test -r "$config" || die "usage: fate.sh <config>"
workdir=$(cd $(dirname $config) && pwd)
make=make
tar='tar c'
. "$config"
test -n "$slot" || die "slot not specified"
test -n "$repo" || die "repo not specified"
test -d "$samples" || die "samples location not specified"
: ${branch:=master}
lock(){
lock=$1/fate.lock
(set -C; exec >$lock) 2>/dev/null || return
trap 'rm $lock' EXIT
}
checkout(){
case "$repo" in
file:*|/*) src="${repo#file:}" ;;
git:*|https:*) git clone --quiet --branch "$branch" "$repo" "$src" ;;
esac
}
update()(
cd ${src} || return
case "$repo" in
git:*|https:*) git fetch --quiet --force && git reset --quiet --hard "origin/$branch" ;;
esac
)
configure()(
cd ${build} || return
${shell} ${src}/configure \
--prefix="${inst}" \
--samples="${samples}" \
--enable-gpl \
--enable-memory-poisoning \
${ignore_tests:+--ignore-tests="$ignore_tests"} \
${arch:+--arch=$arch} \
${cpu:+--cpu="$cpu"} \
${toolchain:+--toolchain="$toolchain"} \
${cross_prefix:+--cross-prefix="$cross_prefix"} \
${as:+--as="$as"} \
${cc:+--cc="$cc"} \
${ld:+--ld="$ld"} \
${target_os:+--target-os="$target_os"} \
${sysroot:+--sysroot="$sysroot"} \
${target_exec:+--target-exec="$target_exec"} \
${target_path:+--target-path="$target_path"} \
${target_samples:+--target-samples="$target_samples"} \
${extra_cflags:+--extra-cflags="$extra_cflags"} \
${extra_ldflags:+--extra-ldflags="$extra_ldflags"} \
${extra_libs:+--extra-libs="$extra_libs"} \
${extra_conf}
)
compile()(
cd ${build} || return
${make} ${makeopts} && ${make} install
)
fate()(
test "$build_only" = "yes" && return
cd ${build} || return
if [ -n "${fate_environments}" ]; then
ret=0
for e in ${fate_environments}; do
eval "curenv=\${${e}_env}"
echo Testing environment ${e}: ${curenv}
${make} ${makeopts_fate-${makeopts}} -k ${fate_targets} FATE_SUFFIX=_${e} ${curenv}
cur_ret=$?
test $cur_ret != 0 && ret=$cur_ret
done
return $ret
else
${make} ${makeopts_fate-${makeopts}} -k ${fate_targets}
fi
)
clean(){
rm -rf ${build} ${inst}
}
report(){
date=$(date -u +%Y%m%d%H%M%S)
echo "fate:1:${date}:${slot}:${version}:$1:$2:${branch}:${comment}" >report
cat ${build}/ffbuild/config.fate >>report
cat ${build}/tests/data/fate/*.rep >>report 2>/dev/null || for i in ${build}/tests/data/fate/*.rep ; do cat "$i" >>report 2>/dev/null; done
test -n "$fate_recv" && $tar report *.log | gzip | $fate_recv
}
fail(){
report "$@"
clean
exit
}
mkdir -p ${workdir} || die "Error creating ${workdir}"
lock ${workdir} || die "${workdir} locked"
cd ${workdir} || die "cd ${workdir} failed"
src=${workdir}/src
: ${build:=${workdir}/build}
: ${inst:=${workdir}/install}
: ${fate_targets:=fate}
test -d "$src" && update || checkout || die "Error fetching source"
cd ${workdir}
version=$(${src}/ffbuild/version.sh ${src})
test "$version" = "$(cat version-$slot 2>/dev/null)" && exit 0
echo ${version} >version-$slot
rm -rf "${build}" *.log
mkdir -p ${build}
configure >configure.log 2>&1 || fail 3 "error configuring"
compile >compile.log 2>&1 || fail 2 "error compiling"
fate >test.log 2>&1 || fail 1 "error testing"
report 0 success
clean
+271
View File
@@ -0,0 +1,271 @@
FATE_AAC += fate-aac-al04_44
fate-aac-al04_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/al04_44.mp4
fate-aac-al04_44: REF = $(SAMPLES)/aac/al04_44.s16
FATE_AAC += fate-aac-al04sf_48
fate-aac-al04sf_48: CMD = pcm -i $(TARGET_SAMPLES)/aac/al04sf_48.mp4
fate-aac-al04sf_48: REF = $(SAMPLES)/aac/al04sf_48.s16
FATE_AAC += fate-aac-al05_44
fate-aac-al05_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/al05_44.mp4
fate-aac-al05_44: REF = $(SAMPLES)/aac/al05_44.s16
FATE_AAC += fate-aac-al06_44
fate-aac-al06_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/al06_44.mp4
fate-aac-al06_44: REF = $(SAMPLES)/aac/al06_44_reorder.s16
FATE_AAC += fate-aac-al07_96
fate-aac-al07_96: CMD = pcm -i $(TARGET_SAMPLES)/aac/al07_96.mp4
fate-aac-al07_96: REF = $(SAMPLES)/aac/al07_96_reorder.s16
FATE_AAC += fate-aac-al15_44
fate-aac-al15_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/al15_44.mp4
fate-aac-al15_44: REF = $(SAMPLES)/aac/al15_44_reorder.s16
FATE_AAC += fate-aac-al17_44
fate-aac-al17_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/al17_44.mp4
fate-aac-al17_44: REF = $(SAMPLES)/aac/al17_44.s16
FATE_AAC += fate-aac-al18_44
fate-aac-al18_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/al18_44.mp4
fate-aac-al18_44: REF = $(SAMPLES)/aac/al18_44.s16
FATE_AAC += fate-aac-am00_88
fate-aac-am00_88: CMD = pcm -i $(TARGET_SAMPLES)/aac/am00_88.mp4
fate-aac-am00_88: REF = $(SAMPLES)/aac/am00_88.s16
FATE_AAC += fate-aac-am05_44
fate-aac-am05_44: CMD = pcm -i $(TARGET_SAMPLES)/aac/am05_44.mp4
fate-aac-am05_44: REF = $(SAMPLES)/aac/am05_44_reorder.s16
FATE_AAC += fate-aac-al_sbr_hq_cm_48_2
fate-aac-al_sbr_hq_cm_48_2: CMD = pcm -i $(TARGET_SAMPLES)/aac/al_sbr_cm_48_2.mp4
fate-aac-al_sbr_hq_cm_48_2: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_2.s16
FATE_AAC += fate-aac-al_sbr_hq_cm_48_5.1
fate-aac-al_sbr_hq_cm_48_5.1: CMD = pcm -i $(TARGET_SAMPLES)/aac/al_sbr_cm_48_5.1.mp4
fate-aac-al_sbr_hq_cm_48_5.1: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_5.1_reorder.s16
FATE_AAC += fate-aac-al_sbr_hq_sr_48_2_fsaac48
fate-aac-al_sbr_hq_sr_48_2_fsaac48: CMD = pcm -i $(TARGET_SAMPLES)/aac/al_sbr_sr_48_2_fsaac48.mp4
fate-aac-al_sbr_hq_sr_48_2_fsaac48: REF = $(SAMPLES)/aac/al_sbr_hq_sr_48_2_fsaac48.s16
FATE_AAC += fate-aac-al_sbr_ps_04_ur
fate-aac-al_sbr_ps_04_ur: CMD = pcm -i $(TARGET_SAMPLES)/aac/al_sbr_ps_04_new.mp4
fate-aac-al_sbr_ps_04_ur: REF = $(SAMPLES)/aac/al_sbr_ps_04_ur.s16
FATE_AAC += fate-aac-al_sbr_ps_06_ur
fate-aac-al_sbr_ps_06_ur: CMD = pcm -i $(TARGET_SAMPLES)/aac/al_sbr_ps_06_new.mp4
fate-aac-al_sbr_ps_06_ur: REF = $(SAMPLES)/aac/al_sbr_ps_06_ur.s16
FATE_AAC += fate-aac-ap05_48
fate-aac-ap05_48: CMD = pcm -i $(TARGET_SAMPLES)/aac/ap05_48.mp4
fate-aac-ap05_48: REF = $(SAMPLES)/aac/ap05_48.s16
FATE_AAC += fate-aac-fd_2_c1_ms_0x01
fate-aac-fd_2_c1_ms_0x01: CMD = pcm -i $(TARGET_SAMPLES)/aac/Fd_2_c1_Ms_0x01.mp4
fate-aac-fd_2_c1_ms_0x01: REF = $(SAMPLES)/aac/Fd_2_c1_Ms_0x01.s16
FATE_AAC += fate-aac-fd_2_c1_ms_0x04
fate-aac-fd_2_c1_ms_0x04: CMD = pcm -i $(TARGET_SAMPLES)/aac/Fd_2_c1_Ms_0x04.mp4
fate-aac-fd_2_c1_ms_0x04: REF = $(SAMPLES)/aac/Fd_2_c1_Ms_0x04.s16
FATE_AAC += fate-aac-er_ad6000np_44_ep0
fate-aac-er_ad6000np_44_ep0: CMD = pcm -i $(TARGET_SAMPLES)/aac/er_ad6000np_44_ep0.mp4
fate-aac-er_ad6000np_44_ep0: REF = $(SAMPLES)/aac/er_ad6000np_44.s16
FATE_AAC += fate-aac-er_eld1001np_44_ep0
fate-aac-er_eld1001np_44_ep0: CMD = pcm -i $(TARGET_SAMPLES)/aac/er_eld1001np_44_ep0.mp4
fate-aac-er_eld1001np_44_ep0: REF = $(SAMPLES)/aac/er_eld1001np_44.s16
FATE_AAC += fate-aac-er_eld2000np_48_ep0
fate-aac-er_eld2000np_48_ep0: CMD = pcm -i $(TARGET_SAMPLES)/aac/er_eld2000np_48_ep0.mp4
fate-aac-er_eld2000np_48_ep0: REF = $(SAMPLES)/aac/er_eld2000np_48_ep0.s16
FATE_AAC += fate-aac-er_eld2100np_48_ep0
fate-aac-er_eld2100np_48_ep0: CMD = pcm -i $(TARGET_SAMPLES)/aac/er_eld2100np_48_ep0.mp4
fate-aac-er_eld2100np_48_ep0: REF = $(SAMPLES)/aac/er_eld2100np_48.s16
FATE_AAC_FIXED += fate-aac-fixed-al04_44
fate-aac-fixed-al04_44: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al04_44.mp4
fate-aac-fixed-al04_44: REF = $(SAMPLES)/aac/al04_44.s16
FATE_AAC_FIXED += fate-aac-fixed-al05_44
fate-aac-fixed-al05_44: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al05_44.mp4
fate-aac-fixed-al05_44: REF = $(SAMPLES)/aac/al05_44.s16
FATE_AAC_FIXED += fate-aac-fixed-al06_44
fate-aac-fixed-al06_44: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al06_44.mp4
fate-aac-fixed-al06_44: REF = $(SAMPLES)/aac/al06_44_reorder.s16
FATE_AAC_FIXED += fate-aac-fixed-al15_44
fate-aac-fixed-al15_44: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al15_44.mp4
fate-aac-fixed-al15_44: REF = $(SAMPLES)/aac/al15_44_reorder.s16
FATE_AAC_FIXED += fate-aac-fixed-al17_44
fate-aac-fixed-al17_44: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al17_44.mp4
fate-aac-fixed-al17_44: REF = $(SAMPLES)/aac/al17_44.s16
FATE_AAC_FIXED += fate-aac-fixed-al18_44
fate-aac-fixed-al18_44: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al18_44.mp4
fate-aac-fixed-al18_44: REF = $(SAMPLES)/aac/al18_44.s16
FATE_AAC_FIXED += fate-aac-fixed-al_sbr_hq_cm_48_2
fate-aac-fixed-al_sbr_hq_cm_48_2: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al_sbr_cm_48_2.mp4
fate-aac-fixed-al_sbr_hq_cm_48_2: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_2.s16
FATE_AAC_FIXED += fate-aac-fixed-al_sbr_hq_cm_48_5.1
fate-aac-fixed-al_sbr_hq_cm_48_5.1: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al_sbr_cm_48_5.1.mp4
fate-aac-fixed-al_sbr_hq_cm_48_5.1: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_5.1_reorder.s16
FATE_AAC_FIXED += fate-aac-fixed-al_sbr_hq_sr_48_2_fsaac48
fate-aac-fixed-al_sbr_hq_sr_48_2_fsaac48: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/al_sbr_sr_48_2_fsaac48.mp4
fate-aac-fixed-al_sbr_hq_sr_48_2_fsaac48: REF = $(SAMPLES)/aac/al_sbr_hq_sr_48_2_fsaac48.s16
#FATE_AAC_FIXED += fate-aac-fixed-al_sbr_ps_06_ur
#fate-aac-fixed-al_sbr_ps_06_ur: CMD = pcm -c aac_fixed-i $(TARGET_SAMPLES)/aac/al_sbr_ps_06_new.mp4
#fate-aac-fixed-al_sbr_ps_06_ur: REF = $(SAMPLES)/aac/al_sbr_ps_06_ur.s16
FATE_AAC_FIXED += fate-aac-fixed-ap05_48
fate-aac-fixed-ap05_48: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/ap05_48.mp4
fate-aac-fixed-ap05_48: REF = $(SAMPLES)/aac/ap05_48.s16
FATE_AAC_FIXED += fate-aac-fixed-er_ad6000np_44_ep0
fate-aac-fixed-er_ad6000np_44_ep0: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/er_ad6000np_44_ep0.mp4
fate-aac-fixed-er_ad6000np_44_ep0: REF = $(SAMPLES)/aac/er_ad6000np_44.s16
FATE_AAC_FIXED += fate-aac-fixed-er_eld1001np_44_ep0
fate-aac-fixed-er_eld1001np_44_ep0: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/er_eld1001np_44_ep0.mp4
fate-aac-fixed-er_eld1001np_44_ep0: REF = $(SAMPLES)/aac/er_eld1001np_44.s16
FATE_AAC_FIXED += fate-aac-fixed-er_eld2000np_48_ep0
fate-aac-fixed-er_eld2000np_48_ep0: CMD = pcm -c aac_fixed -i $(TARGET_SAMPLES)/aac/er_eld2000np_48_ep0.mp4
fate-aac-fixed-er_eld2000np_48_ep0: REF = $(SAMPLES)/aac/er_eld2000np_48_ep0.s16
fate-aac-ct%: CMD = pcm -i $(TARGET_SAMPLES)/aac/CT_DecoderCheck/$(@:fate-aac-ct-%=%)
fate-aac-ct%: REF = $(SAMPLES)/aac/CT_DecoderCheck/aacPlusv2.wav
FATE_AAC_CT_RAW = fate-aac-ct-sbr_i-ps_i.aac
FATE_AAC_CT = sbr_bc-ps_i.3gp \
sbr_bic-ps_i.3gp \
sbr_bc-ps_bc.mp4 \
sbr_bc-ps_i.mp4 \
sbr_i-ps_bic.mp4 \
sbr_i-ps_i.mp4
FATE_AAC += $(FATE_AAC_CT:%=fate-aac-ct-%)
FATE_AAC_ENCODE += fate-aac-aref-encode
fate-aac-aref-encode: ./tests/data/asynth-44100-2.wav
fate-aac-aref-encode: CMD = enc_dec_pcm adts wav s16le $(REF) -c:a aac -aac_coder fast -aac_is 0 -aac_pns 0 -aac_ms 0 -aac_tns 0 -b:a 512k -fflags +bitexact -flags +bitexact
fate-aac-aref-encode: CMP = stddev
fate-aac-aref-encode: REF = ./tests/data/asynth-44100-2.wav
fate-aac-aref-encode: CMP_SHIFT = -4096
fate-aac-aref-encode: CMP_TARGET = 596
fate-aac-aref-encode: SIZE_TOLERANCE = 2464
fate-aac-aref-encode: FUZZ = 89
FATE_AAC_ENCODE += fate-aac-ln-encode
fate-aac-ln-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -c:a aac -aac_coder fast -aac_is 0 -aac_pns 0 -aac_ms 0 -aac_tns 0 -b:a 512k -fflags +bitexact -flags +bitexact
fate-aac-ln-encode: CMP = stddev
fate-aac-ln-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
fate-aac-ln-encode: CMP_SHIFT = -4096
fate-aac-ln-encode: CMP_TARGET = 72
fate-aac-ln-encode: SIZE_TOLERANCE = 3560
fate-aac-ln-encode: FUZZ = 30
FATE_AAC_ENCODE += fate-aac-ln-encode-128k
fate-aac-ln-encode-128k: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -c:a aac -aac_coder fast -aac_is 0 -aac_pns 0 -aac_ms 0 -aac_tns 0 -b:a 128k -cutoff 22050 -fflags +bitexact -flags +bitexact
fate-aac-ln-encode-128k: CMP = stddev
fate-aac-ln-encode-128k: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
fate-aac-ln-encode-128k: CMP_SHIFT = -4096
fate-aac-ln-encode-128k: CMP_TARGET = 622
fate-aac-ln-encode-128k: SIZE_TOLERANCE = 3560
fate-aac-ln-encode-128k: FUZZ = 10
FATE_AAC_ENCODE += fate-aac-pns-encode
fate-aac-pns-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -c:a aac -aac_coder fast -aac_pns 1 -aac_is 0 -aac_ms 0 -aac_tns 0 -b:a 128k -cutoff 22050 -fflags +bitexact -flags +bitexact
fate-aac-pns-encode: CMP = stddev
fate-aac-pns-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
fate-aac-pns-encode: CMP_SHIFT = -4096
fate-aac-pns-encode: CMP_TARGET = 655
fate-aac-pns-encode: SIZE_TOLERANCE = 3560
fate-aac-pns-encode: FUZZ = 74
FATE_AAC_ENCODE += fate-aac-tns-encode
fate-aac-tns-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -c:a aac -aac_coder fast -aac_tns 1 -aac_is 0 -aac_pns 0 -aac_ms 0 -b:a 128k -cutoff 22050 -fflags +bitexact -flags +bitexact
fate-aac-tns-encode: CMP = stddev
fate-aac-tns-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
fate-aac-tns-encode: CMP_SHIFT = -4096
fate-aac-tns-encode: CMP_TARGET = 637
fate-aac-tns-encode: FUZZ = 7
fate-aac-tns-encode: SIZE_TOLERANCE = 3560
FATE_AAC_ENCODE += fate-aac-is-encode
fate-aac-is-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -c:a aac -aac_coder fast -aac_pns 0 -aac_is 1 -aac_ms 0 -b:a 128k -aac_tns 0 -cutoff 22050 -fflags +bitexact -flags +bitexact
fate-aac-is-encode: CMP = stddev
fate-aac-is-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
fate-aac-is-encode: CMP_SHIFT = -4096
fate-aac-is-encode: CMP_TARGET = 514
fate-aac-is-encode: SIZE_TOLERANCE = 3560
fate-aac-is-encode: FUZZ = 10
FATE_AAC_ENCODE += fate-aac-ms-encode
fate-aac-ms-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -c:a aac -aac_coder fast -aac_pns 0 -aac_is 0 -aac_ms 1 -aac_tns 0 -b:a 128k -cutoff 22050 -fflags +bitexact -flags +bitexact
fate-aac-ms-encode: CMP = stddev
fate-aac-ms-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
fate-aac-ms-encode: CMP_SHIFT = -4096
fate-aac-ms-encode: CMP_TARGET = 558
fate-aac-ms-encode: SIZE_TOLERANCE = 3560
fate-aac-ms-encode: FUZZ = 15
#Ticket1784
FATE_AAC_ENCODE += fate-aac-yoraw-encode
fate-aac-yoraw-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/yo.raw-short.wav -c:a aac -aac_coder fast -fflags +bitexact -flags +bitexact
fate-aac-yoraw-encode: CMP = stddev
fate-aac-yoraw-encode: REF = $(SAMPLES)/audio-reference/yo.raw-short.wav
fate-aac-yoraw-encode: CMP_SHIFT = -12288
fate-aac-yoraw-encode: CMP_TARGET = 226
fate-aac-yoraw-encode: SIZE_TOLERANCE = 3560
fate-aac-yoraw-encode: FUZZ = 17
FATE_AAC_ENCODE += fate-aac-pred-encode
fate-aac-pred-encode: CMD = enc_dec_pcm adts wav s16le $(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav -profile:a aac_main -c:a aac -aac_coder fast -aac_is 0 -aac_pns 0 -aac_ms 0 -aac_tns 0 -b:a 128k -cutoff 22050 -fflags +bitexact -flags +bitexact
fate-aac-pred-encode: CMP = stddev
fate-aac-pred-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
fate-aac-pred-encode: CMP_SHIFT = -4096
fate-aac-pred-encode: CMP_TARGET = 662
fate-aac-pred-encode: FUZZ = 12
fate-aac-pred-encode: SIZE_TOLERANCE = 3560
FATE_AAC_LATM += fate-aac-latm_000000001180bc60
fate-aac-latm_000000001180bc60: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_000000001180bc60.mpg
fate-aac-latm_000000001180bc60: REF = $(SAMPLES)/aac/latm_000000001180bc60.s16
FATE_AAC_LATM += fate-aac-latm_stereo_to_51
fate-aac-latm_stereo_to_51: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_stereo_to_51.ts -channel_layout 5.1
fate-aac-latm_stereo_to_51: REF = $(SAMPLES)/aac/latm_stereo_to_51_ref.s16
fate-aac-autobsf-adtstoasc: CMD = transcode "aac" $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \
matroska "-c:a copy" "-c:a copy"
FATE_AAC-$(call DEMDEC, AAC, AAC, ARESAMPLE_FILTER) += $(FATE_AAC_CT_RAW)
FATE_AAC-$(call DEMDEC, MOV, AAC, ARESAMPLE_FILTER) += $(FATE_AAC)
FATE_AAC_LATM-$(call DEMDEC, MPEGTS, AAC_LATM, ARESAMPLE_FILTER) += $(FATE_AAC_LATM)
FATE_AAC-$(call DEMDEC, AAC, AAC_FIXED, ARESAMPLE_FILTER) += $(FATE_AAC_FIXED)
FATE_AAC_ALL = $(FATE_AAC-yes) $(FATE_AAC_LATM-yes) $(FATE_AAC_FIXED-yes)
$(FATE_AAC_ALL): CMP = oneoff
$(FATE_AAC_ALL): FUZZ = 2
FATE_AAC_ENCODE-$(call ENCMUX, AAC, ADTS, ARESAMPLE_FILTER) += $(FATE_AAC_ENCODE)
FATE_AAC_BSF-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER) += fate-aac-autobsf-adtstoasc
FATE_SAMPLES_FFMPEG += $(FATE_AAC_ALL) $(FATE_AAC_ENCODE-yes) $(FATE_AAC_BSF-yes)
fate-aac: $(FATE_AAC_ALL) $(FATE_AAC_ENCODE) $(FATE_AAC_BSF-yes)
fate-aac-latm: $(FATE_AAC_LATM-yes)
+101
View File
@@ -0,0 +1,101 @@
FATE_AC3 += fate-ac3-2.0
fate-ac3-2.0: CMD = pcm -i $(TARGET_SAMPLES)/ac3/monsters_inc_2.0_192_small.ac3
fate-ac3-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small_v2.pcm
FATE_AC3 += fate-ac3-4.0
fate-ac3-4.0: CMD = pcm -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
fate-ac3-4.0: REF = $(SAMPLES)/ac3/millers_crossing_4.0_v2.pcm
#downmix 4.0 -> front channel
FATE_AC3 += fate-ac3-4.0-downmix-mono
fate-ac3-4.0-downmix-mono: CMD = pcm -downmix mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
fate-ac3-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm
FATE_AC3 += fate-ac3-4.0-downmix-stereo
fate-ac3-4.0-downmix-stereo: CMD = pcm -downmix stereo -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
fate-ac3-4.0-downmix-stereo: REF = $(SAMPLES)/ac3/millers_crossing_4.0_stereo_v2.pcm
FATE_AC3 += fate-ac3-5.1
fate-ac3-5.1: CMD = pcm -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
fate-ac3-5.1: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_v2.pcm
FATE_AC3 += fate-ac3-5.1-downmix-mono
fate-ac3-5.1-downmix-mono: CMD = pcm -downmix FC -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
fate-ac3-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm
FATE_AC3 += fate-ac3-5.1-downmix-stereo
fate-ac3-5.1-downmix-stereo: CMD = pcm -downmix stereo -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
fate-ac3-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm
FATE_AC3 += fate-ac3-fixed-2.0
fate-ac3-fixed-2.0: CMD = pcm -c ac3_fixed -i $(TARGET_SAMPLES)/ac3/monsters_inc_2.0_192_small.ac3
fate-ac3-fixed-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small_v2.pcm
FATE_AC3 += fate-ac3-fixed-4.0-downmix-mono
fate-ac3-fixed-4.0-downmix-mono: CMD = pcm -c ac3_fixed -downmix mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
fate-ac3-fixed-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm
FATE_AC3 += fate-ac3-fixed-5.1-downmix-mono
fate-ac3-fixed-5.1-downmix-mono: CMD = pcm -c ac3_fixed -downmix mono -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
fate-ac3-fixed-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm
FATE_AC3 += fate-ac3-fixed-5.1-downmix-stereo
fate-ac3-fixed-5.1-downmix-stereo: CMD = pcm -c ac3_fixed -downmix stereo -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
fate-ac3-fixed-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm
FATE_EAC3 += fate-eac3-1
fate-eac3-1: CMD = pcm -i $(TARGET_SAMPLES)/eac3/csi_miami_5.1_256_spx_small.eac3
fate-eac3-1: REF = $(SAMPLES)/eac3/csi_miami_5.1_256_spx_small_v2.pcm
FATE_EAC3 += fate-eac3-2
fate-eac3-2: CMD = pcm -i $(TARGET_SAMPLES)/eac3/csi_miami_stereo_128_spx_small.eac3
fate-eac3-2: REF = $(SAMPLES)/eac3/csi_miami_stereo_128_spx_small_v2.pcm
FATE_EAC3 += fate-eac3-3
fate-eac3-3: CMD = pcm -i $(TARGET_SAMPLES)/eac3/matrix2_commentary1_stereo_192_small.eac3
fate-eac3-3: REF = $(SAMPLES)/eac3/matrix2_commentary1_stereo_192_small_v2.pcm
FATE_EAC3 += fate-eac3-4
fate-eac3-4: CMD = pcm -i $(TARGET_SAMPLES)/eac3/serenity_english_5.1_1536_small.eac3
fate-eac3-4: REF = $(SAMPLES)/eac3/serenity_english_5.1_1536_small_v2.pcm
FATE_EAC3 += fate-eac3-5
fate-eac3-5: CMD = pcm -i $(TARGET_SAMPLES)/eac3/the_great_wall_7.1.eac3
fate-eac3-5: REF = $(SAMPLES)/eac3/the_great_wall_7.1.pcm
$(FATE_AC3) $(FATE_EAC3): CMP = oneoff
FATE_AC3-$(call DEMDEC, AC3, AC3, ARESAMPLE_FILTER) += $(FATE_AC3)
FATE_EAC3-$(call DEMDEC, EAC3, EAC3, ARESAMPLE_FILTER) += $(FATE_EAC3)
FATE_AC3-$(call ENCDEC, AC3, AC3, ARESAMPLE_FILTER) += fate-ac3-encode
fate-ac3-encode: CMD = enc_dec_pcm ac3 wav s16le $(subst $(SAMPLES),$(TARGET_SAMPLES),$(REF)) -c:a ac3 -b:a 128k
fate-ac3-encode: CMP_SHIFT = -1024
fate-ac3-encode: CMP_TARGET = 404.53
fate-ac3-encode: SIZE_TOLERANCE = 488
FATE_EAC3-$(call ENCDEC, EAC3, EAC3, ARESAMPLE_FILTER) += fate-eac3-encode
fate-eac3-encode: CMD = enc_dec_pcm eac3 wav s16le $(subst $(SAMPLES),$(TARGET_SAMPLES),$(REF)) -c:a eac3 -b:a 128k
fate-eac3-encode: CMP_SHIFT = -1024
fate-eac3-encode: CMP_TARGET = 516.94
fate-eac3-encode: SIZE_TOLERANCE = 488
fate-ac3-encode fate-eac3-encode: CMP = stddev
fate-ac3-encode fate-eac3-encode: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
FATE_AC3-$(call ENCMUX, AC3_FIXED, AC3, ARESAMPLE_FILTER) += fate-ac3-fixed-encode
fate-ac3-fixed-encode: tests/data/asynth-44100-2.wav
fate-ac3-fixed-encode: SRC = $(TARGET_PATH)/tests/data/asynth-44100-2.wav
fate-ac3-fixed-encode: CMD = md5 -i $(SRC) -c ac3_fixed -ab 128k -f ac3 -flags +bitexact -af aresample
fate-ac3-fixed-encode: CMP = oneline
fate-ac3-fixed-encode: REF = e9d78bca187b4bbafc4512bcea8efd3e
FATE_EAC3-$(call ALLYES, EAC3_DEMUXER EAC3_MUXER EAC3_CORE_BSF) += fate-eac3-core-bsf
fate-eac3-core-bsf: CMD = md5pipe -i $(TARGET_SAMPLES)/eac3/the_great_wall_7.1.eac3 -c:a copy -bsf:a eac3_core -fflags +bitexact -f eac3
fate-eac3-core-bsf: CMP = oneline
fate-eac3-core-bsf: REF = b704bf851e99b7442e9bed368b60e6ca
FATE_SAMPLES_AVCONV += $(FATE_AC3-yes) $(FATE_EAC3-yes)
fate-ac3: $(FATE_AC3-yes) $(FATE_EAC3-yes)
+181
View File
@@ -0,0 +1,181 @@
fate-acodec-%: CODEC = $(@:fate-acodec-%=%)
fate-acodec-%: SRC = tests/data/asynth-44100-2.wav
fate-acodec-%: CMD = enc_dec wav $(SRC) $(FMT) "-b:a 128k -c $(CODEC) $(ENCOPTS)" wav "-c pcm_s16le $(DECOPTS)"
fate-acodec-%: CMP_UNIT = 2
fate-acodec-%: REF = $(SRC_PATH)/tests/ref/acodec/$(@:fate-acodec-%=%)
FATE_ACODEC_PCM-$(call ENCDEC, PCM_ALAW, WAV) += alaw
FATE_ACODEC_PCM-$(call ENCDEC, PCM_MULAW, WAV) += mulaw
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S8, MOV) += s8
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_U8, WAV) += u8
FATE_ACODEC_PCM-$(call ENCDEC, PCM_S16BE, MOV) += s16be
FATE_ACODEC_PCM-$(call ENCDEC, PCM_S16LE, WAV) += s16le
FATE_ACODEC_PCM-$(call ENCDEC, PCM_U16BE, NUT) += u16be
FATE_ACODEC_PCM-$(call ENCDEC, PCM_U16LE, NUT) += u16le
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S24BE, MOV) += s24be
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S24LE, WAV) += s24le
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_U24BE, NUT) += u24be
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_U24LE, NUT) += u24le
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S32BE, MOV) += s32be
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S32LE, WAV) += s32le
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_U32BE, NUT) += u32be
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_U32LE, NUT) += u32le
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_F32BE, AU) += f32be
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_F32LE, WAV) += f32le
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_F64BE, AU) += f64be
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_F64LE, WAV) += f64le
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S8_PLANAR, NUT) += s8_planar
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S16BE_PLANAR, NUT) += s16be_planar
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S16LE_PLANAR, NUT) += s16le_planar
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S24LE_PLANAR, NUT) += s24le_planar
FATE_ACODEC_PCM_RESAMPLE-$(call ENCDEC, PCM_S32LE_PLANAR, NUT) += s32le_planar
FATE_ACODEC_PCM-$(CONFIG_ARESAMPLE_FILTER) += $(FATE_ACODEC_PCM_RESAMPLE-yes)
FATE_ACODEC_PCM := $(if $(call ENCDEC, PCM_S16LE, WAV), $(FATE_ACODEC_PCM-yes))
FATE_ACODEC_PCM := $(FATE_ACODEC_PCM:%=fate-acodec-pcm-%)
FATE_ACODEC += $(FATE_ACODEC_PCM)
fate-acodec-pcm: $(FATE_ACODEC_PCM)
fate-acodec-pcm-%: FMT = wav
fate-acodec-pcm-%_planar: FMT = nut
fate-acodec-pcm-%: CODEC = pcm_$(@:fate-acodec-pcm-%=%)
fate-acodec-pcm-s8: FMT = mov
fate-acodec-pcm-s%be: FMT = mov
fate-acodec-pcm-u%be: FMT = nut
fate-acodec-pcm-u%le: FMT = nut
fate-acodec-pcm-f%be: FMT = au
FATE_ACODEC_ADPCM_RESAMPLE-$(call ENCDEC, ADPCM_ADX, ADX) += adx
FATE_ACODEC_ADPCM_RESAMPLE-$(call ENCDEC, ADPCM_ARGO, ARGO_ASF) += argo
FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_APM, APM) += ima_apm
FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_ALP, ALP) += ima_alp
FATE_ACODEC_ADPCM_RESAMPLE-$(call ENCDEC, ADPCM_IMA_QT, AIFF) += ima_qt
FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_SSI, KVAG) += ima_ssi
FATE_ACODEC_ADPCM_RESAMPLE-$(call ENCDEC, ADPCM_IMA_WAV, WAV) += ima_wav
FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_WS, WSAUD) += ima_ws
FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_MS, WAV) += ms
FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_SWF, FLV) += swf
FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_SWF, WAV) += swf-wav
FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_YAMAHA, WAV) += yamaha
FATE_ACODEC_ADPCM-$(CONFIG_ARESAMPLE_FILTER) += $(FATE_ACODEC_ADPCM_RESAMPLE-yes)
FATE_ACODEC_ADPCM := $(if $(call ENCDEC, PCM_S16LE, WAV), $(FATE_ACODEC_ADPCM-yes))
FATE_ACODEC_ADPCM := $(FATE_ACODEC_ADPCM:%=fate-acodec-adpcm-%)
FATE_ACODEC += $(FATE_ACODEC_ADPCM)
fate-acodec-adpcm: $(FATE_ACODEC_ADPCM)
fate-acodec-adpcm-%: CODEC = adpcm_$(@:fate-acodec-adpcm-%=%)
fate-acodec-adpcm-adx: FMT = adx
fate-acodec-adpcm-argo: FMT = argo_asf
fate-acodec-adpcm-ima_apm: FMT = apm
fate-acodec-adpcm-ima_qt: FMT = aiff
fate-acodec-adpcm-ima_ssi: FMT = kvag
fate-acodec-adpcm-ima_wav: FMT = wav
fate-acodec-adpcm-ima_ws: FMT = wsaud
fate-acodec-adpcm-ms: FMT = wav
fate-acodec-adpcm-swf: FMT = flv
fate-acodec-adpcm-yamaha: FMT = wav
fate-acodec-adpcm-swf-wav: FMT = wav
fate-acodec-adpcm-swf-wav: CODEC = adpcm_swf
fate-acodec-adpcm-ima_alp: FMT = alp
fate-acodec-adpcm-ima_alp: ENCOPTS = -type pcm
FATE_ACODEC_ADPCM_TRELLIS := ima_qt ima_wav ms swf yamaha
FATE_ACODEC_ADPCM_TRELLIS := $(FATE_ACODEC_ADPCM_TRELLIS:%=fate-acodec-adpcm-%-trellis)
FATE_ACODEC_ADPCM_TRELLIS := $(filter $(addsuffix -trellis,$(FATE_ACODEC_ADPCM)), $(FATE_ACODEC_ADPCM_TRELLIS))
FATE_ACODEC += $(FATE_ACODEC_ADPCM_TRELLIS)
fate-acodec-adpcm-trellis: $(FATE_ACODEC_ADPCM_TRELLIS)
fate-acodec-adpcm-%-trellis: CODEC = adpcm_$(@:fate-acodec-adpcm-%-trellis=%)
fate-acodec-adpcm-%-trellis: ENCOPTS = -trellis 5
fate-acodec-adpcm-ima_qt-trellis: FMT = aiff
fate-acodec-adpcm-ima_wav-trellis: FMT = wav
fate-acodec-adpcm-ms-trellis: FMT = wav
fate-acodec-adpcm-swf-trellis: FMT = flv
fate-acodec-adpcm-yamaha-trellis: FMT = wav
FATE_ACODEC-$(call ENCDEC, MP2, MP2 MP3, ARESAMPLE_FILTER) += fate-acodec-mp2
fate-acodec-mp2: FMT = mp2
fate-acodec-mp2: CMP_SHIFT = -1924
fate-acodec-mp2: ENCOPTS = -b:a 128k
FATE_ACODEC-$(call ENCDEC, MP2FIXED MP2, MP2 MP3, ARESAMPLE_FILTER) += fate-acodec-mp2fixed
fate-acodec-mp2fixed: FMT = mp2
fate-acodec-mp2fixed: CMP_SHIFT = -1924
fate-acodec-mp2fixed: ENCOPTS = -b:a 384k
FATE_ACODEC-$(call ENCDEC, ALAC, MOV, ARESAMPLE_FILTER) += fate-acodec-alac
fate-acodec-alac: FMT = mov
fate-acodec-alac: CODEC = alac -compression_level 1
FATE_ACODEC-$(call ENCDEC, DCA, DTS, ARESAMPLE_FILTER) += fate-acodec-dca
fate-acodec-dca: tests/data/asynth-44100-2.wav
fate-acodec-dca: SRC = tests/data/asynth-44100-2.wav
fate-acodec-dca: CMD = md5 -i $(TARGET_PATH)/$(SRC) -c:a dca -strict -2 -f dts -flags +bitexact -af aresample
fate-acodec-dca: CMP = oneline
fate-acodec-dca: REF = 2aa580ac67820fce4f581b96ebb34acc
FATE_ACODEC-$(call ENCDEC, DCA, WAV, ARESAMPLE_FILTER) += fate-acodec-dca2
fate-acodec-dca2: CMD = enc_dec_pcm dts wav s16le $(SRC) -c:a dca -strict -2 -flags +bitexact -af aresample
fate-acodec-dca2: REF = $(SRC)
fate-acodec-dca2: CMP = stddev
fate-acodec-dca2: CMP_SHIFT = -2048
fate-acodec-dca2: CMP_TARGET = 534
fate-acodec-dca2: SIZE_TOLERANCE = 1632
FATE_ACODEC-$(call ENCDEC, FLAC, FLAC) += fate-acodec-flac fate-acodec-flac-exact-rice
fate-acodec-flac: FMT = flac
fate-acodec-flac: CODEC = flac -compression_level 2
fate-acodec-flac-exact-rice: FMT = flac
fate-acodec-flac-exact-rice: CODEC = flac -compression_level 2 -exact_rice_parameters 1
FATE_ACODEC-$(call ENCDEC, G723_1, G723_1, ARESAMPLE_FILTER) += fate-acodec-g723_1
fate-acodec-g723_1: tests/data/asynth-8000-1.wav
fate-acodec-g723_1: SRC = tests/data/asynth-8000-1.wav
fate-acodec-g723_1: FMT = g723_1
fate-acodec-g723_1: CODEC = g723_1
fate-acodec-g723_1: ENCOPTS = -b:a 6.3k
fate-acodec-g723_1: CMP_SHIFT = 8
FATE_ACODEC-$(call ENCDEC, RA_144, WAV) += fate-acodec-ra144
fate-acodec-ra144: tests/data/asynth-8000-1.wav
fate-acodec-ra144: SRC = tests/data/asynth-8000-1.wav
fate-acodec-ra144: CMD = enc_dec_pcm rm wav s16le $(SRC) -c:a real_144
fate-acodec-ra144: REF = $(SRC)
fate-acodec-ra144: CMP = stddev
fate-acodec-ra144: CMP_TARGET = 4777
fate-acodec-ra144: CMP_SHIFT = -320
FATE_ACODEC-$(call ENCDEC, ROQ_DPCM, ROQ, ARESAMPLE_FILTER) += fate-acodec-roqaudio
fate-acodec-roqaudio: FMT = roq
fate-acodec-roqaudio: CODEC = roq_dpcm
fate-acodec-roqaudio: ENCOPTS = -af aresample=22050:tsf=s16p
fate-acodec-roqaudio: DECOPTS = -af aresample=44100:tsf=s16p
FATE_ACODEC-$(call ENCDEC, S302M, MPEGTS, ARESAMPLE_FILTER) += fate-acodec-s302m
fate-acodec-s302m: FMT = mpegts
fate-acodec-s302m: CODEC = s302m
fate-acodec-s302m: ENCOPTS = -af aresample=48000:tsf=s16p -strict -2
fate-acodec-s302m: DECOPTS = -af aresample=44100:tsf=s16p
FATE_ACODEC-$(call ENCDEC, WAVPACK, WV, ARESAMPLE_FILTER) += fate-acodec-wavpack
fate-acodec-wavpack: FMT = wv
fate-acodec-wavpack: CODEC = wavpack -compression_level 1
FATE_ACODEC-$(call ENCDEC, TTA, TTA) += fate-acodec-tta
fate-acodec-tta: FMT = tta
FATE_ACODEC-yes := $(if $(call ENCDEC, PCM_S16LE, WAV), $(FATE_ACODEC-yes))
FATE_ACODEC += $(FATE_ACODEC-yes)
$(FATE_ACODEC): tests/data/asynth-44100-2.wav
FATE_AVCONV += $(FATE_ACODEC)
fate-acodec: $(FATE_ACODEC)
+149
View File
@@ -0,0 +1,149 @@
FATE_ADPCM-$(call DEMDEC, FOURXM, ADPCM_4XM, ARESAMPLE_FILTER) += fate-adpcm-4xm
fate-adpcm-4xm: CMD = framecrc -i $(TARGET_SAMPLES)/4xm/dracula.4xm -vn -map 0:6 -af aresample
FATE_ADPCM-$(call DEMDEC, AST, ADPCM_AFC, ARESAMPLE_FILTER) += fate-adpcm-afc
fate-adpcm-afc: CMD = framecrc -i $(TARGET_SAMPLES)/ast/demo11_02_partial.ast -af aresample
FATE_ADPCM-$(call DEMDEC, WAV, ADPCM_CT) += fate-adpcm-creative
fate-adpcm-creative: CMD = md5 -i $(TARGET_SAMPLES)/creative/intro-partial.wav -f s16le
FATE_ADPCM-$(call DEMDEC, VOC, ADPCM_SBPRO_2) += fate-adpcm-creative-8-2bit
fate-adpcm-creative-8-2bit: CMD = md5 -i $(TARGET_SAMPLES)/creative/BBC_2BIT.VOC -f s16le
FATE_ADPCM-$(call DEMDEC, VOC, ADPCM_SBPRO_3) += fate-adpcm-creative-8-2.6bit
fate-adpcm-creative-8-2.6bit: CMD = md5 -i $(TARGET_SAMPLES)/creative/BBC_3BIT.VOC -f s16le
FATE_ADPCM-$(call DEMDEC, VOC, ADPCM_SBPRO_4) += fate-adpcm-creative-8-4bit
fate-adpcm-creative-8-4bit: CMD = md5 -i $(TARGET_SAMPLES)/creative/BBC_4BIT.VOC -f s16le
FATE_ADPCM-$(call DEMDEC, ADP, ADPCM_DTK, ARESAMPLE_FILTER) += fate-adpcm-dtk
fate-adpcm-dtk: CMD = framecrc -i $(TARGET_SAMPLES)/adp/shakespr_partial.adp -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, EA, ADPCM_EA) += fate-adpcm-ea-1
fate-adpcm-ea-1: CMD = framecrc -i $(TARGET_SAMPLES)/ea-wve/networkBackbone-partial.wve -frames:a 26 -vn
FATE_ADPCM-$(call DEMDEC, EA, ADPCM_EA) += fate-adpcm-ea-2
fate-adpcm-ea-2: CMD = framecrc -i $(TARGET_SAMPLES)/ea-dct/NFS2Esprit-partial.dct -vn
FATE_ADPCM-$(call DEMDEC, XA, ADPCM_EA_MAXIS_XA) += fate-adpcm-ea-maxis-xa
fate-adpcm-ea-maxis-xa: CMD = framecrc -i $(TARGET_SAMPLES)/maxis-xa/SC2KBUG.XA -frames:a 30
FATE_ADPCM-$(call DEMDEC, EA, ADPCM_EA_R1, ARESAMPLE_FILTER) += fate-adpcm-ea-r1
fate-adpcm-ea-r1: CMD = framecrc -i $(TARGET_SAMPLES)/ea-mad/NFS6LogoE.mad -vn -af aresample
FATE_ADPCM-$(call DEMDEC, EA, ADPCM_EA_R2, ARESAMPLE_FILTER) += fate-adpcm-ea-r2
fate-adpcm-ea-r2: CMD = crc -i $(TARGET_SAMPLES)/ea-mpc/THX_logo.mpc -vn -af aresample
FATE_ADPCM-$(call DEMDEC, EA, ADPCM_EA_R3, ARESAMPLE_FILTER) += fate-adpcm-ea-r3
fate-adpcm-ea-r3: CMD = crc -i $(TARGET_SAMPLES)/ea-vp6/THX_logo.vp6 -vn -af aresample
FATE_ADPCM-$(call DEMDEC, AVI, ADPCM_IMA_AMV) += fate-adpcm-ima-amv
fate-adpcm-ima-amv: CMD = framecrc -i $(TARGET_SAMPLES)/amv/MTV_high_res_320x240_sample_Penguin_Joke_MTV_from_WMV.amv -t 10 -vn
FATE_ADPCM-$(call DEMDEC, APC, ADPCM_IMA_APC) += fate-adpcm-ima-apc
fate-adpcm-ima-apc: CMD = md5 -i $(TARGET_SAMPLES)/cryo-apc/cine007.APC -f s16le
FATE_ADPCM-$(call DEMDEC, AVI, ADPCM_IMA_DK3) += fate-adpcm-ima-dk3
fate-adpcm-ima-dk3: CMD = md5 -i $(TARGET_SAMPLES)/duck/sop-audio-only.avi -f s16le
FATE_ADPCM-$(call DEMDEC, AVI, ADPCM_IMA_DK4) += fate-adpcm-ima-dk4
fate-adpcm-ima-dk4: CMD = md5 -i $(TARGET_SAMPLES)/duck/salsa-audio-only.avi -f s16le
FATE_ADPCM-$(call DEMDEC, EA, ADPCM_IMA_EA_EACS) += fate-adpcm-ima-ea-eacs
fate-adpcm-ima-ea-eacs: CMD = framecrc -i $(TARGET_SAMPLES)/ea-tgv/INTRO8K-partial.TGV -vn
FATE_ADPCM-$(call DEMDEC, EA, ADPCM_IMA_EA_SEAD) += fate-adpcm-ima-ea-sead
fate-adpcm-ima-ea-sead: CMD = framecrc -i $(TARGET_SAMPLES)/ea-tgv/INTEL_S.TGV -vn
FATE_ADPCM-$(call DEMDEC, ISS, ADPCM_IMA_ISS) += fate-adpcm-ima-iss
fate-adpcm-ima-iss: CMD = md5 -i $(TARGET_SAMPLES)/funcom-iss/0004010100.iss -f s16le
FATE_ADPCM-$(call DEMDEC, WAV, ADPCM_IMA_OKI) += fate-adpcm-ima-oki
fate-adpcm-ima-oki: CMD = md5 -i $(TARGET_SAMPLES)/oki/test.wav -f s16le
FATE_ADPCM-$(call DEMDEC, RSD, ADPCM_IMA_RAD) += fate-adpcm-ima-rad
fate-adpcm-ima-rad: CMD = md5 -i $(TARGET_SAMPLES)/rsd/hit_run_partial.rsd -f s16le
FATE_ADPCM-$(call DEMDEC, SMJPEG, ADPCM_IMA_SMJPEG) += fate-adpcm-ima-smjpeg
fate-adpcm-ima-smjpeg: CMD = framecrc -i $(TARGET_SAMPLES)/smjpeg/scenwin.mjpg -vn
FATE_ADPCM-$(call DEMDEC, MOV, ADPCM_IMA_WAV, ARESAMPLE_FILTER) += fate-adpcm-ima_wav-stereo
fate-adpcm-ima_wav-stereo: CMD = md5 -i $(TARGET_SAMPLES)/qt-surge-suite/surge-2-16-L-ms11.mov -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, WSVQA, ADPCM_IMA_WS) += fate-adpcm-ima-ws
fate-adpcm-ima-ws: CMD = framecrc -i $(TARGET_SAMPLES)/vqa/cc-demo1-partial.vqa -vn
FATE_ADPCM-$(call DEMDEC, WSVQA, ADPCM_IMA_WS, ARESAMPLE_FILTER) += fate-adpcm-ima-ws-vqa3
fate-adpcm-ima-ws-vqa3: CMD = framecrc -i $(TARGET_SAMPLES)/vqa/small-cut-v3.vqa -vn -af aresample
FATE_ADPCM-$(call DEMDEC, DXA, ADPCM_MS) += fate-adpcm-ms-mono
fate-adpcm-ms-mono: CMD = framecrc -i $(TARGET_SAMPLES)/dxa/meetsquid.dxa -t 2 -vn
FATE_ADPCM-$(call DEMDEC, MOV, ADPCM_MS) += fate-adpcm_ms-stereo
fate-adpcm_ms-stereo: CMD = md5 -i $(TARGET_SAMPLES)/qt-surge-suite/surge-2-16-L-ms02.mov -f s16le
FATE_ADPCM-$(call DEMDEC, THP, ADPCM_THP, ARESAMPLE_FILTER) += fate-adpcm-thp
fate-adpcm-thp: CMD = framecrc -i $(TARGET_SAMPLES)/thp/pikmin2-opening1-partial.thp -vn -af aresample
FATE_ADPCM-$(call DEMDEC, SMUSH, ADPCM_VIMA) += fate-adpcm-vima
fate-adpcm-vima: CMD = framecrc -i $(TARGET_SAMPLES)/smush/ronin_part.znm -vn
FATE_ADPCM-$(call DEMDEC, STR, ADPCM_XA, ARESAMPLE_FILTER) += fate-adpcm-xa
fate-adpcm-xa: CMD = framecrc -i $(TARGET_SAMPLES)/psx-str/abc000_cut.str -vn -af aresample
FATE_ADPCM-$(call DEMDEC, ARGO_ASF, ADPCM_ARGO, ARESAMPLE_FILTER) += fate-adpcm-argo-mono
fate-adpcm-argo-mono: CMD = md5 -i $(TARGET_SAMPLES)/argo-asf/PWIN22M.ASF -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, ARGO_ASF, ADPCM_ARGO, ARESAMPLE_FILTER) += fate-adpcm-argo-stereo
fate-adpcm-argo-stereo: CMD = md5 -i $(TARGET_SAMPLES)/argo-asf/CBK2_cut.asf -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, KVAG, ADPCM_IMA_SSI) += fate-adpcm-ima-ssi-mono
fate-adpcm-ima-ssi-mono: CMD = md5 -i $(TARGET_SAMPLES)/kvag/mull1_cut.vag -f s16le
FATE_ADPCM-$(call DEMDEC, KVAG, ADPCM_IMA_SSI) += fate-adpcm-ima-ssi-stereo
fate-adpcm-ima-ssi-stereo: CMD = md5 -i $(TARGET_SAMPLES)/kvag/credits_cut.vag -f s16le
FATE_ADPCM-$(call DEMDEC, APM, ADPCM_IMA_APM) += fate-adpcm-ima-apm-mono
fate-adpcm-ima-apm-mono: CMD = md5 -i $(TARGET_SAMPLES)/apm/outro1.apm -f s16le
FATE_ADPCM-$(call DEMDEC, APM, ADPCM_IMA_APM) += fate-adpcm-ima-apm-stereo
fate-adpcm-ima-apm-stereo: CMD = md5 -i $(TARGET_SAMPLES)/apm/AS01.apm -f s16le
FATE_ADPCM-$(call DEMDEC, ALP, ADPCM_IMA_ALP) += fate-adpcm-ima-alp-mono
fate-adpcm-ima-alp-mono: CMD = md5 -i $(TARGET_SAMPLES)/alp/AD_P11.PCM -f s16le
FATE_ADPCM-$(call DEMDEC, ALP, ADPCM_IMA_ALP) += fate-adpcm-ima-alp-stereo
fate-adpcm-ima-alp-stereo: CMD = md5 -i $(TARGET_SAMPLES)/alp/theme-cut.tun -f s16le
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-single
fate-adpcm-ima-cunning-single: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/GD-cut.5c -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-track0
fate-adpcm-ima-cunning-track0: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/VIDEOMOD-cut.11c -map 0:a:0 -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-track1
fate-adpcm-ima-cunning-track1: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/VIDEOMOD-cut.11c -map 0:a:1 -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-trunc-t1
fate-adpcm-ima-cunning-trunc-t1: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/VIDEOMOD-trunc-t1.11c -map 0:a:0 -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-trunc-t2-track0
fate-adpcm-ima-cunning-trunc-t2-track0: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/VIDEOMOD-trunc-t2.11c -map 0:a:0 -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-trunc-t2-track1
fate-adpcm-ima-cunning-trunc-t2-track1: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/VIDEOMOD-trunc-t2.11c -map 0:a:1 -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-trunc-t2a-track0
fate-adpcm-ima-cunning-trunc-t2a-track0: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/VIDEOMOD-trunc-t2a.11c -map 0:a:0 -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-trunc-t2a-track1
fate-adpcm-ima-cunning-trunc-t2a-track1: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/VIDEOMOD-trunc-t2a.11c -map 0:a:1 -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-trunc-h2
fate-adpcm-ima-cunning-trunc-h2: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/VIDEOMOD-trunc-h2.11c -map 0:a:0 -f s16le -af aresample
FATE_ADPCM-$(call DEMDEC, PP_BNK, ADPCM_IMA_CUNNING, ARESAMPLE_FILTER) += fate-adpcm-ima-cunning-stereo
fate-adpcm-ima-cunning-stereo: CMD = md5 -y -i $(TARGET_SAMPLES)/pp_bnk/MOGODON2-cut.44c -f s16le -af aresample
FATE_SAMPLES_AVCONV += $(FATE_ADPCM-yes)
fate-adpcm: $(FATE_ADPCM-yes)
+26
View File
@@ -0,0 +1,26 @@
FATE_ALAC += fate-alac-16-level-0 \
fate-alac-16-level-1 \
fate-alac-16-level-2 \
fate-alac-16-lpc-orders \
fate-alac-24-level-0 \
fate-alac-24-level-1 \
fate-alac-24-level-2 \
fate-alac-24-lpc-orders \
fate-alac-16-level-%: OPTS = -compression_level $(@:fate-alac-16-level-%=%)
fate-alac-24-level-%: OPTS = -compression_level $(@:fate-alac-24-level-%=%)
fate-alac-%-lpc-orders: OPTS = -min_prediction_order 1 -max_prediction_order 30
fate-alac-16-%: REF = $(SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav
fate-alac-16-%: CMD = enc_dec_pcm mov wav s16le $(subst $(SAMPLES),$(TARGET_SAMPLES),$(REF)) -c alac $(OPTS)
fate-alac-24-%: REF = $(SAMPLES)/audio-reference/divertimenti_2ch_96kHz_s24.wav
fate-alac-24-%: CMD = enc_dec_pcm mov wav s24le $(subst $(SAMPLES),$(TARGET_SAMPLES),$(REF)) -c alac $(OPTS)
fate-alac-%: CMP = oneoff
fate-alac-%: FUZZ = 0
FATE_ALAC-$(call ENCDEC, ALAC, MOV, ARESAMPLE_FILTER) += $(FATE_ALAC)
FATE_SAMPLES_FFMPEG += $(FATE_ALAC-yes)
fate-alac: $(FATE_ALAC-yes)
Loaded 100 of 8663 files, more files were not shown because too many files have changed in this diff. Show more