]>
code.octet-stream.net Git - m17rt/blob - m17core/src/reflector/convert.rs
1 //! Utilities for converting streams between UDP and RF representations
3 use crate::protocol
::{LsfFrame
, StreamFrame
};
5 use super::packet
::Voice
;
7 /// Accepts `Voice` packets from a reflector and turns them into LSF and Stream frames.
9 /// This is the format required for the voice data to cross the KISS protocol boundary.
10 pub struct VoiceToRf
{
11 /// Link Setup most recently acquired
12 lsf
: Option
<LsfFrame
>,
13 /// Which LICH part we are going to emit next, 0-5
18 pub fn new() -> Self {
25 /// For a Voice packet received from a reflector, return the frames that would be transmitted
26 /// on RF, including by reconstructing the LICH parts of the stream frame.
28 /// If this is the start of a new or different stream transmission, this returns the Link Setup
29 /// Frame which comes first, then the first associated Stream frame.
31 /// If this is a continuation of a transmission matching the previous LSF, then it returns only
33 pub fn next(&mut self, voice
: &Voice
) -> (Option
<LsfFrame
>, StreamFrame
) {
34 let this_lsf
= voice
.link_setup_frame();
35 let emit_lsf
= if Some(&this_lsf
) != self.lsf
.as_ref() {
36 self.lsf
= Some(this_lsf
.clone());
42 let lsf
= self.lsf
.as_ref().unwrap
();
43 let stream
= StreamFrame
{
44 lich_idx
: self.lich_cnt
as u8,
45 lich_part
: (&lsf
.0[self.lich_cnt
* 5..(self.lich_cnt
+ 1) * 5])
48 frame_number
: voice
.frame
_n
umber
(),
49 end_of_stream
: voice
.is
_end
_o
f_stream
(),
50 stream_data
: voice
.payload().try_into().unwrap
(),
52 let lsf
= if emit_lsf
{ self.lsf
.clone() } else { None
};
53 if voice
.is
_end
_o
f_stream
() {