8000 implement track permission updates (#563) · livekit/rust-sdks@1d85bac · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
implement track permission updates (#563)
Browse files Browse the repository at this point in the history
* implement track permission updates

* fixed locks

* fix build

* formatting

* changeset
  • Loading branch information
davidzhao authored Feb 3, 2025
1 parent e7e93c4 commit 1d85bac
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 19 deletions.
Empty file added .nanpa/.keep
Empty file.
1 change: 1 addition & 0 deletions .nanpa/track-permissions.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch package="livekit-rtc" type="added" "Support for track subscription permissions"
11 changes: 8 additions & 3 deletions livekit-ffi/protocol/ffi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import "rpc.proto";
// that it receives from the server.
//
// Therefore, the ffi client is easier to implement if there is less handles to manage.
//
//
// - We are mainly using FfiHandle on info messages (e.g: RoomInfo, TrackInfo, etc...)
// For this reason, info are only sent once, at creation (We're not using them for updates, we can infer them from
// events on the client implementation).
Expand All @@ -71,16 +71,16 @@ message FfiRequest {
GetSessionStatsRequest get_session_stats = 12;
PublishTranscriptionRequest publish_transcription = 13;
PublishSipDtmfRequest publish_sip_dtmf = 14;


// Track
CreateVideoTrackRequest create_video_track = 15;
CreateAudioTrackRequest create_audio_track = 16;
LocalTrackMuteRequest local_track_mute = 17;
EnableRemoteTrackRequest enable_remote_track = 18;
GetStatsRequest get_stats = 19;
SetTrackSubscriptionPermissionsRequest set_track_subscription_permissions = 48;

// Video
// Video
NewVideoStreamRequest new_video_stream = 20;
NewVideoSourceRequest new_video_source = 21;
CaptureVideoFrameRequest capture_video_frame = 22;
Expand Down Expand Up @@ -119,6 +119,8 @@ message FfiRequest {

// Data Channel
SetDataChannelBufferedAmountLowThresholdRequest set_data_channel_buffered_amount_low_threshold = 47;

// NEXT_ID: 49
}
}

Expand Down Expand Up @@ -147,6 +149,7 @@ message FfiResponse {
LocalTrackMuteResponse local_track_mute = 17;
EnableRemoteTrackResponse enable_remote_track = 18;
GetStatsResponse get_stats = 19;
SetTrackSubscriptionPermissionsResponse set_track_subscription_permissions = 47;

// Video
NewVideoStreamResponse new_video_stream = 20;
Expand Down Expand Up @@ -184,6 +187,8 @@ message FfiResponse {

// Data Channel
SetDataChannelBufferedAmountLowThresholdResponse set_data_channel_buffered_amount_low_threshold = 46;

// NEXT_ID: 48
}
}

Expand Down
18 changes: 18 additions & 0 deletions livekit-ffi/protocol/track.proto
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,21 @@ message EnableRemoteTrackRequest {
message EnableRemoteTrackResponse {
required bool enabled = 1;
}

message SetTrackSubscriptionPermissionsRequest {
required uint64 local_participant_handle = 1;
required bool all_participants_allowed = 2;
repeated ParticipantTrackPermission permissions = 3;
}

message ParticipantTrackPermission {
// The participant identity this permission applies to.
required string participant_identity = 1;
// Grant permission to all all tracks. Takes precedence over allowedTrackSids.
optional bool allow_all = 2;
// List of track sids to grant permission to.
repeated string allowed_track_sids = 3;
}

message SetTrackSubscriptionPermissionsResponse {
}
30 changes: 29 additions & 1 deletion livekit-ffi/src/conversion/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use livekit::prelude::*;
use livekit::{participant::ParticipantTrackPermission, prelude::*};

use crate::{
proto,
Expand Down Expand Up @@ -93,3 +93,31 @@ impl From<TrackSource> for proto::TrackSource {
}
}
}

impl From<ParticipantTrackPermission> for proto::ParticipantTrackPermission {
fn from(value: ParticipantTrackPermission) -> Self {
proto::ParticipantTrackPermission {
participant_identity: value.participant_identity.to_string(),
allow_all: Some(value.allow_all),
allowed_track_sids: value
.allowed_track_sids
.into_iter()
.map(|sid| sid.to_string())
.collect(),
}
}
}

impl From<proto::ParticipantTrackPermission> for ParticipantTrackPermission {
fn from(value: proto::ParticipantTrackPermission) -> Self {
Self {
participant_identity: value.participant_identity.into(),
allow_all: value.allow_all.unwrap_or(false),
allowed_track_sids: value
.allowed_track_sids
.into_iter()
.map(|sid| sid.try_into().unwrap())
.collect(),
}
}
}
42 changes: 36 additions & 6 deletions livekit-ffi/src/livekit.proto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @generated
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FrameCryptor {
Expand Down Expand Up @@ -1455,6 +1454,33 @@ pub struct EnableRemoteTrackResponse {
#[prost(bool, required, tag="1")]
pub enabled: bool,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SetTrackSubscriptionPermissionsRequest {
#[prost(uint64, required, tag="1")]
pub local_participant_handle: u64,
#[prost(bool, required, tag="2")]
pub all_participants_allowed: bool,
#[prost(message, repeated, tag="3")]
pub permissions: ::prost::alloc::vec::Vec<ParticipantTrackPermission>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ParticipantTrackPermission {
/// The participant identity this permission applies to.
#[prost(string, required, tag="1")]
pub participant_identity: ::prost::alloc::string::String,
/// Grant permission to all all tracks. Takes precedence over allowedTrackSids.
#[prost(bool, optional, tag="2")]
pub allow_all: ::core::option::Option<bool>,
/// List of track sids to grant permission to.
#[prost(string, repeated, tag="3")]
pub allowed_track_sids: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SetTrackSubscriptionPermissionsResponse {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum TrackKind {
Expand Down Expand Up @@ -1844,8 +1870,8 @@ pub struct VideoBufferInfo {
#[prost(uint64, required, tag="4")]
pub data_ptr: u64,
/// only for packed formats
#[prost(uint32, required, tag="6")]
pub stride: u32,
#[prost(uint32, optional, tag="6")]
pub stride: ::core::option::Option<u32>,
#[prost(message, repeated, tag="7")]
pub components: ::prost::alloc::vec::Vec<video_buffer_info::ComponentInfo>,
}
Expand Down Expand Up @@ -4007,7 +4033,7 @@ pub struct RpcMethodInvocationEvent {
// that it receives from the server.
//
// Therefore, the ffi client is easier to implement if there is less handles to manage.
//
//
// - We are mainly using FfiHandle on info messages (e.g: RoomInfo, TrackInfo, etc...)
// For this reason, info are only sent once, at creation (We're not using them for updates, we can infer them from
// events on the client implementation).
Expand All @@ -4018,7 +4044,7 @@ pub struct RpcMethodInvocationEvent {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FfiRequest {
#[prost(oneof="ffi_request::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47")]
#[prost(oneof="ffi_request::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 48, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47")]
pub message: ::core::option::Option<ffi_request::Message>,
}
/// Nested message and enum types in `FfiRequest`.
Expand Down Expand Up @@ -4064,6 +4090,8 @@ pub mod ffi_request {
EnableRemoteTrack(super::EnableRemoteTrackRequest),
#[prost(message, tag="19")]
GetStats(super::GetStatsRequest),
#[prost(message, tag="48")]
SetTrackSubscriptionPermissions(super::SetTrackSubscriptionPermissionsRequest),
/// Video
#[prost(message, tag="20")]
NewVideoStream(super::NewVideoStreamRequest),
Expand Down Expand Up @@ -4132,7 +4160,7 @@ pub mod ffi_request {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FfiResponse {
#[prost(oneof="ffi_response::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46")]
#[prost(oneof="ffi_response::Message", tags="2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 47, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46")]
pub message: ::core::option::Option<ffi_response::Message>,
}
/// Nested message and enum types in `FfiResponse`.
Expand Down Expand Up @@ -4178,6 +4206,8 @@ pub mod ffi_response {
EnableRemoteTrack(super::EnableRemoteTrackResponse),
#[prost(message, tag="19")]
GetStats(super::GetStatsResponse),
#[prost(message, tag="47")]
SetTrackSubscriptionPermissions(super::SetTrackSubscriptionPermissionsResponse),
/// Video
#[prost(message, tag="20")]
NewVideoStream(super::NewVideoStreamResponse),
Expand Down
5 changes: 5 additions & 0 deletions livekit-ffi/src/server/colorcvt/cvtimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub unsafe fn cvt_rgba(
) -> FfiResult<(Box<[u8]>, proto::VideoBufferInfo)> {
assert_eq!(buffer.r#type(), proto::VideoBufferType::Rgba);
let proto::VideoBufferInfo { stride, width, height, data_ptr, .. } = buffer;
let stride = stride.unwrap_or(width * 4);
let data_len = (stride * height) as usize;
let data = unsafe { slice::from_raw_parts(data_ptr as *const u8, data_len as usize) };

Expand Down Expand Up @@ -85,6 +86,7 @@ pub unsafe fn cvt_abgr(
) -> FfiResult<(Box<[u8]>, proto::VideoBufferInfo)> {
assert_eq!(buffer.r#type(), proto::VideoBufferType::Rgba);
let proto::VideoBufferInfo { stride, width, height, data_ptr, .. } = buffer;
let stride = stride.unwrap_or(width * 4);
let data_len = (stride * height) as usize;
let data = unsafe { slice::from_raw_parts(data_ptr as *const u8, data_len as usize) };

Expand Down Expand Up @@ -131,6 +133,7 @@ pub unsafe fn cvt_argb(
) -> FfiResult<(Box<[u8]>, proto::VideoBufferInfo)> {
assert_eq!(buffer.r#type(), proto::VideoBufferType::Argb);
let proto::VideoBufferInfo { stride, width, height, data_ptr, .. } = buffer;
let stride = stride.unwrap_or(width * 4);
let data_len = (stride * height) as usize;
let data = unsafe { slice::from_raw_parts(data_ptr as *const u8, data_len as usize) };

Expand Down Expand Up @@ -176,6 +179,7 @@ pub unsafe fn cvt_bgra(
) -> FfiResult<(Box<[u8]>, proto::VideoBufferInfo)> {
assert_eq!(buffer.r#type(), proto::VideoBufferType::Bgra);
let proto::VideoBufferInfo { stride, width, height, data_ptr, .. } = buffer;
let stride = stride.unwrap_or(width * 4);
let data_len = (stride * height) as usize;
let data = unsafe { slice::from_raw_parts(data_ptr as *const u8, data_len as usize) };

Expand Down Expand Up @@ -231,6 +235,7 @@ pub unsafe fn cvt_rgb24(
) -> FfiResult<(Box<[u8]>, proto::VideoBufferInfo)> {
assert_eq!(buffer.r#type(), proto::VideoBufferType::Rgb24);
let proto::VideoBufferInfo { stride, width, height, data_ptr, .. } = buffer;
let stride = stride.unwrap_or(width * 3);
let data_len = (stride * height) as usize;
let data = unsafe { slice::from_raw_parts(data_ptr as *const u8, data_len as usize) };

Expand Down
16 changes: 8 additions & 8 deletions livekit-ffi/src/server/colorcvt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub fn i420_info(
r#type: proto::VideoBufferType::I420.into(),
components,
data_ptr: data_ptr as u64,
stride: 0,
stride: None,
}
}

Expand Down Expand Up @@ -378,7 +378,7 @@ pub fn i420a_info(
r#type: proto::VideoBufferType::I420a.into(),
components,
data_ptr: data_ptr as u64,
stride: 0,
stride: None,
}
}

Expand Down Expand Up @@ -419,7 +419,7 @@ pub fn i422_info(
r#type: proto::VideoBufferType::I422.into(),
components,
data_ptr: data_ptr as u64,
stride: 0,
stride: None,
}
}

Expand Down Expand Up @@ -460,7 +460,7 @@ pub fn i444_info(
r#type: proto::VideoBufferType::I444.into(),
components,
data_ptr: data_ptr as u64,
stride: 0,
stride: None,
}
}

Expand Down Expand Up @@ -503,7 +503,7 @@ pub fn i010_info(
r#type: proto::VideoBufferType::I010.into(),
components,
data_ptr: data_ptr as u64,
stride: 0,
stride: None,
}
}

Expand Down Expand Up @@ -538,7 +538,7 @@ pub fn nv12_info(
r#type: proto::VideoBufferType::Nv12.into(),
components,
data_ptr: data_ptr as u64,
stride: 0,
stride: None,
}
}

Expand All @@ -554,7 +554,7 @@ pub fn rgba_info(
r#type: r#type.into(),
components: Vec::default(),
data_ptr: data_ptr as u64,
stride: width * 4,
stride: Some(width * 4),
}
}

Expand All @@ -570,6 +570,6 @@ pub fn rgb_info(
r#type: r#type.into(),
components: Vec::default(),
data_ptr: data_ptr as u64,
stride: width * 3,
stride: Some(width * 3),
}
}
15 changes: 15 additions & 0 deletions livekit-ffi/src/server/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,16 @@ fn on_set_data_channel_buffered_amount_low_threshold(
))
}

fn on_set_track_subscription_permissions(
server: &'static FfiServer,
set_permissions: proto::SetTrackSubscriptionPermissionsRequest,
) -> FfiResult<proto::SetTrackSubscriptionPermissionsResponse> {
let ffi_participant =
server.retrieve_handle::<FfiParticipant>(set_permissions.local_participant_handle)?.clone();

Ok(ffi_participant.room.set_track_subscription_permissions(server, set_permissions))
}

#[allow(clippy::field_reassign_with_default)] // Avoid uggly format
pub fn handle_request(
server: &'static FfiServer,
Expand Down Expand Up @@ -1097,6 +1107,11 @@ pub fn handle_request(
on_set_data_channel_buffered_amount_low_threshold(server, request)?,
)
}
proto::ffi_request::Message::SetTrackSubscriptionPermissions(request) => {
proto::ffi_response::Message::SetTrackSubscriptionPermissions(
on_set_track_subscription_permissions(server, request)?,
)
}
});

Ok(res)
Expand Down
18 changes: 18 additions & 0 deletions livekit-ffi/src/server/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,24 @@ impl RoomInner {
);
proto::SetDataChannelBufferedAmountLowThresholdResponse {}
}

pub fn set_track_subscription_permissions(
self: &Arc<Self>,
server: &'static FfiServer,
request: proto::SetTrackSubscriptionPermissionsRequest,
) -> proto::SetTrackSubscriptionPermissionsResponse {
let inner = self.clone();
let permissions = request.permissions.into_iter().map(|p| p.into()).collect();
let handle = server.async_runtime.spawn(async move {
let _ = inner
.room
.local_participant()
.set_track_subscription_permissions(request.all_participants_allowed, permissions)
.await;
});
server.watch_panic(handle);
proto::SetTrackSubscriptionPermissionsResponse {}
}
}

// Task used to publish data without blocking the client thread
Expand Down
Loading

0 comments on commit 1d85bac

Please sign in to comment.
0