44#include < torch/types.h>
55#include < mutex>
66
7- #include " src/torchcodec/_core/CudaDevice .h"
7+ #include " src/torchcodec/_core/CudaDeviceInterface .h"
88#include " src/torchcodec/_core/FFMPEGCommon.h"
99#include " src/torchcodec/_core/SingleStreamDecoder.h"
1010
@@ -16,9 +16,10 @@ extern "C" {
1616namespace facebook ::torchcodec {
1717namespace {
1818
19- bool g_cuda = registerDeviceInterface(
20- torch::kCUDA ,
21- [](const torch::Device& device) { return new CudaDevice (device); });
19+ bool g_cuda =
20+ registerDeviceInterface (torch::kCUDA , [](const torch::Device& device) {
21+ return new CudaDeviceInterface (device);
22+ });
2223
2324// We reuse cuda contexts across VideoDeoder instances. This is because
2425// creating a cuda context is expensive. The cache mechanism is as follows:
@@ -163,20 +164,21 @@ AVBufferRef* getCudaContext(const torch::Device& device) {
163164}
164165} // namespace
165166
166- CudaDevice::CudaDevice (const torch::Device& device) : DeviceInterface(device) {
167+ CudaDeviceInterface::CudaDeviceInterface (const torch::Device& device)
168+ : DeviceInterface(device) {
167169 if (device_.type () != torch::kCUDA ) {
168170 throw std::runtime_error (" Unsupported device: " + device_.str ());
169171 }
170172}
171173
172- CudaDevice ::~CudaDevice () {
174+ CudaDeviceInterface ::~CudaDeviceInterface () {
173175 if (ctx_) {
174176 addToCacheIfCacheHasCapacity (device_, ctx_);
175177 av_buffer_unref (&ctx_);
176178 }
177179}
178180
179- void CudaDevice ::initializeContext (AVCodecContext* codecContext) {
181+ void CudaDeviceInterface ::initializeContext (AVCodecContext* codecContext) {
180182 TORCH_CHECK (!ctx_, " FFmpeg HW device context already initialized" );
181183
182184 // It is important for pytorch itself to create the cuda context. If ffmpeg
@@ -189,7 +191,7 @@ void CudaDevice::initializeContext(AVCodecContext* codecContext) {
189191 return ;
190192}
191193
192- void CudaDevice ::convertAVFrameToFrameOutput (
194+ void CudaDeviceInterface ::convertAVFrameToFrameOutput (
193195 const VideoStreamOptions& videoStreamOptions,
194196 UniqueAVFrame& avFrame,
195197 FrameOutput& frameOutput,
@@ -263,7 +265,8 @@ void CudaDevice::convertAVFrameToFrameOutput(
263265// we have to do this because of an FFmpeg bug where hardware decoding is not
264266// appropriately set, so we just go off and find the matching codec for the CUDA
265267// device
266- std::optional<const AVCodec*> CudaDevice::findCodec (const AVCodecID& codecId) {
268+ std::optional<const AVCodec*> CudaDeviceInterface::findCodec (
269+ const AVCodecID& codecId) {
267270 void * i = nullptr ;
268271 const AVCodec* codec = nullptr ;
269272 while ((codec = av_codec_iterate (&i)) != nullptr ) {
0 commit comments