Updated Input class with preRun() and checkArguments() instead of single setup() function

This commit is contained in:
Thulinma 2017-07-22 18:53:05 +02:00
parent 169830bd15
commit 45e4cddec9
14 changed files with 36 additions and 21 deletions

View file

@ -100,7 +100,7 @@ namespace Mist {
return 0; return 0;
} }
if (!setup()) { if (!checkArguments()) {
FAIL_MSG("Setup failed - exiting"); FAIL_MSG("Setup failed - exiting");
return 0; return 0;
} }
@ -125,6 +125,7 @@ namespace Mist {
pid_t pid = fork(); pid_t pid = fork();
if (pid == 0){ if (pid == 0){
if (needsLock()){playerLock.close();} if (needsLock()){playerLock.close();}
if (!preRun()){return 0;}
return run(); return run();
} }
if (pid == -1){ if (pid == -1){

View file

@ -27,17 +27,18 @@ namespace Mist {
virtual bool needsLock(){return true;} virtual bool needsLock(){return true;}
protected: protected:
static void callbackWrapper(char * data, size_t len, unsigned int id); static void callbackWrapper(char * data, size_t len, unsigned int id);
virtual bool setup() = 0; virtual bool checkArguments() = 0;
virtual bool readHeader() = 0; virtual bool readHeader() = 0;
virtual bool preRun(){return true;}
virtual bool readExistingHeader(); virtual bool readExistingHeader();
virtual bool atKeyFrame(); virtual bool atKeyFrame();
virtual void getNext(bool smart = true) {}; virtual void getNext(bool smart = true) {}
virtual void seek(int seekTime){}; virtual void seek(int seekTime){};
virtual void finish(); virtual void finish();
virtual bool keepRunning(); virtual bool keepRunning();
virtual bool openStreamSource() { return false; }; virtual bool openStreamSource() { return false; }
virtual void closeStreamSource() {}; virtual void closeStreamSource() {}
virtual void parseStreamHeader() {}; virtual void parseStreamHeader() {}
void play(int until = 0); void play(int until = 0);
void playOnce(); void playOnce();
void quitPlay(); void quitPlay();

View file

@ -720,7 +720,7 @@ namespace Mist {
} }
} }
bool inputBuffer::setup() { bool inputBuffer::preRun() {
std::string strName = config->getString("streamname"); std::string strName = config->getString("streamname");
Util::sanitizeName(strName); Util::sanitizeName(strName);
strName = strName.substr(0, (strName.find_first_of("+ "))); strName = strName.substr(0, (strName.find_first_of("+ ")));

View file

@ -16,7 +16,8 @@ namespace Mist {
IPC::semaphore * liveMeta; IPC::semaphore * liveMeta;
protected: protected:
//Private Functions //Private Functions
bool setup(); bool preRun();
bool checkArguments(){return true;}
void updateMeta(); void updateMeta();
bool readHeader(); bool readHeader();
void getNext(bool smart = true); void getNext(bool smart = true);

View file

@ -183,7 +183,7 @@ namespace Mist {
srcConn.close(); srcConn.close();
} }
bool inputDTSC::setup() { bool inputDTSC::checkArguments() {
if (!needsLock()) { if (!needsLock()) {
return true; return true;
} else { } else {

View file

@ -11,7 +11,7 @@ namespace Mist {
bool openStreamSource(); bool openStreamSource();
void closeStreamSource(); void closeStreamSource();
void parseStreamHeader(); void parseStreamHeader();
bool setup(); bool checkArguments();
bool readHeader(); bool readHeader();
void getNext(bool smart = true); void getNext(bool smart = true);
void seek(int seekTime); void seek(int seekTime);

View file

@ -27,7 +27,7 @@ namespace Mist {
capa["codecs"][0u][1u].append("MP3"); capa["codecs"][0u][1u].append("MP3");
} }
bool inputFLV::setup() { bool inputFLV::checkArguments() {
if (config->getString("input") == "-") { if (config->getString("input") == "-") {
std::cerr << "Input from stdin not yet supported" << std::endl; std::cerr << "Input from stdin not yet supported" << std::endl;
return false; return false;
@ -43,7 +43,10 @@ namespace Mist {
return false; return false;
} }
} }
return true;
}
bool inputFLV::preRun() {
//open File //open File
inFile = fopen(config->getString("input").c_str(), "r"); inFile = fopen(config->getString("input").c_str(), "r");
if (!inFile) { if (!inFile) {

View file

@ -8,7 +8,8 @@ namespace Mist {
inputFLV(Util::Config * cfg); inputFLV(Util::Config * cfg);
protected: protected:
//Private Functions //Private Functions
bool setup(); bool checkArguments();
bool preRun();
bool readHeader(); bool readHeader();
void getNext(bool smart = true); void getNext(bool smart = true);
void seek(int seekTime); void seek(int seekTime);

View file

@ -16,7 +16,7 @@ namespace Mist{
inputProcess = 0; inputProcess = 0;
} }
int InputH264::run(){ bool InputH264::preRun(){
if (config->getString("input") != "-"){ if (config->getString("input") != "-"){
std::string input = config->getString("input"); std::string input = config->getString("input");
const char *argv[2]; const char *argv[2];
@ -55,10 +55,10 @@ namespace Mist{
myMeta.tracks[1].codec = "H264"; myMeta.tracks[1].codec = "H264";
myMeta.tracks[1].trackID = 1; myMeta.tracks[1].trackID = 1;
waitsSinceData = 0; waitsSinceData = 0;
return Input::run(); return true;
} }
bool InputH264::setup(){ bool InputH264::checkArguments(){
std::string input = config->getString("input"); std::string input = config->getString("input");
if (input != "-" && input.substr(0, 10) != "h264-exec:"){ if (input != "-" && input.substr(0, 10) != "h264-exec:"){
FAIL_MSG("Unsupported input type: %s", input.c_str()); FAIL_MSG("Unsupported input type: %s", input.c_str());

View file

@ -6,10 +6,10 @@ namespace Mist{
class InputH264 : public Input{ class InputH264 : public Input{
public: public:
InputH264(Util::Config *cfg); InputH264(Util::Config *cfg);
int run();
protected: protected:
bool setup(); bool checkArguments();
bool preRun();
void getNext(bool smart = true); void getNext(bool smart = true);
Socket::Connection myConn; Socket::Connection myConn;
std::string ppsInfo; std::string ppsInfo;

View file

@ -21,7 +21,7 @@ namespace Mist {
timestamp = 0; timestamp = 0;
} }
bool inputMP3::setup() { bool inputMP3::checkArguments() {
if (config->getString("input") == "-") { if (config->getString("input") == "-") {
std::cerr << "Input from stdin not yet supported" << std::endl; std::cerr << "Input from stdin not yet supported" << std::endl;
return false; return false;
@ -37,7 +37,10 @@ namespace Mist {
return false; return false;
} }
} }
return true;
}
bool inputMP3::preRun() {
//open File //open File
inFile = fopen(config->getString("input").c_str(), "r"); inFile = fopen(config->getString("input").c_str(), "r");
if (!inFile) { if (!inFile) {

View file

@ -16,7 +16,8 @@ namespace Mist {
inputMP3(Util::Config * cfg); inputMP3(Util::Config * cfg);
protected: protected:
//Private Functions //Private Functions
bool setup(); bool checkArguments();
bool preRun();
bool readHeader(); bool readHeader();
void getNext(bool smart = true); void getNext(bool smart = true);
void seek(int seekTime); void seek(int seekTime);

View file

@ -53,12 +53,15 @@ namespace Mist {
capa["codecs"][0u][1u].append("opus"); capa["codecs"][0u][1u].append("opus");
} }
bool inputOGG::setup(){ bool inputOGG::checkArguments(){
if (config->getString("input") == "-"){ if (config->getString("input") == "-"){
std::cerr << "Input from stream not yet supported" << std::endl; std::cerr << "Input from stream not yet supported" << std::endl;
return false; return false;
} }
return true;
}
bool inputOGG::preRun(){
//open File //open File
inFile = fopen(config->getString("input").c_str(), "r"); inFile = fopen(config->getString("input").c_str(), "r");
if (!inFile){ if (!inFile){

View file

@ -70,7 +70,8 @@ namespace Mist {
inputOGG(Util::Config * cfg); inputOGG(Util::Config * cfg);
protected: protected:
//Private Functions //Private Functions
bool setup(); bool checkArguments();
bool preRun();
bool readHeader(); bool readHeader();
position seekFirstData(long long unsigned int tid); position seekFirstData(long long unsigned int tid);
void getNext(bool smart = true); void getNext(bool smart = true);