~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to src/mcs/utils.cpp

Add hardware encoding and video streaming support.

The hardware encoding is currently only for Android 5.x based devices. On all others encoding will simply not work. The streaming part of aethercast (MPEGTS packetizing, RTP sending) as based on some code from Android.

Approved by PS Jenkins bot, Thomas Voß, Jim Hodapp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <memory>
22
22
#include <fstream>
 
23
#include <sstream>
23
24
 
24
25
#include <cstring>
25
26
#include <cstdarg>
42
43
  return boost::algorithm::split(tokens, text, boost::is_from_range(sep, sep), boost::algorithm::token_compress_on);
43
44
}
44
45
 
45
 
std::string Utils::GetEnvValue(const std::string &name) {
 
46
std::string Utils::GetEnvValue(const std::string &name, const std::string &default_value) {
46
47
    char *value = getenv(name.c_str());
47
48
    if (!value)
48
 
        return std::string("");
 
49
        return default_value;
49
50
    return std::string(value);
50
51
}
51
52
 
 
53
bool Utils::IsEnvSet(const std::string &name) {
 
54
    return getenv(name.c_str()) != nullptr;
 
55
}
 
56
 
52
57
bool Utils::CreateFile(const std::string &file_path) {
53
58
    boost::filesystem::path p(file_path);
54
59
    if (boost::filesystem::exists(p))
60
65
    of.close();
61
66
    return true;
62
67
}
 
68
 
 
69
uint64_t Utils::GetNowNs() {
 
70
   struct timespec ts;
 
71
   memset(&ts, 0, sizeof(ts));
 
72
   clock_gettime(CLOCK_MONOTONIC, &ts);
 
73
   return ts.tv_sec * 1000000000LL + ts.tv_nsec;
 
74
}
 
75
 
 
76
uint64_t Utils::GetNowUs() {
 
77
    return GetNowNs() / 1000;
 
78
}
 
79
 
 
80
std::string Utils::Hexdump(const uint8_t *data, uint32_t size) {
 
81
    unsigned char buff[17];
 
82
    unsigned char *pc = (unsigned char*) data;
 
83
    std::stringstream buffer;
 
84
 
 
85
    if (size == 0 || size < 0) {
 
86
        buffer << "NULL" << std::endl;
 
87
        return buffer.str();
 
88
    }
 
89
 
 
90
    int i;
 
91
    for (i = 0; i < size; i++) {
 
92
        if ((i % 16) == 0) {
 
93
            if (i != 0)
 
94
                buffer << mcs::Utils::Sprintf("  %s", buff) << std::endl;
 
95
 
 
96
            buffer << mcs::Utils::Sprintf("%02x   ", i);
 
97
        }
 
98
 
 
99
        buffer << mcs::Utils::Sprintf(" %02x", static_cast<int>(pc[i]));
 
100
 
 
101
        if ((pc[i] < 0x20) || (pc[i] > 0x7e))
 
102
            buff[i % 16] = '.';
 
103
        else
 
104
            buff[i % 16] = pc[i];
 
105
        buff[(i % 16) + 1] = '\0';
 
106
    }
 
107
 
 
108
    while ((i % 16) != 0) {
 
109
        buffer << "   ";
 
110
        i++;
 
111
    }
 
112
 
 
113
    buffer << mcs::Utils::Sprintf("  %s", buff) << std::endl;
 
114
 
 
115
    return buffer.str();
 
116
}
 
117
 
 
118
void Utils::SetThreadName(const std::string &name) {
 
119
    pthread_setname_np(pthread_self(), name.c_str());
 
120
}
 
121
 
63
122
} // namespace mcs