Skip to content

Commit

Permalink
EBML: Writing WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Oct 28, 2024
1 parent e37fe44 commit d085422
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lofty/src/ebml/read/segment_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ where
continue;
}

total_audio_data_size += (size.value() - u64::from(header_size));
total_audio_data_size += size.value() - u64::from(header_size);
},
ElementIdent::BlockGroup => read_block_group(
&mut children_reader.children(),
Expand Down Expand Up @@ -144,7 +144,7 @@ where
continue;
}

*total_audio_data_size += (size.value() - u64::from(header_size));
*total_audio_data_size += size.value() - u64::from(header_size);
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion lofty/src/ebml/read/segment_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ where

Ok(SimpleTag {
name: name.into(),
language,
language: language.unwrap_or_default(),
default,
value,
})
Expand Down
2 changes: 1 addition & 1 deletion lofty/src/ebml/read/segment_tracks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
_ => unreachable!("Unhandled child element in TrackEntry: {:?}", ident),
}
},
ElementReaderYield::Master((id, size)) => match id {
ElementReaderYield::Master((id, _size)) => match id {
ElementIdent::Audio => {
read_audio_settings(&mut children_reader.children(), parse_options, &mut track)?
},
Expand Down
40 changes: 38 additions & 2 deletions lofty/src/ebml/tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use tag_name::*;
pub use target::*;

use crate::config::{global_options, WriteOptions};
use crate::error::LoftyError;
use crate::error::{LoftyError, Result};
use crate::io::{FileLike, Length, Truncate};
use crate::picture::Picture;
use crate::tag::companion_tag::CompanionTag;
Expand All @@ -25,7 +25,6 @@ use crate::tag::{Accessor, MergeTag, SplitTag, TagExt, TagType};
use std::borrow::Cow;
use std::io::Write;
use std::ops::Deref;
use std::path::Path;

use lofty_attr::tag;

Expand Down Expand Up @@ -405,3 +404,40 @@ impl From<crate::tag::Tag> for MatroskaTag {
SplitTagRemainder::default().merge_tag(input)
}
}

pub(crate) struct MatroskaTagRef<'a, I, S>
where
I: Iterator<Item = TagRef<'a, S>>,
S: Iterator<Item = Cow<'a, SimpleTag<'a>>> + 'a,
{
tags: I,
}

impl<'a, I, S> From<&'a crate::tag::Tag> for MatroskaTagRef<'a, I, S>
where
I: Iterator<Item = TagRef<'a, S>>,
S: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
{
fn from(_tag: &'a crate::tag::Tag) -> Self {
todo!()
}
}

impl<'a, I, S> MatroskaTagRef<'a, I, S>
where
I: Iterator<Item = TagRef<'a, S>>,
S: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
{
pub(crate) fn write_to<F>(&mut self, _file: &mut F, _write_options: WriteOptions) -> Result<()>
where
F: FileLike,
LoftyError: From<<F as Truncate>::Error>,
LoftyError: From<<F as Length>::Error>,
{
todo!()
}

fn dump_to<W: Write>(&self, _writer: &mut W, _write_options: WriteOptions) -> Result<()> {
todo!()
}
}
10 changes: 10 additions & 0 deletions lofty/src/ebml/tag/tag.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::simple_tag::SimpleTag;
use super::target::{Target, TargetDescriptor, TargetType};

use std::borrow::Cow;

/// A single metadata descriptor.
///
/// This represents a `\Segment\Tags\Tag` element in the EBML tree. It contains a single [`Target`] and
Expand Down Expand Up @@ -119,3 +121,11 @@ impl Tag<'static> {
self.simple_tags.extend(other.simple_tags);
}
}

pub(crate) struct TagRef<'a, I>
where
I: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
{
pub(crate) targets: TargetDescriptor<'a>,
pub(crate) simple_tags: &'a mut I,
}
5 changes: 4 additions & 1 deletion lofty/src/ebml/tag/write/elements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(non_upper_case_globals)]

pub(super) mod attached_file;
mod simple_tag;
pub(super) mod simple_tag;
pub(super) mod tags;
pub(super) mod target;
36 changes: 36 additions & 0 deletions lofty/src/ebml/tag/write/elements/tags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::ebml::tag::write::{write_element, ElementWriterCtx, WriteableElement};
use crate::ebml::{ElementId, SimpleTag, TagRef};
use crate::io::FileLike;

use std::borrow::Cow;
use std::io::Cursor;

impl<'a, I> WriteableElement for TagRef<'a, I>
where
I: Iterator<Item = Cow<'a, SimpleTag<'a>>>,
{
const ID: ElementId = ElementId(0x7373);

fn write_element<F: FileLike>(
&self,
ctx: ElementWriterCtx,
writer: &mut F,
) -> crate::error::Result<()> {
let mut element_children = Cursor::new(Vec::new());
self.targets.write_element(ctx, &mut element_children)?;

// TODO
// for simple_tag in self.simple_tags {
// simple_tag.write_element(ctx, &mut element_children)?;
// }

write_element(
ctx,
Self::ID,
&element_children.get_ref().as_slice(),
writer,
)?;

Ok(())
}
}
1 change: 1 addition & 0 deletions lofty/tests/fuzz/ebmlfile_read_from.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit d085422

Please sign in to comment.