edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! Whole-stream decoding: an IVF file in, decoded pictures out. |
| 2 | //! |
| 3 | //! VP8 frames are not self-delimiting — a bare frame is a 3-byte |
| 4 | //! uncompressed tag followed by partitions whose total size only the |
| 5 | //! container knows — so the whole-stream API takes the stream in the |
| 6 | //! container VP8 actually ships in: IVF (the RFC's companion container, |
| 7 | //! `DKIF`/`VP80`; also what vpxenc, ffmpeg and the WebM toolchain emit |
| 8 | //! for raw VP8 elementaries). Single frames from any other demuxer feed |
| 9 | //! [`crate::decode::Decoder::decode`] directly. |
| 10 | //! |
| 11 | //! The shape mirrors `ec_av1::stream`: [`decode_stream`] collects every |
| 12 | //! shown picture into a `Vec`, and [`decode_stream_with`] hands each |
| 13 | //! picture to a sink the moment it exists. |
| 14 | |
| 15 | use crate; |
| 16 | use crate::; |
| 17 | |
| 18 | /// The IVF file magic, `DKIF`. |
| 19 | const DKIF: & = b"DKIF"; |
| 20 | /// The fourcc for VP8 video (`VP80`; `VP8L`/`VP8x` are WebP-lossless/alpha). |
| 21 | const VP80: & = b"VP80"; |
| 22 | |
| 23 | /// One demuxed IVF frame: presentation timestamp plus the compressed |
| 24 | /// VP8 payload. |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | /// Split an IVF byte stream into its frames, validating the container |
| 31 | /// envelope (magic, fourcc, framing arithmetic) as [`Error`]s rather |
| 32 | /// than panics. |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | /// Decode every frame in an IVF VP8 stream, in presentation order. |
| 89 | /// |
| 90 | /// The stream must start with a key frame; hidden frames (alternate |
| 91 | /// references, `show_frame == 0`) update the reference buffers but are |
| 92 | /// not part of the output, exactly as a player would not display them. |
| 93 | /// |
| 94 | /// # Errors |
| 95 | /// Returns an error when the container is truncated or not VP80 (as |
| 96 | /// [`demux`] reports it), when a frame is malformed (as |
| 97 | /// [`crate::decode::Decoder::decode`] reports it), or when an inter |
| 98 | /// frame appears before any key frame has supplied references. |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | /// Streaming form of [`decode_stream`]: hand every shown picture to |
| 109 | /// `sink` the moment it exists and drop it right after, so peak memory |
| 110 | /// is one output picture plus the reference frames instead of the whole |
| 111 | /// decoded stream. `decode_stream` itself is this function collecting |
| 112 | /// into a `Vec`. |
| 113 | /// |
| 114 | /// `sink` is called with the picture, the decode-order index of the |
| 115 | /// coded frame it came from, and the IVF presentation timestamp. A |
| 116 | /// hidden frame (`show_frame == 0`) updates the decoder state but |
| 117 | /// produces no picture, so the sink is not called for it. An `Err` the |
| 118 | /// sink returns aborts the decode and is returned unchanged. |
| 119 | /// |
| 120 | /// # Errors |
| 121 | /// As [`decode_stream`], plus whatever `sink` returns. |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 |