Add initial cmake support for building the rocdecode library

[ROCm/rocdecode commit: 1ba367988d]
이 커밋은 다음에 포함됨:
Aryan
2023-07-26 17:47:47 -04:00
부모 912031c592
커밋 5b112f2c5c
17개의 변경된 파일1119개의 추가작업 그리고 24개의 파일을 삭제
+54
파일 보기
@@ -0,0 +1,54 @@
################################################################################
# Copyright (c) 2023 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.
#
################################################################################
cmake_minimum_required (VERSION 3.0)
project(videodecode)
set(CMAKE_CXX_STANDARD 17)
set(ROCM_PATH /opt/rocm CACHE PATH "default ROCm installation path")
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake)
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/hip ${ROCM_PATH})
set(CMAKE_CXX_COMPILER ${ROCM_PATH}/llvm/bin/clang++)
set(DEFAULT_AMDGPU_TARGETS "gfx803;gfx900;gfx906;gfx908;gfx90a;gfx940;gfx1030;gfx1031;gfx1032")
set(AMDGPU_TARGETS "${DEFAULT_AMDGPU_TARGETS}" CACHE STRING "List of specific machine types for library to target")
find_package(HIP QUIET)
find_package(FFmpeg QUIET)
find_package(Libva QUIET)
if(HIP_FOUND AND FFMPEG_FOUND AND Libva_FOUND)
include_directories (${ROCM_PATH}/include/rocdecode)
list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecode.cpp)
add_executable(${PROJECT_NAME} ${SOURCES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17")
target_link_libraries(${PROJECT_NAME} ${AVUTIL_LIBRARY} ${AVCODEC_LIBRARY} ${AVFORMAT_LIBRARY} Libva::va Libva::va_drm hip::device rocdecode)
else()
if (NOT HIP_FOUND)
message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!")
endif()
if (NOT FFMPEG_FOUND)
message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please insatll FFMPEG!")
endif()
if (NOT Libva_FOUND)
message(FATAL_ERROR "-- ERROR!: libva-dev Not Found - please install libva-dev!")
endif()
message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!")
endif()
+11
파일 보기
@@ -0,0 +1,11 @@
# Video Decode Sample
This sample illustrates the FFMPEG demuxer to get the individual frames which are then decoded on AMD hardware using VAAPI. This sample supports both YUV420 8-bit and 10-bit streams.
## Build and run the sample:
```
mkdir build
cd build
cmake ..
make -j
./videodecode -i <input video file - required> -o <optional; output path to save decoded YUV frames> -d <GPU device ID, 0 for the first device, 1 for the second device, etc>
```
+146
파일 보기
@@ -0,0 +1,146 @@
/*
Copyright (c) 2023 - 2023 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.
*/
#include <iostream>
#include <unistd.h>
#include <vector>
#include <string>
#include <chrono>
#include <sys/stat.h>
#include <libgen.h>
#include <filesystem>
#include "videoDemuxer.hpp"
#include "rocdecode.h"
void ShowHelpAndExit(const char *option = NULL) {
std::cout << "Options:" << std::endl
<< "-i Input File Path - required" << std::endl
<< "-o Output File Path - dumps output if requested; optional" << std::endl
<< "-d GPU device ID (0 for the first device, 1 for the second, etc.); optional; default: 0" << std::endl;
exit(0);
}
int main(int argc, char **argv) {
std::string inputFilePath, outputFilePath;
int dumpOutputFrames = 0;
int isOutputRGB = 0;
int deviceId = 0;
// Parse command-line arguments
if(argc < 1) {
ShowHelpAndExit();
}
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-h")) {
ShowHelpAndExit();
}
if (!strcmp(argv[i], "-i")) {
if (++i == argc) {
ShowHelpAndExit("-i");
}
inputFilePath = argv[i];
continue;
}
if (!strcmp(argv[i], "-o")) {
if (++i == argc) {
ShowHelpAndExit("-o");
}
outputFilePath = argv[i];
dumpOutputFrames = 1;
continue;
}
if (!strcmp(argv[i], "-d")) {
if (++i == argc) {
ShowHelpAndExit("-d");
}
deviceId = atoi(argv[i]);
continue;
}
ShowHelpAndExit(argv[i]);
}
VideoDemuxer demuxer(inputFilePath.c_str());
//VideoDecode viddec(deviceId);
std::string deviceName, gcnArchName, drmNode;
int pciBusID, pciDomainID, pciDeviceID;
/*viddec.getDeviceinfo(deviceName, gcnArchName, pciBusID, pciDomainID, pciDeviceID, drmNode);
std::cout << "info: Using GPU device " << deviceId << ": (drm node: " << drmNode << ") " << deviceName << "[" << gcnArchName << "] on PCI bus " <<
std::setfill('0') << std::setw(2) << std::right << std::hex << pciBusID << ":" << std::setfill('0') << std::setw(2) <<
std::right << std::hex << pciDomainID << "." << pciDeviceID << std::dec << std::endl;
std::cout << "info: decoding started, please wait!" << std::endl;*/
int nVideoBytes = 0, nFrameReturned = 0, nFrame = 0;
uint8_t *pVideo = nullptr;
uint8_t *pFrame = nullptr;
int64_t pts = 0;
//outputImageInfo *pImageInfo;
bool bDecodeOutSemiPlanar = false;
uint32_t width, height;
//vcnImageFormat_t subsampling;
double totalDecTime = 0;
do {
auto startTime = std::chrono::high_resolution_clock::now();
demuxer.demux(&pVideo, &nVideoBytes, &pts);
//nFrameReturned = viddec.decode(pVideo, nVideoBytes, pts);
auto endTime = std::chrono::high_resolution_clock::now();
auto timePerFrame = std::chrono::duration<double, std::milli>(endTime - startTime).count();
totalDecTime += timePerFrame;
/*if (!nFrame && !viddec.getOutputImageInfo(&pImageInfo)){
std::cerr << "Error: Failed to get Output Image Info!" << std::endl;
break;
}*/
if (dumpOutputFrames) {
for (int i = 0; i < nFrameReturned; i++) {
/*pFrame = viddec.getFrame(&pts);
viddec.saveImage(outputFilePath, pFrame, pImageInfo, false);
// release frame
viddec.releaseFrame(pts);*/
}
}
nFrame += nFrameReturned;
} while (nVideoBytes);
// Flush last frames from the decoder if any
do {
// send null packet to decoder to flush out
pVideo = nullptr; nVideoBytes = 0;
int64_t pts = 0;
//nFrameReturned = viddec.decode(pVideo, nVideoBytes, pts);
} while (nFrameReturned);
/*std::cout << "info: Video codec format: " << viddec.getCodecFmtName(viddec.getVcnVideoCodecId()) << std::endl;
std::cout << "info: Video size: [ " << pImageInfo->nOutputWidth << ", " << pImageInfo->nOutputHeight << " ]" << std::endl;
std::cout << "info: Video pix format: " << viddec.getPixFmtName(pImageInfo->chromaFormat) << std::endl;
std::cout << "info: Video Bit depth: " << pImageInfo->nBitDepth << std::endl;
std::cout << "info: Total frame decoded: " << nFrame << std::endl;
if (!dumpOutputFrames) {
std::cout << "info: avg decoding time per frame (ms): " << totalDecTime / nFrame << std::endl;
std::cout << "info: avg FPS: " << (nFrame / totalDecTime) * 1000 << std::endl;
}*/
return 0;
}