feat: Enhance ExtCaptureSession with QPointer for safer frame handling#766
Merged
deepin-bot[bot] merged 8 commits intoNov 27, 2025
Merged
feat: Enhance ExtCaptureSession with QPointer for safer frame handling#766deepin-bot[bot] merged 8 commits into
deepin-bot[bot] merged 8 commits into
Conversation
…eeLand mode - Update `cancelCapture` method to avoid direct destruction of Wayland proxy, preventing crashes during cleanup. - Modify `exitApp` to handle TreeLand mode exit more gracefully, ensuring proper resource management without immediate destruction. - Implement new UI transition methods `onTreelandSwitchToRecordUI` and `onTreelandSwitchToShotUI` for better handling of mode switches, including toolbar adjustments and region management. - Enhance logging for debugging and tracking state changes during TreeLand operations. This refactor improves stability and user experience when switching between recording and screenshot modes in the TreeLand environment.
- Introduced QPointer to manage ExtCaptureFrame instances, preventing dangling pointers during signal emissions. - Cached DMA-related data before emitting signals to ensure safe access and avoid dereferencing invalid pointers. - Updated frame cleanup process to use deleteLater for asynchronous deletion, enhancing stability during frame processing. This update improves the robustness of frame handling in screen recording, particularly when dealing with DMA buffers.
- Enhanced the cancelCapture method to safely destroy the current capture session without crashing due to invalid proxies. - Added null checks for voice volume and camera watchers to prevent crashes from uninitialized objects. - Implemented asynchronous stopping of recording in ExtCaptureRecorder to ensure complete stop before cleanup, avoiding residual frames. - Updated finalizeRecording to improve error handling and logging for video file creation, ensuring robust resource management. This update enhances the stability and reliability of the screen recording features, particularly in TreeLand and Wayland environments.
- Commented out various debug logging statements in ExtCaptureIntegration and ExtCaptureRecorder to reduce console clutter during screen recording operations. - This change aims to streamline the logging output while maintaining the ability to re-enable logging for debugging purposes if needed. This update enhances the clarity of log outputs during screen recording processes.
- Updated MainWindow to hide the main window during recording in Treeland mode to prevent obstruction of events. - Modified RecorderRegionShow to ensure it stays on top and is transparent for mouse events in Treeland mode. - Improved event handling for the RecorderRegionShow to manage visibility and focus correctly. This update enhances the user experience in Treeland mode by ensuring the recording interface is unobstructed and properly managed.
- Removed unused VAAPI initialization and encoding methods from ExtCaptureRecorder to streamline the codebase. - Updated the header file to reflect the removal of VAAPI-related member variables and methods, enhancing clarity and maintainability. This refactor simplifies the ExtCaptureRecorder class by eliminating unnecessary complexity related to VAAPI, improving overall code readability.
- Deleted outdated technical documents related to ext-image-copy-capture implementation, including the main implementation guide, technical summary, and multi-screen recording design. - This cleanup helps streamline the project by removing unnecessary files that are no longer relevant to the current development efforts. This update ensures that the repository remains focused and organized, facilitating easier navigation and maintenance.
- Added null checks and active connection validations in the TreelandCaptureManager and related classes to ensure safe destruction of objects only when the Wayland connection is active. - Enhanced the destroy methods in various capture classes to skip destruction if the objects are not initialized, preventing potential crashes during cleanup. - Updated logging to provide clearer insights into the state of the capture manager and context during destruction processes. This update enhances the stability and reliability of the capture management system, particularly in Wayland environments.
deepin pr auto review我将对代码进行详细审查,主要关注语法逻辑、代码质量、性能和安全等方面。
具体改进建议:
if (m_context) {
delete m_context;
m_context = nullptr; // 确保指针置空
}
if (isActive()) {
destroy();
}建议改进为: if (m_context) {
delete m_context;
m_context = nullptr;
}
if (isActive()) {
destroy();
} else {
qCDebug(dsrApp) << "Wayland connection not active, skipping destroy";
}这样可以更安全地处理Wayland连接状态。
if (m_state != Recording) {
return;
}建议改进为: if (m_state != Recording && m_state != Starting && m_state != Stopping) {
return;
}这样可以处理更多的状态转换情况。
if (timestamp <= 0) {
qCWarning(dsrApp) << "Invalid timestamp received";
return;
}
if (frame_size <= 0 || frame_size > MAX_FRAME_SIZE) {
qCWarning(dsrApp) << "Invalid frame size:" << frame_size;
return false;
}
if (!manager) {
qCWarning(dsrApp) << "TreelandCaptureManager instance is null";
return;
}
QTimer::singleShot(100, []() {
_Exit(0);
});而不是直接调用_Exit(0),这样可以给Qt事件循环一些处理时间。
ExtCaptureRecorder::ExtCaptureRecorder(QObject *parent)
: QObject(parent)
, m_extCapture(nullptr)
, m_frameBuffer(nullptr)
, m_captureTimer(new QTimer(this))
, m_state(Uninitialized)
, m_frameCount(0)
, m_recording(false)
, m_streamingMode(false)
, m_ffmpegProcess(nullptr)
, m_ffmpegStarted(false)
, m_firstFrameWidth(0)
, m_firstFrameHeight(0)
, m_firstFrameStride(0)
, m_firstFrameTimestampNs(-1)
, m_lastFrameTimestampNs(-1)
{
// 初始化代码
}
if (mapped_data == MAP_FAILED) {
int error_code = errno;
qCWarning(dsrApp) << "DMA-BUF mmap failed:" << strerror(error_code);
// 尝试备用方案
return tryAlternativeMapping();
}这些改进可以提高代码的健壮性、安全性和可维护性。同时,建议在代码中添加更多的注释,特别是对于复杂的业务逻辑和关键的安全检查点。 |
lzwind
approved these changes
Nov 27, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Member
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
54cdbde
into
linuxdeepin:develop/snipe
7 of 10 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(treeland): Refactor capture management and UI transitions for TreeLand mode
cancelCapturemethod to avoid direct destruction of Wayland proxy, preventing crashes during cleanup.exitAppto handle TreeLand mode exit more gracefully, ensuring proper resource management without immediate destruction.onTreelandSwitchToRecordUIandonTreelandSwitchToShotUIfor better handling of mode switches, including toolbar adjustments and region management.This refactor improves stability and user experience when switching between recording and screenshot modes in the TreeLand environment.
feat: Enhance ExtCaptureSession with QPointer for safer frame handling
This update improves the robustness of frame handling in screen recording, particularly when dealing with DMA buffers.