Skip to content

Refactor C++ SingleStreamDecoder to consolidate addStream into constructor #1064

@scotts

Description

@scotts

Right now, the C++ SingleStreamDecoder class has two constructors:

// Creates a SingleStreamDecoder from the video at videoFilePath.
explicit SingleStreamDecoder(
const std::string& videoFilePath,
SeekMode seekMode = SeekMode::exact);
// Creates a SingleStreamDecoder using the provided AVIOContext inside the
// AVIOContextHolder. The AVIOContextHolder is the base class, and the
// derived class will have specialized how the custom read, seek and writes
// work.
explicit SingleStreamDecoder(
std::unique_ptr<AVIOContextHolder> context,
SeekMode seekMode = SeekMode::exact);

And separate from there, there is a public API for adding streams of different media types:

void addVideoStream(
int streamIndex,
std::vector<Transform*>& transforms,
const VideoStreamOptions& videoStreamOptions = VideoStreamOptions(),
std::optional<FrameMappings> customFrameMappings = std::nullopt);
void addAudioStream(
int streamIndex,
const AudioStreamOptions& audioStreamOptions = AudioStreamOptions());

Note that there is also a private member function that both of those call:

void addStream(
int streamIndex,
AVMediaType mediaType,
const torch::Device& device = torch::kCPU,
const std::string_view deviceVariant = "ffmpeg",
std::optional<int> ffmpegThreadCount = std::nullopt);

This separation is a relic of when SingleStreamDecoder was trying to be more than just a single stream decoder. This API does not match the public Python API, and that fact causes some awkwardness, in particular with how we deal with custom frame mappings; see PR #1060 (comment) for more.

Note that one could imagine the current separation enables just getting metadata without adding a decoding stream, but that should be well supported with SeekMode::approximate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorImproves code itself, but does not fix a bug or add new functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions