Skip to content

Commit 447b047

Browse files
Tage Johanssontage64
Tage Johansson
authored andcommitted
Fix incorrect sizes for plane and data slices for audio frames.
1 parent 022eaa2 commit 447b047

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/util/frame/audio.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,18 @@ impl Audio {
144144
panic!("unsupported type");
145145
}
146146

147-
unsafe { slice::from_raw_parts((*self.as_ptr()).data[index] as *const T, self.samples()) }
147+
if self.is_planar() {
148+
unsafe {
149+
slice::from_raw_parts((*self.as_ptr()).data[index] as *const T, self.samples())
150+
}
151+
} else {
152+
unsafe {
153+
slice::from_raw_parts(
154+
(*self.as_ptr()).data[0] as *const T,
155+
self.samples() * usize::from(self.channels()),
156+
)
157+
}
158+
}
148159
}
149160

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

160-
unsafe {
161-
slice::from_raw_parts_mut((*self.as_mut_ptr()).data[index] as *mut T, self.samples())
171+
if self.is_planar() {
172+
unsafe {
173+
slice::from_raw_parts_mut(
174+
(*self.as_mut_ptr()).data[index] as *mut T,
175+
self.samples(),
176+
)
177+
}
178+
} else {
179+
unsafe {
180+
slice::from_raw_parts_mut(
181+
(*self.as_mut_ptr()).data[0] as *mut T,
182+
self.samples() * usize::from(self.channels()),
183+
)
184+
}
162185
}
163186
}
164187

@@ -171,7 +194,7 @@ impl Audio {
171194
unsafe {
172195
slice::from_raw_parts(
173196
(*self.as_ptr()).data[index],
174-
(*self.as_ptr()).linesize[index] as usize,
197+
(*self.as_ptr()).linesize[0] as usize,
175198
)
176199
}
177200
}
@@ -185,7 +208,7 @@ impl Audio {
185208
unsafe {
186209
slice::from_raw_parts_mut(
187210
(*self.as_mut_ptr()).data[index],
188-
(*self.as_ptr()).linesize[index] as usize,
211+
(*self.as_ptr()).linesize[0] as usize,
189212
)
190213
}
191214
}

0 commit comments

Comments
 (0)