Skip to content

Improve the video decoder errors #5491

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

Merged
merged 3 commits into from
Jun 3, 2024

Conversation

JanuszL
Copy link
Contributor

@JanuszL JanuszL commented May 29, 2024

  • adds the source info to the errors in the video decoder operator
  • makes sure the video decoder operator raises the right error instead
    of just crashing the process

Category:

Bug fix (non-breaking change which fixes an issue)

Description:

Additional information:

Affected modules and functionalities:

-frames decoder

  • video decoder operator

Key points relevant for the review:

-NA

Tests:

  • Existing tests apply
  • [ x] New tests added
    • Python tests
      • test_video.test_error_source_info
    • 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

- adds the source info to the errors in the video decoder operator
- makes sure the video decoder operator raises the right error instead
  of just crashing the process

Signed-off-by: Janusz Lisiecki <[email protected]>
@JanuszL JanuszL force-pushed the improve_video_decoder_error branch from c51083b to ba0e516 Compare May 29, 2024 10:46
@JanuszL
Copy link
Contributor Author

JanuszL commented May 29, 2024

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15399757]: BUILD STARTED

@awolant awolant self-assigned this May 29, 2024
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15399757]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15399757]: BUILD PASSED

Filename(),
"due to",
"\", due to",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"\", due to",
"\", due to ",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

: av_state_(std::make_unique<AvState>()),
filename_(source_info.size() ? std::optional<const std::string>(source_info) : std::nullopt),
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole std::optional<const std::string> affair seems unnecessarily complex. I don't think it's possible to have a meaningful empty filename - so we could just use empty string to denote the "memory file" (see frames_decoder.h:202, the only usage of filename_.value). This would simplify the code here, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -206,8 +206,9 @@ FramesDecoder::FramesDecoder(const std::string &filename)


FramesDecoder::FramesDecoder(const char *memory_file, int memory_file_size, bool build_index,
bool init_codecs, int num_frames)
bool init_codecs, int num_frames, const std::string &source_info)
Copy link
Contributor

@mzient mzient May 31, 2024

Choose a reason for hiding this comment

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

You can use std::string_view, which will not create a copy of the argument nor will it construct a temporary string.
Alternatively, since we use it to construct a string member, we could pass source_info by value and move it to filename_. This would save one copy if the constructor call does not use a reference to an existing string object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could pass source_info

Done

move it to filename_

Do we have to move explicitly or the compiler will silently do so?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, compiler won't move out a parameter in any scenario other than when directly returning it, e.g.:

string foo(string a, string b) {
  if (a.find("nemo") != string::npos) 
    return a;  // copy elision
  else
    return b;  // copy elision
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworked

@@ -117,7 +117,7 @@ class DLL_PUBLIC FramesDecoder {
* `memory_file_size` arguments cover the entire video file, including the header.
*/
FramesDecoder(const char *memory_file, int memory_file_size, bool build_index = true,
bool init_codecs = true, int num_frames = -1);
bool init_codecs = true, int num_frames = -1, const std::string &source_info = {});
Copy link
Contributor

@mzient mzient May 31, 2024

Choose a reason for hiding this comment

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

Suggested change
bool init_codecs = true, int num_frames = -1, const std::string &source_info = {});
bool init_codecs = true, int num_frames = -1, std::string_view source_info = {});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pass it by value as suggested earlier.

frame_buffer_(num_decode_surfaces_),
stream_(stream) {
int num_frames,
const std::string &source_info):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const std::string &source_info):
std::string_view source_info):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pass it by value as suggested earlier.

@JanuszL
Copy link
Contributor Author

JanuszL commented Jun 2, 2024

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15513826]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15513826]: BUILD FAILED

Signed-off-by: Janusz Lisiecki <[email protected]>
@JanuszL JanuszL force-pushed the improve_video_decoder_error branch from 3890aec to dd95dc0 Compare June 2, 2024 23:04
@JanuszL
Copy link
Contributor Author

JanuszL commented Jun 2, 2024

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15514517]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15514517]: BUILD PASSED

Comment on lines 209 to 211
bool init_codecs, int num_frames, const std::string source_info)
: av_state_(std::make_unique<AvState>()),
filename_(source_info),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool init_codecs, int num_frames, const std::string source_info)
: av_state_(std::make_unique<AvState>()),
filename_(source_info),
bool init_codecs, int num_frames, std::string source_info)
: av_state_(std::make_unique<AvState>()),
filename_(std::move(source_info)),

...or, as suggested earlier, use std::string_view.

Signed-off-by: Janusz Lisiecki <[email protected]>
@JanuszL
Copy link
Contributor Author

JanuszL commented Jun 3, 2024

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15521941]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15521941]: BUILD PASSED

@JanuszL JanuszL merged commit 5ff5376 into NVIDIA:main Jun 3, 2024
7 checks passed
@JanuszL JanuszL deleted the improve_video_decoder_error branch June 3, 2024 11:27
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