diff options
author | kos <kos@dev3> | 2013-11-05 09:08:35 (GMT) |
---|---|---|
committer | kos <kos@dev3> | 2013-11-05 09:08:35 (GMT) |
commit | aab1af78d7c8152e5f3e8eafc61496898184df9f (patch) | |
tree | 82e3b1b30d5ecbf45847d361a49f5c017f49afb3 | |
parent | 824a37ccd527bca6d922c29fd0decec52a3214be (diff) |
check valid PID before setting to demux.
modify pid parser and upstream socket.
-rw-r--r-- | src/eDemuxPumpThread.cpp | 4 | ||||
-rw-r--r-- | src/eParser.cpp | 19 | ||||
-rw-r--r-- | src/eTransCodingDevice.cpp | 40 | ||||
-rw-r--r-- | src/eUpstreamSocket.cpp | 60 | ||||
-rw-r--r-- | src/eUpstreamSocket.h | 3 | ||||
-rw-r--r-- | src/main.cpp | 38 |
6 files changed, 82 insertions, 82 deletions
diff --git a/src/eDemuxPumpThread.cpp b/src/eDemuxPumpThread.cpp index 576cd51..9c8a4de 100644 --- a/src/eDemuxPumpThread.cpp +++ b/src/eDemuxPumpThread.cpp @@ -230,7 +230,7 @@ bool eDemuxPumpThread::SetPidList(std::vector<unsigned long>& aPidList) rc = ioctl(mDemuxFd, DMX_ADD_PID, pid); #endif #ifdef DEBUG_LOG - LOG("add [%x]!!!", pid); + LOG("add [%x].", pid); #endif if(rc < 0) { mErrMessage = "DMX_ADD_PID FAILED."; @@ -259,7 +259,7 @@ bool eDemuxPumpThread::SetPidList(std::vector<unsigned long>& aPidList) rc = ioctl(mDemuxFd, DMX_REMOVE_PID, pid); #endif #ifdef DEBUG_LOG - LOG("remove [%x]!!!", pid); + LOG("remove [%x].", pid); #endif if(rc < 0) { mErrMessage = "DMX_REMOVE_PID FAILED."; diff --git a/src/eParser.cpp b/src/eParser.cpp index 536554e..e3fefcf 100644 --- a/src/eParser.cpp +++ b/src/eParser.cpp @@ -183,6 +183,9 @@ bool eParser::LiveStreamPid(std::string aData, std::vector<unsigned long>& aPidL if(uStringTool::Split(aData, '\n', tokens)) { int tokenlen = tokens.size(); for(int i = 0; i < tokenlen; i++) { + if(!aVideoPid || !aAudioPid || !aPmtPid) { + aVideoPid = aAudioPid = aPmtPid = 0; + } std::string line = uStringTool::Trim(tokens[i]); #ifdef DEBUG_LOG LOG("[%d] [%s]", state, line.c_str()); @@ -224,31 +227,21 @@ bool eParser::LiveStreamPid(std::string aData, std::vector<unsigned long>& aPidL if(pid == -1) { continue; } - if(aVideoPid == 0) { + if(!aVideoPid || !aAudioPid || !aPmtPid) { if(strcmp(pidtype.c_str(), "video") == 0) { aVideoPid = pid; - } - } - if(aAudioPid == 0) { - if(strcmp(pidtype.c_str(), "audio") == 0) { + } else if(strcmp(pidtype.c_str(), "audio") == 0) { aAudioPid = pid; - } - } - if(aPmtPid == 0) { - if(strcmp(pidtype.c_str(), "pmt") == 0) { + } else if(strcmp(pidtype.c_str(), "pmt") == 0) { aPmtPid = pid; } } - if(!eDemuxPumpThread::ExistPid(aPidList, pid)) { aPidList.push_back(pid); } #ifdef DEBUG_LOG LOG("pid : %s [%04X]", pidtokens[ii].c_str(), pid); #endif - if(aAudioPid && aVideoPid) { - return true; - } } } } diff --git a/src/eTransCodingDevice.cpp b/src/eTransCodingDevice.cpp index 5ff7e42..406fe15 100644 --- a/src/eTransCodingDevice.cpp +++ b/src/eTransCodingDevice.cpp @@ -72,17 +72,21 @@ int eTransCodingDevice::GetDeviceFd() bool eTransCodingDevice::SetStreamPid(int aVideoPid, int aAudioPid) { - if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_VPID, aVideoPid) < 0) { + if(aVideoPid > 0) { + if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_VPID, aVideoPid) < 0) { #ifdef DEBUG_LOG - LOG("setting stream video pid failed."); + LOG("setting stream video pid failed."); #endif - return false; + return false; + } } - if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_APID, aAudioPid) < 0) { + if(aAudioPid > 0) { + if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_APID, aAudioPid) < 0) { #ifdef DEBUG_LOG - LOG("setting stream audio pid failed."); + LOG("setting stream audio pid failed."); #endif - return false; + return false; + } } #ifdef DEBUG_LOG LOG("setting stream pid ok."); @@ -93,23 +97,29 @@ bool eTransCodingDevice::SetStreamPid(int aVideoPid, int aAudioPid) bool eTransCodingDevice::SetStreamPid(int aVideoPid, int aAudioPid, int aPmtPid) { - if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_VPID, aVideoPid) < 0) { + if(aVideoPid > 0) { + if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_VPID, aVideoPid) < 0) { #ifdef DEBUG_LOG - LOG("setting stream video pid failed."); + LOG("setting stream video pid failed."); #endif - return false; + return false; + } } - if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_APID, aAudioPid) < 0) { + if(aAudioPid > 0) { + if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_APID, aAudioPid) < 0) { #ifdef DEBUG_LOG - LOG("setting stream audio pid failed."); + LOG("setting stream audio pid failed."); #endif - return false; + return false; + } } - if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_PMTPID, aPmtPid) < 0) { + if(aPmtPid > 0) { + if(ioctl(mDeviceFd, IOCTL_OPCODE_SET_PMTPID, aPmtPid) < 0) { #ifdef DEBUG_LOG - LOG("setting stream pmt pid failed."); + LOG("setting stream pmt pid failed."); #endif - return false; + return false; + } } #ifdef DEBUG_LOG LOG("setting stream pid ok."); diff --git a/src/eUpstreamSocket.cpp b/src/eUpstreamSocket.cpp index b16251b..b4c0566 100644 --- a/src/eUpstreamSocket.cpp +++ b/src/eUpstreamSocket.cpp @@ -46,55 +46,33 @@ bool eUpstreamSocket::Connect() } //------------------------------------------------------------------------------- -int eUpstreamSocket::Send(std::string aData) +int eUpstreamSocket::Request(std::string aSendData, std::string& aRecvData) { #ifdef DEBUG_LOG - LOG("Send : %s", aData.c_str()); + LOG("Send : %s", aSendData.c_str()); #endif - return write(mSockFd, aData.c_str(), aData.length()); -} -//------------------------------------------------------------------------------- - -int eUpstreamSocket::Recv(std::string& aData) -{ - int rc = 0; - char buffer[4096] = {0}; - struct pollfd pollevt; - - pollevt.fd = mSockFd; - pollevt.events = POLLIN | POLLERR; - - while(true) { - buffer[0] = 0; + if(write(mSockFd, aSendData.c_str(), aSendData.length()) > 0) { + struct pollfd pollevt; + pollevt.fd = mSockFd; + pollevt.events = POLLIN | POLLERR; pollevt.revents = 0; - rc = poll((struct pollfd*)&pollevt, 1, 1000); - - if (pollevt.revents == 0) { - break; - } else if (pollevt.revents & POLLIN) { - rc = read(mSockFd, buffer, 4096); -#ifdef DEBUG_LOG + while(true) { + char buffer[4096] = {0}; + if(read(mSockFd, buffer, 4096) <= 0) { + break; + } + #ifdef DEBUG_LOG LOG("Buffer : %s", buffer); -#endif - aData += buffer; - } - } - return aData.length(); -} -//------------------------------------------------------------------------------- - -int eUpstreamSocket::Request(std::string aSendData, std::string& aRecvData) -{ - int rc = Send(aSendData); - if(rc > 0) { - std::string recvdata; - rc = Recv(recvdata); - if(rc > 0) { - aRecvData = recvdata; + #endif + aRecvData += buffer; + if (poll((struct pollfd*)&pollevt, 1, 1000) == 0) { + break; + } } + return aRecvData.length(); } - return rc; + return -1; } //------------------------------------------------------------------------------- diff --git a/src/eUpstreamSocket.h b/src/eUpstreamSocket.h index 72c5ba7..0998d2a 100644 --- a/src/eUpstreamSocket.h +++ b/src/eUpstreamSocket.h @@ -25,9 +25,6 @@ public: virtual ~eUpstreamSocket(); bool Connect(); - int Send(std::string aData); - int Recv(std::string& aData); - int Request(std::string aSendData, std::string& aRecvData); }; //------------------------------------------------------------------------------- diff --git a/src/main.cpp b/src/main.cpp index 0a8a25b..a9ff0a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,7 @@ #include "eNetworkPumpThread.h" #ifdef DEBUG_LOG -FILE* fpLog = fopen("/tmp/filestreamproxy.log", "w"); +FILE* fpLog = 0; //#undef LOG //#define LOG(X,...) { do{}while(0); } #endif @@ -62,6 +62,10 @@ int main(int argc, char** argv) char request[MAX_LINE_LENGTH] = {0}; int videopid = 0, audiopid = 0, pmtid = 0; +#ifdef DEBUG_LOG + fpLog = fopen("/tmp/transtreamproxy.log", "w"); +#endif + signal(SIGINT, SignalHandler); if (!ReadRequest(request)) { @@ -77,6 +81,9 @@ int main(int argc, char** argv) char* http = strchr(request + 5, ' '); if (!http || strncmp(http, " HTTP/1.", 7)) { +#ifdef DEBUG_LOG + LOG("Not support request (%s).", http); +#endif RETURN_ERR_400("Not support request (%s).", http); } @@ -86,6 +93,9 @@ int main(int argc, char** argv) eTransCodingDevice transcoding; if(transcoding.Open() == false) { +#ifdef DEBUG_LOG + LOG("Opne device failed."); +#endif RETURN_ERR_502("Opne device failed."); } hTranscodingDevice = &transcoding; @@ -102,10 +112,16 @@ int main(int argc, char** argv) eUpstreamSocket upstreamsocket; if(!upstreamsocket.Connect()) { +#ifdef DEBUG_LOG + LOG("Upstream connect failed."); +#endif RETURN_ERR_502("Upstream connect failed."); } std::string responsedata = ""; if(upstreamsocket.Request(eParser::ServiceRef(request + 5, authorization), responsedata) < 0) { +#ifdef DEBUG_LOG + LOG("Upstream request failed."); +#endif RETURN_ERR_502("Upstream request failed."); } @@ -115,6 +131,9 @@ int main(int argc, char** argv) ispidseted = eParser::LiveStreamPid(responsedata, pidlist, demuxno, videopid, audiopid, pmtid, wwwauthenticate); if(ispidseted) { if(transcoding.SetStreamPid(videopid, audiopid, pmtid) == false) { +#ifdef DEBUG_LOG + LOG("Pid setting failed."); +#endif RETURN_ERR_502("Pid setting failed."); } } else { @@ -132,14 +151,17 @@ int main(int argc, char** argv) #endif eDemuxPumpThread demuxpump; - if(!demuxpump.Open(demuxno)) { - RETURN_ERR_502("%s", demuxpump.GetMessage().c_str()); - } - demuxpump.SetDeviceFd(transcoding.GetDeviceFd()); - demuxpump.Start(); - hDemuxPumpThread = &demuxpump; - if(pidlist.size() > 0) { + if(!demuxpump.Open(demuxno)) { +#ifdef DEBUG_LOG + LOG("Demux open failed."); +#endif + RETURN_ERR_502("%s", demuxpump.GetMessage().c_str()); + } + demuxpump.SetDeviceFd(transcoding.GetDeviceFd()); + demuxpump.Start(); + hDemuxPumpThread = &demuxpump; + if(demuxpump.GetState() < eDemuxState::stSetedFilter) { if(!demuxpump.SetFilter(pidlist)) { #ifdef DEBUG_LOG |