在 IOContext 中的 IStream 中寻找
设置自定义 IO 上下文的 API 调用 avio_alloc_context
接收指向 Seek 函数的指针。如果你正在阅读 IStream,则可以使用以下内容:
/**
* Seeks to a given position on an IStream.
*
* @param ptr A pointer to the user-defined IO data structure.
* @param pos The position to seek to.
* @param origin The relative point (origin) from which the seek is performed.
*
* @return The new position in the IStream.
*/
int64_t FileStreamSeek(void* ptr, int64_t pos, int origin){
// Your custom IStream
IStream* stream = reinterpret_cast<IStream*>(ptr);
// Prevent overflows
LARGE_INTEGER in = { pos };
ULARGE_INTEGER out = { 0 };
// Origin is an item from STREAM_SEEK enum.
// STREAM_SEEK_SET - relative to beginning of stream.
// STREAM_SEEK_CUR - relative to current position in stream.
// STREAM_SEEK_END - relative to end of stream.
if(FAILED(stream->Seek(in, origin, &out)))
return -1;
// Return the new position
return out.QuadPart;
}