+ buffer: Rc<NABuffer>,
+ info: Rc<NACodecInfo>,
+ offsets: Vec<usize>,
+ options: HashMap<String, NAValue>,
+}
+
+fn get_plane_size(info: &NAVideoInfo, idx: usize) -> (usize, usize) {
+ let chromaton = info.get_format().get_chromaton(idx);
+ if let None = chromaton { return (0, 0); }
+ let (hs, vs) = chromaton.unwrap().get_subsampling();
+ let w = (info.get_width() + ((1 << hs) - 1)) >> hs;
+ let h = (info.get_height() + ((1 << vs) - 1)) >> vs;
+ (w, h)
+}
+
+impl NAFrame {
+ pub fn new(pts: Option<u64>,
+ dts: Option<u64>,
+ duration: Option<u64>,
+ info: Rc<NACodecInfo>,
+ options: HashMap<String, NAValue>) -> Self {
+ let (buf, offs) = alloc_buf(&info);
+ NAFrame { pts: pts, dts: dts, duration: duration, buffer: buf, offsets: offs, info: info, options: options }
+ }
+ pub fn from_copy(src: &NAFrame) -> Self {
+ let buf = copy_buf(src.get_buffer().as_ref());
+ let mut offs: Vec<usize> = Vec::new();
+ offs.clone_from(&src.offsets);
+ NAFrame { pts: None, dts: None, duration: None, buffer: buf, offsets: offs, info: src.info.clone(), options: src.options.clone() }
+ }
+ pub fn get_pts(&self) -> Option<u64> { self.pts }
+ pub fn get_dts(&self) -> Option<u64> { self.dts }
+ pub fn get_duration(&self) -> Option<u64> { self.duration }
+ pub fn set_pts(&mut self, pts: Option<u64>) { self.pts = pts; }
+ pub fn set_dts(&mut self, dts: Option<u64>) { self.dts = dts; }
+ pub fn set_duration(&mut self, dur: Option<u64>) { self.duration = dur; }
+
+ pub fn get_offset(&self, idx: usize) -> usize { self.offsets[idx] }
+ pub fn get_buffer(&self) -> Rc<NABuffer> { self.buffer.clone() }
+ pub fn get_buffer_mut(&mut self) -> Option<&mut NABuffer> { Rc::get_mut(&mut self.buffer) }
+ pub fn get_stride(&self, idx: usize) -> usize {
+ if let NACodecTypeInfo::Video(vinfo) = self.info.get_properties() {
+ if idx >= vinfo.get_format().get_num_comp() { return 0; }
+ vinfo.get_format().get_chromaton(idx).unwrap().get_linesize(vinfo.get_width())
+ } else {
+ 0
+ }
+ }
+ pub fn get_dimensions(&self, idx: usize) -> (usize, usize) {
+ match self.info.get_properties() {
+ NACodecTypeInfo::Video(ref vinfo) => get_plane_size(vinfo, idx),
+ _ => (0, 0),
+ }
+ }