|
7 | 7 | #include "manager/extcapturemanager.h" |
8 | 8 | #include "session/extcapturesession.h" |
9 | 9 | #include "frame/extcaptureframe.h" |
| 10 | +#include "multiscreencapturecoordinator.h" |
10 | 11 | #include "../utils/log.h" |
11 | 12 |
|
12 | 13 | #include <QDebug> |
13 | 14 | #include <QTimer> |
| 15 | +#include <QGuiApplication> |
14 | 16 |
|
15 | 17 | ExtCaptureIntegration::ExtCaptureIntegration(QObject *parent) |
16 | 18 | : QObject(parent) |
17 | 19 | , m_manager(new ExtCaptureManager(this)) |
18 | 20 | , m_session(nullptr) |
| 21 | + , m_multiScreenCoordinator(new MultiScreenCaptureCoordinator(this)) |
19 | 22 | , m_recording(false) |
| 23 | + , m_multiScreenRecording(false) |
20 | 24 | { |
21 | 25 | // 连接管理器信号 |
22 | 26 | connect(m_manager, &ExtCaptureManager::protocolAvailable, |
23 | 27 | this, &ExtCaptureIntegration::onProtocolAvailable); |
24 | 28 | connect(m_manager, &ExtCaptureManager::protocolUnavailable, |
25 | 29 | this, &ExtCaptureIntegration::onProtocolUnavailable); |
| 30 | + |
| 31 | + // 设置多屏协调器的捕获管理器 |
| 32 | + m_multiScreenCoordinator->setCaptureManager(m_manager); |
| 33 | + |
| 34 | + // 连接多屏协调器信号 |
| 35 | + connect(m_multiScreenCoordinator, &MultiScreenCaptureCoordinator::compositeFrameReady, |
| 36 | + this, &ExtCaptureIntegration::onMultiScreenFrameReady); |
| 37 | + connect(m_multiScreenCoordinator, &MultiScreenCaptureCoordinator::captureStarted, |
| 38 | + this, &ExtCaptureIntegration::onMultiScreenCaptureStarted); |
| 39 | + connect(m_multiScreenCoordinator, &MultiScreenCaptureCoordinator::captureStopped, |
| 40 | + this, &ExtCaptureIntegration::onMultiScreenCaptureStopped); |
| 41 | + connect(m_multiScreenCoordinator, &MultiScreenCaptureCoordinator::error, |
| 42 | + this, &ExtCaptureIntegration::onMultiScreenCaptureError); |
26 | 43 | } |
27 | 44 |
|
28 | 45 | ExtCaptureIntegration::~ExtCaptureIntegration() |
@@ -91,20 +108,33 @@ bool ExtCaptureIntegration::startScreenRecording(QScreen *screen, bool includeCu |
91 | 108 |
|
92 | 109 | void ExtCaptureIntegration::stopRecording() |
93 | 110 | { |
94 | | - if (!m_recording) { |
| 111 | + qCDebug(dsrApp) << "ExtCaptureIntegration::stopRecording: Stopping recording" |
| 112 | + << "single screen:" << m_recording << "multi screen:" << m_multiScreenRecording; |
| 113 | + |
| 114 | + if (!m_recording && !m_multiScreenRecording) { |
95 | 115 | return; |
96 | 116 | } |
97 | 117 |
|
98 | | - m_recording = false; |
| 118 | + // 停止单屏录制 |
| 119 | + if (m_recording) { |
| 120 | + m_recording = false; |
99 | 121 |
|
100 | | - if (m_session) { |
101 | | - m_session->stop(); |
102 | | - m_session->deleteLater(); |
103 | | - m_session = nullptr; |
| 122 | + if (m_session) { |
| 123 | + m_session->stop(); |
| 124 | + m_session->deleteLater(); |
| 125 | + m_session = nullptr; |
| 126 | + } |
| 127 | + |
| 128 | + emit recordingStopped(); |
| 129 | + qCDebug(dsrApp) << "Single screen recording stopped"; |
104 | 130 | } |
105 | 131 |
|
106 | | - emit recordingStopped(); |
107 | | - qDebug() << "Screen recording stopped"; |
| 132 | + // 停止多屏录制 |
| 133 | + if (m_multiScreenRecording) { |
| 134 | + m_multiScreenCoordinator->stopMultiScreenCapture(); |
| 135 | + // m_multiScreenRecording 将在 onMultiScreenCaptureStopped 中设置为 false |
| 136 | + qCDebug(dsrApp) << "Multi-screen recording stop requested"; |
| 137 | + } |
108 | 138 | } |
109 | 139 |
|
110 | 140 | bool ExtCaptureIntegration::captureFrame() |
@@ -241,3 +271,87 @@ void ExtCaptureIntegration::onFrameFailed(const QString &reason) |
241 | 271 | emit error(QString("Frame capture failed: %1").arg(reason)); |
242 | 272 | } |
243 | 273 |
|
| 274 | +bool ExtCaptureIntegration::startMultiScreenRecording(const QList<QScreen*>& screens, bool includeCursor) |
| 275 | +{ |
| 276 | + qCWarning(dsrApp) << "ExtCaptureIntegration::startMultiScreenRecording: Starting with" |
| 277 | + << screens.size() << "screens, includeCursor:" << includeCursor; |
| 278 | + |
| 279 | + if (m_recording || m_multiScreenRecording) { |
| 280 | + qCWarning(dsrApp) << "ExtCaptureIntegration: Already recording"; |
| 281 | + return false; |
| 282 | + } |
| 283 | + |
| 284 | + if (!isAvailable()) { |
| 285 | + qCWarning(dsrApp) << "ExtCaptureIntegration: Protocol not available"; |
| 286 | + emit error("Protocol not available"); |
| 287 | + return false; |
| 288 | + } |
| 289 | + |
| 290 | + if (screens.isEmpty()) { |
| 291 | + qCWarning(dsrApp) << "ExtCaptureIntegration: No screens provided"; |
| 292 | + emit error("No screens to record"); |
| 293 | + return false; |
| 294 | + } |
| 295 | + |
| 296 | + // 开始多屏捕获 |
| 297 | + if (!m_multiScreenCoordinator->startMultiScreenCapture(screens, includeCursor)) { |
| 298 | + qCWarning(dsrApp) << "ExtCaptureIntegration: Failed to start multi-screen capture"; |
| 299 | + emit error("Failed to start multi-screen capture"); |
| 300 | + return false; |
| 301 | + } |
| 302 | + |
| 303 | + m_multiScreenRecording = true; |
| 304 | + qCWarning(dsrApp) << "ExtCaptureIntegration: Multi-screen recording started"; |
| 305 | + |
| 306 | + return true; |
| 307 | +} |
| 308 | + |
| 309 | +bool ExtCaptureIntegration::captureMultiScreenFrame() |
| 310 | +{ |
| 311 | + if (!m_multiScreenRecording) { |
| 312 | + qCWarning(dsrApp) << "ExtCaptureIntegration: Not in multi-screen recording mode"; |
| 313 | + return false; |
| 314 | + } |
| 315 | + |
| 316 | + return m_multiScreenCoordinator->captureMultiScreenFrame(); |
| 317 | +} |
| 318 | + |
| 319 | +bool ExtCaptureIntegration::isMultiScreenRecording() const |
| 320 | +{ |
| 321 | + return m_multiScreenRecording; |
| 322 | +} |
| 323 | + |
| 324 | +QList<QScreen*> ExtCaptureIntegration::getAvailableScreens() const |
| 325 | +{ |
| 326 | + return QGuiApplication::screens(); |
| 327 | +} |
| 328 | + |
| 329 | +void ExtCaptureIntegration::onMultiScreenFrameReady(const QByteArray& compositeFrameData, |
| 330 | + int width, int height, int stride, uint64_t timestamp) |
| 331 | +{ |
| 332 | + qCDebug(dsrApp) << "ExtCaptureIntegration::onMultiScreenFrameReady: Composite frame ready" |
| 333 | + << "size:" << compositeFrameData.size() << "dimensions:" << width << "x" << height; |
| 334 | + |
| 335 | + emit multiScreenFrameReady(compositeFrameData, width, height, stride, timestamp); |
| 336 | +} |
| 337 | + |
| 338 | +void ExtCaptureIntegration::onMultiScreenCaptureStarted() |
| 339 | +{ |
| 340 | + qCDebug(dsrApp) << "ExtCaptureIntegration::onMultiScreenCaptureStarted"; |
| 341 | + emit recordingStarted(); |
| 342 | +} |
| 343 | + |
| 344 | +void ExtCaptureIntegration::onMultiScreenCaptureStopped() |
| 345 | +{ |
| 346 | + qCDebug(dsrApp) << "ExtCaptureIntegration::onMultiScreenCaptureStopped"; |
| 347 | + m_multiScreenRecording = false; |
| 348 | + emit recordingStopped(); |
| 349 | +} |
| 350 | + |
| 351 | +void ExtCaptureIntegration::onMultiScreenCaptureError(const QString& message) |
| 352 | +{ |
| 353 | + qCWarning(dsrApp) << "ExtCaptureIntegration::onMultiScreenCaptureError:" << message; |
| 354 | + m_multiScreenRecording = false; |
| 355 | + emit error(QString("Multi-screen capture error: %1").arg(message)); |
| 356 | +} |
| 357 | + |
0 commit comments