feat: forward libwebrtc logs (#75)

This commit is contained in:
Théo Monnom
2023-05-24 18:37:35 +02:00
committed by GitHub
parent d5b4a8f6fc
commit 3f61e07e09
19 changed files with 300 additions and 98 deletions
+1
View File
@@ -3,6 +3,7 @@ pub mod candidate;
pub mod data_channel;
pub mod helper;
pub mod jsep;
pub mod logsink;
pub mod media_stream;
pub mod peer_connection;
pub mod peer_connection_factory;
+40
View File
@@ -0,0 +1,40 @@
/*
* Copyright 2023 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <memory>
#include "livekit/logsink.h"
namespace livekit {
LogSink::LogSink(rust::Fn<void(rust::String message, LoggingSeverity severity)> fnc) : fnc_(fnc) {
rtc::LogMessage::AddLogToStream(this, rtc::LoggingSeverity::LS_VERBOSE);
}
LogSink::~LogSink() {
rtc::LogMessage::RemoveLogToStream(this);
}
void LogSink::OnLogMessage(const std::string& message, rtc::LoggingSeverity severity) {
fnc_(rust::String(message), static_cast<LoggingSeverity>(severity));
}
std::unique_ptr<LogSink> new_log_sink(rust::Fn<void (rust::String, LoggingSeverity)> fnc) {
return std::make_unique<LogSink>(fnc);
}
}
+24
View File
@@ -0,0 +1,24 @@
use crate::impl_thread_safety;
#[cxx::bridge(namespace = "livekit")]
pub mod ffi {
#[derive(Debug)]
#[repr(i32)]
pub enum LoggingSeverity {
Verbose,
Info,
Warning,
Error,
None,
}
unsafe extern "C++" {
include!("livekit/logsink.h");
type LogSink;
fn new_log_sink(fnc: fn(String, LoggingSeverity)) -> UniquePtr<LogSink>;
}
}
impl_thread_safety!(ffi::LogSink, Send + Sync);