fix: workaround physical display rotation (#9696)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-10-19 10:57:42 +08:00 committed by GitHub
parent 675ffe0381
commit 8c8a643cce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 6 deletions

View File

@ -156,7 +156,7 @@ pub trait TraitPixelBuffer {
#[cfg(not(any(target_os = "ios")))]
pub enum Frame<'a> {
PixelBuffer(PixelBuffer<'a>),
Texture(*mut c_void),
Texture((*mut c_void, usize)),
}
#[cfg(not(any(target_os = "ios")))]
@ -164,7 +164,7 @@ impl Frame<'_> {
pub fn valid<'a>(&'a self) -> bool {
match self {
Frame::PixelBuffer(pixelbuffer) => !pixelbuffer.data().is_empty(),
Frame::Texture(texture) => !texture.is_null(),
Frame::Texture((texture, _)) => !texture.is_null(),
}
}
@ -186,7 +186,7 @@ impl Frame<'_> {
pub enum EncodeInput<'a> {
YUV(&'a [u8]),
Texture(*mut c_void),
Texture((*mut c_void, usize)),
}
impl<'a> EncodeInput<'a> {
@ -197,7 +197,7 @@ impl<'a> EncodeInput<'a> {
}
}
pub fn texture(&self) -> ResultType<*mut c_void> {
pub fn texture(&self) -> ResultType<(*mut c_void, usize)> {
match self {
Self::Texture(f) => Ok(*f),
_ => bail!("not texture frame"),

View File

@ -101,7 +101,12 @@ impl EncoderApi for VRamEncoder {
frame: EncodeInput,
ms: i64,
) -> ResultType<hbb_common::message_proto::VideoFrame> {
let texture = frame.texture()?;
let (texture, rotation) = frame.texture()?;
if rotation != 0 {
// to-do: support rotation
// Both the encoder and display(w,h) information need to be changed.
bail!("rotation not supported");
}
let mut vf = VideoFrame::new();
let mut frames = Vec::new();
for frame in self

View File

@ -253,7 +253,17 @@ impl Capturer {
pub fn frame<'a>(&'a mut self, timeout: UINT) -> io::Result<Frame<'a>> {
if self.output_texture {
Ok(Frame::Texture(self.get_texture(timeout)?))
let rotation = match self.display.rotation() {
DXGI_MODE_ROTATION_IDENTITY | DXGI_MODE_ROTATION_UNSPECIFIED => 0,
DXGI_MODE_ROTATION_ROTATE90 => 90,
DXGI_MODE_ROTATION_ROTATE180 => 180,
DXGI_MODE_ROTATION_ROTATE270 => 270,
_ => {
// Unsupported rotation, try anyway
0
}
};
Ok(Frame::Texture((self.get_texture(timeout)?, rotation)))
} else {
let width = self.width;
let height = self.height;