1

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

0xc00d36ee :提供的字节流应该是可搜索的,但它不是。

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

4

2 回答 2

2

我已经实现了两个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;
        }

如果您希望实现接口的Seek方法,您可以IMFByteStream,但在您的情况下(网络流),您可以只返回搜索位置。

        /// <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;
        }
于 2017-01-10T02:52:32.107 回答
0

你的失败应该来自:

在创建媒体源期间,源解析器会为媒体源从中读取 ASF 内容的文件创建一个字节流。为了使时间转换成功,与 ASF 文件关联的字节流必须具有查找功能;否则,应用程序会MF_E_BYTESTREAM_NOT_SEEKABLE从 Begin... 调用中获取错误。

您可以尝试媒体源属性,但它更像是字节流可搜索的强制性要求。要解决这个问题,您可以做的一件事是确实将流实现标记为可搜索,并在有来自尚不可用的位置的读取请求时实现等待。

于 2016-12-31T08:44:36.737 回答