Merge commit 'd12b5b2f135aade4099f4b26b0fe678656158c13'

* commit 'd12b5b2f135aade4099f4b26b0fe678656158c13':
  build: Split test programs off into separate files

Some conversions done by: James Almer <jamrial@gmail.com>
Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
pull/213/head
Derek Buitenhuis 9 years ago
commit 96d616052b
  1. 2
      libavcodec/Makefile
  2. 52
      libavcodec/avfft-test.c
  3. 34
      libavcodec/avfft.c
  4. 165
      libavcodec/cabac-test.c
  5. 147
      libavcodec/cabac.c
  6. 52
      libavcodec/iirfilter-test.c
  7. 32
      libavcodec/iirfilter.c
  8. 50
      libavcodec/imgconvert-test.c
  9. 28
      libavcodec/imgconvert.c
  10. 141
      libavcodec/jpeg2000dwt-test.c
  11. 122
      libavcodec/jpeg2000dwt.c
  12. 41
      libavcodec/mathops-test.c
  13. 26
      libavcodec/mathops.c
  14. 189
      libavcodec/options-test.c
  15. 64
      libavcodec/rangecoder-test.c
  16. 45
      libavcodec/rangecoder.c
  17. 147
      libavcodec/snowenc-test.c
  18. 129
      libavcodec/snowenc.c
  19. 37
      libavcodec/utils-test.c
  20. 20
      libavcodec/utils.c
  21. 98
      libavdevice/timefilter-test.c
  22. 77
      libavdevice/timefilter.c
  23. 0
      libavfilter/filtfmts-test.c
  24. 65
      libavfilter/formats-test.c
  25. 49
      libavfilter/formats.c
  26. 158
      libavformat/rtmpdh-test.c
  27. 142
      libavformat/rtmpdh.c
  28. 167
      libavformat/srtp-test.c
  29. 147
      libavformat/srtp.c
  30. 53
      libavutil/adler32-test.c
  31. 35
      libavutil/adler32.c
  32. 102
      libavutil/aes-test.c
  33. 84
      libavutil/aes.c
  34. 34
      libavutil/atomic-test.c
  35. 18
      libavutil/atomic.c
  36. 83
      libavutil/avstring-test.c
  37. 64
      libavutil/avstring.c
  38. 128
      libavutil/base64-test.c
  39. 107
      libavutil/base64.c
  40. 190
      libavutil/blowfish-test.c
  41. 170
      libavutil/blowfish.c
  42. 93
      libavutil/bprint-test.c
  43. 76
      libavutil/bprint.c
  44. 78
      libavutil/camellia-test.c
  45. 58
      libavutil/camellia.c
  46. 106
      libavutil/cast5-test.c
  47. 86
      libavutil/cast5.c
  48. 43
      libavutil/color_utils-test.c
  49. 28
      libavutil/color_utils.c
  50. 147
      libavutil/cpu-test.c
  51. 127
      libavutil/cpu.c
  52. 46
      libavutil/crc-test.c
  53. 26
      libavutil/crc.c
  54. 128
      libavutil/des-test.c
  55. 111
      libavutil/des.c
  56. 133
      libavutil/dict-test.c
  57. 114
      libavutil/dict.c
  58. 61
      libavutil/display-test.c
  59. 43
      libavutil/display.c
  60. 37
      libavutil/error-test.c
  61. 22
      libavutil/error.c
  62. 173
      libavutil/eval-test.c
  63. 153
      libavutil/eval.c
  64. 74
      libavutil/fifo-test.c
  65. 57
      libavutil/fifo.c
  66. 34
      libavutil/file-test.c
  67. 19
      libavutil/file.c
  68. 331
      libavutil/float_dsp-test.c
  69. 318
      libavutil/float_dsp.c
  70. 58
      libavutil/hash-test.c
  71. 42
      libavutil/hash.c
  72. 99
      libavutil/hmac-test.c
  73. 81
      libavutil/hmac.c
  74. 74
      libavutil/lfg-test.c
  75. 58
      libavutil/lfg.c
  76. 54
      libavutil/lls-test.c
  77. 38
      libavutil/lls.c
  78. 71
      libavutil/log-test.c
  79. 53
      libavutil/log.c
  80. 55
      libavutil/md5-test.c
  81. 37
      libavutil/md5.c
  82. 56
      libavutil/murmur3-test.c
  83. 37
      libavutil/murmur3.c
  84. 312
      libavutil/opt-test.c
  85. 287
      libavutil/opt.c
  86. 260
      libavutil/parseutils-test.c
  87. 237
      libavutil/parseutils.c
  88. 102
      libavutil/pca-test.c
  89. 83
      libavutil/pca.c
  90. 46
      libavutil/pixdesc-test.c
  91. 29
      libavutil/pixdesc.c
  92. 152
      libavutil/pixelutils-test.c
  93. 135
      libavutil/pixelutils.c
  94. 46
      libavutil/random_seed-test.c
  95. 26
      libavutil/random_seed.c
  96. 135
      libavutil/rational-test.c
  97. 116
      libavutil/rational.c
  98. 74
      libavutil/ripemd-test.c
  99. 54
      libavutil/ripemd.c
  100. 69
      libavutil/sha-test.c
  101. Some files were not shown because too many files have changed in this diff Show More

@ -996,9 +996,9 @@ TESTPROGS = imgconvert \
mathops \
options \
utils \
avfft \
TESTPROGS-$(CONFIG_CABAC) += cabac
TESTPROGS-$(CONFIG_DCT) += avfft
TESTPROGS-$(CONFIG_FFT) += fft fft-fixed fft-fixed32
TESTPROGS-$(CONFIG_GOLOMB) += golomb
TESTPROGS-$(CONFIG_IDCTDSP) += dct

@ -0,0 +1,52 @@
/*
* 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 "avfft.h"
int main(int argc, char **argv)
{
int i;
#define LEN 1024
FFTSample *ref = av_malloc_array(LEN, sizeof(*ref));
FFTSample *data = av_malloc_array(LEN, sizeof(*data));
RDFTContext *rdft_context = av_rdft_init(10, DFT_R2C);
RDFTContext *irdft_context = av_rdft_init(10, IDFT_C2R);
if (!ref || !data || !rdft_context || !irdft_context)
return 2;
for (i=0; i<LEN; i++) {
ref[i] = data[i] = i*456 + 123 + i*i;
}
av_rdft_calc(rdft_context, data);
av_rdft_calc(irdft_context, data);
for (i=0; i<LEN; i++) {
if (fabs(ref[i] - data[i]/LEN*2) > 1) {
fprintf(stderr, "Failed at %d (%f %f)\n", i, ref[i], data[i]/LEN*2);
return 1;
}
}
av_rdft_end(rdft_context);
av_rdft_end(irdft_context);
av_free(data);
av_free(ref);
return 0;
}

@ -142,38 +142,4 @@ av_cold void av_dct_end(DCTContext *s)
}
}
#ifdef TEST
int main(int argc, char **argv)
{
int i;
#define LEN 1024
FFTSample *ref = av_malloc_array(LEN, sizeof(*ref));
FFTSample *data = av_malloc_array(LEN, sizeof(*data));
RDFTContext *rdft_context = av_rdft_init(10, DFT_R2C);
RDFTContext *irdft_context = av_rdft_init(10, IDFT_C2R);
if (!ref || !data || !rdft_context || !irdft_context)
return 2;
for (i=0; i<LEN; i++) {
ref[i] = data[i] = i*456 + 123 + i*i;
}
av_rdft_calc(rdft_context, data);
av_rdft_calc(irdft_context, data);
for (i=0; i<LEN; i++) {
if (fabs(ref[i] - data[i]/LEN*2) > 1) {
fprintf(stderr, "Failed at %d (%f %f)\n", i, ref[i], data[i]/LEN*2);
return 1;
}
}
av_rdft_end(rdft_context);
av_rdft_end(irdft_context);
av_free(data);
av_free(ref);
return 0;
}
#endif
#endif /* CONFIG_DCT */

@ -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 "cabac.c"
#define SIZE 10240
#include "libavutil/lfg.h"
#include "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;
}

@ -200,150 +200,3 @@ int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){
return AVERROR_INVALIDDATA;
return 0;
}
#ifdef TEST
#define SIZE 10240
#include "libavutil/lfg.h"
#include "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;
}
#endif /* TEST */

@ -0,0 +1,52 @@
/*
* 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 "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;
}

@ -323,35 +323,3 @@ void ff_iir_filter_init(FFIIRFilterContext *f) {
if (HAVE_MIPSFPU)
ff_iir_filter_init_mips(f);
}
#ifdef TEST
#include <stdio.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;
}
#endif /* TEST */

@ -0,0 +1,50 @@
/*
* 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 "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));
if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) != (desc->nb_components != 2 && desc->nb_components != 4)) {
av_log(NULL, AV_LOG_ERROR, "Alpha flag mismatch\n");
err = 1;
}
}
return err;
}
FF_ENABLE_DEPRECATION_WARNINGS
#endif /* FF_API_AVPICTURE */

@ -231,33 +231,5 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
return 0;
}
#ifdef TEST
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));
if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) != (desc->nb_components != 2 && desc->nb_components != 4)) {
av_log(NULL, AV_LOG_ERROR, "Alpha flag mismatch\n");
err = 1;
}
}
return err;
}
#endif
FF_ENABLE_DEPRECATION_WARNINGS
#endif /* FF_API_AVPICTURE */

@ -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 "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;
}

@ -622,125 +622,3 @@ void ff_dwt_destroy(DWTContext *s)
av_freep(&s->f_linebuf);
av_freep(&s->i_linebuf);
}
#ifdef TEST
#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;
}
#endif

@ -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 "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;
}

@ -1,26 +0,0 @@
#include "mathops.h"
#ifdef TEST
#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;
}
#endif /* TEST */

@ -0,0 +1,189 @@
/*
* 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 "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;
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) {
printf("opened:\n");
avcodec_open2(ctx1, ctx1->codec, NULL);
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;
}

@ -0,0 +1,64 @@
/*
* 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 "rangecoder.h"
#define SIZE 10240
int main(void)
{
RangeCoder c;
uint8_t b[9 * SIZE];
uint8_t r[9 * SIZE];
int i;
uint8_t state[10];
AVLFG prng;
av_lfg_init(&prng, 1);
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);
ff_rac_terminate(&c);
ff_init_range_decoder(&c, b, SIZE);
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\n", i);
return 1;
}
return 0;
}

@ -114,48 +114,3 @@ int ff_rac_terminate(RangeCoder *c)
return c->bytestream - c->bytestream_start;
}
#ifdef TEST
#define SIZE 10240
#include "libavutil/lfg.h"
#include "libavutil/log.h"
static uint8_t b[9 * SIZE];
static uint8_t r[9 * SIZE];
int main(void)
{
RangeCoder c;
int i;
uint8_t state[10];
AVLFG prng;
av_lfg_init(&prng, 1);
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);
ff_rac_terminate(&c);
ff_init_range_decoder(&c, b, SIZE);
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\n", i);
return 1;
}
return 0;
}
#endif /* TEST */

@ -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 "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;
}

@ -1955,132 +1955,3 @@ AVCodec ff_snow_encoder = {
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
FF_CODEC_CAP_INIT_CLEANUP,
};
#ifdef TEST
#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;
}
#endif /* TEST */

@ -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 "avcodec.h"
int main(void){
AVCodec *codec = NULL;
int ret = 0;
avcodec_register_all();
while (codec = av_codec_next(codec)) {
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;
}

@ -4172,23 +4172,3 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
return 0;
}
#ifdef TEST
int main(void){
AVCodec *codec = NULL;
int ret = 0;
avcodec_register_all();
while (codec = av_codec_next(codec)) {
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;
}
#endif /* TEST */

@ -0,0 +1,98 @@
/*
* 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 "libavutil/common.h"
#include "libavutil/lfg.h"
#include "timefilter.h"
#define LFG_MAX ((1LL << 32) - 1)
int main(void)
{
AVLFG prng;
double n0, n1;
#define SAMPLES 1000
double ideal[SAMPLES];
double samples[SAMPLES];
double samplet[SAMPLES];
for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) {
for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) {
double best_error = 1000000000;
double bestpar0 = n0 ? 1 : 100000;
double bestpar1 = 1;
int better, i;
av_lfg_init(&prng, 123);
for (i = 0; i < SAMPLES; i++) {
samplet[i] = 10 + i + (av_lfg_get(&prng) < LFG_MAX/2 ? 0 : 0.999);
ideal[i] = samplet[i] + n1 * i / (1000);
samples[i] = ideal[i] + n0 * (av_lfg_get(&prng) - LFG_MAX / 2) / (LFG_MAX * 10LL);
if(i && samples[i]<samples[i-1])
samples[i]=samples[i-1]+0.001;
}
do {
double par0, par1;
better = 0;
for (par0 = bestpar0 * 0.8; par0 <= bestpar0 * 1.21; par0 += bestpar0 * 0.05) {
for (par1 = bestpar1 * 0.8; par1 <= bestpar1 * 1.21; par1 += bestpar1 * 0.05) {
double error = 0;
TimeFilter *tf = ff_timefilter_new(1, par0, par1);
if (!tf) {
printf("Could not allocate memory for timefilter.\n");
exit(1);
}
for (i = 0; i < SAMPLES; i++) {
double filtered;
filtered = ff_timefilter_update(tf, samples[i], i ? (samplet[i] - samplet[i-1]) : 1);
if(filtered < 0 || filtered > 1000000000)
printf("filter is unstable\n");
error += (filtered - ideal[i]) * (filtered - ideal[i]);
}
ff_timefilter_destroy(tf);
if (error < best_error) {
best_error = error;
bestpar0 = par0;
bestpar1 = par1;
better = 1;
}
}
}
} while (better);
#if 0
double lastfil = 9;
TimeFilter *tf = ff_timefilter_new(1, bestpar0, bestpar1);
for (i = 0; i < SAMPLES; i++) {
double filtered;
filtered = ff_timefilter_update(tf, samples[i], 1);
printf("%f %f %f %f\n", i - samples[i] + 10, filtered - samples[i],
samples[FFMAX(i, 1)] - samples[FFMAX(i - 1, 0)], filtered - lastfil);
lastfil = filtered;
}
ff_timefilter_destroy(tf);
#else
printf(" [%12f %11f %9f]", bestpar0, bestpar1, best_error);
#endif
}
printf("\n");
}
return 0;
}

@ -89,80 +89,3 @@ double ff_timefilter_eval(TimeFilter *self, double delta)
{
return self->cycle_time + self->clock_period * delta;
}
#ifdef TEST
#include "libavutil/lfg.h"
#define LFG_MAX ((1LL << 32) - 1)
int main(void)
{
AVLFG prng;
double n0, n1;
#define SAMPLES 1000
double ideal[SAMPLES];
double samples[SAMPLES];
double samplet[SAMPLES];
for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) {
for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) {
double best_error = 1000000000;
double bestpar0 = n0 ? 1 : 100000;
double bestpar1 = 1;
int better, i;
av_lfg_init(&prng, 123);
for (i = 0; i < SAMPLES; i++) {
samplet[i] = 10 + i + (av_lfg_get(&prng) < LFG_MAX/2 ? 0 : 0.999);
ideal[i] = samplet[i] + n1 * i / (1000);
samples[i] = ideal[i] + n0 * (av_lfg_get(&prng) - LFG_MAX / 2) / (LFG_MAX * 10LL);
if(i && samples[i]<samples[i-1])
samples[i]=samples[i-1]+0.001;
}
do {
double par0, par1;
better = 0;
for (par0 = bestpar0 * 0.8; par0 <= bestpar0 * 1.21; par0 += bestpar0 * 0.05) {
for (par1 = bestpar1 * 0.8; par1 <= bestpar1 * 1.21; par1 += bestpar1 * 0.05) {
double error = 0;
TimeFilter *tf = ff_timefilter_new(1, par0, par1);
if (!tf) {
printf("Could not allocate memory for timefilter.\n");
exit(1);
}
for (i = 0; i < SAMPLES; i++) {
double filtered;
filtered = ff_timefilter_update(tf, samples[i], i ? (samplet[i] - samplet[i-1]) : 1);
if(filtered < 0 || filtered > 1000000000)
printf("filter is unstable\n");
error += (filtered - ideal[i]) * (filtered - ideal[i]);
}
ff_timefilter_destroy(tf);
if (error < best_error) {
best_error = error;
bestpar0 = par0;
bestpar1 = par1;
better = 1;
}
}
}
} while (better);
#if 0
double lastfil = 9;
TimeFilter *tf = ff_timefilter_new(1, bestpar0, bestpar1);
for (i = 0; i < SAMPLES; i++) {
double filtered;
filtered = ff_timefilter_update(tf, samples[i], 1);
printf("%f %f %f %f\n", i - samples[i] + 10, filtered - samples[i],
samples[FFMAX(i, 1)] - samples[FFMAX(i - 1, 0)], filtered - lastfil);
lastfil = filtered;
}
ff_timefilter_destroy(tf);
#else
printf(" [%12f %11f %9f]", bestpar0, bestpar1, best_error);
#endif
}
printf("\n");
}
return 0;
}
#endif

@ -0,0 +1,65 @@
/*
* Copyright (c) 2007 Bobby Bingham
*
* 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 "formats.c"
#undef printf
int main(void)
{
const int64_t *cl;
char buf[512];
int i;
const char *teststrings[] ={
"blah",
"1",
"2",
"-1",
"60",
"65",
"1c",
"2c",
"-1c",
"60c",
"65c",
"5.1",
"stereo",
"1+1+1+1",
"1c+1c+1c+1c",
"2c+1c",
"0x3",
};
for (cl = avfilter_all_channel_layouts; *cl != -1; cl++) {
av_get_channel_layout_string(buf, sizeof(buf), -1, *cl);
printf("%s\n", buf);
}
for ( i = 0; i<FF_ARRAY_ELEMS(teststrings); i++) {
int64_t layout = -1;
int count = -1;
int ret;
ret = ff_parse_channel_layout(&layout, &count, teststrings[i], NULL);
printf ("%d = ff_parse_channel_layout(%016"PRIX64", %2d, %s);\n", ret ? -1 : 0, layout, count, teststrings[i]);
}
return 0;
}

@ -683,52 +683,3 @@ int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
*nret = av_get_channel_layout_nb_channels(chlayout);
return 0;
}
#ifdef TEST
#undef printf
int main(void)
{
const int64_t *cl;
char buf[512];
int i;
const char *teststrings[] ={
"blah",
"1",
"2",
"-1",
"60",
"65",
"1c",
"2c",
"-1c",
"60c",
"65c",
"5.1",
"stereo",
"1+1+1+1",
"1c+1c+1c+1c",
"2c+1c",
"0x3",
};
for (cl = avfilter_all_channel_layouts; *cl != -1; cl++) {
av_get_channel_layout_string(buf, sizeof(buf), -1, *cl);
printf("%s\n", buf);
}
for ( i = 0; i<FF_ARRAY_ELEMS(teststrings); i++) {
int64_t layout = -1;
int count = -1;
int ret;
ret = ff_parse_channel_layout(&layout, &count, teststrings[i], NULL);
printf ("%d = ff_parse_channel_layout(%016"PRIX64", %2d, %s);\n", ret ? -1 : 0, layout, count, teststrings[i]);
}
return 0;
}
#endif

@ -0,0 +1,158 @@
/*
* 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 "rtmpdh.c"
#include <stdio.h>
static int test_random_shared_secret(void)
{
FF_DH *peer1 = NULL, *peer2 = NULL;
int ret;
uint8_t pubkey1[128], pubkey2[128];
uint8_t sharedkey1[128], sharedkey2[128];
peer1 = ff_dh_init(1024);
peer2 = ff_dh_init(1024);
if (!peer1 || !peer2) {
ret = AVERROR(ENOMEM);
goto fail;
}
if ((ret = ff_dh_generate_public_key(peer1)) < 0)
goto fail;
if ((ret = ff_dh_generate_public_key(peer2)) < 0)
goto fail;
if ((ret = ff_dh_write_public_key(peer1, pubkey1, sizeof(pubkey1))) < 0)
goto fail;
if ((ret = ff_dh_write_public_key(peer2, pubkey2, sizeof(pubkey2))) < 0)
goto fail;
if ((ret = ff_dh_compute_shared_secret_key(peer1, pubkey2, sizeof(pubkey2),
sharedkey1, sizeof(sharedkey1))) < 0)
goto fail;
if ((ret = ff_dh_compute_shared_secret_key(peer2, pubkey1, sizeof(pubkey1),
sharedkey2, sizeof(sharedkey2))) < 0)
goto fail;
if (memcmp(sharedkey1, sharedkey2, sizeof(sharedkey1))) {
printf("Mismatched generated shared key\n");
ret = AVERROR_INVALIDDATA;
} else {
printf("Generated shared key ok\n");
}
fail:
ff_dh_free(peer1);
ff_dh_free(peer2);
return ret;
}
static const char *private_key =
"976C18FCADC255B456564F74F3EEDA59D28AF6B744D743F2357BFD2404797EF896EF1A"
"7C1CBEAAA3AB60AF3192D189CFF3F991C9CBBFD78119FCA2181384B94011943B6D6F28"
"9E1B708E2D1A0C7771169293F03DA27E561F15F16F0AC9BC858C77A80FA98FD088A232"
"19D08BE6F165DE0B02034B18705829FAD0ACB26A5B75EF";
static const char *public_key =
"F272ECF8362257C5D2C3CC2229CF9C0A03225BC109B1DBC76A68C394F256ACA3EF5F64"
"FC270C26382BF315C19E97A76104A716FC998A651E8610A3AE6CF65D8FAE5D3F32EEA0"
"0B32CB9609B494116A825D7142D17B88E3D20EDD98743DE29CF37A23A9F6A58B960591"
"3157D5965FCB46DDA73A1F08DD897BAE88DFE6FC937CBA";
static const uint8_t public_key_bin[] = {
0xf2, 0x72, 0xec, 0xf8, 0x36, 0x22, 0x57, 0xc5, 0xd2, 0xc3, 0xcc, 0x22,
0x29, 0xcf, 0x9c, 0x0a, 0x03, 0x22, 0x5b, 0xc1, 0x09, 0xb1, 0xdb, 0xc7,
0x6a, 0x68, 0xc3, 0x94, 0xf2, 0x56, 0xac, 0xa3, 0xef, 0x5f, 0x64, 0xfc,
0x27, 0x0c, 0x26, 0x38, 0x2b, 0xf3, 0x15, 0xc1, 0x9e, 0x97, 0xa7, 0x61,
0x04, 0xa7, 0x16, 0xfc, 0x99, 0x8a, 0x65, 0x1e, 0x86, 0x10, 0xa3, 0xae,
0x6c, 0xf6, 0x5d, 0x8f, 0xae, 0x5d, 0x3f, 0x32, 0xee, 0xa0, 0x0b, 0x32,
0xcb, 0x96, 0x09, 0xb4, 0x94, 0x11, 0x6a, 0x82, 0x5d, 0x71, 0x42, 0xd1,
0x7b, 0x88, 0xe3, 0xd2, 0x0e, 0xdd, 0x98, 0x74, 0x3d, 0xe2, 0x9c, 0xf3,
0x7a, 0x23, 0xa9, 0xf6, 0xa5, 0x8b, 0x96, 0x05, 0x91, 0x31, 0x57, 0xd5,
0x96, 0x5f, 0xcb, 0x46, 0xdd, 0xa7, 0x3a, 0x1f, 0x08, 0xdd, 0x89, 0x7b,
0xae, 0x88, 0xdf, 0xe6, 0xfc, 0x93, 0x7c, 0xba
};
static const uint8_t peer_public_key[] = {
0x58, 0x66, 0x05, 0x49, 0x94, 0x23, 0x2b, 0x66, 0x52, 0x13, 0xff, 0x46,
0xf2, 0xb3, 0x79, 0xa9, 0xee, 0xae, 0x1a, 0x13, 0xf0, 0x71, 0x52, 0xfb,
0x93, 0x4e, 0xee, 0x97, 0x05, 0x73, 0x50, 0x7d, 0xaf, 0x02, 0x07, 0x72,
0xac, 0xdc, 0xa3, 0x95, 0x78, 0xee, 0x9a, 0x19, 0x71, 0x7e, 0x99, 0x9f,
0x2a, 0xd4, 0xb3, 0xe2, 0x0c, 0x1d, 0x1a, 0x78, 0x4c, 0xde, 0xf1, 0xad,
0xb4, 0x60, 0xa8, 0x51, 0xac, 0x71, 0xec, 0x86, 0x70, 0xa2, 0x63, 0x36,
0x92, 0x7c, 0xe3, 0x87, 0xee, 0xe4, 0xf1, 0x62, 0x24, 0x74, 0xb4, 0x04,
0xfa, 0x5c, 0xdf, 0xba, 0xfa, 0xa3, 0xc2, 0xbb, 0x62, 0x27, 0xd0, 0xf4,
0xe4, 0x43, 0xda, 0x8a, 0x88, 0x69, 0x60, 0xe2, 0xdb, 0x75, 0x2a, 0x98,
0x9d, 0xb5, 0x50, 0xe3, 0x99, 0xda, 0xe0, 0xa6, 0x14, 0xc9, 0x80, 0x12,
0xf9, 0x3c, 0xac, 0x06, 0x02, 0x7a, 0xde, 0x74
};
static const uint8_t shared_secret[] = {
0xb2, 0xeb, 0xcb, 0x71, 0xf3, 0x61, 0xfb, 0x5b, 0x4e, 0x5c, 0x4c, 0xcf,
0x5c, 0x08, 0x5f, 0x96, 0x26, 0x77, 0x1d, 0x31, 0xf1, 0xe1, 0xf7, 0x4b,
0x92, 0xac, 0x82, 0x2a, 0x88, 0xc7, 0x83, 0xe1, 0xc7, 0xf3, 0xd3, 0x1a,
0x7d, 0xc8, 0x31, 0xe3, 0x97, 0xe4, 0xec, 0x31, 0x0e, 0x8f, 0x73, 0x1a,
0xe4, 0xf6, 0xd8, 0xc8, 0x94, 0xff, 0xa0, 0x03, 0x84, 0x03, 0x0f, 0xa5,
0x30, 0x5d, 0x67, 0xe0, 0x7a, 0x3b, 0x5f, 0xed, 0x4c, 0xf5, 0xbc, 0x18,
0xea, 0xd4, 0x77, 0xa9, 0x07, 0xb3, 0x54, 0x0b, 0x02, 0xd9, 0xc6, 0xb8,
0x66, 0x5e, 0xec, 0xa4, 0xcd, 0x47, 0xed, 0xc9, 0x38, 0xc6, 0x91, 0x08,
0xf3, 0x85, 0x9b, 0x69, 0x16, 0x78, 0x0d, 0xb7, 0x74, 0x51, 0xaa, 0x5b,
0x4d, 0x74, 0xe4, 0x29, 0x2e, 0x9e, 0x8e, 0xf7, 0xe5, 0x42, 0x83, 0xb0,
0x65, 0xb0, 0xce, 0xc6, 0xb2, 0x8f, 0x5b, 0xb0
};
static int test_ref_data(void)
{
FF_DH *dh;
int ret = AVERROR(ENOMEM);
uint8_t pubkey_test[128];
uint8_t sharedkey_test[128];
dh = ff_dh_init(1024);
if (!dh)
goto fail;
bn_hex2bn(dh->priv_key, private_key, ret);
if (!ret)
goto fail;
bn_hex2bn(dh->pub_key, public_key, ret);
if (!ret)
goto fail;
if ((ret = ff_dh_write_public_key(dh, pubkey_test, sizeof(pubkey_test))) < 0)
goto fail;
if (memcmp(pubkey_test, public_key_bin, sizeof(pubkey_test))) {
printf("Mismatched generated public key\n");
ret = AVERROR_INVALIDDATA;
goto fail;
} else {
printf("Generated public key ok\n");
}
if ((ret = ff_dh_compute_shared_secret_key(dh, peer_public_key, sizeof(peer_public_key),
sharedkey_test, sizeof(sharedkey_test))) < 0)
goto fail;
if (memcmp(shared_secret, sharedkey_test, sizeof(sharedkey_test))) {
printf("Mismatched generated shared key\n");
ret = AVERROR_INVALIDDATA;
} else {
printf("Generated shared key ok\n");
}
fail:
ff_dh_free(dh);
return ret;
}
int main(void)
{
if (test_random_shared_secret() < 0)
return 1;
if (test_ref_data() < 0)
return 1;
return 0;
}

@ -369,145 +369,3 @@ fail:
return ret;
}
#ifdef TEST
#include <stdio.h>
static int test_random_shared_secret(void)
{
FF_DH *peer1 = NULL, *peer2 = NULL;
int ret;
uint8_t pubkey1[128], pubkey2[128];
uint8_t sharedkey1[128], sharedkey2[128];
peer1 = ff_dh_init(1024);
peer2 = ff_dh_init(1024);
if (!peer1 || !peer2) {
ret = AVERROR(ENOMEM);
goto fail;
}
if ((ret = ff_dh_generate_public_key(peer1)) < 0)
goto fail;
if ((ret = ff_dh_generate_public_key(peer2)) < 0)
goto fail;
if ((ret = ff_dh_write_public_key(peer1, pubkey1, sizeof(pubkey1))) < 0)
goto fail;
if ((ret = ff_dh_write_public_key(peer2, pubkey2, sizeof(pubkey2))) < 0)
goto fail;
if ((ret = ff_dh_compute_shared_secret_key(peer1, pubkey2, sizeof(pubkey2),
sharedkey1, sizeof(sharedkey1))) < 0)
goto fail;
if ((ret = ff_dh_compute_shared_secret_key(peer2, pubkey1, sizeof(pubkey1),
sharedkey2, sizeof(sharedkey2))) < 0)
goto fail;
if (memcmp(sharedkey1, sharedkey2, sizeof(sharedkey1))) {
printf("Mismatched generated shared key\n");
ret = AVERROR_INVALIDDATA;
} else {
printf("Generated shared key ok\n");
}
fail:
ff_dh_free(peer1);
ff_dh_free(peer2);
return ret;
}
static const char *private_key =
"976C18FCADC255B456564F74F3EEDA59D28AF6B744D743F2357BFD2404797EF896EF1A"
"7C1CBEAAA3AB60AF3192D189CFF3F991C9CBBFD78119FCA2181384B94011943B6D6F28"
"9E1B708E2D1A0C7771169293F03DA27E561F15F16F0AC9BC858C77A80FA98FD088A232"
"19D08BE6F165DE0B02034B18705829FAD0ACB26A5B75EF";
static const char *public_key =
"F272ECF8362257C5D2C3CC2229CF9C0A03225BC109B1DBC76A68C394F256ACA3EF5F64"
"FC270C26382BF315C19E97A76104A716FC998A651E8610A3AE6CF65D8FAE5D3F32EEA0"
"0B32CB9609B494116A825D7142D17B88E3D20EDD98743DE29CF37A23A9F6A58B960591"
"3157D5965FCB46DDA73A1F08DD897BAE88DFE6FC937CBA";
static const uint8_t public_key_bin[] = {
0xf2, 0x72, 0xec, 0xf8, 0x36, 0x22, 0x57, 0xc5, 0xd2, 0xc3, 0xcc, 0x22,
0x29, 0xcf, 0x9c, 0x0a, 0x03, 0x22, 0x5b, 0xc1, 0x09, 0xb1, 0xdb, 0xc7,
0x6a, 0x68, 0xc3, 0x94, 0xf2, 0x56, 0xac, 0xa3, 0xef, 0x5f, 0x64, 0xfc,
0x27, 0x0c, 0x26, 0x38, 0x2b, 0xf3, 0x15, 0xc1, 0x9e, 0x97, 0xa7, 0x61,
0x04, 0xa7, 0x16, 0xfc, 0x99, 0x8a, 0x65, 0x1e, 0x86, 0x10, 0xa3, 0xae,
0x6c, 0xf6, 0x5d, 0x8f, 0xae, 0x5d, 0x3f, 0x32, 0xee, 0xa0, 0x0b, 0x32,
0xcb, 0x96, 0x09, 0xb4, 0x94, 0x11, 0x6a, 0x82, 0x5d, 0x71, 0x42, 0xd1,
0x7b, 0x88, 0xe3, 0xd2, 0x0e, 0xdd, 0x98, 0x74, 0x3d, 0xe2, 0x9c, 0xf3,
0x7a, 0x23, 0xa9, 0xf6, 0xa5, 0x8b, 0x96, 0x05, 0x91, 0x31, 0x57, 0xd5,
0x96, 0x5f, 0xcb, 0x46, 0xdd, 0xa7, 0x3a, 0x1f, 0x08, 0xdd, 0x89, 0x7b,
0xae, 0x88, 0xdf, 0xe6, 0xfc, 0x93, 0x7c, 0xba
};
static const uint8_t peer_public_key[] = {
0x58, 0x66, 0x05, 0x49, 0x94, 0x23, 0x2b, 0x66, 0x52, 0x13, 0xff, 0x46,
0xf2, 0xb3, 0x79, 0xa9, 0xee, 0xae, 0x1a, 0x13, 0xf0, 0x71, 0x52, 0xfb,
0x93, 0x4e, 0xee, 0x97, 0x05, 0x73, 0x50, 0x7d, 0xaf, 0x02, 0x07, 0x72,
0xac, 0xdc, 0xa3, 0x95, 0x78, 0xee, 0x9a, 0x19, 0x71, 0x7e, 0x99, 0x9f,
0x2a, 0xd4, 0xb3, 0xe2, 0x0c, 0x1d, 0x1a, 0x78, 0x4c, 0xde, 0xf1, 0xad,
0xb4, 0x60, 0xa8, 0x51, 0xac, 0x71, 0xec, 0x86, 0x70, 0xa2, 0x63, 0x36,
0x92, 0x7c, 0xe3, 0x87, 0xee, 0xe4, 0xf1, 0x62, 0x24, 0x74, 0xb4, 0x04,
0xfa, 0x5c, 0xdf, 0xba, 0xfa, 0xa3, 0xc2, 0xbb, 0x62, 0x27, 0xd0, 0xf4,
0xe4, 0x43, 0xda, 0x8a, 0x88, 0x69, 0x60, 0xe2, 0xdb, 0x75, 0x2a, 0x98,
0x9d, 0xb5, 0x50, 0xe3, 0x99, 0xda, 0xe0, 0xa6, 0x14, 0xc9, 0x80, 0x12,
0xf9, 0x3c, 0xac, 0x06, 0x02, 0x7a, 0xde, 0x74
};
static const uint8_t shared_secret[] = {
0xb2, 0xeb, 0xcb, 0x71, 0xf3, 0x61, 0xfb, 0x5b, 0x4e, 0x5c, 0x4c, 0xcf,
0x5c, 0x08, 0x5f, 0x96, 0x26, 0x77, 0x1d, 0x31, 0xf1, 0xe1, 0xf7, 0x4b,
0x92, 0xac, 0x82, 0x2a, 0x88, 0xc7, 0x83, 0xe1, 0xc7, 0xf3, 0xd3, 0x1a,
0x7d, 0xc8, 0x31, 0xe3, 0x97, 0xe4, 0xec, 0x31, 0x0e, 0x8f, 0x73, 0x1a,
0xe4, 0xf6, 0xd8, 0xc8, 0x94, 0xff, 0xa0, 0x03, 0x84, 0x03, 0x0f, 0xa5,
0x30, 0x5d, 0x67, 0xe0, 0x7a, 0x3b, 0x5f, 0xed, 0x4c, 0xf5, 0xbc, 0x18,
0xea, 0xd4, 0x77, 0xa9, 0x07, 0xb3, 0x54, 0x0b, 0x02, 0xd9, 0xc6, 0xb8,
0x66, 0x5e, 0xec, 0xa4, 0xcd, 0x47, 0xed, 0xc9, 0x38, 0xc6, 0x91, 0x08,
0xf3, 0x85, 0x9b, 0x69, 0x16, 0x78, 0x0d, 0xb7, 0x74, 0x51, 0xaa, 0x5b,
0x4d, 0x74, 0xe4, 0x29, 0x2e, 0x9e, 0x8e, 0xf7, 0xe5, 0x42, 0x83, 0xb0,
0x65, 0xb0, 0xce, 0xc6, 0xb2, 0x8f, 0x5b, 0xb0
};
static int test_ref_data(void)
{
FF_DH *dh;
int ret = AVERROR(ENOMEM);
uint8_t pubkey_test[128];
uint8_t sharedkey_test[128];
dh = ff_dh_init(1024);
if (!dh)
goto fail;
bn_hex2bn(dh->priv_key, private_key, ret);
if (!ret)
goto fail;
bn_hex2bn(dh->pub_key, public_key, ret);
if (!ret)
goto fail;
if ((ret = ff_dh_write_public_key(dh, pubkey_test, sizeof(pubkey_test))) < 0)
goto fail;
if (memcmp(pubkey_test, public_key_bin, sizeof(pubkey_test))) {
printf("Mismatched generated public key\n");
ret = AVERROR_INVALIDDATA;
goto fail;
} else {
printf("Generated public key ok\n");
}
if ((ret = ff_dh_compute_shared_secret_key(dh, peer_public_key, sizeof(peer_public_key),
sharedkey_test, sizeof(sharedkey_test))) < 0)
goto fail;
if (memcmp(shared_secret, sharedkey_test, sizeof(sharedkey_test))) {
printf("Mismatched generated shared key\n");
ret = AVERROR_INVALIDDATA;
} else {
printf("Generated shared key ok\n");
}
fail:
ff_dh_free(dh);
return ret;
}
int main(void)
{
if (test_random_shared_secret() < 0)
return 1;
if (test_ref_data() < 0)
return 1;
return 0;
}
#endif

@ -0,0 +1,167 @@
/*
* 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 <string.h>
#include "rtpdec.h"
#include "srtp.h"
static const char *aes128_80_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
static const uint8_t rtp_aes128_80[] = {
// RTP header
0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x62, 0x69, 0x76, 0xca, 0xc5,
// HMAC
0xa1, 0xac, 0x1b, 0xb4, 0xa0, 0x1c, 0xd5, 0x49, 0x28, 0x99,
};
static const uint8_t rtcp_aes128_80[] = {
// RTCP header
0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x8a, 0xac, 0xdc, 0xa5, 0x4c, 0xf6, 0x78, 0xa6, 0x62, 0x8f, 0x24, 0xda,
0x6c, 0x09, 0x3f, 0xa9, 0x28, 0x7a, 0xb5, 0x7f, 0x1f, 0x0f, 0xc9, 0x35,
// RTCP index
0x80, 0x00, 0x00, 0x03,
// HMAC
0xe9, 0x3b, 0xc0, 0x5c, 0x0c, 0x06, 0x9f, 0xab, 0xc0, 0xde,
};
static const char *aes128_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
static const uint8_t rtp_aes128_32[] = {
// RTP header
0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x62, 0x69, 0x76, 0xca, 0xc5,
// HMAC
0xa1, 0xac, 0x1b, 0xb4,
};
static const uint8_t rtcp_aes128_32[] = {
// RTCP header
0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x35, 0xe9, 0xb5, 0xff, 0x0d, 0xd1, 0xde, 0x70, 0x74, 0x10, 0xaa, 0x1b,
0xb2, 0x8d, 0xf0, 0x20, 0x02, 0x99, 0x6b, 0x1b, 0x0b, 0xd0, 0x47, 0x34,
// RTCP index
0x80, 0x00, 0x00, 0x04,
// HMAC
0x5b, 0xd2, 0xa9, 0x9d,
};
static const char *aes128_80_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
static const uint8_t rtp_aes128_80_32[] = {
// RTP header
0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x62, 0x69, 0x76, 0xca, 0xc5,
// HMAC
0xa1, 0xac, 0x1b, 0xb4,
};
static const uint8_t rtcp_aes128_80_32[] = {
// RTCP header
0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0xd6, 0xae, 0xc1, 0x58, 0x63, 0x70, 0xc9, 0x88, 0x66, 0x26, 0x1c, 0x53,
0xff, 0x5d, 0x5d, 0x2b, 0x0f, 0x8c, 0x72, 0x3e, 0xc9, 0x1d, 0x43, 0xf9,
// RTCP index
0x80, 0x00, 0x00, 0x05,
// HMAC
0x09, 0x16, 0xb4, 0x27, 0x9a, 0xe9, 0x92, 0x26, 0x4e, 0x10,
};
static void print_data(const uint8_t *buf, int len)
{
int i;
for (i = 0; i < len; i++)
printf("%02x", buf[i]);
printf("\n");
}
static int test_decrypt(struct SRTPContext *srtp, const uint8_t *in, int len,
uint8_t *out)
{
memcpy(out, in, len);
if (!ff_srtp_decrypt(srtp, out, &len)) {
print_data(out, len);
return len;
} else
return -1;
}
static void test_encrypt(const uint8_t *data, int in_len, const char *suite,
const char *key)
{
struct SRTPContext enc = { 0 }, dec = { 0 };
int len;
char buf[RTP_MAX_PACKET_LENGTH];
ff_srtp_set_crypto(&enc, suite, key);
ff_srtp_set_crypto(&dec, suite, key);
len = ff_srtp_encrypt(&enc, data, in_len, buf, sizeof(buf));
if (!ff_srtp_decrypt(&dec, buf, &len)) {
if (len == in_len && !memcmp(buf, data, len))
printf("Decrypted content matches input\n");
else
printf("Decrypted content doesn't match input\n");
} else {
printf("Decryption failed\n");
}
ff_srtp_free(&enc);
ff_srtp_free(&dec);
}
int main(void)
{
static const char *aes128_80_suite = "AES_CM_128_HMAC_SHA1_80";
static const char *aes128_32_suite = "AES_CM_128_HMAC_SHA1_32";
static const char *aes128_80_32_suite = "SRTP_AES128_CM_HMAC_SHA1_32";
static const char *test_key = "abcdefghijklmnopqrstuvwxyz1234567890ABCD";
uint8_t buf[RTP_MAX_PACKET_LENGTH];
struct SRTPContext srtp = { 0 };
int len;
ff_srtp_set_crypto(&srtp, aes128_80_suite, aes128_80_key);
len = test_decrypt(&srtp, rtp_aes128_80, sizeof(rtp_aes128_80), buf);
test_encrypt(buf, len, aes128_80_suite, test_key);
test_encrypt(buf, len, aes128_32_suite, test_key);
test_encrypt(buf, len, aes128_80_32_suite, test_key);
test_decrypt(&srtp, rtcp_aes128_80, sizeof(rtcp_aes128_80), buf);
test_encrypt(buf, len, aes128_80_suite, test_key);
test_encrypt(buf, len, aes128_32_suite, test_key);
test_encrypt(buf, len, aes128_80_32_suite, test_key);
ff_srtp_free(&srtp);
memset(&srtp, 0, sizeof(srtp)); // Clear the context
ff_srtp_set_crypto(&srtp, aes128_32_suite, aes128_32_key);
test_decrypt(&srtp, rtp_aes128_32, sizeof(rtp_aes128_32), buf);
test_decrypt(&srtp, rtcp_aes128_32, sizeof(rtcp_aes128_32), buf);
ff_srtp_free(&srtp);
memset(&srtp, 0, sizeof(srtp)); // Clear the context
ff_srtp_set_crypto(&srtp, aes128_80_32_suite, aes128_80_32_key);
test_decrypt(&srtp, rtp_aes128_80_32, sizeof(rtp_aes128_80_32), buf);
test_decrypt(&srtp, rtcp_aes128_80_32, sizeof(rtcp_aes128_80_32), buf);
ff_srtp_free(&srtp);
return 0;
}

@ -323,150 +323,3 @@ int ff_srtp_encrypt(struct SRTPContext *s, const uint8_t *in, int len,
len += hmac_size;
return buf + len - out;
}
#ifdef TEST
#include <stdio.h>
static const char *aes128_80_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
static const uint8_t rtp_aes128_80[] = {
// RTP header
0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x62, 0x69, 0x76, 0xca, 0xc5,
// HMAC
0xa1, 0xac, 0x1b, 0xb4, 0xa0, 0x1c, 0xd5, 0x49, 0x28, 0x99,
};
static const uint8_t rtcp_aes128_80[] = {
// RTCP header
0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x8a, 0xac, 0xdc, 0xa5, 0x4c, 0xf6, 0x78, 0xa6, 0x62, 0x8f, 0x24, 0xda,
0x6c, 0x09, 0x3f, 0xa9, 0x28, 0x7a, 0xb5, 0x7f, 0x1f, 0x0f, 0xc9, 0x35,
// RTCP index
0x80, 0x00, 0x00, 0x03,
// HMAC
0xe9, 0x3b, 0xc0, 0x5c, 0x0c, 0x06, 0x9f, 0xab, 0xc0, 0xde,
};
static const char *aes128_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
static const uint8_t rtp_aes128_32[] = {
// RTP header
0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x62, 0x69, 0x76, 0xca, 0xc5,
// HMAC
0xa1, 0xac, 0x1b, 0xb4,
};
static const uint8_t rtcp_aes128_32[] = {
// RTCP header
0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x35, 0xe9, 0xb5, 0xff, 0x0d, 0xd1, 0xde, 0x70, 0x74, 0x10, 0xaa, 0x1b,
0xb2, 0x8d, 0xf0, 0x20, 0x02, 0x99, 0x6b, 0x1b, 0x0b, 0xd0, 0x47, 0x34,
// RTCP index
0x80, 0x00, 0x00, 0x04,
// HMAC
0x5b, 0xd2, 0xa9, 0x9d,
};
static const char *aes128_80_32_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn";
static const uint8_t rtp_aes128_80_32[] = {
// RTP header
0x80, 0xe0, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0x62, 0x69, 0x76, 0xca, 0xc5,
// HMAC
0xa1, 0xac, 0x1b, 0xb4,
};
static const uint8_t rtcp_aes128_80_32[] = {
// RTCP header
0x81, 0xc9, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
// encrypted payload
0xd6, 0xae, 0xc1, 0x58, 0x63, 0x70, 0xc9, 0x88, 0x66, 0x26, 0x1c, 0x53,
0xff, 0x5d, 0x5d, 0x2b, 0x0f, 0x8c, 0x72, 0x3e, 0xc9, 0x1d, 0x43, 0xf9,
// RTCP index
0x80, 0x00, 0x00, 0x05,
// HMAC
0x09, 0x16, 0xb4, 0x27, 0x9a, 0xe9, 0x92, 0x26, 0x4e, 0x10,
};
static void print_data(const uint8_t *buf, int len)
{
int i;
for (i = 0; i < len; i++)
printf("%02x", buf[i]);
printf("\n");
}
static int test_decrypt(struct SRTPContext *srtp, const uint8_t *in, int len,
uint8_t *out)
{
memcpy(out, in, len);
if (!ff_srtp_decrypt(srtp, out, &len)) {
print_data(out, len);
return len;
} else
return -1;
}
static void test_encrypt(const uint8_t *data, int in_len, const char *suite,
const char *key)
{
struct SRTPContext enc = { 0 }, dec = { 0 };
int len;
char buf[RTP_MAX_PACKET_LENGTH];
ff_srtp_set_crypto(&enc, suite, key);
ff_srtp_set_crypto(&dec, suite, key);
len = ff_srtp_encrypt(&enc, data, in_len, buf, sizeof(buf));
if (!ff_srtp_decrypt(&dec, buf, &len)) {
if (len == in_len && !memcmp(buf, data, len))
printf("Decrypted content matches input\n");
else
printf("Decrypted content doesn't match input\n");
} else {
printf("Decryption failed\n");
}
ff_srtp_free(&enc);
ff_srtp_free(&dec);
}
int main(void)
{
static const char *aes128_80_suite = "AES_CM_128_HMAC_SHA1_80";
static const char *aes128_32_suite = "AES_CM_128_HMAC_SHA1_32";
static const char *aes128_80_32_suite = "SRTP_AES128_CM_HMAC_SHA1_32";
static const char *test_key = "abcdefghijklmnopqrstuvwxyz1234567890ABCD";
uint8_t buf[RTP_MAX_PACKET_LENGTH];
struct SRTPContext srtp = { 0 };
int len;
ff_srtp_set_crypto(&srtp, aes128_80_suite, aes128_80_key);
len = test_decrypt(&srtp, rtp_aes128_80, sizeof(rtp_aes128_80), buf);
test_encrypt(buf, len, aes128_80_suite, test_key);
test_encrypt(buf, len, aes128_32_suite, test_key);
test_encrypt(buf, len, aes128_80_32_suite, test_key);
test_decrypt(&srtp, rtcp_aes128_80, sizeof(rtcp_aes128_80), buf);
test_encrypt(buf, len, aes128_80_suite, test_key);
test_encrypt(buf, len, aes128_32_suite, test_key);
test_encrypt(buf, len, aes128_80_32_suite, test_key);
ff_srtp_free(&srtp);
memset(&srtp, 0, sizeof(srtp)); // Clear the context
ff_srtp_set_crypto(&srtp, aes128_32_suite, aes128_32_key);
test_decrypt(&srtp, rtp_aes128_32, sizeof(rtp_aes128_32), buf);
test_decrypt(&srtp, rtcp_aes128_32, sizeof(rtcp_aes128_32), buf);
ff_srtp_free(&srtp);
memset(&srtp, 0, sizeof(srtp)); // Clear the context
ff_srtp_set_crypto(&srtp, aes128_80_32_suite, aes128_80_32_key);
test_decrypt(&srtp, rtp_aes128_80_32, sizeof(rtp_aes128_80_32), buf);
test_decrypt(&srtp, rtcp_aes128_80_32, sizeof(rtcp_aes128_80_32), buf);
ff_srtp_free(&srtp);
return 0;
}
#endif /* TEST */

@ -0,0 +1,53 @@
/*
* 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
*/
// LCOV_EXCL_START
#include <string.h>
#include "log.h"
#include "timer.h"
#include "adler32.h"
#define LEN 7001
static volatile int checksum;
int main(int argc, char **argv)
{
int i;
uint8_t data[LEN];
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < LEN; i++)
data[i] = ((i * i) >> 3) + 123 * i;
if (argc > 1 && !strcmp(argv[1], "-t")) {
for (i = 0; i < 1000; i++) {
START_TIMER;
checksum = av_adler32_update(1, data, LEN);
STOP_TIMER("adler");
}
} else {
checksum = av_adler32_update(1, data, LEN);
}
av_log(NULL, AV_LOG_DEBUG, "%X (expected 50E6E508)\n", checksum);
return checksum == 0x50e6e508 ? 0 : 1;
}
// LCOV_EXCL_STOP

@ -95,38 +95,3 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf,
}
return (s2 << 16) | s1;
}
#ifdef TEST
// LCOV_EXCL_START
#include <string.h>
#include "log.h"
#include "timer.h"
#define LEN 7001
static volatile int checksum;
int main(int argc, char **argv)
{
int i;
uint8_t data[LEN];
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < LEN; i++)
data[i] = ((i * i) >> 3) + 123 * i;
if (argc > 1 && !strcmp(argv[1], "-t")) {
for (i = 0; i < 1000; i++) {
START_TIMER;
checksum = av_adler32_update(1, data, LEN);
STOP_TIMER("adler");
}
} else {
checksum = av_adler32_update(1, data, LEN);
}
av_log(NULL, AV_LOG_DEBUG, "%X (expected 50E6E508)\n", checksum);
return checksum == 0x50e6e508 ? 0 : 1;
}
// LCOV_EXCL_STOP
#endif

@ -0,0 +1,102 @@
/*
* 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 "aes.c"
// LCOV_EXCL_START
#include <string.h>
#include "lfg.h"
#include "log.h"
int main(int argc, char **argv)
{
int i, j;
AVAES b;
uint8_t rkey[2][16] = {
{ 0 },
{ 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
};
uint8_t pt[32], rpt[2][16] = {
{ 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
{ 0 }
};
uint8_t rct[2][16] = {
{ 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7,
0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf },
{ 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0,
0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65 }
};
uint8_t temp[32];
uint8_t iv[2][16];
int err = 0;
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < 2; i++) {
av_aes_init(&b, rkey[i], 128, 1);
av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
for (j = 0; j < 16; j++) {
if (rpt[i][j] != temp[j]) {
av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n",
j, rpt[i][j], temp[j]);
err = 1;
}
}
}
if (argc > 1 && !strcmp(argv[1], "-t")) {
AVAES ae, ad;
AVLFG prng;
av_aes_init(&ae, (const uint8_t*)"PI=3.141592654..", 128, 0);
av_aes_init(&ad, (const uint8_t*)"PI=3.141592654..", 128, 1);
av_lfg_init(&prng, 1);
for (i = 0; i < 10000; i++) {
for (j = 0; j < 32; j++)
pt[j] = av_lfg_get(&prng);
for (j = 0; j < 16; j++)
iv[0][j] = iv[1][j] = av_lfg_get(&prng);
{
START_TIMER;
av_aes_crypt(&ae, temp, pt, 2, iv[0], 0);
if (!(i & (i - 1)))
av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
temp[0], temp[5], temp[10], temp[15]);
av_aes_crypt(&ad, temp, temp, 2, iv[1], 1);
av_aes_crypt(&ae, temp, pt, 2, NULL, 0);
if (!(i & (i - 1)))
av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
temp[0], temp[5], temp[10], temp[15]);
av_aes_crypt(&ad, temp, temp, 2, NULL, 1);
STOP_TIMER("aes");
}
for (j = 0; j < 16; j++) {
if (pt[j] != temp[j]) {
av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n",
i, j, pt[j], temp[j]);
}
}
}
}
return err;
}
// LCOV_EXCL_STOP

@ -266,87 +266,3 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
return 0;
}
#ifdef TEST
// LCOV_EXCL_START
#include <string.h>
#include "lfg.h"
#include "log.h"
int main(int argc, char **argv)
{
int i, j;
AVAES b;
uint8_t rkey[2][16] = {
{ 0 },
{ 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
};
uint8_t pt[32], rpt[2][16] = {
{ 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
{ 0 }
};
uint8_t rct[2][16] = {
{ 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7,
0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf },
{ 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0,
0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65 }
};
uint8_t temp[32];
uint8_t iv[2][16];
int err = 0;
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < 2; i++) {
av_aes_init(&b, rkey[i], 128, 1);
av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
for (j = 0; j < 16; j++) {
if (rpt[i][j] != temp[j]) {
av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n",
j, rpt[i][j], temp[j]);
err = 1;
}
}
}
if (argc > 1 && !strcmp(argv[1], "-t")) {
AVAES ae, ad;
AVLFG prng;
av_aes_init(&ae, (const uint8_t*)"PI=3.141592654..", 128, 0);
av_aes_init(&ad, (const uint8_t*)"PI=3.141592654..", 128, 1);
av_lfg_init(&prng, 1);
for (i = 0; i < 10000; i++) {
for (j = 0; j < 32; j++)
pt[j] = av_lfg_get(&prng);
for (j = 0; j < 16; j++)
iv[0][j] = iv[1][j] = av_lfg_get(&prng);
{
START_TIMER;
av_aes_crypt(&ae, temp, pt, 2, iv[0], 0);
if (!(i & (i - 1)))
av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
temp[0], temp[5], temp[10], temp[15]);
av_aes_crypt(&ad, temp, temp, 2, iv[1], 1);
av_aes_crypt(&ae, temp, pt, 2, NULL, 0);
if (!(i & (i - 1)))
av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
temp[0], temp[5], temp[10], temp[15]);
av_aes_crypt(&ad, temp, temp, 2, NULL, 1);
STOP_TIMER("aes");
}
for (j = 0; j < 16; j++) {
if (pt[j] != temp[j]) {
av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n",
i, j, pt[j], temp[j]);
}
}
}
}
return err;
}
// LCOV_EXCL_STOP
#endif

@ -0,0 +1,34 @@
/*
* 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 "atomic.h"
#include "avassert.h"
int main(void)
{
volatile int val = 1;
int res;
res = avpriv_atomic_int_add_and_fetch(&val, 1);
av_assert0(res == 2);
avpriv_atomic_int_set(&val, 3);
res = avpriv_atomic_int_get(&val);
av_assert0(res == 3);
return 0;
}

@ -107,21 +107,3 @@ void *avpriv_atomic_ptr_cas(void * volatile *ptr, void *oldval, void *newval)
#endif /* HAVE_PTHREADS */
#endif /* !HAVE_ATOMICS_NATIVE */
#ifdef TEST
#include "avassert.h"
int main(void)
{
volatile int val = 1;
int res;
res = avpriv_atomic_int_add_and_fetch(&val, 1);
av_assert0(res == 2);
avpriv_atomic_int_set(&val, 3);
res = avpriv_atomic_int_get(&val);
av_assert0(res == 3);
return 0;
}
#endif

@ -0,0 +1,83 @@
/*
* 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 "common.h"
#include "mem.h"
#include "avstring.h"
int main(void)
{
int i;
char *fullpath;
static const char * const strings[] = {
"''",
"",
":",
"\\",
"'",
" '' :",
" '' '' :",
"foo '' :",
"'foo'",
"foo ",
" ' foo ' ",
"foo\\",
"foo': blah:blah",
"foo\\: blah:blah",
"foo\'",
"'foo : ' :blahblah",
"\\ :blah",
" foo",
" foo ",
" foo \\ ",
"foo ':blah",
" foo bar : blahblah",
"\\f\\o\\o",
"'foo : \\ \\ ' : blahblah",
"'\\fo\\o:': blahblah",
"\\'fo\\o\\:': foo ' :blahblah"
};
printf("Testing av_get_token()\n");
for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
const char *p = strings[i];
char *q;
printf("|%s|", p);
q = av_get_token(&p, ":");
printf(" -> |%s|", q);
printf(" + |%s|\n", p);
av_free(q);
}
printf("Testing av_append_path_component()\n");
#define TEST_APPEND_PATH_COMPONENT(path, component, expected) \
fullpath = av_append_path_component((path), (component)); \
printf("%s = %s\n", fullpath ? fullpath : "(null)", expected); \
av_free(fullpath);
TEST_APPEND_PATH_COMPONENT(NULL, NULL, "(null)")
TEST_APPEND_PATH_COMPONENT("path", NULL, "path");
TEST_APPEND_PATH_COMPONENT(NULL, "comp", "comp");
TEST_APPEND_PATH_COMPONENT("path", "comp", "path/comp");
TEST_APPEND_PATH_COMPONENT("path/", "comp", "path/comp");
TEST_APPEND_PATH_COMPONENT("path", "/comp", "path/comp");
TEST_APPEND_PATH_COMPONENT("path/", "/comp", "path/comp");
TEST_APPEND_PATH_COMPONENT("path/path2/", "/comp/comp2", "path/path2/comp/comp2");
return 0;
}

@ -435,67 +435,3 @@ int av_match_list(const char *name, const char *list, char separator)
return 0;
}
#ifdef TEST
int main(void)
{
int i;
char *fullpath;
static const char * const strings[] = {
"''",
"",
":",
"\\",
"'",
" '' :",
" '' '' :",
"foo '' :",
"'foo'",
"foo ",
" ' foo ' ",
"foo\\",
"foo': blah:blah",
"foo\\: blah:blah",
"foo\'",
"'foo : ' :blahblah",
"\\ :blah",
" foo",
" foo ",
" foo \\ ",
"foo ':blah",
" foo bar : blahblah",
"\\f\\o\\o",
"'foo : \\ \\ ' : blahblah",
"'\\fo\\o:': blahblah",
"\\'fo\\o\\:': foo ' :blahblah"
};
printf("Testing av_get_token()\n");
for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
const char *p = strings[i];
char *q;
printf("|%s|", p);
q = av_get_token(&p, ":");
printf(" -> |%s|", q);
printf(" + |%s|\n", p);
av_free(q);
}
printf("Testing av_append_path_component()\n");
#define TEST_APPEND_PATH_COMPONENT(path, component, expected) \
fullpath = av_append_path_component((path), (component)); \
printf("%s = %s\n", fullpath ? fullpath : "(null)", expected); \
av_free(fullpath);
TEST_APPEND_PATH_COMPONENT(NULL, NULL, "(null)")
TEST_APPEND_PATH_COMPONENT("path", NULL, "path");
TEST_APPEND_PATH_COMPONENT(NULL, "comp", "comp");
TEST_APPEND_PATH_COMPONENT("path", "comp", "path/comp");
TEST_APPEND_PATH_COMPONENT("path/", "comp", "path/comp");
TEST_APPEND_PATH_COMPONENT("path", "/comp", "path/comp");
TEST_APPEND_PATH_COMPONENT("path/", "/comp", "path/comp");
TEST_APPEND_PATH_COMPONENT("path/path2/", "/comp/comp2", "path/path2/comp/comp2");
return 0;
}
#endif /* TEST */

@ -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
*/
// LCOV_EXCL_START
#include <stdint.h>
#include <stdio.h>
#include "common.h"
#include "base64.h"
#include "timer.h"
#define MAX_DATA_SIZE 1024
#define MAX_ENCODED_SIZE 2048
static int test_encode_decode(const uint8_t *data, unsigned int data_size,
const char *encoded_ref)
{
char encoded[MAX_ENCODED_SIZE];
uint8_t data2[MAX_DATA_SIZE];
int data2_size, max_data2_size = MAX_DATA_SIZE;
if (!av_base64_encode(encoded, MAX_ENCODED_SIZE, data, data_size)) {
printf("Failed: cannot encode the input data\n");
return 1;
}
if (encoded_ref && strcmp(encoded, encoded_ref)) {
printf("Failed: encoded string differs from reference\n"
"Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref);
return 1;
}
if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) != data_size) {
printf("Failed: cannot decode the encoded string\n"
"Encoded:\n%s\n", encoded);
return 1;
}
if ((data2_size = av_base64_decode(data2, encoded, data_size)) != data_size) {
printf("Failed: cannot decode with minimal buffer\n"
"Encoded:\n%s\n", encoded);
return 1;
}
if (memcmp(data2, data, data_size)) {
printf("Failed: encoded/decoded data differs from original data\n");
return 1;
}
if (av_base64_decode(NULL, encoded, 0) != 0) {
printf("Failed: decode to NULL buffer\n");
return 1;
}
if (strlen(encoded)) {
char *end = strchr(encoded, '=');
if (!end)
end = encoded + strlen(encoded) - 1;
*end = '%';
if (av_base64_decode(NULL, encoded, 0) >= 0) {
printf("Failed: error detection\n");
return 1;
}
}
printf("Passed!\n");
return 0;
}
int main(int argc, char ** argv)
{
int i, error_count = 0;
struct test {
const uint8_t *data;
const char *encoded_ref;
} tests[] = {
{ "", ""},
{ "1", "MQ=="},
{ "22", "MjI="},
{ "333", "MzMz"},
{ "4444", "NDQ0NA=="},
{ "55555", "NTU1NTU="},
{ "666666", "NjY2NjY2"},
{ "abc:def", "YWJjOmRlZg=="},
};
char in[1024], out[2048];
printf("Encoding/decoding tests\n");
for (i = 0; i < FF_ARRAY_ELEMS(tests); i++)
error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref);
if (argc>1 && !strcmp(argv[1], "-t")) {
memset(in, 123, sizeof(in));
for(i=0; i<10000; i++){
START_TIMER
av_base64_encode(out, sizeof(out), in, sizeof(in));
STOP_TIMER("encode")
}
for(i=0; i<10000; i++){
START_TIMER
av_base64_decode(in, out, sizeof(in));
STOP_TIMER("decode")
}
for(i=0; i<10000; i++){
START_TIMER
av_base64_decode(NULL, out, 0);
STOP_TIMER("syntax check")
}
}
if (error_count)
printf("Error Count: %d.\n", error_count);
return !!error_count;
}
// LCOV_EXCL_STOP

@ -172,110 +172,3 @@ char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
return ret;
}
#ifdef TEST
// LCOV_EXCL_START
#define MAX_DATA_SIZE 1024
#define MAX_ENCODED_SIZE 2048
static int test_encode_decode(const uint8_t *data, unsigned int data_size,
const char *encoded_ref)
{
char encoded[MAX_ENCODED_SIZE];
uint8_t data2[MAX_DATA_SIZE];
int data2_size, max_data2_size = MAX_DATA_SIZE;
if (!av_base64_encode(encoded, MAX_ENCODED_SIZE, data, data_size)) {
printf("Failed: cannot encode the input data\n");
return 1;
}
if (encoded_ref && strcmp(encoded, encoded_ref)) {
printf("Failed: encoded string differs from reference\n"
"Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref);
return 1;
}
if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) != data_size) {
printf("Failed: cannot decode the encoded string\n"
"Encoded:\n%s\n", encoded);
return 1;
}
if ((data2_size = av_base64_decode(data2, encoded, data_size)) != data_size) {
printf("Failed: cannot decode with minimal buffer\n"
"Encoded:\n%s\n", encoded);
return 1;
}
if (memcmp(data2, data, data_size)) {
printf("Failed: encoded/decoded data differs from original data\n");
return 1;
}
if (av_base64_decode(NULL, encoded, 0) != 0) {
printf("Failed: decode to NULL buffer\n");
return 1;
}
if (strlen(encoded)) {
char *end = strchr(encoded, '=');
if (!end)
end = encoded + strlen(encoded) - 1;
*end = '%';
if (av_base64_decode(NULL, encoded, 0) >= 0) {
printf("Failed: error detection\n");
return 1;
}
}
printf("Passed!\n");
return 0;
}
int main(int argc, char ** argv)
{
int i, error_count = 0;
struct test {
const uint8_t *data;
const char *encoded_ref;
} tests[] = {
{ "", ""},
{ "1", "MQ=="},
{ "22", "MjI="},
{ "333", "MzMz"},
{ "4444", "NDQ0NA=="},
{ "55555", "NTU1NTU="},
{ "666666", "NjY2NjY2"},
{ "abc:def", "YWJjOmRlZg=="},
};
char in[1024], out[2048];
printf("Encoding/decoding tests\n");
for (i = 0; i < FF_ARRAY_ELEMS(tests); i++)
error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref);
if (argc>1 && !strcmp(argv[1], "-t")) {
memset(in, 123, sizeof(in));
for(i=0; i<10000; i++){
START_TIMER
av_base64_encode(out, sizeof(out), in, sizeof(in));
STOP_TIMER("encode")
}
for(i=0; i<10000; i++){
START_TIMER
av_base64_decode(in, out, sizeof(in));
STOP_TIMER("decode")
}
for(i=0; i<10000; i++){
START_TIMER
av_base64_decode(NULL, out, 0);
STOP_TIMER("syntax check")
}
}
if (error_count)
printf("Error Count: %d.\n", error_count);
return !!error_count;
}
// LCOV_EXCL_STOP
#endif

@ -0,0 +1,190 @@
/*
* 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 <stdlib.h>
#include <string.h>
#include "blowfish.h"
#define NUM_VARIABLE_KEY_TESTS 34
/* plaintext bytes -- left halves */
static const uint32_t plaintext_l[NUM_VARIABLE_KEY_TESTS] = {
0x00000000, 0xFFFFFFFF, 0x10000000, 0x11111111, 0x11111111,
0x01234567, 0x00000000, 0x01234567, 0x01A1D6D0, 0x5CD54CA8,
0x0248D438, 0x51454B58, 0x42FD4430, 0x059B5E08, 0x0756D8E0,
0x762514B8, 0x3BDD1190, 0x26955F68, 0x164D5E40, 0x6B056E18,
0x004BD6EF, 0x480D3900, 0x437540C8, 0x072D43A0, 0x02FE5577,
0x1D9D5C50, 0x30553228, 0x01234567, 0x01234567, 0x01234567,
0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
};
/* plaintext bytes -- right halves */
static const uint32_t plaintext_r[NUM_VARIABLE_KEY_TESTS] = {
0x00000000, 0xFFFFFFFF, 0x00000001, 0x11111111, 0x11111111,
0x89ABCDEF, 0x00000000, 0x89ABCDEF, 0x39776742, 0x3DEF57DA,
0x06F67172, 0x2DDF440A, 0x59577FA2, 0x51CF143A, 0x774761D2,
0x29BF486A, 0x49372802, 0x35AF609A, 0x4F275232, 0x759F5CCA,
0x09176062, 0x6EE762F2, 0x698F3CFA, 0x77075292, 0x8117F12A,
0x18F728C2, 0x6D6F295A, 0x89ABCDEF, 0x89ABCDEF, 0x89ABCDEF,
0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
};
/* key bytes for variable key tests */
static const uint8_t variable_key[NUM_VARIABLE_KEY_TESTS][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
{ 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
{ 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
{ 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
{ 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
{ 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
{ 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
{ 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
{ 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
{ 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
{ 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
{ 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
{ 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
{ 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
{ 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
{ 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
{ 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
{ 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
{ 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
{ 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
{ 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }
};
/* ciphertext bytes -- left halves */
static const uint32_t ciphertext_l[NUM_VARIABLE_KEY_TESTS] = {
0x4EF99745, 0x51866FD5, 0x7D856F9A, 0x2466DD87, 0x61F9C380,
0x7D0CC630, 0x4EF99745, 0x0ACEAB0F, 0x59C68245, 0xB1B8CC0B,
0x1730E577, 0xA25E7856, 0x353882B1, 0x48F4D088, 0x432193B7,
0x13F04154, 0x2EEDDA93, 0xD887E039, 0x5F99D04F, 0x4A057A3B,
0x452031C1, 0x7555AE39, 0x53C55F9C, 0x7A8E7BFA, 0xCF9C5D7A,
0xD1ABB290, 0x55CB3774, 0xFA34EC48, 0xA7907951, 0xC39E072D,
0x014933E0, 0xF21E9A77, 0x24594688, 0x6B5C5A9C
};
/* ciphertext bytes -- right halves */
static const uint32_t ciphertext_r[NUM_VARIABLE_KEY_TESTS] = {
0x6198DD78, 0xB85ECB8A, 0x613063F2, 0x8B963C9D, 0x2281B096,
0xAFDA1EC7, 0x6198DD78, 0xC6A0A28D, 0xEB05282B, 0x250F09A0,
0x8BEA1DA4, 0xCF2651EB, 0x09CE8F1A, 0x4C379918, 0x8951FC98,
0xD69D1AE5, 0xFFD39C79, 0x3C2DA6E3, 0x5B163969, 0x24D3977B,
0xE4FADA8E, 0xF59B87BD, 0xB49FC019, 0x937E89A3, 0x4986ADB5,
0x658BC778, 0xD13EF201, 0x47B268B2, 0x08EA3CAE, 0x9FAC631D,
0xCDAFF6E4, 0xB71C49BC, 0x5754369A, 0x5D9E0A5A
};
/* plaintext bytes */
static const uint8_t plaintext[8] = "BLOWFISH";
static const uint8_t plaintext2[16] = "BLOWFISHBLOWFISH";
/* ciphertext bytes */
static const uint8_t ciphertext[8] = {
0x32, 0x4E, 0xD0, 0xFE, 0xF4, 0x13, 0xA2, 0x03
};
static const uint8_t ciphertext2[16] = {
0x53, 0x00, 0x40, 0x06, 0x63, 0xf2, 0x1d, 0x99,
0x3b, 0x9b, 0x27, 0x64, 0x46, 0xfd, 0x20, 0xc1,
};
#define IV "blowfish"
static void test_blowfish(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
const uint8_t *ref, int len, uint8_t *iv, int dir,
const char *test)
{
av_blowfish_crypt(ctx, dst, src, len, iv, dir);
if (memcmp(dst, ref, 8*len)) {
int i;
printf("%s failed\ngot ", test);
for (i = 0; i < 8*len; i++)
printf("%02x ", dst[i]);
printf("\nexpected ");
for (i = 0; i < 8*len; i++)
printf("%02x ", ref[i]);
printf("\n");
exit(1);
}
}
int main(void)
{
AVBlowfish ctx;
uint32_t tmptext_l[NUM_VARIABLE_KEY_TESTS];
uint32_t tmptext_r[NUM_VARIABLE_KEY_TESTS];
uint8_t tmp[16], iv[8];
int i;
av_blowfish_init(&ctx, "abcdefghijklmnopqrstuvwxyz", 26);
test_blowfish(&ctx, tmp, plaintext, ciphertext, 1, NULL, 0, "encryption");
test_blowfish(&ctx, tmp, ciphertext, plaintext, 1, NULL, 1, "decryption");
test_blowfish(&ctx, tmp, tmp, ciphertext, 1, NULL, 0, "Inplace encryption");
test_blowfish(&ctx, tmp, tmp, plaintext, 1, NULL, 1, "Inplace decryption");
memcpy(iv, IV, 8);
test_blowfish(&ctx, tmp, plaintext2, ciphertext2, 2, iv, 0, "CBC encryption");
memcpy(iv, IV, 8);
test_blowfish(&ctx, tmp, ciphertext2, plaintext2, 2, iv, 1, "CBC decryption");
memcpy(iv, IV, 8);
test_blowfish(&ctx, tmp, tmp, ciphertext2, 2, iv, 0, "Inplace CBC encryption");
memcpy(iv, IV, 8);
test_blowfish(&ctx, tmp, tmp, plaintext2, 2, iv, 1, "Inplace CBC decryption");
memcpy(tmptext_l, plaintext_l, sizeof(*plaintext_l) * NUM_VARIABLE_KEY_TESTS);
memcpy(tmptext_r, plaintext_r, sizeof(*plaintext_r) * NUM_VARIABLE_KEY_TESTS);
for (i = 0; i < NUM_VARIABLE_KEY_TESTS; i++) {
av_blowfish_init(&ctx, variable_key[i], 8);
av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 0);
if (tmptext_l[i] != ciphertext_l[i] || tmptext_r[i] != ciphertext_r[i]) {
printf("Test encryption failed.\n");
return 1;
}
av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 1);
if (tmptext_l[i] != plaintext_l[i] || tmptext_r[i] != plaintext_r[i]) {
printf("Test decryption failed.\n");
return 1;
}
}
printf("Test encryption/decryption success.\n");
return 0;
}

@ -422,173 +422,3 @@ void av_blowfish_crypt(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
}
}
}
#ifdef TEST
#include <stdio.h>
#define NUM_VARIABLE_KEY_TESTS 34
/* plaintext bytes -- left halves */
static const uint32_t plaintext_l[NUM_VARIABLE_KEY_TESTS] = {
0x00000000, 0xFFFFFFFF, 0x10000000, 0x11111111, 0x11111111,
0x01234567, 0x00000000, 0x01234567, 0x01A1D6D0, 0x5CD54CA8,
0x0248D438, 0x51454B58, 0x42FD4430, 0x059B5E08, 0x0756D8E0,
0x762514B8, 0x3BDD1190, 0x26955F68, 0x164D5E40, 0x6B056E18,
0x004BD6EF, 0x480D3900, 0x437540C8, 0x072D43A0, 0x02FE5577,
0x1D9D5C50, 0x30553228, 0x01234567, 0x01234567, 0x01234567,
0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
};
/* plaintext bytes -- right halves */
static const uint32_t plaintext_r[NUM_VARIABLE_KEY_TESTS] = {
0x00000000, 0xFFFFFFFF, 0x00000001, 0x11111111, 0x11111111,
0x89ABCDEF, 0x00000000, 0x89ABCDEF, 0x39776742, 0x3DEF57DA,
0x06F67172, 0x2DDF440A, 0x59577FA2, 0x51CF143A, 0x774761D2,
0x29BF486A, 0x49372802, 0x35AF609A, 0x4F275232, 0x759F5CCA,
0x09176062, 0x6EE762F2, 0x698F3CFA, 0x77075292, 0x8117F12A,
0x18F728C2, 0x6D6F295A, 0x89ABCDEF, 0x89ABCDEF, 0x89ABCDEF,
0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
};
/* key bytes for variable key tests */
static const uint8_t variable_key[NUM_VARIABLE_KEY_TESTS][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
{ 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
{ 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
{ 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
{ 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
{ 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
{ 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
{ 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
{ 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
{ 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
{ 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
{ 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
{ 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
{ 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
{ 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
{ 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
{ 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
{ 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
{ 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
{ 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
{ 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }
};
/* ciphertext bytes -- left halves */
static const uint32_t ciphertext_l[NUM_VARIABLE_KEY_TESTS] = {
0x4EF99745, 0x51866FD5, 0x7D856F9A, 0x2466DD87, 0x61F9C380,
0x7D0CC630, 0x4EF99745, 0x0ACEAB0F, 0x59C68245, 0xB1B8CC0B,
0x1730E577, 0xA25E7856, 0x353882B1, 0x48F4D088, 0x432193B7,
0x13F04154, 0x2EEDDA93, 0xD887E039, 0x5F99D04F, 0x4A057A3B,
0x452031C1, 0x7555AE39, 0x53C55F9C, 0x7A8E7BFA, 0xCF9C5D7A,
0xD1ABB290, 0x55CB3774, 0xFA34EC48, 0xA7907951, 0xC39E072D,
0x014933E0, 0xF21E9A77, 0x24594688, 0x6B5C5A9C
};
/* ciphertext bytes -- right halves */
static const uint32_t ciphertext_r[NUM_VARIABLE_KEY_TESTS] = {
0x6198DD78, 0xB85ECB8A, 0x613063F2, 0x8B963C9D, 0x2281B096,
0xAFDA1EC7, 0x6198DD78, 0xC6A0A28D, 0xEB05282B, 0x250F09A0,
0x8BEA1DA4, 0xCF2651EB, 0x09CE8F1A, 0x4C379918, 0x8951FC98,
0xD69D1AE5, 0xFFD39C79, 0x3C2DA6E3, 0x5B163969, 0x24D3977B,
0xE4FADA8E, 0xF59B87BD, 0xB49FC019, 0x937E89A3, 0x4986ADB5,
0x658BC778, 0xD13EF201, 0x47B268B2, 0x08EA3CAE, 0x9FAC631D,
0xCDAFF6E4, 0xB71C49BC, 0x5754369A, 0x5D9E0A5A
};
/* plaintext bytes */
static const uint8_t plaintext[8] = "BLOWFISH";
static const uint8_t plaintext2[16] = "BLOWFISHBLOWFISH";
/* ciphertext bytes */
static const uint8_t ciphertext[8] = {
0x32, 0x4E, 0xD0, 0xFE, 0xF4, 0x13, 0xA2, 0x03
};
static const uint8_t ciphertext2[16] = {
0x53, 0x00, 0x40, 0x06, 0x63, 0xf2, 0x1d, 0x99,
0x3b, 0x9b, 0x27, 0x64, 0x46, 0xfd, 0x20, 0xc1,
};
#define IV "blowfish"
static void test_blowfish(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
const uint8_t *ref, int len, uint8_t *iv, int dir,
const char *test)
{
av_blowfish_crypt(ctx, dst, src, len, iv, dir);
if (memcmp(dst, ref, 8*len)) {
int i;
printf("%s failed\ngot ", test);
for (i = 0; i < 8*len; i++)
printf("%02x ", dst[i]);
printf("\nexpected ");
for (i = 0; i < 8*len; i++)
printf("%02x ", ref[i]);
printf("\n");
exit(1);
}
}
int main(void)
{
AVBlowfish ctx;
uint32_t tmptext_l[NUM_VARIABLE_KEY_TESTS];
uint32_t tmptext_r[NUM_VARIABLE_KEY_TESTS];
uint8_t tmp[16], iv[8];
int i;
av_blowfish_init(&ctx, "abcdefghijklmnopqrstuvwxyz", 26);
test_blowfish(&ctx, tmp, plaintext, ciphertext, 1, NULL, 0, "encryption");
test_blowfish(&ctx, tmp, ciphertext, plaintext, 1, NULL, 1, "decryption");
test_blowfish(&ctx, tmp, tmp, ciphertext, 1, NULL, 0, "Inplace encryption");
test_blowfish(&ctx, tmp, tmp, plaintext, 1, NULL, 1, "Inplace decryption");
memcpy(iv, IV, 8);
test_blowfish(&ctx, tmp, plaintext2, ciphertext2, 2, iv, 0, "CBC encryption");
memcpy(iv, IV, 8);
test_blowfish(&ctx, tmp, ciphertext2, plaintext2, 2, iv, 1, "CBC decryption");
memcpy(iv, IV, 8);
test_blowfish(&ctx, tmp, tmp, ciphertext2, 2, iv, 0, "Inplace CBC encryption");
memcpy(iv, IV, 8);
test_blowfish(&ctx, tmp, tmp, plaintext2, 2, iv, 1, "Inplace CBC decryption");
memcpy(tmptext_l, plaintext_l, sizeof(*plaintext_l) * NUM_VARIABLE_KEY_TESTS);
memcpy(tmptext_r, plaintext_r, sizeof(*plaintext_r) * NUM_VARIABLE_KEY_TESTS);
for (i = 0; i < NUM_VARIABLE_KEY_TESTS; i++) {
av_blowfish_init(&ctx, variable_key[i], 8);
av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 0);
if (tmptext_l[i] != ciphertext_l[i] || tmptext_r[i] != ciphertext_r[i]) {
printf("Test encryption failed.\n");
return 1;
}
av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 1);
if (tmptext_l[i] != plaintext_l[i] || tmptext_r[i] != plaintext_r[i]) {
printf("Test decryption failed.\n");
return 1;
}
}
printf("Test encryption/decryption success.\n");
return 0;
}
#endif

@ -0,0 +1,93 @@
/*
* Copyright (c) 2012 Nicolas George
*
* 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 "bprint.c"
#undef printf
static void bprint_pascal(AVBPrint *b, unsigned size)
{
unsigned i, j;
unsigned p[42];
av_assert0(size < FF_ARRAY_ELEMS(p));
p[0] = 1;
av_bprintf(b, "%8d\n", 1);
for (i = 1; i <= size; i++) {
p[i] = 1;
for (j = i - 1; j > 0; j--)
p[j] = p[j] + p[j - 1];
for (j = 0; j <= i; j++)
av_bprintf(b, "%8d", p[j]);
av_bprintf(b, "\n");
}
}
int main(void)
{
AVBPrint b;
char buf[256];
struct tm testtime = { .tm_year = 100, .tm_mon = 11, .tm_mday = 20 };
av_bprint_init(&b, 0, -1);
bprint_pascal(&b, 5);
printf("Short text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
printf("%s\n", b.str);
av_bprint_finalize(&b, NULL);
av_bprint_init(&b, 0, -1);
bprint_pascal(&b, 25);
printf("Long text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_finalize(&b, NULL);
av_bprint_init(&b, 0, 2048);
bprint_pascal(&b, 25);
printf("Long text in limited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_finalize(&b, NULL);
av_bprint_init(&b, 0, 1);
bprint_pascal(&b, 5);
printf("Short text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_init(&b, 0, 1);
bprint_pascal(&b, 25);
printf("Long text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str)/8*8, b.len);
/* Note that the size of the automatic buffer is arch-dependent. */
av_bprint_init(&b, 0, 0);
bprint_pascal(&b, 25);
printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_init_for_buffer(&b, buf, sizeof(buf));
bprint_pascal(&b, 25);
printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(buf), b.len);
av_bprint_init(&b, 0, -1);
av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
printf("strftime full: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
av_bprint_finalize(&b, NULL);
av_bprint_init(&b, 0, 8);
av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
printf("strftime truncated: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
return 0;
}

@ -303,79 +303,3 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_cha
break;
}
}
#ifdef TEST
#undef printf
static void bprint_pascal(AVBPrint *b, unsigned size)
{
unsigned i, j;
unsigned p[42];
av_assert0(size < FF_ARRAY_ELEMS(p));
p[0] = 1;
av_bprintf(b, "%8d\n", 1);
for (i = 1; i <= size; i++) {
p[i] = 1;
for (j = i - 1; j > 0; j--)
p[j] = p[j] + p[j - 1];
for (j = 0; j <= i; j++)
av_bprintf(b, "%8d", p[j]);
av_bprintf(b, "\n");
}
}
int main(void)
{
AVBPrint b;
char buf[256];
struct tm testtime = { .tm_year = 100, .tm_mon = 11, .tm_mday = 20 };
av_bprint_init(&b, 0, -1);
bprint_pascal(&b, 5);
printf("Short text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
printf("%s\n", b.str);
av_bprint_finalize(&b, NULL);
av_bprint_init(&b, 0, -1);
bprint_pascal(&b, 25);
printf("Long text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_finalize(&b, NULL);
av_bprint_init(&b, 0, 2048);
bprint_pascal(&b, 25);
printf("Long text in limited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_finalize(&b, NULL);
av_bprint_init(&b, 0, 1);
bprint_pascal(&b, 5);
printf("Short text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_init(&b, 0, 1);
bprint_pascal(&b, 25);
printf("Long text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str)/8*8, b.len);
/* Note that the size of the automatic buffer is arch-dependent. */
av_bprint_init(&b, 0, 0);
bprint_pascal(&b, 25);
printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_init_for_buffer(&b, buf, sizeof(buf));
bprint_pascal(&b, 25);
printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(buf), b.len);
av_bprint_init(&b, 0, -1);
av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
printf("strftime full: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
av_bprint_finalize(&b, NULL);
av_bprint_init(&b, 0, 8);
av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
printf("strftime truncated: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
return 0;
}
#endif

@ -0,0 +1,78 @@
/*
* An implementation of the CAMELLIA algorithm as mentioned in RFC3713
* Copyright (c) 2014 Supraja Meedinti
*
* 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 "camellia.c"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
const uint8_t Key[3][32] = {
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10},
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77},
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}
};
const uint8_t rct[3][16] = {
{0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73, 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43},
{0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9,0x96, 0xf8, 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9},
{0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c, 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09}
};
const uint8_t rpt[32] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10};
const int kbits[3] = {128, 192, 256};
int i, j, err = 0;
uint8_t temp[32], iv[16];
AVCAMELLIA *cs;
cs = av_camellia_alloc();
if (!cs)
return 1;
for (j = 0; j < 3; j++) {
av_camellia_init(cs, Key[j], kbits[j]);
av_camellia_crypt(cs, temp, rpt, 1, NULL, 0);
for (i = 0; i < 16; i++) {
if (rct[j][i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[j][i], temp[i]);
err = 1;
}
}
av_camellia_crypt(cs, temp, rct[j], 1, NULL, 1);
for (i = 0; i < 16; i++) {
if (rpt[i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
err = 1;
}
}
}
av_camellia_init(cs, Key[0], 128);
memcpy(iv, "HALLO123HALLO123", 16);
av_camellia_crypt(cs, temp, rpt, 2, iv, 0);
memcpy(iv, "HALLO123HALLO123", 16);
av_camellia_crypt(cs, temp, temp, 2, iv, 1);
for (i = 0; i < 32; i++) {
if (rpt[i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
err = 1;
}
}
av_free(cs);
return err;
}

@ -410,61 +410,3 @@ void av_camellia_crypt(AVCAMELLIA *cs, uint8_t *dst, const uint8_t *src, int cou
dst = dst + 16;
}
}
#ifdef TEST
#include<stdio.h>
#include<stdlib.h>
#include"log.h"
int main(int argc, char *argv[])
{
const uint8_t Key[3][32] = {
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10},
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77},
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}
};
const uint8_t rct[3][16] = {
{0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73, 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43},
{0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9,0x96, 0xf8, 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9},
{0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c, 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09}
};
const uint8_t rpt[32] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10};
const int kbits[3] = {128, 192, 256};
int i, j, err = 0;
uint8_t temp[32], iv[16];
AVCAMELLIA *cs;
cs = av_camellia_alloc();
if (!cs)
return 1;
for (j = 0; j < 3; j++) {
av_camellia_init(cs, Key[j], kbits[j]);
av_camellia_crypt(cs, temp, rpt, 1, NULL, 0);
for (i = 0; i < 16; i++) {
if (rct[j][i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[j][i], temp[i]);
err = 1;
}
}
av_camellia_crypt(cs, temp, rct[j], 1, NULL, 1);
for (i = 0; i < 16; i++) {
if (rpt[i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
err = 1;
}
}
}
av_camellia_init(cs, Key[0], 128);
memcpy(iv, "HALLO123HALLO123", 16);
av_camellia_crypt(cs, temp, rpt, 2, iv, 0);
memcpy(iv, "HALLO123HALLO123", 16);
av_camellia_crypt(cs, temp, temp, 2, iv, 1);
for (i = 0; i < 32; i++) {
if (rpt[i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
err = 1;
}
}
av_free(cs);
return err;
}
#endif

@ -0,0 +1,106 @@
/*
* An implementation of the CAST128 algorithm as mentioned in RFC2144
* Copyright (c) 2014 Supraja Meedinti
*
* 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 "cast5.c"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
static const uint8_t Key[3][16] = {
{0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a},
{0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, 0x23, 0x45},
{0x01, 0x23, 0x45, 0x67, 0x12}
};
static const uint8_t rpt[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
static const uint8_t rct[3][8] = {
{0x23, 0x8b, 0x4f, 0xe5, 0x84, 0x7e, 0x44, 0xb2},
{0xeb, 0x6a, 0x71, 0x1a, 0x2c, 0x02, 0x27, 0x1b},
{0x7a, 0xc8, 0x16, 0xd1, 0x6e, 0x9b, 0x30, 0x2e}
};
static const uint8_t rct2[2][16] = {
{0xee, 0xa9, 0xd0, 0xa2, 0x49, 0xfd, 0x3b, 0xa6, 0xb3, 0x43, 0x6f, 0xb8, 0x9d, 0x6d, 0xca, 0x92},
{0xb2, 0xc9, 0x5e, 0xb0, 0x0c, 0x31, 0xad, 0x71, 0x80, 0xac, 0x05, 0xb8, 0xe8, 0x3d, 0x69, 0x6e}
};
static const uint8_t iv[8] = {0xee, 0xa9, 0xd0, 0xa2, 0x49, 0xfd, 0x3b, 0xa6};
static uint8_t rpt2[2][16];
int i, j, err = 0;
static const int key_bits[3] = {128, 80, 40};
uint8_t temp[8];
AVCAST5 *cs;
cs = av_cast5_alloc();
if (!cs)
return 1;
for (j = 0; j < 3; j++){
av_cast5_init(cs, Key[j], key_bits[j]);
av_cast5_crypt(cs, temp, rpt, 1, 0);
for (i = 0;i < 8; i++){
if (rct[j][i] != temp[i]){
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[j][i], temp[i]);
err = 1;
}
}
av_cast5_crypt(cs, temp, rct[j], 1, 1);
for (i =0; i < 8; i++) {
if (rpt[i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
err = 1;
}
}
}
memcpy(rpt2[0], Key[0], 16);
memcpy(rpt2[1], Key[0], 16);
for (i = 0; i < 1000000; i++){
av_cast5_init(cs, rpt2[1], 128);
av_cast5_crypt(cs, rpt2[0], rpt2[0], 2, 0);
av_cast5_init(cs, rpt2[0], 128);
av_cast5_crypt(cs, rpt2[1], rpt2[1], 2, 0);
}
for (j = 0; j < 2; j++) {
for (i = 0; i < 16; i++) {
if (rct2[j][i] != rpt2[j][i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct2[j][i], rpt2[j][i]);
err = 1;
}
}
}
for (j = 0; j < 3; j++) {
av_cast5_init(cs, Key[j], key_bits[j]);
memcpy(temp, iv, 8);
av_cast5_crypt2(cs, rpt2[0], rct2[0], 2, temp, 0);
memcpy(temp, iv, 8);
av_cast5_crypt2(cs, rpt2[0], rpt2[0], 2, temp, 1);
for (i = 0; i < 16; i++) {
if (rct2[0][i] != rpt2[0][i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct2[0][i], rpt2[0][i]);
err = 1;
}
}
}
av_free(cs);
return err;
}

@ -505,89 +505,3 @@ void av_cast5_crypt(AVCAST5* cs, uint8_t* dst, const uint8_t* src, int count, in
dst = dst + 8;
}
}
#ifdef TEST
#include<stdio.h>
#include<stdlib.h>
#include"log.h"
int main(int argc, char** argv)
{
static const uint8_t Key[3][16] = {
{0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a},
{0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, 0x23, 0x45},
{0x01, 0x23, 0x45, 0x67, 0x12}
};
static const uint8_t rpt[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
static const uint8_t rct[3][8] = {
{0x23, 0x8b, 0x4f, 0xe5, 0x84, 0x7e, 0x44, 0xb2},
{0xeb, 0x6a, 0x71, 0x1a, 0x2c, 0x02, 0x27, 0x1b},
{0x7a, 0xc8, 0x16, 0xd1, 0x6e, 0x9b, 0x30, 0x2e}
};
static const uint8_t rct2[2][16] = {
{0xee, 0xa9, 0xd0, 0xa2, 0x49, 0xfd, 0x3b, 0xa6, 0xb3, 0x43, 0x6f, 0xb8, 0x9d, 0x6d, 0xca, 0x92},
{0xb2, 0xc9, 0x5e, 0xb0, 0x0c, 0x31, 0xad, 0x71, 0x80, 0xac, 0x05, 0xb8, 0xe8, 0x3d, 0x69, 0x6e}
};
static const uint8_t iv[8] = {0xee, 0xa9, 0xd0, 0xa2, 0x49, 0xfd, 0x3b, 0xa6};
static uint8_t rpt2[2][16];
int i, j, err = 0;
static const int key_bits[3] = {128, 80, 40};
uint8_t temp[8];
AVCAST5 *cs;
cs = av_cast5_alloc();
if (!cs)
return 1;
for (j = 0; j < 3; j++){
av_cast5_init(cs, Key[j], key_bits[j]);
av_cast5_crypt(cs, temp, rpt, 1, 0);
for (i = 0;i < 8; i++){
if (rct[j][i] != temp[i]){
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[j][i], temp[i]);
err = 1;
}
}
av_cast5_crypt(cs, temp, rct[j], 1, 1);
for (i =0; i < 8; i++) {
if (rpt[i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]);
err = 1;
}
}
}
memcpy(rpt2[0], Key[0], 16);
memcpy(rpt2[1], Key[0], 16);
for (i = 0; i < 1000000; i++){
av_cast5_init(cs, rpt2[1], 128);
av_cast5_crypt(cs, rpt2[0], rpt2[0], 2, 0);
av_cast5_init(cs, rpt2[0], 128);
av_cast5_crypt(cs, rpt2[1], rpt2[1], 2, 0);
}
for (j = 0; j < 2; j++) {
for (i = 0; i < 16; i++) {
if (rct2[j][i] != rpt2[j][i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct2[j][i], rpt2[j][i]);
err = 1;
}
}
}
for (j = 0; j < 3; j++) {
av_cast5_init(cs, Key[j], key_bits[j]);
memcpy(temp, iv, 8);
av_cast5_crypt2(cs, rpt2[0], rct2[0], 2, temp, 0);
memcpy(temp, iv, 8);
av_cast5_crypt2(cs, rpt2[0], rpt2[0], 2, temp, 1);
for (i = 0; i < 16; i++) {
if (rct2[0][i] != rpt2[0][i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct2[0][i], rpt2[0][i]);
err = 1;
}
}
}
av_free(cs);
return err;
}
#endif

@ -0,0 +1,43 @@
/*
* Copyright (c) 2015 Kevin Wheatley <kevin.j.wheatley@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 "color_utils.c"
int main(int argc, char *argv[])
{
int i, j;
static const double test_data[] = {
-0.1, -0.018053968510807, -0.01, -0.00449, 0.0, 0.00316227760, 0.005,
0.009, 0.015, 0.1, 1.0, 52.37, 125.098765, 1999.11123, 6945.443,
15123.4567, 19845.88923, 98678.4231, 99999.899998
};
for(i = 0; i < AVCOL_TRC_NB; i++) {
avpriv_trc_function func = avpriv_get_trc_function_from_trc(i);
for(j = 0; j < FF_ARRAY_ELEMS(test_data); j++) {
if(func != NULL) {
double result = func(test_data[j]);
printf("AVColorTransferCharacteristic=%d calling func(%f) expected=%f\n",
i, test_data[j], result);
}
}
}
}

@ -217,31 +217,3 @@ avpriv_trc_function avpriv_get_trc_function_from_trc(enum AVColorTransferCharact
}
return func;
}
#ifdef TEST
// LCOV_EXCL_START
int main(int argc, char *argv[])
{
int i, j;
static const double test_data[] = {
-0.1, -0.018053968510807, -0.01, -0.00449, 0.0, 0.00316227760, 0.005,
0.009, 0.015, 0.1, 1.0, 52.37, 125.098765, 1999.11123, 6945.443,
15123.4567, 19845.88923, 98678.4231, 99999.899998
};
for(i = 0; i < AVCOL_TRC_NB; i++) {
avpriv_trc_function func = avpriv_get_trc_function_from_trc(i);
for(j = 0; j < FF_ARRAY_ELEMS(test_data); j++) {
if(func != NULL) {
double result = func(test_data[j]);
printf("AVColorTransferCharacteristic=%d calling func(%f) expected=%f\n",
i, test_data[j], result);
}
}
}
}
// LCOV_EXCL_STOP
#endif

@ -0,0 +1,147 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include "avstring.h"
#if !HAVE_GETOPT
#include "compat/getopt.c"
#endif
#include <stdint.h>
#include <stdio.h>
#include "avstring.h"
#include "common.h"
#include "cpu.h"
static const struct {
int flag;
const char *name;
} cpu_flag_tab[] = {
#if ARCH_AARCH64
{ AV_CPU_FLAG_ARMV8, "armv8" },
{ AV_CPU_FLAG_NEON, "neon" },
{ AV_CPU_FLAG_VFP, "vfp" },
#elif ARCH_ARM
{ AV_CPU_FLAG_ARMV5TE, "armv5te" },
{ AV_CPU_FLAG_ARMV6, "armv6" },
{ AV_CPU_FLAG_ARMV6T2, "armv6t2" },
{ AV_CPU_FLAG_VFP, "vfp" },
{ AV_CPU_FLAG_VFP_VM, "vfp_vm" },
{ AV_CPU_FLAG_VFPV3, "vfpv3" },
{ AV_CPU_FLAG_NEON, "neon" },
{ AV_CPU_FLAG_SETEND, "setend" },
#elif ARCH_PPC
{ AV_CPU_FLAG_ALTIVEC, "altivec" },
#elif ARCH_X86
{ AV_CPU_FLAG_MMX, "mmx" },
{ AV_CPU_FLAG_MMXEXT, "mmxext" },
{ AV_CPU_FLAG_SSE, "sse" },
{ AV_CPU_FLAG_SSE2, "sse2" },
{ AV_CPU_FLAG_SSE2SLOW, "sse2slow" },
{ AV_CPU_FLAG_SSE3, "sse3" },
{ AV_CPU_FLAG_SSE3SLOW, "sse3slow" },
{ AV_CPU_FLAG_SSSE3, "ssse3" },
{ AV_CPU_FLAG_ATOM, "atom" },
{ AV_CPU_FLAG_SSE4, "sse4.1" },
{ AV_CPU_FLAG_SSE42, "sse4.2" },
{ AV_CPU_FLAG_AVX, "avx" },
{ AV_CPU_FLAG_AVXSLOW, "avxslow" },
{ AV_CPU_FLAG_XOP, "xop" },
{ AV_CPU_FLAG_FMA3, "fma3" },
{ AV_CPU_FLAG_FMA4, "fma4" },
{ AV_CPU_FLAG_3DNOW, "3dnow" },
{ AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
{ AV_CPU_FLAG_CMOV, "cmov" },
{ AV_CPU_FLAG_AVX2, "avx2" },
{ AV_CPU_FLAG_BMI1, "bmi1" },
{ AV_CPU_FLAG_BMI2, "bmi2" },
{ AV_CPU_FLAG_AESNI, "aesni" },
#endif
{ 0 }
};
static void print_cpu_flags(int cpu_flags, const char *type)
{
int i;
printf("cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
printf("cpu_flags_str(%s) =", type);
for (i = 0; cpu_flag_tab[i].flag; i++)
if (cpu_flags & cpu_flag_tab[i].flag)
printf(" %s", cpu_flag_tab[i].name);
printf("\n");
}
int main(int argc, char **argv)
{
int cpu_flags_raw = av_get_cpu_flags();
int cpu_flags_eff;
int cpu_count = av_cpu_count();
char threads[5] = "auto";
int i;
for(i = 0; cpu_flag_tab[i].flag; i++) {
unsigned tmp = 0;
if (av_parse_cpu_caps(&tmp, cpu_flag_tab[i].name) < 0) {
fprintf(stderr, "Table missing %s\n", cpu_flag_tab[i].name);
return 4;
}
}
if (cpu_flags_raw < 0)
return 1;
for (;;) {
int c = getopt(argc, argv, "c:t:");
if (c == -1)
break;
switch (c) {
case 'c':
{
unsigned flags = av_get_cpu_flags();
if (av_parse_cpu_caps(&flags, optarg) < 0)
return 2;
av_force_cpu_flags(flags);
break;
}
case 't':
{
int len = av_strlcpy(threads, optarg, sizeof(threads));
if (len >= sizeof(threads)) {
fprintf(stderr, "Invalid thread count '%s'\n", optarg);
return 2;
}
}
}
}
cpu_flags_eff = av_get_cpu_flags();
if (cpu_flags_eff < 0)
return 3;
print_cpu_flags(cpu_flags_raw, "raw");
print_cpu_flags(cpu_flags_eff, "effective");
printf("threads = %s (cpu_count = %d)\n", threads, cpu_count);
return 0;
}

@ -294,130 +294,3 @@ int av_cpu_count(void)
return nb_cpus;
}
#ifdef TEST
#include <stdio.h>
#include "avstring.h"
#if !HAVE_GETOPT
#include "compat/getopt.c"
#endif
static const struct {
int flag;
const char *name;
} cpu_flag_tab[] = {
#if ARCH_AARCH64
{ AV_CPU_FLAG_ARMV8, "armv8" },
{ AV_CPU_FLAG_NEON, "neon" },
{ AV_CPU_FLAG_VFP, "vfp" },
#elif ARCH_ARM
{ AV_CPU_FLAG_ARMV5TE, "armv5te" },
{ AV_CPU_FLAG_ARMV6, "armv6" },
{ AV_CPU_FLAG_ARMV6T2, "armv6t2" },
{ AV_CPU_FLAG_VFP, "vfp" },
{ AV_CPU_FLAG_VFP_VM, "vfp_vm" },
{ AV_CPU_FLAG_VFPV3, "vfpv3" },
{ AV_CPU_FLAG_NEON, "neon" },
{ AV_CPU_FLAG_SETEND, "setend" },
#elif ARCH_PPC
{ AV_CPU_FLAG_ALTIVEC, "altivec" },
#elif ARCH_X86
{ AV_CPU_FLAG_MMX, "mmx" },
{ AV_CPU_FLAG_MMXEXT, "mmxext" },
{ AV_CPU_FLAG_SSE, "sse" },
{ AV_CPU_FLAG_SSE2, "sse2" },
{ AV_CPU_FLAG_SSE2SLOW, "sse2slow" },
{ AV_CPU_FLAG_SSE3, "sse3" },
{ AV_CPU_FLAG_SSE3SLOW, "sse3slow" },
{ AV_CPU_FLAG_SSSE3, "ssse3" },
{ AV_CPU_FLAG_ATOM, "atom" },
{ AV_CPU_FLAG_SSE4, "sse4.1" },
{ AV_CPU_FLAG_SSE42, "sse4.2" },
{ AV_CPU_FLAG_AVX, "avx" },
{ AV_CPU_FLAG_AVXSLOW, "avxslow" },
{ AV_CPU_FLAG_XOP, "xop" },
{ AV_CPU_FLAG_FMA3, "fma3" },
{ AV_CPU_FLAG_FMA4, "fma4" },
{ AV_CPU_FLAG_3DNOW, "3dnow" },
{ AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
{ AV_CPU_FLAG_CMOV, "cmov" },
{ AV_CPU_FLAG_AVX2, "avx2" },
{ AV_CPU_FLAG_BMI1, "bmi1" },
{ AV_CPU_FLAG_BMI2, "bmi2" },
{ AV_CPU_FLAG_AESNI, "aesni" },
#endif
{ 0 }
};
static void print_cpu_flags(int cpu_flags, const char *type)
{
int i;
printf("cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
printf("cpu_flags_str(%s) =", type);
for (i = 0; cpu_flag_tab[i].flag; i++)
if (cpu_flags & cpu_flag_tab[i].flag)
printf(" %s", cpu_flag_tab[i].name);
printf("\n");
}
int main(int argc, char **argv)
{
int cpu_flags_raw = av_get_cpu_flags();
int cpu_flags_eff;
int cpu_count = av_cpu_count();
char threads[5] = "auto";
int i;
for(i = 0; cpu_flag_tab[i].flag; i++) {
unsigned tmp = 0;
if (av_parse_cpu_caps(&tmp, cpu_flag_tab[i].name) < 0) {
fprintf(stderr, "Table missing %s\n", cpu_flag_tab[i].name);
return 4;
}
}
if (cpu_flags_raw < 0)
return 1;
for (;;) {
int c = getopt(argc, argv, "c:t:");
if (c == -1)
break;
switch (c) {
case 'c':
{
unsigned flags = av_get_cpu_flags();
if (av_parse_cpu_caps(&flags, optarg) < 0)
return 2;
av_force_cpu_flags(flags);
break;
}
case 't':
{
int len = av_strlcpy(threads, optarg, sizeof(threads));
if (len >= sizeof(threads)) {
fprintf(stderr, "Invalid thread count '%s'\n", optarg);
return 2;
}
}
}
}
cpu_flags_eff = av_get_cpu_flags();
if (cpu_flags_eff < 0)
return 3;
print_cpu_flags(cpu_flags_raw, "raw");
print_cpu_flags(cpu_flags_eff, "effective");
printf("threads = %s (cpu_count = %d)\n", threads, cpu_count);
return 0;
}
#endif

@ -0,0 +1,46 @@
/*
* 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 "crc.h"
int main(void)
{
uint8_t buf[1999];
int i;
unsigned p[6][3] = {
{ AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
{ AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0 },
{ AV_CRC_24_IEEE , 0x864CFB , 0xB704CE },
{ AV_CRC_16_ANSI_LE, 0xA001 , 0xBFD8 },
{ AV_CRC_16_ANSI , 0x8005 , 0x1FBB },
{ AV_CRC_8_ATM , 0x07 , 0xE3 }
};
const AVCRC *ctx;
for (i = 0; i < sizeof(buf); i++)
buf[i] = i + i * i;
for (i = 0; i < 6; i++) {
ctx = av_crc_get_table(p[i][0]);
printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
}
return 0;
}

@ -378,29 +378,3 @@ uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
return crc;
}
#ifdef TEST
int main(void)
{
uint8_t buf[1999];
int i;
unsigned p[6][3] = {
{ AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
{ AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0 },
{ AV_CRC_24_IEEE , 0x864CFB , 0xB704CE },
{ AV_CRC_16_ANSI_LE, 0xA001 , 0xBFD8 },
{ AV_CRC_16_ANSI , 0x8005 , 0x1FBB },
{ AV_CRC_8_ATM , 0x07 , 0xE3 }
};
const AVCRC *ctx;
for (i = 0; i < sizeof(buf); i++)
buf[i] = i + i * i;
for (i = 0; i < 6; i++) {
ctx = av_crc_get_table(p[i][0]);
printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
}
return 0;
}
#endif

@ -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 "des.c"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "time.h"
static uint64_t rand64(void)
{
uint64_t r = rand();
r = (r << 32) | rand();
return r;
}
static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
static const DECLARE_ALIGNED(8, uint8_t, plain)[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = { 0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18 };
static DECLARE_ALIGNED(8, uint8_t, tmp)[8];
static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8];
static const uint8_t cbc_key[] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
};
static int run_test(int cbc, int decrypt)
{
AVDES d;
int delay = cbc && !decrypt ? 2 : 1;
uint64_t res;
AV_WB64(large_buffer[0], 0x4e6f772069732074ULL);
AV_WB64(large_buffer[1], 0x1234567890abcdefULL);
AV_WB64(tmp, 0x1234567890abcdefULL);
av_des_init(&d, cbc_key, 192, decrypt);
av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt);
res = AV_RB64(large_buffer[9999 + delay]);
if (cbc) {
if (decrypt)
return res == 0xc5cecf63ecec514cULL;
else
return res == 0xcb191f85d1ed8439ULL;
} else {
if (decrypt)
return res == 0x8325397644091a0aULL;
else
return res == 0xdd17e8b8b437d232ULL;
}
}
int main(void)
{
AVDES d;
int i;
uint64_t key[3];
uint64_t data;
uint64_t ct;
uint64_t roundkeys[16];
srand(av_gettime());
key[0] = AV_RB64(test_key);
data = AV_RB64(plain);
gen_roundkeys(roundkeys, key[0]);
if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) {
printf("Test 1 failed\n");
return 1;
}
av_des_init(&d, test_key, 64, 0);
av_des_crypt(&d, tmp, plain, 1, NULL, 0);
if (memcmp(tmp, crypt, sizeof(crypt))) {
printf("Public API decryption failed\n");
return 1;
}
if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) {
printf("Partial Monte-Carlo test failed\n");
return 1;
}
for (i = 0; i < 1000; i++) {
key[0] = rand64();
key[1] = rand64();
key[2] = rand64();
data = rand64();
av_des_init(&d, (uint8_t *) key, 192, 0);
av_des_crypt(&d, (uint8_t *) &ct, (uint8_t *) &data, 1, NULL, 0);
av_des_init(&d, (uint8_t *) key, 192, 1);
av_des_crypt(&d, (uint8_t *) &ct, (uint8_t *) &ct, 1, NULL, 1);
if (ct != data) {
printf("Test 2 failed\n");
return 1;
}
}
#ifdef GENTABLES
printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n");
for (i = 0; i < 8; i++) {
int j;
printf(" {");
for (j = 0; j < 64; j++) {
uint32_t v = S_boxes[i][j >> 1];
v = j & 1 ? v >> 4 : v & 0xf;
v <<= 28 - 4 * i;
v = shuffle(v, P_shuffle, sizeof(P_shuffle));
printf((j & 7) == 0 ? "\n " : " ");
printf("0x%08X,", v);
}
printf("\n },\n");
}
printf("};\n");
#endif
return 0;
}

@ -104,7 +104,7 @@ static const uint8_t S_boxes[8][32] = {
#else
/**
* This table contains the results of applying both the S-box and P-shuffle.
* It can be regenerated by compiling this file with -DCONFIG_SMALL -DTEST -DGENTABLES
* It can be regenerated by compiling des-test.c with "-DCONFIG_SMALL -DGENTABLES".
*/
static const uint32_t S_boxes_P_shuffle[8][64] = {
{ 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
@ -329,112 +329,3 @@ void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count)
{
av_des_crypt_mac(d, dst, src, count, (uint8_t[8]) { 0 }, 0, 1);
}
#ifdef TEST
#include <stdlib.h>
#include <stdio.h>
#include "time.h"
static uint64_t rand64(void)
{
uint64_t r = rand();
r = (r << 32) | rand();
return r;
}
static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
static const DECLARE_ALIGNED(8, uint8_t, plain)[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = { 0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18 };
static DECLARE_ALIGNED(8, uint8_t, tmp)[8];
static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8];
static const uint8_t cbc_key[] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
};
static int run_test(int cbc, int decrypt)
{
AVDES d;
int delay = cbc && !decrypt ? 2 : 1;
uint64_t res;
AV_WB64(large_buffer[0], 0x4e6f772069732074ULL);
AV_WB64(large_buffer[1], 0x1234567890abcdefULL);
AV_WB64(tmp, 0x1234567890abcdefULL);
av_des_init(&d, cbc_key, 192, decrypt);
av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt);
res = AV_RB64(large_buffer[9999 + delay]);
if (cbc) {
if (decrypt)
return res == 0xc5cecf63ecec514cULL;
else
return res == 0xcb191f85d1ed8439ULL;
} else {
if (decrypt)
return res == 0x8325397644091a0aULL;
else
return res == 0xdd17e8b8b437d232ULL;
}
}
int main(void)
{
AVDES d;
int i;
uint64_t key[3];
uint64_t data;
uint64_t ct;
uint64_t roundkeys[16];
srand(av_gettime());
key[0] = AV_RB64(test_key);
data = AV_RB64(plain);
gen_roundkeys(roundkeys, key[0]);
if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) {
printf("Test 1 failed\n");
return 1;
}
av_des_init(&d, test_key, 64, 0);
av_des_crypt(&d, tmp, plain, 1, NULL, 0);
if (memcmp(tmp, crypt, sizeof(crypt))) {
printf("Public API decryption failed\n");
return 1;
}
if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) {
printf("Partial Monte-Carlo test failed\n");
return 1;
}
for (i = 0; i < 1000; i++) {
key[0] = rand64();
key[1] = rand64();
key[2] = rand64();
data = rand64();
av_des_init(&d, (uint8_t *) key, 192, 0);
av_des_crypt(&d, (uint8_t *) &ct, (uint8_t *) &data, 1, NULL, 0);
av_des_init(&d, (uint8_t *) key, 192, 1);
av_des_crypt(&d, (uint8_t *) &ct, (uint8_t *) &ct, 1, NULL, 1);
if (ct != data) {
printf("Test 2 failed\n");
return 1;
}
}
#ifdef GENTABLES
printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n");
for (i = 0; i < 8; i++) {
int j;
printf(" {");
for (j = 0; j < 64; j++) {
uint32_t v = S_boxes[i][j >> 1];
v = j & 1 ? v >> 4 : v & 0xf;
v <<= 28 - 4 * i;
v = shuffle(v, P_shuffle, sizeof(P_shuffle));
printf((j & 7) == 0 ? "\n " : " ");
printf("0x%08X,", v);
}
printf("\n },\n");
}
printf("};\n");
#endif
return 0;
}
#endif

@ -0,0 +1,133 @@
/*
* copyright (c) 2009 Michael Niedermayer
*
* 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 "dict.c"
static void print_dict(const AVDictionary *m)
{
AVDictionaryEntry *t = NULL;
while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX)))
printf("%s %s ", t->key, t->value);
printf("\n");
}
static void test_separators(const AVDictionary *m, const char pair, const char val)
{
AVDictionary *dict = NULL;
char pairs[] = {pair , '\0'};
char vals[] = {val, '\0'};
char *buffer = NULL;
av_dict_copy(&dict, m, 0);
print_dict(dict);
av_dict_get_string(dict, &buffer, val, pair);
printf("%s\n", buffer);
av_dict_free(&dict);
av_dict_parse_string(&dict, buffer, vals, pairs, 0);
av_freep(&buffer);
print_dict(dict);
av_dict_free(&dict);
}
int main(void)
{
AVDictionary *dict = NULL;
AVDictionaryEntry *e;
char *buffer = NULL;
printf("Testing av_dict_get_string() and av_dict_parse_string()\n");
av_dict_get_string(dict, &buffer, '=', ',');
printf("%s\n", buffer);
av_freep(&buffer);
av_dict_set(&dict, "aaa", "aaa", 0);
av_dict_set(&dict, "b,b", "bbb", 0);
av_dict_set(&dict, "c=c", "ccc", 0);
av_dict_set(&dict, "ddd", "d,d", 0);
av_dict_set(&dict, "eee", "e=e", 0);
av_dict_set(&dict, "f,f", "f=f", 0);
av_dict_set(&dict, "g=g", "g,g", 0);
test_separators(dict, ',', '=');
av_dict_free(&dict);
av_dict_set(&dict, "aaa", "aaa", 0);
av_dict_set(&dict, "bbb", "bbb", 0);
av_dict_set(&dict, "ccc", "ccc", 0);
av_dict_set(&dict, "\\,=\'\"", "\\,=\'\"", 0);
test_separators(dict, '"', '=');
test_separators(dict, '\'', '=');
test_separators(dict, ',', '"');
test_separators(dict, ',', '\'');
test_separators(dict, '\'', '"');
test_separators(dict, '"', '\'');
av_dict_free(&dict);
printf("\nTesting av_dict_set()\n");
av_dict_set(&dict, "a", "a", 0);
av_dict_set(&dict, "b", av_strdup("b"), AV_DICT_DONT_STRDUP_VAL);
av_dict_set(&dict, av_strdup("c"), "c", AV_DICT_DONT_STRDUP_KEY);
av_dict_set(&dict, av_strdup("d"), av_strdup("d"), AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
av_dict_set(&dict, "e", "e", AV_DICT_DONT_OVERWRITE);
av_dict_set(&dict, "e", "f", AV_DICT_DONT_OVERWRITE);
av_dict_set(&dict, "f", "f", 0);
av_dict_set(&dict, "f", NULL, 0);
av_dict_set(&dict, "ff", "f", 0);
av_dict_set(&dict, "ff", "f", AV_DICT_APPEND);
e = NULL;
while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
printf("%s %s\n", e->key, e->value);
av_dict_free(&dict);
av_dict_set(&dict, NULL, "a", 0);
av_dict_set(&dict, NULL, "b", 0);
av_dict_get(dict, NULL, NULL, 0);
e = NULL;
while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
printf("'%s' '%s'\n", e->key, e->value);
av_dict_free(&dict);
//valgrind sensible test
printf("\nTesting av_dict_set_int()\n");
av_dict_set_int(&dict, "1", 1, AV_DICT_DONT_STRDUP_VAL);
av_dict_set_int(&dict, av_strdup("2"), 2, AV_DICT_DONT_STRDUP_KEY);
av_dict_set_int(&dict, av_strdup("3"), 3, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
av_dict_set_int(&dict, "4", 4, 0);
av_dict_set_int(&dict, "5", 5, AV_DICT_DONT_OVERWRITE);
av_dict_set_int(&dict, "5", 6, AV_DICT_DONT_OVERWRITE);
av_dict_set_int(&dict, "12", 1, 0);
av_dict_set_int(&dict, "12", 2, AV_DICT_APPEND);
e = NULL;
while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
printf("%s %s\n", e->key, e->value);
av_dict_free(&dict);
//valgrind sensible test
printf("\nTesting av_dict_set() with existing AVDictionaryEntry.key as key\n");
av_dict_set(&dict, "key", "old", 0);
e = av_dict_get(dict, "key", NULL, 0);
av_dict_set(&dict, e->key, "new val OK", 0);
e = av_dict_get(dict, "key", NULL, 0);
printf("%s\n", e->value);
av_dict_set(&dict, e->key, e->value, 0);
e = av_dict_get(dict, "key", NULL, 0);
printf("%s\n", e->value);
av_dict_free(&dict);
return 0;
}

@ -253,117 +253,3 @@ int av_dict_get_string(const AVDictionary *m, char **buffer,
}
return av_bprint_finalize(&bprint, buffer);
}
#ifdef TEST
static void print_dict(const AVDictionary *m)
{
AVDictionaryEntry *t = NULL;
while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX)))
printf("%s %s ", t->key, t->value);
printf("\n");
}
static void test_separators(const AVDictionary *m, const char pair, const char val)
{
AVDictionary *dict = NULL;
char pairs[] = {pair , '\0'};
char vals[] = {val, '\0'};
char *buffer = NULL;
av_dict_copy(&dict, m, 0);
print_dict(dict);
av_dict_get_string(dict, &buffer, val, pair);
printf("%s\n", buffer);
av_dict_free(&dict);
av_dict_parse_string(&dict, buffer, vals, pairs, 0);
av_freep(&buffer);
print_dict(dict);
av_dict_free(&dict);
}
int main(void)
{
AVDictionary *dict = NULL;
AVDictionaryEntry *e;
char *buffer = NULL;
printf("Testing av_dict_get_string() and av_dict_parse_string()\n");
av_dict_get_string(dict, &buffer, '=', ',');
printf("%s\n", buffer);
av_freep(&buffer);
av_dict_set(&dict, "aaa", "aaa", 0);
av_dict_set(&dict, "b,b", "bbb", 0);
av_dict_set(&dict, "c=c", "ccc", 0);
av_dict_set(&dict, "ddd", "d,d", 0);
av_dict_set(&dict, "eee", "e=e", 0);
av_dict_set(&dict, "f,f", "f=f", 0);
av_dict_set(&dict, "g=g", "g,g", 0);
test_separators(dict, ',', '=');
av_dict_free(&dict);
av_dict_set(&dict, "aaa", "aaa", 0);
av_dict_set(&dict, "bbb", "bbb", 0);
av_dict_set(&dict, "ccc", "ccc", 0);
av_dict_set(&dict, "\\,=\'\"", "\\,=\'\"", 0);
test_separators(dict, '"', '=');
test_separators(dict, '\'', '=');
test_separators(dict, ',', '"');
test_separators(dict, ',', '\'');
test_separators(dict, '\'', '"');
test_separators(dict, '"', '\'');
av_dict_free(&dict);
printf("\nTesting av_dict_set()\n");
av_dict_set(&dict, "a", "a", 0);
av_dict_set(&dict, "b", av_strdup("b"), AV_DICT_DONT_STRDUP_VAL);
av_dict_set(&dict, av_strdup("c"), "c", AV_DICT_DONT_STRDUP_KEY);
av_dict_set(&dict, av_strdup("d"), av_strdup("d"), AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
av_dict_set(&dict, "e", "e", AV_DICT_DONT_OVERWRITE);
av_dict_set(&dict, "e", "f", AV_DICT_DONT_OVERWRITE);
av_dict_set(&dict, "f", "f", 0);
av_dict_set(&dict, "f", NULL, 0);
av_dict_set(&dict, "ff", "f", 0);
av_dict_set(&dict, "ff", "f", AV_DICT_APPEND);
e = NULL;
while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
printf("%s %s\n", e->key, e->value);
av_dict_free(&dict);
av_dict_set(&dict, NULL, "a", 0);
av_dict_set(&dict, NULL, "b", 0);
av_dict_get(dict, NULL, NULL, 0);
e = NULL;
while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
printf("'%s' '%s'\n", e->key, e->value);
av_dict_free(&dict);
//valgrind sensible test
printf("\nTesting av_dict_set_int()\n");
av_dict_set_int(&dict, "1", 1, AV_DICT_DONT_STRDUP_VAL);
av_dict_set_int(&dict, av_strdup("2"), 2, AV_DICT_DONT_STRDUP_KEY);
av_dict_set_int(&dict, av_strdup("3"), 3, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
av_dict_set_int(&dict, "4", 4, 0);
av_dict_set_int(&dict, "5", 5, AV_DICT_DONT_OVERWRITE);
av_dict_set_int(&dict, "5", 6, AV_DICT_DONT_OVERWRITE);
av_dict_set_int(&dict, "12", 1, 0);
av_dict_set_int(&dict, "12", 2, AV_DICT_APPEND);
e = NULL;
while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
printf("%s %s\n", e->key, e->value);
av_dict_free(&dict);
//valgrind sensible test
printf("\nTesting av_dict_set() with existing AVDictionaryEntry.key as key\n");
av_dict_set(&dict, "key", "old", 0);
e = av_dict_get(dict, "key", NULL, 0);
av_dict_set(&dict, e->key, "new val OK", 0);
e = av_dict_get(dict, "key", NULL, 0);
printf("%s\n", e->value);
av_dict_set(&dict, e->key, e->value, 0);
e = av_dict_get(dict, "key", NULL, 0);
printf("%s\n", e->value);
av_dict_free(&dict);
return 0;
}
#endif

@ -0,0 +1,61 @@
/*
* Copyright (c) 2014 Vittorio Giovara <vittorio.giovara@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 "display.c"
static void print_matrix(int32_t matrix[9])
{
int i, j;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3 - 1; ++j)
printf("%d ", matrix[i*3 + j]);
printf("%d\n", matrix[i*3 + j]);
}
}
int main(void)
{
int32_t matrix[9];
// Set the matrix to 90 degrees
av_display_rotation_set(matrix, 90);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// Set the matrix to -45 degrees
av_display_rotation_set(matrix, -45);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// flip horizontal
av_display_matrix_flip(matrix, 1, 0);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// flip vertical
av_display_matrix_flip(matrix, 0, 1);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
return 0;
}

@ -71,46 +71,3 @@ void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
for (i = 0; i < 9; i++)
matrix[i] *= flip[i % 3];
}
#ifdef TEST
static void print_matrix(int32_t matrix[9])
{
int i, j;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3 - 1; ++j)
printf("%d ", matrix[i*3 + j]);
printf("%d\n", matrix[i*3 + j]);
}
}
int main(void)
{
int32_t matrix[9];
// Set the matrix to 90 degrees
av_display_rotation_set(matrix, 90);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// Set the matrix to -45 degrees
av_display_rotation_set(matrix, -45);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// flip horizontal
av_display_matrix_flip(matrix, 1, 0);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// flip vertical
av_display_matrix_flip(matrix, 0, 1);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
return 0;
}
#endif

@ -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 "error.c"
#undef printf
int main(void)
{
int i;
for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
const struct error_entry *entry = &error_entries[i];
printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
}
for (i = 0; i < 256; i++) {
printf("%d: %s\n", -i, av_err2str(-i));
}
return 0;
}

@ -127,25 +127,3 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
return ret;
}
#ifdef TEST
#undef printf
int main(void)
{
int i;
for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
const struct error_entry *entry = &error_entries[i];
printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
}
for (i = 0; i < 256; i++) {
printf("%d: %s\n", -i, av_err2str(-i));
}
return 0;
}
#endif /* TEST */

@ -0,0 +1,173 @@
/*
* 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 <stdio.h>
#include <string.h>
#include "timer.h"
#include "eval.h"
static const double const_values[] = {
M_PI,
M_E,
0
};
static const char *const const_names[] = {
"PI",
"E",
0
};
int main(int argc, char **argv)
{
int i;
double d;
const char *const *expr;
static const char *const exprs[] = {
"",
"1;2",
"-20",
"-PI",
"+PI",
"1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
"80G/80Gi",
"1k",
"1Gi",
"1gi",
"1GiFoo",
"1k+1k",
"1Gi*3foo",
"foo",
"foo(",
"foo()",
"foo)",
"sin",
"sin(",
"sin()",
"sin)",
"sin 10",
"sin(1,2,3)",
"sin(1 )",
"1",
"1foo",
"bar + PI + E + 100f*2 + foo",
"13k + 12f - foo(1, 2)",
"1gi",
"1Gi",
"st(0, 123)",
"st(1, 123); ld(1)",
"lte(0, 1)",
"lte(1, 1)",
"lte(1, 0)",
"lt(0, 1)",
"lt(1, 1)",
"gt(1, 0)",
"gt(2, 7)",
"gte(122, 122)",
/* compute 1+2+...+N */
"st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
/* compute Fib(N) */
"st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
"while(0, 10)",
"st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
"isnan(1)",
"isnan(NAN)",
"isnan(INF)",
"isinf(1)",
"isinf(NAN)",
"isinf(INF)",
"floor(NAN)",
"floor(123.123)",
"floor(-123.123)",
"trunc(123.123)",
"trunc(-123.123)",
"ceil(123.123)",
"ceil(-123.123)",
"sqrt(1764)",
"isnan(sqrt(-1))",
"not(1)",
"not(NAN)",
"not(0)",
"6.0206dB",
"-3.0103dB",
"pow(0,1.23)",
"pow(PI,1.23)",
"PI^1.23",
"pow(-1,1.23)",
"if(1, 2)",
"if(1, 1, 2)",
"if(0, 1, 2)",
"ifnot(0, 23)",
"ifnot(1, NaN) + if(0, 1)",
"ifnot(1, 1, 2)",
"ifnot(0, 1, 2)",
"taylor(1, 1)",
"taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)",
"root(sin(ld(0))-1, 2)",
"root(sin(ld(0))+6+sin(ld(0)/12)-log(ld(0)), 100)",
"7000000B*random(0)",
"squish(2)",
"gauss(0.1)",
"hypot(4,3)",
"gcd(30,55)*print(min(9,1))",
"bitor(42, 12)",
"bitand(42, 12)",
"bitand(NAN, 1)",
"between(10, -3, 10)",
"between(-4, -2, -1)",
"between(1,2)",
"clip(0, 2, 1)",
"clip(0/0, 1, 2)",
"clip(0, 0/0, 1)",
NULL
};
for (expr = exprs; *expr; expr++) {
printf("Evaluating '%s'\n", *expr);
av_expr_parse_and_eval(&d, *expr,
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
if (isnan(d))
printf("'%s' -> nan\n\n", *expr);
else
printf("'%s' -> %f\n\n", *expr, d);
}
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("%f == 12.7\n", d);
av_expr_parse_and_eval(&d, "80G/80Gi",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("%f == 0.931322575\n", d);
if (argc > 1 && !strcmp(argv[1], "-t")) {
for (i = 0; i < 1050; i++) {
START_TIMER;
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
STOP_TIMER("av_expr_parse_and_eval");
}
}
return 0;
}

@ -737,156 +737,3 @@ int av_expr_parse_and_eval(double *d, const char *s,
av_expr_free(e);
return isnan(*d) ? AVERROR(EINVAL) : 0;
}
#ifdef TEST
#include <string.h>
static const double const_values[] = {
M_PI,
M_E,
0
};
static const char *const const_names[] = {
"PI",
"E",
0
};
int main(int argc, char **argv)
{
int i;
double d;
const char *const *expr;
static const char *const exprs[] = {
"",
"1;2",
"-20",
"-PI",
"+PI",
"1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
"80G/80Gi",
"1k",
"1Gi",
"1gi",
"1GiFoo",
"1k+1k",
"1Gi*3foo",
"foo",
"foo(",
"foo()",
"foo)",
"sin",
"sin(",
"sin()",
"sin)",
"sin 10",
"sin(1,2,3)",
"sin(1 )",
"1",
"1foo",
"bar + PI + E + 100f*2 + foo",
"13k + 12f - foo(1, 2)",
"1gi",
"1Gi",
"st(0, 123)",
"st(1, 123); ld(1)",
"lte(0, 1)",
"lte(1, 1)",
"lte(1, 0)",
"lt(0, 1)",
"lt(1, 1)",
"gt(1, 0)",
"gt(2, 7)",
"gte(122, 122)",
/* compute 1+2+...+N */
"st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
/* compute Fib(N) */
"st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
"while(0, 10)",
"st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
"isnan(1)",
"isnan(NAN)",
"isnan(INF)",
"isinf(1)",
"isinf(NAN)",
"isinf(INF)",
"floor(NAN)",
"floor(123.123)",
"floor(-123.123)",
"trunc(123.123)",
"trunc(-123.123)",
"ceil(123.123)",
"ceil(-123.123)",
"sqrt(1764)",
"isnan(sqrt(-1))",
"not(1)",
"not(NAN)",
"not(0)",
"6.0206dB",
"-3.0103dB",
"pow(0,1.23)",
"pow(PI,1.23)",
"PI^1.23",
"pow(-1,1.23)",
"if(1, 2)",
"if(1, 1, 2)",
"if(0, 1, 2)",
"ifnot(0, 23)",
"ifnot(1, NaN) + if(0, 1)",
"ifnot(1, 1, 2)",
"ifnot(0, 1, 2)",
"taylor(1, 1)",
"taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)",
"root(sin(ld(0))-1, 2)",
"root(sin(ld(0))+6+sin(ld(0)/12)-log(ld(0)), 100)",
"7000000B*random(0)",
"squish(2)",
"gauss(0.1)",
"hypot(4,3)",
"gcd(30,55)*print(min(9,1))",
"bitor(42, 12)",
"bitand(42, 12)",
"bitand(NAN, 1)",
"between(10, -3, 10)",
"between(-4, -2, -1)",
"between(1,2)",
"clip(0, 2, 1)",
"clip(0/0, 1, 2)",
"clip(0, 0/0, 1)",
NULL
};
for (expr = exprs; *expr; expr++) {
printf("Evaluating '%s'\n", *expr);
av_expr_parse_and_eval(&d, *expr,
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
if (isnan(d))
printf("'%s' -> nan\n\n", *expr);
else
printf("'%s' -> %f\n\n", *expr, d);
}
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("%f == 12.7\n", d);
av_expr_parse_and_eval(&d, "80G/80Gi",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("%f == 0.931322575\n", d);
if (argc > 1 && !strcmp(argv[1], "-t")) {
for (i = 0; i < 1050; i++) {
START_TIMER;
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
STOP_TIMER("av_expr_parse_and_eval");
}
}
return 0;
}
#endif

@ -0,0 +1,74 @@
/*
* 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 "fifo.h"
int main(void)
{
/* create a FIFO buffer */
AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
int i, j, n;
/* fill data */
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
/* peek at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = -n + 1; i < n; i++) {
int *v = (int *)av_fifo_peek2(fifo, i * sizeof(int));
printf("%d: %d\n", i, *v);
}
printf("\n");
/* peek_at at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = 0; i < n; i++) {
av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
printf("%d: %d\n", i, j);
}
printf("\n");
/* read data */
for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
printf("%d ", j);
}
printf("\n");
/* test *ndx overflow */
av_fifo_reset(fifo);
fifo->rndx = fifo->wndx = ~(uint32_t)0 - 5;
/* fill data */
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
/* peek_at at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = 0; i < n; i++) {
av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
printf("%d: %d\n", i, j);
}
av_fifo_free(fifo);
return 0;
}

@ -238,60 +238,3 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
f->rptr -= f->end - f->buffer;
f->rndx += size;
}
#ifdef TEST
int main(void)
{
/* create a FIFO buffer */
AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
int i, j, n;
/* fill data */
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
/* peek at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = -n + 1; i < n; i++) {
int *v = (int *)av_fifo_peek2(fifo, i * sizeof(int));
printf("%d: %d\n", i, *v);
}
printf("\n");
/* peek_at at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = 0; i < n; i++) {
av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
printf("%d: %d\n", i, j);
}
printf("\n");
/* read data */
for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
printf("%d ", j);
}
printf("\n");
/* test *ndx overflow */
av_fifo_reset(fifo);
fifo->rndx = fifo->wndx = ~(uint32_t)0 - 5;
/* fill data */
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
/* peek_at at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = 0; i < n; i++) {
av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
printf("%d: %d\n", i, j);
}
av_fifo_free(fifo);
return 0;
}
#endif

@ -0,0 +1,34 @@
/*
* 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 "file.c"
#undef printf
int main(void)
{
uint8_t *buf;
size_t size;
if (av_file_map("file.c", &buf, &size, 0, NULL) < 0)
return 1;
buf[0] = 's';
printf("%s", buf);
av_file_unmap(buf, size);
return 0;
}

@ -140,22 +140,3 @@ void av_file_unmap(uint8_t *bufptr, size_t size)
int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx) {
return avpriv_tempfile(prefix, filename, log_offset, log_ctx);
}
#ifdef TEST
#undef printf
int main(void)
{
uint8_t *buf;
size_t size;
if (av_file_map("file.c", &buf, &size, 0, NULL) < 0)
return 1;
buf[0] = 's';
printf("%s", buf);
av_file_unmap(buf, size);
return 0;
}
#endif

@ -0,0 +1,331 @@
/*
* 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 <float.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_UNISTD_H
#include <unistd.h> /* for getopt */
#endif
#if !HAVE_GETOPT
#include "compat/getopt.c"
#endif
#include "common.h"
#include "cpu.h"
#include "internal.h"
#include "lfg.h"
#include "log.h"
#include "random_seed.h"
#include "float_dsp.h"
#define LEN 240
static void fill_float_array(AVLFG *lfg, float *a, int len)
{
int i;
double bmg[2], stddev = 10.0, mean = 0.0;
for (i = 0; i < len; i += 2) {
av_bmg_get(lfg, bmg);
a[i] = bmg[0] * stddev + mean;
a[i + 1] = bmg[1] * stddev + mean;
}
}
static int compare_floats(const float *a, const float *b, int len,
float max_diff)
{
int i;
for (i = 0; i < len; i++) {
if (fabsf(a[i] - b[i]) > max_diff) {
av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n",
i, a[i], b[i], a[i] - b[i]);
return -1;
}
}
return 0;
}
static void fill_double_array(AVLFG *lfg, double *a, int len)
{
int i;
double bmg[2], stddev = 10.0, mean = 0.0;
for (i = 0; i < len; i += 2) {
av_bmg_get(lfg, bmg);
a[i] = bmg[0] * stddev + mean;
a[i + 1] = bmg[1] * stddev + mean;
}
}
static int compare_doubles(const double *a, const double *b, int len,
double max_diff)
{
int i;
for (i = 0; i < len; i++) {
if (fabs(a[i] - b[i]) > max_diff) {
av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n",
i, a[i], b[i], a[i] - b[i]);
return -1;
}
}
return 0;
}
static int test_vector_fmul(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul(cdst, v1, v2, LEN);
fdsp->vector_fmul(odst, v1, v2, LEN);
if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
av_log(NULL, AV_LOG_ERROR, "vector_fmul failed\n");
return ret;
}
#define ARBITRARY_FMAC_SCALAR_CONST 0.005
static int test_vector_fmac_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *src0, float scale)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
memcpy(cdst, v1, LEN * sizeof(*v1));
memcpy(odst, v1, LEN * sizeof(*v1));
cdsp->vector_fmac_scalar(cdst, src0, scale, LEN);
fdsp->vector_fmac_scalar(odst, src0, scale, LEN);
if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMAC_SCALAR_CONST))
av_log(NULL, AV_LOG_ERROR, "vector_fmac_scalar failed\n");
return ret;
}
static int test_vector_fmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, float scale)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul_scalar(cdst, v1, scale, LEN);
fdsp->vector_fmul_scalar(odst, v1, scale, LEN);
if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
av_log(NULL, AV_LOG_ERROR, "vector_fmul_scalar failed\n");
return ret;
}
static int test_vector_dmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const double *v1, double scale)
{
LOCAL_ALIGNED(32, double, cdst, [LEN]);
LOCAL_ALIGNED(32, double, odst, [LEN]);
int ret;
cdsp->vector_dmul_scalar(cdst, v1, scale, LEN);
fdsp->vector_dmul_scalar(odst, v1, scale, LEN);
if (ret = compare_doubles(cdst, odst, LEN, DBL_EPSILON))
av_log(NULL, AV_LOG_ERROR, "vector_dmul_scalar failed\n");
return ret;
}
#define ARBITRARY_FMUL_WINDOW_CONST 0.008
static int test_vector_fmul_window(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2, const float *v3)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul_window(cdst, v1, v2, v3, LEN / 2);
fdsp->vector_fmul_window(odst, v1, v2, v3, LEN / 2);
if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_WINDOW_CONST))
av_log(NULL, AV_LOG_ERROR, "vector_fmul_window failed\n");
return ret;
}
#define ARBITRARY_FMUL_ADD_CONST 0.005
static int test_vector_fmul_add(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2, const float *v3)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul_add(cdst, v1, v2, v3, LEN);
fdsp->vector_fmul_add(odst, v1, v2, v3, LEN);
if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_ADD_CONST))
av_log(NULL, AV_LOG_ERROR, "vector_fmul_add failed\n");
return ret;
}
static int test_vector_fmul_reverse(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul_reverse(cdst, v1, v2, LEN);
fdsp->vector_fmul_reverse(odst, v1, v2, LEN);
if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
av_log(NULL, AV_LOG_ERROR, "vector_fmul_reverse failed\n");
return ret;
}
static int test_butterflies_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2)
{
LOCAL_ALIGNED(32, float, cv1, [LEN]);
LOCAL_ALIGNED(32, float, cv2, [LEN]);
LOCAL_ALIGNED(32, float, ov1, [LEN]);
LOCAL_ALIGNED(32, float, ov2, [LEN]);
int ret;
memcpy(cv1, v1, LEN * sizeof(*v1));
memcpy(cv2, v2, LEN * sizeof(*v2));
memcpy(ov1, v1, LEN * sizeof(*v1));
memcpy(ov2, v2, LEN * sizeof(*v2));
cdsp->butterflies_float(cv1, cv2, LEN);
fdsp->butterflies_float(ov1, ov2, LEN);
if ((ret = compare_floats(cv1, ov1, LEN, FLT_EPSILON)) ||
(ret = compare_floats(cv2, ov2, LEN, FLT_EPSILON)))
av_log(NULL, AV_LOG_ERROR, "butterflies_float failed\n");
return ret;
}
#define ARBITRARY_SCALARPRODUCT_CONST 0.2
static int test_scalarproduct_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2)
{
float cprod, oprod;
int ret;
cprod = cdsp->scalarproduct_float(v1, v2, LEN);
oprod = fdsp->scalarproduct_float(v1, v2, LEN);
if (ret = compare_floats(&cprod, &oprod, 1, ARBITRARY_SCALARPRODUCT_CONST))
av_log(NULL, AV_LOG_ERROR, "scalarproduct_float failed\n");
return ret;
}
int main(int argc, char **argv)
{
int ret = 0, seeded = 0;
uint32_t seed;
AVFloatDSPContext *fdsp, *cdsp;
AVLFG lfg;
LOCAL_ALIGNED(32, float, src0, [LEN]);
LOCAL_ALIGNED(32, float, src1, [LEN]);
LOCAL_ALIGNED(32, float, src2, [LEN]);
LOCAL_ALIGNED(32, double, dbl_src0, [LEN]);
LOCAL_ALIGNED(32, double, dbl_src1, [LEN]);
for (;;) {
int arg = getopt(argc, argv, "s:c:");
if (arg == -1)
break;
switch (arg) {
case 's':
seed = strtoul(optarg, NULL, 10);
seeded = 1;
break;
case 'c':
{
int cpuflags = av_get_cpu_flags();
if (av_parse_cpu_caps(&cpuflags, optarg) < 0)
return 1;
av_force_cpu_flags(cpuflags);
break;
}
}
}
if (!seeded)
seed = av_get_random_seed();
av_log(NULL, AV_LOG_INFO, "float_dsp-test: %s %u\n", seeded ? "seed" : "random seed", seed);
fdsp = avpriv_float_dsp_alloc(1);
av_force_cpu_flags(0);
cdsp = avpriv_float_dsp_alloc(1);
if (!fdsp || !cdsp) {
ret = 1;
goto end;
}
av_lfg_init(&lfg, seed);
fill_float_array(&lfg, src0, LEN);
fill_float_array(&lfg, src1, LEN);
fill_float_array(&lfg, src2, LEN);
fill_double_array(&lfg, dbl_src0, LEN);
fill_double_array(&lfg, dbl_src1, LEN);
if (test_vector_fmul(fdsp, cdsp, src0, src1))
ret -= 1 << 0;
if (test_vector_fmac_scalar(fdsp, cdsp, src2, src0, src1[0]))
ret -= 1 << 1;
if (test_vector_fmul_scalar(fdsp, cdsp, src0, src1[0]))
ret -= 1 << 2;
if (test_vector_fmul_window(fdsp, cdsp, src0, src1, src2))
ret -= 1 << 3;
if (test_vector_fmul_add(fdsp, cdsp, src0, src1, src2))
ret -= 1 << 4;
if (test_vector_fmul_reverse(fdsp, cdsp, src0, src1))
ret -= 1 << 5;
if (test_butterflies_float(fdsp, cdsp, src0, src1))
ret -= 1 << 6;
if (test_scalarproduct_float(fdsp, cdsp, src0, src1))
ret -= 1 << 7;
if (test_vector_dmul_scalar(fdsp, cdsp, dbl_src0, dbl_src1[0]))
ret -= 1 << 8;
end:
av_freep(&fdsp);
av_freep(&cdsp);
return ret;
}

@ -144,321 +144,3 @@ av_cold AVFloatDSPContext *avpriv_float_dsp_alloc(int bit_exact)
ff_float_dsp_init_mips(fdsp);
return fdsp;
}
#ifdef TEST
#include <float.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_UNISTD_H
#include <unistd.h> /* for getopt */
#endif
#if !HAVE_GETOPT
#include "compat/getopt.c"
#endif
#include "common.h"
#include "cpu.h"
#include "internal.h"
#include "lfg.h"
#include "log.h"
#include "random_seed.h"
#define LEN 240
static void fill_float_array(AVLFG *lfg, float *a, int len)
{
int i;
double bmg[2], stddev = 10.0, mean = 0.0;
for (i = 0; i < len; i += 2) {
av_bmg_get(lfg, bmg);
a[i] = bmg[0] * stddev + mean;
a[i + 1] = bmg[1] * stddev + mean;
}
}
static int compare_floats(const float *a, const float *b, int len,
float max_diff)
{
int i;
for (i = 0; i < len; i++) {
if (fabsf(a[i] - b[i]) > max_diff) {
av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n",
i, a[i], b[i], a[i] - b[i]);
return -1;
}
}
return 0;
}
static void fill_double_array(AVLFG *lfg, double *a, int len)
{
int i;
double bmg[2], stddev = 10.0, mean = 0.0;
for (i = 0; i < len; i += 2) {
av_bmg_get(lfg, bmg);
a[i] = bmg[0] * stddev + mean;
a[i + 1] = bmg[1] * stddev + mean;
}
}
static int compare_doubles(const double *a, const double *b, int len,
double max_diff)
{
int i;
for (i = 0; i < len; i++) {
if (fabs(a[i] - b[i]) > max_diff) {
av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n",
i, a[i], b[i], a[i] - b[i]);
return -1;
}
}
return 0;
}
static int test_vector_fmul(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul(cdst, v1, v2, LEN);
fdsp->vector_fmul(odst, v1, v2, LEN);
if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
av_log(NULL, AV_LOG_ERROR, "vector_fmul failed\n");
return ret;
}
#define ARBITRARY_FMAC_SCALAR_CONST 0.005
static int test_vector_fmac_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *src0, float scale)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
memcpy(cdst, v1, LEN * sizeof(*v1));
memcpy(odst, v1, LEN * sizeof(*v1));
cdsp->vector_fmac_scalar(cdst, src0, scale, LEN);
fdsp->vector_fmac_scalar(odst, src0, scale, LEN);
if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMAC_SCALAR_CONST))
av_log(NULL, AV_LOG_ERROR, "vector_fmac_scalar failed\n");
return ret;
}
static int test_vector_fmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, float scale)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul_scalar(cdst, v1, scale, LEN);
fdsp->vector_fmul_scalar(odst, v1, scale, LEN);
if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
av_log(NULL, AV_LOG_ERROR, "vector_fmul_scalar failed\n");
return ret;
}
static int test_vector_dmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const double *v1, double scale)
{
LOCAL_ALIGNED(32, double, cdst, [LEN]);
LOCAL_ALIGNED(32, double, odst, [LEN]);
int ret;
cdsp->vector_dmul_scalar(cdst, v1, scale, LEN);
fdsp->vector_dmul_scalar(odst, v1, scale, LEN);
if (ret = compare_doubles(cdst, odst, LEN, DBL_EPSILON))
av_log(NULL, AV_LOG_ERROR, "vector_dmul_scalar failed\n");
return ret;
}
#define ARBITRARY_FMUL_WINDOW_CONST 0.008
static int test_vector_fmul_window(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2, const float *v3)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul_window(cdst, v1, v2, v3, LEN / 2);
fdsp->vector_fmul_window(odst, v1, v2, v3, LEN / 2);
if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_WINDOW_CONST))
av_log(NULL, AV_LOG_ERROR, "vector_fmul_window failed\n");
return ret;
}
#define ARBITRARY_FMUL_ADD_CONST 0.005
static int test_vector_fmul_add(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2, const float *v3)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul_add(cdst, v1, v2, v3, LEN);
fdsp->vector_fmul_add(odst, v1, v2, v3, LEN);
if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_ADD_CONST))
av_log(NULL, AV_LOG_ERROR, "vector_fmul_add failed\n");
return ret;
}
static int test_vector_fmul_reverse(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2)
{
LOCAL_ALIGNED(32, float, cdst, [LEN]);
LOCAL_ALIGNED(32, float, odst, [LEN]);
int ret;
cdsp->vector_fmul_reverse(cdst, v1, v2, LEN);
fdsp->vector_fmul_reverse(odst, v1, v2, LEN);
if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
av_log(NULL, AV_LOG_ERROR, "vector_fmul_reverse failed\n");
return ret;
}
static int test_butterflies_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2)
{
LOCAL_ALIGNED(32, float, cv1, [LEN]);
LOCAL_ALIGNED(32, float, cv2, [LEN]);
LOCAL_ALIGNED(32, float, ov1, [LEN]);
LOCAL_ALIGNED(32, float, ov2, [LEN]);
int ret;
memcpy(cv1, v1, LEN * sizeof(*v1));
memcpy(cv2, v2, LEN * sizeof(*v2));
memcpy(ov1, v1, LEN * sizeof(*v1));
memcpy(ov2, v2, LEN * sizeof(*v2));
cdsp->butterflies_float(cv1, cv2, LEN);
fdsp->butterflies_float(ov1, ov2, LEN);
if ((ret = compare_floats(cv1, ov1, LEN, FLT_EPSILON)) ||
(ret = compare_floats(cv2, ov2, LEN, FLT_EPSILON)))
av_log(NULL, AV_LOG_ERROR, "butterflies_float failed\n");
return ret;
}
#define ARBITRARY_SCALARPRODUCT_CONST 0.2
static int test_scalarproduct_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const float *v1, const float *v2)
{
float cprod, oprod;
int ret;
cprod = cdsp->scalarproduct_float(v1, v2, LEN);
oprod = fdsp->scalarproduct_float(v1, v2, LEN);
if (ret = compare_floats(&cprod, &oprod, 1, ARBITRARY_SCALARPRODUCT_CONST))
av_log(NULL, AV_LOG_ERROR, "scalarproduct_float failed\n");
return ret;
}
int main(int argc, char **argv)
{
int ret = 0, seeded = 0;
uint32_t seed;
AVFloatDSPContext *fdsp, *cdsp;
AVLFG lfg;
LOCAL_ALIGNED(32, float, src0, [LEN]);
LOCAL_ALIGNED(32, float, src1, [LEN]);
LOCAL_ALIGNED(32, float, src2, [LEN]);
LOCAL_ALIGNED(32, double, dbl_src0, [LEN]);
LOCAL_ALIGNED(32, double, dbl_src1, [LEN]);
for (;;) {
int arg = getopt(argc, argv, "s:c:");
if (arg == -1)
break;
switch (arg) {
case 's':
seed = strtoul(optarg, NULL, 10);
seeded = 1;
break;
case 'c':
{
int cpuflags = av_get_cpu_flags();
if (av_parse_cpu_caps(&cpuflags, optarg) < 0)
return 1;
av_force_cpu_flags(cpuflags);
break;
}
}
}
if (!seeded)
seed = av_get_random_seed();
av_log(NULL, AV_LOG_INFO, "float_dsp-test: %s %u\n", seeded ? "seed" : "random seed", seed);
fdsp = avpriv_float_dsp_alloc(1);
av_force_cpu_flags(0);
cdsp = avpriv_float_dsp_alloc(1);
if (!fdsp || !cdsp) {
ret = 1;
goto end;
}
av_lfg_init(&lfg, seed);
fill_float_array(&lfg, src0, LEN);
fill_float_array(&lfg, src1, LEN);
fill_float_array(&lfg, src2, LEN);
fill_double_array(&lfg, dbl_src0, LEN);
fill_double_array(&lfg, dbl_src1, LEN);
if (test_vector_fmul(fdsp, cdsp, src0, src1))
ret -= 1 << 0;
if (test_vector_fmac_scalar(fdsp, cdsp, src2, src0, src1[0]))
ret -= 1 << 1;
if (test_vector_fmul_scalar(fdsp, cdsp, src0, src1[0]))
ret -= 1 << 2;
if (test_vector_fmul_window(fdsp, cdsp, src0, src1, src2))
ret -= 1 << 3;
if (test_vector_fmul_add(fdsp, cdsp, src0, src1, src2))
ret -= 1 << 4;
if (test_vector_fmul_reverse(fdsp, cdsp, src0, src1))
ret -= 1 << 5;
if (test_butterflies_float(fdsp, cdsp, src0, src1))
ret -= 1 << 6;
if (test_scalarproduct_float(fdsp, cdsp, src0, src1))
ret -= 1 << 7;
if (test_vector_dmul_scalar(fdsp, cdsp, dbl_src0, dbl_src1[0]))
ret -= 1 << 8;
end:
av_freep(&fdsp);
av_freep(&cdsp);
return ret;
}
#endif /* TEST */

@ -0,0 +1,58 @@
/*
* Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
* 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 "hash.c"
#define SRC_BUF_SIZE 64
#define DST_BUF_SIZE (AV_HASH_MAX_SIZE * 8)
int main(void)
{
struct AVHashContext *ctx = NULL;
int i, j;
static const uint8_t src[SRC_BUF_SIZE] = { 0 };
uint8_t dst[DST_BUF_SIZE];
for (i = 0; i < NUM_HASHES; i++) {
if (av_hash_alloc(&ctx, av_hash_names(i)) < 0)
return 1;
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
memset(dst, 0, DST_BUF_SIZE);
av_hash_final_hex(ctx, dst, DST_BUF_SIZE);
printf("%s hex: %s\n", av_hash_get_name(ctx), dst);
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
av_hash_final_bin(ctx, dst, DST_BUF_SIZE);
printf("%s bin: ", av_hash_get_name(ctx));
for (j = 0; j < av_hash_get_size(ctx); j++) {
printf("%#x ", dst[j]);
}
printf("\n");
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
av_hash_final_b64(ctx, dst, DST_BUF_SIZE);
printf("%s b64: %s\n", av_hash_get_name(ctx), dst);
av_hash_freep(&ctx);
}
return 0;
}

@ -237,45 +237,3 @@ void av_hash_freep(AVHashContext **ctx)
av_freep(&(*ctx)->ctx);
av_freep(ctx);
}
#ifdef TEST
// LCOV_EXCL_START
#define SRC_BUF_SIZE 64
#define DST_BUF_SIZE (AV_HASH_MAX_SIZE * 8)
int main(void)
{
struct AVHashContext *ctx = NULL;
int i, j;
static const uint8_t src[SRC_BUF_SIZE] = { 0 };
uint8_t dst[DST_BUF_SIZE];
for (i = 0; i < NUM_HASHES; i++) {
if (av_hash_alloc(&ctx, av_hash_names(i)) < 0)
return 1;
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
memset(dst, 0, DST_BUF_SIZE);
av_hash_final_hex(ctx, dst, DST_BUF_SIZE);
printf("%s hex: %s\n", av_hash_get_name(ctx), dst);
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
av_hash_final_bin(ctx, dst, DST_BUF_SIZE);
printf("%s bin: ", av_hash_get_name(ctx));
for (j = 0; j < av_hash_get_size(ctx); j++) {
printf("%#x ", dst[j]);
}
printf("\n");
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
av_hash_final_b64(ctx, dst, DST_BUF_SIZE);
printf("%s b64: %s\n", av_hash_get_name(ctx), dst);
av_hash_freep(&ctx);
}
return 0;
}
// LCOV_EXCL_STOP
#endif

@ -0,0 +1,99 @@
/*
* 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 "hmac.c"
#include <stdio.h>
#include <string.h>
static void test(AVHMAC *hmac, const uint8_t *key, int keylen,
const uint8_t *data, int datalen)
{
uint8_t buf[MAX_HASHLEN];
int out, i;
// Some of the test vectors are strings, where sizeof() includes the
// trailing null byte - remove that.
if (!key[keylen - 1])
keylen--;
if (!data[datalen - 1])
datalen--;
out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf));
for (i = 0; i < out; i++)
printf("%02x", buf[i]);
printf("\n");
}
int main(void)
{
uint8_t key1[20], key3[131], data3[50];
AVHMAC *hmac;
enum AVHMACType i;
static const uint8_t key2[] = "Jefe";
static const uint8_t data1[] = "Hi There";
static const uint8_t data2[] = "what do ya want for nothing?";
static const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First";
static const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
static const uint8_t data6[] = "This is a test using a larger than block-size key and a larger "
"than block-size data. The key needs to be hashed before being used"
" by the HMAC algorithm.";
memset(key1, 0x0b, sizeof(key1));
memset(key3, 0xaa, sizeof(key3));
memset(data3, 0xdd, sizeof(data3));
/* MD5, SHA-1 */
for (i = AV_HMAC_MD5; i <= AV_HMAC_SHA1; i++) {
hmac = av_hmac_alloc(i);
if (!hmac)
return 1;
// RFC 2202 test vectors
test(hmac, key1, hmac->hashlen, data1, sizeof(data1));
test(hmac, key2, sizeof(key2), data2, sizeof(data2));
test(hmac, key3, hmac->hashlen, data3, sizeof(data3));
test(hmac, key3, 80, data4, sizeof(data4));
test(hmac, key3, 80, data5, sizeof(data5));
av_hmac_free(hmac);
}
/* SHA-2 */
for (i = AV_HMAC_SHA224; i <= AV_HMAC_SHA256; i++) {
hmac = av_hmac_alloc(i);
if (!hmac)
return 1;
// RFC 4231 test vectors
test(hmac, key1, sizeof(key1), data1, sizeof(data1));
test(hmac, key2, sizeof(key2), data2, sizeof(data2));
test(hmac, key3, 20, data3, sizeof(data3));
test(hmac, key3, sizeof(key3), data4, sizeof(data4));
test(hmac, key3, sizeof(key3), data6, sizeof(data6));
av_hmac_free(hmac);
}
for (i = AV_HMAC_SHA384; i <= AV_HMAC_SHA512; i++) {
hmac = av_hmac_alloc(i);
if (!hmac)
return 1;
// RFC 4231 test vectors
test(hmac, key1, sizeof(key1), data1, sizeof(data1));
test(hmac, key2, sizeof(key2), data2, sizeof(data2));
test(hmac, key3, 20, data3, sizeof(data3));
test(hmac, key3, sizeof(key3), data4, sizeof(data4));
test(hmac, key3, sizeof(key3), data6, sizeof(data6));
av_hmac_free(hmac);
}
return 0;
}

@ -183,84 +183,3 @@ int av_hmac_calc(AVHMAC *c, const uint8_t *data, unsigned int len,
av_hmac_update(c, data, len);
return av_hmac_final(c, out, outlen);
}
#ifdef TEST
#include <stdio.h>
static void test(AVHMAC *hmac, const uint8_t *key, int keylen,
const uint8_t *data, int datalen)
{
uint8_t buf[MAX_HASHLEN];
int out, i;
// Some of the test vectors are strings, where sizeof() includes the
// trailing null byte - remove that.
if (!key[keylen - 1])
keylen--;
if (!data[datalen - 1])
datalen--;
out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf));
for (i = 0; i < out; i++)
printf("%02x", buf[i]);
printf("\n");
}
int main(void)
{
uint8_t key1[20], key3[131], data3[50];
AVHMAC *hmac;
enum AVHMACType i;
static const uint8_t key2[] = "Jefe";
static const uint8_t data1[] = "Hi There";
static const uint8_t data2[] = "what do ya want for nothing?";
static const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First";
static const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
static const uint8_t data6[] = "This is a test using a larger than block-size key and a larger "
"than block-size data. The key needs to be hashed before being used"
" by the HMAC algorithm.";
memset(key1, 0x0b, sizeof(key1));
memset(key3, 0xaa, sizeof(key3));
memset(data3, 0xdd, sizeof(data3));
/* MD5, SHA-1 */
for (i = AV_HMAC_MD5; i <= AV_HMAC_SHA1; i++) {
hmac = av_hmac_alloc(i);
if (!hmac)
return 1;
// RFC 2202 test vectors
test(hmac, key1, hmac->hashlen, data1, sizeof(data1));
test(hmac, key2, sizeof(key2), data2, sizeof(data2));
test(hmac, key3, hmac->hashlen, data3, sizeof(data3));
test(hmac, key3, 80, data4, sizeof(data4));
test(hmac, key3, 80, data5, sizeof(data5));
av_hmac_free(hmac);
}
/* SHA-2 */
for (i = AV_HMAC_SHA224; i <= AV_HMAC_SHA256; i++) {
hmac = av_hmac_alloc(i);
if (!hmac)
return 1;
// RFC 4231 test vectors
test(hmac, key1, sizeof(key1), data1, sizeof(data1));
test(hmac, key2, sizeof(key2), data2, sizeof(data2));
test(hmac, key3, 20, data3, sizeof(data3));
test(hmac, key3, sizeof(key3), data4, sizeof(data4));
test(hmac, key3, sizeof(key3), data6, sizeof(data6));
av_hmac_free(hmac);
}
for (i = AV_HMAC_SHA384; i <= AV_HMAC_SHA512; i++) {
hmac = av_hmac_alloc(i);
if (!hmac)
return 1;
// RFC 4231 test vectors
test(hmac, key1, sizeof(key1), data1, sizeof(data1));
test(hmac, key2, sizeof(key2), data2, sizeof(data2));
test(hmac, key3, 20, data3, sizeof(data3));
test(hmac, key3, sizeof(key3), data4, sizeof(data4));
test(hmac, key3, sizeof(key3), data6, sizeof(data6));
av_hmac_free(hmac);
}
return 0;
}
#endif /* TEST */

@ -0,0 +1,74 @@
/*
* 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 "log.h"
#include "timer.h"
#include "lfg.h"
int main(void)
{
int x = 0;
int i, j;
AVLFG state;
av_lfg_init(&state, 0xdeadbeef);
for (j = 0; j < 10000; j++) {
START_TIMER
for (i = 0; i < 624; i++) {
//av_log(NULL, AV_LOG_ERROR, "%X\n", av_lfg_get(&state));
x += av_lfg_get(&state);
}
STOP_TIMER("624 calls of av_lfg_get");
}
av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
/* BMG usage example */
{
double mean = 1000;
double stddev = 53;
double samp_mean = 0.0, samp_stddev = 0.0;
double samp0, samp1;
av_lfg_init(&state, 42);
for (i = 0; i < 1000; i += 2) {
double bmg_out[2];
av_bmg_get(&state, bmg_out);
samp0 = bmg_out[0] * stddev + mean;
samp1 = bmg_out[1] * stddev + mean;
samp_mean += samp0 + samp1;
samp_stddev += samp0 * samp0 + samp1 * samp1;
av_log(NULL, AV_LOG_INFO,
"%f\n%f\n",
samp0,
samp1);
}
/* TODO: add proper normality test */
samp_mean /= 1000;
samp_stddev /= 999;
samp_stddev -= (1000.0/999.0)*samp_mean*samp_mean;
samp_stddev = sqrt(samp_stddev);
av_log(NULL, AV_LOG_INFO, "sample mean : %f\n"
"true mean : %f\n"
"sample stddev: %f\n"
"true stddev : %f\n",
samp_mean, mean, samp_stddev, stddev);
}
return 0;
}

@ -58,61 +58,3 @@ void av_bmg_get(AVLFG *lfg, double out[2])
out[0] = x1 * w;
out[1] = x2 * w;
}
#ifdef TEST
#include "log.h"
#include "timer.h"
int main(void)
{
int x = 0;
int i, j;
AVLFG state;
av_lfg_init(&state, 0xdeadbeef);
for (j = 0; j < 10000; j++) {
START_TIMER
for (i = 0; i < 624; i++) {
//av_log(NULL, AV_LOG_ERROR, "%X\n", av_lfg_get(&state));
x += av_lfg_get(&state);
}
STOP_TIMER("624 calls of av_lfg_get");
}
av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
/* BMG usage example */
{
double mean = 1000;
double stddev = 53;
double samp_mean = 0.0, samp_stddev = 0.0;
double samp0, samp1;
av_lfg_init(&state, 42);
for (i = 0; i < 1000; i += 2) {
double bmg_out[2];
av_bmg_get(&state, bmg_out);
samp0 = bmg_out[0] * stddev + mean;
samp1 = bmg_out[1] * stddev + mean;
samp_mean += samp0 + samp1;
samp_stddev += samp0 * samp0 + samp1 * samp1;
av_log(NULL, AV_LOG_INFO,
"%f\n%f\n",
samp0,
samp1);
}
/* TODO: add proper normality test */
samp_mean /= 1000;
samp_stddev /= 999;
samp_stddev -= (1000.0/999.0)*samp_mean*samp_mean;
samp_stddev = sqrt(samp_stddev);
av_log(NULL, AV_LOG_INFO, "sample mean : %f\n"
"true mean : %f\n"
"sample stddev: %f\n"
"true stddev : %f\n",
samp_mean, mean, samp_stddev, stddev);
}
return 0;
}
#endif

@ -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 <limits.h>
#include <stdio.h>
#include "internal.h"
#include "lfg.h"
#include "lls.h"
int main(void)
{
LLSModel m;
int i, order;
AVLFG lfg;
av_lfg_init(&lfg, 1);
avpriv_init_lls(&m, 3);
for (i = 0; i < 100; i++) {
LOCAL_ALIGNED(32, double, var, [4]);
double eval;
var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
m.update_lls(&m, var);
avpriv_solve_lls(&m, 0.001, 0);
for (order = 0; order < 3; order++) {
eval = m.evaluate_lls(&m, var + 1, order);
printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
m.coeff[order][0], m.coeff[order][1],
m.coeff[order][2]);
}
}
return 0;
}

@ -121,41 +121,3 @@ av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
if (ARCH_X86)
ff_init_lls_x86(m);
}
#ifdef TEST
#include <stdio.h>
#include <limits.h>
#include "lfg.h"
int main(void)
{
LLSModel m;
int i, order;
AVLFG lfg;
av_lfg_init(&lfg, 1);
avpriv_init_lls(&m, 3);
for (i = 0; i < 100; i++) {
LOCAL_ALIGNED(32, double, var, [4]);
double eval;
var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
m.update_lls(&m, var);
avpriv_solve_lls(&m, 0.001, 0);
for (order = 0; order < 3; order++) {
eval = m.evaluate_lls(&m, var + 1, order);
printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
m.coeff[order][0], m.coeff[order][1],
m.coeff[order][2]);
}
}
return 0;
}
#endif

@ -0,0 +1,71 @@
/*
* log functions
* Copyright (c) 2003 Michel Bardiaux
*
* 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 "log.c"
#include <string.h>
static int call_log_format_line2(const char *fmt, char *buffer, int buffer_size, ...)
{
va_list args;
int ret;
int print_prefix=1;
va_start(args, buffer_size);
ret = av_log_format_line2(NULL, AV_LOG_INFO, fmt, args, buffer, buffer_size, &print_prefix);
va_end(args);
return ret;
}
int main(int argc, char **argv)
{
int i;
av_log_set_level(AV_LOG_DEBUG);
for (use_color=0; use_color<=256; use_color = 255*use_color+1) {
av_log(NULL, AV_LOG_FATAL, "use_color: %d\n", use_color);
for (i = AV_LOG_DEBUG; i>=AV_LOG_QUIET; i-=8) {
av_log(NULL, i, " %d", i);
av_log(NULL, AV_LOG_INFO, "e ");
av_log(NULL, i + 256*123, "C%d", i);
av_log(NULL, AV_LOG_INFO, "e");
}
av_log(NULL, AV_LOG_PANIC, "\n");
}
{
int result;
char buffer[4];
result = call_log_format_line2("foo", NULL, 0);
if(result != 3) {
printf("Test NULL buffer failed.\n");
return 1;
}
result = call_log_format_line2("foo", buffer, 2);
if(result != 3 || strncmp(buffer, "f", 2)) {
printf("Test buffer too small failed.\n");
return 1;
}
result = call_log_format_line2("foo", buffer, 4);
if(result != 3 || strncmp(buffer, "foo", 4)) {
printf("Test buffer sufficiently big failed.\n");
return 1;
}
}
return 0;
}

@ -439,56 +439,3 @@ void avpriv_report_missing_feature(void *avc, const char *msg, ...)
missing_feature_sample(0, avc, msg, argument_list);
va_end(argument_list);
}
#ifdef TEST
// LCOV_EXCL_START
#include <string.h>
static int call_log_format_line2(const char *fmt, char *buffer, int buffer_size, ...)
{
va_list args;
int ret;
int print_prefix=1;
va_start(args, buffer_size);
ret = av_log_format_line2(NULL, AV_LOG_INFO, fmt, args, buffer, buffer_size, &print_prefix);
va_end(args);
return ret;
}
int main(int argc, char **argv)
{
int i;
av_log_set_level(AV_LOG_DEBUG);
for (use_color=0; use_color<=256; use_color = 255*use_color+1) {
av_log(NULL, AV_LOG_FATAL, "use_color: %d\n", use_color);
for (i = AV_LOG_DEBUG; i>=AV_LOG_QUIET; i-=8) {
av_log(NULL, i, " %d", i);
av_log(NULL, AV_LOG_INFO, "e ");
av_log(NULL, i + 256*123, "C%d", i);
av_log(NULL, AV_LOG_INFO, "e");
}
av_log(NULL, AV_LOG_PANIC, "\n");
}
{
int result;
char buffer[4];
result = call_log_format_line2("foo", NULL, 0);
if(result != 3) {
printf("Test NULL buffer failed.\n");
return 1;
}
result = call_log_format_line2("foo", buffer, 2);
if(result != 3 || strncmp(buffer, "f", 2)) {
printf("Test buffer too small failed.\n");
return 1;
}
result = call_log_format_line2("foo", buffer, 4);
if(result != 3 || strncmp(buffer, "foo", 4)) {
printf("Test buffer sufficiently big failed.\n");
return 1;
}
}
return 0;
}
// LCOV_EXCL_STOP
#endif

@ -0,0 +1,55 @@
/*
* 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 "md5.h"
static void print_md5(uint8_t *md5)
{
int i;
for (i = 0; i < 16; i++)
printf("%02x", md5[i]);
printf("\n");
}
int main(void)
{
uint8_t md5val[16];
int i;
volatile uint8_t in[1000]; // volatile to workaround http://llvm.org/bugs/show_bug.cgi?id=20849
// FIXME remove volatile once it has been fixed and all fate clients are updated
for (i = 0; i < 1000; i++)
in[i] = i * i;
av_md5_sum(md5val, in, 1000);
print_md5(md5val);
av_md5_sum(md5val, in, 63);
print_md5(md5val);
av_md5_sum(md5val, in, 64);
print_md5(md5val);
av_md5_sum(md5val, in, 65);
print_md5(md5val);
for (i = 0; i < 1000; i++)
in[i] = i % 127;
av_md5_sum(md5val, in, 999);
print_md5(md5val);
return 0;
}

@ -212,40 +212,3 @@ void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
av_md5_update(&ctx, src, len);
av_md5_final(&ctx, dst);
}
#ifdef TEST
#include <stdio.h>
static void print_md5(uint8_t *md5)
{
int i;
for (i = 0; i < 16; i++)
printf("%02x", md5[i]);
printf("\n");
}
int main(void)
{
uint8_t md5val[16];
int i;
volatile uint8_t in[1000]; // volatile to workaround http://llvm.org/bugs/show_bug.cgi?id=20849
// FIXME remove volatile once it has been fixed and all fate clients are updated
for (i = 0; i < 1000; i++)
in[i] = i * i;
av_md5_sum(md5val, in, 1000);
print_md5(md5val);
av_md5_sum(md5val, in, 63);
print_md5(md5val);
av_md5_sum(md5val, in, 64);
print_md5(md5val);
av_md5_sum(md5val, in, 65);
print_md5(md5val);
for (i = 0; i < 1000; i++)
in[i] = i % 127;
av_md5_sum(md5val, in, 999);
print_md5(md5val);
return 0;
}
#endif

@ -0,0 +1,56 @@
/*
* Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
* 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 "murmur3.c"
int main(void)
{
int i;
uint8_t hash_result[16] = {0};
AVMurMur3 *ctx = av_murmur3_alloc();
#if 1
uint8_t in[256] = {0};
uint8_t *hashes = av_mallocz(256 * 16);
for (i = 0; i < 256; i++)
{
in[i] = i;
av_murmur3_init_seeded(ctx, 256 - i);
// Note: this actually tests hashing 0 bytes
av_murmur3_update(ctx, in, i);
av_murmur3_final(ctx, hashes + 16 * i);
}
av_murmur3_init_seeded(ctx, 0);
av_murmur3_update(ctx, hashes, 256 * 16);
av_murmur3_final(ctx, hash_result);
av_free(hashes);
av_freep(&ctx);
printf("result: 0x%"PRIx64" 0x%"PRIx64"\n", AV_RL64(hash_result), AV_RL64(hash_result + 8));
// official reference value is 32 bit
return AV_RL32(hash_result) != 0x6384ba69;
#else
uint8_t *in = av_mallocz(512*1024);
av_murmur3_init(ctx);
for (i = 0; i < 40*1024; i++)
av_murmur3_update(ctx, in, 512*1024);
av_murmur3_final(ctx, hash_result);
av_free(in);
return hash_result[0];
#endif
}

@ -153,40 +153,3 @@ void av_murmur3_final(AVMurMur3 *c, uint8_t dst[16])
AV_WL64(dst, h1);
AV_WL64(dst + 8, h2);
}
#ifdef TEST
int main(void)
{
int i;
uint8_t hash_result[16] = {0};
AVMurMur3 *ctx = av_murmur3_alloc();
#if 1
uint8_t in[256] = {0};
uint8_t *hashes = av_mallocz(256 * 16);
for (i = 0; i < 256; i++)
{
in[i] = i;
av_murmur3_init_seeded(ctx, 256 - i);
// Note: this actually tests hashing 0 bytes
av_murmur3_update(ctx, in, i);
av_murmur3_final(ctx, hashes + 16 * i);
}
av_murmur3_init_seeded(ctx, 0);
av_murmur3_update(ctx, hashes, 256 * 16);
av_murmur3_final(ctx, hash_result);
av_free(hashes);
av_freep(&ctx);
printf("result: 0x%"PRIx64" 0x%"PRIx64"\n", AV_RL64(hash_result), AV_RL64(hash_result + 8));
// official reference value is 32 bit
return AV_RL32(hash_result) != 0x6384ba69;
#else
uint8_t *in = av_mallocz(512*1024);
av_murmur3_init(ctx);
for (i = 0; i < 40*1024; i++)
av_murmur3_update(ctx, in, 512*1024);
av_murmur3_final(ctx, hash_result);
av_free(in);
return hash_result[0];
#endif
}
#endif

@ -0,0 +1,312 @@
/*
* 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 <limits.h>
#include <stdio.h>
#include "common.h"
#include "channel_layout.h"
#include "error.h"
#include "log.h"
#include "mem.h"
#include "rational.h"
#include "opt.h"
#include "pixdesc.h"
typedef struct TestContext {
const AVClass *class;
int num;
int toggle;
char *string;
int flags;
AVRational rational;
AVRational video_rate;
int w, h;
enum AVPixelFormat pix_fmt;
enum AVSampleFormat sample_fmt;
int64_t duration;
uint8_t color[4];
int64_t channel_layout;
void *binary;
int binary_size;
void *binary1;
int binary_size1;
void *binary2;
int binary_size2;
int64_t num64;
float flt;
double dbl;
char *escape;
int bool1;
int bool2;
int bool3;
} TestContext;
#define OFFSET(x) offsetof(TestContext, x)
#define TEST_FLAG_COOL 01
#define TEST_FLAG_LAME 02
#define TEST_FLAG_MU 04
static const AVOption test_options[]= {
{"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, 1 },
{"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, 1 },
{"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, 10, 1 },
{"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { .str = "default" }, CHAR_MIN, CHAR_MAX, 1 },
{"escape", "set escape str", OFFSET(escape), AV_OPT_TYPE_STRING, { .str = "\\=," }, CHAR_MIN, CHAR_MAX, 1 },
{"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 1 }, 0, INT_MAX, 1, "flags" },
{"cool", "set cool flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 1, "flags" },
{"lame", "set lame flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 1, "flags" },
{"mu", "set mu flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 1, "flags" },
{"size", "set size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, { .str="200x300" }, 0, 0, 1 },
{"pix_fmt", "set pixfmt", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, { .i64 = AV_PIX_FMT_0BGR }, -1, INT_MAX, 1 },
{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, { .i64 = AV_SAMPLE_FMT_S16 }, -1, INT_MAX, 1 },
{"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, 0, 1 },
{"duration", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 1000 }, 0, INT64_MAX, 1 },
{"color", "set color", OFFSET(color), AV_OPT_TYPE_COLOR, { .str = "pink" }, 0, 0, 1 },
{"cl", "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, { .i64 = AV_CH_LAYOUT_HEXAGONAL }, 0, INT64_MAX, 1 },
{"bin", "set binary value", OFFSET(binary), AV_OPT_TYPE_BINARY, { .str="62696e00" }, 0, 0, 1 },
{"bin1", "set binary value", OFFSET(binary1), AV_OPT_TYPE_BINARY, { .str=NULL }, 0, 0, 1 },
{"bin2", "set binary value", OFFSET(binary2), AV_OPT_TYPE_BINARY, { .str="" }, 0, 0, 1 },
{"num64", "set num 64bit", OFFSET(num64), AV_OPT_TYPE_INT64, { .i64 = 1 }, 0, 100, 1 },
{"flt", "set float", OFFSET(flt), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 / 3 }, 0, 100, 1 },
{"dbl", "set double", OFFSET(dbl), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 / 3 }, 0, 100, 1 },
{"bool1", "set boolean value", OFFSET(bool1), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, 1 },
{"bool2", "set boolean value", OFFSET(bool2), AV_OPT_TYPE_BOOL, { .i64 = 1 }, -1, 1, 1 },
{"bool3", "set boolean value", OFFSET(bool3), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 1 },
{ NULL },
};
static const char *test_get_name(void *ctx)
{
return "test";
}
static const AVClass test_class = {
"TestContext",
test_get_name,
test_options
};
static void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
{
vfprintf(stdout, fmt, vl);
}
int main(void)
{
int i;
av_log_set_level(AV_LOG_DEBUG);
av_log_set_callback(log_callback_help);
printf("Testing default values\n");
{
TestContext test_ctx = { 0 };
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
printf("num=%d\n", test_ctx.num);
printf("toggle=%d\n", test_ctx.toggle);
printf("string=%s\n", test_ctx.string);
printf("escape=%s\n", test_ctx.escape);
printf("flags=%d\n", test_ctx.flags);
printf("rational=%d/%d\n", test_ctx.rational.num, test_ctx.rational.den);
printf("video_rate=%d/%d\n", test_ctx.video_rate.num, test_ctx.video_rate.den);
printf("width=%d height=%d\n", test_ctx.w, test_ctx.h);
printf("pix_fmt=%s\n", av_get_pix_fmt_name(test_ctx.pix_fmt));
printf("sample_fmt=%s\n", av_get_sample_fmt_name(test_ctx.sample_fmt));
printf("duration=%"PRId64"\n", test_ctx.duration);
printf("color=%d %d %d %d\n", test_ctx.color[0], test_ctx.color[1], test_ctx.color[2], test_ctx.color[3]);
printf("channel_layout=%"PRId64"=%"PRId64"\n", test_ctx.channel_layout, (int64_t)AV_CH_LAYOUT_HEXAGONAL);
if (test_ctx.binary)
printf("binary=%x %x %x %x\n", ((uint8_t*)test_ctx.binary)[0], ((uint8_t*)test_ctx.binary)[1], ((uint8_t*)test_ctx.binary)[2], ((uint8_t*)test_ctx.binary)[3]);
printf("binary_size=%d\n", test_ctx.binary_size);
printf("num64=%"PRId64"\n", test_ctx.num64);
printf("flt=%.6f\n", test_ctx.flt);
printf("dbl=%.6f\n", test_ctx.dbl);
av_opt_show2(&test_ctx, NULL, -1, 0);
av_opt_free(&test_ctx);
}
printf("\nTesting av_opt_is_set_to_default()\n");
{
int ret;
TestContext test_ctx = { 0 };
const AVOption *o = NULL;
test_ctx.class = &test_class;
av_log_set_level(AV_LOG_QUIET);
while (o = av_opt_next(&test_ctx, o)) {
ret = av_opt_is_set_to_default_by_name(&test_ctx, o->name, 0);
printf("name:%10s default:%d error:%s\n", o->name, !!ret, ret < 0 ? av_err2str(ret) : "");
}
av_opt_set_defaults(&test_ctx);
while (o = av_opt_next(&test_ctx, o)) {
ret = av_opt_is_set_to_default_by_name(&test_ctx, o->name, 0);
printf("name:%10s default:%d error:%s\n", o->name, !!ret, ret < 0 ? av_err2str(ret) : "");
}
av_opt_free(&test_ctx);
}
printf("\nTest av_opt_serialize()\n");
{
TestContext test_ctx = { 0 };
char *buf;
test_ctx.class = &test_class;
av_log_set_level(AV_LOG_QUIET);
av_opt_set_defaults(&test_ctx);
if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
printf("%s\n", buf);
av_opt_free(&test_ctx);
memset(&test_ctx, 0, sizeof(test_ctx));
test_ctx.class = &test_class;
av_set_options_string(&test_ctx, buf, "=", ",");
av_free(buf);
if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
printf("%s\n", buf);
av_free(buf);
}
}
av_opt_free(&test_ctx);
}
printf("\nTesting av_set_options_string()\n");
{
TestContext test_ctx = { 0 };
static const char * const options[] = {
"",
":",
"=",
"foo=:",
":=foo",
"=foo",
"foo=",
"foo",
"foo=val",
"foo==val",
"toggle=:",
"string=:",
"toggle=1 : foo",
"toggle=100",
"toggle==1",
"flags=+mu-lame : num=42: toggle=0",
"num=42 : string=blahblah",
"rational=0 : rational=1/2 : rational=1/-1",
"rational=-1/0",
"size=1024x768",
"size=pal",
"size=bogus",
"pix_fmt=yuv420p",
"pix_fmt=2",
"pix_fmt=bogus",
"sample_fmt=s16",
"sample_fmt=2",
"sample_fmt=bogus",
"video_rate=pal",
"video_rate=25",
"video_rate=30000/1001",
"video_rate=30/1.001",
"video_rate=bogus",
"duration=bogus",
"duration=123.45",
"duration=1\\:23\\:45.67",
"color=blue",
"color=0x223300",
"color=0x42FF07AA",
"cl=stereo+downmix",
"cl=foo",
"bin=boguss",
"bin=111",
"bin=ffff",
"num64=bogus",
"num64=44",
"num64=44.4",
"num64=-1",
"num64=101",
"flt=bogus",
"flt=2",
"flt=2.2",
"flt=-1",
"flt=101",
"dbl=bogus",
"dbl=2",
"dbl=2.2",
"dbl=-1",
"dbl=101",
"bool1=true",
"bool2=auto",
};
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
av_log_set_level(AV_LOG_QUIET);
for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
int silence_log = !strcmp(options[i], "rational=-1/0"); // inf formating differs between platforms
av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
if (silence_log)
av_log_set_callback(NULL);
if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
printf("Error '%s'\n", options[i]);
else
printf("OK '%s'\n", options[i]);
av_log_set_callback(log_callback_help);
}
av_opt_free(&test_ctx);
}
printf("\nTesting av_opt_set_from_string()\n");
{
TestContext test_ctx = { 0 };
static const char * const options[] = {
"",
"5",
"5:hello",
"5:hello:size=pal",
"5:size=pal:hello",
":",
"=",
" 5 : hello : size = pal ",
"a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
};
static const char * const shorthand[] = { "num", "string", NULL };
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
av_log_set_level(AV_LOG_QUIET);
for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
if (av_opt_set_from_string(&test_ctx, options[i], shorthand, "=", ":") < 0)
printf("Error '%s'\n", options[i]);
else
printf("OK '%s'\n", options[i]);
}
av_opt_free(&test_ctx);
}
return 0;
}

@ -1987,290 +1987,3 @@ int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
av_bprint_finalize(&bprint, buffer);
return 0;
}
#ifdef TEST
typedef struct TestContext {
const AVClass *class;
int num;
int toggle;
char *string;
int flags;
AVRational rational;
AVRational video_rate;
int w, h;
enum AVPixelFormat pix_fmt;
enum AVSampleFormat sample_fmt;
int64_t duration;
uint8_t color[4];
int64_t channel_layout;
void *binary;
int binary_size;
void *binary1;
int binary_size1;
void *binary2;
int binary_size2;
int64_t num64;
float flt;
double dbl;
char *escape;
int bool1;
int bool2;
int bool3;
} TestContext;
#define OFFSET(x) offsetof(TestContext, x)
#define TEST_FLAG_COOL 01
#define TEST_FLAG_LAME 02
#define TEST_FLAG_MU 04
static const AVOption test_options[]= {
{"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, 1 },
{"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, 1 },
{"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, 10, 1 },
{"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { .str = "default" }, CHAR_MIN, CHAR_MAX, 1 },
{"escape", "set escape str", OFFSET(escape), AV_OPT_TYPE_STRING, { .str = "\\=," }, CHAR_MIN, CHAR_MAX, 1 },
{"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 1 }, 0, INT_MAX, 1, "flags" },
{"cool", "set cool flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 1, "flags" },
{"lame", "set lame flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 1, "flags" },
{"mu", "set mu flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 1, "flags" },
{"size", "set size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, { .str="200x300" }, 0, 0, 1 },
{"pix_fmt", "set pixfmt", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, { .i64 = AV_PIX_FMT_0BGR }, -1, INT_MAX, 1 },
{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, { .i64 = AV_SAMPLE_FMT_S16 }, -1, INT_MAX, 1 },
{"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, 0, 1 },
{"duration", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 1000 }, 0, INT64_MAX, 1 },
{"color", "set color", OFFSET(color), AV_OPT_TYPE_COLOR, { .str = "pink" }, 0, 0, 1 },
{"cl", "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, { .i64 = AV_CH_LAYOUT_HEXAGONAL }, 0, INT64_MAX, 1 },
{"bin", "set binary value", OFFSET(binary), AV_OPT_TYPE_BINARY, { .str="62696e00" }, 0, 0, 1 },
{"bin1", "set binary value", OFFSET(binary1), AV_OPT_TYPE_BINARY, { .str=NULL }, 0, 0, 1 },
{"bin2", "set binary value", OFFSET(binary2), AV_OPT_TYPE_BINARY, { .str="" }, 0, 0, 1 },
{"num64", "set num 64bit", OFFSET(num64), AV_OPT_TYPE_INT64, { .i64 = 1 }, 0, 100, 1 },
{"flt", "set float", OFFSET(flt), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 / 3 }, 0, 100, 1 },
{"dbl", "set double", OFFSET(dbl), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 / 3 }, 0, 100, 1 },
{"bool1", "set boolean value", OFFSET(bool1), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, 1 },
{"bool2", "set boolean value", OFFSET(bool2), AV_OPT_TYPE_BOOL, { .i64 = 1 }, -1, 1, 1 },
{"bool3", "set boolean value", OFFSET(bool3), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 1 },
{ NULL },
};
static const char *test_get_name(void *ctx)
{
return "test";
}
static const AVClass test_class = {
"TestContext",
test_get_name,
test_options
};
static void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
{
vfprintf(stdout, fmt, vl);
}
int main(void)
{
int i;
av_log_set_level(AV_LOG_DEBUG);
av_log_set_callback(log_callback_help);
printf("Testing default values\n");
{
TestContext test_ctx = { 0 };
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
printf("num=%d\n", test_ctx.num);
printf("toggle=%d\n", test_ctx.toggle);
printf("string=%s\n", test_ctx.string);
printf("escape=%s\n", test_ctx.escape);
printf("flags=%d\n", test_ctx.flags);
printf("rational=%d/%d\n", test_ctx.rational.num, test_ctx.rational.den);
printf("video_rate=%d/%d\n", test_ctx.video_rate.num, test_ctx.video_rate.den);
printf("width=%d height=%d\n", test_ctx.w, test_ctx.h);
printf("pix_fmt=%s\n", av_get_pix_fmt_name(test_ctx.pix_fmt));
printf("sample_fmt=%s\n", av_get_sample_fmt_name(test_ctx.sample_fmt));
printf("duration=%"PRId64"\n", test_ctx.duration);
printf("color=%d %d %d %d\n", test_ctx.color[0], test_ctx.color[1], test_ctx.color[2], test_ctx.color[3]);
printf("channel_layout=%"PRId64"=%"PRId64"\n", test_ctx.channel_layout, (int64_t)AV_CH_LAYOUT_HEXAGONAL);
if (test_ctx.binary)
printf("binary=%x %x %x %x\n", ((uint8_t*)test_ctx.binary)[0], ((uint8_t*)test_ctx.binary)[1], ((uint8_t*)test_ctx.binary)[2], ((uint8_t*)test_ctx.binary)[3]);
printf("binary_size=%d\n", test_ctx.binary_size);
printf("num64=%"PRId64"\n", test_ctx.num64);
printf("flt=%.6f\n", test_ctx.flt);
printf("dbl=%.6f\n", test_ctx.dbl);
av_opt_show2(&test_ctx, NULL, -1, 0);
av_opt_free(&test_ctx);
}
printf("\nTesting av_opt_is_set_to_default()\n");
{
int ret;
TestContext test_ctx = { 0 };
const AVOption *o = NULL;
test_ctx.class = &test_class;
av_log_set_level(AV_LOG_QUIET);
while (o = av_opt_next(&test_ctx, o)) {
ret = av_opt_is_set_to_default_by_name(&test_ctx, o->name, 0);
printf("name:%10s default:%d error:%s\n", o->name, !!ret, ret < 0 ? av_err2str(ret) : "");
}
av_opt_set_defaults(&test_ctx);
while (o = av_opt_next(&test_ctx, o)) {
ret = av_opt_is_set_to_default_by_name(&test_ctx, o->name, 0);
printf("name:%10s default:%d error:%s\n", o->name, !!ret, ret < 0 ? av_err2str(ret) : "");
}
av_opt_free(&test_ctx);
}
printf("\nTest av_opt_serialize()\n");
{
TestContext test_ctx = { 0 };
char *buf;
test_ctx.class = &test_class;
av_log_set_level(AV_LOG_QUIET);
av_opt_set_defaults(&test_ctx);
if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
printf("%s\n", buf);
av_opt_free(&test_ctx);
memset(&test_ctx, 0, sizeof(test_ctx));
test_ctx.class = &test_class;
av_set_options_string(&test_ctx, buf, "=", ",");
av_free(buf);
if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
printf("%s\n", buf);
av_free(buf);
}
}
av_opt_free(&test_ctx);
}
printf("\nTesting av_set_options_string()\n");
{
TestContext test_ctx = { 0 };
static const char * const options[] = {
"",
":",
"=",
"foo=:",
":=foo",
"=foo",
"foo=",
"foo",
"foo=val",
"foo==val",
"toggle=:",
"string=:",
"toggle=1 : foo",
"toggle=100",
"toggle==1",
"flags=+mu-lame : num=42: toggle=0",
"num=42 : string=blahblah",
"rational=0 : rational=1/2 : rational=1/-1",
"rational=-1/0",
"size=1024x768",
"size=pal",
"size=bogus",
"pix_fmt=yuv420p",
"pix_fmt=2",
"pix_fmt=bogus",
"sample_fmt=s16",
"sample_fmt=2",
"sample_fmt=bogus",
"video_rate=pal",
"video_rate=25",
"video_rate=30000/1001",
"video_rate=30/1.001",
"video_rate=bogus",
"duration=bogus",
"duration=123.45",
"duration=1\\:23\\:45.67",
"color=blue",
"color=0x223300",
"color=0x42FF07AA",
"cl=stereo+downmix",
"cl=foo",
"bin=boguss",
"bin=111",
"bin=ffff",
"num64=bogus",
"num64=44",
"num64=44.4",
"num64=-1",
"num64=101",
"flt=bogus",
"flt=2",
"flt=2.2",
"flt=-1",
"flt=101",
"dbl=bogus",
"dbl=2",
"dbl=2.2",
"dbl=-1",
"dbl=101",
"bool1=true",
"bool2=auto",
};
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
av_log_set_level(AV_LOG_QUIET);
for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
int silence_log = !strcmp(options[i], "rational=-1/0"); // inf formating differs between platforms
av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
if (silence_log)
av_log_set_callback(NULL);
if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
printf("Error '%s'\n", options[i]);
else
printf("OK '%s'\n", options[i]);
av_log_set_callback(log_callback_help);
}
av_opt_free(&test_ctx);
}
printf("\nTesting av_opt_set_from_string()\n");
{
TestContext test_ctx = { 0 };
static const char * const options[] = {
"",
"5",
"5:hello",
"5:hello:size=pal",
"5:size=pal:hello",
":",
"=",
" 5 : hello : size = pal ",
"a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
};
static const char * const shorthand[] = { "num", "string", NULL };
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
av_log_set_level(AV_LOG_QUIET);
for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
if (av_opt_set_from_string(&test_ctx, options[i], shorthand, "=", ":") < 0)
printf("Error '%s'\n", options[i]);
else
printf("OK '%s'\n", options[i]);
}
av_opt_free(&test_ctx);
}
return 0;
}
#endif

@ -0,0 +1,260 @@
/*
* 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 TEST
#include "parseutils.c"
#include <stdint.h>
#include <stdio.h>
#include "common.h"
#include "log.h"
#include "rational.h"
static uint32_t randomv = MKTAG('L','A','V','U');
static uint32_t av_get_random_seed_deterministic(void)
{
return randomv = randomv * 1664525 + 1013904223;
}
static void test_av_parse_video_rate(void)
{
int i;
static const char *const rates[] = {
"-inf",
"inf",
"nan",
"123/0",
"-123 / 0",
"",
"/",
" 123 / 321",
"foo/foo",
"foo/1",
"1/foo",
"0/0",
"/0",
"1/",
"1",
"0",
"-123/123",
"-foo",
"123.23",
".23",
"-.23",
"-0.234",
"-0.0000001",
" 21332.2324 ",
" -21332.2324 ",
};
for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
int ret;
AVRational q = { 0, 0 };
ret = av_parse_video_rate(&q, rates[i]);
printf("'%s' -> %d/%d %s\n",
rates[i], q.num, q.den, ret ? "ERROR" : "OK");
}
}
static void test_av_parse_color(void)
{
int i;
uint8_t rgba[4];
static const char *const color_names[] = {
"bikeshed",
"RaNdOm",
"foo",
"red",
"Red ",
"RED",
"Violet",
"Yellow",
"Red",
"0x000000",
"0x0000000",
"0xff000000",
"0x3e34ff",
"0x3e34ffaa",
"0xffXXee",
"0xfoobar",
"0xffffeeeeeeee",
"#ff0000",
"#ffXX00",
"ff0000",
"ffXX00",
"red@foo",
"random@10",
"0xff0000@1.0",
"red@",
"red@0xfff",
"red@0xf",
"red@2",
"red@0.1",
"red@-1",
"red@0.5",
"red@1.0",
"red@256",
"red@10foo",
"red@-1.0",
"red@-0.0",
};
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
else
printf("%s -> error\n", color_names[i]);
}
}
static void test_av_small_strptime(void)
{
int i;
struct tm tm = { 0 };
struct fmt_timespec_entry {
const char *fmt, *timespec;
} fmt_timespec_entries[] = {
{ "%Y-%m-%d", "2012-12-21" },
{ "%Y - %m - %d", "2012-12-21" },
{ "%Y-%m-%d %H:%M:%S", "2012-12-21 20:12:21" },
{ " %Y - %m - %d %H : %M : %S", " 2012 - 12 - 21 20 : 12 : 21" },
};
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < FF_ARRAY_ELEMS(fmt_timespec_entries); i++) {
char *p;
struct fmt_timespec_entry *e = &fmt_timespec_entries[i];
printf("fmt:'%s' spec:'%s' -> ", e->fmt, e->timespec);
p = av_small_strptime(e->timespec, e->fmt, &tm);
if (p) {
printf("%04d-%02d-%2d %02d:%02d:%02d\n",
1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
} else {
printf("error\n");
}
}
}
static void test_av_parse_time(void)
{
int i;
int64_t tv;
time_t tvi;
struct tm *tm;
static char tzstr[] = "TZ=CET-1";
static const char * const time_string[] = {
"now",
"12:35:46",
"2000-12-20 0:02:47.5z",
"2012 - 02-22 17:44:07",
"2000-12-20T010247.6",
"2000-12-12 1:35:46+05:30",
"2002-12-12 22:30:40-02",
};
static const char * const duration_string[] = {
"2:34:56.79",
"-1:23:45.67",
"42.1729",
"-1729.42",
"12:34",
};
av_log_set_level(AV_LOG_DEBUG);
putenv(tzstr);
printf("(now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1)\n");
for (i = 0; i < FF_ARRAY_ELEMS(time_string); i++) {
printf("%-24s -> ", time_string[i]);
if (av_parse_time(&tv, time_string[i], 0)) {
printf("error\n");
} else {
tvi = tv / 1000000;
tm = gmtime(&tvi);
printf("%14"PRIi64".%06d = %04d-%02d-%02dT%02d:%02d:%02dZ\n",
tv / 1000000, (int)(tv % 1000000),
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
}
for (i = 0; i < FF_ARRAY_ELEMS(duration_string); i++) {
printf("%-24s -> ", duration_string[i]);
if (av_parse_time(&tv, duration_string[i], 1)) {
printf("error\n");
} else {
printf("%+21"PRIi64"\n", tv);
}
}
}
static void test_av_get_known_color_name(void)
{
int i;
const uint8_t *rgba;
const char *color;
for (i = 0; i < FF_ARRAY_ELEMS(color_table); ++i) {
color = av_get_known_color_name(i, &rgba);
if (color)
printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
color, rgba[0], rgba[1], rgba[2], rgba[3]);
else
printf("Color ID: %d not found\n", i);
}
}
static void test_av_find_info_tag(void)
{
static const char args[] = "?tag1=val1&tag2=val2&tag3=val3&tag41=value 41&tag42=random1";
static const char *tags[] = {"tag1", "tag2", "tag3", "tag4", "tag41", "41", "random1"};
char buff[16];
int i;
for (i = 0; i < FF_ARRAY_ELEMS(tags); ++i) {
if (av_find_info_tag(buff, sizeof(buff), tags[i], args))
printf("%d. %s found: %s\n", i, tags[i], buff);
else
printf("%d. %s not found\n", i, tags[i]);
}
}
int main(void)
{
printf("Testing av_parse_video_rate()\n");
test_av_parse_video_rate();
printf("\nTesting av_parse_color()\n");
test_av_parse_color();
printf("\nTesting av_small_strptime()\n");
test_av_small_strptime();
printf("\nTesting av_parse_time()\n");
test_av_parse_time();
printf("\nTesting av_get_known_color_name()\n");
test_av_get_known_color_name();
printf("\nTesting av_find_info_tag()\n");
test_av_find_info_tag();
return 0;
}

@ -739,240 +739,3 @@ int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info
}
return 0;
}
#ifdef TEST
static uint32_t randomv = MKTAG('L','A','V','U');
static uint32_t av_get_random_seed_deterministic(void)
{
return randomv = randomv * 1664525 + 1013904223;
}
static void test_av_parse_video_rate(void)
{
int i;
static const char *const rates[] = {
"-inf",
"inf",
"nan",
"123/0",
"-123 / 0",
"",
"/",
" 123 / 321",
"foo/foo",
"foo/1",
"1/foo",
"0/0",
"/0",
"1/",
"1",
"0",
"-123/123",
"-foo",
"123.23",
".23",
"-.23",
"-0.234",
"-0.0000001",
" 21332.2324 ",
" -21332.2324 ",
};
for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
int ret;
AVRational q = { 0, 0 };
ret = av_parse_video_rate(&q, rates[i]);
printf("'%s' -> %d/%d %s\n",
rates[i], q.num, q.den, ret ? "ERROR" : "OK");
}
}
static void test_av_parse_color(void)
{
int i;
uint8_t rgba[4];
static const char *const color_names[] = {
"bikeshed",
"RaNdOm",
"foo",
"red",
"Red ",
"RED",
"Violet",
"Yellow",
"Red",
"0x000000",
"0x0000000",
"0xff000000",
"0x3e34ff",
"0x3e34ffaa",
"0xffXXee",
"0xfoobar",
"0xffffeeeeeeee",
"#ff0000",
"#ffXX00",
"ff0000",
"ffXX00",
"red@foo",
"random@10",
"0xff0000@1.0",
"red@",
"red@0xfff",
"red@0xf",
"red@2",
"red@0.1",
"red@-1",
"red@0.5",
"red@1.0",
"red@256",
"red@10foo",
"red@-1.0",
"red@-0.0",
};
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
else
printf("%s -> error\n", color_names[i]);
}
}
static void test_av_small_strptime(void)
{
int i;
struct tm tm = { 0 };
struct fmt_timespec_entry {
const char *fmt, *timespec;
} fmt_timespec_entries[] = {
{ "%Y-%m-%d", "2012-12-21" },
{ "%Y - %m - %d", "2012-12-21" },
{ "%Y-%m-%d %H:%M:%S", "2012-12-21 20:12:21" },
{ " %Y - %m - %d %H : %M : %S", " 2012 - 12 - 21 20 : 12 : 21" },
};
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < FF_ARRAY_ELEMS(fmt_timespec_entries); i++) {
char *p;
struct fmt_timespec_entry *e = &fmt_timespec_entries[i];
printf("fmt:'%s' spec:'%s' -> ", e->fmt, e->timespec);
p = av_small_strptime(e->timespec, e->fmt, &tm);
if (p) {
printf("%04d-%02d-%2d %02d:%02d:%02d\n",
1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
} else {
printf("error\n");
}
}
}
static void test_av_parse_time(void)
{
int i;
int64_t tv;
time_t tvi;
struct tm *tm;
static char tzstr[] = "TZ=CET-1";
static const char * const time_string[] = {
"now",
"12:35:46",
"2000-12-20 0:02:47.5z",
"2012 - 02-22 17:44:07",
"2000-12-20T010247.6",
"2000-12-12 1:35:46+05:30",
"2002-12-12 22:30:40-02",
};
static const char * const duration_string[] = {
"2:34:56.79",
"-1:23:45.67",
"42.1729",
"-1729.42",
"12:34",
};
av_log_set_level(AV_LOG_DEBUG);
putenv(tzstr);
printf("(now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1)\n");
for (i = 0; i < FF_ARRAY_ELEMS(time_string); i++) {
printf("%-24s -> ", time_string[i]);
if (av_parse_time(&tv, time_string[i], 0)) {
printf("error\n");
} else {
tvi = tv / 1000000;
tm = gmtime(&tvi);
printf("%14"PRIi64".%06d = %04d-%02d-%02dT%02d:%02d:%02dZ\n",
tv / 1000000, (int)(tv % 1000000),
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
}
for (i = 0; i < FF_ARRAY_ELEMS(duration_string); i++) {
printf("%-24s -> ", duration_string[i]);
if (av_parse_time(&tv, duration_string[i], 1)) {
printf("error\n");
} else {
printf("%+21"PRIi64"\n", tv);
}
}
}
static void test_av_get_known_color_name(void)
{
int i;
const uint8_t *rgba;
const char *color;
for (i = 0; i < FF_ARRAY_ELEMS(color_table); ++i) {
color = av_get_known_color_name(i, &rgba);
if (color)
printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
color, rgba[0], rgba[1], rgba[2], rgba[3]);
else
printf("Color ID: %d not found\n", i);
}
}
static void test_av_find_info_tag(void)
{
static const char args[] = "?tag1=val1&tag2=val2&tag3=val3&tag41=value 41&tag42=random1";
static const char *tags[] = {"tag1", "tag2", "tag3", "tag4", "tag41", "41", "random1"};
char buff[16];
int i;
for (i = 0; i < FF_ARRAY_ELEMS(tags); ++i) {
if (av_find_info_tag(buff, sizeof(buff), tags[i], args))
printf("%d. %s found: %s\n", i, tags[i], buff);
else
printf("%d. %s not found\n", i, tags[i]);
}
}
int main(void)
{
printf("Testing av_parse_video_rate()\n");
test_av_parse_video_rate();
printf("\nTesting av_parse_color()\n");
test_av_parse_color();
printf("\nTesting av_small_strptime()\n");
test_av_small_strptime();
printf("\nTesting av_parse_time()\n");
test_av_parse_time();
printf("\nTesting av_get_known_color_name()\n");
test_av_get_known_color_name();
printf("\nTesting av_find_info_tag()\n");
test_av_find_info_tag();
return 0;
}
#endif /* TEST */

@ -0,0 +1,102 @@
/*
* principal component analysis (PCA)
* 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 "pca.c"
#include "lfg.h"
#undef printf
#include <stdio.h>
#include <stdlib.h>
int main(void){
PCA *pca;
int i, j, k;
#define LEN 8
double eigenvector[LEN*LEN];
double eigenvalue[LEN];
AVLFG prng;
av_lfg_init(&prng, 1);
pca= ff_pca_init(LEN);
for(i=0; i<9000000; i++){
double v[2*LEN+100];
double sum=0;
int pos = av_lfg_get(&prng) % LEN;
int v2 = av_lfg_get(&prng) % 101 - 50;
v[0] = av_lfg_get(&prng) % 101 - 50;
for(j=1; j<8; j++){
if(j<=pos) v[j]= v[0];
else v[j]= v2;
sum += v[j];
}
/* for(j=0; j<LEN; j++){
v[j] -= v[pos];
}*/
// sum += av_lfg_get(&prng) % 10;
/* for(j=0; j<LEN; j++){
v[j] -= sum/LEN;
}*/
// lbt1(v+100,v+100,LEN);
ff_pca_add(pca, v);
}
ff_pca(pca, eigenvector, eigenvalue);
for(i=0; i<LEN; i++){
pca->count= 1;
pca->mean[i]= 0;
// (0.5^|x|)^2 = 0.5^2|x| = 0.25^|x|
// pca.covariance[i + i*LEN]= pow(0.5, fabs
for(j=i; j<LEN; j++){
printf("%f ", pca->covariance[i + j*LEN]);
}
printf("\n");
}
for(i=0; i<LEN; i++){
double v[LEN];
double error=0;
memset(v, 0, sizeof(v));
for(j=0; j<LEN; j++){
for(k=0; k<LEN; k++){
v[j] += pca->covariance[FFMIN(k,j) + FFMAX(k,j)*LEN] * eigenvector[i + k*LEN];
}
v[j] /= eigenvalue[i];
error += fabs(v[j] - eigenvector[i + j*LEN]);
}
printf("%f ", error);
}
printf("\n");
for(i=0; i<LEN; i++){
for(j=0; j<LEN; j++){
printf("%9.6f ", eigenvector[i + j*LEN]);
}
printf(" %9.1f %f\n", eigenvalue[i], eigenvalue[i]/eigenvalue[0]);
}
return 0;
}

@ -171,86 +171,3 @@ int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){
return -1;
}
#ifdef TEST
#undef printf
#include <stdio.h>
#include <stdlib.h>
#include "lfg.h"
int main(void){
PCA *pca;
int i, j, k;
#define LEN 8
double eigenvector[LEN*LEN];
double eigenvalue[LEN];
AVLFG prng;
av_lfg_init(&prng, 1);
pca= ff_pca_init(LEN);
for(i=0; i<9000000; i++){
double v[2*LEN+100];
double sum=0;
int pos = av_lfg_get(&prng) % LEN;
int v2 = av_lfg_get(&prng) % 101 - 50;
v[0] = av_lfg_get(&prng) % 101 - 50;
for(j=1; j<8; j++){
if(j<=pos) v[j]= v[0];
else v[j]= v2;
sum += v[j];
}
/* for(j=0; j<LEN; j++){
v[j] -= v[pos];
}*/
// sum += av_lfg_get(&prng) % 10;
/* for(j=0; j<LEN; j++){
v[j] -= sum/LEN;
}*/
// lbt1(v+100,v+100,LEN);
ff_pca_add(pca, v);
}
ff_pca(pca, eigenvector, eigenvalue);
for(i=0; i<LEN; i++){
pca->count= 1;
pca->mean[i]= 0;
// (0.5^|x|)^2 = 0.5^2|x| = 0.25^|x|
// pca.covariance[i + i*LEN]= pow(0.5, fabs
for(j=i; j<LEN; j++){
printf("%f ", pca->covariance[i + j*LEN]);
}
printf("\n");
}
for(i=0; i<LEN; i++){
double v[LEN];
double error=0;
memset(v, 0, sizeof(v));
for(j=0; j<LEN; j++){
for(k=0; k<LEN; k++){
v[j] += pca->covariance[FFMIN(k,j) + FFMAX(k,j)*LEN] * eigenvector[i + k*LEN];
}
v[j] /= eigenvalue[i];
error += fabs(v[j] - eigenvector[i + j*LEN]);
}
printf("%f ", error);
}
printf("\n");
for(i=0; i<LEN; i++){
for(j=0; j<LEN; j++){
printf("%9.6f ", eigenvector[i + j*LEN]);
}
printf(" %9.1f %f\n", eigenvalue[i], eigenvalue[i]/eigenvalue[0]);
}
return 0;
}
#endif

@ -0,0 +1,46 @@
/*
* pixel format descriptor
* Copyright (c) 2009 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 "pixdesc.c"
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 avg_bpp:%d colortype:%d\n", desc->name, av_get_padded_bits_per_pixel(desc), get_color_type(desc));
if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) != (desc->nb_components != 2 && desc->nb_components != 4)) {
av_log(NULL, AV_LOG_ERROR, "Alpha flag mismatch\n");
err = 1;
}
}
return err;
}

@ -2532,32 +2532,3 @@ const char *av_chroma_location_name(enum AVChromaLocation location)
return (unsigned) location < AVCHROMA_LOC_NB ?
chroma_location_names[location] : NULL;
}
#ifdef TEST
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 avg_bpp:%d colortype:%d\n", desc->name, av_get_padded_bits_per_pixel(desc), get_color_type(desc));
if ((!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) != (desc->nb_components != 2 && desc->nb_components != 4)) {
av_log(NULL, AV_LOG_ERROR, "Alpha flag mismatch\n");
err = 1;
}
}
return err;
}
#endif

@ -0,0 +1,152 @@
/*
* 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 "pixelutils.c"
#define W1 320
#define H1 240
#define W2 640
#define H2 480
static int run_single_test(const char *test,
const uint8_t *block1, ptrdiff_t stride1,
const uint8_t *block2, ptrdiff_t stride2,
int align, int n)
{
int out, ref;
av_pixelutils_sad_fn f_ref = sad_c[n - 1];
av_pixelutils_sad_fn f_out = av_pixelutils_get_sad_fn(n, n, align, NULL);
switch (align) {
case 0: block1++; block2++; break;
case 1: block2++; break;
case 2: break;
}
out = f_out(block1, stride1, block2, stride2);
ref = f_ref(block1, stride1, block2, stride2);
printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
out == ref ? "OK" : "FAIL",
align ? 'A' : 'U', align == 2 ? 'A' : 'U',
test, 1<<n, 1<<n, out, ref);
return out != ref;
}
static int run_test(const char *test,
const uint8_t *b1, const uint8_t *b2)
{
int i, a, ret = 0;
for (a = 0; a < 3; a++) {
const uint8_t *block1 = b1;
const uint8_t *block2 = b2;
switch (a) {
case 0: block1++; block2++; break;
case 1: block2++; break;
case 2: break;
}
for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) {
int r = run_single_test(test, b1, W1, b2, W2, a, i);
if (r)
ret = r;
}
}
return ret;
}
int main(void)
{
int i, align, ret;
uint8_t *buf1 = av_malloc(W1*H1);
uint8_t *buf2 = av_malloc(W2*H2);
uint32_t state = 0;
if (!buf1 || !buf2) {
fprintf(stderr, "malloc failure\n");
ret = 1;
goto end;
}
ff_check_pixfmt_descriptors();
#define RANDOM_INIT(buf, size) do { \
int k; \
for (k = 0; k < size; k++) { \
state = state * 1664525 + 1013904223; \
buf[k] = state>>24; \
} \
} while (0)
/* Normal test with different strides */
RANDOM_INIT(buf1, W1*H1);
RANDOM_INIT(buf2, W2*H2);
ret = run_test("random", buf1, buf2);
if (ret < 0)
goto end;
/* Check for maximum SAD */
memset(buf1, 0xff, W1*H1);
memset(buf2, 0x00, W2*H2);
ret = run_test("max", buf1, buf2);
if (ret < 0)
goto end;
/* Check for minimum SAD */
memset(buf1, 0x90, W1*H1);
memset(buf2, 0x90, W2*H2);
ret = run_test("min", buf1, buf2);
if (ret < 0)
goto end;
/* Exact buffer sizes, to check for overreads */
for (i = 1; i <= 4; i++) {
for (align = 0; align < 3; align++) {
int size1, size2;
av_freep(&buf1);
av_freep(&buf2);
size1 = size2 = 1 << (i << 1);
switch (align) {
case 0: size1++; size2++; break;
case 1: size2++; break;
case 2: break;
}
buf1 = av_malloc(size1);
buf2 = av_malloc(size2);
if (!buf1 || !buf2) {
fprintf(stderr, "malloc failure\n");
ret = 1;
goto end;
}
RANDOM_INIT(buf1, size1);
RANDOM_INIT(buf2, size2);
ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i);
if (ret < 0)
goto end;
}
}
end:
av_free(buf1);
av_free(buf2);
return ret;
}

@ -85,138 +85,3 @@ av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligne
return sad[w_bits - 1];
#endif
}
#ifdef TEST
#define W1 320
#define H1 240
#define W2 640
#define H2 480
static int run_single_test(const char *test,
const uint8_t *block1, ptrdiff_t stride1,
const uint8_t *block2, ptrdiff_t stride2,
int align, int n)
{
int out, ref;
av_pixelutils_sad_fn f_ref = sad_c[n - 1];
av_pixelutils_sad_fn f_out = av_pixelutils_get_sad_fn(n, n, align, NULL);
switch (align) {
case 0: block1++; block2++; break;
case 1: block2++; break;
case 2: break;
}
out = f_out(block1, stride1, block2, stride2);
ref = f_ref(block1, stride1, block2, stride2);
printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
out == ref ? "OK" : "FAIL",
align ? 'A' : 'U', align == 2 ? 'A' : 'U',
test, 1<<n, 1<<n, out, ref);
return out != ref;
}
static int run_test(const char *test,
const uint8_t *b1, const uint8_t *b2)
{
int i, a, ret = 0;
for (a = 0; a < 3; a++) {
const uint8_t *block1 = b1;
const uint8_t *block2 = b2;
switch (a) {
case 0: block1++; block2++; break;
case 1: block2++; break;
case 2: break;
}
for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) {
int r = run_single_test(test, b1, W1, b2, W2, a, i);
if (r)
ret = r;
}
}
return ret;
}
int main(void)
{
int i, align, ret;
uint8_t *buf1 = av_malloc(W1*H1);
uint8_t *buf2 = av_malloc(W2*H2);
uint32_t state = 0;
if (!buf1 || !buf2) {
fprintf(stderr, "malloc failure\n");
ret = 1;
goto end;
}
ff_check_pixfmt_descriptors();
#define RANDOM_INIT(buf, size) do { \
int k; \
for (k = 0; k < size; k++) { \
state = state * 1664525 + 1013904223; \
buf[k] = state>>24; \
} \
} while (0)
/* Normal test with different strides */
RANDOM_INIT(buf1, W1*H1);
RANDOM_INIT(buf2, W2*H2);
ret = run_test("random", buf1, buf2);
if (ret < 0)
goto end;
/* Check for maximum SAD */
memset(buf1, 0xff, W1*H1);
memset(buf2, 0x00, W2*H2);
ret = run_test("max", buf1, buf2);
if (ret < 0)
goto end;
/* Check for minimum SAD */
memset(buf1, 0x90, W1*H1);
memset(buf2, 0x90, W2*H2);
ret = run_test("min", buf1, buf2);
if (ret < 0)
goto end;
/* Exact buffer sizes, to check for overreads */
for (i = 1; i <= 4; i++) {
for (align = 0; align < 3; align++) {
int size1, size2;
av_freep(&buf1);
av_freep(&buf2);
size1 = size2 = 1 << (i << 1);
switch (align) {
case 0: size1++; size2++; break;
case 1: size2++; break;
case 2: break;
}
buf1 = av_malloc(size1);
buf2 = av_malloc(size2);
if (!buf1 || !buf2) {
fprintf(stderr, "malloc failure\n");
ret = 1;
goto end;
}
RANDOM_INIT(buf1, size1);
RANDOM_INIT(buf2, size2);
ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i);
if (ret < 0)
goto end;
}
}
end:
av_free(buf1);
av_free(buf2);
return ret;
}
#endif /* TEST */

@ -0,0 +1,46 @@
/*
* Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@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
*/
#define TEST 1
#include "random_seed.c"
#undef printf
#define N 256
#include <stdio.h>
int main(void)
{
int i, j, retry;
uint32_t seeds[N];
for (retry=0; retry<3; retry++){
for (i=0; i<N; i++){
seeds[i] = av_get_random_seed();
for (j=0; j<i; j++)
if (seeds[j] == seeds[i])
goto retry;
}
printf("seeds OK\n");
return 0;
retry:;
}
printf("FAIL at %d with %X\n", j, seeds[j]);
return 1;
}

@ -136,29 +136,3 @@ uint32_t av_get_random_seed(void)
return seed;
return get_generic_seed();
}
#if TEST
#undef printf
#define N 256
#include <stdio.h>
int main(void)
{
int i, j, retry;
uint32_t seeds[N];
for (retry=0; retry<3; retry++){
for (i=0; i<N; i++){
seeds[i] = av_get_random_seed();
for (j=0; j<i; j++)
if (seeds[j] == seeds[i])
goto retry;
}
printf("seeds OK\n");
return 0;
retry:;
}
printf("FAIL at %d with %X\n", j, seeds[j]);
return 1;
}
#endif

@ -0,0 +1,135 @@
/*
* rational numbers
* 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 "rational.c"
#include "integer.h"
int main(void)
{
AVRational a,b,r;
int i,j,k;
static const int64_t numlist[] = {
INT64_MIN, INT64_MIN+1, INT64_MAX, INT32_MIN, INT32_MAX, 1,0,-1,
123456789, INT32_MAX-1, INT32_MAX+1LL, UINT32_MAX-1, UINT32_MAX, UINT32_MAX+1LL
};
for (a.num = -2; a.num <= 2; a.num++) {
for (a.den = -2; a.den <= 2; a.den++) {
for (b.num = -2; b.num <= 2; b.num++) {
for (b.den = -2; b.den <= 2; b.den++) {
int c = av_cmp_q(a,b);
double d = av_q2d(a) == av_q2d(b) ?
0 : (av_q2d(a) - av_q2d(b));
if (d > 0) d = 1;
else if (d < 0) d = -1;
else if (d != d) d = INT_MIN;
if (c != d)
av_log(NULL, AV_LOG_ERROR, "%d/%d %d/%d, %d %f\n", a.num,
a.den, b.num, b.den, c,d);
r = av_sub_q(av_add_q(b,a), b);
if(b.den && (r.num*a.den != a.num*r.den || !r.num != !a.num || !r.den != !a.den))
av_log(NULL, AV_LOG_ERROR, "%d/%d ", r.num, r.den);
}
}
}
}
for (i = 0; i < FF_ARRAY_ELEMS(numlist); i++) {
int64_t a = numlist[i];
for (j = 0; j < FF_ARRAY_ELEMS(numlist); j++) {
int64_t b = numlist[j];
if (b<=0)
continue;
for (k = 0; k < FF_ARRAY_ELEMS(numlist); k++) {
int64_t c = numlist[k];
int64_t res;
AVInteger ai;
if (c<=0)
continue;
res = av_rescale_rnd(a,b,c, AV_ROUND_ZERO);
ai = av_mul_i(av_int2i(a), av_int2i(b));
ai = av_div_i(ai, av_int2i(c));
if (av_cmp_i(ai, av_int2i(INT64_MAX)) > 0 && res == INT64_MIN)
continue;
if (av_cmp_i(ai, av_int2i(INT64_MIN)) < 0 && res == INT64_MIN)
continue;
if (av_cmp_i(ai, av_int2i(res)) == 0)
continue;
// Special exception for INT64_MIN, remove this in case INT64_MIN is handled without off by 1 error
if (av_cmp_i(ai, av_int2i(res-1)) == 0 && a == INT64_MIN)
continue;
av_log(NULL, AV_LOG_ERROR, "%"PRId64" * %"PRId64" / %"PRId64" = %"PRId64" or %"PRId64"\n", a,b,c, res, av_i2int(ai));
}
}
}
for (a.num = 1; a.num <= 10; a.num++) {
for (a.den = 1; a.den <= 10; a.den++) {
if (av_gcd(a.num, a.den) > 1)
continue;
for (b.num = 1; b.num <= 10; b.num++) {
for (b.den = 1; b.den <= 10; b.den++) {
int start;
if (av_gcd(b.num, b.den) > 1)
continue;
if (av_cmp_q(b, a) < 0)
continue;
for (start = 0; start < 10 ; start++) {
int acc= start;
int i;
for (i = 0; i<100; i++) {
int exact = start + av_rescale_q(i+1, b, a);
acc = av_add_stable(a, acc, b, 1);
if (FFABS(acc - exact) > 2) {
av_log(NULL, AV_LOG_ERROR, "%d/%d %d/%d, %d %d\n", a.num,
a.den, b.num, b.den, acc, exact);
return 1;
}
}
}
}
}
}
}
for (a.den = 1; a.den < 0x100000000U/3; a.den*=3) {
for (a.num = -1; a.num < (1<<27); a.num += 1 + a.num/100) {
float f = av_int2float(av_q2intfloat(a));
float f2 = av_q2d(a);
if (fabs(f - f2) > fabs(f)/5000000) {
av_log(NULL, AV_LOG_ERROR, "%d/%d %f %f\n", a.num,
a.den, f, f2);
return 1;
}
}
}
return 0;
}

@ -182,119 +182,3 @@ uint32_t av_q2intfloat(AVRational q) {
return sign<<31 | (150-shift)<<23 | (n - (1<<23));
}
#ifdef TEST
#include "integer.h"
int main(void)
{
AVRational a,b,r;
int i,j,k;
static const int64_t numlist[] = {
INT64_MIN, INT64_MIN+1, INT64_MAX, INT32_MIN, INT32_MAX, 1,0,-1,
123456789, INT32_MAX-1, INT32_MAX+1LL, UINT32_MAX-1, UINT32_MAX, UINT32_MAX+1LL
};
for (a.num = -2; a.num <= 2; a.num++) {
for (a.den = -2; a.den <= 2; a.den++) {
for (b.num = -2; b.num <= 2; b.num++) {
for (b.den = -2; b.den <= 2; b.den++) {
int c = av_cmp_q(a,b);
double d = av_q2d(a) == av_q2d(b) ?
0 : (av_q2d(a) - av_q2d(b));
if (d > 0) d = 1;
else if (d < 0) d = -1;
else if (d != d) d = INT_MIN;
if (c != d)
av_log(NULL, AV_LOG_ERROR, "%d/%d %d/%d, %d %f\n", a.num,
a.den, b.num, b.den, c,d);
r = av_sub_q(av_add_q(b,a), b);
if(b.den && (r.num*a.den != a.num*r.den || !r.num != !a.num || !r.den != !a.den))
av_log(NULL, AV_LOG_ERROR, "%d/%d ", r.num, r.den);
}
}
}
}
for (i = 0; i < FF_ARRAY_ELEMS(numlist); i++) {
int64_t a = numlist[i];
for (j = 0; j < FF_ARRAY_ELEMS(numlist); j++) {
int64_t b = numlist[j];
if (b<=0)
continue;
for (k = 0; k < FF_ARRAY_ELEMS(numlist); k++) {
int64_t c = numlist[k];
int64_t res;
AVInteger ai;
if (c<=0)
continue;
res = av_rescale_rnd(a,b,c, AV_ROUND_ZERO);
ai = av_mul_i(av_int2i(a), av_int2i(b));
ai = av_div_i(ai, av_int2i(c));
if (av_cmp_i(ai, av_int2i(INT64_MAX)) > 0 && res == INT64_MIN)
continue;
if (av_cmp_i(ai, av_int2i(INT64_MIN)) < 0 && res == INT64_MIN)
continue;
if (av_cmp_i(ai, av_int2i(res)) == 0)
continue;
// Special exception for INT64_MIN, remove this in case INT64_MIN is handled without off by 1 error
if (av_cmp_i(ai, av_int2i(res-1)) == 0 && a == INT64_MIN)
continue;
av_log(NULL, AV_LOG_ERROR, "%"PRId64" * %"PRId64" / %"PRId64" = %"PRId64" or %"PRId64"\n", a,b,c, res, av_i2int(ai));
}
}
}
for (a.num = 1; a.num <= 10; a.num++) {
for (a.den = 1; a.den <= 10; a.den++) {
if (av_gcd(a.num, a.den) > 1)
continue;
for (b.num = 1; b.num <= 10; b.num++) {
for (b.den = 1; b.den <= 10; b.den++) {
int start;
if (av_gcd(b.num, b.den) > 1)
continue;
if (av_cmp_q(b, a) < 0)
continue;
for (start = 0; start < 10 ; start++) {
int acc= start;
int i;
for (i = 0; i<100; i++) {
int exact = start + av_rescale_q(i+1, b, a);
acc = av_add_stable(a, acc, b, 1);
if (FFABS(acc - exact) > 2) {
av_log(NULL, AV_LOG_ERROR, "%d/%d %d/%d, %d %d\n", a.num,
a.den, b.num, b.den, acc, exact);
return 1;
}
}
}
}
}
}
}
for (a.den = 1; a.den < 0x100000000U/3; a.den*=3) {
for (a.num = -1; a.num < (1<<27); a.num += 1 + a.num/100) {
float f = av_int2float(av_q2intfloat(a));
float f2 = av_q2d(a);
if (fabs(f - f2) > fabs(f)/5000000) {
av_log(NULL, AV_LOG_ERROR, "%d/%d %f %f\n", a.num,
a.den, f, f2);
return 1;
}
}
}
return 0;
}
#endif

@ -0,0 +1,74 @@
/*
* Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
* Copyright (C) 2013 James Almer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU 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 "ripemd.c"
#include <stdio.h>
int main(void)
{
int i, j, k;
AVRIPEMD ctx;
unsigned char digest[40];
static const int lengths[4] = { 128, 160, 256, 320 };
for (j = 0; j < 4; j++) {
printf("Testing RIPEMD-%d\n", lengths[j]);
for (k = 0; k < 3; k++) {
av_ripemd_init(&ctx, lengths[j]);
if (k == 0)
av_ripemd_update(&ctx, "abc", 3);
else if (k == 1)
av_ripemd_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
else
for (i = 0; i < 1000*1000; i++)
av_ripemd_update(&ctx, "a", 1);
av_ripemd_final(&ctx, digest);
for (i = 0; i < lengths[j] >> 3; i++)
printf("%02X", digest[i]);
putchar('\n');
}
switch (j) { //test vectors (from ISO:IEC 10118-3 (2004) and http://homes.esat.kuleuven.be/~bosselae/ripemd160.html)
case 0:
printf("c14a1219 9c66e4ba 84636b0f 69144c77\n"
"a1aa0689 d0fafa2d dc22e88b 49133a06\n"
"4a7f5723 f954eba1 216c9d8f 6320431f\n");
break;
case 1:
printf("8eb208f7 e05d987a 9b044a8e 98c6b087 f15a0bfc\n"
"12a05338 4a9c0c88 e405a06c 27dcf49a da62eb2b\n"
"52783243 c1697bdb e16d37f9 7f68f083 25dc1528\n");
break;
case 2:
printf("afbd6e22 8b9d8cbb cef5ca2d 03e6dba1 0ac0bc7d cbe4680e 1e42d2e9 75459b65\n"
"38430455 83aac6c8 c8d91285 73e7a980 9afb2a0f 34ccc36e a9e72f16 f6368e3f\n"
"ac953744 e10e3151 4c150d4d 8d7b6773 42e33399 788296e4 3ae4850c e4f97978\n");
break;
case 3:
printf("de4c01b3 054f8930 a79d09ae 738e9230 1e5a1708 5beffdc1 b8d11671 3e74f82f a942d64c dbc4682d\n"
"d034a795 0cf72202 1ba4b84d f769a5de 2060e259 df4c9bb4 a4268c0e 935bbc74 70a969c9 d072a1ac\n"
"bdee37f4 371e2064 6b8b0d86 2dda1629 2ae36f40 965e8c85 09e63d1d bddecc50 3e2b63eb 9245bb66\n");
break;
}
}
return 0;
}

@ -549,57 +549,3 @@ void av_ripemd_final(AVRIPEMD* ctx, uint8_t *digest)
for (i = 0; i < ctx->digest_len; i++)
AV_WL32(digest + i*4, ctx->state[i]);
}
#ifdef TEST
#include <stdio.h>
int main(void)
{
int i, j, k;
AVRIPEMD ctx;
unsigned char digest[40];
static const int lengths[4] = { 128, 160, 256, 320 };
for (j = 0; j < 4; j++) {
printf("Testing RIPEMD-%d\n", lengths[j]);
for (k = 0; k < 3; k++) {
av_ripemd_init(&ctx, lengths[j]);
if (k == 0)
av_ripemd_update(&ctx, "abc", 3);
else if (k == 1)
av_ripemd_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
else
for (i = 0; i < 1000*1000; i++)
av_ripemd_update(&ctx, "a", 1);
av_ripemd_final(&ctx, digest);
for (i = 0; i < lengths[j] >> 3; i++)
printf("%02X", digest[i]);
putchar('\n');
}
switch (j) { //test vectors (from ISO:IEC 10118-3 (2004) and http://homes.esat.kuleuven.be/~bosselae/ripemd160.html)
case 0:
printf("c14a1219 9c66e4ba 84636b0f 69144c77\n"
"a1aa0689 d0fafa2d dc22e88b 49133a06\n"
"4a7f5723 f954eba1 216c9d8f 6320431f\n");
break;
case 1:
printf("8eb208f7 e05d987a 9b044a8e 98c6b087 f15a0bfc\n"
"12a05338 4a9c0c88 e405a06c 27dcf49a da62eb2b\n"
"52783243 c1697bdb e16d37f9 7f68f083 25dc1528\n");
break;
case 2:
printf("afbd6e22 8b9d8cbb cef5ca2d 03e6dba1 0ac0bc7d cbe4680e 1e42d2e9 75459b65\n"
"38430455 83aac6c8 c8d91285 73e7a980 9afb2a0f 34ccc36e a9e72f16 f6368e3f\n"
"ac953744 e10e3151 4c150d4d 8d7b6773 42e33399 788296e4 3ae4850c e4f97978\n");
break;
case 3:
printf("de4c01b3 054f8930 a79d09ae 738e9230 1e5a1708 5beffdc1 b8d11671 3e74f82f a942d64c dbc4682d\n"
"d034a795 0cf72202 1ba4b84d f769a5de 2060e259 df4c9bb4 a4268c0e 935bbc74 70a969c9 d072a1ac\n"
"bdee37f4 371e2064 6b8b0d86 2dda1629 2ae36f40 965e8c85 09e63d1d bddecc50 3e2b63eb 9245bb66\n");
break;
}
}
return 0;
}
#endif

@ -0,0 +1,69 @@
/*
* 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 "sha.c"
#include <stdio.h>
int main(void)
{
int i, j, k;
AVSHA ctx;
unsigned char digest[32];
static const int lengths[3] = { 160, 224, 256 };
for (j = 0; j < 3; j++) {
printf("Testing SHA-%d\n", lengths[j]);
for (k = 0; k < 3; k++) {
av_sha_init(&ctx, lengths[j]);
if (k == 0)
av_sha_update(&ctx, "abc", 3);
else if (k == 1)
av_sha_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
else
for (i = 0; i < 1000*1000; i++)
av_sha_update(&ctx, "a", 1);
av_sha_final(&ctx, digest);
for (i = 0; i < lengths[j] >> 3; i++)
printf("%02X", digest[i]);
putchar('\n');
}
switch (j) {
case 0:
//test vectors (from FIPS PUB 180-1)
printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n"
"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n"
"34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n");
break;
case 1:
//test vectors (from FIPS PUB 180-2 Appendix A)
printf("23097d22 3405d822 8642a477 bda255b3 2aadbce4 bda0b3f7 e36c9da7\n"
"75388b16 512776cc 5dba5da1 fd890150 b0c6455c b4f58b19 52522525\n"
"20794655 980c91d8 bbb4c1ea 97618a4b f03f4258 1948b2ee 4ee7ad67\n");
break;
case 2:
//test vectors (from FIPS PUB 180-2)
printf("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad\n"
"248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1\n"
"cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0\n");
break;
}
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save