Dispose some sound streams.
This commit is contained in:
@@ -78,9 +78,12 @@ namespace OpenRA.FileSystem
|
|||||||
{
|
{
|
||||||
if (kv.Key == dbNameClassic || kv.Key == dbNameCRC)
|
if (kv.Key == dbNameClassic || kv.Key == dbNameCRC)
|
||||||
{
|
{
|
||||||
var db = new XccLocalDatabase(GetContent(kv.Value));
|
using (var content = GetContent(kv.Value))
|
||||||
|
{
|
||||||
|
var db = new XccLocalDatabase(content);
|
||||||
foreach (var e in db.Entries)
|
foreach (var e in db.Entries)
|
||||||
allPossibleFilenames.Add(e);
|
allPossibleFilenames.Add(e);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,18 +42,24 @@ namespace OpenRA.GameRules
|
|||||||
if (!fileSystem.TryOpen(Filename, out stream))
|
if (!fileSystem.TryOpen(Filename, out stream))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
Exists = true;
|
Exists = true;
|
||||||
ISoundFormat soundFormat;
|
|
||||||
foreach (var loader in Game.ModData.SoundLoaders)
|
foreach (var loader in Game.ModData.SoundLoaders)
|
||||||
{
|
{
|
||||||
|
ISoundFormat soundFormat;
|
||||||
if (loader.TryParseSound(stream, out soundFormat))
|
if (loader.TryParseSound(stream, out soundFormat))
|
||||||
{
|
{
|
||||||
Length = (int)soundFormat.LengthInSeconds;
|
Length = (int)soundFormat.LengthInSeconds;
|
||||||
|
soundFormat.Dispose();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
stream.Dispose();
|
stream.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRA
|
|||||||
bool TryParseSound(Stream stream, out ISoundFormat sound);
|
bool TryParseSound(Stream stream, out ISoundFormat sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ISoundFormat
|
public interface ISoundFormat : IDisposable
|
||||||
{
|
{
|
||||||
int Channels { get; }
|
int Channels { get; }
|
||||||
int SampleBits { get; }
|
int SampleBits { get; }
|
||||||
@@ -67,8 +67,12 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
if (loader.TryParseSound(stream, out soundFormat))
|
if (loader.TryParseSound(stream, out soundFormat))
|
||||||
return soundEngine.AddSoundSourceFromMemory(
|
{
|
||||||
|
var source = soundEngine.AddSoundSourceFromMemory(
|
||||||
soundFormat.GetPCMInputStream().ReadAllBytes(), soundFormat.Channels, soundFormat.SampleBits, soundFormat.SampleRate);
|
soundFormat.GetPCMInputStream().ReadAllBytes(), soundFormat.Channels, soundFormat.SampleBits, soundFormat.SampleRate);
|
||||||
|
soundFormat.Dispose();
|
||||||
|
return source;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,13 +51,14 @@ namespace OpenRA.Mods.Common.AudioLoaders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AudFormat : ISoundFormat
|
public sealed class AudFormat : ISoundFormat
|
||||||
{
|
{
|
||||||
public int Channels { get { return 1; } }
|
public int Channels { get { return 1; } }
|
||||||
public int SampleBits { get { return 16; } }
|
public int SampleBits { get { return 16; } }
|
||||||
public int SampleRate { get { return sampleRate; } }
|
public int SampleRate { get { return sampleRate; } }
|
||||||
public float LengthInSeconds { get { return AudReader.SoundLength(stream); } }
|
public float LengthInSeconds { get { return AudReader.SoundLength(stream); } }
|
||||||
public Stream GetPCMInputStream() { return new MemoryStream(rawData.Value); }
|
public Stream GetPCMInputStream() { return new MemoryStream(rawData.Value); }
|
||||||
|
public void Dispose() { stream.Dispose(); }
|
||||||
|
|
||||||
int sampleRate;
|
int sampleRate;
|
||||||
Lazy<byte[]> rawData;
|
Lazy<byte[]> rawData;
|
||||||
|
|||||||
@@ -35,13 +35,14 @@ namespace OpenRA.Mods.Common.AudioLoaders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VocFormat : ISoundFormat
|
public sealed class VocFormat : ISoundFormat
|
||||||
{
|
{
|
||||||
public int SampleBits { get { return 8; } }
|
public int SampleBits { get { return 8; } }
|
||||||
public int Channels { get { return 1; } }
|
public int Channels { get { return 1; } }
|
||||||
public int SampleRate { get; private set; }
|
public int SampleRate { get; private set; }
|
||||||
public float LengthInSeconds { get { return (float)totalSamples / SampleRate; } }
|
public float LengthInSeconds { get { return (float)totalSamples / SampleRate; } }
|
||||||
public Stream GetPCMInputStream() { return new VocStream(this); }
|
public Stream GetPCMInputStream() { return new VocStream(this); }
|
||||||
|
public void Dispose() { stream.Dispose(); }
|
||||||
|
|
||||||
int totalSamples = 0;
|
int totalSamples = 0;
|
||||||
int samplePosition = 0;
|
int samplePosition = 0;
|
||||||
|
|||||||
@@ -48,13 +48,14 @@ namespace OpenRA.Mods.Common.AudioLoaders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WavFormat : ISoundFormat
|
public sealed class WavFormat : ISoundFormat
|
||||||
{
|
{
|
||||||
public int Channels { get { return reader.Value.Channels; } }
|
public int Channels { get { return reader.Value.Channels; } }
|
||||||
public int SampleBits { get { return reader.Value.BitsPerSample; } }
|
public int SampleBits { get { return reader.Value.BitsPerSample; } }
|
||||||
public int SampleRate { get { return reader.Value.SampleRate; } }
|
public int SampleRate { get { return reader.Value.SampleRate; } }
|
||||||
public float LengthInSeconds { get { return WavReader.WaveLength(stream); } }
|
public float LengthInSeconds { get { return WavReader.WaveLength(stream); } }
|
||||||
public Stream GetPCMInputStream() { return new MemoryStream(reader.Value.RawOutput); }
|
public Stream GetPCMInputStream() { return new MemoryStream(reader.Value.RawOutput); }
|
||||||
|
public void Dispose() { stream.Dispose(); }
|
||||||
|
|
||||||
Lazy<WavReader> reader;
|
Lazy<WavReader> reader;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user