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

Merged
merged 69 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
b902adf
Add CMakeList changes
fiona-gladwin May 8, 2024
4b928e7
Add rocDecode utils files and cmake changes
fiona-gladwin May 8, 2024
ad1161a
rocDecode integration for rocAL
rrawther May 8, 2024
bcc6f5c
Merge remote-tracking branch 'upstream/develop' into rr/rocdec_integr…
rrawther May 8, 2024
0fcb28d
merge with tot
rrawther May 8, 2024
342d9ac
Add initial support for rocDecode integration
fiona-gladwin May 13, 2024
d26c18c
Add fix to decode sequences
fiona-gladwin May 13, 2024
bfd1ad9
VideoDemuxer - support to return dts
fiona-gladwin May 13, 2024
6873f6c
Support to seek exact frame
fiona-gladwin May 13, 2024
d89d3d9
Add intermediary buffers to copy
fiona-gladwin May 14, 2024
2e22877
Change the name of rocdec files
fiona-gladwin May 14, 2024
4bbc597
Merge branch 'rocdecode_integrate_1' into rr/rocdec_integration
fiona-gladwin May 14, 2024
21b0538
Temporary rocDecode cmake changes
fiona-gladwin May 14, 2024
e343af0
Fix CMake for rocDecode
fiona-gladwin May 15, 2024
9223116
Minor fix
fiona-gladwin May 15, 2024
526d170
Fix stride for rocdecode video decoder
fiona-gladwin May 15, 2024
b0a7b01
Revert "Temporary rocDecode cmake changes"
fiona-gladwin May 17, 2024
494839e
Introduce CMake for rocDecode
fiona-gladwin May 17, 2024
1752acf
Fix issues with CMake
fiona-gladwin May 21, 2024
c03169a
rocDecode Flush decoder after decoding each sequence
fiona-gladwin May 29, 2024
7a09b51
Merge branch 'develop' of https://github.com/ROCm/rocAL into fg/rocde…
fiona-gladwin Aug 21, 2024
77041e3
Add changes to flush decoder after seek
fiona-gladwin Aug 22, 2024
a937981
Add support in rocDecode to seek to exact frame using dts
fiona-gladwin Aug 22, 2024
feed1c6
Add changes in API to pass device ID to video decoder
fiona-gladwin Aug 22, 2024
b5d4a4c
Merge branch 'develop' of https://github.com/ROCm/rocAL into fg/rocde…
fiona-gladwin Oct 16, 2024
a6f9c04
Add stream synchronize
fiona-gladwin Oct 29, 2024
3ef5613
Merge branch 'develop' of https://github.com/ROCm/rocAL into fg/rocde…
fiona-gladwin Nov 4, 2024
8e04589
Merge branch 'develop' of https://github.com/ROCm/rocAL into fg/rocde…
fiona-gladwin Dec 12, 2024
97b5a03
Minor changes
fiona-gladwin Dec 12, 2024
0370b4d
Minor change
fiona-gladwin Dec 12, 2024
5d0e2bd
Change rocDecode to all caps in CMake
fiona-gladwin Dec 13, 2024
a613ebf
Minor changes
fiona-gladwin Dec 13, 2024
c4d231f
Minor CMake change
fiona-gladwin Dec 16, 2024
0d3b80e
Minor changes
fiona-gladwin Dec 16, 2024
b341b31
Introduce enable rocdecode flag in CMake
fiona-gladwin Dec 17, 2024
9239eb4
Minor fix
fiona-gladwin Dec 17, 2024
8507402
Merge branch 'develop' into fg/rocdec_integration
fiona-gladwin Dec 18, 2024
1a23995
Merge branch 'develop' into fg/rocdec_integration
SundarRajan28 Dec 21, 2024
d61e280
Minor changes
fiona-gladwin Jan 2, 2025
37f59aa
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 6, 2025
5ddf898
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 6, 2025
853353b
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 8, 2025
033689d
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 8, 2025
54e403f
Merge branch 'develop' of https://github.com/ROCm/rocAL into fg/rocde…
fiona-gladwin Jan 16, 2025
3be3d68
Modify CMake to use only ROCM_PATH
fiona-gladwin Jan 16, 2025
f77cb20
Use Pascal case for fn names in Video Decoder and other derived classes
fiona-gladwin Jan 16, 2025
1dae448
Fix CMakeLists
fiona-gladwin Jan 16, 2025
ab4bffb
Minor change
fiona-gladwin Jan 16, 2025
a5649be
Fix rocAL_hip CMakeLists for rocDecode
fiona-gladwin Jan 16, 2025
91f02d3
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 17, 2025
45bc87c
Add decoder type argument to Video readers
fiona-gladwin Jan 18, 2025
6c896d0
Fix video metadata reader
fiona-gladwin Jan 18, 2025
58307f1
Minor changes
fiona-gladwin Jan 18, 2025
0813b0a
Merge branch 'fg/rocdec_integration' of https://github.com/fiona-glad…
fiona-gladwin Jan 18, 2025
f909905
Merge branch 'develop' into fg/rocdec_integration
fiona-gladwin Jan 21, 2025
863e80f
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 23, 2025
bf55600
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 27, 2025
c4678be
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 27, 2025
fedfa27
Merge branch 'develop' into fg/rocdec_integration
kiritigowda Jan 28, 2025
156e8ac
Move default constructor to class
fiona-gladwin Jan 28, 2025
7cdb702
Merge branch 'fg/rocdec_integration' of https://github.com/fiona-glad…
fiona-gladwin Jan 28, 2025
2941f4d
Minor fix
fiona-gladwin Jan 30, 2025
77a248c
Update CHANGELOG and docs
fiona-gladwin Jan 30, 2025
21979aa
Add link to rocDecode
fiona-gladwin Jan 30, 2025
cd8e913
Merge branch 'develop' into fg/rocdec_integration
rrawther Jan 31, 2025
d9fa1a0
Update README with rocDecode installation instructions
fiona-gladwin Feb 4, 2025
494c6c0
Update rocAL version
fiona-gladwin Feb 4, 2025
44ec20b
Update README with rocDecode manual installation
fiona-gladwin Feb 4, 2025
1e5f7b7
Merge branch 'fg/rocdec_integration' of https://github.com/fiona-glad…
fiona-gladwin Feb 4, 2025
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
80 changes: 80 additions & 0 deletions cmake/FindrocDecode.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
################################################################################
#
# MIT License
#
# Copyright (c) 2025 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################

# ROCM Path
if(ROCM_PATH)
message("-- ${White}FindrocDecode: ROCM_PATH Set -- ${ROCM_PATH}${ColourReset}")
else()
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
endif()

# find rocDecode - library and headers
find_path(ROCDECODE_INCLUDE_DIR NAMES rocdecode.h PATHS ${ROCM_PATH}/include/rocdecode)
find_library(ROCDECODE_LIBRARY NAMES rocdecode HINTS ${ROCM_PATH}/lib)
mark_as_advanced(ROCDECODE_INCLUDE_DIR)
mark_as_advanced(ROCDECODE_LIBRARY)

if(ROCDECODE_INCLUDE_DIR AND ROCDECODE_LIBRARY)
message("-- ${White}FindrocDecode -- Using rocDecode: \n\tIncludes:${ROCDECODE_INCLUDE_DIR}\n\tLib:${ROCDECODE_LIBRARY}${ColourReset}")
set(ROCDECODE_FOUND TRUE)
else()
if(rocDecode_FIND_REQUIRED)
message(FATAL_ERROR "FindrocDecode -- Failed to find rocDecode Library")
endif()
message( "-- ${Yellow}NOTE: FindrocDecode failed to find rocDecode -- INSTALL rocDecode${ColourReset}" )
endif()

if(ROCDECODE_FOUND)
# Find rocDecode Version
file(READ "${ROCDECODE_INCLUDE_DIR}/rocdecode_version.h" ROCDECODE_VERSION_FILE)
string(REGEX MATCH "ROCDECODE_MAJOR_VERSION ([0-9]*)" _ ${ROCDECODE_VERSION_FILE})
set(ROCDECODE_VER_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "ROCDECODE_MINOR_VERSION ([0-9]*)" _ ${ROCDECODE_VERSION_FILE})
set(ROCDECODE_VER_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "ROCDECODE_MICRO_VERSION ([0-9]*)" _ ${ROCDECODE_VERSION_FILE})
set(ROCDECODE_VER_MICRO ${CMAKE_MATCH_1})
message("-- ${White}Found rocDecode Version: ${ROCDECODE_VER_MAJOR}.${ROCDECODE_VER_MINOR}.${ROCDECODE_VER_MICRO}${ColourReset}")
mark_as_advanced(ROCDECODE_VER_MAJOR)
mark_as_advanced(ROCDECODE_VER_MINOR)
mark_as_advanced(ROCDECODE_VER_MICRO)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
rocDecode
FOUND_VAR
ROCDECODE_FOUND
REQUIRED_VARS
ROCDECODE_INCLUDE_DIR
ROCDECODE_LIBRARY
)

set(ROCDECODE_FOUND ${ROCDECODE_FOUND} CACHE INTERNAL "")
set(ROCDECODE_INCLUDE_DIR ${ROCDECODE_INCLUDE_DIR} CACHE INTERNAL "")
set(ROCDECODE_LIBRARY ${ROCDECODE_LIBRARY} CACHE INTERNAL "")
set(ROCDECODE_VER_MAJOR ${ROCDECODE_VER_MAJOR} CACHE INTERNAL "")
set(ROCDECODE_VER_MINOR ${ROCDECODE_VER_MINOR} CACHE INTERNAL "")
set(ROCDECODE_VER_MICRO ${ROCDECODE_VER_MICRO} CACHE INTERNAL "")
18 changes: 16 additions & 2 deletions rocAL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ find_package(FFmpeg QUIET)
find_package(OpenCV QUIET)
find_package(SndFile QUIET)
find_package(LibTar QUIET)
find_package(rocDecode QUIET)

# HIP Backend
if(GPU_SUPPORT AND "${BACKEND}" STREQUAL "HIP")
Expand Down Expand Up @@ -268,7 +269,11 @@ if(${BUILD_ROCAL})
)

link_directories(${ROCM_PATH}/${CMAKE_INSTALL_LIBDIR})

#rocDecode
if ("${BACKEND}" STREQUAL "HIP" AND HIP_FOUND AND ROCDECODE_FOUND)
include_directories(${ROCDECODE_INCLUDE_DIR} ${ROCM_PATH}/share/rocdecode/utils/rocvideodecode)
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY})
endif()
if("${BACKEND}" STREQUAL "HIP" AND HIP_FOUND)
link_directories(${HIP_PATH}/${CMAKE_INSTALL_LIBDIR})
include_directories(${ROCM_PATH}/${CMAKE_INSTALL_INCLUDEDIR} rocAL_hip)
Expand All @@ -281,14 +286,22 @@ if(${BUILD_ROCAL})
link_directories(${AMDRPP_LIBRARIES_DIRS} ${TurboJpeg_LIBRARIES_DIRS} ${PROTOBUF_LIBRARY_DIRS} /usr/local/lib/)

file(GLOB_RECURSE SOURCES "source/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${TF_PROTO_SRCS} ${TF_PROTO_HEADERS} ${CAFFE_PROTO_HEADERS} ${CAFFE_PROTO_SRCS} ${CAFFE2_PROTO_SRCS} ${CAFFE2_PROTO_HEADERS})
set(ROCDECODE_SRCS ${ROCM_PATH}/share/rocdecode/utils/rocvideodecode/roc_video_dec.cpp)
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${TF_PROTO_SRCS} ${TF_PROTO_HEADERS} ${CAFFE_PROTO_HEADERS}
${CAFFE_PROTO_SRCS} ${CAFFE2_PROTO_SRCS} ${CAFFE2_PROTO_HEADERS} ${ROCDECODE_SRCS})

if("${BACKEND}" STREQUAL "HIP" AND HIP_FOUND)
add_dependencies(${PROJECT_NAME} rocAL_hip)
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} $<TARGET_OBJECTS:rocAL_hip>)
target_compile_definitions(${PROJECT_NAME} PRIVATE __HIP_PLATFORM_AMD__)
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_HIP=1)
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_OPENCL=0)
if(ROCDECODE_FOUND)
include_directories(${ROCM_PATH}/share/rocdecode/utils)
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_ROCDECODE=1)
else()
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_ROCDECODE=0)
endif()
message("-- ${White}rocAL built with HIP Backend${ColourReset}")
elseif("${BACKEND}" STREQUAL "OPENCL" AND OPENCL_FOUND)
include_directories(${OpenCL_INCLUDE_DIRS} ${OpenCL_INCLUDE_DIRS}/Headers)
Expand Down Expand Up @@ -321,6 +334,7 @@ if(${BUILD_ROCAL})
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_OPENCV=0)
message("-- ${Yellow}NOTE: rocAL built without OpenCV extension functionality${ColourReset}")
endif()

# FFMPEG
if(NOT FFMPEG_FOUND)
message("-- ${Yellow}NOTE: rocAL built without FFmpeg video decode functionality${ColourReset}")
Expand Down
8 changes: 8 additions & 0 deletions rocAL/include/api/rocal_api_data_loaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalRawTFRecordSourceSingleShard(RocalCon
* \param [in] shuffle: to shuffle sequences.
* \param [in] is_output Determines if the user wants the loaded sequence of frames to be part of the output or not.
* \param [in] loop: repeat data loading.
* \param [in] rocal_decoder_type Determines the decoder_type, FFmepg or RocDecode
* \param [in] step: Frame interval between each sequence.
* \param [in] stride: Frame interval between frames in a sequence.
* \param [in] file_list_frame_num: Determines if the user wants to read frame number or timestamps if a text file is passed in the source_path.
Expand All @@ -644,6 +645,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalVideoFileSource(RocalContext context,
bool is_output = false,
bool shuffle = false,
bool loop = false,
RocalDecoderType rocal_decoder_type = RocalDecoderType::ROCAL_DECODER_VIDEO_FFMPEG_SW,
unsigned step = 0,
unsigned stride = 0,
bool file_list_frame_num = true,
Expand All @@ -661,6 +663,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalVideoFileSource(RocalContext context,
* \param [in] shuffle: to shuffle sequences.
* \param [in] is_output Determines if the user wants the loaded sequence of frames to be part of the output or not.
* \param [in] loop: repeat data loading.
* \param [in] rocal_decoder_type Determines the decoder_type, FFmepg or RocDecode
* \param [in] step: Frame interval between each sequence.
* \param [in] stride: Frame interval between frames in a sequence.
* \param [in] file_list_frame_num: Determines if the user wants to read frame number or timestamps if a text file is passed in the source_path.
Expand All @@ -677,6 +680,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalVideoFileSourceSingleShard(RocalConte
bool shuffle = false,
bool is_output = false,
bool loop = false,
RocalDecoderType rocal_decoder_type = RocalDecoderType::ROCAL_DECODER_VIDEO_FFMPEG_SW,
unsigned step = 0,
unsigned stride = 0,
bool file_list_frame_num = true,
Expand All @@ -695,6 +699,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalVideoFileSourceSingleShard(RocalConte
* \param [in] shuffle: to shuffle sequences.
* \param [in] is_output Determines if the user wants the loaded sequence of frames to be part of the output or not.
* \param [in] loop: repeat data loading.
* \param [in] rocal_decoder_type Determines the decoder_type, FFmepg or RocDecode
* \param [in] step: Frame interval between each sequence.
* \param [in] stride: Frame interval between frames in a sequence.
* \param [in] file_list_frame_num: Determines if the user wants to read frame number or timestamps if a text file is passed in the source_path.
Expand All @@ -712,6 +717,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalVideoFileResize(RocalContext context,
bool shuffle = false,
bool is_output = false,
bool loop = false,
RocalDecoderType rocal_decoder_type = RocalDecoderType::ROCAL_DECODER_VIDEO_FFMPEG_SW,
unsigned step = 0,
unsigned stride = 0,
bool file_list_frame_num = true,
Expand All @@ -736,6 +742,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalVideoFileResize(RocalContext context,
* \param [in] shuffle: to shuffle sequences.
* \param [in] is_output Determines if the user wants the loaded sequence of frames to be part of the output or not.
* \param [in] loop: repeat data loading.
* \param [in] rocal_decoder_type Determines the decoder_type, FFmepg or RocDecode
* \param [in] step: Frame interval between each sequence.
* \param [in] stride: Frame interval between frames in a sequence.
* \param [in] file_list_frame_num: Determines if the user wants to read frame number or timestamps if a text file is passed in the source_path.
Expand All @@ -754,6 +761,7 @@ extern "C" RocalTensor ROCAL_API_CALL rocalVideoFileResizeSingleShard(RocalConte
bool shuffle = false,
bool is_output = false,
bool loop = false,
RocalDecoderType rocal_decoder_type = RocalDecoderType::ROCAL_DECODER_VIDEO_FFMPEG_SW,
unsigned step = 0,
unsigned stride = 0,
bool file_list_frame_num = true,
Expand Down
6 changes: 5 additions & 1 deletion rocAL/include/api/rocal_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ enum RocalDecoderType {
/*! \brief AMD ROCAL_DECODER_AUDIO_GENERIC
* Uses SndFile library to read audio files
*/
ROCAL_DECODER_AUDIO_GENERIC = 5
ROCAL_DECODER_AUDIO_GENERIC = 5,
/*! \brief AMD ROCAL_DECODER_VIDEO_ROCDECODE
* Uses rocDecode library to decode videos on hardware
*/
ROCAL_DECODER_VIDEO_ROCDECODE = 6
};

enum RocalOutputMemType {
Expand Down
10 changes: 5 additions & 5 deletions rocAL/include/decoders/image/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ enum class DecoderType {
TURBO_JPEG = 0, //!< Can only decode
FUSED_TURBO_JPEG = 1, //!< FOR PARTIAL DECODING
OPENCV_DEC = 2, //!< for back_up decoding
HW_JPEG_DEC = 3,
HW_JPEG_DEC = 3, //!< for JPEG decoding using HW via FFMPEG
SKIP_DECODE = 4, //!< For skipping decoding in case of uncompressed data from reader
OVX_FFMPEG = 5, //!< Uses FFMPEG to decode video streams, can decode up to 4 video streams simultaneously
FFMPEG_SOFTWARE_DECODE = 6,
FFMPEG_HARDWARE_DECODE = 7,
AUDIO_SOFTWARE_DECODE = 8 //!< Uses sndfile to decode audio files
FFMPEG_SW_DECODE = 6, //!< for video decoding using CPU and FFMPEG
rrawther marked this conversation as resolved.
Show resolved Hide resolved
FFMPEG_HW_DECODE = 7, //!< for video decoding using HW via FFMPEG
rrawther marked this conversation as resolved.
Show resolved Hide resolved
ROCDEC_VIDEO_DECODE = 8, //!< for video decoding using HW via rocDecode
AUDIO_SOFTWARE_DECODE = 9 //!< Uses sndfile to decode audio files
};

class DecoderConfig {
Expand Down
6 changes: 3 additions & 3 deletions rocAL/include/decoders/video/ffmpeg_video_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class FFmpegVideoDecoder : public VideoDecoder {
public:
//! Default constructor
FFmpegVideoDecoder();
VideoDecoder::Status Initialize(const char *src_filename) override;
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;
void release() override;
int SeekFrame(AVRational avg_frame_rate, AVRational time_base, unsigned frame_number) override;
void Release() override;
~FFmpegVideoDecoder() override;

private:
Expand Down
6 changes: 3 additions & 3 deletions rocAL/include/decoders/video/hardware_video_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class HardWareVideoDecoder : public VideoDecoder {
public:
//! Default constructor
HardWareVideoDecoder();
VideoDecoder::Status Initialize(const char *src_filename) override;
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;
void release() override;
int SeekFrame(AVRational avg_frame_rate, AVRational time_base, unsigned frame_number) override;
void Release() override;
~HardWareVideoDecoder() override;

private:
Expand Down
64 changes: 64 additions & 0 deletions rocAL/include/decoders/video/rocdec_video_decoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#pragma once

#include "video_decoder.h"

#ifdef ROCAL_VIDEO
#if ENABLE_HIP && ENABLE_ROCDECODE

#include "video_demuxer.h"
#include "video_post_process.h"
#include "rocvideodecode/roc_video_dec.h"

typedef enum ReconfigFlushModeEnum {
RECONFIG_FLUSH_MODE_NONE = 0, /**< Just flush to get the frame count */
RECONFIG_FLUSH_MODE_DUMP_TO_FILE = 1, /**< The remaining frames will be dumped to file in this mode */
RECONFIG_FLUSH_MODE_CALCULATE_MD5 = 2, /**< Calculate the MD5 of the flushed frames */
} ReconfigFlushMode;

typedef struct ReconfigDumpFileStruct_t {
bool b_dump_frames_to_file;
std::string output_file_name;
} ReconfigDumpFileStruct;

class RocDecVideoDecoder : public VideoDecoder {
public:
//! Default constructor
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 SeekFrame(AVRational avg_frame_rate, AVRational time_base, unsigned frame_number) override { return 0; }
void Release() override {}
~RocDecVideoDecoder() override;

private:
const char *_src_filename = NULL;
std::shared_ptr<VideoDemuxer> _demuxer;
std::shared_ptr<RocVideoDecoder> _rocvid_decoder;
OutputFormatEnum _output_format = rgb;
int _device_id;
};

#endif
#endif
6 changes: 3 additions & 3 deletions rocAL/include/decoders/video/video_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class VideoDecoder {
RGB,
BGR
};
virtual VideoDecoder::Status Initialize(const char *src_filename) = 0;
virtual VideoDecoder::Status Initialize(const char *src_filename, int device_id = 0) = 0;
virtual 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) = 0;
virtual int seek_frame(AVRational avg_frame_rate, AVRational time_base, unsigned frame_number) = 0;
virtual void release() = 0;
virtual int SeekFrame(AVRational avg_frame_rate, AVRational time_base, unsigned frame_number) = 0;
virtual void Release() = 0;
virtual ~VideoDecoder() = default;
};
#endif
2 changes: 2 additions & 0 deletions rocAL/include/loaders/video/video_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class VideoLoader : public LoaderModule {
void start_loading() override;
LoaderModuleStatus set_cpu_affinity(cpu_set_t cpu_mask);
LoaderModuleStatus set_cpu_sched_policy(struct sched_param sched_policy);
void set_gpu_device_id(int device_id);
std::vector<std::string> get_id() override;
DecodedDataInfo get_decode_data_info() override;
void set_prefetch_queue_depth(size_t prefetch_queue_depth) override;
Expand Down Expand Up @@ -83,6 +84,7 @@ class VideoLoader : public LoaderModule {
size_t _image_counter = 0; //!< How many frames have been loaded already
size_t _remaining_sequences_count; //!< How many frames are there yet to be loaded
bool _decoder_keep_original = false;
int _device_id = 0; //!< device_id for this loader
std::vector<std::vector<size_t>> _sequence_start_framenum_vec;
std::vector<std::vector<std::vector<float>>> _sequence_frame_timestamps_vec;
CropImageInfo _crop_img_info;
Expand Down
Loading