diff --git a/lib/App/common/dataBinder_structures.h b/lib/App/common/dataBinder_structures.h index 4538c632..4d3cb56c 100644 --- a/lib/App/common/dataBinder_structures.h +++ b/lib/App/common/dataBinder_structures.h @@ -872,8 +872,10 @@ typedef struct S_DBC_RPC_MEDIA_INFO{ typedef struct S_DBC_SERVA_MEDIA_ENCODER_SETTINGS{ char CODEC[5]; uint8_t CRF; - char preset[32]; - char tune[32]; + uint8_t TH_MODE; + char preset[16]; + char tune[16]; + char profile[16]; uint32_t bitrate; char CONTAINER[5]; }DBC_SERVA_MEDIA_ENCODER_SETTINGS; diff --git a/lib/App/common/kernelModuleModemManager.cpp b/lib/App/common/kernelModuleModemManager.cpp index 31c6b0ae..9386ae7f 100644 --- a/lib/App/common/kernelModuleModemManager.cpp +++ b/lib/App/common/kernelModuleModemManager.cpp @@ -388,6 +388,7 @@ bool kernelModuleModemManager::dispatchEvent( EVENT_CONTAINER *Evt ){ case EVT_TARGET_3D_BLACK: case EVT_TARGET_2D_WHITE: case EVT_TARGET_2D_BLACK:{ + LOG("Start Session!"); sessionStarted = true; setWM( MDM_INIT_CALL_WM ); break; @@ -403,13 +404,21 @@ bool kernelModuleModemManager::dispatchEvent( EVENT_CONTAINER *Evt ){ }; bool kernelModuleModemManager::validate(){ - //LOG("Validate"); + LOG("Validate"); reloadSettings(); if ( moduleActive ) { if( m_sMMData.sms_enabled ){ // Get current WAN IP Address return updateWanIP(); +#ifdef DEBUG + } else { + LOG("SMS Disabled!"); +#endif }; +#ifdef DEBUG + } else { + LOG("Module is Disabled"); +#endif }; return true; }; @@ -592,6 +601,14 @@ bool kernelModuleModemManager::updateWanIP(){ }; pclose( fd ); }; +#ifdef DEBUG + if ( bDone ) { + sprintf( CMD, "WAN IP4: %s", m_cMyWanIP ); + LOG( CMD ); + } else { + LOG_ERROR("Cannot Find WAN IP4 Address!"); + }; +#endif return bDone; }; diff --git a/lib/App/serva/servaMediaEncoder.cpp b/lib/App/serva/servaMediaEncoder.cpp index d2d57f60..44cc6b94 100644 --- a/lib/App/serva/servaMediaEncoder.cpp +++ b/lib/App/serva/servaMediaEncoder.cpp @@ -19,6 +19,20 @@ servaMediaEncoder::servaMediaEncoder( uint64_t Ref ):basicThread(){ m_nInFileSize = 0; m_nOutFileSize = 0; m_bStatus = ENCODER_NONE; + DBC_SERVA_MEDIA_ENCODER_SETTINGS *tData = NULL;//m_pDBC->getMediaEncoderSettings(); + if( tData ){ + memcpy( &m_sEncoderSettings, tData, sizeof( DBC_SERVA_MEDIA_ENCODER_SETTINGS ) ); + } else { + memset( &m_sEncoderSettings, 0, sizeof( DBC_SERVA_MEDIA_ENCODER_SETTINGS )); + m_sEncoderSettings.CRF = 20; + strncpy( m_sEncoderSettings.preset, "medium", 15 ); + strncpy( m_sEncoderSettings.tune, "fastdecode", 15 ); + strncpy( m_sEncoderSettings.profile, "high422", 15 ); + m_sEncoderSettings.TH_MODE = FF_THREAD_FRAME; + m_sEncoderSettings.bitrate = 400000; + strncpy( m_sEncoderSettings.CONTAINER, "mp4", 4 ); + strncpy( m_sEncoderSettings.CODEC, "h264", 4 ); + } memset( &m_sDecoderVS, 0, sizeof(LIBAV_VS)); memset( &m_sEncoderVS, 0, sizeof(LIBAV_VS)); }; @@ -133,7 +147,7 @@ bool servaMediaEncoder::create( CSTR src, CSTR dst, uint8_t fps, int width, int Thread pool will be managed by FFmpeg itself, although some answers say that it is also possible using application-provided pool. */ //m_sDecoderVS.m_pCodecCtx->thread_count = 4; - m_sDecoderVS.m_pCodecCtx->thread_type = FF_THREAD_FRAME; + m_sDecoderVS.m_pCodecCtx->thread_type = m_sEncoderSettings.TH_MODE;//FF_THREAD_FRAME; //if (is_live) //m_sDecoderVS.m_pCodecCtx->thread_count = FF_THREAD_SLICE; //else @@ -242,9 +256,11 @@ bool servaMediaEncoder::create( CSTR src, CSTR dst, uint8_t fps, int width, int } else { LOG("Video Container Format Guessed"); }; - - if( av_dict_set( &m_sEncoderVS.m_pFormatOpts, "brand", "mp42", 0) < 0 ){ - LOG_ERROR( "av_dict_set brand!" ); + //In Case mp4 + if ( strcasestr( m_sEncoderSettings.CONTAINER, "mp4" ) ) { + if (av_dict_set(&m_sEncoderVS.m_pFormatOpts, "brand", "mp42", 0) < 0) { + LOG_ERROR( "av_dict_set brand!" ); + }; }; m_sEncoderVS.m_pVideoStr = avformat_new_stream( m_sEncoderVS.m_pFormatCtx, m_sEncoderVS.m_pVideoCodec ); @@ -253,9 +269,14 @@ bool servaMediaEncoder::create( CSTR src, CSTR dst, uint8_t fps, int width, int LOG_ERROR("VideoStream Not Created!"); }else{ LOG("VideoStream is Created"); - }; - - m_sEncoderVS.m_pVideoCodec = avcodec_find_encoder( av_guess_codec( m_sEncoderVS.m_pFormatCtx->oformat, NULL, m_sEncoderVS.m_pFileName, NULL, AVMEDIA_TYPE_VIDEO ) ); + }; + + //m_sEncoderVS.m_pVideoCodec = avcodec_find_encoder(av_guess_codec(m_sEncoderVS.m_pFormatCtx->oformat, NULL, m_sEncoderVS.m_pFileName, NULL, AVMEDIA_TYPE_VIDEO)); + if ( strcasestr( m_sEncoderSettings.CODEC, "h264" ) ) { + m_sEncoderVS.m_pVideoCodec = avcodec_find_encoder( AV_CODEC_ID_H264 ); + } else { + m_sEncoderVS.m_pVideoCodec = avcodec_find_encoder( AV_CODEC_ID_H265 ); + }; if( m_sEncoderVS.m_pVideoCodec == NULL ){ LOG_ERROR("VideoCodec Not Found!"); @@ -285,10 +306,13 @@ bool servaMediaEncoder::create( CSTR src, CSTR dst, uint8_t fps, int width, int m_sEncoderVS.m_pCodecCtx->time_base = av_make_q( 1, 10000 );//.num = 1; //m_sEncoderVS.m_pCodecCtx->time_base.den = fps; m_sEncoderVS.m_pCodecCtx->gop_size = fps << 1; // emit one intra frame every fps*2 frames - m_sEncoderVS.m_pCodecCtx->bit_rate = 400000; + m_sEncoderVS.m_pCodecCtx->bit_rate = m_sEncoderSettings.bitrate; //400000; m_sEncoderVS.m_pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P; //if (codec_id == AV_CODEC_ID_H264) - av_opt_set(m_sEncoderVS.m_pCodecCtx->priv_data, "preset", "slow", 0); + + //av_opt_set(m_sEncoderVS.m_pCodecCtx->priv_data, "preset", "slow", 0); + av_opt_set(m_sEncoderVS.m_pCodecCtx->priv_data, "preset", m_sEncoderSettings.preset, 0 ); + av_opt_set(m_sEncoderVS.m_pCodecCtx->priv_data, "profile", m_sEncoderSettings.profile, 0 ); //m_pCodecCtx->max_b_frames = 1; //m_pCodecCtx->level = 31; @@ -311,12 +335,15 @@ bool servaMediaEncoder::create( CSTR src, CSTR dst, uint8_t fps, int width, int /// Compression rate (lower -> higher compression) compress to lower size, makes decoded image more noisy /// Range: [0; 51], sane range: [18; 26]. I used 35 as good compression/quality compromise. This option also critical for realtime encoding - av_opt_set( m_sEncoderVS.m_pCodecCtx->priv_data, "crf", "20", 0); + //av_opt_set( m_sEncoderVS.m_pCodecCtx->priv_data, "crf", "20", 0); + char tBuf[16]; sprintf( tBuf, "%d", m_sEncoderSettings.CRF ); + av_opt_set(m_sEncoderVS.m_pCodecCtx->priv_data, "crf", tBuf, 0 ); /// Change settings based upon the specifics of input /// [psnr, ssim, grain, zerolatency, fastdecode, animation] - /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. + /// This option is most critical for realtime encoding, because it removes delay between 1th input frame and 1th output packet. //av_opt_set( m_sEncoderVS.m_pCodecCtx->priv_data, "tune", "zerolatency", 0); + av_opt_set( m_sEncoderVS.m_pCodecCtx->priv_data, "tune", m_sEncoderSettings.tune, 0); /// Disable b-pyramid. CLI options for this is "-b-pyramid 0" /// Because Quicktime (ie. iOS) doesn't support this option diff --git a/lib/App/serva/servaMediaEncoder.h b/lib/App/serva/servaMediaEncoder.h index 9de730cd..b4a68675 100644 --- a/lib/App/serva/servaMediaEncoder.h +++ b/lib/App/serva/servaMediaEncoder.h @@ -1,7 +1,7 @@ #ifndef __LA_SERVA_MEDIA_ENCODER_HEADER__ #define __LA_SERVA_MEDIA_ENCODER_HEADER__ - +#include "../common/serverMySQL_dataBinder.h" #include "../../components/base/basicThread.h" #include "../../components/base/basicMutex.h" #include "../../components/base/basicLIBAV.h" @@ -42,6 +42,7 @@ class servaKernel; class servaMediaEncoder: public basicThread{ private: basicLogCollection * m_pLog; + DBC_SERVA_MEDIA_ENCODER_SETTINGS m_sEncoderSettings; uint64_t m_nInFileSize; uint64_t m_nReadSize; uint64_t m_nOutFileSize;