Skip to content

Commit 5828cfd

Browse files
committed
Adding namespaces and moving private methods to anonymous namespaces.
1 parent 94a8192 commit 5828cfd

File tree

4 files changed

+171
-100
lines changed

4 files changed

+171
-100
lines changed

torchvision/csrc/io/video/video.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
#include <regex>
44

5-
using namespace std;
6-
using namespace ffmpeg;
5+
namespace vision {
6+
namespace video {
7+
8+
namespace {
79

810
const size_t decoderTimeoutMs = 600000;
911
const AVPixelFormat defaultVideoPixelFormat = AV_PIX_FMT_RGB24;
@@ -90,6 +92,8 @@ std::tuple<std::string, long> _parseStream(const std::string& streamString) {
9092
return std::make_tuple(type_, index_);
9193
}
9294

95+
} // namespace
96+
9397
void Video::_getDecoderParams(
9498
double videoStartS,
9599
int64_t getPtsOnly,
@@ -325,3 +329,6 @@ static auto registerVideo =
325329
.def("get_metadata", &Video::getStreamMetadata)
326330
.def("seek", &Video::Seek)
327331
.def("next", &Video::Next);
332+
333+
} // namespace video
334+
} // namespace vision

torchvision/csrc/io/video/video.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
using namespace ffmpeg;
1010

11+
namespace vision {
12+
namespace video {
13+
1114
struct Video : torch::CustomClassHolder {
1215
std::tuple<std::string, long> current_stream; // stream type, id
1316
// global video metadata
@@ -50,3 +53,6 @@ struct Video : torch::CustomClassHolder {
5053
DecoderParameters params;
5154

5255
}; // struct Video
56+
57+
} // namespace video
58+
} // namespace vision

torchvision/csrc/io/video_reader/video_reader.cpp

Lines changed: 104 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#include <Python.h>
44

5+
#include "../decoder/memory_buffer.h"
6+
#include "../decoder/sync_decoder.h"
7+
58
// If we are in a Windows environment, we need to define
69
// initialization functions for the _custom_ops extension
710
#ifdef _WIN32
@@ -11,11 +14,13 @@ PyMODINIT_FUNC PyInit_video_reader(void) {
1114
}
1215
#endif
1316

14-
using namespace std;
1517
using namespace ffmpeg;
1618

19+
namespace vision {
1720
namespace video_reader {
1821

22+
namespace {
23+
1924
const AVPixelFormat defaultVideoPixelFormat = AV_PIX_FMT_RGB24;
2025
const AVSampleFormat defaultAudioSampleFormat = AV_SAMPLE_FMT_FLT;
2126
const AVRational timeBaseQ = AVRational{1, AV_TIME_BASE};
@@ -413,95 +418,6 @@ torch::List<torch::Tensor> readVideo(
413418
return result;
414419
}
415420

416-
torch::List<torch::Tensor> readVideoFromMemory(
417-
torch::Tensor input_video,
418-
double seekFrameMargin,
419-
int64_t getPtsOnly,
420-
int64_t readVideoStream,
421-
int64_t width,
422-
int64_t height,
423-
int64_t minDimension,
424-
int64_t maxDimension,
425-
int64_t videoStartPts,
426-
int64_t videoEndPts,
427-
int64_t videoTimeBaseNum,
428-
int64_t videoTimeBaseDen,
429-
int64_t readAudioStream,
430-
int64_t audioSamples,
431-
int64_t audioChannels,
432-
int64_t audioStartPts,
433-
int64_t audioEndPts,
434-
int64_t audioTimeBaseNum,
435-
int64_t audioTimeBaseDen) {
436-
return readVideo(
437-
false,
438-
input_video,
439-
"", // videoPath
440-
seekFrameMargin,
441-
getPtsOnly,
442-
readVideoStream,
443-
width,
444-
height,
445-
minDimension,
446-
maxDimension,
447-
videoStartPts,
448-
videoEndPts,
449-
videoTimeBaseNum,
450-
videoTimeBaseDen,
451-
readAudioStream,
452-
audioSamples,
453-
audioChannels,
454-
audioStartPts,
455-
audioEndPts,
456-
audioTimeBaseNum,
457-
audioTimeBaseDen);
458-
}
459-
460-
torch::List<torch::Tensor> readVideoFromFile(
461-
std::string videoPath,
462-
double seekFrameMargin,
463-
int64_t getPtsOnly,
464-
int64_t readVideoStream,
465-
int64_t width,
466-
int64_t height,
467-
int64_t minDimension,
468-
int64_t maxDimension,
469-
int64_t videoStartPts,
470-
int64_t videoEndPts,
471-
int64_t videoTimeBaseNum,
472-
int64_t videoTimeBaseDen,
473-
int64_t readAudioStream,
474-
int64_t audioSamples,
475-
int64_t audioChannels,
476-
int64_t audioStartPts,
477-
int64_t audioEndPts,
478-
int64_t audioTimeBaseNum,
479-
int64_t audioTimeBaseDen) {
480-
torch::Tensor dummy_input_video = torch::ones({0});
481-
return readVideo(
482-
true,
483-
dummy_input_video,
484-
videoPath,
485-
seekFrameMargin,
486-
getPtsOnly,
487-
readVideoStream,
488-
width,
489-
height,
490-
minDimension,
491-
maxDimension,
492-
videoStartPts,
493-
videoEndPts,
494-
videoTimeBaseNum,
495-
videoTimeBaseDen,
496-
readAudioStream,
497-
audioSamples,
498-
audioChannels,
499-
audioStartPts,
500-
audioEndPts,
501-
audioTimeBaseNum,
502-
audioTimeBaseDen);
503-
}
504-
505421
torch::List<torch::Tensor> probeVideo(
506422
bool isReadFile,
507423
const torch::Tensor& input_video,
@@ -646,6 +562,97 @@ torch::List<torch::Tensor> probeVideo(
646562
return result;
647563
}
648564

565+
} // namespace
566+
567+
torch::List<torch::Tensor> readVideoFromMemory(
568+
torch::Tensor input_video,
569+
double seekFrameMargin,
570+
int64_t getPtsOnly,
571+
int64_t readVideoStream,
572+
int64_t width,
573+
int64_t height,
574+
int64_t minDimension,
575+
int64_t maxDimension,
576+
int64_t videoStartPts,
577+
int64_t videoEndPts,
578+
int64_t videoTimeBaseNum,
579+
int64_t videoTimeBaseDen,
580+
int64_t readAudioStream,
581+
int64_t audioSamples,
582+
int64_t audioChannels,
583+
int64_t audioStartPts,
584+
int64_t audioEndPts,
585+
int64_t audioTimeBaseNum,
586+
int64_t audioTimeBaseDen) {
587+
return readVideo(
588+
false,
589+
input_video,
590+
"", // videoPath
591+
seekFrameMargin,
592+
getPtsOnly,
593+
readVideoStream,
594+
width,
595+
height,
596+
minDimension,
597+
maxDimension,
598+
videoStartPts,
599+
videoEndPts,
600+
videoTimeBaseNum,
601+
videoTimeBaseDen,
602+
readAudioStream,
603+
audioSamples,
604+
audioChannels,
605+
audioStartPts,
606+
audioEndPts,
607+
audioTimeBaseNum,
608+
audioTimeBaseDen);
609+
}
610+
611+
torch::List<torch::Tensor> readVideoFromFile(
612+
std::string videoPath,
613+
double seekFrameMargin,
614+
int64_t getPtsOnly,
615+
int64_t readVideoStream,
616+
int64_t width,
617+
int64_t height,
618+
int64_t minDimension,
619+
int64_t maxDimension,
620+
int64_t videoStartPts,
621+
int64_t videoEndPts,
622+
int64_t videoTimeBaseNum,
623+
int64_t videoTimeBaseDen,
624+
int64_t readAudioStream,
625+
int64_t audioSamples,
626+
int64_t audioChannels,
627+
int64_t audioStartPts,
628+
int64_t audioEndPts,
629+
int64_t audioTimeBaseNum,
630+
int64_t audioTimeBaseDen) {
631+
torch::Tensor dummy_input_video = torch::ones({0});
632+
return readVideo(
633+
true,
634+
dummy_input_video,
635+
videoPath,
636+
seekFrameMargin,
637+
getPtsOnly,
638+
readVideoStream,
639+
width,
640+
height,
641+
minDimension,
642+
maxDimension,
643+
videoStartPts,
644+
videoEndPts,
645+
videoTimeBaseNum,
646+
videoTimeBaseDen,
647+
readAudioStream,
648+
audioSamples,
649+
audioChannels,
650+
audioStartPts,
651+
audioEndPts,
652+
audioTimeBaseNum,
653+
audioTimeBaseDen);
654+
}
655+
649656
torch::List<torch::Tensor> probeVideoFromMemory(torch::Tensor input_video) {
650657
return probeVideo(false, input_video, "");
651658
}
@@ -655,11 +662,12 @@ torch::List<torch::Tensor> probeVideoFromFile(std::string videoPath) {
655662
return probeVideo(true, dummy_input_video, videoPath);
656663
}
657664

658-
} // namespace video_reader
659-
660665
TORCH_LIBRARY_FRAGMENT(video_reader, m) {
661-
m.def("read_video_from_memory", video_reader::readVideoFromMemory);
662-
m.def("read_video_from_file", video_reader::readVideoFromFile);
663-
m.def("probe_video_from_memory", video_reader::probeVideoFromMemory);
664-
m.def("probe_video_from_file", video_reader::probeVideoFromFile);
666+
m.def("read_video_from_memory", readVideoFromMemory);
667+
m.def("read_video_from_file", readVideoFromFile);
668+
m.def("probe_video_from_memory", probeVideoFromMemory);
669+
m.def("probe_video_from_file", probeVideoFromFile);
665670
}
671+
672+
} // namespace video_reader
673+
} // namespace vision
Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
#pragma once
22

33
#include <torch/types.h>
4-
#include "../decoder/memory_buffer.h"
5-
#include "../decoder/sync_decoder.h"
4+
5+
namespace vision {
6+
namespace video_reader {
7+
8+
torch::List<torch::Tensor> readVideoFromMemory(
9+
torch::Tensor input_video,
10+
double seekFrameMargin,
11+
int64_t getPtsOnly,
12+
int64_t readVideoStream,
13+
int64_t width,
14+
int64_t height,
15+
int64_t minDimension,
16+
int64_t maxDimension,
17+
int64_t videoStartPts,
18+
int64_t videoEndPts,
19+
int64_t videoTimeBaseNum,
20+
int64_t videoTimeBaseDen,
21+
int64_t readAudioStream,
22+
int64_t audioSamples,
23+
int64_t audioChannels,
24+
int64_t audioStartPts,
25+
int64_t audioEndPts,
26+
int64_t audioTimeBaseNum,
27+
int64_t audioTimeBaseDen);
28+
29+
torch::List<torch::Tensor> readVideoFromFile(
30+
std::string videoPath,
31+
double seekFrameMargin,
32+
int64_t getPtsOnly,
33+
int64_t readVideoStream,
34+
int64_t width,
35+
int64_t height,
36+
int64_t minDimension,
37+
int64_t maxDimension,
38+
int64_t videoStartPts,
39+
int64_t videoEndPts,
40+
int64_t videoTimeBaseNum,
41+
int64_t videoTimeBaseDen,
42+
int64_t readAudioStream,
43+
int64_t audioSamples,
44+
int64_t audioChannels,
45+
int64_t audioStartPts,
46+
int64_t audioEndPts,
47+
int64_t audioTimeBaseNum,
48+
int64_t audioTimeBaseDen);
49+
50+
torch::List<torch::Tensor> probeVideoFromMemory(torch::Tensor input_video);
51+
52+
torch::List<torch::Tensor> probeVideoFromFile(std::string videoPath);
53+
54+
} // namespace video_reader
55+
} // namespace vision

0 commit comments

Comments
 (0)