#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "attributes.h"
#include "macros.h"
#include "version.h"
#include "libavutil/avconfig.h"
#include "config.h"
#include "intmath.h"
#include "common.h"
#include "mem.h"
#include "internal.h"
Go to the source code of this file.
|
#define | AV_NE(be, le) (le) |
|
#define | RSHIFT(a, b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) |
|
#define | ROUNDED_DIV(a, b) (((a)>=0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) |
|
#define | AV_CEIL_RSHIFT(a, b) |
|
#define | FF_CEIL_RSHIFT AV_CEIL_RSHIFT |
|
#define | FFUDIV(a, b) (((a)>0 ?(a):(a)-(b)+1) / (b)) |
|
#define | FFUMOD(a, b) ((a)-(b)*FFUDIV(a,b)) |
|
#define | FFABS(a) ((a) >= 0 ? (a) : (-(a))) |
| Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable as absolute values of their type. More...
|
|
#define | FFSIGN(a) ((a) > 0 ? 1 : -1) |
|
#define | FFNABS(a) ((a) <= 0 ? (a) : (-(a))) |
| Negative Absolute value. More...
|
|
#define | FFDIFFSIGN(x, y) (((x)>(y)) - ((x)<(y))) |
| Comparator. More...
|
|
#define | FFMAX(a, b) ((a) > (b) ? (a) : (b)) |
|
#define | FFMAX3(a, b, c) FFMAX(FFMAX(a,b),c) |
|
#define | FFMIN(a, b) ((a) > (b) ? (b) : (a)) |
|
#define | FFMIN3(a, b, c) FFMIN(FFMIN(a,b),c) |
|
#define | FFSWAP(type, a, b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) |
|
#define | FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) |
|
#define | MKTAG(a, b, c, d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24)) |
|
#define | MKBETAG(a, b, c, d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24)) |
|
#define | GET_UTF8(val, GET_BYTE, ERROR) |
| Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form. More...
|
|
#define | GET_UTF16(val, GET_16BIT, ERROR) |
| Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form. More...
|
|
#define | PUT_UTF8(val, tmp, PUT_BYTE) |
|
#define | PUT_UTF16(val, tmp, PUT_16BIT) |
|
|
static av_always_inline av_const int | av_clip_c (int a, int amin, int amax) |
| Clip a signed integer value into the amin-amax range. More...
|
|
static av_always_inline av_const int64_t | av_clip64_c (int64_t a, int64_t amin, int64_t amax) |
| Clip a signed 64bit integer value into the amin-amax range. More...
|
|
static av_always_inline av_const uint8_t | av_clip_uint8_c (int a) |
| Clip a signed integer value into the 0-255 range. More...
|
|
static av_always_inline av_const int8_t | av_clip_int8_c (int a) |
| Clip a signed integer value into the -128,127 range. More...
|
|
static av_always_inline av_const uint16_t | av_clip_uint16_c (int a) |
| Clip a signed integer value into the 0-65535 range. More...
|
|
static av_always_inline av_const int16_t | av_clip_int16_c (int a) |
| Clip a signed integer value into the -32768,32767 range. More...
|
|
static av_always_inline av_const int32_t | av_clipl_int32_c (int64_t a) |
| Clip a signed 64-bit integer value into the -2147483648,2147483647 range. More...
|
|
static av_always_inline av_const int | av_clip_intp2_c (int a, int p) |
| Clip a signed integer into the -(2^p),(2^p-1) range. More...
|
|
static av_always_inline av_const unsigned | av_clip_uintp2_c (int a, int p) |
| Clip a signed integer to an unsigned power of two range. More...
|
|
static av_always_inline av_const unsigned | av_mod_uintp2_c (unsigned a, unsigned p) |
| Clear high bits from an unsigned integer starting with specific bit position. More...
|
|
static av_always_inline int | av_sat_add32_c (int a, int b) |
| Add two signed 32-bit values with saturation. More...
|
|
static av_always_inline int | av_sat_dadd32_c (int a, int b) |
| Add a doubled value to another value with saturation at both stages. More...
|
|
static av_always_inline int | av_sat_sub32_c (int a, int b) |
| Subtract two signed 32-bit values with saturation. More...
|
|
static av_always_inline int | av_sat_dsub32_c (int a, int b) |
| Subtract a doubled value from another value with saturation at both stages. More...
|
|
static av_always_inline int64_t | av_sat_add64_c (int64_t a, int64_t b) |
| Add two signed 64-bit values with saturation. More...
|
|
static av_always_inline int64_t | av_sat_sub64_c (int64_t a, int64_t b) |
| Subtract two signed 64-bit values with saturation. More...
|
|
static av_always_inline av_const float | av_clipf_c (float a, float amin, float amax) |
| Clip a float value into the amin-amax range. More...
|
|
static av_always_inline av_const double | av_clipd_c (double a, double amin, double amax) |
| Clip a double value into the amin-amax range. More...
|
|
static av_always_inline av_const int | av_ceil_log2_c (int x) |
| Compute ceil(log2(x)). More...
|
|
static av_always_inline av_const int | av_popcount_c (uint32_t x) |
| Count number of bits set to one in x. More...
|
|
static av_always_inline av_const int | av_popcount64_c (uint64_t x) |
| Count number of bits set to one in x. More...
|
|
static av_always_inline av_const int | av_parity_c (uint32_t v) |
|
common internal and external API header
Definition in file common.h.
◆ AV_NE
#define AV_NE |
( |
|
be, |
|
|
|
le |
|
) |
| (le) |
◆ RSHIFT
#define RSHIFT |
( |
|
a, |
|
|
|
b |
|
) |
| ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) |
◆ ROUNDED_DIV
#define ROUNDED_DIV |
( |
|
a, |
|
|
|
b |
|
) |
| (((a)>=0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) |
◆ AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT |
( |
|
a, |
|
|
|
b |
|
) |
| |
Value:
: ((
a) + (1<<(
b)) - 1) >> (
b))
Definition at line 58 of file common.h.
◆ FF_CEIL_RSHIFT
◆ FFUDIV
#define FFUDIV |
( |
|
a, |
|
|
|
b |
|
) |
| (((a)>0 ?(a):(a)-(b)+1) / (b)) |
◆ FFUMOD
◆ FFABS
#define FFABS |
( |
|
a | ) |
((a) >= 0 ? (a) : (-(a))) |
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable as absolute values of their type.
This is the same as with *abs()
- See also
- FFNABS()
Definition at line 72 of file common.h.
◆ FFSIGN
#define FFSIGN |
( |
|
a | ) |
((a) > 0 ? 1 : -1) |
◆ FFNABS
#define FFNABS |
( |
|
a | ) |
((a) <= 0 ? (a) : (-(a))) |
Negative Absolute value.
this works for all integers of all types. As with many macros, this evaluates its argument twice, it thus must not have a sideeffect, that is FFNABS(x++) has undefined behavior.
Definition at line 81 of file common.h.
◆ FFDIFFSIGN
#define FFDIFFSIGN |
( |
|
x, |
|
|
|
y |
|
) |
| (((x)>(y)) - ((x)<(y))) |
Comparator.
For two numerical expressions x and y, gives 1 if x > y, -1 if x < y, and 0 if x == y. This is useful for instance in a qsort comparator callback. Furthermore, compilers are able to optimize this to branchless code, and there is no risk of overflow with signed types. As with many macros, this evaluates its argument multiple times, it thus must not have a side-effect.
Definition at line 92 of file common.h.
◆ FFMAX
#define FFMAX |
( |
|
a, |
|
|
|
b |
|
) |
| ((a) > (b) ? (a) : (b)) |
◆ FFMAX3
◆ FFMIN
#define FFMIN |
( |
|
a, |
|
|
|
b |
|
) |
| ((a) > (b) ? (b) : (a)) |
◆ FFMIN3
◆ FFSWAP
◆ FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS |
( |
|
a | ) |
(sizeof(a) / sizeof((a)[0])) |
◆ MKTAG
#define MKTAG |
( |
|
a, |
|
|
|
b, |
|
|
|
c, |
|
|
|
d |
|
) |
| ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24)) |
◆ MKBETAG
#define MKBETAG |
( |
|
a, |
|
|
|
b, |
|
|
|
c, |
|
|
|
d |
|
) |
| ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24)) |
◆ GET_UTF8
#define GET_UTF8 |
( |
|
val, |
|
|
|
GET_BYTE, |
|
|
|
ERROR |
|
) |
| |
Value:
{\
uint32_t top = (
val & 128) >> 1;\
if ((
val & 0xc0) == 0x80 ||
val >= 0xFE)\
unsigned
int tmp = (GET_BYTE) - 128;\
top <<= 5;\
}\
val &= (top << 1) - 1;\
}
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
- Parameters
-
val | Output value, must be an lvalue of type uint32_t. |
GET_BYTE | Expression reading one byte from the input. Evaluated up to 7 times (4 for the currently assigned Unicode range). With a memory buffer input, this could be *ptr++, or if you want to make sure that *ptr stops at the end of a NULL terminated string then *ptr ? *ptr++ : 0 |
ERROR | Expression to be evaluated on invalid input, typically a goto statement. |
- Warning
- ERROR should not contain a loop control statement which could interact with the internal while loop, and should force an exit from the macro code (e.g. through a goto or a return) in order to prevent undefined results.
Definition at line 427 of file common.h.
◆ GET_UTF16
#define GET_UTF16 |
( |
|
val, |
|
|
|
GET_16BIT, |
|
|
|
ERROR |
|
) |
| |
Value:
{\
unsigned
int hi =
val - 0xD800;\
if (hi < 0x800) {\
val = (GET_16BIT) - 0xDC00;\
if (
val > 0x3FFU || hi > 0x3FFU)\
val += (hi<<10) + 0x10000;\
}\
}\
Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form.
- Parameters
-
val | Output value, must be an lvalue of type uint32_t. |
GET_16BIT | Expression returning two bytes of UTF-16 data converted to native byte order. Evaluated one or two times. |
ERROR | Expression to be evaluated on invalid input, typically a goto statement. |
Definition at line 452 of file common.h.
◆ PUT_UTF8
#define PUT_UTF8 |
( |
|
val, |
|
|
|
tmp, |
|
|
|
PUT_BYTE |
|
) |
| |
Value: {\
PUT_BYTE\
} else {\
shift = (bytes - 1) * 6;\
tmp = (256 - (256 >> bytes)) | (
in >>
shift);\
PUT_BYTE\
shift -= 6;\
tmp = 0x80 | ((
in >>
shift) & 0x3f);\
PUT_BYTE\
}\
}\
}
Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
- Parameters
-
val | is an input-only argument and should be of type uint32_t. It holds a UCS-4 encoded Unicode character that is to be converted to UTF-8. If val is given as a function it is executed only once. |
tmp | is a temporary variable and should be of type uint8_t. It represents an intermediate value during conversion that is to be output by PUT_BYTE. |
PUT_BYTE | writes the converted UTF-8 bytes to any proper destination. It could be a function or a statement, and uses tmp as the input byte. For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be executed up to 4 times for values in the valid UTF-8 range and up to 7 times in the general case, depending on the length of the converted Unicode character. |
Definition at line 480 of file common.h.
◆ PUT_UTF16
#define PUT_UTF16 |
( |
|
val, |
|
|
|
tmp, |
|
|
|
PUT_16BIT |
|
) |
| |
Value: {\
PUT_16BIT\
} else {\
tmp = 0xD800 | ((
in - 0x10000) >> 10);\
PUT_16BIT\
tmp = 0xDC00 | ((
in - 0x10000) & 0x3FF);\
PUT_16BIT\
}\
}\
Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
- Parameters
-
val | is an input-only argument and should be of type uint32_t. It holds a UCS-4 encoded Unicode character that is to be converted to UTF-16. If val is given as a function it is executed only once. |
tmp | is a temporary variable and should be of type uint16_t. It represents an intermediate value during conversion that is to be output by PUT_16BIT. |
PUT_16BIT | writes the converted UTF-16 data to any proper destination in desired endianness. It could be a function or a statement, and uses tmp as the input byte. For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be executed 1 or 2 times depending on input character. |
Definition at line 514 of file common.h.
◆ av_clip_c()
Clip a signed integer value into the amin-amax range.
- Parameters
-
a | value to clip |
amin | minimum value of the clip range |
amax | maximum value of the clip range |
- Returns
- clipped value
Definition at line 127 of file common.h.
◆ av_clip64_c()
Clip a signed 64bit integer value into the amin-amax range.
- Parameters
-
a | value to clip |
amin | minimum value of the clip range |
amax | maximum value of the clip range |
- Returns
- clipped value
Definition at line 144 of file common.h.
◆ av_clip_uint8_c()
Clip a signed integer value into the 0-255 range.
- Parameters
-
- Returns
- clipped value
Definition at line 159 of file common.h.
◆ av_clip_int8_c()
Clip a signed integer value into the -128,127 range.
- Parameters
-
- Returns
- clipped value
Definition at line 170 of file common.h.
◆ av_clip_uint16_c()
Clip a signed integer value into the 0-65535 range.
- Parameters
-
- Returns
- clipped value
Definition at line 181 of file common.h.
Referenced by dng_process_color16().
◆ av_clip_int16_c()
Clip a signed integer value into the -32768,32767 range.
- Parameters
-
- Returns
- clipped value
Definition at line 192 of file common.h.
◆ av_clipl_int32_c()
Clip a signed 64-bit integer value into the -2147483648,2147483647 range.
- Parameters
-
- Returns
- clipped value
Definition at line 203 of file common.h.
◆ av_clip_intp2_c()
Clip a signed integer into the -(2^p),(2^p-1) range.
- Parameters
-
a | value to clip |
p | bit position to clip at |
- Returns
- clipped value
Definition at line 215 of file common.h.
◆ av_clip_uintp2_c()
Clip a signed integer to an unsigned power of two range.
- Parameters
-
a | value to clip |
p | bit position to clip at |
- Returns
- clipped value
Definition at line 229 of file common.h.
Referenced by amplify_frame(), cas_slice16(), color_balance16(), color_balance16_p(), do_output16(), export_row16(), filter(), normalize(), parse_band_ext(), postprocess_chroma(), and vibrance_slice16().
◆ av_mod_uintp2_c()
Clear high bits from an unsigned integer starting with specific bit position.
- Parameters
-
a | value to clip |
p | bit position to clip at |
- Returns
- clipped value
Definition at line 241 of file common.h.
◆ av_sat_add32_c()
Add two signed 32-bit values with saturation.
- Parameters
-
a | one value |
b | another value |
- Returns
- sum with signed saturation
Definition at line 253 of file common.h.
◆ av_sat_dadd32_c()
Add a doubled value to another value with saturation at both stages.
- Parameters
-
a | first value |
b | value doubled and added to a |
- Returns
- sum sat(a + sat(2*b)) with signed saturation
Definition at line 265 of file common.h.
◆ av_sat_sub32_c()
Subtract two signed 32-bit values with saturation.
- Parameters
-
a | one value |
b | another value |
- Returns
- difference with signed saturation
Definition at line 277 of file common.h.
◆ av_sat_dsub32_c()
Subtract a doubled value from another value with saturation at both stages.
- Parameters
-
a | first value |
b | value doubled and subtracted from a |
- Returns
- difference sat(a - sat(2*b)) with signed saturation
Definition at line 289 of file common.h.
◆ av_sat_add64_c()
Add two signed 64-bit values with saturation.
- Parameters
-
a | one value |
b | another value |
- Returns
- sum with signed saturation
Definition at line 301 of file common.h.
◆ av_sat_sub64_c()
Subtract two signed 64-bit values with saturation.
- Parameters
-
a | one value |
b | another value |
- Returns
- difference with signed saturation
Definition at line 321 of file common.h.
◆ av_clipf_c()
Clip a float value into the amin-amax range.
- Parameters
-
a | value to clip |
amin | minimum value of the clip range |
amax | maximum value of the clip range |
- Returns
- clipped value
Definition at line 341 of file common.h.
◆ av_clipd_c()
Clip a double value into the amin-amax range.
- Parameters
-
a | value to clip |
amin | minimum value of the clip range |
amax | maximum value of the clip range |
- Returns
- clipped value
Definition at line 358 of file common.h.
◆ av_ceil_log2_c()
◆ av_popcount_c()
Count number of bits set to one in x.
- Parameters
-
- Returns
- the number of bits set to one in x
Definition at line 382 of file common.h.
◆ av_popcount64_c()
Count number of bits set to one in x.
- Parameters
-
- Returns
- the number of bits set to one in x
Definition at line 396 of file common.h.
◆ av_parity_c()
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