Commit 96d61605 authored by Derek Buitenhuis's avatar Derek Buitenhuis

Merge commit 'd12b5b2f'

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

Some conversions done by: James Almer <jamrial@gmail.com>
Merged-by: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parents 27506ace d12b5b2f
......@@ -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
......
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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
#include "mathops.h"
/*
* 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
*/
#ifdef TEST
#include "mathops.h"
#include <stdlib.h>
......@@ -23,4 +39,3 @@ int main(void)
}
return 0;
}
#endif /* TEST */
/*
* 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;
}
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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
/*
* 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
/*
* 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
/*
* 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 */
/*
* 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
/*
* 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
/*
* 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
/*
* 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 */
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
This diff is collapsed.
......@@ -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
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment