当前位置:网站首页>Player actual combat 25 unpacking module add close
Player actual combat 25 unpacking module add close
2022-06-12 14:12:00 【Sister Suo】
With the increase of open multimedia files , More and more memory will be used :

The starting point for accessing media files is through xplay2.cpp Medium xdemuxthread.open(), Therefore, cleaning also starts from xdemuxthread Start :
void xdemuxthread::Close()
{
isexit = true;
wait();
if (vt) vt->Close();
if (at) at->Close();
mux.lock();
delete vt;
delete at;
vt = NULL;
at = NULL;
mux.unlock();
}
1.vt And at It is called by unpacking threads , Because the unpacking thread is responsible for cleaning up vt And at
2. To prevent the pointer from being deleted to half , Then other threads suddenly use the deleted pointer to cause bug, So lock these four sentences
3. After we delete a pointer , The compiler only frees the memory space that the pointer points to , Instead of deleting the pointer itself , So we have to put these new Out pointer setting null
about vt And at Of close Come on , Most of their functions are the same , So put the same functionality in their common base class xdecodethread in :
void xdecodethread::Close()
{
Clear();
// Wait for thread to exit
isexit = true;
wait();
decode->close();
mux.lock();
delete decode;
decode = NULL;
mux.unlock();
}
class xaudiothread:public xdecodethread
{
public:
long long pts = 0;
xaudiothread();
virtual ~xaudiothread();
void run();
virtual bool open(AVCodecParameters* par, int samplerate, int channels);
protected:
std::mutex amux;
xaudioplay* audioplay=0;
xresample* resample=0;
};
```cpp
class xvideothread:public xdecodethread
{
public:
xvideothread();
virtual ~xvideothread();
virtual bool open(AVCodecParameters*par,ivideocall*call,int width,int height);
void run();
long long synpts = 0;
protected:
xvideowidget* video=0;
ivideocall* call = 0;
std::mutex vmux;
};
Next, we will deal with the special part :
Audio thread specific res And ap
void xaudiothread::Close()
{
xdecodethread::Close();
if (resample)
{
resample->Close();
amux.lock();
delete resample;
resample = NULL;
amux.unlock();
}
if (audioplay)
{
audioplay->close();
amux.lock();
audioplay = NULL;
amux.unlock();
}
}
First call the cleanup common part of its parent class , Clean up your own unique parts
audioplay It's a singleton mode , Unwanted delete
The singleton pattern : Make sure there is only one instance of a class , And provide a global access point for the instance . ——《 Design patterns 》GoF
In software system , There are often special classes like this , It must be ensured that there is only one instance of them in the system , To ensure their logical correctness 、 And good efficiency .
For different media files , They all use the same audioplay
stay xplay2 The... Is called in the destructor of close:
Xplay2::~Xplay2()
{
dt.Close();
}
But it was found that there was no egg
You can see from the graph of process memory that the memory occupied 2G, Therefore, the decoded video data is not released
Then look at the... About decoding receive(), Sure enough, something went wrong here :
// Maybe once send many times receive
while (!isexit)
{
AVFrame* frame = decode->receive();
if (!frame)break;
if(call)
{
call->Repaint(frame);
}
else {
cout << "repaint fail " << endl;
}
av_frame_free(&frame);
}
When received from the decoding queue frame to repaint After finishing , This frame It's useless. , So with av_frame_free(&frame) Release it 
At this time, the process memory is stable in 250MB about , Audio or video data per frame , After it is played or drawn , Will be released immediately .
边栏推荐
- Greed issues - Egypt scores
- 单总线温度传感器18B20数据上云(阿里云)
- Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode
- Leetcode 2185. Counts the string containing the given prefix
- Summary of virtual box usage problems
- 编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构
- Shell notes
- 使用make方法创建slice切片的坑
- [semidrive source code analysis] [x9 chip startup process] 25 - Introduction to mailbox inter core communication mechanism (code analysis) rpmsg-ipcc RTOS & QNX
- SystemC uses SC_ report_ Handler processing log printing
猜你喜欢

通过loganalyzer展示数据库中的日志

高考回憶錄

Alicloud development board vscode development environment setup

Redis core configuration and advanced data types

chrome://tracing Performance analysis artifact

CSDN博客积分规则

如果要打造品牌知名度,可以选择什么出价策略?

Tlm/systemc: TLM socket binding problem

Implementation of Ackermann function with simulated recursion

Leetcode 2176. 统计数组中相等且可以被整除的数对
随机推荐
Paw advanced user guide
Player actual combat 12 QT playing audio
Alibaba cloud development board haas510 connects to the Internet of things platform -- Haas essay solicitation
Llvm 13.1 new pass plug-in form [for win]
Codeforces Round #798 (Div. 2)(A~D)
chapter19 Allocation
SystemC time
Create a small root heap and judge the node relationship (also.C\u str() substr(),atoi(),string. Use of find())
3. Hidden processes under the ring
动态搜索广告智能查找匹配关键字
[advanced MySQL] evolution of MySQL index data structure (IV)
My resume.
Create a slice slice pit using the make method
Leetcode questions brushing February /1020 Number of enclaves
chrome://tracing Performance analysis artifact
Details of bypassing safeseh mechanism by using modules that do not enable safeseh
Lua common built-in functions
Display logs in the database through loganalyzer
CSDN博客积分规则
什么是自动出价?它的优势是什么?