From a7804891ae1a0be8cf6c37e60953b4f63fdd2150 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Fri, 29 Sep 2017 00:12:49 -0400 Subject: [PATCH] add chunk mutators/utilities --- src/chunk.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/chunk.rs b/src/chunk.rs index cfa4506..072f902 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -21,6 +21,18 @@ pub enum Chunk = Vec> { } impl> Chunk { + pub fn new_cluster_head(timecode: u64) -> Chunk { + let mut chunk = Chunk::ClusterHead { + keyframe: false, + start: 0, + end: 0, + bytes: [0;16], + bytes_used: 0 + }; + chunk.update_timecode(timecode); + chunk + } + pub fn update_timecode(&mut self, timecode: u64) { if let &mut Chunk::ClusterHead {ref mut start, ref mut end, ref mut bytes, ref mut bytes_used, ..} = self { let delta = *end - *start; @@ -33,6 +45,18 @@ impl> Chunk { *bytes_used = cursor.position() as u8; } } + pub fn extend_timespan(&mut self, timecode: u64) { + if let &mut Chunk::ClusterHead {start, ref mut end, ..} = self { + if timecode > start { + *end = timecode; + } + } + } + pub fn mark_keyframe(&mut self, new_keyframe: bool) { + if let &mut Chunk::ClusterHead {ref mut keyframe, ..} = self { + *keyframe = new_keyframe; + } + } } impl> AsRef<[u8]> for Chunk {