*: refactor setters to return self

This commit is contained in:
meh
2015-09-26 18:01:23 +02:00
parent 4747a5a123
commit 510e8604b6
16 changed files with 254 additions and 116 deletions

View File

@ -19,9 +19,9 @@ impl Audio {
#[inline]
pub unsafe fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) {
self.set_format(format);
self.set_samples(samples);
self.set_channel_layout(layout);
self.set_format(format)
.set_samples(samples)
.set_channel_layout(layout);
av_frame_get_buffer(self.as_mut_ptr(), 0);
}
@ -58,10 +58,12 @@ impl Audio {
}
#[inline]
pub fn set_format(&mut self, value: format::Sample) {
pub fn set_format(&mut self, value: format::Sample) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).format = mem::transmute::<AVSampleFormat, c_int>(value.into());
}
self
}
#[inline]
@ -72,10 +74,12 @@ impl Audio {
}
#[inline]
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
pub fn set_channel_layout(&mut self, value: ChannelLayout) -> &mut Self {
unsafe {
av_frame_set_channel_layout(self.as_mut_ptr(), value.bits() as int64_t);
}
self
}
#[inline]
@ -86,10 +90,12 @@ impl Audio {
}
#[inline]
pub fn set_channels(&mut self, value: u16) {
pub fn set_channels(&mut self, value: u16) -> &mut Self {
unsafe {
av_frame_set_channels(self.as_mut_ptr(), value as c_int);
}
self
}
#[inline]
@ -100,10 +106,12 @@ impl Audio {
}
#[inline]
pub fn set_rate(&mut self, value: u32) {
pub fn set_rate(&mut self, value: u32) -> &mut Self {
unsafe {
av_frame_set_sample_rate(self.as_mut_ptr(), value as c_int);
}
self
}
#[inline]
@ -114,10 +122,12 @@ impl Audio {
}
#[inline]
pub fn set_samples(&mut self, value: usize) {
pub fn set_samples(&mut self, value: usize) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).nb_samples = value as c_int;
}
self
}
#[inline]

View File

@ -85,10 +85,12 @@ impl Frame {
}
}
pub fn set_pts(&mut self, value: Option<i64>) {
pub fn set_pts(&mut self, value: Option<i64>) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).pts = value.unwrap_or(AV_NOPTS_VALUE);
}
self
}
pub fn timestamp(&self) -> Option<i64> {
@ -118,10 +120,12 @@ impl Frame {
}
}
pub fn set_metadata(&mut self, value: Dictionary) {
pub fn set_metadata(&mut self, value: Dictionary) -> &mut Self {
unsafe {
av_frame_set_metadata(self.as_mut_ptr(), value.disown());
}
self
}
pub fn side_data(&self, kind: side_data::Type) -> Option<SideData> {

View File

@ -22,9 +22,9 @@ impl Video {
#[inline]
pub unsafe fn alloc(&mut self, format: format::Pixel, width: u32, height: u32) {
self.set_format(format);
self.set_width(width);
self.set_height(height);
self.set_format(format)
.set_width(width)
.set_height(height);
av_frame_get_buffer(self.as_mut_ptr(), 32);
}
@ -61,10 +61,12 @@ impl Video {
}
#[inline]
pub fn set_format(&mut self, value: format::Pixel) {
pub fn set_format(&mut self, value: format::Pixel) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).format = mem::transmute::<AVPixelFormat, c_int>(value.into());
}
self
}
#[inline]
@ -75,10 +77,12 @@ impl Video {
}
#[inline]
pub fn set_kind(&mut self, value: picture::Type) {
pub fn set_kind(&mut self, value: picture::Type) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).pict_type = value.into();
}
self
}
#[inline]
@ -110,10 +114,12 @@ impl Video {
}
#[inline]
pub fn set_width(&mut self, value: u32) {
pub fn set_width(&mut self, value: u32) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).width = value as c_int;
}
self
}
#[inline]
@ -124,10 +130,12 @@ impl Video {
}
#[inline]
pub fn set_height(&mut self, value: u32) {
pub fn set_height(&mut self, value: u32) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).height = value as c_int;
}
self
}
#[inline]
@ -138,10 +146,12 @@ impl Video {
}
#[inline]
pub fn set_color_space(&mut self, value: color::Space) {
pub fn set_color_space(&mut self, value: color::Space) -> &mut Self {
unsafe {
av_frame_set_colorspace(self.as_mut_ptr(), value.into());
}
self
}
#[inline]
@ -152,10 +162,12 @@ impl Video {
}
#[inline]
pub fn set_color_range(&mut self, value: color::Range) {
pub fn set_color_range(&mut self, value: color::Range) -> &mut Self {
unsafe {
av_frame_set_color_range(self.as_mut_ptr(), value.into());
}
self
}
#[inline]
@ -166,10 +178,12 @@ impl Video {
}
#[inline]
pub fn set_color_primaries(&mut self, value: color::Primaries) {
pub fn set_color_primaries(&mut self, value: color::Primaries) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).color_primaries = value.into();
}
self
}
#[inline]
@ -180,10 +194,12 @@ impl Video {
}
#[inline]
pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) {
pub fn set_color_transfer_characteristic(&mut self, value: color::TransferCharacteristic) -> &mut Self {
unsafe {
(*self.as_mut_ptr()).color_trc = value.into();
}
self
}
#[inline]