-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
StreamMediaFoundationReader.cs
42 lines (37 loc) · 1.42 KB
/
StreamMediaFoundationReader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.IO;
using NAudio.MediaFoundation;
// ReSharper disable once CheckNamespace
namespace NAudio.Wave
{
/// <summary>
/// MediaFoundationReader supporting reading from a stream
/// </summary>
public class StreamMediaFoundationReader : MediaFoundationReader
{
private readonly Stream stream;
/// <summary>
/// Constructs a new media foundation reader from a stream
/// </summary>
public StreamMediaFoundationReader(Stream stream, MediaFoundationReaderSettings settings = null)
{
this.stream = stream;
Init(settings);
}
/// <summary>
/// Creates the reader
/// </summary>
protected override IMFSourceReader CreateReader(MediaFoundationReaderSettings settings)
{
var ppSourceReader = MediaFoundationApi.CreateSourceReaderFromByteStream(MediaFoundationApi.CreateByteStream(new ComStream(stream)));
ppSourceReader.SetStreamSelection(-2, false);
ppSourceReader.SetStreamSelection(-3, true);
ppSourceReader.SetCurrentMediaType(-3, IntPtr.Zero, new MediaType
{
MajorType = MediaTypes.MFMediaType_Audio,
SubType = settings.RequestFloatOutput ? AudioSubtypes.MFAudioFormat_Float : AudioSubtypes.MFAudioFormat_PCM
}.MediaFoundationObject);
return ppSourceReader;
}
}
}