Unverified Commit 1980f8af authored by Richard Barnes's avatar Richard Barnes Committed by GitHub
Browse files

[codemod] c10::optional -> std::optional in pytorch/audio/src/libtorchaudio/sox/effects.cpp +20

Differential Revision: D57294298

Pull Request resolved: https://github.com/pytorch/audio/pull/3791
parent 9f10306b
...@@ -86,9 +86,9 @@ auto apply_effects_tensor( ...@@ -86,9 +86,9 @@ auto apply_effects_tensor(
auto apply_effects_file( auto apply_effects_file(
const std::string& path, const std::string& path,
const std::vector<std::vector<std::string>>& effects, const std::vector<std::vector<std::string>>& effects,
c10::optional<bool> normalize, std::optional<bool> normalize,
c10::optional<bool> channels_first, std::optional<bool> channels_first,
const c10::optional<std::string>& format) const std::optional<std::string>& format)
-> std::tuple<torch::Tensor, int64_t> { -> std::tuple<torch::Tensor, int64_t> {
// Open input file // Open input file
SoxFormat sf(sox_open_read( SoxFormat sf(sox_open_read(
......
...@@ -19,9 +19,9 @@ auto apply_effects_tensor( ...@@ -19,9 +19,9 @@ auto apply_effects_tensor(
auto apply_effects_file( auto apply_effects_file(
const std::string& path, const std::string& path,
const std::vector<std::vector<std::string>>& effects, const std::vector<std::vector<std::string>>& effects,
c10::optional<bool> normalize, std::optional<bool> normalize,
c10::optional<bool> channels_first, std::optional<bool> channels_first,
const c10::optional<std::string>& format) const std::optional<std::string>& format)
-> std::tuple<torch::Tensor, int64_t>; -> std::tuple<torch::Tensor, int64_t>;
} // namespace torchaudio::sox } // namespace torchaudio::sox
......
...@@ -10,7 +10,7 @@ namespace torchaudio::sox { ...@@ -10,7 +10,7 @@ namespace torchaudio::sox {
std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file( std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
const std::string& path, const std::string& path,
const c10::optional<std::string>& format) { const std::optional<std::string>& format) {
SoxFormat sf(sox_open_read( SoxFormat sf(sox_open_read(
path.c_str(), path.c_str(),
/*signal=*/nullptr, /*signal=*/nullptr,
...@@ -28,8 +28,8 @@ std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file( ...@@ -28,8 +28,8 @@ std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
} }
std::vector<std::vector<std::string>> get_effects( std::vector<std::vector<std::string>> get_effects(
const c10::optional<int64_t>& frame_offset, const std::optional<int64_t>& frame_offset,
const c10::optional<int64_t>& num_frames) { const std::optional<int64_t>& num_frames) {
const auto offset = frame_offset.value_or(0); const auto offset = frame_offset.value_or(0);
TORCH_CHECK( TORCH_CHECK(
offset >= 0, offset >= 0,
...@@ -57,11 +57,11 @@ std::vector<std::vector<std::string>> get_effects( ...@@ -57,11 +57,11 @@ std::vector<std::vector<std::string>> get_effects(
std::tuple<torch::Tensor, int64_t> load_audio_file( std::tuple<torch::Tensor, int64_t> load_audio_file(
const std::string& path, const std::string& path,
const c10::optional<int64_t>& frame_offset, const std::optional<int64_t>& frame_offset,
const c10::optional<int64_t>& num_frames, const std::optional<int64_t>& num_frames,
c10::optional<bool> normalize, std::optional<bool> normalize,
c10::optional<bool> channels_first, std::optional<bool> channels_first,
const c10::optional<std::string>& format) { const std::optional<std::string>& format) {
auto effects = get_effects(frame_offset, num_frames); auto effects = get_effects(frame_offset, num_frames);
return apply_effects_file(path, effects, normalize, channels_first, format); return apply_effects_file(path, effects, normalize, channels_first, format);
} }
...@@ -71,10 +71,10 @@ void save_audio_file( ...@@ -71,10 +71,10 @@ void save_audio_file(
torch::Tensor tensor, torch::Tensor tensor,
int64_t sample_rate, int64_t sample_rate,
bool channels_first, bool channels_first,
c10::optional<double> compression, std::optional<double> compression,
c10::optional<std::string> format, std::optional<std::string> format,
c10::optional<std::string> encoding, std::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample) { std::optional<int64_t> bits_per_sample) {
validate_input_tensor(tensor); validate_input_tensor(tensor);
const auto filetype = [&]() { const auto filetype = [&]() {
......
...@@ -7,31 +7,31 @@ ...@@ -7,31 +7,31 @@
namespace torchaudio::sox { namespace torchaudio::sox {
auto get_effects( auto get_effects(
const c10::optional<int64_t>& frame_offset, const std::optional<int64_t>& frame_offset,
const c10::optional<int64_t>& num_frames) const std::optional<int64_t>& num_frames)
-> std::vector<std::vector<std::string>>; -> std::vector<std::vector<std::string>>;
std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file( std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
const std::string& path, const std::string& path,
const c10::optional<std::string>& format); const std::optional<std::string>& format);
std::tuple<torch::Tensor, int64_t> load_audio_file( std::tuple<torch::Tensor, int64_t> load_audio_file(
const std::string& path, const std::string& path,
const c10::optional<int64_t>& frame_offset, const std::optional<int64_t>& frame_offset,
const c10::optional<int64_t>& num_frames, const std::optional<int64_t>& num_frames,
c10::optional<bool> normalize, std::optional<bool> normalize,
c10::optional<bool> channels_first, std::optional<bool> channels_first,
const c10::optional<std::string>& format); const std::optional<std::string>& format);
void save_audio_file( void save_audio_file(
const std::string& path, const std::string& path,
torch::Tensor tensor, torch::Tensor tensor,
int64_t sample_rate, int64_t sample_rate,
bool channels_first, bool channels_first,
c10::optional<double> compression, std::optional<double> compression,
c10::optional<std::string> format, std::optional<std::string> format,
c10::optional<std::string> encoding, std::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample); std::optional<int64_t> bits_per_sample);
} // namespace torchaudio::sox } // namespace torchaudio::sox
......
...@@ -67,7 +67,7 @@ std::string to_string(Encoding v) { ...@@ -67,7 +67,7 @@ std::string to_string(Encoding v) {
} }
} }
Encoding get_encoding_from_option(const c10::optional<std::string>& encoding) { Encoding get_encoding_from_option(const std::optional<std::string>& encoding) {
if (!encoding.has_value()) if (!encoding.has_value())
return Encoding::NOT_PROVIDED; return Encoding::NOT_PROVIDED;
std::string v = encoding.value(); std::string v = encoding.value();
...@@ -84,7 +84,7 @@ Encoding get_encoding_from_option(const c10::optional<std::string>& encoding) { ...@@ -84,7 +84,7 @@ Encoding get_encoding_from_option(const c10::optional<std::string>& encoding) {
TORCH_CHECK(false, "Internal Error: unexpected encoding value: ", v); TORCH_CHECK(false, "Internal Error: unexpected encoding value: ", v);
} }
BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth) { BitDepth get_bit_depth_from_option(const std::optional<int64_t>& bit_depth) {
if (!bit_depth.has_value()) if (!bit_depth.has_value())
return BitDepth::NOT_PROVIDED; return BitDepth::NOT_PROVIDED;
int64_t v = bit_depth.value(); int64_t v = bit_depth.value();
......
...@@ -38,7 +38,7 @@ enum class Encoding { ...@@ -38,7 +38,7 @@ enum class Encoding {
}; };
std::string to_string(Encoding v); std::string to_string(Encoding v);
Encoding get_encoding_from_option(const c10::optional<std::string>& encoding); Encoding get_encoding_from_option(const std::optional<std::string>& encoding);
enum class BitDepth : unsigned { enum class BitDepth : unsigned {
NOT_PROVIDED = 0, NOT_PROVIDED = 0,
...@@ -49,7 +49,7 @@ enum class BitDepth : unsigned { ...@@ -49,7 +49,7 @@ enum class BitDepth : unsigned {
B64 = 64, B64 = 64,
}; };
BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth); BitDepth get_bit_depth_from_option(const std::optional<int64_t>& bit_depth);
std::string get_encoding(sox_encoding_t encoding); std::string get_encoding(sox_encoding_t encoding);
......
...@@ -289,8 +289,8 @@ std::tuple<sox_encoding_t, unsigned> get_save_encoding_for_wav( ...@@ -289,8 +289,8 @@ std::tuple<sox_encoding_t, unsigned> get_save_encoding_for_wav(
std::tuple<sox_encoding_t, unsigned> get_save_encoding( std::tuple<sox_encoding_t, unsigned> get_save_encoding(
const std::string& format, const std::string& format,
const caffe2::TypeMeta& dtype, const caffe2::TypeMeta& dtype,
const c10::optional<std::string>& encoding, const std::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample) { const std::optional<int64_t>& bits_per_sample) {
const Format fmt = get_format_from_string(format); const Format fmt = get_format_from_string(format);
const Encoding enc = get_encoding_from_option(encoding); const Encoding enc = get_encoding_from_option(encoding);
const BitDepth bps = get_bit_depth_from_option(bits_per_sample); const BitDepth bps = get_bit_depth_from_option(bits_per_sample);
...@@ -492,9 +492,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(caffe2::TypeMeta dtype) { ...@@ -492,9 +492,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(caffe2::TypeMeta dtype) {
sox_encodinginfo_t get_encodinginfo_for_save( sox_encodinginfo_t get_encodinginfo_for_save(
const std::string& format, const std::string& format,
const caffe2::TypeMeta& dtype, const caffe2::TypeMeta& dtype,
const c10::optional<double>& compression, const std::optional<double>& compression,
const c10::optional<std::string>& encoding, const std::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample) { const std::optional<int64_t>& bits_per_sample) {
auto enc = get_save_encoding(format, dtype, encoding, bits_per_sample); auto enc = get_save_encoding(format, dtype, encoding, bits_per_sample);
return sox_encodinginfo_t{ return sox_encodinginfo_t{
/*encoding=*/std::get<0>(enc), /*encoding=*/std::get<0>(enc),
......
...@@ -104,9 +104,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(const caffe2::TypeMeta dtype); ...@@ -104,9 +104,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(const caffe2::TypeMeta dtype);
sox_encodinginfo_t get_encodinginfo_for_save( sox_encodinginfo_t get_encodinginfo_for_save(
const std::string& format, const std::string& format,
const caffe2::TypeMeta& dtype, const caffe2::TypeMeta& dtype,
const c10::optional<double>& compression, const std::optional<double>& compression,
const c10::optional<std::string>& encoding, const std::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample); const std::optional<int64_t>& bits_per_sample);
} // namespace torchaudio::sox } // namespace torchaudio::sox
#endif #endif
...@@ -23,7 +23,7 @@ bool is_align_available() { ...@@ -23,7 +23,7 @@ bool is_align_available() {
#endif #endif
} }
c10::optional<int64_t> cuda_version() { std::optional<int64_t> cuda_version() {
#ifdef USE_CUDA #ifdef USE_CUDA
return CUDA_VERSION; return CUDA_VERSION;
#else #else
......
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
namespace torchaudio { namespace torchaudio {
bool is_rir_available(); bool is_rir_available();
bool is_align_available(); bool is_align_available();
c10::optional<int64_t> cuda_version(); std::optional<int64_t> cuda_version();
} // namespace torchaudio } // namespace torchaudio
...@@ -10,7 +10,7 @@ namespace torio::io { ...@@ -10,7 +10,7 @@ namespace torio::io {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// AVDictionary // AVDictionary
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AVDictionary* get_option_dict(const c10::optional<OptionDict>& option) { AVDictionary* get_option_dict(const std::optional<OptionDict>& option) {
AVDictionary* opt = nullptr; AVDictionary* opt = nullptr;
if (option) { if (option) {
for (auto const& [key, value] : option.value()) { for (auto const& [key, value] : option.value()) {
......
...@@ -77,7 +77,7 @@ class Wrapper { ...@@ -77,7 +77,7 @@ class Wrapper {
// IIRC-semantic. Instead we provide helper functions. // IIRC-semantic. Instead we provide helper functions.
// Convert standard dict to FFmpeg native type // Convert standard dict to FFmpeg native type
AVDictionary* get_option_dict(const c10::optional<OptionDict>& option); AVDictionary* get_option_dict(const std::optional<OptionDict>& option);
// Clean up the dict after use. If there is an unsed key, throw runtime error // Clean up the dict after use. If there is an unsed key, throw runtime error
void clean_up_dict(AVDictionary* p); void clean_up_dict(AVDictionary* p);
......
...@@ -160,8 +160,8 @@ struct StreamingMediaDecoderFileObj : private FileObj, ...@@ -160,8 +160,8 @@ struct StreamingMediaDecoderFileObj : private FileObj,
public StreamingMediaDecoderCustomIO { public StreamingMediaDecoderCustomIO {
StreamingMediaDecoderFileObj( StreamingMediaDecoderFileObj(
py::object fileobj, py::object fileobj,
const c10::optional<std::string>& format, const std::optional<std::string>& format,
const c10::optional<std::map<std::string, std::string>>& option, const std::optional<std::map<std::string, std::string>>& option,
int buffer_size) int buffer_size)
: FileObj{fileobj, buffer_size}, : FileObj{fileobj, buffer_size},
StreamingMediaDecoderCustomIO( StreamingMediaDecoderCustomIO(
...@@ -177,7 +177,7 @@ struct StreamingMediaEncoderFileObj : private FileObj, ...@@ -177,7 +177,7 @@ struct StreamingMediaEncoderFileObj : private FileObj,
public StreamingMediaEncoderCustomIO { public StreamingMediaEncoderCustomIO {
StreamingMediaEncoderFileObj( StreamingMediaEncoderFileObj(
py::object fileobj, py::object fileobj,
const c10::optional<std::string>& format, const std::optional<std::string>& format,
int buffer_size) int buffer_size)
: FileObj{fileobj, buffer_size}, : FileObj{fileobj, buffer_size},
StreamingMediaEncoderCustomIO( StreamingMediaEncoderCustomIO(
...@@ -231,8 +231,8 @@ struct StreamingMediaDecoderBytes : private BytesWrapper, ...@@ -231,8 +231,8 @@ struct StreamingMediaDecoderBytes : private BytesWrapper,
public StreamingMediaDecoderCustomIO { public StreamingMediaDecoderCustomIO {
StreamingMediaDecoderBytes( StreamingMediaDecoderBytes(
std::string_view src, std::string_view src,
const c10::optional<std::string>& format, const std::optional<std::string>& format,
const c10::optional<std::map<std::string, std::string>>& option, const std::optional<std::map<std::string, std::string>>& option,
int64_t buffer_size) int64_t buffer_size)
: BytesWrapper{src}, : BytesWrapper{src},
StreamingMediaDecoderCustomIO( StreamingMediaDecoderCustomIO(
...@@ -278,10 +278,10 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) { ...@@ -278,10 +278,10 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
.def_readwrite("frames", &Chunk::frames) .def_readwrite("frames", &Chunk::frames)
.def_readwrite("pts", &Chunk::pts); .def_readwrite("pts", &Chunk::pts);
py::class_<CodecConfig>(m, "CodecConfig", py::module_local()) py::class_<CodecConfig>(m, "CodecConfig", py::module_local())
.def(py::init<int, int, const c10::optional<int>&, int, int>()); .def(py::init<int, int, const std::optional<int>&, int, int>());
py::class_<StreamingMediaEncoder>( py::class_<StreamingMediaEncoder>(
m, "StreamingMediaEncoder", py::module_local()) m, "StreamingMediaEncoder", py::module_local())
.def(py::init<const std::string&, const c10::optional<std::string>&>()) .def(py::init<const std::string&, const std::optional<std::string>&>())
.def("set_metadata", &StreamingMediaEncoder::set_metadata) .def("set_metadata", &StreamingMediaEncoder::set_metadata)
.def("add_audio_stream", &StreamingMediaEncoder::add_audio_stream) .def("add_audio_stream", &StreamingMediaEncoder::add_audio_stream)
.def("add_video_stream", &StreamingMediaEncoder::add_video_stream) .def("add_video_stream", &StreamingMediaEncoder::add_video_stream)
...@@ -293,7 +293,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) { ...@@ -293,7 +293,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
.def("close", &StreamingMediaEncoder::close); .def("close", &StreamingMediaEncoder::close);
py::class_<StreamingMediaEncoderFileObj>( py::class_<StreamingMediaEncoderFileObj>(
m, "StreamingMediaEncoderFileObj", py::module_local()) m, "StreamingMediaEncoderFileObj", py::module_local())
.def(py::init<py::object, const c10::optional<std::string>&, int64_t>()) .def(py::init<py::object, const std::optional<std::string>&, int64_t>())
.def("set_metadata", &StreamingMediaEncoderFileObj::set_metadata) .def("set_metadata", &StreamingMediaEncoderFileObj::set_metadata)
.def("add_audio_stream", &StreamingMediaEncoderFileObj::add_audio_stream) .def("add_audio_stream", &StreamingMediaEncoderFileObj::add_audio_stream)
.def("add_video_stream", &StreamingMediaEncoderFileObj::add_video_stream) .def("add_video_stream", &StreamingMediaEncoderFileObj::add_video_stream)
...@@ -366,8 +366,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) { ...@@ -366,8 +366,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
m, "StreamingMediaDecoder", py::module_local()) m, "StreamingMediaDecoder", py::module_local())
.def(py::init< .def(py::init<
const std::string&, const std::string&,
const c10::optional<std::string>&, const std::optional<std::string>&,
const c10::optional<OptionDict>&>()) const std::optional<OptionDict>&>())
.def("num_src_streams", &StreamingMediaDecoder::num_src_streams) .def("num_src_streams", &StreamingMediaDecoder::num_src_streams)
.def("num_out_streams", &StreamingMediaDecoder::num_out_streams) .def("num_out_streams", &StreamingMediaDecoder::num_out_streams)
.def( .def(
...@@ -385,7 +385,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) { ...@@ -385,7 +385,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
.def("remove_stream", &StreamingMediaDecoder::remove_stream) .def("remove_stream", &StreamingMediaDecoder::remove_stream)
.def( .def(
"process_packet", "process_packet",
py::overload_cast<const c10::optional<double>&, const double>( py::overload_cast<const std::optional<double>&, const double>(
&StreamingMediaDecoder::process_packet)) &StreamingMediaDecoder::process_packet))
.def("process_all_packets", &StreamingMediaDecoder::process_all_packets) .def("process_all_packets", &StreamingMediaDecoder::process_all_packets)
.def("fill_buffer", &StreamingMediaDecoder::fill_buffer) .def("fill_buffer", &StreamingMediaDecoder::fill_buffer)
...@@ -395,8 +395,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) { ...@@ -395,8 +395,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
m, "StreamingMediaDecoderFileObj", py::module_local()) m, "StreamingMediaDecoderFileObj", py::module_local())
.def(py::init< .def(py::init<
py::object, py::object,
const c10::optional<std::string>&, const std::optional<std::string>&,
const c10::optional<OptionDict>&, const std::optional<OptionDict>&,
int64_t>()) int64_t>())
.def("num_src_streams", &StreamingMediaDecoderFileObj::num_src_streams) .def("num_src_streams", &StreamingMediaDecoderFileObj::num_src_streams)
.def("num_out_streams", &StreamingMediaDecoderFileObj::num_out_streams) .def("num_out_streams", &StreamingMediaDecoderFileObj::num_out_streams)
...@@ -419,7 +419,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) { ...@@ -419,7 +419,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
.def("remove_stream", &StreamingMediaDecoderFileObj::remove_stream) .def("remove_stream", &StreamingMediaDecoderFileObj::remove_stream)
.def( .def(
"process_packet", "process_packet",
py::overload_cast<const c10::optional<double>&, const double>( py::overload_cast<const std::optional<double>&, const double>(
&StreamingMediaDecoder::process_packet)) &StreamingMediaDecoder::process_packet))
.def( .def(
"process_all_packets", "process_all_packets",
...@@ -431,8 +431,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) { ...@@ -431,8 +431,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
m, "StreamingMediaDecoderBytes", py::module_local()) m, "StreamingMediaDecoderBytes", py::module_local())
.def(py::init< .def(py::init<
std::string_view, std::string_view,
const c10::optional<std::string>&, const std::optional<std::string>&,
const c10::optional<OptionDict>&, const std::optional<OptionDict>&,
int64_t>()) int64_t>())
.def("num_src_streams", &StreamingMediaDecoderBytes::num_src_streams) .def("num_src_streams", &StreamingMediaDecoderBytes::num_src_streams)
.def("num_out_streams", &StreamingMediaDecoderBytes::num_out_streams) .def("num_out_streams", &StreamingMediaDecoderBytes::num_out_streams)
...@@ -455,7 +455,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) { ...@@ -455,7 +455,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
.def("remove_stream", &StreamingMediaDecoderBytes::remove_stream) .def("remove_stream", &StreamingMediaDecoderBytes::remove_stream)
.def( .def(
"process_packet", "process_packet",
py::overload_cast<const c10::optional<double>&, const double>( py::overload_cast<const std::optional<double>&, const double>(
&StreamingMediaDecoder::process_packet)) &StreamingMediaDecoder::process_packet))
.def( .def(
"process_all_packets", "process_all_packets",
......
...@@ -105,7 +105,7 @@ void ChunkedBuffer::push_frame(torch::Tensor frame, int64_t pts_) { ...@@ -105,7 +105,7 @@ void ChunkedBuffer::push_frame(torch::Tensor frame, int64_t pts_) {
} }
} }
c10::optional<Chunk> ChunkedBuffer::pop_chunk() { std::optional<Chunk> ChunkedBuffer::pop_chunk() {
using namespace torch::indexing; using namespace torch::indexing;
if (!num_buffered_frames) { if (!num_buffered_frames) {
return {}; return {};
......
...@@ -26,7 +26,7 @@ class ChunkedBuffer { ...@@ -26,7 +26,7 @@ class ChunkedBuffer {
bool is_ready() const; bool is_ready() const;
void flush(); void flush();
c10::optional<Chunk> pop_chunk(); std::optional<Chunk> pop_chunk();
void push_frame(torch::Tensor frame, int64_t pts_); void push_frame(torch::Tensor frame, int64_t pts_);
}; };
......
...@@ -15,7 +15,7 @@ void UnchunkedBuffer::push_frame(torch::Tensor frame, int64_t pts_) { ...@@ -15,7 +15,7 @@ void UnchunkedBuffer::push_frame(torch::Tensor frame, int64_t pts_) {
chunks.push_back(frame); chunks.push_back(frame);
} }
c10::optional<Chunk> UnchunkedBuffer::pop_chunk() { std::optional<Chunk> UnchunkedBuffer::pop_chunk() {
if (chunks.size() == 0) { if (chunks.size() == 0) {
return {}; return {};
} }
......
...@@ -16,7 +16,7 @@ class UnchunkedBuffer { ...@@ -16,7 +16,7 @@ class UnchunkedBuffer {
explicit UnchunkedBuffer(AVRational time_base); explicit UnchunkedBuffer(AVRational time_base);
bool is_ready() const; bool is_ready() const;
void push_frame(torch::Tensor frame, int64_t pts_); void push_frame(torch::Tensor frame, int64_t pts_);
c10::optional<Chunk> pop_chunk(); std::optional<Chunk> pop_chunk();
void flush(); void flush();
}; };
......
...@@ -144,7 +144,7 @@ struct ProcessImpl : public IPostDecodeProcess { ...@@ -144,7 +144,7 @@ struct ProcessImpl : public IPostDecodeProcess {
return ret; return ret;
} }
c10::optional<Chunk> pop_chunk() override { std::optional<Chunk> pop_chunk() override {
return buffer.pop_chunk(); return buffer.pop_chunk();
} }
}; };
......
...@@ -8,7 +8,7 @@ struct IPostDecodeProcess { ...@@ -8,7 +8,7 @@ struct IPostDecodeProcess {
virtual ~IPostDecodeProcess() = default; virtual ~IPostDecodeProcess() = default;
virtual int process_frame(AVFrame* frame) = 0; virtual int process_frame(AVFrame* frame) = 0;
virtual c10::optional<Chunk> pop_chunk() = 0; virtual std::optional<Chunk> pop_chunk() = 0;
virtual bool is_buffer_ready() const = 0; virtual bool is_buffer_ready() const = 0;
virtual const std::string& get_filter_desc() const = 0; virtual const std::string& get_filter_desc() const = 0;
virtual FilterGraphOutputInfo get_filter_output_info() const = 0; virtual FilterGraphOutputInfo get_filter_output_info() const = 0;
......
...@@ -8,7 +8,7 @@ namespace torio::io { ...@@ -8,7 +8,7 @@ namespace torio::io {
namespace { namespace {
AVCodecContextPtr alloc_codec_context( AVCodecContextPtr alloc_codec_context(
enum AVCodecID codec_id, enum AVCodecID codec_id,
const c10::optional<std::string>& decoder_name) { const std::optional<std::string>& decoder_name) {
const AVCodec* codec = [&]() { const AVCodec* codec = [&]() {
if (decoder_name) { if (decoder_name) {
const AVCodec* c = const AVCodec* c =
...@@ -132,7 +132,7 @@ void configure_codec_context( ...@@ -132,7 +132,7 @@ void configure_codec_context(
void open_codec( void open_codec(
AVCodecContext* codec_ctx, AVCodecContext* codec_ctx,
const c10::optional<OptionDict>& decoder_option) { const std::optional<OptionDict>& decoder_option) {
AVDictionary* opts = get_option_dict(decoder_option); AVDictionary* opts = get_option_dict(decoder_option);
// Default to single thread execution. // Default to single thread execution.
...@@ -158,8 +158,8 @@ bool ends_with(std::string_view str, std::string_view suffix) { ...@@ -158,8 +158,8 @@ bool ends_with(std::string_view str, std::string_view suffix) {
AVCodecContextPtr get_codec_ctx( AVCodecContextPtr get_codec_ctx(
const AVCodecParameters* params, const AVCodecParameters* params,
const c10::optional<std::string>& decoder_name, const std::optional<std::string>& decoder_name,
const c10::optional<OptionDict>& decoder_option, const std::optional<OptionDict>& decoder_option,
const torch::Device& device) { const torch::Device& device) {
AVCodecContextPtr codec_ctx = AVCodecContextPtr codec_ctx =
alloc_codec_context(params->codec_id, decoder_name); alloc_codec_context(params->codec_id, decoder_name);
...@@ -266,8 +266,8 @@ void StreamProcessor::set_discard_timestamp(int64_t timestamp) { ...@@ -266,8 +266,8 @@ void StreamProcessor::set_discard_timestamp(int64_t timestamp) {
void StreamProcessor::set_decoder( void StreamProcessor::set_decoder(
const AVCodecParameters* codecpar, const AVCodecParameters* codecpar,
const c10::optional<std::string>& decoder_name, const std::optional<std::string>& decoder_name,
const c10::optional<OptionDict>& decoder_option, const std::optional<OptionDict>& decoder_option,
const torch::Device& device) { const torch::Device& device) {
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(!codec_ctx, "Decoder has already been set."); TORCH_INTERNAL_ASSERT_DEBUG_ONLY(!codec_ctx, "Decoder has already been set.");
codec_ctx = get_codec_ctx(codecpar, decoder_name, decoder_option, device); codec_ctx = get_codec_ctx(codecpar, decoder_name, decoder_option, device);
...@@ -390,7 +390,7 @@ int StreamProcessor::send_frame(AVFrame* frame_) { ...@@ -390,7 +390,7 @@ int StreamProcessor::send_frame(AVFrame* frame_) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Retrieval // Retrieval
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
c10::optional<Chunk> StreamProcessor::pop_chunk(KeyType key) { std::optional<Chunk> StreamProcessor::pop_chunk(KeyType key) {
return post_processes.at(key)->pop_chunk(); return post_processes.at(key)->pop_chunk();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment