Skip to content

Commit 5047dae

Browse files
authored
DataStream sending support and recv fixes (#533)
* sending support and recv fixes * fix duplicated function * fixes * fix compilation errors * add error callback * fix forwarding issues * fix optional params * fix conversion * fix optional fields * required/optional changes * remove totalchunks * fix none
1 parent c6132e8 commit 5047dae

File tree

10 files changed

+366
-65
lines changed

10 files changed

+366
-65
lines changed

livekit-ffi/protocol/ffi.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ message FfiRequest {
111111
// Track Publication
112112
EnableRemoteTrackPublicationRequest enable_remote_track_publication = 42;
113113
UpdateRemoteTrackPublicationDimensionRequest update_remote_track_publication_dimension = 43;
114+
115+
// Data Streams
116+
SendStreamHeaderRequest send_stream_header = 44;
117+
SendStreamChunkRequest send_stream_chunk = 45;
118+
114119
}
115120
}
116121

@@ -168,6 +173,10 @@ message FfiResponse {
168173
// Track Publication
169174
EnableRemoteTrackPublicationResponse enable_remote_track_publication = 41;
170175
UpdateRemoteTrackPublicationDimensionResponse update_remote_track_publication_dimension = 42;
176+
177+
// Data Streams
178+
SendStreamHeaderResponse send_stream_header = 43;
179+
SendStreamChunkResponse send_stream_chunk = 44;
171180
}
172181
}
173182

@@ -199,6 +208,8 @@ message FfiEvent {
199208
SendChatMessageCallback chat_message = 22;
200209
PerformRpcCallback perform_rpc = 23;
201210
RpcMethodInvocationEvent rpc_method_invocation = 24;
211+
SendStreamHeaderCallback send_stream_header = 25;
212+
SendStreamChunkCallback send_stream_chunk = 26;
202213
}
203214
}
204215

livekit-ffi/protocol/room.proto

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ message RoomEvent {
367367
DataPacketReceived data_packet_received = 27;
368368
TranscriptionReceived transcription_received = 28;
369369
ChatMessageReceived chat_message = 29;
370-
DataStream.Header stream_header = 30;
371-
DataStream.Chunk stream_chunk = 31;
370+
DataStreamHeaderReceived stream_header_received = 30;
371+
DataStreamChunkReceived stream_chunk_received = 31;
372372
}
373373
}
374374

@@ -541,10 +541,10 @@ message DataStream {
541541
// header properties specific to text streams
542542
message TextHeader {
543543
required OperationType operation_type = 1;
544-
required int32 version = 2; // Optional: Version for updates/edits
545-
required string reply_to_stream_id = 3; // Optional: Reply to specific message
544+
optional int32 version = 2; // Optional: Version for updates/edits
545+
optional string reply_to_stream_id = 3; // Optional: Reply to specific message
546546
repeated string attached_stream_ids = 4; // file attachments for text streams
547-
required bool generated = 5; // true if the text has been generated by an agent from a participant's audio transcription
547+
optional bool generated = 5; // true if the text has been generated by an agent from a participant's audio transcription
548548

549549
}
550550

@@ -557,26 +557,66 @@ message DataStream {
557557
message Header {
558558
required string stream_id = 1; // unique identifier for this data stream
559559
required int64 timestamp = 2; // using int64 for Unix timestamp
560-
required string topic = 3;
561-
required string mime_type = 4;
560+
required string mime_type = 3;
561+
required string topic = 4;
562562
optional uint64 total_length = 5; // only populated for finite streams, if it's a stream of unknown size this stays empty
563-
optional uint64 total_chunks = 6; // only populated for finite streams, if it's a stream of unknown size this stays empty
564-
map<string, string> extensions = 7; // user defined extensions map that can carry additional info
563+
map<string, string> extensions = 6; // user defined extensions map that can carry additional info
565564

566565
// oneof to choose between specific header types
567566
oneof content_header {
568-
TextHeader text_header = 8;
569-
FileHeader file_header = 9;
567+
TextHeader text_header = 7;
568+
FileHeader file_header = 8;
570569
}
571570
}
572571

573572
message Chunk {
574573
required string stream_id = 1; // unique identifier for this data stream to map it to the correct header
575574
required uint64 chunk_index = 2;
576575
required bytes content = 3; // content as binary (bytes)
577-
required bool complete = 4; // true only if this is the last chunk of this stream - can also be sent with empty content
578-
required int32 version = 5; // a version indicating that this chunk_index has been retroactively modified and the original one needs to be replaced
576+
optional bool complete = 4; // true only if this is the last chunk of this stream - can also be sent with empty content
577+
optional int32 version = 5; // a version indicating that this chunk_index has been retroactively modified and the original one needs to be replaced
579578
optional bytes iv = 6; // optional, initialization vector for AES-GCM encryption
580579
}
581580
}
582581

582+
message DataStreamHeaderReceived {
583+
required string participant_identity = 1;
584+
required DataStream.Header header = 2;
585+
}
586+
587+
message DataStreamChunkReceived {
588+
required string participant_identity = 1;
589+
required DataStream.Chunk chunk = 2;
590+
}
591+
592+
message SendStreamHeaderRequest {
593+
required uint64 local_participant_handle = 1;
594+
required DataStream.Header header = 2;
595+
repeated string destination_identities = 3;
596+
optional string sender_identity = 4;
597+
}
598+
599+
message SendStreamChunkRequest {
600+
required uint64 local_participant_handle = 1;
601+
required DataStream.Chunk chunk = 2;
602+
repeated string destination_identities = 3;
603+
optional string sender_identity = 4;
604+
}
605+
606+
message SendStreamHeaderResponse {
607+
required uint64 async_id = 1;
608+
}
609+
610+
message SendStreamChunkResponse {
611+
required uint64 async_id = 1;
612+
}
613+
614+
message SendStreamHeaderCallback {
615+
required uint64 async_id = 1;
616+
optional string error = 2;
617+
}
618+
619+
message SendStreamChunkCallback {
620+
required uint64 async_id = 1;
621+
optional string error = 2;
622+
}

livekit-ffi/src/conversion/room.rs

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ impl From<livekit_protocol::data_stream::Header> for proto::data_stream::Header
289289
Some(proto::data_stream::header::ContentHeader::TextHeader(
290290
proto::data_stream::TextHeader {
291291
operation_type: text_header.operation_type,
292-
version: text_header.version,
293-
reply_to_stream_id: text_header.reply_to_stream_id,
292+
version: Some(text_header.version),
293+
reply_to_stream_id: Some(text_header.reply_to_stream_id),
294294
attached_stream_ids: text_header.attached_stream_ids,
295-
generated: text_header.generated,
295+
generated: Some(text_header.generated),
296296
},
297297
))
298298
}
@@ -309,22 +309,70 @@ impl From<livekit_protocol::data_stream::Header> for proto::data_stream::Header
309309
timestamp: msg.timestamp,
310310
topic: msg.topic,
311311
mime_type: msg.mime_type,
312-
total_chunks: msg.total_chunks,
313312
total_length: msg.total_length,
314313
extensions: msg.extensions,
315314
content_header,
316315
}
317316
}
318317
}
319318

319+
impl From<proto::data_stream::Header> for livekit_protocol::data_stream::Header {
320+
fn from(msg: proto::data_stream::Header) -> Self {
321+
let content_header = match msg.content_header {
322+
Some(proto::data_stream::header::ContentHeader::TextHeader(text_header)) => {
323+
Some(livekit_protocol::data_stream::header::ContentHeader::TextHeader(
324+
livekit_protocol::data_stream::TextHeader {
325+
operation_type: text_header.operation_type,
326+
version: text_header.version.unwrap_or_default(),
327+
reply_to_stream_id: text_header.reply_to_stream_id.unwrap_or_default(),
328+
attached_stream_ids: text_header.attached_stream_ids,
329+
generated: text_header.generated.unwrap_or(false),
330+
},
331+
))
332+
}
333+
Some(proto::data_stream::header::ContentHeader::FileHeader(file_header)) => {
334+
Some(livekit_protocol::data_stream::header::ContentHeader::FileHeader(
335+
livekit_protocol::data_stream::FileHeader { file_name: file_header.file_name },
336+
))
337+
}
338+
None => None,
339+
};
340+
341+
livekit_protocol::data_stream::Header {
342+
stream_id: msg.stream_id,
343+
timestamp: msg.timestamp,
344+
topic: msg.topic,
345+
mime_type: msg.mime_type,
346+
total_length: msg.total_length,
347+
total_chunks: None,
348+
extensions: msg.extensions,
349+
content_header,
350+
encryption_type: 0,
351+
}
352+
}
353+
}
354+
320355
impl From<livekit_protocol::data_stream::Chunk> for proto::data_stream::Chunk {
321356
fn from(msg: livekit_protocol::data_stream::Chunk) -> Self {
322357
proto::data_stream::Chunk {
323358
stream_id: msg.stream_id,
324359
content: msg.content,
325-
complete: msg.complete,
360+
complete: Some(msg.complete),
361+
chunk_index: msg.chunk_index,
362+
version: Some(msg.version),
363+
iv: msg.iv,
364+
}
365+
}
366+
}
367+
368+
impl From<proto::data_stream::Chunk> for livekit_protocol::data_stream::Chunk {
369+
fn from(msg: proto::data_stream::Chunk) -> Self {
370+
livekit_protocol::data_stream::Chunk {
371+
stream_id: msg.stream_id,
372+
content: msg.content,
373+
complete: msg.complete.unwrap_or(false),
326374
chunk_index: msg.chunk_index,
327-
version: msg.version,
375+
version: msg.version.unwrap_or(0),
328376
iv: msg.iv,
329377
}
330378
}

0 commit comments

Comments
 (0)