Skip to content

Commit

Permalink
Fix incorrect sizes for plane and data slices for audio frames.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tage Johansson authored and tage64 committed Oct 14, 2022
1 parent 022eaa2 commit 447b047
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/util/frame/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,18 @@ impl Audio {
panic!("unsupported type");
}

unsafe { slice::from_raw_parts((*self.as_ptr()).data[index] as *const T, self.samples()) }
if self.is_planar() {
unsafe {
slice::from_raw_parts((*self.as_ptr()).data[index] as *const T, self.samples())
}
} else {
unsafe {
slice::from_raw_parts(
(*self.as_ptr()).data[0] as *const T,
self.samples() * usize::from(self.channels()),
)
}
}
}

#[inline]
Expand All @@ -157,8 +168,20 @@ impl Audio {
panic!("unsupported type");
}

unsafe {
slice::from_raw_parts_mut((*self.as_mut_ptr()).data[index] as *mut T, self.samples())
if self.is_planar() {
unsafe {
slice::from_raw_parts_mut(
(*self.as_mut_ptr()).data[index] as *mut T,
self.samples(),
)
}
} else {
unsafe {
slice::from_raw_parts_mut(
(*self.as_mut_ptr()).data[0] as *mut T,
self.samples() * usize::from(self.channels()),
)
}
}
}

Expand All @@ -171,7 +194,7 @@ impl Audio {
unsafe {
slice::from_raw_parts(
(*self.as_ptr()).data[index],
(*self.as_ptr()).linesize[index] as usize,
(*self.as_ptr()).linesize[0] as usize,
)
}
}
Expand All @@ -185,7 +208,7 @@ impl Audio {
unsafe {
slice::from_raw_parts_mut(
(*self.as_mut_ptr()).data[index],
(*self.as_ptr()).linesize[index] as usize,
(*self.as_ptr()).linesize[0] as usize,
)
}
}
Expand Down

0 comments on commit 447b047

Please sign in to comment.