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

Improve video decoder seeking and reset behavior #5830

Merged
merged 6 commits into from
Feb 28, 2025

Conversation

jantonguirao
Copy link
Contributor

@jantonguirao jantonguirao commented Feb 25, 2025

Category:

Refactoring / New feature / Bug fix

Description:

  • Allows reset and seeking on any format

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

@jantonguirao jantonguirao marked this pull request as ready for review February 25, 2025 19:00
}
}

if (av_state_->codec_params_->codec_type != AVMEDIA_TYPE_VIDEO) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where av_state_->codec_params_->codec_type from if av_state_->codec_params_->codec_type is false?

@@ -282,6 +293,7 @@ class DLL_PUBLIC FramesDecoderBase {
std::optional<MemoryVideoFile> memory_video_file_ = {};

std::optional<int> num_frames_ = {};
std::optional<bool> is_seekable_ = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be optional?

Comment on lines 626 to 628
if (!is_seekable_.has_value()) {
is_seekable_ = ret >= 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks convoluted

Comment on lines 653 to 657
uint8_t *av_io_buffer = static_cast<uint8_t *>(av_malloc(default_av_buffer_size));
AVIOContext *av_io_context = avio_alloc_context(
av_io_buffer, default_av_buffer_size, 0, &memory_video_file_.value(),
detail::read_memory_video_file, nullptr, detail::seek_memory_video_file);
av_state_->ctx_->pb = av_io_context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What if allocation fails?
  2. Shouldn't we clean up av_state_->ctx_->pb?
 auto custom_ctx = ctx_->pb;
      auto custom_buffer = ctx_->pb ? ctx_->pb->buffer : nullptr;
      if (custom_dealloc) {
        av_freep(&custom_buffer);
        avio_context_free(&custom_ctx);
      }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I'll handle that
  2. No need, it already gets cleaned up when we do av_state_ = std::make_unique<AvState>();

@JanuszL JanuszL self-assigned this Feb 25, 2025
@jantonguirao jantonguirao force-pushed the video_changes branch 2 times, most recently from 3f64339 to 40dd932 Compare February 26, 2025 13:09
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24605517]: BUILD STARTED

int AvState::OpenFile(const std::string& filename) {
LOG_LINE << "Opening file " << filename << std::endl;
CloseInput();
DALI_ENFORCE((ctx_ = avformat_alloc_context()), "Could not alloc avformat context");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should put assignment to DALI_ENFORCE

Signed-off-by: Joaquin Anton Guirao <[email protected]>
Signed-off-by: Joaquin Anton Guirao <[email protected]>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24606155]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24606525]: BUILD STARTED

Signed-off-by: Joaquin Anton Guirao <[email protected]>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24611381]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24611422]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24606525]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24606155]: BUILD FAILED

}
av_state_->frame_ = av_frame_alloc();
if (ret != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

Suggested change
if (ret != 0) {
if (av_state_->frame_ == nullptr) {

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24611381]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24611422]: BUILD FAILED

Signed-off-by: Joaquin Anton Guirao <[email protected]>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24670395]: BUILD STARTED

Signed-off-by: Joaquin Anton Guirao <[email protected]>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [24670395]: BUILD PASSED

@jantonguirao jantonguirao merged commit 8cd3e0d into NVIDIA:main Feb 28, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants