请帮我完善代码,杜绝内存泄漏以及优化错误的地方 push.cpp: #include "Pusher.h" #include <iostream> #include…
- User
请帮我完善代码,杜绝内存泄漏以及优化错误的地方 push.cpp: #include "Pusher.h" #include #include "Common/config.h" #include "appPublic.h" #include "FifoMsg.h"
using namespace std; using namespace mediakit; using namespace toolkit;
enum AVCodeConst { AV_CODER_NONE = 0, AV_VIDEO_CODER_H264 = 1, AV_VIDEO_CODER_HEVC = 2, AV_AUDIO_CODER_AAC = 3 };
enum EnumFrameType { FRAME_TYPE_VIDEO = 0, FRAME_TYPE_AUDIO = 1, };
#define PUSH_FIELD "push." const string kEnableAAC2G711A = PUSH_FIELD"EnableAAC2G711A";
#define MAX_WRITE_FAILED_TIME (10)
Pusher::Pusher(const SdpInfo &p_SdpInfo) :m_bIsInitOK(false) ,m_SdpInfo(p_SdpInfo) ,m_audioIdx(0) ,m_videoIdx(0) ,m_ofmt_ctx(NULL) ,aac_swr_ctx(NULL) ,pAcodecContext(NULL) ,alaw_codecContext(NULL) ,m_writeFailedTime(0){
int nInitFlag = init(); if (nInitFlag == 0){ m_bIsInitOK = true; InfoL<<"create pusher success,dev:"<<m_SdpInfo.szPlayUrl; } else{ nInitFlag = false; InfoL<<"create pusher failed,dev:"<<m_SdpInfo.szPlayUrl; release(); return; }}
Pusher::~Pusher(){ release(); InfoL<<m_SdpInfo.szPlayUrl<<" pusher is released"; }
void Pusher::release(){ if(m_ofmt_ctx == NULL) return;
av_write_trailer(m_ofmt_ctx); if (!(m_ofmt_ctx->flags & AVFMT_NOFILE)) { avio_close(m_ofmt_ctx->pb); } avformat_free_context(m_ofmt_ctx); m_ofmt_ctx = NULL; if(pAcodecContext){ avcodec_free_context(&pAcodecContext); pAcodecContext = NULL; } if (alaw_codecContext){ avcodec_free_context(&alaw_codecContext); alaw_codecContext = NULL; }}
void Pusher::ffLogCallback(void *ptr, int level, const char *fmt, va_list vl) { if (level > av_log_get_level()) return;
char temp[1024]; vsprintf(temp, fmt, vl); size_t len = strlen(temp); if (len > 0 && len < 1024&&temp[len - 1] == '\n') { temp[len - 1] = '\0'; } DebugL << (char *)temp;}
/* select layout with the highest channel count */ uint64_t Pusher::select_channel_layout(const AVCodec *codec) { if (!codec) return AV_CH_LAYOUT_STEREO;
const uint64_t *p; uint64_t best_ch_layout = 0; int best_nb_channels = 0; if (!codec->channel_layouts) return AV_CH_LAYOUT_STEREO; p = codec->channel_layouts; while (*p) { int nb_channels = av_get_channel_layout_nb_channels(*p); if (nb_channels > best_nb_channels) { best_ch_layout = *p; best_nb_channels = nb_channels; } p++; } return best_ch_layout;}
int Pusher::select_sample_rate(const AVCodec *codec) { if (!codec) return 44100;
const int *p; int best_samplerate = 0; if (!codec->supported_samplerates) return 44100; p = codec->supported_samplerates; while (*p) { if (!best_samplerate || abs(44100 - *p) < abs(44100 - best_samplerate)) best_samplerate = *p; p++; } return best_samplerate; - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.