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
12 changes: 10 additions & 2 deletions livekit/src/room/participant/local_participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
r#type: proto::TrackType::from(track.kind()) as i32,
muted: track.is_muted(),
source: proto::TrackSource::from(options.source) as i32,
disable_dtx: !options.dtx,

Check warning on line 390 in livekit/src/room/participant/local_participant.rs

View workflow job for this annotation

GitHub Actions / Features per-commit (aarch64-unknown-linux-gnu)

use of deprecated field `livekit_protocol::AddTrackRequest::disable_dtx`

Check warning on line 390 in livekit/src/room/participant/local_participant.rs

View workflow job for this annotation

GitHub Actions / Features per-commit (x86_64-pc-windows-msvc)

use of deprecated field `livekit_protocol::AddTrackRequest::disable_dtx`

Check warning on line 390 in livekit/src/room/participant/local_participant.rs

View workflow job for this annotation

GitHub Actions / Features per-commit (aarch64-pc-windows-msvc)

use of deprecated field `livekit_protocol::AddTrackRequest::disable_dtx`

Check warning on line 390 in livekit/src/room/participant/local_participant.rs

View workflow job for this annotation

GitHub Actions / Features per-commit (x86_64-unknown-linux-gnu)

use of deprecated field `livekit_protocol::AddTrackRequest::disable_dtx`

Check warning on line 390 in livekit/src/room/participant/local_participant.rs

View workflow job for this annotation

GitHub Actions / Features per-commit (x86_64-apple-darwin)

use of deprecated field `livekit_protocol::AddTrackRequest::disable_dtx`

Check warning on line 390 in livekit/src/room/participant/local_participant.rs

View workflow job for this annotation

GitHub Actions / Features per-commit (aarch64-apple-darwin)

use of deprecated field `livekit_protocol::AddTrackRequest::disable_dtx`

Check warning on line 390 in livekit/src/room/participant/local_participant.rs

View workflow job for this annotation

GitHub Actions / Features per-commit (aarch64-apple-ios-sim)

use of deprecated field `livekit_protocol::AddTrackRequest::disable_dtx`

Check warning on line 390 in livekit/src/room/participant/local_participant.rs

View workflow job for this annotation

GitHub Actions / Features per-commit (aarch64-apple-ios)

use of deprecated field `livekit_protocol::AddTrackRequest::disable_dtx`
disable_red,
encryption: proto::encryption::Type::from(self.local.encryption_type) as i32,
stream: options.stream.clone(),
Expand Down Expand Up @@ -667,7 +667,11 @@
let track = publication.track().unwrap();
let sender = track.transceiver().unwrap().sender();

self.inner.rtc_engine.remove_track(sender)?;
let remove_result = self.inner.rtc_engine.remove_track(sender);

// The peer connection may already be closed after a server-initiated
// disconnect. Always release the local publication/track graph even
// when removing its sender is no longer possible.
track.set_transceiver(None);

if let Some(local_track_unpublished) =
Expand All @@ -677,7 +681,11 @@
}

publication.set_track(None);
self.inner.rtc_engine.publisher_negotiation_needed();
if remove_result.is_ok() {
self.inner.rtc_engine.publisher_negotiation_needed();
}

remove_result?;

Ok(publication)
} else {
Expand Down
48 changes: 45 additions & 3 deletions livekit/tests/reconnection_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@
use {
anyhow::{anyhow, bail, Result},
common::test_rooms,
libwebrtc::native::create_random_uuid,
livekit::{ConnectionState, Room, RoomEvent, RoomOptions, SimulateScenario},
libwebrtc::{
native::create_random_uuid,
prelude::{RtcVideoSource, VideoResolution},
video_source::native::NativeVideoSource,
},
livekit::{
options::TrackPublishOptions,
track::{LocalTrack, LocalVideoTrack},
ConnectionState, Room, RoomEvent, RoomOptions, SimulateScenario,
},
livekit_api::services::room::RoomClient,
livekit_token::{AccessToken, VideoGrants},
std::{env, net::SocketAddr, time::Duration},
tokio::{
net::{TcpListener, TcpStream},
sync::{mpsc::UnboundedReceiver, watch},
time::timeout,
time::{self, timeout},
},
};

Expand Down Expand Up @@ -396,6 +404,19 @@ async fn test_room_deleted_disconnects_without_reconnect() -> Result<()> {
let (room, mut events) = Room::connect(&server_url, &token, RoomOptions::default()).await?;
assert_eq!(room.connection_state(), ConnectionState::Connected);

let session_dropped = room.drop_probe();

let source = NativeVideoSource::new(VideoResolution { width: 16, height: 16 }, false);
let track = LocalVideoTrack::create_video_track(
"server-deleted-track",
RtcVideoSource::Native(source.clone()),
);
let publication = room
.local_participant()
.publish_track(LocalTrack::Video(track), TrackPublishOptions::default())
.await?;
assert!(publication.track().is_some());

let http_url = server_url.replacen("ws", "http", 1);
RoomClient::with_api_key(&http_url, &api_key, &api_secret).delete_room(&room_name).await?;

Expand All @@ -413,5 +434,26 @@ async fn test_room_deleted_disconnects_without_reconnect() -> Result<()> {

assert_eq!(reason, livekit::DisconnectReason::RoomDeleted);
assert_eq!(room.connection_state(), ConnectionState::Disconnected);

timeout(Duration::from_secs(5), async {
while publication.track().is_some() {
time::sleep(Duration::from_millis(10)).await;
}
})
.await
.map_err(|_| anyhow!("server deletion did not detach the published local track"))?;

drop(publication);
drop(source);
drop(events);
drop(room);

timeout(Duration::from_secs(5), async {
while !session_dropped() {
time::sleep(Duration::from_millis(10)).await;
}
})
.await
.map_err(|_| anyhow!("published track retained the room session after server deletion"))?;
Ok(())
}
1 change: 0 additions & 1 deletion webrtc-sys/src/nvidia/cuda_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <dlfcn.h>
#endif

#include <iostream>
#include <mutex>

#if defined(WIN32)
Expand Down
24 changes: 9 additions & 15 deletions webrtc-sys/src/nvidia/nvidia_decoder_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,22 @@ bool IsNvdecRuntimeAvailable() {

} // namespace

static int GetCudaDeviceCapabilityMajorVersion(CUcontext context) {
cuCtxSetCurrent(context);

CUdevice device;
cuCtxGetDevice(&device);

static int GetCudaDeviceCapabilityMajorVersion(CUdevice device) {
int major;
cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR,
device);

return major;
}

std::vector<SdpVideoFormat> SupportedNvDecoderCodecs(CUcontext context) {
std::vector<SdpVideoFormat> SupportedNvDecoderCodecs(CUdevice device) {
std::vector<SdpVideoFormat> supportedFormats;

// HardwareGeneration Kepler is 3.x
// https://docs.nvidia.com/deploy/cuda-compatibility/index.html#faq
// Kepler support h264 profile Main, Highprofile up to Level4.1
// https://docs.nvidia.com/video-technologies/video-codec-sdk/nvdec-video-decoder-api-prog-guide/index.html#video-decoder-capabilities__table_o3x_fms_3lb
if (GetCudaDeviceCapabilityMajorVersion(context) <= 3) {
if (GetCudaDeviceCapabilityMajorVersion(device) <= 3) {
supportedFormats = {
CreateH264Format(webrtc::H264Profile::kProfileHigh,
webrtc::H264Level::kLevel4_1, "1"),
Expand Down Expand Up @@ -117,13 +112,12 @@ NvidiaVideoDecoderFactory::NvidiaVideoDecoderFactory()
return;
}

cu_context_ = livekit_ffi::CudaContext::GetInstance();
if (cu_context_->Initialize()) {
supported_formats_ = SupportedNvDecoderCodecs(cu_context_->GetContext());
} else {
RTC_LOG(LS_ERROR) << "Failed to initialize CUDA context.";
cu_context_ = nullptr;
CUdevice device;
if (cuDeviceGet(&device, 0) != CUDA_SUCCESS) {
RTC_LOG(LS_ERROR) << "Failed to get CUDA device.";
return;
}
supported_formats_ = SupportedNvDecoderCodecs(device);
RTC_LOG(LS_INFO) << "NvidiaVideoDecoderFactory created with "
<< supported_formats_.size() << " supported formats.";
}
Expand Down Expand Up @@ -154,7 +148,7 @@ bool NvidiaVideoDecoderFactory::IsSupported() {
return false;
}

std::cout << "Nvidia Decoder is supported." << std::endl;
RTC_LOG(LS_INFO) << "Nvidia Decoder is supported.";
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions webrtc-sys/src/vaapi/vaapi_display_drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static bool check_h264_encoding_support(VADisplay va_display) {
entrypoints = new VAEntrypoint[num_entrypoints * sizeof(*entrypoints)];
if (!entrypoints) {
RTC_LOG(LS_ERROR) << "failed to allocate VA entrypoints";
vaTerminate(va_display);
return false;
}

Expand Down Expand Up @@ -75,10 +76,12 @@ static bool check_h264_encoding_support(VADisplay va_display) {
<< "Can't find VAEntrypointEncSlice or VAEntrypointEncSliceLP for "
"H264 profiles";
delete[] entrypoints;
vaTerminate(va_display);
return false;
}

delete[] entrypoints;
vaTerminate(va_display);
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions webrtc-sys/src/vaapi/vaapi_encoder_factory.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "vaapi_encoder_factory.h"

#include <memory>
#include <iostream>
#include <dlfcn.h>

#include "h264_encoder_impl.h"
Expand Down Expand Up @@ -64,7 +63,7 @@ bool VAAPIVideoEncoderFactory::IsSupported() {

vaapi_display.Close();
// If we can open the VAAPI display, we consider it supported.
std::cout << "VAAPI is supported." << std::endl;
RTC_LOG(LS_INFO) << "VAAPI is supported.";
return true;
}

Expand Down
Loading