diff options
author | 2024-02-01 14:08:04 -0500 | |
---|---|---|
committer | 2024-02-16 02:49:20 +0000 | |
commit | 0c3ff29b54e7e9323ea75db009605dd8fcade994 (patch) | |
tree | 8ee05bdce7f88f6c1d7d111b5d8a116fcacd451e | |
parent | d1ce298dca8720479c4db78de0b35a3e3b5727f0 (diff) |
bufferstreams: Present times are no longer Instants.
We need to be able to read these over the wire and send them as
timestamps to C++ code. Replace the instants with a more compatible i64
timestamp nanos timestamp.
Test: atest
Change-Id: Ia63685ac406855b4a9257c661839640ab74a555c
-rw-r--r-- | libs/bufferstreams/rust/src/lib.rs | 25 | ||||
-rw-r--r-- | libs/bufferstreams/rust/src/publishers/buffer_pool_publisher.rs | 6 |
2 files changed, 13 insertions, 18 deletions
diff --git a/libs/bufferstreams/rust/src/lib.rs b/libs/bufferstreams/rust/src/lib.rs index be1525d41f..17d4d8767f 100644 --- a/libs/bufferstreams/rust/src/lib.rs +++ b/libs/bufferstreams/rust/src/lib.rs @@ -23,8 +23,6 @@ pub mod subscriptions; use buffers::Buffer; pub use stream_config::*; -use std::time::Instant; - /// This function will print Hello World. #[no_mangle] pub extern "C" fn hello() -> bool { @@ -106,7 +104,8 @@ pub trait BufferSubscriber { /// BufferSubscriptions serve as the bridge between BufferPublishers and /// BufferSubscribers. BufferSubscribers receive a BufferSubscription when they /// subscribe to a BufferPublisher via on_subscribe. -/// This object is to be used by the BufferSubscriber to cancel its subscription +/// +/// This object is used by the BufferSubscriber to cancel its subscription /// or request more buffers. /// /// BufferSubcriptions are required to adhere to the following, based on the @@ -147,7 +146,7 @@ pub trait BufferSubscriber { /// no other Subscription exists at this point. /// * Calling Subscription.cancel MUST return normally. /// * Calling Subscription.request MUST return normally. -pub trait BufferSubscription { +pub trait BufferSubscription: Send + Sync + 'static { /// request fn request(&self, n: u64); /// cancel @@ -161,8 +160,8 @@ pub type BufferError = anyhow::Error; pub struct Frame { /// A buffer to be used this frame. pub buffer: Buffer, - /// The time at which the buffer was dispatched. - pub present_time: Instant, + /// The time at which this buffer is expected to be displayed. + pub present_time: i64, /// A fence used for reading/writing safely. pub fence: i32, } @@ -175,14 +174,12 @@ mod test { use anyhow::anyhow; use buffers::Buffer; use nativewindow::{AHardwareBuffer_Format, AHardwareBuffer_UsageFlags}; - use std::borrow::BorrowMut; - use std::error::Error; - use std::ops::Add; - use std::sync::Arc; - use std::time::Duration; + use std::{borrow::BorrowMut, error::Error, ops::Add, sync::Arc}; - use crate::publishers::testing::*; - use crate::subscribers::{testing::*, SharedSubscriber}; + use crate::{ + publishers::testing::*, + subscribers::{testing::*, SharedSubscriber}, + }; const STREAM_CONFIG: StreamConfig = StreamConfig { width: 1, @@ -200,7 +197,7 @@ mod test { .create_hardware_buffer() .expect("Unable to create hardware buffer for test"), ), - present_time: Instant::now() + Duration::from_secs(1), + present_time: 1, fence: 0, } } diff --git a/libs/bufferstreams/rust/src/publishers/buffer_pool_publisher.rs b/libs/bufferstreams/rust/src/publishers/buffer_pool_publisher.rs index 846105dacd..73a15be897 100644 --- a/libs/bufferstreams/rust/src/publishers/buffer_pool_publisher.rs +++ b/libs/bufferstreams/rust/src/publishers/buffer_pool_publisher.rs @@ -14,8 +14,6 @@ //! -use std::time::Instant; - use crate::{ buffers::BufferPool, subscriptions::SharedBufferSubscription, BufferPublisher, BufferSubscriber, Frame, StreamConfig, @@ -43,7 +41,7 @@ impl BufferPoolPublisher { /// If the [SharedBufferSubscription] is ready for a [Frame], a buffer will be requested from /// [BufferPool] and sent over to the [BufferSubscriber]. - pub fn send_next_frame(&mut self, present_time: Instant) -> bool { + pub fn send_next_frame(&mut self, present_time: i64) -> bool { if let Some(subscriber) = self.subscriber.as_mut() { if self.subscription.take_request() { if let Some(buffer) = self.buffer_pool.next_buffer() { @@ -103,7 +101,7 @@ mod test { subscriber.map_inner(|s| s.request(1)); - assert!(buffer_pool_publisher.send_next_frame(Instant::now())); + assert!(buffer_pool_publisher.send_next_frame(1)); let events = subscriber.map_inner_mut(|s| s.take_events()); assert!(matches!(events.last().unwrap(), TestingSubscriberEvent::Next(_))); |