2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// Copyright (C) 2022 lainon <GermanAizek@yandex.ru>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2018-04-28 23:02:05 +00:00
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "utility.hpp"
|
2022-08-28 12:28:37 +00:00
|
|
|
#include "common.hpp"
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "plugin.hpp"
|
|
|
|
|
|
|
|
#include "warning-disable.hpp"
|
2019-05-28 17:54:23 +00:00
|
|
|
#include <sstream>
|
2019-09-04 01:03:41 +00:00
|
|
|
#include <stdexcept>
|
2019-09-05 16:42:28 +00:00
|
|
|
#include <unordered_map>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-enable.hpp"
|
2019-05-28 17:54:23 +00:00
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
obs_property_t* streamfx::util::obs_properties_add_tristate(obs_properties_t* props, const char* name, const char* desc)
|
2020-01-13 21:40:15 +00:00
|
|
|
{
|
|
|
|
obs_property_t* p = obs_properties_add_list(props, name, desc, OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
|
|
|
obs_property_list_add_int(p, D_TRANSLATE(S_STATE_DEFAULT), -1);
|
|
|
|
obs_property_list_add_int(p, D_TRANSLATE(S_STATE_DISABLED), 0);
|
|
|
|
obs_property_list_add_int(p, D_TRANSLATE(S_STATE_ENABLED), 1);
|
|
|
|
return p;
|
|
|
|
}
|
2020-01-14 00:11:08 +00:00
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void* streamfx::util::vec2a::operator new(std::size_t count)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
return streamfx::util::malloc_aligned(16, count);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void* streamfx::util::vec2a::operator new[](std::size_t count)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
return streamfx::util::malloc_aligned(16, count);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void streamfx::util::vec2a::operator delete(void* p)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::free_aligned(p);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void streamfx::util::vec2a::operator delete[](void* p)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::free_aligned(p);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void* streamfx::util::vec3a::operator new(std::size_t count)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
return streamfx::util::malloc_aligned(16, count);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void* streamfx::util::vec3a::operator new[](std::size_t count)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
return streamfx::util::malloc_aligned(16, count);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void streamfx::util::vec3a::operator delete(void* p)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::free_aligned(p);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void streamfx::util::vec3a::operator delete[](void* p)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::free_aligned(p);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void* streamfx::util::vec4a::operator new(std::size_t count)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
return streamfx::util::malloc_aligned(16, count);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void* streamfx::util::vec4a::operator new[](std::size_t count)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
return streamfx::util::malloc_aligned(16, count);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void streamfx::util::vec4a::operator delete(void* p)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::free_aligned(p);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void streamfx::util::vec4a::operator delete[](void* p)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::free_aligned(p);
|
2020-01-14 00:11:08 +00:00
|
|
|
}
|
|
|
|
|
2022-07-21 11:09:10 +00:00
|
|
|
std::pair<int64_t, int64_t> streamfx::util::size_from_string(std::string_view text, bool allowSquare)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
|
|
|
int64_t width, height;
|
|
|
|
|
2022-07-21 11:09:10 +00:00
|
|
|
const auto* begin = text.data();
|
|
|
|
const auto* end = text.data() + text.size() + 1;
|
2020-01-14 00:11:08 +00:00
|
|
|
char* here = const_cast<char*>(end);
|
|
|
|
|
|
|
|
long long res = strtoll(begin, &here, 0);
|
|
|
|
if (errno == ERANGE) {
|
|
|
|
return {0, 0};
|
|
|
|
}
|
|
|
|
width = res;
|
|
|
|
|
|
|
|
while (here != end) {
|
|
|
|
if (isdigit(*here) || (*here == '-') || (*here == '+')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
here++;
|
|
|
|
}
|
|
|
|
if (here == end) {
|
|
|
|
// Are we allowed to return a square?
|
|
|
|
if (allowSquare) {
|
|
|
|
// Yes: Return width,width.
|
|
|
|
return {width, width};
|
|
|
|
} else {
|
|
|
|
// No: Return width,0.
|
|
|
|
return {width, 0};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res = strtoll(here, nullptr, 0);
|
|
|
|
if (errno == ERANGE) {
|
|
|
|
return {width, 0};
|
|
|
|
}
|
|
|
|
height = res;
|
|
|
|
|
|
|
|
return {width, height};
|
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void* streamfx::util::malloc_aligned(std::size_t align, std::size_t size)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
|
|
|
#ifdef USE_MSC_ALLOC
|
|
|
|
return _aligned_malloc(size, align);
|
|
|
|
#elif defined(USE_STD_ALLOC)
|
|
|
|
return aligned_alloc(size, align);
|
|
|
|
#else
|
|
|
|
// Ensure that we have space for the pointer and the data.
|
2020-04-08 21:38:42 +00:00
|
|
|
std::size_t asize = aligned_offset(align, size + (sizeof(void*) * 2));
|
2020-01-14 00:11:08 +00:00
|
|
|
|
|
|
|
// Allocate memory and store integer representation of pointer.
|
|
|
|
void* ptr = malloc(asize);
|
|
|
|
|
|
|
|
// Calculate actual aligned position
|
|
|
|
intptr_t ptr_off = static_cast<intptr_t>(aligned_offset(align, reinterpret_cast<size_t>(ptr) + sizeof(void*)));
|
|
|
|
|
|
|
|
// Store actual pointer at ptr_off - sizeof(void*).
|
|
|
|
*reinterpret_cast<intptr_t*>(ptr_off - sizeof(void*)) = reinterpret_cast<intptr_t>(ptr);
|
|
|
|
|
|
|
|
// Return aligned pointer
|
|
|
|
return reinterpret_cast<void*>(ptr_off);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void streamfx::util::free_aligned(void* mem)
|
2020-01-14 00:11:08 +00:00
|
|
|
{
|
|
|
|
#ifdef USE_MSC_ALLOC
|
|
|
|
_aligned_free(mem);
|
|
|
|
#elif defined(USE_STD_ALLOC_FREE)
|
|
|
|
free(mem);
|
|
|
|
#else
|
2020-07-27 00:17:34 +00:00
|
|
|
if (mem == nullptr)
|
|
|
|
return;
|
2020-01-14 00:11:08 +00:00
|
|
|
void* ptr = reinterpret_cast<void*>(*reinterpret_cast<intptr_t*>(static_cast<char*>(mem) - sizeof(void*)));
|
|
|
|
free(ptr);
|
|
|
|
#endif
|
|
|
|
}
|