Merge branch 'development' into LTS_development
This commit is contained in:
commit
7629b00a4c
10 changed files with 65 additions and 17 deletions
|
@ -1457,6 +1457,7 @@ namespace DTSC {
|
||||||
}
|
}
|
||||||
vod = (packBytePos > 0);
|
vod = (packBytePos > 0);
|
||||||
live = !vod;
|
live = !vod;
|
||||||
|
EXTREME_MSG("Updating meta with %lld@%lld+%lld", packTrack, packTime, packOffset);
|
||||||
if (packTrack > 0 && tracks.count(packTrack)){
|
if (packTrack > 0 && tracks.count(packTrack)){
|
||||||
tracks[packTrack].update(packTime, packOffset, packDataSize, packBytePos, isKeyframe, packSendSize, segment_size, ivec);
|
tracks[packTrack].update(packTime, packOffset, packDataSize, packBytePos, isKeyframe, packSendSize, segment_size, ivec);
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,6 +155,8 @@ namespace h264 {
|
||||||
unsigned int timeScale = bs.get(32);
|
unsigned int timeScale = bs.get(32);
|
||||||
result.fps = (double)timeScale / (2 * unitsInTick);
|
result.fps = (double)timeScale / (2 * unitsInTick);
|
||||||
bs.skip(1);
|
bs.skip(1);
|
||||||
|
}else{
|
||||||
|
result.fps = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
lib/json.cpp
18
lib/json.cpp
|
@ -284,7 +284,7 @@ static std::string UTF16(uint32_t c){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string string_escape(const std::string val) {
|
std::string JSON::string_escape(const std::string & val) {
|
||||||
std::string out = "\"";
|
std::string out = "\"";
|
||||||
for (unsigned int i = 0; i < val.size(); ++i) {
|
for (unsigned int i = 0; i < val.size(); ++i) {
|
||||||
const char & c = val.data()[i];
|
const char & c = val.data()[i];
|
||||||
|
@ -1059,7 +1059,7 @@ std::string JSON::Value::toString() const {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING: {
|
case STRING: {
|
||||||
return string_escape(strVal);
|
return JSON::string_escape(strVal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ARRAY: {
|
case ARRAY: {
|
||||||
|
@ -1080,7 +1080,7 @@ std::string JSON::Value::toString() const {
|
||||||
std::string tmp2 = "{";
|
std::string tmp2 = "{";
|
||||||
if (objVal.size() > 0) {
|
if (objVal.size() > 0) {
|
||||||
jsonForEachConst(*this, i){
|
jsonForEachConst(*this, i){
|
||||||
tmp2 += string_escape(i.key()) + ":";
|
tmp2 += JSON::string_escape(i.key()) + ":";
|
||||||
tmp2 += i->toString();
|
tmp2 += i->toString();
|
||||||
if (i.num()+1 != objVal.size()) {
|
if (i.num()+1 != objVal.size()) {
|
||||||
tmp2 += ",";
|
tmp2 += ",";
|
||||||
|
@ -1114,7 +1114,7 @@ std::string JSON::Value::toPrettyString(int indentation) const {
|
||||||
return "\"" + JSON::Value((long long int)strVal.size()).asString() + " bytes of data\"";
|
return "\"" + JSON::Value((long long int)strVal.size()).asString() + " bytes of data\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string_escape(strVal);
|
return JSON::string_escape(strVal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ARRAY: {
|
case ARRAY: {
|
||||||
|
@ -1141,7 +1141,7 @@ std::string JSON::Value::toPrettyString(int indentation) const {
|
||||||
}
|
}
|
||||||
std::string tmp2 = "{" + std::string((shortMode ? "" : "\n"));
|
std::string tmp2 = "{" + std::string((shortMode ? "" : "\n"));
|
||||||
jsonForEachConst(*this, i){
|
jsonForEachConst(*this, i){
|
||||||
tmp2 += (shortMode ? std::string("") : std::string(indentation + 2, ' ')) + string_escape(i.key()) + ":";
|
tmp2 += (shortMode ? std::string("") : std::string(indentation + 2, ' ')) + JSON::string_escape(i.key()) + ":";
|
||||||
tmp2 += i->toPrettyString(indentation + 2);
|
tmp2 += i->toPrettyString(indentation + 2);
|
||||||
if (i.num() + 1 != objVal.size()) {
|
if (i.num() + 1 != objVal.size()) {
|
||||||
tmp2 += "," + std::string((shortMode ? " " : "\n"));
|
tmp2 += "," + std::string((shortMode ? " " : "\n"));
|
||||||
|
@ -1249,7 +1249,13 @@ unsigned int JSON::Value::size() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a std::string to a JSON::Value.
|
/// Converts a std::string to a JSON::Value.
|
||||||
JSON::Value JSON::fromString(std::string json) {
|
JSON::Value JSON::fromString(const char * data, const uint32_t data_len) {
|
||||||
|
const std::string str(data, data_len);
|
||||||
|
return JSON::fromString(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts a std::string to a JSON::Value.
|
||||||
|
JSON::Value JSON::fromString(const std::string & json) {
|
||||||
std::istringstream is(json);
|
std::istringstream is(json);
|
||||||
return JSON::Value(is);
|
return JSON::Value(is);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ namespace JSON {
|
||||||
EMPTY, BOOL, INTEGER, STRING, ARRAY, OBJECT
|
EMPTY, BOOL, INTEGER, STRING, ARRAY, OBJECT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// JSON-string-escapes a value
|
||||||
|
std::string string_escape(const std::string & val);
|
||||||
|
|
||||||
/// A JSON::Value is either a string or an integer, but may also be an object, array or null.
|
/// A JSON::Value is either a string or an integer, but may also be an object, array or null.
|
||||||
class Value {
|
class Value {
|
||||||
|
@ -91,7 +93,8 @@ namespace JSON {
|
||||||
Value fromDTMI2(const unsigned char * data, unsigned int len, unsigned int & i);
|
Value fromDTMI2(const unsigned char * data, unsigned int len, unsigned int & i);
|
||||||
Value fromDTMI(std::string & data);
|
Value fromDTMI(std::string & data);
|
||||||
Value fromDTMI(const unsigned char * data, unsigned int len, unsigned int & i);
|
Value fromDTMI(const unsigned char * data, unsigned int len, unsigned int & i);
|
||||||
Value fromString(std::string json);
|
Value fromString(const std::string & json);
|
||||||
|
Value fromString(const char * data, const uint32_t data_len);
|
||||||
Value fromFile(std::string filename);
|
Value fromFile(std::string filename);
|
||||||
void fromDTMI2(std::string & data, Value & ret);
|
void fromDTMI2(std::string & data, Value & ret);
|
||||||
void fromDTMI2(const unsigned char * data, unsigned int len, unsigned int & i, Value & ret);
|
void fromDTMI2(const unsigned char * data, unsigned int len, unsigned int & i, Value & ret);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
|
||||||
#define BUFFER_BLOCKSIZE 4096 // set buffer blocksize to 4KiB
|
#define BUFFER_BLOCKSIZE 4096 // set buffer blocksize to 4KiB
|
||||||
|
|
||||||
|
@ -656,17 +657,17 @@ bool Socket::Connection::isAddress(std::string addr){
|
||||||
int s = getaddrinfo(addr.c_str(), 0, &hints, &result);
|
int s = getaddrinfo(addr.c_str(), 0, &hints, &result);
|
||||||
if (s != 0){return false;}
|
if (s != 0){return false;}
|
||||||
|
|
||||||
char newaddr[INET_ADDRSTRLEN];
|
char newaddr[INET6_ADDRSTRLEN];
|
||||||
newaddr[0] = 0;
|
newaddr[0] = 0;
|
||||||
for (rp = result; rp != NULL; rp = rp->ai_next){
|
for (rp = result; rp != NULL; rp = rp->ai_next){
|
||||||
if (rp->ai_family == AF_INET && inet_ntop(rp->ai_family, &(((sockaddr_in *)rp->ai_addr)->sin_addr), newaddr, INET_ADDRSTRLEN)){
|
if (rp->ai_family == AF_INET && inet_ntop(rp->ai_family, &(((sockaddr_in *)rp->ai_addr)->sin_addr), newaddr, INET6_ADDRSTRLEN)){
|
||||||
DEBUG_MSG(DLVL_DEVEL, "Comparing: '%s' to '%s'", remotehost.c_str(), newaddr);
|
INFO_MSG("Comparing '%s' to '%s'", remotehost.c_str(), newaddr);
|
||||||
if (remotehost == newaddr){return true;}
|
if (remotehost == newaddr){return true;}
|
||||||
DEBUG_MSG(DLVL_DEVEL, "Comparing: '%s' to '::ffff:%s'", remotehost.c_str(), newaddr);
|
INFO_MSG("Comparing '%s' to '::ffff:%s'", remotehost.c_str(), newaddr);
|
||||||
if (remotehost == std::string("::ffff:") + newaddr){return true;}
|
if (remotehost == std::string("::ffff:") + newaddr){return true;}
|
||||||
}
|
}
|
||||||
if (rp->ai_family == AF_INET6 && inet_ntop(rp->ai_family, &(((sockaddr_in6 *)rp->ai_addr)->sin6_addr), newaddr, INET_ADDRSTRLEN)){
|
if (rp->ai_family == AF_INET6 && inet_ntop(rp->ai_family, &(((sockaddr_in6 *)rp->ai_addr)->sin6_addr), newaddr, INET6_ADDRSTRLEN)){
|
||||||
DEBUG_MSG(DLVL_DEVEL, "Comparing: '%s' to '%s'", remotehost.c_str(), newaddr);
|
INFO_MSG("Comparing '%s' to '%s'", remotehost.c_str(), newaddr);
|
||||||
if (remotehost == newaddr){return true;}
|
if (remotehost == newaddr){return true;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -674,6 +675,36 @@ bool Socket::Connection::isAddress(std::string addr){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Socket::Connection::isLocal(){
|
||||||
|
struct ifaddrs * ifAddrStruct=NULL;
|
||||||
|
struct ifaddrs * ifa=NULL;
|
||||||
|
void * tmpAddrPtr=NULL;
|
||||||
|
char addressBuffer[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
|
getifaddrs(&ifAddrStruct);
|
||||||
|
|
||||||
|
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
|
||||||
|
if (!ifa->ifa_addr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4
|
||||||
|
tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
|
||||||
|
inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
|
||||||
|
INFO_MSG("Comparing '%s' to '%s'", remotehost.c_str(), addressBuffer);
|
||||||
|
if (remotehost == addressBuffer){return true;}
|
||||||
|
INFO_MSG("Comparing '%s' to '::ffff:%s'", remotehost.c_str(), addressBuffer);
|
||||||
|
if (remotehost == std::string("::ffff:") + addressBuffer){return true;}
|
||||||
|
} else if (ifa->ifa_addr->sa_family == AF_INET6) { // check it is IP6
|
||||||
|
tmpAddrPtr=&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
|
||||||
|
inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
|
||||||
|
INFO_MSG("Comparing '%s' to '%s'", remotehost.c_str(), addressBuffer);
|
||||||
|
if (remotehost == addressBuffer){return true;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new base Server. The socket is never connected, and a placeholder for later connections.
|
/// Create a new base Server. The socket is never connected, and a placeholder for later connections.
|
||||||
Socket::Server::Server(){
|
Socket::Server::Server(){
|
||||||
sock = -1;
|
sock = -1;
|
||||||
|
|
|
@ -82,6 +82,7 @@ namespace Socket{
|
||||||
std::string getError(); ///< Returns a string describing the last error that occured.
|
std::string getError(); ///< Returns a string describing the last error that occured.
|
||||||
bool connected() const; ///< Returns the connected-state for this socket.
|
bool connected() const; ///< Returns the connected-state for this socket.
|
||||||
bool isAddress(std::string addr);
|
bool isAddress(std::string addr);
|
||||||
|
bool isLocal(); ///< Returns true if remote address is a local address.
|
||||||
// buffered i/o methods
|
// buffered i/o methods
|
||||||
bool spool(); ///< Updates the downbufferinternal variables.
|
bool spool(); ///< Updates the downbufferinternal variables.
|
||||||
bool peek(); ///< Clears the downbuffer and fills it with peek
|
bool peek(); ///< Clears the downbuffer and fills it with peek
|
||||||
|
|
|
@ -196,6 +196,11 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
||||||
}
|
}
|
||||||
{//lock the config mutex here - do not unlock until done processing
|
{//lock the config mutex here - do not unlock until done processing
|
||||||
tthread::lock_guard<tthread::mutex> guard(configMutex);
|
tthread::lock_guard<tthread::mutex> guard(configMutex);
|
||||||
|
//Are we local and not forwarded? Instant-authorized.
|
||||||
|
if (!authorized && !H.hasHeader("X-Real-IP") && conn.isLocal()){
|
||||||
|
INFO_MSG("Local API access automatically authorized");
|
||||||
|
authorized = true;
|
||||||
|
}
|
||||||
//if already authorized, do not re-check for authorization
|
//if already authorized, do not re-check for authorization
|
||||||
if (authorized){
|
if (authorized){
|
||||||
Response["authorize"]["status"] = "OK";
|
Response["authorize"]["status"] = "OK";
|
||||||
|
|
|
@ -370,9 +370,7 @@ namespace Mist {
|
||||||
|
|
||||||
|
|
||||||
if (myMeta.live){
|
if (myMeta.live){
|
||||||
//Update the metadata
|
myMeta.update(pack);
|
||||||
DTSC::Packet updatePack(myPage.mapped + curOffset, size + 8, true);
|
|
||||||
myMeta.update(updatePack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//End of brain melt
|
//End of brain melt
|
||||||
|
@ -467,6 +465,7 @@ namespace Mist {
|
||||||
myMeta.live = true;
|
myMeta.live = true;
|
||||||
//Store the trackid for easier access
|
//Store the trackid for easier access
|
||||||
unsigned long tid = packet.getTrackId();
|
unsigned long tid = packet.getTrackId();
|
||||||
|
VERYHIGH_MSG("Buffering %s packet on track %lu: %llums, %db", myMeta.tracks[tid].codec.c_str(), tid, packet.getTime(), packet.getPayloadLen());
|
||||||
//Do nothing if the trackid is invalid
|
//Do nothing if the trackid is invalid
|
||||||
if (!tid) {
|
if (!tid) {
|
||||||
WARN_MSG("Packet without trackid!");
|
WARN_MSG("Packet without trackid!");
|
||||||
|
|
|
@ -328,6 +328,7 @@ namespace Mist{
|
||||||
if (nProxy.userClient.getData()){
|
if (nProxy.userClient.getData()){
|
||||||
nProxy.userClient.finish();
|
nProxy.userClient.finish();
|
||||||
}
|
}
|
||||||
|
nProxy.streamName = streamName;
|
||||||
char userPageName[NAME_BUFFER_SIZE];
|
char userPageName[NAME_BUFFER_SIZE];
|
||||||
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
|
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
|
||||||
unsigned int attempts = 0;
|
unsigned int attempts = 0;
|
||||||
|
|
|
@ -1119,7 +1119,6 @@ namespace Mist {
|
||||||
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
|
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
|
||||||
nProxy.userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true);
|
nProxy.userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true);
|
||||||
}
|
}
|
||||||
nProxy.streamName = streamName;
|
|
||||||
bufferLivePacket(thisPacket);
|
bufferLivePacket(thisPacket);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue