Skip to content

Commit

Permalink
Merge branch 'main' into lukas/chat-api
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO committed Sep 25, 2024
2 parents 1d575c7 + fc9a382 commit 139e875
Show file tree
Hide file tree
Showing 74 changed files with 10,225 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gen-protocol.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install prost generators
run: cargo install protoc-gen-prost protoc-gen-prost-serde
run: cargo install protoc-gen-prost@0.3.1 protoc-gen-prost-serde@0.3.1

- name: generate python stubs
run: ./generate_proto.sh
Expand Down
2 changes: 1 addition & 1 deletion .nanparc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
packages livekit livekit-ffi livekit-protocol livekit-runtime livekit-api libwebrtc webrtc-sys webrtc-sys/build
packages livekit livekit-ffi livekit-protocol livekit-runtime livekit-api libwebrtc webrtc-sys webrtc-sys/build soxr-sys
2 changes: 1 addition & 1 deletion Cargo.lock

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

10 changes: 5 additions & 5 deletions livekit-api/src/signal_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl SignalClient {

/// Close the connection to the server
pub async fn close(&self) {
self.inner.close().await;
self.inner.close(true).await;

let handle = self.handle.lock().take();
if let Some(signal_task) = handle {
Expand Down Expand Up @@ -254,7 +254,7 @@ impl SignalInner {
proto::ReconnectResponse,
mpsc::UnboundedReceiver<Box<proto::signal_response::Message>>,
)> {
self.close().await;
self.close(false).await;

// Lock while we are reconnecting
let mut stream = self.stream.write().await;
Expand All @@ -278,9 +278,9 @@ impl SignalInner {
}

/// Close the connection
pub async fn close(&self) {
pub async fn close(&self, notify_close: bool) {
if let Some(stream) = self.stream.write().await.take() {
stream.close().await;
stream.close(notify_close).await;
}
}

Expand Down Expand Up @@ -392,7 +392,7 @@ async fn signal_task(
}
}

inner.close().await; // Make sure to always close the ws connection when the loop is terminated
inner.close(true).await; // Make sure to always close the ws connection when the loop is terminated
}

/// Check if the signal is queuable
Expand Down
6 changes: 4 additions & 2 deletions livekit-api/src/signal_client/signal_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ impl SignalStream {

/// Close the websocket
/// It sends a CloseFrame to the server before closing
pub async fn close(self) {
let _ = self.internal_tx.send(InternalMessage::Close).await;
pub async fn close(self, notify_close: bool) {
if notify_close {
let _ = self.internal_tx.send(InternalMessage::Close).await;
}
let _ = self.write_handle.await;
let _ = self.read_handle.await;
}
Expand Down
2 changes: 1 addition & 1 deletion livekit-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "livekit-ffi"
version = "0.10.2"
version = "0.10.3"
edition = "2021"
license = "Apache-2.0"
description = "FFI interface for bindings in other languages"
Expand Down
3 changes: 3 additions & 0 deletions livekit-protocol/generate_proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# limitations under the License.


# dependencies: cargo install protoc-gen-prost@0.3.1 protoc-gen-prost-serde@0.3.1


PROTOCOL=protocol/protobufs
OUT_RUST=src

Expand Down
4 changes: 2 additions & 2 deletions livekit/src/rtc_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl EngineInner {
async fn on_session_event(self: &Arc<Self>, event: SessionEvent) -> EngineResult<()> {
match event {
SessionEvent::Close { source, reason, action, retry_now } => {
log::debug!("received session close: {}, {:?}", source, reason);
log::warn!("received session close: {:?} {:?} {:?}", source, reason, action);
match action {
proto::leave_request::Action::Resume => {
self.reconnection_needed(retry_now, false)
Expand Down Expand Up @@ -619,7 +619,7 @@ impl EngineInner {
log::error!("resuming connection... attempt: {}", i);
if let Err(err) = self.try_resume_connection().await {
log::error!("resuming connection failed: {}", err);
if let EngineError::Signal(_) = err {
if !matches!(err, EngineError::Signal(_)) {
let mut running_handle = self.running_handle.write();
running_handle.full_reconnect = true;
}
Expand Down
19 changes: 11 additions & 8 deletions livekit/src/rtc_engine/rtc_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,15 @@ impl SessionInner {
task.await;
}
SignalEvent::Close(reason) => {
// SignalClient has been closed
self.on_session_disconnected(
format!("signal client closed: {:?}", reason).as_str(),
DisconnectReason::UnknownReason,
proto::leave_request::Action::Disconnect,
false,
);
if !self.closed.load(Ordering::Acquire) {
// SignalClient has been closed unexpectedly
self.on_session_disconnected(
format!("signal client closed: {:?}", reason).as_str(),
DisconnectReason::UnknownReason,
proto::leave_request::Action::Resume,
false,
);
}
}
}
},
Expand Down Expand Up @@ -787,6 +789,8 @@ impl SessionInner {
}

async fn close(&self) {
self.closed.store(true, Ordering::Release);

self.signal_client
.send(proto::signal_request::Message::Leave(proto::LeaveRequest {
action: proto::leave_request::Action::Disconnect.into(),
Expand All @@ -795,7 +799,6 @@ impl SessionInner {
}))
.await;

self.closed.store(true, Ordering::Release);
self.signal_client.close().await;
self.publisher_pc.close();
self.subscriber_pc.close();
Expand Down
2 changes: 2 additions & 0 deletions soxr-sys/.nanparc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version 0.1.0
language rust
32 changes: 32 additions & 0 deletions soxr-sys/Cargo.lock

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

14 changes: 14 additions & 0 deletions soxr-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "soxr-sys"
version = "0.1.0"
authors = ["Theo Monnom <theo.8bits@gmail.com"]
edition = "2021"

[dependencies]


[build-dependencies]
cc = "1.0"

[dev-dependencies]
hound = "3.4"
40 changes: 40 additions & 0 deletions soxr-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
fn main() {
let mut build = cc::Build::new();

build.include("src");
build.define("SOXR_LIB", "0");

build
.flag_if_supported("-std=gnu89")
.flag_if_supported("-Wnested-externs")
.flag_if_supported("-Wmissing-prototypes")
.flag_if_supported("-Wstrict-prototypes")
.flag_if_supported("-Wconversion")
.flag_if_supported("-Wall")
.flag_if_supported("-Wextra")
.flag_if_supported("-pedantic")
.flag_if_supported("-Wundef")
.flag_if_supported("-Wpointer-arith")
.flag_if_supported("-Wno-long-long");

// TODO(theomonnom): Add SIMD support
let sources = [
"src/soxr.c",
"src/data-io.c",
"src/dbesi0.c",
"src/filter.c",
"src/cr.c",
"src/cr32.c",
"src/fft4g32.c",
"src/fft4g.c",
"src/fft4g64.c",
"src/vr32.c",
];

for source in &sources {
build.file(source);
}

build.compile("libsoxr.a");
println!("cargo:rustc-link-lib=m");
}
1 change: 1 addition & 0 deletions soxr-sys/generate_bindings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bindgen --no-prepend-enum-name src/soxr.h -o src/soxr.rs
23 changes: 23 additions & 0 deletions soxr-sys/src/LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SoX Resampler Library Copyright (c) 2007-18 robs@users.sourceforge.net

This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.

This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library; if not, see <https://www.gnu.org/licenses/>.


Notes

1. Re software in the `examples' directory: works that are not resampling
examples but are based on the given examples -- for example, applications using
the library -- shall not be considered to be derivative works of the examples.

2. If building with pffft.c, see the licence embedded in that file.
39 changes: 39 additions & 0 deletions soxr-sys/src/aliases.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */

#if defined SOXR_LIB

#define lsx_bessel_I_0 _soxr_bessel_I_0
#define lsx_cdft_f _soxr_cdft_f
#define lsx_cdft _soxr_cdft
#define lsx_clear_fft_cache_f _soxr_clear_fft_cache_f
#define lsx_clear_fft_cache _soxr_clear_fft_cache
#define lsx_ddct_f _soxr_ddct_f
#define lsx_ddct _soxr_ddct
#define lsx_ddst_f _soxr_ddst_f
#define lsx_ddst _soxr_ddst
#define lsx_design_lpf _soxr_design_lpf
#define lsx_dfct_f _soxr_dfct_f
#define lsx_dfct _soxr_dfct
#define lsx_dfst_f _soxr_dfst_f
#define lsx_dfst _soxr_dfst
#define lsx_fir_to_phase _soxr_fir_to_phase
#define lsx_f_resp _soxr_f_resp
#define lsx_init_fft_cache_f _soxr_init_fft_cache_f
#define lsx_init_fft_cache _soxr_init_fft_cache
#define lsx_inv_f_resp _soxr_inv_f_resp
#define lsx_kaiser_beta _soxr_kaiser_beta
#define lsx_kaiser_params _soxr_kaiser_params
#define lsx_make_lpf _soxr_make_lpf
#define lsx_ordered_convolve_f _soxr_ordered_convolve_f
#define lsx_ordered_convolve _soxr_ordered_convolve
#define lsx_ordered_partial_convolve_f _soxr_ordered_partial_convolve_f
#define lsx_ordered_partial_convolve _soxr_ordered_partial_convolve
#define lsx_rdft_f _soxr_rdft_f
#define lsx_rdft _soxr_rdft
#define lsx_safe_cdft_f _soxr_safe_cdft_f
#define lsx_safe_cdft _soxr_safe_cdft
#define lsx_safe_rdft_f _soxr_safe_rdft_f
#define lsx_safe_rdft _soxr_safe_rdft

#endif
33 changes: 33 additions & 0 deletions soxr-sys/src/avfft32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */

#include <stdlib.h>
#include <math.h>
#include <libavcodec/avfft.h>
#include "filter.h"
#include "rdft_t.h"

static void * forward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),DFT_R2C);}
static void * backward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),IDFT_C2R);}
static void rdft(int length, void * setup, float * h) {av_rdft_calc(setup, h); (void)length;}
static int multiplier(void) {return 2;}
static void nothing(void) {}
static int flags(void) {return 0;}

fn_t _soxr_rdft32_cb[] = {
(fn_t)forward_setup,
(fn_t)backward_setup,
(fn_t)av_rdft_end,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)_soxr_ordered_convolve_f,
(fn_t)_soxr_ordered_partial_convolve_f,
(fn_t)multiplier,
(fn_t)nothing,
(fn_t)malloc,
(fn_t)calloc,
(fn_t)free,
(fn_t)flags,
};
32 changes: 32 additions & 0 deletions soxr-sys/src/avfft32s.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */

#include <math.h>
#include <libavcodec/avfft.h>
#include "util32s.h"
#include "rdft_t.h"

static void * forward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),DFT_R2C);}
static void * backward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),IDFT_C2R);}
static void rdft(int length, void * setup, float * h) {av_rdft_calc(setup, h); (void)length;}
static int multiplier(void) {return 2;}
static void nothing(void) {}
static int flags(void) {return RDFT_IS_SIMD;}

fn_t _soxr_rdft32s_cb[] = {
(fn_t)forward_setup,
(fn_t)backward_setup,
(fn_t)av_rdft_end,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)ORDERED_CONVOLVE_SIMD,
(fn_t)ORDERED_PARTIAL_CONVOLVE_SIMD,
(fn_t)multiplier,
(fn_t)nothing,
(fn_t)SIMD_ALIGNED_MALLOC,
(fn_t)SIMD_ALIGNED_CALLOC,
(fn_t)SIMD_ALIGNED_FREE,
(fn_t)flags,
};
Loading

0 comments on commit 139e875

Please sign in to comment.