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);
            }
        }
Exemplo n.º 2
0
 private void WriteHeader()
 {
     header = fileWriter.OpenList(KnownFourCC.Lists.Header);
     WriteFileHeader();
     foreach (var stream in streams)
     {
         WriteStreamList(stream);
     }
     WriteOdmlHeader();
     WriteJunkInsteadOfMissingSuperIndexEntries();
     fileWriter.CloseItem(header);
 }
Exemplo n.º 3
0
        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(KnownFourCC.Lists.AviExtended, KnownFourCC.ListTypes.Riff);
                currentMovie = fileWriter.OpenList(KnownFourCC.Lists.Movie);
            }
        }
Exemplo n.º 4
0
        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(KnownFourCC.Chunks.IndexData(s.Index))).ToArray();

            riffSizeTreshold = RIFF_AVI_SIZE_TRESHOLD;

            currentRiff = fileWriter.OpenList(KnownFourCC.Lists.Avi, KnownFourCC.ListTypes.Riff);
            WriteHeader();
            currentMovie = fileWriter.OpenList(KnownFourCC.Lists.Movie);
        }