Table of Contents

Class InputStream

Namespace
Kook.Audio.Streams
Assembly
Kook.Net.WebSocket.dll

表示输入音频流,用于在 IAudioClient 实例中,从语音服务器接收语音数据。

public class InputStream : AudioInStream, IAsyncDisposable, IDisposable
Inheritance
InputStream
Implements
Inherited Members

Constructors

InputStream()

public InputStream()

Properties

AvailableFrames

获取当前可用的帧数。

public override int AvailableFrames { get; }

Property Value

int

CanRead

When overridden in a derived class, gets a value indicating whether the current stream supports reading.

public override bool CanRead { get; }

Property Value

bool

true if the stream supports reading; otherwise, false.

CanSeek

When overridden in a derived class, gets a value indicating whether the current stream supports seeking.

public override bool CanSeek { get; }

Property Value

bool

true if the stream supports seeking; otherwise, false.

CanWrite

When overridden in a derived class, gets a value indicating whether the current stream supports writing.

public override bool CanWrite { get; }

Property Value

bool

true if the stream supports writing; otherwise, false.

Methods

Dispose(bool)

Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

ReadAsync(byte[], int, int, CancellationToken)

Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

Parameters

buffer byte[]

The buffer to write the data into.

offset int

The byte offset in buffer at which to begin writing data from the stream.

count int

The maximum number of bytes to read.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<int>

A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if count is 0 or if the end of the stream has been reached.

Exceptions

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset or count is negative.

ArgumentException

The sum of offset and count is larger than the buffer length.

NotSupportedException

The stream does not support reading.

ObjectDisposedException

The stream has been disposed.

InvalidOperationException

The stream is currently in use by a previous read operation.

ReadFrameAsync(CancellationToken)

读取一个 RTP 帧。

public override Task<RtpFrame> ReadFrameAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

用于取消任务的取消令牌。

Returns

Task<RtpFrame>

一个表示异步读取的任务。任务的结果为读取到的 RTP 帧。

TryReadFrame(CancellationToken, out RtpFrame)

尝试读取一个 RTP 帧。

public override bool TryReadFrame(CancellationToken cancellationToken, out RtpFrame frame)

Parameters

cancellationToken CancellationToken

用于取消任务的取消令牌。

frame RtpFrame

如果成功读取到 RTP 帧,则为读取到的 RTP 帧;否则为 default

Returns

bool

是否成功读取到 RTP 帧。

WriteAsync(byte[], int, int, CancellationToken)

Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

Parameters

buffer byte[]

The buffer to write data from.

offset int

The zero-based byte offset in buffer from which to begin copying bytes to the stream.

count int

The maximum number of bytes to write.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous write operation.

Exceptions

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset or count is negative.

ArgumentException

The sum of offset and count is larger than the buffer length.

NotSupportedException

The stream does not support writing.

ObjectDisposedException

The stream has been disposed.

InvalidOperationException

The stream is currently in use by a previous write operation.

WriteHeader(ushort, uint, bool)

向流中写入一个头部信息。

public override void WriteHeader(ushort seq, uint timestamp, bool missed)

Parameters

seq ushort

头部的序列号。

timestamp uint

头部的时间戳。

missed bool

头部是否用于标识丢失的数据包。

Exceptions

InvalidOperationException

该流不接收头部信息。