Draft
[WIP]修复升级ffmpeg8.0遗留问题 #239
linsanjiuAdd on Jul 17
[WIP]修复升级ffmpeg8.0遗留问题 #239
Draft
Total: 3 files changed+6-16
| @@ -14,7 +14,9 @@ | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | import IjkplayerXtsTest from './IjkplayerXtsTest.test'; | 16 | import IjkplayerXtsTest from './IjkplayerXtsTest.test'; |
| 17 | +import abilityTest from './Ability.test'; | ||
| 17 | 18 | ||
| 18 | export default function testsuite() { | 19 | export default function testsuite() { |
| 19 | IjkplayerXtsTest(); | 20 | IjkplayerXtsTest(); |
| 21 | + abilityTest(); | ||
| 20 | } | 22 | } |
| @@ -1648,26 +1648,16 @@ void UpdateRecordResult(void *ffp, int result) | |||
| 1648 | 1648 | ||
| 1649 | int FindRecordResult(void *ffp) | 1649 | int FindRecordResult(void *ffp) |
| 1650 | { | 1650 | { |
| 1651 | - int preHit = 0; | ||
| 1652 | - | ||
| 1653 | if (!ffp) { | 1651 | if (!ffp) { |
| 1654 | LOGE("findRecordResult ffp null"); | 1652 | LOGE("findRecordResult ffp null"); |
| 1655 | return OHOS_RECORD_CALLBACK_STATUS_FAILED; | 1653 | return OHOS_RECORD_CALLBACK_STATUS_FAILED; |
| 1656 | } | 1654 | } |
| 1657 | - { | 1655 | + /* Caller already pthread_join'd the record thread; result is ready. */ |
| 1658 | - auto pre = ijkplayerRecordResultMap.find(ffp); | ||
| 1659 | - preHit = (pre != ijkplayerRecordResultMap.end()) ? 1 : 0; | ||
| 1660 | - } | ||
| 1661 | - sleep(SLEEP_TIME_2); | ||
| 1662 | auto it = ijkplayerRecordResultMap.find(ffp); | 1656 | auto it = ijkplayerRecordResultMap.find(ffp); |
| 1663 | if (it != ijkplayerRecordResultMap.end()) { | 1657 | if (it != ijkplayerRecordResultMap.end()) { |
| 1664 | - return it->second; | 1658 | + int result = it->second; |
| 1665 | - } else { | 1659 | + ijkplayerRecordResultMap.erase(it); |
| 1666 | - sleep(SLEEP_TIME_5); | 1660 | + return result; |
| 1667 | - auto it2 = ijkplayerRecordResultMap.find(ffp); | ||
| 1668 | - if (it2 != ijkplayerRecordResultMap.end()) { | ||
| 1669 | - return it2->second; | ||
| 1670 | - } | ||
| 1671 | } | 1661 | } |
| 1672 | LOGE("findRecordResult not find"); | 1662 | LOGE("findRecordResult not find"); |
| 1673 | return OHOS_RECORD_CALLBACK_STATUS_FAILED; | 1663 | return OHOS_RECORD_CALLBACK_STATUS_FAILED; |
| @@ -77,8 +77,6 @@ extern "C" { | |||
| 77 | #define VIDEO_BIT_RATE (2028 * 1024) | 77 | #define VIDEO_BIT_RATE (2028 * 1024) |
| 78 | #define SLEEP_TIME 1000 | 78 | #define SLEEP_TIME 1000 |
| 79 | #define SLEEP_TIME_100 100 | 79 | #define SLEEP_TIME_100 100 |
| 80 | -#define SLEEP_TIME_2 2 | ||
| 81 | -#define SLEEP_TIME_5 5 | ||
| 82 | #define DATA_NUM_110 110.0 | 80 | #define DATA_NUM_110 110.0 |
| 83 | #define OHOS_CALLBACK_RESULT_STATUS_SUCCESS 1 | 81 | #define OHOS_CALLBACK_RESULT_STATUS_SUCCESS 1 |
| 84 | #define OHOS_CALLBACK_RESULT_STATUS_FAILED 0 | 82 | #define OHOS_CALLBACK_RESULT_STATUS_FAILED 0 |
【AI-Review】【建议】【基础代码问题】【资源使用问题】ijkplayerRecordStatusMap 与 ijkplayerRecordResultMap 泄漏模式不一致
● 问题:本次PR在 FindRecordResult 中为 ijkplayerRecordResultMap 添加了 erase 调用,修复了该 map 的条目永不释放的内存泄漏。但 ijkplayerRecordStatusMap(同文件第174行声明)存在相同的泄漏模式:UpdateRecordStatus(第1641行)写入条目后从未执行 erase 清理。触发路径:ffp_start_record(A) → UpdateRecordStatus(A, ON) → ijkplayerRecordStatusMap[A]=ON → FFPlayer A 销毁 → ijkplayerRecordStatusMap[A] 永久残留。每个残留条目占用 sizeof(void*)+sizeof(int) 加哈希表开销,随着 FFPlayer 实例创建/销毁不断累积。
● 影响:建议。ijkplayerRecordStatusMap 条目随 FFPlayer 实例生命周期增长而不释放,属于慢速内存泄漏。单个条目开销小,但在长时间运行或频繁创建/销毁播放器实例的场景下会持续累积。
● 建议:在 ffp_stop_record 中 pthread_join 之后、调用 FindRecordResult 的同时,对 ijkplayerRecordStatusMap 也执行 erase 清理,与 ijkplayerRecordResultMap 的修复保持一致。参考修复点:
// ffp_stop_record 中,FindRecordResult 之后添加: auto statusIt = ijkplayerRecordStatusMap.find(ffp); if (statusIt != ijkplayerRecordStatusMap.end()) { ijkplayerRecordStatusMap.erase(statusIt); }或在 FindRecordResult 同级新增一个 CleanupRecordStatus 函数统一处理。