mirror of
https://github.com/alfg/mp4-rust.git
synced 2025-03-30 08:45:26 +00:00
remove duplicated code.
This commit is contained in:
parent
4df1097948
commit
71f0f78ae6
24 changed files with 48 additions and 129 deletions
|
@ -55,11 +55,11 @@ impl Avc1Box {
|
|||
|
||||
impl Mp4Box for Avc1Box {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::Avc1Box
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + 8 + 70 + self.avcc.box_size()
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ impl Co64Box {
|
|||
|
||||
impl Mp4Box for Co64Box {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::Co64Box
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 4 + (8 * self.entries.len() as u64)
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,11 +28,11 @@ pub struct CttsEntry {
|
|||
|
||||
impl Mp4Box for CttsBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::CttsBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 4 + (8 * self.entries.len() as u64)
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,15 +28,11 @@ impl EdtsBox {
|
|||
|
||||
impl Mp4Box for EdtsBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::EdtsBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE;
|
||||
if let Some(ref elst) = self.elst {
|
||||
size += elst.box_size();
|
||||
}
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,18 +37,11 @@ impl ElstBox {
|
|||
|
||||
impl Mp4Box for ElstBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::ElstBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE + HEADER_EXT_SIZE + 4;
|
||||
if self.version == 1 {
|
||||
size += self.entries.len() as u64 * 20;
|
||||
} else {
|
||||
assert_eq!(self.version, 0);
|
||||
size += self.entries.len() as u64 * 12;
|
||||
}
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ impl FtypBox {
|
|||
|
||||
impl Mp4Box for FtypBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::FtypBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + 8 + (4 * self.compatible_brands.len() as u64)
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ impl HdlrBox {
|
|||
|
||||
impl Mp4Box for HdlrBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::HdlrBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 20 + self.name.len() as u64 + 1
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,20 +50,11 @@ impl Default for MdhdBox {
|
|||
|
||||
impl Mp4Box for MdhdBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::MdhdBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE + HEADER_EXT_SIZE;
|
||||
|
||||
if self.version == 1 {
|
||||
size += 28;
|
||||
} else {
|
||||
assert_eq!(self.version, 0);
|
||||
size += 16;
|
||||
}
|
||||
size += 4;
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ impl MdiaBox {
|
|||
|
||||
impl Mp4Box for MdiaBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::MdiaBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + self.mdhd.box_size() + self.hdlr.box_size() + self.minf.box_size()
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,19 +30,11 @@ impl MinfBox {
|
|||
|
||||
impl Mp4Box for MinfBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::MinfBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE;
|
||||
if let Some(ref vmhd) = self.vmhd {
|
||||
size += vmhd.box_size();
|
||||
}
|
||||
if let Some(ref smhd) = self.smhd {
|
||||
size += smhd.box_size();
|
||||
}
|
||||
size += self.stbl.box_size();
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,15 +25,11 @@ impl MoovBox {
|
|||
|
||||
impl Mp4Box for MoovBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::MoovBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE + self.mvhd.box_size();
|
||||
for trak in self.traks.iter() {
|
||||
size += trak.box_size();
|
||||
}
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,15 +50,11 @@ impl Mp4aBox {
|
|||
|
||||
impl Mp4Box for Mp4aBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::Mp4aBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE + 8 + 20;
|
||||
if let Some(ref esds) = self.esds {
|
||||
size += esds.box_size();
|
||||
}
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,19 +48,11 @@ impl Default for MvhdBox {
|
|||
|
||||
impl Mp4Box for MvhdBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::MvhdBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE + HEADER_EXT_SIZE;
|
||||
if self.version == 1 {
|
||||
size += 28;
|
||||
} else {
|
||||
assert_eq!(self.version, 0);
|
||||
size += 16;
|
||||
}
|
||||
size += 80;
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,11 +32,11 @@ impl Default for SmhdBox {
|
|||
|
||||
impl Mp4Box for SmhdBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::SmhdBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 4
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,28 +47,11 @@ impl StblBox {
|
|||
|
||||
impl Mp4Box for StblBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::StblBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE;
|
||||
size += self.stsd.box_size();
|
||||
size += self.stts.box_size();
|
||||
if let Some(ref ctts) = self.ctts {
|
||||
size += ctts.box_size();
|
||||
}
|
||||
if let Some(ref stss) = self.stss {
|
||||
size += stss.box_size();
|
||||
}
|
||||
size += self.stsc.box_size();
|
||||
size += self.stsz.box_size();
|
||||
if let Some(ref stco) = self.stco {
|
||||
size += stco.box_size();
|
||||
}
|
||||
if let Some(ref co64) = self.co64 {
|
||||
size += co64.box_size();
|
||||
}
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ impl StcoBox {
|
|||
|
||||
impl Mp4Box for StcoBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::StcoBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 4 + (4 * self.entries.len() as u64)
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,11 +30,11 @@ pub struct StscEntry {
|
|||
|
||||
impl Mp4Box for StscBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::StscBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 4 + (12 * self.entries.len() as u64)
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,17 +30,11 @@ impl StsdBox {
|
|||
|
||||
impl Mp4Box for StsdBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::StsdBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE + HEADER_EXT_SIZE + 4;
|
||||
if let Some(ref avc1) = self.avc1 {
|
||||
size += avc1.box_size();
|
||||
} else if let Some(ref mp4a) = self.mp4a {
|
||||
size += mp4a.box_size();
|
||||
}
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ impl StssBox {
|
|||
|
||||
impl Mp4Box for StssBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::StssBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 4 + (4 * self.entries.len() as u64)
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,11 @@ impl StszBox {
|
|||
|
||||
impl Mp4Box for StszBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::StszBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 8 + (4 * self.sample_sizes.len() as u64)
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,11 +28,11 @@ pub struct SttsEntry {
|
|||
|
||||
impl Mp4Box for SttsBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::SttsBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 4 + (8 * self.entries.len() as u64)
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,19 +79,11 @@ impl TkhdBox {
|
|||
|
||||
impl Mp4Box for TkhdBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::TkhdBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE + HEADER_EXT_SIZE;
|
||||
if self.version == 1 {
|
||||
size += 32;
|
||||
} else {
|
||||
assert_eq!(self.version, 0);
|
||||
size += 20;
|
||||
}
|
||||
size += 60;
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,17 +28,11 @@ impl TrakBox {
|
|||
|
||||
impl Mp4Box for TrakBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::TrakBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
let mut size = HEADER_SIZE;
|
||||
size += self.tkhd.box_size();
|
||||
if let Some(ref edts) = self.edts {
|
||||
size += edts.box_size();
|
||||
}
|
||||
size += self.mdia.box_size();
|
||||
size
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,11 +30,11 @@ impl VmhdBox {
|
|||
|
||||
impl Mp4Box for VmhdBox {
|
||||
fn box_type(&self) -> BoxType {
|
||||
BoxType::VmhdBox
|
||||
return self.get_type();
|
||||
}
|
||||
|
||||
fn box_size(&self) -> u64 {
|
||||
HEADER_SIZE + HEADER_EXT_SIZE + 8
|
||||
return self.get_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue