Restructurization

This commit is contained in:
Sergey Duck
2020-05-26 13:23:42 +03:00
parent d44526af83
commit 4d9bcd489b
6 changed files with 37 additions and 36 deletions

View File

@@ -12,13 +12,13 @@
//! the [libopus documentation](https://opus-codec.org/docs/opus_api-1.1.2/).
#![warn(missing_docs)]
extern crate opus_sys as ffi;
extern crate libc;
extern crate opusic_sys as ffi;
use std::ffi::CStr;
use std::marker::PhantomData;
use libc::c_int;
use std::os::raw::c_int;
// ============================================================================
// Constants
@@ -246,7 +246,7 @@ impl Encoder {
/// Encode an Opus frame to a new buffer.
pub fn encode_vec(&mut self, input: &[i16], max_size: usize) -> Result<Vec<u8>> {
let mut output: Vec<u8> = vec![0; max_size];
let result = try!(self.encode(input, output.as_mut_slice()));
let result = self.encode(input, output.as_mut_slice())?;
output.truncate(result);
Ok(output)
}
@@ -254,7 +254,7 @@ impl Encoder {
/// Encode an Opus frame from floating point input to a new buffer.
pub fn encode_vec_float(&mut self, input: &[f32], max_size: usize) -> Result<Vec<u8>> {
let mut output: Vec<u8> = vec![0; max_size];
let result = try!(self.encode_float(input, output.as_mut_slice()));
let result = self.encode_float(input, output.as_mut_slice())?;
output.truncate(result);
Ok(output)
}
@@ -552,7 +552,6 @@ pub mod packet {
use super::*;
use super::ffi;
use std::{ptr, slice};
use libc::c_int;
/// Get the bandwidth of an Opus packet.
pub fn get_bandwidth(packet: &[u8]) -> Result<Bandwidth> {
@@ -702,7 +701,7 @@ impl Repacketizer {
pub fn combine(&mut self, input: &[&[u8]], output: &mut [u8]) -> Result<usize> {
let mut state = self.begin();
for &packet in input {
try!(state.cat(packet));
state.cat(packet)?;
}
state.out(output)
}
@@ -748,7 +747,7 @@ impl<'rp, 'buf> RepacketizerState<'rp, 'buf> {
#[inline]
pub fn cat_move<'b2>(self, packet: &'b2 [u8]) -> Result<RepacketizerState<'rp, 'b2>> where 'buf: 'b2 {
let mut shorter = self;
try!(shorter.cat(packet));
shorter.cat(packet)?;
Ok(shorter)
}