mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Patch the remaining uses or FFmpeg APIs
This commit is contained in:
parent
21b0454461
commit
c6c2a44e9d
5 changed files with 23 additions and 18 deletions
|
@ -47,11 +47,11 @@ private:
|
||||||
return (_rotation == 90) || (_rotation == 270);
|
return (_rotation == 90) || (_rotation == 270);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static int Read(
|
[[nodiscard]] static int _read(
|
||||||
void *opaque,
|
void *opaque,
|
||||||
uint8_t *buf,
|
uint8_t *buf,
|
||||||
int buf_size);
|
int buf_size);
|
||||||
[[nodiscard]] static int64_t Seek(
|
[[nodiscard]] static int64_t _seek(
|
||||||
void *opaque,
|
void *opaque,
|
||||||
int64_t offset,
|
int64_t offset,
|
||||||
int whence);
|
int whence);
|
||||||
|
@ -113,7 +113,7 @@ int FrameGenerator::Impl::Read(void *opaque, uint8_t *buf, int buf_size) {
|
||||||
int FrameGenerator::Impl::read(uint8_t *buf, int buf_size) {
|
int FrameGenerator::Impl::read(uint8_t *buf, int buf_size) {
|
||||||
const auto available = _bytes.size() - _deviceOffset;
|
const auto available = _bytes.size() - _deviceOffset;
|
||||||
if (available <= 0) {
|
if (available <= 0) {
|
||||||
return -1;
|
return AVERROR_EOF;
|
||||||
}
|
}
|
||||||
const auto fill = std::min(int(available), buf_size);
|
const auto fill = std::min(int(available), buf_size);
|
||||||
memcpy(buf, _bytes.data() + _deviceOffset, fill);
|
memcpy(buf, _bytes.data() + _deviceOffset, fill);
|
||||||
|
|
|
@ -181,7 +181,7 @@ struct Instance::Inner::Private {
|
||||||
|
|
||||||
int32 nbytes = qMin(l->data.size() - l->dataPos, int32(buf_size));
|
int32 nbytes = qMin(l->data.size() - l->dataPos, int32(buf_size));
|
||||||
if (nbytes <= 0) {
|
if (nbytes <= 0) {
|
||||||
return 0;
|
return AVERROR_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, l->data.constData() + l->dataPos, nbytes);
|
memcpy(buf, l->data.constData() + l->dataPos, nbytes);
|
||||||
|
|
|
@ -105,7 +105,7 @@ int AbstractFFMpegLoader::_read_data(void *opaque, uint8_t *buf, int buf_size) {
|
||||||
|
|
||||||
auto nbytes = qMin(l->_data.size() - l->_dataPos, int32(buf_size));
|
auto nbytes = qMin(l->_data.size() - l->_dataPos, int32(buf_size));
|
||||||
if (nbytes <= 0) {
|
if (nbytes <= 0) {
|
||||||
return 0;
|
return AVERROR_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, l->_data.constData() + l->_dataPos, nbytes);
|
memcpy(buf, l->_data.constData() + l->_dataPos, nbytes);
|
||||||
|
@ -138,7 +138,7 @@ int AbstractFFMpegLoader::_read_bytes(void *opaque, uint8_t *buf, int buf_size)
|
||||||
|
|
||||||
auto nbytes = qMin(static_cast<int>(l->_bytes.size()) - l->_dataPos, buf_size);
|
auto nbytes = qMin(static_cast<int>(l->_bytes.size()) - l->_dataPos, buf_size);
|
||||||
if (nbytes <= 0) {
|
if (nbytes <= 0) {
|
||||||
return 0;
|
return AVERROR_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, l->_bytes.data() + l->_dataPos, nbytes);
|
memcpy(buf, l->_bytes.data() + l->_dataPos, nbytes);
|
||||||
|
@ -169,7 +169,12 @@ int64_t AbstractFFMpegLoader::_seek_bytes(void *opaque, int64_t offset, int when
|
||||||
|
|
||||||
int AbstractFFMpegLoader::_read_file(void *opaque, uint8_t *buf, int buf_size) {
|
int AbstractFFMpegLoader::_read_file(void *opaque, uint8_t *buf, int buf_size) {
|
||||||
auto l = reinterpret_cast<AbstractFFMpegLoader *>(opaque);
|
auto l = reinterpret_cast<AbstractFFMpegLoader *>(opaque);
|
||||||
return int(l->_f.read((char *)(buf), buf_size));
|
int ret = l->_f.read((char *)(buf), buf_size);
|
||||||
|
switch (ret) {
|
||||||
|
case -1: return AVERROR_EXTERNAL;
|
||||||
|
case 0: return AVERROR_EOF;
|
||||||
|
default: return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t AbstractFFMpegLoader::_seek_file(void *opaque, int64_t offset, int whence) {
|
int64_t AbstractFFMpegLoader::_seek_file(void *opaque, int64_t offset, int whence) {
|
||||||
|
|
|
@ -44,12 +44,12 @@ File::Context::Context(
|
||||||
|
|
||||||
File::Context::~Context() = default;
|
File::Context::~Context() = default;
|
||||||
|
|
||||||
int File::Context::Read(void *opaque, uint8_t *buffer, int bufferSize) {
|
int File::Context::_read(void *opaque, uint8_t *buffer, int bufferSize) {
|
||||||
return static_cast<Context*>(opaque)->read(
|
return static_cast<Context*>(opaque)->read(
|
||||||
bytes::make_span(buffer, bufferSize));
|
bytes::make_span(buffer, bufferSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t File::Context::Seek(void *opaque, int64_t offset, int whence) {
|
int64_t File::Context::_seek(void *opaque, int64_t offset, int whence) {
|
||||||
return static_cast<Context*>(opaque)->seek(offset, whence);
|
return static_cast<Context*>(opaque)->seek(offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,13 +59,13 @@ int File::Context::read(bytes::span buffer) {
|
||||||
const auto amount = std::min(_size - _offset, int64(buffer.size()));
|
const auto amount = std::min(_size - _offset, int64(buffer.size()));
|
||||||
|
|
||||||
if (unroll()) {
|
if (unroll()) {
|
||||||
return -1;
|
return AVERROR_EXTERNAL;
|
||||||
} else if (amount > kMaxSingleReadAmount) {
|
} else if (amount > kMaxSingleReadAmount) {
|
||||||
LOG(("Streaming Error: Read callback asked for too much data: %1"
|
LOG(("Streaming Error: Read callback asked for too much data: %1"
|
||||||
).arg(amount));
|
).arg(amount));
|
||||||
return -1;
|
return AVERROR_EXTERNAL;
|
||||||
} else if (!amount) {
|
} else if (!amount) {
|
||||||
return amount;
|
return AVERROR_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = buffer.subspan(0, amount);
|
buffer = buffer.subspan(0, amount);
|
||||||
|
@ -87,10 +87,10 @@ int File::Context::read(bytes::span buffer) {
|
||||||
}
|
}
|
||||||
_semaphore.acquire();
|
_semaphore.acquire();
|
||||||
if (_interrupted) {
|
if (_interrupted) {
|
||||||
return -1;
|
return AVERROR_EXTERNAL;
|
||||||
} else if (const auto error = _reader->streamingError()) {
|
} else if (const auto error = _reader->streamingError()) {
|
||||||
fail(*error);
|
fail(*error);
|
||||||
return -1;
|
return AVERROR_EXTERNAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,9 +276,9 @@ void File::Context::start(crl::time position, bool hwAllow) {
|
||||||
}
|
}
|
||||||
auto format = FFmpeg::MakeFormatPointer(
|
auto format = FFmpeg::MakeFormatPointer(
|
||||||
static_cast<void *>(this),
|
static_cast<void *>(this),
|
||||||
&Context::Read,
|
&Context::_read,
|
||||||
nullptr,
|
nullptr,
|
||||||
&Context::Seek);
|
&Context::_seek);
|
||||||
if (!format) {
|
if (!format) {
|
||||||
return fail(Error::OpenFailed);
|
return fail(Error::OpenFailed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,8 +62,8 @@ private:
|
||||||
Allowed,
|
Allowed,
|
||||||
Disallowed,
|
Disallowed,
|
||||||
};
|
};
|
||||||
static int Read(void *opaque, uint8_t *buffer, int bufferSize);
|
static int _read(void *opaque, uint8_t *buffer, int bufferSize);
|
||||||
static int64_t Seek(void *opaque, int64_t offset, int whence);
|
static int64_t _seek(void *opaque, int64_t offset, int whence);
|
||||||
|
|
||||||
[[nodiscard]] int read(bytes::span buffer);
|
[[nodiscard]] int read(bytes::span buffer);
|
||||||
[[nodiscard]] int64_t seek(int64_t offset, int whence);
|
[[nodiscard]] int64_t seek(int64_t offset, int whence);
|
||||||
|
|
Loading…
Add table
Reference in a new issue