Skip to content

Commit

Permalink
Reorganize code
Browse files Browse the repository at this point in the history
  • Loading branch information
sgasse committed Sep 14, 2024
1 parent 8a38407 commit 4db2b6b
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 489 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ use axum::{routing::get, Extension, Router};
use clap::Parser;
use env_logger::TimestampPrecision;
use infer_server::{
hour_glass::{
data_socket::spawn_data_socket,
endpoints::{faces_stream, healthcheck, named_stream},
inferer::Inferer,
router::FrameRouter,
INCOMING_FRAMES_CHANNEL, INFER_IMAGES_CHANNEL,
},
data_socket::spawn_data_socket,
endpoints::{faces_stream, healthcheck, named_stream},
inferer::Inferer,
meter::spawn_meter_logger,
router::FrameRouter,
INCOMING_FRAMES_CHANNEL, INFER_IMAGES_CHANNEL,
};

#[derive(Parser, Debug)]
Expand Down
62 changes: 0 additions & 62 deletions infer_server/src/bin/msg_passing.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tokio::{
};
use tokio_util::codec::{Framed, LengthDelimitedCodec};

use crate::hour_glass::StaticFrameSender;
use crate::StaticFrameSender;

pub async fn spawn_data_socket(
tx: StaticFrameSender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use futures::StreamExt;
use serde::Deserialize;
use tokio_stream::wrappers::BroadcastStream;

use crate::{hour_glass::router::FrameRouter, meter::METER};
use crate::{meter::METER, router::FrameRouter};

/// Search parameters available to streams.
#[derive(Debug, Deserialize)]
Expand Down
51 changes: 0 additions & 51 deletions infer_server/src/hour_glass/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use imageproc::{
use lazy_static::lazy_static;

use crate::{
hour_glass::StaticImageReceiver,
nn::{Bbox, InferModel, UltrafaceModel},
StaticImageReceiver,
};

use super::as_jpeg_stream_item;
Expand Down Expand Up @@ -93,7 +93,7 @@ fn draw_bboxes_on_image(

lazy_static! {
static ref DEJAVU_MONO: rusttype::Font<'static> = {
let font_data: &[u8] = include_bytes!("../../../resources/DejaVuSansMono.ttf");
let font_data: &[u8] = include_bytes!("../../resources/DejaVuSansMono.ttf");
let font: rusttype::Font<'static> =
rusttype::Font::try_from_bytes(font_data).expect("failed to load font");
font
Expand Down
39 changes: 37 additions & 2 deletions infer_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,36 @@ use std::{
hash::{Hash, Hasher},
};

pub mod hour_glass;
use bytes::{Bytes, BytesMut};
use thingbuf::mpsc::{StaticChannel, StaticReceiver, StaticSender};

pub mod data_socket;
pub mod endpoints;
pub mod inferer;
pub mod meter;
pub mod msg_passing;
pub mod nn;
pub mod router;
pub mod utils;

pub type StaticFrameSender = StaticSender<BytesMut>;
pub type StaticFrameReceiver = StaticReceiver<BytesMut>;

pub static INCOMING_FRAMES_CHANNEL: StaticChannel<BytesMut, 200> = StaticChannel::new();

pub type BroadcastSender = tokio::sync::broadcast::Sender<Bytes>;
pub type BroadcastReceiver = tokio::sync::broadcast::Receiver<Bytes>;

pub fn broadcast_channel() -> (BroadcastSender, BroadcastReceiver) {
tokio::sync::broadcast::channel(20)
}

pub type StaticImage = (u32, u32, Vec<u8>, Option<BroadcastSender>);

pub type StaticImageSender = StaticSender<StaticImage>;
pub type StaticImageReceiver = StaticReceiver<StaticImage>;

pub static INFER_IMAGES_CHANNEL: StaticChannel<StaticImage, 10> = StaticChannel::new();

fn hashed<T>(data: T) -> u64
where
T: Hash,
Expand All @@ -20,3 +44,14 @@ where
data.hash(&mut hasher);
hasher.finish()
}

fn as_jpeg_stream_item(data: &[u8]) -> Bytes {
Bytes::copy_from_slice(
&[
"--frame\r\nContent-Type: image/jpeg\r\n\r\n".as_bytes(),
&data[..],
"\r\n\r\n".as_bytes(),
]
.concat(),
)
}
108 changes: 0 additions & 108 deletions infer_server/src/msg_passing/data_socket.rs

This file was deleted.

53 changes: 0 additions & 53 deletions infer_server/src/msg_passing/endpoints.rs

This file was deleted.

3 changes: 0 additions & 3 deletions infer_server/src/msg_passing/mod.rs

This file was deleted.

Loading

0 comments on commit 4db2b6b

Please sign in to comment.