Fix stride align
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
42c95f71f6
commit
5aa97faedd
@ -380,6 +380,7 @@ impl Decoder {
|
|||||||
fn handle_hw_video_frame(
|
fn handle_hw_video_frame(
|
||||||
decoder: &mut HwDecoder,
|
decoder: &mut HwDecoder,
|
||||||
frames: &EncodedVideoFrames,
|
frames: &EncodedVideoFrames,
|
||||||
|
stride_align: usize,
|
||||||
fmt: ImageFormat,
|
fmt: ImageFormat,
|
||||||
raw: &mut Vec<u8>,
|
raw: &mut Vec<u8>,
|
||||||
i420: &mut Vec<u8>,
|
i420: &mut Vec<u8>,
|
||||||
@ -388,7 +389,7 @@ impl Decoder {
|
|||||||
for h264 in frames.frames.iter() {
|
for h264 in frames.frames.iter() {
|
||||||
for image in decoder.decode(&h264.data)? {
|
for image in decoder.decode(&h264.data)? {
|
||||||
// TODO: just process the last frame
|
// TODO: just process the last frame
|
||||||
if image.to_fmt(fmt, raw, i420).is_ok() {
|
if image.to_fmt(stride_align, fmt, raw, i420).is_ok() {
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,12 +401,13 @@ impl Decoder {
|
|||||||
fn handle_mediacodec_video_frame(
|
fn handle_mediacodec_video_frame(
|
||||||
decoder: &mut MediaCodecDecoder,
|
decoder: &mut MediaCodecDecoder,
|
||||||
frames: &EncodedVideoFrames,
|
frames: &EncodedVideoFrames,
|
||||||
|
stride_align: usize,
|
||||||
fmt: ImageFormat,
|
fmt: ImageFormat,
|
||||||
raw: &mut Vec<u8>,
|
raw: &mut Vec<u8>,
|
||||||
) -> ResultType<bool> {
|
) -> ResultType<bool> {
|
||||||
let mut ret = false;
|
let mut ret = false;
|
||||||
for h264 in frames.frames.iter() {
|
for h264 in frames.frames.iter() {
|
||||||
return decoder.decode(&h264.data, fmt, raw);
|
return decoder.decode(&h264.data, stride_align, fmt, raw);
|
||||||
}
|
}
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ pub struct HwDecoderImage<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HwDecoderImage<'_> {
|
impl HwDecoderImage<'_> {
|
||||||
pub fn to_fmt(&self, fmt: ImageFormat, fmt_data: &mut Vec<u8>, i420: &mut Vec<u8>) -> ResultType<()> {
|
pub fn to_fmt(&self, stride_align: usize, fmt: ImageFormat, fmt_data: &mut Vec<u8>, i420: &mut Vec<u8>) -> ResultType<()> {
|
||||||
let frame = self.frame;
|
let frame = self.frame;
|
||||||
match frame.pixfmt {
|
match frame.pixfmt {
|
||||||
AVPixelFormat::AV_PIX_FMT_NV12 => hw::hw_nv12_to(
|
AVPixelFormat::AV_PIX_FMT_NV12 => hw::hw_nv12_to(
|
||||||
@ -269,12 +269,12 @@ impl HwDecoderImage<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bgra(&self, bgra: &mut Vec<u8>, i420: &mut Vec<u8>) -> ResultType<()> {
|
pub fn bgra(&self, stride_align: usize, bgra: &mut Vec<u8>, i420: &mut Vec<u8>) -> ResultType<()> {
|
||||||
self.to_fmt(ImageFormat::ARGB, bgra, i420)
|
self.to_fmt(stride_align, ImageFormat::ARGB, bgra, i420)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rgba(&self, rgba: &mut Vec<u8>, i420: &mut Vec<u8>) -> ResultType<()> {
|
pub fn rgba(&self, stride_align: usize, rgba: &mut Vec<u8>, i420: &mut Vec<u8>) -> ResultType<()> {
|
||||||
self.to_fmt(ImageFormat::ABGR, rgba, i420)
|
self.to_fmt(stride_align, ImageFormat::ABGR, rgba, i420)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,8 @@ impl MediaCodecDecoder {
|
|||||||
MediaCodecDecoders { h264, h265 }
|
MediaCodecDecoders { h264, h265 }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode(&mut self, data: &[u8], fmt: ImageFormat, raw: &mut Vec<u8>) -> ResultType<bool> {
|
// to-do: apply stride_align to raw output data
|
||||||
|
pub fn decode(&mut self, data: &[u8], stride_align: usize, fmt: ImageFormat, raw: &mut Vec<u8>) -> ResultType<bool> {
|
||||||
match self.dequeue_input_buffer(Duration::from_millis(10))? {
|
match self.dequeue_input_buffer(Duration::from_millis(10))? {
|
||||||
Some(mut input_buffer) => {
|
Some(mut input_buffer) => {
|
||||||
let mut buf = input_buffer.buffer_mut();
|
let mut buf = input_buffer.buffer_mut();
|
||||||
|
@ -541,13 +541,15 @@ impl Image {
|
|||||||
|
|
||||||
pub fn to(&self, fmt: ImageFormat, stride_align: usize, dst: &mut Vec<u8>) {
|
pub fn to(&self, fmt: ImageFormat, stride_align: usize, dst: &mut Vec<u8>) {
|
||||||
let h = self.height();
|
let h = self.height();
|
||||||
let mut w = self.width();
|
let w = self.width();
|
||||||
let bps = match fmt {
|
let bytes_per_pixel = match fmt {
|
||||||
ImageFormat::Raw => 3,
|
ImageFormat::Raw => 3,
|
||||||
ImageFormat::ARGB | ImageFormat::ABGR => 4,
|
ImageFormat::ARGB | ImageFormat::ABGR => 4,
|
||||||
};
|
};
|
||||||
w = (w + stride_align - 1) & !(stride_align - 1);
|
// https://github.com/lemenkov/libyuv/blob/6900494d90ae095d44405cd4cc3f346971fa69c9/source/convert_argb.cc#L128
|
||||||
dst.resize(h * w * bps, 0);
|
// https://github.com/lemenkov/libyuv/blob/6900494d90ae095d44405cd4cc3f346971fa69c9/source/convert_argb.cc#L129
|
||||||
|
let bytes_per_row = (w * bytes_per_pixel + stride_align - 1) & !(stride_align - 1);
|
||||||
|
dst.resize(h * bytes_per_row, 0);
|
||||||
let img = self.inner();
|
let img = self.inner();
|
||||||
unsafe {
|
unsafe {
|
||||||
match fmt {
|
match fmt {
|
||||||
@ -560,7 +562,7 @@ impl Image {
|
|||||||
img.planes[2],
|
img.planes[2],
|
||||||
img.stride[2],
|
img.stride[2],
|
||||||
dst.as_mut_ptr(),
|
dst.as_mut_ptr(),
|
||||||
(w * bps) as _,
|
bytes_per_row as _,
|
||||||
self.width() as _,
|
self.width() as _,
|
||||||
self.height() as _,
|
self.height() as _,
|
||||||
);
|
);
|
||||||
@ -574,7 +576,7 @@ impl Image {
|
|||||||
img.planes[2],
|
img.planes[2],
|
||||||
img.stride[2],
|
img.stride[2],
|
||||||
dst.as_mut_ptr(),
|
dst.as_mut_ptr(),
|
||||||
(w * bps) as _,
|
bytes_per_row as _,
|
||||||
self.width() as _,
|
self.width() as _,
|
||||||
self.height() as _,
|
self.height() as _,
|
||||||
);
|
);
|
||||||
@ -588,7 +590,7 @@ impl Image {
|
|||||||
img.planes[2],
|
img.planes[2],
|
||||||
img.stride[2],
|
img.stride[2],
|
||||||
dst.as_mut_ptr(),
|
dst.as_mut_ptr(),
|
||||||
(w * bps) as _,
|
bytes_per_row as _,
|
||||||
self.width() as _,
|
self.width() as _,
|
||||||
self.height() as _,
|
self.height() as _,
|
||||||
);
|
);
|
||||||
|
@ -40,7 +40,9 @@ pub const CLIPBOARD_INTERVAL: u64 = 333;
|
|||||||
pub const SYNC_PEER_INFO_DISPLAYS: i32 = 1;
|
pub const SYNC_PEER_INFO_DISPLAYS: i32 = 1;
|
||||||
|
|
||||||
#[cfg(all(target_os = "macos", feature = "flutter_texture_render"))]
|
#[cfg(all(target_os = "macos", feature = "flutter_texture_render"))]
|
||||||
pub const STRIDE_ALIGN: usize = 16;
|
// https://developer.apple.com/forums/thread/712709
|
||||||
|
// Memory alignment should be multiple of 64.
|
||||||
|
pub const STRIDE_ALIGN: usize = 64;
|
||||||
#[cfg(not(all(target_os = "macos", feature = "flutter_texture_render")))]
|
#[cfg(not(all(target_os = "macos", feature = "flutter_texture_render")))]
|
||||||
pub const STRIDE_ALIGN: usize = 1;
|
pub const STRIDE_ALIGN: usize = 1;
|
||||||
|
|
||||||
|
@ -207,8 +207,8 @@ impl VideoRenderer {
|
|||||||
self.height = height;
|
self.height = height;
|
||||||
self.data_len = if width > 0 && height > 0 {
|
self.data_len = if width > 0 && height > 0 {
|
||||||
let sa1 = crate::common::STRIDE_ALIGN - 1;
|
let sa1 = crate::common::STRIDE_ALIGN - 1;
|
||||||
let w = (width as usize + sa1) & !sa1;
|
let row_bytes = (width as usize * 4 + sa1) & !sa1;
|
||||||
w * (height as usize) * 4
|
row_bytes * height as usize
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user