FFmpeg  4.3
base64.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 // LCOV_EXCL_START
20 
21 #include "libavutil/timer.h"
22 
23 #include <stdint.h>
24 #include <stdio.h>
25 
26 #include "libavutil/common.h"
27 #include "libavutil/base64.h"
28 
29 #define MAX_DATA_SIZE 1024
30 #define MAX_ENCODED_SIZE 2048
31 
32 static int test_encode_decode(const uint8_t *data, unsigned int data_size,
33  const char *encoded_ref)
34 {
35  char encoded[MAX_ENCODED_SIZE];
36  uint8_t data2[MAX_DATA_SIZE];
37  int data2_size, max_data2_size = MAX_DATA_SIZE;
38 
39  if (!av_base64_encode(encoded, MAX_ENCODED_SIZE, data, data_size)) {
40  printf("Failed: cannot encode the input data\n");
41  return 1;
42  }
43  if (encoded_ref && strcmp(encoded, encoded_ref)) {
44  printf("Failed: encoded string differs from reference\n"
45  "Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref);
46  return 1;
47  }
48 
49  if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) != data_size) {
50  printf("Failed: cannot decode the encoded string\n"
51  "Encoded:\n%s\n", encoded);
52  return 1;
53  }
54  if ((data2_size = av_base64_decode(data2, encoded, data_size)) != data_size) {
55  printf("Failed: cannot decode with minimal buffer\n"
56  "Encoded:\n%s\n", encoded);
57  return 1;
58  }
59  if (memcmp(data2, data, data_size)) {
60  printf("Failed: encoded/decoded data differs from original data\n");
61  return 1;
62  }
63  if (av_base64_decode(NULL, encoded, 0) != 0) {
64  printf("Failed: decode to NULL buffer\n");
65  return 1;
66  }
67  if (strlen(encoded)) {
68  char *end = strchr(encoded, '=');
69  if (!end)
70  end = encoded + strlen(encoded) - 1;
71  *end = '%';
72  if (av_base64_decode(NULL, encoded, 0) >= 0) {
73  printf("Failed: error detection\n");
74  return 1;
75  }
76  }
77 
78  printf("Passed!\n");
79  return 0;
80 }
81 
82 int main(int argc, char ** argv)
83 {
84  int i, error_count = 0;
85  struct test {
86  const uint8_t *data;
87  const char *encoded_ref;
88  } tests[] = {
89  { "", ""},
90  { "1", "MQ=="},
91  { "22", "MjI="},
92  { "333", "MzMz"},
93  { "4444", "NDQ0NA=="},
94  { "55555", "NTU1NTU="},
95  { "666666", "NjY2NjY2"},
96  { "abc:def", "YWJjOmRlZg=="},
97  };
98  char in[1024], out[2048];
99 
100  printf("Encoding/decoding tests\n");
101  for (i = 0; i < FF_ARRAY_ELEMS(tests); i++)
102  error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref);
103 
104  if (argc>1 && !strcmp(argv[1], "-t")) {
105  memset(in, 123, sizeof(in));
106  for(i=0; i<10000; i++){
108  av_base64_encode(out, sizeof(out), in, sizeof(in));
109  STOP_TIMER("encode")
110  }
111  for(i=0; i<10000; i++){
113  av_base64_decode(in, out, sizeof(in));
114  STOP_TIMER("decode")
115  }
116 
117  for(i=0; i<10000; i++){
120  STOP_TIMER("syntax check")
121  }
122  }
123 
124  if (error_count)
125  printf("Error Count: %d.\n", error_count);
126 
127  return !!error_count;
128 }
129 
130 // LCOV_EXCL_STOP
out
FILE * out
Definition: movenc.c:54
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
data
const char data[16]
Definition: mxf.c:91
main
int main(int argc, char **argv)
Definition: base64.c:82
START_TIMER
#define START_TIMER
Definition: timer.h:137
test_encode_decode
static int test_encode_decode(const uint8_t *data, unsigned int data_size, const char *encoded_ref)
Definition: base64.c:32
MAX_DATA_SIZE
#define MAX_DATA_SIZE
Definition: base64.c:29
NULL
#define NULL
Definition: coverity.c:32
timer.h
av_base64_decode
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
Definition: base64.c:79
base64.h
tests
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo ug o o X fate suite ffmpeg Duo ug o o X fate suite fate suite ffmpeg Duo ug o o X fate suite fate suite ffmpeg can be set or it has a meaning only while running the regression tests ‘THREADS’ Specify how many threads to use while running regression tests
Definition: fate.txt:188
test
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the test
Definition: fate.txt:76
printf
printf("static const uint8_t my_array[100] = {\n")
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
MAX_ENCODED_SIZE
#define MAX_ENCODED_SIZE
Definition: base64.c:30
common.h
uint8_t
uint8_t
Definition: audio_convert.c:194
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
av_base64_encode
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
Definition: base64.c:138
STOP_TIMER
#define STOP_TIMER(id)
Definition: timer.h:138