early-access version 1432

This commit is contained in:
pineappleEA
2021-02-09 04:25:58 +01:00
parent de64eab4b4
commit 3d5a9d908a
7336 changed files with 1773492 additions and 111 deletions

51
externals/ffmpeg/libavutil/tests/.gitignore vendored Executable file
View File

@@ -0,0 +1,51 @@
/adler32
/aes
/aes_ctr
/atomic
/audio_fifo
/avstring
/base64
/blowfish
/bprint
/camellia
/cast5
/color_utils
/cpu
/cpu_init
/crc
/des
/dict
/display
/error
/encryption_info
/eval
/fifo
/file
/hash
/hmac
/hwdevice
/imgutils
/integer
/lfg
/lls
/log
/lzo
/md5
/murmur3
/opt
/parseutils
/pca
/pixdesc
/pixelutils
/pixfmt_best
/random_seed
/rational
/ripemd
/sha
/sha512
/softfloat
/tea
/tree
/twofish
/utf8
/xtea

55
externals/ffmpeg/libavutil/tests/adler32.c vendored Executable file
View File

@@ -0,0 +1,55 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// LCOV_EXCL_START
#include "libavutil/timer.h"
#include <string.h>
#include "libavutil/log.h"
#include "libavutil/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

122
externals/ffmpeg/libavutil/tests/aes.c vendored Executable file
View File

@@ -0,0 +1,122 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// LCOV_EXCL_START
#include "libavutil/timer.h"
#include <string.h>
#include "libavutil/aes.h"
#include "libavutil/lfg.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
int main(int argc, char **argv)
{
int i, j;
struct AVAES *b;
static const uint8_t rkey[2][16] = {
{ 0 },
{ 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
};
static const uint8_t rpt[2][16] = {
{ 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
{ 0 }
};
static const 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 pt[32];
uint8_t temp[32];
uint8_t iv[2][16];
int err = 0;
b = av_aes_alloc();
if (!b)
return 1;
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;
}
}
}
av_free(b);
if (argc > 1 && !strcmp(argv[1], "-t")) {
struct AVAES *ae, *ad;
AVLFG prng;
ae = av_aes_alloc();
ad = av_aes_alloc();
if (!ae || !ad) {
av_free(ae);
av_free(ad);
return 1;
}
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]);
}
}
}
av_free(ae);
av_free(ad);
}
return err;
}
// LCOV_EXCL_STOP

65
externals/ffmpeg/libavutil/tests/aes_ctr.c vendored Executable file
View File

@@ -0,0 +1,65 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/aes_ctr.h"
static const DECLARE_ALIGNED(8, uint8_t, plain)[] = {
0x6d, 0x6f, 0x73, 0x74, 0x20, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d
};
static DECLARE_ALIGNED(8, uint8_t, tmp)[11];
int main (void)
{
int ret = 1;
struct AVAESCTR *ae, *ad;
const uint8_t *iv;
ae = av_aes_ctr_alloc();
ad = av_aes_ctr_alloc();
if (!ae || !ad)
goto ERROR;
if (av_aes_ctr_init(ae, (const uint8_t*)"0123456789abcdef") < 0)
goto ERROR;
if (av_aes_ctr_init(ad, (const uint8_t*)"0123456789abcdef") < 0)
goto ERROR;
av_aes_ctr_set_random_iv(ae);
iv = av_aes_ctr_get_iv(ae);
av_aes_ctr_set_full_iv(ad, iv);
av_aes_ctr_crypt(ae, tmp, plain, sizeof(tmp));
av_aes_ctr_crypt(ad, tmp, tmp, sizeof(tmp));
if (memcmp(tmp, plain, sizeof(tmp)) != 0){
av_log(NULL, AV_LOG_ERROR, "test failed\n");
goto ERROR;
}
av_log(NULL, AV_LOG_INFO, "test passed\n");
ret = 0;
ERROR:
av_aes_ctr_free(ae);
av_aes_ctr_free(ad);
return ret;
}

200
externals/ffmpeg/libavutil/tests/audio_fifo.c vendored Executable file
View File

@@ -0,0 +1,200 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include "libavutil/mem.h"
#include "libavutil/audio_fifo.c"
#define MAX_CHANNELS 32
typedef struct TestStruct {
const enum AVSampleFormat format;
const int nb_ch;
void const *data_planes[MAX_CHANNELS];
const int nb_samples_pch;
} TestStruct;
static const uint8_t data_U8 [] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
static const int16_t data_S16[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
static const float data_FLT[] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0};
static const TestStruct test_struct[] = {
{.format = AV_SAMPLE_FMT_U8 , .nb_ch = 1, .data_planes = {data_U8 , }, .nb_samples_pch = 12},
{.format = AV_SAMPLE_FMT_U8P , .nb_ch = 2, .data_planes = {data_U8 , data_U8 +6, }, .nb_samples_pch = 6 },
{.format = AV_SAMPLE_FMT_S16 , .nb_ch = 1, .data_planes = {data_S16, }, .nb_samples_pch = 12},
{.format = AV_SAMPLE_FMT_S16P , .nb_ch = 2, .data_planes = {data_S16, data_S16+6, }, .nb_samples_pch = 6 },
{.format = AV_SAMPLE_FMT_FLT , .nb_ch = 1, .data_planes = {data_FLT, }, .nb_samples_pch = 12},
{.format = AV_SAMPLE_FMT_FLTP , .nb_ch = 2, .data_planes = {data_FLT, data_FLT+6, }, .nb_samples_pch = 6 }
};
static void free_data_planes(AVAudioFifo *afifo, void **output_data)
{
int i;
for (i = 0; i < afifo->nb_buffers; ++i){
av_freep(&output_data[i]);
}
av_freep(&output_data);
}
static void ERROR(const char *str)
{
fprintf(stderr, "%s\n", str);
exit(1);
}
static void print_audio_bytes(const TestStruct *test_sample, void **data_planes, int nb_samples)
{
int p, b, f;
int byte_offset = av_get_bytes_per_sample(test_sample->format);
int buffers = av_sample_fmt_is_planar(test_sample->format)
? test_sample->nb_ch : 1;
int line_size = (buffers > 1) ? nb_samples * byte_offset
: nb_samples * byte_offset * test_sample->nb_ch;
for (p = 0; p < buffers; ++p){
for(b = 0; b < line_size; b+=byte_offset){
for (f = 0; f < byte_offset; f++){
int order = !HAVE_BIGENDIAN ? (byte_offset - f - 1) : f;
printf("%02x", *((uint8_t*)data_planes[p] + b + order));
}
putchar(' ');
}
putchar('\n');
}
}
static int read_samples_from_audio_fifo(AVAudioFifo* afifo, void ***output, int nb_samples)
{
int i;
int samples = FFMIN(nb_samples, afifo->nb_samples);
int tot_elements = !av_sample_fmt_is_planar(afifo->sample_fmt)
? samples : afifo->channels * samples;
void **data_planes = av_malloc_array(afifo->nb_buffers, sizeof(void*));
if (!data_planes)
ERROR("failed to allocate memory!");
if (*output)
free_data_planes(afifo, *output);
*output = data_planes;
for (i = 0; i < afifo->nb_buffers; ++i){
data_planes[i] = av_malloc_array(tot_elements, afifo->sample_size);
if (!data_planes[i])
ERROR("failed to allocate memory!");
}
return av_audio_fifo_read(afifo, *output, nb_samples);
}
static int write_samples_to_audio_fifo(AVAudioFifo* afifo, const TestStruct *test_sample,
int nb_samples, int offset)
{
int offset_size, i;
void *data_planes[MAX_CHANNELS];
if(nb_samples > test_sample->nb_samples_pch - offset){
return 0;
}
if(offset >= test_sample->nb_samples_pch){
return 0;
}
offset_size = offset * afifo->sample_size;
for (i = 0; i < afifo->nb_buffers ; ++i){
data_planes[i] = (uint8_t*)test_sample->data_planes[i] + offset_size;
}
return av_audio_fifo_write(afifo, data_planes, nb_samples);
}
static void test_function(const TestStruct *test_sample)
{
int ret, i;
void **output_data = NULL;
AVAudioFifo *afifo = av_audio_fifo_alloc(test_sample->format, test_sample->nb_ch,
test_sample->nb_samples_pch);
if (!afifo) {
ERROR("ERROR: av_audio_fifo_alloc returned NULL!");
}
ret = write_samples_to_audio_fifo(afifo, test_sample, test_sample->nb_samples_pch, 0);
if (ret < 0){
ERROR("ERROR: av_audio_fifo_write failed!");
}
printf("written: %d\n", ret);
ret = write_samples_to_audio_fifo(afifo, test_sample, test_sample->nb_samples_pch, 0);
if (ret < 0){
ERROR("ERROR: av_audio_fifo_write failed!");
}
printf("written: %d\n", ret);
printf("remaining samples in audio_fifo: %d\n\n", av_audio_fifo_size(afifo));
ret = read_samples_from_audio_fifo(afifo, &output_data, test_sample->nb_samples_pch);
if (ret < 0){
ERROR("ERROR: av_audio_fifo_read failed!");
}
printf("read: %d\n", ret);
print_audio_bytes(test_sample, output_data, ret);
printf("remaining samples in audio_fifo: %d\n\n", av_audio_fifo_size(afifo));
/* test av_audio_fifo_peek */
ret = av_audio_fifo_peek(afifo, output_data, afifo->nb_samples);
if (ret < 0){
ERROR("ERROR: av_audio_fifo_peek failed!");
}
printf("peek:\n");
print_audio_bytes(test_sample, output_data, ret);
printf("\n");
/* test av_audio_fifo_peek_at */
printf("peek_at:\n");
for (i = 0; i < afifo->nb_samples; ++i){
ret = av_audio_fifo_peek_at(afifo, output_data, 1, i);
if (ret < 0){
ERROR("ERROR: av_audio_fifo_peek_at failed!");
}
printf("%d:\n", i);
print_audio_bytes(test_sample, output_data, ret);
}
printf("\n");
/* test av_audio_fifo_drain */
ret = av_audio_fifo_drain(afifo, afifo->nb_samples);
if (ret < 0){
ERROR("ERROR: av_audio_fifo_drain failed!");
}
if (afifo->nb_samples){
ERROR("drain failed to flush all samples in audio_fifo!");
}
/* deallocate */
free_data_planes(afifo, output_data);
av_audio_fifo_free(afifo);
}
int main(void)
{
int t, tests = sizeof(test_struct)/sizeof(test_struct[0]);
for (t = 0; t < tests; ++t){
printf("\nTEST: %d\n\n", t+1);
test_function(&test_struct[t]);
}
return 0;
}

125
externals/ffmpeg/libavutil/tests/avstring.c vendored Executable file
View File

@@ -0,0 +1,125 @@
/*
* 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/mem.h"
#include "libavutil/avstring.h"
int main(void)
{
int i;
char *fullpath, *ptr;
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"
};
const char *haystack = "Education consists mainly in what we have unlearned.";
const char * const needle[] = {"learned.", "unlearned.", "Unlearned"};
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");
/*Testing av_strnstr()*/
#define TEST_STRNSTR(haystack, needle, hay_length, expected) \
ptr = av_strnstr(haystack, needle, hay_length); \
if (ptr != expected){ \
printf("expected: %p, received %p\n", expected, ptr); \
}
TEST_STRNSTR(haystack, needle [0], strlen(haystack), haystack+44);
TEST_STRNSTR(haystack, needle [1], strlen(haystack), haystack+42);
TEST_STRNSTR(haystack, needle [2], strlen(haystack), NULL );
TEST_STRNSTR(haystack, strings[1], strlen(haystack), haystack );
/*Testing av_strireplace()*/
#define TEST_STRIREPLACE(haystack, needle, expected) \
ptr = av_strireplace(haystack, needle, "instead"); \
if (ptr == NULL) { \
printf("error, received null pointer!\n"); \
} else { \
if (strcmp(ptr, expected) != 0) \
printf( "expected: %s, received: %s\n", expected, ptr); \
av_free(ptr); \
}
TEST_STRIREPLACE(haystack, needle [0], "Education consists mainly in what we have uninstead");
TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what we have instead");
TEST_STRIREPLACE(haystack, needle [2], "Education consists mainly in what we have instead.");
TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what we have instead");
/*Testing av_d2str()*/
#define TEST_D2STR(value, expected) \
if((ptr = av_d2str(value)) == NULL){ \
printf("error, received null pointer!\n"); \
} else { \
if(strcmp(ptr, expected) != 0) \
printf( "expected: %s, received: %s\n", expected, ptr); \
av_free(ptr); \
}
TEST_D2STR(0 , "0.000000");
TEST_D2STR(-1.2333234, "-1.233323");
TEST_D2STR(-1.2333237, "-1.233324");
return 0;
}

130
externals/ffmpeg/libavutil/tests/base64.c vendored Executable file
View File

@@ -0,0 +1,130 @@
/*
* 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 "libavutil/timer.h"
#include <stdint.h>
#include <stdio.h>
#include "libavutil/common.h"
#include "libavutil/base64.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

194
externals/ffmpeg/libavutil/tests/blowfish.c vendored Executable file
View File

@@ -0,0 +1,194 @@
/*
* 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 "libavutil/mem.h"
#include "libavutil/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)
{
uint32_t tmptext_l[NUM_VARIABLE_KEY_TESTS];
uint32_t tmptext_r[NUM_VARIABLE_KEY_TESTS];
uint8_t tmp[16], iv[8];
int i;
AVBlowfish *ctx = av_blowfish_alloc();
if (!ctx)
return 1;
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 2;
}
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 3;
}
}
printf("Test encryption/decryption success.\n");
av_free(ctx);
return 0;
}

93
externals/ffmpeg/libavutil/tests/bprint.c vendored Executable file
View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2012 Nicolas George
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/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, AV_BPRINT_SIZE_UNLIMITED);
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, AV_BPRINT_SIZE_UNLIMITED);
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, AV_BPRINT_SIZE_AUTOMATIC);
bprint_pascal(&b, 5);
printf("Short text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
av_bprint_init(&b, 0, AV_BPRINT_SIZE_AUTOMATIC);
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, AV_BPRINT_SIZE_COUNT_ONLY);
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, AV_BPRINT_SIZE_UNLIMITED);
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;
}

75
externals/ffmpeg/libavutil/tests/camellia.c vendored Executable file
View File

@@ -0,0 +1,75 @@
/*
* 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 "libavutil/camellia.h"
#include "libavutil/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];
struct 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;
}

103
externals/ffmpeg/libavutil/tests/cast5.c vendored Executable file
View File

@@ -0,0 +1,103 @@
/*
* 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 "libavutil/cast5.h"
#include "libavutil/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];
struct 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;
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2015 Kevin Wheatley <kevin.j.wheatley@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/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);
}
}
}
}

148
externals/ffmpeg/libavutil/tests/cpu.c vendored Executable file
View File

@@ -0,0 +1,148 @@
/*
* 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 "config.h"
#include "libavutil/cpu.h"
#include "libavutil/avstring.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#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" },
{ AV_CPU_FLAG_AVX512, "avx512" },
#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;
}

65
externals/ffmpeg/libavutil/tests/cpu_init.c vendored Executable file
View File

@@ -0,0 +1,65 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* This test program tests whether the one-time initialization in
* av_get_cpu_flags() has data races.
*/
#include <stdio.h>
#include <string.h>
#include "libavutil/cpu.h"
#include "libavutil/thread.h"
static void *thread_main(void *arg)
{
int *flags = arg;
*flags = av_get_cpu_flags();
return NULL;
}
int main(void)
{
int cpu_flags1;
int cpu_flags2;
int ret;
pthread_t thread1;
pthread_t thread2;
if ((ret = pthread_create(&thread1, NULL, thread_main, &cpu_flags1))) {
fprintf(stderr, "pthread_create failed: %s.\n", strerror(ret));
return 1;
}
if ((ret = pthread_create(&thread2, NULL, thread_main, &cpu_flags2))) {
fprintf(stderr, "pthread_create failed: %s.\n", strerror(ret));
return 1;
}
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
if (cpu_flags1 < 0)
return 2;
if (cpu_flags2 < 0)
return 2;
if (cpu_flags1 != cpu_flags2)
return 3;
return 0;
}

47
externals/ffmpeg/libavutil/tests/crc.c vendored Executable file
View File

@@ -0,0 +1,47 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include <stdio.h>
#include "libavutil/crc.h"
int main(void)
{
uint8_t buf[1999];
int i;
static const unsigned p[7][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 },
{ AV_CRC_8_EBU , 0x1D , 0xD6 },
};
const AVCRC *ctx;
for (i = 0; i < sizeof(buf); i++)
buf[i] = i + i * i;
for (i = 0; i < 7; 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;
}

133
externals/ffmpeg/libavutil/tests/des.c vendored Executable file
View File

@@ -0,0 +1,133 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/timer.h"
#include "libavutil/des.c"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libavutil/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_ref)[] = { 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;
}
}
union word_byte {
uint64_t word;
uint8_t byte[8];
};
int main(void)
{
AVDES d;
int i;
union word_byte key[3], data, ct;
uint64_t roundkeys[16];
srand(av_gettime());
key[0].word = AV_RB64(test_key);
data.word = AV_RB64(plain);
gen_roundkeys(roundkeys, key[0].word);
if (des_encdec(data.word, roundkeys, 0) != AV_RB64(crypt_ref)) {
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_ref, sizeof(crypt_ref))) {
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].word = rand64();
key[1].word = rand64();
key[2].word = rand64();
data.word = rand64();
av_des_init(&d, key[0].byte, 192, 0);
av_des_crypt(&d, ct.byte, data.byte, 1, NULL, 0);
av_des_init(&d, key[0].byte, 192, 1);
av_des_crypt(&d, ct.byte, ct.byte, 1, NULL, 1);
if (ct.word != data.word) {
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;
}

136
externals/ffmpeg/libavutil/tests/dict.c vendored Executable file
View File

@@ -0,0 +1,136 @@
/*
* 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 "libavutil/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;
int ret;
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);
ret = av_dict_parse_string(&dict, buffer, vals, pairs, 0);
printf("ret %d\n", ret);
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;
}

61
externals/ffmpeg/libavutil/tests/display.c vendored Executable file
View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2014 Vittorio Giovara <vittorio.giovara@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/display.c"
static void print_matrix(int32_t matrix[9])
{
int i, j;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3 - 1; ++j)
printf("%d ", matrix[i*3 + j]);
printf("%d\n", matrix[i*3 + j]);
}
}
int main(void)
{
int32_t matrix[9];
// Set the matrix to 90 degrees
av_display_rotation_set(matrix, 90);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// Set the matrix to -45 degrees
av_display_rotation_set(matrix, -45);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// flip horizontal
av_display_matrix_flip(matrix, 1, 0);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
// flip vertical
av_display_matrix_flip(matrix, 0, 1);
print_matrix(matrix);
printf("degrees: %f\n", av_display_rotation_get(matrix));
return 0;
}

View File

@@ -0,0 +1,176 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/encryption_info.h"
#include <stdio.h>
#include <string.h>
#include "libavutil/avassert.h"
static const AVSubsampleEncryptionInfo test_subsamples[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
static const size_t test_subsample_count = sizeof(test_subsamples) / sizeof(test_subsamples[0]);
static const uint8_t test_iv[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18};
static const uint8_t test_key_id[] = {0x21, 0x22, 0x23, 0x24};
static const uint8_t test_key_id_2[] = {0x31, 0x32, 0x33, 0x34};
static const uint8_t test_system_id[] = {0x41, 0x42, 0x43};
static const uint8_t test_data[] = {0x51, 0x52};
static int compare_encryption_info(const AVEncryptionInfo *a, const AVEncryptionInfo *b) {
if (!a || !b || a->scheme != b->scheme || a->crypt_byte_block != b->crypt_byte_block ||
a->skip_byte_block != b->skip_byte_block || a->key_id_size != b->key_id_size ||
a->iv_size != b->iv_size || a->subsample_count != b->subsample_count)
return 1;
if (memcmp(a->key_id, b->key_id, a->key_id_size) != 0 ||
memcmp(a->iv, b->iv, a->iv_size) != 0 ||
memcmp(a->subsamples, b->subsamples, a->subsample_count * sizeof(a->subsamples[0])))
return 1;
return 0;
}
static int compare_encryption_init_info(const AVEncryptionInitInfo *a, const AVEncryptionInitInfo *b) {
if (!a || !b || a->system_id_size != b->system_id_size ||
a->num_key_ids != b->num_key_ids || a->key_id_size != b->key_id_size ||
a->data_size != b->data_size)
return 1;
if (memcmp(a->system_id, b->system_id, a->system_id_size) != 0 ||
memcmp(a->data, b->data, a->data_size) != 0)
return 1;
for (uint32_t i = 0; i < a->num_key_ids; i++) {
if (memcmp(a->key_ids[i], b->key_ids[i], a->key_id_size) != 0)
return 1;
}
if (a->next || b->next) {
if (!a->next || !b->next)
return 1;
if (compare_encryption_init_info(a->next, b->next) != 0)
return 1;
}
return 0;
}
static void run_encryption_info_test(void)
{
AVEncryptionInfo *info, *copy;
uint8_t *side_data;
size_t side_data_size;
info = av_encryption_info_alloc(test_subsample_count, sizeof(test_key_id), sizeof(test_iv));
av_assert0(info);
av_assert0(info->key_id);
av_assert0(info->key_id_size == sizeof(test_key_id));
av_assert0(info->iv);
av_assert0(info->iv_size == sizeof(test_iv));
av_assert0(info->subsamples);
av_assert0(info->subsample_count == test_subsample_count);
info->scheme = 1234;
info->crypt_byte_block = 333;
info->skip_byte_block = 444;
memcpy(info->key_id, test_key_id, sizeof(test_key_id));
memcpy(info->iv, test_iv, sizeof(test_iv));
memcpy(info->subsamples, test_subsamples, sizeof(test_subsamples));
copy = av_encryption_info_clone(info);
av_assert0(copy);
av_assert0(copy != info);
av_assert0(compare_encryption_info(info, copy) == 0);
av_encryption_info_free(copy);
side_data = av_encryption_info_add_side_data(info, &side_data_size);
av_assert0(side_data);
av_assert0(side_data_size > 0);
copy = av_encryption_info_get_side_data(side_data, side_data_size);
av_assert0(copy);
av_assert0(copy != info);
av_assert0(compare_encryption_info(info, copy) == 0);
av_encryption_info_free(copy);
av_free(side_data);
av_encryption_info_free(info);
}
static AVEncryptionInitInfo *create_init_info(void)
{
AVEncryptionInitInfo *info;
info = av_encryption_init_info_alloc(sizeof(test_system_id), 2, sizeof(test_key_id), sizeof(test_data));
av_assert0(info);
av_assert0(info->system_id);
av_assert0(info->system_id_size == sizeof(test_system_id));
av_assert0(info->key_ids);
av_assert0(info->num_key_ids == 2);
av_assert0(info->key_id_size == sizeof(test_key_id));
av_assert0(info->key_ids[0]);
av_assert0(info->key_ids[1]);
av_assert0(info->data);
av_assert0(info->data_size == sizeof(test_data));
av_assert0(!info->next);
memcpy(info->system_id, test_system_id, sizeof(test_system_id));
memcpy(info->key_ids[0], test_key_id, sizeof(test_key_id));
memcpy(info->key_ids[1], test_key_id_2, sizeof(test_key_id_2));
memcpy(info->data, test_data, sizeof(test_data));
return info;
}
static void run_encryption_init_info_test(void)
{
AVEncryptionInitInfo *info, *copy;
uint8_t *side_data;
size_t side_data_size;
info = create_init_info();
side_data = av_encryption_init_info_add_side_data(info, &side_data_size);
av_assert0(side_data);
av_assert0(side_data_size > 0);
copy = av_encryption_init_info_get_side_data(side_data, side_data_size);
av_assert0(copy);
av_assert0(compare_encryption_init_info(info, copy) == 0);
av_encryption_init_info_free(copy);
av_free(side_data);
// Make the first init info different from the second to test the correct order.
memset(info->system_id, 0, info->system_id_size);
info->next = create_init_info();
side_data = av_encryption_init_info_add_side_data(info, &side_data_size);
av_assert0(side_data);
copy = av_encryption_init_info_get_side_data(side_data, side_data_size);
av_assert0(copy);
av_assert0(compare_encryption_init_info(info, copy) == 0);
av_encryption_init_info_free(copy);
av_free(side_data);
av_encryption_init_info_free(info);
}
int main(int argc, char **argv)
{
run_encryption_info_test();
run_encryption_init_info_test();
return 0;
}

37
externals/ffmpeg/libavutil/tests/error.c vendored Executable file
View File

@@ -0,0 +1,37 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/error.c"
#undef printf
int main(void)
{
int i;
for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
const struct error_entry *entry = &error_entries[i];
printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
}
for (i = 0; i < 256; i++) {
printf("%d: %s\n", -i, av_err2str(-i));
}
return 0;
}

184
externals/ffmpeg/libavutil/tests/eval.c vendored Executable file
View File

@@ -0,0 +1,184 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/timer.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "libavutil/libm.h"
#include "libavutil/eval.h"
static const double const_values[] = {
M_PI,
M_E,
0
};
static const char *const const_names[] = {
"PI",
"E",
0
};
int main(int argc, char **argv)
{
int i;
double d;
const char *const *expr;
static const char *const exprs[] = {
"",
"1;2",
"-20",
"-PI",
"+PI",
"1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
"80G/80Gi",
"1k",
"1Gi",
"1gi",
"1GiFoo",
"1k+1k",
"1Gi*3foo",
"foo",
"foo(",
"foo()",
"foo)",
"sin",
"sin(",
"sin()",
"sin)",
"sin 10",
"sin(1,2,3)",
"sin(1 )",
"1",
"1foo",
"bar + PI + E + 100f*2 + foo",
"13k + 12f - foo(1, 2)",
"1gi",
"1Gi",
"st(0, 123)",
"st(1, 123); ld(1)",
"lte(0, 1)",
"lte(1, 1)",
"lte(1, 0)",
"lt(0, 1)",
"lt(1, 1)",
"gt(1, 0)",
"gt(2, 7)",
"gte(122, 122)",
/* compute 1+2+...+N */
"st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
/* compute Fib(N) */
"st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
"while(0, 10)",
"st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
"isnan(1)",
"isnan(NAN)",
"isnan(INF)",
"isinf(1)",
"isinf(NAN)",
"isinf(INF)",
"floor(NAN)",
"floor(123.123)",
"floor(-123.123)",
"trunc(123.123)",
"trunc(-123.123)",
"ceil(123.123)",
"ceil(-123.123)",
"sqrt(1764)",
"isnan(sqrt(-1))",
"not(1)",
"not(NAN)",
"not(0)",
"6.0206dB",
"-3.0103dB",
"pow(0,1.23)",
"pow(PI,1.23)",
"PI^1.23",
"pow(-1,1.23)",
"if(1, 2)",
"if(1, 1, 2)",
"if(0, 1, 2)",
"ifnot(0, 23)",
"ifnot(1, NaN) + if(0, 1)",
"ifnot(1, 1, 2)",
"ifnot(0, 1, 2)",
"taylor(1, 1)",
"taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)",
"root(sin(ld(0))-1, 2)",
"root(sin(ld(0))+6+sin(ld(0)/12)-log(ld(0)), 100)",
"7000000B*random(0)",
"squish(2)",
"gauss(0.1)",
"hypot(4,3)",
"gcd(30,55)*print(min(9,1))",
"bitor(42, 12)",
"bitand(42, 12)",
"bitand(NAN, 1)",
"between(10, -3, 10)",
"between(-4, -2, -1)",
"between(1,2)",
"clip(0, 2, 1)",
"clip(0/0, 1, 2)",
"clip(0, 0/0, 1)",
NULL
};
int ret;
for (expr = exprs; *expr; expr++) {
printf("Evaluating '%s'\n", *expr);
ret = av_expr_parse_and_eval(&d, *expr,
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
if (isnan(d))
printf("'%s' -> nan\n\n", *expr);
else
printf("'%s' -> %f\n\n", *expr, d);
if (ret < 0)
printf("av_expr_parse_and_eval failed\n");
}
ret = av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("%f == 12.7\n", d);
if (ret < 0)
printf("av_expr_parse_and_eval failed\n");
ret = av_expr_parse_and_eval(&d, "80G/80Gi",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
printf("%f == 0.931322575\n", d);
if (ret < 0)
printf("av_expr_parse_and_eval failed\n");
if (argc > 1 && !strcmp(argv[1], "-t")) {
for (i = 0; i < 1050; i++) {
START_TIMER;
ret = av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
const_names, const_values,
NULL, NULL, NULL, NULL, NULL, 0, NULL);
if (ret < 0)
printf("av_expr_parse_and_eval failed\n");
STOP_TIMER("av_expr_parse_and_eval");
}
}
return 0;
}

109
externals/ffmpeg/libavutil/tests/fifo.c vendored Executable file
View File

@@ -0,0 +1,109 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include "libavutil/fifo.h"
int main(void)
{
/* create a FIFO buffer */
AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
int i, j, n, *p;
/* fill data */
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
/* peek at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = -n + 1; i < n; i++) {
int *v = (int *)av_fifo_peek2(fifo, i * sizeof(int));
printf("%d: %d\n", i, *v);
}
printf("\n");
/* peek_at at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = 0; i < n; i++) {
av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
printf("%d: %d\n", i, j);
}
printf("\n");
/* generic peek at FIFO */
n = av_fifo_size(fifo);
p = malloc(n);
if (p == NULL) {
fprintf(stderr, "failed to allocate memory.\n");
exit(1);
}
(void) av_fifo_generic_peek(fifo, p, n, NULL);
/* read data at p */
n /= sizeof(int);
for(i = 0; i < n; ++i)
printf("%d: %d\n", i, p[i]);
putchar('\n');
/* read data */
for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
printf("%d ", j);
}
printf("\n");
/* test *ndx overflow */
av_fifo_reset(fifo);
fifo->rndx = fifo->wndx = ~(uint32_t)0 - 5;
/* fill data */
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
/* peek_at at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = 0; i < n; i++) {
av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
printf("%d: %d\n", i, j);
}
putchar('\n');
/* test fifo_grow */
(void) av_fifo_grow(fifo, 15 * sizeof(int));
/* fill data */
n = av_fifo_size(fifo) / sizeof(int);
for (i = n; av_fifo_space(fifo) >= sizeof(int); ++i)
av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
/* peek_at at FIFO */
n = av_fifo_size(fifo) / sizeof(int);
for (i = 0; i < n; i++) {
av_fifo_generic_peek_at(fifo, &j, i * sizeof(int), sizeof(j), NULL);
printf("%d: %d\n", i, j);
}
av_fifo_free(fifo);
free(p);
return 0;
}

34
externals/ffmpeg/libavutil/tests/file.c vendored Executable file
View File

@@ -0,0 +1,34 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/file.c"
#undef printf
int main(void)
{
uint8_t *buf;
size_t size;
if (av_file_map("file.c", &buf, &size, 0, NULL) < 0)
return 1;
buf[0] = 's';
printf("%s", buf);
av_file_unmap(buf, size);
return 0;
}

65
externals/ffmpeg/libavutil/tests/hash.c vendored Executable file
View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <string.h>
#include "libavutil/hash.h"
#define SRC_BUF_SIZE 64
#define DST_BUF_SIZE (AV_HASH_MAX_SIZE * 8)
int main(void)
{
struct AVHashContext *ctx = NULL;
int i, j, numhashes = 0;
static const uint8_t src[SRC_BUF_SIZE] = { 0 };
uint8_t dst[DST_BUF_SIZE];
while (av_hash_names(numhashes))
numhashes++;
for (i = 0; i < numhashes; i++) {
if (av_hash_alloc(&ctx, av_hash_names(i)) < 0)
return 1;
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
memset(dst, 0, DST_BUF_SIZE);
av_hash_final_hex(ctx, dst, DST_BUF_SIZE);
printf("%s hex: %s\n", av_hash_get_name(ctx), dst);
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
av_hash_final_bin(ctx, dst, DST_BUF_SIZE);
printf("%s bin: ", av_hash_get_name(ctx));
for (j = 0; j < av_hash_get_size(ctx); j++) {
printf("%#x ", dst[j]);
}
printf("\n");
av_hash_init(ctx);
av_hash_update(ctx, src, SRC_BUF_SIZE);
av_hash_final_b64(ctx, dst, DST_BUF_SIZE);
printf("%s b64: %s\n", av_hash_get_name(ctx), dst);
av_hash_freep(&ctx);
}
return 0;
}

87
externals/ffmpeg/libavutil/tests/hmac.c vendored Executable file
View File

@@ -0,0 +1,87 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/hmac.c"
#include <stdio.h>
#include <string.h>
static void test(AVHMAC *hmac, const uint8_t *key, int keylen,
const uint8_t *data, int datalen)
{
uint8_t buf[MAX_HASHLEN];
int out, i;
// Some of the test vectors are strings, where sizeof() includes the
// trailing null byte - remove that.
if (!key[keylen - 1])
keylen--;
if (!data[datalen - 1])
datalen--;
out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf));
for (i = 0; i < out; i++)
printf("%02x", buf[i]);
printf("\n");
}
int main(void)
{
uint8_t key1[20], key3[131], data3[50];
AVHMAC *hmac;
enum AVHMACType i;
static const uint8_t key2[] = "Jefe";
static const uint8_t data1[] = "Hi There";
static const uint8_t data2[] = "what do ya want for nothing?";
static const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First";
static const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
static const uint8_t data6[] = "This is a test using a larger than block-size key and a larger "
"than block-size data. The key needs to be hashed before being used"
" by the HMAC algorithm.";
memset(key1, 0x0b, sizeof(key1));
memset(key3, 0xaa, sizeof(key3));
memset(data3, 0xdd, sizeof(data3));
/* MD5, SHA-1 */
for (i = AV_HMAC_MD5; i <= AV_HMAC_SHA1; i++) {
hmac = av_hmac_alloc(i);
if (!hmac)
return 1;
// RFC 2202 test vectors
test(hmac, key1, hmac->hashlen, data1, sizeof(data1));
test(hmac, key2, sizeof(key2), data2, sizeof(data2));
test(hmac, key3, hmac->hashlen, data3, sizeof(data3));
test(hmac, key3, 80, data4, sizeof(data4));
test(hmac, key3, 80, data5, sizeof(data5));
av_hmac_free(hmac);
}
/* SHA-2 */
for (i = AV_HMAC_SHA224; i <= AV_HMAC_SHA512; i++) {
hmac = av_hmac_alloc(i);
if (!hmac)
return 1;
// RFC 4231 test vectors
test(hmac, key1, sizeof(key1), data1, sizeof(data1));
test(hmac, key2, sizeof(key2), data2, sizeof(data2));
test(hmac, key3, 20, data3, sizeof(data3));
test(hmac, key3, sizeof(key3), data4, sizeof(data4));
test(hmac, key3, sizeof(key3), data6, sizeof(data6));
av_hmac_free(hmac);
}
return 0;
}

226
externals/ffmpeg/libavutil/tests/hwdevice.c vendored Executable file
View File

@@ -0,0 +1,226 @@
/*
* 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/hwcontext.h"
static int test_derivation(AVBufferRef *src_ref, const char *src_name)
{
enum AVHWDeviceType derived_type;
const char *derived_name;
AVBufferRef *derived_ref = NULL, *back_ref = NULL;
AVHWDeviceContext *src_dev, *derived_dev;
int err;
src_dev = (AVHWDeviceContext*)src_ref->data;
derived_type = AV_HWDEVICE_TYPE_NONE;
while (1) {
derived_type = av_hwdevice_iterate_types(derived_type);
if (derived_type == AV_HWDEVICE_TYPE_NONE)
break;
derived_name = av_hwdevice_get_type_name(derived_type);
err = av_hwdevice_ctx_create_derived(&derived_ref, derived_type,
src_ref, 0);
if (err < 0) {
fprintf(stderr, "Unable to derive %s -> %s: %d.\n",
src_name, derived_name, err);
continue;
}
derived_dev = (AVHWDeviceContext*)derived_ref->data;
if (derived_dev->type != derived_type) {
fprintf(stderr, "Device derived as type %d has type %d.\n",
derived_type, derived_dev->type);
goto fail;
}
if (derived_type == src_dev->type) {
if (derived_dev != src_dev) {
fprintf(stderr, "Derivation of %s from itself succeeded "
"but did not return the same device.\n", src_name);
goto fail;
}
av_buffer_unref(&derived_ref);
continue;
}
err = av_hwdevice_ctx_create_derived(&back_ref, src_dev->type,
derived_ref, 0);
if (err < 0) {
fprintf(stderr, "Derivation %s to %s succeeded, but derivation "
"back again failed: %d.\n",
src_name, derived_name, err);
goto fail;
}
if (back_ref->data != src_ref->data) {
fprintf(stderr, "Derivation %s to %s succeeded, but derivation "
"back again did not return the original device.\n",
src_name, derived_name);
goto fail;
}
fprintf(stderr, "Successfully tested derivation %s -> %s.\n",
src_name, derived_name);
av_buffer_unref(&derived_ref);
av_buffer_unref(&back_ref);
}
return 0;
fail:
av_buffer_unref(&derived_ref);
av_buffer_unref(&back_ref);
return -1;
}
static int test_device(enum AVHWDeviceType type, const char *name,
const char *device, AVDictionary *opts, int flags)
{
AVBufferRef *ref;
AVHWDeviceContext *dev;
int err;
err = av_hwdevice_ctx_create(&ref, type, device, opts, flags);
if (err < 0) {
fprintf(stderr, "Failed to create %s device: %d.\n", name, err);
return 1;
}
dev = (AVHWDeviceContext*)ref->data;
if (dev->type != type) {
fprintf(stderr, "Device created as type %d has type %d.\n",
type, dev->type);
av_buffer_unref(&ref);
return -1;
}
fprintf(stderr, "Device type %s successfully created.\n", name);
err = test_derivation(ref, name);
av_buffer_unref(&ref);
return err;
}
static const struct {
enum AVHWDeviceType type;
const char *possible_devices[5];
} test_devices[] = {
{ AV_HWDEVICE_TYPE_CUDA,
{ "0", "1", "2" } },
{ AV_HWDEVICE_TYPE_DRM,
{ "/dev/dri/card0", "/dev/dri/card1",
"/dev/dri/renderD128", "/dev/dri/renderD129" } },
{ AV_HWDEVICE_TYPE_DXVA2,
{ "0", "1", "2" } },
{ AV_HWDEVICE_TYPE_D3D11VA,
{ "0", "1", "2" } },
{ AV_HWDEVICE_TYPE_OPENCL,
{ "0.0", "0.1", "1.0", "1.1" } },
{ AV_HWDEVICE_TYPE_VAAPI,
{ "/dev/dri/renderD128", "/dev/dri/renderD129", ":0" } },
};
static int test_device_type(enum AVHWDeviceType type)
{
enum AVHWDeviceType check;
const char *name;
int i, j, found, err;
name = av_hwdevice_get_type_name(type);
if (!name) {
fprintf(stderr, "No name available for device type %d.\n", type);
return -1;
}
check = av_hwdevice_find_type_by_name(name);
if (check != type) {
fprintf(stderr, "Type %d maps to name %s maps to type %d.\n",
type, name, check);
return -1;
}
found = 0;
err = test_device(type, name, NULL, NULL, 0);
if (err < 0) {
fprintf(stderr, "Test failed for %s with default options.\n", name);
return -1;
}
if (err == 0) {
fprintf(stderr, "Test passed for %s with default options.\n", name);
++found;
}
for (i = 0; i < FF_ARRAY_ELEMS(test_devices); i++) {
if (test_devices[i].type != type)
continue;
for (j = 0; test_devices[i].possible_devices[j]; j++) {
err = test_device(type, name,
test_devices[i].possible_devices[j],
NULL, 0);
if (err < 0) {
fprintf(stderr, "Test failed for %s with device %s.\n",
name, test_devices[i].possible_devices[j]);
return -1;
}
if (err == 0) {
fprintf(stderr, "Test passed for %s with device %s.\n",
name, test_devices[i].possible_devices[j]);
++found;
}
}
}
return !found;
}
int main(void)
{
enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
int pass, fail, skip, err;
pass = fail = skip = 0;
while (1) {
type = av_hwdevice_iterate_types(type);
if (type == AV_HWDEVICE_TYPE_NONE)
break;
err = test_device_type(type);
if (err == 0)
++pass;
else if (err < 0)
++fail;
else
++skip;
}
fprintf(stderr, "Attempted to test %d device types: "
"%d passed, %d failed, %d skipped.\n",
pass + fail + skip, pass, fail, skip);
return fail > 0;
}

36
externals/ffmpeg/libavutil/tests/imgutils.c vendored Executable file
View File

@@ -0,0 +1,36 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/imgutils.c"
#undef printf
int main(void)
{
int64_t x, y;
for (y = -1; y<UINT_MAX; y+= y/2 + 1) {
for (x = -1; x<UINT_MAX; x+= x/2 + 1) {
int ret = av_image_check_size(x, y, 0, NULL);
printf("%d", ret >= 0);
}
printf("\n");
}
return 0;
}

49
externals/ffmpeg/libavutil/tests/integer.c vendored Executable file
View File

@@ -0,0 +1,49 @@
/*
* 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 <stdint.h>
#include "libavutil/avassert.h"
#include "libavutil/integer.h"
#include "libavutil/intmath.h"
int main(void){
int64_t a,b;
for(a=7; a<256*256*256; a+=13215){
for(b=3; b<256*256*256; b+=27118){
AVInteger ai= av_int2i(a);
AVInteger bi= av_int2i(b);
av_assert0(av_i2int(ai) == a);
av_assert0(av_i2int(bi) == b);
av_assert0(av_i2int(av_add_i(ai,bi)) == a+b);
av_assert0(av_i2int(av_sub_i(ai,bi)) == a-b);
av_assert0(av_i2int(av_mul_i(ai,bi)) == a*b);
av_assert0(av_i2int(av_shr_i(ai, 9)) == a>>9);
av_assert0(av_i2int(av_shr_i(ai,-9)) == a<<9);
av_assert0(av_i2int(av_shr_i(ai, 17)) == a>>17);
av_assert0(av_i2int(av_shr_i(ai,-17)) == a<<17);
av_assert0(av_log2_i(ai) == av_log2(a));
av_assert0(av_i2int(av_div_i(ai,bi)) == a/b);
}
}
return 0;
}

191
externals/ffmpeg/libavutil/tests/lfg.c vendored Executable file
View File

@@ -0,0 +1,191 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/log.h"
#include "libavutil/timer.h"
#include "libavutil/lfg.h"
static const double Z_TABLE[31][10] = {
{0.5000, 0.5040, 0.5080, 0.5120, 0.5160, 0.5199, 0.5239, 0.5279, 0.5319, 0.5359},
{0.5398, 0.5438, 0.5478, 0.5517, 0.5557, 0.5596, 0.5636, 0.5675, 0.5714, 0.5753},
{0.5793, 0.5832, 0.5871, 0.5910, 0.5948, 0.5987, 0.6026, 0.6064, 0.6103, 0.6141},
{0.6179, 0.6217, 0.6255, 0.6293, 0.6331, 0.6368, 0.6406, 0.6443, 0.6480, 0.6517},
{0.6554, 0.6591, 0.6628, 0.6664, 0.6700, 0.6736, 0.6772, 0.6808, 0.6844, 0.6879},
{0.6915, 0.6950, 0.6985, 0.7019, 0.7054, 0.7088, 0.7123, 0.7157, 0.7190, 0.7224},
{0.7257, 0.7291, 0.7324, 0.7357, 0.7389, 0.7422, 0.7454, 0.7486, 0.7517, 0.7549},
{0.7580, 0.7611, 0.7642, 0.7673, 0.7704, 0.7734, 0.7764, 0.7794, 0.7823, 0.7852},
{0.7881, 0.7910, 0.7939, 0.7967, 0.7995, 0.8023, 0.8051, 0.8078, 0.8106, 0.8133},
{0.8159, 0.8186, 0.8212, 0.8238, 0.8264, 0.8289, 0.8315, 0.8340, 0.8365, 0.8389},
{0.8413, 0.8438, 0.8461, 0.8485, 0.8508, 0.8531, 0.8554, 0.8577, 0.8599, 0.8621},
{0.8643, 0.8665, 0.8686, 0.8708, 0.8729, 0.8749, 0.8770, 0.8790, 0.8810, 0.8830},
{0.8849, 0.8869, 0.8888, 0.8907, 0.8925, 0.8944, 0.8962, 0.8980, 0.8997, 0.9015},
{0.9032, 0.9049, 0.9066, 0.9082, 0.9099, 0.9115, 0.9131, 0.9147, 0.9162, 0.9177},
{0.9192, 0.9207, 0.9222, 0.9236, 0.9251, 0.9265, 0.9279, 0.9292, 0.9306, 0.9319},
{0.9332, 0.9345, 0.9357, 0.9370, 0.9382, 0.9394, 0.9406, 0.9418, 0.9429, 0.9441},
{0.9452, 0.9463, 0.9474, 0.9484, 0.9495, 0.9505, 0.9515, 0.9525, 0.9535, 0.9545},
{0.9554, 0.9564, 0.9573, 0.9582, 0.9591, 0.9599, 0.9608, 0.9616, 0.9625, 0.9633},
{0.9641, 0.9649, 0.9656, 0.9664, 0.9671, 0.9678, 0.9686, 0.9693, 0.9699, 0.9706},
{0.9713, 0.9719, 0.9726, 0.9732, 0.9738, 0.9744, 0.9750, 0.9756, 0.9761, 0.9767},
{0.9772, 0.9778, 0.9783, 0.9788, 0.9793, 0.9798, 0.9803, 0.9808, 0.9812, 0.9817},
{0.9821, 0.9826, 0.9830, 0.9834, 0.9838, 0.9842, 0.9846, 0.9850, 0.9854, 0.9857},
{0.9861, 0.9864, 0.9868, 0.9871, 0.9875, 0.9878, 0.9881, 0.9884, 0.9887, 0.9890},
{0.9893, 0.9896, 0.9898, 0.9901, 0.9904, 0.9906, 0.9909, 0.9911, 0.9913, 0.9916},
{0.9918, 0.9920, 0.9922, 0.9925, 0.9927, 0.9929, 0.9931, 0.9932, 0.9934, 0.9936},
{0.9938, 0.9940, 0.9941, 0.9943, 0.9945, 0.9946, 0.9948, 0.9949, 0.9951, 0.9952},
{0.9953, 0.9955, 0.9956, 0.9957, 0.9959, 0.9960, 0.9961, 0.9962, 0.9963, 0.9964},
{0.9965, 0.9966, 0.9967, 0.9968, 0.9969, 0.9970, 0.9971, 0.9972, 0.9973, 0.9974},
{0.9974, 0.9975, 0.9976, 0.9977, 0.9977, 0.9978, 0.9979, 0.9979, 0.9980, 0.9981},
{0.9981, 0.9982, 0.9982, 0.9983, 0.9984, 0.9984, 0.9985, 0.9985, 0.9986, 0.9986},
{0.9987, 0.9987, 0.9987, 0.9988, 0.9988, 0.9989, 0.9989, 0.9989, 0.9990, 0.9990} };
// Inverse cumulative distribution function
static double inv_cdf(double u)
{
const double a[4] = { 2.50662823884,
-18.61500062529,
41.39119773534,
-25.44106049637};
const double b[4] = {-8.47351093090,
23.08336743743,
-21.06224101826,
3.13082909833};
const double c[9] = {0.3374754822726147,
0.9761690190917186,
0.1607979714918209,
0.0276438810333863,
0.0038405729373609,
0.0003951896511919,
0.0000321767881768,
0.0000002888167364,
0.0000003960315187};
double r;
double x = u - 0.5;
// Beasley-Springer
if (fabs(x) < 0.42) {
double y = x * x;
r = x * (((a[3]*y+a[2])*y+a[1])*y+a[0]) /
((((b[3]*y+b[2])*y+b[1])*y+b[0])*y+1.0);
}
else {// Moro
r = u;
if (x > 0.0)
r = 1.0 - u;
r = log(-log(r));
r = c[0] + r*(c[1]+r*(c[2]+r*(c[3]+r*(c[4]+r*(c[5]+r*(c[6]+
r*(c[7]+r*c[8])))))));
if (x < 0.0)
r = -r;
}
return r;
}
int main(void)
{
int x = 0;
int i, j;
AVLFG state;
av_lfg_init(&state, 0xdeadbeef);
for (j = 0; j < 10000; j++) {
for (i = 0; i < 624; i++) {
//av_log(NULL, AV_LOG_ERROR, "%X\n", av_lfg_get(&state));
x += av_lfg_get(&state);
}
}
av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
/* BMG usage example */
{
double mean = 1000;
double stddev = 53;
double samp_mean = 0.0, samp_stddev = 0.0, QH = 0;
double Z, p_value = -1, tot_samp = 1000;
double *PRN_arr = av_malloc_array(tot_samp, sizeof(double));
if (!PRN_arr) {
fprintf(stderr, "failed to allocate memory!\n");
return 1;
}
av_lfg_init(&state, 42);
for (i = 0; i < tot_samp; i += 2) {
double bmg_out[2];
av_bmg_get(&state, bmg_out);
PRN_arr[i ] = bmg_out[0] * stddev + mean;
PRN_arr[i+1] = bmg_out[1] * stddev + mean;
samp_mean += PRN_arr[i] + PRN_arr[i+1];
samp_stddev += PRN_arr[i] * PRN_arr[i] + PRN_arr[i+1] * PRN_arr[i+1];
printf("PRN%d : %f\n"
"PRN%d : %f\n",
i, PRN_arr[i], i+1, PRN_arr[i+1]);
}
samp_mean /= tot_samp;
samp_stddev /= (tot_samp - 1);
samp_stddev -= (tot_samp * 1.0 / (tot_samp - 1))*samp_mean*samp_mean;
samp_stddev = sqrt(samp_stddev);
Z = (mean - samp_mean) / (stddev / sqrt(tot_samp));
{
int x, y, a, b, flag = 0;
if (Z < 0.0) {
flag = !flag;
Z = Z * -1.0;
}
a = (int)(Z * 100);
b = ((int)Z * 100);
x = Z * 10;
y = (b > 0) ? a % b : a;
y = y % 10;
if (x > 30 || y > 9) {
av_log(NULL, AV_LOG_INFO, "error: out of bounds! tried to access"
"Z_TABLE[%d][%d]\n", x, y);
goto SKIP;
}
p_value = flag ? 1 - Z_TABLE[x][y] : Z_TABLE[x][y];
}
SKIP: for (i = 0; i < tot_samp; ++i) {
if ( i < (tot_samp - 1)) {
double H_diff;
H_diff = inv_cdf((i + 2.0 - (3.0/8.0)) / (tot_samp + (1.0/4.0)));
H_diff -= inv_cdf((i + 1.0 - (3.0/8.0)) / (tot_samp + (1.0/4.0)));
QH += ((PRN_arr[i + 1] - PRN_arr[i]) / H_diff);
}
}
QH = 1.0 - QH / ((tot_samp - 1.0) * samp_stddev);
printf("sample mean : %f\n"
"true mean : %f\n"
"sample stddev: %f\n"
"true stddev : %f\n"
"z-score : %f\n"
"p-value : %f\n"
"QH[normality]: %f\n",
samp_mean, mean, samp_stddev, stddev, Z, p_value, QH);
av_freep(&PRN_arr);
}
return 0;
}

54
externals/ffmpeg/libavutil/tests/lls.c vendored Executable file
View File

@@ -0,0 +1,54 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <limits.h>
#include <stdio.h>
#include "libavutil/internal.h"
#include "libavutil/lfg.h"
#include "libavutil/lls.h"
int main(void)
{
LLSModel m;
int i, order;
AVLFG lfg;
av_lfg_init(&lfg, 1);
avpriv_init_lls(&m, 3);
for (i = 0; i < 100; i++) {
LOCAL_ALIGNED(32, double, var, [4]);
double eval;
var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
m.update_lls(&m, var);
avpriv_solve_lls(&m, 0.001, 0);
for (order = 0; order < 3; order++) {
eval = m.evaluate_lls(&m, var + 1, order);
printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
m.coeff[order][0], m.coeff[order][1],
m.coeff[order][2]);
}
}
return 0;
}

71
externals/ffmpeg/libavutil/tests/log.c vendored Executable file
View File

@@ -0,0 +1,71 @@
/*
* log functions
* Copyright (c) 2003 Michel Bardiaux
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/log.c"
#include <string.h>
static int call_log_format_line2(const char *fmt, char *buffer, int buffer_size, ...)
{
va_list args;
int ret;
int print_prefix=1;
va_start(args, buffer_size);
ret = av_log_format_line2(NULL, AV_LOG_INFO, fmt, args, buffer, buffer_size, &print_prefix);
va_end(args);
return ret;
}
int main(int argc, char **argv)
{
int i;
av_log_set_level(AV_LOG_DEBUG);
for (use_color=0; use_color<=256; use_color = 255*use_color+1) {
av_log(NULL, AV_LOG_FATAL, "use_color: %d\n", use_color);
for (i = AV_LOG_DEBUG; i>=AV_LOG_QUIET; i-=8) {
av_log(NULL, i, " %d", i);
av_log(NULL, AV_LOG_INFO, "e ");
av_log(NULL, i + 256*123, "C%d", i);
av_log(NULL, AV_LOG_INFO, "e");
}
av_log(NULL, AV_LOG_PANIC, "\n");
}
{
int result;
char buffer[4];
result = call_log_format_line2("foo", NULL, 0);
if(result != 3) {
printf("Test NULL buffer failed.\n");
return 1;
}
result = call_log_format_line2("foo", buffer, 2);
if(result != 3 || strncmp(buffer, "f", 2)) {
printf("Test buffer too small failed.\n");
return 1;
}
result = call_log_format_line2("foo", buffer, 4);
if(result != 3 || strncmp(buffer, "foo", 4)) {
printf("Test buffer sufficiently big failed.\n");
return 1;
}
}
return 0;
}

79
externals/ffmpeg/libavutil/tests/lzo.c vendored Executable file
View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2006 Reimar Doeffinger
*
* 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 <lzo/lzo1x.h>
#include "libavutil/log.h"
#include "libavutil/lzo.h"
#include "libavutil/mem.h"
#define MAXSZ (10*1024*1024)
/* Define one of these to 1 if you wish to benchmark liblzo
* instead of our native implementation. */
#define BENCHMARK_LIBLZO_SAFE 0
#define BENCHMARK_LIBLZO_UNSAFE 0
int main(int argc, char *argv[]) {
FILE *in = fopen(argv[1], "rb");
int comp_level = argc > 2 ? atoi(argv[2]) : 0;
uint8_t *orig = av_malloc(MAXSZ + 16);
uint8_t *comp = av_malloc(2*MAXSZ + 16);
uint8_t *decomp = av_malloc(MAXSZ + 16);
size_t s = fread(orig, 1, MAXSZ, in);
lzo_uint clen = 0;
long tmp[LZO1X_MEM_COMPRESS];
int inlen, outlen;
int i;
av_log_set_level(AV_LOG_DEBUG);
if (comp_level == 0) {
lzo1x_1_compress(orig, s, comp, &clen, tmp);
} else if (comp_level == 11) {
lzo1x_1_11_compress(orig, s, comp, &clen, tmp);
} else if (comp_level == 12) {
lzo1x_1_12_compress(orig, s, comp, &clen, tmp);
} else if (comp_level == 15) {
lzo1x_1_15_compress(orig, s, comp, &clen, tmp);
} else
lzo1x_999_compress(orig, s, comp, &clen, tmp);
for (i = 0; i < 300; i++) {
START_TIMER
inlen = clen; outlen = MAXSZ;
#if BENCHMARK_LIBLZO_SAFE
if (lzo1x_decompress_safe(comp, inlen, decomp, &outlen, NULL))
#elif BENCHMARK_LIBLZO_UNSAFE
if (lzo1x_decompress(comp, inlen, decomp, &outlen, NULL))
#else
if (av_lzo1x_decode(decomp, &outlen, comp, &inlen))
#endif
av_log(NULL, AV_LOG_ERROR, "decompression error\n");
STOP_TIMER("lzod")
}
if (memcmp(orig, decomp, s))
av_log(NULL, AV_LOG_ERROR, "decompression incorrect\n");
else
av_log(NULL, AV_LOG_ERROR, "decompression OK\n");
fclose(in);
av_free(orig);
av_free(comp);
av_free(decomp);
return 0;
}

55
externals/ffmpeg/libavutil/tests/md5.c vendored Executable file
View File

@@ -0,0 +1,55 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include <stdio.h>
#include "libavutil/md5.h"
static void print_md5(uint8_t *md5)
{
int i;
for (i = 0; i < 16; i++)
printf("%02x", md5[i]);
printf("\n");
}
int main(void)
{
uint8_t md5val[16];
int i;
volatile uint8_t in[1000]; // volatile to workaround http://llvm.org/bugs/show_bug.cgi?id=20849
// FIXME remove volatile once it has been fixed and all fate clients are updated
for (i = 0; i < 1000; i++)
in[i] = i * i;
av_md5_sum(md5val, in, 1000);
print_md5(md5val);
av_md5_sum(md5val, in, 63);
print_md5(md5val);
av_md5_sum(md5val, in, 64);
print_md5(md5val);
av_md5_sum(md5val, in, 65);
print_md5(md5val);
for (i = 0; i < 1000; i++)
in[i] = i % 127;
av_md5_sum(md5val, in, 999);
print_md5(md5val);
return 0;
}

58
externals/ffmpeg/libavutil/tests/murmur3.c vendored Executable file
View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/murmur3.h"
int main(void)
{
int i;
uint8_t hash_result[16] = {0};
struct AVMurMur3 *ctx = av_murmur3_alloc();
#if 1
uint8_t in[256] = {0};
uint8_t *hashes = av_mallocz(256 * 16);
for (i = 0; i < 256; i++)
{
in[i] = i;
av_murmur3_init_seeded(ctx, 256 - i);
// Note: this actually tests hashing 0 bytes
av_murmur3_update(ctx, in, i);
av_murmur3_final(ctx, hashes + 16 * i);
}
av_murmur3_init_seeded(ctx, 0);
av_murmur3_update(ctx, hashes, 256 * 16);
av_murmur3_final(ctx, hash_result);
av_free(hashes);
av_freep(&ctx);
printf("result: 0x%"PRIx64" 0x%"PRIx64"\n", AV_RL64(hash_result), AV_RL64(hash_result + 8));
// official reference value is 32 bit
return AV_RL32(hash_result) != 0x6384ba69;
#else
uint8_t *in = av_mallocz(512*1024);
av_murmur3_init(ctx);
for (i = 0; i < 40*1024; i++)
av_murmur3_update(ctx, in, 512*1024);
av_murmur3_final(ctx, hash_result);
av_free(in);
return hash_result[0];
#endif
}

358
externals/ffmpeg/libavutil/tests/opt.c vendored Executable file
View File

@@ -0,0 +1,358 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <limits.h>
#include <stdio.h>
#include "libavutil/common.h"
#include "libavutil/channel_layout.h"
#include "libavutil/error.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/rational.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
typedef struct TestContext {
const AVClass *class;
int num;
int toggle;
char *string;
int flags;
AVRational rational;
AVRational video_rate;
int w, h;
enum AVPixelFormat pix_fmt;
enum AVSampleFormat sample_fmt;
int64_t duration;
uint8_t color[4];
int64_t channel_layout;
void *binary;
int binary_size;
void *binary1;
int binary_size1;
void *binary2;
int binary_size2;
int64_t num64;
float flt;
double dbl;
char *escape;
int bool1;
int bool2;
int bool3;
AVDictionary *dict1;
AVDictionary *dict2;
} TestContext;
#define OFFSET(x) offsetof(TestContext, x)
#define TEST_FLAG_COOL 01
#define TEST_FLAG_LAME 02
#define TEST_FLAG_MU 04
static const AVOption test_options[]= {
{"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, 1 },
{"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, 1 },
{"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, 10, 1 },
{"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { .str = "default" }, CHAR_MIN, CHAR_MAX, 1 },
{"escape", "set escape str", OFFSET(escape), AV_OPT_TYPE_STRING, { .str = "\\=," }, CHAR_MIN, CHAR_MAX, 1 },
{"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 1 }, 0, INT_MAX, 1, "flags" },
{"cool", "set cool flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 1, "flags" },
{"lame", "set lame flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 1, "flags" },
{"mu", "set mu flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 1, "flags" },
{"size", "set size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, { .str="200x300" }, 0, 0, 1 },
{"pix_fmt", "set pixfmt", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, { .i64 = AV_PIX_FMT_0BGR }, -1, INT_MAX, 1 },
{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, { .i64 = AV_SAMPLE_FMT_S16 }, -1, INT_MAX, 1 },
{"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, INT_MAX, 1 },
{"duration", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 1000 }, 0, INT64_MAX, 1 },
{"color", "set color", OFFSET(color), AV_OPT_TYPE_COLOR, { .str = "pink" }, 0, 0, 1 },
{"cl", "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, { .i64 = AV_CH_LAYOUT_HEXAGONAL }, 0, INT64_MAX, 1 },
{"bin", "set binary value", OFFSET(binary), AV_OPT_TYPE_BINARY, { .str="62696e00" }, 0, 0, 1 },
{"bin1", "set binary value", OFFSET(binary1), AV_OPT_TYPE_BINARY, { .str=NULL }, 0, 0, 1 },
{"bin2", "set binary value", OFFSET(binary2), AV_OPT_TYPE_BINARY, { .str="" }, 0, 0, 1 },
{"num64", "set num 64bit", OFFSET(num64), AV_OPT_TYPE_INT64, { .i64 = 1 }, 0, 100, 1 },
{"flt", "set float", OFFSET(flt), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 / 3 }, 0, 100, 1 },
{"dbl", "set double", OFFSET(dbl), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 / 3 }, 0, 100, 1 },
{"bool1", "set boolean value", OFFSET(bool1), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, 1 },
{"bool2", "set boolean value", OFFSET(bool2), AV_OPT_TYPE_BOOL, { .i64 = 1 }, -1, 1, 1 },
{"bool3", "set boolean value", OFFSET(bool3), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 1 },
{"dict1", "set dictionary value", OFFSET(dict1), AV_OPT_TYPE_DICT, { .str = NULL}, 0, 0, 1 },
{"dict2", "set dictionary value", OFFSET(dict2), AV_OPT_TYPE_DICT, { .str = "happy=':-)'"}, 0, 0, 1 },
{ NULL },
};
static const char *test_get_name(void *ctx)
{
return "test";
}
static const AVClass test_class = {
.class_name = "TestContext",
.item_name = test_get_name,
.option = test_options,
};
static void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
{
vfprintf(stdout, fmt, vl);
}
int main(void)
{
int i;
av_log_set_level(AV_LOG_DEBUG);
av_log_set_callback(log_callback_help);
printf("Testing default values\n");
{
TestContext test_ctx = { 0 };
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
printf("num=%d\n", test_ctx.num);
printf("toggle=%d\n", test_ctx.toggle);
printf("string=%s\n", test_ctx.string);
printf("escape=%s\n", test_ctx.escape);
printf("flags=%d\n", test_ctx.flags);
printf("rational=%d/%d\n", test_ctx.rational.num, test_ctx.rational.den);
printf("video_rate=%d/%d\n", test_ctx.video_rate.num, test_ctx.video_rate.den);
printf("width=%d height=%d\n", test_ctx.w, test_ctx.h);
printf("pix_fmt=%s\n", av_get_pix_fmt_name(test_ctx.pix_fmt));
printf("sample_fmt=%s\n", av_get_sample_fmt_name(test_ctx.sample_fmt));
printf("duration=%"PRId64"\n", test_ctx.duration);
printf("color=%d %d %d %d\n", test_ctx.color[0], test_ctx.color[1], test_ctx.color[2], test_ctx.color[3]);
printf("channel_layout=%"PRId64"=%"PRId64"\n", test_ctx.channel_layout, (int64_t)AV_CH_LAYOUT_HEXAGONAL);
if (test_ctx.binary)
printf("binary=%x %x %x %x\n", ((uint8_t*)test_ctx.binary)[0], ((uint8_t*)test_ctx.binary)[1], ((uint8_t*)test_ctx.binary)[2], ((uint8_t*)test_ctx.binary)[3]);
printf("binary_size=%d\n", test_ctx.binary_size);
printf("num64=%"PRId64"\n", test_ctx.num64);
printf("flt=%.6f\n", test_ctx.flt);
printf("dbl=%.6f\n", test_ctx.dbl);
av_opt_show2(&test_ctx, NULL, -1, 0);
av_opt_free(&test_ctx);
}
printf("\nTesting av_opt_is_set_to_default()\n");
{
int ret;
TestContext test_ctx = { 0 };
const AVOption *o = NULL;
test_ctx.class = &test_class;
av_log_set_level(AV_LOG_QUIET);
while (o = av_opt_next(&test_ctx, o)) {
ret = av_opt_is_set_to_default_by_name(&test_ctx, o->name, 0);
printf("name:%10s default:%d error:%s\n", o->name, !!ret, ret < 0 ? av_err2str(ret) : "");
}
av_opt_set_defaults(&test_ctx);
while (o = av_opt_next(&test_ctx, o)) {
ret = av_opt_is_set_to_default_by_name(&test_ctx, o->name, 0);
printf("name:%10s default:%d error:%s\n", o->name, !!ret, ret < 0 ? av_err2str(ret) : "");
}
av_opt_free(&test_ctx);
}
printf("\nTesting av_opt_get/av_opt_set()\n");
{
TestContext test_ctx = { 0 };
TestContext test2_ctx = { 0 };
const AVOption *o = NULL;
test_ctx.class = &test_class;
test2_ctx.class = &test_class;
av_log_set_level(AV_LOG_QUIET);
av_opt_set_defaults(&test_ctx);
while (o = av_opt_next(&test_ctx, o)) {
char *value1 = NULL;
char *value2 = NULL;
int ret1 = AVERROR_BUG;
int ret2 = AVERROR_BUG;
int ret3 = AVERROR_BUG;
if (o->type == AV_OPT_TYPE_CONST)
continue;
ret1 = av_opt_get(&test_ctx, o->name, 0, (uint8_t **)&value1);
if (ret1 >= 0) {
ret2 = av_opt_set(&test2_ctx, o->name, value1, 0);
if (ret2 >= 0)
ret3 = av_opt_get(&test2_ctx, o->name, 0, (uint8_t **)&value2);
}
printf("name: %-11s get: %-16s set: %-16s get: %-16s %s\n", o->name,
ret1 >= 0 ? value1 : av_err2str(ret1),
ret2 >= 0 ? "OK" : av_err2str(ret2),
ret3 >= 0 ? value2 : av_err2str(ret3),
ret1 >= 0 && ret2 >= 0 && ret3 >= 0 && !strcmp(value1, value2) ? "OK" : "Mismatch");
av_free(value1);
av_free(value2);
}
av_opt_free(&test_ctx);
av_opt_free(&test2_ctx);
}
printf("\nTest av_opt_serialize()\n");
{
TestContext test_ctx = { 0 };
char *buf;
test_ctx.class = &test_class;
av_log_set_level(AV_LOG_QUIET);
av_opt_set_defaults(&test_ctx);
if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
printf("%s\n", buf);
av_opt_free(&test_ctx);
memset(&test_ctx, 0, sizeof(test_ctx));
test_ctx.class = &test_class;
av_set_options_string(&test_ctx, buf, "=", ",");
av_free(buf);
if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
printf("%s\n", buf);
av_free(buf);
}
}
av_opt_free(&test_ctx);
}
printf("\nTesting av_set_options_string()\n");
{
TestContext test_ctx = { 0 };
static const char * const options[] = {
"",
":",
"=",
"foo=:",
":=foo",
"=foo",
"foo=",
"foo",
"foo=val",
"foo==val",
"toggle=:",
"string=:",
"toggle=1 : foo",
"toggle=100",
"toggle==1",
"flags=+mu-lame : num=42: toggle=0",
"num=42 : string=blahblah",
"rational=0 : rational=1/2 : rational=1/-1",
"rational=-1/0",
"size=1024x768",
"size=pal",
"size=bogus",
"pix_fmt=yuv420p",
"pix_fmt=2",
"pix_fmt=bogus",
"sample_fmt=s16",
"sample_fmt=2",
"sample_fmt=bogus",
"video_rate=pal",
"video_rate=25",
"video_rate=30000/1001",
"video_rate=30/1.001",
"video_rate=bogus",
"duration=bogus",
"duration=123.45",
"duration=1\\:23\\:45.67",
"color=blue",
"color=0x223300",
"color=0x42FF07AA",
"cl=stereo+downmix",
"cl=foo",
"bin=boguss",
"bin=111",
"bin=ffff",
"num64=bogus",
"num64=44",
"num64=44.4",
"num64=-1",
"num64=101",
"flt=bogus",
"flt=2",
"flt=2.2",
"flt=-1",
"flt=101",
"dbl=bogus",
"dbl=2",
"dbl=2.2",
"dbl=-1",
"dbl=101",
"bool1=true",
"bool2=auto",
"dict1='happy=\\:-):sad=\\:-('",
};
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
av_log_set_level(AV_LOG_QUIET);
for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
int silence_log = !strcmp(options[i], "rational=-1/0"); // inf formating differs between platforms
av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
if (silence_log)
av_log_set_callback(NULL);
if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
printf("Error '%s'\n", options[i]);
else
printf("OK '%s'\n", options[i]);
av_log_set_callback(log_callback_help);
}
av_opt_free(&test_ctx);
}
printf("\nTesting av_opt_set_from_string()\n");
{
TestContext test_ctx = { 0 };
static const char * const options[] = {
"",
"5",
"5:hello",
"5:hello:size=pal",
"5:size=pal:hello",
":",
"=",
" 5 : hello : size = pal ",
"a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
};
static const char * const shorthand[] = { "num", "string", NULL };
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
av_log_set_level(AV_LOG_QUIET);
for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
if (av_opt_set_from_string(&test_ctx, options[i], shorthand, "=", ":") < 0)
printf("Error '%s'\n", options[i]);
else
printf("OK '%s'\n", options[i]);
}
av_opt_free(&test_ctx);
}
return 0;
}

271
externals/ffmpeg/libavutil/tests/parseutils.c vendored Executable file
View File

@@ -0,0 +1,271 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define TEST
#include "libavutil/parseutils.c"
#include <stdint.h>
#include <stdio.h>
#include "libavutil/common.h"
#include "libavutil/log.h"
#include "libavutil/rational.h"
static uint32_t randomv = MKTAG('L','A','V','U');
static uint32_t av_get_random_seed_deterministic(void)
{
return randomv = randomv * 1664525 + 1013904223;
}
static void test_av_parse_video_rate(void)
{
int i;
static const char *const rates[] = {
"-inf",
"inf",
"nan",
"123/0",
"-123 / 0",
"",
"/",
" 123 / 321",
"foo/foo",
"foo/1",
"1/foo",
"0/0",
"/0",
"1/",
"1",
"0",
"-123/123",
"-foo",
"123.23",
".23",
"-.23",
"-0.234",
"-0.0000001",
" 21332.2324 ",
" -21332.2324 ",
};
for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
int ret;
AVRational q = { 0, 0 };
ret = av_parse_video_rate(&q, rates[i]);
printf("'%s' -> %d/%d %s\n",
rates[i], q.num, q.den, ret ? "ERROR" : "OK");
}
}
static void test_av_parse_color(void)
{
int i;
uint8_t rgba[4];
static const char *const color_names[] = {
"bikeshed",
"RaNdOm",
"foo",
"red",
"Red ",
"RED",
"Violet",
"Yellow",
"Red",
"0x000000",
"0x0000000",
"0xff000000",
"0x3e34ff",
"0x3e34ffaa",
"0xffXXee",
"0xfoobar",
"0xffffeeeeeeee",
"#ff0000",
"#ffXX00",
"ff0000",
"ffXX00",
"red@foo",
"random@10",
"0xff0000@1.0",
"red@",
"red@0xfff",
"red@0xf",
"red@2",
"red@0.1",
"red@-1",
"red@0.5",
"red@1.0",
"red@256",
"red@10foo",
"red@-1.0",
"red@-0.0",
};
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
else
printf("%s -> error\n", color_names[i]);
}
}
static void test_av_small_strptime(void)
{
int i;
struct tm tm = { 0 };
struct fmt_timespec_entry {
const char *fmt, *timespec;
} fmt_timespec_entries[] = {
{ "%Y-%m-%d", "2012-12-21" },
{ "%Y - %m - %d", "2012-12-21" },
{ "%Y-%m-%d %H:%M:%S", "2012-12-21 20:12:21" },
{ " %Y - %m - %d %H : %M : %S", " 2012 - 12 - 21 20 : 12 : 21" },
{ " %Y - %b - %d %H : %M : %S", " 2012 - nOV - 21 20 : 12 : 21" },
{ " %Y - %B - %d %H : %M : %S", " 2012 - nOVemBeR - 21 20 : 12 : 21" },
{ " %Y - %B%d %H : %M : %S", " 2012 - may21 20 : 12 : 21" },
{ " %Y - %B%d %H : %M : %S", " 2012 - mby21 20 : 12 : 21" },
{ " %Y - %B - %d %H : %M : %S", " 2012 - JunE - 21 20 : 12 : 21" },
{ " %Y - %B - %d %H : %M : %S", " 2012 - Jane - 21 20 : 12 : 21" },
{ " %Y - %B - %d %H : %M : %S", " 2012 - January - 21 20 : 12 : 21" },
};
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < FF_ARRAY_ELEMS(fmt_timespec_entries); i++) {
char *p;
struct fmt_timespec_entry *e = &fmt_timespec_entries[i];
printf("fmt:'%s' spec:'%s' -> ", e->fmt, e->timespec);
p = av_small_strptime(e->timespec, e->fmt, &tm);
if (p) {
printf("%04d-%02d-%2d %02d:%02d:%02d\n",
1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
} else {
printf("error\n");
}
}
}
static void test_av_parse_time(void)
{
int i;
int64_t tv;
time_t tvi;
struct tm *tm;
static char tzstr[] = "TZ=CET-1";
static const char * const time_string[] = {
"now",
"12:35:46",
"2000-12-20 0:02:47.5z",
"2012 - 02-22 17:44:07",
"2000-12-20T010247.6",
"2000-12-12 1:35:46+05:30",
"2002-12-12 22:30:40-02",
};
static const char * const duration_string[] = {
"2:34:56.79",
"-1:23:45.67",
"42.1729",
"-1729.42",
"12:34",
"2147483648s",
"4294967296ms",
"8589934592us",
"9223372036854775808us",
};
av_log_set_level(AV_LOG_DEBUG);
putenv(tzstr);
printf("(now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1)\n");
for (i = 0; i < FF_ARRAY_ELEMS(time_string); i++) {
printf("%-24s -> ", time_string[i]);
if (av_parse_time(&tv, time_string[i], 0)) {
printf("error\n");
} else {
tvi = tv / 1000000;
tm = gmtime(&tvi);
printf("%14"PRIi64".%06d = %04d-%02d-%02dT%02d:%02d:%02dZ\n",
tv / 1000000, (int)(tv % 1000000),
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
}
for (i = 0; i < FF_ARRAY_ELEMS(duration_string); i++) {
printf("%-24s -> ", duration_string[i]);
if (av_parse_time(&tv, duration_string[i], 1)) {
printf("error\n");
} else {
printf("%+21"PRIi64"\n", tv);
}
}
}
static void test_av_get_known_color_name(void)
{
int i;
const uint8_t *rgba;
const char *color;
for (i = 0; i < FF_ARRAY_ELEMS(color_table); ++i) {
color = av_get_known_color_name(i, &rgba);
if (color)
printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
color, rgba[0], rgba[1], rgba[2], rgba[3]);
else
printf("Color ID: %d not found\n", i);
}
}
static void test_av_find_info_tag(void)
{
static const char args[] = "?tag1=val1&tag2=val2&tag3=val3&tag41=value 41&tag42=random1";
static const char *tags[] = {"tag1", "tag2", "tag3", "tag4", "tag41", "41", "random1"};
char buff[16];
int i;
for (i = 0; i < FF_ARRAY_ELEMS(tags); ++i) {
if (av_find_info_tag(buff, sizeof(buff), tags[i], args))
printf("%d. %s found: %s\n", i, tags[i], buff);
else
printf("%d. %s not found\n", i, tags[i]);
}
}
int main(void)
{
printf("Testing av_parse_video_rate()\n");
test_av_parse_video_rate();
printf("\nTesting av_parse_color()\n");
test_av_parse_color();
printf("\nTesting av_small_strptime()\n");
test_av_small_strptime();
printf("\nTesting av_parse_time()\n");
test_av_parse_time();
printf("\nTesting av_get_known_color_name()\n");
test_av_get_known_color_name();
printf("\nTesting av_find_info_tag()\n");
test_av_find_info_tag();
return 0;
}

102
externals/ffmpeg/libavutil/tests/pca.c vendored Executable file
View File

@@ -0,0 +1,102 @@
/*
* principal component analysis (PCA)
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/pca.c"
#include "libavutil/lfg.h"
#undef printf
#include <stdio.h>
#include <stdlib.h>
int main(void){
PCA *pca;
int i, j, k;
#define LEN 8
double eigenvector[LEN*LEN];
double eigenvalue[LEN];
AVLFG prng;
av_lfg_init(&prng, 1);
pca= ff_pca_init(LEN);
for(i=0; i<9000000; i++){
double v[2*LEN+100];
double sum=0;
int pos = av_lfg_get(&prng) % LEN;
int v2 = av_lfg_get(&prng) % 101 - 50;
v[0] = av_lfg_get(&prng) % 101 - 50;
for(j=1; j<8; j++){
if(j<=pos) v[j]= v[0];
else v[j]= v2;
sum += v[j];
}
/* for(j=0; j<LEN; j++){
v[j] -= v[pos];
}*/
// sum += av_lfg_get(&prng) % 10;
/* for(j=0; j<LEN; j++){
v[j] -= sum/LEN;
}*/
// lbt1(v+100,v+100,LEN);
ff_pca_add(pca, v);
}
ff_pca(pca, eigenvector, eigenvalue);
for(i=0; i<LEN; i++){
pca->count= 1;
pca->mean[i]= 0;
// (0.5^|x|)^2 = 0.5^2|x| = 0.25^|x|
// pca.covariance[i + i*LEN]= pow(0.5, fabs
for(j=i; j<LEN; j++){
printf("%f ", pca->covariance[i + j*LEN]);
}
printf("\n");
}
for(i=0; i<LEN; i++){
double v[LEN];
double error=0;
memset(v, 0, sizeof(v));
for(j=0; j<LEN; j++){
for(k=0; k<LEN; k++){
v[j] += pca->covariance[FFMIN(k,j) + FFMAX(k,j)*LEN] * eigenvector[i + k*LEN];
}
v[j] /= eigenvalue[i];
error += fabs(v[j] - eigenvector[i + j*LEN]);
}
printf("%f ", error);
}
printf("\n");
for(i=0; i<LEN; i++){
for(j=0; j<LEN; j++){
printf("%9.6f ", eigenvector[i + j*LEN]);
}
printf(" %9.1f %f\n", eigenvalue[i], eigenvalue[i]/eigenvalue[0]);
}
return 0;
}

42
externals/ffmpeg/libavutil/tests/pixdesc.c vendored Executable file
View File

@@ -0,0 +1,42 @@
/*
* pixel format descriptor
* Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/pixdesc.c"
int main(void){
int i;
int err=0;
int skip = 0;
for (i=0; i<AV_PIX_FMT_NB*2; i++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
if(!desc || !desc->name) {
skip ++;
continue;
}
if (skip) {
av_log(NULL, AV_LOG_INFO, "%3d unused pixel format values\n", skip);
skip = 0;
}
av_log(NULL, AV_LOG_INFO, "pix fmt %s avg_bpp:%d colortype:%d\n", desc->name, av_get_padded_bits_per_pixel(desc), get_color_type(desc));
}
return err;
}

152
externals/ffmpeg/libavutil/tests/pixelutils.c vendored Executable file
View File

@@ -0,0 +1,152 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/pixelutils.c"
#define W1 320
#define H1 240
#define W2 640
#define H2 480
static int run_single_test(const char *test,
const uint8_t *block1, ptrdiff_t stride1,
const uint8_t *block2, ptrdiff_t stride2,
int align, int n)
{
int out, ref;
av_pixelutils_sad_fn f_ref = sad_c[n - 1];
av_pixelutils_sad_fn f_out = av_pixelutils_get_sad_fn(n, n, align, NULL);
switch (align) {
case 0: block1++; block2++; break;
case 1: block2++; break;
case 2: break;
}
out = f_out(block1, stride1, block2, stride2);
ref = f_ref(block1, stride1, block2, stride2);
printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
out == ref ? "OK" : "FAIL",
align ? 'A' : 'U', align == 2 ? 'A' : 'U',
test, 1<<n, 1<<n, out, ref);
return out != ref;
}
static int run_test(const char *test,
const uint8_t *b1, const uint8_t *b2)
{
int i, a, ret = 0;
for (a = 0; a < 3; a++) {
const uint8_t *block1 = b1;
const uint8_t *block2 = b2;
switch (a) {
case 0: block1++; block2++; break;
case 1: block2++; break;
case 2: break;
}
for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) {
int r = run_single_test(test, b1, W1, b2, W2, a, i);
if (r)
ret = r;
}
}
return ret;
}
int main(void)
{
int i, align, ret;
uint8_t *buf1 = av_malloc(W1*H1);
uint8_t *buf2 = av_malloc(W2*H2);
uint32_t state = 0;
if (!buf1 || !buf2) {
fprintf(stderr, "malloc failure\n");
ret = 1;
goto end;
}
ff_check_pixfmt_descriptors();
#define RANDOM_INIT(buf, size) do { \
int k; \
for (k = 0; k < size; k++) { \
state = state * 1664525 + 1013904223; \
buf[k] = state>>24; \
} \
} while (0)
/* Normal test with different strides */
RANDOM_INIT(buf1, W1*H1);
RANDOM_INIT(buf2, W2*H2);
ret = run_test("random", buf1, buf2);
if (ret < 0)
goto end;
/* Check for maximum SAD */
memset(buf1, 0xff, W1*H1);
memset(buf2, 0x00, W2*H2);
ret = run_test("max", buf1, buf2);
if (ret < 0)
goto end;
/* Check for minimum SAD */
memset(buf1, 0x90, W1*H1);
memset(buf2, 0x90, W2*H2);
ret = run_test("min", buf1, buf2);
if (ret < 0)
goto end;
/* Exact buffer sizes, to check for overreads */
for (i = 1; i <= 5; i++) {
for (align = 0; align < 3; align++) {
int size1, size2;
av_freep(&buf1);
av_freep(&buf2);
size1 = size2 = 1 << (i << 1);
switch (align) {
case 0: size1++; size2++; break;
case 1: size2++; break;
case 2: break;
}
buf1 = av_malloc(size1);
buf2 = av_malloc(size2);
if (!buf1 || !buf2) {
fprintf(stderr, "malloc failure\n");
ret = 1;
goto end;
}
RANDOM_INIT(buf1, size1);
RANDOM_INIT(buf2, size2);
ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i);
if (ret < 0)
goto end;
}
}
end:
av_free(buf1);
av_free(buf2);
return ret;
}

140
externals/ffmpeg/libavutil/tests/pixfmt_best.c vendored Executable file
View File

@@ -0,0 +1,140 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/pixdesc.c"
static const enum AVPixelFormat pixfmt_list[] = {
AV_PIX_FMT_MONOWHITE,
AV_PIX_FMT_GRAY8,
AV_PIX_FMT_GRAY10,
AV_PIX_FMT_GRAY16,
AV_PIX_FMT_YUV420P,
AV_PIX_FMT_YUV420P10,
AV_PIX_FMT_YUV420P16,
AV_PIX_FMT_YUV422P,
AV_PIX_FMT_YUV422P10,
AV_PIX_FMT_YUV422P16,
AV_PIX_FMT_YUV444P,
AV_PIX_FMT_YUV444P10,
AV_PIX_FMT_YUV444P16,
AV_PIX_FMT_RGB565,
AV_PIX_FMT_RGB24,
AV_PIX_FMT_RGB48,
AV_PIX_FMT_VDPAU,
AV_PIX_FMT_VAAPI,
};
static enum AVPixelFormat find_best(enum AVPixelFormat pixfmt)
{
enum AVPixelFormat best = AV_PIX_FMT_NONE;
int i;
for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
best = av_find_best_pix_fmt_of_2(best, pixfmt_list[i],
pixfmt, 0, NULL);
return best;
}
int main(void)
{
enum AVPixelFormat output;
int i, pass = 0, fail = 0;
#define TEST(input, expected) do { \
output = find_best(input); \
if (output != expected) { \
printf("Matching %s: got %s, expected %s\n", \
av_get_pix_fmt_name(input), \
av_get_pix_fmt_name(output), \
av_get_pix_fmt_name(expected)); \
++fail; \
} else \
++pass; \
} while (0)
// Same formats.
for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
TEST(pixfmt_list[i], pixfmt_list[i]);
// Formats containing the same data in different layouts.
TEST(AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_MONOWHITE);
TEST(AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P);
TEST(AV_PIX_FMT_P010, AV_PIX_FMT_YUV420P10);
TEST(AV_PIX_FMT_P016, AV_PIX_FMT_YUV420P16);
TEST(AV_PIX_FMT_NV16, AV_PIX_FMT_YUV422P);
TEST(AV_PIX_FMT_NV24, AV_PIX_FMT_YUV444P);
TEST(AV_PIX_FMT_YUYV422, AV_PIX_FMT_YUV422P);
TEST(AV_PIX_FMT_UYVY422, AV_PIX_FMT_YUV422P);
TEST(AV_PIX_FMT_BGR565, AV_PIX_FMT_RGB565);
TEST(AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24);
TEST(AV_PIX_FMT_GBRP, AV_PIX_FMT_RGB24);
TEST(AV_PIX_FMT_0RGB, AV_PIX_FMT_RGB24);
TEST(AV_PIX_FMT_GBRP16, AV_PIX_FMT_RGB48);
// Formats additionally containing alpha (here ignored).
TEST(AV_PIX_FMT_YA8, AV_PIX_FMT_GRAY8);
TEST(AV_PIX_FMT_YA16, AV_PIX_FMT_GRAY16);
TEST(AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P);
TEST(AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P);
TEST(AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P);
TEST(AV_PIX_FMT_AYUV64, AV_PIX_FMT_YUV444P16);
TEST(AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB24);
TEST(AV_PIX_FMT_ABGR, AV_PIX_FMT_RGB24);
TEST(AV_PIX_FMT_GBRAP, AV_PIX_FMT_RGB24);
TEST(AV_PIX_FMT_RGBA64, AV_PIX_FMT_RGB48);
TEST(AV_PIX_FMT_BGRA64, AV_PIX_FMT_RGB48);
TEST(AV_PIX_FMT_GBRAP16, AV_PIX_FMT_RGB48);
// Formats requiring upsampling to represent exactly.
TEST(AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY16);
TEST(AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV420P);
TEST(AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV422P);
TEST(AV_PIX_FMT_UYYVYY411, AV_PIX_FMT_YUV422P);
TEST(AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P);
TEST(AV_PIX_FMT_YUV440P10, AV_PIX_FMT_YUV444P10);
TEST(AV_PIX_FMT_YUV440P12, AV_PIX_FMT_YUV444P16);
TEST(AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV420P10);
TEST(AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV420P16);
TEST(AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10);
TEST(AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P16);
TEST(AV_PIX_FMT_BGR4, AV_PIX_FMT_RGB565);
TEST(AV_PIX_FMT_RGB444, AV_PIX_FMT_RGB565);
TEST(AV_PIX_FMT_RGB555, AV_PIX_FMT_RGB565);
TEST(AV_PIX_FMT_GBRP10, AV_PIX_FMT_RGB48);
TEST(AV_PIX_FMT_GBRAP10, AV_PIX_FMT_RGB48);
TEST(AV_PIX_FMT_GBRAP12, AV_PIX_FMT_RGB48);
// Formats containing the same data in different endianness.
TEST(AV_PIX_FMT_GRAY10BE, AV_PIX_FMT_GRAY10);
TEST(AV_PIX_FMT_GRAY10LE, AV_PIX_FMT_GRAY10);
TEST(AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_GRAY16);
TEST(AV_PIX_FMT_GRAY16LE, AV_PIX_FMT_GRAY16);
TEST(AV_PIX_FMT_YUV422P10BE, AV_PIX_FMT_YUV422P10);
TEST(AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUV422P10);
TEST(AV_PIX_FMT_YUV444P16BE, AV_PIX_FMT_YUV444P16);
TEST(AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUV444P16);
TEST(AV_PIX_FMT_RGB565BE, AV_PIX_FMT_RGB565);
TEST(AV_PIX_FMT_RGB565LE, AV_PIX_FMT_RGB565);
TEST(AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGB48);
TEST(AV_PIX_FMT_RGB48LE, AV_PIX_FMT_RGB48);
// Opaque formats are least unlike each other.
TEST(AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_VDPAU);
printf("%d tests passed, %d tests failed.\n", pass, fail);
return !!fail;
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define TEST 1
#include "libavutil/random_seed.c"
#undef printf
#define N 256
#define F 2
#include <stdio.h>
typedef uint32_t (*random_seed_ptr_t)(void);
int main(void)
{
int i, j, rsf, retry;
uint32_t seeds[N];
random_seed_ptr_t random_seed[F] = {av_get_random_seed, get_generic_seed};
for (rsf=0; rsf<F; ++rsf){
for (retry=0; retry<3; retry++){
for (i=0; i<N; i++){
seeds[i] = random_seed[rsf]();
for (j=0; j<i; j++)
if (seeds[j] == seeds[i])
goto retry;
}
printf("seeds OK\n");
break;
retry:;
}
if (retry >= 3) {
printf("rsf %d: FAIL at %d with %"PRIX32"\n", rsf, j, seeds[j]);
return 1;
}
}
return 0;
}

134
externals/ffmpeg/libavutil/tests/rational.c vendored Executable file
View File

@@ -0,0 +1,134 @@
/*
* rational numbers
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/rational.c"
#include "libavutil/integer.h"
int main(void)
{
AVRational a,b,r;
int i,j,k;
static const int64_t numlist[] = {
INT64_MIN, INT64_MIN+1, INT64_MAX, INT32_MIN, INT32_MAX, 1,0,-1,
123456789, INT32_MAX-1, INT32_MAX+1LL, UINT32_MAX-1, UINT32_MAX, UINT32_MAX+1LL
};
for (a.num = -2; a.num <= 2; a.num++) {
for (a.den = -2; a.den <= 2; a.den++) {
for (b.num = -2; b.num <= 2; b.num++) {
for (b.den = -2; b.den <= 2; b.den++) {
int c = av_cmp_q(a,b);
double d = av_q2d(a) == av_q2d(b) ?
0 : (av_q2d(a) - av_q2d(b));
if (d > 0) d = 1;
else if (d < 0) d = -1;
else if (d != d) d = INT_MIN;
if (c != d)
av_log(NULL, AV_LOG_ERROR, "%d/%d %d/%d, %d %f\n", a.num,
a.den, b.num, b.den, c,d);
r = av_sub_q(av_add_q(b,a), b);
if(b.den && (r.num*a.den != a.num*r.den || !r.num != !a.num || !r.den != !a.den))
av_log(NULL, AV_LOG_ERROR, "%d/%d ", r.num, r.den);
}
}
}
}
for (i = 0; i < FF_ARRAY_ELEMS(numlist); i++) {
int64_t a = numlist[i];
for (j = 0; j < FF_ARRAY_ELEMS(numlist); j++) {
int64_t b = numlist[j];
if (b<=0)
continue;
for (k = 0; k < FF_ARRAY_ELEMS(numlist); k++) {
int64_t c = numlist[k];
int64_t res;
AVInteger ai;
if (c<=0)
continue;
res = av_rescale_rnd(a,b,c, AV_ROUND_ZERO);
ai = av_mul_i(av_int2i(a), av_int2i(b));
ai = av_div_i(ai, av_int2i(c));
if (av_cmp_i(ai, av_int2i(INT64_MAX)) > 0 && res == INT64_MIN)
continue;
if (av_cmp_i(ai, av_int2i(INT64_MIN)) < 0 && res == INT64_MIN)
continue;
if (av_cmp_i(ai, av_int2i(res)) == 0)
continue;
// Special exception for INT64_MIN, remove this in case INT64_MIN is handled without off by 1 error
if (av_cmp_i(ai, av_int2i(res-1)) == 0 && a == INT64_MIN)
continue;
av_log(NULL, AV_LOG_ERROR, "%"PRId64" * %"PRId64" / %"PRId64" = %"PRId64" or %"PRId64"\n", a,b,c, res, av_i2int(ai));
}
}
}
for (a.num = 1; a.num <= 10; a.num++) {
for (a.den = 1; a.den <= 10; a.den++) {
if (av_gcd(a.num, a.den) > 1)
continue;
for (b.num = 1; b.num <= 10; b.num++) {
for (b.den = 1; b.den <= 10; b.den++) {
int start;
if (av_gcd(b.num, b.den) > 1)
continue;
if (av_cmp_q(b, a) < 0)
continue;
for (start = 0; start < 10 ; start++) {
int acc= start;
int i;
for (i = 0; i<100; i++) {
int exact = start + av_rescale_q(i+1, b, a);
acc = av_add_stable(a, acc, b, 1);
if (FFABS(acc - exact) > 2) {
av_log(NULL, AV_LOG_ERROR, "%d/%d %d/%d, %d %d\n", a.num,
a.den, b.num, b.den, acc, exact);
return 1;
}
}
}
}
}
}
}
for (a.den = 1; a.den < 0x100000000U/3; a.den*=3) {
for (a.num = -1; a.num < (1<<27); a.num += 1 + a.num/100) {
float f = av_int2float(av_q2intfloat(a));
float f2 = av_q2d(a);
if (fabs(f - f2) > fabs(f)/5000000) {
av_log(NULL, AV_LOG_ERROR, "%d/%d %f %f\n", a.num,
a.den, f, f2);
return 1;
}
}
}
return 0;
}

80
externals/ffmpeg/libavutil/tests/ripemd.c vendored Executable file
View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
* Copyright (C) 2013 James Almer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include "libavutil/mem.h"
#include "libavutil/ripemd.h"
int main(void)
{
int i, j, k;
struct AVRIPEMD *ctx;
unsigned char digest[40];
static const int lengths[4] = { 128, 160, 256, 320 };
ctx = av_ripemd_alloc();
if (!ctx)
return 1;
for (j = 0; j < 4; j++) {
printf("Testing RIPEMD-%d\n", lengths[j]);
for (k = 0; k < 3; k++) {
av_ripemd_init(ctx, lengths[j]);
if (k == 0)
av_ripemd_update(ctx, "abc", 3);
else if (k == 1)
av_ripemd_update(ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
else
for (i = 0; i < 1000*1000; i++)
av_ripemd_update(ctx, "a", 1);
av_ripemd_final(ctx, digest);
for (i = 0; i < lengths[j] >> 3; i++)
printf("%02X", digest[i]);
putchar('\n');
}
switch (j) { //test vectors (from ISO:IEC 10118-3 (2004) and http://homes.esat.kuleuven.be/~bosselae/ripemd160.html)
case 0:
printf("c14a1219 9c66e4ba 84636b0f 69144c77\n"
"a1aa0689 d0fafa2d dc22e88b 49133a06\n"
"4a7f5723 f954eba1 216c9d8f 6320431f\n");
break;
case 1:
printf("8eb208f7 e05d987a 9b044a8e 98c6b087 f15a0bfc\n"
"12a05338 4a9c0c88 e405a06c 27dcf49a da62eb2b\n"
"52783243 c1697bdb e16d37f9 7f68f083 25dc1528\n");
break;
case 2:
printf("afbd6e22 8b9d8cbb cef5ca2d 03e6dba1 0ac0bc7d cbe4680e 1e42d2e9 75459b65\n"
"38430455 83aac6c8 c8d91285 73e7a980 9afb2a0f 34ccc36e a9e72f16 f6368e3f\n"
"ac953744 e10e3151 4c150d4d 8d7b6773 42e33399 788296e4 3ae4850c e4f97978\n");
break;
case 3:
printf("de4c01b3 054f8930 a79d09ae 738e9230 1e5a1708 5beffdc1 b8d11671 3e74f82f a942d64c dbc4682d\n"
"d034a795 0cf72202 1ba4b84d f769a5de 2060e259 df4c9bb4 a4268c0e 935bbc74 70a969c9 d072a1ac\n"
"bdee37f4 371e2064 6b8b0d86 2dda1629 2ae36f40 965e8c85 09e63d1d bddecc50 3e2b63eb 9245bb66\n");
break;
}
}
av_free(ctx);
return 0;
}

75
externals/ffmpeg/libavutil/tests/sha.c vendored Executable file
View File

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

90
externals/ffmpeg/libavutil/tests/sha512.c vendored Executable file
View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
* Copyright (C) 2009 Konstantin Shishkov
* Copyright (C) 2013 James Almer
* based on BSD-licensed SHA-2 code by Aaron D. Gifford
*
* 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/mem.h"
#include "libavutil/sha512.h"
int main(void)
{
int i, j, k;
struct AVSHA512 *ctx;
unsigned char digest[64];
static const int lengths[4] = { 224, 256, 384, 512 };
ctx = av_sha512_alloc();
if (!ctx)
return 1;
for (j = 0; j < 4; j++) {
if (j < 2) printf("Testing SHA-512/%d\n", lengths[j]);
else printf("Testing SHA-%d\n", lengths[j]);
for (k = 0; k < 3; k++) {
av_sha512_init(ctx, lengths[j]);
if (k == 0)
av_sha512_update(ctx, "abc", 3);
else if (k == 1)
av_sha512_update(ctx, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", 112);
else
for (i = 0; i < 1000*1000; i++)
av_sha512_update(ctx, "a", 1);
av_sha512_final(ctx, digest);
for (i = 0; i < lengths[j] >> 3; i++)
printf("%02X", digest[i]);
putchar('\n');
}
switch (j) { //test vectors (from FIPS PUB 180-4 Apendix A)
case 0:
printf("4634270f 707b6a54 daae7530 460842e2 0e37ed26 5ceee9a4 3e8924aa\n"
"23fec5bb 94d60b23 30819264 0b0c4533 35d66473 4fe40e72 68674af9\n"
"37ab331d 76f0d36d e422bd0e deb22a28 accd487b 7a8453ae 965dd287\n");
break;
case 1:
printf("53048e26 81941ef9 9b2e29b7 6b4c7dab e4c2d0c6 34fc6d46 e0e2f131 07e7af23\n"
"3928e184 fb8690f8 40da3988 121d31be 65cb9d3e f83ee614 6feac861 e19b563a\n"
"9a59a052 930187a9 7038cae6 92f30708 aa649192 3ef51943 94dc68d5 6c74fb21\n");
break;
case 2:
printf("cb00753f 45a35e8b b5a03d69 9ac65007 272c32ab 0eded163 "
"1a8b605a 43ff5bed 8086072b a1e7cc23 58baeca1 34c825a7\n"
"09330c33 f71147e8 3d192fc7 82cd1b47 53111b17 3b3b05d2 "
"2fa08086 e3b0f712 fcc7c71a 557e2db9 66c3e9fa 91746039\n"
"9d0e1809 716474cb 086e834e 310a4a1c ed149e9c 00f24852 "
"7972cec5 704c2a5b 07b8b3dc 38ecc4eb ae97ddd8 7f3d8985\n");
break;
case 3:
printf("ddaf35a1 93617aba cc417349 ae204131 12e6fa4e 89a97ea2 0a9eeee6 4b55d39a "
"2192992a 274fc1a8 36ba3c23 a3feebbd 454d4423 643ce80e 2a9ac94f a54ca49f\n"
"8e959b75 dae313da 8cf4f728 14fc143f 8f7779c6 eb9f7fa1 7299aead b6889018 "
"501d289e 4900f7e4 331b99de c4b5433a c7d329ee b6dd2654 5e96e55b 874be909\n"
"e718483d 0ce76964 4e2e42c7 bc15b463 8e1f98b1 3b204428 5632a803 afa973eb "
"de0ff244 877ea60a 4cb0432c e577c31b eb009c5c 2c49aa2e 4eadb217 ad8cc09b\n");
break;
}
}
av_free(ctx);
return 0;
}

158
externals/ffmpeg/libavutil/tests/softfloat.c vendored Executable file
View File

@@ -0,0 +1,158 @@
/*
* copyright (c) 2006 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 "libavutil/timer.h"
#include <inttypes.h>
#include "libavutil/softfloat.h"
#include "libavutil/common.h"
#include "libavutil/log.h"
#include <stdio.h>
static const SoftFloat FLOAT_0_017776489257 = {0x1234, 12};
static const SoftFloat FLOAT_1374_40625 = {0xabcd, 25};
static const SoftFloat FLOAT_0_1249694824218 = {0xFFF, 15};
int main(void){
SoftFloat one= av_int2sf(1, 0);
SoftFloat sf1, sf2, sf3;
double d1, d2, d3;
int i, j;
av_log_set_level(AV_LOG_DEBUG);
d1= 1;
for(i= 0; i<10; i++){
d1= 1/(d1+1);
}
printf("test1 double=%d\n", (int)(d1 * (1<<24)));
sf1= one;
for(i= 0; i<10; i++){
sf1= av_div_sf(one, av_normalize_sf(av_add_sf(one, sf1)));
}
printf("test1 sf =%d\n", av_sf2int(sf1, 24));
for(i= 0; i<100; i++){
START_TIMER
d1= i;
d2= i/100.0;
for(j= 0; j<1000; j++){
d1= (d1+1)*d2;
}
STOP_TIMER("float add mul")
}
printf("test2 double=%d\n", (int)(d1 * (1<<24)));
for(i= 0; i<100; i++){
START_TIMER
sf1= av_int2sf(i, 0);
sf2= av_div_sf(av_int2sf(i, 2), av_int2sf(200, 3));
for(j= 0; j<1000; j++){
sf1= av_mul_sf(av_add_sf(sf1, one),sf2);
}
STOP_TIMER("softfloat add mul")
}
printf("test2 sf =%d (%d %d)\n", av_sf2int(sf1, 24), sf1.exp, sf1.mant);
d1 = 0.0177764893;
d2 = 1374.40625;
d3 = 0.1249694824;
d2 += d1;
d3 += d2;
printf("test3 double: %.10lf\n", d3);
sf1 = FLOAT_0_017776489257;
sf2 = FLOAT_1374_40625;
sf3 = FLOAT_0_1249694824218;
sf2 = av_add_sf(sf1, sf2);
sf3 = av_add_sf(sf3, sf2);
printf("test3 softfloat: %.10lf (0x%08x %d)\n", (double)av_sf2double(sf3), sf3.mant, sf3.exp);
sf1 = av_int2sf(0xFFFFFFF0, 0);
printf("test4 softfloat: %.10lf (0x%08x %d)\n", (double)av_sf2double(sf1), sf1.mant, sf1.exp);
sf1 = av_int2sf(0x00000010, 0);
printf("test4 softfloat: %.10lf (0x%08x %d)\n", (double)av_sf2double(sf1), sf1.mant, sf1.exp);
sf1 = av_int2sf(0x1FFFFFFF, 0);
printf("test4 softfloat: %.10lf (0x%08x %d)\n", (double)av_sf2double(sf1), sf1.mant, sf1.exp);
sf1 = av_int2sf(0xE0000001, 0);
printf("test4 softfloat: %.10lf (0x%08x %d)\n", (double)av_sf2double(sf1), sf1.mant, sf1.exp);
sf1 = (SoftFloat){ 0x20000000, MIN_EXP };
sf1 = av_mul_sf(sf1, sf1);
printf("test5 softfloat: %.10lf (0x%08x %d)\n", (double)av_sf2double(sf1), sf1.mant, sf1.exp);
sf1 = (SoftFloat){ 0x20000000, MIN_EXP };
sf2 = (SoftFloat){ 0x20000000, MAX_EXP };
i = av_cmp_sf(sf1, sf2);
j = av_cmp_sf(sf2, sf1);
sf1 = av_div_sf(sf1, sf2);
printf("test6 softfloat: %.10lf (0x%08x %d) %d %d\n", (double)av_sf2double(sf1), sf1.mant, sf1.exp, i, j);
for(i= -50; i<50; i++) {
sf1= av_int2sf(i, 0);
for(j= -50; j<50; j++) {
int c;
sf2= av_int2sf(j, 0);
c = av_cmp_sf(sf1, sf2);
if (FFDIFFSIGN(i,j) != c && (FFDIFFSIGN(i,j)^c)<0) {
printf("av_cmp_sf failed at %d %d as %X\n", i, j, c);
}
c = av_gt_sf(sf1, sf2);
if ((i>j) != c) {
printf("av_gt_sf failed at %d %d as %X\n", i, j, c);
}
}
sf1 = av_int2sf(1, i);
for(j = -50; j < 50; j++) {
int c;
sf2 = av_int2sf(1, j);
c = av_cmp_sf(sf2, sf1);
if (FFDIFFSIGN(i,j) != c && (FFDIFFSIGN(i,j)^c) < 0) {
printf("av_cmp_sf failed2 at %d %d as %X\n", i, j, c);
}
c = av_gt_sf(sf1, sf2);
if ((i<j) != c) {
printf("av_gt_sf failed2 at %d %d as %X\n", i, j, c);
}
}
}
for(i= 0; i<4*36; i++){
int s, c;
double errs, errc;
av_sincos_sf(i*(1ULL<<32)/36/4, &s, &c);
errs = (double)s/ (1<<30) - sin(i*M_PI/36);
errc = (double)c/ (1<<30) - cos(i*M_PI/36);
if (fabs(errs) > 0.00000002 || fabs(errc) >0.001) {
printf("sincos FAIL %d %f %f %f %f\n", i, (float)s/ (1<<30), (float)c/ (1<<30), sin(i*M_PI/36), cos(i*M_PI/36));
}
}
return 0;
}

115
externals/ffmpeg/libavutil/tests/tea.c vendored Executable file
View File

@@ -0,0 +1,115 @@
/*
* A 32-bit implementation of the TEA algorithm
* Copyright (c) 2015 Vesselin Bontchev
*
* Loosely based on the implementation of David Wheeler and Roger Needham,
* https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm#Reference_code
*
* 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/tea.h"
#define TEA_NUM_TESTS 4
// https://github.com/logandrews/TeaCrypt/blob/master/tea/tea_test.go
static const uint8_t tea_test_key[TEA_NUM_TESTS][16] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
},
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
}
};
static const uint8_t tea_test_pt[TEA_NUM_TESTS][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 },
{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }
};
static const uint8_t tea_test_ct[TEA_NUM_TESTS][8] = {
{ 0x41, 0xEA, 0x3A, 0x0A, 0x94, 0xBA, 0xA9, 0x40 },
{ 0x6A, 0x2F, 0x9C, 0xF3, 0xFC, 0xCF, 0x3C, 0x55 },
{ 0xDE, 0xB1, 0xC0, 0xA2, 0x7E, 0x74, 0x5D, 0xB3 },
{ 0x12, 0x6C, 0x6B, 0x92, 0xC0, 0x65, 0x3A, 0x3E }
};
static void test_tea(struct AVTEA *ctx, uint8_t *dst, const uint8_t *src,
const uint8_t *ref, int len, uint8_t *iv, int dir,
const char *test)
{
av_tea_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)
{
struct AVTEA *ctx;
uint8_t buf[8], iv[8];
int i;
static const uint8_t src[32] = "HelloWorldHelloWorldHelloWorld";
uint8_t ct[32];
uint8_t pl[32];
ctx = av_tea_alloc();
if (!ctx)
return 1;
for (i = 0; i < TEA_NUM_TESTS; i++) {
av_tea_init(ctx, tea_test_key[i], 64);
test_tea(ctx, buf, tea_test_pt[i], tea_test_ct[i], 1, NULL, 0, "encryption");
test_tea(ctx, buf, tea_test_ct[i], tea_test_pt[i], 1, NULL, 1, "decryption");
/* encrypt */
memcpy(iv, "HALLO123", 8);
av_tea_crypt(ctx, ct, src, 4, iv, 0);
/* decrypt into pl */
memcpy(iv, "HALLO123", 8);
test_tea(ctx, pl, ct, src, 4, iv, 1, "CBC decryption");
memcpy(iv, "HALLO123", 8);
test_tea(ctx, ct, ct, src, 4, iv, 1, "CBC inplace decryption");
}
printf("Test encryption/decryption success.\n");
av_free(ctx);
return 0;
}

108
externals/ffmpeg/libavutil/tests/tree.c vendored Executable file
View File

@@ -0,0 +1,108 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/tree.c"
#include <stdint.h>
#include "libavutil/common.h"
#include "libavutil/lfg.h"
#include "libavutil/log.h"
static int check(AVTreeNode *t)
{
if (t) {
int left = check(t->child[0]);
int right = check(t->child[1]);
if (left > 999 || right > 999)
return 1000;
if (right - left != t->state)
return 1000;
if (t->state > 1 || t->state < -1)
return 1000;
return FFMAX(left, right) + 1;
}
return 0;
}
static void print(AVTreeNode *t, int depth)
{
int i;
for (i = 0; i < depth * 4; i++)
av_log(NULL, AV_LOG_ERROR, " ");
if (t) {
av_log(NULL, AV_LOG_ERROR, "Node %p %2d %p\n", t, t->state, t->elem);
print(t->child[0], depth + 1);
print(t->child[1], depth + 1);
} else
av_log(NULL, AV_LOG_ERROR, "NULL\n");
}
static int cmp(const void *a, const void *b)
{
return (const uint8_t *) a - (const uint8_t *) b;
}
int main(int argc, char **argv)
{
int i;
void *k;
AVTreeNode *root = NULL, *node = NULL;
AVLFG prng;
int log_level = argc <= 1 ? AV_LOG_INFO : atoi(argv[1]);
av_log_set_level(log_level);
av_lfg_init(&prng, 1);
for (i = 0; i < 10000; i++) {
intptr_t j = av_lfg_get(&prng) % 86294;
if (check(root) > 999) {
av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i);
print(root, 0);
return 1;
}
av_log(NULL, AV_LOG_DEBUG, "inserting %4d\n", (int)j);
if (!node)
node = av_tree_node_alloc();
if (!node) {
av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n");
return 1;
}
av_tree_insert(&root, (void *)(j + 1), cmp, &node);
j = av_lfg_get(&prng) % 86294;
{
AVTreeNode *node2 = NULL;
av_log(NULL, AV_LOG_DEBUG, "removing %4d\n", (int)j);
av_tree_insert(&root, (void *)(j + 1), cmp, &node2);
k = av_tree_find(root, (void *)(j + 1), cmp, NULL);
if (k)
av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i);
av_free(node2);
}
}
av_free(node);
av_tree_destroy(root);
return 0;
}

94
externals/ffmpeg/libavutil/tests/twofish.c vendored Executable file
View File

@@ -0,0 +1,94 @@
/*
* An implementation of the TwoFish algorithm
* Copyright (c) 2015 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 "libavutil/log.h"
#include "libavutil/twofish.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
uint8_t Key[32] = {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[6][16] = {
{0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32, 0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a},
{0xcf, 0xd1, 0xd2, 0xe5, 0xa9, 0xbe, 0x9c, 0xdf, 0x50, 0x1f, 0x13, 0xb8, 0x92, 0xbd, 0x22, 0x48},
{0x37, 0x52, 0x7b, 0xe0, 0x05, 0x23, 0x34, 0xb8, 0x9f, 0x0c, 0xfc, 0xca, 0xe8, 0x7c, 0xfa, 0x20},
{0x5d, 0x9d, 0x4e, 0xef, 0xfa, 0x91, 0x51, 0x57, 0x55, 0x24, 0xf1, 0x15, 0x81, 0x5a, 0x12, 0xe0},
{0xe7, 0x54, 0x49, 0x21, 0x2b, 0xee, 0xf9, 0xf4, 0xa3, 0x90, 0xbd, 0x86, 0x0a, 0x64, 0x09, 0x41},
{0x37, 0xfe, 0x26, 0xff, 0x1c, 0xf6, 0x61, 0x75, 0xf5, 0xdd, 0xf4, 0xc3, 0x3b, 0x97, 0xa2, 0x05}
};
uint8_t temp[32], iv[16], rpt[32] = {0};
const int kbits[3] = {128, 192, 256};
int i, j, err = 0;
struct AVTWOFISH *cs;
cs = av_twofish_alloc();
if (!cs)
return 1;
for (j = 1; j < 3; j++) {
av_twofish_init(cs, Key, kbits[j]);
av_twofish_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_twofish_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;
}
}
}
for (j = 0; j < 3; j++) {
memset(Key, 0, sizeof(Key));
memset(rpt, 0, sizeof(rpt));
for (i = 1; i < 50; i++) {
av_twofish_init(cs, Key, kbits[j]);
av_twofish_crypt(cs, temp, rpt, 1, NULL, 0);
memcpy(Key+16,Key,(kbits[j]-128) >> 3);
memcpy(Key,rpt,16);
memcpy(rpt,temp,16);
}
for (i = 0; i < 16; i++) {
if (rct[3 + j][i] != temp[i]) {
av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rct[3 + j][i], temp[i]);
err = 1;
}
}
}
memset(rpt, 0, sizeof(rpt));
memcpy(iv, "HALLO123HALLO123", 16);
av_twofish_crypt(cs, temp, rpt, 2, iv, 0);
memcpy(iv, "HALLO123HALLO123", 16);
av_twofish_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;
}

71
externals/ffmpeg/libavutil/tests/utf8.c vendored Executable file
View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013 Stefano Sabatini
*
* 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/avstring.h"
#include "libavutil/file.h"
static void print_sequence(const char *p, int l, int indent)
{
int i;
for (i = 0; i < l; i++)
printf("%02X", (uint8_t)p[i]);
printf("%*s", indent-l*2, "");
}
int main(int argc, char **argv)
{
int ret;
char *filename = argv[1];
uint8_t *file_buf;
size_t file_buf_size;
uint32_t code;
const uint8_t *p, *endp;
ret = av_file_map(filename, &file_buf, &file_buf_size, 0, NULL);
if (ret < 0)
return 1;
p = file_buf;
endp = file_buf + file_buf_size;
while (p < endp) {
int l, r;
const uint8_t *p0 = p;
code = UINT32_MAX;
r = av_utf8_decode(&code, &p, endp, 0);
l = (int)(p-p0);
print_sequence(p0, l, 20);
if (code != UINT32_MAX) {
printf("%-10d 0x%-10X %-5d ", code, code, l);
if (r >= 0) {
if (*p0 == '\n') printf("\\n\n");
else printf ("%.*s\n", l, p0);
} else {
printf("invalid code range\n");
}
} else {
printf("invalid sequence\n");
}
}
av_file_unmap(file_buf, file_buf_size);
return 0;
}

125
externals/ffmpeg/libavutil/tests/xtea.c vendored Executable file
View File

@@ -0,0 +1,125 @@
/*
* 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 "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/xtea.h"
#define XTEA_NUM_TESTS 6
static const uint8_t xtea_test_key[XTEA_NUM_TESTS][16] = {
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
static const uint8_t xtea_test_pt[XTEA_NUM_TESTS][8] = {
{ 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
{ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
{ 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f },
{ 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
{ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
{ 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 }
};
static const uint8_t xtea_test_ct[XTEA_NUM_TESTS][8] = {
{ 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 },
{ 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 },
{ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
{ 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 },
{ 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d },
{ 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }
};
static void test_xtea(AVXTEA *ctx, uint8_t *dst, const uint8_t *src,
const uint8_t *ref, int len, uint8_t *iv, int dir,
const char *test,
void (*crypt)(AVXTEA *, uint8_t *, const uint8_t *, int, uint8_t *, int))
{
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)
{
uint8_t buf[16], iv[8];
int i, j;
static const uint8_t src[32] = "HelloWorldHelloWorldHelloWorld";
uint8_t ct[32];
uint8_t pl[32];
AVXTEA *ctx = av_xtea_alloc();
if (!ctx)
return 1;
for (i = 0; i < XTEA_NUM_TESTS; i++) {
av_xtea_init(ctx, xtea_test_key[i]);
test_xtea(ctx, buf, xtea_test_pt[i], xtea_test_ct[i], 1, NULL, 0, "encryption", av_xtea_crypt);
test_xtea(ctx, buf, xtea_test_ct[i], xtea_test_pt[i], 1, NULL, 1, "decryption", av_xtea_crypt);
for (j = 0; j < 4; j++)
AV_WL32(&buf[4*j], AV_RB32(&xtea_test_key[i][4*j]));
av_xtea_le_init(ctx, buf);
for (j = 0; j < 2; j++) {
AV_WL32(&ct[4*j], AV_RB32(&xtea_test_ct[i][4*j]));
AV_WL32(&pl[4*j], AV_RB32(&xtea_test_pt[i][4*j]));
}
test_xtea(ctx, buf, pl, ct, 1, NULL, 0, "encryption", av_xtea_le_crypt);
test_xtea(ctx, buf, ct, pl, 1, NULL, 1, "decryption", av_xtea_le_crypt);
/* encrypt */
memcpy(iv, "HALLO123", 8);
av_xtea_crypt(ctx, ct, src, 4, iv, 0);
/* decrypt into pl */
memcpy(iv, "HALLO123", 8);
test_xtea(ctx, pl, ct, src, 4, iv, 1, "CBC decryption", av_xtea_crypt);
memcpy(iv, "HALLO123", 8);
test_xtea(ctx, ct, ct, src, 4, iv, 1, "CBC inplace decryption", av_xtea_crypt);
}
printf("Test encryption/decryption success.\n");
av_free(ctx);
return 0;
}