/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 | 29.9k | size_t Test(const size_t val) const { |
32 | 29.9k | if ( val < Min || val > Max ) { |
33 | | /* If not within bounds, default to the minimum allowed value */ |
34 | 17.2k | return Min; |
35 | 17.2k | } |
36 | | |
37 | 12.6k | return val; |
38 | 29.9k | } limits::Limit<1ul, 1048576ul>::Test(unsigned long) const Line | Count | Source | 31 | 7.25k | size_t Test(const size_t val) const { | 32 | 7.25k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 2.88k | return Min; | 35 | 2.88k | } | 36 | | | 37 | 4.37k | return val; | 38 | 7.25k | } |
limits::Limit<1ul, 1024ul>::Test(unsigned long) const Line | Count | Source | 31 | 7.21k | size_t Test(const size_t val) const { | 32 | 7.21k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 4.75k | return Min; | 35 | 4.75k | } | 36 | | | 37 | 2.45k | return val; | 38 | 7.21k | } |
limits::Limit<0ul, 9ul>::Test(unsigned long) const Line | Count | Source | 31 | 6.57k | size_t Test(const size_t val) const { | 32 | 6.57k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 3.92k | return Min; | 35 | 3.92k | } | 36 | | | 37 | 2.65k | return val; | 38 | 6.57k | } |
limits::Limit<100ul, 1000000ul>::Test(unsigned long) const Line | Count | Source | 31 | 6.56k | size_t Test(const size_t val) const { | 32 | 6.56k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 4.25k | return Min; | 35 | 4.25k | } | 36 | | | 37 | 2.31k | return val; | 38 | 6.56k | } |
limits::Limit<0ul, 1000000ul>::Test(unsigned long) const Line | Count | Source | 31 | 775 | size_t Test(const size_t val) const { | 32 | 775 | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 284 | return Min; | 35 | 284 | } | 36 | | | 37 | 491 | return val; | 38 | 775 | } |
limits::Limit<1000ul, 1000000ul>::Test(unsigned long) const Line | Count | Source | 31 | 1.54k | size_t Test(const size_t val) const { | 32 | 1.54k | if ( val < Min || val > Max ) { | 33 | | /* If not within bounds, default to the minimum allowed value */ | 34 | 1.18k | return Min; | 35 | 1.18k | } | 36 | | | 37 | 361 | return val; | 38 | 1.54k | } |
|
39 | | |
40 | | template <typename T = uint32_t> |
41 | 30.0k | size_t Generate(fuzzing::datasource::Datasource& ds) { |
42 | 30.0k | const size_t ret = ds.Get<T>(); |
43 | 30.0k | return Test(ret); |
44 | 30.0k | } unsigned long limits::Limit<1ul, 1048576ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 7.31k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 7.31k | const size_t ret = ds.Get<T>(); | 43 | 7.31k | return Test(ret); | 44 | 7.31k | } |
unsigned long limits::Limit<1ul, 1024ul>::Generate<unsigned char>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 1.27k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 1.27k | const size_t ret = ds.Get<T>(); | 43 | 1.27k | return Test(ret); | 44 | 1.27k | } |
unsigned long limits::Limit<1ul, 1024ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 5.94k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 5.94k | const size_t ret = ds.Get<T>(); | 43 | 5.94k | return Test(ret); | 44 | 5.94k | } |
unsigned long limits::Limit<0ul, 9ul>::Generate<unsigned char>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 6.57k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 6.57k | const size_t ret = ds.Get<T>(); | 43 | 6.57k | return Test(ret); | 44 | 6.57k | } |
unsigned long limits::Limit<100ul, 1000000ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 6.57k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 6.57k | const size_t ret = ds.Get<T>(); | 43 | 6.57k | return Test(ret); | 44 | 6.57k | } |
unsigned long limits::Limit<0ul, 1000000ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 776 | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 776 | const size_t ret = ds.Get<T>(); | 43 | 776 | return Test(ret); | 44 | 776 | } |
unsigned long limits::Limit<1000ul, 1000000ul>::Generate<unsigned int>(fuzzing::datasource::Datasource&) Line | Count | Source | 41 | 1.55k | size_t Generate(fuzzing::datasource::Datasource& ds) { | 42 | 1.55k | const size_t ret = ds.Get<T>(); | 43 | 1.55k | return Test(ret); | 44 | 1.55k | } |
|
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 | 24.4k | #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 | 113M | template <typename T> bool isNAN(const T& val) { |
69 | 113M | (void)val; |
70 | | |
71 | 113M | return false; |
72 | 113M | } bool isNAN<short>(short const&) Line | Count | Source | 68 | 108M | template <typename T> bool isNAN(const T& val) { | 69 | 108M | (void)val; | 70 | | | 71 | 108M | return false; | 72 | 108M | } |
bool isNAN<int>(int const&) Line | Count | Source | 68 | 3.29M | template <typename T> bool isNAN(const T& val) { | 69 | 3.29M | (void)val; | 70 | | | 71 | 3.29M | return false; | 72 | 3.29M | } |
bool isNAN<long>(long const&) Line | Count | Source | 68 | 1.71M | template <typename T> bool isNAN(const T& val) { | 69 | 1.71M | (void)val; | 70 | | | 71 | 1.71M | return false; | 72 | 1.71M | } |
|
73 | | |
74 | 4.80M | template <> bool isNAN<float>(const float& val) { |
75 | 4.80M | return std::isnan(val); |
76 | 4.80M | } |
77 | | |
78 | 1.77M | template <> bool isNAN<double>(const double& val) { |
79 | 1.77M | return std::isnan(val); |
80 | 1.77M | } |
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.18k | EncoderCoreBase(void) { } |
126 | 7.18k | 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.16k | void getInputData(void) { |
142 | 432k | while ( ds.Get<bool>() ) { |
143 | 425k | const auto data = ds.GetData(0); |
144 | | |
145 | | /* Round to a multiple of sizeof(T) */ |
146 | 425k | const size_t copySize = data.size() - (data.size() % sizeof(T)); |
147 | | |
148 | 425k | std::vector<T> toInsert; |
149 | 425k | toInsert.resize( data.size() / sizeof(T) ); |
150 | | |
151 | 425k | memcpy(toInsert.data(), data.data(), copySize); |
152 | | |
153 | | /* Correct NAN values */ |
154 | 120M | for (size_t i = 0; i < toInsert.size(); i++) { |
155 | 119M | if ( isNAN(toInsert[i]) ) { |
156 | | /* If NaN, set to default value (0.0) */ |
157 | 155k | toInsert[i] = {}; |
158 | 155k | } |
159 | 119M | } |
160 | | |
161 | 425k | inDataV.push_back(toInsert); |
162 | 425k | } |
163 | | |
164 | 7.16k | it = inDataV.begin(); |
165 | 7.16k | } EncoderCore<short, false>::getInputData() Line | Count | Source | 141 | 4.22k | void getInputData(void) { | 142 | 63.8k | while ( ds.Get<bool>() ) { | 143 | 59.6k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 59.6k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 59.6k | std::vector<T> toInsert; | 149 | 59.6k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 59.6k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 108M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 108M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 0 | toInsert[i] = {}; | 158 | 0 | } | 159 | 108M | } | 160 | | | 161 | 59.6k | inDataV.push_back(toInsert); | 162 | 59.6k | } | 163 | | | 164 | 4.22k | it = inDataV.begin(); | 165 | 4.22k | } |
EncoderCore<int, false>::getInputData() Line | Count | Source | 141 | 581 | void getInputData(void) { | 142 | 51.4k | while ( ds.Get<bool>() ) { | 143 | 50.8k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 50.8k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 50.8k | std::vector<T> toInsert; | 149 | 50.8k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 50.8k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 3.34M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 3.29M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 0 | toInsert[i] = {}; | 158 | 0 | } | 159 | 3.29M | } | 160 | | | 161 | 50.8k | inDataV.push_back(toInsert); | 162 | 50.8k | } | 163 | | | 164 | 581 | it = inDataV.begin(); | 165 | 581 | } |
EncoderCore<long, false>::getInputData() Line | Count | Source | 141 | 913 | void getInputData(void) { | 142 | 132k | while ( ds.Get<bool>() ) { | 143 | 131k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 131k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 131k | std::vector<T> toInsert; | 149 | 131k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 131k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 1.84M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 1.71M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 0 | toInsert[i] = {}; | 158 | 0 | } | 159 | 1.71M | } | 160 | | | 161 | 131k | inDataV.push_back(toInsert); | 162 | 131k | } | 163 | | | 164 | 913 | it = inDataV.begin(); | 165 | 913 | } |
EncoderCore<float, false>::getInputData() Line | Count | Source | 141 | 835 | void getInputData(void) { | 142 | 52.1k | while ( ds.Get<bool>() ) { | 143 | 51.3k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 51.3k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 51.3k | std::vector<T> toInsert; | 149 | 51.3k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 51.3k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 4.85M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 4.80M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 109k | toInsert[i] = {}; | 158 | 109k | } | 159 | 4.80M | } | 160 | | | 161 | 51.3k | inDataV.push_back(toInsert); | 162 | 51.3k | } | 163 | | | 164 | 835 | it = inDataV.begin(); | 165 | 835 | } |
EncoderCore<double, false>::getInputData() Line | Count | Source | 141 | 616 | void getInputData(void) { | 142 | 133k | while ( ds.Get<bool>() ) { | 143 | 132k | const auto data = ds.GetData(0); | 144 | | | 145 | | /* Round to a multiple of sizeof(T) */ | 146 | 132k | const size_t copySize = data.size() - (data.size() % sizeof(T)); | 147 | | | 148 | 132k | std::vector<T> toInsert; | 149 | 132k | toInsert.resize( data.size() / sizeof(T) ); | 150 | | | 151 | 132k | memcpy(toInsert.data(), data.data(), copySize); | 152 | | | 153 | | /* Correct NAN values */ | 154 | 1.90M | for (size_t i = 0; i < toInsert.size(); i++) { | 155 | 1.77M | if ( isNAN(toInsert[i]) ) { | 156 | | /* If NaN, set to default value (0.0) */ | 157 | 45.3k | toInsert[i] = {}; | 158 | 45.3k | } | 159 | 1.77M | } | 160 | | | 161 | 132k | inDataV.push_back(toInsert); | 162 | 132k | } | 163 | | | 164 | 616 | it = inDataV.begin(); | 165 | 616 | } |
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.73k | static void Correct(_T* inData, const size_t inDataSize) { |
173 | 3.73k | if ( inData == nullptr ) { |
174 | 830 | return; |
175 | 830 | } |
176 | | |
177 | 6.90M | for (size_t i = 0; i < inDataSize; i++) { |
178 | 6.90M | if ( inData[i] > Max ) { |
179 | 1.31M | inData[i] = Max; |
180 | 5.59M | } else if ( inData[i] < Min ) { |
181 | 1.45M | inData[i] = Min; |
182 | 1.45M | } |
183 | 6.90M | } |
184 | 2.90k | } EncoderCore<long, false>::InputCorrect<long, -32768l, 32768l>::Correct(long*, unsigned long) Line | Count | Source | 172 | 1.33k | static void Correct(_T* inData, const size_t inDataSize) { | 173 | 1.33k | if ( inData == nullptr ) { | 174 | 341 | return; | 175 | 341 | } | 176 | | | 177 | 1.39M | for (size_t i = 0; i < inDataSize; i++) { | 178 | 1.39M | if ( inData[i] > Max ) { | 179 | 755k | inData[i] = Max; | 180 | 755k | } else if ( inData[i] < Min ) { | 181 | 429k | inData[i] = Min; | 182 | 429k | } | 183 | 1.39M | } | 184 | 995 | } |
EncoderCore<float, false>::InputCorrect<float, -32768l, 32768l>::Correct(float*, unsigned long) Line | Count | Source | 172 | 624 | static void Correct(_T* inData, const size_t inDataSize) { | 173 | 624 | if ( inData == nullptr ) { | 174 | 117 | return; | 175 | 117 | } | 176 | | | 177 | 1.05M | for (size_t i = 0; i < inDataSize; i++) { | 178 | 1.05M | if ( inData[i] > Max ) { | 179 | 143k | inData[i] = Max; | 180 | 908k | } else if ( inData[i] < Min ) { | 181 | 173k | inData[i] = Min; | 182 | 173k | } | 183 | 1.05M | } | 184 | 507 | } |
EncoderCore<float, false>::InputCorrect<float, -1l, 1l>::Correct(float*, unsigned long) Line | Count | Source | 172 | 966 | static void Correct(_T* inData, const size_t inDataSize) { | 173 | 966 | if ( inData == nullptr ) { | 174 | 148 | return; | 175 | 148 | } | 176 | | | 177 | 3.01M | for (size_t i = 0; i < inDataSize; i++) { | 178 | 3.01M | if ( inData[i] > Max ) { | 179 | 295k | inData[i] = Max; | 180 | 2.71M | } else if ( inData[i] < Min ) { | 181 | 579k | inData[i] = Min; | 182 | 579k | } | 183 | 3.01M | } | 184 | 818 | } |
EncoderCore<double, false>::InputCorrect<double, -1l, 1l>::Correct(double*, unsigned long) Line | Count | Source | 172 | 809 | static void Correct(_T* inData, const size_t inDataSize) { | 173 | 809 | if ( inData == nullptr ) { | 174 | 224 | return; | 175 | 224 | } | 176 | | | 177 | 1.43M | for (size_t i = 0; i < inDataSize; i++) { | 178 | 1.43M | if ( inData[i] > Max ) { | 179 | 118k | inData[i] = Max; | 180 | 1.32M | } else if ( inData[i] < Min ) { | 181 | 269k | inData[i] = Min; | 182 | 269k | } | 183 | 1.43M | } | 184 | 585 | } |
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.17k | bool useIEEEFunction) { |
209 | | /* Not applicable for short int */ |
210 | 7.17k | (void)useIEEEFunction; |
211 | | |
212 | 7.17k | if ( useInterleavingFunction == false ) { |
213 | 4.75k | Debug ? printf("{\n") : 0; |
214 | | |
215 | 4.75k | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
216 | | |
217 | 4.75k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataL", "short int", inDataL, inDataSize, true).c_str()) : 0; |
218 | 4.75k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataR", "short int", inDataR, inDataSize, true).c_str()) : 0; |
219 | | |
220 | 4.75k | Debug ? |
221 | 0 | printf("\tlame_encode_buffer(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
222 | 4.75k | : 0; |
223 | | |
224 | 4.75k | const int ret = lame_encode_buffer(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
225 | | |
226 | 4.75k | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
227 | | |
228 | 4.75k | Debug ? printf("}\n") : 0; |
229 | | |
230 | 4.75k | return ret; |
231 | 4.75k | } else { |
232 | 2.42k | Debug ? printf("{\n") : 0; |
233 | | |
234 | 2.42k | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
235 | | |
236 | 2.42k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataL", "short int", inDataL, inDataSize * 2, true).c_str()) : 0; |
237 | | |
238 | 2.42k | Debug ? |
239 | 0 | printf("\tlame_encode_buffer_interleaved(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") |
240 | 2.42k | : 0; |
241 | | |
242 | 2.42k | const int ret = lame_encode_buffer_interleaved(flags, inDataL, inDataSize, outBuffer, outBufferSize); |
243 | | |
244 | 2.42k | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
245 | | |
246 | 2.42k | Debug ? printf("}\n") : 0; |
247 | | |
248 | 2.42k | return ret; |
249 | 2.42k | } |
250 | 7.17k | } 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.17k | bool useIEEEFunction) { | 209 | | /* Not applicable for short int */ | 210 | 7.17k | (void)useIEEEFunction; | 211 | | | 212 | 7.17k | if ( useInterleavingFunction == false ) { | 213 | 4.75k | Debug ? printf("{\n") : 0; | 214 | | | 215 | 4.75k | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 216 | | | 217 | 4.75k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataL", "short int", inDataL, inDataSize, true).c_str()) : 0; | 218 | 4.75k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataR", "short int", inDataR, inDataSize, true).c_str()) : 0; | 219 | | | 220 | 4.75k | Debug ? | 221 | 0 | printf("\tlame_encode_buffer(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 222 | 4.75k | : 0; | 223 | | | 224 | 4.75k | const int ret = lame_encode_buffer(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 225 | | | 226 | 4.75k | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 227 | | | 228 | 4.75k | Debug ? printf("}\n") : 0; | 229 | | | 230 | 4.75k | return ret; | 231 | 4.75k | } else { | 232 | 2.42k | Debug ? printf("{\n") : 0; | 233 | | | 234 | 2.42k | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 235 | | | 236 | 2.42k | Debug ? printf("%s\n", DebugDefineArray<short int>::Str("inDataL", "short int", inDataL, inDataSize * 2, true).c_str()) : 0; | 237 | | | 238 | 2.42k | Debug ? | 239 | 0 | printf("\tlame_encode_buffer_interleaved(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") | 240 | 2.42k | : 0; | 241 | | | 242 | 2.42k | const int ret = lame_encode_buffer_interleaved(flags, inDataL, inDataSize, outBuffer, outBufferSize); | 243 | | | 244 | 2.42k | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 245 | | | 246 | 2.42k | Debug ? printf("}\n") : 0; | 247 | | | 248 | 2.42k | return ret; | 249 | 2.42k | } | 250 | 7.17k | } |
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 | 420 | bool useIEEEFunction ) { |
263 | | /* Not applicable for int */ |
264 | 420 | (void)useIEEEFunction; |
265 | | |
266 | 420 | if ( useInterleavingFunction == false ) { |
267 | 291 | Debug ? printf("{\n") : 0; |
268 | | |
269 | 291 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
270 | | |
271 | 291 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataL", "int", inDataL, inDataSize, true).c_str()) : 0; |
272 | 291 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataR", "int", inDataR, inDataSize, true).c_str()) : 0; |
273 | | |
274 | 291 | Debug ? |
275 | 0 | printf("\tlame_encode_buffer_int(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
276 | 291 | : 0; |
277 | | |
278 | 291 | const int ret = lame_encode_buffer_int(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
279 | | |
280 | 291 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
281 | | |
282 | 291 | Debug ? printf("}\n") : 0; |
283 | | |
284 | 291 | return ret; |
285 | 291 | } else { |
286 | 129 | Debug ? printf("{\n") : 0; |
287 | | |
288 | 129 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
289 | | |
290 | 129 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataL", "int", inDataL, inDataSize * 2, true).c_str()) : 0; |
291 | | |
292 | 129 | Debug ? |
293 | 0 | printf("\tlame_encode_buffer_interleaved_int(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") |
294 | 129 | : 0; |
295 | | |
296 | 129 | const int ret = lame_encode_buffer_interleaved_int(flags, inDataL, inDataSize, outBuffer, outBufferSize); |
297 | | |
298 | 129 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
299 | | |
300 | 129 | Debug ? printf("}\n") : 0; |
301 | | |
302 | 129 | return ret; |
303 | 129 | } |
304 | 420 | } EncoderCore<int, false>::EncodeSingle<int, false>::encode(lame_global_struct*, int*, int*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 262 | 420 | bool useIEEEFunction ) { | 263 | | /* Not applicable for int */ | 264 | 420 | (void)useIEEEFunction; | 265 | | | 266 | 420 | if ( useInterleavingFunction == false ) { | 267 | 291 | Debug ? printf("{\n") : 0; | 268 | | | 269 | 291 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 270 | | | 271 | 291 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataL", "int", inDataL, inDataSize, true).c_str()) : 0; | 272 | 291 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataR", "int", inDataR, inDataSize, true).c_str()) : 0; | 273 | | | 274 | 291 | Debug ? | 275 | 0 | printf("\tlame_encode_buffer_int(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 276 | 291 | : 0; | 277 | | | 278 | 291 | const int ret = lame_encode_buffer_int(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 279 | | | 280 | 291 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 281 | | | 282 | 291 | Debug ? printf("}\n") : 0; | 283 | | | 284 | 291 | return ret; | 285 | 291 | } else { | 286 | 129 | Debug ? printf("{\n") : 0; | 287 | | | 288 | 129 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 289 | | | 290 | 129 | Debug ? printf("%s\n", DebugDefineArray<int>::Str("inDataL", "int", inDataL, inDataSize * 2, true).c_str()) : 0; | 291 | | | 292 | 129 | Debug ? | 293 | 0 | printf("\tlame_encode_buffer_interleaved_int(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") | 294 | 129 | : 0; | 295 | | | 296 | 129 | const int ret = lame_encode_buffer_interleaved_int(flags, inDataL, inDataSize, outBuffer, outBufferSize); | 297 | | | 298 | 129 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 299 | | | 300 | 129 | Debug ? printf("}\n") : 0; | 301 | | | 302 | 129 | return ret; | 303 | 129 | } | 304 | 420 | } |
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 | 694 | bool useIEEEFunction) { |
317 | | /* Not applicable for long */ |
318 | 694 | (void)useIEEEFunction; |
319 | | |
320 | 694 | if ( useInterleavingFunction == false ) { |
321 | 668 | InputCorrect<long, -32768, 32768>::Correct(inDataL, inDataSize); |
322 | 668 | InputCorrect<long, -32768, 32768>::Correct(inDataR, inDataSize); |
323 | | |
324 | 668 | Debug ? printf("{\n") : 0; |
325 | | |
326 | 668 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
327 | | |
328 | 668 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataL", "long", inDataL, inDataSize, true).c_str()) : 0; |
329 | 668 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataR", "long", inDataR, inDataSize, true).c_str()) : 0; |
330 | | |
331 | 668 | Debug ? |
332 | 0 | printf("\tlame_encode_buffer_long(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
333 | 668 | : 0; |
334 | | |
335 | 668 | const int ret = lame_encode_buffer_long(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
336 | | |
337 | 668 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
338 | | |
339 | 668 | Debug ? printf("}\n") : 0; |
340 | | |
341 | 668 | return ret; |
342 | 668 | } else { |
343 | 26 | Debug ? printf("{\n") : 0; |
344 | | |
345 | 26 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
346 | | |
347 | 26 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataL", "long", inDataL, inDataSize, true).c_str()) : 0; |
348 | 26 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataR", "long", inDataR, inDataSize, true).c_str()) : 0; |
349 | | |
350 | 26 | Debug ? |
351 | 0 | printf("\tlame_encode_buffer_long2(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
352 | 26 | : 0; |
353 | | |
354 | | /* Not actually interleaved */ |
355 | 26 | const int ret = lame_encode_buffer_long2(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
356 | | |
357 | 26 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
358 | | |
359 | 26 | Debug ? printf("}\n") : 0; |
360 | | |
361 | 26 | return ret; |
362 | 26 | } |
363 | 694 | } EncoderCore<long, false>::EncodeSingle<long, false>::encode(lame_global_struct*, long*, long*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 316 | 694 | bool useIEEEFunction) { | 317 | | /* Not applicable for long */ | 318 | 694 | (void)useIEEEFunction; | 319 | | | 320 | 694 | if ( useInterleavingFunction == false ) { | 321 | 668 | InputCorrect<long, -32768, 32768>::Correct(inDataL, inDataSize); | 322 | 668 | InputCorrect<long, -32768, 32768>::Correct(inDataR, inDataSize); | 323 | | | 324 | 668 | Debug ? printf("{\n") : 0; | 325 | | | 326 | 668 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 327 | | | 328 | 668 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataL", "long", inDataL, inDataSize, true).c_str()) : 0; | 329 | 668 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataR", "long", inDataR, inDataSize, true).c_str()) : 0; | 330 | | | 331 | 668 | Debug ? | 332 | 0 | printf("\tlame_encode_buffer_long(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 333 | 668 | : 0; | 334 | | | 335 | 668 | const int ret = lame_encode_buffer_long(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 336 | | | 337 | 668 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 338 | | | 339 | 668 | Debug ? printf("}\n") : 0; | 340 | | | 341 | 668 | return ret; | 342 | 668 | } else { | 343 | 26 | Debug ? printf("{\n") : 0; | 344 | | | 345 | 26 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 346 | | | 347 | 26 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataL", "long", inDataL, inDataSize, true).c_str()) : 0; | 348 | 26 | Debug ? printf("%s\n", DebugDefineArray<long>::Str("inDataR", "long", inDataR, inDataSize, true).c_str()) : 0; | 349 | | | 350 | 26 | Debug ? | 351 | 0 | printf("\tlame_encode_buffer_long2(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 352 | 26 | : 0; | 353 | | | 354 | | /* Not actually interleaved */ | 355 | 26 | const int ret = lame_encode_buffer_long2(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 356 | | | 357 | 26 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 358 | | | 359 | 26 | Debug ? printf("}\n") : 0; | 360 | | | 361 | 26 | return ret; | 362 | 26 | } | 363 | 694 | } |
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 | 934 | bool useIEEEFunction) { |
376 | | |
377 | 934 | if ( useInterleavingFunction == false ) { |
378 | 657 | if ( useIEEEFunction == false ) { |
379 | 312 | InputCorrect<float, -32768, 32768>::Correct(inDataL, inDataSize); |
380 | 312 | InputCorrect<float, -32768, 32768>::Correct(inDataR, inDataSize); |
381 | | |
382 | 312 | Debug ? printf("{\n") : 0; |
383 | | |
384 | 312 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
385 | | |
386 | 312 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize, true).c_str()) : 0; |
387 | 312 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataR", "float", inDataR, inDataSize, true).c_str()) : 0; |
388 | | |
389 | 312 | Debug ? |
390 | 0 | printf("\tlame_encode_buffer_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
391 | 312 | : 0; |
392 | | |
393 | 312 | const int ret = lame_encode_buffer_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
394 | | |
395 | 312 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
396 | | |
397 | 312 | Debug ? printf("}\n") : 0; |
398 | | |
399 | 312 | return ret; |
400 | 345 | } else { |
401 | 345 | InputCorrect<float, -1, 1>::Correct(inDataL, inDataSize); |
402 | 345 | InputCorrect<float, -1, 1>::Correct(inDataR, inDataSize); |
403 | | |
404 | 345 | Debug ? printf("{\n") : 0; |
405 | | |
406 | 345 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
407 | | |
408 | 345 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize, true).c_str()) : 0; |
409 | 345 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataR", "float", inDataR, inDataSize, true).c_str()) : 0; |
410 | | |
411 | 345 | Debug ? |
412 | 0 | printf("\tlame_encode_buffer_ieee_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
413 | 345 | : 0; |
414 | | |
415 | 345 | const int ret = lame_encode_buffer_ieee_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
416 | | |
417 | 345 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
418 | | |
419 | 345 | Debug ? printf("}\n") : 0; |
420 | | |
421 | 345 | return ret; |
422 | 345 | } |
423 | 657 | } else { |
424 | 277 | if ( useIEEEFunction == true ) { |
425 | 276 | InputCorrect<float, -1, 1>::Correct(inDataL, inDataSize * 2); |
426 | | |
427 | 276 | Debug ? printf("{\n") : 0; |
428 | | |
429 | 276 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize * 2).c_str()) : 0; |
430 | | |
431 | 276 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize * 2, true).c_str()) : 0; |
432 | | |
433 | 276 | Debug ? |
434 | 0 | printf("\tlame_encode_buffer_interleaved_ieee_float(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") |
435 | 276 | : 0; |
436 | | |
437 | 276 | const int ret = lame_encode_buffer_interleaved_ieee_float(flags, inDataL, inDataSize, outBuffer, outBufferSize); |
438 | | |
439 | 276 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
440 | | |
441 | 276 | Debug ? printf("}\n") : 0; |
442 | | |
443 | 276 | return ret; |
444 | 276 | } else { |
445 | | /* No function for interleaved float */ |
446 | 1 | return -1; |
447 | 1 | } |
448 | 277 | } |
449 | 934 | } EncoderCore<float, false>::EncodeSingle<float, false>::encode(lame_global_struct*, float*, float*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 375 | 934 | bool useIEEEFunction) { | 376 | | | 377 | 934 | if ( useInterleavingFunction == false ) { | 378 | 657 | if ( useIEEEFunction == false ) { | 379 | 312 | InputCorrect<float, -32768, 32768>::Correct(inDataL, inDataSize); | 380 | 312 | InputCorrect<float, -32768, 32768>::Correct(inDataR, inDataSize); | 381 | | | 382 | 312 | Debug ? printf("{\n") : 0; | 383 | | | 384 | 312 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 385 | | | 386 | 312 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize, true).c_str()) : 0; | 387 | 312 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataR", "float", inDataR, inDataSize, true).c_str()) : 0; | 388 | | | 389 | 312 | Debug ? | 390 | 0 | printf("\tlame_encode_buffer_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 391 | 312 | : 0; | 392 | | | 393 | 312 | const int ret = lame_encode_buffer_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 394 | | | 395 | 312 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 396 | | | 397 | 312 | Debug ? printf("}\n") : 0; | 398 | | | 399 | 312 | return ret; | 400 | 345 | } else { | 401 | 345 | InputCorrect<float, -1, 1>::Correct(inDataL, inDataSize); | 402 | 345 | InputCorrect<float, -1, 1>::Correct(inDataR, inDataSize); | 403 | | | 404 | 345 | Debug ? printf("{\n") : 0; | 405 | | | 406 | 345 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 407 | | | 408 | 345 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize, true).c_str()) : 0; | 409 | 345 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataR", "float", inDataR, inDataSize, true).c_str()) : 0; | 410 | | | 411 | 345 | Debug ? | 412 | 0 | printf("\tlame_encode_buffer_ieee_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 413 | 345 | : 0; | 414 | | | 415 | 345 | const int ret = lame_encode_buffer_ieee_float(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 416 | | | 417 | 345 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 418 | | | 419 | 345 | Debug ? printf("}\n") : 0; | 420 | | | 421 | 345 | return ret; | 422 | 345 | } | 423 | 657 | } else { | 424 | 277 | if ( useIEEEFunction == true ) { | 425 | 276 | InputCorrect<float, -1, 1>::Correct(inDataL, inDataSize * 2); | 426 | | | 427 | 276 | Debug ? printf("{\n") : 0; | 428 | | | 429 | 276 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize * 2).c_str()) : 0; | 430 | | | 431 | 276 | Debug ? printf("%s\n", DebugDefineArray<float>::Str("inDataL", "float", inDataL, inDataSize * 2, true).c_str()) : 0; | 432 | | | 433 | 276 | Debug ? | 434 | 0 | printf("\tlame_encode_buffer_interleaved_ieee_float(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") | 435 | 276 | : 0; | 436 | | | 437 | 276 | const int ret = lame_encode_buffer_interleaved_ieee_float(flags, inDataL, inDataSize, outBuffer, outBufferSize); | 438 | | | 439 | 276 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 440 | | | 441 | 276 | Debug ? printf("}\n") : 0; | 442 | | | 443 | 276 | return ret; | 444 | 276 | } else { | 445 | | /* No function for interleaved float */ | 446 | 1 | return -1; | 447 | 1 | } | 448 | 277 | } | 449 | 934 | } |
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 | 461 | bool useIEEEFunction) { |
462 | | |
463 | 461 | if ( useInterleavingFunction == false ) { |
464 | 355 | if ( useIEEEFunction == false ) { |
465 | | /* No non-IEEE function for interleaved double */ |
466 | 3 | return -1; |
467 | 352 | } else { |
468 | 352 | InputCorrect<double, -1, 1>::Correct(inDataL, inDataSize); |
469 | 352 | InputCorrect<double, -1, 1>::Correct(inDataR, inDataSize); |
470 | | |
471 | 352 | Debug ? printf("{\n") : 0; |
472 | | |
473 | 352 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
474 | | |
475 | 352 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataL", "double", inDataL, inDataSize, true).c_str()) : 0; |
476 | 352 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataR", "double", inDataR, inDataSize, true).c_str()) : 0; |
477 | | |
478 | 352 | Debug ? |
479 | 0 | printf("\tlame_encode_buffer_ieee_double(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") |
480 | 352 | : 0; |
481 | | |
482 | 352 | const int ret = lame_encode_buffer_ieee_double(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); |
483 | | |
484 | 352 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
485 | | |
486 | 352 | Debug ? printf("}\n") : 0; |
487 | | |
488 | 352 | return ret; |
489 | 352 | } |
490 | 355 | } else { |
491 | 106 | if ( useIEEEFunction == false ) { |
492 | 105 | InputCorrect<double, -1, 1>::Correct(inDataL, inDataSize * 2); |
493 | | |
494 | 105 | Debug ? printf("{\n") : 0; |
495 | | |
496 | 105 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; |
497 | | |
498 | 105 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataL", "double", inDataL, inDataSize * 2, true).c_str()) : 0; |
499 | | |
500 | 105 | Debug ? |
501 | 0 | printf("lame_encode_buffer_interleaved_ieee_double(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") |
502 | 105 | : 0; |
503 | | |
504 | 105 | const int ret = lame_encode_buffer_interleaved_ieee_double(flags, inDataL, inDataSize, outBuffer, outBufferSize); |
505 | | |
506 | | |
507 | 105 | Debug ? printf("\t// (returns %d)\n", ret) : 0; |
508 | | |
509 | 105 | Debug ? printf("}\n") : 0; |
510 | | |
511 | 105 | return ret; |
512 | 105 | } else { |
513 | | /* No non-IEEE function for double */ |
514 | 1 | return -1; |
515 | 1 | } |
516 | 106 | } |
517 | 461 | } EncoderCore<double, false>::EncodeSingle<double, false>::encode(lame_global_struct*, double*, double*, unsigned long, unsigned char*, unsigned long, bool, bool) Line | Count | Source | 461 | 461 | bool useIEEEFunction) { | 462 | | | 463 | 461 | if ( useInterleavingFunction == false ) { | 464 | 355 | if ( useIEEEFunction == false ) { | 465 | | /* No non-IEEE function for interleaved double */ | 466 | 3 | return -1; | 467 | 352 | } else { | 468 | 352 | InputCorrect<double, -1, 1>::Correct(inDataL, inDataSize); | 469 | 352 | InputCorrect<double, -1, 1>::Correct(inDataR, inDataSize); | 470 | | | 471 | 352 | Debug ? printf("{\n") : 0; | 472 | | | 473 | 352 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 474 | | | 475 | 352 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataL", "double", inDataL, inDataSize, true).c_str()) : 0; | 476 | 352 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataR", "double", inDataR, inDataSize, true).c_str()) : 0; | 477 | | | 478 | 352 | Debug ? | 479 | 0 | printf("\tlame_encode_buffer_ieee_double(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize);\n") | 480 | 352 | : 0; | 481 | | | 482 | 352 | const int ret = lame_encode_buffer_ieee_double(flags, inDataL, inDataR, inDataSize, outBuffer, outBufferSize); | 483 | | | 484 | 352 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 485 | | | 486 | 352 | Debug ? printf("}\n") : 0; | 487 | | | 488 | 352 | return ret; | 489 | 352 | } | 490 | 355 | } else { | 491 | 106 | if ( useIEEEFunction == false ) { | 492 | 105 | InputCorrect<double, -1, 1>::Correct(inDataL, inDataSize * 2); | 493 | | | 494 | 105 | Debug ? printf("{\n") : 0; | 495 | | | 496 | 105 | Debug ? printf("\t%s\n", debug_define_size_t("inDataSize", inDataSize).c_str()) : 0; | 497 | | | 498 | 105 | Debug ? printf("%s\n", DebugDefineArray<double>::Str("inDataL", "double", inDataL, inDataSize * 2, true).c_str()) : 0; | 499 | | | 500 | 105 | Debug ? | 501 | 0 | printf("lame_encode_buffer_interleaved_ieee_double(flags, inDataL, inDataSize, outBuffer, outBufferSize);\n") | 502 | 105 | : 0; | 503 | | | 504 | 105 | const int ret = lame_encode_buffer_interleaved_ieee_double(flags, inDataL, inDataSize, outBuffer, outBufferSize); | 505 | | | 506 | | | 507 | 105 | Debug ? printf("\t// (returns %d)\n", ret) : 0; | 508 | | | 509 | 105 | Debug ? printf("}\n") : 0; | 510 | | | 511 | 105 | return ret; | 512 | 105 | } else { | 513 | | /* No non-IEEE function for double */ | 514 | 1 | return -1; | 515 | 1 | } | 516 | 106 | } | 517 | 461 | } |
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 | 9.68k | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { |
521 | 9.68k | if ( useInterleavingFunction && mono ) { |
522 | 5 | return -1; |
523 | 5 | } |
524 | | |
525 | 9.67k | if ( mono == true ) { |
526 | 1.58k | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); |
527 | 8.09k | } 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.13k | } else { |
537 | 5.13k | size_t numSamples = inData.size(); |
538 | | |
539 | | /* Round to a multiple of 2 */ |
540 | 5.13k | if ( numSamples % 2 ) { |
541 | 1.97k | numSamples--; |
542 | 1.97k | } |
543 | | |
544 | | /* To samples per channel */ |
545 | 5.13k | numSamples /= 2; |
546 | | |
547 | | /* Left, right channels */ |
548 | 5.13k | std::vector<T> inDataL, inDataR; |
549 | 5.13k | inDataL.resize(numSamples); |
550 | 5.13k | inDataR.resize(numSamples); |
551 | | |
552 | | /* Split inData evenly between inDataL and inDataR */ |
553 | 5.13k | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); |
554 | 5.13k | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); |
555 | | |
556 | 5.13k | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); |
557 | 5.13k | } |
558 | 9.67k | } EncoderCore<short, false>::encode(std::__1::vector<short, std::__1::allocator<short> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 7.17k | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 7.17k | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 7.17k | if ( mono == true ) { | 526 | 1.00k | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 6.16k | } else if ( useInterleavingFunction ) { | 528 | 2.42k | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 2.42k | std::vector<T> inDataCopy; | 531 | 2.42k | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 2.42k | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 2.42k | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 3.74k | } else { | 537 | 3.74k | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 3.74k | if ( numSamples % 2 ) { | 541 | 1.55k | numSamples--; | 542 | 1.55k | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 3.74k | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 3.74k | std::vector<T> inDataL, inDataR; | 549 | 3.74k | inDataL.resize(numSamples); | 550 | 3.74k | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 3.74k | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 3.74k | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 3.74k | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 3.74k | } | 558 | 7.17k | } |
EncoderCore<int, false>::encode(std::__1::vector<int, std::__1::allocator<int> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 421 | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 421 | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 420 | if ( mono == true ) { | 526 | 110 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 310 | } else if ( useInterleavingFunction ) { | 528 | 129 | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 129 | std::vector<T> inDataCopy; | 531 | 129 | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 129 | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 129 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 181 | } else { | 537 | 181 | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 181 | if ( numSamples % 2 ) { | 541 | 47 | numSamples--; | 542 | 47 | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 181 | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 181 | std::vector<T> inDataL, inDataR; | 549 | 181 | inDataL.resize(numSamples); | 550 | 181 | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 181 | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 181 | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 181 | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 181 | } | 558 | 420 | } |
EncoderCore<long, false>::encode(std::__1::vector<long, std::__1::allocator<long> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 695 | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 695 | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 694 | if ( mono == true ) { | 526 | 197 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 497 | } else if ( useInterleavingFunction ) { | 528 | 26 | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 26 | std::vector<T> inDataCopy; | 531 | 26 | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 26 | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 26 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 471 | } else { | 537 | 471 | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 471 | if ( numSamples % 2 ) { | 541 | 145 | numSamples--; | 542 | 145 | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 471 | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 471 | std::vector<T> inDataL, inDataR; | 549 | 471 | inDataL.resize(numSamples); | 550 | 471 | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 471 | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 471 | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 471 | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 471 | } | 558 | 694 | } |
EncoderCore<float, false>::encode(std::__1::vector<float, std::__1::allocator<float> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 935 | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 935 | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 934 | if ( mono == true ) { | 526 | 141 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 793 | } else if ( useInterleavingFunction ) { | 528 | 277 | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 277 | std::vector<T> inDataCopy; | 531 | 277 | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 277 | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 277 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 536 | 516 | } else { | 537 | 516 | size_t numSamples = inData.size(); | 538 | | | 539 | | /* Round to a multiple of 2 */ | 540 | 516 | if ( numSamples % 2 ) { | 541 | 117 | numSamples--; | 542 | 117 | } | 543 | | | 544 | | /* To samples per channel */ | 545 | 516 | numSamples /= 2; | 546 | | | 547 | | /* Left, right channels */ | 548 | 516 | std::vector<T> inDataL, inDataR; | 549 | 516 | inDataL.resize(numSamples); | 550 | 516 | inDataR.resize(numSamples); | 551 | | | 552 | | /* Split inData evenly between inDataL and inDataR */ | 553 | 516 | memcpy(inDataL.data(), inData.data(), numSamples * sizeof(T)); | 554 | 516 | memcpy(inDataR.data(), inData.data() + numSamples, numSamples * sizeof(T)); | 555 | | | 556 | 516 | return EncodeSingle<T, Debug>::encode(flags, inDataL.data(), inDataR.data(), numSamples, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 557 | 516 | } | 558 | 934 | } |
EncoderCore<double, false>::encode(std::__1::vector<double, std::__1::allocator<double> >&, unsigned char*, unsigned long, bool) Line | Count | Source | 520 | 462 | int encode(std::vector<T>& inData, uint8_t* outBuffer, const size_t outBufferSize, const bool mono) { | 521 | 462 | if ( useInterleavingFunction && mono ) { | 522 | 1 | return -1; | 523 | 1 | } | 524 | | | 525 | 461 | if ( mono == true ) { | 526 | 128 | return EncodeSingle<T, Debug>::encode(flags, inData.data(), nullptr, inData.size() / 2, outBuffer, outBufferSize, useInterleavingFunction, useIEEEFunction); | 527 | 333 | } else if ( useInterleavingFunction ) { | 528 | 106 | const size_t numSamples = inData.size() / 2; | 529 | | | 530 | 106 | std::vector<T> inDataCopy; | 531 | 106 | inDataCopy.resize(numSamples * 2); | 532 | | | 533 | 106 | memcpy(inDataCopy.data(), inData.data(), numSamples * 2 * sizeof(T)); | 534 | | | 535 | 106 | 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 | 105 | numSamples--; | 542 | 105 | } | 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 | 461 | } |
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.58k | int flush(uint8_t* outBuffer, const size_t outBufferSize) { |
561 | 9.58k | if ( ds.Get<bool>() ) { |
562 | | /* No flush */ |
563 | 1.18k | return 0; |
564 | 1.18k | } |
565 | | |
566 | 8.40k | if ( ds.Get<bool>() ) { |
567 | 6.42k | Debug ? |
568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") |
569 | 6.42k | : 0; |
570 | | |
571 | 6.42k | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); |
572 | | |
573 | 6.42k | Debug ? printf("// (returns %d)\n", ret) : 0; |
574 | | |
575 | 6.42k | 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.42k | return ret; |
584 | 6.42k | } 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 | 1.98k | return 0; |
600 | 1.98k | #endif |
601 | 1.98k | } |
602 | 8.40k | } EncoderCore<short, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 7.14k | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 7.14k | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 657 | return 0; | 564 | 657 | } | 565 | | | 566 | 6.48k | if ( ds.Get<bool>() ) { | 567 | 5.60k | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 5.60k | : 0; | 570 | | | 571 | 5.60k | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 5.60k | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 5.60k | 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.60k | return ret; | 584 | 5.60k | } 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 | 884 | return 0; | 600 | 884 | #endif | 601 | 884 | } | 602 | 6.48k | } |
EncoderCore<int, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 413 | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 413 | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 132 | return 0; | 564 | 132 | } | 565 | | | 566 | 281 | if ( ds.Get<bool>() ) { | 567 | 143 | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 143 | : 0; | 570 | | | 571 | 143 | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 143 | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 143 | 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 | 143 | return ret; | 584 | 143 | } 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 | 138 | return 0; | 600 | 138 | #endif | 601 | 138 | } | 602 | 281 | } |
EncoderCore<long, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 661 | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 661 | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 100 | return 0; | 564 | 100 | } | 565 | | | 566 | 561 | if ( ds.Get<bool>() ) { | 567 | 147 | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 147 | : 0; | 570 | | | 571 | 147 | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 147 | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 147 | 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 | 147 | return ret; | 584 | 414 | } 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 | 414 | return 0; | 600 | 414 | #endif | 601 | 414 | } | 602 | 561 | } |
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 | 193 | return 0; | 564 | 193 | } | 565 | | | 566 | 730 | if ( ds.Get<bool>() ) { | 567 | 424 | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 424 | : 0; | 570 | | | 571 | 424 | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 424 | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 424 | 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 | 424 | return ret; | 584 | 424 | } 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 | 306 | return 0; | 600 | 306 | #endif | 601 | 306 | } | 602 | 730 | } |
EncoderCore<double, false>::flush(unsigned char*, unsigned long) Line | Count | Source | 560 | 449 | int flush(uint8_t* outBuffer, const size_t outBufferSize) { | 561 | 449 | if ( ds.Get<bool>() ) { | 562 | | /* No flush */ | 563 | 99 | return 0; | 564 | 99 | } | 565 | | | 566 | 350 | if ( ds.Get<bool>() ) { | 567 | 110 | Debug ? | 568 | 0 | printf("lame_encode_flush(flags, outBuffer, outBufferSize);\n") | 569 | 110 | : 0; | 570 | | | 571 | 110 | const int ret = lame_encode_flush(flags, outBuffer, outBufferSize); | 572 | | | 573 | 110 | Debug ? printf("// (returns %d)\n", ret) : 0; | 574 | | | 575 | 110 | 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 | 110 | return ret; | 584 | 240 | } 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 | 240 | return 0; | 600 | 240 | #endif | 601 | 240 | } | 602 | 350 | } |
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 | 7.18k | EncoderCoreBase(), |
606 | 7.18k | ds(ds), |
607 | 7.18k | flags(flags), |
608 | 7.18k | it(inDataV.end()), |
609 | 7.18k | useInterleavingFunction( ds.Get<bool>() ), |
610 | 7.18k | useIEEEFunction( ds.Get<bool>() ) |
611 | 7.18k | { |
612 | 7.18k | getInputData(); |
613 | 7.18k | } EncoderCore<short, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 605 | 4.22k | EncoderCoreBase(), | 606 | 4.22k | ds(ds), | 607 | 4.22k | flags(flags), | 608 | 4.22k | it(inDataV.end()), | 609 | 4.22k | useInterleavingFunction( ds.Get<bool>() ), | 610 | 4.22k | useIEEEFunction( ds.Get<bool>() ) | 611 | 4.22k | { | 612 | 4.22k | getInputData(); | 613 | 4.22k | } |
EncoderCore<int, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 605 | 585 | EncoderCoreBase(), | 606 | 585 | ds(ds), | 607 | 585 | flags(flags), | 608 | 585 | it(inDataV.end()), | 609 | 585 | useInterleavingFunction( ds.Get<bool>() ), | 610 | 585 | useIEEEFunction( ds.Get<bool>() ) | 611 | 585 | { | 612 | 585 | getInputData(); | 613 | 585 | } |
EncoderCore<long, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 605 | 917 | EncoderCoreBase(), | 606 | 917 | ds(ds), | 607 | 917 | flags(flags), | 608 | 917 | it(inDataV.end()), | 609 | 917 | useInterleavingFunction( ds.Get<bool>() ), | 610 | 917 | useIEEEFunction( ds.Get<bool>() ) | 611 | 917 | { | 612 | 917 | getInputData(); | 613 | 917 | } |
EncoderCore<float, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 605 | 837 | EncoderCoreBase(), | 606 | 837 | ds(ds), | 607 | 837 | flags(flags), | 608 | 837 | it(inDataV.end()), | 609 | 837 | useInterleavingFunction( ds.Get<bool>() ), | 610 | 837 | useIEEEFunction( ds.Get<bool>() ) | 611 | 837 | { | 612 | 837 | getInputData(); | 613 | 837 | } |
EncoderCore<double, false>::EncoderCore(fuzzing::datasource::Datasource&, lame_global_struct*) Line | Count | Source | 605 | 619 | EncoderCoreBase(), | 606 | 619 | ds(ds), | 607 | 619 | flags(flags), | 608 | 619 | it(inDataV.end()), | 609 | 619 | useInterleavingFunction( ds.Get<bool>() ), | 610 | 619 | useIEEEFunction( ds.Get<bool>() ) | 611 | 619 | { | 612 | 619 | getInputData(); | 613 | 619 | } |
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 | 11.6k | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { |
616 | 11.6k | if ( it == inDataV.end() ) { |
617 | 1.98k | return false; |
618 | 1.98k | } |
619 | | |
620 | 9.68k | auto& inData = *it; |
621 | 9.68k | 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 | 9.68k | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); |
631 | | |
632 | 9.68k | if ( encodeRet < 0 ) { |
633 | 97 | return false; |
634 | 97 | } |
635 | | |
636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ |
637 | 9.58k | 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.58k | const int flushRet = flush(outBuffer, outBufferSize); |
652 | | |
653 | 9.58k | if ( flushRet < 0 ) { |
654 | 396 | return false; |
655 | 396 | } |
656 | | |
657 | 9.19k | fuzzing::memory::memory_test_msan(outBuffer, flushRet); |
658 | | |
659 | 9.19k | if ( encodeRet == 0 ) { |
660 | 1.61k | return false; |
661 | 1.61k | } |
662 | | |
663 | 7.57k | return true; |
664 | 9.19k | } EncoderCore<short, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 8.65k | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 8.65k | if ( it == inDataV.end() ) { | 617 | 1.48k | return false; | 618 | 1.48k | } | 619 | | | 620 | 7.17k | auto& inData = *it; | 621 | 7.17k | 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.17k | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 7.17k | if ( encodeRet < 0 ) { | 633 | 30 | return false; | 634 | 30 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 7.14k | 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.14k | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 7.14k | if ( flushRet < 0 ) { | 654 | 298 | return false; | 655 | 298 | } | 656 | | | 657 | 6.84k | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 6.84k | if ( encodeRet == 0 ) { | 660 | 1.29k | return false; | 661 | 1.29k | } | 662 | | | 663 | 5.54k | return true; | 664 | 6.84k | } |
EncoderCore<int, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 557 | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 557 | if ( it == inDataV.end() ) { | 617 | 136 | return false; | 618 | 136 | } | 619 | | | 620 | 421 | auto& inData = *it; | 621 | 421 | 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 | 421 | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 421 | if ( encodeRet < 0 ) { | 633 | 8 | return false; | 634 | 8 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 413 | 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 | 413 | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 413 | if ( flushRet < 0 ) { | 654 | 19 | return false; | 655 | 19 | } | 656 | | | 657 | 394 | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 394 | if ( encodeRet == 0 ) { | 660 | 46 | return false; | 661 | 46 | } | 662 | | | 663 | 348 | return true; | 664 | 394 | } |
EncoderCore<long, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 789 | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 789 | if ( it == inDataV.end() ) { | 617 | 94 | return false; | 618 | 94 | } | 619 | | | 620 | 695 | auto& inData = *it; | 621 | 695 | 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 | 695 | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 695 | if ( encodeRet < 0 ) { | 633 | 34 | return false; | 634 | 34 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 661 | 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 | 661 | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 661 | if ( flushRet < 0 ) { | 654 | 15 | return false; | 655 | 15 | } | 656 | | | 657 | 646 | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 646 | if ( encodeRet == 0 ) { | 660 | 75 | return false; | 661 | 75 | } | 662 | | | 663 | 571 | return true; | 664 | 646 | } |
EncoderCore<float, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 1.12k | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 1.12k | if ( it == inDataV.end() ) { | 617 | 187 | return false; | 618 | 187 | } | 619 | | | 620 | 935 | auto& inData = *it; | 621 | 935 | 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 | 935 | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 935 | if ( encodeRet < 0 ) { | 633 | 12 | return false; | 634 | 12 | } | 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 | 56 | return false; | 655 | 56 | } | 656 | | | 657 | 867 | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 867 | if ( encodeRet == 0 ) { | 660 | 147 | return false; | 661 | 147 | } | 662 | | | 663 | 720 | return true; | 664 | 867 | } |
EncoderCore<double, false>::Run(unsigned char*, unsigned long, bool) Line | Count | Source | 615 | 543 | bool Run(uint8_t* outBuffer, const size_t outBufferSize, const bool mono) override { | 616 | 543 | if ( it == inDataV.end() ) { | 617 | 81 | return false; | 618 | 81 | } | 619 | | | 620 | 462 | auto& inData = *it; | 621 | 462 | 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 | 462 | const int encodeRet = encode(inData, outBuffer, outBufferSize, mono); | 631 | | | 632 | 462 | if ( encodeRet < 0 ) { | 633 | 13 | return false; | 634 | 13 | } | 635 | | | 636 | | /* static_cast is safe because outBufferSize is never anywhere near 2**31 */ | 637 | 449 | 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 | 449 | const int flushRet = flush(outBuffer, outBufferSize); | 652 | | | 653 | 449 | if ( flushRet < 0 ) { | 654 | 8 | return false; | 655 | 8 | } | 656 | | | 657 | 441 | fuzzing::memory::memory_test_msan(outBuffer, flushRet); | 658 | | | 659 | 441 | if ( encodeRet == 0 ) { | 660 | 51 | return false; | 661 | 51 | } | 662 | | | 663 | 390 | return true; | 664 | 441 | } |
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 | 921 | void setBitrateModeVBR_RH(void) { |
680 | 921 | _(lame_set_VBR(flags, vbr_rh);); |
681 | 921 | } EncoderFuzzer<false>::setBitrateModeVBR_RH() Line | Count | Source | 679 | 921 | void setBitrateModeVBR_RH(void) { | 680 | 921 | _(lame_set_VBR(flags, vbr_rh);); | 681 | 921 | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateModeVBR_RH() |
682 | | |
683 | 1.46k | void setBitrateModeVBR_MTRH(void) { |
684 | 1.46k | _(lame_set_VBR(flags, vbr_mtrh);); |
685 | 1.46k | } EncoderFuzzer<false>::setBitrateModeVBR_MTRH() Line | Count | Source | 683 | 1.46k | void setBitrateModeVBR_MTRH(void) { | 684 | 1.46k | _(lame_set_VBR(flags, vbr_mtrh);); | 685 | 1.46k | } |
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.38k | void setVBRQ(void) { |
698 | 2.38k | if ( ds.Get<bool>() ) return; |
699 | | |
700 | 1.28k | const size_t vbrQ = limits::VBRQ.Generate<uint8_t>(ds); |
701 | | |
702 | 1.28k | Debug ? printf("lame_set_VBR_q(flags, %zu);\n", vbrQ) : 0; |
703 | | |
704 | 1.28k | lame_set_VBR_q(flags, vbrQ); |
705 | 1.28k | } EncoderFuzzer<false>::setVBRQ() Line | Count | Source | 697 | 2.38k | void setVBRQ(void) { | 698 | 2.38k | if ( ds.Get<bool>() ) return; | 699 | | | 700 | 1.28k | const size_t vbrQ = limits::VBRQ.Generate<uint8_t>(ds); | 701 | | | 702 | 1.28k | Debug ? printf("lame_set_VBR_q(flags, %zu);\n", vbrQ) : 0; | 703 | | | 704 | 1.28k | lame_set_VBR_q(flags, vbrQ); | 705 | 1.28k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setVBRQ() |
706 | | |
707 | 2.38k | size_t setMinBitrate(void) { |
708 | 2.38k | if ( ds.Get<bool>() ) return 0; |
709 | | |
710 | 725 | const size_t minBitrate = limits::MinBitrate.Generate(ds); |
711 | | |
712 | 725 | Debug ? printf("lame_set_VBR_min_bitrate_kbps(flags, %zu);\n", minBitrate) : 0; |
713 | | |
714 | 725 | lame_set_VBR_min_bitrate_kbps(flags, minBitrate); |
715 | | |
716 | 725 | return minBitrate; |
717 | 2.38k | } EncoderFuzzer<false>::setMinBitrate() Line | Count | Source | 707 | 2.38k | size_t setMinBitrate(void) { | 708 | 2.38k | if ( ds.Get<bool>() ) return 0; | 709 | | | 710 | 725 | const size_t minBitrate = limits::MinBitrate.Generate(ds); | 711 | | | 712 | 725 | Debug ? printf("lame_set_VBR_min_bitrate_kbps(flags, %zu);\n", minBitrate) : 0; | 713 | | | 714 | 725 | lame_set_VBR_min_bitrate_kbps(flags, minBitrate); | 715 | | | 716 | 725 | return minBitrate; | 717 | 2.38k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setMinBitrate() |
718 | | |
719 | 2.36k | void setMaxBitrate(const size_t minBitrate) { |
720 | 2.36k | if ( ds.Get<bool>() ) return; |
721 | | |
722 | 891 | size_t maxBitrate = limits::MaxBitrate.Generate(ds); |
723 | 891 | 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 | 63 | maxBitrate = minBitrate; |
728 | 63 | } |
729 | | |
730 | 891 | Debug ? printf("lame_set_VBR_max_bitrate_kbps(flags, %zu);\n", maxBitrate) : 0; |
731 | | |
732 | 891 | lame_set_VBR_max_bitrate_kbps(flags, maxBitrate); |
733 | 891 | } EncoderFuzzer<false>::setMaxBitrate(unsigned long) Line | Count | Source | 719 | 2.36k | void setMaxBitrate(const size_t minBitrate) { | 720 | 2.36k | if ( ds.Get<bool>() ) return; | 721 | | | 722 | 891 | size_t maxBitrate = limits::MaxBitrate.Generate(ds); | 723 | 891 | 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 | 63 | maxBitrate = minBitrate; | 728 | 63 | } | 729 | | | 730 | 891 | Debug ? printf("lame_set_VBR_max_bitrate_kbps(flags, %zu);\n", maxBitrate) : 0; | 731 | | | 732 | 891 | lame_set_VBR_max_bitrate_kbps(flags, maxBitrate); | 733 | 891 | } |
Unexecuted instantiation: EncoderFuzzer<true>::setMaxBitrate(unsigned long) |
734 | | |
735 | 2.38k | void setBitrateModeVBR(void) { |
736 | 2.38k | const uint8_t whichVbr = ds.Get<uint8_t>() % 3; |
737 | | |
738 | 2.38k | if ( whichVbr == 0 ) { |
739 | 921 | setBitrateModeVBR_RH(); |
740 | 1.46k | } else if ( whichVbr == 1 ) { |
741 | 1.46k | setBitrateModeVBR_MTRH(); |
742 | 1.46k | } else if ( whichVbr == 2 ) { |
743 | 1 | /* Disabled due to crash */ throw std::runtime_error(""); |
744 | 0 | setBitrateModeVBR_ABR(); |
745 | 0 | } |
746 | | |
747 | 2.38k | setVBRQ(); |
748 | | |
749 | 2.38k | size_t minBitrate = setMinBitrate(); |
750 | 2.38k | setMaxBitrate(minBitrate); |
751 | 2.38k | } EncoderFuzzer<false>::setBitrateModeVBR() Line | Count | Source | 735 | 2.38k | void setBitrateModeVBR(void) { | 736 | 2.38k | const uint8_t whichVbr = ds.Get<uint8_t>() % 3; | 737 | | | 738 | 2.38k | if ( whichVbr == 0 ) { | 739 | 921 | setBitrateModeVBR_RH(); | 740 | 1.46k | } else if ( whichVbr == 1 ) { | 741 | 1.46k | setBitrateModeVBR_MTRH(); | 742 | 1.46k | } else if ( whichVbr == 2 ) { | 743 | 1 | /* Disabled due to crash */ throw std::runtime_error(""); | 744 | 0 | setBitrateModeVBR_ABR(); | 745 | 0 | } | 746 | | | 747 | 2.38k | setVBRQ(); | 748 | | | 749 | 2.38k | size_t minBitrate = setMinBitrate(); | 750 | 2.38k | setMaxBitrate(minBitrate); | 751 | 2.38k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateModeVBR() |
752 | | |
753 | 4.39k | void setBitrateModeCBR(void) { |
754 | 4.39k | _(lame_set_VBR(flags, vbr_off);); |
755 | | |
756 | 4.39k | const size_t bitrate = limits::CBRBitrate.Generate(ds); |
757 | | |
758 | 4.39k | Debug ? printf("lame_set_brate(flags, %zu);\n", bitrate) : 0; |
759 | | |
760 | 4.39k | lame_set_brate(flags, bitrate); |
761 | 4.39k | } EncoderFuzzer<false>::setBitrateModeCBR() Line | Count | Source | 753 | 4.39k | void setBitrateModeCBR(void) { | 754 | 4.39k | _(lame_set_VBR(flags, vbr_off);); | 755 | | | 756 | 4.39k | const size_t bitrate = limits::CBRBitrate.Generate(ds); | 757 | | | 758 | 4.39k | Debug ? printf("lame_set_brate(flags, %zu);\n", bitrate) : 0; | 759 | | | 760 | 4.39k | lame_set_brate(flags, bitrate); | 761 | 4.39k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateModeCBR() |
762 | | |
763 | 6.79k | void setBitrateMode(void) { |
764 | 6.79k | ds.Get<bool>() ? setBitrateModeVBR() : setBitrateModeCBR(); |
765 | 6.79k | } EncoderFuzzer<false>::setBitrateMode() Line | Count | Source | 763 | 6.79k | void setBitrateMode(void) { | 764 | 6.79k | ds.Get<bool>() ? setBitrateModeVBR() : setBitrateModeCBR(); | 765 | 6.79k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setBitrateMode() |
766 | | |
767 | 6.80k | void setInputChannels(void) { |
768 | 6.80k | const int numChannels = ds.Get<bool>() ? 1 : 2; |
769 | | |
770 | 6.80k | Debug ? printf("lame_set_num_channels(flags, %d);\n", numChannels) : 0; |
771 | | |
772 | 6.80k | lame_set_num_channels(flags, numChannels); |
773 | | |
774 | 6.80k | if ( numChannels == 1 ) { |
775 | 1.47k | mono = true; |
776 | 1.47k | } |
777 | 6.80k | } EncoderFuzzer<false>::setInputChannels() Line | Count | Source | 767 | 6.80k | void setInputChannels(void) { | 768 | 6.80k | const int numChannels = ds.Get<bool>() ? 1 : 2; | 769 | | | 770 | 6.80k | Debug ? printf("lame_set_num_channels(flags, %d);\n", numChannels) : 0; | 771 | | | 772 | 6.80k | lame_set_num_channels(flags, numChannels); | 773 | | | 774 | 6.80k | if ( numChannels == 1 ) { | 775 | 1.47k | mono = true; | 776 | 1.47k | } | 777 | 6.80k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setInputChannels() |
778 | | |
779 | 6.70k | void setChannelMode(void) { |
780 | 6.70k | const uint8_t whichChannelMode = ds.Get<uint8_t>() % 3; |
781 | | |
782 | 6.70k | if ( whichChannelMode == 0 ) { |
783 | 2.97k | _(lame_set_mode(flags, STEREO);); |
784 | 3.72k | } else if ( whichChannelMode == 1 ) { |
785 | 2.53k | _(lame_set_mode(flags, JOINT_STEREO);); |
786 | 2.53k | } else if ( whichChannelMode == 2 ) { |
787 | 1.06k | _(lame_set_mode(flags, MONO);); |
788 | 1.06k | } |
789 | 6.70k | } EncoderFuzzer<false>::setChannelMode() Line | Count | Source | 779 | 6.70k | void setChannelMode(void) { | 780 | 6.70k | const uint8_t whichChannelMode = ds.Get<uint8_t>() % 3; | 781 | | | 782 | 6.70k | if ( whichChannelMode == 0 ) { | 783 | 2.97k | _(lame_set_mode(flags, STEREO);); | 784 | 3.72k | } else if ( whichChannelMode == 1 ) { | 785 | 2.53k | _(lame_set_mode(flags, JOINT_STEREO);); | 786 | 2.53k | } else if ( whichChannelMode == 2 ) { | 787 | 1.06k | _(lame_set_mode(flags, MONO);); | 788 | 1.06k | } | 789 | 6.70k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setChannelMode() |
790 | | |
791 | 6.57k | void setQuality(void) { |
792 | 6.57k | const size_t quality = limits::Quality.Generate<uint8_t>(ds); |
793 | | |
794 | 6.57k | Debug ? printf("lame_set_quality(flags, %zu);\n", quality) : 0; |
795 | | |
796 | 6.57k | lame_set_quality(flags, quality); |
797 | 6.57k | } EncoderFuzzer<false>::setQuality() Line | Count | Source | 791 | 6.57k | void setQuality(void) { | 792 | 6.57k | const size_t quality = limits::Quality.Generate<uint8_t>(ds); | 793 | | | 794 | 6.57k | Debug ? printf("lame_set_quality(flags, %zu);\n", quality) : 0; | 795 | | | 796 | 6.57k | lame_set_quality(flags, quality); | 797 | 6.57k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setQuality() |
798 | | |
799 | 6.57k | void setOutSamplerate(void) { |
800 | 6.57k | const size_t outSamplerate = limits::OutSamplerate.Generate(ds); |
801 | | |
802 | 6.57k | Debug ? printf("lame_set_out_samplerate(flags, %zu);\n", outSamplerate) : 0; |
803 | | |
804 | 6.57k | lame_set_out_samplerate(flags, outSamplerate); |
805 | 6.57k | } EncoderFuzzer<false>::setOutSamplerate() Line | Count | Source | 799 | 6.57k | void setOutSamplerate(void) { | 800 | 6.57k | const size_t outSamplerate = limits::OutSamplerate.Generate(ds); | 801 | | | 802 | 6.57k | Debug ? printf("lame_set_out_samplerate(flags, %zu);\n", outSamplerate) : 0; | 803 | | | 804 | 6.57k | lame_set_out_samplerate(flags, outSamplerate); | 805 | 6.57k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setOutSamplerate() |
806 | | |
807 | 6.56k | void setID3(void) { |
808 | | /* Optionally set various ID3 fields */ |
809 | | |
810 | 6.56k | if ( ds.Get<bool>() ) { |
811 | 1.31k | id3tag_init(flags); |
812 | | |
813 | 1.31k | if ( ds.Get<bool>() ) { |
814 | 148 | const std::string title = ds.Get<std::string>(); |
815 | | |
816 | 148 | Debug ? printf("id3tag_set_title(flags, %s);\n", title.c_str()) : 0; |
817 | | |
818 | 148 | id3tag_set_title(flags, title.c_str()); |
819 | 148 | } |
820 | | |
821 | 1.31k | if ( ds.Get<bool>() ) { |
822 | 158 | const std::string artist = ds.Get<std::string>(); |
823 | | |
824 | 158 | Debug ? printf("id3tag_set_artist(flags, %s);\n", artist.c_str()) : 0; |
825 | | |
826 | 158 | id3tag_set_artist(flags, artist.c_str()); |
827 | 158 | } |
828 | | |
829 | 1.31k | if ( ds.Get<bool>() ) { |
830 | 144 | const std::string album = ds.Get<std::string>(); |
831 | | |
832 | 144 | Debug ? printf("id3tag_set_album(flags, %s);\n", album.c_str()) : 0; |
833 | | |
834 | 144 | id3tag_set_album(flags, album.c_str()); |
835 | 144 | } |
836 | | |
837 | 1.31k | if ( ds.Get<bool>() ) { |
838 | 171 | const std::string year = ds.Get<std::string>(); |
839 | | |
840 | 171 | Debug ? printf("id3tag_set_year(flags, %s);\n", year.c_str()) : 0; |
841 | | |
842 | 171 | id3tag_set_year(flags, year.c_str()); |
843 | 171 | } |
844 | | |
845 | 1.31k | if ( ds.Get<bool>() ) { |
846 | 140 | const std::string comment = ds.Get<std::string>(); |
847 | | |
848 | 140 | Debug ? printf("id3tag_set_comment(flags, %s);\n", comment.c_str()) : 0; |
849 | | |
850 | 140 | id3tag_set_comment(flags, comment.c_str()); |
851 | 140 | } |
852 | | |
853 | 1.31k | if ( ds.Get<bool>() ) { |
854 | 139 | const std::string track = ds.Get<std::string>(); |
855 | | |
856 | 139 | Debug ? printf("id3tag_set_track(flags, %s);\n", track.c_str()) : 0; |
857 | | |
858 | 139 | id3tag_set_track(flags, track.c_str()); |
859 | 139 | } |
860 | | |
861 | 1.31k | if ( ds.Get<bool>() ) { |
862 | 250 | const std::string genre = ds.Get<std::string>(); |
863 | | |
864 | 250 | Debug ? printf("id3tag_set_genre(flags, %s);\n", genre.c_str()) : 0; |
865 | | |
866 | 250 | id3tag_set_genre(flags, genre.c_str()); |
867 | 250 | } |
868 | | |
869 | 1.31k | if ( ds.Get<bool>() ) { |
870 | 439 | const std::string fieldvalue = ds.Get<std::string>(); |
871 | | |
872 | 439 | Debug ? printf("id3tag_set_fieldvalue(flags, %s);\n", fieldvalue.c_str()) : 0; |
873 | | |
874 | 439 | id3tag_set_fieldvalue(flags, fieldvalue.c_str()); |
875 | 439 | } |
876 | | |
877 | 1.31k | if ( ds.Get<bool>() ) { |
878 | 159 | const auto albumArt = ds.GetData(0); |
879 | | |
880 | 159 | Debug ? printf("{\n") : 0; |
881 | | |
882 | 159 | Debug ? printf("\t%s\n", debug_define_size_t("albumArtSize", albumArt.size()).c_str()) : 0; |
883 | 159 | Debug ? printf("%s\n", DebugDefineArray<unsigned char>::Str("albumart", "char", albumArt.data(), albumArt.size(), true).c_str()) : 0; |
884 | | |
885 | 159 | Debug ? |
886 | 0 | printf("\tid3tag_set_albumart(flags, albumArt, albumArtSize);\n") |
887 | 159 | : 0; |
888 | | |
889 | 159 | Debug ? printf("}\n") : 0; |
890 | | |
891 | 159 | id3tag_set_albumart(flags, (const char*)albumArt.data(), albumArt.size()); |
892 | 159 | } |
893 | 1.31k | } |
894 | 6.56k | } EncoderFuzzer<false>::setID3() Line | Count | Source | 807 | 6.56k | void setID3(void) { | 808 | | /* Optionally set various ID3 fields */ | 809 | | | 810 | 6.56k | if ( ds.Get<bool>() ) { | 811 | 1.31k | id3tag_init(flags); | 812 | | | 813 | 1.31k | if ( ds.Get<bool>() ) { | 814 | 148 | const std::string title = ds.Get<std::string>(); | 815 | | | 816 | 148 | Debug ? printf("id3tag_set_title(flags, %s);\n", title.c_str()) : 0; | 817 | | | 818 | 148 | id3tag_set_title(flags, title.c_str()); | 819 | 148 | } | 820 | | | 821 | 1.31k | if ( ds.Get<bool>() ) { | 822 | 158 | const std::string artist = ds.Get<std::string>(); | 823 | | | 824 | 158 | Debug ? printf("id3tag_set_artist(flags, %s);\n", artist.c_str()) : 0; | 825 | | | 826 | 158 | id3tag_set_artist(flags, artist.c_str()); | 827 | 158 | } | 828 | | | 829 | 1.31k | if ( ds.Get<bool>() ) { | 830 | 144 | const std::string album = ds.Get<std::string>(); | 831 | | | 832 | 144 | Debug ? printf("id3tag_set_album(flags, %s);\n", album.c_str()) : 0; | 833 | | | 834 | 144 | id3tag_set_album(flags, album.c_str()); | 835 | 144 | } | 836 | | | 837 | 1.31k | if ( ds.Get<bool>() ) { | 838 | 171 | const std::string year = ds.Get<std::string>(); | 839 | | | 840 | 171 | Debug ? printf("id3tag_set_year(flags, %s);\n", year.c_str()) : 0; | 841 | | | 842 | 171 | id3tag_set_year(flags, year.c_str()); | 843 | 171 | } | 844 | | | 845 | 1.31k | if ( ds.Get<bool>() ) { | 846 | 140 | const std::string comment = ds.Get<std::string>(); | 847 | | | 848 | 140 | Debug ? printf("id3tag_set_comment(flags, %s);\n", comment.c_str()) : 0; | 849 | | | 850 | 140 | id3tag_set_comment(flags, comment.c_str()); | 851 | 140 | } | 852 | | | 853 | 1.31k | if ( ds.Get<bool>() ) { | 854 | 139 | const std::string track = ds.Get<std::string>(); | 855 | | | 856 | 139 | Debug ? printf("id3tag_set_track(flags, %s);\n", track.c_str()) : 0; | 857 | | | 858 | 139 | id3tag_set_track(flags, track.c_str()); | 859 | 139 | } | 860 | | | 861 | 1.31k | if ( ds.Get<bool>() ) { | 862 | 250 | const std::string genre = ds.Get<std::string>(); | 863 | | | 864 | 250 | Debug ? printf("id3tag_set_genre(flags, %s);\n", genre.c_str()) : 0; | 865 | | | 866 | 250 | id3tag_set_genre(flags, genre.c_str()); | 867 | 250 | } | 868 | | | 869 | 1.31k | if ( ds.Get<bool>() ) { | 870 | 439 | const std::string fieldvalue = ds.Get<std::string>(); | 871 | | | 872 | 439 | Debug ? printf("id3tag_set_fieldvalue(flags, %s);\n", fieldvalue.c_str()) : 0; | 873 | | | 874 | 439 | id3tag_set_fieldvalue(flags, fieldvalue.c_str()); | 875 | 439 | } | 876 | | | 877 | 1.31k | if ( ds.Get<bool>() ) { | 878 | 159 | const auto albumArt = ds.GetData(0); | 879 | | | 880 | 159 | Debug ? printf("{\n") : 0; | 881 | | | 882 | 159 | Debug ? printf("\t%s\n", debug_define_size_t("albumArtSize", albumArt.size()).c_str()) : 0; | 883 | 159 | Debug ? printf("%s\n", DebugDefineArray<unsigned char>::Str("albumart", "char", albumArt.data(), albumArt.size(), true).c_str()) : 0; | 884 | | | 885 | 159 | Debug ? | 886 | 0 | printf("\tid3tag_set_albumart(flags, albumArt, albumArtSize);\n") | 887 | 159 | : 0; | 888 | | | 889 | 159 | Debug ? printf("}\n") : 0; | 890 | | | 891 | 159 | id3tag_set_albumart(flags, (const char*)albumArt.data(), albumArt.size()); | 892 | 159 | } | 893 | 1.31k | } | 894 | 6.56k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setID3() |
895 | | |
896 | 5.55k | void setFilters(void) { |
897 | 5.55k | if ( ds.Get<bool>() ) { |
898 | 776 | const size_t lowpassFreq = limits::LowpassFrequency.Generate(ds); |
899 | | |
900 | 776 | Debug ? printf("lame_set_lowpassfreq(flags, %zu);\n", lowpassFreq) : 0; |
901 | | |
902 | 776 | lame_set_lowpassfreq(flags, lowpassFreq); |
903 | 776 | } |
904 | | |
905 | 5.55k | if ( ds.Get<bool>() ) { |
906 | 496 | const size_t lowpassWidth = limits::LowpassWidth.Generate(ds); |
907 | | |
908 | 496 | Debug ? printf("lame_set_lowpasswidth(flags, %zu);\n", lowpassWidth) : 0; |
909 | | |
910 | 496 | lame_set_lowpasswidth(flags, lowpassWidth); |
911 | 496 | } |
912 | | |
913 | 5.55k | if ( ds.Get<bool>() ) { |
914 | 613 | const size_t highpassFreq = limits::HighpassFrequency.Generate(ds); |
915 | | |
916 | 613 | Debug ? printf("lame_set_highpassfreq(flags, %zu);\n", highpassFreq) : 0; |
917 | | |
918 | 613 | lame_set_highpassfreq(flags, highpassFreq); |
919 | 613 | } |
920 | | |
921 | 5.55k | if ( ds.Get<bool>() ) { |
922 | 443 | const size_t highpassWidth = limits::HighpassWidth.Generate(ds); |
923 | | |
924 | 443 | Debug ? printf("lame_set_highpasswidth(flags, %zu);\n", highpassWidth) : 0; |
925 | | |
926 | 443 | lame_set_highpasswidth(flags, highpassWidth); |
927 | 443 | } |
928 | 5.55k | } EncoderFuzzer<false>::setFilters() Line | Count | Source | 896 | 5.55k | void setFilters(void) { | 897 | 5.55k | if ( ds.Get<bool>() ) { | 898 | 776 | const size_t lowpassFreq = limits::LowpassFrequency.Generate(ds); | 899 | | | 900 | 776 | Debug ? printf("lame_set_lowpassfreq(flags, %zu);\n", lowpassFreq) : 0; | 901 | | | 902 | 776 | lame_set_lowpassfreq(flags, lowpassFreq); | 903 | 776 | } | 904 | | | 905 | 5.55k | if ( ds.Get<bool>() ) { | 906 | 496 | const size_t lowpassWidth = limits::LowpassWidth.Generate(ds); | 907 | | | 908 | 496 | Debug ? printf("lame_set_lowpasswidth(flags, %zu);\n", lowpassWidth) : 0; | 909 | | | 910 | 496 | lame_set_lowpasswidth(flags, lowpassWidth); | 911 | 496 | } | 912 | | | 913 | 5.55k | if ( ds.Get<bool>() ) { | 914 | 613 | const size_t highpassFreq = limits::HighpassFrequency.Generate(ds); | 915 | | | 916 | 613 | Debug ? printf("lame_set_highpassfreq(flags, %zu);\n", highpassFreq) : 0; | 917 | | | 918 | 613 | lame_set_highpassfreq(flags, highpassFreq); | 919 | 613 | } | 920 | | | 921 | 5.55k | if ( ds.Get<bool>() ) { | 922 | 443 | const size_t highpassWidth = limits::HighpassWidth.Generate(ds); | 923 | | | 924 | 443 | Debug ? printf("lame_set_highpasswidth(flags, %zu);\n", highpassWidth) : 0; | 925 | | | 926 | 443 | lame_set_highpasswidth(flags, highpassWidth); | 927 | 443 | } | 928 | 5.55k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setFilters() |
929 | | |
930 | | |
931 | 5.25k | void setMisc(void) { |
932 | 5.25k | if ( ds.Get<bool>() ) { |
933 | 1.69k | _(lame_set_strict_ISO(flags, MDB_STRICT_ISO);); |
934 | 1.69k | } |
935 | | |
936 | 5.25k | if ( ds.Get<bool>() ) { |
937 | 1.73k | _(lame_set_bWriteVbrTag(flags, 1);); |
938 | 1.73k | } |
939 | | |
940 | 5.25k | if ( ds.Get<bool>() ) { |
941 | 1.79k | _(lame_set_copyright(flags, 1);); |
942 | 1.79k | } |
943 | | |
944 | 5.25k | if ( ds.Get<bool>() ) { |
945 | 1.79k | _(lame_set_original(flags, 1);); |
946 | 1.79k | } |
947 | | |
948 | 5.25k | if ( ds.Get<bool>() ) { |
949 | 2.10k | _(lame_set_error_protection(flags, 1);); |
950 | 2.10k | } |
951 | | |
952 | 5.25k | if ( ds.Get<bool>() ) { |
953 | 1.92k | _(lame_set_extension(flags, 1);); |
954 | 1.92k | } |
955 | | |
956 | 5.25k | if ( ds.Get<bool>() ) { |
957 | | /* Crashes */ |
958 | | /* _(lame_set_free_format(flags, 1);); */ |
959 | 2.07k | } |
960 | 5.25k | } EncoderFuzzer<false>::setMisc() Line | Count | Source | 931 | 5.25k | void setMisc(void) { | 932 | 5.25k | if ( ds.Get<bool>() ) { | 933 | 1.69k | _(lame_set_strict_ISO(flags, MDB_STRICT_ISO);); | 934 | 1.69k | } | 935 | | | 936 | 5.25k | if ( ds.Get<bool>() ) { | 937 | 1.73k | _(lame_set_bWriteVbrTag(flags, 1);); | 938 | 1.73k | } | 939 | | | 940 | 5.25k | if ( ds.Get<bool>() ) { | 941 | 1.79k | _(lame_set_copyright(flags, 1);); | 942 | 1.79k | } | 943 | | | 944 | 5.25k | if ( ds.Get<bool>() ) { | 945 | 1.79k | _(lame_set_original(flags, 1);); | 946 | 1.79k | } | 947 | | | 948 | 5.25k | if ( ds.Get<bool>() ) { | 949 | 2.10k | _(lame_set_error_protection(flags, 1);); | 950 | 2.10k | } | 951 | | | 952 | 5.25k | if ( ds.Get<bool>() ) { | 953 | 1.92k | _(lame_set_extension(flags, 1);); | 954 | 1.92k | } | 955 | | | 956 | 5.25k | if ( ds.Get<bool>() ) { | 957 | | /* Crashes */ | 958 | | /* _(lame_set_free_format(flags, 1);); */ | 959 | 2.07k | } | 960 | 5.25k | } |
Unexecuted instantiation: EncoderFuzzer<true>::setMisc() |
961 | | |
962 | | public: |
963 | | EncoderFuzzer(Datasource& ds) : |
964 | 7.31k | ds(ds), outBufferSize(limits::OutBufferSize.Generate(ds)) |
965 | 7.31k | { |
966 | 7.31k | Debug ? |
967 | 0 | printf("lame_global_flags* flags = lame_init();\n") |
968 | 7.31k | : 0; |
969 | 7.31k | flags = lame_init(); |
970 | | |
971 | 7.31k | Debug ? |
972 | 0 | printf("const size_t outBufferSize = %zu;\n", outBufferSize) |
973 | 7.31k | : 0; |
974 | 7.31k | Debug ? |
975 | 0 | printf("unsigned char outBuffer[outBufferSize];\n") |
976 | 7.31k | : 0; |
977 | | |
978 | 7.31k | outBuffer = (uint8_t*)malloc(outBufferSize + 1024 /* Add 1024 due to crash */); |
979 | 7.31k | } EncoderFuzzer<false>::EncoderFuzzer(fuzzing::datasource::Datasource&) Line | Count | Source | 964 | 7.31k | ds(ds), outBufferSize(limits::OutBufferSize.Generate(ds)) | 965 | 7.31k | { | 966 | 7.31k | Debug ? | 967 | 0 | printf("lame_global_flags* flags = lame_init();\n") | 968 | 7.31k | : 0; | 969 | 7.31k | flags = lame_init(); | 970 | | | 971 | 7.31k | Debug ? | 972 | 0 | printf("const size_t outBufferSize = %zu;\n", outBufferSize) | 973 | 7.31k | : 0; | 974 | 7.31k | Debug ? | 975 | 0 | printf("unsigned char outBuffer[outBufferSize];\n") | 976 | 7.31k | : 0; | 977 | | | 978 | 7.31k | outBuffer = (uint8_t*)malloc(outBufferSize + 1024 /* Add 1024 due to crash */); | 979 | 7.31k | } |
Unexecuted instantiation: EncoderFuzzer<true>::EncoderFuzzer(fuzzing::datasource::Datasource&) |
980 | | |
981 | 7.25k | void Run(void) { |
982 | | |
983 | 7.25k | std::unique_ptr<EncoderCoreBase> encoder = nullptr; |
984 | | |
985 | 7.25k | const uint8_t whichSampleSize = ds.Get<uint8_t>() % 5; |
986 | | |
987 | 7.25k | if ( whichSampleSize == 0 ) { |
988 | 4.22k | encoder = std::make_unique<EncoderCore<short int, Debug>>(ds, flags); |
989 | 4.22k | } else if ( whichSampleSize == 1 ) { |
990 | 585 | encoder = std::make_unique<EncoderCore<int, Debug>>(ds, flags); |
991 | 2.44k | } else if ( whichSampleSize == 2 ) { |
992 | 917 | encoder = std::make_unique<EncoderCore<long, Debug>>(ds, flags); |
993 | 1.53k | } else if ( whichSampleSize == 3 ) { |
994 | 837 | encoder = std::make_unique<EncoderCore<float, Debug>>(ds, flags); |
995 | 837 | } else if ( whichSampleSize == 4 ) { |
996 | 619 | encoder = std::make_unique<EncoderCore<double, Debug>>(ds, flags); |
997 | 619 | } |
998 | | |
999 | 7.25k | setInputChannels(); |
1000 | 7.25k | setBitrateMode(); |
1001 | 7.25k | setChannelMode(); |
1002 | 7.25k | setQuality(); |
1003 | 7.25k | setOutSamplerate(); |
1004 | 7.25k | setID3(); |
1005 | 7.25k | setFilters(); |
1006 | 7.25k | setMisc(); |
1007 | | |
1008 | 7.25k | Debug ? printf("lame_init_params(flags);\n") : 0; |
1009 | | |
1010 | 7.25k | if ( lame_init_params(flags) == -1 ) { |
1011 | 0 | abort(); |
1012 | 0 | } |
1013 | | |
1014 | 13.7k | while ( encoder->Run(outBuffer, outBufferSize, mono) ) { } |
1015 | 7.25k | } EncoderFuzzer<false>::Run() Line | Count | Source | 981 | 7.25k | void Run(void) { | 982 | | | 983 | 7.25k | std::unique_ptr<EncoderCoreBase> encoder = nullptr; | 984 | | | 985 | 7.25k | const uint8_t whichSampleSize = ds.Get<uint8_t>() % 5; | 986 | | | 987 | 7.25k | if ( whichSampleSize == 0 ) { | 988 | 4.22k | encoder = std::make_unique<EncoderCore<short int, Debug>>(ds, flags); | 989 | 4.22k | } else if ( whichSampleSize == 1 ) { | 990 | 585 | encoder = std::make_unique<EncoderCore<int, Debug>>(ds, flags); | 991 | 2.44k | } else if ( whichSampleSize == 2 ) { | 992 | 917 | encoder = std::make_unique<EncoderCore<long, Debug>>(ds, flags); | 993 | 1.53k | } else if ( whichSampleSize == 3 ) { | 994 | 837 | encoder = std::make_unique<EncoderCore<float, Debug>>(ds, flags); | 995 | 837 | } else if ( whichSampleSize == 4 ) { | 996 | 619 | encoder = std::make_unique<EncoderCore<double, Debug>>(ds, flags); | 997 | 619 | } | 998 | | | 999 | 7.25k | setInputChannels(); | 1000 | 7.25k | setBitrateMode(); | 1001 | 7.25k | setChannelMode(); | 1002 | 7.25k | setQuality(); | 1003 | 7.25k | setOutSamplerate(); | 1004 | 7.25k | setID3(); | 1005 | 7.25k | setFilters(); | 1006 | 7.25k | setMisc(); | 1007 | | | 1008 | 7.25k | Debug ? printf("lame_init_params(flags);\n") : 0; | 1009 | | | 1010 | 7.25k | if ( lame_init_params(flags) == -1 ) { | 1011 | 0 | abort(); | 1012 | 0 | } | 1013 | | | 1014 | 13.7k | while ( encoder->Run(outBuffer, outBufferSize, mono) ) { } | 1015 | 7.25k | } |
Unexecuted instantiation: EncoderFuzzer<true>::Run() |
1016 | | |
1017 | 7.25k | ~EncoderFuzzer() { |
1018 | 7.25k | lame_close(flags); |
1019 | 7.25k | free(outBuffer); |
1020 | 7.25k | outBuffer = nullptr; |
1021 | 7.25k | } EncoderFuzzer<false>::~EncoderFuzzer() Line | Count | Source | 1017 | 7.25k | ~EncoderFuzzer() { | 1018 | 7.25k | lame_close(flags); | 1019 | 7.25k | free(outBuffer); | 1020 | 7.25k | outBuffer = nullptr; | 1021 | 7.25k | } |
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.31k | { |
1040 | 7.31k | Datasource ds(data, size); |
1041 | | |
1042 | 7.31k | try { |
1043 | 7.31k | if ( debug == false ) { |
1044 | 7.31k | EncoderFuzzer<false> encoder(ds); |
1045 | 7.31k | encoder.Run(); |
1046 | 7.31k | } else { |
1047 | 0 | EncoderFuzzer<true> encoder(ds); |
1048 | 0 | encoder.Run(); |
1049 | 0 | } |
1050 | 7.31k | } catch ( ... ) { } |
1051 | | |
1052 | 7.31k | return 0; |
1053 | 7.31k | } |