core/frame: add means for NAVideoBufferPool to grow and report its usage
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 10 Jun 2023 10:30:54 +0000 (12:30 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 10 Jun 2023 10:30:54 +0000 (12:30 +0200)
nihav-core/src/frame.rs

index 61741d726f082789e5f2ee5b49c4fd78ebc5fe9b..10db18de0d15ccf7be8a9d4dc50123e4a7f5c4fc 100644 (file)
@@ -746,6 +746,22 @@ impl<T:Copy> NAVideoBufferPool<T> {
     pub fn reset(&mut self) {
         self.pool.clear();
     }
+    /// Returns the number of frames currently in use.
+    pub fn get_num_used(&self) -> usize {
+        self.pool.iter().filter(|el| el.get_num_refs() != 1).count()
+    }
+    /// Adds a manually allocated frame to the pool.
+    pub fn add_frame(&mut self, buf: NAVideoBufferRef<T>) {
+        self.pool.push(buf);
+    }
+    /// Returns current video format (if available).
+    pub fn get_info(&self) -> Option<NAVideoInfo> {
+        if !self.pool.is_empty() {
+            Some(self.pool[0].get_info())
+        } else {
+            None
+        }
+    }
 }
 
 impl NAVideoBufferPool<u8> {