Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/torchcodec/decoders/_core/FFMPEGCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "src/torchcodec/decoders/_core/FFMPEGCommon.h"

#include <c10/util/Exception.h>

namespace facebook::torchcodec {

std::string getFFMPEGErrorStringFromErrorCode(int errorCode) {
Expand Down Expand Up @@ -68,6 +70,14 @@ int AVIOBytesContext::read(void* opaque, uint8_t* buf, int buf_size) {
struct AVIOBufferData* bufferData =
static_cast<struct AVIOBufferData*>(opaque);
buf_size = FFMIN(buf_size, bufferData->size - bufferData->current);
TORCH_CHECK(
buf_size >= 0,
"Tried to read negative bytes: buf_size=",
buf_size,
", size=",
bufferData->size,
", current=",
bufferData->current);
if (!buf_size) {
return AVERROR_EOF;
}
Expand Down
1 change: 1 addition & 0 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ std::unique_ptr<VideoDecoder> VideoDecoder::createFromBuffer(
const void* buffer,
size_t length,
const VideoDecoder::DecoderOptions& options) {
TORCH_CHECK(buffer != nullptr, "Video buffer cannot be nullptr!");
AVInput input = createAVFormatContextFromBuffer(buffer, length);
std::unique_ptr<VideoDecoder> decoder(new VideoDecoder());
decoder->formatContext_ = std::move(input.formatContext);
Expand Down