Skip to content

VideoDecoder -> SingleStreamDecoder #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
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
2 changes: 1 addition & 1 deletion src/torchcodec/_core/AVIOContextHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace facebook::torchcodec {
// createAVIOContext(), ideally in their constructor.
// 3. A generic handle for those that just need to manage having access to an
// AVIOContext, but aren't necessarily concerned with how it was customized:
// typically, the VideoDecoder.
// typically, the SingleStreamDecoder.
class AVIOContextHolder {
public:
virtual ~AVIOContextHolder();
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function(make_torchcodec_libraries
set(decoder_sources
AVIOContextHolder.cpp
FFMPEGCommon.cpp
VideoDecoder.cpp
SingleStreamDecoder.cpp
)

if(ENABLE_CUDA)
Expand Down
5 changes: 3 additions & 2 deletions src/torchcodec/_core/CPUOnlyDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ namespace facebook::torchcodec {

void convertAVFrameToFrameOutputOnCuda(
const torch::Device& device,
[[maybe_unused]] const VideoDecoder::VideoStreamOptions& videoStreamOptions,
[[maybe_unused]] const SingleStreamDecoder::VideoStreamOptions&
videoStreamOptions,
[[maybe_unused]] UniqueAVFrame& avFrame,
[[maybe_unused]] VideoDecoder::FrameOutput& frameOutput,
[[maybe_unused]] SingleStreamDecoder::FrameOutput& frameOutput,
[[maybe_unused]] std::optional<torch::Tensor> preAllocatedOutputTensor) {
throwUnsupportedDeviceError(device);
}
Expand Down
12 changes: 7 additions & 5 deletions src/torchcodec/_core/CudaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "src/torchcodec/_core/DeviceInterface.h"
#include "src/torchcodec/_core/FFMPEGCommon.h"
#include "src/torchcodec/_core/VideoDecoder.h"
#include "src/torchcodec/_core/SingleStreamDecoder.h"

extern "C" {
#include <libavutil/hwcontext_cuda.h>
Expand All @@ -20,9 +20,11 @@ namespace {
// creating a cuda context is expensive. The cache mechanism is as follows:
// 1. There is a cache of size MAX_CONTEXTS_PER_GPU_IN_CACHE cuda contexts for
// each GPU.
// 2. When we destroy a VideoDecoder instance we release the cuda context to
// 2. When we destroy a SingleStreamDecoder instance we release the cuda context
// to
// the cache if the cache is not full.
// 3. When we create a VideoDecoder instance we try to get a cuda context from
// 3. When we create a SingleStreamDecoder instance we try to get a cuda context
// from
// the cache. If the cache is empty we create a new cuda context.

// Pytorch can only handle up to 128 GPUs.
Expand Down Expand Up @@ -189,9 +191,9 @@ void initializeContextOnCuda(

void convertAVFrameToFrameOutputOnCuda(
const torch::Device& device,
const VideoDecoder::VideoStreamOptions& videoStreamOptions,
const SingleStreamDecoder::VideoStreamOptions& videoStreamOptions,
UniqueAVFrame& avFrame,
VideoDecoder::FrameOutput& frameOutput,
SingleStreamDecoder::FrameOutput& frameOutput,
std::optional<torch::Tensor> preAllocatedOutputTensor) {
TORCH_CHECK(
avFrame->format == AV_PIX_FMT_CUDA,
Expand Down
8 changes: 4 additions & 4 deletions src/torchcodec/_core/DeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include <stdexcept>
#include <string>
#include "FFMPEGCommon.h"
#include "src/torchcodec/_core/VideoDecoder.h"
#include "src/torchcodec/_core/SingleStreamDecoder.h"

namespace facebook::torchcodec {

// Note that all these device functions should only be called if the device is
// not a CPU device. CPU device functions are already implemented in the
// VideoDecoder implementation.
// SingleStreamDecoder implementation.
// These functions should only be called from within an if block like this:
// if (device.type() != torch::kCPU) {
// deviceFunction(device, ...);
Expand All @@ -31,9 +31,9 @@ void initializeContextOnCuda(

void convertAVFrameToFrameOutputOnCuda(
const torch::Device& device,
const VideoDecoder::VideoStreamOptions& videoStreamOptions,
const SingleStreamDecoder::VideoStreamOptions& videoStreamOptions,
UniqueAVFrame& avFrame,
VideoDecoder::FrameOutput& frameOutput,
SingleStreamDecoder::FrameOutput& frameOutput,
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);

void releaseContextOnCuda(
Expand Down
Loading
Loading