mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
vulkan_hevc: switch from a buffer pool to a malloc and simplify
Simpler and more robust now that contexts are not shared between threads.
This commit is contained in:
parent
4565747056
commit
552a5fa496
@ -1104,7 +1104,7 @@ int ff_vk_decode_uninit(AVCodecContext *avctx)
|
||||
/* Wait on and free execution pool */
|
||||
ff_vk_exec_pool_free(&ctx->s, &dec->exec_pool);
|
||||
|
||||
av_buffer_pool_uninit(&dec->tmp_pool);
|
||||
av_freep(&dec->hevc_headers);
|
||||
av_buffer_unref(&dec->session_params);
|
||||
av_buffer_unref(&dec->shared_ref);
|
||||
av_freep(&dec->slice_off);
|
||||
|
@ -64,8 +64,8 @@ typedef struct FFVulkanDecodeContext {
|
||||
uint32_t frame_id_alloc_mask; /* For AV1 only */
|
||||
|
||||
/* Thread-local state below */
|
||||
AVBufferPool *tmp_pool; /* Pool for temporary data, if needed (HEVC) */
|
||||
size_t tmp_pool_ele_size;
|
||||
struct HEVCHeaderSet *hevc_headers;
|
||||
size_t hevc_headers_size;
|
||||
|
||||
uint32_t *slice_off;
|
||||
unsigned int slice_off_max;
|
||||
|
@ -68,49 +68,33 @@ typedef struct HEVCHeaderSet {
|
||||
HEVCHeaderVPS *hvps;
|
||||
} HEVCHeaderSet;
|
||||
|
||||
static int get_data_set_buf(FFVulkanDecodeContext *s, AVBufferRef **data_buf,
|
||||
int nb_vps, AVBufferRef * const vps_list[HEVC_MAX_VPS_COUNT])
|
||||
static int alloc_hevc_header_structs(FFVulkanDecodeContext *s,
|
||||
int nb_vps,
|
||||
AVBufferRef * const vps_list[HEVC_MAX_VPS_COUNT])
|
||||
{
|
||||
uint8_t *data_ptr;
|
||||
HEVCHeaderSet *hdr;
|
||||
|
||||
size_t base_size = sizeof(StdVideoH265SequenceParameterSet)*HEVC_MAX_SPS_COUNT +
|
||||
sizeof(HEVCHeaderSPS)*HEVC_MAX_SPS_COUNT +
|
||||
sizeof(StdVideoH265PictureParameterSet)*HEVC_MAX_PPS_COUNT +
|
||||
sizeof(HEVCHeaderPPS)*HEVC_MAX_PPS_COUNT +
|
||||
sizeof(StdVideoH265VideoParameterSet)*HEVC_MAX_VPS_COUNT +
|
||||
sizeof(HEVCHeaderVPS *);
|
||||
|
||||
size_t vps_size = sizeof(StdVideoH265ProfileTierLevel) +
|
||||
sizeof(StdVideoH265DecPicBufMgr) +
|
||||
sizeof(StdVideoH265HrdParameters)*HEVC_MAX_LAYER_SETS +
|
||||
sizeof(HEVCHeaderVPSSet *);
|
||||
|
||||
size_t buf_size = base_size + vps_size*nb_vps;
|
||||
|
||||
size_t buf_size = sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS);
|
||||
for (int i = 0; i < nb_vps; i++) {
|
||||
const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data;
|
||||
buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters;
|
||||
}
|
||||
|
||||
if (buf_size > s->tmp_pool_ele_size) {
|
||||
av_buffer_pool_uninit(&s->tmp_pool);
|
||||
s->tmp_pool_ele_size = 0;
|
||||
s->tmp_pool = av_buffer_pool_init(buf_size, NULL);
|
||||
if (!s->tmp_pool)
|
||||
if (buf_size > s->hevc_headers_size) {
|
||||
av_freep(&s->hevc_headers);
|
||||
s->hevc_headers_size = 0;
|
||||
s->hevc_headers = av_mallocz(buf_size);
|
||||
if (!s->hevc_headers)
|
||||
return AVERROR(ENOMEM);
|
||||
s->tmp_pool_ele_size = buf_size;
|
||||
s->hevc_headers_size = buf_size;
|
||||
}
|
||||
|
||||
*data_buf = av_buffer_pool_get(s->tmp_pool);
|
||||
if (!(*data_buf))
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
/* Setup pointers */
|
||||
data_ptr = (*data_buf)->data;
|
||||
hdr = (HEVCHeaderSet *)data_ptr;
|
||||
hdr->hvps = (HEVCHeaderVPS *)(data_ptr + base_size);
|
||||
data_ptr += base_size + vps_size*nb_vps;
|
||||
/* Setup struct pointers */
|
||||
hdr = s->hevc_headers;
|
||||
data_ptr = (uint8_t *)hdr;
|
||||
hdr->hvps = (HEVCHeaderVPS *)(data_ptr + sizeof(HEVCHeaderSet));
|
||||
data_ptr += sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS);
|
||||
for (int i = 0; i < nb_vps; i++) {
|
||||
const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data;
|
||||
hdr->hvps[i].sls = (HEVCHeaderVPSSet *)data_ptr;
|
||||
@ -672,17 +656,16 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf)
|
||||
};
|
||||
|
||||
int nb_vps = 0;
|
||||
AVBufferRef *data_set;
|
||||
HEVCHeaderSet *hdr;
|
||||
|
||||
for (int i = 0; h->ps.vps_list[i]; i++)
|
||||
nb_vps++;
|
||||
|
||||
err = get_data_set_buf(dec, &data_set, nb_vps, h->ps.vps_list);
|
||||
err = alloc_hevc_header_structs(dec, nb_vps, h->ps.vps_list);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
hdr = (HEVCHeaderSet *)data_set->data;
|
||||
hdr = dec->hevc_headers;
|
||||
|
||||
h265_params_info.pStdSPSs = hdr->sps;
|
||||
h265_params_info.pStdPPSs = hdr->pps;
|
||||
@ -719,7 +702,6 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf)
|
||||
h265_params.maxStdVPSCount = h265_params_info.stdVPSCount;
|
||||
|
||||
err = ff_vk_decode_create_params(buf, avctx, ctx, &session_params_create);
|
||||
av_buffer_unref(&data_set);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user