5 #include "libavformat/avio.h"
6 #include "libavutil/error.h"
10 #include <QRecursiveMutex>
15 : m_buffer(
Buffer), m_avioContext(alloc_context(write_flag, force_seek))
19 LOG(VB_GENERAL, LOG_ERR,
"MythAVFormatBuffer failed to allocate an AVIOContext.");
31 LOG(VB_LIBAV, LOG_DEBUG, QString(
"AVIOContext (%1): %2 bytes written")
36 LOG(VB_LIBAV, LOG_DEBUG, QString(
"AVIOContext (%1): %2 bytes read")
45 AVIOContext* context =
nullptr;
47 auto *avio_buffer =
static_cast<unsigned char *
>(av_malloc(buf_size));
48 if (avio_buffer ==
nullptr)
50 LOG(VB_LIBAV, LOG_ERR,
"av_malloc() failed to create a buffer for avio.");
53 context = avio_alloc_context(avio_buffer, buf_size, write_flag,
this,
55 if (context ==
nullptr)
61 context->seekable &= ~AVIO_SEEKABLE_NORMAL;
70 return AVERROR(EINVAL);
72 int ret =
p->m_buffer->Read(buf, buf_size);
83 return AVERROR(EINVAL);
85 return p->m_buffer->Write(buf,
static_cast<uint>(buf_size));
92 return AVERROR(EINVAL);
94 if (whence == AVSEEK_SIZE)
95 return p->m_buffer->GetRealFileSize();
97 if (whence == SEEK_END)
98 return p->m_buffer->Seek(
p->m_buffer->GetRealFileSize() + offset, SEEK_SET);
100 return p->m_buffer->Seek(offset, whence);