From 4cae7a51b74234081c89bbb8ddc3608111cbab88 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 4 Feb 2026 18:22:20 +0100 Subject: [PATCH] videoplayer: use SDL YUV texture update function instead of manual copying --- videoplayer/src/videodec.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/videoplayer/src/videodec.rs b/videoplayer/src/videodec.rs index d439537..f54e46a 100644 --- a/videoplayer/src/videodec.rs +++ b/videoplayer/src/videodec.rs @@ -338,26 +338,14 @@ impl Advance for FrameSkipMode { fn output_yuv(yuv_texture: &mut Texture, buf: &NAVideoBuffer, width: usize, height: usize) { let src = buf.get_data(); let ysstride = buf.get_stride(0); - let ysrc = &src[buf.get_offset(0)..]; + let ysrc = &src[buf.get_offset(0)..][..ysstride * height]; let usstride = buf.get_stride(2); - let usrc = &src[buf.get_offset(2)..]; + let usrc = &src[buf.get_offset(2)..][..usstride * (height / 2)]; let vsstride = buf.get_stride(1); - let vsrc = &src[buf.get_offset(1)..]; - yuv_texture.with_lock(None, |buffer: &mut [u8], pitch: usize| { - let csize = pitch.min(width); - for (dline, sline) in buffer.chunks_exact_mut(pitch).take(height).zip(ysrc.chunks_exact(ysstride)) { - dline[..csize].copy_from_slice(&sline[..csize]); - } - let coff = pitch * height; - let csize = (pitch / 2).min(width / 2); - for (dline, sline) in buffer[coff..].chunks_exact_mut(pitch / 2).take(height/2).zip(vsrc.chunks(vsstride)) { - dline[..csize].copy_from_slice(&sline[..csize]); - } - let coff = pitch * height + (pitch / 2) * (height / 2); - for (dline, sline) in buffer[coff..].chunks_exact_mut(pitch / 2).take(height/2).zip(usrc.chunks(usstride)) { - dline[..csize].copy_from_slice(&sline[..csize]); - } - }).expect("surface should be locked"); + let vsrc = &src[buf.get_offset(1)..][..vsstride * (height / 2)]; + let rect = Some(sdl2::rect::Rect::new(0, 0, width as u32, height as u32)); + yuv_texture.update_yuv(rect, ysrc, ysstride, vsrc, vsstride, usrc, usstride) + .expect("YUV surface updated"); } -- 2.39.5