Commit | Line | Data |
---|---|---|
22cb00db | 1 | use std::cmp::max; |
5869fd63 | 2 | use std::collections::HashMap; |
83e603fa | 3 | use std::fmt; |
2422d969 | 4 | use std::sync::Arc; |
4e8b4f31 | 5 | pub use crate::formats::*; |
1a967e6b | 6 | pub use crate::refs::*; |
94dbb551 | 7 | |
5869fd63 | 8 | #[allow(dead_code)] |
66116504 | 9 | #[derive(Clone,Copy,PartialEq)] |
5869fd63 KS |
10 | pub struct NAAudioInfo { |
11 | sample_rate: u32, | |
12 | channels: u8, | |
13 | format: NASoniton, | |
14 | block_len: usize, | |
15 | } | |
16 | ||
17 | impl NAAudioInfo { | |
18 | pub fn new(sr: u32, ch: u8, fmt: NASoniton, bl: usize) -> Self { | |
19 | NAAudioInfo { sample_rate: sr, channels: ch, format: fmt, block_len: bl } | |
20 | } | |
66116504 KS |
21 | pub fn get_sample_rate(&self) -> u32 { self.sample_rate } |
22 | pub fn get_channels(&self) -> u8 { self.channels } | |
23 | pub fn get_format(&self) -> NASoniton { self.format } | |
24 | pub fn get_block_len(&self) -> usize { self.block_len } | |
5869fd63 KS |
25 | } |
26 | ||
83e603fa KS |
27 | impl fmt::Display for NAAudioInfo { |
28 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
29 | write!(f, "{} Hz, {} ch", self.sample_rate, self.channels) | |
30 | } | |
31 | } | |
32 | ||
5869fd63 | 33 | #[allow(dead_code)] |
66116504 | 34 | #[derive(Clone,Copy,PartialEq)] |
5869fd63 | 35 | pub struct NAVideoInfo { |
66116504 KS |
36 | width: usize, |
37 | height: usize, | |
5869fd63 KS |
38 | flipped: bool, |
39 | format: NAPixelFormaton, | |
40 | } | |
41 | ||
42 | impl NAVideoInfo { | |
66116504 | 43 | pub fn new(w: usize, h: usize, flip: bool, fmt: NAPixelFormaton) -> Self { |
5869fd63 KS |
44 | NAVideoInfo { width: w, height: h, flipped: flip, format: fmt } |
45 | } | |
66116504 KS |
46 | pub fn get_width(&self) -> usize { self.width as usize } |
47 | pub fn get_height(&self) -> usize { self.height as usize } | |
48 | pub fn is_flipped(&self) -> bool { self.flipped } | |
49 | pub fn get_format(&self) -> NAPixelFormaton { self.format } | |
dd1b60e1 KS |
50 | pub fn set_width(&mut self, w: usize) { self.width = w; } |
51 | pub fn set_height(&mut self, h: usize) { self.height = h; } | |
5869fd63 KS |
52 | } |
53 | ||
83e603fa KS |
54 | impl fmt::Display for NAVideoInfo { |
55 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
56 | write!(f, "{}x{}", self.width, self.height) | |
57 | } | |
58 | } | |
59 | ||
66116504 | 60 | #[derive(Clone,Copy,PartialEq)] |
5869fd63 KS |
61 | pub enum NACodecTypeInfo { |
62 | None, | |
63 | Audio(NAAudioInfo), | |
64 | Video(NAVideoInfo), | |
65 | } | |
66 | ||
22cb00db KS |
67 | impl NACodecTypeInfo { |
68 | pub fn get_video_info(&self) -> Option<NAVideoInfo> { | |
69 | match *self { | |
70 | NACodecTypeInfo::Video(vinfo) => Some(vinfo), | |
71 | _ => None, | |
72 | } | |
73 | } | |
74 | pub fn get_audio_info(&self) -> Option<NAAudioInfo> { | |
75 | match *self { | |
76 | NACodecTypeInfo::Audio(ainfo) => Some(ainfo), | |
77 | _ => None, | |
78 | } | |
79 | } | |
5076115b KS |
80 | pub fn is_video(&self) -> bool { |
81 | match *self { | |
82 | NACodecTypeInfo::Video(_) => true, | |
83 | _ => false, | |
84 | } | |
85 | } | |
86 | pub fn is_audio(&self) -> bool { | |
87 | match *self { | |
88 | NACodecTypeInfo::Audio(_) => true, | |
89 | _ => false, | |
90 | } | |
91 | } | |
22cb00db KS |
92 | } |
93 | ||
83e603fa KS |
94 | impl fmt::Display for NACodecTypeInfo { |
95 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
96 | let ret = match *self { | |
e243ceb4 | 97 | NACodecTypeInfo::None => "".to_string(), |
83e603fa KS |
98 | NACodecTypeInfo::Audio(fmt) => format!("{}", fmt), |
99 | NACodecTypeInfo::Video(fmt) => format!("{}", fmt), | |
100 | }; | |
101 | write!(f, "{}", ret) | |
102 | } | |
103 | } | |
104 | ||
22cb00db KS |
105 | #[derive(Clone)] |
106 | pub struct NAVideoBuffer<T> { | |
6c8e5c40 | 107 | info: NAVideoInfo, |
1a967e6b | 108 | data: NABufferRef<Vec<T>>, |
6c8e5c40 KS |
109 | offs: Vec<usize>, |
110 | strides: Vec<usize>, | |
22cb00db KS |
111 | } |
112 | ||
113 | impl<T: Clone> NAVideoBuffer<T> { | |
114 | pub fn get_offset(&self, idx: usize) -> usize { | |
115 | if idx >= self.offs.len() { 0 } | |
116 | else { self.offs[idx] } | |
117 | } | |
118 | pub fn get_info(&self) -> NAVideoInfo { self.info } | |
1a967e6b KS |
119 | pub fn get_data(&self) -> &Vec<T> { self.data.as_ref() } |
120 | pub fn get_data_mut(&mut self) -> Option<&mut Vec<T>> { self.data.as_mut() } | |
22cb00db | 121 | pub fn copy_buffer(&mut self) -> Self { |
1a967e6b KS |
122 | let mut data: Vec<T> = Vec::with_capacity(self.data.len()); |
123 | data.clone_from(self.data.as_ref()); | |
22cb00db KS |
124 | let mut offs: Vec<usize> = Vec::with_capacity(self.offs.len()); |
125 | offs.clone_from(&self.offs); | |
6c8e5c40 KS |
126 | let mut strides: Vec<usize> = Vec::with_capacity(self.strides.len()); |
127 | strides.clone_from(&self.strides); | |
e243ceb4 | 128 | NAVideoBuffer { info: self.info, data: NABufferRef::new(data), offs, strides } |
22cb00db KS |
129 | } |
130 | pub fn get_stride(&self, idx: usize) -> usize { | |
6c8e5c40 KS |
131 | if idx >= self.strides.len() { return 0; } |
132 | self.strides[idx] | |
22cb00db KS |
133 | } |
134 | pub fn get_dimensions(&self, idx: usize) -> (usize, usize) { | |
135 | get_plane_size(&self.info, idx) | |
136 | } | |
3fc28ece KS |
137 | pub fn into_ref(self) -> NABufferRef<Self> { |
138 | NABufferRef::new(self) | |
139 | } | |
22cb00db KS |
140 | } |
141 | ||
3fc28ece KS |
142 | pub type NAVideoBufferRef<T> = NABufferRef<NAVideoBuffer<T>>; |
143 | ||
22cb00db KS |
144 | #[derive(Clone)] |
145 | pub struct NAAudioBuffer<T> { | |
146 | info: NAAudioInfo, | |
1a967e6b | 147 | data: NABufferRef<Vec<T>>, |
22cb00db KS |
148 | offs: Vec<usize>, |
149 | chmap: NAChannelMap, | |
5076115b | 150 | len: usize, |
22cb00db KS |
151 | } |
152 | ||
153 | impl<T: Clone> NAAudioBuffer<T> { | |
154 | pub fn get_offset(&self, idx: usize) -> usize { | |
155 | if idx >= self.offs.len() { 0 } | |
156 | else { self.offs[idx] } | |
157 | } | |
158 | pub fn get_info(&self) -> NAAudioInfo { self.info } | |
159 | pub fn get_chmap(&self) -> NAChannelMap { self.chmap.clone() } | |
1a967e6b KS |
160 | pub fn get_data(&self) -> &Vec<T> { self.data.as_ref() } |
161 | pub fn get_data_mut(&mut self) -> Option<&mut Vec<T>> { self.data.as_mut() } | |
22cb00db | 162 | pub fn copy_buffer(&mut self) -> Self { |
1a967e6b KS |
163 | let mut data: Vec<T> = Vec::with_capacity(self.data.len()); |
164 | data.clone_from(self.data.as_ref()); | |
22cb00db KS |
165 | let mut offs: Vec<usize> = Vec::with_capacity(self.offs.len()); |
166 | offs.clone_from(&self.offs); | |
e243ceb4 | 167 | NAAudioBuffer { info: self.info, data: NABufferRef::new(data), offs, chmap: self.get_chmap(), len: self.len } |
22cb00db | 168 | } |
5076115b | 169 | pub fn get_length(&self) -> usize { self.len } |
22cb00db KS |
170 | } |
171 | ||
87a1ebc3 | 172 | impl NAAudioBuffer<u8> { |
1a967e6b KS |
173 | pub fn new_from_buf(info: NAAudioInfo, data: NABufferRef<Vec<u8>>, chmap: NAChannelMap) -> Self { |
174 | let len = data.len(); | |
e243ceb4 | 175 | NAAudioBuffer { info, data, chmap, offs: Vec::new(), len } |
87a1ebc3 KS |
176 | } |
177 | } | |
178 | ||
22cb00db KS |
179 | #[derive(Clone)] |
180 | pub enum NABufferType { | |
3fc28ece KS |
181 | Video (NAVideoBufferRef<u8>), |
182 | Video16 (NAVideoBufferRef<u16>), | |
183 | Video32 (NAVideoBufferRef<u32>), | |
184 | VideoPacked(NAVideoBufferRef<u8>), | |
22cb00db KS |
185 | AudioU8 (NAAudioBuffer<u8>), |
186 | AudioI16 (NAAudioBuffer<i16>), | |
87a1ebc3 | 187 | AudioI32 (NAAudioBuffer<i32>), |
22cb00db KS |
188 | AudioF32 (NAAudioBuffer<f32>), |
189 | AudioPacked(NAAudioBuffer<u8>), | |
1a967e6b | 190 | Data (NABufferRef<Vec<u8>>), |
22cb00db KS |
191 | None, |
192 | } | |
193 | ||
194 | impl NABufferType { | |
195 | pub fn get_offset(&self, idx: usize) -> usize { | |
196 | match *self { | |
197 | NABufferType::Video(ref vb) => vb.get_offset(idx), | |
198 | NABufferType::Video16(ref vb) => vb.get_offset(idx), | |
3bba1c4a | 199 | NABufferType::Video32(ref vb) => vb.get_offset(idx), |
22cb00db KS |
200 | NABufferType::VideoPacked(ref vb) => vb.get_offset(idx), |
201 | NABufferType::AudioU8(ref ab) => ab.get_offset(idx), | |
202 | NABufferType::AudioI16(ref ab) => ab.get_offset(idx), | |
203 | NABufferType::AudioF32(ref ab) => ab.get_offset(idx), | |
204 | NABufferType::AudioPacked(ref ab) => ab.get_offset(idx), | |
205 | _ => 0, | |
206 | } | |
207 | } | |
3bba1c4a KS |
208 | pub fn get_video_info(&self) -> Option<NAVideoInfo> { |
209 | match *self { | |
210 | NABufferType::Video(ref vb) => Some(vb.get_info()), | |
211 | NABufferType::Video16(ref vb) => Some(vb.get_info()), | |
212 | NABufferType::Video32(ref vb) => Some(vb.get_info()), | |
213 | NABufferType::VideoPacked(ref vb) => Some(vb.get_info()), | |
214 | _ => None, | |
215 | } | |
216 | } | |
3fc28ece | 217 | pub fn get_vbuf(&self) -> Option<NAVideoBufferRef<u8>> { |
22cb00db KS |
218 | match *self { |
219 | NABufferType::Video(ref vb) => Some(vb.clone()), | |
87a1ebc3 KS |
220 | NABufferType::VideoPacked(ref vb) => Some(vb.clone()), |
221 | _ => None, | |
222 | } | |
223 | } | |
3fc28ece | 224 | pub fn get_vbuf16(&self) -> Option<NAVideoBufferRef<u16>> { |
87a1ebc3 KS |
225 | match *self { |
226 | NABufferType::Video16(ref vb) => Some(vb.clone()), | |
227 | _ => None, | |
228 | } | |
229 | } | |
3fc28ece | 230 | pub fn get_vbuf32(&self) -> Option<NAVideoBufferRef<u32>> { |
3bba1c4a KS |
231 | match *self { |
232 | NABufferType::Video32(ref vb) => Some(vb.clone()), | |
233 | _ => None, | |
234 | } | |
235 | } | |
6e09a92e | 236 | pub fn get_abuf_u8(&self) -> Option<NAAudioBuffer<u8>> { |
87a1ebc3 KS |
237 | match *self { |
238 | NABufferType::AudioU8(ref ab) => Some(ab.clone()), | |
239 | NABufferType::AudioPacked(ref ab) => Some(ab.clone()), | |
240 | _ => None, | |
241 | } | |
242 | } | |
6e09a92e | 243 | pub fn get_abuf_i16(&self) -> Option<NAAudioBuffer<i16>> { |
87a1ebc3 KS |
244 | match *self { |
245 | NABufferType::AudioI16(ref ab) => Some(ab.clone()), | |
246 | _ => None, | |
247 | } | |
248 | } | |
6e09a92e | 249 | pub fn get_abuf_i32(&self) -> Option<NAAudioBuffer<i32>> { |
87a1ebc3 KS |
250 | match *self { |
251 | NABufferType::AudioI32(ref ab) => Some(ab.clone()), | |
252 | _ => None, | |
253 | } | |
254 | } | |
6e09a92e | 255 | pub fn get_abuf_f32(&self) -> Option<NAAudioBuffer<f32>> { |
87a1ebc3 KS |
256 | match *self { |
257 | NABufferType::AudioF32(ref ab) => Some(ab.clone()), | |
22cb00db KS |
258 | _ => None, |
259 | } | |
260 | } | |
261 | } | |
262 | ||
cd830591 KS |
263 | const NA_SIMPLE_VFRAME_COMPONENTS: usize = 4; |
264 | pub struct NASimpleVideoFrame<'a, T: Copy> { | |
265 | pub width: [usize; NA_SIMPLE_VFRAME_COMPONENTS], | |
266 | pub height: [usize; NA_SIMPLE_VFRAME_COMPONENTS], | |
267 | pub flip: bool, | |
268 | pub stride: [usize; NA_SIMPLE_VFRAME_COMPONENTS], | |
269 | pub offset: [usize; NA_SIMPLE_VFRAME_COMPONENTS], | |
270 | pub components: usize, | |
dc45d8ce | 271 | pub data: &'a mut [T], |
cd830591 KS |
272 | } |
273 | ||
274 | impl<'a, T:Copy> NASimpleVideoFrame<'a, T> { | |
275 | pub fn from_video_buf(vbuf: &'a mut NAVideoBuffer<T>) -> Option<Self> { | |
276 | let vinfo = vbuf.get_info(); | |
277 | let components = vinfo.format.components as usize; | |
278 | if components > NA_SIMPLE_VFRAME_COMPONENTS { | |
279 | return None; | |
280 | } | |
281 | let mut w: [usize; NA_SIMPLE_VFRAME_COMPONENTS] = [0; NA_SIMPLE_VFRAME_COMPONENTS]; | |
282 | let mut h: [usize; NA_SIMPLE_VFRAME_COMPONENTS] = [0; NA_SIMPLE_VFRAME_COMPONENTS]; | |
283 | let mut s: [usize; NA_SIMPLE_VFRAME_COMPONENTS] = [0; NA_SIMPLE_VFRAME_COMPONENTS]; | |
284 | let mut o: [usize; NA_SIMPLE_VFRAME_COMPONENTS] = [0; NA_SIMPLE_VFRAME_COMPONENTS]; | |
285 | for comp in 0..components { | |
286 | let (width, height) = vbuf.get_dimensions(comp); | |
287 | w[comp] = width; | |
288 | h[comp] = height; | |
289 | s[comp] = vbuf.get_stride(comp); | |
290 | o[comp] = vbuf.get_offset(comp); | |
291 | } | |
292 | let flip = vinfo.flipped; | |
293 | Some(NASimpleVideoFrame { | |
294 | width: w, | |
295 | height: h, | |
296 | flip, | |
297 | stride: s, | |
298 | offset: o, | |
299 | components, | |
dc45d8ce | 300 | data: vbuf.data.as_mut_slice(), |
cd830591 KS |
301 | }) |
302 | } | |
303 | } | |
304 | ||
22cb00db KS |
305 | #[derive(Debug,Clone,Copy,PartialEq)] |
306 | pub enum AllocatorError { | |
307 | TooLargeDimensions, | |
308 | FormatError, | |
309 | } | |
310 | ||
311 | pub fn alloc_video_buffer(vinfo: NAVideoInfo, align: u8) -> Result<NABufferType, AllocatorError> { | |
312 | let fmt = &vinfo.format; | |
313 | let mut new_size: usize = 0; | |
6c8e5c40 KS |
314 | let mut offs: Vec<usize> = Vec::new(); |
315 | let mut strides: Vec<usize> = Vec::new(); | |
22cb00db KS |
316 | |
317 | for i in 0..fmt.get_num_comp() { | |
318 | if fmt.get_chromaton(i) == None { return Err(AllocatorError::FormatError); } | |
319 | } | |
320 | ||
321 | let align_mod = ((1 << align) as usize) - 1; | |
322 | let width = ((vinfo.width as usize) + align_mod) & !align_mod; | |
323 | let height = ((vinfo.height as usize) + align_mod) & !align_mod; | |
324 | let mut max_depth = 0; | |
325 | let mut all_packed = true; | |
3bba1c4a | 326 | let mut all_bytealigned = true; |
22cb00db | 327 | for i in 0..fmt.get_num_comp() { |
6c8e5c40 | 328 | let ochr = fmt.get_chromaton(i); |
e243ceb4 | 329 | if ochr.is_none() { continue; } |
6c8e5c40 | 330 | let chr = ochr.unwrap(); |
22cb00db KS |
331 | if !chr.is_packed() { |
332 | all_packed = false; | |
3bba1c4a KS |
333 | } else if ((chr.get_shift() + chr.get_depth()) & 7) != 0 { |
334 | all_bytealigned = false; | |
22cb00db KS |
335 | } |
336 | max_depth = max(max_depth, chr.get_depth()); | |
337 | } | |
3bba1c4a KS |
338 | let unfit_elem_size = match fmt.get_elem_size() { |
339 | 2 | 4 => false, | |
340 | _ => true, | |
341 | }; | |
22cb00db KS |
342 | |
343 | //todo semi-packed like NV12 | |
bc6aac3d KS |
344 | if fmt.is_paletted() { |
345 | //todo various-sized palettes? | |
6c8e5c40 KS |
346 | let stride = vinfo.get_format().get_chromaton(0).unwrap().get_linesize(width); |
347 | let pic_sz = stride.checked_mul(height); | |
bc6aac3d KS |
348 | if pic_sz == None { return Err(AllocatorError::TooLargeDimensions); } |
349 | let pal_size = 256 * (fmt.get_elem_size() as usize); | |
350 | let new_size = pic_sz.unwrap().checked_add(pal_size); | |
351 | if new_size == None { return Err(AllocatorError::TooLargeDimensions); } | |
352 | offs.push(0); | |
6c8e5c40 KS |
353 | offs.push(stride * height); |
354 | strides.push(stride); | |
e243ceb4 KS |
355 | let data: Vec<u8> = vec![0; new_size.unwrap()]; |
356 | let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; | |
3fc28ece | 357 | Ok(NABufferType::Video(buf.into_ref())) |
bc6aac3d | 358 | } else if !all_packed { |
22cb00db | 359 | for i in 0..fmt.get_num_comp() { |
6c8e5c40 | 360 | let ochr = fmt.get_chromaton(i); |
e243ceb4 | 361 | if ochr.is_none() { continue; } |
6c8e5c40 | 362 | let chr = ochr.unwrap(); |
74afc7de | 363 | offs.push(new_size as usize); |
6c8e5c40 | 364 | let stride = chr.get_linesize(width); |
22cb00db | 365 | let cur_h = chr.get_height(height); |
6c8e5c40 | 366 | let cur_sz = stride.checked_mul(cur_h); |
22cb00db KS |
367 | if cur_sz == None { return Err(AllocatorError::TooLargeDimensions); } |
368 | let new_sz = new_size.checked_add(cur_sz.unwrap()); | |
369 | if new_sz == None { return Err(AllocatorError::TooLargeDimensions); } | |
370 | new_size = new_sz.unwrap(); | |
6c8e5c40 | 371 | strides.push(stride); |
22cb00db KS |
372 | } |
373 | if max_depth <= 8 { | |
e243ceb4 KS |
374 | let data: Vec<u8> = vec![0; new_size]; |
375 | let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; | |
3fc28ece | 376 | Ok(NABufferType::Video(buf.into_ref())) |
3bba1c4a | 377 | } else if max_depth <= 16 { |
e243ceb4 KS |
378 | let data: Vec<u16> = vec![0; new_size]; |
379 | let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; | |
3fc28ece | 380 | Ok(NABufferType::Video16(buf.into_ref())) |
3bba1c4a | 381 | } else { |
e243ceb4 KS |
382 | let data: Vec<u32> = vec![0; new_size]; |
383 | let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; | |
3fc28ece | 384 | Ok(NABufferType::Video32(buf.into_ref())) |
22cb00db | 385 | } |
3bba1c4a | 386 | } else if all_bytealigned || unfit_elem_size { |
22cb00db KS |
387 | let elem_sz = fmt.get_elem_size(); |
388 | let line_sz = width.checked_mul(elem_sz as usize); | |
389 | if line_sz == None { return Err(AllocatorError::TooLargeDimensions); } | |
390 | let new_sz = line_sz.unwrap().checked_mul(height); | |
391 | if new_sz == None { return Err(AllocatorError::TooLargeDimensions); } | |
392 | new_size = new_sz.unwrap(); | |
e243ceb4 | 393 | let data: Vec<u8> = vec![0; new_size]; |
6c8e5c40 | 394 | strides.push(line_sz.unwrap()); |
e243ceb4 | 395 | let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; |
3fc28ece | 396 | Ok(NABufferType::VideoPacked(buf.into_ref())) |
3bba1c4a KS |
397 | } else { |
398 | let elem_sz = fmt.get_elem_size(); | |
399 | let new_sz = width.checked_mul(height); | |
400 | if new_sz == None { return Err(AllocatorError::TooLargeDimensions); } | |
401 | new_size = new_sz.unwrap(); | |
402 | match elem_sz { | |
403 | 2 => { | |
e243ceb4 | 404 | let data: Vec<u16> = vec![0; new_size]; |
3bba1c4a | 405 | strides.push(width); |
e243ceb4 | 406 | let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; |
3fc28ece | 407 | Ok(NABufferType::Video16(buf.into_ref())) |
3bba1c4a KS |
408 | }, |
409 | 4 => { | |
e243ceb4 | 410 | let data: Vec<u32> = vec![0; new_size]; |
3bba1c4a | 411 | strides.push(width); |
e243ceb4 | 412 | let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides }; |
3fc28ece | 413 | Ok(NABufferType::Video32(buf.into_ref())) |
3bba1c4a KS |
414 | }, |
415 | _ => unreachable!(), | |
416 | } | |
22cb00db KS |
417 | } |
418 | } | |
419 | ||
e243ceb4 | 420 | #[allow(clippy::collapsible_if)] |
22cb00db KS |
421 | pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelMap) -> Result<NABufferType, AllocatorError> { |
422 | let mut offs: Vec<usize> = Vec::new(); | |
4c6c19cb | 423 | if ainfo.format.is_planar() || (ainfo.channels == 1 && (ainfo.format.get_bits() % 8) == 0) { |
22cb00db KS |
424 | let len = nsamples.checked_mul(ainfo.channels as usize); |
425 | if len == None { return Err(AllocatorError::TooLargeDimensions); } | |
426 | let length = len.unwrap(); | |
427 | for i in 0..ainfo.channels { | |
428 | offs.push((i as usize) * nsamples); | |
429 | } | |
430 | if ainfo.format.is_float() { | |
431 | if ainfo.format.get_bits() == 32 { | |
e243ceb4 KS |
432 | let data: Vec<f32> = vec![0.0; length]; |
433 | let buf: NAAudioBuffer<f32> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples }; | |
22cb00db KS |
434 | Ok(NABufferType::AudioF32(buf)) |
435 | } else { | |
436 | Err(AllocatorError::TooLargeDimensions) | |
437 | } | |
438 | } else { | |
439 | if ainfo.format.get_bits() == 8 && !ainfo.format.is_signed() { | |
e243ceb4 KS |
440 | let data: Vec<u8> = vec![0; length]; |
441 | let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples }; | |
22cb00db KS |
442 | Ok(NABufferType::AudioU8(buf)) |
443 | } else if ainfo.format.get_bits() == 16 && ainfo.format.is_signed() { | |
e243ceb4 KS |
444 | let data: Vec<i16> = vec![0; length]; |
445 | let buf: NAAudioBuffer<i16> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples }; | |
22cb00db KS |
446 | Ok(NABufferType::AudioI16(buf)) |
447 | } else { | |
448 | Err(AllocatorError::TooLargeDimensions) | |
449 | } | |
450 | } | |
451 | } else { | |
452 | let len = nsamples.checked_mul(ainfo.channels as usize); | |
453 | if len == None { return Err(AllocatorError::TooLargeDimensions); } | |
454 | let length = ainfo.format.get_audio_size(len.unwrap() as u64); | |
e243ceb4 KS |
455 | let data: Vec<u8> = vec![0; length]; |
456 | let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples }; | |
1a151e53 | 457 | Ok(NABufferType::AudioPacked(buf)) |
22cb00db KS |
458 | } |
459 | } | |
460 | ||
461 | pub fn alloc_data_buffer(size: usize) -> Result<NABufferType, AllocatorError> { | |
e243ceb4 | 462 | let data: Vec<u8> = vec![0; size]; |
1a967e6b | 463 | let buf: NABufferRef<Vec<u8>> = NABufferRef::new(data); |
22cb00db KS |
464 | Ok(NABufferType::Data(buf)) |
465 | } | |
466 | ||
467 | pub fn copy_buffer(buf: NABufferType) -> NABufferType { | |
468 | buf.clone() | |
469 | } | |
470 | ||
01613464 KS |
471 | pub struct NAVideoBufferPool<T:Copy> { |
472 | pool: Vec<NAVideoBufferRef<T>>, | |
1a967e6b | 473 | max_len: usize, |
01613464 | 474 | add_len: usize, |
1a967e6b KS |
475 | } |
476 | ||
01613464 | 477 | impl<T:Copy> NAVideoBufferPool<T> { |
1a967e6b KS |
478 | pub fn new(max_len: usize) -> Self { |
479 | Self { | |
480 | pool: Vec::with_capacity(max_len), | |
481 | max_len, | |
01613464 | 482 | add_len: 0, |
1a967e6b KS |
483 | } |
484 | } | |
01613464 KS |
485 | pub fn set_dec_bufs(&mut self, add_len: usize) { |
486 | self.add_len = add_len; | |
487 | } | |
488 | pub fn get_free(&mut self) -> Option<NAVideoBufferRef<T>> { | |
489 | for e in self.pool.iter() { | |
490 | if e.get_num_refs() == 1 { | |
491 | return Some(e.clone()); | |
492 | } | |
493 | } | |
494 | None | |
495 | } | |
496 | pub fn get_copy(&mut self, rbuf: &NAVideoBufferRef<T>) -> Option<NAVideoBufferRef<T>> { | |
e243ceb4 | 497 | let mut dbuf = self.get_free()?; |
01613464 KS |
498 | dbuf.data.copy_from_slice(&rbuf.data); |
499 | Some(dbuf) | |
500 | } | |
501 | pub fn reset(&mut self) { | |
502 | self.pool.truncate(0); | |
503 | } | |
504 | } | |
505 | ||
506 | impl NAVideoBufferPool<u8> { | |
1a967e6b | 507 | pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> { |
01613464 | 508 | let nbufs = self.max_len + self.add_len - self.pool.len(); |
1a967e6b | 509 | for _ in 0..nbufs { |
e243ceb4 | 510 | let vbuf = alloc_video_buffer(vinfo, align)?; |
01613464 KS |
511 | if let NABufferType::Video(buf) = vbuf { |
512 | self.pool.push(buf); | |
513 | } else if let NABufferType::VideoPacked(buf) = vbuf { | |
514 | self.pool.push(buf); | |
515 | } else { | |
516 | return Err(AllocatorError::FormatError); | |
517 | } | |
1a967e6b KS |
518 | } |
519 | Ok(()) | |
520 | } | |
01613464 KS |
521 | } |
522 | ||
523 | impl NAVideoBufferPool<u16> { | |
524 | pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> { | |
525 | let nbufs = self.max_len + self.add_len - self.pool.len(); | |
1a967e6b | 526 | for _ in 0..nbufs { |
e243ceb4 | 527 | let vbuf = alloc_video_buffer(vinfo, align)?; |
01613464 KS |
528 | if let NABufferType::Video16(buf) = vbuf { |
529 | self.pool.push(buf); | |
530 | } else { | |
531 | return Err(AllocatorError::FormatError); | |
532 | } | |
1a967e6b KS |
533 | } |
534 | Ok(()) | |
535 | } | |
01613464 KS |
536 | } |
537 | ||
538 | impl NAVideoBufferPool<u32> { | |
539 | pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> { | |
540 | let nbufs = self.max_len + self.add_len - self.pool.len(); | |
541 | for _ in 0..nbufs { | |
e243ceb4 | 542 | let vbuf = alloc_video_buffer(vinfo, align)?; |
01613464 KS |
543 | if let NABufferType::Video32(buf) = vbuf { |
544 | self.pool.push(buf); | |
545 | } else { | |
546 | return Err(AllocatorError::FormatError); | |
1a967e6b KS |
547 | } |
548 | } | |
01613464 | 549 | Ok(()) |
1a967e6b KS |
550 | } |
551 | } | |
552 | ||
5869fd63 | 553 | #[allow(dead_code)] |
8869d452 KS |
554 | #[derive(Clone)] |
555 | pub struct NACodecInfo { | |
ccae5343 | 556 | name: &'static str, |
5869fd63 | 557 | properties: NACodecTypeInfo, |
2422d969 | 558 | extradata: Option<Arc<Vec<u8>>>, |
5869fd63 KS |
559 | } |
560 | ||
2422d969 KS |
561 | pub type NACodecInfoRef = Arc<NACodecInfo>; |
562 | ||
8869d452 | 563 | impl NACodecInfo { |
ccae5343 | 564 | pub fn new(name: &'static str, p: NACodecTypeInfo, edata: Option<Vec<u8>>) -> Self { |
8869d452 KS |
565 | let extradata = match edata { |
566 | None => None, | |
2422d969 | 567 | Some(vec) => Some(Arc::new(vec)), |
8869d452 | 568 | }; |
e243ceb4 | 569 | NACodecInfo { name, properties: p, extradata } |
8869d452 | 570 | } |
2422d969 | 571 | pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option<Arc<Vec<u8>>>) -> Self { |
e243ceb4 | 572 | NACodecInfo { name, properties: p, extradata: edata } |
66116504 | 573 | } |
2422d969 | 574 | pub fn into_ref(self) -> NACodecInfoRef { Arc::new(self) } |
8869d452 | 575 | pub fn get_properties(&self) -> NACodecTypeInfo { self.properties } |
2422d969 | 576 | pub fn get_extradata(&self) -> Option<Arc<Vec<u8>>> { |
8869d452 KS |
577 | if let Some(ref vec) = self.extradata { return Some(vec.clone()); } |
578 | None | |
5869fd63 | 579 | } |
66116504 KS |
580 | pub fn get_name(&self) -> &'static str { self.name } |
581 | pub fn is_video(&self) -> bool { | |
582 | if let NACodecTypeInfo::Video(_) = self.properties { return true; } | |
583 | false | |
584 | } | |
585 | pub fn is_audio(&self) -> bool { | |
586 | if let NACodecTypeInfo::Audio(_) = self.properties { return true; } | |
587 | false | |
588 | } | |
2422d969 KS |
589 | pub fn new_dummy() -> Arc<Self> { |
590 | Arc::new(DUMMY_CODEC_INFO) | |
5076115b | 591 | } |
2422d969 KS |
592 | pub fn replace_info(&self, p: NACodecTypeInfo) -> Arc<Self> { |
593 | Arc::new(NACodecInfo { name: self.name, properties: p, extradata: self.extradata.clone() }) | |
5076115b | 594 | } |
66116504 KS |
595 | } |
596 | ||
241e56f1 KS |
597 | impl Default for NACodecInfo { |
598 | fn default() -> Self { DUMMY_CODEC_INFO } | |
599 | } | |
600 | ||
66116504 KS |
601 | impl fmt::Display for NACodecInfo { |
602 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
603 | let edata = match self.extradata.clone() { | |
e243ceb4 | 604 | None => "no extradata".to_string(), |
66116504 KS |
605 | Some(v) => format!("{} byte(s) of extradata", v.len()), |
606 | }; | |
607 | write!(f, "{}: {} {}", self.name, self.properties, edata) | |
608 | } | |
609 | } | |
610 | ||
611 | pub const DUMMY_CODEC_INFO: NACodecInfo = NACodecInfo { | |
612 | name: "none", | |
613 | properties: NACodecTypeInfo::None, | |
614 | extradata: None }; | |
615 | ||
66116504 KS |
616 | #[derive(Debug,Clone)] |
617 | pub enum NAValue { | |
5869fd63 KS |
618 | None, |
619 | Int(i32), | |
620 | Long(i64), | |
621 | String(String), | |
2422d969 | 622 | Data(Arc<Vec<u8>>), |
5869fd63 KS |
623 | } |
624 | ||
88c03b61 KS |
625 | #[derive(Debug,Clone,Copy,PartialEq)] |
626 | #[allow(dead_code)] | |
627 | pub enum FrameType { | |
628 | I, | |
629 | P, | |
630 | B, | |
bc6aac3d | 631 | Skip, |
88c03b61 KS |
632 | Other, |
633 | } | |
634 | ||
635 | impl fmt::Display for FrameType { | |
636 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
637 | match *self { | |
638 | FrameType::I => write!(f, "I"), | |
639 | FrameType::P => write!(f, "P"), | |
640 | FrameType::B => write!(f, "B"), | |
bc6aac3d | 641 | FrameType::Skip => write!(f, "skip"), |
88c03b61 KS |
642 | FrameType::Other => write!(f, "x"), |
643 | } | |
644 | } | |
645 | } | |
646 | ||
e189501e KS |
647 | #[derive(Debug,Clone,Copy)] |
648 | pub struct NATimeInfo { | |
5869fd63 KS |
649 | pts: Option<u64>, |
650 | dts: Option<u64>, | |
651 | duration: Option<u64>, | |
e189501e KS |
652 | tb_num: u32, |
653 | tb_den: u32, | |
654 | } | |
655 | ||
656 | impl NATimeInfo { | |
657 | pub fn new(pts: Option<u64>, dts: Option<u64>, duration: Option<u64>, tb_num: u32, tb_den: u32) -> Self { | |
e243ceb4 | 658 | NATimeInfo { pts, dts, duration, tb_num, tb_den } |
e189501e KS |
659 | } |
660 | pub fn get_pts(&self) -> Option<u64> { self.pts } | |
661 | pub fn get_dts(&self) -> Option<u64> { self.dts } | |
662 | pub fn get_duration(&self) -> Option<u64> { self.duration } | |
663 | pub fn set_pts(&mut self, pts: Option<u64>) { self.pts = pts; } | |
664 | pub fn set_dts(&mut self, dts: Option<u64>) { self.dts = dts; } | |
665 | pub fn set_duration(&mut self, dur: Option<u64>) { self.duration = dur; } | |
666 | } | |
667 | ||
668 | #[allow(dead_code)] | |
669 | #[derive(Clone)] | |
670 | pub struct NAFrame { | |
671 | ts: NATimeInfo, | |
f18bba90 | 672 | id: i64, |
22cb00db | 673 | buffer: NABufferType, |
2422d969 | 674 | info: NACodecInfoRef, |
88c03b61 KS |
675 | ftype: FrameType, |
676 | key: bool, | |
66116504 KS |
677 | options: HashMap<String, NAValue>, |
678 | } | |
679 | ||
171860fc | 680 | pub type NAFrameRef = Arc<NAFrame>; |
ebd71c92 | 681 | |
66116504 KS |
682 | fn get_plane_size(info: &NAVideoInfo, idx: usize) -> (usize, usize) { |
683 | let chromaton = info.get_format().get_chromaton(idx); | |
e243ceb4 | 684 | if chromaton.is_none() { return (0, 0); } |
66116504 KS |
685 | let (hs, vs) = chromaton.unwrap().get_subsampling(); |
686 | let w = (info.get_width() + ((1 << hs) - 1)) >> hs; | |
687 | let h = (info.get_height() + ((1 << vs) - 1)) >> vs; | |
688 | (w, h) | |
689 | } | |
690 | ||
691 | impl NAFrame { | |
e189501e | 692 | pub fn new(ts: NATimeInfo, |
88c03b61 KS |
693 | ftype: FrameType, |
694 | keyframe: bool, | |
2422d969 | 695 | info: NACodecInfoRef, |
22cb00db KS |
696 | options: HashMap<String, NAValue>, |
697 | buffer: NABufferType) -> Self { | |
f18bba90 | 698 | NAFrame { ts, id: 0, buffer, info, ftype, key: keyframe, options } |
ebd71c92 | 699 | } |
2422d969 | 700 | pub fn get_info(&self) -> NACodecInfoRef { self.info.clone() } |
88c03b61 KS |
701 | pub fn get_frame_type(&self) -> FrameType { self.ftype } |
702 | pub fn is_keyframe(&self) -> bool { self.key } | |
88c03b61 KS |
703 | pub fn set_frame_type(&mut self, ftype: FrameType) { self.ftype = ftype; } |
704 | pub fn set_keyframe(&mut self, key: bool) { self.key = key; } | |
e189501e KS |
705 | pub fn get_time_information(&self) -> NATimeInfo { self.ts } |
706 | pub fn get_pts(&self) -> Option<u64> { self.ts.get_pts() } | |
707 | pub fn get_dts(&self) -> Option<u64> { self.ts.get_dts() } | |
f18bba90 | 708 | pub fn get_id(&self) -> i64 { self.id } |
e189501e KS |
709 | pub fn get_duration(&self) -> Option<u64> { self.ts.get_duration() } |
710 | pub fn set_pts(&mut self, pts: Option<u64>) { self.ts.set_pts(pts); } | |
711 | pub fn set_dts(&mut self, dts: Option<u64>) { self.ts.set_dts(dts); } | |
f18bba90 | 712 | pub fn set_id(&mut self, id: i64) { self.id = id; } |
e189501e | 713 | pub fn set_duration(&mut self, dur: Option<u64>) { self.ts.set_duration(dur); } |
66116504 | 714 | |
22cb00db | 715 | pub fn get_buffer(&self) -> NABufferType { self.buffer.clone() } |
171860fc KS |
716 | |
717 | pub fn into_ref(self) -> NAFrameRef { Arc::new(self) } | |
5869fd63 KS |
718 | } |
719 | ||
ebd71c92 KS |
720 | impl fmt::Display for NAFrame { |
721 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
e243ceb4 KS |
722 | let mut ostr = format!("frame type {}", self.ftype); |
723 | if let Some(pts) = self.ts.pts { ostr = format!("{} pts {}", ostr, pts); } | |
724 | if let Some(dts) = self.ts.dts { ostr = format!("{} dts {}", ostr, dts); } | |
725 | if let Some(dur) = self.ts.duration { ostr = format!("{} duration {}", ostr, dur); } | |
726 | if self.key { ostr = format!("{} kf", ostr); } | |
727 | write!(f, "[{}]", ostr) | |
ebd71c92 KS |
728 | } |
729 | } | |
88c03b61 | 730 | |
48c88fde KS |
731 | /// Possible stream types. |
732 | #[derive(Debug,Clone,Copy)] | |
5869fd63 | 733 | #[allow(dead_code)] |
48c88fde KS |
734 | pub enum StreamType { |
735 | /// video stream | |
736 | Video, | |
737 | /// audio stream | |
738 | Audio, | |
739 | /// subtitles | |
740 | Subtitles, | |
741 | /// any data stream (or might be an unrecognized audio/video stream) | |
742 | Data, | |
743 | /// nonexistent stream | |
744 | None, | |
745 | } | |
746 | ||
747 | impl fmt::Display for StreamType { | |
748 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
749 | match *self { | |
750 | StreamType::Video => write!(f, "Video"), | |
751 | StreamType::Audio => write!(f, "Audio"), | |
752 | StreamType::Subtitles => write!(f, "Subtitles"), | |
753 | StreamType::Data => write!(f, "Data"), | |
754 | StreamType::None => write!(f, "-"), | |
755 | } | |
756 | } | |
757 | } | |
758 | ||
759 | #[allow(dead_code)] | |
760 | #[derive(Clone)] | |
761 | pub struct NAStream { | |
762 | media_type: StreamType, | |
763 | id: u32, | |
764 | num: usize, | |
2422d969 | 765 | info: NACodecInfoRef, |
e189501e KS |
766 | tb_num: u32, |
767 | tb_den: u32, | |
768 | } | |
769 | ||
70910ac3 KS |
770 | pub type NAStreamRef = Arc<NAStream>; |
771 | ||
e189501e KS |
772 | pub fn reduce_timebase(tb_num: u32, tb_den: u32) -> (u32, u32) { |
773 | if tb_num == 0 { return (tb_num, tb_den); } | |
774 | if (tb_den % tb_num) == 0 { return (1, tb_den / tb_num); } | |
775 | ||
776 | let mut a = tb_num; | |
777 | let mut b = tb_den; | |
778 | ||
779 | while a != b { | |
780 | if a > b { a -= b; } | |
781 | else if b > a { b -= a; } | |
782 | } | |
783 | ||
784 | (tb_num / a, tb_den / a) | |
5869fd63 | 785 | } |
48c88fde KS |
786 | |
787 | impl NAStream { | |
e189501e KS |
788 | pub fn new(mt: StreamType, id: u32, info: NACodecInfo, tb_num: u32, tb_den: u32) -> Self { |
789 | let (n, d) = reduce_timebase(tb_num, tb_den); | |
e243ceb4 | 790 | NAStream { media_type: mt, id, num: 0, info: info.into_ref(), tb_num: n, tb_den: d } |
48c88fde KS |
791 | } |
792 | pub fn get_id(&self) -> u32 { self.id } | |
793 | pub fn get_num(&self) -> usize { self.num } | |
794 | pub fn set_num(&mut self, num: usize) { self.num = num; } | |
2422d969 | 795 | pub fn get_info(&self) -> NACodecInfoRef { self.info.clone() } |
e189501e KS |
796 | pub fn get_timebase(&self) -> (u32, u32) { (self.tb_num, self.tb_den) } |
797 | pub fn set_timebase(&mut self, tb_num: u32, tb_den: u32) { | |
798 | let (n, d) = reduce_timebase(tb_num, tb_den); | |
799 | self.tb_num = n; | |
800 | self.tb_den = d; | |
801 | } | |
70910ac3 | 802 | pub fn into_ref(self) -> NAStreamRef { Arc::new(self) } |
48c88fde KS |
803 | } |
804 | ||
805 | impl fmt::Display for NAStream { | |
806 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
e189501e | 807 | write!(f, "({}#{} @ {}/{} - {})", self.media_type, self.id, self.tb_num, self.tb_den, self.info.get_properties()) |
48c88fde KS |
808 | } |
809 | } | |
810 | ||
811 | #[allow(dead_code)] | |
812 | pub struct NAPacket { | |
70910ac3 | 813 | stream: NAStreamRef, |
e189501e | 814 | ts: NATimeInfo, |
1a967e6b | 815 | buffer: NABufferRef<Vec<u8>>, |
48c88fde KS |
816 | keyframe: bool, |
817 | // options: HashMap<String, NAValue<'a>>, | |
818 | } | |
819 | ||
820 | impl NAPacket { | |
70910ac3 | 821 | pub fn new(str: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self { |
48c88fde KS |
822 | // let mut vec: Vec<u8> = Vec::new(); |
823 | // vec.resize(size, 0); | |
e243ceb4 | 824 | NAPacket { stream: str, ts, keyframe: kf, buffer: NABufferRef::new(vec) } |
48c88fde | 825 | } |
70910ac3 | 826 | pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() } |
e189501e KS |
827 | pub fn get_time_information(&self) -> NATimeInfo { self.ts } |
828 | pub fn get_pts(&self) -> Option<u64> { self.ts.get_pts() } | |
829 | pub fn get_dts(&self) -> Option<u64> { self.ts.get_dts() } | |
830 | pub fn get_duration(&self) -> Option<u64> { self.ts.get_duration() } | |
48c88fde | 831 | pub fn is_keyframe(&self) -> bool { self.keyframe } |
1a967e6b | 832 | pub fn get_buffer(&self) -> NABufferRef<Vec<u8>> { self.buffer.clone() } |
48c88fde KS |
833 | } |
834 | ||
835 | impl Drop for NAPacket { | |
836 | fn drop(&mut self) {} | |
837 | } | |
838 | ||
839 | impl fmt::Display for NAPacket { | |
840 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
e243ceb4 KS |
841 | let mut ostr = format!("[pkt for {} size {}", self.stream, self.buffer.len()); |
842 | if let Some(pts) = self.ts.pts { ostr = format!("{} pts {}", ostr, pts); } | |
843 | if let Some(dts) = self.ts.dts { ostr = format!("{} dts {}", ostr, dts); } | |
844 | if let Some(dur) = self.ts.duration { ostr = format!("{} duration {}", ostr, dur); } | |
845 | if self.keyframe { ostr = format!("{} kf", ostr); } | |
846 | ostr += "]"; | |
847 | write!(f, "{}", ostr) | |
48c88fde KS |
848 | } |
849 | } | |
850 | ||
851 | pub trait FrameFromPacket { | |
2422d969 | 852 | fn new_from_pkt(pkt: &NAPacket, info: NACodecInfoRef, buf: NABufferType) -> NAFrame; |
48c88fde KS |
853 | fn fill_timestamps(&mut self, pkt: &NAPacket); |
854 | } | |
855 | ||
856 | impl FrameFromPacket for NAFrame { | |
2422d969 | 857 | fn new_from_pkt(pkt: &NAPacket, info: NACodecInfoRef, buf: NABufferType) -> NAFrame { |
e189501e | 858 | NAFrame::new(pkt.ts, FrameType::Other, pkt.keyframe, info, HashMap::new(), buf) |
48c88fde KS |
859 | } |
860 | fn fill_timestamps(&mut self, pkt: &NAPacket) { | |
e189501e | 861 | self.ts = pkt.get_time_information(); |
48c88fde KS |
862 | } |
863 | } | |
864 |