ivf-0.1.3/.cargo_vcs_info.json0000644000000001410000000000100116150ustar { "git": { "sha1": "f0b611ec52f226ed020625b2f98f4730ce394347" }, "path_in_vcs": "ivf" }ivf-0.1.3/CHANGELOG.md000064400000000000000000000001161046102023000122200ustar 00000000000000## Version 0.1.2 - Fix additional clippy lints - Update to Rust Version 2021 ivf-0.1.3/Cargo.toml0000644000000013120000000000100076140ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "ivf" version = "0.1.3" authors = ["Thomas Daede "] description = "Simple ivf muxer" homepage = "https://github.com/xiph/rav1e" license = "BSD-2-Clause" [dependencies.bitstream-io] version = "2" ivf-0.1.3/Cargo.toml.orig000064400000000000000000000003571046102023000133050ustar 00000000000000[package] name = "ivf" version = "0.1.3" authors = ["Thomas Daede "] edition = "2021" description = "Simple ivf muxer" license = "BSD-2-Clause" homepage = "https://github.com/xiph/rav1e" [dependencies] bitstream-io = "2" ivf-0.1.3/LICENSE000064400000000000000000000024641046102023000114240ustar 00000000000000BSD 2-Clause License Copyright (c) 2017-2021, the rav1e contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ivf-0.1.3/src/lib.rs000064400000000000000000000121701046102023000123150ustar 00000000000000// Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved // Copyright (c) 2017-2022, The rav1e contributors. All rights reserved // // This source code is subject to the terms of the BSD 2 Clause License and // the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License // was not distributed with this source code in the LICENSE file, you can // obtain it at www.aomedia.org/license/software. If the Alliance for Open // Media Patent License 1.0 was not distributed with this source code in the // PATENTS file, you can obtain it at www.aomedia.org/license/patent. #![deny(bare_trait_objects)] #![allow(clippy::cast_lossless)] #![allow(clippy::cast_ptr_alignment)] #![allow(clippy::cognitive_complexity)] #![allow(clippy::needless_range_loop)] #![allow(clippy::too_many_arguments)] #![allow(clippy::verbose_bit_mask)] #![allow(clippy::unreadable_literal)] #![allow(clippy::many_single_char_names)] // Performance lints #![warn(clippy::linkedlist)] #![warn(clippy::missing_const_for_fn)] #![warn(clippy::mutex_integer)] #![warn(clippy::suboptimal_flops)] // Correctness lints #![warn(clippy::expl_impl_clone_on_copy)] #![warn(clippy::mem_forget)] #![warn(clippy::path_buf_push_overwrite)] // Clarity/formatting lints #![warn(clippy::map_flatten)] #![warn(clippy::mut_mut)] #![warn(clippy::needless_borrow)] #![warn(clippy::needless_continue)] #![warn(clippy::range_plus_one)] // Documentation lints #![warn(clippy::doc_markdown)] #![warn(clippy::missing_errors_doc)] #![warn(clippy::missing_panics_doc)] /// Simple ivf muxer /// use bitstream_io::{BitRead, BitReader, BitWrite, BitWriter, LittleEndian}; use std::io; /// # Panics /// /// - If header cannot be written to output file. pub fn write_ivf_header( output_file: &mut dyn io::Write, width: usize, height: usize, framerate_num: usize, framerate_den: usize, ) { let mut bw = BitWriter::endian(output_file, LittleEndian); bw.write_bytes(b"DKIF").unwrap(); bw.write(16, 0).unwrap(); // version bw.write(16, 32).unwrap(); // version bw.write_bytes(b"AV01").unwrap(); bw.write(16, width as u16).unwrap(); bw.write(16, height as u16).unwrap(); bw.write(32, framerate_num as u32).unwrap(); bw.write(32, framerate_den as u32).unwrap(); bw.write(32, 0).unwrap(); bw.write(32, 0).unwrap(); } /// # Panics /// /// - If frame cannot be written to output file. pub fn write_ivf_frame( output_file: &mut dyn io::Write, pts: u64, data: &[u8], ) { let mut bw = BitWriter::endian(output_file, LittleEndian); bw.write(32, data.len() as u32).unwrap(); bw.write(64, pts).unwrap(); bw.write_bytes(data).unwrap(); } #[derive(Debug, PartialEq, Eq)] pub struct Header { pub tag: [u8; 4], pub w: u16, pub h: u16, pub timebase_num: u32, pub timebase_den: u32, } /// # Errors /// /// - Returns `io::Error` if packet cannot be read /// - Returns `io::ErrorKind::InvalidData` if header signature is invalid pub fn read_header(r: &mut dyn io::Read) -> io::Result
{ let mut br = BitReader::endian(r, LittleEndian); let mut signature = [0u8; 4]; let mut tag = [0u8; 4]; br.read_bytes(&mut signature)?; if &signature != b"DKIF" { return Err(io::ErrorKind::InvalidData.into()); } let _v0: u16 = br.read(16)?; let _v1: u16 = br.read(16)?; br.read_bytes(&mut tag)?; let w: u16 = br.read(16)?; let h: u16 = br.read(16)?; let timebase_den: u32 = br.read(32)?; let timebase_num: u32 = br.read(32)?; let _: u32 = br.read(32)?; let _: u32 = br.read(32)?; Ok(Header { tag, w, h, timebase_num, timebase_den }) } pub struct Packet { pub data: Box<[u8]>, pub pts: u64, } /// # Errors /// /// - Returns `io::Error` if packet cannot be read pub fn read_packet(r: &mut dyn io::Read) -> io::Result { let mut br = BitReader::endian(r, LittleEndian); let len: u32 = br.read(32)?; let pts: u64 = br.read(64)?; let mut buf = vec![0u8; len as usize]; br.read_bytes(&mut buf)?; Ok(Packet { data: buf.into_boxed_slice(), pts }) } #[cfg(test)] mod tests { use crate::{read_header, read_packet}; use std::io::{BufReader, ErrorKind::InvalidData}; #[test] fn read_invalid_headers() { // Invalid magic. let mut br = BufReader::new(&b"FIKD"[..]); let result = read_header(&mut br).map_err(|e| e.kind()); let expected = Err(InvalidData); assert_eq!(result, expected); } #[test] fn read_valid_headers() { let bytes: [u8; 32] = [ 0x44, 0x4b, 0x49, 0x46, 0x00, 0x00, 0x20, 0x00, 0x41, 0x56, 0x30, 0x31, 0x80, 0x07, 0x38, 0x04, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; let mut br = BufReader::new(&bytes[..]); let header = read_header(&mut br).unwrap(); assert_eq!(header.tag, [0x41, 0x56, 0x30, 0x31]); assert_eq!(header.w, 1920); assert_eq!(header.h, 1080); assert_eq!(header.timebase_num, 1); assert_eq!(header.timebase_den, 24); } #[test] fn read_valid_packet() { let bytes: [u8; 13] = [ 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, ]; let mut br = BufReader::new(&bytes[..]); let packet = read_packet(&mut br).unwrap(); assert_eq!(packet.pts, 3u64); } }