1 parent
052a27bc48
commit
528017b0e6
36 files changed
+3394
-216
No files matched your search
@@ -31,6 +31,12 @@ pub struct Clients {
|
||||
sent: AtomicU64,
|
||||
/// Total bytes written by recordings since start.
|
||||
recorded: AtomicU64,
|
||||
/// Bytes sent per protocol: MPEG-TS over HTTP, HLS, HTSP.
|
||||
sent_ts: AtomicU64,
|
||||
sent_hls: AtomicU64,
|
||||
sent_htsp: AtomicU64,
|
||||
/// Finished viewing sessions go here (written to the watch history).
|
||||
history: Mutex<Option<tokio::sync::mpsc::UnboundedSender<crate::db::WatchRecord>>>,
|
||||
}
|
||||
|
||||
pub struct ClientGuard {
|
||||
@@ -49,6 +55,24 @@ impl ClientGuard {
|
||||
impl Drop for ClientGuard {
|
||||
fn drop(&mut self) {
|
||||
self.owner.map.lock().unwrap().remove(&self.clients.id);
|
||||
let c = &self.clients;
|
||||
let ended = now();
|
||||
// sessions shorter than 10 s are channel zapping / probes, not viewing
|
||||
if c.kind != "recording" && ended - c.started >= 10 {
|
||||
if let Some(tx) = self.owner.history.lock().unwrap().as_ref() {
|
||||
let _ = tx.send(crate::db::WatchRecord {
|
||||
channel_id: Some(c.channel_id).filter(|id| *id > 0),
|
||||
channel_name: c.channel_name.clone(),
|
||||
kind: c.kind.clone(),
|
||||
who: c.who.clone(),
|
||||
ip: c.ip.clone(),
|
||||
device: device_name(&c.user_agent),
|
||||
started: c.started,
|
||||
ended,
|
||||
bytes: c.bytes.load(Ordering::Relaxed) as i64,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,14 +87,34 @@ pub struct NewClient<'a> {
|
||||
}
|
||||
|
||||
impl Clients {
|
||||
/// Enables the watch history (finished sessions are sent to `tx`).
|
||||
pub fn set_history(&self, tx: tokio::sync::mpsc::UnboundedSender<crate::db::WatchRecord>) {
|
||||
*self.history.lock().unwrap() = Some(tx);
|
||||
}
|
||||
|
||||
fn count(&self, kind: &str, n: u64) {
|
||||
if kind == "recording" {
|
||||
self.recorded.fetch_add(n, Ordering::Relaxed);
|
||||
} else {
|
||||
self.sent.fetch_add(n, Ordering::Relaxed);
|
||||
match kind {
|
||||
"hls" => &self.sent_hls,
|
||||
"htsp" => &self.sent_htsp,
|
||||
_ => &self.sent_ts,
|
||||
}
|
||||
.fetch_add(n, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
/// Bytes sent since start per protocol: (TS over HTTP, HLS, HTSP).
|
||||
pub fn by_protocol(&self) -> (u64, u64, u64) {
|
||||
(
|
||||
self.sent_ts.load(Ordering::Relaxed),
|
||||
self.sent_hls.load(Ordering::Relaxed),
|
||||
self.sent_htsp.load(Ordering::Relaxed),
|
||||
)
|
||||
}
|
||||
|
||||
/// (bytes sent to clients, bytes recorded) since start.
|
||||
pub fn totals(&self) -> (u64, u64) {
|
||||
(
|
||||
|
||||
Reference in new issue
Block a user