| 184 | } |
| 185 | |
| 186 | fn encode_to_message(&mut self, input: EncodeInput, ms: i64) -> ResultType<VideoFrame> { |
| 187 | let mut frames = Vec::new(); |
| 188 | for ref frame in self |
| 189 | .encode(ms, input.yuv()?, STRIDE_ALIGN) |
| 190 | .with_context(|| "Failed to encode")? |
| 191 | { |
| 192 | frames.push(VpxEncoder::create_frame(frame)); |
| 193 | } |
| 194 | for ref frame in self.flush().with_context(|| "Failed to flush")? { |
| 195 | frames.push(VpxEncoder::create_frame(frame)); |
| 196 | } |
| 197 | |
| 198 | // to-do: flush periodically, e.g. 1 second |
| 199 | if frames.len() > 0 { |
| 200 | Ok(VpxEncoder::create_video_frame(self.id, frames)) |
| 201 | } else { |
| 202 | Err(anyhow!("no valid frame")) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | fn yuvfmt(&self) -> crate::EncodeYuvFormat { |
| 207 | self.yuvfmt.clone() |