2023-08-14 14:14:09 -07:00
|
|
|
/*
|
2024-01-09 20:47:16 -05:00
|
|
|
Copyright (c) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
|
2023-08-14 14:14:09 -07:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2023-11-01 09:22:46 -04:00
|
|
|
#include <iostream>
|
2024-03-28 21:40:45 -04:00
|
|
|
#include <fstream>
|
2023-11-01 09:22:46 -04:00
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <unistd.h>
|
2024-03-25 14:31:02 -04:00
|
|
|
#include <cstring>
|
2024-05-06 21:12:23 -04:00
|
|
|
#if __cplusplus >= 201703L && __has_include(<filesystem>)
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#else
|
|
|
|
|
#include <experimental/filesystem>
|
|
|
|
|
#endif
|
2023-11-01 09:22:46 -04:00
|
|
|
#include <va/va.h>
|
|
|
|
|
#include <va/va_drm.h>
|
|
|
|
|
#include <va/va_drmcommon.h>
|
|
|
|
|
#include "../roc_decoder_caps.h"
|
|
|
|
|
#include "../../commons.h"
|
|
|
|
|
#include "../../../api/rocdecode.h"
|
|
|
|
|
|
2023-11-28 16:52:27 -05:00
|
|
|
#define CHECK_VAAPI(call) {\
|
|
|
|
|
VAStatus va_status = call;\
|
|
|
|
|
if (va_status != VA_STATUS_SUCCESS) {\
|
2024-02-06 13:35:41 -05:00
|
|
|
std::cout << "VAAPI failure: " << #call << " failed with status: " << std::hex << "0x" << va_status << std::dec << " = '" << vaErrorStr(va_status) << "' at " << __FILE__ << ":" << __LINE__ << std::endl;\
|
2023-11-28 16:52:27 -05:00
|
|
|
return ROCDEC_RUNTIME_ERROR;\
|
|
|
|
|
}\
|
2023-11-01 09:22:46 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-09 15:09:49 -05:00
|
|
|
#define INIT_SLICE_PARAM_LIST_NUM 16 // initial slice parameter buffer list size
|
|
|
|
|
|
2024-03-28 21:40:45 -04:00
|
|
|
typedef enum {
|
|
|
|
|
kSpx = 0, // Single Partition Accelerator
|
|
|
|
|
kDpx = 1, // Dual Partition Accelerator
|
|
|
|
|
kTpx = 2, // Triple Partition Accelerator
|
|
|
|
|
kQpx = 3, // Quad Partition Accelerator
|
|
|
|
|
kCpx = 4, // Core Partition Accelerator
|
|
|
|
|
} ComputePartition;
|
|
|
|
|
|
2023-11-01 09:22:46 -04:00
|
|
|
class VaapiVideoDecoder {
|
2023-08-14 14:14:09 -07:00
|
|
|
public:
|
2023-11-01 09:22:46 -04:00
|
|
|
VaapiVideoDecoder(RocDecoderCreateInfo &decoder_create_info);
|
|
|
|
|
~VaapiVideoDecoder();
|
2024-03-28 21:40:45 -04:00
|
|
|
rocDecStatus InitializeDecoder(std::string device_name, std::string gcn_arch_name);
|
2023-11-06 22:04:25 -05:00
|
|
|
rocDecStatus SubmitDecode(RocdecPicParams *pPicParams);
|
2023-11-09 08:47:58 -05:00
|
|
|
rocDecStatus GetDecodeStatus(int pic_idx, RocdecDecodeStatus* decode_status);
|
2023-11-10 17:02:57 -05:00
|
|
|
rocDecStatus ExportSurface(int pic_idx, VADRMPRIMESurfaceDescriptor &va_drm_prime_surface_desc);
|
2024-02-05 17:12:39 -05:00
|
|
|
rocDecStatus SyncSurface(int pic_idx);
|
2023-12-05 11:16:32 -05:00
|
|
|
rocDecStatus ReconfigureDecoder(RocdecReconfigureDecoderInfo *reconfig_params);
|
2023-11-01 09:22:46 -04:00
|
|
|
private:
|
|
|
|
|
RocDecoderCreateInfo decoder_create_info_;
|
|
|
|
|
int drm_fd_;
|
|
|
|
|
VADisplay va_display_;
|
|
|
|
|
VAConfigAttrib va_config_attrib_;
|
|
|
|
|
VAConfigID va_config_id_;
|
|
|
|
|
VAProfile va_profile_;
|
2023-11-07 13:47:53 -05:00
|
|
|
VAContextID va_context_id_;
|
|
|
|
|
std::vector<VASurfaceID> va_surface_ids_;
|
2023-11-10 17:15:47 -05:00
|
|
|
|
|
|
|
|
VABufferID pic_params_buf_id_;
|
|
|
|
|
VABufferID iq_matrix_buf_id_;
|
2024-02-09 15:09:49 -05:00
|
|
|
std::vector<VABufferID> slice_params_buf_id_ = std::vector<VABufferID>(INIT_SLICE_PARAM_LIST_NUM, 0);
|
|
|
|
|
uint32_t num_slices_;
|
2023-11-10 17:15:47 -05:00
|
|
|
VABufferID slice_data_buf_id_;
|
|
|
|
|
uint32_t slice_data_buf_size_;
|
|
|
|
|
|
2023-11-07 11:08:20 -05:00
|
|
|
rocDecStatus InitVAAPI(std::string drm_node);
|
2023-11-01 09:22:46 -04:00
|
|
|
rocDecStatus CreateDecoderConfig();
|
2023-11-07 13:47:53 -05:00
|
|
|
rocDecStatus CreateSurfaces();
|
|
|
|
|
rocDecStatus CreateContext();
|
2023-11-10 17:15:47 -05:00
|
|
|
rocDecStatus DestroyDataBuffers();
|
2024-03-25 14:31:02 -04:00
|
|
|
void GetVisibleDevices(std::vector<int>& visible_devices);
|
2024-03-28 21:40:45 -04:00
|
|
|
void GetCurrentComputePartition(std::vector<ComputePartition> &currnet_compute_partitions);
|
2024-04-09 18:17:02 -04:00
|
|
|
void GetDrmNodeOffset(std::string device_name, uint8_t device_id, std::vector<int>& visible_devices,
|
|
|
|
|
std::vector<ComputePartition> ¤t_compute_partitions, int &offset);
|
2023-08-14 14:14:09 -07:00
|
|
|
};
|