Example #1
0
        private void WriteStreamFrame(AviStreamBase stream, bool isKeyFrame, byte[] frameData, int startIndex, int count)
        {
            lock (syncWrite)
            {
                CheckNotClosed();

                if (!startedWriting)
                {
                    PrepareForWriting();
                }

                var si = streamsInfo[stream.Index];
                if (si.SuperIndex.Count == MAX_SUPER_INDEX_ENTRIES)
                {
                    throw new InvalidOperationException("Cannot write more frames to this stream.");
                }

                if (ShouldFlushStreamIndex(si.StandardIndex))
                {
                    FlushStreamIndex(stream);
                }

                var shouldCreateIndex1Entry = emitIndex1 && isFirstRiff;

                CreateNewRiffIfNeeded(count + (shouldCreateIndex1Entry ? INDEX1_ENTRY_SIZE : 0));

                var chunk = fileWriter.OpenChunk(stream.ChunkId, count);
                fileWriter.Write(frameData, startIndex, count);
                fileWriter.CloseItem(chunk);

                si.OnFrameWritten(chunk.DataSize);
                var dataSize = (uint)chunk.DataSize;
                // Set highest bit for non-key frames according to the OpenDML spec
                if (!isKeyFrame)
                {
                    dataSize |= 0x80000000U;
                }

                var newEntry = new StandardIndexEntry
                {
                    DataOffset = chunk.DataStart,
                    DataSize   = dataSize
                };
                si.StandardIndex.Add(newEntry);

                if (shouldCreateIndex1Entry)
                {
                    var index1Entry = new Index1Entry
                    {
                        IsKeyFrame = isKeyFrame,
                        DataOffset = (uint)(chunk.ItemStart - currentMovie.DataStart),
                        DataSize   = dataSize
                    };
                    si.Index1.Add(index1Entry);
                    index1Count++;
                }
            }
        }
Example #2
0
 private void WriteStreamFrame(AviStreamBase stream, bool isKeyFrame, ReadOnlySpan <byte> frameData)