1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-06-10 17:09:22 +00:00

chore(Mp4Box): use a trait function for to_json

This commit is contained in:
Stuart Woodbury 2023-07-05 11:52:19 -04:00
parent ff9e75922b
commit 0fdd2d16b4
45 changed files with 7 additions and 197 deletions

View file

@ -67,10 +67,6 @@ impl Mp4Box for Avc1Box {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"data_reference_index={} width={} height={} frame_count={}",
@ -199,10 +195,6 @@ impl Mp4Box for AvcCBox {
size
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("avc_profile_indication={}", self.avc_profile_indication);
Ok(s)

View file

@ -33,10 +33,6 @@ impl Mp4Box for Co64Box {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("entries_count={}", self.entries.len());
Ok(s)

View file

@ -39,10 +39,6 @@ impl Mp4Box for CttsBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("entries_count={}", self.entries.len());
Ok(s)

View file

@ -36,10 +36,6 @@ impl Mp4Box for DataBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("type={:?} len={}", self.data_type, self.data.len());
Ok(s)

View file

@ -27,10 +27,6 @@ impl Mp4Box for DinfBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)
@ -131,10 +127,6 @@ impl Mp4Box for DrefBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)
@ -248,10 +240,6 @@ impl Mp4Box for UrlBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("location={}", self.location);
Ok(s)

View file

@ -36,10 +36,6 @@ impl Mp4Box for EdtsBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)

View file

@ -47,10 +47,6 @@ impl Mp4Box for ElstBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("elst_entries={}", self.entries.len());
Ok(s)

View file

@ -48,10 +48,6 @@ impl Mp4Box for EmsgBox {
+ self.message_data.len() as u64
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("id={} value={}", self.id, self.value);
Ok(s)

View file

@ -30,10 +30,6 @@ impl Mp4Box for FtypBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let mut compatible_brands = Vec::new();
for brand in self.compatible_brands.iter() {

View file

@ -31,10 +31,6 @@ impl Mp4Box for HdlrBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("handler_type={} name={}", self.handler_type, self.name);
Ok(s)

View file

@ -67,10 +67,6 @@ impl Mp4Box for Hev1Box {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"data_reference_index={} width={} height={} frame_count={}",
@ -180,10 +176,6 @@ impl Mp4Box for HvcCBox {
HEADER_SIZE + 1
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("configuration_version={}", self.configuration_version);
Ok(s)

View file

@ -36,10 +36,6 @@ impl Mp4Box for IlstBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("item_count={}", self.items.len());
Ok(s)

View file

@ -57,10 +57,6 @@ impl Mp4Box for MdhdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"creation_time={} timescale={} duration={} language={}",

View file

@ -30,10 +30,6 @@ impl Mp4Box for MdiaBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)

View file

@ -37,10 +37,6 @@ impl Mp4Box for MehdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("fragment_duration={}", self.fragment_duration);
Ok(s)

View file

@ -56,10 +56,6 @@ impl Mp4Box for MetaBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = match self {
Self::Mdir { .. } => "hdlr=ilst".to_string(),

View file

@ -40,10 +40,6 @@ impl Mp4Box for MfhdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("sequence_number={}", self.sequence_number);
Ok(s)

View file

@ -44,10 +44,6 @@ impl Mp4Box for MinfBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)

View file

@ -57,6 +57,7 @@
//!
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use serde::Serialize;
use std::convert::TryInto;
use std::io::{Read, Seek, SeekFrom, Write};
@ -206,7 +207,12 @@ boxtype! {
pub trait Mp4Box: Sized {
fn box_type(&self) -> BoxType;
fn box_size(&self) -> u64;
fn to_json(&self) -> Result<String>;
fn to_json(&self) -> Result<String>
where
Self: Serialize,
{
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String>;
}

View file

@ -35,10 +35,6 @@ impl Mp4Box for MoofBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("trafs={}", self.trafs.len());
Ok(s)

View file

@ -51,10 +51,6 @@ impl Mp4Box for MoovBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("traks={}", self.traks.len());
Ok(s)

View file

@ -60,10 +60,6 @@ impl Mp4Box for Mp4aBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"channel_count={} sample_size={} sample_rate={}",
@ -169,10 +165,6 @@ impl Mp4Box for EsdsBox {
+ ESDescriptor::desc_size() as u64
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
Ok(String::new())
}

View file

@ -29,10 +29,6 @@ impl Mp4Box for MvexBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)

View file

@ -66,10 +66,6 @@ impl Mp4Box for MvhdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"creation_time={} timescale={} duration={} rate={} volume={}, matrix={}, next_track_id={}",

View file

@ -42,10 +42,6 @@ impl Mp4Box for SmhdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("balance={}", self.balance.value());
Ok(s)

View file

@ -22,10 +22,6 @@ impl Mp4Box for SounBox {
todo!()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
todo!()
}

View file

@ -63,10 +63,6 @@ impl Mp4Box for StblBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)

View file

@ -33,10 +33,6 @@ impl Mp4Box for StcoBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("entries={}", self.entries.len());
Ok(s)

View file

@ -41,10 +41,6 @@ impl Mp4Box for StscBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("entries={}", self.entries.len());
Ok(s)

View file

@ -58,10 +58,6 @@ impl Mp4Box for StsdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)

View file

@ -33,10 +33,6 @@ impl Mp4Box for StssBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("entries={}", self.entries.len());
Ok(s)

View file

@ -35,10 +35,6 @@ impl Mp4Box for StszBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"sample_size={} sample_count={} sample_sizes={}",

View file

@ -39,10 +39,6 @@ impl Mp4Box for SttsBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("entries={}", self.entries.len());
Ok(s)

View file

@ -36,10 +36,6 @@ impl Mp4Box for TfdtBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("base_media_decode_time={}", self.base_media_decode_time);
Ok(s)

View file

@ -57,10 +57,6 @@ impl Mp4Box for TfhdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("track_id={}", self.track_id);
Ok(s)

View file

@ -125,10 +125,6 @@ impl Mp4Box for TkhdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"creation_time={} track_id={} duration={} layer={} volume={} matrix={} width={} height={}",

View file

@ -35,10 +35,6 @@ impl Mp4Box for TrafBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)

View file

@ -43,10 +43,6 @@ impl Mp4Box for TrakBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = String::new();
Ok(s)

View file

@ -34,10 +34,6 @@ impl Mp4Box for TrexBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"track_id={} default_sample_duration={}",

View file

@ -68,10 +68,6 @@ impl Mp4Box for TrunBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("sample_size={}", self.sample_count);
Ok(s)

View file

@ -61,10 +61,6 @@ impl Mp4Box for Tx3gBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!("data_reference_index={} horizontal_justification={} vertical_justification={} rgba={}{}{}{}",
self.data_reference_index, self.horizontal_justification,

View file

@ -34,10 +34,6 @@ impl Mp4Box for UdtaBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
Ok(String::new())
}

View file

@ -38,10 +38,6 @@ impl Mp4Box for VmhdBox {
self.get_size()
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
let s = format!(
"graphics_mode={} op_color={}{}{}",

View file

@ -74,10 +74,6 @@ impl Mp4Box for Vp09Box {
0x6A
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
Ok(format!("{self:?}"))
}

View file

@ -31,10 +31,6 @@ impl Mp4Box for VpccBox {
HEADER_SIZE + HEADER_EXT_SIZE + 8
}
fn to_json(&self) -> Result<String> {
serde_json::to_string(&self).map_err(|e| crate::error::Error::IoError(e.into()))
}
fn summary(&self) -> Result<String> {
Ok(format!("{self:?}"))
}