switch NAFrame references to Arc
[nihav.git] / nihav-core / src / frame.rs
index bc3216bd2b3a37a9247f4414caf951be723bf64e..d219ee45967b180e9174b8b01d1b9c6d44d23022 100644 (file)
@@ -1,8 +1,6 @@
 use std::cmp::max;
 use std::collections::HashMap;
 use std::fmt;
-pub use std::rc::Rc;
-pub use std::cell::*;
 use std::sync::Arc;
 pub use crate::formats::*;
 pub use crate::refs::*;
@@ -653,7 +651,7 @@ pub struct NAFrame {
     options:        HashMap<String, NAValue>,
 }
 
-pub type NAFrameRef = Rc<RefCell<NAFrame>>;
+pub type NAFrameRef = Arc<NAFrame>;
 
 fn get_plane_size(info: &NAVideoInfo, idx: usize) -> (usize, usize) {
     let chromaton = info.get_format().get_chromaton(idx);
@@ -687,6 +685,8 @@ impl NAFrame {
     pub fn set_duration(&mut self, dur: Option<u64>) { self.ts.set_duration(dur); }
 
     pub fn get_buffer(&self) -> NABufferType { self.buffer.clone() }
+
+    pub fn into_ref(self) -> NAFrameRef { Arc::new(self) }
 }
 
 impl fmt::Display for NAFrame {
@@ -739,6 +739,8 @@ pub struct NAStream {
     tb_den:         u32,
 }
 
+pub type NAStreamRef = Arc<NAStream>;
+
 pub fn reduce_timebase(tb_num: u32, tb_den: u32) -> (u32, u32) {
     if tb_num == 0 { return (tb_num, tb_den); }
     if (tb_den % tb_num) == 0 { return (1, tb_den / tb_num); }
@@ -769,6 +771,7 @@ impl NAStream {
         self.tb_num = n;
         self.tb_den = d;
     }
+    pub fn into_ref(self) -> NAStreamRef { Arc::new(self) }
 }
 
 impl fmt::Display for NAStream {
@@ -779,7 +782,7 @@ impl fmt::Display for NAStream {
 
 #[allow(dead_code)]
 pub struct NAPacket {
-    stream:         Rc<NAStream>,
+    stream:         NAStreamRef,
     ts:             NATimeInfo,
     buffer:         NABufferRef<Vec<u8>>,
     keyframe:       bool,
@@ -787,12 +790,12 @@ pub struct NAPacket {
 }
 
 impl NAPacket {
-    pub fn new(str: Rc<NAStream>, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
+    pub fn new(str: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
 //        let mut vec: Vec<u8> = Vec::new();
 //        vec.resize(size, 0);
         NAPacket { stream: str, ts: ts, keyframe: kf, buffer: NABufferRef::new(vec) }
     }
-    pub fn get_stream(&self) -> Rc<NAStream> { self.stream.clone() }
+    pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() }
     pub fn get_time_information(&self) -> NATimeInfo { self.ts }
     pub fn get_pts(&self) -> Option<u64> { self.ts.get_pts() }
     pub fn get_dts(&self) -> Option<u64> { self.ts.get_dts() }