我已經實現了兩個IMFByteStream
接口,其中一個稱爲MediaByteStream,用於非存儲內存流,另一個稱爲StoreByteStream(是的,我知道),用於內存存儲。
將以下代碼放置在您的IMFByteStream
實現中將消除您的可尋址錯誤,並且不會影響您的流式傳輸能力。
/// <summary>
/// Retrieves the characteristics of the byte stream.
/// </summary>
/// <param name="pdwCapabilities">Receives a bitwise OR of zero or more flags. The following flags are defined. [out]</param>
/// <returns>The result of the operation.</returns>
HRESULT MediaByteStream::GetCapabilities(
DWORD *pdwCapabilities)
{
HRESULT hr = S_OK;
// Stream can read, can write, can seek.
*pdwCapabilities = MFBYTESTREAM_IS_READABLE | MFBYTESTREAM_IS_WRITABLE | MFBYTESTREAM_IS_SEEKABLE;
// Return the result.
return hr;
}
你可以,如果你想實現IMFByteStream
接口的Seek
方法,但在你的情況下(網絡流),你可以只返回搜索位置。
/// <summary>
/// Moves the current position in the stream by a specified offset.
/// </summary>
/// <param name="SeekOrigin">Specifies the origin of the seek as a member of the MFBYTESTREAM_SEEK_ORIGIN enumeration. The offset is calculated relative to this position. [in]</param>
/// <param name="qwSeekOffset">Specifies the new position, as a byte offset from the seek origin. [in]</param>
/// <param name="dwSeekFlags">Specifies zero or more flags. The following flags are defined. [in]</param>
/// <param name="pqwCurrentPosition">Receives the new position after the seek. [out]</param>
/// <returns>The result of the operation.</returns>
HRESULT MediaByteStream::Seek(
MFBYTESTREAM_SEEK_ORIGIN SeekOrigin,
LONGLONG qwSeekOffset,
DWORD dwSeekFlags,
QWORD *pqwCurrentPosition)
{
HRESULT hr = S_OK;
_seekRequest = true;
// Select the seek origin.
switch (SeekOrigin)
{
case MFBYTESTREAM_SEEK_ORIGIN::msoCurrent:
// If the buffer is less or same.
if ((qwSeekOffset + _position) < size)
_position += qwSeekOffset;
else
_position = size;
break;
case MFBYTESTREAM_SEEK_ORIGIN::msoBegin:
default:
// If the buffer is less or same.
if (qwSeekOffset < size)
_position = qwSeekOffset;
else
_position = size;
break;
}
// Get the current position in the stream.
*pqwCurrentPosition = _position;
// Return the result.
return hr;
}
您需要一個媒體源,對於不可查找的流很好。一些消息來源需要尋找的是整個觀點,並且他們檢查這些上限以確保尋求可用。 –
我的目標媒體源的內容類型是ASF。可以創建不需要可查找字節流的ASF媒體源? – pawel
我認爲所有的尋求都是「前進」的,所以最有可能實現一個簡單的尋找流(只是讀取不需要的數據) –