/src/LAME-fuzzers/fuzzer-encoder.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* LAME encoder fuzzer by Guido Vranken <guidovranken@gmail.com> */ |
2 | | |
3 | | #include <cmath> |
4 | | #include <cstdint> |
5 | | #include <cstdlib> |
6 | | #include <fuzzing/datasource/datasource.hpp> |
7 | | #include <fuzzing/memory.hpp> |
8 | | #include <lame.h> |
9 | | #include <limits> |
10 | | #include <memory> |
11 | | #include <sstream> |
12 | | #include <stdexcept> |
13 | | #include <string> |
14 | | |
15 | | #ifdef MSAN |
16 | | extern "C" { |
17 | | void __msan_allocated_memory(const volatile void* data, size_t size); |
18 | | } |
19 | | #endif |
20 | | |
21 | | using fuzzing::datasource::Datasource; |
22 | | |
23 | | namespace limits { |
24 | | template <size_t Min, size_t Max> |
25 | | class Limit { |
26 | | static_assert(Min <= Max); |
27 | | |
28 | | public: |
29 | 26 | Limit(void) { } limits::Limit<1ul, 1048576ul>::Limit() Line | Count | Source | 29 | 2 | Limit(void) { } |
limits::Limit<1ul, 1024ul>::Limit() Line | Count | Source | 29 | 10 | Limit(void) { } |
limits::Limit<100ul, 1000000ul>::Limit() Line | Count | Source | 29 | 2 | Limit(void) { } |
limits::Limit<0ul, 9ul>::Limit() Line | Count | Source | 29 | 2 | Limit(void) { } |
limits::Limit<0ul, 1000000ul>::Limit() Line | Count | Source | 29 | 2 | Limit(void) { } |
limits::Limit<1000ul, 1000000ul>::Limit() Line | Count | Source | 29 | 6 | Limit(void) { } |
limits::Limit<1ul, 100ul>::Limit() Line | Count | Source | 29 | 2 | Limit(void) { } |
|
30 | | |
31 | 32.4k | size_t Test(const size_t val) const { |
32 | 32.4k | if ( val < Min || val > Max ) { |
33 | | /* If not within bounds, default to the minimum allowed value */ |
34 | 18.6k | return Min; |
35 | 18.6k | } |
36 | | |
37 | 13.7k | return val; |
38 | 32.4k | } limits::Limit<1ul, 1048576ul>::Test(unsigned long) const Line | Count | Source | 31 | 7.92k | size_t Test(const size_t val) const { | 32 | 7.92k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 3.16k | return Min; | 35 | 3.16k | } | 36 | | | 37 | 4.76k | return val; | 38 | 7.92k | } |
limits::Limit<1ul, 1024ul>::Test(unsigned long) const Line | Count | Source | 31 | 7.80k | size_t Test(const size_t val) const { | 32 | 7.80k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 5.11k | return Min; | 35 | 5.11k | } | 36 | | | 37 | 2.69k | return val; | 38 | 7.80k | } |
limits::Limit<0ul, 9ul>::Test(unsigned long) const Line | Count | Source | 31 | 7.12k | size_t Test(const size_t val) const { | 32 | 7.12k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 4.22k | return Min; | 35 | 4.22k | } | 36 | | | 37 | 2.89k | return val; | 38 | 7.12k | } |
limits::Limit<100ul, 1000000ul>::Test(unsigned long) const Line | Count | Source | 31 | 7.10k | size_t Test(const size_t val) const { | 32 | 7.10k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 4.59k | return Min; | 35 | 4.59k | } | 36 | | | 37 | 2.51k | return val; | 38 | 7.10k | } |
limits::Limit<0ul, 1000000ul>::Test(unsigned long) const Line | Count | Source | 31 | 852 | size_t Test(const size_t val) const { | 32 | 852 | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 340 | return Min; | 35 | 340 | } | 36 | | | 37 | 512 | return val; | 38 | 852 | } |
limits::Limit<1000ul, 1000000ul>::Test(unsigned long) const Line | Count | Source | 31 | 1.58k | size_t Test(const size_t val) const { | 32 | 1.58k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 1.21k | return Min; | 35 | 1.21k | } | 36 | | | 37 | 375 | return val; | 38 | 1.58k | } |
|
39 | | |
40 | | template <typename T = uint32_t> |
41 | 32.4k | size_t Generate(fuzzing::datasource::Datasource& ds) { |
42 | 32.4k | const size_t ret = ds.Get<T>(); |
43 | 32.4k | return Test(ret); |
44 | 32.4k | } unsigned long limits::Limit<1ul, 1048576ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 7.98k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 7.98k | const size_t ret = ds.Get<T>(); | 43 | 7.98k | return Test(ret); | 44 | 7.98k | } |
unsigned long limits::Limit<1ul, 1024ul>::Generate<unsigned char>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 1.35k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 1.35k | const size_t ret = ds.Get<T>(); | 43 | 1.35k | return Test(ret); | 44 | 1.35k | } |
unsigned long limits::Limit<1ul, 1024ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 6.45k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 6.45k | const size_t ret = ds.Get<T>(); | 43 | 6.45k | return Test(ret); | 44 | 6.45k | } |
unsigned long limits::Limit<0ul, 9ul>::Generate<unsigned char>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 7.12k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 7.12k | const size_t ret = ds.Get<T>(); | 43 | 7.12k | return Test(ret); | 44 | 7.12k | } |
unsigned long limits::Limit<100ul, 1000000ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 7.12k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 7.12k | const size_t ret = ds.Get<T>(); | 43 | 7.12k | return Test(ret); | 44 | 7.12k | } |
unsigned long limits::Limit<0ul, 1000000ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 854 | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 854 | const size_t ret = ds.Get<T>(); | 43 | 854 | return Test(ret); | 44 | 854 | } |
unsigned long limits::Limit<1000ul, 1000000ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 1.59k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 1.59k | const size_t ret = ds.Get<T>(); | 43 | 1.59k | return Test(ret); | 44 | 1.59k | } |
|
45 | | }; |
46 | | |
47 | | /* Set these to acceptable min/max limits */ |
48 | | static Limit<1, 1024*1024> OutBufferSize; |
49 | | static Limit<1, 1024> MinBitrate; |
50 | | static Limit<1, 1024> MaxBitrate; |
51 | | static Limit<1, 1024> VBRQ; |
52 | | static Limit<1, 1024> ABRBitrate; |
53 | | static Limit<1, 1024> CBRBitrate; |
54 | | static Limit<100, 1000000> OutSamplerate; |
55 | | static Limit<0, 9> Quality; |
56 | | static Limit<0, 1000000> LowpassFrequency; |
57 | | static Limit<1000, 1000000> LowpassWidth; |
58 | | static Limit<1000, 1000000> HighpassFrequency; |
59 | | static Limit<1000, 1000000> HighpassWidth; |
60 | | static Limit<1, 100> CompressionRatio; |
61 | | } |
62 | | |
63 | 26.3k | #define _(expr) Debug ? printf("%s\n", #expr) : 0; expr; |
64 | | |
65 | | /* Unspecialized method, for all types other than |
66 | | * float and double; do nothing. |
67 | | */ |
68 | 119M | template <typename T> bool isNAN(const T& val) { |
69 | 119M | (void)val; |
70 | | |
71 | 119M | return false; |
72 | 119M | } bool isNAN<short>(short const&) Line | Count | Source | 68 | 113M | template <typename T> bool isNAN(const T& val) { | 69 | 113M | (void)val; | 70 | | | 71 | 113M | return false; | 72 | 113M | } |
bool isNAN<int>(int const&) Line | Count | Source | 68 | 4.17M | template <typename T> bool isNAN(const T& val) { | 69 | 4.17M | (void)val; | 70 | | | 71 | 4.17M | return false; | 72 | 4.17M | } |
bool isNAN<long>(long const&) Line | Count | Source | 68 | 2.36M | template <typename T> bool isNAN(const T& val) { | 69 | 2.36M | (void)val; | 70 | | | 71 | 2.36M | return false; | 72 | 2.36M | } |
|
73 | | |
74 | 5.24M | template <> bool isNAN<float>(const float& val) { |
75 | 5.24M | return std::isnan(val); |
76 | 5.24M | } |
77 | | |
78 | 2.26M | template <> bool isNAN<double>(const double& val) { |
79 | 2.26M | return std::isnan(val); |
80 | 2.26M | } |
81 | | |
82 | 0 | std::string debug_define_size_t(const std::string name, const size_t val) { |
83 | 0 | return "const size_t " + name + " = " + std::to_string(val) + ";"; |
84 | 0 | } |
85 | | |
86 | | template <typename T> |
87 | | struct DebugDefineArray { |
88 | 0 | static std::string Str(const std::string name, const std::string typeName, const T* inData, const size_t inDataSize, const bool indent) { |
89 | 0 | std::stringstream ret; |
90 | |
|
91 | 0 | if ( indent ) { |
92 | 0 | ret << "\t"; |
93 | 0 | } |
94 | |
|
95 | 0 | ret << "const " << typeName << " " << name << "[] = {\n"; |
96 | |
|
97 | 0 | if ( indent ) { |
98 | 0 | ret << "\t"; |
99 | 0 | } |
100 | |
|
101 | 0 | for (size_t i = 0; i < inDataSize; i++) { |
102 | 0 | if ( i && !(i % 16) ) { |
103 | 0 | ret << "\n"; |
104 | 0 | if ( indent ) { |
105 | 0 | ret << "\t"; |
106 | 0 | } |
107 | 0 | } |
108 | |
|
109 | 0 | ret << "\t" << std::to_string(inData[i]) << ", "; |
110 | 0 | } |
111 | 0 | ret << "\n"; |
112 | |
|
113 | 0 | if ( indent ) { |
114 | 0 | ret << "\t"; |
115 | 0 | } |
116 | |
|
117 | 0 | ret << "};\n"; |
118 | |
|
119 | 0 | return ret.str(); |
120 | 0 | } Unexecuted instantiation: DebugDefineArray<short>::Str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, short const*, unsigned long, bool) Unexecuted instantiation: DebugDefineArray<int>::Str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int const*, unsigned long, bool) Unexecuted instantiation: DebugDefineArray<long>::Str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long const*, unsigned long, bool) Unexecuted instantiation: DebugDefineArray<float>::Str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float const*, unsigned long, bool) Unexecuted instantiation: DebugDefineArray<double>::Str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, double const*, unsigned long, bool) Unexecuted instantiation: DebugDefineArray<unsigned char>::Str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned char const*, unsigned long, bool) |
121 | | }; |
122 | | |
123 | | class EncoderCoreBase { |
124 | | public: |
125 | 7.84k | EncoderCoreBase(void) { } |
126 | 7.84k | virtual ~EncoderCoreBase() { } |
127 | | virtual bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) = 0; |
128 | | }; |
129 | | |
130 | | template <typename T, bool Debug> |
131 | | class EncoderCore : public EncoderCoreBase { |
132 | | private: |
133 | | Datasource& ds; |
134 | | lame_global_flags* flags; |
135 | | |
136 | | std::vector< std::vector<T> > inDataV; |
137 | | typename std::vector< std::vector<T> >::iterator it; |
138 | | const bool useInterleavingFunction; |
139 | | const bool useIEEEFunction; |
140 | | |
141 | 7.83k | void getInputData(void) { |
142 | 715k | while ( ds.Get<bool>() ) { |
143 | 707k | const auto data = ds.GetData(0); |
144 | | |
145 | | /* Round to a multiple of sizeof(T) */ |
146 | 707k | const size_t copySize = data.size() - (data.size() % sizeof(T)); |
147 | | |
148 | 707k | std::vector<T> toInsert; |
149 | 707k | toInsert.resize( data.size() / sizeof(T) ); |
150 | | |
151 | 707k | memcpy(toInsert.data(), data.data(), copySize); |
152 | | |
153 | | /* Correct NAN values */ |
154 | 127M | for (size_t i = 0; i < toInsert.size(); i++) { |
155 | 127M | if ( isNAN(toInsert[i]) ) { |
156 | | /* If NaN, set to default value (0.0) */ |
157 | 276k | toInsert[i] = {}; |
158 | 276k | } |
159 | 127M | } |
160 | | |
161 | 707k | inDataV.push_back(toInsert); |
162 | 707k | } |
163 | | |
164 | 7.83k | it = inDataV.begin(); |
165 | 7.83k | } EncoderCore<short, false>::getInputData() Line | Count | Source | 141 | 4.69k | void getInputData(void) { | 142 | 144k | while ( ds.Get<bool>() ) { | 143 | 140k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 140k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 140k | std::vector<T> toInsert; | 149 | 140k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 140k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 113M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 113M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 0 | toInsert[i] = {}; | 158 | 0 | } | 159 | 113M | } | 160 | | | 161 | 140k | inDataV.push_back(toInsert); | 162 | 140k | } | 163 | | | 164 | 4.69k | it = inDataV.begin(); | 165 | 4.69k | } |
EncoderCore<int, false>::getInputData() Line | Count | Source | 141 | 701 | void getInputData(void) { | 142 | 133k | while ( ds.Get<bool>() ) { | 143 | 133k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 133k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 133k | std::vector<T> toInsert; | 149 | 133k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 133k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 4.30M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 4.17M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 0 | toInsert[i] = {}; | 158 | 0 | } | 159 | 4.17M | } | 160 | | | 161 | 133k | inDataV.push_back(toInsert); | 162 | 133k | } | 163 | | | 164 | 701 | it = inDataV.begin(); | 165 | 701 | } |
EncoderCore<long, false>::getInputData() Line | Count | Source | 141 | 976 | void getInputData(void) { | 142 | 117k | while ( ds.Get<bool>() ) { | 143 | 116k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 116k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 116k | std::vector<T> toInsert; | 149 | 116k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 116k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 2.48M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 2.36M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 0 | toInsert[i] = {}; | 158 | 0 | } | 159 | 2.36M | } | 160 | | | 161 | 116k | inDataV.push_back(toInsert); | 162 | 116k | } | 163 | | | 164 | 976 | it = inDataV.begin(); | 165 | 976 | } |
EncoderCore<float, false>::getInputData() Line | Count | Source | 141 | 910 | void getInputData(void) { | 142 | 250k | while ( ds.Get<bool>() ) { | 143 | 250k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 250k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 250k | std::vector<T> toInsert; | 149 | 250k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 250k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 5.49M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 5.24M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 220k | toInsert[i] = {}; | 158 | 220k | } | 159 | 5.24M | } | 160 | | | 161 | 250k | inDataV.push_back(toInsert); | 162 | 250k | } | 163 | | | 164 | 910 | it = inDataV.begin(); | 165 | 910 | } |
EncoderCore<double, false>::getInputData() Line | Count | Source | 141 | 548 | void getInputData(void) { | 142 | 68.1k | while ( ds.Get<bool>() ) { | 143 | 67.5k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 67.5k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 67.5k | std::vector<T> toInsert; | 149 | 67.5k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 67.5k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 2.33M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 2.26M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 56.1k | toInsert[i] = {}; | 158 | 56.1k | } | 159 | 2.26M | } | 160 | | | 161 | 67.5k | inDataV.push_back(toInsert); | 162 | 67.5k | } | 163 | | | 164 | 548 | it = inDataV.begin(); | 165 | 548 | } |
Unexecuted instantiation: EncoderCore<short, true>::getInputData() Unexecuted instantiation: EncoderCore<int, true>::getInputData() Unexecuted instantiation: EncoderCore<long, true>::getInputData() Unexecuted instantiation: EncoderCore<float, true>::getInputData() Unexecuted instantiation: EncoderCore<double, true>::getInputData() |
166 | | |
167 | | template <typename _T, long Min, long Max> |
168 | | struct InputCorrect { |
169 | | static_assert(std::numeric_limits<_T>::lowest() <= Min); |
170 | | static_assert(std::numeric_limits<_T>::max() >= Max); |
171 | | |
172 | 3.83k | static void Correct(_T* inData, const size_t inDataSize) { |
173 | 3.83k | if ( inData == nullptr ) { |
174 | 847 | return; |
175 | 847 | } |
176 | | |
177 | 7.59M | for (size_t i = 0; i < inDataSize; i++) { |
178 | 7.58M | if ( inData[i] > Max ) { |
179 | 1.40M | inData[i] = Max; |
180 | 6.18M | } else if ( inData[i] < Min ) { |
181 | 1.62M | inData[i] = Min; |
182 | 1.62M | } |
183 | 7.58M | } |
184 | 2.98k | } EncoderCore<long, false>::InputCorrect<long, -32768l, 32768l>::Correct(long*, unsigned long) Line | Count | Source | 172 | 1.36k | static void Correct(_T* inData, const size_t inDataSize) { | 173 | 1.36k | if ( inData == nullptr ) { | 174 | 306 | return; | 175 | 306 | } | 176 | | | 177 | 1.80M | for (size_t i = 0; i < inDataSize; i++) { | 178 | 1.79M | if ( inData[i] > Max ) { | 179 | 943k | inData[i] = Max; | 180 | 943k | } else if ( inData[i] < Min ) { | 181 | 582k | inData[i] = Min; | 182 | 582k | } | 183 | 1.79M | } | 184 | 1.05k | } |
EncoderCore<float, false>::InputCorrect<float, -32768l, 32768l>::Correct(float*, unsigned long) Line | Count | Source | 172 | 696 | static void Correct(_T* inData, const size_t inDataSize) { | 173 | 696 | if ( inData == nullptr ) { | 174 | 126 | return; | 175 | 126 | } | 176 | | | 177 | 1.48M | for (size_t i = 0; i < inDataSize; i++) { | 178 | 1.48M | if ( inData[i] > Max ) { | 179 | 120k | inData[i] = Max; | 180 | 1.36M | } else if ( inData[i] < Min ) { | 181 | 270k | inData[i] = Min; | 182 | 270k | } | 183 | 1.48M | } | 184 | 570 | } |
EncoderCore<float, false>::InputCorrect<float, -1l, 1l>::Correct(float*, unsigned long) Line | Count | Source | 172 | 939 | static void Correct(_T* inData, const size_t inDataSize) { | 173 | 939 | if ( inData == nullptr ) { | 174 | 196 | return; | 175 | 196 | } | 176 | | | 177 | 2.72M | for (size_t i = 0; i < inDataSize; i++) { | 178 | 2.72M | if ( inData[i] > Max ) { | 179 | 205k | inData[i] = Max; | 180 | 2.52M | } else if ( inData[i] < Min ) { | 181 | 481k | inData[i] = Min; | 182 | 481k | } | 183 | 2.72M | } | 184 | 743 | } |
EncoderCore<double, false>::InputCorrect<double, -1l, 1l>::Correct(double*, unsigned long) Line | Count | Source | 172 | 836 | static void Correct(_T* inData, const size_t inDataSize) { | 173 | 836 | if ( inData == nullptr ) { | 174 | 219 | return; | 175 | 219 | } | 176 | | | 177 | 1.57M | for (size_t i = 0; i < inDataSize; i++) { | 178 | 1.57M | if ( inData[i] > Max ) { | 179 | 131k | inData[i] = Max; | 180 | 1.44M | } else if ( inData[i] < Min ) { | 181 | 288k | inData[i] = Min; | 182 | 288k | } | 183 | 1.57M | } | 184 | 617 | } |
Unexecuted instantiation: EncoderCore<long, true>::InputCorrect<long, -32768l, 32768l>::Correct(long*, unsigned long) Unexecuted instantiation: EncoderCore<float, true>::InputCorrect<float, -32768l, 32768l>::Correct(float*, unsigned long) Unexecuted instantiation: EncoderCore<float, true>::InputCorrect<float, -1l, 1l>::Correct(float*, unsigned long) Unexecuted instantiation: EncoderCore<double, true>::InputCorrect<double, -1l, 1l>::Correct(double*, unsigned long) |
185 | | }; |
186 | | |
187 | | template <typename T_, bool Debug_> |
188 | | struct EncodeSingle { |
189 | | static int encode( |
190 | | lame_global_flags* flags, |
191 | | T* inData, |
192 | | const size_t inDataSize, |
193 | | uint8_t* outBuffer, |
194 | | const size_t outBufferSize, |
195 | | bool useInterleavedFunction, |
196 | | bool useIEEEFunction); |
197 | | }; |
198 | | |
199 | | template<bool Debug_> struct EncodeSingle<short int, Debug_> { |
200 | | static int encode( |
201 | | lame_global_flags* flags, |
202 | | short int* inDataL, |
203 | | short int* inDataR, |
204 | | const size_t inDataSize, |
205 | | uint8_t* outBuffer, |
206 | | const size_t outBufferSize, |
207 | | bool useInterleavingFunction, |
208 | 7.40k | bool useIEEEFunction) { |
209 | | /* Not applicable for short int */ |
210 | 7.40k | (void)useIEEEFunction; |
211 | | |
212 | 7.40k | if ( useInterleavingFunction == false ) { |
213 | 5.02k | Debug ? printf("{\n") : 0; |
214 | | |
215 | 5.02k | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
216 | | |
217 | 5.02k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataL", "short int", inDataL, inDataSize, true).c_str()) : 0; |
218 | 5.02k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataR", "short int", inDataR, inDataSize, true).c_str()) : 0; |
219 | | |
220 | 5.02k | Debug ? |
221 | 0 | printf("\tlame_encode_buffer(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
222 | 5.02k | : 0; |
223 | | |
224 | 5.02k | const int ret = lame_encode_buffer(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
225 | | |
226 | 5.02k | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
227 | | |
228 | 5.02k | Debug ? printf("}\n") : 0; |
229 | | |
230 | 5.02k | return ret; |
231 | 5.02k | } else { |
232 | 2.37k | Debug ? printf("{\n") : 0; |
233 | | |
234 | 2.37k | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
235 | | |
236 | 2.37k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataL", "short int", inDataL, inDataSize * 2, true).c_str()) : 0; |
237 | | |
238 | 2.37k | Debug ? |
239 | 0 | printf("\tlame_encode_buffer_interleaved(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") |
240 | 2.37k | : 0; |
241 | | |
242 | 2.37k | const int ret = lame_encode_buffer_interleaved(flags, inDataL, inDataSize, outBuffer, outBufferSize); |
243 | | |
244 | 2.37k | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
245 | | |
246 | 2.37k | Debug ? printf("}\n") : 0; |
247 | | |
248 | 2.37k | return ret; |
249 | 2.37k | } |
250 | 7.40k | } EncoderCore<short, false>::EncodeSingle<short, false>::encode(lame_global_struct*, short*, short*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 208 | 7.40k | bool useIEEEFunction) { | 209 | | /* Not applicable for short int */ | 210 | 7.40k | (void)useIEEEFunction; | 211 | | | 212 | 7.40k | if ( useInterleavingFunction == false ) { | 213 | 5.02k | Debug ? printf("{\n") : 0; | 214 | | | 215 | 5.02k | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 216 | | | 217 | 5.02k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataL", "short int", inDataL, inDataSize, true).c_str()) : 0; | 218 | 5.02k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataR", "short int", inDataR, inDataSize, true).c_str()) : 0; | 219 | | | 220 | 5.02k | Debug ? | 221 | 0 | printf("\tlame_encode_buffer(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 222 | 5.02k | : 0; | 223 | | | 224 | 5.02k | const int ret = lame_encode_buffer(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 225 | | | 226 | 5.02k | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 227 | | | 228 | 5.02k | Debug ? printf("}\n") : 0; | 229 | | | 230 | 5.02k | return ret; | 231 | 5.02k | } else { | 232 | 2.37k | Debug ? printf("{\n") : 0; | 233 | | | 234 | 2.37k | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 235 | | | 236 | 2.37k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataL", "short int", inDataL, inDataSize * 2, true).c_str()) : 0; | 237 | | | 238 | 2.37k | Debug ? | 239 | 0 | printf("\tlame_encode_buffer_interleaved(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") | 240 | 2.37k | : 0; | 241 | | | 242 | 2.37k | const int ret = lame_encode_buffer_interleaved(flags, inDataL, inDataSize, outBuffer, outBufferSize); | 243 | | | 244 | 2.37k | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 245 | | | 246 | 2.37k | Debug ? printf("}\n") : 0; | 247 | | | 248 | 2.37k | return ret; | 249 | 2.37k | } | 250 | 7.40k | } |
Unexecuted instantiation: EncoderCore<short, true>::EncodeSingle<short, true>::encode(lame_global_struct*, short*, short*, unsigned long, unsigned char*, unsigned long, bool, bool) |
251 | | }; |
252 | | |
253 | | template<bool Debug_> struct EncodeSingle<int, Debug_> { |
254 | | static int encode( |
255 | | lame_global_flags* flags, |
256 | | int* inDataL, |
257 | | int* inDataR, |
258 | | const size_t inDataSize, |
259 | | uint8_t* outBuffer, |
260 | | const size_t outBufferSize, |
261 | | bool useInterleavingFunction, |
262 | 489 | bool useIEEEFunction ) { |
263 | | /* Not applicable for int */ |
264 | 489 | (void)useIEEEFunction; |
265 | | |
266 | 489 | if ( useInterleavingFunction == false ) { |
267 | 319 | Debug ? printf("{\n") : 0; |
268 | | |
269 | 319 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
270 | | |
271 | 319 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataL", "int", inDataL, inDataSize, true).c_str()) : 0; |
272 | 319 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataR", "int", inDataR, inDataSize, true).c_str()) : 0; |
273 | | |
274 | 319 | Debug ? |
275 | 0 | printf("\tlame_encode_buffer_int(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
276 | 319 | : 0; |
277 | | |
278 | 319 | const int ret = lame_encode_buffer_int(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
279 | | |
280 | 319 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
281 | | |
282 | 319 | Debug ? printf("}\n") : 0; |
283 | | |
284 | 319 | return ret; |
285 | 319 | } else { |
286 | 170 | Debug ? printf("{\n") : 0; |
287 | | |
288 | 170 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
289 | | |
290 | 170 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataL", "int", inDataL, inDataSize * 2, true).c_str()) : 0; |
291 | | |
292 | 170 | Debug ? |
293 | 0 | printf("\tlame_encode_buffer_interleaved_int(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") |
294 | 170 | : 0; |
295 | | |
296 | 170 | const int ret = lame_encode_buffer_interleaved_int(flags, inDataL, inDataSize, outBuffer, outBufferSize); |
297 | | |
298 | 170 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
299 | | |
300 | 170 | Debug ? printf("}\n") : 0; |
301 | | |
302 | 170 | return ret; |
303 | 170 | } |
304 | 489 | } EncoderCore<int, false>::EncodeSingle<int, false>::encode(lame_global_struct*, int*, int*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 262 | 489 | bool useIEEEFunction ) { | 263 | | /* Not applicable for int */ | 264 | 489 | (void)useIEEEFunction; | 265 | | | 266 | 489 | if ( useInterleavingFunction == false ) { | 267 | 319 | Debug ? printf("{\n") : 0; | 268 | | | 269 | 319 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 270 | | | 271 | 319 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataL", "int", inDataL, inDataSize, true).c_str()) : 0; | 272 | 319 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataR", "int", inDataR, inDataSize, true).c_str()) : 0; | 273 | | | 274 | 319 | Debug ? | 275 | 0 | printf("\tlame_encode_buffer_int(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 276 | 319 | : 0; | 277 | | | 278 | 319 | const int ret = lame_encode_buffer_int(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 279 | | | 280 | 319 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 281 | | | 282 | 319 | Debug ? printf("}\n") : 0; | 283 | | | 284 | 319 | return ret; | 285 | 319 | } else { | 286 | 170 | Debug ? printf("{\n") : 0; | 287 | | | 288 | 170 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 289 | | | 290 | 170 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataL", "int", inDataL, inDataSize * 2, true).c_str()) : 0; | 291 | | | 292 | 170 | Debug ? | 293 | 0 | printf("\tlame_encode_buffer_interleaved_int(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") | 294 | 170 | : 0; | 295 | | | 296 | 170 | const int ret = lame_encode_buffer_interleaved_int(flags, inDataL, inDataSize, outBuffer, outBufferSize); | 297 | | | 298 | 170 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 299 | | | 300 | 170 | Debug ? printf("}\n") : 0; | 301 | | | 302 | 170 | return ret; | 303 | 170 | } | 304 | 489 | } |
Unexecuted instantiation: EncoderCore<int, true>::EncodeSingle<int, true>::encode(lame_global_struct*, int*, int*, unsigned long, unsigned char*, unsigned long, bool, bool) |
305 | | }; |
306 | | |
307 | | template<bool Debug_> struct EncodeSingle<long, Debug_> { |
308 | | static int encode( |
309 | | lame_global_flags* flags, |
310 | | long* inDataL, |
311 | | long* inDataR, |
312 | | const size_t inDataSize, |
313 | | uint8_t* outBuffer, |
314 | | const size_t outBufferSize, |
315 | | bool useInterleavingFunction, |
316 | 726 | bool useIEEEFunction) { |
317 | | /* Not applicable for long */ |
318 | 726 | (void)useIEEEFunction; |
319 | | |
320 | 726 | if ( useInterleavingFunction == false ) { |
321 | 682 | InputCorrect<long, -32768, 32768>::Correct(inDataL, inDataSize); |
322 | 682 | InputCorrect<long, -32768, 32768>::Correct(inDataR, inDataSize); |
323 | | |
324 | 682 | Debug ? printf("{\n") : 0; |
325 | | |
326 | 682 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
327 | | |
328 | 682 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataL", "long", inDataL, inDataSize, true).c_str()) : 0; |
329 | 682 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataR", "long", inDataR, inDataSize, true).c_str()) : 0; |
330 | | |
331 | 682 | Debug ? |
332 | 0 | printf("\tlame_encode_buffer_long(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
333 | 682 | : 0; |
334 | | |
335 | 682 | const int ret = lame_encode_buffer_long(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
336 | | |
337 | 682 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
338 | | |
339 | 682 | Debug ? printf("}\n") : 0; |
340 | | |
341 | 682 | return ret; |
342 | 682 | } else { |
343 | 44 | Debug ? printf("{\n") : 0; |
344 | | |
345 | 44 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
346 | | |
347 | 44 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataL", "long", inDataL, inDataSize, true).c_str()) : 0; |
348 | 44 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataR", "long", inDataR, inDataSize, true).c_str()) : 0; |
349 | | |
350 | 44 | Debug ? |
351 | 0 | printf("\tlame_encode_buffer_long2(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
352 | 44 | : 0; |
353 | | |
354 | | /* Not actually interleaved */ |
355 | 44 | const int ret = lame_encode_buffer_long2(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
356 | | |
357 | 44 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
358 | | |
359 | 44 | Debug ? printf("}\n") : 0; |
360 | | |
361 | 44 | return ret; |
362 | 44 | } |
363 | 726 | } EncoderCore<long, false>::EncodeSingle<long, false>::encode(lame_global_struct*, long*, long*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 316 | 726 | bool useIEEEFunction) { | 317 | | /* Not applicable for long */ | 318 | 726 | (void)useIEEEFunction; | 319 | | | 320 | 726 | if ( useInterleavingFunction == false ) { | 321 | 682 | InputCorrect<long, -32768, 32768>::Correct(inDataL, inDataSize); | 322 | 682 | InputCorrect<long, -32768, 32768>::Correct(inDataR, inDataSize); | 323 | | | 324 | 682 | Debug ? printf("{\n") : 0; | 325 | | | 326 | 682 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 327 | | | 328 | 682 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataL", "long", inDataL, inDataSize, true).c_str()) : 0; | 329 | 682 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataR", "long", inDataR, inDataSize, true).c_str()) : 0; | 330 | | | 331 | 682 | Debug ? | 332 | 0 | printf("\tlame_encode_buffer_long(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 333 | 682 | : 0; | 334 | | | 335 | 682 | const int ret = lame_encode_buffer_long(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 336 | | | 337 | 682 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 338 | | | 339 | 682 | Debug ? printf("}\n") : 0; | 340 | | | 341 | 682 | return ret; | 342 | 682 | } else { | 343 | 44 | Debug ? printf("{\n") : 0; | 344 | | | 345 | 44 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 346 | | | 347 | 44 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataL", "long", inDataL, inDataSize, true).c_str()) : 0; | 348 | 44 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataR", "long", inDataR, inDataSize, true).c_str()) : 0; | 349 | | | 350 | 44 | Debug ? | 351 | 0 | printf("\tlame_encode_buffer_long2(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 352 | 44 | : 0; | 353 | | | 354 | | /* Not actually interleaved */ | 355 | 44 | const int ret = lame_encode_buffer_long2(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 356 | | | 357 | 44 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 358 | | | 359 | 44 | Debug ? printf("}\n") : 0; | 360 | | | 361 | 44 | return ret; | 362 | 44 | } | 363 | 726 | } |
Unexecuted instantiation: EncoderCore<long, true>::EncodeSingle<long, true>::encode(lame_global_struct*, long*, long*, unsigned long, unsigned char*, unsigned long, bool, bool) |
364 | | }; |
365 | | |
366 | | template<bool Debug_> struct EncodeSingle<float, Debug_> { |
367 | | static int encode( |
368 | | lame_global_flags* flags, |
369 | | float* inDataL, |
370 | | float* inDataR, |
371 | | const size_t inDataSize, |
372 | | uint8_t* outBuffer, |
373 | | const size_t outBufferSize, |
374 | | bool useInterleavingFunction, |
375 | 938 | bool useIEEEFunction) { |
376 | | |
377 | 938 | if ( useInterleavingFunction == false ) { |
378 | 699 | if ( useIEEEFunction == false ) { |
379 | 348 | InputCorrect<float, -32768, 32768>::Correct(inDataL, inDataSize); |
380 | 348 | InputCorrect<float, -32768, 32768>::Correct(inDataR, inDataSize); |
381 | | |
382 | 348 | Debug ? printf("{\n") : 0; |
383 | | |
384 | 348 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
385 | | |
386 | 348 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize, true).c_str()) : 0; |
387 | 348 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataR", "float", inDataR, inDataSize, true).c_str()) : 0; |
388 | | |
389 | 348 | Debug ? |
390 | 0 | printf("\tlame_encode_buffer_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
391 | 348 | : 0; |
392 | | |
393 | 348 | const int ret = lame_encode_buffer_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
394 | | |
395 | 348 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
396 | | |
397 | 348 | Debug ? printf("}\n") : 0; |
398 | | |
399 | 348 | return ret; |
400 | 351 | } else { |
401 | 351 | InputCorrect<float, -1, 1>::Correct(inDataL, inDataSize); |
402 | 351 | InputCorrect<float, -1, 1>::Correct(inDataR, inDataSize); |
403 | | |
404 | 351 | Debug ? printf("{\n") : 0; |
405 | | |
406 | 351 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
407 | | |
408 | 351 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize, true).c_str()) : 0; |
409 | 351 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataR", "float", inDataR, inDataSize, true).c_str()) : 0; |
410 | | |
411 | 351 | Debug ? |
412 | 0 | printf("\tlame_encode_buffer_ieee_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
413 | 351 | : 0; |
414 | | |
415 | 351 | const int ret = lame_encode_buffer_ieee_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
416 | | |
417 | 351 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
418 | | |
419 | 351 | Debug ? printf("}\n") : 0; |
420 | | |
421 | 351 | return ret; |
422 | 351 | } |
423 | 699 | } else { |
424 | 239 | if ( useIEEEFunction == true ) { |
425 | 237 | InputCorrect<float, -1, 1>::Correct(inDataL, inDataSize * 2); |
426 | | |
427 | 237 | Debug ? printf("{\n") : 0; |
428 | | |
429 | 237 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize * 2).c_str()) : 0; |
430 | | |
431 | 237 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize * 2, true).c_str()) : 0; |
432 | | |
433 | 237 | Debug ? |
434 | 0 | printf("\tlame_encode_buffer_interleaved_ieee_float(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") |
435 | 237 | : 0; |
436 | | |
437 | 237 | const int ret = lame_encode_buffer_interleaved_ieee_float(flags, inDataL, inDataSize, outBuffer, outBufferSize); |
438 | | |
439 | 237 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
440 | | |
441 | 237 | Debug ? printf("}\n") : 0; |
442 | | |
443 | 237 | return ret; |
444 | 237 | } else { |
445 | | /* No function for interleaved float */ |
446 | 2 | return -1; |
447 | 2 | } |
448 | 239 | } |
449 | 938 | } EncoderCore<float, false>::EncodeSingle<float, false>::encode(lame_global_struct*, float*, float*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 375 | 938 | bool useIEEEFunction) { | 376 | | | 377 | 938 | if ( useInterleavingFunction == false ) { | 378 | 699 | if ( useIEEEFunction == false ) { | 379 | 348 | InputCorrect<float, -32768, 32768>::Correct(inDataL, inDataSize); | 380 | 348 | InputCorrect<float, -32768, 32768>::Correct(inDataR, inDataSize); | 381 | | | 382 | 348 | Debug ? printf("{\n") : 0; | 383 | | | 384 | 348 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 385 | | | 386 | 348 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize, true).c_str()) : 0; | 387 | 348 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataR", "float", inDataR, inDataSize, true).c_str()) : 0; | 388 | | | 389 | 348 | Debug ? | 390 | 0 | printf("\tlame_encode_buffer_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 391 | 348 | : 0; | 392 | | | 393 | 348 | const int ret = lame_encode_buffer_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 394 | | | 395 | 348 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 396 | | | 397 | 348 | Debug ? printf("}\n") : 0; | 398 | | | 399 | 348 | return ret; | 400 | 351 | } else { | 401 | 351 | InputCorrect<float, -1, 1>::Correct(inDataL, inDataSize); | 402 | 351 | InputCorrect<float, -1, 1>::Correct(inDataR, inDataSize); | 403 | | | 404 | 351 | Debug ? printf("{\n") : 0; | 405 | | | 406 | 351 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 407 | | | 408 | 351 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize, true).c_str()) : 0; | 409 | 351 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataR", "float", inDataR, inDataSize, true).c_str()) : 0; | 410 | | | 411 | 351 | Debug ? | 412 | 0 | printf("\tlame_encode_buffer_ieee_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 413 | 351 | : 0; | 414 | | | 415 | 351 | const int ret = lame_encode_buffer_ieee_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 416 | | | 417 | 351 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 418 | | | 419 | 351 | Debug ? printf("}\n") : 0; | 420 | | | 421 | 351 | return ret; | 422 | 351 | } | 423 | 699 | } else { | 424 | 239 | if ( useIEEEFunction == true ) { | 425 | 237 | InputCorrect<float, -1, 1>::Correct(inDataL, inDataSize * 2); | 426 | | | 427 | 237 | Debug ? printf("{\n") : 0; | 428 | | | 429 | 237 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize * 2).c_str()) : 0; | 430 | | | 431 | 237 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize * 2, true).c_str()) : 0; | 432 | | | 433 | 237 | Debug ? | 434 | 0 | printf("\tlame_encode_buffer_interleaved_ieee_float(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") | 435 | 237 | : 0; | 436 | | | 437 | 237 | const int ret = lame_encode_buffer_interleaved_ieee_float(flags, inDataL, inDataSize, outBuffer, outBufferSize); | 438 | | | 439 | 237 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 440 | | | 441 | 237 | Debug ? printf("}\n") : 0; | 442 | | | 443 | 237 | return ret; | 444 | 237 | } else { | 445 | | /* No function for interleaved float */ | 446 | 2 | return -1; | 447 | 2 | } | 448 | 239 | } | 449 | 938 | } |
Unexecuted instantiation: EncoderCore<float, true>::EncodeSingle<float, true>::encode(lame_global_struct*, float*, float*, unsigned long, unsigned char*, unsigned long, bool, bool) |
450 | | }; |
451 | | |
452 | | template<bool Debug_> struct EncodeSingle<double, Debug_> { |
453 | | int static encode( |
454 | | lame_global_flags* flags, |
455 | | double* inDataL, |
456 | | double* inDataR, |
457 | | const size_t inDataSize, |
458 | | uint8_t* outBuffer, |
459 | | const size_t outBufferSize, |
460 | | bool useInterleavingFunction, |
461 | 493 | bool useIEEEFunction) { |
462 | | |
463 | 493 | if ( useInterleavingFunction == false ) { |
464 | 366 | if ( useIEEEFunction == false ) { |
465 | | /* No non-IEEE function for interleaved double */ |
466 | 9 | return -1; |
467 | 357 | } else { |
468 | 357 | InputCorrect<double, -1, 1>::Correct(inDataL, inDataSize); |
469 | 357 | InputCorrect<double, -1, 1>::Correct(inDataR, inDataSize); |
470 | | |
471 | 357 | Debug ? printf("{\n") : 0; |
472 | | |
473 | 357 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
474 | | |
475 | 357 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataL", "double", inDataL, inDataSize, true).c_str()) : 0; |
476 | 357 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataR", "double", inDataR, inDataSize, true).c_str()) : 0; |
477 | | |
478 | 357 | Debug ? |
479 | 0 | printf("\tlame_encode_buffer_ieee_double(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
480 | 357 | : 0; |
481 | | |
482 | 357 | const int ret = lame_encode_buffer_ieee_double(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
483 | | |
484 | 357 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
485 | | |
486 | 357 | Debug ? printf("}\n") : 0; |
487 | | |
488 | 357 | return ret; |
489 | 357 | } |
490 | 366 | } else { |
491 | 127 | if ( useIEEEFunction == false ) { |
492 | 122 | InputCorrect<double, -1, 1>::Correct(inDataL, inDataSize * 2); |
493 | | |
494 | 122 | Debug ? printf("{\n") : 0; |
495 | | |
496 | 122 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
497 | | |
498 | 122 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataL", "double", inDataL, inDataSize * 2, true).c_str()) : 0; |
499 | | |
500 | 122 | Debug ? |
501 | 0 | printf("lame_encode_buffer_interleaved_ieee_double(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") |
502 | 122 | : 0; |
503 | | |
504 | 122 | const int ret = lame_encode_buffer_interleaved_ieee_double(flags, inDataL, inDataSize, outBuffer, outBufferSize); |
505 | | |
506 | | |
507 | 122 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
508 | | |
509 | 122 | Debug ? printf("}\n") : 0; |
510 | | |
511 | 122 | return ret; |
512 | 122 | } else { |
513 | | /* No non-IEEE function for double */ |
514 | 5 | return -1; |
515 | 5 | } |
516 | 127 | } |
517 | 493 | } EncoderCore<double, false>::EncodeSingle<double, false>::encode(lame_global_struct*, double*, double*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 461 | 493 | bool useIEEEFunction) { | 462 | | | 463 | 493 | if ( useInterleavingFunction == false ) { | 464 | 366 | if ( useIEEEFunction == false ) { | 465 | | /* No non-IEEE function for interleaved double */ | 466 | 9 | return -1; | 467 | 357 | } else { | 468 | 357 | InputCorrect<double, -1, 1>::Correct(inDataL, inDataSize); | 469 | 357 | InputCorrect<double, -1, 1>::Correct(inDataR, inDataSize); | 470 | | | 471 | 357 | Debug ? printf("{\n") : 0; | 472 | | | 473 | 357 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 474 | | | 475 | 357 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataL", "double", inDataL, inDataSize, true).c_str()) : 0; | 476 | 357 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataR", "double", inDataR, inDataSize, true).c_str()) : 0; | 477 | | | 478 | 357 | Debug ? | 479 | 0 | printf("\tlame_encode_buffer_ieee_double(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 480 | 357 | : 0; | 481 | | | 482 | 357 | const int ret = lame_encode_buffer_ieee_double(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 483 | | | 484 | 357 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 485 | | | 486 | 357 | Debug ? printf("}\n") : 0; | 487 | | | 488 | 357 | return ret; | 489 | 357 | } | 490 | 366 | } else { | 491 | 127 | if ( useIEEEFunction == false ) { | 492 | 122 | InputCorrect<double, -1, 1>::Correct(inDataL, inDataSize * 2); | 493 | | | 494 | 122 | Debug ? printf("{\n") : 0; | 495 | | | 496 | 122 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 497 | | | 498 | 122 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataL", "double", inDataL, inDataSize * 2, true).c_str()) : 0; | 499 | | | 500 | 122 | Debug ? | 501 | 0 | printf("lame_encode_buffer_interleaved_ieee_double(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") | 502 | 122 | : 0; | 503 | | | 504 | 122 | const int ret = lame_encode_buffer_interleaved_ieee_double(flags, inDataL, inDataSize, outBuffer, outBufferSize); | 505 | | | 506 | | | 507 | 122 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 508 | | | 509 | 122 | Debug ? printf("}\n") : 0; | 510 | | | 511 | 122 | return ret; | 512 | 122 | } else { | 513 | | /* No non-IEEE function for double */ | 514 | 5 | return -1; | 515 | 5 | } | 516 | 127 | } | 517 | 493 | } |
Unexecuted instantiation: EncoderCore<double, true>::EncodeSingle<double, true>::encode(lame_global_struct*, double*, double*, unsigned long, unsigned char*, unsigned long, bool, bool) |
518 | | }; |
519 | | |
520 | 10.0k | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { |
521 | 10.0k | if ( useInterleavingFunction && mono ) { |
522 | 6 | return -1; |
523 | 6 | } |
524 | | |
525 | 10.0k | if ( mono == true ) { |
526 | 1.54k | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); |
527 | 8.50k | } else if ( useInterleavingFunction ) { |
528 | 2.95k | const size_t numSamples = inData.size() / 2; |
529 | | |
530 | 2.95k | std::vector<T> inDataCopy; |
531 | 2.95k | inDataCopy.resize(numSamples * 2); |
532 | | |
533 | 2.95k | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); |
534 | | |
535 | 2.95k | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); |
536 | 5.55k | } else { |
537 | 5.55k | size_t numSamples = inData.size(); |
538 | | |
539 | | /* Round to a multiple of 2 */ |
540 | 5.55k | if ( numSamples % 2 ) { |
541 | 2.13k | numSamples--; |
542 | 2.13k | } |
543 | | |
544 | | /* To samples per channel */ |
545 | 5.55k | numSamples /= 2; |
546 | | |
547 | | /* Left, right channels */ |
548 | 5.55k | std::vector<T> inDataL, inDataR; |
549 | 5.55k | inDataL.resize(numSamples); |
550 | 5.55k | inDataR.resize(numSamples); |
551 | | |
552 | | /* Split inData evenly between inDataL and inDataR */ |
553 | 5.55k | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); |
554 | 5.55k | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); |
555 | | |
556 | 5.55k | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); |
557 | 5.55k | } |
558 | 10.0k | } EncoderCore<short, false>::encode(std::__1::vector<short, std::__1::allocator<short> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 7.40k | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 7.40k | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 7.40k | if ( mono == true ) { | 526 | 971 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 6.43k | } else if ( useInterleavingFunction ) { | 528 | 2.37k | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 2.37k | std::vector<T> inDataCopy; | 531 | 2.37k | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 2.37k | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 2.37k | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 4.05k | } else { | 537 | 4.05k | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 4.05k | if ( numSamples % 2 ) { | 541 | 1.68k | numSamples--; | 542 | 1.68k | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 4.05k | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 4.05k | std::vector<T> inDataL, inDataR; | 549 | 4.05k | inDataL.resize(numSamples); | 550 | 4.05k | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 4.05k | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 4.05k | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 4.05k | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 4.05k | } | 558 | 7.40k | } |
EncoderCore<int, false>::encode(std::__1::vector<int, std::__1::allocator<int> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 490 | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 490 | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 489 | if ( mono == true ) { | 526 | 92 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 397 | } else if ( useInterleavingFunction ) { | 528 | 170 | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 170 | std::vector<T> inDataCopy; | 531 | 170 | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 170 | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 170 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 227 | } else { | 537 | 227 | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 227 | if ( numSamples % 2 ) { | 541 | 63 | numSamples--; | 542 | 63 | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 227 | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 227 | std::vector<T> inDataL, inDataR; | 549 | 227 | inDataL.resize(numSamples); | 550 | 227 | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 227 | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 227 | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 227 | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 227 | } | 558 | 489 | } |
EncoderCore<long, false>::encode(std::__1::vector<long, std::__1::allocator<long> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 728 | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 728 | if ( useInterleavingFunction && mono ) { | 522 | 2 | return -1; | 523 | 2 | } | 524 | | | 525 | 726 | if ( mono == true ) { | 526 | 191 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 535 | } else if ( useInterleavingFunction ) { | 528 | 44 | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 44 | std::vector<T> inDataCopy; | 531 | 44 | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 44 | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 44 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 491 | } else { | 537 | 491 | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 491 | if ( numSamples % 2 ) { | 541 | 178 | numSamples--; | 542 | 178 | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 491 | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 491 | std::vector<T> inDataL, inDataR; | 549 | 491 | inDataL.resize(numSamples); | 550 | 491 | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 491 | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 491 | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 491 | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 491 | } | 558 | 726 | } |
EncoderCore<float, false>::encode(std::__1::vector<float, std::__1::allocator<float> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 939 | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 939 | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 938 | if ( mono == true ) { | 526 | 158 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 780 | } else if ( useInterleavingFunction ) { | 528 | 239 | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 239 | std::vector<T> inDataCopy; | 531 | 239 | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 239 | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 239 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 541 | } else { | 537 | 541 | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 541 | if ( numSamples % 2 ) { | 541 | 84 | numSamples--; | 542 | 84 | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 541 | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 541 | std::vector<T> inDataL, inDataR; | 549 | 541 | inDataL.resize(numSamples); | 550 | 541 | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 541 | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 541 | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 541 | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 541 | } | 558 | 938 | } |
EncoderCore<double, false>::encode(std::__1::vector<double, std::__1::allocator<double> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 494 | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 494 | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 493 | if ( mono == true ) { | 526 | 130 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 363 | } else if ( useInterleavingFunction ) { | 528 | 127 | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 127 | std::vector<T> inDataCopy; | 531 | 127 | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 127 | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 127 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 236 | } else { | 537 | 236 | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 236 | if ( numSamples % 2 ) { | 541 | 120 | numSamples--; | 542 | 120 | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 236 | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 236 | std::vector<T> inDataL, inDataR; | 549 | 236 | inDataL.resize(numSamples); | 550 | 236 | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 236 | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 236 | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 236 | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 236 | } | 558 | 493 | } |
Unexecuted instantiation: EncoderCore<short, true>::encode(std::__1::vector<short, std::__1::allocator<short> >&, unsigned char*, unsigned long, bool) Unexecuted instantiation: EncoderCore<int, true>::encode(std::__1::vector<int, std::__1::allocator<int> >&, unsigned char*, unsigned long, bool) Unexecuted instantiation: EncoderCore<long, true>::encode(std::__1::vector<long, std::__1::allocator<long> >&, unsigned char*, unsigned long, bool) Unexecuted instantiation: EncoderCore<float, true>::encode(std::__1::vector<float, std::__1::allocator<float> >&, unsigned char*, unsigned long, bool) Unexecuted instantiation: EncoderCore<double, true>::encode(std::__1::vector<double, std::__1::allocator<double> >&, unsigned char*, unsigned long, bool) |
559 | | |
560 | 9.94k | int flush(uint8_t* outBuffer, const size_t outBufferSize) { |
561 | 9.94k | if ( ds.Get<bool>() ) { |
562 | | /* No flush */ |
563 | 1.10k | return 0; |
564 | 1.10k | } |
565 | | |
566 | 8.83k | if ( ds.Get<bool>() ) { |
567 | 6.73k | Debug ? |
568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") |
569 | 6.73k | : 0; |
570 | | |
571 | 6.73k | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); |
572 | | |
573 | 6.73k | Debug ? printf("// (returns %d)\n", ret) : 0; |
574 | | |
575 | 6.73k | if ( ret > static_cast<int>(outBufferSize) ) { |
576 | | /* Crashes |
577 | | printf("lame_encode_flush reported more output bytes (%zu) than the buffer can hold (%zu)\n", static_cast<size_t>(ret), outBufferSize); |
578 | | |
579 | | abort(); |
580 | | */ |
581 | 0 | } |
582 | | |
583 | 6.73k | return ret; |
584 | 6.73k | } else { |
585 | | #if 0 |
586 | | /* XXX disabled because it prints: |
587 | | * "strange error flushing buffer ..." |
588 | | */ |
589 | | Debug ? |
590 | | printf("lame_encode_flush_nogap(flags, outBuffer, outBufferSize);\n") |
591 | | : 0; |
592 | | |
593 | | const int ret = lame_encode_flush_nogap(flags, outBuffer, outBufferSize); |
594 | | |
595 | | Debug ? printf("// (returns %d)\n", ret) : 0; |
596 | | |
597 | | return ret; |
598 | | #else |
599 | 2.10k | return 0; |
600 | 2.10k | #endif |
601 | 2.10k | } |
602 | 8.83k | } EncoderCore<short, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 7.37k | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 7.37k | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 684 | return 0; | 564 | 684 | } | 565 | | | 566 | 6.69k | if ( ds.Get<bool>() ) { | 567 | 5.80k | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 5.80k | : 0; | 570 | | | 571 | 5.80k | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 5.80k | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 5.80k | if ( ret > static_cast<int>(outBufferSize) ) { | 576 | | /* Crashes | 577 | | printf("lame_encode_flush reported more output bytes (%zu) than the buffer can hold (%zu)\n", static_cast<size_t>(ret), outBufferSize); | 578 | | | 579 | | abort(); | 580 | | */ | 581 | 0 | } | 582 | | | 583 | 5.80k | return ret; | 584 | 5.80k | } else { | 585 | | #if 0 | 586 | | /* XXX disabled because it prints: | 587 | | * "strange error flushing buffer ..." | 588 | | */ | 589 | | Debug ? | 590 | | printf("lame_encode_flush_nogap(flags, outBuffer, outBufferSize);\n") | 591 | | : 0; | 592 | | | 593 | | const int ret = lame_encode_flush_nogap(flags, outBuffer, outBufferSize); | 594 | | | 595 | | Debug ? printf("// (returns %d)\n", ret) : 0; | 596 | | | 597 | | return ret; | 598 | | #else | 599 | 886 | return 0; | 600 | 886 | #endif | 601 | 886 | } | 602 | 6.69k | } |
EncoderCore<int, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 476 | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 476 | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 87 | return 0; | 564 | 87 | } | 565 | | | 566 | 389 | if ( ds.Get<bool>() ) { | 567 | 193 | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 193 | : 0; | 570 | | | 571 | 193 | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 193 | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 193 | if ( ret > static_cast<int>(outBufferSize) ) { | 576 | | /* Crashes | 577 | | printf("lame_encode_flush reported more output bytes (%zu) than the buffer can hold (%zu)\n", static_cast<size_t>(ret), outBufferSize); | 578 | | | 579 | | abort(); | 580 | | */ | 581 | 0 | } | 582 | | | 583 | 193 | return ret; | 584 | 196 | } else { | 585 | | #if 0 | 586 | | /* XXX disabled because it prints: | 587 | | * "strange error flushing buffer ..." | 588 | | */ | 589 | | Debug ? | 590 | | printf("lame_encode_flush_nogap(flags, outBuffer, outBufferSize);\n") | 591 | | : 0; | 592 | | | 593 | | const int ret = lame_encode_flush_nogap(flags, outBuffer, outBufferSize); | 594 | | | 595 | | Debug ? printf("// (returns %d)\n", ret) : 0; | 596 | | | 597 | | return ret; | 598 | | #else | 599 | 196 | return 0; | 600 | 196 | #endif | 601 | 196 | } | 602 | 389 | } |
EncoderCore<long, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 703 | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 703 | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 106 | return 0; | 564 | 106 | } | 565 | | | 566 | 597 | if ( ds.Get<bool>() ) { | 567 | 160 | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 160 | : 0; | 570 | | | 571 | 160 | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 160 | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 160 | if ( ret > static_cast<int>(outBufferSize) ) { | 576 | | /* Crashes | 577 | | printf("lame_encode_flush reported more output bytes (%zu) than the buffer can hold (%zu)\n", static_cast<size_t>(ret), outBufferSize); | 578 | | | 579 | | abort(); | 580 | | */ | 581 | 0 | } | 582 | | | 583 | 160 | return ret; | 584 | 437 | } else { | 585 | | #if 0 | 586 | | /* XXX disabled because it prints: | 587 | | * "strange error flushing buffer ..." | 588 | | */ | 589 | | Debug ? | 590 | | printf("lame_encode_flush_nogap(flags, outBuffer, outBufferSize);\n") | 591 | | : 0; | 592 | | | 593 | | const int ret = lame_encode_flush_nogap(flags, outBuffer, outBufferSize); | 594 | | | 595 | | Debug ? printf("// (returns %d)\n", ret) : 0; | 596 | | | 597 | | return ret; | 598 | | #else | 599 | 437 | return 0; | 600 | 437 | #endif | 601 | 437 | } | 602 | 597 | } |
EncoderCore<float, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 923 | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 923 | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 128 | return 0; | 564 | 128 | } | 565 | | | 566 | 795 | if ( ds.Get<bool>() ) { | 567 | 468 | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 468 | : 0; | 570 | | | 571 | 468 | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 468 | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 468 | if ( ret > static_cast<int>(outBufferSize) ) { | 576 | | /* Crashes | 577 | | printf("lame_encode_flush reported more output bytes (%zu) than the buffer can hold (%zu)\n", static_cast<size_t>(ret), outBufferSize); | 578 | | | 579 | | abort(); | 580 | | */ | 581 | 0 | } | 582 | | | 583 | 468 | return ret; | 584 | 468 | } else { | 585 | | #if 0 | 586 | | /* XXX disabled because it prints: | 587 | | * "strange error flushing buffer ..." | 588 | | */ | 589 | | Debug ? | 590 | | printf("lame_encode_flush_nogap(flags, outBuffer, outBufferSize);\n") | 591 | | : 0; | 592 | | | 593 | | const int ret = lame_encode_flush_nogap(flags, outBuffer, outBufferSize); | 594 | | | 595 | | Debug ? printf("// (returns %d)\n", ret) : 0; | 596 | | | 597 | | return ret; | 598 | | #else | 599 | 327 | return 0; | 600 | 327 | #endif | 601 | 327 | } | 602 | 795 | } |
EncoderCore<double, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 470 | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 470 | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 102 | return 0; | 564 | 102 | } | 565 | | | 566 | 368 | if ( ds.Get<bool>() ) { | 567 | 112 | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 112 | : 0; | 570 | | | 571 | 112 | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 112 | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 112 | if ( ret > static_cast<int>(outBufferSize) ) { | 576 | | /* Crashes | 577 | | printf("lame_encode_flush reported more output bytes (%zu) than the buffer can hold (%zu)\n", static_cast<size_t>(ret), outBufferSize); | 578 | | | 579 | | abort(); | 580 | | */ | 581 | 0 | } | 582 | | | 583 | 112 | return ret; | 584 | 256 | } else { | 585 | | #if 0 | 586 | | /* XXX disabled because it prints: | 587 | | * "strange error flushing buffer ..." | 588 | | */ | 589 | | Debug ? | 590 | | printf("lame_encode_flush_nogap(flags, outBuffer, outBufferSize);\n") | 591 | | : 0; | 592 | | | 593 | | const int ret = lame_encode_flush_nogap(flags, outBuffer, outBufferSize); | 594 | | | 595 | | Debug ? printf("// (returns %d)\n", ret) : 0; | 596 | | | 597 | | return ret; | 598 | | #else | 599 | 256 | return 0; | 600 | 256 | #endif | 601 | 256 | } | 602 | 368 | } |
Unexecuted instantiation: EncoderCore<short, true>::flush(unsigned char*, unsigned long) Unexecuted instantiation: EncoderCore<int, true>::flush(unsigned char*, unsigned long) Unexecuted instantiation: EncoderCore<long, true>::flush(unsigned char*, unsigned long) Unexecuted instantiation: EncoderCore<float, true>::flush(unsigned char*, unsigned long) Unexecuted instantiation: EncoderCore<double, true>::flush(unsigned char*, unsigned long) |
603 | | public: |
604 | | EncoderCore(Datasource& ds, lame_global_flags* flags) : |
605 | | EncoderCoreBase(), |
606 | | ds(ds), |
607 | | flags(flags), |
608 | | it(inDataV.end()), |
609 | | useInterleavingFunction( ds.Get<bool>() ), |
610 | | useIEEEFunction( ds.Get<bool>() ) |
611 | 7.84k | { |
612 | 7.84k | getInputData(); |
613 | 7.84k | } EncoderCore<short, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 611 | 4.70k | { | 612 | 4.70k | getInputData(); | 613 | 4.70k | } |
EncoderCore<int, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 611 | 703 | { | 612 | 703 | getInputData(); | 613 | 703 | } |
EncoderCore<long, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 611 | 979 | { | 612 | 979 | getInputData(); | 613 | 979 | } |
EncoderCore<float, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 611 | 913 | { | 612 | 913 | getInputData(); | 613 | 913 | } |
EncoderCore<double, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 611 | 551 | { | 612 | 551 | getInputData(); | 613 | 551 | } |
Unexecuted instantiation: EncoderCore<short, true>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Unexecuted instantiation: EncoderCore<int, true>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Unexecuted instantiation: EncoderCore<long, true>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Unexecuted instantiation: EncoderCore<float, true>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Unexecuted instantiation: EncoderCore<double, true>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) |
614 | | |
615 | 12.1k | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { |
616 | 12.1k | if ( it == inDataV.end() ) { |
617 | 2.09k | return false; |
618 | 2.09k | } |
619 | | |
620 | 10.0k | auto& inData = *it; |
621 | 10.0k | it++; |
622 | | |
623 | | #ifdef MSAN |
624 | | /* Poison the outbuffer so if encode() puts uninitialized memory in it, |
625 | | * this can be detected. |
626 | | */ |
627 | | __msan_allocated_memory(outBuffer, outBufferSize); |
628 | | #endif |
629 | | |
630 | 10.0k | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); |
631 | | |
632 | 10.0k | if ( encodeRet < 0 ) { |
633 | 108 | return false; |
634 | 108 | } |
635 | | |
636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ |
637 | 9.94k | if ( encodeRet > static_cast<int>(outBufferSize) ) { |
638 | 0 | printf("encode reported more output bytes than the buffer can hold\n"); |
639 | |
|
640 | 0 | abort(); |
641 | 0 | } |
642 | | |
643 | | #ifdef MSAN |
644 | | /* Check for uninitialized data in the output buffer */ |
645 | | fuzzing::memory::memory_test_msan(outBuffer, encodeRet); |
646 | | |
647 | | /* Poison it again */ |
648 | | __msan_allocated_memory(outBuffer, outBufferSize); |
649 | | #endif |
650 | | |
651 | 9.94k | const int flushRet = flush(outBuffer, outBufferSize); |
652 | | |
653 | 9.94k | if ( flushRet < 0 ) { |
654 | 422 | return false; |
655 | 422 | } |
656 | | |
657 | 9.52k | fuzzing::memory::memory_test_msan(outBuffer, flushRet); |
658 | | |
659 | 9.52k | if ( encodeRet == 0 ) { |
660 | 1.89k | return false; |
661 | 1.89k | } |
662 | | |
663 | 7.62k | return true; |
664 | 9.52k | } EncoderCore<short, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 9.01k | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 9.01k | if ( it == inDataV.end() ) { | 617 | 1.61k | return false; | 618 | 1.61k | } | 619 | | | 620 | 7.40k | auto& inData = *it; | 621 | 7.40k | it++; | 622 | | | 623 | | #ifdef MSAN | 624 | | /* Poison the outbuffer so if encode() puts uninitialized memory in it, | 625 | | * this can be detected. | 626 | | */ | 627 | | __msan_allocated_memory(outBuffer, outBufferSize); | 628 | | #endif | 629 | | | 630 | 7.40k | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 7.40k | if ( encodeRet < 0 ) { | 633 | 29 | return false; | 634 | 29 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 7.37k | if ( encodeRet > static_cast<int>(outBufferSize) ) { | 638 | 0 | printf("encode reported more output bytes than the buffer can hold\n"); | 639 | |
| 640 | 0 | abort(); | 641 | 0 | } | 642 | | | 643 | | #ifdef MSAN | 644 | | /* Check for uninitialized data in the output buffer */ | 645 | | fuzzing::memory::memory_test_msan(outBuffer, encodeRet); | 646 | | | 647 | | /* Poison it again */ | 648 | | __msan_allocated_memory(outBuffer, outBufferSize); | 649 | | #endif | 650 | | | 651 | 7.37k | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 7.37k | if ( flushRet < 0 ) { | 654 | 328 | return false; | 655 | 328 | } | 656 | | | 657 | 7.04k | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 7.04k | if ( encodeRet == 0 ) { | 660 | 1.52k | return false; | 661 | 1.52k | } | 662 | | | 663 | 5.51k | return true; | 664 | 7.04k | } |
EncoderCore<int, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 618 | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 618 | if ( it == inDataV.end() ) { | 617 | 128 | return false; | 618 | 128 | } | 619 | | | 620 | 490 | auto& inData = *it; | 621 | 490 | it++; | 622 | | | 623 | | #ifdef MSAN | 624 | | /* Poison the outbuffer so if encode() puts uninitialized memory in it, | 625 | | * this can be detected. | 626 | | */ | 627 | | __msan_allocated_memory(outBuffer, outBufferSize); | 628 | | #endif | 629 | | | 630 | 490 | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 490 | if ( encodeRet < 0 ) { | 633 | 14 | return false; | 634 | 14 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 476 | if ( encodeRet > static_cast<int>(outBufferSize) ) { | 638 | 0 | printf("encode reported more output bytes than the buffer can hold\n"); | 639 | |
| 640 | 0 | abort(); | 641 | 0 | } | 642 | | | 643 | | #ifdef MSAN | 644 | | /* Check for uninitialized data in the output buffer */ | 645 | | fuzzing::memory::memory_test_msan(outBuffer, encodeRet); | 646 | | | 647 | | /* Poison it again */ | 648 | | __msan_allocated_memory(outBuffer, outBufferSize); | 649 | | #endif | 650 | | | 651 | 476 | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 476 | if ( flushRet < 0 ) { | 654 | 25 | return false; | 655 | 25 | } | 656 | | | 657 | 451 | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 451 | if ( encodeRet == 0 ) { | 660 | 79 | return false; | 661 | 79 | } | 662 | | | 663 | 372 | return true; | 664 | 451 | } |
EncoderCore<long, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 841 | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 841 | if ( it == inDataV.end() ) { | 617 | 113 | return false; | 618 | 113 | } | 619 | | | 620 | 728 | auto& inData = *it; | 621 | 728 | it++; | 622 | | | 623 | | #ifdef MSAN | 624 | | /* Poison the outbuffer so if encode() puts uninitialized memory in it, | 625 | | * this can be detected. | 626 | | */ | 627 | | __msan_allocated_memory(outBuffer, outBufferSize); | 628 | | #endif | 629 | | | 630 | 728 | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 728 | if ( encodeRet < 0 ) { | 633 | 25 | return false; | 634 | 25 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 703 | if ( encodeRet > static_cast<int>(outBufferSize) ) { | 638 | 0 | printf("encode reported more output bytes than the buffer can hold\n"); | 639 | |
| 640 | 0 | abort(); | 641 | 0 | } | 642 | | | 643 | | #ifdef MSAN | 644 | | /* Check for uninitialized data in the output buffer */ | 645 | | fuzzing::memory::memory_test_msan(outBuffer, encodeRet); | 646 | | | 647 | | /* Poison it again */ | 648 | | __msan_allocated_memory(outBuffer, outBufferSize); | 649 | | #endif | 650 | | | 651 | 703 | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 703 | if ( flushRet < 0 ) { | 654 | 14 | return false; | 655 | 14 | } | 656 | | | 657 | 689 | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 689 | if ( encodeRet == 0 ) { | 660 | 73 | return false; | 661 | 73 | } | 662 | | | 663 | 616 | return true; | 664 | 689 | } |
EncoderCore<float, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 1.10k | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 1.10k | if ( it == inDataV.end() ) { | 617 | 165 | return false; | 618 | 165 | } | 619 | | | 620 | 939 | auto& inData = *it; | 621 | 939 | it++; | 622 | | | 623 | | #ifdef MSAN | 624 | | /* Poison the outbuffer so if encode() puts uninitialized memory in it, | 625 | | * this can be detected. | 626 | | */ | 627 | | __msan_allocated_memory(outBuffer, outBufferSize); | 628 | | #endif | 629 | | | 630 | 939 | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 939 | if ( encodeRet < 0 ) { | 633 | 16 | return false; | 634 | 16 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 923 | if ( encodeRet > static_cast<int>(outBufferSize) ) { | 638 | 0 | printf("encode reported more output bytes than the buffer can hold\n"); | 639 | |
| 640 | 0 | abort(); | 641 | 0 | } | 642 | | | 643 | | #ifdef MSAN | 644 | | /* Check for uninitialized data in the output buffer */ | 645 | | fuzzing::memory::memory_test_msan(outBuffer, encodeRet); | 646 | | | 647 | | /* Poison it again */ | 648 | | __msan_allocated_memory(outBuffer, outBufferSize); | 649 | | #endif | 650 | | | 651 | 923 | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 923 | if ( flushRet < 0 ) { | 654 | 52 | return false; | 655 | 52 | } | 656 | | | 657 | 871 | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 871 | if ( encodeRet == 0 ) { | 660 | 161 | return false; | 661 | 161 | } | 662 | | | 663 | 710 | return true; | 664 | 871 | } |
EncoderCore<double, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 563 | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 563 | if ( it == inDataV.end() ) { | 617 | 69 | return false; | 618 | 69 | } | 619 | | | 620 | 494 | auto& inData = *it; | 621 | 494 | it++; | 622 | | | 623 | | #ifdef MSAN | 624 | | /* Poison the outbuffer so if encode() puts uninitialized memory in it, | 625 | | * this can be detected. | 626 | | */ | 627 | | __msan_allocated_memory(outBuffer, outBufferSize); | 628 | | #endif | 629 | | | 630 | 494 | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 494 | if ( encodeRet < 0 ) { | 633 | 24 | return false; | 634 | 24 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 470 | if ( encodeRet > static_cast<int>(outBufferSize) ) { | 638 | 0 | printf("encode reported more output bytes than the buffer can hold\n"); | 639 | |
| 640 | 0 | abort(); | 641 | 0 | } | 642 | | | 643 | | #ifdef MSAN | 644 | | /* Check for uninitialized data in the output buffer */ | 645 | | fuzzing::memory::memory_test_msan(outBuffer, encodeRet); | 646 | | | 647 | | /* Poison it again */ | 648 | | __msan_allocated_memory(outBuffer, outBufferSize); | 649 | | #endif | 650 | | | 651 | 470 | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 470 | if ( flushRet < 0 ) { | 654 | 3 | return false; | 655 | 3 | } | 656 | | | 657 | 467 | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 467 | if ( encodeRet == 0 ) { | 660 | 56 | return false; | 661 | 56 | } | 662 | | | 663 | 411 | return true; | 664 | 467 | } |
Unexecuted instantiation: EncoderCore<short, true>::Run(unsigned char*, unsigned long, bool) Unexecuted instantiation: EncoderCore<int, true>::Run(unsigned char*, unsigned long, bool) Unexecuted instantiation: EncoderCore<long, true>::Run(unsigned char*, unsigned long, bool) Unexecuted instantiation: EncoderCore<float, true>::Run(unsigned char*, unsigned long, bool) Unexecuted instantiation: EncoderCore<double, true>::Run(unsigned char*, unsigned long, bool) |
665 | | }; |
666 | | |
667 | | /* In the interest of speed, let Debug be a template parameter, |
668 | | * so that in non-debug mode, all debug checks will be optimized away. |
669 | | */ |
670 | | template <bool Debug> |
671 | | class EncoderFuzzer { |
672 | | private: |
673 | | Datasource& ds; |
674 | | lame_global_flags* flags = nullptr; |
675 | | uint8_t* outBuffer = nullptr; |
676 | | const size_t outBufferSize; |
677 | | bool mono = false; |
678 | | |
679 | 950 | void setBitrateModeVBR_RH(void) { |
680 | 950 | _(lame_set_VBR(flags, vbr_rh);); |
681 | 950 | } EncoderFuzzer<false>::setBitrateModeVBR_RH() Line | Count | Source | 679 | 950 | void setBitrateModeVBR_RH(void) { | 680 | 950 | _(lame_set_VBR(flags, vbr_rh);); | 681 | 950 | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateModeVBR_RH() |
682 | | |
683 | 1.56k | void setBitrateModeVBR_MTRH(void) { |
684 | 1.56k | _(lame_set_VBR(flags, vbr_mtrh);); |
685 | 1.56k | } EncoderFuzzer<false>::setBitrateModeVBR_MTRH() Line | Count | Source | 683 | 1.56k | void setBitrateModeVBR_MTRH(void) { | 684 | 1.56k | _(lame_set_VBR(flags, vbr_mtrh);); | 685 | 1.56k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateModeVBR_MTRH() |
686 | | |
687 | 0 | void setBitrateModeVBR_ABR(void) { |
688 | 0 | _(lame_set_VBR(flags, vbr_abr);); |
689 | 0 |
|
690 | 0 | const size_t ABRBitrate = limits::ABRBitrate.Generate(ds); |
691 | 0 |
|
692 | 0 | Debug ? printf("lame_set_VBR_mean_bitrate_kbps(flags, %zu);\n", ABRBitrate) : 0; |
693 | 0 |
|
694 | 0 | lame_set_VBR_mean_bitrate_kbps(flags, ABRBitrate); |
695 | 0 | } Unexecuted instantiation: EncoderFuzzer<false>::setBitrateModeVBR_ABR() Unexecuted instantiation: EncoderFuzzer<true>::setBitrateModeVBR_ABR() |
696 | | |
697 | 2.51k | void setVBRQ(void) { |
698 | 2.51k | if ( ds.Get<bool>() ) return; |
699 | | |
700 | 1.36k | const size_t vbrQ = limits::VBRQ.Generate<uint8_t>(ds); |
701 | | |
702 | 1.36k | Debug ? printf("lame_set_VBR_q(flags, %zu);\n", vbrQ) : 0; |
703 | | |
704 | 1.36k | lame_set_VBR_q(flags, vbrQ); |
705 | 1.36k | } EncoderFuzzer<false>::setVBRQ() Line | Count | Source | 697 | 2.51k | void setVBRQ(void) { | 698 | 2.51k | if ( ds.Get<bool>() ) return; | 699 | | | 700 | 1.36k | const size_t vbrQ = limits::VBRQ.Generate<uint8_t>(ds); | 701 | | | 702 | 1.36k | Debug ? printf("lame_set_VBR_q(flags, %zu);\n", vbrQ) : 0; | 703 | | | 704 | 1.36k | lame_set_VBR_q(flags, vbrQ); | 705 | 1.36k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setVBRQ() |
706 | | |
707 | 2.51k | size_t setMinBitrate(void) { |
708 | 2.51k | if ( ds.Get<bool>() ) return 0; |
709 | | |
710 | 762 | const size_t minBitrate = limits::MinBitrate.Generate(ds); |
711 | | |
712 | 762 | Debug ? printf("lame_set_VBR_min_bitrate_kbps(flags, %zu);\n", minBitrate) : 0; |
713 | | |
714 | 762 | lame_set_VBR_min_bitrate_kbps(flags, minBitrate); |
715 | | |
716 | 762 | return minBitrate; |
717 | 2.51k | } EncoderFuzzer<false>::setMinBitrate() Line | Count | Source | 707 | 2.51k | size_t setMinBitrate(void) { | 708 | 2.51k | if ( ds.Get<bool>() ) return 0; | 709 | | | 710 | 762 | const size_t minBitrate = limits::MinBitrate.Generate(ds); | 711 | | | 712 | 762 | Debug ? printf("lame_set_VBR_min_bitrate_kbps(flags, %zu);\n", minBitrate) : 0; | 713 | | | 714 | 762 | lame_set_VBR_min_bitrate_kbps(flags, minBitrate); | 715 | | | 716 | 762 | return minBitrate; | 717 | 2.51k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setMinBitrate() |
718 | | |
719 | 2.50k | void setMaxBitrate(const size_t minBitrate) { |
720 | 2.50k | if ( ds.Get<bool>() ) return; |
721 | | |
722 | 950 | size_t maxBitrate = limits::MaxBitrate.Generate(ds); |
723 | 950 | if ( minBitrate > maxBitrate ) { |
724 | | /* minBitrate should be <= maxBitrate, so if that is not the case, |
725 | | * set them both to the same value. |
726 | | */ |
727 | 61 | maxBitrate = minBitrate; |
728 | 61 | } |
729 | | |
730 | 950 | Debug ? printf("lame_set_VBR_max_bitrate_kbps(flags, %zu);\n", maxBitrate) : 0; |
731 | | |
732 | 950 | lame_set_VBR_max_bitrate_kbps(flags, maxBitrate); |
733 | 950 | } EncoderFuzzer<false>::setMaxBitrate(unsigned long) Line | Count | Source | 719 | 2.50k | void setMaxBitrate(const size_t minBitrate) { | 720 | 2.50k | if ( ds.Get<bool>() ) return; | 721 | | | 722 | 950 | size_t maxBitrate = limits::MaxBitrate.Generate(ds); | 723 | 950 | if ( minBitrate > maxBitrate ) { | 724 | | /* minBitrate should be <= maxBitrate, so if that is not the case, | 725 | | * set them both to the same value. | 726 | | */ | 727 | 61 | maxBitrate = minBitrate; | 728 | 61 | } | 729 | | | 730 | 950 | Debug ? printf("lame_set_VBR_max_bitrate_kbps(flags, %zu);\n", maxBitrate) : 0; | 731 | | | 732 | 950 | lame_set_VBR_max_bitrate_kbps(flags, maxBitrate); | 733 | 950 | } |
Unexecuted instantiation: EncoderFuzzer<true>::setMaxBitrate(unsigned long) |
734 | | |
735 | 2.52k | void setBitrateModeVBR(void) { |
736 | 2.52k | const uint8_t whichVbr = ds.Get<uint8_t>() % 3; |
737 | | |
738 | 2.52k | if ( whichVbr == 0 ) { |
739 | 950 | setBitrateModeVBR_RH(); |
740 | 1.57k | } else if ( whichVbr == 1 ) { |
741 | 1.56k | setBitrateModeVBR_MTRH(); |
742 | 1.56k | } else if ( whichVbr == 2 ) { |
743 | 3 | /* Disabled due to crash */ throw std::runtime_error(""); |
744 | 0 | setBitrateModeVBR_ABR(); |
745 | 0 | } |
746 | | |
747 | 2.52k | setVBRQ(); |
748 | | |
749 | 2.52k | size_t minBitrate = setMinBitrate(); |
750 | 2.52k | setMaxBitrate(minBitrate); |
751 | 2.52k | } EncoderFuzzer<false>::setBitrateModeVBR() Line | Count | Source | 735 | 2.52k | void setBitrateModeVBR(void) { | 736 | 2.52k | const uint8_t whichVbr = ds.Get<uint8_t>() % 3; | 737 | | | 738 | 2.52k | if ( whichVbr == 0 ) { | 739 | 950 | setBitrateModeVBR_RH(); | 740 | 1.57k | } else if ( whichVbr == 1 ) { | 741 | 1.56k | setBitrateModeVBR_MTRH(); | 742 | 1.56k | } else if ( whichVbr == 2 ) { | 743 | 3 | /* Disabled due to crash */ throw std::runtime_error(""); | 744 | 0 | setBitrateModeVBR_ABR(); | 745 | 0 | } | 746 | | | 747 | 2.52k | setVBRQ(); | 748 | | | 749 | 2.52k | size_t minBitrate = setMinBitrate(); | 750 | 2.52k | setMaxBitrate(minBitrate); | 751 | 2.52k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateModeVBR() |
752 | | |
753 | 4.81k | void setBitrateModeCBR(void) { |
754 | 4.81k | _(lame_set_VBR(flags, vbr_off);); |
755 | | |
756 | 4.81k | const size_t bitrate = limits::CBRBitrate.Generate(ds); |
757 | | |
758 | 4.81k | Debug ? printf("lame_set_brate(flags, %zu);\n", bitrate) : 0; |
759 | | |
760 | 4.81k | lame_set_brate(flags, bitrate); |
761 | 4.81k | } EncoderFuzzer<false>::setBitrateModeCBR() Line | Count | Source | 753 | 4.81k | void setBitrateModeCBR(void) { | 754 | 4.81k | _(lame_set_VBR(flags, vbr_off);); | 755 | | | 756 | 4.81k | const size_t bitrate = limits::CBRBitrate.Generate(ds); | 757 | | | 758 | 4.81k | Debug ? printf("lame_set_brate(flags, %zu);\n", bitrate) : 0; | 759 | | | 760 | 4.81k | lame_set_brate(flags, bitrate); | 761 | 4.81k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateModeCBR() |
762 | | |
763 | 7.35k | void setBitrateMode(void) { |
764 | 7.35k | ds.Get<bool>() ? setBitrateModeVBR() : setBitrateModeCBR(); |
765 | 7.35k | } EncoderFuzzer<false>::setBitrateMode() Line | Count | Source | 763 | 7.35k | void setBitrateMode(void) { | 764 | 7.35k | ds.Get<bool>() ? setBitrateModeVBR() : setBitrateModeCBR(); | 765 | 7.35k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateMode() |
766 | | |
767 | 7.39k | void setInputChannels(void) { |
768 | 7.39k | const int numChannels = ds.Get<bool>() ? 1 : 2; |
769 | | |
770 | 7.39k | Debug ? printf("lame_set_num_channels(flags, %d);\n", numChannels) : 0; |
771 | | |
772 | 7.39k | lame_set_num_channels(flags, numChannels); |
773 | | |
774 | 7.39k | if ( numChannels == 1 ) { |
775 | 1.43k | mono = true; |
776 | 1.43k | } |
777 | 7.39k | } EncoderFuzzer<false>::setInputChannels() Line | Count | Source | 767 | 7.39k | void setInputChannels(void) { | 768 | 7.39k | const int numChannels = ds.Get<bool>() ? 1 : 2; | 769 | | | 770 | 7.39k | Debug ? printf("lame_set_num_channels(flags, %d);\n", numChannels) : 0; | 771 | | | 772 | 7.39k | lame_set_num_channels(flags, numChannels); | 773 | | | 774 | 7.39k | if ( numChannels == 1 ) { | 775 | 1.43k | mono = true; | 776 | 1.43k | } | 777 | 7.39k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setInputChannels() |
778 | | |
779 | 7.25k | void setChannelMode(void) { |
780 | 7.25k | const uint8_t whichChannelMode = ds.Get<uint8_t>() % 3; |
781 | | |
782 | 7.25k | if ( whichChannelMode == 0 ) { |
783 | 3.27k | _(lame_set_mode(flags, STEREO);); |
784 | 3.98k | } else if ( whichChannelMode == 1 ) { |
785 | 2.71k | _(lame_set_mode(flags, JOINT_STEREO);); |
786 | 2.71k | } else if ( whichChannelMode == 2 ) { |
787 | 1.13k | _(lame_set_mode(flags, MONO);); |
788 | 1.13k | } |
789 | 7.25k | } EncoderFuzzer<false>::setChannelMode() Line | Count | Source | 779 | 7.25k | void setChannelMode(void) { | 780 | 7.25k | const uint8_t whichChannelMode = ds.Get<uint8_t>() % 3; | 781 | | | 782 | 7.25k | if ( whichChannelMode == 0 ) { | 783 | 3.27k | _(lame_set_mode(flags, STEREO);); | 784 | 3.98k | } else if ( whichChannelMode == 1 ) { | 785 | 2.71k | _(lame_set_mode(flags, JOINT_STEREO);); | 786 | 2.71k | } else if ( whichChannelMode == 2 ) { | 787 | 1.13k | _(lame_set_mode(flags, MONO);); | 788 | 1.13k | } | 789 | 7.25k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setChannelMode() |
790 | | |
791 | 7.12k | void setQuality(void) { |
792 | 7.12k | const size_t quality = limits::Quality.Generate<uint8_t>(ds); |
793 | | |
794 | 7.12k | Debug ? printf("lame_set_quality(flags, %zu);\n", quality) : 0; |
795 | | |
796 | 7.12k | lame_set_quality(flags, quality); |
797 | 7.12k | } EncoderFuzzer<false>::setQuality() Line | Count | Source | 791 | 7.12k | void setQuality(void) { | 792 | 7.12k | const size_t quality = limits::Quality.Generate<uint8_t>(ds); | 793 | | | 794 | 7.12k | Debug ? printf("lame_set_quality(flags, %zu);\n", quality) : 0; | 795 | | | 796 | 7.12k | lame_set_quality(flags, quality); | 797 | 7.12k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setQuality() |
798 | | |
799 | 7.12k | void setOutSamplerate(void) { |
800 | 7.12k | const size_t outSamplerate = limits::OutSamplerate.Generate(ds); |
801 | | |
802 | 7.12k | Debug ? printf("lame_set_out_samplerate(flags, %zu);\n", outSamplerate) : 0; |
803 | | |
804 | 7.12k | lame_set_out_samplerate(flags, outSamplerate); |
805 | 7.12k | } EncoderFuzzer<false>::setOutSamplerate() Line | Count | Source | 799 | 7.12k | void setOutSamplerate(void) { | 800 | 7.12k | const size_t outSamplerate = limits::OutSamplerate.Generate(ds); | 801 | | | 802 | 7.12k | Debug ? printf("lame_set_out_samplerate(flags, %zu);\n", outSamplerate) : 0; | 803 | | | 804 | 7.12k | lame_set_out_samplerate(flags, outSamplerate); | 805 | 7.12k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setOutSamplerate() |
806 | | |
807 | 7.10k | void setID3(void) { |
808 | | /* Optionally set various ID3 fields */ |
809 | | |
810 | 7.10k | if ( ds.Get<bool>() ) { |
811 | 1.37k | id3tag_init(flags); |
812 | | |
813 | 1.37k | if ( ds.Get<bool>() ) { |
814 | 137 | const std::string title = ds.Get<std::string>(); |
815 | | |
816 | 137 | Debug ? printf("id3tag_set_title(flags, %s);\n", title.c_str()) : 0; |
817 | | |
818 | 137 | id3tag_set_title(flags, title.c_str()); |
819 | 137 | } |
820 | | |
821 | 1.37k | if ( ds.Get<bool>() ) { |
822 | 141 | const std::string artist = ds.Get<std::string>(); |
823 | | |
824 | 141 | Debug ? printf("id3tag_set_artist(flags, %s);\n", artist.c_str()) : 0; |
825 | | |
826 | 141 | id3tag_set_artist(flags, artist.c_str()); |
827 | 141 | } |
828 | | |
829 | 1.37k | if ( ds.Get<bool>() ) { |
830 | 136 | const std::string album = ds.Get<std::string>(); |
831 | | |
832 | 136 | Debug ? printf("id3tag_set_album(flags, %s);\n", album.c_str()) : 0; |
833 | | |
834 | 136 | id3tag_set_album(flags, album.c_str()); |
835 | 136 | } |
836 | | |
837 | 1.37k | if ( ds.Get<bool>() ) { |
838 | 164 | const std::string year = ds.Get<std::string>(); |
839 | | |
840 | 164 | Debug ? printf("id3tag_set_year(flags, %s);\n", year.c_str()) : 0; |
841 | | |
842 | 164 | id3tag_set_year(flags, year.c_str()); |
843 | 164 | } |
844 | | |
845 | 1.37k | if ( ds.Get<bool>() ) { |
846 | 168 | const std::string comment = ds.Get<std::string>(); |
847 | | |
848 | 168 | Debug ? printf("id3tag_set_comment(flags, %s);\n", comment.c_str()) : 0; |
849 | | |
850 | 168 | id3tag_set_comment(flags, comment.c_str()); |
851 | 168 | } |
852 | | |
853 | 1.37k | if ( ds.Get<bool>() ) { |
854 | 193 | const std::string track = ds.Get<std::string>(); |
855 | | |
856 | 193 | Debug ? printf("id3tag_set_track(flags, %s);\n", track.c_str()) : 0; |
857 | | |
858 | 193 | id3tag_set_track(flags, track.c_str()); |
859 | 193 | } |
860 | | |
861 | 1.37k | if ( ds.Get<bool>() ) { |
862 | 266 | const std::string genre = ds.Get<std::string>(); |
863 | | |
864 | 266 | Debug ? printf("id3tag_set_genre(flags, %s);\n", genre.c_str()) : 0; |
865 | | |
866 | 266 | id3tag_set_genre(flags, genre.c_str()); |
867 | 266 | } |
868 | | |
869 | 1.37k | if ( ds.Get<bool>() ) { |
870 | 465 | const std::string fieldvalue = ds.Get<std::string>(); |
871 | | |
872 | 465 | Debug ? printf("id3tag_set_fieldvalue(flags, %s);\n", fieldvalue.c_str()) : 0; |
873 | | |
874 | 465 | id3tag_set_fieldvalue(flags, fieldvalue.c_str()); |
875 | 465 | } |
876 | | |
877 | 1.37k | if ( ds.Get<bool>() ) { |
878 | 173 | const auto albumArt = ds.GetData(0); |
879 | | |
880 | 173 | Debug ? printf("{\n") : 0; |
881 | | |
882 | 173 | Debug ? printf("\t%s\n", debug_define_size_t("albumArtSize", albumArt.size()).c_str()) : 0; |
883 | 173 | Debug ? printf("%s\n", DebugDefineArray<unsigned char>::Str("albumart", "char", albumArt.data(), albumArt.size(), true).c_str()) : 0; |
884 | | |
885 | 173 | Debug ? |
886 | 0 | printf("\tid3tag_set_albumart(flags, albumArt, albumArtSize);\n") |
887 | 173 | : 0; |
888 | | |
889 | 173 | Debug ? printf("}\n") : 0; |
890 | | |
891 | 173 | id3tag_set_albumart(flags, (const char*)albumArt.data(), albumArt.size()); |
892 | 173 | } |
893 | 1.37k | } |
894 | 7.10k | } EncoderFuzzer<false>::setID3() Line | Count | Source | 807 | 7.10k | void setID3(void) { | 808 | | /* Optionally set various ID3 fields */ | 809 | | | 810 | 7.10k | if ( ds.Get<bool>() ) { | 811 | 1.37k | id3tag_init(flags); | 812 | | | 813 | 1.37k | if ( ds.Get<bool>() ) { | 814 | 137 | const std::string title = ds.Get<std::string>(); | 815 | | | 816 | 137 | Debug ? printf("id3tag_set_title(flags, %s);\n", title.c_str()) : 0; | 817 | | | 818 | 137 | id3tag_set_title(flags, title.c_str()); | 819 | 137 | } | 820 | | | 821 | 1.37k | if ( ds.Get<bool>() ) { | 822 | 141 | const std::string artist = ds.Get<std::string>(); | 823 | | | 824 | 141 | Debug ? printf("id3tag_set_artist(flags, %s);\n", artist.c_str()) : 0; | 825 | | | 826 | 141 | id3tag_set_artist(flags, artist.c_str()); | 827 | 141 | } | 828 | | | 829 | 1.37k | if ( ds.Get<bool>() ) { | 830 | 136 | const std::string album = ds.Get<std::string>(); | 831 | | | 832 | 136 | Debug ? printf("id3tag_set_album(flags, %s);\n", album.c_str()) : 0; | 833 | | | 834 | 136 | id3tag_set_album(flags, album.c_str()); | 835 | 136 | } | 836 | | | 837 | 1.37k | if ( ds.Get<bool>() ) { | 838 | 164 | const std::string year = ds.Get<std::string>(); | 839 | | | 840 | 164 | Debug ? printf("id3tag_set_year(flags, %s);\n", year.c_str()) : 0; | 841 | | | 842 | 164 | id3tag_set_year(flags, year.c_str()); | 843 | 164 | } | 844 | | | 845 | 1.37k | if ( ds.Get<bool>() ) { | 846 | 168 | const std::string comment = ds.Get<std::string>(); | 847 | | | 848 | 168 | Debug ? printf("id3tag_set_comment(flags, %s);\n", comment.c_str()) : 0; | 849 | | | 850 | 168 | id3tag_set_comment(flags, comment.c_str()); | 851 | 168 | } | 852 | | | 853 | 1.37k | if ( ds.Get<bool>() ) { | 854 | 193 | const std::string track = ds.Get<std::string>(); | 855 | | | 856 | 193 | Debug ? printf("id3tag_set_track(flags, %s);\n", track.c_str()) : 0; | 857 | | | 858 | 193 | id3tag_set_track(flags, track.c_str()); | 859 | 193 | } | 860 | | | 861 | 1.37k | if ( ds.Get<bool>() ) { | 862 | 266 | const std::string genre = ds.Get<std::string>(); | 863 | | | 864 | 266 | Debug ? printf("id3tag_set_genre(flags, %s);\n", genre.c_str()) : 0; | 865 | | | 866 | 266 | id3tag_set_genre(flags, genre.c_str()); | 867 | 266 | } | 868 | | | 869 | 1.37k | if ( ds.Get<bool>() ) { | 870 | 465 | const std::string fieldvalue = ds.Get<std::string>(); | 871 | | | 872 | 465 | Debug ? printf("id3tag_set_fieldvalue(flags, %s);\n", fieldvalue.c_str()) : 0; | 873 | | | 874 | 465 | id3tag_set_fieldvalue(flags, fieldvalue.c_str()); | 875 | 465 | } | 876 | | | 877 | 1.37k | if ( ds.Get<bool>() ) { | 878 | 173 | const auto albumArt = ds.GetData(0); | 879 | | | 880 | 173 | Debug ? printf("{\n") : 0; | 881 | | | 882 | 173 | Debug ? printf("\t%s\n", debug_define_size_t("albumArtSize", albumArt.size()).c_str()) : 0; | 883 | 173 | Debug ? printf("%s\n", DebugDefineArray<unsigned char>::Str("albumart", "char", albumArt.data(), albumArt.size(), true).c_str()) : 0; | 884 | | | 885 | 173 | Debug ? | 886 | 0 | printf("\tid3tag_set_albumart(flags, albumArt, albumArtSize);\n") | 887 | 173 | : 0; | 888 | | | 889 | 173 | Debug ? printf("}\n") : 0; | 890 | | | 891 | 173 | id3tag_set_albumart(flags, (const char*)albumArt.data(), albumArt.size()); | 892 | 173 | } | 893 | 1.37k | } | 894 | 7.10k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setID3() |
895 | | |
896 | 5.99k | void setFilters(void) { |
897 | 5.99k | if ( ds.Get<bool>() ) { |
898 | 854 | const size_t lowpassFreq = limits::LowpassFrequency.Generate(ds); |
899 | | |
900 | 854 | Debug ? printf("lame_set_lowpassfreq(flags, %zu);\n", lowpassFreq) : 0; |
901 | | |
902 | 854 | lame_set_lowpassfreq(flags, lowpassFreq); |
903 | 854 | } |
904 | | |
905 | 5.99k | if ( ds.Get<bool>() ) { |
906 | 518 | const size_t lowpassWidth = limits::LowpassWidth.Generate(ds); |
907 | | |
908 | 518 | Debug ? printf("lame_set_lowpasswidth(flags, %zu);\n", lowpassWidth) : 0; |
909 | | |
910 | 518 | lame_set_lowpasswidth(flags, lowpassWidth); |
911 | 518 | } |
912 | | |
913 | 5.99k | if ( ds.Get<bool>() ) { |
914 | 641 | const size_t highpassFreq = limits::HighpassFrequency.Generate(ds); |
915 | | |
916 | 641 | Debug ? printf("lame_set_highpassfreq(flags, %zu);\n", highpassFreq) : 0; |
917 | | |
918 | 641 | lame_set_highpassfreq(flags, highpassFreq); |
919 | 641 | } |
920 | | |
921 | 5.99k | if ( ds.Get<bool>() ) { |
922 | 435 | const size_t highpassWidth = limits::HighpassWidth.Generate(ds); |
923 | | |
924 | 435 | Debug ? printf("lame_set_highpasswidth(flags, %zu);\n", highpassWidth) : 0; |
925 | | |
926 | 435 | lame_set_highpasswidth(flags, highpassWidth); |
927 | 435 | } |
928 | 5.99k | } EncoderFuzzer<false>::setFilters() Line | Count | Source | 896 | 5.99k | void setFilters(void) { | 897 | 5.99k | if ( ds.Get<bool>() ) { | 898 | 854 | const size_t lowpassFreq = limits::LowpassFrequency.Generate(ds); | 899 | | | 900 | 854 | Debug ? printf("lame_set_lowpassfreq(flags, %zu);\n", lowpassFreq) : 0; | 901 | | | 902 | 854 | lame_set_lowpassfreq(flags, lowpassFreq); | 903 | 854 | } | 904 | | | 905 | 5.99k | if ( ds.Get<bool>() ) { | 906 | 518 | const size_t lowpassWidth = limits::LowpassWidth.Generate(ds); | 907 | | | 908 | 518 | Debug ? printf("lame_set_lowpasswidth(flags, %zu);\n", lowpassWidth) : 0; | 909 | | | 910 | 518 | lame_set_lowpasswidth(flags, lowpassWidth); | 911 | 518 | } | 912 | | | 913 | 5.99k | if ( ds.Get<bool>() ) { | 914 | 641 | const size_t highpassFreq = limits::HighpassFrequency.Generate(ds); | 915 | | | 916 | 641 | Debug ? printf("lame_set_highpassfreq(flags, %zu);\n", highpassFreq) : 0; | 917 | | | 918 | 641 | lame_set_highpassfreq(flags, highpassFreq); | 919 | 641 | } | 920 | | | 921 | 5.99k | if ( ds.Get<bool>() ) { | 922 | 435 | const size_t highpassWidth = limits::HighpassWidth.Generate(ds); | 923 | | | 924 | 435 | Debug ? printf("lame_set_highpasswidth(flags, %zu);\n", highpassWidth) : 0; | 925 | | | 926 | 435 | lame_set_highpasswidth(flags, highpassWidth); | 927 | 435 | } | 928 | 5.99k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setFilters() |
929 | | |
930 | | |
931 | 5.67k | void setMisc(void) { |
932 | 5.67k | if ( ds.Get<bool>() ) { |
933 | 1.87k | _(lame_set_strict_ISO(flags, MDB_STRICT_ISO);); |
934 | 1.87k | } |
935 | | |
936 | 5.67k | if ( ds.Get<bool>() ) { |
937 | 1.75k | _(lame_set_bWriteVbrTag(flags, 1);); |
938 | 1.75k | } |
939 | | |
940 | 5.67k | if ( ds.Get<bool>() ) { |
941 | 1.85k | _(lame_set_copyright(flags, 1);); |
942 | 1.85k | } |
943 | | |
944 | 5.67k | if ( ds.Get<bool>() ) { |
945 | 2.03k | _(lame_set_original(flags, 1);); |
946 | 2.03k | } |
947 | | |
948 | 5.67k | if ( ds.Get<bool>() ) { |
949 | 2.24k | _(lame_set_error_protection(flags, 1);); |
950 | 2.24k | } |
951 | | |
952 | 5.67k | if ( ds.Get<bool>() ) { |
953 | 2.14k | _(lame_set_extension(flags, 1);); |
954 | 2.14k | } |
955 | | |
956 | 5.67k | if ( ds.Get<bool>() ) { |
957 | | /* Crashes */ |
958 | | /* _(lame_set_free_format(flags, 1);); */ |
959 | 2.29k | } |
960 | 5.67k | } EncoderFuzzer<false>::setMisc() Line | Count | Source | 931 | 5.67k | void setMisc(void) { | 932 | 5.67k | if ( ds.Get<bool>() ) { | 933 | 1.87k | _(lame_set_strict_ISO(flags, MDB_STRICT_ISO);); | 934 | 1.87k | } | 935 | | | 936 | 5.67k | if ( ds.Get<bool>() ) { | 937 | 1.75k | _(lame_set_bWriteVbrTag(flags, 1);); | 938 | 1.75k | } | 939 | | | 940 | 5.67k | if ( ds.Get<bool>() ) { | 941 | 1.85k | _(lame_set_copyright(flags, 1);); | 942 | 1.85k | } | 943 | | | 944 | 5.67k | if ( ds.Get<bool>() ) { | 945 | 2.03k | _(lame_set_original(flags, 1);); | 946 | 2.03k | } | 947 | | | 948 | 5.67k | if ( ds.Get<bool>() ) { | 949 | 2.24k | _(lame_set_error_protection(flags, 1);); | 950 | 2.24k | } | 951 | | | 952 | 5.67k | if ( ds.Get<bool>() ) { | 953 | 2.14k | _(lame_set_extension(flags, 1);); | 954 | 2.14k | } | 955 | | | 956 | 5.67k | if ( ds.Get<bool>() ) { | 957 | | /* Crashes */ | 958 | | /* _(lame_set_free_format(flags, 1);); */ | 959 | 2.29k | } | 960 | 5.67k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setMisc() |
961 | | |
962 | | public: |
963 | | EncoderFuzzer(Datasource& ds) : |
964 | | ds(ds), outBufferSize(limits::OutBufferSize.Generate(ds)) |
965 | 7.98k | { |
966 | 7.98k | Debug ? |
967 | 0 | printf("lame_global_flags* flags = lame_init();\n") |
968 | 7.98k | : 0; |
969 | 7.98k | flags = lame_init(); |
970 | | |
971 | 7.98k | Debug ? |
972 | 0 | printf("const size_t outBufferSize = %zu;\n", outBufferSize) |
973 | 7.98k | : 0; |
974 | 7.98k | Debug ? |
975 | 0 | printf("unsigned char outBuffer[outBufferSize];\n") |
976 | 7.98k | : 0; |
977 | | |
978 | 7.98k | outBuffer = (uint8_t*)malloc(outBufferSize + 1024 /* Add 1024 due to crash */); |
979 | 7.98k | } EncoderFuzzer<false>::EncoderFuzzer(fuzzing::datasource::Datasource&) Line | Count | Source | 965 | 7.98k | { | 966 | 7.98k | Debug ? | 967 | 0 | printf("lame_global_flags* flags = lame_init();\n") | 968 | 7.98k | : 0; | 969 | 7.98k | flags = lame_init(); | 970 | | | 971 | 7.98k | Debug ? | 972 | 0 | printf("const size_t outBufferSize = %zu;\n", outBufferSize) | 973 | 7.98k | : 0; | 974 | 7.98k | Debug ? | 975 | 0 | printf("unsigned char outBuffer[outBufferSize];\n") | 976 | 7.98k | : 0; | 977 | | | 978 | 7.98k | outBuffer = (uint8_t*)malloc(outBufferSize + 1024 /* Add 1024 due to crash */); | 979 | 7.98k | } |
Unexecuted instantiation: EncoderFuzzer<true>::EncoderFuzzer(fuzzing::datasource::Datasource&) |
980 | | |
981 | 7.92k | void Run(void) { |
982 | | |
983 | 7.92k | std::unique_ptr<EncoderCoreBase> encoder = nullptr; |
984 | | |
985 | 7.92k | const uint8_t whichSampleSize = ds.Get<uint8_t>() % 5; |
986 | | |
987 | 7.92k | if ( whichSampleSize == 0 ) { |
988 | 4.70k | encoder = std::make_unique<EncoderCore<short int, Debug>>(ds, flags); |
989 | 4.70k | } else if ( whichSampleSize == 1 ) { |
990 | 703 | encoder = std::make_unique<EncoderCore<int, Debug>>(ds, flags); |
991 | 2.52k | } else if ( whichSampleSize == 2 ) { |
992 | 979 | encoder = std::make_unique<EncoderCore<long, Debug>>(ds, flags); |
993 | 1.54k | } else if ( whichSampleSize == 3 ) { |
994 | 913 | encoder = std::make_unique<EncoderCore<float, Debug>>(ds, flags); |
995 | 913 | } else if ( whichSampleSize == 4 ) { |
996 | 551 | encoder = std::make_unique<EncoderCore<double, Debug>>(ds, flags); |
997 | 551 | } |
998 | | |
999 | 7.92k | setInputChannels(); |
1000 | 7.92k | setBitrateMode(); |
1001 | 7.92k | setChannelMode(); |
1002 | 7.92k | setQuality(); |
1003 | 7.92k | setOutSamplerate(); |
1004 | 7.92k | setID3(); |
1005 | 7.92k | setFilters(); |
1006 | 7.92k | setMisc(); |
1007 | | |
1008 | 7.92k | Debug ? printf("lame_init_params(flags);\n") : 0; |
1009 | | |
1010 | 7.92k | if ( lame_init_params(flags) == -1 ) { |
1011 | 0 | abort(); |
1012 | 0 | } |
1013 | | |
1014 | 14.4k | while ( encoder->Run(outBuffer, outBufferSize, mono) ) { } |
1015 | 7.92k | } EncoderFuzzer<false>::Run() Line | Count | Source | 981 | 7.92k | void Run(void) { | 982 | | | 983 | 7.92k | std::unique_ptr<EncoderCoreBase> encoder = nullptr; | 984 | | | 985 | 7.92k | const uint8_t whichSampleSize = ds.Get<uint8_t>() % 5; | 986 | | | 987 | 7.92k | if ( whichSampleSize == 0 ) { | 988 | 4.70k | encoder = std::make_unique<EncoderCore<short int, Debug>>(ds, flags); | 989 | 4.70k | } else if ( whichSampleSize == 1 ) { | 990 | 703 | encoder = std::make_unique<EncoderCore<int, Debug>>(ds, flags); | 991 | 2.52k | } else if ( whichSampleSize == 2 ) { | 992 | 979 | encoder = std::make_unique<EncoderCore<long, Debug>>(ds, flags); | 993 | 1.54k | } else if ( whichSampleSize == 3 ) { | 994 | 913 | encoder = std::make_unique<EncoderCore<float, Debug>>(ds, flags); | 995 | 913 | } else if ( whichSampleSize == 4 ) { | 996 | 551 | encoder = std::make_unique<EncoderCore<double, Debug>>(ds, flags); | 997 | 551 | } | 998 | | | 999 | 7.92k | setInputChannels(); | 1000 | 7.92k | setBitrateMode(); | 1001 | 7.92k | setChannelMode(); | 1002 | 7.92k | setQuality(); | 1003 | 7.92k | setOutSamplerate(); | 1004 | 7.92k | setID3(); | 1005 | 7.92k | setFilters(); | 1006 | 7.92k | setMisc(); | 1007 | | | 1008 | 7.92k | Debug ? printf("lame_init_params(flags);\n") : 0; | 1009 | | | 1010 | 7.92k | if ( lame_init_params(flags) == -1 ) { | 1011 | 0 | abort(); | 1012 | 0 | } | 1013 | | | 1014 | 14.4k | while ( encoder->Run(outBuffer, outBufferSize, mono) ) { } | 1015 | 7.92k | } |
Unexecuted instantiation: EncoderFuzzer<true>::Run() |
1016 | | |
1017 | 7.92k | ~EncoderFuzzer() { |
1018 | 7.92k | lame_close(flags); |
1019 | 7.92k | free(outBuffer); |
1020 | 7.92k | outBuffer = nullptr; |
1021 | 7.92k | } EncoderFuzzer<false>::~EncoderFuzzer() Line | Count | Source | 1017 | 7.92k | ~EncoderFuzzer() { | 1018 | 7.92k | lame_close(flags); | 1019 | 7.92k | free(outBuffer); | 1020 | 7.92k | outBuffer = nullptr; | 1021 | 7.92k | } |
Unexecuted instantiation: EncoderFuzzer<true>::~EncoderFuzzer() |
1022 | | }; |
1023 | | |
1024 | | static bool debug = false; |
1025 | | |
1026 | | extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) |
1027 | 2 | { |
1028 | 2 | char** _argv = *argv; |
1029 | 13 | for (int i = 0; i < *argc; i++) { |
1030 | 11 | if ( std::string(_argv[i]) == "--debug") { |
1031 | 0 | debug = true; |
1032 | 0 | } |
1033 | 11 | } |
1034 | | |
1035 | 2 | return 0; |
1036 | 2 | } |
1037 | | |
1038 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
1039 | 7.98k | { |
1040 | 7.98k | Datasource ds(data, size); |
1041 | | |
1042 | 7.98k | try { |
1043 | 7.98k | if ( debug == false ) { |
1044 | 7.98k | EncoderFuzzer<false> encoder(ds); |
1045 | 7.98k | encoder.Run(); |
1046 | 7.98k | } else { |
1047 | 0 | EncoderFuzzer<true> encoder(ds); |
1048 | 0 | encoder.Run(); |
1049 | 0 | } |
1050 | 7.98k | } catch ( ... ) { } |
1051 | | |
1052 | 7.98k | return 0; |
1053 | 7.98k | } |