Skip to content
Merged
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
18 changes: 17 additions & 1 deletion src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ VideoDecoder::BatchDecodedOutput::BatchDecodedOutput(
frames = allocateEmptyHWCTensor(height, width, options.device, numFrames);
}

bool VideoDecoder::SwsContextKey::operator==(
const VideoDecoder::SwsContextKey& other) {
return decodedWidth == other.decodedWidth && decodedHeight == decodedHeight &&
decodedFormat == other.decodedFormat &&
outputWidth == other.outputWidth && outputHeight == other.outputHeight;
}

bool VideoDecoder::SwsContextKey::operator!=(
const VideoDecoder::SwsContextKey& other) {
return !(*this == other);
}

VideoDecoder::VideoDecoder() {}

void VideoDecoder::initializeDecoder() {
Expand Down Expand Up @@ -1340,7 +1352,11 @@ int VideoDecoder::convertFrameToBufferUsingSwsScale(
int expectedOutputHeight = outputTensor.sizes()[0];
int expectedOutputWidth = outputTensor.sizes()[1];
auto curFrameSwsContextKey = SwsContextKey{
frame->width, frame->height, frameFormat, expectedOutputWidth, expectedOutputHeight};
frame->width,
frame->height,
frameFormat,
expectedOutputWidth,
expectedOutputHeight};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a drive-by linting. I think it's easier to keep it in the PR.

if (activeStream.swsContext.get() == nullptr ||
activeStream.swsContextKey != curFrameSwsContextKey) {
SwsContext* swsContext = sws_getContext(
Expand Down
4 changes: 2 additions & 2 deletions src/torchcodec/decoders/_core/VideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ class VideoDecoder {
AVPixelFormat decodedFormat;
int outputWidth;
int outputHeight;
bool operator==(const SwsContextKey&) const = default;
bool operator!=(const SwsContextKey&) const = default;
bool operator==(const SwsContextKey&);
bool operator!=(const SwsContextKey&);
};
// Stores information for each stream.
struct StreamInfo {
Expand Down
Loading