Some small optimizations, added reference functions to JSON lib, fixed config commandline options.
This commit is contained in:
parent
0c059f0ca3
commit
ea71dd2d5c
7 changed files with 38 additions and 10 deletions
|
@ -348,6 +348,7 @@ void Util::Config::addConnectorOptions(int port, JSON::Value & capabilities){
|
||||||
capabilities["optional"]["port"]["name"] = "TCP port";
|
capabilities["optional"]["port"]["name"] = "TCP port";
|
||||||
capabilities["optional"]["port"]["help"] = "TCP port to listen on - default if unprovided is "+option["value"][0u].asString();
|
capabilities["optional"]["port"]["help"] = "TCP port to listen on - default if unprovided is "+option["value"][0u].asString();
|
||||||
capabilities["optional"]["port"]["type"] = "uint";
|
capabilities["optional"]["port"]["type"] = "uint";
|
||||||
|
capabilities["optional"]["port"]["option"] = "--port";
|
||||||
capabilities["optional"]["port"]["default"] = option["value"][0u];
|
capabilities["optional"]["port"]["default"] = option["value"][0u];
|
||||||
|
|
||||||
option.null();
|
option.null();
|
||||||
|
@ -359,6 +360,7 @@ void Util::Config::addConnectorOptions(int port, JSON::Value & capabilities){
|
||||||
addOption("listen_interface", option);
|
addOption("listen_interface", option);
|
||||||
capabilities["optional"]["interface"]["name"] = "Interface";
|
capabilities["optional"]["interface"]["name"] = "Interface";
|
||||||
capabilities["optional"]["interface"]["help"] = "Address of the interface to listen on - default if unprovided is all interfaces";
|
capabilities["optional"]["interface"]["help"] = "Address of the interface to listen on - default if unprovided is all interfaces";
|
||||||
|
capabilities["optional"]["interface"]["option"] = "--interface";
|
||||||
capabilities["optional"]["interface"]["type"] = "str";
|
capabilities["optional"]["interface"]["type"] = "str";
|
||||||
|
|
||||||
addBasicConnectorOptions(capabilities);
|
addBasicConnectorOptions(capabilities);
|
||||||
|
@ -376,6 +378,7 @@ void Util::Config::addBasicConnectorOptions(JSON::Value & capabilities){
|
||||||
addOption("username", option);
|
addOption("username", option);
|
||||||
capabilities["optional"]["username"]["name"] = "Username";
|
capabilities["optional"]["username"]["name"] = "Username";
|
||||||
capabilities["optional"]["username"]["help"] = "Username to drop privileges to - default if unprovided means do not drop privileges";
|
capabilities["optional"]["username"]["help"] = "Username to drop privileges to - default if unprovided means do not drop privileges";
|
||||||
|
capabilities["optional"]["username"]["option"] = "--username";
|
||||||
capabilities["optional"]["username"]["type"] = "str";
|
capabilities["optional"]["username"]["type"] = "str";
|
||||||
|
|
||||||
option.null();
|
option.null();
|
||||||
|
|
|
@ -222,10 +222,10 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
|
||||||
datapointertype = INVALID;
|
datapointertype = INVALID;
|
||||||
std::string tmp = "";
|
std::string tmp = "";
|
||||||
if (newPack.isMember("trackid")){
|
if (newPack.isMember("trackid")){
|
||||||
tmp = getTrackById(newPack["trackid"].asInt())["type"].asString();
|
tmp = getTrackById(newPack["trackid"].asInt())["type"].asStringRef();
|
||||||
}
|
}
|
||||||
if (newPack.isMember("datatype")){
|
if (newPack.isMember("datatype")){
|
||||||
tmp = newPack["datatype"].asString();
|
tmp = newPack["datatype"].asStringRef();
|
||||||
}
|
}
|
||||||
if (tmp == "video"){
|
if (tmp == "video"){
|
||||||
datapointertype = VIDEO;
|
datapointertype = VIDEO;
|
||||||
|
@ -300,7 +300,7 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (keySize){
|
if (keySize){
|
||||||
metadata["tracks"][newTrack]["keys"][keySize - 1]["parts"].append((long long int)newPack["data"].asString().size());
|
metadata["tracks"][newTrack]["keys"][keySize - 1]["parts"].append((long long int)newPack["data"].asStringRef().size());
|
||||||
}
|
}
|
||||||
metadata["live"] = 1ll;
|
metadata["live"] = 1ll;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ DTSC::livePos DTSC::Stream::msSeek(unsigned int ms, std::set<int> & allowedTrack
|
||||||
std::set<int> seekTracks = allowedTracks;
|
std::set<int> seekTracks = allowedTracks;
|
||||||
livePos result = buffers.begin()->first;
|
livePos result = buffers.begin()->first;
|
||||||
for (std::set<int>::iterator it = allowedTracks.begin(); it != allowedTracks.end(); it++){
|
for (std::set<int>::iterator it = allowedTracks.begin(); it != allowedTracks.end(); it++){
|
||||||
if (getTrackById(*it).isMember("type") && getTrackById(*it)["type"].asString() == "video"){
|
if (getTrackById(*it).isMember("type") && getTrackById(*it)["type"].asStringRef() == "video"){
|
||||||
int trackNo = *it;
|
int trackNo = *it;
|
||||||
seekTracks.clear();
|
seekTracks.clear();
|
||||||
seekTracks.insert(trackNo);
|
seekTracks.insert(trackNo);
|
||||||
|
|
|
@ -355,7 +355,7 @@ bool FLV::Tag::DTSCLoader(DTSC::Stream & S){
|
||||||
case DTSC::VIDEO:
|
case DTSC::VIDEO:
|
||||||
len = S.lastData().length() + 16;
|
len = S.lastData().length() + 16;
|
||||||
if (track && track.isMember("codec")){
|
if (track && track.isMember("codec")){
|
||||||
if (track["codec"].asString() == "H264"){
|
if (track["codec"].asStringRef() == "H264"){
|
||||||
len += 4;
|
len += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ bool FLV::Tag::DTSCLoader(DTSC::Stream & S){
|
||||||
case DTSC::AUDIO:
|
case DTSC::AUDIO:
|
||||||
len = S.lastData().length() + 16;
|
len = S.lastData().length() + 16;
|
||||||
if (track && track.isMember("codec")){
|
if (track && track.isMember("codec")){
|
||||||
if (track["codec"].asString() == "AAC"){
|
if (track["codec"].asStringRef() == "AAC"){
|
||||||
len += 1;
|
len += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -407,10 +407,10 @@ bool FLV::Tag::DTSCLoader(DTSC::Stream & S){
|
||||||
data[15] = offset & 0xFF;
|
data[15] = offset & 0xFF;
|
||||||
}
|
}
|
||||||
data[11] = 0;
|
data[11] = 0;
|
||||||
if (track.isMember("codec") && track["codec"].asString() == "H264"){
|
if (track.isMember("codec") && track["codec"].asStringRef() == "H264"){
|
||||||
data[11] += 7;
|
data[11] += 7;
|
||||||
}
|
}
|
||||||
if (track.isMember("codec") && track["codec"].asString() == "H263"){
|
if (track.isMember("codec") && track["codec"].asStringRef() == "H263"){
|
||||||
data[11] += 2;
|
data[11] += 2;
|
||||||
}
|
}
|
||||||
if (S.getPacket().isMember("keyframe")){
|
if (S.getPacket().isMember("keyframe")){
|
||||||
|
|
23
lib/json.cpp
23
lib/json.cpp
|
@ -380,6 +380,29 @@ const bool JSON::Value::asBool(){
|
||||||
return (bool) *this;
|
return (bool) *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Explicit conversion to std::string reference.
|
||||||
|
/// Returns a direct reference for string type JSON::Value objects,
|
||||||
|
/// but a reference to a static empty string otherwise.
|
||||||
|
/// \warning Only save to use when the JSON::Value is a string type!
|
||||||
|
const std::string & JSON::Value::asStringRef(){
|
||||||
|
static std::string ugly_buffer;
|
||||||
|
if (myType == STRING){
|
||||||
|
return strVal;
|
||||||
|
}
|
||||||
|
return ugly_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Explicit conversion to c-string.
|
||||||
|
/// Returns a direct reference for string type JSON::Value objects,
|
||||||
|
/// a reference to an empty string otherwise.
|
||||||
|
/// \warning Only save to use when the JSON::Value is a string type!
|
||||||
|
const char * JSON::Value::c_str(){
|
||||||
|
if (myType == STRING){
|
||||||
|
return strVal.c_str();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieves or sets the JSON::Value at this position in the object.
|
/// Retrieves or sets the JSON::Value at this position in the object.
|
||||||
/// Converts destructively to object if not already an object.
|
/// Converts destructively to object if not already an object.
|
||||||
JSON::Value & JSON::Value::operator[](const std::string i){
|
JSON::Value & JSON::Value::operator[](const std::string i){
|
||||||
|
|
|
@ -64,6 +64,8 @@ namespace JSON {
|
||||||
const std::string asString();
|
const std::string asString();
|
||||||
const long long int asInt();
|
const long long int asInt();
|
||||||
const bool asBool();
|
const bool asBool();
|
||||||
|
const std::string & asStringRef();
|
||||||
|
const char * c_str();
|
||||||
//array operator for maps and arrays
|
//array operator for maps and arrays
|
||||||
Value & operator[](const std::string i);
|
Value & operator[](const std::string i);
|
||||||
Value & operator[](const char * i);
|
Value & operator[](const char * i);
|
||||||
|
|
|
@ -477,7 +477,7 @@ void Socket::Connection::Send(const char * data){
|
||||||
/// Will not buffer anything but always send right away. Blocks.
|
/// Will not buffer anything but always send right away. Blocks.
|
||||||
/// This will send the upbuffer (if non-empty) first, then the data.
|
/// This will send the upbuffer (if non-empty) first, then the data.
|
||||||
/// Any data that could not be send will block until it can be send or the connection is severed.
|
/// Any data that could not be send will block until it can be send or the connection is severed.
|
||||||
void Socket::Connection::SendNow(std::string & data){
|
void Socket::Connection::SendNow(const std::string & data){
|
||||||
SendNow(data.c_str(), data.size());
|
SendNow(data.c_str(), data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ namespace Socket {
|
||||||
void Send(std::string & data); ///< Appends data to the upbuffer.
|
void Send(std::string & data); ///< Appends data to the upbuffer.
|
||||||
void Send(const char * data); ///< Appends data to the upbuffer.
|
void Send(const char * data); ///< Appends data to the upbuffer.
|
||||||
void Send(const char * data, size_t len); ///< Appends data to the upbuffer.
|
void Send(const char * data, size_t len); ///< Appends data to the upbuffer.
|
||||||
void SendNow(std::string & data); ///< Will not buffer anything but always send right away. Blocks.
|
void SendNow(const std::string & data); ///< Will not buffer anything but always send right away. Blocks.
|
||||||
void SendNow(const char * data); ///< Will not buffer anything but always send right away. Blocks.
|
void SendNow(const char * data); ///< Will not buffer anything but always send right away. Blocks.
|
||||||
void SendNow(const char * data, size_t len); ///< Will not buffer anything but always send right away. Blocks.
|
void SendNow(const char * data, size_t len); ///< Will not buffer anything but always send right away. Blocks.
|
||||||
//stats related methods
|
//stats related methods
|
||||||
|
|
Loading…
Add table
Reference in a new issue