-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVideoCommon.cpp
66 lines (54 loc) · 1.47 KB
/
VideoCommon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "VideoCommon.h"
#include <cstdarg>
#include <cassert>
#include <array>
using namespace video;
namespace
{
std::function<void(const std::string&)> VideoLoggingFunction;
}
void video::setLoggingFunction(const std::function<void(const std::string&)>& callback)
{
VideoLoggingFunction = callback;
}
void video::logging(const char* format, ...)
{
if (!VideoLoggingFunction)
return;
constexpr auto BUFFER_LENGTH = 512;
va_list args;
std::string buffer(BUFFER_LENGTH, '\0');
va_start(args, format);
int nret = vsnprintf(&buffer.front(), buffer.length() + 1, format, args);
va_end(args);
if (nret >= 0) {
if ((unsigned int)nret < buffer.length()) {
buffer.resize(nret);
}
else if ((unsigned int)nret > buffer.length()) { // VS2015/2017 or later Visual Studio Version
buffer.resize(nret);
va_start(args, format);
nret = vsnprintf(&buffer.front(), buffer.length() + 1, format, args);
va_end(args);
assert(nret == buffer.length());
}
// else equals, do nothing.
}
else { // less or equal VS2013 and Unix System glibc implement.
do {
buffer.resize(buffer.length() * 3 / 2);
va_start(args, format);
nret = vsnprintf(&buffer.front(), buffer.length() + 1, format, args);
va_end(args);
} while (nret < 0);
buffer.resize(nret);
}
VideoLoggingFunction(buffer);
}
std::string video::getErrorString(int errorCode)
{
constexpr size_t size = 64;
char buffer[size];
av_make_error_string(buffer, size, errorCode);
return std::string(buffer);
}