mirror of
https://github.com/rustdesk/magnum-opus.git
synced 2025-07-01 15:25:27 +00:00
Restructurization
This commit is contained in:
parent
d44526af83
commit
4d9bcd489b
14
Cargo.toml
14
Cargo.toml
@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "opus"
|
name = "magnum-opus"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
authors = ["Tad Hardesty <tad@platymuus.com>"]
|
authors = ["Tad Hardesty <tad@platymuus.com>", "Sergey Duck <sergeypechnikov326@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
description = "Safe Rust bindings for libopus"
|
description = "Safe Rust bindings for libopus"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
@ -10,9 +10,9 @@ keywords = ["opus", "codec", "voice", "sound", "audio"]
|
|||||||
categories = ["api-bindings", "encoding", "compression",
|
categories = ["api-bindings", "encoding", "compression",
|
||||||
"multimedia::audio", "multimedia::encoding"]
|
"multimedia::audio", "multimedia::encoding"]
|
||||||
|
|
||||||
repository = "https://github.com/SpaceManiac/opus-rs"
|
repository = "https://github.com/DuckerMan/magnum-opus"
|
||||||
documentation = "https://docs.rs/opus/0.2.1/opus/"
|
documentation = "https://docs.rs/magnum-opus"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
opus-sys = "0.2.0"
|
opusic-sys = "0.2.2"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
# opus-rs [](https://crates.io/crates/opus) [](https://docs.rs/opus/0.2.1/opus/)
|
# opus-rs [](https://crates.io/crates/magnum-opus) [](https://docs.rs/magnum-opus)
|
||||||
|
|
||||||
|
### This is the fork of @SpaceManiac repo, which now is abandoned
|
||||||
|
|
||||||
Safe Rust bindings for libopus. The rustdoc (available through `cargo doc`)
|
Safe Rust bindings for libopus. The rustdoc (available through `cargo doc`)
|
||||||
includes brief descriptions for methods, and detailed API information can be
|
includes brief descriptions for methods, and detailed API information can be
|
||||||
|
15
src/lib.rs
15
src/lib.rs
@ -12,13 +12,13 @@
|
|||||||
//! the [libopus documentation](https://opus-codec.org/docs/opus_api-1.1.2/).
|
//! the [libopus documentation](https://opus-codec.org/docs/opus_api-1.1.2/).
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
extern crate opus_sys as ffi;
|
extern crate opusic_sys as ffi;
|
||||||
extern crate libc;
|
|
||||||
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use libc::c_int;
|
use std::os::raw::c_int;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Constants
|
// Constants
|
||||||
@ -246,7 +246,7 @@ impl Encoder {
|
|||||||
/// Encode an Opus frame to a new buffer.
|
/// Encode an Opus frame to a new buffer.
|
||||||
pub fn encode_vec(&mut self, input: &[i16], max_size: usize) -> Result<Vec<u8>> {
|
pub fn encode_vec(&mut self, input: &[i16], max_size: usize) -> Result<Vec<u8>> {
|
||||||
let mut output: Vec<u8> = vec![0; max_size];
|
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);
|
output.truncate(result);
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@ -254,7 +254,7 @@ impl Encoder {
|
|||||||
/// Encode an Opus frame from floating point input to a new buffer.
|
/// 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>> {
|
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 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);
|
output.truncate(result);
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@ -552,7 +552,6 @@ pub mod packet {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use super::ffi;
|
use super::ffi;
|
||||||
use std::{ptr, slice};
|
use std::{ptr, slice};
|
||||||
use libc::c_int;
|
|
||||||
|
|
||||||
/// Get the bandwidth of an Opus packet.
|
/// Get the bandwidth of an Opus packet.
|
||||||
pub fn get_bandwidth(packet: &[u8]) -> Result<Bandwidth> {
|
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> {
|
pub fn combine(&mut self, input: &[&[u8]], output: &mut [u8]) -> Result<usize> {
|
||||||
let mut state = self.begin();
|
let mut state = self.begin();
|
||||||
for &packet in input {
|
for &packet in input {
|
||||||
try!(state.cat(packet));
|
state.cat(packet)?;
|
||||||
}
|
}
|
||||||
state.out(output)
|
state.out(output)
|
||||||
}
|
}
|
||||||
@ -748,7 +747,7 @@ impl<'rp, 'buf> RepacketizerState<'rp, 'buf> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn cat_move<'b2>(self, packet: &'b2 [u8]) -> Result<RepacketizerState<'rp, 'b2>> where 'buf: 'b2 {
|
pub fn cat_move<'b2>(self, packet: &'b2 [u8]) -> Result<RepacketizerState<'rp, 'b2>> where 'buf: 'b2 {
|
||||||
let mut shorter = self;
|
let mut shorter = self;
|
||||||
try!(shorter.cat(packet));
|
shorter.cat(packet)?;
|
||||||
Ok(shorter)
|
Ok(shorter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
//! Test that supplying empty packets does forward error correction.
|
//! Test that supplying empty packets does forward error correction.
|
||||||
|
|
||||||
extern crate opus;
|
extern crate magnum_opus;
|
||||||
use opus::*;
|
use magnum_opus::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn blah() {
|
fn blah() {
|
||||||
let mut opus = Decoder::new(48000, Channels::Mono).unwrap();
|
let mut magnum_opus = Decoder::new(48000, Channels::Mono).unwrap();
|
||||||
|
|
||||||
let mut output = vec![0i16; 5760];
|
let mut output = vec![0i16; 5760];
|
||||||
let size = opus.decode(&[], &mut output[..], true).unwrap();
|
let size = magnum_opus.decode(&[], &mut output[..], true).unwrap();
|
||||||
assert_eq!(size, 5760);
|
assert_eq!(size, 5760);
|
||||||
}
|
}
|
@ -1,15 +1,15 @@
|
|||||||
// Based on libopus/tests/test_opus_padding.c
|
// Based on libmagnum_opus/tests/test_magnum_opus_padding.c
|
||||||
|
|
||||||
/* Check for overflow in reading the padding length.
|
/* Check for overflow in reading the padding length.
|
||||||
* http://lists.xiph.org/pipermail/opus/2012-November/001834.html
|
* http://lists.xiph.org/pipermail/magnum_opus/2012-November/001834.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate opus;
|
extern crate magnum_opus;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_overflow() {
|
fn test_overflow() {
|
||||||
const PACKETSIZE: usize = 16909318;
|
const PACKETSIZE: usize = 16909318;
|
||||||
const CHANNELS: opus::Channels = opus::Channels::Stereo;
|
const CHANNELS: magnum_opus::Channels = magnum_opus::Channels::Stereo;
|
||||||
const FRAMESIZE: usize = 5760;
|
const FRAMESIZE: usize = 5760;
|
||||||
|
|
||||||
let mut input = vec![0xff; PACKETSIZE];
|
let mut input = vec![0xff; PACKETSIZE];
|
||||||
@ -19,11 +19,11 @@ fn test_overflow() {
|
|||||||
input[1] = 0x41;
|
input[1] = 0x41;
|
||||||
*input.last_mut().unwrap() = 0x0b;
|
*input.last_mut().unwrap() = 0x0b;
|
||||||
|
|
||||||
let mut decoder = opus::Decoder::new(48000, CHANNELS).unwrap();
|
let mut decoder = magnum_opus::Decoder::new(48000, CHANNELS).unwrap();
|
||||||
let result = decoder.decode(&input[..], &mut output[..], false);
|
let result = decoder.decode(&input[..], &mut output[..], false);
|
||||||
drop(decoder);
|
drop(decoder);
|
||||||
drop(input);
|
drop(input);
|
||||||
drop(output);
|
drop(output);
|
||||||
|
|
||||||
assert_eq!(result.unwrap_err().code(), opus::ErrorCode::InvalidPacket);
|
assert_eq!(result.unwrap_err().code(), magnum_opus::ErrorCode::InvalidPacket);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate opus;
|
extern crate magnum_opus;
|
||||||
|
|
||||||
fn check_ascii(s: &str) -> &str {
|
fn check_ascii(s: &str) -> &str {
|
||||||
for &b in s.as_bytes() {
|
for &b in s.as_bytes() {
|
||||||
@ -10,9 +10,9 @@ fn check_ascii(s: &str) -> &str {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn strings_ascii() {
|
fn strings_ascii() {
|
||||||
use opus::ErrorCode::*;
|
use magnum_opus::ErrorCode::*;
|
||||||
|
|
||||||
println!("\nVersion: {}", check_ascii(opus::version()));
|
println!("\nVersion: {}", check_ascii(magnum_opus::version()));
|
||||||
|
|
||||||
let codes = [BadArg, BufferTooSmall, InternalError, InvalidPacket,
|
let codes = [BadArg, BufferTooSmall, InternalError, InvalidPacket,
|
||||||
Unimplemented, InvalidState, AllocFail, Unknown];
|
Unimplemented, InvalidState, AllocFail, Unknown];
|
||||||
@ -26,7 +26,7 @@ const MONO_20MS: usize = 48000 * 1 * 20 / 1000;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_mono() {
|
fn encode_mono() {
|
||||||
let mut encoder = opus::Encoder::new(48000, opus::Channels::Mono, opus::Application::Audio).unwrap();
|
let mut encoder = magnum_opus::Encoder::new(48000, magnum_opus::Channels::Mono, magnum_opus::Application::Audio).unwrap();
|
||||||
|
|
||||||
let mut output = [0; 256];
|
let mut output = [0; 256];
|
||||||
let len = encoder.encode(&[0_i16; MONO_20MS], &mut output).unwrap();
|
let len = encoder.encode(&[0_i16; MONO_20MS], &mut output).unwrap();
|
||||||
@ -47,7 +47,7 @@ fn encode_mono() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_stereo() {
|
fn encode_stereo() {
|
||||||
let mut encoder = opus::Encoder::new(48000, opus::Channels::Stereo, opus::Application::Audio).unwrap();
|
let mut encoder = magnum_opus::Encoder::new(48000, magnum_opus::Channels::Stereo, magnum_opus::Application::Audio).unwrap();
|
||||||
|
|
||||||
let mut output = [0; 512];
|
let mut output = [0; 512];
|
||||||
let len = encoder.encode(&[0_i16; 2 * MONO_20MS], &mut output).unwrap();
|
let len = encoder.encode(&[0_i16; 2 * MONO_20MS], &mut output).unwrap();
|
||||||
@ -72,24 +72,24 @@ fn encode_stereo() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_bad_rate() {
|
fn encode_bad_rate() {
|
||||||
match opus::Encoder::new(48001, opus::Channels::Mono, opus::Application::Audio) {
|
match magnum_opus::Encoder::new(48001, magnum_opus::Channels::Mono, magnum_opus::Application::Audio) {
|
||||||
Ok(_) => panic!("Encoder::new did not return BadArg"),
|
Ok(_) => panic!("Encoder::new did not return BadArg"),
|
||||||
Err(err) => assert_eq!(err.code(), opus::ErrorCode::BadArg),
|
Err(err) => assert_eq!(err.code(), magnum_opus::ErrorCode::BadArg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_bad_buffer() {
|
fn encode_bad_buffer() {
|
||||||
let mut encoder = opus::Encoder::new(48000, opus::Channels::Stereo, opus::Application::Audio).unwrap();
|
let mut encoder = magnum_opus::Encoder::new(48000, magnum_opus::Channels::Stereo, magnum_opus::Application::Audio).unwrap();
|
||||||
match encoder.encode(&[1_i16; 2 * MONO_20MS], &mut [0; 0]) {
|
match encoder.encode(&[1_i16; 2 * MONO_20MS], &mut [0; 0]) {
|
||||||
Ok(_) => panic!("encode with 0-length buffer did not return BadArg"),
|
Ok(_) => panic!("encode with 0-length buffer did not return BadArg"),
|
||||||
Err(err) => assert_eq!(err.code(), opus::ErrorCode::BadArg),
|
Err(err) => assert_eq!(err.code(), magnum_opus::ErrorCode::BadArg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn repacketizer() {
|
fn repacketizer() {
|
||||||
let mut rp = opus::Repacketizer::new().unwrap();
|
let mut rp = magnum_opus::Repacketizer::new().unwrap();
|
||||||
let mut out = [0; 256];
|
let mut out = [0; 256];
|
||||||
|
|
||||||
for _ in 0..2 {
|
for _ in 0..2 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user