mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-06-10 17:09:22 +00:00
Add custom serializer for FixedPoint types.
This commit is contained in:
parent
e554e61557
commit
8f8d14317a
|
@ -9,7 +9,11 @@ pub struct Avc1Box {
|
|||
pub data_reference_index: u16,
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
|
||||
#[serde(with = "value_u32")]
|
||||
pub horizresolution: FixedPointU16,
|
||||
|
||||
#[serde(with = "value_u32")]
|
||||
pub vertresolution: FixedPointU16,
|
||||
pub frame_count: u16,
|
||||
pub depth: u16,
|
||||
|
|
|
@ -9,7 +9,11 @@ pub struct Hev1Box {
|
|||
pub data_reference_index: u16,
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
|
||||
#[serde(with = "value_u32")]
|
||||
pub horizresolution: FixedPointU16,
|
||||
|
||||
#[serde(with = "value_u32")]
|
||||
pub vertresolution: FixedPointU16,
|
||||
pub frame_count: u16,
|
||||
pub depth: u16,
|
||||
|
|
|
@ -222,6 +222,52 @@ pub fn write_zeros<W: Write>(writer: &mut W, size: u64) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
mod value_u32 {
|
||||
use crate::types::FixedPointU16;
|
||||
use serde::{self, Serializer};
|
||||
|
||||
pub fn serialize<S>(
|
||||
fixed: &FixedPointU16,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_u16(fixed.value())
|
||||
}
|
||||
}
|
||||
|
||||
mod value_i16 {
|
||||
use crate::types::FixedPointI8;
|
||||
use serde::{self, Serializer};
|
||||
|
||||
pub fn serialize<S>(
|
||||
fixed: &FixedPointI8,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_i8(fixed.value())
|
||||
}
|
||||
}
|
||||
|
||||
mod value_u8 {
|
||||
use crate::types::FixedPointU8;
|
||||
use serde::{self, Serializer};
|
||||
|
||||
pub fn serialize<S>(
|
||||
fixed: &FixedPointU8,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_u8(fixed.value())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -9,6 +9,8 @@ pub struct Mp4aBox {
|
|||
pub data_reference_index: u16,
|
||||
pub channelcount: u16,
|
||||
pub samplesize: u16,
|
||||
|
||||
#[serde(with = "value_u32")]
|
||||
pub samplerate: FixedPointU16,
|
||||
pub esds: Option<EsdsBox>,
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ pub struct MvhdBox {
|
|||
pub modification_time: u64,
|
||||
pub timescale: u32,
|
||||
pub duration: u64,
|
||||
|
||||
#[serde(with = "value_u32")]
|
||||
pub rate: FixedPointU16,
|
||||
}
|
||||
|
||||
|
@ -61,8 +63,8 @@ impl Mp4Box for MvhdBox {
|
|||
}
|
||||
|
||||
fn summary(&self) -> Result<String> {
|
||||
let s = format!("creation_time={} timescale={} duration={}",
|
||||
self.creation_time, self.timescale, self.duration);
|
||||
let s = format!("creation_time={} timescale={} duration={} rate={}",
|
||||
self.creation_time, self.timescale, self.duration, self.rate.value());
|
||||
Ok(s)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ use crate::mp4box::*;
|
|||
pub struct SmhdBox {
|
||||
pub version: u8,
|
||||
pub flags: u32,
|
||||
|
||||
#[serde(with = "value_i16")]
|
||||
pub balance: FixedPointI8,
|
||||
}
|
||||
|
||||
|
|
|
@ -17,11 +17,19 @@ use crate::mp4box::{
|
|||
pub struct StblBox {
|
||||
pub stsd: StsdBox,
|
||||
pub stts: SttsBox,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ctts: Option<CttsBox>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stss: Option<StssBox>,
|
||||
pub stsc: StscBox,
|
||||
pub stsz: StszBox,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stco: Option<StcoBox>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub co64: Option<Co64Box>,
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,17 @@ use crate::mp4box::{avc1::Avc1Box, hev1::Hev1Box, mp4a::Mp4aBox, tx3g::Tx3gBox};
|
|||
pub struct StsdBox {
|
||||
pub version: u8,
|
||||
pub flags: u32,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub avc1: Option<Avc1Box>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub hev1: Option<Hev1Box>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mp4a: Option<Mp4aBox>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tx3g: Option<Tx3gBox>,
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,15 @@ pub struct TkhdBox {
|
|||
pub duration: u64,
|
||||
pub layer: u16,
|
||||
pub alternate_group: u16,
|
||||
|
||||
#[serde(with = "value_u8")]
|
||||
pub volume: FixedPointU8,
|
||||
pub matrix: Matrix,
|
||||
|
||||
#[serde(with = "value_u32")]
|
||||
pub width: FixedPointU16,
|
||||
|
||||
#[serde(with = "value_u32")]
|
||||
pub height: FixedPointU16,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue