mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-10-17 17:33:21 +08:00
[fix] align MiniRtc media interfaces and timestamps
This commit is contained in:
@@ -42,7 +42,7 @@ class NativeVideoFrameRef {
|
||||
public:
|
||||
NativeVideoFrameRef() = default;
|
||||
|
||||
explicit NativeVideoFrameRef(const XNativeVideoFrame *frame) {
|
||||
explicit NativeVideoFrameRef(const MiniRtcNativeVideoFrame *frame) {
|
||||
if (frame && frame->owner && frame->retain && frame->release) {
|
||||
frame_ = *frame;
|
||||
frame_.struct_size = sizeof(frame_);
|
||||
@@ -79,18 +79,18 @@ public:
|
||||
std::swap(valid_, other.valid_);
|
||||
}
|
||||
|
||||
const XNativeVideoFrame *Get() const { return valid_ ? &frame_ : nullptr; }
|
||||
const MiniRtcNativeVideoFrame *Get() const { return valid_ ? &frame_ : nullptr; }
|
||||
explicit operator bool() const { return valid_; }
|
||||
|
||||
private:
|
||||
XNativeVideoFrame frame_{};
|
||||
MiniRtcNativeVideoFrame frame_{};
|
||||
bool valid_ = false;
|
||||
};
|
||||
|
||||
const XNativeVideoFrame *GetOpenGlNativeFrame(
|
||||
const XNativeVideoFrame &frame) {
|
||||
const XNativeVideoFrame *native = &frame;
|
||||
if (native->struct_size < static_cast<uint32_t>(sizeof(XNativeVideoFrame)) ||
|
||||
const MiniRtcNativeVideoFrame *GetOpenGlNativeFrame(
|
||||
const MiniRtcNativeVideoFrame &frame) {
|
||||
const MiniRtcNativeVideoFrame *native = &frame;
|
||||
if (native->struct_size < static_cast<uint32_t>(sizeof(MiniRtcNativeVideoFrame)) ||
|
||||
!native->owner || !native->retain || !native->release ||
|
||||
!native->copy_to_nv12 || native->width == 0 || native->height == 0 ||
|
||||
(native->width & 1U) != 0 || (native->height & 1U) != 0 ||
|
||||
@@ -98,7 +98,7 @@ const XNativeVideoFrame *GetOpenGlNativeFrame(
|
||||
native->height > static_cast<uint32_t>(std::numeric_limits<int>::max())) {
|
||||
return nullptr;
|
||||
}
|
||||
if (native->type == XNativeVideoFrameCpuNv12) {
|
||||
if (native->type == MiniRtcNativeVideoFrameCpuNv12) {
|
||||
return native->payload.cpu_nv12.y_plane &&
|
||||
native->payload.cpu_nv12.uv_plane &&
|
||||
native->payload.cpu_nv12.y_stride >= native->width &&
|
||||
@@ -106,7 +106,7 @@ const XNativeVideoFrame *GetOpenGlNativeFrame(
|
||||
? native
|
||||
: nullptr;
|
||||
}
|
||||
if (native->type == XNativeVideoFrameCudaNv12) {
|
||||
if (native->type == MiniRtcNativeVideoFrameCudaNv12) {
|
||||
return native->payload.cuda_nv12.y_device_pointer != 0 &&
|
||||
native->payload.cuda_nv12.uv_device_pointer != 0 &&
|
||||
native->payload.cuda_nv12.y_stride >= native->width &&
|
||||
@@ -457,7 +457,7 @@ struct OpenGlVideoRenderer::Impl {
|
||||
}
|
||||
|
||||
bool PrepareCudaContext(const NativeVideoFrameRef &native_frame) {
|
||||
const XNativeVideoFrame *frame = native_frame.Get();
|
||||
const MiniRtcNativeVideoFrame *frame = native_frame.Get();
|
||||
if (!frame || !frame->payload.cuda_nv12.context ||
|
||||
cuda_interop_disabled ||
|
||||
!cuda_sync_functions_available ||
|
||||
@@ -564,7 +564,7 @@ struct OpenGlVideoRenderer::Impl {
|
||||
|
||||
CudaUploadResult CopyCudaFrameToUploadBuffer(
|
||||
const NativeVideoFrameRef &native_frame, size_t *upload_slot_index) {
|
||||
const XNativeVideoFrame *frame = native_frame.Get();
|
||||
const MiniRtcNativeVideoFrame *frame = native_frame.Get();
|
||||
if (!upload_slot_index || !PrepareCudaContext(native_frame)) {
|
||||
return CudaUploadResult::unavailable;
|
||||
}
|
||||
@@ -1096,11 +1096,11 @@ OpenGlVideoRenderer::SubmitNv12Internal(std::string_view remote_id,
|
||||
|
||||
OpenGlVideoRenderer::SubmitResult
|
||||
OpenGlVideoRenderer::SubmitNativeFrame(std::string_view remote_id,
|
||||
const XNativeVideoFrame &frame) {
|
||||
const MiniRtcNativeVideoFrame &frame) {
|
||||
if (!IsReady()) {
|
||||
return SubmitResult::failed;
|
||||
}
|
||||
const XNativeVideoFrame *native = GetOpenGlNativeFrame(frame);
|
||||
const MiniRtcNativeVideoFrame *native = GetOpenGlNativeFrame(frame);
|
||||
if (!native) {
|
||||
return SubmitResult::failed;
|
||||
}
|
||||
@@ -1144,7 +1144,7 @@ OpenGlVideoRenderer::SubmitNativeFrame(std::string_view remote_id,
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && USE_CUDA
|
||||
if (native->type == XNativeVideoFrameCudaNv12 &&
|
||||
if (native->type == MiniRtcNativeVideoFrameCudaNv12 &&
|
||||
impl_->cuda_cpu_fallback.load(std::memory_order_acquire)) {
|
||||
const size_t required_size =
|
||||
static_cast<size_t>(native->width) * native->height * 3U / 2U;
|
||||
@@ -1295,13 +1295,13 @@ OpenGlVideoRenderer::RenderLatest(std::string_view remote_id,
|
||||
bool use_pixel_unpack_buffer = false;
|
||||
size_t cuda_upload_slot = 0;
|
||||
std::vector<unsigned char> cpu_fallback;
|
||||
if (const XNativeVideoFrame *native = active_native_frame.Get()) {
|
||||
if (native->type == XNativeVideoFrameCpuNv12 &&
|
||||
if (const MiniRtcNativeVideoFrame *native = active_native_frame.Get()) {
|
||||
if (native->type == MiniRtcNativeVideoFrameCpuNv12 &&
|
||||
native->payload.cpu_nv12.y_stride == native->width &&
|
||||
native->payload.cpu_nv12.uv_stride == native->width) {
|
||||
y_data = native->payload.cpu_nv12.y_plane;
|
||||
uv_data = native->payload.cpu_nv12.uv_plane;
|
||||
} else if (native->type == XNativeVideoFrameCudaNv12) {
|
||||
} else if (native->type == MiniRtcNativeVideoFrameCudaNv12) {
|
||||
#if defined(_WIN32) && USE_CUDA
|
||||
const auto cuda_result = impl_->CopyCudaFrameToUploadBuffer(
|
||||
active_native_frame, &cuda_upload_slot);
|
||||
@@ -1603,7 +1603,7 @@ bool OpenGlVideoRenderer::CopyLatestNv12(
|
||||
*output = std::move(cpu_frame);
|
||||
return true;
|
||||
}
|
||||
if (const XNativeVideoFrame *native = native_frame.Get()) {
|
||||
if (const MiniRtcNativeVideoFrame *native = native_frame.Get()) {
|
||||
const size_t required_size =
|
||||
static_cast<size_t>(native->width) * native->height * 3U / 2U;
|
||||
output->resize(required_size);
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
SubmitResult SubmitCachedNv12(std::string_view remote_id, const uint8_t *data,
|
||||
size_t size, int width, int height) override;
|
||||
SubmitResult SubmitNativeFrame(std::string_view remote_id,
|
||||
const XNativeVideoFrame &frame) override;
|
||||
const MiniRtcNativeVideoFrame &frame) override;
|
||||
|
||||
// Draws below Slint while its OpenGL context is current. All dimensions are
|
||||
// physical pixels in the window client area. corner_radius_pixels clips the
|
||||
|
||||
@@ -51,7 +51,7 @@ int ScreenCapturerLinux::Init(const int fps, cb_desktop_data cb) {
|
||||
callback_orig_ = std::move(cb);
|
||||
callback_ = [this](unsigned char* data, int size, int width, int height,
|
||||
const char* reported_stream_id,
|
||||
const XNativeVideoFrame* native_frame) {
|
||||
const MiniRtcNativeVideoFrame* native_frame) {
|
||||
const std::string mapped_stream_id = MapStreamId(reported_stream_id);
|
||||
if (mapped_stream_id.empty()) {
|
||||
if (!invalid_stream_id_logged_.exchange(true,
|
||||
|
||||
@@ -40,7 +40,7 @@ class MacMetalVideoRenderer final : public VideoRenderer {
|
||||
// Retains an IOSurface-backed VideoToolbox CVPixelBuffer until the Metal
|
||||
// command buffer using it has completed.
|
||||
SubmitResult SubmitNativeFrame(std::string_view remote_id,
|
||||
const XNativeVideoFrame& frame) override;
|
||||
const MiniRtcNativeVideoFrame& frame) override;
|
||||
|
||||
// Seeds a newly selected stream from its retained CPU snapshot without
|
||||
// replacing a newer decoded frame that is already queued or rendering.
|
||||
|
||||
@@ -199,7 +199,7 @@ class NativeVideoFrameRef {
|
||||
public:
|
||||
NativeVideoFrameRef() = default;
|
||||
|
||||
explicit NativeVideoFrameRef(const XNativeVideoFrame* frame) {
|
||||
explicit NativeVideoFrameRef(const MiniRtcNativeVideoFrame* frame) {
|
||||
if (frame && frame->owner && frame->retain && frame->release) {
|
||||
frame_ = *frame;
|
||||
frame_.struct_size = sizeof(frame_);
|
||||
@@ -236,21 +236,21 @@ class NativeVideoFrameRef {
|
||||
std::swap(valid_, other.valid_);
|
||||
}
|
||||
|
||||
const XNativeVideoFrame* Get() const {
|
||||
const MiniRtcNativeVideoFrame* Get() const {
|
||||
return valid_ ? &frame_ : nullptr;
|
||||
}
|
||||
explicit operator bool() const { return valid_; }
|
||||
|
||||
private:
|
||||
XNativeVideoFrame frame_{};
|
||||
MiniRtcNativeVideoFrame frame_{};
|
||||
bool valid_ = false;
|
||||
};
|
||||
|
||||
const XNativeVideoFrame* GetMacNativeFrame(
|
||||
const XNativeVideoFrame& frame) {
|
||||
const XNativeVideoFrame* native = &frame;
|
||||
const MiniRtcNativeVideoFrame* GetMacNativeFrame(
|
||||
const MiniRtcNativeVideoFrame& frame) {
|
||||
const MiniRtcNativeVideoFrame* native = &frame;
|
||||
if (native->struct_size < static_cast<uint32_t>(sizeof(*native)) ||
|
||||
native->type != XNativeVideoFrameCVPixelBuffer ||
|
||||
native->type != MiniRtcNativeVideoFrameCVPixelBuffer ||
|
||||
!native->payload.cv_pixel_buffer || !native->owner || !native->retain ||
|
||||
!native->release || !native->copy_to_nv12 || native->width == 0 ||
|
||||
native->height == 0 || (native->width & 1U) != 0 ||
|
||||
@@ -471,7 +471,7 @@ fragment half4 nv12_fragment(
|
||||
- 16.0 / 255.0);
|
||||
const float2 uv = uv_texture.sample(video_sampler, in.texcoord).rg - 0.5;
|
||||
// BT.601 limited-range NV12, matching the previous libyuv NV12ToABGR/RAW
|
||||
// path. MiniRTC's current XVideoFrame API does not carry color metadata, so
|
||||
// path. MiniRTC's current MiniRtcVideoFrame API does not carry color metadata, so
|
||||
// retaining the established matrix avoids a platform-only color change.
|
||||
const float3 rgb = float3(y + 1.59602678 * uv.y,
|
||||
y - 0.39176229 * uv.x - 0.81296764 * uv.y,
|
||||
@@ -751,11 +751,11 @@ MacMetalVideoRenderer::SubmitResult MacMetalVideoRenderer::SubmitNv12(
|
||||
}
|
||||
|
||||
MacMetalVideoRenderer::SubmitResult MacMetalVideoRenderer::SubmitNativeFrame(
|
||||
std::string_view remote_id, const XNativeVideoFrame& frame) {
|
||||
std::string_view remote_id, const MiniRtcNativeVideoFrame& frame) {
|
||||
if (!IsReady()) {
|
||||
return SubmitResult::failed;
|
||||
}
|
||||
const XNativeVideoFrame* native = GetMacNativeFrame(frame);
|
||||
const MiniRtcNativeVideoFrame* native = GetMacNativeFrame(frame);
|
||||
if (!native) {
|
||||
return SubmitResult::failed;
|
||||
}
|
||||
@@ -1322,7 +1322,7 @@ bool MacMetalVideoRenderer::CopyLatestNv12(
|
||||
}
|
||||
}
|
||||
|
||||
const XNativeVideoFrame* native = native_frame.Get();
|
||||
const MiniRtcNativeVideoFrame* native = native_frame.Get();
|
||||
const size_t y_size = static_cast<size_t>(native->width) * native->height;
|
||||
output->resize(y_size + y_size / 2);
|
||||
return native->copy_to_nv12(native->owner, output->data(), output->size()) ==
|
||||
|
||||
@@ -695,9 +695,9 @@ void ScreenCapturerSckImpl::OnNewCVPixelBuffer(CVPixelBufferRef pixelBuffer,
|
||||
}
|
||||
}
|
||||
|
||||
XNativeVideoFrame native_frame{};
|
||||
MiniRtcNativeVideoFrame native_frame{};
|
||||
native_frame.struct_size = sizeof(native_frame);
|
||||
native_frame.type = XNativeVideoFrameCVPixelBuffer;
|
||||
native_frame.type = MiniRtcNativeVideoFrameCVPixelBuffer;
|
||||
native_frame.width = static_cast<uint32_t>(width);
|
||||
native_frame.height = static_cast<uint32_t>(height);
|
||||
native_frame.payload.cv_pixel_buffer = pixelBuffer;
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
// Retains a platform-native decoded frame when the backend supports its
|
||||
// storage and handle types. Unsupported backends keep the default fallback.
|
||||
virtual SubmitResult SubmitNativeFrame(std::string_view,
|
||||
const XNativeVideoFrame&) {
|
||||
const MiniRtcNativeVideoFrame&) {
|
||||
return SubmitResult::failed;
|
||||
}
|
||||
|
||||
|
||||
@@ -414,7 +414,7 @@ int ScreenCapturerWin::Init(const int fps, cb_desktop_data cb) {
|
||||
}
|
||||
cb_ = [this](unsigned char* data, int size, int w, int h,
|
||||
const char* reported_stream_id,
|
||||
const XNativeVideoFrame* native_frame) {
|
||||
const MiniRtcNativeVideoFrame* native_frame) {
|
||||
if (secure_desktop_capture_active_.load(std::memory_order_relaxed)) {
|
||||
return;
|
||||
}
|
||||
@@ -530,7 +530,7 @@ int ScreenCapturerWin::Destroy() {
|
||||
|
||||
void ScreenCapturerWin::EmitCapturedFrame(
|
||||
unsigned char* data, int size, int width, int height,
|
||||
const char* stream_id, const XNativeVideoFrame* native_frame) {
|
||||
const char* stream_id, const MiniRtcNativeVideoFrame* native_frame) {
|
||||
if (!cb_orig_) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ class ScreenCapturerWin : public ScreenCapturer {
|
||||
void RebuildAliasesFromImpl();
|
||||
void EmitCapturedFrame(unsigned char* data, int size, int width, int height,
|
||||
const char* stream_id,
|
||||
const XNativeVideoFrame* native_frame = nullptr);
|
||||
const MiniRtcNativeVideoFrame* native_frame = nullptr);
|
||||
void StopSecureCaptureThread();
|
||||
bool RestartCaptureBackendAfterSecureDesktop();
|
||||
void SecureDesktopCaptureLoop();
|
||||
|
||||
Reference in New Issue
Block a user