diff --git a/server/Process.h b/server/Process.h index cd0b2917..db752232 100644 --- a/server/Process.h +++ b/server/Process.h @@ -29,10 +29,12 @@ public: bool wait(bool block = true); int exit_code(); private: + int _exit_code = 0; pid_t _pid = -1; void *_handle = nullptr; - void* _process_stack = nullptr; - int _exit_code = 0; +#if (defined(__linux) || defined(__linux__)) + void *_process_stack = nullptr; +#endif }; diff --git a/src/Codec/Transcode.cpp b/src/Codec/Transcode.cpp index 989dcda7..18d0cfae 100644 --- a/src/Codec/Transcode.cpp +++ b/src/Codec/Transcode.cpp @@ -386,7 +386,7 @@ FFmpegDecoder::FFmpegDecoder(const Track::Ptr &track, int thread_num) { if (thread_num <= 0) { av_dict_set(&dict, "threads", "auto", 0); } else { - av_dict_set(&dict, "threads", to_string(MIN(thread_num, thread::hardware_concurrency())).data(), 0); + av_dict_set(&dict, "threads", to_string(MIN((unsigned int)thread_num, thread::hardware_concurrency())).data(), 0); } av_dict_set(&dict, "zerolatency", "1", 0); av_dict_set(&dict, "strict", "-2", 0); diff --git a/src/Extension/AAC.cpp b/src/Extension/AAC.cpp index 1d923271..ea57d643 100644 --- a/src/Extension/AAC.cpp +++ b/src/Extension/AAC.cpp @@ -132,7 +132,8 @@ string makeAacConfig(const uint8_t *hex, size_t length){ audioSpecificConfig[1] = (sampling_frequency_index << 7) | (channel_configuration << 3); return string((char *)audioSpecificConfig,2); #else - struct mpeg4_aac_t aac = {0}; + struct mpeg4_aac_t aac; + memset(&aac, 0, sizeof(aac)); if (mpeg4_aac_adts_load(hex, length, &aac) > 0) { char buf[32] = {0}; int len = mpeg4_aac_audio_specific_config_save(&aac, (uint8_t *) buf, sizeof(buf)); @@ -153,7 +154,8 @@ int dumpAacConfig(const string &config, size_t length, uint8_t *out, size_t out_ dumpAdtsHeader(header, out); return ADTS_HEADER_LEN; #else - struct mpeg4_aac_t aac = {0}; + struct mpeg4_aac_t aac; + memset(&aac, 0, sizeof(aac)); int ret = mpeg4_aac_audio_specific_config_load((uint8_t *) config.data(), config.size(), &aac); if (ret > 0) { ret = mpeg4_aac_adts_save(&aac, length, out, out_size); @@ -174,7 +176,8 @@ bool parseAacConfig(const string &config, int &samplerate, int &channels){ channels = header.channel_configuration; return true; #else - struct mpeg4_aac_t aac = {0}; + struct mpeg4_aac_t aac; + memset(&aac, 0, sizeof(aac)); int ret = mpeg4_aac_audio_specific_config_load((uint8_t *) config.data(), config.size(), &aac); if (ret > 0) { samplerate = aac.sampling_frequency; @@ -284,7 +287,7 @@ bool AACTrack::inputFrame(const Frame::Ptr &frame) { if (frame_len < ADTS_HEADER_LEN) { break; } - if (frame_len == frame->size()) { + if (frame_len == (int)frame->size()) { return inputFrame_l(frame); } auto sub_frame = std::make_shared >(frame, (char *) ptr, frame_len, ADTS_HEADER_LEN,dts,pts); diff --git a/src/Extension/H265Rtmp.cpp b/src/Extension/H265Rtmp.cpp index 54f9aeb5..19e450e8 100644 --- a/src/Extension/H265Rtmp.cpp +++ b/src/Extension/H265Rtmp.cpp @@ -49,7 +49,8 @@ static bool getH265ConfigFrame(const RtmpPacket &thiz,string &frame) { auto extra = thiz.buffer.data() + 5; auto bytes = thiz.buffer.size() - 5; - struct mpeg4_hevc_t hevc = {0}; + struct mpeg4_hevc_t hevc; + memset(&hevc, 0, sizeof(hevc)); if (mpeg4_hevc_decoder_configuration_record_load((uint8_t *) extra, bytes, &hevc) > 0) { uint8_t *config = new uint8_t[bytes * 2]; int size = mpeg4_hevc_to_nalu(&hevc, config, bytes * 2); @@ -207,7 +208,8 @@ void H265RtmpEncoder::makeVideoConfigPkt() { //cts rtmpPkt->buffer.append("\x0\x0\x0", 3); - struct mpeg4_hevc_t hevc = {0}; + struct mpeg4_hevc_t hevc; + memset(&hevc, 0, sizeof(hevc)); string vps_sps_pps = string("\x00\x00\x00\x01", 4) + _vps + string("\x00\x00\x00\x01", 4) + _sps + string("\x00\x00\x00\x01", 4) + _pps; diff --git a/src/Http/HttpCookieManager.cpp b/src/Http/HttpCookieManager.cpp index 2c514451..2ce0f188 100644 --- a/src/Http/HttpCookieManager.cpp +++ b/src/Http/HttpCookieManager.cpp @@ -67,7 +67,7 @@ void HttpServerCookie::setAttach(std::shared_ptr attach) { string HttpServerCookie::cookieExpireTime() const { char buf[64]; - time_t tt = time(NULL) + _max_elapsed; + time_t tt = time(nullptr) + _max_elapsed; strftime(buf, sizeof buf, "%a, %b %d %Y %H:%M:%S GMT", gmtime(&tt)); return buf; } @@ -105,8 +105,8 @@ void HttpCookieManager::onManager() { } if (it_name->second.empty()) { - //该类型下没有任何cooki记录,移除之 - DebugL << "该path下没有任何cooki记录:" << it_name->first; + //该类型下没有任何cookie记录,移除之 + DebugL << "该path下没有任何cookie记录:" << it_name->first; it_name = _map_cookie.erase(it_name); continue; } @@ -117,7 +117,7 @@ void HttpCookieManager::onManager() { HttpServerCookie::Ptr HttpCookieManager::addCookie(const string &cookie_name, const string &uid_in, uint64_t max_elapsed, std::shared_ptr attach, int max_client) { lock_guard lck(_mtx_cookie); - auto cookie = _geneator.obtain(); + auto cookie = _generator.obtain(); auto uid = uid_in.empty() ? cookie : uid_in; auto oldCookie = getOldestCookie(cookie_name, uid, max_client); if (!oldCookie.empty()) { @@ -159,13 +159,13 @@ HttpServerCookie::Ptr HttpCookieManager::getCookie(const string &cookie_name, co return nullptr; } auto cookie = FindField(it->second.data(), (cookie_name + "=").data(), ";"); - if (!cookie.size()) { + if (cookie.empty()) { cookie = FindField(it->second.data(), (cookie_name + "=").data(), nullptr); } if (cookie.empty()) { return nullptr; } - return HttpCookieManager::Instance().getCookie(cookie_name, cookie); + return getCookie(cookie_name, cookie); } HttpServerCookie::Ptr HttpCookieManager::getCookieByUid(const string &cookie_name, const string &uid) { @@ -205,7 +205,7 @@ void HttpCookieManager::onAddCookie(const string &cookie_name, const string &uid void HttpCookieManager::onDelCookie(const string &cookie_name, const string &uid, const string &cookie) { lock_guard lck(_mtx_cookie); //回收随机字符串 - _geneator.release(cookie); + _generator.release(cookie); auto it_name = _map_uid_to_cookie.find(cookie_name); if (it_name == _map_uid_to_cookie.end()) { @@ -227,14 +227,14 @@ void HttpCookieManager::onDelCookie(const string &cookie_name, const string &uid //移除该用户名下的某个cookie,这个设备cookie将失效 it_uid->second.erase(it_cookie); - if (it_uid->second.size() != 0) { + if (!it_uid->second.empty()) { break; } //该用户名下没有任何设备在线,移除之 it_name->second.erase(it_uid); - if (it_name->second.size() != 0) { + if (!it_name->second.empty()) { break; } //该类型下未有任何用户在线,移除之 @@ -255,7 +255,7 @@ string HttpCookieManager::getOldestCookie(const string &cookie_name, const strin //该用户从未登录过 return ""; } - if (it_uid->second.size() < MAX(1, max_client)) { + if ((int)it_uid->second.size() < MAX(1, max_client)) { //同一名用户下,客户端个数还没达到限制个数 return ""; } @@ -263,8 +263,8 @@ string HttpCookieManager::getOldestCookie(const string &cookie_name, const strin return it_uid->second.begin()->second; } -/////////////////////////////////RandStrGeneator//////////////////////////////////// -string RandStrGeneator::obtain() { +/////////////////////////////////RandStrGenerator//////////////////////////////////// +string RandStrGenerator::obtain() { //获取唯一的防膨胀的随机字符串 while (true) { auto str = obtain_l(); @@ -276,12 +276,12 @@ string RandStrGeneator::obtain() { } } -void RandStrGeneator::release(const string &str) { +void RandStrGenerator::release(const string &str) { //从防膨胀库中移除 _obtained.erase(str); } -string RandStrGeneator::obtain_l() { +string RandStrGenerator::obtain_l() { // 12个伪随机字节 + 4个递增的整形字节,然后md5即为随机字符串 auto str = makeRandStr(12, false); str.append((char *)&_index, sizeof(_index)); diff --git a/src/Http/HttpCookieManager.h b/src/Http/HttpCookieManager.h index ccdc0fd0..f1dcfa68 100644 --- a/src/Http/HttpCookieManager.h +++ b/src/Http/HttpCookieManager.h @@ -111,10 +111,10 @@ private: /** * cookie随机字符串生成器 */ -class RandStrGeneator { +class RandStrGenerator { public: - RandStrGeneator() = default; - ~RandStrGeneator() = default; + RandStrGenerator() = default; + ~RandStrGenerator() = default; /** * 获取不碰撞的随机字符串 @@ -244,7 +244,7 @@ private: _map_uid_to_cookie; std::recursive_mutex _mtx_cookie; toolkit::Timer::Ptr _timer; - RandStrGeneator _geneator; + RandStrGenerator _generator; }; } // namespace mediakit diff --git a/src/Record/MP4Demuxer.cpp b/src/Record/MP4Demuxer.cpp index 4ea3fc83..a1c657fd 100644 --- a/src/Record/MP4Demuxer.cpp +++ b/src/Record/MP4Demuxer.cpp @@ -96,7 +96,8 @@ void MP4Demuxer::onVideoTrack(uint32_t track, uint8_t object, int width, int hei auto video = std::make_shared(); _track_to_codec.emplace(track,video); - struct mpeg4_avc_t avc = {0}; + struct mpeg4_avc_t avc; + memset(&avc, 0, sizeof(avc)); if (mpeg4_avc_decoder_configuration_record_load((uint8_t *) extra, bytes, &avc) > 0) { uint8_t config[1024 * 10] = {0}; int size = mpeg4_avc_to_nalu(&avc, config, sizeof(config)); @@ -110,7 +111,8 @@ void MP4Demuxer::onVideoTrack(uint32_t track, uint8_t object, int width, int hei auto video = std::make_shared(); _track_to_codec.emplace(track,video); - struct mpeg4_hevc_t hevc = {0}; + struct mpeg4_hevc_t hevc; + memset(&hevc, 0, sizeof(hevc)); if (mpeg4_hevc_decoder_configuration_record_load((uint8_t *) extra, bytes, &hevc) > 0) { uint8_t config[1024 * 10] = {0}; int size = mpeg4_hevc_to_nalu(&hevc, config, sizeof(config)); @@ -160,12 +162,13 @@ int64_t MP4Demuxer::seekTo(int64_t stamp_ms) { return stamp_ms; } -struct Context{ +struct Context { + Context(MP4Demuxer *ptr) : thiz(ptr) {} MP4Demuxer *thiz; - int flags; - int64_t pts; - int64_t dts; - uint32_t track_id; + int flags = 0; + int64_t pts = 0; + int64_t dts = 0; + uint32_t track_id = 0; BufferRaw::Ptr buffer; }; @@ -188,7 +191,7 @@ Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame, bool &eof) { return ctx->buffer->data() + DATA_OFFSET; }; - Context ctx = {this, 0}; + Context ctx(this); auto ret = mov_reader_read2(_mov_reader.get(), mov_onalloc, &ctx); switch (ret) { case 0 : { diff --git a/src/Record/MP4Muxer.cpp b/src/Record/MP4Muxer.cpp index f9a13fe6..0b4357a6 100644 --- a/src/Record/MP4Muxer.cpp +++ b/src/Record/MP4Muxer.cpp @@ -221,7 +221,8 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) { return false; } - struct mpeg4_avc_t avc = {0}; + struct mpeg4_avc_t avc; + memset(&avc, 0, sizeof(avc)); string sps_pps = string("\x00\x00\x00\x01", 4) + h264_track->getSps() + string("\x00\x00\x00\x01", 4) + h264_track->getPps(); h264_annexbtomp4(&avc, sps_pps.data(), (int) sps_pps.size(), NULL, 0, NULL, NULL); @@ -256,7 +257,8 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) { return false; } - struct mpeg4_hevc_t hevc = {0}; + struct mpeg4_hevc_t hevc; + memset(&hevc, 0, sizeof(hevc)); string vps_sps_pps = string("\x00\x00\x00\x01", 4) + h265_track->getVps() + string("\x00\x00\x00\x01", 4) + h265_track->getSps() + string("\x00\x00\x00\x01", 4) + h265_track->getPps(); diff --git a/srt/PacketQueue.cpp b/srt/PacketQueue.cpp index 9349f050..9dcdf9e5 100644 --- a/srt/PacketQueue.cpp +++ b/srt/PacketQueue.cpp @@ -237,12 +237,12 @@ std::string PacketQueue::dump() { //////////////////// PacketRecvQueue ////////////////////////////////// -PacketRecvQueue::PacketRecvQueue(uint32_t max_size, uint32_t init_seq, uint32_t latency,uint32_t flag) +PacketRecvQueue::PacketRecvQueue(uint32_t max_size, uint32_t init_seq, uint32_t latency, uint32_t flag) : _pkt_cap(max_size) , _pkt_latency(latency) , _pkt_expected_seq(init_seq) - , _pkt_buf(max_size) - , _srt_flag(flag) {} + , _srt_flag(flag) + , _pkt_buf(max_size) {} bool PacketRecvQueue::TLPKTDrop(){ return (_srt_flag&HSExtMessage::HS_EXT_MSG_TLPKTDROP) && (_srt_flag &HSExtMessage::HS_EXT_MSG_TSBPDRCV); diff --git a/srt/PacketSendQueue.cpp b/srt/PacketSendQueue.cpp index 06beddde..3cd2b8f2 100644 --- a/srt/PacketSendQueue.cpp +++ b/srt/PacketSendQueue.cpp @@ -3,9 +3,9 @@ namespace SRT { PacketSendQueue::PacketSendQueue(uint32_t max_size, uint32_t latency,uint32_t flag) - : _pkt_cap(max_size) - , _pkt_latency(latency) - , _srt_flag(flag) {} + : _srt_flag(flag) + , _pkt_cap(max_size) + , _pkt_latency(latency) {} bool PacketSendQueue::drop(uint32_t num) { decltype(_pkt_cache.begin()) it; diff --git a/tests/test_rtp.cpp b/tests/test_rtp.cpp index 4826c821..441d1563 100644 --- a/tests/test_rtp.cpp +++ b/tests/test_rtp.cpp @@ -37,7 +37,8 @@ static bool loadFile(const char *path){ uint64_t timeStamp_last = 0; uint16_t len; char rtp[0xFFFF]; - struct sockaddr_storage addr = {0}; + struct sockaddr_storage addr; + memset(&addr, 0, sizeof(addr)); addr.ss_family = AF_INET; auto sock = Socket::createSocket(); size_t total_size = 0;