Skip to content

Commit c42388f

Browse files
committed
put initializeBSF below
1 parent 718a3e3 commit c42388f

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/torchcodec/_core/BetaCudaDeviceInterface.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,44 @@ BetaCudaDeviceInterface::~BetaCudaDeviceInterface() {
180180
}
181181
}
182182

183+
void BetaCudaDeviceInterface::initialize(
184+
const AVStream* avStream,
185+
const UniqueDecodingAVFormatContext& avFormatCtx) {
186+
torch::Tensor dummyTensorForCudaInitialization = torch::empty(
187+
{1}, torch::TensorOptions().dtype(torch::kUInt8).device(device_));
188+
189+
auto cudaDevice = torch::Device(torch::kCUDA);
190+
defaultCudaInterface_ =
191+
std::unique_ptr<DeviceInterface>(createDeviceInterface(cudaDevice));
192+
AVCodecContext dummyCodecContext = {};
193+
defaultCudaInterface_->initialize(avStream, avFormatCtx);
194+
defaultCudaInterface_->registerHardwareDeviceWithCodec(&dummyCodecContext);
195+
196+
TORCH_CHECK(avStream != nullptr, "AVStream cannot be null");
197+
timeBase_ = avStream->time_base;
198+
199+
const AVCodecParameters* codecPar = avStream->codecpar;
200+
TORCH_CHECK(codecPar != nullptr, "CodecParameters cannot be null");
201+
202+
initializeBSF(codecPar, avFormatCtx);
203+
204+
// Create parser. Default values that aren't obvious are taken from DALI.
205+
CUVIDPARSERPARAMS parserParams = {};
206+
parserParams.CodecType = validateCodecSupport(codecPar->codec_id);
207+
parserParams.ulMaxNumDecodeSurfaces = 8;
208+
parserParams.ulMaxDisplayDelay = 0;
209+
// Callback setup, all are triggered by the parser within a call
210+
// to cuvidParseVideoData
211+
parserParams.pUserData = this;
212+
parserParams.pfnSequenceCallback = pfnSequenceCallback;
213+
parserParams.pfnDecodePicture = pfnDecodePictureCallback;
214+
parserParams.pfnDisplayPicture = pfnDisplayPictureCallback;
215+
216+
CUresult result = cuvidCreateVideoParser(&videoParser_, &parserParams);
217+
TORCH_CHECK(
218+
result == CUDA_SUCCESS, "Failed to create video parser: ", result);
219+
}
220+
183221
void BetaCudaDeviceInterface::initializeBSF(
184222
const AVCodecParameters* codecPar,
185223
const UniqueDecodingAVFormatContext& avFormatCtx) {
@@ -259,44 +297,6 @@ void BetaCudaDeviceInterface::initializeBSF(
259297
getFFMPEGErrorStringFromErrorCode(retVal));
260298
}
261299

262-
void BetaCudaDeviceInterface::initialize(
263-
const AVStream* avStream,
264-
const UniqueDecodingAVFormatContext& avFormatCtx) {
265-
torch::Tensor dummyTensorForCudaInitialization = torch::empty(
266-
{1}, torch::TensorOptions().dtype(torch::kUInt8).device(device_));
267-
268-
auto cudaDevice = torch::Device(torch::kCUDA);
269-
defaultCudaInterface_ =
270-
std::unique_ptr<DeviceInterface>(createDeviceInterface(cudaDevice));
271-
AVCodecContext dummyCodecContext = {};
272-
defaultCudaInterface_->initialize(avStream, avFormatCtx);
273-
defaultCudaInterface_->registerHardwareDeviceWithCodec(&dummyCodecContext);
274-
275-
TORCH_CHECK(avStream != nullptr, "AVStream cannot be null");
276-
timeBase_ = avStream->time_base;
277-
278-
const AVCodecParameters* codecPar = avStream->codecpar;
279-
TORCH_CHECK(codecPar != nullptr, "CodecParameters cannot be null");
280-
281-
initializeBSF(codecPar, avFormatCtx);
282-
283-
// Create parser. Default values that aren't obvious are taken from DALI.
284-
CUVIDPARSERPARAMS parserParams = {};
285-
parserParams.CodecType = validateCodecSupport(codecPar->codec_id);
286-
parserParams.ulMaxNumDecodeSurfaces = 8;
287-
parserParams.ulMaxDisplayDelay = 0;
288-
// Callback setup, all are triggered by the parser within a call
289-
// to cuvidParseVideoData
290-
parserParams.pUserData = this;
291-
parserParams.pfnSequenceCallback = pfnSequenceCallback;
292-
parserParams.pfnDecodePicture = pfnDecodePictureCallback;
293-
parserParams.pfnDisplayPicture = pfnDisplayPictureCallback;
294-
295-
CUresult result = cuvidCreateVideoParser(&videoParser_, &parserParams);
296-
TORCH_CHECK(
297-
result == CUDA_SUCCESS, "Failed to create video parser: ", result);
298-
}
299-
300300
// This callback is called by the parser within cuvidParseVideoData when there
301301
// is a change in the stream's properties (like resolution change), as specified
302302
// by CUVIDEOFORMAT. Particularly (but not just!), this is called at the very

0 commit comments

Comments
 (0)