connection.rs 871 B

12345678910111213141516171819202122232425262728293031323334353637
  1. use crate::protocol::parser::{AudioPacket, ControlMessage, Message};
  2. use async_trait::async_trait;
  3. #[async_trait]
  4. pub trait ControlChannel: Send + Sync {
  5. async fn send(&self, message: impl Message + 'async_trait) -> Result<(), Error>;
  6. async fn receive(&self) -> Result<ControlMessage, Error>;
  7. fn get_stats(&self) -> ControlChannelStats;
  8. }
  9. #[async_trait]
  10. pub trait AudioChannel: Send + Sync {
  11. async fn send(&self, packet: AudioPacket) -> Result<(), Error>;
  12. async fn receive(&self) -> Result<AudioPacket, Error>;
  13. fn get_stats(&self) -> AudioChannelStats;
  14. }
  15. pub struct ControlChannelStats {
  16. pub received: u32,
  17. }
  18. pub struct AudioChannelStats {
  19. pub good: u32,
  20. pub late: u32,
  21. pub lost: u32,
  22. pub received: u32,
  23. }
  24. #[derive(Debug)]
  25. pub enum Error {
  26. IO(std::io::Error),
  27. Parsing(crate::protocol::parser::ParsingError),
  28. }