Skip to content

Commit 30db077

Browse files
committed
Merged PR 50634: April 2021 release
1 parent 20a1b81 commit 30db077

File tree

417 files changed

+17789
-8243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

417 files changed

+17789
-8243
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Company>Microsoft Corporation</Company>
77
<Owners>microsoft,psi</Owners>
88
<Authors>Microsoft</Authors>
9-
<AssemblyVersion>0.14.35.3</AssemblyVersion>
9+
<AssemblyVersion>0.15.49.1</AssemblyVersion>
1010
<FileVersion>$(AssemblyVersion)</FileVersion>
1111
<Version>$(AssemblyVersion)-beta</Version>
1212
<SignAssembly>false</SignAssembly>

Sources/Audio/Microsoft.Psi.Audio/WaveFileImporter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public sealed class WaveFileImporter : Importer
2121
/// <param name="startTime">Starting time for streams of data..</param>
2222
/// <param name="audioBufferSizeMs">The size of each data buffer in milliseconds.</param>
2323
public WaveFileImporter(Pipeline pipeline, string name, string path, DateTime startTime, int audioBufferSizeMs = WaveFileStreamReader.DefaultAudioBufferSizeMs)
24-
: base(pipeline, new WaveFileStreamReader(name, path, startTime, audioBufferSizeMs))
24+
: base(pipeline, new WaveFileStreamReader(name, path, startTime, audioBufferSizeMs), false)
2525
{
2626
}
2727
}

Sources/Audio/Microsoft.Psi.Audio/WaveFileStreamReader.cs

+55-25
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ public sealed class WaveFileStreamReader : IStreamReader
3636
private readonly long dataStart;
3737
private readonly long dataLength;
3838

39+
private readonly List<Delegate> audioTargets = new List<Delegate>();
40+
private readonly List<Delegate> audioIndexTargets = new List<Delegate>();
41+
3942
private int sequenceId = 0;
4043
private byte[] buffer;
4144
private TimeInterval seekInterval = TimeInterval.Infinite;
4245

43-
private List<Delegate> audioTargets = new List<Delegate>();
44-
private List<Delegate> audioIndexTargets = new List<Delegate>();
46+
/// <summary>
47+
/// Initializes a new instance of the <see cref="WaveFileStreamReader"/> class.
48+
/// </summary>
49+
/// <param name="name">Name of the WAVE file.</param>
50+
/// <param name="path">Path of the WAVE file.</param>
51+
public WaveFileStreamReader(string name, string path)
52+
: this(name, path, DateTime.UtcNow, DefaultAudioBufferSizeMs)
53+
{
54+
}
4555

4656
/// <summary>
4757
/// Initializes a new instance of the <see cref="WaveFileStreamReader"/> class.
@@ -50,35 +60,26 @@ public sealed class WaveFileStreamReader : IStreamReader
5060
/// <param name="path">Path of the WAVE file.</param>
5161
/// <param name="startTime">Starting time for streams of data..</param>
5262
/// <param name="audioBufferSizeMs">The size of each data buffer in milliseconds.</param>
53-
public WaveFileStreamReader(string name, string path, DateTime startTime, int audioBufferSizeMs = DefaultAudioBufferSizeMs)
63+
internal WaveFileStreamReader(string name, string path, DateTime startTime, int audioBufferSizeMs = DefaultAudioBufferSizeMs)
5464
{
5565
this.Name = name;
5666
this.Path = path;
5767
this.startTime = startTime;
5868
var file = System.IO.Path.Combine(path, name);
69+
this.Size = file.Length;
5970
this.waveFileReader = new BinaryReader(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read));
6071
this.waveFormat = WaveFileHelper.ReadWaveFileHeader(this.waveFileReader);
61-
this.dataLength = (int)WaveFileHelper.ReadWaveDataLength(this.waveFileReader);
72+
this.dataLength = WaveFileHelper.ReadWaveDataLength(this.waveFileReader);
6273
this.dataStart = this.waveFileReader.BaseStream.Position;
6374
var bufferSize = (int)(this.waveFormat.AvgBytesPerSec * audioBufferSizeMs / 1000);
6475
this.buffer = new byte[bufferSize];
6576

6677
// Compute originating times based on audio chunk start time + duration
6778
var endTime = this.startTime.AddSeconds((double)this.dataLength / (double)this.waveFormat.AvgBytesPerSec);
68-
this.MessageOriginatingTimeInterval = this.MessageCreationTimeInterval = new TimeInterval(this.startTime, endTime);
79+
this.MessageOriginatingTimeInterval = this.MessageCreationTimeInterval = this.StreamTimeInterval = new TimeInterval(this.startTime, endTime);
6980

70-
var messageCount = (int)Math.Ceiling((double)this.dataLength / bufferSize);
71-
this.audioStreamMetadata = new WaveAudioStreamMetadata(AudioStreamName, typeof(AudioBuffer).AssemblyQualifiedName, name, path, this.startTime, endTime, (int)this.dataLength / messageCount, messageCount, audioBufferSizeMs);
72-
}
73-
74-
/// <summary>
75-
/// Initializes a new instance of the <see cref="WaveFileStreamReader"/> class.
76-
/// </summary>
77-
/// <param name="name">Name of the WAVE file.</param>
78-
/// <param name="path">Path of the WAVE file.</param>
79-
public WaveFileStreamReader(string name, string path)
80-
: this(name, path, DateTime.UtcNow, DefaultAudioBufferSizeMs)
81-
{
81+
var messageCount = (long)Math.Ceiling((double)this.dataLength / bufferSize);
82+
this.audioStreamMetadata = new WaveAudioStreamMetadata(AudioStreamName, typeof(AudioBuffer).AssemblyQualifiedName, name, path, this.startTime, endTime, messageCount, (double)this.dataLength / messageCount, audioBufferSizeMs);
8283
}
8384

8485
/// <inheritdoc />
@@ -102,6 +103,15 @@ public IEnumerable<IStreamMetadata> AvailableStreams
102103
/// <inheritdoc />
103104
public TimeInterval MessageOriginatingTimeInterval { get; private set; }
104105

106+
/// <inheritdoc />
107+
public TimeInterval StreamTimeInterval { get; private set; }
108+
109+
/// <inheritdoc/>
110+
public long? Size { get; }
111+
112+
/// <inheritdoc/>
113+
public int? StreamCount => 1;
114+
105115
/// <inheritdoc />
106116
public bool ContainsStream(string name)
107117
{
@@ -128,7 +138,7 @@ public T GetSupplementalMetadata<T>(string streamName)
128138

129139
if (typeof(T) != typeof(WaveFormat))
130140
{
131-
throw new ArgumentException("The Audio stream supports only supplemental metadata of type WaveFormat.");
141+
throw new NotSupportedException("The Audio stream supports only supplemental metadata of type WaveFormat.");
132142
}
133143

134144
return (T)(object)this.waveFormat;
@@ -161,20 +171,40 @@ public IStreamReader OpenNew()
161171
}
162172

163173
/// <inheritdoc />
164-
public IStreamMetadata OpenStream<T>(string name, Action<T, Envelope> target, Func<T> allocator = null, Action<SerializationException> errorHandler = null)
174+
public IStreamMetadata OpenStream<T>(string name, Action<T, Envelope> target, Func<T> allocator = null, Action<T> deallocator = null, Action<SerializationException> errorHandler = null)
165175
{
166176
ValidateStreamName(name);
167177

178+
if (target == null)
179+
{
180+
throw new ArgumentNullException(nameof(target));
181+
}
182+
183+
if (allocator != null)
184+
{
185+
throw new NotSupportedException($"Allocators are not supported by {nameof(WaveFileStreamReader)} and must be null.");
186+
}
187+
168188
// targets are later called when data is read by MoveNext or ReadAll (see InvokeTargets).
169189
this.audioTargets.Add(target);
170190
return this.audioStreamMetadata;
171191
}
172192

173193
/// <inheritdoc />
174-
public IStreamMetadata OpenStreamIndex<T>(string name, Action<Func<IStreamReader, T>, Envelope> target)
194+
public IStreamMetadata OpenStreamIndex<T>(string name, Action<Func<IStreamReader, T>, Envelope> target, Func<T> allocator = null)
175195
{
176196
ValidateStreamName(name);
177197

198+
if (target == null)
199+
{
200+
throw new ArgumentNullException(nameof(target));
201+
}
202+
203+
if (allocator != null)
204+
{
205+
throw new NotSupportedException($"Allocators are not supported by {nameof(WaveFileStreamReader)} and must be null.");
206+
}
207+
178208
// targets are later called when data is read by MoveNext or ReadAll (see InvokeTargets).
179209
this.audioIndexTargets.Add(target);
180210
return this.audioStreamMetadata;
@@ -222,7 +252,7 @@ private static void ValidateStreamName(string name)
222252
if (name != AudioStreamName)
223253
{
224254
// the only supported stream is the single audio stream.
225-
throw new ArgumentException($"Only '{AudioStreamName}' stream is supported.");
255+
throw new NotSupportedException($"Only '{AudioStreamName}' stream is supported.");
226256
}
227257
}
228258

@@ -327,11 +357,11 @@ public class WaveAudioStreamMetadata : StreamMetadataBase
327357
/// <param name="partitionPath">Partition/file path.</param>
328358
/// <param name="first">First message time.</param>
329359
/// <param name="last">Last message time.</param>
330-
/// <param name="averageMessageSize">Average message size (bytes).</param>
331360
/// <param name="messageCount">Total message count.</param>
332-
/// <param name="averageLatency">Average message latency.</param>
333-
public WaveAudioStreamMetadata(string name, string typeName, string partitionName, string partitionPath, DateTime first, DateTime last, int averageMessageSize, int messageCount, int averageLatency)
334-
: base(name, AudioSourceId, typeName, partitionName, partitionPath, first, last, averageMessageSize, messageCount, averageLatency)
361+
/// <param name="averageMessageSize">Average message size (bytes).</param>
362+
/// <param name="averageLatencyMs">Average message latency (milliseconds).</param>
363+
internal WaveAudioStreamMetadata(string name, string typeName, string partitionName, string partitionPath, DateTime first, DateTime last, long messageCount, double averageMessageSize, double averageLatencyMs)
364+
: base(name, AudioSourceId, typeName, partitionName, partitionPath, first, last, messageCount, averageMessageSize, averageLatencyMs)
335365
{
336366
}
337367
}

0 commit comments

Comments
 (0)