From 6e799535401c12087185e759f65e895f95d9249d Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Tue, 5 Sep 2023 17:25:16 +0000 Subject: [PATCH] Live555 Trouble Stage 1 --- Projects/la_mojo/Debug/server.conf | 1 + Projects/la_mojo/build | 2 +- lib/App/common/deviceNode2D.cpp | 3 + lib/App/common/deviceNode2D.h | 2 +- lib/App/common/kernelModuleEmbedVideo.cpp | 7 +- lib/components/base/basicThread.cpp | 5 + lib/components/base/basicThread.h | 1 + lib/data/media/video/videoAVLIBSource.cpp | 4 +- .../media/video/videoLive555AVLibSource.cpp | 92 ++++++++++++++----- .../media/video/videoLive555AVLibSource.h | 20 ++-- 10 files changed, 95 insertions(+), 42 deletions(-) diff --git a/Projects/la_mojo/Debug/server.conf b/Projects/la_mojo/Debug/server.conf index ab535594..6e4c77da 100644 --- a/Projects/la_mojo/Debug/server.conf +++ b/Projects/la_mojo/Debug/server.conf @@ -8,6 +8,7 @@ GENERAL : WEB_ACCESS_GROUP = "www-data"; DATA_MEMORY_NAME = "mem_db.db"; REPORT_FILE_NAME = "data/reports.db"; + REPORTS_DIR_NAME = "data/reports"; }; KERNEL : { diff --git a/Projects/la_mojo/build b/Projects/la_mojo/build index 0d3905e9..70621108 100755 --- a/Projects/la_mojo/build +++ b/Projects/la_mojo/build @@ -1,7 +1,7 @@ #! /bin/sh -make clean -e "CFG=Debug" +#make clean -e "CFG=Debug" make -e "CFG=Debug" -j6 #make clean -e "CFG=Debug86" diff --git a/lib/App/common/deviceNode2D.cpp b/lib/App/common/deviceNode2D.cpp index 0a9af983..6fe7098b 100644 --- a/lib/App/common/deviceNode2D.cpp +++ b/lib/App/common/deviceNode2D.cpp @@ -2486,6 +2486,9 @@ bool device2DSensor::packetHandler( protocolPackage *Package ){ #ifdef DEBUG LOG("CMD_UNSUPPORTED!!"); #endif + if( getWM() == LRF_WM_SYNC_UP ){ + setStage( LRF_WS_STAGE_1 ); + } break; }; case CMD_FULL_RESET:{ diff --git a/lib/App/common/deviceNode2D.h b/lib/App/common/deviceNode2D.h index a3078ba2..4a752ed6 100644 --- a/lib/App/common/deviceNode2D.h +++ b/lib/App/common/deviceNode2D.h @@ -23,7 +23,7 @@ #define LGS_DEFAULT_SLEEP_TIME 100 #define LGS_ALERT_SLEEP_TIME 10 #define LGS_DEFAULT_TO_COUNTER 10 //100ms -#define LGS_DEFAULT_WS_TIME 6 //60ms +#define LGS_DEFAULT_WS_TIME 10 //100ms #define LGS_INITIAL_FLIPS 8 #define LGS_CMD_RETRY_COUNT 3 diff --git a/lib/App/common/kernelModuleEmbedVideo.cpp b/lib/App/common/kernelModuleEmbedVideo.cpp index 588d515f..13fee4d6 100644 --- a/lib/App/common/kernelModuleEmbedVideo.cpp +++ b/lib/App/common/kernelModuleEmbedVideo.cpp @@ -206,7 +206,8 @@ static const char * ht_no_signal = "HTTP/1.1 200 OK\r\n" void signal_pipe_handler( int SIG ){ - basicLogCollection::getInstance()->Log("SIG_PIPE", NULL, _LOG_ERROR, "Sig Pipe Received"); + //basicLogCollection::getInstance()->Log("SIG_PIPE", NULL, _LOG_ERROR, "Sig Pipe Received"); + // Web Client Disconnected! }; void *kernelModuleEmbedVideo::webClientProc( void *ptr ){ @@ -3425,12 +3426,14 @@ bool streamHandler::validate( void ){ if( m_nGlobalFrameCounter ) { //Frames Received from a source if( m_nGlobalFrameCounter == m_nValidatorFrameCounter ) { // Video Stalled! - return false;// Try use System to recuperate + LOG_ERROR("Video Stalled"); + //return false;// Try use System to recuperate } else m_nValidatorFrameCounter = m_nGlobalFrameCounter; }; if( m_bThreadStatus < TH_ENDED ) return true; #endif }; + LOG_ERROR("Video Ended"); }; return false; }; diff --git a/lib/components/base/basicThread.cpp b/lib/components/base/basicThread.cpp index 5f235551..0bf5a800 100644 --- a/lib/components/base/basicThread.cpp +++ b/lib/components/base/basicThread.cpp @@ -93,6 +93,11 @@ bool basicThread::uninit( void ){ return true; }; +void basicThread::abort(){ + pthread_cancel( m_sThreadHandler ); + pthread_join( m_sThreadHandler, NULL); +}; + #undef LOG #undef LOG_ERROR #undef SLOG diff --git a/lib/components/base/basicThread.h b/lib/components/base/basicThread.h index 7e71d55f..d8ea0dfe 100644 --- a/lib/components/base/basicThread.h +++ b/lib/components/base/basicThread.h @@ -67,6 +67,7 @@ class basicThread { thredStatus getStatus( void ){ return m_bThreadStatus; }; void setStatus( thredStatus A ){ m_bThreadStatus = A; }; void waitThreadEnd( bool forced = false ); + void abort( void ); // Copy constructor // TODO: Uncomment the copy constructor when you need it. //basicThread(const basicThread& src); diff --git a/lib/data/media/video/videoAVLIBSource.cpp b/lib/data/media/video/videoAVLIBSource.cpp index d2531ee6..9b448a53 100644 --- a/lib/data/media/video/videoAVLIBSource.cpp +++ b/lib/data/media/video/videoAVLIBSource.cpp @@ -867,8 +867,8 @@ void videoAVLIBSource::m_fThreadProc( void ){ SLEEP( 5 ); }; av_packet_unref( pPacket ); - SLEEP( 10 ); - } else SLEEP( 10 ); + SLEEP( 5 ); + } else SLEEP( 5 ); }; #ifdef DEBUG LOG("Video Source Ended!"); diff --git a/lib/data/media/video/videoLive555AVLibSource.cpp b/lib/data/media/video/videoLive555AVLibSource.cpp index a6f8fa4f..56907875 100644 --- a/lib/data/media/video/videoLive555AVLibSource.cpp +++ b/lib/data/media/video/videoLive555AVLibSource.cpp @@ -35,7 +35,7 @@ CustomRTSPClient::CustomRTSPClient( int verbosityLevel, char const* applicationName, portNumBits tunnelOverHTTPPortNum) - : RTSPClient(env,rtspURL, verbosityLevel, applicationName, tunnelOverHTTPPortNum, -1) , + : RTSPClient( env, rtspURL, verbosityLevel, applicationName, tunnelOverHTTPPortNum, -1 ), session(session){ }; @@ -355,6 +355,7 @@ DummySink::DummySink( videoLIVE555Source* session, UsageEnvironment& env, MediaS m_pSwsContext = sws_getContext( m_pCodecContext->width, m_pCodecContext->height, m_pCodecContext->pix_fmt, m_nOutWidth, m_nOutHeight, AV_PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL); m_pRGB = new cv::Mat( m_nOutHeight, m_nOutWidth, CV_8UC3, cv::Scalar( 255, 0, 255 ) ); } else { + LOG("No Decode Frames Mode!"); m_pFrame = m_pRGBFrame = NULL; m_pSwsContext = NULL; m_pRGB = NULL; @@ -368,7 +369,7 @@ DummySink::DummySink( videoLIVE555Source* session, UsageEnvironment& env, MediaS }; DummySink::~DummySink() { - + LOG("Sink Destructor!"); if( m_pOutFormatCtx != NULL ) { av_write_trailer( m_pOutFormatCtx ); avio_close( m_pOutFormatCtx->pb ); @@ -421,6 +422,7 @@ void DummySink::afterGettingFrame(void* clientData, unsigned frameSize, unsigned void DummySink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds ) { // We've just received a frame of data. (Optionally) print out information about it: //if (strcmp(fSubsession.codecName(),"H264") == 0) { + LOG("FRM"); if( m_eCodecProbe != AV_CODEC_ID_NONE ) { int got_picture; @@ -443,6 +445,7 @@ void DummySink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes m_iFrameIndex ++; }; }; + av_packet_unref( &m_sAvPkt ); if ( m_pSession->getWM() & MS_MODE_STREAM_PROXY ) { if ( m_pSession->getWM() & MS_MODE_OVERLAYED_LOOPS ) { @@ -648,13 +651,20 @@ videoLIVE555Source::~videoLIVE555Source(){ }; void videoLIVE555Source::m_fThreadProc( void ){ + LOG("Start Thread"); _eventLoopWatchVariable = 0; + m_bThreadStatus = TH_WORKING; + //while ( m_bThreadStatus == TH_WORKING ) { m_pScheduler->doEventLoop( &_eventLoopWatchVariable ); + //streamTimerHandler( m_pRtspClient ); + //SLEEP(3); + //}; LOG( "Rtsp event finished" ); - m_pUsageEnvironment->reclaim(); - m_pUsageEnvironment = NULL; - delete m_pScheduler; - m_pScheduler = NULL; + //m_pUsageEnvironment->reclaim(); + //m_pUsageEnvironment = NULL; + //delete m_pScheduler; + //m_pScheduler = NULL; + LOG("End Thread"); }; @@ -670,7 +680,7 @@ void videoLIVE555Source::continueAfterDESCRIBE( RTSPClient* rtspClient, int resu UsageEnvironment& env = rtspClient->envir(); // alias StreamClientState& scs = MM->getStreamClientState(); // alias - if (resultCode != 0) { + if( resultCode != 0 ){ MLOG( "Failed to get a SDP description: "); MLOG( resultString ); delete[] resultString; @@ -682,9 +692,9 @@ void videoLIVE555Source::continueAfterDESCRIBE( RTSPClient* rtspClient, int resu MLOG( sdpDescription ); // Create a media session object from this SDP description: - scs.session = MediaSession::createNew(env, sdpDescription); + scs.session = MediaSession::createNew( env, sdpDescription ); delete[] sdpDescription; // because we don't need it anymore - if (scs.session == NULL) { + if( scs.session == NULL ){ MLOG( "Failed to create a MediaSession object from the SDP description:" ); MLOG( env.getResultMsg() ); break; @@ -698,7 +708,7 @@ void videoLIVE555Source::continueAfterDESCRIBE( RTSPClient* rtspClient, int resu // Then, create and set up our data source objects for the session. We do this by iterating over the session's 'subsessions', // calling "MediaSubsession::initiate()", and then sending a RTSP "SETUP" command, on each one. // (Each 'subsession' will have its own data source.) - scs.iter = new MediaSubsessionIterator(*scs.session); + scs.iter = new MediaSubsessionIterator( *scs.session ); ME->setupNextSubsession( rtspClient ); return; } while (0); @@ -771,8 +781,8 @@ void videoLIVE555Source::continueAfterSETUP( RTSPClient* rtspClient, int resultC }; MLOG( "Created a data sink for the subsession" ); - MLOG( streamClientState.subsession->mediumName() ); - MLOG( streamClientState.subsession->codecName() ); + //MLOG( streamClientState.subsession->mediumName() ); + //MLOG( streamClientState.subsession->codecName() ); streamClientState.subsession->miscPtr = rtspClient; // a hack to let subsession handler functions get the "RTSPClient" from the subsession @@ -792,10 +802,11 @@ void videoLIVE555Source::continueAfterSETUP( RTSPClient* rtspClient, int resultC streamClientState.subsession->rtcpInstance()->setByeHandler( subsessionByeHandler, streamClientState.subsession ); } - } while (0); + } while (0); delete[] resultString; // Set up the next subsession, if any: - ME->setupNextSubsession(rtspClient); + ME->setupNextSubsession( rtspClient ); + MLOG("Done ContAfterSetup"); }; void videoLIVE555Source::continueAfterPLAY( RTSPClient* rtspClient, int resultCode, char* resultString){ @@ -899,7 +910,6 @@ void videoLIVE555Source::streamTimerHandler( void* clientData ){ StreamClientState& scs = rtspClient->getStreamClientState(); // alias videoLIVE555Source * ME = (videoLIVE555Source *) rtspClient->getSession(); scs.streamTimerTask = NULL; - // Shut down the stream: ME->shutdownStream(rtspClient); }; @@ -967,6 +977,40 @@ void videoLIVE555Source::shutdownStream(RTSPClient* rtspClient, int exitCode ){ #ifdef DEBUG MLOG("Shutdown EVT"); #endif + StreamClientState & streamClientState = MM->getStreamClientState(); // alias + //if( resultCode != 0 ){ + // MLOG( "Failed to set up the subsession:"); + // MLOG( streamClientState.subsession->mediumName() ); + // MLOG( streamClientState.subsession->codecName() ); + // MLOG( resultString ); + // break; + //}; + UsageEnvironment & env = rtspClient->envir(); + MLOG( "sendTearDown" ); + rtspClient->sendTeardownCommand( *streamClientState.session, NULL ); + MLOG( "Close Client" ); + Medium::close( rtspClient ); + MLOG( "SetLOOP" ); + _eventLoopWatchVariable = 1; + //MLOG( "Close Session" ); + //Medium::close( streamClientState.session ); + //MLOG( "Abort Thread" ); + //waitThreadEnd( true ); + // close RTSP client + //MLOG( "recalm Env" ); + //env.reclaim(); + //MLOG( "Delete Client" ); + //delete MM; + //MLOG( "Delete Sink" ); + //delete( (DummySink*) streamClientState.subsession->sink ); + //*/ + + MLOG( "Delete Scheduler" ); + m_pUsageEnvironment->reclaim(); + m_pUsageEnvironment = NULL; + delete m_pScheduler; + m_pScheduler = NULL; + MLOG( "All Done!" ); m_eMediaStatus = MS_CLOSED; }; @@ -1011,17 +1055,21 @@ bool videoLIVE555Source::_close( void ){ LOG("CLOSE!"); return _stop(); }; + bool videoLIVE555Source::_stop( void ){ LOG("STOP!"); - shutdownStream( m_pRtspClient ); - LOG("SHUTDOWN!"); - _eventLoopWatchVariable = 1; - basicThread::waitThreadEnd( true ); - LOG("TH ENDED!"); + shutdownStream( m_pRtspClient ); return true; }; -bool videoLIVE555Source::isFinished( void ){ return false;}; -MediaStateStatus videoLIVE555Source::getStatus( void ){ return MS_UNDEFINED; }; + +bool videoLIVE555Source::isFinished( void ){ + return (m_eMediaStatus == MS_CLOSED); +}; + +MediaStateStatus videoLIVE555Source::getStatus( void ){ + return m_eMediaStatus; +}; + bool videoLIVE555Source::setSize( int Width, int Height ){ return false; }; bool videoLIVE555Source::setProportionalByWidth( int Width ){ return false; }; bool videoLIVE555Source::setProportionalByHeight( int Height ){ return false; }; diff --git a/lib/data/media/video/videoLive555AVLibSource.h b/lib/data/media/video/videoLive555AVLibSource.h index 9f334075..ee3afd2d 100644 --- a/lib/data/media/video/videoLive555AVLibSource.h +++ b/lib/data/media/video/videoLive555AVLibSource.h @@ -48,21 +48,19 @@ class CustomRTSPClient: public RTSPClient { StreamClientState& getStreamClientState() { return this->streamClientState; } videoLIVE555Source * getSession() { return this->session; } - protected: + virtual ~CustomRTSPClient(); + private: CustomRTSPClient( videoLIVE555Source *session, UsageEnvironment& env, char const* rtspURL, int verbosityLevel, char const* applicationName, portNumBits tunnelOverHTTPPortNum ); - virtual ~CustomRTSPClient(); }; class DummySink: public MediaSink { public: - static DummySink* createNew( videoLIVE555Source *session, - UsageEnvironment& env, - MediaSubsession& subsession, // identifies the kind of data that's being received + static DummySink* createNew( videoLIVE555Source *session, UsageEnvironment& env, MediaSubsession& subsession, // identifies the kind of data that's being received char const* streamId = NULL, int w = -1, int h = -1, int ww = -1, int hh = -1 ); // identifies the stream itself (optional) virtual ~DummySink(); private: @@ -79,12 +77,8 @@ class DummySink: public MediaSink { // called only by "createNew()" - static void afterGettingFrame(void* clientData, unsigned frameSize, - unsigned numTruncatedBytes, - struct timeval presentationTime, - unsigned durationInMicroseconds); - void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, - struct timeval presentationTime, unsigned durationInMicroseconds); + static void afterGettingFrame( void* clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds ); + void afterGettingFrame( unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds ); //void saveFrameToFile() private: // redefined virtual functions: @@ -94,7 +88,6 @@ class DummySink: public MediaSink { void setSprop( u_int8_t const* prop, unsigned size ); private: videoLIVE555Source * m_pSession; - private: uint8_t * m_pReceiveBuffer; uint8_t * m_pReceiveBufferAV; MediaSubsession & m_sSubSession; @@ -102,7 +95,6 @@ class DummySink: public MediaSink { H264or5VideoFileSink * qtOut; FILE * m_pOutFile[2]; uint8_t m_nCurrentOutFile; - private: AVCodec * m_pCodec; AVCodecContext * m_pCodecContext; @@ -144,7 +136,7 @@ class videoLIVE555Source : public basicMediaSource, public basicThread { UsageEnvironment * m_pUsageEnvironment; MediaSession * m_pMediaSession; - char _eventLoopWatchVariable; + volatile char _eventLoopWatchVariable; CustomRTSPClient * m_pRtspClient; DummySink * m_pSink;