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

rocDecode integration in rocAL #253

Draft
wants to merge 43 commits into
base: develop
Choose a base branch
from

Conversation

fiona-gladwin
Copy link
Contributor

  • Add support for rocDecode hardware decoder in rocAL
  • Add support to create sequences using the seek operation in rocDecode, works seamlessly for H265 videos.

fiona-gladwin and others added 30 commits May 8, 2024 02:52
Requires VideoDemuxer to have .cpp file
Add utils folder to rocAL hip to compile with rocDecode
Revert additional changes
@kiritigowda kiritigowda self-assigned this Dec 19, 2024
@kiritigowda kiritigowda added enhancement New feature or request ci:precheckin labels Dec 19, 2024
@kiritigowda
Copy link
Collaborator

@fiona-gladwin failing to compile

/home/vsts/work/1/s/rocAL/source/decoders/video/rocdec_video_decoder.cpp:134:49: error: no member named 'selected_frame_dts_' in 'VideoSeekContext'
  134 |             required_frame_dts = video_seek_ctx.selected_frame_dts_;
      |                                  ~~~~~~~~~~~~~~ ^
/home/vsts/work/1/s/rocAL/source/decoders/video/rocdec_video_decoder.cpp:138:60: error: too many arguments to function call, expected at most 3, have 4
  138 |             _demuxer->Demux(&pvideo, &n_video_bytes, &pts, &dts);
      |             ~~~~~~~~~~~~~~~                                ^~~~
/home/vsts/work/1/rocm/share/rocdecode/utils/video_demuxer.h:156:14: note: 'Demux' declared here
  156 |         bool Demux(uint8_t **video, int *video_size, int64_t *pts = nullptr) {
      |              ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/vsts/work/1/s/rocAL/source/decoders/video/rocdec_video_decoder.cpp:23:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/iomanip:40:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/ios_base.h:41:

@kiritigowda kiritigowda marked this pull request as draft December 23, 2024 20:31
@fiona-gladwin
Copy link
Contributor Author

fiona-gladwin commented Dec 24, 2024

@fiona-gladwin failing to compile

/home/vsts/work/1/s/rocAL/source/decoders/video/rocdec_video_decoder.cpp:134:49: error: no member named 'selected_frame_dts_' in 'VideoSeekContext'
  134 |             required_frame_dts = video_seek_ctx.selected_frame_dts_;
      |                                  ~~~~~~~~~~~~~~ ^
/home/vsts/work/1/s/rocAL/source/decoders/video/rocdec_video_decoder.cpp:138:60: error: too many arguments to function call, expected at most 3, have 4
  138 |             _demuxer->Demux(&pvideo, &n_video_bytes, &pts, &dts);
      |             ~~~~~~~~~~~~~~~                                ^~~~
/home/vsts/work/1/rocm/share/rocdecode/utils/video_demuxer.h:156:14: note: 'Demux' declared here
  156 |         bool Demux(uint8_t **video, int *video_size, int64_t *pts = nullptr) {
      |              ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/vsts/work/1/s/rocAL/source/decoders/video/rocdec_video_decoder.cpp:23:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/iomanip:40:
In file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/ios_base.h:41:

@kiritigowda This PR requires PR #479 of rocDecode to be merged for successful compilation

Copy link
Contributor

@rrawther rrawther left a comment

Choose a reason for hiding this comment

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

Please address the review comments

#
# MIT License
#
# Copyright (c) 2024 Advanced Micro Devices, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

2025

find_path(ROCDECODE_INCLUDE_DIRS
NAMES rocdecode.h rocparser.h
HINTS
$ENV{rocDecode_PATH}/include/rocdecode
Copy link
Contributor

Choose a reason for hiding this comment

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

what is rocDecode_PATH? did you mean ROCM_PATH

find_library(ROCDECODE_LIBRARIES
NAMES rocdecode
HINTS
$ENV{rocDecode_PATH}/lib
Copy link
Contributor

Choose a reason for hiding this comment

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

same here. Please copy FindrocDecode from rocDecode repo instead

RocDecVideoDecoder();
VideoDecoder::Status Initialize(const char *src_filename, int device_id = 0) override;
VideoDecoder::Status Decode(unsigned char *output_buffer, unsigned seek_frame_number, size_t sequence_length, size_t stride, int out_width, int out_height, int out_stride, AVPixelFormat out_format) override;
int seek_frame(AVRational avg_frame_rate, AVRational time_base, unsigned frame_number) override { return 0; }
Copy link
Contributor

Choose a reason for hiding this comment

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

please use same function name style for all functions here. Here snake and camel cases are mixed

#include "video_decoder.h"

#ifdef ROCAL_VIDEO
#if ENABLE_HIP
Copy link
Contributor

Choose a reason for hiding this comment

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

we should get rid of ENABLE_HIP and ENABLE_ROCDECODE flags

}

// Seeks to the frame_number in the video file and decodes each frame in the sequence.
VideoDecoder::Status RocDecVideoDecoder::Decode(unsigned char *out_buffer, unsigned seek_frame_number, size_t sequence_length, size_t stride, int out_width, int out_height, int out_stride, AVPixelFormat out_pix_format) {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename out_buffer to output_buffer_ptr

return Status::FAILED;
}
// Take the min of sequence length and num frames to avoid out of bounds memory error
int required_n_frames = std::min(static_cast<int>(sequence_length), n_frame_returned);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the sequence_length always <= n_frame_returned. In line#144 please check if n_frame_returned < sequence_length and return error.
Remove this line

}
// Take the min of sequence length and num frames to avoid out of bounds memory error
int required_n_frames = std::min(static_cast<int>(sequence_length), n_frame_returned);
for (int i = 0; i < required_n_frames; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

change it to sequence_length. What if there in not enough frames in the sequence when there is EOF?

int required_n_frames = std::min(static_cast<int>(sequence_length), n_frame_returned);
for (int i = 0; i < required_n_frames; i++) {
uint8_t *pframe = _rocvid_decoder->GetFrame(&pts);
if (dts >= requested_frame_dts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how is the dts value updated here. We are only returning pts in the call

@@ -102,6 +102,12 @@ void VideoLoader::set_output(Tensor *output_tensor) {
_output_mem_size = ((_output_tensor->info().data_size() + 8) & ~7); // Making output size as a multiple of 8 to support vectorized load and store in RPP
}

void VideoLoader::set_gpu_device_id(int device_id) {
if (device_id < 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

please set to 0 here as default instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:precheckin enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants