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 committed Jun 14, 2022
1 parent 4275a8b commit af5166f
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 af5166f

Please sign in to comment.