Skip to content

Commit 0c3ff29

Browse files
author
James Shargo
committed
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
1 parent d1ce298 commit 0c3ff29

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

libs/bufferstreams/rust/src/lib.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ pub mod subscriptions;
2323
use buffers::Buffer;
2424
pub use stream_config::*;
2525

26-
use std::time::Instant;
27-
2826
/// This function will print Hello World.
2927
#[no_mangle]
3028
pub extern "C" fn hello() -> bool {
@@ -106,7 +104,8 @@ pub trait BufferSubscriber {
106104
/// BufferSubscriptions serve as the bridge between BufferPublishers and
107105
/// BufferSubscribers. BufferSubscribers receive a BufferSubscription when they
108106
/// subscribe to a BufferPublisher via on_subscribe.
109-
/// This object is to be used by the BufferSubscriber to cancel its subscription
107+
///
108+
/// This object is used by the BufferSubscriber to cancel its subscription
110109
/// or request more buffers.
111110
///
112111
/// BufferSubcriptions are required to adhere to the following, based on the
@@ -147,7 +146,7 @@ pub trait BufferSubscriber {
147146
/// no other Subscription exists at this point.
148147
/// * Calling Subscription.cancel MUST return normally.
149148
/// * Calling Subscription.request MUST return normally.
150-
pub trait BufferSubscription {
149+
pub trait BufferSubscription: Send + Sync + 'static {
151150
/// request
152151
fn request(&self, n: u64);
153152
/// cancel
@@ -161,8 +160,8 @@ pub type BufferError = anyhow::Error;
161160
pub struct Frame {
162161
/// A buffer to be used this frame.
163162
pub buffer: Buffer,
164-
/// The time at which the buffer was dispatched.
165-
pub present_time: Instant,
163+
/// The time at which this buffer is expected to be displayed.
164+
pub present_time: i64,
166165
/// A fence used for reading/writing safely.
167166
pub fence: i32,
168167
}
@@ -175,14 +174,12 @@ mod test {
175174
use anyhow::anyhow;
176175
use buffers::Buffer;
177176
use nativewindow::{AHardwareBuffer_Format, AHardwareBuffer_UsageFlags};
178-
use std::borrow::BorrowMut;
179-
use std::error::Error;
180-
use std::ops::Add;
181-
use std::sync::Arc;
182-
use std::time::Duration;
177+
use std::{borrow::BorrowMut, error::Error, ops::Add, sync::Arc};
183178

184-
use crate::publishers::testing::*;
185-
use crate::subscribers::{testing::*, SharedSubscriber};
179+
use crate::{
180+
publishers::testing::*,
181+
subscribers::{testing::*, SharedSubscriber},
182+
};
186183

187184
const STREAM_CONFIG: StreamConfig = StreamConfig {
188185
width: 1,
@@ -200,7 +197,7 @@ mod test {
200197
.create_hardware_buffer()
201198
.expect("Unable to create hardware buffer for test"),
202199
),
203-
present_time: Instant::now() + Duration::from_secs(1),
200+
present_time: 1,
204201
fence: 0,
205202
}
206203
}

libs/bufferstreams/rust/src/publishers/buffer_pool_publisher.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
//!
1616
17-
use std::time::Instant;
18-
1917
use crate::{
2018
buffers::BufferPool, subscriptions::SharedBufferSubscription, BufferPublisher,
2119
BufferSubscriber, Frame, StreamConfig,
@@ -43,7 +41,7 @@ impl BufferPoolPublisher {
4341

4442
/// If the [SharedBufferSubscription] is ready for a [Frame], a buffer will be requested from
4543
/// [BufferPool] and sent over to the [BufferSubscriber].
46-
pub fn send_next_frame(&mut self, present_time: Instant) -> bool {
44+
pub fn send_next_frame(&mut self, present_time: i64) -> bool {
4745
if let Some(subscriber) = self.subscriber.as_mut() {
4846
if self.subscription.take_request() {
4947
if let Some(buffer) = self.buffer_pool.next_buffer() {
@@ -103,7 +101,7 @@ mod test {
103101

104102
subscriber.map_inner(|s| s.request(1));
105103

106-
assert!(buffer_pool_publisher.send_next_frame(Instant::now()));
104+
assert!(buffer_pool_publisher.send_next_frame(1));
107105

108106
let events = subscriber.map_inner_mut(|s| s.take_events());
109107
assert!(matches!(events.last().unwrap(), TestingSubscriberEvent::Next(_)));

0 commit comments

Comments
 (0)