}
/// Reports whether the current stream is video stream.
pub fn is_video(&self) -> bool {
- match *self {
- NACodecTypeInfo::Video(_) => true,
- _ => false,
- }
+ matches!(*self, NACodecTypeInfo::Video(_))
}
/// Reports whether the current stream is audio stream.
pub fn is_audio(&self) -> bool {
- match *self {
- NACodecTypeInfo::Audio(_) => true,
- _ => false,
- }
+ matches!(*self, NACodecTypeInfo::Audio(_))
}
}
impl NAAudioBuffer<u8> {
/// Constructs a new `NAAudioBuffer` instance.
pub fn new_from_buf(info: NAAudioInfo, data: NABufferRef<Vec<u8>>, chmap: NAChannelMap) -> Self {
- let len = data.len();
+ let len = data.len() * 8 / chmap.num_channels() / (info.format.bits as usize);
+
NAAudioBuffer { info, data, chmap, offs: Vec::new(), len, stride: 0, step: 0 }
}
}
}
max_depth = max(max_depth, chr.get_depth());
}
- let unfit_elem_size = match fmt.get_elem_size() {
- 2 | 4 => false,
- _ => true,
- };
+ let unfit_elem_size = !matches!(fmt.get_elem_size(), 2 | 4);
//todo semi-packed like NV12
if fmt.is_paletted() {
impl NACodecInfo {
/// Constructs a new instance of `NACodecInfo`.
pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self {
- let extradata = match edata {
- None => None,
- Some(vec) => Some(Arc::new(vec)),
- };
- NACodecInfo { name, properties: p, extradata }
+ NACodecInfo { name, properties: p, extradata: edata.map(Arc::new) }
}
/// Constructs a new reference-counted instance of `NACodecInfo`.
pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option<Arc<Vec<u8>>>) -> Self {
let mut mval = 0;
let mut base = 0;
for ch in val.chars() {
- if ch >= '0' && ch <= '9' {
+ if ('0'..='9').contains(&ch) {
mval = mval * 10 + u64::from((ch as u8) - b'0');
base += 1;
if base > 3 { break; }
}
/// Returns stream duration.
pub fn get_duration(&self) -> u64 { self.duration }
+ /// Constructs a new timestamp.
+ pub fn make_ts(&self, pts: Option<u64>, dts: Option<u64>, duration: Option<u64>) -> NATimeInfo {
+ NATimeInfo::new(pts, dts, duration, self.tb_num, self.tb_den)
+ }
/// Converts current instance into a reference-counted one.
pub fn into_ref(self) -> NAStreamRef { Arc::new(self) }
}
impl NAPacket {
/// Constructs a new `NAPacket` instance.
- pub fn new(str: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
+ pub fn new(stream: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
// let mut vec: Vec<u8> = Vec::new();
// vec.resize(size, 0);
- NAPacket { stream: str, ts, keyframe: kf, buffer: NABufferRef::new(vec), side_data: Vec::new() }
+ NAPacket { stream, ts, keyframe: kf, buffer: NABufferRef::new(vec), side_data: Vec::new() }
}
/// Constructs a new `NAPacket` instance reusing a buffer reference.
- pub fn new_from_refbuf(str: NAStreamRef, ts: NATimeInfo, kf: bool, buffer: NABufferRef<Vec<u8>>) -> Self {
- NAPacket { stream: str, ts, keyframe: kf, buffer, side_data: Vec::new() }
+ pub fn new_from_refbuf(stream: NAStreamRef, ts: NATimeInfo, kf: bool, buffer: NABufferRef<Vec<u8>>) -> Self {
+ NAPacket { stream, ts, keyframe: kf, buffer, side_data: Vec::new() }
}
/// Returns information about the stream packet belongs to.
pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() }
/// Adds side data for a packet.
pub fn add_side_data(&mut self, side_data: NASideData) { self.side_data.push(side_data); }
/// Assigns packet to a new stream.
- pub fn reassign(&mut self, str: NAStreamRef, ts: NATimeInfo) {
- self.stream = str;
+ pub fn reassign(&mut self, stream: NAStreamRef, ts: NATimeInfo) {
+ self.stream = stream;
self.ts = ts;
}
}