Such style. (Code style unification)

This commit is contained in:
Thulinma 2014-06-18 10:39:27 +02:00
parent 57bcd8f25c
commit 8c01ec8897
57 changed files with 6548 additions and 6437 deletions

View file

@ -20,7 +20,8 @@ namespace Secure {
0xe5, 0x16, 0x01, 0xf1, 0x98, 0xc9, 0x0b, 0xd6, 0xdf, 0x8a, 0x64, 0x47, 0xc4, 0x44, 0xcc, 0x92, 0x69, 0x28, 0xee, 0x7d, 0xac, 0xdc, 0x30, 0x56,
0x3a, 0xe7, 0xbc, 0xba, 0x45, 0x16, 0x2c, 0x4c, 0x46, 0x6b, 0x2b, 0x20, 0xfb, 0x3d, 0x20, 0x35, 0xbb, 0x48, 0x49, 0x13, 0x65, 0xc9, 0x9a, 0x38,
0x10, 0x84, 0x1a, 0x8c, 0xc9, 0xd7, 0xde, 0x07, 0x10, 0x5a, 0xfb, 0xb4, 0x95, 0xae, 0x18, 0xf2, 0xe3, 0x15, 0xe8, 0xad, 0x7e, 0xe5, 0x3c, 0xa8,
0x47, 0x85, 0xd6, 0x1f, 0x54, 0xb5, 0xa3, 0x79, 0x02, 0x03, 0x01, 0x00, 0x01}; ///< The GBv2 public key file.
0x47, 0x85, 0xd6, 0x1f, 0x54, 0xb5, 0xa3, 0x79, 0x02, 0x03, 0x01, 0x00, 0x01
}; ///< The GBv2 public key file.
static unsigned int __gbv2keypub_der_len = 294; ///< Length of GBv2 public key data
/// Attempts to load the GBv2 public key.

View file

@ -592,7 +592,9 @@ void Util::getMyExec(std::deque<std::string> & execs){
}
#else
DIR * d = opendir(path.c_str());
if (!d){return;}
if (!d) {
return;
}
struct dirent * dp;
do {
errno = 0;

View file

@ -31,7 +31,9 @@ namespace Converter {
cmd.push_back(NULL);
int outFD = -1;
Util::Procs::StartPiped("FFMpegInfo", &cmd[0], 0, &outFD, 0);
while( Util::Procs::isActive("FFMpegInfo")){ Util::sleep(100); }
while (Util::Procs::isActive("FFMpegInfo")) {
Util::sleep(100);
}
FILE * outFile = fdopen(outFD, "r");
char * fileBuf = 0;
size_t fileBufLen = 0;

View file

@ -169,7 +169,9 @@ bool DTSC::Stream::parsePacket(Socket::Buffer & buffer){
/// Adds a keyframe packet to all tracks, so the stream can be fully played.
void DTSC::Stream::endStream() {
if (!metadata.tracks.size()){return;}
if (!metadata.tracks.size()) {
return;
}
for (std::map<int, Track>::iterator it = metadata.tracks.begin(); it != metadata.tracks.end(); it++) {
JSON::Value newPack;
newPack["time"] = (long long)it->second.lastms;
@ -271,7 +273,9 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
livePos newPos;
newPos.trackID = newPack["trackid"].asInt();
newPos.seekTime = newPack["time"].asInt();
if (!metadata.tracks.count(newPos.trackID) && (!newPack.isMember("mark") || newPack["mark"].asStringRef() != "pause")){return;}
if (!metadata.tracks.count(newPos.trackID) && (!newPack.isMember("mark") || newPack["mark"].asStringRef() != "pause")) {
return;
}
if (buffercount > 1 && metadata.tracks[newPos.trackID].keys.size() > 1 && newPos.seekTime < (long long unsigned int)metadata.tracks[newPos.trackID].keys.rbegin()->getTime()) {
resetStream();
}
@ -325,7 +329,9 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
/// Deletes a the first part of the buffer, updating the keyframes list and metadata as required.
/// Will print a warning if a track has less than 2 keyframes left because of this.
void DTSC::Stream::cutOneBuffer() {
if ( !buffers.size()){return;}
if (!buffers.size()) {
return;
}
int trid = buffers.begin()->first.trackID;
long long unsigned int delTime = buffers.begin()->first.seekTime;
if (buffercount > 1) {
@ -469,11 +475,15 @@ int DTSC::Stream::canSeekms(unsigned int ms){
if (it->second.keys[0].getTime() <= ms && it->second.keys[it->second.keys.size() - 1].getTime() >= ms) {
return 0;
}
if (it->second.keys[0].getTime() > ms){too_late = true;}
if (it->second.keys[0].getTime() > ms) {
too_late = true;
}
}
}
//did we spot a track already past this point? return too late.
if (too_late){return -1;}
if (too_late) {
return -1;
}
//otherwise, assume not available yet
return 1;
}
@ -512,7 +522,9 @@ bool DTSC::Stream::isNewest(DTSC::livePos & pos, std::set<int> & allowedTracks){
DTSC::livePos DTSC::Stream::getNext(DTSC::livePos & pos, std::set<int> & allowedTracks) {
std::map<livePos, JSON::Value>::iterator iter = buffers.upper_bound(pos);
while (iter != buffers.end()) {
if (allowedTracks.count(iter->first.trackID)){return iter->first;}
if (allowedTracks.count(iter->first.trackID)) {
return iter->first;
}
iter++;
}
return pos;
@ -1078,8 +1090,12 @@ DTSC::File::~File(){
bool DTSC::isFixed(JSON::Value & metadata) {
if (metadata.isMember("is_fixed")){return true;}
if ( !metadata.isMember("tracks")){return false;}
if (metadata.isMember("is_fixed")) {
return true;
}
if (!metadata.isMember("tracks")) {
return false;
}
for (JSON::ObjIter it = metadata["tracks"].ObjBegin(); it != metadata["tracks"].ObjEnd(); it++) {
if (it->second["type"].asString() == "meta") {
continue;

View file

@ -288,7 +288,9 @@ namespace DTSC {
///\return The timestamp of this packet.
long long unsigned int Packet::getTime() const {
if (version != DTSC_V2) {
if (!data){return 0;}
if (!data) {
return 0;
}
return getInt("time");
}
return ((long long int)ntohl(((int *)(data + 12))[0]) << 32) | ntohl(((int *)(data + 12))[1]);
@ -443,7 +445,9 @@ namespace DTSC {
/// Returns the first byte of this DTSC value, or 0 on error.
char Scan::getType() {
if (!p){return 0;}
if (!p) {
return 0;
}
return p[0];
}
@ -478,7 +482,9 @@ namespace DTSC {
char * str;
unsigned int strlen;
getString(str, strlen);
if (!strlen){return 0;}
if (!strlen) {
return 0;
}
return strtoll(str, 0, 0);
default:
return 0;
@ -513,8 +519,12 @@ namespace DTSC {
/// \todo Move this function to some generic area. Duplicate from json.cpp
static inline char hex2c(char c) {
if (c < 10){return '0' + c;}
if (c < 16){return 'A' + (c - 10);}
if (c < 10) {
return '0' + c;
}
if (c < 16) {
return 'A' + (c - 10);
}
return '0';
}

View file

@ -455,9 +455,15 @@ bool FLV::Tag::DTSCLoader(DTSC::Packet & packData, DTSC::Track & track){
return false;
}
setLen();
if (track.type == "video"){data[0] = 0x09;}
if (track.type == "audio"){data[0] = 0x08;}
if (track.type == "meta"){data[0] = 0x12;}
if (track.type == "video") {
data[0] = 0x09;
}
if (track.type == "audio") {
data[0] = 0x08;
}
if (track.type == "meta") {
data[0] = 0x12;
}
data[1] = ((len - 15) >> 16) & 0xFF;
data[2] = ((len - 15) >> 8) & 0xFF;
data[3] = (len - 15) & 0xFF;
@ -910,7 +916,9 @@ bool FLV::Tag::FileLoader(FILE * f){
int postflags = preflags | O_NONBLOCK;
fcntl(fileno(f), F_SETFL, postflags);
if (len < 15){len = 15;}
if (len < 15) {
len = 15;
}
if (!checkBufferSize()) {
return false;
}

View file

@ -17,8 +17,12 @@ static inline char c2hex(char c){
}
static inline char hex2c(char c) {
if (c < 10){return '0' + c;}
if (c < 16){return 'A' + (c - 10);}
if (c < 10) {
return '0' + c;
}
if (c < 16) {
return 'A' + (c - 10);
}
return '0';
}
@ -1130,7 +1134,9 @@ JSON::Value JSON::fromDTMI2(std::string & data){
}
void JSON::fromDTMI2(const unsigned char * data, unsigned int len, unsigned int & i, JSON::Value & ret) {
if (len < 13){return;}
if (len < 13) {
return;
}
long long int tmpTrackID = ntohl(((int *)(data + i))[0]);
long long int tmpTime = ntohl(((int *)(data + i))[1]);
tmpTime <<= 32;

View file

@ -1075,8 +1075,12 @@ namespace MP4{
}
memset(data + payloadOffset, 0, 24); //set all bytes (32 - 8) to zeroes
if (type == "video"){setHandlerType("vide");}
if (type == "audio"){setHandlerType("soun");}
if (type == "video") {
setHandlerType("vide");
}
if (type == "audio") {
setHandlerType("soun");
}
setName(name);
}

0
lib/nal.cpp Executable file → Normal file
View file

0
lib/nal.h Executable file → Normal file
View file

View file

@ -412,8 +412,7 @@ namespace OGG{
0xBCB4666DU, 0xB8757BDAU, 0xB5365D03U, 0xB1F740B4U,
};
while (len > 0)
{
while (len > 0) {
crc = table[*data ^ ((crc >> 24) & 0xff)] ^ (crc << 8);
data++;
len--;

View file

@ -27,11 +27,15 @@ bool Util::Procs::handler_set = false;
static bool childRunning(pid_t p) {
pid_t ret = waitpid(p, 0, WNOHANG);
if (ret == p){return false;}
if (ret == p) {
return false;
}
if (ret < 0 && errno == EINTR) {
return childRunning(p);
}
if (kill(p, 0) == 0){return true;}
if (kill(p, 0) == 0) {
return true;
}
return false;
}
@ -43,7 +47,9 @@ void Util::Procs::exit_handler(){
int waiting = 0;
std::map<pid_t, std::string> listcopy = plist;
std::map<pid_t, std::string>::iterator it;
if (listcopy.empty()){return;}
if (listcopy.empty()) {
return;
}
//wait up to 0.5 second for applications to shut down
while (!listcopy.empty() && waiting <= 25) {
@ -58,7 +64,9 @@ void Util::Procs::exit_handler(){
}
}
}
if (listcopy.empty()){return;}
if (listcopy.empty()) {
return;
}
DEBUG_MSG(DLVL_DEVEL, "Sending SIGINT to remaining %d children", (int)listcopy.size());
//send sigint to all remaining
@ -84,7 +92,9 @@ void Util::Procs::exit_handler(){
}
}
}
if (listcopy.empty()){return;}
if (listcopy.empty()) {
return;
}
DEBUG_MSG(DLVL_DEVEL, "Sending SIGKILL to remaining %d children", (int)listcopy.size());
//send sigkill to all remaining
@ -110,7 +120,9 @@ void Util::Procs::exit_handler(){
}
}
}
if (listcopy.empty()){return;}
if (listcopy.empty()) {
return;
}
DEBUG_MSG(DLVL_DEVEL, "Giving up with %d children left.", (int)listcopy.size());
}
@ -183,7 +195,9 @@ std::string Util::Procs::getOutputOf(char* const* argv){
std::string ret;
int fin = 0, fout = -1, ferr = 0;
StartPiped("output_getter", argv, &fin, &fout, &ferr);
while (isActive("output_getter")){Util::sleep(100);}
while (isActive("output_getter")) {
Util::sleep(100);
}
FILE * outFile = fdopen(fout, "r");
char * fileBuf = 0;
size_t fileBufLen = 0;
@ -200,7 +214,9 @@ std::string Util::Procs::getOutputOf(std::string cmd){
std::string ret;
int fin = 0, fout = -1, ferr = 0;
StartPiped("output_getter", cmd, &fin, &fout, &ferr);
while (isActive("output_getter")){Util::sleep(100);}
while (isActive("output_getter")) {
Util::sleep(100);
}
FILE * outFile = fdopen(fout, "r");
char * fileBuf = 0;
size_t fileBufLen = 0;

View file

@ -47,13 +47,15 @@ uint8_t genuineFMSKey[] = {0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20, 0x41,
0x4d, 0x65, 0x64, 0x69, 0x61, 0x20, 0x53, 0x65, 0x72,
0x76, // Genuine Adobe Flash Media Server 001
0x65, 0x72, 0x20, 0x30, 0x30, 0x31, 0xf0, 0xee, 0xc2, 0x4a, 0x80, 0x68, 0xbe, 0xe8, 0x2e, 0x00, 0xd0, 0xd1, 0x02, 0x9e, 0x7e, 0x57, 0x6e, 0xec,
0x5d, 0x2d, 0x29, 0x80, 0x6f, 0xab, 0x93, 0xb8, 0xe6, 0x36, 0xcf, 0xeb, 0x31, 0xae}; // 68
0x5d, 0x2d, 0x29, 0x80, 0x6f, 0xab, 0x93, 0xb8, 0xe6, 0x36, 0xcf, 0xeb, 0x31, 0xae
}; // 68
uint8_t genuineFPKey[] = {0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20, 0x41, 0x64, 0x6f, 0x62, 0x65, 0x20, 0x46, 0x6c, 0x61, 0x73, 0x68, 0x20,
0x50, 0x6c, 0x61,
0x79, // Genuine Adobe Flash Player 001
0x65, 0x72, 0x20, 0x30, 0x30, 0x31, 0xf0, 0xee, 0xc2, 0x4a, 0x80, 0x68, 0xbe, 0xe8, 0x2e, 0x00, 0xd0, 0xd1, 0x02, 0x9e, 0x7e, 0x57, 0x6e, 0xec,
0x5d, 0x2d, 0x29, 0x80, 0x6f, 0xab, 0x93, 0xb8, 0xe6, 0x36, 0xcf, 0xeb, 0x31, 0xae}; // 62
0x5d, 0x2d, 0x29, 0x80, 0x6f, 0xab, 0x93, 0xb8, 0xe6, 0x36, 0xcf, 0xeb, 0x31, 0xae
}; // 62
inline uint32_t GetDigestOffset(uint8_t * pBuffer, uint8_t scheme) {
if (scheme == 0) {

View file

@ -438,11 +438,15 @@ bool Socket::Connection::peek(){
/// Returns true if new data was received, false otherwise.
bool Socket::Connection::flush() {
bool bing = isBlocking();
if (!bing){setBlocking(true);}
if (!bing) {
setBlocking(true);
}
while (upbuffer.size() > 0 && connected()) {
iwrite(upbuffer.get());
}
if (!bing){setBlocking(false);}
if (!bing) {
setBlocking(false);
}
/// \todo Provide better mechanism to prevent overbuffering.
if (downbuffer.size() > 1000) {
return true;
@ -461,7 +465,9 @@ Socket::Buffer & Socket::Connection::Received(){
/// Any data that could not be send will block until it can be send or the connection is severed.
void Socket::Connection::SendNow(const char * data, size_t len) {
bool bing = isBlocking();
if (!bing){setBlocking(true);}
if (!bing) {
setBlocking(true);
}
while (upbuffer.size() > 0 && connected()) {
iwrite(upbuffer.get());
}
@ -469,7 +475,9 @@ void Socket::Connection::SendNow(const char * data, size_t len){
while (i < len && connected()) {
i += iwrite(data + i, std::min((long unsigned int)(len - i), 51200ul));
}
if (!bing){setBlocking(false);}
if (!bing) {
setBlocking(false);
}
}
/// Appends data to the upbuffer.
@ -1111,7 +1119,9 @@ void Socket::UDPConnection::SendNow(const char* sdata){
/// Does not do anything if len < 1.
/// Prints an DLVL_FAIL level debug message if sending failed.
void Socket::UDPConnection::SendNow(const char * sdata, size_t len) {
if (len < 1){return;}
if (len < 1) {
return;
}
int r = sendto(sock, sdata, len, 0, (sockaddr *)destAddr, destAddr_size);
if (r > 0) {
up += r;
@ -1130,16 +1140,24 @@ int Socket::UDPConnection::bind(int port){
struct sockaddr_in6 s6;
s6.sin6_family = AF_INET6;
s6.sin6_addr = in6addr_any;
if (port){s6.sin6_port = htons(port);}
if (port) {
s6.sin6_port = htons(port);
}
int r = ::bind(sock, (sockaddr *)&s6, sizeof(s6));
if (r == 0){return ntohs(s6.sin6_port);}
if (r == 0) {
return ntohs(s6.sin6_port);
}
struct sockaddr_in s4;
s4.sin_family = AF_INET;
s4.sin_addr.s_addr = INADDR_ANY;
if (port){s4.sin_port = htons(port);}
if (port) {
s4.sin_port = htons(port);
}
r = ::bind(sock, (sockaddr *)&s4, sizeof(s4));
if (r == 0){return ntohs(s4.sin_port);}
if (r == 0) {
return ntohs(s4.sin_port);
}
DEBUG_MSG(DLVL_FAIL, "Could not bind UDP socket to port %d", port);
return 0;

View file

@ -60,18 +60,42 @@ namespace theora{
}
bool header::validateIdentificationHeader() {
if (datasize != 42){return false;}
if (getHeaderType() != 0){return false;}
if (getVMAJ() != 3){return false;}
if (getVMIN() != 2){return false;}
if (getFMBW() == 0){return false;}
if (getFMBH() == 0){return false;}
if ((short)getPICW() > getFMBW() * 16){return false;}
if ((short)getPICH() > getFMBH() * 16){return false;}
if ((short)getPICX() > (getFMBW() * 16) - (short)getPICW()){return false;}
if ((short)getPICY() > (getFMBH() * 16) - (short)getPICH()){return false;}
if (getFRN() == 0){return false;}
if (getFRD() == 0){return false;}
if (datasize != 42) {
return false;
}
if (getHeaderType() != 0) {
return false;
}
if (getVMAJ() != 3) {
return false;
}
if (getVMIN() != 2) {
return false;
}
if (getFMBW() == 0) {
return false;
}
if (getFMBH() == 0) {
return false;
}
if ((short)getPICW() > getFMBW() * 16) {
return false;
}
if ((short)getPICH() > getFMBH() * 16) {
return false;
}
if ((short)getPICX() > (getFMBW() * 16) - (short)getPICW()) {
return false;
}
if ((short)getPICY() > (getFMBH() * 16) - (short)getPICH()) {
return false;
}
if (getFRN() == 0) {
return false;
}
if (getFRD() == 0) {
return false;
}
return true;
}
@ -109,115 +133,161 @@ namespace theora{
}
char header::getVMAJ() {
if (getHeaderType() == 0){return data[7];}
if (getHeaderType() == 0) {
return data[7];
}
return 0;
}
char header::getVMIN() {
if (getHeaderType() == 0){return data[8];}
if (getHeaderType() == 0) {
return data[8];
}
return 0;
}
char header::getVREV() {
if (getHeaderType() == 0){return data[9];}
if (getHeaderType() == 0) {
return data[9];
}
return 0;
}
short header::getFMBW() {
if (getHeaderType() == 0){return getInt16(10);}
if (getHeaderType() == 0) {
return getInt16(10);
}
return 0;
}
short header::getFMBH() {
if (getHeaderType() == 0){return getInt16(12);}
if (getHeaderType() == 0) {
return getInt16(12);
}
return 0;
}
char header::getPICX() {
if (getHeaderType() == 0){return data[20];}
if (getHeaderType() == 0) {
return data[20];
}
return 0;
}
char header::getPICY() {
if (getHeaderType() == 0){return data[21];}
if (getHeaderType() == 0) {
return data[21];
}
return 0;
}
char header::getKFGShift() {
if (getHeaderType() == 0){return (getInt16(40) >> 5) & 0x1F;}
if (getHeaderType() == 0) {
return (getInt16(40) >> 5) & 0x1F;
}
return 0;
}
long unsigned int header::getFRN() {
if (getHeaderType() == 0){return getInt32(22);}
if (getHeaderType() == 0) {
return getInt32(22);
}
return 0;
}
long unsigned int header::getPICH() {
if (getHeaderType() == 0){return getInt24(17);}
if (getHeaderType() == 0) {
return getInt24(17);
}
return 0;
}
long unsigned int header::getPICW() {
if (getHeaderType() == 0){return getInt24(14);}
if (getHeaderType() == 0) {
return getInt24(14);
}
return 0;
}
long unsigned int header::getFRD() {
if (getHeaderType() == 0){return getInt32(26);}
if (getHeaderType() == 0) {
return getInt32(26);
}
return 0;
}
long unsigned int header::getPARN() {
if (getHeaderType() == 0){return getInt24(30);}
if (getHeaderType() == 0) {
return getInt24(30);
}
return 0;
}
long unsigned int header::getPARD() {
if (getHeaderType() == 0){return getInt24(33);}
if (getHeaderType() == 0) {
return getInt24(33);
}
return 0;
}
char header::getCS() {
if (getHeaderType() == 0){return data[36];}
if (getHeaderType() == 0) {
return data[36];
}
return 0;
}
long unsigned int header::getNOMBR() {
if (getHeaderType() == 0){return getInt24(37);}
if (getHeaderType() == 0) {
return getInt24(37);
}
return 0;
}
char header::getQUAL() {
if (getHeaderType() == 0){return (data[40] >> 3) & 0x1F;}
if (getHeaderType() == 0) {
return (data[40] >> 3) & 0x1F;
}
return 0;
}
char header::getPF() {
if (getHeaderType() == 0){return (data[41] >> 3) & 0x03;}
if (getHeaderType() == 0) {
return (data[41] >> 3) & 0x03;
}
return 0;
}
std::string header::getVendor() {
if (getHeaderType() != 1){return "";}
if (getHeaderType() != 1) {
return "";
}
return std::string(data + 11, commentLen(7));
}
long unsigned int header::getNComments() {
if (getHeaderType() != 1){return 0;}
if (getHeaderType() != 1) {
return 0;
}
int offset = 11 + commentLen(7);
return commentLen(offset);
}
char header::getLFLIMS(size_t index) {
if (getHeaderType() != 2){return 0;}
if (index >= 64){return 0;}
if (getHeaderType() != 2) {
return 0;
}
if (index >= 64) {
return 0;
}
char NBITS = (data[0] >> 5) & 0x07;
return NBITS;
}
std::string header::getUserComment(size_t index) {
if (index >= getNComments()){return "";}
if (index >= getNComments()) {
return "";
}
int offset = 11 + commentLen(7) + 4;
for (size_t i = 0; i < index; i++) {
offset += 4 + commentLen(offset);
@ -306,7 +376,9 @@ namespace theora{
}
char frame::getQIS(size_t index) {
if (index >= 3){return 0;}
if (index >= 3) {
return 0;
}
return 0;
}

View file

@ -54,8 +54,7 @@ namespace tthread {
#endif
#if defined(_TTHREAD_WIN32_)
condition_variable::condition_variable() : mWaitersCount(0)
{
condition_variable::condition_variable() : mWaitersCount(0) {
mEvents[_CONDITION_EVENT_ONE] = CreateEvent(NULL, FALSE, FALSE, NULL);
mEvents[_CONDITION_EVENT_ALL] = CreateEvent(NULL, TRUE, FALSE, NULL);
InitializeCriticalSection(&mWaitersCountLock);
@ -63,8 +62,7 @@ condition_variable::condition_variable() : mWaitersCount(0)
#endif
#if defined(_TTHREAD_WIN32_)
condition_variable::~condition_variable()
{
condition_variable::~condition_variable() {
CloseHandle(mEvents[_CONDITION_EVENT_ONE]);
CloseHandle(mEvents[_CONDITION_EVENT_ALL]);
DeleteCriticalSection(&mWaitersCountLock);
@ -72,8 +70,7 @@ condition_variable::~condition_variable()
#endif
#if defined(_TTHREAD_WIN32_)
void condition_variable::_wait()
{
void condition_variable::_wait() {
// Wait for either event to become signaled due to notify_one() or
// notify_all() being called
int result = WaitForMultipleObjects(2, mEvents, FALSE, INFINITE);
@ -92,8 +89,7 @@ void condition_variable::_wait()
#endif
#if defined(_TTHREAD_WIN32_)
void condition_variable::notify_one()
{
void condition_variable::notify_one() {
// Are there any waiters?
EnterCriticalSection(&mWaitersCountLock);
bool haveWaiters = (mWaitersCount > 0);
@ -106,8 +102,7 @@ void condition_variable::notify_one()
#endif
#if defined(_TTHREAD_WIN32_)
void condition_variable::notify_all()
{
void condition_variable::notify_all() {
// Are there any waiters?
EnterCriticalSection(&mWaitersCountLock);
bool haveWaiters = (mWaitersCount > 0);
@ -128,8 +123,7 @@ void condition_variable::notify_all()
//------------------------------------------------------------------------------
#if defined(_TTHREAD_POSIX_)
static thread::id _pthread_t_to_ID(const pthread_t &aHandle)
{
static thread::id _pthread_t_to_ID(const pthread_t & aHandle) {
static mutex idMapLock;
static std::map<pthread_t, unsigned long int> idMap;
static unsigned long int idCount(1);
@ -163,13 +157,10 @@ void * thread::wrapper_function(void * aArg)
// Get thread startup information
_thread_start_info * ti = (_thread_start_info *) aArg;
try
{
try {
// Call the actual client thread function
ti->mFunction(ti->mArg);
}
catch(...)
{
} catch (...) {
// Uncaught exceptions will terminate the application (default behavior
// according to C++11)
std::terminate();
@ -188,8 +179,7 @@ void * thread::wrapper_function(void * aArg)
return 0;
}
thread::thread(void (*aFunction)(void *), void * aArg)
{
thread::thread(void (*aFunction)(void *), void * aArg) {
// Serialize access to this thread structure
lock_guard<mutex> guard(mDataMutex);
@ -213,16 +203,14 @@ thread::thread(void (*aFunction)(void *), void * aArg)
#endif
// Did we fail to create the thread?
if(!mHandle)
{
if (!mHandle) {
mNotAThread = true;
ti_copy = 0;
delete ti;
}
}
thread::~thread()
{
thread::~thread() {
if (ti_copy) {
((_thread_start_info *)ti_copy)->mThread = 0;
}
@ -230,10 +218,8 @@ thread::~thread()
std::terminate();
}
void thread::join()
{
if(joinable())
{
void thread::join() {
if (joinable()) {
#if defined(_TTHREAD_WIN32_)
WaitForSingleObject(mHandle, INFINITE);
CloseHandle(mHandle);
@ -243,19 +229,16 @@ void thread::join()
}
}
bool thread::joinable() const
{
bool thread::joinable() const {
mDataMutex.lock();
bool result = !mNotAThread;
mDataMutex.unlock();
return result;
}
void thread::detach()
{
void thread::detach() {
mDataMutex.lock();
if(!mNotAThread)
{
if (!mNotAThread) {
#if defined(_TTHREAD_WIN32_)
CloseHandle(mHandle);
#elif defined(_TTHREAD_POSIX_)
@ -266,8 +249,7 @@ void thread::detach()
mDataMutex.unlock();
}
thread::id thread::get_id() const
{
thread::id thread::get_id() const {
if (!joinable())
return id();
#if defined(_TTHREAD_WIN32_)
@ -277,8 +259,7 @@ thread::id thread::get_id() const
#endif
}
unsigned thread::hardware_concurrency()
{
unsigned thread::hardware_concurrency() {
#if defined(_TTHREAD_WIN32_)
SYSTEM_INFO si;
GetSystemInfo(&si);
@ -299,8 +280,7 @@ unsigned thread::hardware_concurrency()
// this_thread
//------------------------------------------------------------------------------
thread::id this_thread::get_id()
{
thread::id this_thread::get_id() {
#if defined(_TTHREAD_WIN32_)
return thread::id((unsigned long int) GetCurrentThreadId());
#elif defined(_TTHREAD_POSIX_)

View file

@ -172,8 +172,7 @@ class mutex {
}
/// Destructor.
~mutex()
{
~mutex() {
#if defined(_TTHREAD_WIN32_)
DeleteCriticalSection(&mHandle);
#else
@ -185,8 +184,7 @@ class mutex {
/// The method will block the calling thread until a lock on the mutex can
/// be obtained. The mutex remains locked until @c unlock() is called.
/// @see lock_guard
inline void lock()
{
inline void lock() {
#if defined(_TTHREAD_WIN32_)
EnterCriticalSection(&mHandle);
while (mAlreadyLocked) Sleep(1000); // Simulate deadlock...
@ -201,12 +199,10 @@ class mutex {
/// return immediately (non-blocking).
/// @return @c true if the lock was acquired, or @c false if the lock could
/// not be acquired.
inline bool try_lock()
{
inline bool try_lock() {
#if defined(_TTHREAD_WIN32_)
bool ret = (TryEnterCriticalSection(&mHandle) ? true : false);
if(ret && mAlreadyLocked)
{
if (ret && mAlreadyLocked) {
LeaveCriticalSection(&mHandle);
ret = false;
}
@ -219,8 +215,7 @@ class mutex {
/// Unlock the mutex.
/// If any threads are waiting for the lock on this mutex, one of them will
/// be unblocked.
inline void unlock()
{
inline void unlock() {
#if defined(_TTHREAD_WIN32_)
mAlreadyLocked = false;
LeaveCriticalSection(&mHandle);
@ -251,8 +246,7 @@ class mutex {
class recursive_mutex {
public:
/// Constructor.
recursive_mutex()
{
recursive_mutex() {
#if defined(_TTHREAD_WIN32_)
InitializeCriticalSection(&mHandle);
#else
@ -264,8 +258,7 @@ class recursive_mutex {
}
/// Destructor.
~recursive_mutex()
{
~recursive_mutex() {
#if defined(_TTHREAD_WIN32_)
DeleteCriticalSection(&mHandle);
#else
@ -277,8 +270,7 @@ class recursive_mutex {
/// The method will block the calling thread until a lock on the mutex can
/// be obtained. The mutex remains locked until @c unlock() is called.
/// @see lock_guard
inline void lock()
{
inline void lock() {
#if defined(_TTHREAD_WIN32_)
EnterCriticalSection(&mHandle);
#else
@ -291,8 +283,7 @@ class recursive_mutex {
/// return immediately (non-blocking).
/// @return @c true if the lock was acquired, or @c false if the lock could
/// not be acquired.
inline bool try_lock()
{
inline bool try_lock() {
#if defined(_TTHREAD_WIN32_)
return TryEnterCriticalSection(&mHandle) ? true : false;
#else
@ -303,8 +294,7 @@ class recursive_mutex {
/// Unlock the mutex.
/// If any threads are waiting for the lock on this mutex, one of them will
/// be unblocked.
inline void unlock()
{
inline void unlock() {
#if defined(_TTHREAD_WIN32_)
LeaveCriticalSection(&mHandle);
#else
@ -347,15 +337,13 @@ class lock_guard {
lock_guard() : mMutex(0) {}
/// The constructor locks the mutex.
explicit lock_guard(mutex_type &aMutex)
{
explicit lock_guard(mutex_type & aMutex) {
mMutex = &aMutex;
mMutex->lock();
}
/// The destructor unlocks the mutex.
~lock_guard()
{
~lock_guard() {
if (mMutex)
mMutex->unlock();
}
@ -395,8 +383,7 @@ class condition_variable {
#if defined(_TTHREAD_WIN32_)
condition_variable();
#else
condition_variable()
{
condition_variable() {
pthread_cond_init(&mHandle, NULL);
}
#endif
@ -405,8 +392,7 @@ class condition_variable {
#if defined(_TTHREAD_WIN32_)
~condition_variable();
#else
~condition_variable()
{
~condition_variable() {
pthread_cond_destroy(&mHandle);
}
#endif
@ -417,8 +403,7 @@ class condition_variable {
/// @param[in] aMutex A mutex that will be unlocked when the wait operation
/// starts, an locked again as soon as the wait operation is finished.
template <class _mutexT>
inline void wait(_mutexT &aMutex)
{
inline void wait(_mutexT & aMutex) {
#if defined(_TTHREAD_WIN32_)
// Increment number of waiters
EnterCriticalSection(&mWaitersCountLock);
@ -443,8 +428,7 @@ class condition_variable {
#if defined(_TTHREAD_WIN32_)
void notify_one();
#else
inline void notify_one()
{
inline void notify_one() {
pthread_cond_signal(&mHandle);
}
#endif
@ -457,8 +441,7 @@ class condition_variable {
#if defined(_TTHREAD_WIN32_)
void notify_all();
#else
inline void notify_all()
{
inline void notify_all() {
pthread_cond_broadcast(&mHandle);
}
#endif
@ -536,8 +519,7 @@ class thread {
/// Get the native handle for this thread.
/// @note Under Windows, this is a @c HANDLE, and under POSIX systems, this
/// is a @c pthread_t.
inline native_handle_type native_handle()
{
inline native_handle_type native_handle() {
return mHandle;
}
@ -581,44 +563,36 @@ class thread::id {
id(const id & aId) : mId(aId.mId) {};
inline id & operator=(const id &aId)
{
inline id & operator=(const id & aId) {
mId = aId.mId;
return *this;
}
inline friend bool operator==(const id &aId1, const id &aId2)
{
inline friend bool operator==(const id & aId1, const id & aId2) {
return (aId1.mId == aId2.mId);
}
inline friend bool operator!=(const id &aId1, const id &aId2)
{
inline friend bool operator!=(const id & aId1, const id & aId2) {
return (aId1.mId != aId2.mId);
}
inline friend bool operator<=(const id &aId1, const id &aId2)
{
inline friend bool operator<=(const id & aId1, const id & aId2) {
return (aId1.mId <= aId2.mId);
}
inline friend bool operator<(const id &aId1, const id &aId2)
{
inline friend bool operator<(const id & aId1, const id & aId2) {
return (aId1.mId < aId2.mId);
}
inline friend bool operator>=(const id &aId1, const id &aId2)
{
inline friend bool operator>=(const id & aId1, const id & aId2) {
return (aId1.mId >= aId2.mId);
}
inline friend bool operator>(const id &aId1, const id &aId2)
{
inline friend bool operator>(const id & aId1, const id & aId2) {
return (aId1.mId > aId2.mId);
}
inline friend std::ostream& operator <<(std::ostream &os, const id &obj)
{
inline friend std::ostream & operator <<(std::ostream & os, const id & obj) {
os << obj.mId;
return os;
}
@ -635,7 +609,9 @@ typedef long long __intmax_t;
/// functionality to implement some basic @c chrono classes.
template <__intmax_t N, __intmax_t D = 1> class ratio {
public:
static double _as_double() { return double(N) / double(D); }
static double _as_double() {
return double(N) / double(D);
}
};
/// Minimal implementation of the @c chrono namespace.
@ -655,8 +631,7 @@ namespace chrono {
explicit duration(const _Rep2 & r) : rep_(r) {};
/// Return the value of the duration object.
rep count() const
{
rep count() const {
return rep_;
}
};
@ -679,8 +654,7 @@ namespace this_thread {
/// Yield execution to another thread.
/// Offers the operating system the opportunity to schedule another thread
/// that is ready to run on the current processor.
inline void yield()
{
inline void yield() {
#if defined(_TTHREAD_WIN32_)
Sleep(0);
#else
@ -697,8 +671,7 @@ namespace this_thread {
/// @endcode
/// @note Supported duration types are: nanoseconds, microseconds,
/// milliseconds, seconds, minutes and hours.
template <class _Rep, class _Period> void sleep_for(const chrono::duration<_Rep, _Period>& aTime)
{
template <class _Rep, class _Period> void sleep_for(const chrono::duration<_Rep, _Period> & aTime) {
#if defined(_TTHREAD_WIN32_)
Sleep(int(double(aTime.count()) * (1000.0 * _Period::_as_double()) + 0.5));
#else

0
lib/ts_packet.cpp Executable file → Normal file
View file

6
lib/ts_packet.h Executable file → Normal file
View file

@ -168,7 +168,8 @@ namespace TS {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
/// A standard Program Mapping Table, as generated by FFMPEG.
/// Contains both Audio and Video mappings, works also on video- or audio-only streams.
@ -198,7 +199,8 @@ namespace TS {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
} //TS namespace