prettify the chunker match blocks a bit
This commit is contained in:
parent
d3b147f8ea
commit
e6d8b58492
1 changed files with 64 additions and 61 deletions
33
src/chunk.rs
33
src/chunk.rs
|
@ -144,7 +144,8 @@ impl<I: Buf, S: Stream<Item = Result<I, WebmetroError>> + Unpin> Stream for Webm
|
|||
Err(passthru) => return Ready(Some(Err(passthru))),
|
||||
Ok(Async::NotReady) => return Pending,
|
||||
Ok(Async::Ready(None)) => return Ready(None),
|
||||
Ok(Async::Ready(Some(WebmElement::Cluster))) => {
|
||||
Ok(Async::Ready(Some(element))) => match element {
|
||||
WebmElement::Cluster => {
|
||||
let liberated_buffer = mem::replace(buffer, Cursor::new(Vec::new()));
|
||||
let header_chunk = Chunk::Headers {bytes: Bytes::from(liberated_buffer.into_inner())};
|
||||
|
||||
|
@ -154,23 +155,24 @@ impl<I: Buf, S: Stream<Item = Result<I, WebmetroError>> + Unpin> Stream for Webm
|
|||
);
|
||||
return Ready(Some(Ok(header_chunk)));
|
||||
},
|
||||
Ok(Async::Ready(Some(WebmElement::Info))) => {},
|
||||
Ok(Async::Ready(Some(WebmElement::Void))) => {},
|
||||
Ok(Async::Ready(Some(WebmElement::Unknown(_)))) => {},
|
||||
Ok(Async::Ready(Some(element))) => {
|
||||
WebmElement::Info => {},
|
||||
WebmElement::Void => {},
|
||||
WebmElement::Unknown(_) => {},
|
||||
element => {
|
||||
if let Err(err) = encode(element, buffer, chunker.buffer_size_limit) {
|
||||
chunker.state = ChunkerState::End;
|
||||
return Ready(Some(Err(err)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ChunkerState::BuildingCluster(ref mut cluster_head, ref mut buffer) => {
|
||||
match chunker.source.poll_event(cx) {
|
||||
Err(passthru) => return Ready(Some(Err(passthru))),
|
||||
Ok(Async::NotReady) => return Pending,
|
||||
Ok(Async::Ready(Some(element @ WebmElement::EbmlHead)))
|
||||
| Ok(Async::Ready(Some(element @ WebmElement::Segment))) => {
|
||||
Ok(Async::Ready(Some(element))) => match element {
|
||||
WebmElement::EbmlHead | WebmElement::Segment => {
|
||||
let liberated_cluster_head = mem::replace(cluster_head, ClusterHead::new(0));
|
||||
let liberated_buffer = mem::replace(buffer, Cursor::new(Vec::new()));
|
||||
|
||||
|
@ -188,18 +190,18 @@ impl<I: Buf, S: Stream<Item = Result<I, WebmetroError>> + Unpin> Stream for Webm
|
|||
return Ready(Some(Err(err)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Async::Ready(Some(WebmElement::Cluster))) => {
|
||||
},
|
||||
WebmElement::Cluster => {
|
||||
let liberated_cluster_head = mem::replace(cluster_head, ClusterHead::new(0));
|
||||
let liberated_buffer = mem::replace(buffer, Cursor::new(Vec::new()));
|
||||
|
||||
chunker.state = ChunkerState::EmittingClusterBody(liberated_buffer.into_inner());
|
||||
return Ready(Some(Ok(Chunk::ClusterHead(liberated_cluster_head))));
|
||||
},
|
||||
Ok(Async::Ready(Some(WebmElement::Timecode(timecode)))) => {
|
||||
WebmElement::Timecode(timecode) => {
|
||||
cluster_head.update_timecode(timecode);
|
||||
},
|
||||
Ok(Async::Ready(Some(WebmElement::SimpleBlock(ref block)))) => {
|
||||
WebmElement::SimpleBlock(ref block) => {
|
||||
if (block.flags & 0b10000000) != 0 {
|
||||
// TODO: this is incorrect, condition needs to also affirm we're the first video block of the cluster
|
||||
cluster_head.keyframe = true;
|
||||
|
@ -210,15 +212,16 @@ impl<I: Buf, S: Stream<Item = Result<I, WebmetroError>> + Unpin> Stream for Webm
|
|||
return Ready(Some(Err(err)));
|
||||
}
|
||||
},
|
||||
Ok(Async::Ready(Some(WebmElement::Info))) => {},
|
||||
Ok(Async::Ready(Some(WebmElement::Void))) => {},
|
||||
Ok(Async::Ready(Some(WebmElement::Unknown(_)))) => {},
|
||||
Ok(Async::Ready(Some(element))) => {
|
||||
WebmElement::Info => {},
|
||||
WebmElement::Void => {},
|
||||
WebmElement::Unknown(_) => {},
|
||||
element => {
|
||||
if let Err(err) = encode(element, buffer, chunker.buffer_size_limit) {
|
||||
chunker.state = ChunkerState::End;
|
||||
return Ready(Some(Err(err)));
|
||||
}
|
||||
},
|
||||
},
|
||||
Ok(Async::Ready(None)) => {
|
||||
// flush final Cluster on end of stream
|
||||
let liberated_cluster_head = mem::replace(cluster_head, ClusterHead::new(0));
|
||||
|
|
Loading…
Reference in a new issue