mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-10-01 06:24:55 -07:00
api: h.264 video stream (#876)
## Link to GitHub Issue or related Pull Request, if one exists fixes #875 ## Description of change Adds `-apistream`, an optional HTTP video stream of the mirrored screen. It listens on the API port +2. Two endpoints, sharing the same `screen`, `fps` and `q` parameters: /stream.mjpg JPEG frames, for clients with no container support /stream.h264 H.264 annex-b, for an app driving MediaCodec or VideoToolbox itself One encoder per connection, fed by a per-screen pump that always hands over the newest frame, so a slow reader drops frames instead of building a backlog. `capture.get_jpg` behaviour is unchanged. Additional documentation for developers: https://github.com/spice2x/spice2x.github.io/wiki/Video-Stream ## Testing
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#include "capture_pump.h"
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "hooks/graphics/graphics.h"
|
||||
|
||||
namespace api::capture_pump {
|
||||
|
||||
namespace {
|
||||
|
||||
std::array<std::mutex, GRAPHICS_CAPTURE_SCREEN_NO> CONSUMER_M;
|
||||
|
||||
std::mutex CLAIMED_M;
|
||||
std::array<bool, GRAPHICS_CAPTURE_SCREEN_NO> CLAIMED {};
|
||||
|
||||
bool valid_screen(int screen) {
|
||||
return 0 <= screen && screen < static_cast<int>(GRAPHICS_CAPTURE_SCREEN_NO);
|
||||
}
|
||||
}
|
||||
|
||||
bool capture_direct(int screen, std::shared_ptr<uint8_t[]> &out, int divide,
|
||||
uint64_t *timestamp, int *width, int *height) {
|
||||
|
||||
if (!valid_screen(screen)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(CONSUMER_M[screen]);
|
||||
graphics_capture_trigger(screen);
|
||||
return graphics_capture_receive_raw(
|
||||
screen, out, divide, timestamp, width, height);
|
||||
}
|
||||
|
||||
bool claim_screen(int screen) {
|
||||
if (!valid_screen(screen)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(CLAIMED_M);
|
||||
|
||||
if (CLAIMED[screen]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CLAIMED[screen] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void release_screen(int screen) {
|
||||
if (!valid_screen(screen)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(CLAIMED_M);
|
||||
CLAIMED[screen] = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user