@drutech/react-native-audio-analyzer 1.1.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +124 -0
  3. package/android/CMakeCache.txt +372 -0
  4. package/android/CMakeLists.txt +44 -0
  5. package/android/Makefile +211 -0
  6. package/android/build.gradle +110 -0
  7. package/android/cmake_install.cmake +49 -0
  8. package/android/cpp-adapter.cpp +40 -0
  9. package/android/ffmpeg_16kb/include/config.h +749 -0
  10. package/android/ffmpeg_16kb/include/libavcodec/ac3_parser.h +36 -0
  11. package/android/ffmpeg_16kb/include/libavcodec/adts_parser.h +37 -0
  12. package/android/ffmpeg_16kb/include/libavcodec/arm/mathops.h +108 -0
  13. package/android/ffmpeg_16kb/include/libavcodec/avcodec.h +3192 -0
  14. package/android/ffmpeg_16kb/include/libavcodec/avdct.h +88 -0
  15. package/android/ffmpeg_16kb/include/libavcodec/avfft.h +118 -0
  16. package/android/ffmpeg_16kb/include/libavcodec/bsf.h +332 -0
  17. package/android/ffmpeg_16kb/include/libavcodec/codec.h +375 -0
  18. package/android/ffmpeg_16kb/include/libavcodec/codec_desc.h +128 -0
  19. package/android/ffmpeg_16kb/include/libavcodec/codec_id.h +661 -0
  20. package/android/ffmpeg_16kb/include/libavcodec/codec_par.h +247 -0
  21. package/android/ffmpeg_16kb/include/libavcodec/d3d11va.h +112 -0
  22. package/android/ffmpeg_16kb/include/libavcodec/defs.h +192 -0
  23. package/android/ffmpeg_16kb/include/libavcodec/dirac.h +131 -0
  24. package/android/ffmpeg_16kb/include/libavcodec/dv_profile.h +82 -0
  25. package/android/ffmpeg_16kb/include/libavcodec/dxva2.h +93 -0
  26. package/android/ffmpeg_16kb/include/libavcodec/jni.h +46 -0
  27. package/android/ffmpeg_16kb/include/libavcodec/mathops.h +255 -0
  28. package/android/ffmpeg_16kb/include/libavcodec/mediacodec.h +103 -0
  29. package/android/ffmpeg_16kb/include/libavcodec/packet.h +731 -0
  30. package/android/ffmpeg_16kb/include/libavcodec/qsv.h +109 -0
  31. package/android/ffmpeg_16kb/include/libavcodec/vdpau.h +157 -0
  32. package/android/ffmpeg_16kb/include/libavcodec/version.h +45 -0
  33. package/android/ffmpeg_16kb/include/libavcodec/version_major.h +52 -0
  34. package/android/ffmpeg_16kb/include/libavcodec/videotoolbox.h +150 -0
  35. package/android/ffmpeg_16kb/include/libavcodec/vorbis_parser.h +74 -0
  36. package/android/ffmpeg_16kb/include/libavcodec/x86/mathops.h +133 -0
  37. package/android/ffmpeg_16kb/include/libavcodec/xvmc.h +171 -0
  38. package/android/ffmpeg_16kb/include/libavdevice/avdevice.h +397 -0
  39. package/android/ffmpeg_16kb/include/libavdevice/version.h +45 -0
  40. package/android/ffmpeg_16kb/include/libavdevice/version_major.h +36 -0
  41. package/android/ffmpeg_16kb/include/libavfilter/avfilter.h +1491 -0
  42. package/android/ffmpeg_16kb/include/libavfilter/buffersink.h +173 -0
  43. package/android/ffmpeg_16kb/include/libavfilter/buffersrc.h +218 -0
  44. package/android/ffmpeg_16kb/include/libavfilter/version.h +48 -0
  45. package/android/ffmpeg_16kb/include/libavfilter/version_major.h +38 -0
  46. package/android/ffmpeg_16kb/include/libavformat/avformat.h +2826 -0
  47. package/android/ffmpeg_16kb/include/libavformat/avio.h +837 -0
  48. package/android/ffmpeg_16kb/include/libavformat/network.h +341 -0
  49. package/android/ffmpeg_16kb/include/libavformat/os_support.h +317 -0
  50. package/android/ffmpeg_16kb/include/libavformat/url.h +409 -0
  51. package/android/ffmpeg_16kb/include/libavformat/version.h +47 -0
  52. package/android/ffmpeg_16kb/include/libavformat/version_major.h +52 -0
  53. package/android/ffmpeg_16kb/include/libavutil/aarch64/timer.h +50 -0
  54. package/android/ffmpeg_16kb/include/libavutil/adler32.h +63 -0
  55. package/android/ffmpeg_16kb/include/libavutil/aes.h +69 -0
  56. package/android/ffmpeg_16kb/include/libavutil/aes_ctr.h +99 -0
  57. package/android/ffmpeg_16kb/include/libavutil/ambient_viewing_environment.h +72 -0
  58. package/android/ffmpeg_16kb/include/libavutil/arm/timer.h +46 -0
  59. package/android/ffmpeg_16kb/include/libavutil/attributes.h +173 -0
  60. package/android/ffmpeg_16kb/include/libavutil/attributes_internal.h +34 -0
  61. package/android/ffmpeg_16kb/include/libavutil/audio_fifo.h +186 -0
  62. package/android/ffmpeg_16kb/include/libavutil/avassert.h +75 -0
  63. package/android/ffmpeg_16kb/include/libavutil/avconfig.h +6 -0
  64. package/android/ffmpeg_16kb/include/libavutil/avstring.h +429 -0
  65. package/android/ffmpeg_16kb/include/libavutil/avutil.h +371 -0
  66. package/android/ffmpeg_16kb/include/libavutil/base64.h +72 -0
  67. package/android/ffmpeg_16kb/include/libavutil/blowfish.h +82 -0
  68. package/android/ffmpeg_16kb/include/libavutil/bprint.h +251 -0
  69. package/android/ffmpeg_16kb/include/libavutil/bswap.h +111 -0
  70. package/android/ffmpeg_16kb/include/libavutil/buffer.h +322 -0
  71. package/android/ffmpeg_16kb/include/libavutil/camellia.h +70 -0
  72. package/android/ffmpeg_16kb/include/libavutil/cast5.h +80 -0
  73. package/android/ffmpeg_16kb/include/libavutil/channel_layout.h +783 -0
  74. package/android/ffmpeg_16kb/include/libavutil/common.h +578 -0
  75. package/android/ffmpeg_16kb/include/libavutil/cpu.h +134 -0
  76. package/android/ffmpeg_16kb/include/libavutil/crc.h +102 -0
  77. package/android/ffmpeg_16kb/include/libavutil/csp.h +150 -0
  78. package/android/ffmpeg_16kb/include/libavutil/des.h +81 -0
  79. package/android/ffmpeg_16kb/include/libavutil/detection_bbox.h +108 -0
  80. package/android/ffmpeg_16kb/include/libavutil/dict.h +241 -0
  81. package/android/ffmpeg_16kb/include/libavutil/display.h +109 -0
  82. package/android/ffmpeg_16kb/include/libavutil/dovi_meta.h +236 -0
  83. package/android/ffmpeg_16kb/include/libavutil/downmix_info.h +115 -0
  84. package/android/ffmpeg_16kb/include/libavutil/encryption_info.h +205 -0
  85. package/android/ffmpeg_16kb/include/libavutil/error.h +128 -0
  86. package/android/ffmpeg_16kb/include/libavutil/eval.h +140 -0
  87. package/android/ffmpeg_16kb/include/libavutil/ffversion.h +5 -0
  88. package/android/ffmpeg_16kb/include/libavutil/fifo.h +448 -0
  89. package/android/ffmpeg_16kb/include/libavutil/file.h +115 -0
  90. package/android/ffmpeg_16kb/include/libavutil/film_grain_params.h +260 -0
  91. package/android/ffmpeg_16kb/include/libavutil/frame.h +964 -0
  92. package/android/ffmpeg_16kb/include/libavutil/getenv_utf8.h +86 -0
  93. package/android/ffmpeg_16kb/include/libavutil/hash.h +264 -0
  94. package/android/ffmpeg_16kb/include/libavutil/hdr_dynamic_metadata.h +343 -0
  95. package/android/ffmpeg_16kb/include/libavutil/hdr_dynamic_vivid_metadata.h +285 -0
  96. package/android/ffmpeg_16kb/include/libavutil/hmac.h +99 -0
  97. package/android/ffmpeg_16kb/include/libavutil/hwcontext.h +610 -0
  98. package/android/ffmpeg_16kb/include/libavutil/hwcontext_cuda.h +69 -0
  99. package/android/ffmpeg_16kb/include/libavutil/hwcontext_d3d11va.h +178 -0
  100. package/android/ffmpeg_16kb/include/libavutil/hwcontext_drm.h +169 -0
  101. package/android/ffmpeg_16kb/include/libavutil/hwcontext_dxva2.h +75 -0
  102. package/android/ffmpeg_16kb/include/libavutil/hwcontext_mediacodec.h +61 -0
  103. package/android/ffmpeg_16kb/include/libavutil/hwcontext_opencl.h +100 -0
  104. package/android/ffmpeg_16kb/include/libavutil/hwcontext_qsv.h +64 -0
  105. package/android/ffmpeg_16kb/include/libavutil/hwcontext_vaapi.h +117 -0
  106. package/android/ffmpeg_16kb/include/libavutil/hwcontext_vdpau.h +44 -0
  107. package/android/ffmpeg_16kb/include/libavutil/hwcontext_videotoolbox.h +96 -0
  108. package/android/ffmpeg_16kb/include/libavutil/hwcontext_vulkan.h +281 -0
  109. package/android/ffmpeg_16kb/include/libavutil/imgutils.h +331 -0
  110. package/android/ffmpeg_16kb/include/libavutil/internal.h +190 -0
  111. package/android/ffmpeg_16kb/include/libavutil/intfloat.h +77 -0
  112. package/android/ffmpeg_16kb/include/libavutil/intreadwrite.h +644 -0
  113. package/android/ffmpeg_16kb/include/libavutil/lfg.h +81 -0
  114. package/android/ffmpeg_16kb/include/libavutil/libm.h +471 -0
  115. package/android/ffmpeg_16kb/include/libavutil/log.h +387 -0
  116. package/android/ffmpeg_16kb/include/libavutil/lzo.h +66 -0
  117. package/android/ffmpeg_16kb/include/libavutil/macros.h +80 -0
  118. package/android/ffmpeg_16kb/include/libavutil/mastering_display_metadata.h +128 -0
  119. package/android/ffmpeg_16kb/include/libavutil/mathematics.h +245 -0
  120. package/android/ffmpeg_16kb/include/libavutil/md5.h +89 -0
  121. package/android/ffmpeg_16kb/include/libavutil/mem.h +609 -0
  122. package/android/ffmpeg_16kb/include/libavutil/motion_vector.h +57 -0
  123. package/android/ffmpeg_16kb/include/libavutil/murmur3.h +115 -0
  124. package/android/ffmpeg_16kb/include/libavutil/opt.h +891 -0
  125. package/android/ffmpeg_16kb/include/libavutil/parseutils.h +197 -0
  126. package/android/ffmpeg_16kb/include/libavutil/pixdesc.h +435 -0
  127. package/android/ffmpeg_16kb/include/libavutil/pixelutils.h +51 -0
  128. package/android/ffmpeg_16kb/include/libavutil/pixfmt.h +691 -0
  129. package/android/ffmpeg_16kb/include/libavutil/random_seed.h +43 -0
  130. package/android/ffmpeg_16kb/include/libavutil/rational.h +221 -0
  131. package/android/ffmpeg_16kb/include/libavutil/rc4.h +69 -0
  132. package/android/ffmpeg_16kb/include/libavutil/replaygain.h +50 -0
  133. package/android/ffmpeg_16kb/include/libavutil/reverse.h +28 -0
  134. package/android/ffmpeg_16kb/include/libavutil/ripemd.h +83 -0
  135. package/android/ffmpeg_16kb/include/libavutil/samplefmt.h +269 -0
  136. package/android/ffmpeg_16kb/include/libavutil/sha.h +90 -0
  137. package/android/ffmpeg_16kb/include/libavutil/sha512.h +92 -0
  138. package/android/ffmpeg_16kb/include/libavutil/spherical.h +227 -0
  139. package/android/ffmpeg_16kb/include/libavutil/stereo3d.h +229 -0
  140. package/android/ffmpeg_16kb/include/libavutil/tea.h +71 -0
  141. package/android/ffmpeg_16kb/include/libavutil/thread.h +204 -0
  142. package/android/ffmpeg_16kb/include/libavutil/threadmessage.h +115 -0
  143. package/android/ffmpeg_16kb/include/libavutil/time.h +56 -0
  144. package/android/ffmpeg_16kb/include/libavutil/timecode.h +199 -0
  145. package/android/ffmpeg_16kb/include/libavutil/timer.h +156 -0
  146. package/android/ffmpeg_16kb/include/libavutil/timestamp.h +78 -0
  147. package/android/ffmpeg_16kb/include/libavutil/tree.h +137 -0
  148. package/android/ffmpeg_16kb/include/libavutil/twofish.h +70 -0
  149. package/android/ffmpeg_16kb/include/libavutil/tx.h +176 -0
  150. package/android/ffmpeg_16kb/include/libavutil/uuid.h +146 -0
  151. package/android/ffmpeg_16kb/include/libavutil/version.h +122 -0
  152. package/android/ffmpeg_16kb/include/libavutil/video_enc_params.h +171 -0
  153. package/android/ffmpeg_16kb/include/libavutil/x86/asm.h +154 -0
  154. package/android/ffmpeg_16kb/include/libavutil/x86/emms.h +58 -0
  155. package/android/ffmpeg_16kb/include/libavutil/x86/timer.h +50 -0
  156. package/android/ffmpeg_16kb/include/libavutil/xtea.h +94 -0
  157. package/android/ffmpeg_16kb/include/libswresample/swresample.h +650 -0
  158. package/android/ffmpeg_16kb/include/libswresample/version.h +46 -0
  159. package/android/ffmpeg_16kb/include/libswresample/version_major.h +31 -0
  160. package/android/ffmpeg_16kb/include/libswscale/swscale.h +436 -0
  161. package/android/ffmpeg_16kb/include/libswscale/version.h +44 -0
  162. package/android/ffmpeg_16kb/include/libswscale/version_major.h +35 -0
  163. package/android/ffmpeg_16kb/lib/arm64-v8a/libavcodec.so +0 -0
  164. package/android/ffmpeg_16kb/lib/arm64-v8a/libavdevice.so +0 -0
  165. package/android/ffmpeg_16kb/lib/arm64-v8a/libavfilter.so +0 -0
  166. package/android/ffmpeg_16kb/lib/arm64-v8a/libavformat.so +0 -0
  167. package/android/ffmpeg_16kb/lib/arm64-v8a/libavutil.so +0 -0
  168. package/android/ffmpeg_16kb/lib/arm64-v8a/libswresample.so +0 -0
  169. package/android/ffmpeg_16kb/lib/arm64-v8a/libswscale.so +0 -0
  170. package/android/ffmpeg_16kb/lib/armeabi-v7a/libavcodec_neon.so +0 -0
  171. package/android/ffmpeg_16kb/lib/armeabi-v7a/libavdevice_neon.so +0 -0
  172. package/android/ffmpeg_16kb/lib/armeabi-v7a/libavfilter_neon.so +0 -0
  173. package/android/ffmpeg_16kb/lib/armeabi-v7a/libavformat_neon.so +0 -0
  174. package/android/ffmpeg_16kb/lib/armeabi-v7a/libavutil_neon.so +0 -0
  175. package/android/ffmpeg_16kb/lib/armeabi-v7a/libswresample_neon.so +0 -0
  176. package/android/ffmpeg_16kb/lib/armeabi-v7a/libswscale_neon.so +0 -0
  177. package/android/ffmpeg_16kb/lib/x86/libavcodec.so +0 -0
  178. package/android/ffmpeg_16kb/lib/x86/libavdevice.so +0 -0
  179. package/android/ffmpeg_16kb/lib/x86/libavfilter.so +0 -0
  180. package/android/ffmpeg_16kb/lib/x86/libavformat.so +0 -0
  181. package/android/ffmpeg_16kb/lib/x86/libavutil.so +0 -0
  182. package/android/ffmpeg_16kb/lib/x86/libswresample.so +0 -0
  183. package/android/ffmpeg_16kb/lib/x86/libswscale.so +0 -0
  184. package/android/ffmpeg_16kb/lib/x86_64/libavcodec.so +0 -0
  185. package/android/ffmpeg_16kb/lib/x86_64/libavdevice.so +0 -0
  186. package/android/ffmpeg_16kb/lib/x86_64/libavfilter.so +0 -0
  187. package/android/ffmpeg_16kb/lib/x86_64/libavformat.so +0 -0
  188. package/android/ffmpeg_16kb/lib/x86_64/libavutil.so +0 -0
  189. package/android/ffmpeg_16kb/lib/x86_64/libswresample.so +0 -0
  190. package/android/ffmpeg_16kb/lib/x86_64/libswscale.so +0 -0
  191. package/android/gradle.properties +5 -0
  192. package/android/src/main/AndroidManifest.xml +3 -0
  193. package/android/src/main/AndroidManifestNew.xml +2 -0
  194. package/android/src/main/java/com/audioanalyzer/AmplitudeData.java +20 -0
  195. package/android/src/main/java/com/audioanalyzer/AudioAnalyzerModule.java +52 -0
  196. package/android/src/main/java/com/audioanalyzer/AudioAnalyzerPackage.java +28 -0
  197. package/cpp/react-native-audio-analyzer.cpp +143 -0
  198. package/cpp/react-native-audio-analyzer.h +27 -0
  199. package/ios/AudioAnalyzer.h +19 -0
  200. package/ios/AudioAnalyzer.mm +43 -0
  201. package/lib/commonjs/helpers.js +34 -0
  202. package/lib/commonjs/helpers.js.map +1 -0
  203. package/lib/commonjs/helpers.test.js +49 -0
  204. package/lib/commonjs/helpers.test.js.map +1 -0
  205. package/lib/commonjs/index.js +35 -0
  206. package/lib/commonjs/index.js.map +1 -0
  207. package/lib/module/helpers.js +27 -0
  208. package/lib/module/helpers.js.map +1 -0
  209. package/lib/module/helpers.test.js +47 -0
  210. package/lib/module/helpers.test.js.map +1 -0
  211. package/lib/module/index.js +15 -0
  212. package/lib/module/index.js.map +1 -0
  213. package/lib/typescript/src/helpers.d.ts +3 -0
  214. package/lib/typescript/src/helpers.d.ts.map +1 -0
  215. package/lib/typescript/src/helpers.test.d.ts +2 -0
  216. package/lib/typescript/src/helpers.test.d.ts.map +1 -0
  217. package/lib/typescript/src/index.d.ts +7 -0
  218. package/lib/typescript/src/index.d.ts.map +1 -0
  219. package/package.json +163 -0
  220. package/react-native-audio-analyzer.podspec +44 -0
  221. package/src/helpers.test.ts +59 -0
  222. package/src/helpers.ts +34 -0
  223. package/src/index.tsx +30 -0
@@ -0,0 +1,609 @@
1
+ /*
2
+ * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+ /**
22
+ * @file
23
+ * @ingroup lavu_mem
24
+ * Memory handling functions
25
+ */
26
+
27
+ #ifndef AVUTIL_MEM_H
28
+ #define AVUTIL_MEM_H
29
+
30
+ #include <limits.h>
31
+ #include <stdint.h>
32
+
33
+ #include "attributes.h"
34
+ #include "avutil.h"
35
+ #include "version.h"
36
+
37
+ /**
38
+ * @addtogroup lavu_mem
39
+ * Utilities for manipulating memory.
40
+ *
41
+ * FFmpeg has several applications of memory that are not required of a typical
42
+ * program. For example, the computing-heavy components like video decoding and
43
+ * encoding can be sped up significantly through the use of aligned memory.
44
+ *
45
+ * However, for each of FFmpeg's applications of memory, there might not be a
46
+ * recognized or standardized API for that specific use. Memory alignment, for
47
+ * instance, varies wildly depending on operating systems, architectures, and
48
+ * compilers. Hence, this component of @ref libavutil is created to make
49
+ * dealing with memory consistently possible on all platforms.
50
+ *
51
+ * @{
52
+ */
53
+
54
+ /**
55
+ * @defgroup lavu_mem_attrs Function Attributes
56
+ * Function attributes applicable to memory handling functions.
57
+ *
58
+ * These function attributes can help compilers emit more useful warnings, or
59
+ * generate better code.
60
+ * @{
61
+ */
62
+
63
+ /**
64
+ * @def av_malloc_attrib
65
+ * Function attribute denoting a malloc-like function.
66
+ *
67
+ * @see <a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007bmalloc_007d-function-attribute-3251">Function attribute `malloc` in GCC's documentation</a>
68
+ */
69
+
70
+ #if AV_GCC_VERSION_AT_LEAST(3,1)
71
+ #define av_malloc_attrib __attribute__((__malloc__))
72
+ #else
73
+ #define av_malloc_attrib
74
+ #endif
75
+
76
+ /**
77
+ * @def av_alloc_size(...)
78
+ * Function attribute used on a function that allocates memory, whose size is
79
+ * given by the specified parameter(s).
80
+ *
81
+ * @code{.c}
82
+ * void *av_malloc(size_t size) av_alloc_size(1);
83
+ * void *av_calloc(size_t nmemb, size_t size) av_alloc_size(1, 2);
84
+ * @endcode
85
+ *
86
+ * @param ... One or two parameter indexes, separated by a comma
87
+ *
88
+ * @see <a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007balloc_005fsize_007d-function-attribute-3220">Function attribute `alloc_size` in GCC's documentation</a>
89
+ */
90
+
91
+ #if AV_GCC_VERSION_AT_LEAST(4,3)
92
+ #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
93
+ #else
94
+ #define av_alloc_size(...)
95
+ #endif
96
+
97
+ /**
98
+ * @}
99
+ */
100
+
101
+ /**
102
+ * @defgroup lavu_mem_funcs Heap Management
103
+ * Functions responsible for allocating, freeing, and copying memory.
104
+ *
105
+ * All memory allocation functions have a built-in upper limit of `INT_MAX`
106
+ * bytes. This may be changed with av_max_alloc(), although exercise extreme
107
+ * caution when doing so.
108
+ *
109
+ * @{
110
+ */
111
+
112
+ /**
113
+ * Allocate a memory block with alignment suitable for all memory accesses
114
+ * (including vectors if available on the CPU).
115
+ *
116
+ * @param size Size in bytes for the memory block to be allocated
117
+ * @return Pointer to the allocated block, or `NULL` if the block cannot
118
+ * be allocated
119
+ * @see av_mallocz()
120
+ */
121
+ void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
122
+
123
+ /**
124
+ * Allocate a memory block with alignment suitable for all memory accesses
125
+ * (including vectors if available on the CPU) and zero all the bytes of the
126
+ * block.
127
+ *
128
+ * @param size Size in bytes for the memory block to be allocated
129
+ * @return Pointer to the allocated block, or `NULL` if it cannot be allocated
130
+ * @see av_malloc()
131
+ */
132
+ void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
133
+
134
+ /**
135
+ * Allocate a memory block for an array with av_malloc().
136
+ *
137
+ * The allocated memory will have size `size * nmemb` bytes.
138
+ *
139
+ * @param nmemb Number of element
140
+ * @param size Size of a single element
141
+ * @return Pointer to the allocated block, or `NULL` if the block cannot
142
+ * be allocated
143
+ * @see av_malloc()
144
+ */
145
+ av_alloc_size(1, 2) void *av_malloc_array(size_t nmemb, size_t size);
146
+
147
+ /**
148
+ * Allocate a memory block for an array with av_mallocz().
149
+ *
150
+ * The allocated memory will have size `size * nmemb` bytes.
151
+ *
152
+ * @param nmemb Number of elements
153
+ * @param size Size of the single element
154
+ * @return Pointer to the allocated block, or `NULL` if the block cannot
155
+ * be allocated
156
+ *
157
+ * @see av_mallocz()
158
+ * @see av_malloc_array()
159
+ */
160
+ void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib av_alloc_size(1, 2);
161
+
162
+ /**
163
+ * Allocate, reallocate, or free a block of memory.
164
+ *
165
+ * If `ptr` is `NULL` and `size` > 0, allocate a new block. Otherwise, expand or
166
+ * shrink that block of memory according to `size`.
167
+ *
168
+ * @param ptr Pointer to a memory block already allocated with
169
+ * av_realloc() or `NULL`
170
+ * @param size Size in bytes of the memory block to be allocated or
171
+ * reallocated
172
+ *
173
+ * @return Pointer to a newly-reallocated block or `NULL` if the block
174
+ * cannot be reallocated
175
+ *
176
+ * @warning Unlike av_malloc(), the returned pointer is not guaranteed to be
177
+ * correctly aligned. The returned pointer must be freed after even
178
+ * if size is zero.
179
+ * @see av_fast_realloc()
180
+ * @see av_reallocp()
181
+ */
182
+ void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
183
+
184
+ /**
185
+ * Allocate, reallocate, or free a block of memory through a pointer to a
186
+ * pointer.
187
+ *
188
+ * If `*ptr` is `NULL` and `size` > 0, allocate a new block. If `size` is
189
+ * zero, free the memory block pointed to by `*ptr`. Otherwise, expand or
190
+ * shrink that block of memory according to `size`.
191
+ *
192
+ * @param[in,out] ptr Pointer to a pointer to a memory block already allocated
193
+ * with av_realloc(), or a pointer to `NULL`. The pointer
194
+ * is updated on success, or freed on failure.
195
+ * @param[in] size Size in bytes for the memory block to be allocated or
196
+ * reallocated
197
+ *
198
+ * @return Zero on success, an AVERROR error code on failure
199
+ *
200
+ * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
201
+ * correctly aligned.
202
+ */
203
+ av_warn_unused_result
204
+ int av_reallocp(void *ptr, size_t size);
205
+
206
+ /**
207
+ * Allocate, reallocate, or free a block of memory.
208
+ *
209
+ * This function does the same thing as av_realloc(), except:
210
+ * - It takes two size arguments and allocates `nelem * elsize` bytes,
211
+ * after checking the result of the multiplication for integer overflow.
212
+ * - It frees the input block in case of failure, thus avoiding the memory
213
+ * leak with the classic
214
+ * @code{.c}
215
+ * buf = realloc(buf);
216
+ * if (!buf)
217
+ * return -1;
218
+ * @endcode
219
+ * pattern.
220
+ */
221
+ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
222
+
223
+ /**
224
+ * Allocate, reallocate, or free an array.
225
+ *
226
+ * If `ptr` is `NULL` and `nmemb` > 0, allocate a new block.
227
+ *
228
+ * @param ptr Pointer to a memory block already allocated with
229
+ * av_realloc() or `NULL`
230
+ * @param nmemb Number of elements in the array
231
+ * @param size Size of the single element of the array
232
+ *
233
+ * @return Pointer to a newly-reallocated block or NULL if the block
234
+ * cannot be reallocated
235
+ *
236
+ * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
237
+ * correctly aligned. The returned pointer must be freed after even if
238
+ * nmemb is zero.
239
+ * @see av_reallocp_array()
240
+ */
241
+ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
242
+
243
+ /**
244
+ * Allocate, reallocate an array through a pointer to a pointer.
245
+ *
246
+ * If `*ptr` is `NULL` and `nmemb` > 0, allocate a new block.
247
+ *
248
+ * @param[in,out] ptr Pointer to a pointer to a memory block already
249
+ * allocated with av_realloc(), or a pointer to `NULL`.
250
+ * The pointer is updated on success, or freed on failure.
251
+ * @param[in] nmemb Number of elements
252
+ * @param[in] size Size of the single element
253
+ *
254
+ * @return Zero on success, an AVERROR error code on failure
255
+ *
256
+ * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
257
+ * correctly aligned. *ptr must be freed after even if nmemb is zero.
258
+ */
259
+ int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
260
+
261
+ /**
262
+ * Reallocate the given buffer if it is not large enough, otherwise do nothing.
263
+ *
264
+ * If the given buffer is `NULL`, then a new uninitialized buffer is allocated.
265
+ *
266
+ * If the given buffer is not large enough, and reallocation fails, `NULL` is
267
+ * returned and `*size` is set to 0, but the original buffer is not changed or
268
+ * freed.
269
+ *
270
+ * A typical use pattern follows:
271
+ *
272
+ * @code{.c}
273
+ * uint8_t *buf = ...;
274
+ * uint8_t *new_buf = av_fast_realloc(buf, &current_size, size_needed);
275
+ * if (!new_buf) {
276
+ * // Allocation failed; clean up original buffer
277
+ * av_freep(&buf);
278
+ * return AVERROR(ENOMEM);
279
+ * }
280
+ * @endcode
281
+ *
282
+ * @param[in,out] ptr Already allocated buffer, or `NULL`
283
+ * @param[in,out] size Pointer to the size of buffer `ptr`. `*size` is
284
+ * updated to the new allocated size, in particular 0
285
+ * in case of failure.
286
+ * @param[in] min_size Desired minimal size of buffer `ptr`
287
+ * @return `ptr` if the buffer is large enough, a pointer to newly reallocated
288
+ * buffer if the buffer was not large enough, or `NULL` in case of
289
+ * error
290
+ * @see av_realloc()
291
+ * @see av_fast_malloc()
292
+ */
293
+ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
294
+
295
+ /**
296
+ * Allocate a buffer, reusing the given one if large enough.
297
+ *
298
+ * Contrary to av_fast_realloc(), the current buffer contents might not be
299
+ * preserved and on error the old buffer is freed, thus no special handling to
300
+ * avoid memleaks is necessary.
301
+ *
302
+ * `*ptr` is allowed to be `NULL`, in which case allocation always happens if
303
+ * `size_needed` is greater than 0.
304
+ *
305
+ * @code{.c}
306
+ * uint8_t *buf = ...;
307
+ * av_fast_malloc(&buf, &current_size, size_needed);
308
+ * if (!buf) {
309
+ * // Allocation failed; buf already freed
310
+ * return AVERROR(ENOMEM);
311
+ * }
312
+ * @endcode
313
+ *
314
+ * @param[in,out] ptr Pointer to pointer to an already allocated buffer.
315
+ * `*ptr` will be overwritten with pointer to new
316
+ * buffer on success or `NULL` on failure
317
+ * @param[in,out] size Pointer to the size of buffer `*ptr`. `*size` is
318
+ * updated to the new allocated size, in particular 0
319
+ * in case of failure.
320
+ * @param[in] min_size Desired minimal size of buffer `*ptr`
321
+ * @see av_realloc()
322
+ * @see av_fast_mallocz()
323
+ */
324
+ void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
325
+
326
+ /**
327
+ * Allocate and clear a buffer, reusing the given one if large enough.
328
+ *
329
+ * Like av_fast_malloc(), but all newly allocated space is initially cleared.
330
+ * Reused buffer is not cleared.
331
+ *
332
+ * `*ptr` is allowed to be `NULL`, in which case allocation always happens if
333
+ * `size_needed` is greater than 0.
334
+ *
335
+ * @param[in,out] ptr Pointer to pointer to an already allocated buffer.
336
+ * `*ptr` will be overwritten with pointer to new
337
+ * buffer on success or `NULL` on failure
338
+ * @param[in,out] size Pointer to the size of buffer `*ptr`. `*size` is
339
+ * updated to the new allocated size, in particular 0
340
+ * in case of failure.
341
+ * @param[in] min_size Desired minimal size of buffer `*ptr`
342
+ * @see av_fast_malloc()
343
+ */
344
+ void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size);
345
+
346
+ /**
347
+ * Free a memory block which has been allocated with a function of av_malloc()
348
+ * or av_realloc() family.
349
+ *
350
+ * @param ptr Pointer to the memory block which should be freed.
351
+ *
352
+ * @note `ptr = NULL` is explicitly allowed.
353
+ * @note It is recommended that you use av_freep() instead, to prevent leaving
354
+ * behind dangling pointers.
355
+ * @see av_freep()
356
+ */
357
+ void av_free(void *ptr);
358
+
359
+ /**
360
+ * Free a memory block which has been allocated with a function of av_malloc()
361
+ * or av_realloc() family, and set the pointer pointing to it to `NULL`.
362
+ *
363
+ * @code{.c}
364
+ * uint8_t *buf = av_malloc(16);
365
+ * av_free(buf);
366
+ * // buf now contains a dangling pointer to freed memory, and accidental
367
+ * // dereference of buf will result in a use-after-free, which may be a
368
+ * // security risk.
369
+ *
370
+ * uint8_t *buf = av_malloc(16);
371
+ * av_freep(&buf);
372
+ * // buf is now NULL, and accidental dereference will only result in a
373
+ * // NULL-pointer dereference.
374
+ * @endcode
375
+ *
376
+ * @param ptr Pointer to the pointer to the memory block which should be freed
377
+ * @note `*ptr = NULL` is safe and leads to no action.
378
+ * @see av_free()
379
+ */
380
+ void av_freep(void *ptr);
381
+
382
+ /**
383
+ * Duplicate a string.
384
+ *
385
+ * @param s String to be duplicated
386
+ * @return Pointer to a newly-allocated string containing a
387
+ * copy of `s` or `NULL` if the string cannot be allocated
388
+ * @see av_strndup()
389
+ */
390
+ char *av_strdup(const char *s) av_malloc_attrib;
391
+
392
+ /**
393
+ * Duplicate a substring of a string.
394
+ *
395
+ * @param s String to be duplicated
396
+ * @param len Maximum length of the resulting string (not counting the
397
+ * terminating byte)
398
+ * @return Pointer to a newly-allocated string containing a
399
+ * substring of `s` or `NULL` if the string cannot be allocated
400
+ */
401
+ char *av_strndup(const char *s, size_t len) av_malloc_attrib;
402
+
403
+ /**
404
+ * Duplicate a buffer with av_malloc().
405
+ *
406
+ * @param p Buffer to be duplicated
407
+ * @param size Size in bytes of the buffer copied
408
+ * @return Pointer to a newly allocated buffer containing a
409
+ * copy of `p` or `NULL` if the buffer cannot be allocated
410
+ */
411
+ void *av_memdup(const void *p, size_t size);
412
+
413
+ /**
414
+ * Overlapping memcpy() implementation.
415
+ *
416
+ * @param dst Destination buffer
417
+ * @param back Number of bytes back to start copying (i.e. the initial size of
418
+ * the overlapping window); must be > 0
419
+ * @param cnt Number of bytes to copy; must be >= 0
420
+ *
421
+ * @note `cnt > back` is valid, this will copy the bytes we just copied,
422
+ * thus creating a repeating pattern with a period length of `back`.
423
+ */
424
+ void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
425
+
426
+ /**
427
+ * @}
428
+ */
429
+
430
+ /**
431
+ * @defgroup lavu_mem_dynarray Dynamic Array
432
+ *
433
+ * Utilities to make an array grow when needed.
434
+ *
435
+ * Sometimes, the programmer would want to have an array that can grow when
436
+ * needed. The libavutil dynamic array utilities fill that need.
437
+ *
438
+ * libavutil supports two systems of appending elements onto a dynamically
439
+ * allocated array, the first one storing the pointer to the value in the
440
+ * array, and the second storing the value directly. In both systems, the
441
+ * caller is responsible for maintaining a variable containing the length of
442
+ * the array, as well as freeing of the array after use.
443
+ *
444
+ * The first system stores pointers to values in a block of dynamically
445
+ * allocated memory. Since only pointers are stored, the function does not need
446
+ * to know the size of the type. Both av_dynarray_add() and
447
+ * av_dynarray_add_nofree() implement this system.
448
+ *
449
+ * @code
450
+ * type **array = NULL; //< an array of pointers to values
451
+ * int nb = 0; //< a variable to keep track of the length of the array
452
+ *
453
+ * type to_be_added = ...;
454
+ * type to_be_added2 = ...;
455
+ *
456
+ * av_dynarray_add(&array, &nb, &to_be_added);
457
+ * if (nb == 0)
458
+ * return AVERROR(ENOMEM);
459
+ *
460
+ * av_dynarray_add(&array, &nb, &to_be_added2);
461
+ * if (nb == 0)
462
+ * return AVERROR(ENOMEM);
463
+ *
464
+ * // Now:
465
+ * // nb == 2
466
+ * // &to_be_added == array[0]
467
+ * // &to_be_added2 == array[1]
468
+ *
469
+ * av_freep(&array);
470
+ * @endcode
471
+ *
472
+ * The second system stores the value directly in a block of memory. As a
473
+ * result, the function has to know the size of the type. av_dynarray2_add()
474
+ * implements this mechanism.
475
+ *
476
+ * @code
477
+ * type *array = NULL; //< an array of values
478
+ * int nb = 0; //< a variable to keep track of the length of the array
479
+ *
480
+ * type to_be_added = ...;
481
+ * type to_be_added2 = ...;
482
+ *
483
+ * type *addr = av_dynarray2_add((void **)&array, &nb, sizeof(*array), NULL);
484
+ * if (!addr)
485
+ * return AVERROR(ENOMEM);
486
+ * memcpy(addr, &to_be_added, sizeof(to_be_added));
487
+ *
488
+ * // Shortcut of the above.
489
+ * type *addr = av_dynarray2_add((void **)&array, &nb, sizeof(*array),
490
+ * (const void *)&to_be_added2);
491
+ * if (!addr)
492
+ * return AVERROR(ENOMEM);
493
+ *
494
+ * // Now:
495
+ * // nb == 2
496
+ * // to_be_added == array[0]
497
+ * // to_be_added2 == array[1]
498
+ *
499
+ * av_freep(&array);
500
+ * @endcode
501
+ *
502
+ * @{
503
+ */
504
+
505
+ /**
506
+ * Add the pointer to an element to a dynamic array.
507
+ *
508
+ * The array to grow is supposed to be an array of pointers to
509
+ * structures, and the element to add must be a pointer to an already
510
+ * allocated structure.
511
+ *
512
+ * The array is reallocated when its size reaches powers of 2.
513
+ * Therefore, the amortized cost of adding an element is constant.
514
+ *
515
+ * In case of success, the pointer to the array is updated in order to
516
+ * point to the new grown array, and the number pointed to by `nb_ptr`
517
+ * is incremented.
518
+ * In case of failure, the array is freed, `*tab_ptr` is set to `NULL` and
519
+ * `*nb_ptr` is set to 0.
520
+ *
521
+ * @param[in,out] tab_ptr Pointer to the array to grow
522
+ * @param[in,out] nb_ptr Pointer to the number of elements in the array
523
+ * @param[in] elem Element to add
524
+ * @see av_dynarray_add_nofree(), av_dynarray2_add()
525
+ */
526
+ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
527
+
528
+ /**
529
+ * Add an element to a dynamic array.
530
+ *
531
+ * Function has the same functionality as av_dynarray_add(),
532
+ * but it doesn't free memory on fails. It returns error code
533
+ * instead and leave current buffer untouched.
534
+ *
535
+ * @return >=0 on success, negative otherwise
536
+ * @see av_dynarray_add(), av_dynarray2_add()
537
+ */
538
+ av_warn_unused_result
539
+ int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
540
+
541
+ /**
542
+ * Add an element of size `elem_size` to a dynamic array.
543
+ *
544
+ * The array is reallocated when its number of elements reaches powers of 2.
545
+ * Therefore, the amortized cost of adding an element is constant.
546
+ *
547
+ * In case of success, the pointer to the array is updated in order to
548
+ * point to the new grown array, and the number pointed to by `nb_ptr`
549
+ * is incremented.
550
+ * In case of failure, the array is freed, `*tab_ptr` is set to `NULL` and
551
+ * `*nb_ptr` is set to 0.
552
+ *
553
+ * @param[in,out] tab_ptr Pointer to the array to grow
554
+ * @param[in,out] nb_ptr Pointer to the number of elements in the array
555
+ * @param[in] elem_size Size in bytes of an element in the array
556
+ * @param[in] elem_data Pointer to the data of the element to add. If
557
+ * `NULL`, the space of the newly added element is
558
+ * allocated but left uninitialized.
559
+ *
560
+ * @return Pointer to the data of the element to copy in the newly allocated
561
+ * space
562
+ * @see av_dynarray_add(), av_dynarray_add_nofree()
563
+ */
564
+ void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
565
+ const uint8_t *elem_data);
566
+
567
+ /**
568
+ * @}
569
+ */
570
+
571
+ /**
572
+ * @defgroup lavu_mem_misc Miscellaneous Functions
573
+ *
574
+ * Other functions related to memory allocation.
575
+ *
576
+ * @{
577
+ */
578
+
579
+ /**
580
+ * Multiply two `size_t` values checking for overflow.
581
+ *
582
+ * @param[in] a Operand of multiplication
583
+ * @param[in] b Operand of multiplication
584
+ * @param[out] r Pointer to the result of the operation
585
+ * @return 0 on success, AVERROR(EINVAL) on overflow
586
+ */
587
+ int av_size_mult(size_t a, size_t b, size_t *r);
588
+
589
+ /**
590
+ * Set the maximum size that may be allocated in one block.
591
+ *
592
+ * The value specified with this function is effective for all libavutil's @ref
593
+ * lavu_mem_funcs "heap management functions."
594
+ *
595
+ * By default, the max value is defined as `INT_MAX`.
596
+ *
597
+ * @param max Value to be set as the new maximum size
598
+ *
599
+ * @warning Exercise extreme caution when using this function. Don't touch
600
+ * this if you do not understand the full consequence of doing so.
601
+ */
602
+ void av_max_alloc(size_t max);
603
+
604
+ /**
605
+ * @}
606
+ * @}
607
+ */
608
+
609
+ #endif /* AVUTIL_MEM_H */
@@ -0,0 +1,57 @@
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
+ #ifndef AVUTIL_MOTION_VECTOR_H
20
+ #define AVUTIL_MOTION_VECTOR_H
21
+
22
+ #include <stdint.h>
23
+
24
+ typedef struct AVMotionVector {
25
+ /**
26
+ * Where the current macroblock comes from; negative value when it comes
27
+ * from the past, positive value when it comes from the future.
28
+ * XXX: set exact relative ref frame reference instead of a +/- 1 "direction".
29
+ */
30
+ int32_t source;
31
+ /**
32
+ * Width and height of the block.
33
+ */
34
+ uint8_t w, h;
35
+ /**
36
+ * Absolute source position. Can be outside the frame area.
37
+ */
38
+ int16_t src_x, src_y;
39
+ /**
40
+ * Absolute destination position. Can be outside the frame area.
41
+ */
42
+ int16_t dst_x, dst_y;
43
+ /**
44
+ * Extra flag information.
45
+ * Currently unused.
46
+ */
47
+ uint64_t flags;
48
+ /**
49
+ * Motion vector
50
+ * src_x = dst_x + motion_x / motion_scale
51
+ * src_y = dst_y + motion_y / motion_scale
52
+ */
53
+ int32_t motion_x, motion_y;
54
+ uint16_t motion_scale;
55
+ } AVMotionVector;
56
+
57
+ #endif /* AVUTIL_MOTION_VECTOR_H */