Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c3ff29b authored by James Shargo's avatar James Shargo Committed by Jim Shargo
Browse files

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
parent d1ce298d
Loading
Loading
Loading
Loading
+11 −14
Original line number Diff line number Diff line
@@ -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,
        }
    }
+2 −4
Original line number Diff line number Diff line
@@ -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(_)));