Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/platform/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ enum class capture_e : int {
class display_t {
public:
/**
* When display has a new image ready, this callback will be called with the new image.
* When display has a new image ready or a timeout occurs, this callback will be called with the image.
* If a frame was captured, frame_captured will be true. If a timeout occurred, it will be false.
*
* On Break Request -->
* Returns nullptr
Expand All @@ -225,7 +226,7 @@ class display_t {
* Returns the image object that should be filled next.
* This may or may not be the image send with the callback
*/
using snapshot_cb_t = std::function<std::shared_ptr<img_t>(std::shared_ptr<img_t> &img)>;
using snapshot_cb_t = std::function<std::shared_ptr<img_t>(std::shared_ptr<img_t> &img, bool frame_captured)>;

display_t() noexcept : offset_x { 0 }, offset_y { 0 } {}

Expand Down
6 changes: 3 additions & 3 deletions src/platform/linux/cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,10 @@ class display_t : public platf::display_t {
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
std::this_thread::sleep_for(1ms);
continue;
img = snapshot_cb(img, false);
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down
12 changes: 6 additions & 6 deletions src/platform/linux/kmsgrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,10 @@ class display_ram_t : public display_t {
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
std::this_thread::sleep_for(1ms);
continue;
img = snapshot_cb(img, false);
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down Expand Up @@ -805,10 +805,10 @@ class display_vram_t : public display_t {
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
std::this_thread::sleep_for(1ms);
continue;
img = snapshot_cb(img, false);
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down
10 changes: 6 additions & 4 deletions src/platform/linux/wlgrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ class wlr_ram_t : public wlr_t {
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
continue;
img = snapshot_cb(img, false);
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down Expand Up @@ -239,9 +240,10 @@ class wlr_vram_t : public wlr_t {
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
continue;
img = snapshot_cb(img, false);
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down
12 changes: 6 additions & 6 deletions src/platform/linux/x11grab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,10 @@ struct x11_attr_t : public display_t {
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
std::this_thread::sleep_for(1ms);
continue;
img = snapshot_cb(img, false);
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down Expand Up @@ -587,10 +587,10 @@ struct shm_attr_t : public x11_attr_t {
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
std::this_thread::sleep_for(1ms);
continue;
img = snapshot_cb(img, false);
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down
3 changes: 2 additions & 1 deletion src/platform/macos/display.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ capture_e capture(snapshot_cb_t &&snapshot_cb, std::shared_ptr<img_t> img, bool
img_next->row_pitch = CVPixelBufferGetBytesPerRow(pixelBuffer);
img_next->pixel_pitch = img_next->row_pitch / img_next->width;

img_next = snapshot_cb(img_next);
img_next = snapshot_cb(img_next, true);

return img_next != nullptr;
}];

// FIXME: We should time out if an image isn't returned for a while
dispatch_semaphore_wait(signal, DISPATCH_TIME_FOREVER);

return capture_e::ok;
Expand Down
5 changes: 3 additions & 2 deletions src/platform/windows/display_ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ capture_e display_ram_t::capture(snapshot_cb_t &&snapshot_cb, std::shared_ptr<::
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
img = snapshot_cb(img, false);
std::this_thread::sleep_for(1ms);
continue;
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down
5 changes: 3 additions & 2 deletions src/platform/windows/display_vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,11 @@ capture_e display_vram_t::capture(snapshot_cb_t &&snapshot_cb, std::shared_ptr<:
case platf::capture_e::error:
return status;
case platf::capture_e::timeout:
img = snapshot_cb(img, false);
std::this_thread::sleep_for(1ms);
continue;
break;
case platf::capture_e::ok:
img = snapshot_cb(img);
img = snapshot_cb(img, true);
break;
default:
BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']';
Expand Down
11 changes: 7 additions & 4 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,15 +707,18 @@ void captureThread(
while(capture_ctx_queue->running()) {
bool artificial_reinit = false;

auto status = disp->capture([&](std::shared_ptr<platf::img_t> &img) -> std::shared_ptr<platf::img_t> {
auto status = disp->capture([&](std::shared_ptr<platf::img_t> &img, bool frame_captured) -> std::shared_ptr<platf::img_t> {
KITTY_WHILE_LOOP(auto capture_ctx = std::begin(capture_ctxs), capture_ctx != std::end(capture_ctxs), {
if(!capture_ctx->images->running()) {
capture_ctx = capture_ctxs.erase(capture_ctx);

continue;
}

capture_ctx->images->raise(img);
if(frame_captured) {
capture_ctx->images->raise(img);
}

++capture_ctx;
})

Expand Down Expand Up @@ -1274,7 +1277,7 @@ encode_e encode_run_sync(

auto ec = platf::capture_e::ok;
while(encode_session_ctx_queue.running()) {
auto snapshot_cb = [&](std::shared_ptr<platf::img_t> &img) -> std::shared_ptr<platf::img_t> {
auto snapshot_cb = [&](std::shared_ptr<platf::img_t> &img, bool frame_captured) -> std::shared_ptr<platf::img_t> {
while(encode_session_ctx_queue.peek()) {
auto encode_session_ctx = encode_session_ctx_queue.pop();
if(!encode_session_ctx) {
Expand Down Expand Up @@ -1318,7 +1321,7 @@ encode_e encode_run_sync(
ctx->idr_events->pop();
}

if(pos->session.device->convert(*img)) {
if(frame_captured && pos->session.device->convert(*img)) {
BOOST_LOG(error) << "Could not convert image"sv;
ctx->shutdown_event->raise(true);

Expand Down