From 722b43466371625c5c1a5e62a252a41291548e23 Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Thu, 13 Apr 2023 08:34:33 +0200 Subject: [PATCH 1/2] Derive Default for Track This allows the various demuxers to constructs the parts of Track they support. --- symphonia-core/src/formats.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/symphonia-core/src/formats.rs b/symphonia-core/src/formats.rs index 58158f31..47a1e129 100644 --- a/symphonia-core/src/formats.rs +++ b/symphonia-core/src/formats.rs @@ -133,7 +133,7 @@ pub struct CuePoint { /// A `Track` is an independently coded media bitstream. A media format may contain multiple tracks /// in one container. Each of those tracks are represented by one `Track`. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Track { /// A unique identifier for the track. pub id: u32, @@ -141,11 +141,13 @@ pub struct Track { pub codec_params: CodecParameters, /// The language of the track. May be unknown. pub language: Option, + /// The name of the track. May be unknown. + pub name: Option, } impl Track { pub fn new(id: u32, codec_params: CodecParameters) -> Self { - Track { id, codec_params, language: None } + Track { id, codec_params, language: None, name: None } } } From 626bf06778384aca2f1d8173f7e3adf58cbbf788 Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Thu, 13 Apr 2023 08:38:47 +0200 Subject: [PATCH 2/2] Implement track name for MKV This adds Track::name as an Optional. This in turn is used by MKV demuxer to surface the track name. --- symphonia-format-mkv/src/demuxer.rs | 2 ++ symphonia-format-mkv/src/segment.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/symphonia-format-mkv/src/demuxer.rs b/symphonia-format-mkv/src/demuxer.rs index ccbc7484..43fdca28 100644 --- a/symphonia-format-mkv/src/demuxer.rs +++ b/symphonia-format-mkv/src/demuxer.rs @@ -501,6 +501,8 @@ impl FormatReader for MkvReader { id: track_id, codec_params: codec_params.clone(), language: track.language, + name: track.name, + ..Default::default() }); states.insert( diff --git a/symphonia-format-mkv/src/segment.rs b/symphonia-format-mkv/src/segment.rs index bda51ad9..61c5f513 100644 --- a/symphonia-format-mkv/src/segment.rs +++ b/symphonia-format-mkv/src/segment.rs @@ -23,6 +23,7 @@ pub(crate) struct TrackElement { pub(crate) codec_private: Option>, pub(crate) audio: Option, pub(crate) default_duration: Option, + pub(crate) name: Option, } impl Element for TrackElement { @@ -36,6 +37,7 @@ impl Element for TrackElement { let mut codec_private = None; let mut codec_id = None; let mut default_duration = None; + let mut name = None; let mut it = header.children(reader); while let Some(header) = it.read_header()? { @@ -61,6 +63,9 @@ impl Element for TrackElement { ElementType::DefaultDuration => { default_duration = Some(it.read_u64()?); } + ElementType::Name => { + name = Some(it.read_string()?); + } other => { log::debug!("ignored element {:?}", other); } @@ -75,6 +80,7 @@ impl Element for TrackElement { codec_private, audio, default_duration, + name, }) } }