re_types/components/
video_codec.rs1#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
15#![allow(non_camel_case_types)]
16
17use ::re_types_core::try_serialize_field;
18use ::re_types_core::SerializationResult;
19use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
20use ::re_types_core::{ComponentDescriptor, ComponentType};
21use ::re_types_core::{DeserializationError, DeserializationResult};
22
23#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
30#[repr(u32)]
31pub enum VideoCodec {
32 H264 = 0x61766331,
43}
44
45impl ::re_types_core::Component for VideoCodec {
46 #[inline]
47 fn name() -> ComponentType {
48 "rerun.components.VideoCodec".into()
49 }
50}
51
52::re_types_core::macros::impl_into_cow!(VideoCodec);
53
54impl ::re_types_core::Loggable for VideoCodec {
55 #[inline]
56 fn arrow_datatype() -> arrow::datatypes::DataType {
57 #![allow(clippy::wildcard_imports)]
58 use arrow::datatypes::*;
59 DataType::UInt32
60 }
61
62 fn to_arrow_opt<'a>(
63 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
64 ) -> SerializationResult<arrow::array::ArrayRef>
65 where
66 Self: Clone + 'a,
67 {
68 #![allow(clippy::wildcard_imports)]
69 #![allow(clippy::manual_is_variant_and)]
70 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
71 use arrow::{array::*, buffer::*, datatypes::*};
72 Ok({
73 let (somes, data0): (Vec<_>, Vec<_>) = data
74 .into_iter()
75 .map(|datum| {
76 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
77 let datum = datum.map(|datum| *datum as u32);
78 (datum.is_some(), datum)
79 })
80 .unzip();
81 let data0_validity: Option<arrow::buffer::NullBuffer> = {
82 let any_nones = somes.iter().any(|some| !*some);
83 any_nones.then(|| somes.into())
84 };
85 as_array_ref(PrimitiveArray::<UInt32Type>::new(
86 ScalarBuffer::from(
87 data0
88 .into_iter()
89 .map(|v| v.unwrap_or_default())
90 .collect::<Vec<_>>(),
91 ),
92 data0_validity,
93 ))
94 })
95 }
96
97 fn from_arrow_opt(
98 arrow_data: &dyn arrow::array::Array,
99 ) -> DeserializationResult<Vec<Option<Self>>>
100 where
101 Self: Sized,
102 {
103 #![allow(clippy::wildcard_imports)]
104 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
105 use arrow::{array::*, buffer::*, datatypes::*};
106 Ok(arrow_data
107 .as_any()
108 .downcast_ref::<UInt32Array>()
109 .ok_or_else(|| {
110 let expected = Self::arrow_datatype();
111 let actual = arrow_data.data_type().clone();
112 DeserializationError::datatype_mismatch(expected, actual)
113 })
114 .with_context("rerun.components.VideoCodec#enum")?
115 .into_iter()
116 .map(|typ| match typ {
117 Some(1635148593) => Ok(Some(Self::H264)),
118 None => Ok(None),
119 Some(invalid) => Err(DeserializationError::missing_union_arm(
120 Self::arrow_datatype(),
121 "<invalid>",
122 invalid as _,
123 )),
124 })
125 .collect::<DeserializationResult<Vec<Option<_>>>>()
126 .with_context("rerun.components.VideoCodec")?)
127 }
128}
129
130impl std::fmt::Display for VideoCodec {
131 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
132 match self {
133 Self::H264 => write!(f, "H264"),
134 }
135 }
136}
137
138impl ::re_types_core::reflection::Enum for VideoCodec {
139 #[inline]
140 fn variants() -> &'static [Self] {
141 &[Self::H264]
142 }
143
144 #[inline]
145 fn docstring_md(self) -> &'static str {
146 match self {
147 Self::H264 => {
148 "Advanced Video Coding (AVC/H.264)\n\nSee <https://en.wikipedia.org/wiki/Advanced_Video_Coding>\n\n[`components.VideoSample`](https://rerun.io/docs/reference/types/components/video_sample?speculative-link)s using this codec should be formatted according to Annex B specification.\n(Note that this is different from AVCC format found in MP4 files.\nTo learn more about Annex B, check for instance <https://membrane.stream/learn/h264/3>)\nKey frames (IDR) require inclusion of a SPS (Sequence Parameter Set)\n\nEnum value is the fourcc for 'avc1' (the WebCodec string assigned to this codec) in big endian."
149 }
150 }
151 }
152}
153
154impl ::re_byte_size::SizeBytes for VideoCodec {
155 #[inline]
156 fn heap_size_bytes(&self) -> u64 {
157 0
158 }
159
160 #[inline]
161 fn is_pod() -> bool {
162 true
163 }
164}