Skip to main content

matter_kit/clusters/generated/
media_playback.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Media Playback — cluster 0x0506.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Media Playback (cluster `0x0506`, revision 2).
10//!
11//! 27 identifiers, 5 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x0506;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 2;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "MEDIAPLAYBACK";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Advanced media seeking
42    ///
43    /// Code `AS`, bit 0.
44    pub const ADVANCED_SEEK: u32 = 1 << 0;
45    /// Variable speed playback
46    ///
47    /// Code `VS`, bit 1.
48    pub const VARIABLE_SPEED: u32 = 1 << 1;
49    /// Text Tracks
50    ///
51    /// Code `TT`, bit 2.
52    pub const TEXT_TRACKS: u32 = 1 << 2;
53    /// Audio Tracks
54    ///
55    /// Code `AT`, bit 3.
56    pub const AUDIO_TRACKS: u32 = 1 << 3;
57    /// Can play audio during fast and slow playback speeds
58    ///
59    /// Code `AA`, bit 4.
60    pub const AUDIO_ADVANCE: u32 = 1 << 4;
61}
62
63/// Every feature bit, with its conformance.
64pub const FEATURES: &[Feature] = &[
65    Feature {
66        bit: 0,
67        code: "AS",
68        name: "AdvancedSeek",
69        conform: Conform::OPTIONAL,
70    },
71    Feature {
72        bit: 1,
73        code: "VS",
74        name: "VariableSpeed",
75        conform: Conform::OPTIONAL,
76    },
77    Feature {
78        bit: 2,
79        code: "TT",
80        name: "TextTracks",
81        conform: Conform::OPTIONAL,
82    },
83    Feature {
84        bit: 3,
85        code: "AT",
86        name: "AudioTracks",
87        conform: Conform::OPTIONAL,
88    },
89    Feature {
90        bit: 4,
91        code: "AA",
92        name: "AudioAdvance",
93        conform: Conform::OPTIONAL,
94    },
95];
96
97/// The attribute ids.
98pub mod attribute {
99    use crate::im::AttributeId;
100
101    /// `CurrentState`.
102    pub const CURRENT_STATE: AttributeId = 0x00;
103    /// `StartTime`.
104    pub const START_TIME: AttributeId = 0x01;
105    /// `Duration`.
106    pub const DURATION: AttributeId = 0x02;
107    /// `SampledPosition`.
108    pub const SAMPLED_POSITION: AttributeId = 0x03;
109    /// `PlaybackSpeed`.
110    pub const PLAYBACK_SPEED: AttributeId = 0x04;
111    /// `SeekRangeEnd`.
112    pub const SEEK_RANGE_END: AttributeId = 0x05;
113    /// `SeekRangeStart`.
114    pub const SEEK_RANGE_START: AttributeId = 0x06;
115    /// `ActiveAudioTrack`.
116    pub const ACTIVE_AUDIO_TRACK: AttributeId = 0x07;
117    /// `AvailableAudioTracks`.
118    pub const AVAILABLE_AUDIO_TRACKS: AttributeId = 0x08;
119    /// `ActiveTextTrack`.
120    pub const ACTIVE_TEXT_TRACK: AttributeId = 0x09;
121    /// `AvailableTextTracks`.
122    pub const AVAILABLE_TEXT_TRACKS: AttributeId = 0x0A;
123}
124
125/// The command ids.
126pub mod command {
127    use crate::im::CommandId;
128
129    /// `Play`.
130    pub const PLAY: CommandId = 0x00;
131    /// `Pause`.
132    pub const PAUSE: CommandId = 0x01;
133    /// `Stop`.
134    pub const STOP: CommandId = 0x02;
135    /// `StartOver`.
136    pub const START_OVER: CommandId = 0x03;
137    /// `Previous`.
138    pub const PREVIOUS: CommandId = 0x04;
139    /// `Next`.
140    pub const NEXT: CommandId = 0x05;
141    /// `Rewind`.
142    pub const REWIND: CommandId = 0x06;
143    /// `FastForward`.
144    pub const FAST_FORWARD: CommandId = 0x07;
145    /// `SkipForward`.
146    pub const SKIP_FORWARD: CommandId = 0x08;
147    /// `SkipBackward`.
148    pub const SKIP_BACKWARD: CommandId = 0x09;
149    /// `PlaybackResponse`.
150    pub const PLAYBACK_RESPONSE: CommandId = 0x0A;
151    /// `Seek`.
152    pub const SEEK: CommandId = 0x0B;
153    /// `ActivateAudioTrack`.
154    pub const ACTIVATE_AUDIO_TRACK: CommandId = 0x0C;
155    /// `ActivateTextTrack`.
156    pub const ACTIVATE_TEXT_TRACK: CommandId = 0x0D;
157    /// `DeactivateTextTrack`.
158    pub const DEACTIVATE_TEXT_TRACK: CommandId = 0x0E;
159}
160
161/// The event ids.
162pub mod event {
163    use crate::im::EventId;
164
165    /// `StateChanged`.
166    pub const STATE_CHANGED: EventId = 0x00;
167}
168
169/// `CharacteristicEnum`.
170#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
171#[repr(u8)]
172pub enum CharacteristicEnum {
173    /// Textual information meant for display when no other text representation is selected. It is used to clarify dialogue, alternate languages, texted graphics or location/person IDs that are not otherwise covered in the dubbed/localized audio.
174    ForcedSubtitles = 0,
175    /// Textual or audio media component containing a textual description (intended for audio synthesis) or an audio description describing a visual component
176    DescribesVideo = 1,
177    /// Simplified or reduced captions as specified in [United States Code Title 47 CFR 79.103(c)(9)].
178    EasyToRead = 2,
179    /// A media characteristic that indicates that a track selection option includes frame-based content.
180    FrameBased = 3,
181    /// Main media component(s) which is/are intended for presentation if no other information is provided
182    MainProgram = 4,
183    /// A media characteristic that indicates that a track or media selection option contains original content.
184    OriginalContent = 5,
185    /// A media characteristic that indicates that a track or media selection option contains a language translation and verbal interpretation of spoken dialog.
186    VoiceOverTranslation = 6,
187    /// Textual media component containing transcriptions of spoken dialog and auditory cues such as sound effects and music for the hearing impaired.
188    Caption = 7,
189    /// Textual transcriptions of spoken dialog.
190    Subtitle = 8,
191    /// Textual media component containing transcriptions of spoken dialog and auditory cues such as sound effects and music for the hearing impaired.
192    Alternate = 9,
193    /// Media content component that is supplementary to a media content component of a different media component type.
194    Supplementary = 10,
195    /// Experience that contains a commentary (e.g. director’s commentary) (typically audio)
196    Commentary = 11,
197    /// Experience that contains an element that is presented in a different language from the original (e.g. dubbed audio, translated captions)
198    DubbedTranslation = 12,
199    /// Textual or audio media component containing a textual description (intended for audio synthesis) or an audio description describing a visual component
200    Description = 13,
201    /// Media component containing information intended to be processed by application specific elements.
202    Metadata = 14,
203    /// Experience containing an element for improved intelligibility of the dialogue.
204    EnhancedAudioIntelligibility = 15,
205    /// Experience that provides information, about a current emergency, that is intended to enable the protection of life, health, safety, and property, and may also include critical details regarding the emergency and how to respond to the emergency.
206    Emergency = 16,
207    /// Textual representation of a songs’ lyrics, usually in the same language as the associated song as specified in [SMPTE ST 2067-2].
208    Karaoke = 17,
209}
210
211impl CharacteristicEnum {
212    /// Reads a wire value, or `None` for one this revision does not define.
213    #[must_use]
214    pub const fn from_value(value: u8) -> Option<Self> {
215        match value {
216            0 => Some(Self::ForcedSubtitles),
217            1 => Some(Self::DescribesVideo),
218            2 => Some(Self::EasyToRead),
219            3 => Some(Self::FrameBased),
220            4 => Some(Self::MainProgram),
221            5 => Some(Self::OriginalContent),
222            6 => Some(Self::VoiceOverTranslation),
223            7 => Some(Self::Caption),
224            8 => Some(Self::Subtitle),
225            9 => Some(Self::Alternate),
226            10 => Some(Self::Supplementary),
227            11 => Some(Self::Commentary),
228            12 => Some(Self::DubbedTranslation),
229            13 => Some(Self::Description),
230            14 => Some(Self::Metadata),
231            15 => Some(Self::EnhancedAudioIntelligibility),
232            16 => Some(Self::Emergency),
233            17 => Some(Self::Karaoke),
234            _ => None,
235        }
236    }
237
238    /// Its wire value.
239    #[must_use]
240    pub const fn value(self) -> u8 {
241        self as u8
242    }
243}
244
245impl ToTlv for CharacteristicEnum {
246    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
247        self.value().to_tlv(w, tag)
248    }
249}
250
251impl<'a> FromTlv<'a> for CharacteristicEnum {
252    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
253        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
254        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
255    }
256}
257
258/// `PlaybackStateEnum`.
259#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
260#[repr(u8)]
261pub enum PlaybackStateEnum {
262    /// Media is currently playing (includes FF and REW)
263    Playing = 0,
264    /// Media is currently paused
265    Paused = 1,
266    /// Media is not currently playing
267    NotPlaying = 2,
268    /// Media is not currently buffering and playback will start when buffer has been filled
269    Buffering = 3,
270}
271
272impl PlaybackStateEnum {
273    /// Reads a wire value, or `None` for one this revision does not define.
274    #[must_use]
275    pub const fn from_value(value: u8) -> Option<Self> {
276        match value {
277            0 => Some(Self::Playing),
278            1 => Some(Self::Paused),
279            2 => Some(Self::NotPlaying),
280            3 => Some(Self::Buffering),
281            _ => None,
282        }
283    }
284
285    /// Its wire value.
286    #[must_use]
287    pub const fn value(self) -> u8 {
288        self as u8
289    }
290}
291
292impl ToTlv for PlaybackStateEnum {
293    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
294        self.value().to_tlv(w, tag)
295    }
296}
297
298impl<'a> FromTlv<'a> for PlaybackStateEnum {
299    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
300        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
301        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
302    }
303}
304
305/// `StatusEnum`.
306#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
307#[repr(u8)]
308pub enum StatusEnum {
309    /// Succeeded
310    Success = 0,
311    /// Requested playback command is invalid in the current playback state.
312    InvalidStateForCommand = 1,
313    /// Requested playback command is not allowed in the current playback state. For example, attempting to fast-forward during a commercial might return NotAllowed.
314    NotAllowed = 2,
315    /// This endpoint is not active for playback.
316    NotActive = 3,
317    /// The FastForward or Rewind Command was issued but the media is already playing back at the fastest speed supported by the server in the respective direction.
318    SpeedOutOfRange = 4,
319    /// The Seek Command was issued with a value of position outside of the allowed seek range of the media.
320    SeekOutOfRange = 5,
321}
322
323impl StatusEnum {
324    /// Reads a wire value, or `None` for one this revision does not define.
325    #[must_use]
326    pub const fn from_value(value: u8) -> Option<Self> {
327        match value {
328            0 => Some(Self::Success),
329            1 => Some(Self::InvalidStateForCommand),
330            2 => Some(Self::NotAllowed),
331            3 => Some(Self::NotActive),
332            4 => Some(Self::SpeedOutOfRange),
333            5 => Some(Self::SeekOutOfRange),
334            _ => None,
335        }
336    }
337
338    /// Its wire value.
339    #[must_use]
340    pub const fn value(self) -> u8 {
341        self as u8
342    }
343}
344
345impl ToTlv for StatusEnum {
346    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
347        self.value().to_tlv(w, tag)
348    }
349}
350
351impl<'a> FromTlv<'a> for StatusEnum {
352    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
353        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
354        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
355    }
356}
357
358/// `PlaybackPositionStruct`.
359#[derive(Debug, Clone, Copy, PartialEq)]
360pub struct PlaybackPositionStruct {
361    /// `UpdatedAt`, field 0.
362    pub updated_at: u64,
363    /// `Position`, field 1.
364    pub position: Nullable<u64>,
365}
366
367impl ToTlv for PlaybackPositionStruct {
368    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
369        w.start_structure(tag)?;
370        self.updated_at.to_tlv(w, Tag::Context(0))?;
371        self.position.to_tlv(w, Tag::Context(1))?;
372        w.end_container()
373    }
374}
375
376impl<'a> FromTlv<'a> for PlaybackPositionStruct {
377    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
378        if element.value.container() != Some(ContainerKind::Structure) {
379            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
380        }
381        let mut updated_at = None;
382        let mut position = None;
383        loop {
384            let Some(field) = reader.next_element()? else {
385                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
386            };
387            if field.value == Value::EndOfContainer {
388                break;
389            }
390            match field.tag.context() {
391                Some(0) => updated_at = Some(<u64>::from_tlv(reader, &field)?),
392                Some(1) => position = Some(<Nullable<u64>>::from_tlv(reader, &field)?),
393                // A field this revision does not define. §7.19.2: a receiver
394                // ignores what it does not know rather than refusing the whole
395                // structure, which is what lets a newer peer talk to an older one.
396                _ => reader.skip_value(&field)?,
397            }
398        }
399        Ok(Self {
400            updated_at: updated_at.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
401            position: position.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
402        })
403    }
404}
405
406/// `TrackAttributesStruct`.
407#[derive(Debug, Clone, Copy, PartialEq)]
408pub struct TrackAttributesStruct<'a> {
409    /// `LanguageCode`, field 0.
410    pub language_code: &'a str,
411    /// `Characteristics`, field 1.
412    pub characteristics: Option<Nullable<TlvList<'a, CharacteristicEnum>>>,
413    /// `DisplayName`, field 2.
414    pub display_name: Option<Nullable<&'a str>>,
415}
416
417impl<'a> ToTlv for TrackAttributesStruct<'a> {
418    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
419        w.start_structure(tag)?;
420        self.language_code.to_tlv(w, Tag::Context(0))?;
421        if let Some(value) = &self.characteristics {
422            value.to_tlv(w, Tag::Context(1))?;
423        }
424        if let Some(value) = &self.display_name {
425            value.to_tlv(w, Tag::Context(2))?;
426        }
427        w.end_container()
428    }
429}
430
431impl<'a> FromTlv<'a> for TrackAttributesStruct<'a> {
432    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
433        if element.value.container() != Some(ContainerKind::Structure) {
434            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
435        }
436        let mut language_code = None;
437        let mut characteristics = None;
438        let mut display_name = None;
439        loop {
440            let Some(field) = reader.next_element()? else {
441                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
442            };
443            if field.value == Value::EndOfContainer {
444                break;
445            }
446            match field.tag.context() {
447                Some(0) => language_code = Some(<&'a str>::from_tlv(reader, &field)?),
448                Some(1) => {
449                    characteristics = Some(<Nullable<TlvList<'a, CharacteristicEnum>>>::from_tlv(
450                        reader, &field,
451                    )?)
452                }
453                Some(2) => display_name = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
454                // A field this revision does not define. §7.19.2: a receiver
455                // ignores what it does not know rather than refusing the whole
456                // structure, which is what lets a newer peer talk to an older one.
457                _ => reader.skip_value(&field)?,
458            }
459        }
460        Ok(Self {
461            language_code: language_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
462            characteristics,
463            display_name,
464        })
465    }
466}
467
468/// `TrackStruct`.
469#[derive(Debug, Clone, Copy, PartialEq)]
470pub struct TrackStruct<'a> {
471    /// `ID`, field 0.
472    pub id: &'a str,
473    /// `TrackAttributes`, field 1.
474    pub track_attributes: TrackAttributesStruct<'a>,
475}
476
477impl<'a> ToTlv for TrackStruct<'a> {
478    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
479        w.start_structure(tag)?;
480        self.id.to_tlv(w, Tag::Context(0))?;
481        self.track_attributes.to_tlv(w, Tag::Context(1))?;
482        w.end_container()
483    }
484}
485
486impl<'a> FromTlv<'a> for TrackStruct<'a> {
487    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
488        if element.value.container() != Some(ContainerKind::Structure) {
489            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
490        }
491        let mut id = None;
492        let mut track_attributes = None;
493        loop {
494            let Some(field) = reader.next_element()? else {
495                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
496            };
497            if field.value == Value::EndOfContainer {
498                break;
499            }
500            match field.tag.context() {
501                Some(0) => id = Some(<&'a str>::from_tlv(reader, &field)?),
502                Some(1) => {
503                    track_attributes = Some(<TrackAttributesStruct<'a>>::from_tlv(reader, &field)?)
504                }
505                // A field this revision does not define. §7.19.2: a receiver
506                // ignores what it does not know rather than refusing the whole
507                // structure, which is what lets a newer peer talk to an older one.
508                _ => reader.skip_value(&field)?,
509            }
510        }
511        Ok(Self {
512            id: id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
513            track_attributes: track_attributes
514                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
515        })
516    }
517}
518
519/// The fields of `Rewind` (command `0x06`).
520#[derive(Debug, Clone, Copy, PartialEq)]
521pub struct RewindFields {
522    /// `AudioAdvanceUnmuted`, field 0.
523    pub audio_advance_unmuted: Option<bool>,
524}
525
526impl ToTlv for RewindFields {
527    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
528        w.start_structure(tag)?;
529        if let Some(value) = &self.audio_advance_unmuted {
530            value.to_tlv(w, Tag::Context(0))?;
531        }
532        w.end_container()
533    }
534}
535
536impl<'a> FromTlv<'a> for RewindFields {
537    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
538        if element.value.container() != Some(ContainerKind::Structure) {
539            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
540        }
541        let mut audio_advance_unmuted = None;
542        loop {
543            let Some(field) = reader.next_element()? else {
544                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
545            };
546            if field.value == Value::EndOfContainer {
547                break;
548            }
549            match field.tag.context() {
550                Some(0) => audio_advance_unmuted = Some(<bool>::from_tlv(reader, &field)?),
551                // A field this revision does not define. §7.19.2: a receiver
552                // ignores what it does not know rather than refusing the whole
553                // structure, which is what lets a newer peer talk to an older one.
554                _ => reader.skip_value(&field)?,
555            }
556        }
557        Ok(Self {
558            audio_advance_unmuted,
559        })
560    }
561}
562
563/// The fields of `FastForward` (command `0x07`).
564#[derive(Debug, Clone, Copy, PartialEq)]
565pub struct FastForwardFields {
566    /// `AudioAdvanceUnmuted`, field 0.
567    pub audio_advance_unmuted: Option<bool>,
568}
569
570impl ToTlv for FastForwardFields {
571    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
572        w.start_structure(tag)?;
573        if let Some(value) = &self.audio_advance_unmuted {
574            value.to_tlv(w, Tag::Context(0))?;
575        }
576        w.end_container()
577    }
578}
579
580impl<'a> FromTlv<'a> for FastForwardFields {
581    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
582        if element.value.container() != Some(ContainerKind::Structure) {
583            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
584        }
585        let mut audio_advance_unmuted = None;
586        loop {
587            let Some(field) = reader.next_element()? else {
588                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
589            };
590            if field.value == Value::EndOfContainer {
591                break;
592            }
593            match field.tag.context() {
594                Some(0) => audio_advance_unmuted = Some(<bool>::from_tlv(reader, &field)?),
595                // A field this revision does not define. §7.19.2: a receiver
596                // ignores what it does not know rather than refusing the whole
597                // structure, which is what lets a newer peer talk to an older one.
598                _ => reader.skip_value(&field)?,
599            }
600        }
601        Ok(Self {
602            audio_advance_unmuted,
603        })
604    }
605}
606
607/// The fields of `SkipForward` (command `0x08`).
608#[derive(Debug, Clone, Copy, PartialEq)]
609pub struct SkipForwardFields {
610    /// `DeltaPositionMilliseconds`, field 0.
611    pub delta_position_milliseconds: u64,
612}
613
614impl ToTlv for SkipForwardFields {
615    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
616        w.start_structure(tag)?;
617        self.delta_position_milliseconds
618            .to_tlv(w, Tag::Context(0))?;
619        w.end_container()
620    }
621}
622
623impl<'a> FromTlv<'a> for SkipForwardFields {
624    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
625        if element.value.container() != Some(ContainerKind::Structure) {
626            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
627        }
628        let mut delta_position_milliseconds = None;
629        loop {
630            let Some(field) = reader.next_element()? else {
631                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
632            };
633            if field.value == Value::EndOfContainer {
634                break;
635            }
636            match field.tag.context() {
637                Some(0) => delta_position_milliseconds = Some(<u64>::from_tlv(reader, &field)?),
638                // A field this revision does not define. §7.19.2: a receiver
639                // ignores what it does not know rather than refusing the whole
640                // structure, which is what lets a newer peer talk to an older one.
641                _ => reader.skip_value(&field)?,
642            }
643        }
644        Ok(Self {
645            delta_position_milliseconds: delta_position_milliseconds
646                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
647        })
648    }
649}
650
651/// The fields of `SkipBackward` (command `0x09`).
652#[derive(Debug, Clone, Copy, PartialEq)]
653pub struct SkipBackwardFields {
654    /// `DeltaPositionMilliseconds`, field 0.
655    pub delta_position_milliseconds: u64,
656}
657
658impl ToTlv for SkipBackwardFields {
659    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
660        w.start_structure(tag)?;
661        self.delta_position_milliseconds
662            .to_tlv(w, Tag::Context(0))?;
663        w.end_container()
664    }
665}
666
667impl<'a> FromTlv<'a> for SkipBackwardFields {
668    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
669        if element.value.container() != Some(ContainerKind::Structure) {
670            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
671        }
672        let mut delta_position_milliseconds = None;
673        loop {
674            let Some(field) = reader.next_element()? else {
675                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
676            };
677            if field.value == Value::EndOfContainer {
678                break;
679            }
680            match field.tag.context() {
681                Some(0) => delta_position_milliseconds = Some(<u64>::from_tlv(reader, &field)?),
682                // A field this revision does not define. §7.19.2: a receiver
683                // ignores what it does not know rather than refusing the whole
684                // structure, which is what lets a newer peer talk to an older one.
685                _ => reader.skip_value(&field)?,
686            }
687        }
688        Ok(Self {
689            delta_position_milliseconds: delta_position_milliseconds
690                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
691        })
692    }
693}
694
695/// The fields of `PlaybackResponse` (command `0x0A`).
696#[derive(Debug, Clone, Copy, PartialEq)]
697pub struct PlaybackResponseFields<'a> {
698    /// `Status`, field 0.
699    pub status: StatusEnum,
700    /// `Data`, field 1.
701    pub data: Option<&'a str>,
702}
703
704impl<'a> ToTlv for PlaybackResponseFields<'a> {
705    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
706        w.start_structure(tag)?;
707        self.status.to_tlv(w, Tag::Context(0))?;
708        if let Some(value) = &self.data {
709            value.to_tlv(w, Tag::Context(1))?;
710        }
711        w.end_container()
712    }
713}
714
715impl<'a> FromTlv<'a> for PlaybackResponseFields<'a> {
716    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
717        if element.value.container() != Some(ContainerKind::Structure) {
718            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
719        }
720        let mut status = None;
721        let mut data = None;
722        loop {
723            let Some(field) = reader.next_element()? else {
724                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
725            };
726            if field.value == Value::EndOfContainer {
727                break;
728            }
729            match field.tag.context() {
730                Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
731                Some(1) => data = Some(<&'a str>::from_tlv(reader, &field)?),
732                // A field this revision does not define. §7.19.2: a receiver
733                // ignores what it does not know rather than refusing the whole
734                // structure, which is what lets a newer peer talk to an older one.
735                _ => reader.skip_value(&field)?,
736            }
737        }
738        Ok(Self {
739            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
740            data,
741        })
742    }
743}
744
745/// The fields of `Seek` (command `0x0B`).
746#[derive(Debug, Clone, Copy, PartialEq)]
747pub struct SeekFields {
748    /// `Position`, field 0.
749    pub position: u64,
750}
751
752impl ToTlv for SeekFields {
753    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
754        w.start_structure(tag)?;
755        self.position.to_tlv(w, Tag::Context(0))?;
756        w.end_container()
757    }
758}
759
760impl<'a> FromTlv<'a> for SeekFields {
761    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
762        if element.value.container() != Some(ContainerKind::Structure) {
763            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
764        }
765        let mut position = None;
766        loop {
767            let Some(field) = reader.next_element()? else {
768                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
769            };
770            if field.value == Value::EndOfContainer {
771                break;
772            }
773            match field.tag.context() {
774                Some(0) => position = Some(<u64>::from_tlv(reader, &field)?),
775                // A field this revision does not define. §7.19.2: a receiver
776                // ignores what it does not know rather than refusing the whole
777                // structure, which is what lets a newer peer talk to an older one.
778                _ => reader.skip_value(&field)?,
779            }
780        }
781        Ok(Self {
782            position: position.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
783        })
784    }
785}
786
787/// The fields of `ActivateAudioTrack` (command `0x0C`).
788#[derive(Debug, Clone, Copy, PartialEq)]
789pub struct ActivateAudioTrackFields<'a> {
790    /// `TrackID`, field 0.
791    pub track_id: &'a str,
792    /// `AudioOutputIndex`, field 1.
793    pub audio_output_index: Option<Nullable<u8>>,
794}
795
796impl<'a> ToTlv for ActivateAudioTrackFields<'a> {
797    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
798        w.start_structure(tag)?;
799        self.track_id.to_tlv(w, Tag::Context(0))?;
800        if let Some(value) = &self.audio_output_index {
801            value.to_tlv(w, Tag::Context(1))?;
802        }
803        w.end_container()
804    }
805}
806
807impl<'a> FromTlv<'a> for ActivateAudioTrackFields<'a> {
808    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
809        if element.value.container() != Some(ContainerKind::Structure) {
810            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
811        }
812        let mut track_id = None;
813        let mut audio_output_index = None;
814        loop {
815            let Some(field) = reader.next_element()? else {
816                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
817            };
818            if field.value == Value::EndOfContainer {
819                break;
820            }
821            match field.tag.context() {
822                Some(0) => track_id = Some(<&'a str>::from_tlv(reader, &field)?),
823                Some(1) => audio_output_index = Some(<Nullable<u8>>::from_tlv(reader, &field)?),
824                // A field this revision does not define. §7.19.2: a receiver
825                // ignores what it does not know rather than refusing the whole
826                // structure, which is what lets a newer peer talk to an older one.
827                _ => reader.skip_value(&field)?,
828            }
829        }
830        Ok(Self {
831            track_id: track_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
832            audio_output_index,
833        })
834    }
835}
836
837/// The fields of `ActivateTextTrack` (command `0x0D`).
838#[derive(Debug, Clone, Copy, PartialEq)]
839pub struct ActivateTextTrackFields<'a> {
840    /// `TrackID`, field 0.
841    pub track_id: &'a str,
842}
843
844impl<'a> ToTlv for ActivateTextTrackFields<'a> {
845    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
846        w.start_structure(tag)?;
847        self.track_id.to_tlv(w, Tag::Context(0))?;
848        w.end_container()
849    }
850}
851
852impl<'a> FromTlv<'a> for ActivateTextTrackFields<'a> {
853    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
854        if element.value.container() != Some(ContainerKind::Structure) {
855            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
856        }
857        let mut track_id = None;
858        loop {
859            let Some(field) = reader.next_element()? else {
860                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
861            };
862            if field.value == Value::EndOfContainer {
863                break;
864            }
865            match field.tag.context() {
866                Some(0) => track_id = Some(<&'a str>::from_tlv(reader, &field)?),
867                // A field this revision does not define. §7.19.2: a receiver
868                // ignores what it does not know rather than refusing the whole
869                // structure, which is what lets a newer peer talk to an older one.
870                _ => reader.skip_value(&field)?,
871            }
872        }
873        Ok(Self {
874            track_id: track_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
875        })
876    }
877}
878
879/// Every attribute the specification defines, with its conformance.
880pub const ATTRIBUTES: &[Attribute] = &[
881    Attribute {
882        id: 0x0000,
883        name: "CurrentState",
884        kind: "PlaybackStateEnum",
885        access: Access::read_only(Privilege::View),
886        qualities: AttributeQualities::empty(),
887        reporting: Reporting::OnChange,
888        conform: Conform::MANDATORY,
889    },
890    Attribute {
891        id: 0x0001,
892        name: "StartTime",
893        kind: "epoch-us",
894        access: Access::read_only(Privilege::View),
895        qualities: AttributeQualities::NULLABLE,
896        reporting: Reporting::OnChange,
897        conform: Conform {
898            clauses: &[Clause {
899                verdict: Conformance::Mandatory,
900                when: Condition::Feature(0),
901            }],
902        },
903    },
904    Attribute {
905        id: 0x0002,
906        name: "Duration",
907        kind: "uint64",
908        access: Access::read_only(Privilege::View),
909        qualities: AttributeQualities::NULLABLE,
910        reporting: Reporting::OnChange,
911        conform: Conform {
912            clauses: &[Clause {
913                verdict: Conformance::Mandatory,
914                when: Condition::Feature(0),
915            }],
916        },
917    },
918    Attribute {
919        id: 0x0003,
920        name: "SampledPosition",
921        kind: "PlaybackPositionStruct",
922        access: Access::read_only(Privilege::View),
923        qualities: AttributeQualities::NULLABLE,
924        reporting: Reporting::OnChange,
925        conform: Conform {
926            clauses: &[Clause {
927                verdict: Conformance::Mandatory,
928                when: Condition::Feature(0),
929            }],
930        },
931    },
932    Attribute {
933        id: 0x0004,
934        name: "PlaybackSpeed",
935        kind: "single",
936        access: Access::read_only(Privilege::View),
937        qualities: AttributeQualities::empty(),
938        reporting: Reporting::OnChange,
939        conform: Conform {
940            clauses: &[Clause {
941                verdict: Conformance::Mandatory,
942                when: Condition::Feature(0),
943            }],
944        },
945    },
946    Attribute {
947        id: 0x0005,
948        name: "SeekRangeEnd",
949        kind: "uint64",
950        access: Access::read_only(Privilege::View),
951        qualities: AttributeQualities::NULLABLE,
952        reporting: Reporting::OnChange,
953        conform: Conform {
954            clauses: &[Clause {
955                verdict: Conformance::Mandatory,
956                when: Condition::Feature(0),
957            }],
958        },
959    },
960    Attribute {
961        id: 0x0006,
962        name: "SeekRangeStart",
963        kind: "uint64",
964        access: Access::read_only(Privilege::View),
965        qualities: AttributeQualities::NULLABLE,
966        reporting: Reporting::OnChange,
967        conform: Conform {
968            clauses: &[Clause {
969                verdict: Conformance::Mandatory,
970                when: Condition::Feature(0),
971            }],
972        },
973    },
974    Attribute {
975        id: 0x0007,
976        name: "ActiveAudioTrack",
977        kind: "TrackStruct",
978        access: Access::read_only(Privilege::View),
979        qualities: AttributeQualities::NULLABLE,
980        reporting: Reporting::OnChange,
981        conform: Conform {
982            clauses: &[Clause {
983                verdict: Conformance::Mandatory,
984                when: Condition::Feature(3),
985            }],
986        },
987    },
988    Attribute {
989        id: 0x0008,
990        name: "AvailableAudioTracks",
991        kind: "list[TrackStruct]",
992        access: Access::read_only(Privilege::View),
993        qualities: AttributeQualities::NULLABLE,
994        reporting: Reporting::OnChange,
995        conform: Conform {
996            clauses: &[Clause {
997                verdict: Conformance::Mandatory,
998                when: Condition::Feature(3),
999            }],
1000        },
1001    },
1002    Attribute {
1003        id: 0x0009,
1004        name: "ActiveTextTrack",
1005        kind: "TrackStruct",
1006        access: Access::read_only(Privilege::View),
1007        qualities: AttributeQualities::NULLABLE,
1008        reporting: Reporting::OnChange,
1009        conform: Conform {
1010            clauses: &[Clause {
1011                verdict: Conformance::Mandatory,
1012                when: Condition::Feature(2),
1013            }],
1014        },
1015    },
1016    Attribute {
1017        id: 0x000A,
1018        name: "AvailableTextTracks",
1019        kind: "list[TrackStruct]",
1020        access: Access::read_only(Privilege::View),
1021        qualities: AttributeQualities::NULLABLE,
1022        reporting: Reporting::OnChange,
1023        conform: Conform {
1024            clauses: &[Clause {
1025                verdict: Conformance::Mandatory,
1026                when: Condition::Feature(2),
1027            }],
1028        },
1029    },
1030];
1031
1032/// Every command, with its conformance.
1033pub const COMMANDS: &[Command] = &[
1034    Command {
1035        id: 0x00,
1036        name: "Play",
1037        to_server: true,
1038        response: Some(0x0A),
1039        access: Access::invoke(Privilege::Operate),
1040        conform: Conform::MANDATORY,
1041    },
1042    Command {
1043        id: 0x01,
1044        name: "Pause",
1045        to_server: true,
1046        response: Some(0x0A),
1047        access: Access::invoke(Privilege::Operate),
1048        conform: Conform::MANDATORY,
1049    },
1050    Command {
1051        id: 0x02,
1052        name: "Stop",
1053        to_server: true,
1054        response: Some(0x0A),
1055        access: Access::invoke(Privilege::Operate),
1056        conform: Conform::MANDATORY,
1057    },
1058    Command {
1059        id: 0x03,
1060        name: "StartOver",
1061        to_server: true,
1062        response: Some(0x0A),
1063        access: Access::invoke(Privilege::Operate),
1064        conform: Conform::OPTIONAL,
1065    },
1066    Command {
1067        id: 0x04,
1068        name: "Previous",
1069        to_server: true,
1070        response: Some(0x0A),
1071        access: Access::invoke(Privilege::Operate),
1072        conform: Conform::OPTIONAL,
1073    },
1074    Command {
1075        id: 0x05,
1076        name: "Next",
1077        to_server: true,
1078        response: Some(0x0A),
1079        access: Access::invoke(Privilege::Operate),
1080        conform: Conform::OPTIONAL,
1081    },
1082    Command {
1083        id: 0x06,
1084        name: "Rewind",
1085        to_server: true,
1086        response: Some(0x0A),
1087        access: Access::invoke(Privilege::Operate),
1088        conform: Conform {
1089            clauses: &[Clause {
1090                verdict: Conformance::Mandatory,
1091                when: Condition::Feature(1),
1092            }],
1093        },
1094    },
1095    Command {
1096        id: 0x07,
1097        name: "FastForward",
1098        to_server: true,
1099        response: Some(0x0A),
1100        access: Access::invoke(Privilege::Operate),
1101        conform: Conform {
1102            clauses: &[Clause {
1103                verdict: Conformance::Mandatory,
1104                when: Condition::Feature(1),
1105            }],
1106        },
1107    },
1108    Command {
1109        id: 0x08,
1110        name: "SkipForward",
1111        to_server: true,
1112        response: Some(0x0A),
1113        access: Access::invoke(Privilege::Operate),
1114        conform: Conform::OPTIONAL,
1115    },
1116    Command {
1117        id: 0x09,
1118        name: "SkipBackward",
1119        to_server: true,
1120        response: Some(0x0A),
1121        access: Access::invoke(Privilege::Operate),
1122        conform: Conform::OPTIONAL,
1123    },
1124    Command {
1125        id: 0x0A,
1126        name: "PlaybackResponse",
1127        to_server: false,
1128        response: None,
1129        access: Access::invoke(Privilege::Operate),
1130        conform: Conform::MANDATORY,
1131    },
1132    Command {
1133        id: 0x0B,
1134        name: "Seek",
1135        to_server: true,
1136        response: Some(0x0A),
1137        access: Access::invoke(Privilege::Operate),
1138        conform: Conform {
1139            clauses: &[Clause {
1140                verdict: Conformance::Mandatory,
1141                when: Condition::Feature(0),
1142            }],
1143        },
1144    },
1145    Command {
1146        id: 0x0C,
1147        name: "ActivateAudioTrack",
1148        to_server: true,
1149        response: None,
1150        access: Access::invoke(Privilege::Operate),
1151        conform: Conform {
1152            clauses: &[Clause {
1153                verdict: Conformance::Mandatory,
1154                when: Condition::Feature(3),
1155            }],
1156        },
1157    },
1158    Command {
1159        id: 0x0D,
1160        name: "ActivateTextTrack",
1161        to_server: true,
1162        response: None,
1163        access: Access::invoke(Privilege::Operate),
1164        conform: Conform {
1165            clauses: &[Clause {
1166                verdict: Conformance::Mandatory,
1167                when: Condition::Feature(2),
1168            }],
1169        },
1170    },
1171    Command {
1172        id: 0x0E,
1173        name: "DeactivateTextTrack",
1174        to_server: true,
1175        response: None,
1176        access: Access::invoke(Privilege::Operate),
1177        conform: Conform {
1178            clauses: &[Clause {
1179                verdict: Conformance::Mandatory,
1180                when: Condition::Feature(2),
1181            }],
1182        },
1183    },
1184];
1185
1186/// Every event, with its conformance.
1187pub const EVENTS: &[Event] = &[Event {
1188    id: 0x00,
1189    name: "StateChanged",
1190    priority: EventPriority::Info,
1191    access: Access::read_only(Privilege::View),
1192    conform: Conform::OPTIONAL,
1193}];
1194
1195/// The whole cluster, as the specification defines it.
1196pub const CLUSTER: Cluster = Cluster {
1197    id: ID,
1198    name: "Media Playback",
1199    revision: REVISION,
1200    pics: "MEDIAPLAYBACK",
1201    derived_from: None,
1202    features: FEATURES,
1203    attributes: ATTRIBUTES,
1204    commands: COMMANDS,
1205    events: EVENTS,
1206};