1#![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
26pub const ID: ClusterId = 0x0506;
28
29pub const REVISION: u16 = 2;
32
33pub const PICS: &str = "MEDIAPLAYBACK";
35
36pub mod feature {
41 pub const ADVANCED_SEEK: u32 = 1 << 0;
45 pub const VARIABLE_SPEED: u32 = 1 << 1;
49 pub const TEXT_TRACKS: u32 = 1 << 2;
53 pub const AUDIO_TRACKS: u32 = 1 << 3;
57 pub const AUDIO_ADVANCE: u32 = 1 << 4;
61}
62
63pub 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
97pub mod attribute {
99 use crate::im::AttributeId;
100
101 pub const CURRENT_STATE: AttributeId = 0x00;
103 pub const START_TIME: AttributeId = 0x01;
105 pub const DURATION: AttributeId = 0x02;
107 pub const SAMPLED_POSITION: AttributeId = 0x03;
109 pub const PLAYBACK_SPEED: AttributeId = 0x04;
111 pub const SEEK_RANGE_END: AttributeId = 0x05;
113 pub const SEEK_RANGE_START: AttributeId = 0x06;
115 pub const ACTIVE_AUDIO_TRACK: AttributeId = 0x07;
117 pub const AVAILABLE_AUDIO_TRACKS: AttributeId = 0x08;
119 pub const ACTIVE_TEXT_TRACK: AttributeId = 0x09;
121 pub const AVAILABLE_TEXT_TRACKS: AttributeId = 0x0A;
123}
124
125pub mod command {
127 use crate::im::CommandId;
128
129 pub const PLAY: CommandId = 0x00;
131 pub const PAUSE: CommandId = 0x01;
133 pub const STOP: CommandId = 0x02;
135 pub const START_OVER: CommandId = 0x03;
137 pub const PREVIOUS: CommandId = 0x04;
139 pub const NEXT: CommandId = 0x05;
141 pub const REWIND: CommandId = 0x06;
143 pub const FAST_FORWARD: CommandId = 0x07;
145 pub const SKIP_FORWARD: CommandId = 0x08;
147 pub const SKIP_BACKWARD: CommandId = 0x09;
149 pub const PLAYBACK_RESPONSE: CommandId = 0x0A;
151 pub const SEEK: CommandId = 0x0B;
153 pub const ACTIVATE_AUDIO_TRACK: CommandId = 0x0C;
155 pub const ACTIVATE_TEXT_TRACK: CommandId = 0x0D;
157 pub const DEACTIVATE_TEXT_TRACK: CommandId = 0x0E;
159}
160
161pub mod event {
163 use crate::im::EventId;
164
165 pub const STATE_CHANGED: EventId = 0x00;
167}
168
169#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
171#[repr(u8)]
172pub enum CharacteristicEnum {
173 ForcedSubtitles = 0,
175 DescribesVideo = 1,
177 EasyToRead = 2,
179 FrameBased = 3,
181 MainProgram = 4,
183 OriginalContent = 5,
185 VoiceOverTranslation = 6,
187 Caption = 7,
189 Subtitle = 8,
191 Alternate = 9,
193 Supplementary = 10,
195 Commentary = 11,
197 DubbedTranslation = 12,
199 Description = 13,
201 Metadata = 14,
203 EnhancedAudioIntelligibility = 15,
205 Emergency = 16,
207 Karaoke = 17,
209}
210
211impl CharacteristicEnum {
212 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
260#[repr(u8)]
261pub enum PlaybackStateEnum {
262 Playing = 0,
264 Paused = 1,
266 NotPlaying = 2,
268 Buffering = 3,
270}
271
272impl PlaybackStateEnum {
273 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
307#[repr(u8)]
308pub enum StatusEnum {
309 Success = 0,
311 InvalidStateForCommand = 1,
313 NotAllowed = 2,
315 NotActive = 3,
317 SpeedOutOfRange = 4,
319 SeekOutOfRange = 5,
321}
322
323impl StatusEnum {
324 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq)]
360pub struct PlaybackPositionStruct {
361 pub updated_at: u64,
363 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
408pub struct TrackAttributesStruct<'a> {
409 pub language_code: &'a str,
411 pub characteristics: Option<Nullable<TlvList<'a, CharacteristicEnum>>>,
413 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
470pub struct TrackStruct<'a> {
471 pub id: &'a str,
473 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
521pub struct RewindFields {
522 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 _ => reader.skip_value(&field)?,
555 }
556 }
557 Ok(Self {
558 audio_advance_unmuted,
559 })
560 }
561}
562
563#[derive(Debug, Clone, Copy, PartialEq)]
565pub struct FastForwardFields {
566 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 _ => reader.skip_value(&field)?,
599 }
600 }
601 Ok(Self {
602 audio_advance_unmuted,
603 })
604 }
605}
606
607#[derive(Debug, Clone, Copy, PartialEq)]
609pub struct SkipForwardFields {
610 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
653pub struct SkipBackwardFields {
654 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
697pub struct PlaybackResponseFields<'a> {
698 pub status: StatusEnum,
700 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
747pub struct SeekFields {
748 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
789pub struct ActivateAudioTrackFields<'a> {
790 pub track_id: &'a str,
792 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
839pub struct ActivateTextTrackFields<'a> {
840 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 _ => 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
879pub 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
1032pub 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
1186pub 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
1195pub 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};