early-access version 1432
This commit is contained in:
24
externals/ffmpeg/libavcodec/tests/.gitignore
vendored
Executable file
24
externals/ffmpeg/libavcodec/tests/.gitignore
vendored
Executable file
@@ -0,0 +1,24 @@
|
||||
/avfft
|
||||
/avpacket
|
||||
/cabac
|
||||
/celp_math
|
||||
/codec_desc
|
||||
/dct
|
||||
/fft
|
||||
/fft-fixed
|
||||
/fft-fixed32
|
||||
/golomb
|
||||
/h264_levels
|
||||
/h265_levels
|
||||
/htmlsubtitles
|
||||
/iirfilter
|
||||
/imgconvert
|
||||
/jpeg2000dwt
|
||||
/mathops
|
||||
/mjpegenc_huffman
|
||||
/motion
|
||||
/mpeg12framerate
|
||||
/options
|
||||
/rangecoder
|
||||
/snowenc
|
||||
/utils
|
30
externals/ffmpeg/libavcodec/tests/aarch64/dct.c
vendored
Executable file
30
externals/ffmpeg/libavcodec/tests/aarch64/dct.c
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
|
||||
#include "libavcodec/aarch64/idct.h"
|
||||
|
||||
static const struct algo fdct_tab_arch[] = {
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static const struct algo idct_tab_arch[] = {
|
||||
{ "SIMPLE-NEON", ff_simple_idct_neon, FF_IDCT_PERM_PARTTRANS, AV_CPU_FLAG_NEON },
|
||||
{ 0 }
|
||||
};
|
40
externals/ffmpeg/libavcodec/tests/arm/dct.c
vendored
Executable file
40
externals/ffmpeg/libavcodec/tests/arm/dct.c
vendored
Executable file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
|
||||
#include "libavcodec/arm/idct.h"
|
||||
|
||||
static const struct algo fdct_tab_arch[] = {
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static const struct algo idct_tab_arch[] = {
|
||||
{ "SIMPLE-ARM", ff_simple_idct_arm, FF_IDCT_PERM_NONE },
|
||||
{ "INT-ARM", ff_j_rev_dct_arm, FF_IDCT_PERM_LIBMPEG2 },
|
||||
#if HAVE_ARMV5TE
|
||||
{ "SIMPLE-ARMV5TE", ff_simple_idct_armv5te, FF_IDCT_PERM_NONE, AV_CPU_FLAG_ARMV5TE },
|
||||
#endif
|
||||
#if HAVE_ARMV6
|
||||
{ "SIMPLE-ARMV6", ff_simple_idct_armv6, FF_IDCT_PERM_LIBMPEG2, AV_CPU_FLAG_ARMV6 },
|
||||
#endif
|
||||
#if HAVE_NEON
|
||||
{ "SIMPLE-NEON", ff_simple_idct_neon, FF_IDCT_PERM_PARTTRANS, AV_CPU_FLAG_NEON },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
25
externals/ffmpeg/libavcodec/tests/avfft.c
vendored
Executable file
25
externals/ffmpeg/libavcodec/tests/avfft.c
vendored
Executable file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* This test is similar to fft-fixed.c or fft-fixed32.c
|
||||
*/
|
||||
|
||||
#define AVFFT 1
|
||||
#define FFT_FLOAT 1
|
||||
#include "fft.c"
|
128
externals/ffmpeg/libavcodec/tests/avpacket.c
vendored
Executable file
128
externals/ffmpeg/libavcodec/tests/avpacket.c
vendored
Executable file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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 <inttypes.h>
|
||||
#include <string.h>
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "libavutil/error.h"
|
||||
|
||||
|
||||
|
||||
static int setup_side_data_entry(AVPacket* avpkt)
|
||||
{
|
||||
const uint8_t *data_name = NULL;
|
||||
int ret = 0, bytes;
|
||||
uint8_t *extra_data = NULL;
|
||||
|
||||
|
||||
/* get side_data_name string */
|
||||
data_name = av_packet_side_data_name(AV_PKT_DATA_NEW_EXTRADATA);
|
||||
|
||||
/* Allocate a memory bloc */
|
||||
bytes = strlen(data_name);
|
||||
|
||||
if(!(extra_data = av_malloc(bytes))){
|
||||
ret = AVERROR(ENOMEM);
|
||||
fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
|
||||
exit(1);
|
||||
}
|
||||
/* copy side_data_name to extra_data array */
|
||||
memcpy(extra_data, data_name, bytes);
|
||||
|
||||
/* create side data for AVPacket */
|
||||
ret = av_packet_add_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
|
||||
extra_data, bytes);
|
||||
if(ret < 0){
|
||||
fprintf(stderr,
|
||||
"Error occurred in av_packet_add_side_data: %s\n",
|
||||
av_err2str(ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int initializations(AVPacket* avpkt)
|
||||
{
|
||||
const static uint8_t* data = "selftest for av_packet_clone(...)";
|
||||
int ret = 0;
|
||||
|
||||
/* initialize avpkt */
|
||||
av_init_packet(avpkt);
|
||||
|
||||
/* set values for avpkt */
|
||||
avpkt->pts = 17;
|
||||
avpkt->dts = 2;
|
||||
avpkt->data = (uint8_t*)data;
|
||||
avpkt->size = strlen(data);
|
||||
avpkt->flags = AV_PKT_FLAG_DISCARD;
|
||||
avpkt->duration = 100;
|
||||
avpkt->pos = 3;
|
||||
|
||||
ret = setup_side_data_entry(avpkt);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
AVPacket avpkt;
|
||||
AVPacket *avpkt_clone = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if(initializations(&avpkt) < 0){
|
||||
printf("failed to initialize variables\n");
|
||||
return 1;
|
||||
}
|
||||
/* test av_packet_clone*/
|
||||
avpkt_clone = av_packet_clone(&avpkt);
|
||||
|
||||
if(!avpkt_clone) {
|
||||
av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n");
|
||||
return 1;
|
||||
}
|
||||
/*test av_grow_packet*/
|
||||
if(av_grow_packet(avpkt_clone, 20) < 0){
|
||||
av_log(NULL, AV_LOG_ERROR, "av_grow_packet failed\n");
|
||||
return 1;
|
||||
}
|
||||
if(av_grow_packet(avpkt_clone, INT_MAX) == 0){
|
||||
printf( "av_grow_packet failed to return error "
|
||||
"when \"grow_by\" parameter is too large.\n" );
|
||||
ret = 1;
|
||||
}
|
||||
/* test size error check in av_new_packet*/
|
||||
if(av_new_packet(avpkt_clone, INT_MAX) == 0){
|
||||
printf( "av_new_packet failed to return error "
|
||||
"when \"size\" parameter is too large.\n" );
|
||||
ret = 1;
|
||||
}
|
||||
/*test size error check in av_packet_from_data*/
|
||||
if(av_packet_from_data(avpkt_clone, avpkt_clone->data, INT_MAX) == 0){
|
||||
printf("av_packet_from_data failed to return error "
|
||||
"when \"size\" parameter is too large.\n" );
|
||||
ret = 1;
|
||||
}
|
||||
/*clean up*/
|
||||
av_packet_free(&avpkt_clone);
|
||||
av_packet_unref(&avpkt);
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
165
externals/ffmpeg/libavcodec/tests/cabac.c
vendored
Executable file
165
externals/ffmpeg/libavcodec/tests/cabac.c
vendored
Executable file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavcodec/cabac.c"
|
||||
|
||||
#define SIZE 10240
|
||||
|
||||
#include "libavutil/lfg.h"
|
||||
#include "libavcodec/avcodec.h"
|
||||
|
||||
static inline void put_cabac_bit(CABACContext *c, int b){
|
||||
put_bits(&c->pb, 1, b);
|
||||
for(;c->outstanding_count; c->outstanding_count--){
|
||||
put_bits(&c->pb, 1, 1-b);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void renorm_cabac_encoder(CABACContext *c){
|
||||
while(c->range < 0x100){
|
||||
//FIXME optimize
|
||||
if(c->low<0x100){
|
||||
put_cabac_bit(c, 0);
|
||||
}else if(c->low<0x200){
|
||||
c->outstanding_count++;
|
||||
c->low -= 0x100;
|
||||
}else{
|
||||
put_cabac_bit(c, 1);
|
||||
c->low -= 0x200;
|
||||
}
|
||||
|
||||
c->range+= c->range;
|
||||
c->low += c->low;
|
||||
}
|
||||
}
|
||||
|
||||
static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
|
||||
int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state];
|
||||
|
||||
if(bit == ((*state)&1)){
|
||||
c->range -= RangeLPS;
|
||||
*state = ff_h264_mlps_state[128 + *state];
|
||||
}else{
|
||||
c->low += c->range - RangeLPS;
|
||||
c->range = RangeLPS;
|
||||
*state= ff_h264_mlps_state[127 - *state];
|
||||
}
|
||||
|
||||
renorm_cabac_encoder(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bit 0 -> write zero bit, !=0 write one bit
|
||||
*/
|
||||
static void put_cabac_bypass(CABACContext *c, int bit){
|
||||
c->low += c->low;
|
||||
|
||||
if(bit){
|
||||
c->low += c->range;
|
||||
}
|
||||
//FIXME optimize
|
||||
if(c->low<0x200){
|
||||
put_cabac_bit(c, 0);
|
||||
}else if(c->low<0x400){
|
||||
c->outstanding_count++;
|
||||
c->low -= 0x200;
|
||||
}else{
|
||||
put_cabac_bit(c, 1);
|
||||
c->low -= 0x400;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the number of bytes written
|
||||
*/
|
||||
static int put_cabac_terminate(CABACContext *c, int bit){
|
||||
c->range -= 2;
|
||||
|
||||
if(!bit){
|
||||
renorm_cabac_encoder(c);
|
||||
}else{
|
||||
c->low += c->range;
|
||||
c->range= 2;
|
||||
|
||||
renorm_cabac_encoder(c);
|
||||
|
||||
av_assert0(c->low <= 0x1FF);
|
||||
put_cabac_bit(c, c->low>>9);
|
||||
put_bits(&c->pb, 2, ((c->low>>7)&3)|1);
|
||||
|
||||
flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong
|
||||
}
|
||||
|
||||
return (put_bits_count(&c->pb)+7)>>3;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
CABACContext c;
|
||||
uint8_t b[9*SIZE];
|
||||
uint8_t r[9*SIZE];
|
||||
int i, ret = 0;
|
||||
uint8_t state[10]= {0};
|
||||
AVLFG prng;
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
ff_init_cabac_encoder(&c, b, SIZE);
|
||||
|
||||
for(i=0; i<SIZE; i++){
|
||||
if(2*i<SIZE) r[i] = av_lfg_get(&prng) % 7;
|
||||
else r[i] = (i>>8)&1;
|
||||
}
|
||||
|
||||
for(i=0; i<SIZE; i++){
|
||||
put_cabac_bypass(&c, r[i]&1);
|
||||
}
|
||||
|
||||
for(i=0; i<SIZE; i++){
|
||||
put_cabac(&c, state, r[i]&1);
|
||||
}
|
||||
|
||||
i= put_cabac_terminate(&c, 1);
|
||||
b[i++] = av_lfg_get(&prng);
|
||||
b[i ] = av_lfg_get(&prng);
|
||||
|
||||
ff_init_cabac_decoder(&c, b, SIZE);
|
||||
|
||||
memset(state, 0, sizeof(state));
|
||||
|
||||
for(i=0; i<SIZE; i++){
|
||||
if( (r[i]&1) != get_cabac_bypass(&c) ) {
|
||||
av_log(NULL, AV_LOG_ERROR, "CABAC bypass failure at %d\n", i);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i<SIZE; i++){
|
||||
if( (r[i]&1) != get_cabac_noinline(&c, state) ) {
|
||||
av_log(NULL, AV_LOG_ERROR, "CABAC failure at %d\n", i);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
if(!get_cabac_terminate(&c)) {
|
||||
av_log(NULL, AV_LOG_ERROR, "where's the Terminator?\n");
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
49
externals/ffmpeg/libavcodec/tests/celp_math.c
vendored
Executable file
49
externals/ffmpeg/libavcodec/tests/celp_math.c
vendored
Executable file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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/libm.h"
|
||||
#include "libavcodec/celp_math.c"
|
||||
|
||||
static inline void IsAlmostEqual(float A, float B, float epsilon)
|
||||
{
|
||||
float diff = fabsf(A - B);
|
||||
float absa = fabsf(A);
|
||||
float absb = fabsf(B);
|
||||
float largest = (absb > absa) ? absb : absa;
|
||||
av_assert0(diff <= largest * epsilon);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
const float f1[3] = {0.0, 1.1, 2.2};
|
||||
const float f2[3] = {3.3, 4.4, 5.5};
|
||||
const int16_t i1[3] = {6, 7, 8};
|
||||
const int16_t i2[3] = {9, 10, 11};
|
||||
|
||||
float r = ff_dot_productf(f1, f2, FF_ARRAY_ELEMS(f1));
|
||||
int64_t d = ff_dot_product(i1, i2, FF_ARRAY_ELEMS(i1));
|
||||
|
||||
IsAlmostEqual(16.94f, r, 0.000001f);
|
||||
av_assert0(212 == d);
|
||||
|
||||
for (i = 1024; i >= 1; i/=2)
|
||||
av_assert0(ff_log2_q15(i) == (1<<15)*((int)log2(i))+(1<<2));
|
||||
|
||||
return 0;
|
||||
}
|
45
externals/ffmpeg/libavcodec/tests/codec_desc.c
vendored
Executable file
45
externals/ffmpeg/libavcodec/tests/codec_desc.c
vendored
Executable file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavcodec/avcodec.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const AVCodecDescriptor *old_desc = NULL, *desc;
|
||||
|
||||
while (desc = avcodec_descriptor_next(old_desc)) {
|
||||
if (old_desc && old_desc->id >= desc->id) {
|
||||
av_log(NULL, AV_LOG_FATAL, "Unsorted codec_descriptors '%s' and '%s'.\n", old_desc->name, desc->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (avcodec_descriptor_get(desc->id) != desc) {
|
||||
av_log(NULL, AV_LOG_FATAL, "avcodec_descriptor_get() failed with '%s'.\n", desc->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (avcodec_descriptor_get_by_name(desc->name) != desc) {
|
||||
av_log(NULL, AV_LOG_FATAL, "avcodec_descriptor_get_by_name() failed with '%s'.\n", desc->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
old_desc = desc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
532
externals/ffmpeg/libavcodec/tests/dct.c
vendored
Executable file
532
externals/ffmpeg/libavcodec/tests/dct.c
vendored
Executable file
@@ -0,0 +1,532 @@
|
||||
/*
|
||||
* (c) 2001 Fabrice Bellard
|
||||
* 2007 Marc Hoffman <marc.hoffman@analog.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* DCT test (c) 2001 Fabrice Bellard
|
||||
* Started from sample code by Juan J. Sierralta P.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "libavutil/cpu.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/internal.h"
|
||||
#include "libavutil/lfg.h"
|
||||
#include "libavutil/time.h"
|
||||
|
||||
#include "libavcodec/dct.h"
|
||||
#include "libavcodec/idctdsp.h"
|
||||
#include "libavcodec/simple_idct.h"
|
||||
#include "libavcodec/xvididct.h"
|
||||
#include "libavcodec/aandcttab.h"
|
||||
#include "libavcodec/faandct.h"
|
||||
#include "libavcodec/faanidct.h"
|
||||
#include "libavcodec/dctref.h"
|
||||
|
||||
struct algo {
|
||||
const char *name;
|
||||
void (*func)(int16_t *block);
|
||||
enum idct_permutation_type perm_type;
|
||||
int cpu_flag;
|
||||
int nonspec;
|
||||
};
|
||||
|
||||
static const struct algo fdct_tab[] = {
|
||||
{ "REF-DBL", ff_ref_fdct, FF_IDCT_PERM_NONE },
|
||||
{ "IJG-AAN-INT", ff_fdct_ifast, FF_IDCT_PERM_NONE },
|
||||
{ "IJG-LLM-INT", ff_jpeg_fdct_islow_8, FF_IDCT_PERM_NONE },
|
||||
#if CONFIG_FAANDCT
|
||||
{ "FAAN", ff_faandct, FF_IDCT_PERM_NONE },
|
||||
#endif /* CONFIG_FAANDCT */
|
||||
};
|
||||
|
||||
static void ff_prores_idct_wrap(int16_t *dst){
|
||||
LOCAL_ALIGNED(16, int16_t, qmat, [64]);
|
||||
int i;
|
||||
|
||||
for(i=0; i<64; i++){
|
||||
qmat[i]=4;
|
||||
}
|
||||
ff_prores_idct_10(dst, qmat);
|
||||
for(i=0; i<64; i++) {
|
||||
dst[i] -= 512;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct algo idct_tab[] = {
|
||||
{ "REF-DBL", ff_ref_idct, FF_IDCT_PERM_NONE },
|
||||
{ "INT", ff_j_rev_dct, FF_IDCT_PERM_LIBMPEG2 },
|
||||
{ "SIMPLE-C", ff_simple_idct_int16_8bit, FF_IDCT_PERM_NONE },
|
||||
{ "SIMPLE-C10", ff_simple_idct_int16_10bit, FF_IDCT_PERM_NONE },
|
||||
{ "SIMPLE-C12", ff_simple_idct_int16_12bit, FF_IDCT_PERM_NONE, 0, 1 },
|
||||
{ "PR-C", ff_prores_idct_wrap, FF_IDCT_PERM_NONE, 0, 1 },
|
||||
#if CONFIG_FAANIDCT
|
||||
{ "FAANI", ff_faanidct, FF_IDCT_PERM_NONE },
|
||||
#endif /* CONFIG_FAANIDCT */
|
||||
#if CONFIG_MPEG4_DECODER
|
||||
{ "XVID", ff_xvid_idct, FF_IDCT_PERM_NONE, 0, 1 },
|
||||
#endif /* CONFIG_MPEG4_DECODER */
|
||||
};
|
||||
|
||||
#if ARCH_AARCH64
|
||||
#include "aarch64/dct.c"
|
||||
#elif ARCH_ARM
|
||||
#include "arm/dct.c"
|
||||
#elif ARCH_PPC
|
||||
#include "ppc/dct.c"
|
||||
#elif ARCH_X86
|
||||
#include "x86/dct.c"
|
||||
#else
|
||||
static const struct algo fdct_tab_arch[] = { { 0 } };
|
||||
static const struct algo idct_tab_arch[] = { { 0 } };
|
||||
#endif
|
||||
|
||||
#define AANSCALE_BITS 12
|
||||
|
||||
#define NB_ITS 20000
|
||||
#define NB_ITS_SPEED 50000
|
||||
|
||||
DECLARE_ALIGNED(16, static int16_t, block)[64];
|
||||
DECLARE_ALIGNED(8, static int16_t, block1)[64];
|
||||
|
||||
static void init_block(int16_t block[64], int test, int is_idct, AVLFG *prng, int vals)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
memset(block, 0, 64 * sizeof(*block));
|
||||
|
||||
switch (test) {
|
||||
case 0:
|
||||
for (i = 0; i < 64; i++)
|
||||
block[i] = (av_lfg_get(prng) % (2*vals)) -vals;
|
||||
if (is_idct) {
|
||||
ff_ref_fdct(block);
|
||||
for (i = 0; i < 64; i++)
|
||||
block[i] >>= 3;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
j = av_lfg_get(prng) % 10 + 1;
|
||||
for (i = 0; i < j; i++) {
|
||||
int idx = av_lfg_get(prng) % 64;
|
||||
block[idx] = av_lfg_get(prng) % (2*vals) -vals;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
block[ 0] = av_lfg_get(prng) % (16*vals) - (8*vals);
|
||||
block[63] = (block[0] & 1) ^ 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void permute(int16_t dst[64], const int16_t src[64],
|
||||
enum idct_permutation_type perm_type)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if ARCH_X86
|
||||
if (permute_x86(dst, src, perm_type))
|
||||
return;
|
||||
#endif
|
||||
|
||||
switch (perm_type) {
|
||||
case FF_IDCT_PERM_LIBMPEG2:
|
||||
for (i = 0; i < 64; i++)
|
||||
dst[(i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2)] = src[i];
|
||||
break;
|
||||
case FF_IDCT_PERM_PARTTRANS:
|
||||
for (i = 0; i < 64; i++)
|
||||
dst[(i & 0x24) | ((i & 3) << 3) | ((i >> 3) & 3)] = src[i];
|
||||
break;
|
||||
case FF_IDCT_PERM_TRANSPOSE:
|
||||
for (i = 0; i < 64; i++)
|
||||
dst[(i>>3) | ((i<<3)&0x38)] = src[i];
|
||||
break;
|
||||
default:
|
||||
for (i = 0; i < 64; i++)
|
||||
dst[i] = src[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int dct_error(const struct algo *dct, int test, int is_idct, int speed, const int bits)
|
||||
{
|
||||
void (*ref)(int16_t *block) = is_idct ? ff_ref_idct : ff_ref_fdct;
|
||||
int it, i, scale;
|
||||
int err_inf, v;
|
||||
int64_t err2, ti, ti1, it1, err_sum = 0;
|
||||
int64_t sysErr[64], sysErrMax = 0;
|
||||
int64_t err2_matrix[64], err2_max = 0;
|
||||
int maxout = 0;
|
||||
int blockSumErrMax = 0, blockSumErr;
|
||||
AVLFG prng;
|
||||
const int vals=1<<bits;
|
||||
double omse, ome;
|
||||
int spec_err;
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
|
||||
err_inf = 0;
|
||||
err2 = 0;
|
||||
for (i = 0; i < 64; i++)
|
||||
err2_matrix[i] = sysErr[i] = 0;
|
||||
for (it = 0; it < NB_ITS; it++) {
|
||||
init_block(block1, test, is_idct, &prng, vals);
|
||||
permute(block, block1, dct->perm_type);
|
||||
|
||||
dct->func(block);
|
||||
emms_c();
|
||||
|
||||
if (!strcmp(dct->name, "IJG-AAN-INT")) {
|
||||
for (i = 0; i < 64; i++) {
|
||||
scale = 8 * (1 << (AANSCALE_BITS + 11)) / ff_aanscales[i];
|
||||
block[i] = (block[i] * scale) >> AANSCALE_BITS;
|
||||
}
|
||||
}
|
||||
|
||||
ref(block1);
|
||||
if (!strcmp(dct->name, "PR-SSE2"))
|
||||
for (i = 0; i < 64; i++)
|
||||
block1[i] = av_clip(block1[i], 4-512, 1019-512);
|
||||
|
||||
blockSumErr = 0;
|
||||
for (i = 0; i < 64; i++) {
|
||||
int err = block[i] - block1[i];
|
||||
err_sum += err;
|
||||
v = abs(err);
|
||||
if (v > err_inf)
|
||||
err_inf = v;
|
||||
err2_matrix[i] += v * v;
|
||||
err2 += v * v;
|
||||
sysErr[i] += block[i] - block1[i];
|
||||
blockSumErr += v;
|
||||
if (abs(block[i]) > maxout)
|
||||
maxout = abs(block[i]);
|
||||
}
|
||||
if (blockSumErrMax < blockSumErr)
|
||||
blockSumErrMax = blockSumErr;
|
||||
}
|
||||
for (i = 0; i < 64; i++) {
|
||||
sysErrMax = FFMAX(sysErrMax, FFABS(sysErr[i]));
|
||||
err2_max = FFMAX(err2_max , FFABS(err2_matrix[i]));
|
||||
}
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
if (i % 8 == 0)
|
||||
printf("\n");
|
||||
printf("%7d ", (int) sysErr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
omse = (double) err2 / NB_ITS / 64;
|
||||
ome = (double) err_sum / NB_ITS / 64;
|
||||
|
||||
spec_err = is_idct && (err_inf > 1 || omse > 0.02 || fabs(ome) > 0.0015);
|
||||
if (test < 2)
|
||||
spec_err = is_idct && ((double) err2_max / NB_ITS > 0.06 || (double) sysErrMax / NB_ITS > 0.015);
|
||||
|
||||
printf("%s %s: max_err=%d omse=%0.8f ome=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n",
|
||||
is_idct ? "IDCT" : "DCT", dct->name, err_inf,
|
||||
omse, ome, (double) sysErrMax / NB_ITS,
|
||||
maxout, blockSumErrMax);
|
||||
|
||||
if (spec_err && !dct->nonspec) {
|
||||
printf("Failed!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!speed)
|
||||
return 0;
|
||||
|
||||
/* speed test */
|
||||
|
||||
init_block(block, test, is_idct, &prng, vals);
|
||||
permute(block1, block, dct->perm_type);
|
||||
|
||||
ti = av_gettime_relative();
|
||||
it1 = 0;
|
||||
do {
|
||||
for (it = 0; it < NB_ITS_SPEED; it++) {
|
||||
memcpy(block, block1, sizeof(block));
|
||||
dct->func(block);
|
||||
}
|
||||
emms_c();
|
||||
it1 += NB_ITS_SPEED;
|
||||
ti1 = av_gettime_relative() - ti;
|
||||
} while (ti1 < 1000000);
|
||||
|
||||
printf("%s %s: %0.1f kdct/s\n", is_idct ? "IDCT" : "DCT", dct->name,
|
||||
(double) it1 * 1000.0 / (double) ti1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DECLARE_ALIGNED(8, static uint8_t, img_dest)[64];
|
||||
DECLARE_ALIGNED(8, static uint8_t, img_dest1)[64];
|
||||
|
||||
static void idct248_ref(uint8_t *dest, ptrdiff_t linesize, int16_t *block)
|
||||
{
|
||||
static int init;
|
||||
static double c8[8][8];
|
||||
static double c4[4][4];
|
||||
double block1[64], block2[64], block3[64];
|
||||
double s, sum, v;
|
||||
int i, j, k;
|
||||
|
||||
if (!init) {
|
||||
init = 1;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
sum = 0;
|
||||
for (j = 0; j < 8; j++) {
|
||||
s = (i == 0) ? sqrt(1.0 / 8.0) : sqrt(1.0 / 4.0);
|
||||
c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0);
|
||||
sum += c8[i][j] * c8[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
sum = 0;
|
||||
for (j = 0; j < 4; j++) {
|
||||
s = (i == 0) ? sqrt(1.0 / 4.0) : sqrt(1.0 / 2.0);
|
||||
c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0);
|
||||
sum += c4[i][j] * c4[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* butterfly */
|
||||
s = 0.5 * sqrt(2.0);
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
block1[8 * (2 * i) + j] =
|
||||
(block[8 * (2 * i) + j] + block[8 * (2 * i + 1) + j]) * s;
|
||||
block1[8 * (2 * i + 1) + j] =
|
||||
(block[8 * (2 * i) + j] - block[8 * (2 * i + 1) + j]) * s;
|
||||
}
|
||||
}
|
||||
|
||||
/* idct8 on lines */
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
sum = 0;
|
||||
for (k = 0; k < 8; k++)
|
||||
sum += c8[k][j] * block1[8 * i + k];
|
||||
block2[8 * i + j] = sum;
|
||||
}
|
||||
}
|
||||
|
||||
/* idct4 */
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
/* top */
|
||||
sum = 0;
|
||||
for (k = 0; k < 4; k++)
|
||||
sum += c4[k][j] * block2[8 * (2 * k) + i];
|
||||
block3[8 * (2 * j) + i] = sum;
|
||||
|
||||
/* bottom */
|
||||
sum = 0;
|
||||
for (k = 0; k < 4; k++)
|
||||
sum += c4[k][j] * block2[8 * (2 * k + 1) + i];
|
||||
block3[8 * (2 * j + 1) + i] = sum;
|
||||
}
|
||||
}
|
||||
|
||||
/* clamp and store the result */
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
v = block3[8 * i + j];
|
||||
if (v < 0) v = 0;
|
||||
else if (v > 255) v = 255;
|
||||
dest[i * linesize + j] = (int) rint(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void idct248_error(const char *name,
|
||||
void (*idct248_put)(uint8_t *dest,
|
||||
ptrdiff_t line_size,
|
||||
int16_t *block),
|
||||
int speed)
|
||||
{
|
||||
int it, i, it1, ti, ti1, err_max, v;
|
||||
AVLFG prng;
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
|
||||
/* just one test to see if code is correct (precision is less
|
||||
important here) */
|
||||
err_max = 0;
|
||||
for (it = 0; it < NB_ITS; it++) {
|
||||
/* XXX: use forward transform to generate values */
|
||||
for (i = 0; i < 64; i++)
|
||||
block1[i] = av_lfg_get(&prng) % 256 - 128;
|
||||
block1[0] += 1024;
|
||||
|
||||
for (i = 0; i < 64; i++)
|
||||
block[i] = block1[i];
|
||||
idct248_ref(img_dest1, 8, block);
|
||||
|
||||
for (i = 0; i < 64; i++)
|
||||
block[i] = block1[i];
|
||||
idct248_put(img_dest, 8, block);
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
v = abs((int) img_dest[i] - (int) img_dest1[i]);
|
||||
if (v == 255)
|
||||
printf("%d %d\n", img_dest[i], img_dest1[i]);
|
||||
if (v > err_max)
|
||||
err_max = v;
|
||||
}
|
||||
#if 0
|
||||
printf("ref=\n");
|
||||
for(i=0;i<8;i++) {
|
||||
int j;
|
||||
for(j=0;j<8;j++) {
|
||||
printf(" %3d", img_dest1[i*8+j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("out=\n");
|
||||
for(i=0;i<8;i++) {
|
||||
int j;
|
||||
for(j=0;j<8;j++) {
|
||||
printf(" %3d", img_dest[i*8+j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
printf("%s %s: err_inf=%d\n", 1 ? "IDCT248" : "DCT248", name, err_max);
|
||||
|
||||
if (!speed)
|
||||
return;
|
||||
|
||||
ti = av_gettime_relative();
|
||||
it1 = 0;
|
||||
do {
|
||||
for (it = 0; it < NB_ITS_SPEED; it++) {
|
||||
for (i = 0; i < 64; i++)
|
||||
block[i] = block1[i];
|
||||
idct248_put(img_dest, 8, block);
|
||||
}
|
||||
emms_c();
|
||||
it1 += NB_ITS_SPEED;
|
||||
ti1 = av_gettime_relative() - ti;
|
||||
} while (ti1 < 1000000);
|
||||
|
||||
printf("%s %s: %0.1f kdct/s\n", 1 ? "IDCT248" : "DCT248", name,
|
||||
(double) it1 * 1000.0 / (double) ti1);
|
||||
}
|
||||
|
||||
static void help(void)
|
||||
{
|
||||
printf("dct-test [-i] [<test-number>] [<bits>]\n"
|
||||
"test-number 0 -> test with random matrixes\n"
|
||||
" 1 -> test with random sparse matrixes\n"
|
||||
" 2 -> do 3. test from MPEG-4 std\n"
|
||||
"bits Number of time domain bits to use, 8 is default\n"
|
||||
"-i test IDCT implementations\n"
|
||||
"-4 test IDCT248 implementations\n"
|
||||
"-t speed test\n");
|
||||
}
|
||||
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int test_idct = 0, test_248_dct = 0;
|
||||
int c, i;
|
||||
int test = 1;
|
||||
int speed = 0;
|
||||
int err = 0;
|
||||
int bits=8;
|
||||
|
||||
ff_ref_dct_init();
|
||||
|
||||
for (;;) {
|
||||
c = getopt(argc, argv, "ih4t");
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'i':
|
||||
test_idct = 1;
|
||||
break;
|
||||
case '4':
|
||||
test_248_dct = 1;
|
||||
break;
|
||||
case 't':
|
||||
speed = 1;
|
||||
break;
|
||||
default:
|
||||
case 'h':
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
test = atoi(argv[optind]);
|
||||
if(optind+1 < argc) bits= atoi(argv[optind+1]);
|
||||
|
||||
printf("ffmpeg DCT/IDCT test\n");
|
||||
|
||||
if (test_248_dct) {
|
||||
idct248_error("SIMPLE-C", ff_simple_idct248_put, speed);
|
||||
} else {
|
||||
const int cpu_flags = av_get_cpu_flags();
|
||||
if (test_idct) {
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(idct_tab); i++)
|
||||
err |= dct_error(&idct_tab[i], test, test_idct, speed, bits);
|
||||
|
||||
for (i = 0; idct_tab_arch[i].name; i++)
|
||||
if (!(~cpu_flags & idct_tab_arch[i].cpu_flag))
|
||||
err |= dct_error(&idct_tab_arch[i], test, test_idct, speed, bits);
|
||||
}
|
||||
#if CONFIG_FDCTDSP
|
||||
else {
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(fdct_tab); i++)
|
||||
err |= dct_error(&fdct_tab[i], test, test_idct, speed, bits);
|
||||
|
||||
for (i = 0; fdct_tab_arch[i].name; i++)
|
||||
if (!(~cpu_flags & fdct_tab_arch[i].cpu_flag))
|
||||
err |= dct_error(&fdct_tab_arch[i], test, test_idct, speed, bits);
|
||||
}
|
||||
#endif /* CONFIG_FDCTDSP */
|
||||
}
|
||||
|
||||
if (err)
|
||||
printf("Error: %d.\n", err);
|
||||
|
||||
return !!err;
|
||||
}
|
21
externals/ffmpeg/libavcodec/tests/fft-fixed.c
vendored
Executable file
21
externals/ffmpeg/libavcodec/tests/fft-fixed.c
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define FFT_FLOAT 0
|
||||
#define AVFFT 0
|
||||
#include "fft.c"
|
22
externals/ffmpeg/libavcodec/tests/fft-fixed32.c
vendored
Executable file
22
externals/ffmpeg/libavcodec/tests/fft-fixed32.c
vendored
Executable file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define FFT_FLOAT 0
|
||||
#define FFT_FIXED_32 1
|
||||
#define AVFFT 0
|
||||
#include "fft.c"
|
676
externals/ffmpeg/libavcodec/tests/fft.c
vendored
Executable file
676
externals/ffmpeg/libavcodec/tests/fft.c
vendored
Executable file
@@ -0,0 +1,676 @@
|
||||
/*
|
||||
* (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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* FFT and MDCT tests.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef AVFFT
|
||||
#define AVFFT 0
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/cpu.h"
|
||||
#include "libavutil/lfg.h"
|
||||
#include "libavutil/log.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "libavutil/time.h"
|
||||
|
||||
#if AVFFT
|
||||
#include "libavcodec/avfft.h"
|
||||
#else
|
||||
#include "libavcodec/fft.h"
|
||||
#endif
|
||||
|
||||
#if FFT_FLOAT
|
||||
#include "libavcodec/dct.h"
|
||||
#include "libavcodec/rdft.h"
|
||||
#endif
|
||||
|
||||
/* reference fft */
|
||||
|
||||
#define MUL16(a, b) ((a) * (b))
|
||||
|
||||
#define CMAC(pre, pim, are, aim, bre, bim) \
|
||||
{ \
|
||||
pre += (MUL16(are, bre) - MUL16(aim, bim)); \
|
||||
pim += (MUL16(are, bim) + MUL16(bre, aim)); \
|
||||
}
|
||||
|
||||
#if FFT_FLOAT || AVFFT
|
||||
#define RANGE 1.0
|
||||
#define REF_SCALE(x, bits) (x)
|
||||
#define FMT "%10.6f"
|
||||
#elif FFT_FIXED_32
|
||||
#define RANGE 8388608
|
||||
#define REF_SCALE(x, bits) (x)
|
||||
#define FMT "%6d"
|
||||
#else
|
||||
#define RANGE 16384
|
||||
#define REF_SCALE(x, bits) ((x) / (1 << (bits)))
|
||||
#define FMT "%6d"
|
||||
#endif
|
||||
|
||||
static struct {
|
||||
float re, im;
|
||||
} *exptab;
|
||||
|
||||
static int fft_ref_init(int nbits, int inverse)
|
||||
{
|
||||
int i, n = 1 << nbits;
|
||||
|
||||
exptab = av_malloc_array((n / 2), sizeof(*exptab));
|
||||
if (!exptab)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
for (i = 0; i < (n / 2); i++) {
|
||||
double alpha = 2 * M_PI * (float) i / (float) n;
|
||||
double c1 = cos(alpha), s1 = sin(alpha);
|
||||
if (!inverse)
|
||||
s1 = -s1;
|
||||
exptab[i].re = c1;
|
||||
exptab[i].im = s1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
|
||||
{
|
||||
int i, j;
|
||||
int n = 1 << nbits;
|
||||
int n2 = n >> 1;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
double tmp_re = 0, tmp_im = 0;
|
||||
FFTComplex *q = tab;
|
||||
for (j = 0; j < n; j++) {
|
||||
double s, c;
|
||||
int k = (i * j) & (n - 1);
|
||||
if (k >= n2) {
|
||||
c = -exptab[k - n2].re;
|
||||
s = -exptab[k - n2].im;
|
||||
} else {
|
||||
c = exptab[k].re;
|
||||
s = exptab[k].im;
|
||||
}
|
||||
CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
|
||||
q++;
|
||||
}
|
||||
tabr[i].re = REF_SCALE(tmp_re, nbits);
|
||||
tabr[i].im = REF_SCALE(tmp_im, nbits);
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_MDCT
|
||||
static void imdct_ref(FFTSample *out, FFTSample *in, int nbits)
|
||||
{
|
||||
int i, k, n = 1 << nbits;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
double sum = 0;
|
||||
for (k = 0; k < n / 2; k++) {
|
||||
int a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
|
||||
double f = cos(M_PI * a / (double) (2 * n));
|
||||
sum += f * in[k];
|
||||
}
|
||||
out[i] = REF_SCALE(-sum, nbits - 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE: no normalisation by 1 / N is done */
|
||||
static void mdct_ref(FFTSample *output, FFTSample *input, int nbits)
|
||||
{
|
||||
int i, k, n = 1 << nbits;
|
||||
|
||||
/* do it by hand */
|
||||
for (k = 0; k < n / 2; k++) {
|
||||
double s = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
double a = (2 * M_PI * (2 * i + 1 + n / 2) * (2 * k + 1) / (4 * n));
|
||||
s += input[i] * cos(a);
|
||||
}
|
||||
output[k] = REF_SCALE(s, nbits - 1);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_MDCT */
|
||||
|
||||
#if FFT_FLOAT
|
||||
#if CONFIG_DCT
|
||||
static void idct_ref(FFTSample *output, FFTSample *input, int nbits)
|
||||
{
|
||||
int i, k, n = 1 << nbits;
|
||||
|
||||
/* do it by hand */
|
||||
for (i = 0; i < n; i++) {
|
||||
double s = 0.5 * input[0];
|
||||
for (k = 1; k < n; k++) {
|
||||
double a = M_PI * k * (i + 0.5) / n;
|
||||
s += input[k] * cos(a);
|
||||
}
|
||||
output[i] = 2 * s / n;
|
||||
}
|
||||
}
|
||||
|
||||
static void dct_ref(FFTSample *output, FFTSample *input, int nbits)
|
||||
{
|
||||
int i, k, n = 1 << nbits;
|
||||
|
||||
/* do it by hand */
|
||||
for (k = 0; k < n; k++) {
|
||||
double s = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
double a = M_PI * k * (i + 0.5) / n;
|
||||
s += input[i] * cos(a);
|
||||
}
|
||||
output[k] = s;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_DCT */
|
||||
#endif /* FFT_FLOAT */
|
||||
|
||||
static FFTSample frandom(AVLFG *prng)
|
||||
{
|
||||
return (int16_t) av_lfg_get(prng) / 32768.0 * RANGE;
|
||||
}
|
||||
|
||||
static int check_diff(FFTSample *tab1, FFTSample *tab2, int n, double scale)
|
||||
{
|
||||
int i, err = 0;
|
||||
double error = 0, max = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
double e = fabs(tab1[i] - (tab2[i] / scale)) / RANGE;
|
||||
if (e >= 1e-3) {
|
||||
av_log(NULL, AV_LOG_ERROR, "ERROR %5d: "FMT" "FMT"\n",
|
||||
i, tab1[i], tab2[i]);
|
||||
err = 1;
|
||||
}
|
||||
error += e * e;
|
||||
if (e > max)
|
||||
max = e;
|
||||
}
|
||||
av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error / n));
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline void fft_init(FFTContext **s, int nbits, int inverse)
|
||||
{
|
||||
#if AVFFT
|
||||
*s = av_fft_init(nbits, inverse);
|
||||
#else
|
||||
ff_fft_init(*s, nbits, inverse);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void mdct_init(FFTContext **s, int nbits, int inverse, double scale)
|
||||
{
|
||||
#if AVFFT
|
||||
*s = av_mdct_init(nbits, inverse, scale);
|
||||
#else
|
||||
ff_mdct_init(*s, nbits, inverse, scale);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
#if AVFFT
|
||||
av_mdct_calc(s, output, input);
|
||||
#else
|
||||
s->mdct_calc(s, output, input);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void imdct_calc(struct FFTContext *s, FFTSample *output, const FFTSample *input)
|
||||
{
|
||||
#if AVFFT
|
||||
av_imdct_calc(s, output, input);
|
||||
#else
|
||||
s->imdct_calc(s, output, input);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void fft_permute(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
#if AVFFT
|
||||
av_fft_permute(s, z);
|
||||
#else
|
||||
s->fft_permute(s, z);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void fft_calc(FFTContext *s, FFTComplex *z)
|
||||
{
|
||||
#if AVFFT
|
||||
av_fft_calc(s, z);
|
||||
#else
|
||||
s->fft_calc(s, z);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void mdct_end(FFTContext *s)
|
||||
{
|
||||
#if AVFFT
|
||||
av_mdct_end(s);
|
||||
#else
|
||||
ff_mdct_end(s);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void fft_end(FFTContext *s)
|
||||
{
|
||||
#if AVFFT
|
||||
av_fft_end(s);
|
||||
#else
|
||||
ff_fft_end(s);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FFT_FLOAT
|
||||
static inline void rdft_init(RDFTContext **r, int nbits, enum RDFTransformType trans)
|
||||
{
|
||||
#if AVFFT
|
||||
*r = av_rdft_init(nbits, trans);
|
||||
#else
|
||||
ff_rdft_init(*r, nbits, trans);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void dct_init(DCTContext **d, int nbits, enum DCTTransformType trans)
|
||||
{
|
||||
#if AVFFT
|
||||
*d = av_dct_init(nbits, trans);
|
||||
#else
|
||||
ff_dct_init(*d, nbits, trans);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void rdft_calc(RDFTContext *r, FFTSample *tab)
|
||||
{
|
||||
#if AVFFT
|
||||
av_rdft_calc(r, tab);
|
||||
#else
|
||||
r->rdft_calc(r, tab);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void dct_calc(DCTContext *d, FFTSample *data)
|
||||
{
|
||||
#if AVFFT
|
||||
av_dct_calc(d, data);
|
||||
#else
|
||||
d->dct_calc(d, data);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void rdft_end(RDFTContext *r)
|
||||
{
|
||||
#if AVFFT
|
||||
av_rdft_end(r);
|
||||
#else
|
||||
ff_rdft_end(r);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void dct_end(DCTContext *d)
|
||||
{
|
||||
#if AVFFT
|
||||
av_dct_end(d);
|
||||
#else
|
||||
ff_dct_end(d);
|
||||
#endif
|
||||
}
|
||||
#endif /* FFT_FLOAT */
|
||||
|
||||
static void help(void)
|
||||
{
|
||||
av_log(NULL, AV_LOG_INFO,
|
||||
"usage: fft-test [-h] [-s] [-i] [-n b]\n"
|
||||
"-h print this help\n"
|
||||
"-s speed test\n"
|
||||
"-m (I)MDCT test\n"
|
||||
"-d (I)DCT test\n"
|
||||
"-r (I)RDFT test\n"
|
||||
"-i inverse transform test\n"
|
||||
"-n b set the transform size to 2^b\n"
|
||||
"-f x set scale factor for output data of (I)MDCT to x\n");
|
||||
}
|
||||
|
||||
enum tf_transform {
|
||||
TRANSFORM_FFT,
|
||||
TRANSFORM_MDCT,
|
||||
TRANSFORM_RDFT,
|
||||
TRANSFORM_DCT,
|
||||
};
|
||||
|
||||
#if !HAVE_GETOPT
|
||||
#include "compat/getopt.c"
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FFTComplex *tab, *tab1, *tab_ref;
|
||||
FFTSample *tab2;
|
||||
enum tf_transform transform = TRANSFORM_FFT;
|
||||
FFTContext *m, *s;
|
||||
#if FFT_FLOAT
|
||||
RDFTContext *r;
|
||||
DCTContext *d;
|
||||
#endif /* FFT_FLOAT */
|
||||
int it, i, err = 1;
|
||||
int do_speed = 0, do_inverse = 0;
|
||||
int fft_nbits = 9, fft_size;
|
||||
double scale = 1.0;
|
||||
AVLFG prng;
|
||||
|
||||
#if !AVFFT
|
||||
s = av_mallocz(sizeof(*s));
|
||||
m = av_mallocz(sizeof(*m));
|
||||
#endif
|
||||
|
||||
#if !AVFFT && FFT_FLOAT
|
||||
r = av_mallocz(sizeof(*r));
|
||||
d = av_mallocz(sizeof(*d));
|
||||
#endif
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
|
||||
for (;;) {
|
||||
int c = getopt(argc, argv, "hsimrdn:f:c:");
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'h':
|
||||
help();
|
||||
return 1;
|
||||
case 's':
|
||||
do_speed = 1;
|
||||
break;
|
||||
case 'i':
|
||||
do_inverse = 1;
|
||||
break;
|
||||
case 'm':
|
||||
transform = TRANSFORM_MDCT;
|
||||
break;
|
||||
case 'r':
|
||||
transform = TRANSFORM_RDFT;
|
||||
break;
|
||||
case 'd':
|
||||
transform = TRANSFORM_DCT;
|
||||
break;
|
||||
case 'n':
|
||||
fft_nbits = atoi(optarg);
|
||||
break;
|
||||
case 'f':
|
||||
scale = atof(optarg);
|
||||
break;
|
||||
case 'c':
|
||||
{
|
||||
unsigned cpuflags = av_get_cpu_flags();
|
||||
|
||||
if (av_parse_cpu_caps(&cpuflags, optarg) < 0)
|
||||
return 1;
|
||||
|
||||
av_force_cpu_flags(cpuflags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fft_size = 1 << fft_nbits;
|
||||
tab = av_malloc_array(fft_size, sizeof(FFTComplex));
|
||||
tab1 = av_malloc_array(fft_size, sizeof(FFTComplex));
|
||||
tab_ref = av_malloc_array(fft_size, sizeof(FFTComplex));
|
||||
tab2 = av_malloc_array(fft_size, sizeof(FFTSample));
|
||||
|
||||
if (!(tab && tab1 && tab_ref && tab2))
|
||||
goto cleanup;
|
||||
|
||||
switch (transform) {
|
||||
#if CONFIG_MDCT
|
||||
case TRANSFORM_MDCT:
|
||||
av_log(NULL, AV_LOG_INFO, "Scale factor is set to %f\n", scale);
|
||||
if (do_inverse)
|
||||
av_log(NULL, AV_LOG_INFO, "IMDCT");
|
||||
else
|
||||
av_log(NULL, AV_LOG_INFO, "MDCT");
|
||||
mdct_init(&m, fft_nbits, do_inverse, scale);
|
||||
break;
|
||||
#endif /* CONFIG_MDCT */
|
||||
case TRANSFORM_FFT:
|
||||
if (do_inverse)
|
||||
av_log(NULL, AV_LOG_INFO, "IFFT");
|
||||
else
|
||||
av_log(NULL, AV_LOG_INFO, "FFT");
|
||||
fft_init(&s, fft_nbits, do_inverse);
|
||||
if ((err = fft_ref_init(fft_nbits, do_inverse)) < 0)
|
||||
goto cleanup;
|
||||
break;
|
||||
#if FFT_FLOAT
|
||||
# if CONFIG_RDFT
|
||||
case TRANSFORM_RDFT:
|
||||
if (do_inverse)
|
||||
av_log(NULL, AV_LOG_INFO, "IDFT_C2R");
|
||||
else
|
||||
av_log(NULL, AV_LOG_INFO, "DFT_R2C");
|
||||
rdft_init(&r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C);
|
||||
if ((err = fft_ref_init(fft_nbits, do_inverse)) < 0)
|
||||
goto cleanup;
|
||||
break;
|
||||
# endif /* CONFIG_RDFT */
|
||||
# if CONFIG_DCT
|
||||
case TRANSFORM_DCT:
|
||||
if (do_inverse)
|
||||
av_log(NULL, AV_LOG_INFO, "DCT_III");
|
||||
else
|
||||
av_log(NULL, AV_LOG_INFO, "DCT_II");
|
||||
dct_init(&d, fft_nbits, do_inverse ? DCT_III : DCT_II);
|
||||
break;
|
||||
# endif /* CONFIG_DCT */
|
||||
#endif /* FFT_FLOAT */
|
||||
default:
|
||||
av_log(NULL, AV_LOG_ERROR, "Requested transform not supported\n");
|
||||
goto cleanup;
|
||||
}
|
||||
av_log(NULL, AV_LOG_INFO, " %d test\n", fft_size);
|
||||
|
||||
/* generate random data */
|
||||
|
||||
for (i = 0; i < fft_size; i++) {
|
||||
tab1[i].re = frandom(&prng);
|
||||
tab1[i].im = frandom(&prng);
|
||||
}
|
||||
|
||||
/* checking result */
|
||||
av_log(NULL, AV_LOG_INFO, "Checking...\n");
|
||||
|
||||
switch (transform) {
|
||||
#if CONFIG_MDCT
|
||||
case TRANSFORM_MDCT:
|
||||
if (do_inverse) {
|
||||
imdct_ref(&tab_ref->re, &tab1->re, fft_nbits);
|
||||
imdct_calc(m, tab2, &tab1->re);
|
||||
err = check_diff(&tab_ref->re, tab2, fft_size, scale);
|
||||
} else {
|
||||
mdct_ref(&tab_ref->re, &tab1->re, fft_nbits);
|
||||
mdct_calc(m, tab2, &tab1->re);
|
||||
err = check_diff(&tab_ref->re, tab2, fft_size / 2, scale);
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_MDCT */
|
||||
case TRANSFORM_FFT:
|
||||
memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
|
||||
fft_permute(s, tab);
|
||||
fft_calc(s, tab);
|
||||
|
||||
fft_ref(tab_ref, tab1, fft_nbits);
|
||||
err = check_diff(&tab_ref->re, &tab->re, fft_size * 2, 1.0);
|
||||
break;
|
||||
#if FFT_FLOAT
|
||||
#if CONFIG_RDFT
|
||||
case TRANSFORM_RDFT:
|
||||
{
|
||||
int fft_size_2 = fft_size >> 1;
|
||||
if (do_inverse) {
|
||||
tab1[0].im = 0;
|
||||
tab1[fft_size_2].im = 0;
|
||||
for (i = 1; i < fft_size_2; i++) {
|
||||
tab1[fft_size_2 + i].re = tab1[fft_size_2 - i].re;
|
||||
tab1[fft_size_2 + i].im = -tab1[fft_size_2 - i].im;
|
||||
}
|
||||
|
||||
memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
|
||||
tab2[1] = tab1[fft_size_2].re;
|
||||
|
||||
rdft_calc(r, tab2);
|
||||
fft_ref(tab_ref, tab1, fft_nbits);
|
||||
for (i = 0; i < fft_size; i++) {
|
||||
tab[i].re = tab2[i];
|
||||
tab[i].im = 0;
|
||||
}
|
||||
err = check_diff(&tab_ref->re, &tab->re, fft_size * 2, 0.5);
|
||||
} else {
|
||||
for (i = 0; i < fft_size; i++) {
|
||||
tab2[i] = tab1[i].re;
|
||||
tab1[i].im = 0;
|
||||
}
|
||||
rdft_calc(r, tab2);
|
||||
fft_ref(tab_ref, tab1, fft_nbits);
|
||||
tab_ref[0].im = tab_ref[fft_size_2].re;
|
||||
err = check_diff(&tab_ref->re, tab2, fft_size, 1.0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_RDFT */
|
||||
#if CONFIG_DCT
|
||||
case TRANSFORM_DCT:
|
||||
memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
|
||||
dct_calc(d, &tab->re);
|
||||
if (do_inverse)
|
||||
idct_ref(&tab_ref->re, &tab1->re, fft_nbits);
|
||||
else
|
||||
dct_ref(&tab_ref->re, &tab1->re, fft_nbits);
|
||||
err = check_diff(&tab_ref->re, &tab->re, fft_size, 1.0);
|
||||
break;
|
||||
#endif /* CONFIG_DCT */
|
||||
#endif /* FFT_FLOAT */
|
||||
}
|
||||
|
||||
/* do a speed test */
|
||||
|
||||
if (do_speed) {
|
||||
int64_t time_start, duration;
|
||||
int nb_its;
|
||||
|
||||
av_log(NULL, AV_LOG_INFO, "Speed test...\n");
|
||||
/* we measure during about 1 seconds */
|
||||
nb_its = 1;
|
||||
for (;;) {
|
||||
time_start = av_gettime_relative();
|
||||
for (it = 0; it < nb_its; it++) {
|
||||
switch (transform) {
|
||||
case TRANSFORM_MDCT:
|
||||
if (do_inverse)
|
||||
imdct_calc(m, &tab->re, &tab1->re);
|
||||
else
|
||||
mdct_calc(m, &tab->re, &tab1->re);
|
||||
break;
|
||||
case TRANSFORM_FFT:
|
||||
memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
|
||||
fft_calc(s, tab);
|
||||
break;
|
||||
#if FFT_FLOAT
|
||||
case TRANSFORM_RDFT:
|
||||
memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
|
||||
rdft_calc(r, tab2);
|
||||
break;
|
||||
case TRANSFORM_DCT:
|
||||
memcpy(tab2, tab1, fft_size * sizeof(FFTSample));
|
||||
dct_calc(d, tab2);
|
||||
break;
|
||||
#endif /* FFT_FLOAT */
|
||||
}
|
||||
}
|
||||
duration = av_gettime_relative() - time_start;
|
||||
if (duration >= 1000000)
|
||||
break;
|
||||
nb_its *= 2;
|
||||
}
|
||||
av_log(NULL, AV_LOG_INFO,
|
||||
"time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
|
||||
(double) duration / nb_its,
|
||||
(double) duration / 1000000.0,
|
||||
nb_its);
|
||||
}
|
||||
|
||||
switch (transform) {
|
||||
#if CONFIG_MDCT
|
||||
case TRANSFORM_MDCT:
|
||||
mdct_end(m);
|
||||
break;
|
||||
#endif /* CONFIG_MDCT */
|
||||
case TRANSFORM_FFT:
|
||||
fft_end(s);
|
||||
break;
|
||||
#if FFT_FLOAT
|
||||
# if CONFIG_RDFT
|
||||
case TRANSFORM_RDFT:
|
||||
rdft_end(r);
|
||||
break;
|
||||
# endif /* CONFIG_RDFT */
|
||||
# if CONFIG_DCT
|
||||
case TRANSFORM_DCT:
|
||||
dct_end(d);
|
||||
break;
|
||||
# endif /* CONFIG_DCT */
|
||||
#endif /* FFT_FLOAT */
|
||||
}
|
||||
|
||||
cleanup:
|
||||
av_free(tab);
|
||||
av_free(tab1);
|
||||
av_free(tab2);
|
||||
av_free(tab_ref);
|
||||
av_free(exptab);
|
||||
|
||||
#if !AVFFT
|
||||
av_free(s);
|
||||
av_free(m);
|
||||
#endif
|
||||
|
||||
#if !AVFFT && FFT_FLOAT
|
||||
av_free(r);
|
||||
av_free(d);
|
||||
#endif
|
||||
|
||||
if (err)
|
||||
printf("Error: %d.\n", err);
|
||||
|
||||
return !!err;
|
||||
}
|
118
externals/ffmpeg/libavcodec/tests/golomb.c
vendored
Executable file
118
externals/ffmpeg/libavcodec/tests/golomb.c
vendored
Executable file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libavutil/internal.h"
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
#include "libavcodec/get_bits.h"
|
||||
#include "libavcodec/golomb.h"
|
||||
#include "libavcodec/put_bits.h"
|
||||
|
||||
#define COUNT 8191
|
||||
#define SIZE (COUNT * 4)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, ret = 0;
|
||||
uint8_t *temp;
|
||||
PutBitContext pb;
|
||||
GetBitContext gb;
|
||||
|
||||
temp = av_malloc(SIZE);
|
||||
if (!temp)
|
||||
return 2;
|
||||
|
||||
init_put_bits(&pb, temp, SIZE);
|
||||
for (i = 0; i < COUNT; i++)
|
||||
set_ue_golomb(&pb, i);
|
||||
flush_put_bits(&pb);
|
||||
|
||||
init_get_bits(&gb, temp, 8 * SIZE);
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
int j, s = show_bits(&gb, 25);
|
||||
|
||||
j = get_ue_golomb(&gb);
|
||||
if (j != i) {
|
||||
fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n",
|
||||
i, j, s);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#define EXTEND(i) ((i) << 3 | (i) & 7)
|
||||
init_put_bits(&pb, temp, SIZE);
|
||||
for (i = 0; i < COUNT; i++)
|
||||
set_ue_golomb(&pb, EXTEND(i));
|
||||
flush_put_bits(&pb);
|
||||
|
||||
init_get_bits(&gb, temp, 8 * SIZE);
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
int j, s = show_bits_long(&gb, 32);
|
||||
|
||||
j = get_ue_golomb_long(&gb);
|
||||
if (j != EXTEND(i)) {
|
||||
fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. "
|
||||
"bits: %8x\n", EXTEND(i), j, s);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#define EXTEND_L(i) ((i) << 4 | (i) & 15)
|
||||
init_put_bits(&pb, temp, SIZE);
|
||||
for (i = 0; i < COUNT; i++)
|
||||
set_ue_golomb_long(&pb, EXTEND_L(i));
|
||||
flush_put_bits(&pb);
|
||||
|
||||
init_get_bits(&gb, temp, 8 * SIZE);
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
int j, s = show_bits_long(&gb, 32);
|
||||
|
||||
j = get_ue_golomb_long(&gb);
|
||||
if (j != EXTEND_L(i)) {
|
||||
fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. "
|
||||
"bits: %8x\n", EXTEND_L(i), j, s);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
init_put_bits(&pb, temp, SIZE);
|
||||
for (i = 0; i < COUNT; i++)
|
||||
set_se_golomb(&pb, i - COUNT / 2);
|
||||
flush_put_bits(&pb);
|
||||
|
||||
init_get_bits(&gb, temp, 8 * SIZE);
|
||||
for (i = 0; i < COUNT; i++) {
|
||||
int j, s = show_bits(&gb, 25);
|
||||
|
||||
j = get_se_golomb(&gb);
|
||||
if (j != i - COUNT / 2) {
|
||||
fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n",
|
||||
i - COUNT / 2, j, s);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_free(temp);
|
||||
|
||||
return ret;
|
||||
}
|
235
externals/ffmpeg/libavcodec/tests/h264_levels.c
vendored
Executable file
235
externals/ffmpeg/libavcodec/tests/h264_levels.c
vendored
Executable file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* 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/common.h"
|
||||
#include "libavcodec/h264_levels.h"
|
||||
|
||||
static const struct {
|
||||
int width;
|
||||
int height;
|
||||
int level_idc;
|
||||
} test_sizes[] = {
|
||||
// First level usable at some standard sizes.
|
||||
// (From H.264 table A-6.)
|
||||
{ 176, 144, 10 }, // QCIF
|
||||
{ 352, 288, 11 }, // CIF
|
||||
{ 640, 480, 22 }, // VGA
|
||||
{ 720, 480, 22 }, // NTSC
|
||||
{ 720, 576, 22 }, // PAL
|
||||
{ 800, 600, 31 }, // SVGA
|
||||
{ 1280, 720, 31 }, // 720p
|
||||
{ 1280, 1024, 32 }, // SXGA
|
||||
{ 1920, 1080, 40 }, // 1080p
|
||||
{ 2048, 1080, 42 }, // 2Kx1080
|
||||
{ 2048, 1536, 50 }, // 4XGA
|
||||
{ 3840, 2160, 51 }, // 4K
|
||||
{ 7680, 4320, 60 }, // 8K
|
||||
|
||||
// Overly wide or tall sizes.
|
||||
{ 1, 256, 10 },
|
||||
{ 1, 512, 11 },
|
||||
{ 1, 1024, 21 },
|
||||
{ 1, 1808, 22 },
|
||||
{ 1, 1824, 31 },
|
||||
{ 256, 1, 10 },
|
||||
{ 512, 1, 11 },
|
||||
{ 1024, 1, 21 },
|
||||
{ 1808, 1, 22 },
|
||||
{ 1824, 1, 31 },
|
||||
{ 512, 4096, 40 },
|
||||
{ 256, 4112, 42 },
|
||||
{ 8688, 1024, 51 },
|
||||
{ 8704, 512, 60 },
|
||||
{ 16880, 1, 60 },
|
||||
{ 16896, 1, 0 },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
int width;
|
||||
int height;
|
||||
int framerate;
|
||||
int level_idc;
|
||||
} test_framerate[] = {
|
||||
// Some typical sizes and frame rates.
|
||||
// (From H.264 table A-1 and table A-6)
|
||||
{ 176, 144, 15, 10 },
|
||||
{ 176, 144, 16, 11 },
|
||||
{ 320, 240, 10, 11 },
|
||||
{ 320, 240, 20, 12 },
|
||||
{ 320, 240, 40, 21 },
|
||||
{ 352, 288, 30, 13 },
|
||||
{ 352, 288, 51, 22 },
|
||||
{ 352, 576, 25, 21 },
|
||||
{ 352, 576, 26, 30 },
|
||||
{ 640, 480, 33, 30 },
|
||||
{ 640, 480, 34, 31 },
|
||||
{ 720, 480, 50, 31 },
|
||||
{ 720, 576, 25, 30 },
|
||||
{ 800, 600, 55, 31 },
|
||||
{ 1024, 768, 35, 31 },
|
||||
{ 1024, 768, 70, 32 },
|
||||
{ 1280, 720, 30, 31 },
|
||||
{ 1280, 720, 31, 32 },
|
||||
{ 1280, 960, 45, 32 },
|
||||
{ 1280, 960, 46, 40 },
|
||||
{ 1280, 1024, 42, 32 },
|
||||
{ 1600, 1200, 32, 40 },
|
||||
{ 1600, 1200, 33, 42 },
|
||||
{ 1920, 1088, 30, 40 },
|
||||
{ 1920, 1088, 55, 42 },
|
||||
{ 2048, 1024, 30, 40 },
|
||||
{ 2048, 1024, 62, 42 },
|
||||
{ 2048, 1088, 60, 42 },
|
||||
{ 3680, 1536, 26, 50 },
|
||||
{ 4096, 2048, 30, 51 },
|
||||
{ 4096, 2048, 59, 52 },
|
||||
{ 4096, 2160, 60, 52 },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
int width;
|
||||
int height;
|
||||
int dpb_size;
|
||||
int level_idc;
|
||||
} test_dpb[] = {
|
||||
// First level usable for some DPB sizes.
|
||||
// (From H.264 table A-7.)
|
||||
{ 176, 144, 4, 10 },
|
||||
{ 176, 144, 8, 11 },
|
||||
{ 176, 144, 16, 12 },
|
||||
{ 1280, 720, 1, 31 },
|
||||
{ 1280, 720, 5, 31 },
|
||||
{ 1280, 720, 9, 40 },
|
||||
{ 1280, 720, 10, 50 },
|
||||
{ 1920, 1080, 1, 40 },
|
||||
{ 1920, 1080, 5, 50 },
|
||||
{ 1920, 1080, 13, 50 },
|
||||
{ 1920, 1080, 14, 51 },
|
||||
{ 3840, 2160, 5, 51 },
|
||||
{ 3840, 2160, 6, 60 },
|
||||
{ 3840, 2160, 16, 60 },
|
||||
{ 7680, 4320, 5, 60 },
|
||||
{ 7680, 4320, 6, 0 },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
int64_t bitrate;
|
||||
int profile_idc;
|
||||
int level_idc;
|
||||
} test_bitrate[] = {
|
||||
// Values where profile affects level at a given bitrate.
|
||||
{ 2500000, 77, 21 },
|
||||
{ 2500000, 100, 20 },
|
||||
{ 2500000, 244, 13 },
|
||||
{ 100000000, 77, 50 },
|
||||
{ 100000000, 100, 50 },
|
||||
{ 100000000, 244, 41 },
|
||||
{ 999999999, 77, 0 },
|
||||
{ 999999999, 100, 62 },
|
||||
// Check level 1b.
|
||||
{ 32 * 1200, 66, 10 },
|
||||
{ 32 * 1500, 100, 10 },
|
||||
{ 96 * 1200, 66, 11 },
|
||||
{ 96 * 1500, 100, 9 },
|
||||
{ 144 * 1200, 66, 11 },
|
||||
{ 144 * 1500, 100, 11 },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
int profile_idc;
|
||||
int64_t bitrate;
|
||||
int width;
|
||||
int height;
|
||||
int dpb_frames;
|
||||
int level_idc;
|
||||
} test_all[] = {
|
||||
{ "Bluray 1080p 40Mb/s", 100, 40000000, 1920, 1080, 4, 41 },
|
||||
{ "Bluray 1080p 24Mb/s", 100, 24000000, 1920, 1080, 4, 40 },
|
||||
{ "Bluray 720p 40Mb/s", 100, 40000000, 1280, 720, 6, 41 },
|
||||
{ "Bluray 720p 24Mb/s", 100, 24000000, 1280, 720, 6, 40 },
|
||||
{ "Bluray PAL 40Mb/s", 100, 40000000, 720, 576, 6, 41 },
|
||||
{ "Bluray PAL 24Mb/s", 100, 24000000, 720, 576, 6, 32 },
|
||||
{ "Bluray PAL 16Mb/s", 100, 16800000, 720, 576, 6, 31 },
|
||||
{ "Bluray PAL 12Mb/s", 100, 12000000, 720, 576, 5, 30 },
|
||||
{ "Bluray NTSC 40Mb/s", 100, 40000000, 720, 480, 6, 41 },
|
||||
{ "Bluray NTSC 24Mb/s", 100, 24000000, 720, 480, 6, 32 },
|
||||
{ "Bluray NTSC 16Mb/s", 100, 16800000, 720, 480, 6, 31 },
|
||||
{ "Bluray NTSC 12Mb/s", 100, 12000000, 720, 480, 6, 30 },
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const H264LevelDescriptor *level;
|
||||
int i;
|
||||
|
||||
#define CHECK(expected, format, ...) do { \
|
||||
if (expected ? (!level || level->level_idc != expected) \
|
||||
: !!level) { \
|
||||
av_log(NULL, AV_LOG_ERROR, "Incorrect level for " \
|
||||
format ": expected %d, got %d.\n", __VA_ARGS__, \
|
||||
expected, level ? level->level_idc : -1); \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) {
|
||||
level = ff_h264_guess_level(0, 0, 0, test_sizes[i].width,
|
||||
test_sizes[i].height, 0);
|
||||
CHECK(test_sizes[i].level_idc, "size %dx%d",
|
||||
test_sizes[i].width, test_sizes[i].height);
|
||||
}
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_framerate); i++) {
|
||||
level = ff_h264_guess_level(0, 0, test_framerate[i].framerate,
|
||||
test_framerate[i].width,
|
||||
test_framerate[i].height, 0);
|
||||
CHECK(test_framerate[i].level_idc, "framerate %d, size %dx%d",
|
||||
test_framerate[i].framerate, test_framerate[i].width,
|
||||
test_framerate[i].height);
|
||||
}
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_dpb); i++) {
|
||||
level = ff_h264_guess_level(0, 0, 0, test_dpb[i].width,
|
||||
test_dpb[i].height,
|
||||
test_dpb[i].dpb_size);
|
||||
CHECK(test_dpb[i].level_idc, "size %dx%d dpb %d",
|
||||
test_dpb[i].width, test_dpb[i].height,
|
||||
test_dpb[i].dpb_size);
|
||||
}
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_bitrate); i++) {
|
||||
level = ff_h264_guess_level(test_bitrate[i].profile_idc,
|
||||
test_bitrate[i].bitrate,
|
||||
0, 0, 0, 0);
|
||||
CHECK(test_bitrate[i].level_idc, "bitrate %"PRId64" profile %d",
|
||||
test_bitrate[i].bitrate, test_bitrate[i].profile_idc);
|
||||
}
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_all); i++) {
|
||||
level = ff_h264_guess_level(test_all[i].profile_idc,
|
||||
test_all[i].bitrate,
|
||||
0,
|
||||
test_all[i].width,
|
||||
test_all[i].height,
|
||||
test_all[i].dpb_frames);
|
||||
CHECK(test_all[i].level_idc, "%s", test_all[i].name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
297
externals/ffmpeg/libavcodec/tests/h265_levels.c
vendored
Executable file
297
externals/ffmpeg/libavcodec/tests/h265_levels.c
vendored
Executable file
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
* 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/common.h"
|
||||
#include "libavcodec/h265_profile_level.h"
|
||||
|
||||
static const struct {
|
||||
int width;
|
||||
int height;
|
||||
int level_idc;
|
||||
} test_sizes[] = {
|
||||
// First level usable at standard sizes, from H.265 table A.9.
|
||||
{ 176, 144, 30 }, // QCIF
|
||||
{ 352, 288, 60 }, // CIF
|
||||
{ 640, 480, 90 }, // VGA
|
||||
{ 720, 480, 90 }, // NTSC
|
||||
{ 720, 576, 90 }, // PAL
|
||||
{ 1024, 768, 93 }, // XGA
|
||||
{ 1280, 720, 93 }, // 720p
|
||||
{ 1280, 1024, 120 }, // SXGA
|
||||
{ 1920, 1080, 120 }, // 1080p
|
||||
{ 2048, 1080, 120 }, // 2Kx1080
|
||||
{ 2048, 1536, 150 }, // 4XGA
|
||||
{ 3840, 2160, 150 }, // 4K
|
||||
{ 7680, 4320, 180 }, // 8K
|
||||
|
||||
// Overly wide or tall sizes.
|
||||
{ 1, 512, 30 },
|
||||
{ 1, 1024, 63 },
|
||||
{ 1, 2048, 90 },
|
||||
{ 1, 4096, 120 },
|
||||
{ 1, 8192, 150 },
|
||||
{ 1, 16384, 180 },
|
||||
{ 1, 32768, 0 },
|
||||
{ 512, 1, 30 },
|
||||
{ 1024, 1, 63 },
|
||||
{ 2048, 1, 90 },
|
||||
{ 4096, 1, 120 },
|
||||
{ 8192, 1, 150 },
|
||||
{ 16384, 1, 180 },
|
||||
{ 32768, 1, 0 },
|
||||
{ 2800, 256, 93 },
|
||||
{ 2816, 128, 120 },
|
||||
{ 256, 4208, 120 },
|
||||
{ 128, 4224, 150 },
|
||||
{ 8432, 256, 150 },
|
||||
{ 8448, 128, 180 },
|
||||
{ 256, 16880, 180 },
|
||||
{ 128, 16896, 0 },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
int width;
|
||||
int height;
|
||||
int dpb_size;
|
||||
int level_idc;
|
||||
} test_dpb[] = {
|
||||
// First level usable for some DPB sizes.
|
||||
|
||||
// L1: 176 * 144 = 25344 <= 36864 * 3/4 = 27648
|
||||
// L2: <= 122880 * 1/4 = 30720
|
||||
{ 176, 144, 8, 30 },
|
||||
{ 176, 144, 9, 60 },
|
||||
|
||||
// L2: 352 * 288 = 101376 <= 122880
|
||||
// L2.1: <= 245760 * 1/2 = 122880
|
||||
// L3: <= 552960 * 1/4 = 138240
|
||||
{ 352, 288, 6, 60 },
|
||||
{ 352, 288, 7, 63 },
|
||||
{ 352, 288, 13, 90 },
|
||||
|
||||
// L3.1: 1280 * 720 = 921600 <= 983040
|
||||
// L4: <= 2228224 * 1/2 = 1114112
|
||||
// L5: <= 8912896 * 1/4 = 2228224
|
||||
{ 1280, 720, 6, 93 },
|
||||
{ 1280, 720, 12, 120 },
|
||||
{ 1280, 720, 16, 150 },
|
||||
|
||||
// L5: 3840 * 2160 = 8294400 <= 8912896
|
||||
// L6: <= 35651584 * 1/4 = 8912896
|
||||
{ 3840, 2160, 6, 150 },
|
||||
{ 3840, 2160, 7, 180 },
|
||||
{ 3840, 2160, 16, 180 },
|
||||
};
|
||||
|
||||
static const H265RawProfileTierLevel profile_main = {
|
||||
// CpbNalFactor = 1100
|
||||
.general_profile_space = 0,
|
||||
.general_profile_idc = 1,
|
||||
.general_tier_flag = 0,
|
||||
.general_profile_compatibility_flag[1] = 1,
|
||||
};
|
||||
|
||||
static const H265RawProfileTierLevel profile_main_12 = {
|
||||
// CpbNalFactor = 1650
|
||||
.general_profile_space = 0,
|
||||
.general_profile_idc = 4,
|
||||
.general_tier_flag = 0,
|
||||
.general_profile_compatibility_flag[4] = 1,
|
||||
.general_max_12bit_constraint_flag = 1,
|
||||
.general_max_10bit_constraint_flag = 0,
|
||||
.general_max_8bit_constraint_flag = 0,
|
||||
.general_max_422chroma_constraint_flag = 1,
|
||||
.general_max_420chroma_constraint_flag = 1,
|
||||
.general_max_monochrome_constraint_flag = 0,
|
||||
.general_intra_constraint_flag = 0,
|
||||
.general_one_picture_only_constraint_flag = 0,
|
||||
.general_lower_bit_rate_constraint_flag = 1,
|
||||
};
|
||||
|
||||
static const H265RawProfileTierLevel profile_main_422_12_intra = {
|
||||
// CpbNalFactor = 2200
|
||||
.general_profile_space = 0,
|
||||
.general_profile_idc = 4,
|
||||
.general_tier_flag = 0,
|
||||
.general_profile_compatibility_flag[4] = 1,
|
||||
.general_max_12bit_constraint_flag = 1,
|
||||
.general_max_10bit_constraint_flag = 0,
|
||||
.general_max_8bit_constraint_flag = 0,
|
||||
.general_max_422chroma_constraint_flag = 1,
|
||||
.general_max_420chroma_constraint_flag = 0,
|
||||
.general_max_monochrome_constraint_flag = 0,
|
||||
.general_intra_constraint_flag = 1,
|
||||
.general_one_picture_only_constraint_flag = 0,
|
||||
};
|
||||
|
||||
static const H265RawProfileTierLevel profile_ht_444_14 = {
|
||||
// CpbNalFactor = 3850
|
||||
.general_profile_space = 0,
|
||||
.general_profile_idc = 5,
|
||||
.general_tier_flag = 0,
|
||||
.general_profile_compatibility_flag[5] = 1,
|
||||
.general_max_14bit_constraint_flag = 1,
|
||||
.general_max_12bit_constraint_flag = 0,
|
||||
.general_max_10bit_constraint_flag = 0,
|
||||
.general_max_8bit_constraint_flag = 0,
|
||||
.general_max_422chroma_constraint_flag = 0,
|
||||
.general_max_420chroma_constraint_flag = 0,
|
||||
.general_max_monochrome_constraint_flag = 0,
|
||||
.general_intra_constraint_flag = 0,
|
||||
.general_one_picture_only_constraint_flag = 0,
|
||||
.general_lower_bit_rate_constraint_flag = 1,
|
||||
};
|
||||
|
||||
static const H265RawProfileTierLevel profile_main_high_tier = {
|
||||
// CpbNalFactor = 1100
|
||||
.general_profile_space = 0,
|
||||
.general_profile_idc = 1,
|
||||
.general_tier_flag = 1,
|
||||
.general_profile_compatibility_flag[1] = 1,
|
||||
};
|
||||
|
||||
static const struct {
|
||||
int64_t bitrate;
|
||||
const H265RawProfileTierLevel *ptl;
|
||||
int level_idc;
|
||||
} test_bitrate[] = {
|
||||
// First level usable for some bitrates and profiles.
|
||||
|
||||
// L2.1: 3000 * 1100 = 3300000
|
||||
// L3: 6000 * 1100 = 6600000
|
||||
{ 4000000, &profile_main, 90 },
|
||||
// L2: 1500 * 1650 = 2475000
|
||||
// L2.1: 3000 * 1650 = 4950000
|
||||
{ 4000000, &profile_main_12, 63 },
|
||||
// L1: 350 * 2200 * 2 = 1540000
|
||||
// L2: 1500 * 2200 * 2 = 6600000
|
||||
{ 4000000, &profile_main_422_12_intra, 60 },
|
||||
|
||||
// L5.1: 40000 * 1100 = 44000000
|
||||
// L5.2: 60000 * 1100 = 66000000
|
||||
{ 50000000, &profile_main, 156 },
|
||||
// L5: 25000 * 1650 = 41250000
|
||||
// L5.1: 40000 * 1650 = 66000000
|
||||
{ 50000000, &profile_main_12, 153 },
|
||||
// L3.1: 10000 * 2200 * 2 = 44000000
|
||||
// L4: 12000 * 2200 * 2 = 52800000
|
||||
{ 50000000, &profile_main_422_12_intra, 120 },
|
||||
// L2: 1500 * 3850 * 6 = 34650000
|
||||
// L2.1: 3000 * 3850 * 6 = 69300000
|
||||
{ 50000000, &profile_ht_444_14, 63 },
|
||||
|
||||
// Level changes based on tier.
|
||||
{ 1000, &profile_main, 30 },
|
||||
{ 1000, &profile_main_high_tier, 120 },
|
||||
{ 40000000, &profile_main, 153 },
|
||||
{ 40000000, &profile_main_high_tier, 123 },
|
||||
{ 200000000, &profile_main, 186 },
|
||||
{ 200000000, &profile_main_high_tier, 156 },
|
||||
|
||||
// Overflowing 32-bit integers.
|
||||
// L6: 60000 * 3850 * 6 = 1386000000
|
||||
// L6.1: 120000 * 3850 * 6 = 2772000000
|
||||
// L6.2: 240000 * 3850 * 6 = 5544000000
|
||||
{ INT64_C(2700000000), &profile_ht_444_14, 183 },
|
||||
{ INT64_C(4200000000), &profile_ht_444_14, 186 },
|
||||
{ INT64_C(5600000000), &profile_ht_444_14, 0 },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
int slice_segments;
|
||||
int tile_rows;
|
||||
int tile_cols;
|
||||
int level_idc;
|
||||
} test_fragments[] = {
|
||||
// Slices.
|
||||
{ 4, 1, 1, 30 },
|
||||
{ 32, 1, 1, 93 },
|
||||
{ 70, 1, 1, 120 },
|
||||
{ 80, 1, 1, 150 },
|
||||
{ 201, 1, 1, 180 },
|
||||
{ 600, 1, 1, 180 },
|
||||
{ 601, 1, 1, 0 },
|
||||
|
||||
// Tiles.
|
||||
{ 1, 2, 1, 90 },
|
||||
{ 1, 1, 2, 90 },
|
||||
{ 1, 3, 3, 93 },
|
||||
{ 1, 4, 2, 120 },
|
||||
{ 1, 2, 4, 120 },
|
||||
{ 1, 11, 10, 150 },
|
||||
{ 1, 10, 11, 180 },
|
||||
{ 1, 22, 20, 180 },
|
||||
{ 1, 20, 22, 0 },
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const H265ProfileDescriptor *profile;
|
||||
const H265LevelDescriptor *level;
|
||||
int i;
|
||||
|
||||
#define CHECK(expected, format, ...) do { \
|
||||
if (expected ? (!level || level->level_idc != expected) \
|
||||
: !!level) { \
|
||||
av_log(NULL, AV_LOG_ERROR, "Incorrect level for " \
|
||||
format ": expected %d, got %d.\n", __VA_ARGS__, \
|
||||
expected, level ? level->level_idc : -1); \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) {
|
||||
level = ff_h265_guess_level(&profile_main, 0,
|
||||
test_sizes[i].width,
|
||||
test_sizes[i].height,
|
||||
0, 0, 0, 0);
|
||||
CHECK(test_sizes[i].level_idc, "size %dx%d",
|
||||
test_sizes[i].width, test_sizes[i].height);
|
||||
}
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_dpb); i++) {
|
||||
level = ff_h265_guess_level(&profile_main, 0,
|
||||
test_dpb[i].width,
|
||||
test_dpb[i].height,
|
||||
0, 0, 0, test_dpb[i].dpb_size);
|
||||
CHECK(test_dpb[i].level_idc, "size %dx%d dpb %d",
|
||||
test_dpb[i].width, test_dpb[i].height,
|
||||
test_dpb[i].dpb_size);
|
||||
}
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_bitrate); i++) {
|
||||
profile = ff_h265_get_profile(test_bitrate[i].ptl);
|
||||
level = ff_h265_guess_level(test_bitrate[i].ptl,
|
||||
test_bitrate[i].bitrate,
|
||||
0, 0, 0, 0, 0, 0);
|
||||
CHECK(test_bitrate[i].level_idc, "bitrate %"PRId64" profile %s",
|
||||
test_bitrate[i].bitrate, profile->name);
|
||||
}
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_fragments); i++) {
|
||||
level = ff_h265_guess_level(&profile_main, 0, 0, 0,
|
||||
test_fragments[i].slice_segments,
|
||||
test_fragments[i].tile_rows,
|
||||
test_fragments[i].tile_cols, 0);
|
||||
CHECK(test_fragments[i].level_idc, "%d slices %dx%d tiles",
|
||||
test_fragments[i].slice_segments,
|
||||
test_fragments[i].tile_cols, test_fragments[i].tile_rows);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
51
externals/ffmpeg/libavcodec/tests/htmlsubtitles.c
vendored
Executable file
51
externals/ffmpeg/libavcodec/tests/htmlsubtitles.c
vendored
Executable file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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/common.h"
|
||||
#include "libavcodec/htmlsubtitles.c"
|
||||
|
||||
static const char * const test_cases[] = {
|
||||
/* latin guillemets and other < > garbage */
|
||||
"<<hello>>", // guillemets
|
||||
"<<<b>hello</b>>>", // guillemets + tags
|
||||
"< hello < 2000 > world >", // unlikely tags due to spaces
|
||||
"<h1>TITLE</h1>", // likely unhandled tags
|
||||
"< font color=red >red</font>", // invalid format of valid tag
|
||||
"Foo <foo@bar.com>", // not a tag (not alnum)
|
||||
|
||||
"<b> foo <I> bar </B> bla </i>", // broken nesting
|
||||
|
||||
"A<br>B<BR/>C<br / >D< Br >E<brk><brk/>", // misc line breaks
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
AVBPrint dst;
|
||||
|
||||
av_bprint_init(&dst, 0, AV_BPRINT_SIZE_UNLIMITED);
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(test_cases); i++) {
|
||||
int ret = ff_htmlmarkup_to_ass(NULL, &dst, test_cases[i]);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
printf("%s --> %s\n", test_cases[i], dst.str);
|
||||
av_bprint_clear(&dst);
|
||||
}
|
||||
av_bprint_finalize(&dst, NULL);
|
||||
return 0;
|
||||
}
|
54
externals/ffmpeg/libavcodec/tests/iirfilter.c
vendored
Executable file
54
externals/ffmpeg/libavcodec/tests/iirfilter.c
vendored
Executable 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
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libavutil/libm.h"
|
||||
|
||||
#include "libavcodec/iirfilter.h"
|
||||
|
||||
#define FILT_ORDER 4
|
||||
#define SIZE 1024
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct FFIIRFilterCoeffs *fcoeffs = NULL;
|
||||
struct FFIIRFilterState *fstate = NULL;
|
||||
float cutoff_coeff = 0.4;
|
||||
int16_t x[SIZE], y[SIZE];
|
||||
int i;
|
||||
|
||||
fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH,
|
||||
FF_FILTER_MODE_LOWPASS, FILT_ORDER,
|
||||
cutoff_coeff, 0.0, 0.0);
|
||||
fstate = ff_iir_filter_init_state(FILT_ORDER);
|
||||
|
||||
for (i = 0; i < SIZE; i++)
|
||||
x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE));
|
||||
|
||||
ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1);
|
||||
|
||||
for (i = 0; i < SIZE; i++)
|
||||
printf("%6d %6d\n", x[i], y[i]);
|
||||
|
||||
ff_iir_filter_free_coeffsp(&fcoeffs);
|
||||
ff_iir_filter_free_statep(&fstate);
|
||||
return 0;
|
||||
}
|
46
externals/ffmpeg/libavcodec/tests/imgconvert.c
vendored
Executable file
46
externals/ffmpeg/libavcodec/tests/imgconvert.c
vendored
Executable file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Misc image conversion routines
|
||||
* Copyright (c) 2001, 2002, 2003 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 "libavcodec/imgconvert.c"
|
||||
|
||||
#if FF_API_AVPICTURE
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
int main(void){
|
||||
int i;
|
||||
int err=0;
|
||||
int skip = 0;
|
||||
|
||||
for (i=0; i<AV_PIX_FMT_NB*2; i++) {
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
|
||||
if(!desc || !desc->name) {
|
||||
skip ++;
|
||||
continue;
|
||||
}
|
||||
if (skip) {
|
||||
av_log(NULL, AV_LOG_INFO, "%3d unused pixel format values\n", skip);
|
||||
skip = 0;
|
||||
}
|
||||
av_log(NULL, AV_LOG_INFO, "pix fmt %s yuv_plan:%d avg_bpp:%d\n", desc->name, is_yuv_planar(desc), av_get_padded_bits_per_pixel(desc));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif /* FF_API_AVPICTURE */
|
141
externals/ffmpeg/libavcodec/tests/jpeg2000dwt.c
vendored
Executable file
141
externals/ffmpeg/libavcodec/tests/jpeg2000dwt.c
vendored
Executable file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Discrete wavelet transform
|
||||
* Copyright (c) 2007 Kamil Nowosad
|
||||
* Copyright (c) 2013 Nicolas Bertrand <nicoinattendu@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 "libavcodec/jpeg2000dwt.c"
|
||||
|
||||
#include "libavutil/lfg.h"
|
||||
|
||||
#define MAX_W 256
|
||||
|
||||
static int test_dwt(int *array, int *ref, int border[2][2], int decomp_levels, int type, int max_diff) {
|
||||
int ret, j;
|
||||
DWTContext s1={{{0}}}, *s= &s1;
|
||||
int64_t err2 = 0;
|
||||
|
||||
ret = ff_jpeg2000_dwt_init(s, border, decomp_levels, type);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ff_jpeg2000_dwt_init failed\n");
|
||||
return 1;
|
||||
}
|
||||
ret = ff_dwt_encode(s, array);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ff_dwt_encode failed\n");
|
||||
return 1;
|
||||
}
|
||||
ret = ff_dwt_decode(s, array);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ff_dwt_encode failed\n");
|
||||
return 1;
|
||||
}
|
||||
for (j = 0; j<MAX_W * MAX_W; j++) {
|
||||
if (FFABS(array[j] - ref[j]) > max_diff) {
|
||||
fprintf(stderr, "missmatch at %d (%d != %d) decomp:%d border %d %d %d %d\n",
|
||||
j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]);
|
||||
return 2;
|
||||
}
|
||||
err2 += (array[j] - ref[j]) * (array[j] - ref[j]);
|
||||
array[j] = ref[j];
|
||||
}
|
||||
ff_dwt_destroy(s);
|
||||
|
||||
printf("%s, decomp:%2d border %3d %3d %3d %3d milli-err2:%9"PRId64"\n",
|
||||
type == FF_DWT53 ? "5/3i" : "9/7i",
|
||||
decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1],
|
||||
1000*err2 / ((border[0][1] - border[0][0])*(border[1][1] - border[1][0])));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_dwtf(float *array, float *ref, int border[2][2], int decomp_levels, float max_diff) {
|
||||
int ret, j;
|
||||
DWTContext s1={{{0}}}, *s= &s1;
|
||||
double err2 = 0;
|
||||
|
||||
ret = ff_jpeg2000_dwt_init(s, border, decomp_levels, FF_DWT97);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ff_jpeg2000_dwt_init failed\n");
|
||||
return 1;
|
||||
}
|
||||
ret = ff_dwt_encode(s, array);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ff_dwt_encode failed\n");
|
||||
return 1;
|
||||
}
|
||||
ret = ff_dwt_decode(s, array);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ff_dwt_encode failed\n");
|
||||
return 1;
|
||||
}
|
||||
for (j = 0; j<MAX_W * MAX_W; j++) {
|
||||
if (FFABS(array[j] - ref[j]) > max_diff) {
|
||||
fprintf(stderr, "missmatch at %d (%f != %f) decomp:%d border %d %d %d %d\n",
|
||||
j, array[j], ref[j],decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1]);
|
||||
return 2;
|
||||
}
|
||||
err2 += (array[j] - ref[j]) * (array[j] - ref[j]);
|
||||
array[j] = ref[j];
|
||||
}
|
||||
ff_dwt_destroy(s);
|
||||
|
||||
printf("9/7f, decomp:%2d border %3d %3d %3d %3d err2:%20.3f\n",
|
||||
decomp_levels, border[0][0], border[0][1], border[1][0], border[1][1],
|
||||
err2 / ((border[0][1] - border[0][0])*(border[1][1] - border[1][0])));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int array[MAX_W * MAX_W];
|
||||
static int ref [MAX_W * MAX_W];
|
||||
static float arrayf[MAX_W * MAX_W];
|
||||
static float reff [MAX_W * MAX_W];
|
||||
|
||||
int main(void) {
|
||||
AVLFG prng;
|
||||
int i,j;
|
||||
int border[2][2];
|
||||
int ret, decomp_levels;
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
|
||||
for (i = 0; i<MAX_W * MAX_W; i++)
|
||||
arrayf[i] = reff[i] = array[i] = ref[i] = av_lfg_get(&prng) % 2048;
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
for (j=0; j<4; j++)
|
||||
border[j>>1][j&1] = av_lfg_get(&prng) % MAX_W;
|
||||
if (border[0][0] >= border[0][1] || border[1][0] >= border[1][1])
|
||||
continue;
|
||||
decomp_levels = av_lfg_get(&prng) % FF_DWT_MAX_DECLVLS;
|
||||
|
||||
ret = test_dwt(array, ref, border, decomp_levels, FF_DWT53, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = test_dwt(array, ref, border, decomp_levels, FF_DWT97_INT, FFMIN(7+5*decomp_levels, 15+3*decomp_levels));
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = test_dwtf(arrayf, reff, border, decomp_levels, 0.05);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
41
externals/ffmpeg/libavcodec/tests/mathops.c
vendored
Executable file
41
externals/ffmpeg/libavcodec/tests/mathops.c
vendored
Executable file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavcodec/mathops.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned u;
|
||||
|
||||
for(u=0; u<65536; u++) {
|
||||
unsigned s = u*u;
|
||||
unsigned root = ff_sqrt(s);
|
||||
unsigned root_m1 = ff_sqrt(s-1);
|
||||
if (s && root != u) {
|
||||
fprintf(stderr, "ff_sqrt failed at %u with %u\n", s, root);
|
||||
return 1;
|
||||
}
|
||||
if (u && root_m1 != u - 1) {
|
||||
fprintf(stderr, "ff_sqrt failed at %u with %u\n", s, root);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
167
externals/ffmpeg/libavcodec/tests/mjpegenc_huffman.c
vendored
Executable file
167
externals/ffmpeg/libavcodec/tests/mjpegenc_huffman.c
vendored
Executable file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2016 William Ma, Sofia Kim, Dustin Woo
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Optimal Huffman Encoding tests.
|
||||
*/
|
||||
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include <stdlib.h>
|
||||
#include "libavcodec/mjpegenc.h"
|
||||
#include "libavcodec/mjpegenc_huffman.h"
|
||||
#include "libavcodec/mjpegenc_common.h"
|
||||
#include "libavcodec/mpegvideo.h"
|
||||
|
||||
// Validate the computed lengths satisfy the JPEG restrictions and is optimal.
|
||||
static int check_lengths(int L, int expected_length,
|
||||
const int *probs, int nprobs)
|
||||
{
|
||||
HuffTable lengths[256];
|
||||
PTable val_counts[256];
|
||||
int actual_length = 0, i, j, k, prob, length;
|
||||
int ret = 0;
|
||||
double cantor_measure = 0;
|
||||
av_assert0(nprobs <= 256);
|
||||
|
||||
for (i = 0; i < nprobs; i++) {
|
||||
val_counts[i] = (PTable){.value = i, .prob = probs[i]};
|
||||
}
|
||||
|
||||
ff_mjpegenc_huffman_compute_bits(val_counts, lengths, nprobs, L);
|
||||
|
||||
for (i = 0; i < nprobs; i++) {
|
||||
// Find the value's prob and length
|
||||
for (j = 0; j < nprobs; j++)
|
||||
if (val_counts[j].value == i) break;
|
||||
for (k = 0; k < nprobs; k++)
|
||||
if (lengths[k].code == i) break;
|
||||
if (!(j < nprobs && k < nprobs)) return 1;
|
||||
prob = val_counts[j].prob;
|
||||
length = lengths[k].length;
|
||||
|
||||
if (prob) {
|
||||
actual_length += prob * length;
|
||||
cantor_measure += 1. / (1 << length);
|
||||
}
|
||||
|
||||
if (length > L || length < 1) return 1;
|
||||
}
|
||||
// Check that the codes can be prefix-free.
|
||||
if (cantor_measure > 1) ret = 1;
|
||||
// Check that the total length is optimal
|
||||
if (actual_length != expected_length) ret = 1;
|
||||
|
||||
if (ret == 1) {
|
||||
fprintf(stderr,
|
||||
"Cantor measure: %f\n"
|
||||
"Actual length: %d\n"
|
||||
"Expected length: %d\n",
|
||||
cantor_measure, actual_length, expected_length);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const int probs_zeroes[] = {
|
||||
6, 6, 0, 0, 0
|
||||
};
|
||||
|
||||
static const int probs_skewed[] = {
|
||||
2, 0, 0, 0, 0, 1, 0, 0, 20, 0, 2, 0, 10, 5, 1, 1, 9, 1, 1, 6, 0, 5, 0, 1, 0, 7, 6,
|
||||
1, 1, 5, 0, 0, 0, 0, 11, 0, 0, 0, 51, 1, 0, 20, 0, 1, 0, 0, 0, 0, 6, 106, 1, 0, 1,
|
||||
0, 2, 1, 16, 0, 0, 5, 0, 0, 0, 4, 3, 15, 4, 4, 0, 0, 0, 3, 0, 0, 1, 0, 3, 0, 3, 2,
|
||||
2, 0, 0, 4, 3, 40, 1, 2, 0, 22, 0, 0, 0, 9, 0, 0, 0, 0, 1, 1, 0, 1, 6, 11, 4, 10,
|
||||
28, 6, 1, 0, 0, 9, 9, 4, 0, 0, 0, 0, 8, 33844, 2, 0, 2, 1, 1, 5, 0, 0, 1, 9, 1, 0,
|
||||
4, 14, 4, 0, 0, 3, 8, 0, 51, 9, 6, 1, 1, 2, 2, 3, 1, 5, 5, 29, 0, 0, 0, 0, 14, 29,
|
||||
6, 4, 13, 12, 2, 3, 1, 0, 5, 4, 1, 1, 0, 0, 29, 1, 0, 0, 0, 0, 4, 0, 0, 1, 0, 1,
|
||||
7, 0, 42, 0, 0, 0, 0, 0, 2, 0, 3, 9, 0, 0, 0, 2, 1, 0, 0, 6, 5, 6, 1, 2, 3, 0, 0,
|
||||
0, 3, 0, 0, 28, 0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 23, 0, 0, 0, 0,
|
||||
0, 21, 1, 0, 3, 24, 2, 0, 0, 7, 0, 0, 1, 5, 1, 2, 0, 5
|
||||
};
|
||||
|
||||
static const int probs_sat[] = {
|
||||
74, 8, 14, 7, 9345, 40, 0, 2014, 2, 1, 115, 0, 2, 1, 194, 388, 20, 0, 0, 2, 1, 121,
|
||||
1, 1583, 0, 16, 21, 2, 132, 2, 15, 9, 13, 1, 0, 2293, 2, 8, 5, 2, 30, 0, 0, 4, 54,
|
||||
783, 4, 1, 2, 4, 0, 22, 93, 1, 143, 19, 0, 36, 32, 4, 6, 33, 3, 45, 0, 8, 1, 0, 18,
|
||||
17, 1, 0, 1, 0, 0, 1, 1004, 38, 3, 8, 90, 23, 0, 2819, 3, 0, 970, 158, 9, 6, 4, 48,
|
||||
4, 0, 1, 0, 0, 60, 3, 62, 0, 2, 2, 2, 279, 66, 16, 1, 20, 0, 7, 9, 32, 1411, 6, 3,
|
||||
27, 1, 5, 49, 0, 0, 0, 0, 0, 2, 10, 1, 1, 2, 3, 801, 3, 25, 5, 1, 1, 0, 632, 0, 14,
|
||||
18, 5, 8, 200, 4, 4, 22, 12, 0, 4, 1, 0, 2, 4, 9, 3, 16, 7, 2, 2, 213, 0, 2, 620,
|
||||
39303, 0, 1, 0, 2, 1, 183781, 1, 0, 0, 0, 94, 7, 3, 4, 0, 4, 306, 43, 352, 76, 34,
|
||||
13, 11, 0, 51, 1, 13, 19, 0, 26, 0, 7276, 4, 207, 31, 1, 2, 4, 6, 19, 8, 17, 4, 6,
|
||||
0, 1085, 0, 0, 0, 3, 489, 36, 1, 0, 1, 9420, 294, 28, 0, 57, 5, 0, 9, 2, 0, 1, 2,
|
||||
2, 0, 0, 9, 2, 29, 2, 2, 7, 0, 5, 490, 0, 7, 5, 0, 1, 8, 0, 0, 23255, 0, 1
|
||||
};
|
||||
|
||||
// Test the example given on @see
|
||||
// http://guru.multimedia.cx/small-tasks-for-ffmpeg/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, ret = 0;
|
||||
// Probabilities of symbols 0..4
|
||||
PTable val_counts[] = {
|
||||
{.value = 0, .prob = 1},
|
||||
{.value = 1, .prob = 2},
|
||||
{.value = 2, .prob = 5},
|
||||
{.value = 3, .prob = 10},
|
||||
{.value = 4, .prob = 21},
|
||||
};
|
||||
// Expected code lengths for each symbol
|
||||
static const HuffTable expected[] = {
|
||||
{.code = 0, .length = 3},
|
||||
{.code = 1, .length = 3},
|
||||
{.code = 2, .length = 3},
|
||||
{.code = 3, .length = 3},
|
||||
{.code = 4, .length = 1},
|
||||
};
|
||||
// Actual code lengths
|
||||
HuffTable distincts[5];
|
||||
|
||||
// Build optimal huffman tree using an internal function, to allow for
|
||||
// smaller-than-normal test cases. This mutates val_counts by sorting.
|
||||
ff_mjpegenc_huffman_compute_bits(val_counts, distincts,
|
||||
FF_ARRAY_ELEMS(distincts), 3);
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(distincts); i++) {
|
||||
if (distincts[i].code != expected[i].code ||
|
||||
distincts[i].length != expected[i].length) {
|
||||
fprintf(stderr,
|
||||
"Built huffman does not equal expectations. "
|
||||
"Expected: code %d probability %d, "
|
||||
"Actual: code %d probability %d\n",
|
||||
expected[i].code, expected[i].length,
|
||||
distincts[i].code, distincts[i].length);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check handling of zero probabilities
|
||||
if (check_lengths(16, 18, probs_zeroes, FF_ARRAY_ELEMS(probs_zeroes)))
|
||||
ret = 1;
|
||||
// Check skewed distribution over 256 without saturated lengths
|
||||
if (check_lengths(16, 41282, probs_skewed, FF_ARRAY_ELEMS(probs_skewed)))
|
||||
ret = 1;
|
||||
// Check skewed distribution over 256 with saturated lengths
|
||||
if (check_lengths(16, 669904, probs_sat, FF_ARRAY_ELEMS(probs_sat)))
|
||||
ret = 1;
|
||||
|
||||
return ret;
|
||||
}
|
152
externals/ffmpeg/libavcodec/tests/motion.c
vendored
Executable file
152
externals/ffmpeg/libavcodec/tests/motion.c
vendored
Executable file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* (c) 2001 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* motion test.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "libavcodec/me_cmp.h"
|
||||
#include "libavutil/internal.h"
|
||||
#include "libavutil/lfg.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/time.h"
|
||||
|
||||
#undef printf
|
||||
|
||||
#define WIDTH 64
|
||||
#define HEIGHT 64
|
||||
|
||||
static uint8_t img1[WIDTH * HEIGHT];
|
||||
static uint8_t img2[WIDTH * HEIGHT];
|
||||
|
||||
static void fill_random(uint8_t *tab, int size)
|
||||
{
|
||||
int i;
|
||||
AVLFG prng;
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
for(i=0;i<size;i++) {
|
||||
tab[i] = av_lfg_get(&prng) % 256;
|
||||
}
|
||||
}
|
||||
|
||||
static void help(void)
|
||||
{
|
||||
printf("motion-test [-h]\n"
|
||||
"test motion implementations\n");
|
||||
}
|
||||
|
||||
#define NB_ITS 500
|
||||
|
||||
int dummy;
|
||||
|
||||
static void test_motion(const char *name,
|
||||
me_cmp_func test_func, me_cmp_func ref_func)
|
||||
{
|
||||
int x, y, d1, d2, it;
|
||||
uint8_t *ptr;
|
||||
int64_t ti;
|
||||
printf("testing '%s'\n", name);
|
||||
|
||||
/* test correctness */
|
||||
for(it=0;it<20;it++) {
|
||||
|
||||
fill_random(img1, WIDTH * HEIGHT);
|
||||
fill_random(img2, WIDTH * HEIGHT);
|
||||
|
||||
for(y=0;y<HEIGHT-17;y++) {
|
||||
for(x=0;x<WIDTH-17;x++) {
|
||||
ptr = img2 + y * WIDTH + x;
|
||||
d1 = test_func(NULL, img1, ptr, WIDTH, 8);
|
||||
d2 = ref_func(NULL, img1, ptr, WIDTH, 8);
|
||||
if (d1 != d2) {
|
||||
printf("error: mmx=%d c=%d\n", d1, d2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
emms_c();
|
||||
|
||||
/* speed test */
|
||||
ti = av_gettime_relative();
|
||||
d1 = 0;
|
||||
for(it=0;it<NB_ITS;it++) {
|
||||
for(y=0;y<HEIGHT-17;y++) {
|
||||
for(x=0;x<WIDTH-17;x++) {
|
||||
ptr = img2 + y * WIDTH + x;
|
||||
d1 += test_func(NULL, img1, ptr, WIDTH, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
emms_c();
|
||||
dummy = d1; /* avoid optimization */
|
||||
ti = av_gettime_relative() - ti;
|
||||
|
||||
printf(" %0.0f kop/s\n",
|
||||
(double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
|
||||
(double)(ti / 1000.0));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
AVCodecContext *ctx;
|
||||
int c;
|
||||
MECmpContext cctx, mmxctx;
|
||||
int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMXEXT };
|
||||
int flags_size = HAVE_MMXEXT ? 2 : 1;
|
||||
|
||||
if (argc > 1) {
|
||||
help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("ffmpeg motion test\n");
|
||||
|
||||
ctx = avcodec_alloc_context3(NULL);
|
||||
ctx->flags |= AV_CODEC_FLAG_BITEXACT;
|
||||
av_force_cpu_flags(0);
|
||||
memset(&cctx, 0, sizeof(cctx));
|
||||
ff_me_cmp_init(&cctx, ctx);
|
||||
for (c = 0; c < flags_size; c++) {
|
||||
int x;
|
||||
av_force_cpu_flags(flags[c]);
|
||||
memset(&mmxctx, 0, sizeof(mmxctx));
|
||||
ff_me_cmp_init(&mmxctx, ctx);
|
||||
|
||||
for (x = 0; x < 2; x++) {
|
||||
printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
|
||||
x ? 8 : 16, x ? 8 : 16);
|
||||
test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
|
||||
test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
|
||||
test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
|
||||
test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
|
||||
}
|
||||
}
|
||||
av_free(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
87
externals/ffmpeg/libavcodec/tests/mpeg12framerate.c
vendored
Executable file
87
externals/ffmpeg/libavcodec/tests/mpeg12framerate.c
vendored
Executable file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavcodec/mpeg12.h"
|
||||
#include "libavcodec/mpeg12data.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
#define TEST_MATCH(frame_rate, code, ext_n, ext_d) do { \
|
||||
AVRational fr = frame_rate; \
|
||||
int c, n, d; \
|
||||
ff_mpeg12_find_best_frame_rate(fr, &c, &n, &d, 0); \
|
||||
if (c != code || n != ext_n || d != ext_d) { \
|
||||
av_log(NULL, AV_LOG_ERROR, "Failed to match %d/%d: " \
|
||||
"code = %d, ext_n = %d, ext_d = %d.\n", \
|
||||
fr.num, fr.den, c, n, d); \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
#define TEST_EXACT(frn, frd) do { \
|
||||
AVRational fr = (AVRational) { frn, frd }; \
|
||||
int c, n, d; \
|
||||
ff_mpeg12_find_best_frame_rate(fr, &c, &n, &d, 0); \
|
||||
if (av_cmp_q(fr, av_mul_q(ff_mpeg12_frame_rate_tab[c], \
|
||||
(AVRational) { n + 1, d + 1 })) != 0) { \
|
||||
av_log(NULL, AV_LOG_ERROR, "Failed to find exact %d/%d: " \
|
||||
"code = %d, ext_n = %d, ext_d = %d.\n", \
|
||||
fr.num, fr.den, c, n, d); \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Framerates in the table must be chosen exactly.
|
||||
for (i = 1; i <= 8; i++)
|
||||
TEST_MATCH(ff_mpeg12_frame_rate_tab[i], i, 0, 0);
|
||||
|
||||
// As should the same ones with small perturbations.
|
||||
// (1/1000 used here to be smaller than half the difference
|
||||
// between 24 and 24000/1001.)
|
||||
for (i = 1; i <= 8; i++) {
|
||||
TEST_MATCH(av_sub_q(ff_mpeg12_frame_rate_tab[i],
|
||||
(AVRational) { 1, 1000 }), i, 0, 0);
|
||||
TEST_MATCH(av_add_q(ff_mpeg12_frame_rate_tab[i],
|
||||
(AVRational) { 1, 1000 }), i, 0, 0);
|
||||
}
|
||||
|
||||
// Exactly constructable framerates should be exact. Note that some
|
||||
// values can be made in multiple ways (e.g. 12 = 24 / 2 == 60 / 5),
|
||||
// and there is no reason to favour any particular choice.
|
||||
TEST_EXACT( 1, 1);
|
||||
TEST_EXACT( 2, 1);
|
||||
TEST_EXACT( 12, 1);
|
||||
TEST_EXACT( 15000, 1001);
|
||||
TEST_EXACT( 15, 1);
|
||||
TEST_EXACT( 120, 1);
|
||||
TEST_EXACT(120000, 1001);
|
||||
TEST_EXACT( 200, 1);
|
||||
TEST_EXACT( 240, 1);
|
||||
|
||||
// Values higher than 240 (the highest representable, as 60 * 4 / 1)
|
||||
// should be mapped to 240.
|
||||
for (i = 240; i < 1000; i += 10)
|
||||
TEST_MATCH(((AVRational) { i, 1 }), 8, 3, 0);
|
||||
// Values lower than 24000/32032 (the lowest representable, as
|
||||
// 24000/1001 * 1 / 32) should be mapped to 24000/32032.
|
||||
for (i = 74; i > 0; i--)
|
||||
TEST_MATCH(((AVRational) { i, 100 }), 1, 0, 31);
|
||||
|
||||
return 0;
|
||||
}
|
195
externals/ffmpeg/libavcodec/tests/options.c
vendored
Executable file
195
externals/ffmpeg/libavcodec/tests/options.c
vendored
Executable file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2001 Fabrice Bellard
|
||||
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavcodec/options.c"
|
||||
|
||||
static int dummy_init(AVCodecContext *ctx)
|
||||
{
|
||||
//TODO: this code should set every possible pointer that could be set by codec and is not an option;
|
||||
ctx->extradata_size = 8;
|
||||
ctx->extradata = av_malloc(ctx->extradata_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dummy_close(AVCodecContext *ctx)
|
||||
{
|
||||
av_freep(&ctx->extradata);
|
||||
ctx->extradata_size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dummy_encode(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
|
||||
{
|
||||
return AVERROR(ENOSYS);
|
||||
}
|
||||
|
||||
typedef struct Dummy12Context {
|
||||
AVClass *av_class;
|
||||
int num;
|
||||
char* str;
|
||||
} Dummy12Context;
|
||||
|
||||
typedef struct Dummy3Context {
|
||||
void *fake_av_class;
|
||||
int num;
|
||||
char* str;
|
||||
} Dummy3Context;
|
||||
|
||||
#define OFFSET(x) offsetof(Dummy12Context, x)
|
||||
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
|
||||
static const AVOption dummy_options[] = {
|
||||
{ "str", "set str", OFFSET(str), AV_OPT_TYPE_STRING, { .str = "i'm src default value" }, 0, 0, VE},
|
||||
{ "num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 1500100900 }, 0, INT_MAX, VE},
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
static const AVClass dummy_v1_class = {
|
||||
.class_name = "dummy_v1_class",
|
||||
.item_name = av_default_item_name,
|
||||
.option = dummy_options,
|
||||
.version = LIBAVUTIL_VERSION_INT,
|
||||
};
|
||||
|
||||
static const AVClass dummy_v2_class = {
|
||||
.class_name = "dummy_v2_class",
|
||||
.item_name = av_default_item_name,
|
||||
.option = dummy_options,
|
||||
.version = LIBAVUTIL_VERSION_INT,
|
||||
};
|
||||
|
||||
/* codec with options */
|
||||
static AVCodec dummy_v1_encoder = {
|
||||
.name = "dummy_v1_codec",
|
||||
.type = AVMEDIA_TYPE_VIDEO,
|
||||
.id = AV_CODEC_ID_NONE - 1,
|
||||
.encode2 = dummy_encode,
|
||||
.init = dummy_init,
|
||||
.close = dummy_close,
|
||||
.priv_class = &dummy_v1_class,
|
||||
.priv_data_size = sizeof(Dummy12Context),
|
||||
};
|
||||
|
||||
/* codec with options, different class */
|
||||
static AVCodec dummy_v2_encoder = {
|
||||
.name = "dummy_v2_codec",
|
||||
.type = AVMEDIA_TYPE_VIDEO,
|
||||
.id = AV_CODEC_ID_NONE - 2,
|
||||
.encode2 = dummy_encode,
|
||||
.init = dummy_init,
|
||||
.close = dummy_close,
|
||||
.priv_class = &dummy_v2_class,
|
||||
.priv_data_size = sizeof(Dummy12Context),
|
||||
};
|
||||
|
||||
/* codec with priv data, but no class */
|
||||
static AVCodec dummy_v3_encoder = {
|
||||
.name = "dummy_v3_codec",
|
||||
.type = AVMEDIA_TYPE_VIDEO,
|
||||
.id = AV_CODEC_ID_NONE - 3,
|
||||
.encode2 = dummy_encode,
|
||||
.init = dummy_init,
|
||||
.close = dummy_close,
|
||||
.priv_data_size = sizeof(Dummy3Context),
|
||||
};
|
||||
|
||||
/* codec without priv data */
|
||||
static AVCodec dummy_v4_encoder = {
|
||||
.name = "dummy_v4_codec",
|
||||
.type = AVMEDIA_TYPE_VIDEO,
|
||||
.id = AV_CODEC_ID_NONE - 4,
|
||||
.encode2 = dummy_encode,
|
||||
.init = dummy_init,
|
||||
.close = dummy_close,
|
||||
};
|
||||
|
||||
static void test_copy_print_codec(const AVCodecContext *ctx)
|
||||
{
|
||||
printf("%-14s: %dx%d prv: %s",
|
||||
ctx->codec ? ctx->codec->name : "NULL",
|
||||
ctx->width, ctx->height,
|
||||
ctx->priv_data ? "set" : "null");
|
||||
if (ctx->codec && ctx->codec->priv_class && ctx->codec->priv_data_size) {
|
||||
int64_t i64;
|
||||
char *str = NULL;
|
||||
av_opt_get_int(ctx->priv_data, "num", 0, &i64);
|
||||
av_opt_get(ctx->priv_data, "str", 0, (uint8_t**)&str);
|
||||
printf(" opts: %"PRId64" %s", i64, str);
|
||||
av_free(str);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void test_copy(const AVCodec *c1, const AVCodec *c2)
|
||||
{
|
||||
AVCodecContext *ctx1, *ctx2;
|
||||
printf("%s -> %s\nclosed:\n", c1 ? c1->name : "NULL", c2 ? c2->name : "NULL");
|
||||
ctx1 = avcodec_alloc_context3(c1);
|
||||
ctx2 = avcodec_alloc_context3(c2);
|
||||
ctx1->width = ctx1->height = 128;
|
||||
ctx1->time_base = (AVRational){12,34};
|
||||
if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
|
||||
av_opt_set(ctx2->priv_data, "num", "667", 0);
|
||||
av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
|
||||
}
|
||||
avcodec_copy_context(ctx2, ctx1);
|
||||
test_copy_print_codec(ctx1);
|
||||
test_copy_print_codec(ctx2);
|
||||
if (ctx1->codec) {
|
||||
int ret;
|
||||
printf("opened:\n");
|
||||
ret = avcodec_open2(ctx1, ctx1->codec, NULL);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "avcodec_open2 failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if (ctx2->codec && ctx2->codec->priv_class && ctx2->codec->priv_data_size) {
|
||||
av_opt_set(ctx2->priv_data, "num", "667", 0);
|
||||
av_opt_set(ctx2->priv_data, "str", "i'm dest value before copy", 0);
|
||||
}
|
||||
avcodec_copy_context(ctx2, ctx1);
|
||||
test_copy_print_codec(ctx1);
|
||||
test_copy_print_codec(ctx2);
|
||||
avcodec_close(ctx1);
|
||||
}
|
||||
avcodec_free_context(&ctx1);
|
||||
avcodec_free_context(&ctx2);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
AVCodec *dummy_codec[] = {
|
||||
&dummy_v1_encoder,
|
||||
&dummy_v2_encoder,
|
||||
&dummy_v3_encoder,
|
||||
&dummy_v4_encoder,
|
||||
NULL,
|
||||
};
|
||||
int i, j;
|
||||
|
||||
for (i = 0; dummy_codec[i]; i++)
|
||||
avcodec_register(dummy_codec[i]);
|
||||
|
||||
printf("testing avcodec_copy_context()\n");
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(dummy_codec); i++)
|
||||
for (j = 0; j < FF_ARRAY_ELEMS(dummy_codec); j++)
|
||||
test_copy(dummy_codec[i], dummy_codec[j]);
|
||||
return 0;
|
||||
}
|
32
externals/ffmpeg/libavcodec/tests/ppc/dct.c
vendored
Executable file
32
externals/ffmpeg/libavcodec/tests/ppc/dct.c
vendored
Executable file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
|
||||
#include "libavcodec/ppc/fdct.h"
|
||||
|
||||
static const struct algo fdct_tab_arch[] = {
|
||||
#if HAVE_ALTIVEC
|
||||
{ "altivecfdct", ff_fdct_altivec, FF_IDCT_PERM_NONE, AV_CPU_FLAG_ALTIVEC },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static const struct algo idct_tab_arch[] = {
|
||||
{ 0 }
|
||||
};
|
76
externals/ffmpeg/libavcodec/tests/rangecoder.c
vendored
Executable file
76
externals/ffmpeg/libavcodec/tests/rangecoder.c
vendored
Executable file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/lfg.h"
|
||||
#include "libavutil/log.h"
|
||||
|
||||
#include "libavcodec/rangecoder.h"
|
||||
|
||||
#define SIZE 1240
|
||||
|
||||
int main(void)
|
||||
{
|
||||
RangeCoder c;
|
||||
uint8_t b[9 * SIZE] = {0};
|
||||
uint8_t r[9 * SIZE];
|
||||
int i, p, actual_length, version;
|
||||
uint8_t state[10];
|
||||
AVLFG prng;
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
for (version = 0; version < 2; version++) {
|
||||
for (p = 0; p< 1024; p++) {
|
||||
ff_init_range_encoder(&c, b, SIZE);
|
||||
ff_build_rac_states(&c, (1LL << 32) / 20, 128 + 64 + 32 + 16);
|
||||
|
||||
memset(state, 128, sizeof(state));
|
||||
|
||||
for (i = 0; i < SIZE; i++)
|
||||
r[i] = av_lfg_get(&prng) % 7;
|
||||
|
||||
for (i = 0; i < SIZE; i++)
|
||||
put_rac(&c, state, r[i] & 1);
|
||||
|
||||
actual_length = ff_rac_terminate(&c, version);
|
||||
|
||||
ff_init_range_decoder(&c, b, version ? SIZE : actual_length);
|
||||
|
||||
memset(state, 128, sizeof(state));
|
||||
|
||||
for (i = 0; i < SIZE; i++)
|
||||
if ((r[i] & 1) != get_rac(&c, state)) {
|
||||
av_log(NULL, AV_LOG_ERROR, "rac failure at %d pass %d version %d\n", i, p, version);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ff_rac_check_termination(&c, version) < 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "rac failure at termination pass %d version %d\n", p, version);
|
||||
return 1;
|
||||
}
|
||||
if (c.bytestream - c.bytestream_start - actual_length != version) {
|
||||
av_log(NULL, AV_LOG_ERROR, "rac failure at pass %d version %d\n", p, version);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
147
externals/ffmpeg/libavcodec/tests/snowenc.c
vendored
Executable file
147
externals/ffmpeg/libavcodec/tests/snowenc.c
vendored
Executable file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavcodec/snowenc.c"
|
||||
|
||||
#undef malloc
|
||||
#undef free
|
||||
#undef printf
|
||||
|
||||
#include "libavutil/lfg.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
|
||||
int main(void){
|
||||
#define width 256
|
||||
#define height 256
|
||||
int buffer[2][width*height];
|
||||
SnowContext s;
|
||||
int i;
|
||||
AVLFG prng;
|
||||
s.spatial_decomposition_count=6;
|
||||
s.spatial_decomposition_type=1;
|
||||
|
||||
s.temp_dwt_buffer = av_mallocz_array(width, sizeof(DWTELEM));
|
||||
s.temp_idwt_buffer = av_mallocz_array(width, sizeof(IDWTELEM));
|
||||
|
||||
if (!s.temp_dwt_buffer || !s.temp_idwt_buffer) {
|
||||
fprintf(stderr, "Failed to allocate memory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
|
||||
printf("testing 5/3 DWT\n");
|
||||
for(i=0; i<width*height; i++)
|
||||
buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345;
|
||||
|
||||
ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
|
||||
ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
|
||||
|
||||
for(i=0; i<width*height; i++)
|
||||
if(buffer[0][i]!= buffer[1][i]) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]);
|
||||
|
||||
printf("testing 9/7 DWT\n");
|
||||
s.spatial_decomposition_type=0;
|
||||
for(i=0; i<width*height; i++)
|
||||
buffer[0][i] = buffer[1][i] = av_lfg_get(&prng) % 54321 - 12345;
|
||||
|
||||
ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
|
||||
ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
|
||||
|
||||
for(i=0; i<width*height; i++)
|
||||
if(FFABS(buffer[0][i] - buffer[1][i])>20) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]);
|
||||
|
||||
{
|
||||
int level, orientation, x, y;
|
||||
int64_t errors[8][4];
|
||||
int64_t g=0;
|
||||
|
||||
memset(errors, 0, sizeof(errors));
|
||||
s.spatial_decomposition_count=3;
|
||||
s.spatial_decomposition_type=0;
|
||||
for(level=0; level<s.spatial_decomposition_count; level++){
|
||||
for(orientation=level ? 1 : 0; orientation<4; orientation++){
|
||||
int w= width >> (s.spatial_decomposition_count-level);
|
||||
int h= height >> (s.spatial_decomposition_count-level);
|
||||
int stride= width << (s.spatial_decomposition_count-level);
|
||||
DWTELEM *buf= buffer[0];
|
||||
int64_t error=0;
|
||||
|
||||
if(orientation&1) buf+=w;
|
||||
if(orientation>1) buf+=stride>>1;
|
||||
|
||||
memset(buffer[0], 0, sizeof(int)*width*height);
|
||||
buf[w/2 + h/2*stride]= 256*256;
|
||||
ff_spatial_idwt((IDWTELEM*)buffer[0], s.temp_idwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
|
||||
for(y=0; y<height; y++){
|
||||
for(x=0; x<width; x++){
|
||||
int64_t d= buffer[0][x + y*width];
|
||||
error += d*d;
|
||||
if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d);
|
||||
}
|
||||
if(FFABS(height/2-y)<9 && level==2) printf("\n");
|
||||
}
|
||||
error= (int)(sqrt(error)+0.5);
|
||||
errors[level][orientation]= error;
|
||||
if(g) g=av_gcd(g, error);
|
||||
else g= error;
|
||||
}
|
||||
}
|
||||
printf("static int const visual_weight[][4]={\n");
|
||||
for(level=0; level<s.spatial_decomposition_count; level++){
|
||||
printf(" {");
|
||||
for(orientation=0; orientation<4; orientation++){
|
||||
printf("%8"PRId64",", errors[level][orientation]/g);
|
||||
}
|
||||
printf("},\n");
|
||||
}
|
||||
printf("};\n");
|
||||
{
|
||||
int level=2;
|
||||
int w= width >> (s.spatial_decomposition_count-level);
|
||||
//int h= height >> (s.spatial_decomposition_count-level);
|
||||
int stride= width << (s.spatial_decomposition_count-level);
|
||||
DWTELEM *buf= buffer[0];
|
||||
int64_t error=0;
|
||||
|
||||
buf+=w;
|
||||
buf+=stride>>1;
|
||||
|
||||
memset(buffer[0], 0, sizeof(int)*width*height);
|
||||
for(y=0; y<height; y++){
|
||||
for(x=0; x<width; x++){
|
||||
int tab[4]={0,2,3,1};
|
||||
buffer[0][x+width*y]= 256*256*tab[(x&1) + 2*(y&1)];
|
||||
}
|
||||
}
|
||||
ff_spatial_dwt(buffer[0], s.temp_dwt_buffer, width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
|
||||
for(y=0; y<height; y++){
|
||||
for(x=0; x<width; x++){
|
||||
int64_t d= buffer[0][x + y*width];
|
||||
error += d*d;
|
||||
if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d);
|
||||
}
|
||||
if(FFABS(height/2-y)<9) printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
37
externals/ffmpeg/libavcodec/tests/utils.c
vendored
Executable file
37
externals/ffmpeg/libavcodec/tests/utils.c
vendored
Executable file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavcodec/avcodec.h"
|
||||
|
||||
int main(void){
|
||||
void *iter = NULL;
|
||||
const AVCodec *codec = NULL;
|
||||
int ret = 0;
|
||||
|
||||
while (codec = av_codec_iterate(&iter)) {
|
||||
if (av_codec_is_encoder(codec)) {
|
||||
if (codec->type == AVMEDIA_TYPE_AUDIO) {
|
||||
if (!codec->sample_fmts) {
|
||||
av_log(NULL, AV_LOG_FATAL, "Encoder %s is missing the sample_fmts field\n", codec->name);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
135
externals/ffmpeg/libavcodec/tests/x86/dct.c
vendored
Executable file
135
externals/ffmpeg/libavcodec/tests/x86/dct.c
vendored
Executable file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
|
||||
#include "libavcodec/x86/fdct.h"
|
||||
#include "libavcodec/x86/xvididct.h"
|
||||
#include "libavcodec/x86/simple_idct.h"
|
||||
|
||||
#if (CONFIG_PRORES_DECODER || CONFIG_PRORES_LGPL_DECODER) && ARCH_X86_64 && HAVE_X86ASM
|
||||
void ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize,
|
||||
int16_t *block, int16_t *qmat);
|
||||
|
||||
#define PR_WRAP(INSN) \
|
||||
static void ff_prores_idct_put_10_##INSN##_wrap(int16_t *dst){ \
|
||||
LOCAL_ALIGNED(16, int16_t, qmat, [64]); \
|
||||
LOCAL_ALIGNED(16, int16_t, tmp, [64]); \
|
||||
int i; \
|
||||
\
|
||||
for(i=0; i<64; i++){ \
|
||||
qmat[i]=4; \
|
||||
tmp[i]= dst[i]; \
|
||||
} \
|
||||
ff_prores_idct_put_10_##INSN (dst, 16, tmp, qmat); \
|
||||
\
|
||||
for(i=0; i<64; i++) { \
|
||||
dst[i] -= 512; \
|
||||
} \
|
||||
}
|
||||
|
||||
PR_WRAP(sse2)
|
||||
|
||||
# if HAVE_AVX_EXTERNAL
|
||||
void ff_prores_idct_put_10_avx(uint16_t *dst, int linesize,
|
||||
int16_t *block, int16_t *qmat);
|
||||
PR_WRAP(avx)
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
static const struct algo fdct_tab_arch[] = {
|
||||
#if HAVE_MMX_INLINE
|
||||
{ "MMX", ff_fdct_mmx, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMX },
|
||||
#endif
|
||||
#if HAVE_MMXEXT_INLINE
|
||||
{ "MMXEXT", ff_fdct_mmxext, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMXEXT },
|
||||
#endif
|
||||
#if HAVE_SSE2_INLINE
|
||||
{ "SSE2", ff_fdct_sse2, FF_IDCT_PERM_NONE, AV_CPU_FLAG_SSE2 },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static const struct algo idct_tab_arch[] = {
|
||||
#if HAVE_MMX_EXTERNAL
|
||||
{ "SIMPLE-MMX", ff_simple_idct_mmx, FF_IDCT_PERM_SIMPLE, AV_CPU_FLAG_MMX },
|
||||
#endif
|
||||
#if CONFIG_MPEG4_DECODER && HAVE_X86ASM
|
||||
#if ARCH_X86_32
|
||||
{ "XVID-MMX", ff_xvid_idct_mmx, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMX, 1 },
|
||||
{ "XVID-MMXEXT", ff_xvid_idct_mmxext, FF_IDCT_PERM_NONE, AV_CPU_FLAG_MMXEXT, 1 },
|
||||
#endif
|
||||
#if HAVE_SSE2_EXTERNAL
|
||||
{ "XVID-SSE2", ff_xvid_idct_sse2, FF_IDCT_PERM_SSE2, AV_CPU_FLAG_SSE2, 1 },
|
||||
#endif
|
||||
#endif /* CONFIG_MPEG4_DECODER && HAVE_X86ASM */
|
||||
#if (CONFIG_PRORES_DECODER || CONFIG_PRORES_LGPL_DECODER) && ARCH_X86_64 && HAVE_X86ASM
|
||||
{ "PR-SSE2", ff_prores_idct_put_10_sse2_wrap, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_SSE2, 1 },
|
||||
# if HAVE_AVX_EXTERNAL
|
||||
{ "PR-AVX", ff_prores_idct_put_10_avx_wrap, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_AVX, 1 },
|
||||
# endif
|
||||
#endif
|
||||
#if HAVE_X86ASM
|
||||
#if ARCH_X86_64
|
||||
#if HAVE_SSE2_EXTERNAL
|
||||
{ "SIMPLE8-SSE2", ff_simple_idct8_sse2, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_SSE2},
|
||||
{ "SIMPLE10-SSE2", ff_simple_idct10_sse2, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_SSE2},
|
||||
{ "SIMPLE12-SSE2", ff_simple_idct12_sse2, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_SSE2, 1 },
|
||||
#endif
|
||||
#if HAVE_AVX_EXTERNAL
|
||||
{ "SIMPLE8-AVX", ff_simple_idct8_avx, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_AVX},
|
||||
{ "SIMPLE10-AVX", ff_simple_idct10_avx, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_AVX},
|
||||
{ "SIMPLE12-AVX", ff_simple_idct12_avx, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_AVX, 1 },
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static const uint8_t idct_simple_mmx_perm[64] = {
|
||||
0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
|
||||
0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
|
||||
0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
|
||||
0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
|
||||
0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
|
||||
0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
|
||||
0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
|
||||
0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
|
||||
};
|
||||
|
||||
static const uint8_t idct_sse2_row_perm[8] = { 0, 4, 1, 5, 2, 6, 3, 7 };
|
||||
|
||||
static int permute_x86(int16_t dst[64], const int16_t src[64],
|
||||
enum idct_permutation_type perm_type)
|
||||
{
|
||||
int i;
|
||||
|
||||
switch (perm_type) {
|
||||
case FF_IDCT_PERM_SIMPLE:
|
||||
for (i = 0; i < 64; i++)
|
||||
dst[idct_simple_mmx_perm[i]] = src[i];
|
||||
return 1;
|
||||
case FF_IDCT_PERM_SSE2:
|
||||
for (i = 0; i < 64; i++)
|
||||
dst[(i & 0x38) | idct_sse2_row_perm[i & 7]] = src[i];
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user