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

fix memory leak: live_player_activity: re call the fn showDialog #330

Merged
merged 10 commits into from
May 3, 2024

Conversation

lanytcc
Copy link
Contributor

@lanytcc lanytcc commented May 2, 2024

fix #329

@xfangfang
Copy link
Owner

感谢,原来是轮播视频造成的问题,那里还没写完,当时匆忙加了个临时的未开播对话框。

@@ -279,6 +279,7 @@ void LiveActivity::onLiveData(const bilibili::LiveRoomPlayInfo& result) {
// todo: 支持轮播视频
this->video->showOSD(false);
showDialog("未开播", "pictures/sorry.png", true);
return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和对话框相关的所有修复,我认为只加这一个return就足够了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加上这个就不会触发 tl_event_id 所绑定的事件回调中的this->retryRequestData()了吗?
如果主播关播了,不是应该是会走result.live_status == 0的?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关播了之后应该有两种情况,这里对应的是轮播投稿视频的情况。
正常情况下关播了之后:1. mpv 会报错 2. 报错后等待几秒会重新请求直播间数据 3. 如果请求到的是直播间正常,那就继续尝试播放(这种情况对应网络波动)4. 如果请求到的是直播间关闭 那就显示一个对话框,然后return

这里是之前忘记加return 导致继续尝试播放,进而无限循环。

我一时半会找不到有轮播的直播间来测试,如果你方便找历史记录的话,可以对比看一看是否真的修复了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那这个逻辑确实用不上这样写,我先改回去

@@ -100,7 +100,7 @@ void LiveActivity::setCommonData() {
MPVCore::instance().reset();

// 清空自定义着色器
ShaderHelper::instance().clearShader(false);
// ShaderHelper::instance().clearShader(false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要注释掉呢?当时加了这个是因为我感觉直播间应该用不上着色器,但是B站确实老是放开给小主播放盗版视频,如果是因为这些低清盗版视频的缘故,那可以将这句完全删掉了~

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -60,6 +60,7 @@ LiveDanmaku::~LiveDanmaku() {
#ifdef _WIN32
WSACleanup();
#endif
while (!msg_q.empty()) msg_q.pop();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是加个锁好一些,避免在PSV上有问题(我感觉正常设备应该不加锁也没问题,PSV是太卡了避免它发生乱七八糟的问题)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我现在跑wiliwili的设备就非常。。。性能什么的还说得过去,就是他那个cpu不支持乱序,然后就老报错:无网络连接。这里是因为已经disconnect过了,我觉得只要没有同时两个LiveActivity在跑应该问题不大。但是保险起见,我还是等会加一下锁吧

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个其实是有可能同时存在两个 LiveActivity 的,因为上一个 LiveActivity 的关闭不是立刻发生的,他有一个关闭的动画,动画运行结束之后才会销毁。在PSV这种设备上执行的可能会很慢,导致网络速度比动画速度还快,因此快速关闭打开的时候就可能出现两个 LiveActivity 同时存在的情况。

顺便一提,为什么要调整这里的单例呀,也是因为网络问题吗?我看前面有 WSAStartup 不知道这个函数反复调用对性能有没有影响。(我感觉应该还好)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WSAStartup可以移到main函数里面,这玩意反复调用也是增加引用计数,但如果能调用一次最好。我来把它提出来

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果要换个位置的话,可以放在 ProgramConfig::initProgramConfig::exit 里,如果影响不大的话就不用改了 : )

auto fnSymGetModuleInfo64 = (WINBOOL(WINAPI*)(HANDLE, DWORD64, PIMAGEHLP_MODULE64))::GetProcAddress(dbghelp, "SymGetModuleInfo64");
auto fnSymGetSymFromAddr64 = (BOOL(WINAPI*)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64))::GetProcAddress(dbghelp, "SymGetSymFromAddr64");
auto fnSymGetLineFromAddr64 = (BOOL(WINAPI*)(HANDLE, DWORD64, PDWORD, PIMAGEHLP_LINE64))::GetProcAddress(dbghelp, "SymGetLineFromAddr64");
auto fnSymGetModuleInfo64 = (BOOL(WINAPI*)(HANDLE, DWORD64, PIMAGEHLP_MODULE64))::GetProcAddress(dbghelp, "SymGetModuleInfo64");
auto fnSymFTA64 = (PFUNCTION_TABLE_ACCESS_ROUTINE64)::GetProcAddress(dbghelp, "SymFunctionTableAccess64");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的修改是因为 xmake 脚本编译不过嘛?这个部分只能麻烦 @dragonflylee 来看一下啦,感谢感谢🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我在win api里面没找到winbool相关的描述,倒是在mingw有。而且定义也很简单typedef int BOOL,应该问题不大

WSADATA wsaData;
int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (result != 0) {
printf("WSAStartup failed with error: %d\n", result);
Copy link
Owner

@xfangfang xfangfang May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抱歉,再提一个点,可以把这里的 printf 换成 brls::Logger::error 嘛?万一真的出错了,用brls::Logger可以记录下log来


brls::Logger::error("WSAStartup failed with error: {}", result); 

@xfangfang xfangfang merged commit a319bbe into xfangfang:dev May 3, 2024
16 checks passed
@xfangfang
Copy link
Owner

非常感谢~

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

Successfully merging this pull request may close these issues.

2 participants