Skip to content

fix(a/v-sync): use monotonic clock for audio PTS to fix desync#483

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:release/eagle
Jun 8, 2026
Merged

fix(a/v-sync): use monotonic clock for audio PTS to fix desync#483
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:release/eagle

Conversation

@LiHua000
Copy link
Copy Markdown
Contributor

@LiHua000 LiHua000 commented Jun 8, 2026

Audio PTS was derived from the hardware device timestamp while video PTS
used CLOCK_MONOTONIC, causing progressive A/V drift. Unify both to
ns_time_monotonic(). Also preserve original_pts for the muxer to avoid
precision loss from audio codec time_base rescaling.

log: fix bug

Bug:https://pms.uniontech.com/bug-view-363537.html

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Sorry @LiHua000, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Audio PTS was derived from the hardware device timestamp while video PTS
  used CLOCK_MONOTONIC, causing progressive A/V drift. Unify both to
  ns_time_monotonic(). Also preserve original_pts for the muxer to avoid
  precision loss from audio codec time_base rescaling.

log: fix bug

Bug:https://pms.uniontech.com/bug-view-363537.html
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

代码审查意见

总体评价

这个代码修改主要涉及音频处理、编码和时间戳管理方面。整体来看,修改是为了改进时间戳处理的准确性和可靠性,引入了系统单调时钟来替代之前可能不稳定的音频缓冲区时间戳。

具体分析

1. 时间戳处理改进 (camview.c)

  • 优点

    • 引入了 ns_time_monotonic() 函数来获取系统单调时钟,提高了时间戳的可靠性
    • 在音频处理循环开始时初始化时间戳参考点,确保时间计算的基准一致
    • 使用系统单调时钟替代了音频缓冲区的时间戳,避免了音频缓冲区可能带来的时间戳不连续问题
  • 建议

    • 考虑添加错误处理,如果 ns_time_monotonic() 调用失败应有适当的回退机制
    • 可以添加日志记录,便于调试时间戳相关问题

2. 编码器上下文修改 (encoder.c)

  • 优点

    • 添加了 original_pts 字段来保存原始时间戳,防止被编码器覆盖
    • 在编码前保存原始时间戳,确保后续处理可以使用准确的时间信息
  • 建议

    • 考虑为 original_pts 添加范围检查,防止溢出
    • 可以添加注释说明 original_pts 的单位(纳秒)和用途

3. 头文件修改 (gviewencoder.h)

  • 优点

    • 清晰地定义了 original_pts 字段,并添加了注释说明其用途
    • 结构体组织合理,字段命名清晰
  • 建议

    • 考虑为时间戳字段添加单位注释,如 /* nanoseconds */
    • 可以考虑将时间戳相关的字段组织在一起,提高代码可读性

4. 多路复用器修改 (muxer.c)

  • 优点

    • 使用 original_pts 替代 pts 进行多路复用,确保了时间戳的准确性
    • 修改简单直接,解决了时间戳被编码器覆盖的问题
  • 建议

    • 添加注释说明为什么使用 original_pts 而不是 pts
    • 考虑添加错误处理,如果时间戳无效应有适当的处理

性能考虑

  • 使用系统单调时钟可能会带来轻微的性能开销,但考虑到时间戳准确性的重要性,这是值得的
  • 建议在实际运行中监控时间戳获取的性能影响

安全性考虑

  • 时间戳计算应该考虑溢出的情况,特别是当长时间运行时
  • 建议添加适当的边界检查和错误处理机制

总体建议

  1. 添加更详细的错误处理机制
  2. 增加日志记录,便于调试
  3. 添加注释说明时间戳处理的逻辑和目的
  4. 考虑添加单元测试,确保时间戳处理的正确性
  5. 在长时间运行的场景下测试时间戳计算的准确性,防止溢出问题

这些修改整体上是积极的,提高了时间戳处理的准确性和可靠性,但还需要进一步完善错误处理和文档注释。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@LiHua000
Copy link
Copy Markdown
Contributor Author

LiHua000 commented Jun 8, 2026

/merge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Jun 8, 2026

This pr cannot be merged! (status: unstable)

@LiHua000
Copy link
Copy Markdown
Contributor Author

LiHua000 commented Jun 8, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Jun 8, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 12ff976 into linuxdeepin:release/eagle Jun 8, 2026
21 of 22 checks passed
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.

3 participants