优化代码,去除编译警告,修复拼写错误

This commit is contained in:
ziyue 2022-08-08 17:36:07 +08:00
parent 9c3b8a6a95
commit 35791aac89
11 changed files with 57 additions and 44 deletions

View File

@ -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;
#if (defined(__linux) || defined(__linux__))
void *_process_stack = nullptr;
int _exit_code = 0;
#endif
};

View File

@ -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);

View File

@ -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<FrameTSInternal<FrameFromPtr> >(frame, (char *) ptr, frame_len, ADTS_HEADER_LEN,dts,pts);

View File

@ -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;

View File

@ -67,7 +67,7 @@ void HttpServerCookie::setAttach(std::shared_ptr<void> 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<void> attach, int max_client) {
lock_guard<recursive_mutex> 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<recursive_mutex> 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));

View File

@ -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

View File

@ -96,7 +96,8 @@ void MP4Demuxer::onVideoTrack(uint32_t track, uint8_t object, int width, int hei
auto video = std::make_shared<H264Track>();
_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<H265Track>();
_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));
@ -161,11 +163,12 @@ int64_t MP4Demuxer::seekTo(int64_t stamp_ms) {
}
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 : {

View File

@ -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();

View File

@ -241,8 +241,8 @@ PacketRecvQueue::PacketRecvQueue(uint32_t max_size, uint32_t init_seq, uint32_t
: _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);

View File

@ -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;

View File

@ -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;