Skip to content

Commit 4ddb1f5

Browse files
authored
VideoDecoder -> SingleStreamDecoder (#611)
1 parent 2d74e98 commit 4ddb1f5

File tree

10 files changed

+208
-182
lines changed

10 files changed

+208
-182
lines changed

src/torchcodec/_core/AVIOContextHolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace facebook::torchcodec {
3232
// createAVIOContext(), ideally in their constructor.
3333
// 3. A generic handle for those that just need to manage having access to an
3434
// AVIOContext, but aren't necessarily concerned with how it was customized:
35-
// typically, the VideoDecoder.
35+
// typically, the SingleStreamDecoder.
3636
class AVIOContextHolder {
3737
public:
3838
virtual ~AVIOContextHolder();

src/torchcodec/_core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function(make_torchcodec_libraries
6060
set(decoder_sources
6161
AVIOContextHolder.cpp
6262
FFMPEGCommon.cpp
63-
VideoDecoder.cpp
63+
SingleStreamDecoder.cpp
6464
)
6565

6666
if(ENABLE_CUDA)

src/torchcodec/_core/CPUOnlyDevice.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ namespace facebook::torchcodec {
1616

1717
void convertAVFrameToFrameOutputOnCuda(
1818
const torch::Device& device,
19-
[[maybe_unused]] const VideoDecoder::VideoStreamOptions& videoStreamOptions,
19+
[[maybe_unused]] const SingleStreamDecoder::VideoStreamOptions&
20+
videoStreamOptions,
2021
[[maybe_unused]] UniqueAVFrame& avFrame,
21-
[[maybe_unused]] VideoDecoder::FrameOutput& frameOutput,
22+
[[maybe_unused]] SingleStreamDecoder::FrameOutput& frameOutput,
2223
[[maybe_unused]] std::optional<torch::Tensor> preAllocatedOutputTensor) {
2324
throwUnsupportedDeviceError(device);
2425
}

src/torchcodec/_core/CudaDevice.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "src/torchcodec/_core/DeviceInterface.h"
88
#include "src/torchcodec/_core/FFMPEGCommon.h"
9-
#include "src/torchcodec/_core/VideoDecoder.h"
9+
#include "src/torchcodec/_core/SingleStreamDecoder.h"
1010

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

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

190192
void convertAVFrameToFrameOutputOnCuda(
191193
const torch::Device& device,
192-
const VideoDecoder::VideoStreamOptions& videoStreamOptions,
194+
const SingleStreamDecoder::VideoStreamOptions& videoStreamOptions,
193195
UniqueAVFrame& avFrame,
194-
VideoDecoder::FrameOutput& frameOutput,
196+
SingleStreamDecoder::FrameOutput& frameOutput,
195197
std::optional<torch::Tensor> preAllocatedOutputTensor) {
196198
TORCH_CHECK(
197199
avFrame->format == AV_PIX_FMT_CUDA,

src/torchcodec/_core/DeviceInterface.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
#include <stdexcept>
1212
#include <string>
1313
#include "FFMPEGCommon.h"
14-
#include "src/torchcodec/_core/VideoDecoder.h"
14+
#include "src/torchcodec/_core/SingleStreamDecoder.h"
1515

1616
namespace facebook::torchcodec {
1717

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

3232
void convertAVFrameToFrameOutputOnCuda(
3333
const torch::Device& device,
34-
const VideoDecoder::VideoStreamOptions& videoStreamOptions,
34+
const SingleStreamDecoder::VideoStreamOptions& videoStreamOptions,
3535
UniqueAVFrame& avFrame,
36-
VideoDecoder::FrameOutput& frameOutput,
36+
SingleStreamDecoder::FrameOutput& frameOutput,
3737
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
3838

3939
void releaseContextOnCuda(

0 commit comments

Comments
 (0)