Skip to content

Commit 4574e95

Browse files
committed
Merge branch 'main' of github.com:pytorch/torchcodec into approx
2 parents f4c001b + d26bfbc commit 4574e95

File tree

9 files changed

+36
-38
lines changed

9 files changed

+36
-38
lines changed

.github/workflows/docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
run: |
113113
cd docs
114114
${CONDA_RUN} make html
115-
- uses: actions/upload-artifact@v3
115+
- uses: actions/upload-artifact@v4
116116
with:
117117
name: Built-Docs
118118
path: docs/build/html/

src/torchcodec/decoders/_core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD 17)
44
set(CMAKE_CXX_STANDARD_REQUIRED ON)
55

66
find_package(Torch REQUIRED)
7-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
7+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Werror ${TORCH_CXX_FLAGS}")
88
find_package(Python3 ${PYTHON_VERSION} EXACT COMPONENTS Development)
99

1010
function(make_torchcodec_library library_name ffmpeg_target)

src/torchcodec/decoders/_core/CPUOnlyDevice.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ namespace facebook::torchcodec {
1616

1717
void convertAVFrameToDecodedOutputOnCuda(
1818
const torch::Device& device,
19-
const VideoDecoder::VideoStreamDecoderOptions& options,
20-
VideoDecoder::RawDecodedOutput& rawOutput,
21-
VideoDecoder::DecodedOutput& output,
22-
std::optional<torch::Tensor> preAllocatedOutputTensor) {
19+
[[maybe_unused]] const VideoDecoder::VideoStreamDecoderOptions& options,
20+
[[maybe_unused]] VideoDecoder::RawDecodedOutput& rawOutput,
21+
[[maybe_unused]] VideoDecoder::DecodedOutput& output,
22+
[[maybe_unused]] std::optional<torch::Tensor> preAllocatedOutputTensor) {
2323
throwUnsupportedDeviceError(device);
2424
}
2525

2626
void initializeContextOnCuda(
2727
const torch::Device& device,
28-
AVCodecContext* codecContext) {
28+
[[maybe_unused]] AVCodecContext* codecContext) {
2929
throwUnsupportedDeviceError(device);
3030
}
3131

3232
void releaseContextOnCuda(
3333
const torch::Device& device,
34-
AVCodecContext* codecContext) {
34+
[[maybe_unused]] AVCodecContext* codecContext) {
3535
throwUnsupportedDeviceError(device);
3636
}
3737

3838
std::optional<AVCodecPtr> findCudaCodec(
3939
const torch::Device& device,
40-
const AVCodecID& codecId) {
40+
[[maybe_unused]] const AVCodecID& codecId) {
4141
throwUnsupportedDeviceError(device);
4242
}
4343

src/torchcodec/decoders/_core/CudaDevice.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
1010

1111
extern "C" {
12-
#include <libavcodec/avcodec.h>
1312
#include <libavutil/hwcontext_cuda.h>
1413
#include <libavutil/pixdesc.h>
1514
}
@@ -110,7 +109,7 @@ AVBufferRef* getFFMPEGContextFromExistingCudaContext(
110109
#else
111110

112111
AVBufferRef* getFFMPEGContextFromNewCudaContext(
113-
const torch::Device& device,
112+
[[maybe_unused]] const torch::Device& device,
114113
torch::DeviceIndex nonNegativeDeviceIndex,
115114
enum AVHWDeviceType type) {
116115
AVBufferRef* hw_device_ctx = nullptr;
@@ -260,24 +259,23 @@ void convertAVFrameToDecodedOutputOnCuda(
260259
// we have to do this because of an FFmpeg bug where hardware decoding is not
261260
// appropriately set, so we just go off and find the matching codec for the CUDA
262261
// device
263-
std::optional<AVCodecPtr> findCudaCodec(
262+
std::optional<const AVCodec*> findCudaCodec(
264263
const torch::Device& device,
265264
const AVCodecID& codecId) {
266265
throwErrorIfNonCudaDevice(device);
267266

268-
void* i = NULL;
269-
270-
AVCodecPtr c;
271-
while (c = av_codec_iterate(&i)) {
272-
const AVCodecHWConfig* config;
273-
274-
if (c->id != codecId || !av_codec_is_decoder(c)) {
267+
void* i = nullptr;
268+
const AVCodec* codec = nullptr;
269+
while ((codec = av_codec_iterate(&i)) != nullptr) {
270+
if (codec->id != codecId || !av_codec_is_decoder(codec)) {
275271
continue;
276272
}
277273

278-
for (int j = 0; config = avcodec_get_hw_config(c, j); j++) {
274+
const AVCodecHWConfig* config = nullptr;
275+
for (int j = 0; (config = avcodec_get_hw_config(codec, j)) != nullptr;
276+
++j) {
279277
if (config->device_type == AV_HWDEVICE_TYPE_CUDA) {
280-
return c;
278+
return codec;
281279
}
282280
}
283281
}

src/torchcodec/decoders/_core/DeviceInterface.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
#include "FFMPEGCommon.h"
1414
#include "src/torchcodec/decoders/_core/VideoDecoder.h"
1515

16-
extern "C" {
17-
#include <libavcodec/avcodec.h>
18-
}
19-
2016
namespace facebook::torchcodec {
2117

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

src/torchcodec/decoders/_core/FFMPEGCommon.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int64_t getDuration(const UniqueAVFrame& frame) {
2121
}
2222

2323
int64_t getDuration(const AVFrame* frame) {
24-
#if LIBAVUTIL_VERSION_MAJOR < 59
24+
#if LIBAVUTIL_VERSION_MAJOR < 58
2525
return frame->pkt_duration;
2626
#else
2727
return frame->duration;
@@ -75,7 +75,8 @@ int AVIOBytesContext::read(void* opaque, uint8_t* buf, int buf_size) {
7575
bufferData->current,
7676
", size=",
7777
bufferData->size);
78-
buf_size = FFMIN(buf_size, bufferData->size - bufferData->current);
78+
buf_size =
79+
FFMIN(buf_size, static_cast<int>(bufferData->size - bufferData->current));
7980
TORCH_CHECK(
8081
buf_size >= 0,
8182
"Tried to read negative bytes: buf_size=",

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ VideoDecoder::BatchDecodedOutput::BatchDecodedOutput(
206206

207207
bool VideoDecoder::DecodedFrameContext::operator==(
208208
const VideoDecoder::DecodedFrameContext& other) {
209-
return decodedWidth == other.decodedWidth && decodedHeight == decodedHeight &&
209+
return decodedWidth == other.decodedWidth &&
210+
decodedHeight == other.decodedHeight &&
210211
decodedFormat == other.decodedFormat &&
211212
expectedWidth == other.expectedWidth &&
212213
expectedHeight == other.expectedHeight;
@@ -251,12 +252,12 @@ void VideoDecoder::initializeDecoder() {
251252
getFFMPEGErrorStringFromErrorCode(ffmpegStatus));
252253
}
253254

254-
for (int i = 0; i < formatContext_->nb_streams; i++) {
255+
for (unsigned int i = 0; i < formatContext_->nb_streams; i++) {
255256
AVStream* stream = formatContext_->streams[i];
256257
StreamMetadata meta;
257258

258259
TORCH_CHECK(
259-
i == stream->index,
260+
static_cast<int>(i) == stream->index,
260261
"Our stream index, " + std::to_string(i) +
261262
", does not match AVStream's index, " +
262263
std::to_string(stream->index) + ".");
@@ -611,7 +612,7 @@ void VideoDecoder::scanFileAndUpdateMetadataAndIndex() {
611612

612613
// Set all per-stream metadata that requires knowing the content of all
613614
// packets.
614-
for (int i = 0; i < containerMetadata_.streams.size(); ++i) {
615+
for (size_t i = 0; i < containerMetadata_.streams.size(); ++i) {
615616
auto& streamMetadata = containerMetadata_.streams[i];
616617
auto stream = formatContext_->streams[i];
617618

@@ -651,7 +652,7 @@ void VideoDecoder::scanFileAndUpdateMetadataAndIndex() {
651652
return frameInfo1.pts < frameInfo2.pts;
652653
});
653654

654-
for (int i = 0; i < stream.allFrames.size(); ++i) {
655+
for (size_t i = 0; i < stream.allFrames.size(); ++i) {
655656
if (i + 1 < stream.allFrames.size()) {
656657
stream.allFrames[i].nextPts = stream.allFrames[i + 1].pts;
657658
}
@@ -1094,8 +1095,8 @@ VideoDecoder::DecodedOutput VideoDecoder::getFramePlayedAtTimestampNoDemux(
10941095
return output;
10951096
}
10961097

1097-
void VideoDecoder::validateUserProvidedStreamIndex(uint64_t streamIndex) {
1098-
size_t streamsSize = containerMetadata_.streams.size();
1098+
void VideoDecoder::validateUserProvidedStreamIndex(int streamIndex) {
1099+
int streamsSize = static_cast<int>(containerMetadata_.streams.size());
10991100
TORCH_CHECK(
11001101
streamIndex >= 0 && streamIndex < streamsSize,
11011102
"Invalid stream index=" + std::to_string(streamIndex) +
@@ -1272,9 +1273,10 @@ VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesAtIndices(
12721273
BatchDecodedOutput output(frameIndices.size(), options, streamMetadata);
12731274

12741275
auto previousIndexInVideo = -1;
1275-
for (auto f = 0; f < frameIndices.size(); ++f) {
1276+
for (size_t f = 0; f < frameIndices.size(); ++f) {
12761277
auto indexInOutput = indicesAreSorted ? f : argsort[f];
12771278
auto indexInVideo = frameIndices[indexInOutput];
1279+
12781280
validateFrameIndex(streamMetadata, indexInVideo);
12791281

12801282
if ((f > 0) && (indexInVideo == previousIndexInVideo)) {
@@ -1314,7 +1316,7 @@ VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesPlayedByTimestamps(
13141316
// to indices, and leverage the de-duplication logic of getFramesAtIndices.
13151317

13161318
std::vector<int64_t> frameIndices(timestamps.size());
1317-
for (auto i = 0; i < timestamps.size(); ++i) {
1319+
for (size_t i = 0; i < timestamps.size(); ++i) {
13181320
auto frameSeconds = timestamps[i];
13191321
TORCH_CHECK(
13201322
frameSeconds >= minSeconds && frameSeconds < maxSeconds,

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class VideoDecoder {
370370
// for more details about the heuristics.
371371
int getBestStreamIndex(AVMediaType mediaType);
372372
void initializeDecoder();
373-
void validateUserProvidedStreamIndex(uint64_t streamIndex);
373+
void validateUserProvidedStreamIndex(int streamIndex);
374374
void validateScannedAllStreams(const std::string& msg);
375375
void validateFrameIndex(
376376
const StreamMetadata& streamMetadata,

src/torchcodec/decoders/_core/VideoDecoderOps.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ std::string get_stream_json_metadata(
433433
int64_t stream_index) {
434434
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
435435
auto streams = videoDecoder->getContainerMetadata().streams;
436-
if (stream_index < 0 || stream_index >= streams.size()) {
436+
if (stream_index < 0 ||
437+
stream_index >= static_cast<int64_t>(streams.size())) {
437438
throw std::out_of_range(
438439
"stream_index out of bounds: " + std::to_string(stream_index));
439440
}

0 commit comments

Comments
 (0)