public static void CloseItem(this BinaryWriter writer, RiffItem item) { var position = writer.BaseStream.Position; var dataSize = position - item.DataStart; if (dataSize > int.MaxValue - RiffItem.ITEM_HEADER_SIZE) { throw new InvalidOperationException("Item size is too big."); } if (item.DataSize < 0) { item.DataSize = (int)dataSize; writer.BaseStream.Position = item.DataSizeStart; writer.Write((uint)dataSize); writer.BaseStream.Position = position; } else if (dataSize != item.DataSize) { throw new InvalidOperationException("Item size is not equal to what was previously specified."); } // Pad to the WORD boundary according to the RIFF spec if (position % 2 > 0) { writer.SkipBytes(1); } }
private void WriteHeader() { header = fileWriter.OpenList(KnownFourCCs.Lists.Header); WriteFileHeader(); foreach (var stream in streams) { WriteStreamList(stream); } WriteOdmlHeader(); WriteJunkInsteadOfMissingSuperIndexEntries(); fileWriter.CloseItem(header); }
private void CreateNewRiffIfNeeded(int approximateSizeOfNextChunk) { var estimatedSize = fileWriter.BaseStream.Position + approximateSizeOfNextChunk - currentRiff.ItemStart; if (isFirstRiff && emitIndex1) { estimatedSize += RiffItem.ITEM_HEADER_SIZE + index1Count * INDEX1_ENTRY_SIZE; } if (estimatedSize > riffSizeTreshold) { CloseCurrentRiff(); currentRiff = fileWriter.OpenList(KnownFourCCs.Lists.AviExtended, KnownFourCCs.ListTypes.Riff); currentMovie = fileWriter.OpenList(KnownFourCCs.Lists.Movie); } }
private void PrepareForWriting() { startedWriting = true; foreach (var stream in streams) { stream.PrepareForWriting(); } AviUtils.SplitFrameRate(FramesPerSecond, out frameRateNumerator, out frameRateDenominator); streamsInfo = streams.Select(s => new StreamInfo(KnownFourCCs.Chunks.IndexData(s.Index))).ToArray(); riffSizeTreshold = RIFF_AVI_SIZE_TRESHOLD; currentRiff = fileWriter.OpenList(KnownFourCCs.Lists.Avi, KnownFourCCs.ListTypes.Riff); WriteHeader(); currentMovie = fileWriter.OpenList(KnownFourCCs.Lists.Movie); }