From 32bf1b37ac8bb1358e0dbe273de7cdb44eefbb9b Mon Sep 17 00:00:00 2001 From: meh Date: Tue, 9 Jun 2015 23:47:10 +0200 Subject: [PATCH] util/frame: only Frame needs to be Send --- src/util/frame/audio.rs | 32 +++++++++++++++++++++++++++++--- src/util/frame/mod.rs | 4 ++-- src/util/frame/video.rs | 2 -- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/util/frame/audio.rs b/src/util/frame/audio.rs index 4ac5894..f1c5b2f 100644 --- a/src/util/frame/audio.rs +++ b/src/util/frame/audio.rs @@ -127,7 +127,7 @@ impl Audio { 1 } else { - self.samples() + self.channels() as usize } } @@ -162,9 +162,35 @@ impl Audio { mem::size_of::() * self.samples()) } } -} -unsafe impl Send for Audio { } + pub fn data(&self) -> Vec<&[u8]> { + let mut result = Vec::new(); + + unsafe { + for i in 0 .. self.planes() { + result.push(slice::from_raw_parts( + (*self.as_ptr()).data[i], + (*self.as_ptr()).linesize[0] as usize)); + } + } + + result + } + + pub fn data_mut(&mut self) -> Vec<&mut [u8]> { + let mut result = Vec::new(); + + unsafe { + for i in 0 .. self.planes() { + result.push(slice::from_raw_parts_mut( + (*self.as_mut_ptr()).data[i], + (*self.as_ptr()).linesize[0] as usize)); + } + } + + result + } +} impl Deref for Audio { type Target = Frame; diff --git a/src/util/frame/mod.rs b/src/util/frame/mod.rs index 5a7b59a..8443f13 100644 --- a/src/util/frame/mod.rs +++ b/src/util/frame/mod.rs @@ -31,6 +31,8 @@ pub struct Frame { _own: bool, } +unsafe impl Send for Frame { } + impl Frame { pub unsafe fn wrap(ptr: *mut AVFrame) -> Self { Frame { ptr: ptr, _own: false } @@ -149,8 +151,6 @@ impl Frame { } } -unsafe impl Send for Frame { } - impl Drop for Frame { fn drop(&mut self) { unsafe { diff --git a/src/util/frame/video.rs b/src/util/frame/video.rs index 23dd429..3672e6e 100644 --- a/src/util/frame/video.rs +++ b/src/util/frame/video.rs @@ -261,8 +261,6 @@ impl Video { } } -unsafe impl Send for Video { } - impl Deref for Video { type Target = Frame;