scte35_reader/upid.rs
1//! _Unique Program Identifier_ types from a range of different identification schemes supported in
2//! _SCTE-35_ `segmentation_descriptor()` messages.
3//!
4//! Instances of these types will be obtainable from the variants of the [`SegmentationUpid`](../enum.SegmentationUpid.html) enum found in the
5//! [`SegmentationDescriptor::Insert.segmentation_upid`](../enum.SegmentationDescriptor.html#variant.Insert.field.segmentation_upid)
6//! field.
7//!
8//!
9//! The standard defines the following types of UPID, where Type and Length columns give values for `segmentation_upid_type` and `segmentation_upid_length` fields,
10//!
11//! | Type | Length (bytes) | Name | Description |
12//! |------|----------------|------|-------------|
13//! | `0x00` | `0` | _Not Used_ | The `segmentation_upid` is not defined and is not present in the descriptor. |
14//! | `0x01` | _variable_ | _User defined_ | Deprecated: use type `0x0C`; The `segmentation_upid` does not follow a standard naming scheme. |
15//! | `0x02` | `8` | ISCI | Deprecated: use type `0x03`, 8 characters; 4 alpha characters followed by 4 numbers. <br><br> e.g `ABCD1234` |
16//! | `0x03` | `12` | Ad-ID | Defined by the Advertising Digital Identification, LLC group. 12 characters; 4 alpha characters (company identification prefix) followed by 8 alphanumeric characters. (See [Ad-ID](http://www.ad-id.org/)) <br><br> e.g. `ABCD0001000H` |
17//! | `0x04` | `32` | UMID | See [SMPTE 330](https://en.wikipedia.org/wiki/Unique_Material_Identifier) <br><br> e.g. `060A2B34.01010105.01010D20.13000000.D2C9036C.8F195343.AB7014D2.D718BFDA` |
18//! | `0x05` | `8` | ISAN | Deprecated: use type `0x06`, ISO 15706 binary encoding. |
19//! | `0x06` | `12` | ISAN | Formerly known as V-ISAN. ISO 15706-2 binary encoding (“versioned” ISAN). See [ISO15706-2](https://en.wikipedia.org/wiki/ISO_15706-2). <br><br> e.g. `0000-0001-2C52-0000-P-0000-0000-0` |
20//! | `0x07` | `12` | TID | Tribune Media Systems Program identifier. 12 characters; 2 alpha characters followed by 10 numbers. <br><br> e.g. `MV0004146400` |
21//! | `0x08` | `8` | TI | AiringID (Formerly Turner ID), used to indicate a specific airing of a program that is unique within a network. <br><br> e.g. `0x0A42235B81BC70FC` |
22//! | `0x09` | _variable_ | ADI | CableLabs metadata identifier <br><br> e.g. `provider.com/MOVE1234567890123456` |
23//! | `0x0A` | `12` | EIDR | An EIDR (see [EIDR](http://eidr.org/documents/EIDR_ID_Format_v1.3.pdfx)) represented in Compact Binary encoding <br><br> e.g. Content: `10.5240/0E4F-892E-442F-6BD4-15B0-1` Video Service: `10.5239/C370-DCA5` |
24//! | `0x0B` | _variable_ | ATSC Content Identifier | `ATSC_content_identifier()` structure as defined in [ATSC A/57B](https://www.atsc.org/atsc-documents/a57b-content-identification-and-labeling-for-atsc-transport-revision-b/). |
25//! | `0x0C` | _variable_ | `MPU()` | Managed Private UPID structure |
26//! | `0x0D` | _variable_ | `MID()` | Multiple UPID types structure |
27//! | `0x0E` | _variable_ | ADS Information | Advertising information. The specific usage is out of scope of this standard. |
28//! | `0x0F` | _variable_ | URI | Universal Resource Identifier (see [RFC 3986](https://tools.ietf.org/html/rfc3986)). <br><br> e.g. `urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6` |
29//! | `0x10` - `0xFF` | _variable_ | _Reserved_ | Reserved for future standardization. |
30
31use hex_slice::AsHex;
32use serde::Serializer;
33use std::fmt;
34
35fn hex_tuple(name: &str, f: &mut fmt::Formatter<'_>, val: &[u8]) -> fmt::Result {
36 write!(f, "{}({:02x})", name, val.plain_hex(false))
37}
38
39/// Represents the UPID with type `0x01`, which the SCTE-35 standard says is deprecated.
40#[derive(serde_derive::Serialize)]
41pub struct UserDefinedDeprecated(pub Vec<u8>);
42impl fmt::Debug for UserDefinedDeprecated {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 hex_tuple("UserDefinedDeprecated", f, &self.0)
45 }
46}
47
48/// _Industry Standard Commercial Identifier_
49#[derive(Debug, serde_derive::Serialize)]
50pub struct IsciDeprecated(pub String);
51
52/// Defined by the _Advertising Digital Identification_ group
53#[derive(Debug, serde_derive::Serialize)]
54pub struct AdID(pub String);
55
56/// Represents the UPID with type `0x05`, which the SCTE-35 standard says is deprecated.
57#[derive(serde_derive::Serialize)]
58pub struct IsanDeprecated(pub Vec<u8>);
59impl fmt::Debug for IsanDeprecated {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 hex_tuple("IsanDeprecated", f, &self.0)
62 }
63}
64
65/// SMPTE ST 330:2011 Unique Material Identifier
66#[derive(serde_derive::Serialize)]
67pub struct Umid(pub Vec<u8>);
68impl fmt::Debug for Umid {
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 f.write_str("Umid(")?;
71 for (i, c) in self.0.chunks(4).enumerate() {
72 if i > 0 {
73 f.write_str(".")?;
74 }
75 write!(f, "{:02x}", c.plain_hex(false))?;
76 }
77 f.write_str(")")
78 }
79}
80
81/// Tribune Media Systems Program identifier
82#[derive(Debug, serde_derive::Serialize)]
83pub struct TID(pub String);
84
85/// AiringID
86///
87/// (Formerly Turner ID)
88#[derive(PartialEq, serde_derive::Serialize)]
89pub struct TI(pub Vec<u8>);
90impl fmt::Debug for TI {
91 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92 hex_tuple("TI", f, &self.0)
93 }
94}
95
96/// Cablelabs metadata identifier
97#[derive(Debug, serde_derive::Serialize)]
98pub struct ADI(pub String);
99
100/// An _Entertainment ID Registry Association_ identifier (compact binary representation)
101#[derive(serde_derive::Serialize)]
102pub struct EIDR(pub [u8; 12]);
103impl fmt::Debug for EIDR {
104 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105 hex_tuple("EIDR", f, &self.0)
106 }
107}
108
109/// `ATSC_content_identifier()` structure
110#[derive(serde_derive::Serialize)]
111pub struct ATSC(pub Vec<u8>);
112impl fmt::Debug for ATSC {
113 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114 hex_tuple("ATSC", f, &self.0)
115 }
116}
117
118/// _Managed Private UPID_ structure
119#[derive(serde_derive::Serialize)]
120pub struct MPU(pub Vec<u8>);
121impl fmt::Debug for MPU {
122 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123 hex_tuple("MPU", f, &self.0)
124 }
125}
126
127/// _Advertising Information_ (SCTE-35 does not specify the format)
128#[derive(Debug, serde_derive::Serialize)]
129pub struct ADSInformation(pub Vec<u8>);
130
131/// Just a wrapper around `url::Url` that adds serde serialisation
132#[derive(Debug)]
133pub struct Url(pub url::Url);
134impl serde::Serialize for Url {
135 fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
136 where
137 S: Serializer,
138 {
139 serializer.serialize_str(self.0.as_str())
140 }
141}
142
143#[cfg(test)]
144mod test {
145 use super::*;
146 use hex_literal::*;
147
148 #[test]
149 fn umid_fmt() {
150 assert_eq!(
151 "Umid(00000000.11111111.22222222.33333333.44444444.55555555.66666666.77889900)",
152 format!(
153 "{:?}",
154 Umid(
155 hex!("0000000011111111222222223333333344444444555555556666666677889900")
156 .to_vec()
157 )
158 )
159 )
160 }
161}