/* Источник только для тестовых worker-процессов: неподвижный экран и зависания на границах native lifecycle. */ #pragma once #include "../src/video_capture_source.h" #include "../../../src/call/call_video_playout.h" #include #include #include #include #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) #include class BlockedStreamFrame : public QAbstractVideoBuffer { public: MapData map(QVideoFrame::MapMode) override { QThread::sleep(60); return {}; } QVideoFrameFormat format() const override { return {QSize(16, 16), QVideoFrameFormat::Format_BGRX8888}; } }; #endif class StreamCaptureFixture : public VideoCaptureSource { QTimer timer; QByteArray mode; bool started = false; public: explicit StreamCaptureFixture(QByteArray testMode) : mode(std::move(testMode)) { timer.setSingleShot(true); connect(&timer, &QTimer::timeout, this, [this] { #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) if (mode == "convert") { QVideoFrame raw(std::make_unique()); raw.setStartTime(call_video_playout_now_us()); emit frame(raw); return; } #endif if (mode == "bad-frame") { QVideoFrame raw(QVideoFrameFormat(QSize(16, 16), QVideoFrameFormat::Format_Jpeg)); if (raw.map(QVideoFrame::WriteOnly)) { std::memset(raw.bits(0), 0, raw.mappedBytes(0)); raw.unmap(); } emit frame(raw); return; } QImage image(640, 360, QImage::Format_RGB32); image.fill(Qt::red); #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) QVideoFrame raw(image); #else QVideoFrame raw(QVideoFrameFormat(image.size(), QVideoFrameFormat::Format_BGRA8888)); if (!raw.map(QVideoFrame::WriteOnly)) return; for (int row = 0; row < image.height(); ++row) std::memcpy(raw.bits(0) + row * raw.bytesPerLine(0), image.constScanLine(row), size_t(image.width()) * 4); raw.unmap(); #endif raw.setStartTime(call_video_playout_now_us()); emit frame(raw); }); } ~StreamCaptureFixture() override { if (started && mode == "destroy") QThread::sleep(60); } VideoCaptureDevices devices(bool) override { return {{QStringLiteral("Isolated test screen"), "fixture", {}, VideoCaptureKind::Screen, QSize(640, 360)}}; } bool start(const VideoCaptureConfig&) override { started = true; timer.start(1); return true; } void stop() override { timer.stop(); emit stage(QStringLiteral("screen.stop")); if (started && mode == "stop") QThread::sleep(60); } };