Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions livekit-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ downcast-rs = "1.2"
console-subscriber = { version = "0.1", features = ["parking_lot"], optional = true }
bytes = "1.10.1"
from_variants = "1.0.2"
metrics-logger = "0.22.1"

[target.'cfg(target_os = "android")'.dependencies]
jni = "0.21.1"
Expand Down
11 changes: 11 additions & 0 deletions livekit-ffi/src/server/colorcvt/cvtimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::time::Instant;

use super::*;
use crate::proto;
use crate::{FfiError, FfiResult};
use imgproc::colorcvt;
use metrics_logger::metrics::histogram;

pub unsafe fn cvt(
buffer: proto::VideoBufferInfo,
Expand Down Expand Up @@ -312,16 +315,24 @@ pub unsafe fn cvt_i420(
| proto::VideoBufferType::Abgr
| proto::VideoBufferType::Argb
| proto::VideoBufferType::Bgra => {

let start = Instant::now();
let mut dst = vec![0u8; (width * height * 4) as usize].into_boxed_slice();
let delta = start.elapsed();
histogram!("dst_alloc").record(delta.as_millis() as f64);

let stride = width * 4;

macro_rules! cvt {
($rgba:expr, $fnc:ident) => {
if dst_type == $rgba {
let start = Instant::now();
colorcvt::$fnc(
data_y, c0.stride, data_u, c1.stride, data_v, c2.stride, &mut dst,
stride, width, height, flip_y,
);
let delta = start.elapsed();
histogram!(stringify!($fnc)).record(delta.as_millis() as f64);
}
};
}
Expand Down
8 changes: 8 additions & 0 deletions livekit-ffi/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use livekit::webrtc::{
};
use parking_lot::{deadlock, Mutex};
use tokio::{sync::oneshot, task::JoinHandle};
use metrics_logger::{metrics, MetricsLogger, LogMode};

use crate::{proto, proto::FfiEvent, FfiError, FfiHandleId, FfiResult, INVALID_HANDLE};

Expand Down Expand Up @@ -101,6 +102,13 @@ impl Default for FfiServer {
#[cfg(feature = "tracing")]
console_subscriber::init();

let recorder = MetricsLogger::new(
LogMode::Periodic(10),
|logs| log::info!(target: "metrics", "{}", logs),
|err| log::error!(target: "metrics", "{}", err),
);
metrics::set_global_recorder(recorder).unwrap();

// Create a background thread which checks for deadlocks every 10s
thread::spawn(move || loop {
thread::sleep(Duration::from_secs(10));
Expand Down
11 changes: 9 additions & 2 deletions livekit-ffi/src/server/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{slice, sync::Arc};
use std::{slice, sync::Arc, time::Instant};
use metrics_logger::metrics::histogram;

use colorcvt::cvtimpl;
use livekit::{
Expand Down Expand Up @@ -480,7 +481,13 @@ unsafe fn on_video_convert(
let ref buffer = video_convert.buffer;
let flip_y = video_convert.flip_y;
let dst_type = video_convert.dst_type();
match cvtimpl::cvt(buffer.clone(), dst_type, flip_y.unwrap_or(false)) {

let start = Instant::now();
let cvt_result = cvtimpl::cvt(buffer.clone(), dst_type, flip_y.unwrap_or(false));
let delta = start.elapsed();
histogram!("color_cvt").record(delta.as_millis() as f64);

match cvt_result {
Ok((buffer, info)) => {
let id = server.next_id();
server.store_handle(id, buffer);
Expand Down