gpt4 book ai didi

c++ - 源阅读器和自定义不可搜索的字节流

转载 作者:行者123 更新时间:2023-11-28 05:21:32 25 4
gpt4 key购买 nike

我正在实现自定义 IMFByteStream 以通过网络流式传输视频,但问题是我无法将其对象传递给源解析器以创建媒体源,因为 CreateObjectFromByteStream 返回错误:

0xc00d36ee : The provided bytestream was expected to be seekable and it is not.

当然,我的自定义字节流是不可搜索的,因为无法通过网络进行搜索。所以问题是如何使用不可搜索的字节流创建媒体源?我的最终目标是创建一个 IMFSourceReader 对象。源内容类型为ASF。

最佳答案

我已经实现了两个 IMFByteStream 接口(interface),一个称为 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 接口(interface)的 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;
}

关于c++ - 源阅读器和自定义不可搜索的字节流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41406319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com