Skip to content

Commit

Permalink
Fix Pipewire crash on stream pause
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Mar 16, 2024
1 parent fc83579 commit f48842e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sources/grabber/pipewire/PipewireGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ void PipewireGrabber::grabFrame()
{
if (data.isError)
{
QString err = QString("%1").arg(_getPipewireError());
Error(_log, "Could not capture pipewire frame: %s", QSTRING_CSTR(err));
//QString err = QString("%1").arg(_getPipewireError());
Error(_log, "Could not capture pipewire frame. The grabber is reporting an error");
stopNow = true;
}
}
Expand Down
17 changes: 16 additions & 1 deletion sources/grabber/pipewire/PipewireHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ void PipewireHandler::closeSession()

void PipewireHandler::releaseWorkingFrame()
{
if (_isError)
{
_image.data = nullptr;
_image.isError = _isError;
}
}

QString PipewireHandler::getSessionToken()
Expand Down Expand Up @@ -699,7 +704,7 @@ void PipewireHandler::captureFrame()
uint8_t* mappedMemory = nullptr;
uint8_t* frameBuffer = nullptr;

if (_pwStream == nullptr)
if (_pwStream == nullptr || _framePaused)
return;

_hasFrame = false;
Expand All @@ -714,7 +719,12 @@ void PipewireHandler::captureFrame()
while ((dequeueFrame = pw_stream_dequeue_buffer(_pwStream)) != nullptr)
{
if (newFrame != nullptr)
{
if (pw_stream_get_state(_pwStream, NULL) != PW_STREAM_STATE_STREAMING)
return;

pw_stream_queue_buffer(_pwStream, newFrame);
}
newFrame = dequeueFrame;
}

Expand Down Expand Up @@ -881,7 +891,12 @@ void PipewireHandler::captureFrame()
munmap(mappedMemory, newFrame->buffer->datas->maxsize + newFrame->buffer->datas->mapoffset);

if (newFrame != nullptr)
{
if (pw_stream_get_state(_pwStream, NULL) != PW_STREAM_STATE_STREAMING)
return;

pw_stream_queue_buffer(_pwStream, newFrame);
}

// goodbye
_infoUpdated = true;
Expand Down

0 comments on commit f48842e

Please sign in to comment.