fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
7cbdddf
main
1// Copyright 2023 LiveKit, Inc. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15syntax = "proto2" ; 16 17package livekit . proto ; 18option csharp_namespace= "LiveKit.Proto" ; 19 20// import "handle.proto"; 21import "e2ee.proto" ; 22import "track.proto" ; 23import "track_publication.proto" ; 24import "room.proto" ; 25import "video_frame.proto" ; 26import "audio_frame.proto" ; 27import "rpc.proto" ; 28 29// **How is the livekit-ffi working: 30// We refer as the ffi server the Rust server that is running the LiveKit client implementation, and we 31// refer as the ffi client the foreign language that commumicates with the ffi server. (e.g Python SDK, Unity SDK, etc...) 32// 33// We expose the Rust client implementation of livekit using the protocol defined here. 34// Everything starts with a FfiRequest, which is a oneof message that contains all the possible 35// requests that can be made to the ffi server. 36// The server will then respond with a FfiResponse, which is also a oneof message that contains 37// all the possible responses. 38// The first request sent to the server must be an InitializeRequest, which contains the a pointer 39// to the callback function that will be used to send events and async responses to the ffi client. 40// (e.g participant joined, track published, etc...) 41// 42// **Useful things know when collaborating on the protocol:** 43// Everything is subject to discussion and change :-) 44// 45// - The ffi client implementation must never forget to correctly dispose all the owned handles 46// that it receives from the server. 47// 48// Therefore, the ffi client is easier to implement if there is less handles to manage. 49// 50// - We are mainly using FfiHandle on info messages (e.g: RoomInfo, TrackInfo, etc...) 51// For this reason, info are only sent once, at creation (We're not using them for updates, we can infer them from 52// events on the client implementation). 53// e.g: set speaking to true when we receive a ActiveSpeakerChanged event. 54 55// This is the input of livekit_ffi_request function 56// We always expect a response (FFIResponse, even if it's empty) 57message FfiRequest { 58oneof message { 59DisposeRequest dispose = 2 ; 60 61// Room 62ConnectRequest connect = 3 ; 63DisconnectRequest disconnect = 4 ; 64PublishTrackRequest publish_track = 5 ; 65UnpublishTrackRequest unpublish_track = 6 ; 66PublishDataRequest publish_data = 7 ; 67SetSubscribedRequest set_subscribed = 8 ; 68SetLocalMetadataRequest set_local_metadata = 9 ; 69SetLocalNameRequest set_local_name = 10 ; 70SetLocalAttributesRequest set_local_attributes = 11 ; 71GetSessionStatsRequest get_session_stats = 12 ; 72PublishTranscriptionRequest publish_transcription = 13 ; 73PublishSipDtmfRequest publish_sip_dtmf = 14 ; 74 75// Track 76CreateVideoTrackRequest create_video_track = 15 ; 77CreateAudioTrackRequest create_audio_track = 16 ; 78LocalTrackMuteRequest local_track_mute = 17 ; 79EnableRemoteTrackRequest enable_remote_track = 18 ; 80GetStatsRequest get_stats = 19 ; 81SetTrackSubscriptionPermissionsRequest set_track_subscription_permissions = 48 ; 82 83// Video 84NewVideoStreamRequest new_video_stream = 20 ; 85NewVideoSourceRequest new_video_source = 21 ; 86CaptureVideoFrameRequest capture_video_frame = 22 ; 87VideoConvertRequest video_convert = 23 ; 88VideoStreamFromParticipantRequest video_stream_from_participant = 24 ; 89 90// Audio 91NewAudioStreamRequest new_audio_stream = 25 ; 92NewAudioSourceRequest new_audio_source = 26 ; 93CaptureAudioFrameRequest capture_audio_frame = 27 ; 94ClearAudioBufferRequest clear_audio_buffer = 28 ; 95NewAudioResamplerRequest new_audio_resampler = 29 ; 96RemixAndResampleRequest remix_and_resample = 30 ; 97E2eeRequest e2ee = 31 ; 98AudioStreamFromParticipantRequest audio_stream_from_participant = 32 ; 99NewSoxResamplerRequest new_sox_resampler = 33 ; 100PushSoxResamplerRequest push_sox_resampler = 34 ; 101FlushSoxResamplerRequest flush_sox_resampler = 35 ; 102SendChatMessageRequest send_chat_message = 36 ; 103EditChatMessageRequest edit_chat_message = 37 ; 104 105// RPC 106PerformRpcRequest perform_rpc = 38 ; 107RegisterRpcMethodRequest register_rpc_method = 39 ; 108UnregisterRpcMethodRequest unregister_rpc_method = 40 ; 109RpcMethodInvocationResponseRequest rpc_method_invocation_response = 41 ; 110 111// Track Publication 112EnableRemoteTrackPublicationRequest enable_remote_track_publication = 42 ; 113UpdateRemoteTrackPublicationDimensionRequest update_remote_track_publication_dimension = 43 ; 114 115// Data Streams 116SendStreamHeaderRequest send_stream_header = 44 ; 117SendStreamChunkRequest send_stream_chunk = 45 ; 118SendStreamTrailerRequest send_stream_trailer = 46 ; 119 120// Data Channel 121SetDataChannelBufferedAmountLowThresholdRequest set_data_channel_buffered_amount_low_threshold = 47 ; 122 123// Audio Filter Plugin 124LoadAudioFilterPluginRequest load_audio_filter_plugin = 49 ; 125 126NewApmRequest new_apm = 50 ; 127ApmProcessStreamRequest apm_process_stream = 51 ; 128ApmProcessReverseStreamRequest apm_process_reverse_stream = 52 ; 129ApmSetStreamDelayRequest apm_set_stream_delay = 53 ; 130 131// NEXT_ID: 54 132} 133} 134 135// This is the output of livekit_ffi_request function. 136message FfiResponse { 137oneof message { 138DisposeResponse dispose = 2 ; 139 140// Room 141ConnectResponse connect = 3 ; 142DisconnectResponse disconnect = 4 ; 143PublishTrackResponse publish_track = 5 ; 144UnpublishTrackResponse unpublish_track = 6 ; 145PublishDataResponse publish_data = 7 ; 146SetSubscribedResponse set_subscribed = 8 ; 147SetLocalMetadataResponse set_local_metadata = 9 ; 148SetLocalNameResponse set_local_name = 10 ; 149SetLocalAttributesResponse set_local_attributes = 11 ; 150GetSessionStatsResponse get_session_stats = 12 ; 151PublishTranscriptionResponse publish_transcription = 13 ; 152PublishSipDtmfResponse publish_sip_dtmf = 14 ; 153 154// Track 155CreateVideoTrackResponse create_video_track = 15 ; 156CreateAudioTrackResponse create_audio_track = 16 ; 157LocalTrackMuteResponse local_track_mute = 17 ; 158EnableRemoteTrackResponse enable_remote_track = 18 ; 159GetStatsResponse get_stats = 19 ; 160SetTrackSubscriptionPermissionsResponse set_track_subscription_permissions = 47 ; 161 162// Video 163NewVideoStreamResponse new_video_stream = 20 ; 164NewVideoSourceResponse new_video_source = 21 ; 165CaptureVideoFrameResponse capture_video_frame = 22 ; 166VideoConvertResponse video_convert = 23 ; 167VideoStreamFromParticipantResponse video_stream_from_participant = 24 ; 168 169// Audio 170NewAudioStreamResponse new_audio_stream = 25 ; 171NewAudioSourceResponse new_audio_source = 26 ; 172CaptureAudioFrameResponse capture_audio_frame = 27 ; 173ClearAudioBufferResponse clear_audio_buffer = 28 ; 174NewAudioResamplerResponse new_audio_resampler = 29 ; 175RemixAndResampleResponse remix_and_resample = 30 ; 176AudioStreamFromParticipantResponse audio_stream_from_participant = 31 ; 177E2eeResponse e2ee = 32 ; 178NewSoxResamplerResponse new_sox_resampler = 33 ; 179PushSoxResamplerResponse push_sox_resampler = 34 ; 180FlushSoxResamplerResponse flush_sox_resampler = 35 ; 181SendChatMessageResponse send_chat_message = 36 ; 182// RPC 183PerformRpcResponse perform_rpc = 37 ; 184RegisterRpcMethodResponse register_rpc_method = 38 ; 185UnregisterRpcMethodResponse unregister_rpc_method = 39 ; 186RpcMethodInvocationResponseResponse rpc_method_invocation_response = 40 ; 187// Track Publication 188EnableRemoteTrackPublicationResponse enable_remote_track_publication = 41 ; 189UpdateRemoteTrackPublicationDimensionResponse update_remote_track_publication_dimension = 42 ; 190 191// Data Streams 192SendStreamHeaderResponse send_stream_header = 43 ; 193SendStreamChunkResponse send_stream_chunk = 44 ; 194SendStreamTrailerResponse send_stream_trailer = 45 ; 195 196// Data Channel 197SetDataChannelBufferedAmountLowThresholdResponse set_data_channel_buffered_amount_low_threshold = 46 ; 198 199// Audio Filter Plugin 200LoadAudioFilterPluginResponse load_audio_filter_plugin = 48 ; 201 202NewApmResponse new_apm = 49 ; 203ApmProcessStreamResponse apm_process_stream = 50 ; 204ApmProcessReverseStreamResponse apm_process_reverse_stream = 51 ; 205ApmSetStreamDelayResponse apm_set_stream_delay = 52 ; 206 207// NEXT_ID: 53 208} 209} 210 211// To minimize complexity, participant events are not included in the protocol. 212// It is easily deducible from the room events and it turned out that is is easier to implement 213// on the ffi client side. 214message FfiEvent { 215oneof message { 216RoomEvent room_event = 1 ; 217TrackEvent track_event = 2 ; 218VideoStreamEvent video_stream_event = 3 ; 219AudioStreamEvent audio_stream_event = 4 ; 220ConnectCallback connect = 5 ; 221DisconnectCallback disconnect = 7 ; 222DisposeCallback dispose = 8 ; 223PublishTrackCallback publish_track = 9 ; 224UnpublishTrackCallback unpublish_track = 10 ; 225PublishDataCallback publish_data = 11 ; 226PublishTranscriptionCallback publish_transcription = 12 ; 227CaptureAudioFrameCallback capture_audio_frame = 13 ; 228SetLocalMetadataCallback set_local_metadata = 14 ; 229SetLocalNameCallback set_local_name = 15 ; 230SetLocalAttributesCallback set_local_attributes = 16 ; 231GetStatsCallback get_stats = 17 ; 232LogBatch logs = 18 ; 233GetSessionStatsCallback get_session_stats = 19 ; 234Panic panic = 20 ; 235PublishSipDtmfCallback publish_sip_dtmf = 21 ; 236SendChatMessageCallback chat_message = 22 ; 237PerformRpcCallback perform_rpc = 23 ; 238RpcMethodInvocationEvent rpc_method_invocation = 24 ; 239SendStreamHeaderCallback send_stream_header = 25 ; 240SendStreamChunkCallback send_stream_chunk = 26 ; 241SendStreamTrailerCallback send_stream_trailer = 27 ; 242} 243} 244 245// Stop all rooms synchronously (Do we need async here?). 246// e.g: This is used for the Unity Editor after each assemblies reload. 247// TODO(theomonnom): Implement a debug mode where we can find all leaked handles? 248message DisposeRequest { 249required bool async = 1 ; 250} 251message DisposeResponse { 252optional uint64 async_id = 1 ; // None if sync 253} 254 255message DisposeCallback { 256required uint64 async_id = 1 ; 257} 258 259enum LogLevel { 260LOG_ERROR = 0 ; 261LOG_WARN = 1 ; 262LOG_INFO = 2 ; 263LOG_DEBUG = 3 ; 264LOG_TRACE = 4 ; 265} 266 267message LogRecord { 268required LogLevel level = 1 ; 269required string target = 2 ; // e.g "livekit", "libwebrtc", "tokio-tungstenite", etc... 270optional string module_path = 3 ; 271optional string file = 4 ; 272optional uint32 line = 5 ; 273required string message = 6 ; 274} 275 276message LogBatch { 277repeated LogRecord records = 1 ; 278} 279 280message Panic { 281required string message = 1 ; 282} 283 284// TODO(theomonnom): Debug messages (Print handles). 285 286 287