Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::optional types #3812

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/libtorio.stream_reader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ StreamingMediaDecoder

.. doxygenclass:: torio::io::StreamingMediaDecoder

.. doxygenfunction:: torio::io::StreamingMediaDecoder::StreamingMediaDecoder(const std::string &src, const std::optional<std::string> &format = {}, const c10::optional<OptionDict> &option = {})
.. doxygenfunction:: torio::io::StreamingMediaDecoder::StreamingMediaDecoder(const std::string &src, const std::optional<std::string> &format = {}, const std::optional<OptionDict> &option = {})

StreamingMediaDecoderCustomIO
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions src/libtorio/ffmpeg/ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <string>

extern "C" {
Expand Down
26 changes: 13 additions & 13 deletions src/libtorio/ffmpeg/stream_reader/stream_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class StreamingMediaDecoder {
/// (opening source).
explicit StreamingMediaDecoder(
AVIOContext* io_ctx,
const std::optional<std::string>& format = c10::nullopt,
const std::optional<OptionDict>& option = c10::nullopt);
const std::optional<std::string>& format = std::nullopt,
const std::optional<OptionDict>& option = std::nullopt);

/// @endcond

Expand All @@ -81,8 +81,8 @@ class StreamingMediaDecoder {
/// (opening source).
explicit StreamingMediaDecoder(
const std::string& src,
const std::optional<std::string>& format = c10::nullopt,
const std::optional<OptionDict>& option = c10::nullopt);
const std::optional<std::string>& format = std::nullopt,
const std::optional<OptionDict>& option = std::nullopt);

///@}

Expand Down Expand Up @@ -205,9 +205,9 @@ class StreamingMediaDecoder {
int64_t i,
int64_t frames_per_chunk,
int64_t num_chunks,
const std::optional<std::string>& filter_desc = c10::nullopt,
const std::optional<std::string>& decoder = c10::nullopt,
const std::optional<OptionDict>& decoder_option = c10::nullopt);
const std::optional<std::string>& filter_desc = std::nullopt,
const std::optional<std::string>& decoder = std::nullopt,
const std::optional<OptionDict>& decoder_option = std::nullopt);
/// Define an output video stream.
///
/// @param i,frames_per_chunk,num_chunks,filter_desc,decoder,decoder_option
Expand All @@ -226,10 +226,10 @@ class StreamingMediaDecoder {
int64_t i,
int64_t frames_per_chunk,
int64_t num_chunks,
const std::optional<std::string>& filter_desc = c10::nullopt,
const std::optional<std::string>& decoder = c10::nullopt,
const std::optional<OptionDict>& decoder_option = c10::nullopt,
const std::optional<std::string>& hw_accel = c10::nullopt);
const std::optional<std::string>& filter_desc = std::nullopt,
const std::optional<std::string>& decoder = std::nullopt,
const std::optional<OptionDict>& decoder_option = std::nullopt,
const std::optional<std::string>& hw_accel = std::nullopt);

/// @cond
/// Add a output packet stream.
Expand Down Expand Up @@ -315,7 +315,7 @@ class StreamingMediaDecoder {
/// @param timeout See `process_packet_block()`
/// @param backoff See `process_packet_block()`
int fill_buffer(
const std::optional<double>& timeout = c10::nullopt,
const std::optional<double>& timeout = std::nullopt,
const double backoff = 10.);

///@}
Expand Down Expand Up @@ -383,7 +383,7 @@ class StreamingMediaDecoderCustomIO : private detail::CustomInput,
int buffer_size,
int (*read_packet)(void* opaque, uint8_t* buf, int buf_size),
int64_t (*seek)(void* opaque, int64_t offset, int whence) = nullptr,
const std::optional<OptionDict>& option = c10::nullopt);
const std::optional<OptionDict>& option = std::nullopt);
};

// For BC
Expand Down
74 changes: 37 additions & 37 deletions src/libtorio/ffmpeg/stream_writer/stream_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class StreamingMediaEncoder {
/// @param format Specify output format.
explicit StreamingMediaEncoder(
AVIOContext* io_ctx,
const std::optional<std::string>& format = c10::nullopt);
const std::optional<std::string>& format = std::nullopt);

/// @endcond

Expand All @@ -50,7 +50,7 @@ class StreamingMediaEncoder {
/// ``dst``.
explicit StreamingMediaEncoder(
const std::string& dst,
const std::optional<std::string>& format = c10::nullopt);
const std::optional<std::string>& format = std::nullopt);

// Non-copyable
StreamingMediaEncoder(const StreamingMediaEncoder&) = delete;
Expand Down Expand Up @@ -113,13 +113,13 @@ class StreamingMediaEncoder {
int sample_rate,
int num_channels,
const std::string& format,
const std::optional<std::string>& encoder = c10::nullopt,
const std::optional<OptionDict>& encoder_option = c10::nullopt,
const std::optional<std::string>& encoder_format = c10::nullopt,
const std::optional<int>& encoder_sample_rate = c10::nullopt,
const std::optional<int>& encoder_num_channels = c10::nullopt,
const std::optional<CodecConfig>& codec_config = c10::nullopt,
const std::optional<std::string>& filter_desc = c10::nullopt);
const std::optional<std::string>& encoder = std::nullopt,
const std::optional<OptionDict>& encoder_option = std::nullopt,
const std::optional<std::string>& encoder_format = std::nullopt,
const std::optional<int>& encoder_sample_rate = std::nullopt,
const std::optional<int>& encoder_num_channels = std::nullopt,
const std::optional<CodecConfig>& codec_config = std::nullopt,
const std::optional<std::string>& filter_desc = std::nullopt);

/// Add an output video stream.
///
Expand Down Expand Up @@ -161,15 +161,15 @@ class StreamingMediaEncoder {
int width,
int height,
const std::string& format,
const std::optional<std::string>& encoder = c10::nullopt,
const std::optional<OptionDict>& encoder_option = c10::nullopt,
const std::optional<std::string>& encoder_format = c10::nullopt,
const std::optional<double>& encoder_frame_rate = c10::nullopt,
const std::optional<int>& encoder_width = c10::nullopt,
const std::optional<int>& encoder_height = c10::nullopt,
const std::optional<std::string>& hw_accel = c10::nullopt,
const std::optional<CodecConfig>& codec_config = c10::nullopt,
const std::optional<std::string>& filter_desc = c10::nullopt);
const std::optional<std::string>& encoder = std::nullopt,
const std::optional<OptionDict>& encoder_option = std::nullopt,
const std::optional<std::string>& encoder_format = std::nullopt,
const std::optional<double>& encoder_frame_rate = std::nullopt,
const std::optional<int>& encoder_width = std::nullopt,
const std::optional<int>& encoder_height = std::nullopt,
const std::optional<std::string>& hw_accel = std::nullopt,
const std::optional<CodecConfig>& codec_config = std::nullopt,
const std::optional<std::string>& filter_desc = std::nullopt);
/// @cond
/// Add output audio frame stream.
/// Allows for writing frames rather than tensors via `write_frame`.
Expand All @@ -179,13 +179,13 @@ class StreamingMediaEncoder {
int sample_rate,
int num_channels,
const std::string& format,
const std::optional<std::string>& encoder = c10::nullopt,
const std::optional<OptionDict>& encoder_option = c10::nullopt,
const std::optional<std::string>& encoder_format = c10::nullopt,
const std::optional<int>& encoder_sample_rate = c10::nullopt,
const std::optional<int>& encoder_num_channels = c10::nullopt,
const std::optional<CodecConfig>& codec_config = c10::nullopt,
const std::optional<std::string>& filter_desc = c10::nullopt);
const std::optional<std::string>& encoder = std::nullopt,
const std::optional<OptionDict>& encoder_option = std::nullopt,
const std::optional<std::string>& encoder_format = std::nullopt,
const std::optional<int>& encoder_sample_rate = std::nullopt,
const std::optional<int>& encoder_num_channels = std::nullopt,
const std::optional<CodecConfig>& codec_config = std::nullopt,
const std::optional<std::string>& filter_desc = std::nullopt);

/// Add output video frame stream.
/// Allows for writing frames rather than tensors via `write_frame`.
Expand All @@ -196,15 +196,15 @@ class StreamingMediaEncoder {
int width,
int height,
const std::string& format,
const std::optional<std::string>& encoder = c10::nullopt,
const std::optional<OptionDict>& encoder_option = c10::nullopt,
const std::optional<std::string>& encoder_format = c10::nullopt,
const std::optional<double>& encoder_frame_rate = c10::nullopt,
const std::optional<int>& encoder_width = c10::nullopt,
const std::optional<int>& encoder_height = c10::nullopt,
const std::optional<std::string>& hw_accel = c10::nullopt,
const std::optional<CodecConfig>& codec_config = c10::nullopt,
const std::optional<std::string>& filter_desc = c10::nullopt);
const std::optional<std::string>& encoder = std::nullopt,
const std::optional<OptionDict>& encoder_option = std::nullopt,
const std::optional<std::string>& encoder_format = std::nullopt,
const std::optional<double>& encoder_frame_rate = std::nullopt,
const std::optional<int>& encoder_width = std::nullopt,
const std::optional<int>& encoder_height = std::nullopt,
const std::optional<std::string>& hw_accel = std::nullopt,
const std::optional<CodecConfig>& codec_config = std::nullopt,
const std::optional<std::string>& filter_desc = std::nullopt);

/// Add packet stream. Intended to be used in conjunction with
/// ``StreamingMediaDecoder`` to perform packet passthrough.
Expand All @@ -226,7 +226,7 @@ class StreamingMediaEncoder {
/// Open the output file / device and write the header.
///
/// @param opt Private options for protocol, device and muxer.
void open(const std::optional<OptionDict>& opt = c10::nullopt);
void open(const std::optional<OptionDict>& opt = std::nullopt);
/// Close the output file / device and finalize metadata.
void close();

Expand All @@ -248,7 +248,7 @@ class StreamingMediaEncoder {
void write_audio_chunk(
int i,
const torch::Tensor& frames,
const std::optional<double>& pts = c10::nullopt);
const std::optional<double>& pts = std::nullopt);
/// Write video data
/// @param i Stream index.
/// @param frames Video/image tensor. Shape: ``(time, channel, height,
Expand All @@ -269,7 +269,7 @@ class StreamingMediaEncoder {
void write_video_chunk(
int i,
const torch::Tensor& frames,
const std::optional<double>& pts = c10::nullopt);
const std::optional<double>& pts = std::nullopt);
/// @cond
/// Write frame to stream.
/// @param i Stream index.
Expand Down