From 0c49ae53602680075abecbd926ad6af913151b44 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 29 Mar 2024 18:31:10 +0200 Subject: [PATCH] plugins/screencast: Corrupt header to indicate that buffer has no data SPA_META_HEADER_FLAG_CORRUPTED indicates that the buffer contains absolutely no any data. SPA_CHUNK_FLAG_CORRUPTED indicates that the buffer has no frame contents but it can contain other data, for example cursor metadata. --- src/plugins/screencast/screencaststream.cpp | 16 ++++++++++++---- src/plugins/screencast/screencaststream.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index e4e6b517c3..fb35825c80 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -546,7 +546,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) uint8_t *data = static_cast(spa_data->data); if (!data) { qCWarning(KWIN_SCREENCAST) << objectName() << "Failed to record frame: invalid buffer data"; - spa_data->chunk->flags = SPA_CHUNK_FLAG_CORRUPTED; + corruptHeader(spa_buffer); pw_stream_queue_buffer(m_pwStream, buffer); return; } @@ -557,7 +557,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) if ((stride * size.height()) > spa_data->maxsize) { qCDebug(KWIN_SCREENCAST) << objectName() << "Failed to record frame: frame is too big"; - spa_data->chunk->flags = SPA_CHUNK_FLAG_CORRUPTED; + corruptHeader(spa_buffer); pw_stream_queue_buffer(m_pwStream, buffer); return; } @@ -576,7 +576,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) auto dmabuf = m_dmabufDataForPwBuffer.constFind(buffer); if (dmabuf == m_dmabufDataForPwBuffer.constEnd()) { qCDebug(KWIN_SCREENCAST) << objectName() << "Failed to record frame: no dmabuf data"; - spa_data->chunk->flags = SPA_CHUNK_FLAG_CORRUPTED; + corruptHeader(spa_buffer); pw_stream_queue_buffer(m_pwStream, buffer); return; } @@ -630,7 +630,7 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) } } else { qCWarning(KWIN_SCREENCAST, "%s Failed to record frame: invalid buffer type: %d", objectName().toUtf8().constData(), spa_data[0].type); - spa_data->chunk->flags = SPA_CHUNK_FLAG_CORRUPTED; + corruptHeader(spa_buffer); pw_stream_queue_buffer(m_pwStream, buffer); return; } @@ -656,6 +656,14 @@ void ScreenCastStream::addHeader(spa_buffer *spaBuffer) } } +void ScreenCastStream::corruptHeader(spa_buffer *spaBuffer) +{ + spa_meta_header *spaHeader = (spa_meta_header *)spa_buffer_find_meta_data(spaBuffer, SPA_META_Header, sizeof(spaHeader)); + if (spaHeader) { + spaHeader->flags = SPA_META_HEADER_FLAG_CORRUPTED; + } +} + void ScreenCastStream::addDamage(spa_buffer *spaBuffer, const QRegion &damagedRegion) { if (spa_meta *vdMeta = spa_buffer_find_meta(spaBuffer, SPA_META_VideoDamage)) { diff --git a/src/plugins/screencast/screencaststream.h b/src/plugins/screencast/screencaststream.h index 5abf2dd0bb..33073c9119 100644 --- a/src/plugins/screencast/screencaststream.h +++ b/src/plugins/screencast/screencaststream.h @@ -91,6 +91,7 @@ private: void coreFailed(const QString &errorMessage); void sendCursorData(Cursor *cursor, spa_meta_cursor *spa_cursor); void addHeader(spa_buffer *spaBuffer); + void corruptHeader(spa_buffer *spaBuffer); void addDamage(spa_buffer *spaBuffer, const QRegion &damagedRegion); void newStreamParams(); void enqueue(pw_buffer *buffer);