Skip to content

Commit 4d41abb

Browse files
author
Daniel Flores
committed
replace nullptrs with torch check
1 parent c4d0df8 commit 4d41abb

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/torchcodec/_core/FFMPEGCommon.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,18 @@ AVFilterContext* createBuffersinkFilter(
384384
const char* name,
385385
enum AVPixelFormat outputFormat) {
386386
const AVFilter* buffersink = avfilter_get_by_name("buffersink");
387-
if (!buffersink) {
388-
return nullptr;
389-
}
387+
TORCH_CHECK(buffersink != nullptr, "Failed to get buffersink filter.");
388+
390389
AVFilterContext* sinkContext = nullptr;
391390
int status;
392391

393392
// av_opt_set_int_list was replaced by av_opt_set() in FFmpeg 8.
394393
#if LIBAVUTIL_VERSION_MAJOR >= 60 // FFmpeg >= 8
395394
// Output options like pixel_formats must be set before filter init
396395
sinkContext = avfilter_graph_alloc_filter(filterGraph, buffersink, name);
397-
if (!sinkContext) {
398-
return nullptr;
399-
}
396+
TORCH_CHECK(
397+
sinkContext != nullptr, "Failed to allocate buffersink filter context.");
398+
400399
status = av_opt_set_array(
401400
sinkContext,
402401
"pixel_formats",
@@ -405,20 +404,24 @@ AVFilterContext* createBuffersinkFilter(
405404
1, // nb_elems
406405
AV_OPT_TYPE_PIXEL_FMT,
407406
&outputFormat);
408-
if (status < 0) {
409-
return nullptr;
410-
}
407+
TORCH_CHECK(
408+
status >= 0,
409+
"Failed to set pixel format for buffersink filter: ",
410+
getFFMPEGErrorStringFromErrorCode(status));
411+
411412
status = avfilter_init_str(sinkContext, nullptr);
412-
if (status < 0) {
413-
return nullptr;
414-
}
413+
TORCH_CHECK(
414+
status >= 0,
415+
"Failed to initialize buffersink filter: ",
416+
getFFMPEGErrorStringFromErrorCode(status));
415417
#else // FFmpeg <= 7
416418
// For older FFmpeg versions, create filter and then set options
417419
status = avfilter_graph_create_filter(
418420
&sinkContext, buffersink, name, nullptr, nullptr, filterGraph);
419-
if (status < 0) {
420-
return nullptr;
421-
}
421+
TORCH_CHECK(
422+
status >= 0,
423+
"Failed to create buffersink filter: ",
424+
getFFMPEGErrorStringFromErrorCode(status));
422425

423426
enum AVPixelFormat pix_fmts[] = {outputFormat, AV_PIX_FMT_NONE};
424427

@@ -428,9 +431,10 @@ AVFilterContext* createBuffersinkFilter(
428431
pix_fmts,
429432
AV_PIX_FMT_NONE,
430433
AV_OPT_SEARCH_CHILDREN);
431-
if (status < 0) {
432-
return nullptr;
433-
}
434+
TORCH_CHECK(
435+
status >= 0,
436+
"Failed to set pixel formats for buffersink filter: ",
437+
getFFMPEGErrorStringFromErrorCode(status));
434438
#endif
435439

436440
return sinkContext;

0 commit comments

Comments
 (0)