Skip to content

Commit

Permalink
Move declarations out of while loop
Browse files Browse the repository at this point in the history
  • Loading branch information
scotts committed Jan 16, 2025
1 parent 4883b03 commit a4df539
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/torchcodec/decoders/_core/CudaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "src/torchcodec/decoders/_core/VideoDecoder.h"

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/hwcontext_cuda.h>
#include <libavutil/pixdesc.h>
}
Expand Down Expand Up @@ -266,14 +265,15 @@ std::optional<const AVCodec*> findCudaCodec(
throwErrorIfNonCudaDevice(device);

void* i = nullptr;
while ((AVCodec* codec = av_codec_iterate(&i)) != nullptr) {
const AVCodec** codec = nullptr;
while ((*codec = av_codec_iterate(&i)) != nullptr) {
if (codec->id != codecId || !av_codec_is_decoder(codec)) {
continue;
}

for (int j = 0;
(AVCodecHWConfig* config = avcodec_get_hw_config(codec, j)) != nullptr;
j++) {
const AVCodecHWConfig** config = nullptr;
for (int j = 0; (*config = avcodec_get_hw_config(codec, j)) != nullptr;
++j) {
if (config->device_type == AV_HWDEVICE_TYPE_CUDA) {
return codec;
}
Expand Down
4 changes: 0 additions & 4 deletions src/torchcodec/decoders/_core/DeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
#include "FFMPEGCommon.h"
#include "src/torchcodec/decoders/_core/VideoDecoder.h"

extern "C" {
#include <libavcodec/avcodec.h>
}

namespace facebook::torchcodec {

// Note that all these device functions should only be called if the device is
Expand Down

0 comments on commit a4df539

Please sign in to comment.