Skip to content

Commit

Permalink
Move UDPEndpoint to core, re-write scheme-specific structure, add new…
Browse files Browse the repository at this point in the history
… configuration options
  • Loading branch information
ypo committed Nov 12, 2023
1 parent 842a3d4 commit 0ea7179
Show file tree
Hide file tree
Showing 50 changed files with 1,090 additions and 276 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ rand = "0.8"

[dev-dependencies]
env_logger = "0.10.0"
tempfile = "3.8.0"

[features]
python = ["pyo3", "pyo3-log"]
Expand Down
20 changes: 20 additions & 0 deletions assets/xsd/FLUTE-FDT-3GPP-2005-Extensions.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns="urn:3GPP:metadata:2005:MBMS:FLUTE:FDT"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:3GPP:metadata:2005:MBMS:FLUTE:FDT"
elementFormDefault="qualified">
<xs:complexType name="MBMS-Session-Identity-Expiry-Type">
<xs:simpleContent>
<xs:extension base="MBMS-Session-Identity-Type">
<xs:attribute name="value" type="xs:unsignedInt" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="MBMS-Session-Identity-Type">
<xs:restriction base="xs:unsignedByte"/>
</xs:simpleType>
<xs:simpleType name="groupIdType">
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:schema>
17 changes: 17 additions & 0 deletions assets/xsd/FLUTE-FDT-3GPP-2007-Extensions.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns="urn:3GPP:metadata:2007:MBMS:FLUTE:FDT"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:3GPP:metadata:2007:MBMS:FLUTE:FDT"
elementFormDefault="qualified">
<xs:element name="Cache-Control">
<xs:complexType>
<xs:choice>
<xs:element name="no-cache" type="xs:boolean" fixed="true"/>
<xs:element name="max-stale" type="xs:boolean" fixed="true"/>
<xs:element name="Expires" type="xs:unsignedInt"/>
</xs:choice>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:schema>
8 changes: 8 additions & 0 deletions assets/xsd/FLUTE-FDT-3GPP-2008-Extensions.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:3GPP:metadata:2008:MBMS:FLUTE:FDT_ext"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:3GPP:metadata:2008:MBMS:FLUTE:FDT_ext"
elementFormDefault="qualified">
<xs:attribute name="FullFDT" type="xs:boolean"
/>
</xs:schema>
7 changes: 7 additions & 0 deletions assets/xsd/FLUTE-FDT-3GPP-2009-Extensions.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:3GPP:metadata:2009:MBMS:FLUTE:FDT_ext"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:3GPP:metadata:2009:MBMS:FLUTE:FDT_ext"
elementFormDefault="qualified">
<xs:attribute name="Decryption-KEY-URI" type="xs:anyURI"/>
</xs:schema>
21 changes: 21 additions & 0 deletions assets/xsd/FLUTE-FDT-3GPP-2012-Extensions.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns="urn:3GPP:metadata:2012:MBMS:FLUTE:FDT"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="urn:3GPP:metadata:2012:MBMS:FLUTE:FDT"
targetNamespace="urn:3GPP:metadata:2012:MBMS:FLUTE:FDT"
elementFormDefault="qualified">
<xs:element name="Alternate-Content-Location-1" type="Alternative-Content-LocationType"/>
<xs:element name="Alternate-Content-Location-2" type="Alternative-Content-LocationType"/>
<xs:complexType name="Alternative-Content-LocationType">
<xs:sequence>
<xs:element name="Alternate-Content-Location" type="xs:anyURI" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Availability-Time" type="xs:dateTime"/>
</xs:complexType>
<xs:element name="Base-URL-1" type="xs:anyURI"/>
<xs:element name="Base-URL-2" type="xs:anyURI"/>
<xs:attribute name="FEC-Redundancy-Level" type="xs:unsignedInt"/>
<xs:attribute name="File-ETag" type="xs:string"/>
</xs:schema>
11 changes: 11 additions & 0 deletions assets/xsd/FLUTE-FDT-3GPP-2015-Extensions.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns="urn:3GPP:metadata:2015:MBMS:FLUTE:FDT"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:3GPP:metadata:2015:MBMS:FLUTE:FDT"
elementFormDefault="qualified">
<xs:attribute name="IndependentUnitPositions" type="IndependentUnitPositionsType"/>
<xs:simpleType name="IndependentUnitPositionsType">
<xs:list itemType="xs:unsignedLong"/>
</xs:simpleType>
</xs:schema>
90 changes: 90 additions & 0 deletions assets/xsd/FLUTE-FDT-3GPP-Main.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns="urn:IETF:metadata:2005:FLUTE:FDT"
xmlns:fl="urn:IETF:metadata:2005:FLUTE:FDT"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mbms2005="urn:3GPP:metadata:2005:MBMS:FLUTE:FDT"
xmlns:mbms2007="urn:3GPP:metadata:2007:MBMS:FLUTE:FDT"
xmlns:mbms2008="urn:3GPP:metadata:2008:MBMS:FLUTE:FDT_ext"
xmlns:mbms2009="urn:3GPP:metadata:2009:MBMS:FLUTE:FDT_ext"
xmlns:mbms2012="urn:3GPP:metadata:2012:MBMS:FLUTE:FDT"
xmlns:mbms2015="urn:3GPP:metadata:2015:MBMS:FLUTE:FDT"
xmlns:sv="urn:3gpp:metadata:2009:MBMS:schemaVersion"
targetNamespace="urn:IETF:metadata:2005:FLUTE:FDT"
elementFormDefault="qualified"
version="3">
<xs:import namespace="urn:3GPP:metadata:2005:MBMS:FLUTE:FDT"
schemaLocation="FLUTE-FDT-3GPP-2005-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2007:MBMS:FLUTE:FDT"
schemaLocation="FLUTE-FDT-3GPP-2007-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2008:MBMS:FLUTE:FDT_ext"
schemaLocation="FLUTE-FDT-3GPP-2008-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2009:MBMS:FLUTE:FDT_ext"
schemaLocation="FLUTE-FDT-3GPP-2009-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2012:MBMS:FLUTE:FDT"
schemaLocation="FLUTE-FDT-3GPP-2012-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2015:MBMS:FLUTE:FDT"
schemaLocation="FLUTE-FDT-3GPP-2015-Extensions.xsd"/>
<xs:import namespace="urn:3gpp:metadata:2009:MBMS:schemaVersion"
schemaLocation="schema-version.xsd"/>
<xs:element name="FDT-Instance" type="FDT-InstanceType"/>
<xs:complexType name="FDT-InstanceType">
<xs:sequence>
<xs:element name="File" type="FileType" maxOccurs="unbounded"/>
<xs:element ref="sv:schemaVersion"/>
<xs:element ref="mbms2012:Base-URL-1" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="mbms2012:Base-URL-2" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="sv:delimiter"/>
<xs:any namespace="##other" processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Group" type="mbms2005:groupIdType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="MBMS-Session-Identity-Expiry" type="mbms2005:MBMS-Session-Identity-Expiry-Type" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Expires" type="xs:string" use="required"/>
<xs:attribute name="Complete" type="xs:boolean" use="optional"/>
<xs:attribute name="Content-Type" type="xs:string" use="optional"/>
<xs:attribute name="Content-Encoding" type="xs:string" use="optional"/>
<xs:attribute name="FEC-OTI-FEC-Encoding-ID" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-FEC-Instance-ID" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Maximum-Source-Block-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Encoding-Symbol-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Max-Number-of-Encoding-Symbols" type="xs:unsignedLong"
use="optional"/>
<xs:attribute name="FEC-OTI-Scheme-Specific-Info" type="xs:base64Binary" use="optional"/>
<xs:attribute ref="mbms2008:FullFDT" use="optional" default="false"/>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
<xs:complexType name="FileType">
<xs:sequence>
<xs:element ref="mbms2007:Cache-Control" minOccurs="0"/>
<xs:element ref="sv:delimiter"/>
<xs:element ref="mbms2012:Alternate-Content-Location-1" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="mbms2012:Alternate-Content-Location-2" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="sv:delimiter"/>
<xs:any namespace="##other" processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Group" type="mbms2005:groupIdType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="MBMS-Session-Identity" type="mbms2005:MBMS-Session-Identity-Type"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Content-Location" type="xs:anyURI" use="required"/>
<xs:attribute name="TOI" type="xs:positiveInteger" use="required"/>
<xs:attribute name="Content-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="Transfer-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="Content-Type" type="xs:string" use="optional"/>
<xs:attribute name="Content-Encoding" type="xs:string" use="optional"/>
<xs:attribute name="Content-MD5" type="xs:base64Binary" use="optional"/>
<xs:attribute name="FEC-OTI-FEC-Encoding-ID" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-FEC-Instance-ID" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Maximum-Source-Block-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Encoding-Symbol-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Max-Number-of-Encoding-Symbols" type="xs:unsignedLong"
use="optional"/>
<xs:attribute name="FEC-OTI-Scheme-Specific-Info" type="xs:base64Binary" use="optional"/>
<xs:attribute ref="mbms2009:Decryption-KEY-URI" use="optional"/>
<xs:attribute ref="mbms2012:FEC-Redundancy-Level" use="optional"/>
<xs:attribute ref="mbms2012:File-ETag" use="optional"/>
<xs:attribute ref="mbms2015:IndependentUnitPositions" use="optional"/>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:schema>
8 changes: 8 additions & 0 deletions assets/xsd/schema-version.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:3gpp:metadata:2009:MBMS:schemaVersion"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:3gpp:metadata:2009:MBMS:schemaVersion"
elementFormDefault="qualified">
<xs:element name="schemaVersion" type="xs:unsignedInt"/>
<xs:element name="delimiter" type="xs:byte"/>
</xs:schema>
5 changes: 4 additions & 1 deletion examples/udpreceiver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use flute::receiver::{writer, MultiReceiver, UDPEndpoint};
use flute::{
core::UDPEndpoint,
receiver::{writer, MultiReceiver},
};
use std::{net::UdpSocket, rc::Rc};

fn main() {
Expand Down
10 changes: 8 additions & 2 deletions examples/udpsender.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use flute::sender::{Cenc, ObjectDesc, Sender};
use flute::{
core::UDPEndpoint,
sender::{Cenc, ObjectDesc, Sender},
};
use std::{net::UdpSocket, time::SystemTime};

fn main() {
std::env::set_var("RUST_LOG", "info");
env_logger::builder().try_init().ok();
let dest = "224.0.0.1:3400";
let endpoint = UDPEndpoint::new(None, "224.0.0.1".to_owned(), 3400);

let args: Vec<String> = std::env::args().collect();
if args.len() == 1 {
Expand All @@ -14,11 +18,12 @@ fn main() {
}

log::info!("Create UDP Socket");

let udp_socket = UdpSocket::bind("0.0.0.0:0").unwrap();

log::info!("Create FLUTE Sender");
let tsi = 1;
let mut sender = Sender::new(tsi, &Default::default(), &Default::default());
let mut sender = Sender::new(endpoint, tsi, &Default::default(), &Default::default());

log::info!("Connect to {}", dest);
udp_socket.connect(dest).expect("Connection failed");
Expand All @@ -39,6 +44,7 @@ fn main() {
1,
None,
None,
None,
Cenc::Null,
true,
None,
Expand Down
13 changes: 13 additions & 0 deletions src/common/alc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ pub fn parse_payload_id(pkt: &AlcPkt, oti: &oti::Oti) -> Result<PayloadID> {
codec.get_fec_payload_id(pkt, oti)
}

/// Get Inline Payload ID
pub fn get_fec_inline_payload_id(pkt: &AlcPkt) -> Result<PayloadID> {
let fec: oti::FECEncodingID = pkt
.lct
.cp
.try_into()
.map_err(|_| FluteError::new(format!("Codepoint {} not supported", pkt.lct.cp)))?;

let codec = <dyn AlcCodec>::instance(fec);
codec.get_fec_inline_payload_id(pkt)
}

fn parse_ext_fdt(ext: &[u8]) -> Result<Option<ExtFDT>> {
if ext.len() != 4 {
return Err(FluteError::new("Wrong size of FDT Extension"));
Expand Down Expand Up @@ -349,6 +361,7 @@ fn parse_sct(ext: &[u8]) -> Result<Option<std::time::SystemTime>> {
1 => u32::from_be_bytes(ext[8..12].as_ref().try_into().unwrap()),
_ => 0,
};

let ntp: u64 = ((ntp_seconds as u64) << 32) | (ntp_faction as u64);
tools::ntp_to_system_time(ntp).map(|op| Some(op))
}
Expand Down
8 changes: 5 additions & 3 deletions src/common/alccodec/alcnocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ impl AlcCodec for AlcNoCode {
maximum_source_block_length,
encoding_symbol_length,
max_number_of_parity_symbols: 0,
reed_solomon_scheme_specific: None,
raptorq_scheme_specific: None,
raptor_scheme_specific: None,
scheme_specific: None,
inband_fti: true,
};

Expand All @@ -77,6 +75,10 @@ impl AlcCodec for AlcNoCode {
pkt: &alc::AlcPkt,
_oti: &oti::Oti,
) -> crate::error::Result<alc::PayloadID> {
self.get_fec_inline_payload_id(pkt)
}

fn get_fec_inline_payload_id(&self, pkt: &alc::AlcPkt) -> crate::error::Result<alc::PayloadID> {
let data = &pkt.data[pkt.data_alc_header_offset..pkt.data_payload_offset];
let arr: [u8; 4] = match data.try_into() {
Ok(arr) => arr,
Expand Down
41 changes: 24 additions & 17 deletions src/common/alccodec/alcraptor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use super::AlcCodec;
use crate::{
common::{alc, lct, oti, pkt},
common::{
alc, lct,
oti::{self, SchemeSpecific},
pkt,
},
error::FluteError,
};

Expand Down Expand Up @@ -31,18 +35,19 @@ impl AlcCodec for AlcRaptor {
let transfer_header: u64 =
(transfer_length << 24) | (oti.encoding_symbol_length as u64 & 0xFFFF);

assert!(oti.raptor_scheme_specific.is_some());
let raptor = oti.raptor_scheme_specific.as_ref().unwrap();

let padding: u16 = 0;

data.extend(ext_header.to_be_bytes());
data.extend(transfer_header.to_be_bytes());
data.extend(raptor.source_blocks_length.to_be_bytes());
data.extend(raptor.sub_blocks_length.to_be_bytes());
data.extend(raptor.symbol_alignment.to_be_bytes());
data.extend(padding.to_be_bytes());
lct::inc_hdr_len(data, len);
assert!(oti.scheme_specific.is_some());
if let SchemeSpecific::Raptor(raptor) = oti.scheme_specific.as_ref().unwrap() {
let padding: u16 = 0;
data.extend(ext_header.to_be_bytes());
data.extend(transfer_header.to_be_bytes());
data.extend(raptor.source_blocks_length.to_be_bytes());
data.extend(raptor.sub_blocks_length.to_be_bytes());
data.extend(raptor.symbol_alignment.to_be_bytes());
data.extend(padding.to_be_bytes());
lct::inc_hdr_len(data, len);
} else {
assert!(false);
}
}

fn get_fti(
Expand Down Expand Up @@ -86,13 +91,11 @@ impl AlcCodec for AlcRaptor {
maximum_source_block_length: maximum_source_block_length as u32,
encoding_symbol_length: symbol_size,
max_number_of_parity_symbols: 0, // Unknown for RaptorQ
reed_solomon_scheme_specific: None,
raptorq_scheme_specific: None,
raptor_scheme_specific: Some(oti::RaptorSchemeSpecific {
scheme_specific: Some(SchemeSpecific::Raptor(oti::RaptorSchemeSpecific {
source_blocks_length: z,
sub_blocks_length: n,
symbol_alignment: al,
}),
})),
inband_fti: true,
};

Expand All @@ -115,6 +118,10 @@ impl AlcCodec for AlcRaptor {
pkt: &alc::AlcPkt,
_oti: &oti::Oti,
) -> crate::error::Result<alc::PayloadID> {
self.get_fec_inline_payload_id(pkt)
}

fn get_fec_inline_payload_id(&self, pkt: &alc::AlcPkt) -> crate::error::Result<alc::PayloadID> {
let data = &pkt.data[pkt.data_alc_header_offset..pkt.data_payload_offset];
let arr: [u8; 4] = match data.try_into() {
Ok(arr) => arr,
Expand Down
Loading

0 comments on commit 0ea7179

Please sign in to comment.