Write AVI files: hdrl with avih and one strl (strh, strf, strn, indx) per
stream, odml/dmlh, an interleaved movi and idx1. Past the RIFF limit
(default 1 GiB) the file continues in OpenDML RIFF AVIX extensions with
ix## standard indexes and an indx super index per stream.
- VideoSpec::for_codec builds the stream from CodecParams; MPEG-4 Part 2
is tagged FMP4.
- Audio is timed by bytes (PCM-style) or one packet per chunk.
- Bad options and chunks are errors; finish() closes a readable file
after a failed write.
Tests read the files back through this crate's demuxer by every index,
and through ffmpeg (decode identical to the sources, seeks through the
index, ffprobe fields), in one RIFF and across AVIX extensions. The
MPEG-4 encoder tests play its packets from an AVI file.
The SBR decoders now record the layout they were built for and are rebuilt when the
decoder's layout differs, instead of being cleared in set_layout. An access unit whose new
program config fails puts the layout back, and with it the SBR decoders still match.
Refs #1121
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A VARFIX pointer of 1 marks no transient envelope, like 0.
- A start at QMF channel 32 is valid; kx is checked once the crossover is known.
- The noise and harmonic gains take q / (1 + q) first, so two clamped levels no longer
overflow to infinity and NaN.
- A header that runs past its fill element is refused before it replaces the one in use.
- A new program config layout drops the SBR decoders, whose history was the old order's.
- The ffmpeg oracle requires a high band to compare on every channel but the 5.1 LFE.
Refs #1121
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aac::Decoder::set_sbr(true) decodes HE-AAC at twice the core rate with the
SBR tool of ISO/IEC 14496-3 §4.6.18: QMF analysis and synthesis, frequency
band tables, patching with LPC inverse filtering, envelope adjustment with
limiter, boost, noise and sinusoids. TrackDecoder uses it in place of the
2x upsampler. Tables are transcribed from ETSI ES 201 980 Annex I.
Matches ffmpeg's decoder on AudioToolbox HE-AAC streams of 1-6 channels:
the same 962-sample delay, ~54 dB SNR, high band level within 0.01 dB.
Parametric stereo is still not decoded.
Refs #1121
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The start of MPEG-2 encoding in craft_video::mpeg2 (feature
mpeg2-encode): progressive frame pictures, closed I/P GOPs, 4:2:0 Main
Profile and 4:2:2 Profile, constant quantiser or single-pass average
bitrate with adaptive quantisation, half-sample motion search.
The encoder shares the decoder's code tables, IDCT, dequantisation and
motion compensation, so the decoder outputs exactly the encoder's
reconstruction. B pictures, a VBV guarantee, interlaced coding and DVD
or broadcast presets are later steps of #1133.
The mpeg2 feature is split into mpeg2-decode and mpeg2-encode; mpeg2
still turns on both.
From the first review round:
- 468 (0x1D4) is CONVERT, with 3 arguments. [MS-XLSB]'s Ftab table has no row for it, though
its grammar lists convert-params among the fixed-argument functions; Excel writes
=CONVERT(1,"m","ft") in .xlsb as a PtgFunc calling 0x1D4 (observed in Excel). It was the only
unassigned number from 0x17C to 0x1E4. The module doc says it isn't the specification's row.
- A BrtShrFmla's tokens and extra data are borrowed from the worksheet part instead of copied: a
record may claim up to 256 MiB, and each shared formula is kept for the rest of the sheet, so
the copies could cost as much again as the part. BrtArrFmla's are used at once and borrowed too.
- A formula record's cell metadata goes with its formula: when the formula is kept as its value
(tokens the reader can't decode, an unreadable BrtArrFmla), the cell loses its `cm`, which
would otherwise mark a dynamic-array formula that isn't there. A value cell keeps its cell
metadata, as the file has it.
The CONVERT and cell-metadata tests fail without this commit. The Excel-saved workbook still
reads with all 33 formulas as in its .xlsx.
They were "token streams that are not decoded". The README now says what the decoder gives
(text in the file's spelling, shared and array kinds and ranges, cell metadata, each shared copy's
own text), what keeps its saved result and why, that the function table and printer are this
crate's own, and the binary_formula_text limit with the decoder's fixed bounds.
From gridcraft#3821's review (CodeRabbit, still open there): a shared formula's copies are
checked against the formula text allowance with the first cell's length, which a copy can
exceed. A copy that was decoded and printed, then kept as its value because it didn't fit, or
because it couldn't be decoded, charged nothing, so a file with many cells of one long shared
formula could repeat that work for each of them. The PR's case was GridCraft's 8,192-character
rejection, which isn't here; the allowance and decode failures are the same path.
After one such copy the group keeps every later copy as its value without decoding it, so a
group costs at most one wasted decode. A new test shows a later copy that would have fit kept
as its value; it fails without this commit.
A cell whose tokens are only PtgExp (row) + PtgExtraCol (column) belongs to the shared or array
formula starting there; its first cell is followed by BrtShrFmla or BrtArrFmla.
- Shared formulas: each cell's copy is decoded from the shared tokens at its own cell, as
[MS-XLSB] defines it (PtgRefN/PtgAreaN offsets, wrapping around the grid). Every cell of the
group gets FormulaKind::Shared, its own text and the group's index (`si`, counted per sheet);
the first also gets the group's range. Its first cell is the first that uses it, anywhere in
its range. Copies are charged to the formula text allowance before they are decoded, so a long
formula shared by a million cells stops costing once the allowance is spent.
- Ctrl+Shift+Enter and dynamic arrays: the first cell gets FormulaKind::Array with its range; a
dynamic one also has its cell metadata (BrtCellMeta, which now also holds across a BrtValueMeta
written in between), as `cm` marks it in .xlsx. The other cells of an array keep their cached
values and have no formula, as in .xlsx.
- A record that can't be read leaves its range as values and never fails the file, with a
warning; so does a first cell with no formula record after it.
Ported from storytold/gridcraft#3821 (issue gridcraft#3806), with its review fixes (each copy
decoded at its own cell; a shared formula may start inside its range). Changed from the
GridCraft PR:
- In .xlsx a shared formula's other cells have empty text. Here they have their own decoded text
(and CellFormula's doc says so), because that is exact where shifting the first cell's text is
not, as the PR's review found.
- Clearing an array's other cells for recalculation, marking dynamic arrays to spill, and the
check against GridCraft's parser's 8,192-character limit are GridCraft's reading, not the
file's: the cells keep what the file holds. That test becomes one that a copy may be longer
than its first cell.
The PR's tests come along in tests/xlsb.rs, with craft-xlsx's model in the expectations.
Checked against Excel: in a workbook Excel saved both as .xlsb and as .xlsx, every formula this
reads (33, shared, array and dynamic ones included) has the .xlsx text, kind and range; the other
5 use tables, an external link or defined names.
A BIFF12 decoder for cell formulas (xlsb/formula.rs), separate from craft-xls's BIFF8 one because
nearly every operand differs (32-bit rows, 14-bit columns, UTF-16 strings, its own array-constant
codes, newer functions called through hidden names). It reads references, 3-D references,
constants, array constants, functions by number (xlsb/ftab.rs) and newer functions through
Excel's hidden _xlfn. names. A formula cell's CellFormula holds the text as an .xlsx file holds it
(`_xlfn.CONCAT`, `_xlpm.x`, no implicit `@`), and a BrtCellMeta before a cell gives it
cell_metadata, as `cm` does. Reverse-Polish tokens group by order alone, so the decoded tree
gets the parentheses its text needs from operator precedence; Excel's own text is unchanged. A
chain of string constants joined with & prints as one flat chain.
What a formula refers to must be readable too, so shared, array and data-table forms, user
defined names (XLSB names aren't read yet), table references, external links and PY(index, ...)
(code stored elsewhere in the package) keep only their saved results, with a warning saying why.
So does a formula past Limits::binary_formula_text (128 MiB of text over the workbook). The
workbook's links and names are optional: if they can't be read, the file opens with values only,
as before, and a warning says so.
Ported from storytold/gridcraft#3818 (issue gridcraft#3806), with its two review fixes
(grouping by precedence, the flat & chain). Changed from the GridCraft PR:
- The tree and its A1 printer (xlsb/expr.rs) are a copy of craft-xls's expr.rs, with
BinOp::precedence added; the decoder's stack and depth guards are copies of craft-xls's. The
PR used GridCraft's formula crate and shared these with GridCraft's .xls decoder.
- No fmla::from_file, implicit `@`, parse check or Python-cell adoption: those are GridCraft's
reading of the text, not the file's. A single-cell dynamic-array formula is read (with its
cell metadata) instead of being kept as its value; the PR left dynamic arrays to the next PR.
- The links are read with the workbook part and kept by Package for its sheets.
Its tests come along in tests/xlsb.rs, with the expected text in the file's spelling.
Checked against Excel: of the formulas in a workbook Excel saved both as .xlsb and as .xlsx,
every one this reads (26) has the text of the .xlsx; the other 12 are the kinds above.