Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

内存异常增长问题 #85

Open
11hwu2 opened this issue Oct 10, 2023 · 0 comments
Open

内存异常增长问题 #85

11hwu2 opened this issue Oct 10, 2023 · 0 comments

Comments

@11hwu2
Copy link

11hwu2 commented Oct 10, 2023

使用rtsp_h264_file推一个H264文件,在局域网内用ffplay指定udp传输数据播放。
在网络环境较好的情况下,进程内存占用在4MB左右,偶尔丢包导致马赛克,画面延时基本在1秒左右;
在网络环境不太好的情况下,存在大量丢包,ffplay会经常输出日志: RTP missed 2 packets ,画面马赛克严重.;进程长时间运行后,视频画面(对着时钟计数器)累积延时可以达到1分钟甚至更长(4分半钟),此时进程内存占用增长至40MB甚至更高(最高86MB)。

问题大概出在对trigger_events_的操作:

bool TaskScheduler::AddTriggerEvent(TriggerEvent callback)
{
	if (trigger_events_->Size() < kMaxTriggetEvents) {
		std::lock_guard<std::mutex> lock(mutex_);
		char event = kTriggetEvent;
		trigger_events_->Push(std::move(callback));
		wakeup_pipe_->Write(&event, 1);
		return true;
	}

	return false;
}

......

void TaskScheduler::HandleTriggerEvent()
{
	do 
	{
		TriggerEvent callback;
		if (trigger_events_->Pop(callback)) {
			callback();
		}
	} while (trigger_events_->Size() > 0);
}

TaskScheduler::AddTriggerEvent由读取H264帧的线程进行RTP封包后调用;
TaskScheduler::HandleTriggerEvent由任务调度主线程调用;
两个线程需要做好互斥处理,修改如下再测试,没有内存异常增长问题:

void TaskScheduler::HandleTriggerEvent()
{
    std::lock_guard<std::mutex> lock(mutex_);
	do 
	{
		TriggerEvent callback;
		if (trigger_events_->Pop(callback)) {
			callback();
		}
	} while (trigger_events_->Size() > 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant