isobmff/boxes/
protected_streams.rs1use std::io;
2
3use scuffle_bytes_util::zero_copy::{Deserialize, DeserializeSeed, Serialize};
4
5use super::StereoVideoBox;
6use crate::{BoxHeader, FullBoxHeader, IsoBox, UnknownBox, Utf8String};
7
8#[derive(IsoBox, Debug, PartialEq, Eq)]
12#[iso_box(box_type = b"sinf", crate_path = crate)]
13pub struct ProtectionSchemeInfoBox<'a> {
14 #[iso_box(nested_box)]
16 pub orginal_format: OriginalFormatBox,
17 #[iso_box(nested_box(collect))]
19 pub scheme_type: Option<SchemeTypeBox>,
20 #[iso_box(nested_box(collect))]
22 pub info: Option<SchemeInformationBox<'a>>,
23}
24
25#[derive(IsoBox, Debug, PartialEq, Eq)]
29#[iso_box(box_type = b"frma", crate_path = crate)]
30pub struct OriginalFormatBox {
31 pub data_format: [u8; 4],
34}
35
36#[derive(IsoBox, Debug, PartialEq, Eq)]
40#[iso_box(box_type = b"schm", skip_impl(deserialize_seed, serialize), crate_path = crate)]
41pub struct SchemeTypeBox {
42 pub full_header: FullBoxHeader,
44 pub scheme_type: [u8; 4],
46 pub scheme_version: u32,
48 pub scheme_uri: Option<Utf8String>,
51}
52
53impl<'a> DeserializeSeed<'a, BoxHeader> for SchemeTypeBox {
54 fn deserialize_seed<R>(mut reader: R, _seed: BoxHeader) -> std::io::Result<Self>
55 where
56 R: scuffle_bytes_util::zero_copy::ZeroCopyReader<'a>,
57 {
58 let full_header = FullBoxHeader::deserialize(&mut reader)?;
59
60 let scheme_type = <[u8; 4]>::deserialize(&mut reader)?;
61 let scheme_version = u32::deserialize(&mut reader)?;
62 let scheme_uri = if (*full_header.flags & 0x000001) != 0 {
63 Some(Utf8String::deserialize(&mut reader)?)
64 } else {
65 None
66 };
67
68 Ok(Self {
69 full_header,
70 scheme_type,
71 scheme_version,
72 scheme_uri,
73 })
74 }
75}
76
77impl Serialize for SchemeTypeBox {
78 fn serialize<W>(&self, mut writer: W) -> io::Result<()>
79 where
80 W: std::io::Write,
81 {
82 self.serialize_box_header(&mut writer)?;
83 self.full_header.serialize(&mut writer)?;
84
85 self.scheme_type.serialize(&mut writer)?;
86 self.scheme_version.serialize(&mut writer)?;
87
88 if (*self.full_header.flags & 0x000001) != 0 {
89 self.scheme_uri
90 .as_ref()
91 .ok_or(io::Error::new(io::ErrorKind::InvalidData, "scheme_uri is required"))?
92 .serialize(&mut writer)?;
93 }
94
95 Ok(())
96 }
97}
98
99#[derive(IsoBox, Debug, PartialEq, Eq)]
103#[iso_box(box_type = b"schi", crate_path = crate)]
104pub struct SchemeInformationBox<'a> {
105 #[iso_box(nested_box(collect))]
107 pub stvi: Option<StereoVideoBox<'a>>,
108 #[iso_box(nested_box(collect_unknown))]
110 pub boxes: Vec<UnknownBox<'a>>,
111}
112
113#[derive(IsoBox, Debug, PartialEq, Eq)]
117#[iso_box(box_type = b"scrb", crate_path = crate)]
118pub struct ScrambleSchemeInfoBox<'a> {
119 #[iso_box(nested_box)]
121 pub scheme_type_box: SchemeTypeBox,
122 #[iso_box(nested_box(collect))]
124 pub info: Option<SchemeInformationBox<'a>>,
125}