HLS stream track selector support in index URLs, fixed source matching when multi-select or type-select is used, handle user agent exceptions in Output::selectDefaultTracks(), added Util::codecString to stream.h library, removed duplicate/wrong code from DASH/HLS outputs

This commit is contained in:
Thulinma 2019-04-26 16:55:11 +02:00
parent 7eb4f6634a
commit 095a60e0ed
5 changed files with 114 additions and 74 deletions

View file

@ -9,12 +9,30 @@
#include "procs.h"
#include "shared_memory.h"
#include "socket.h"
#include "mp4_generic.h"
#include <semaphore.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
std::string Util::codecString(const std::string & codec, const std::string & initData){
if (codec == "H264"){
std::stringstream r;
MP4::AVCC avccBox;
avccBox.setPayload(initData);
r << "avc1.";
r << std::hex << std::setw(2) << std::setfill('0') << (int)initData[1] << std::dec;
r << std::hex << std::setw(2) << std::setfill('0') << (int)initData[2] << std::dec;
r << std::hex << std::setw(2) << std::setfill('0') << (int)initData[3] << std::dec;
return r.str();
}
if (codec == "AAC"){return "mp4a.40.2";}
if (codec == "MP3"){return "mp4a.40.34";}
if (codec == "AC3"){return "ec-3";}
return "";
}
std::string Util::getTmpFolder(){
std::string dir;
char *tmp_char = 0;
@ -351,6 +369,29 @@ uint8_t Util::getStreamStatus(const std::string &streamname){
return streamStatus.mapped[0];
}
/// Checks if a given user agent is allowed according to the given exception.
bool Util::checkException(const JSON::Value & ex, const std::string & useragent){
//No user agent? Always allow everything.
if (!useragent.size()){return true;}
if (!ex.isArray() || !ex.size()){return true;}
bool ret = true;
jsonForEachConst(ex, e){
if (!e->isArray() || !e->size()){continue;}
bool setTo = ((*e)[0u].asStringRef() == "whitelist");
if (e->size() == 1){
ret = setTo;
continue;
}
if (!(*e)[1].isArray()){continue;}
jsonForEachConst((*e)[1u], i){
if (useragent.find(i->asStringRef()) != std::string::npos){
ret = setTo;
}
}
}
return ret;
}
Util::DTSCShmReader::DTSCShmReader(const std::string &pageName){
rPage.init(pageName, 0, false, false);
if (rPage){rAcc = Util::RelAccX(rPage.mapped);}

View file

@ -18,6 +18,8 @@ namespace Util {
JSON::Value getInputBySource(const std::string & filename, bool isProvider = false);
DTSC::Meta getStreamMeta(const std::string & streamname);
uint8_t getStreamStatus(const std::string & streamname);
bool checkException(const JSON::Value & ex, const std::string & useragent);
std::string codecString(const std::string & codec, const std::string & initData = "");
class DTSCShmReader{
public: