Providing streaming AudFormat data.

AudFormat.GetPCMInputStream now returns data that is streamed, rather than a MemoryStream.
This commit is contained in:
RoosterDragon
2017-07-09 20:21:02 +00:00
committed by Paul Chote
parent 85c948fd8d
commit 9413d9595c
7 changed files with 218 additions and 75 deletions

View File

@@ -183,23 +183,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
public Stream GetContent(PackageEntry entry)
{
Stream parentStream;
var baseOffset = dataStart + entry.Offset;
var nestedOffset = baseOffset + SegmentStream.GetOverallNestedOffset(s, out parentStream);
// Special case FileStream - instead of creating an in-memory copy,
// just reference the portion of the on-disk file that we need to save memory.
// We use GetType instead of 'is' here since we can't handle any derived classes of FileStream.
if (parentStream.GetType() == typeof(FileStream))
{
var path = ((FileStream)parentStream).Name;
return new SegmentStream(File.OpenRead(path), nestedOffset, entry.Length);
}
// For all other streams, create a copy in memory.
// This uses more memory but is the only way in general to ensure the returned streams won't clash.
s.Seek(baseOffset, SeekOrigin.Begin);
return new MemoryStream(s.ReadBytes((int)entry.Length));
return SegmentStream.CreateWithoutOwningStream(s, dataStart + entry.Offset, (int)entry.Length);
}
public Stream GetStream(string filename)