Optimize slice header building
This commit is contained in:
parent
e110e8b3d0
commit
a489604278
3 changed files with 12 additions and 13 deletions
|
@ -1,11 +1,11 @@
|
|||
#ifndef BITSTREAM_H
|
||||
#define BITSTREAM_H
|
||||
#include <stdlib.h>
|
||||
template <int max_size_in_dword>
|
||||
struct BaseBitstream
|
||||
{
|
||||
constexpr static int max_size_in_dword = 4096;
|
||||
unsigned int buffer[max_size_in_dword] = {0};
|
||||
int bit_offset = 0;
|
||||
unsigned int buffer[max_size_in_dword];
|
||||
static unsigned int Swap32(unsigned int val)
|
||||
{
|
||||
unsigned char *pval = (unsigned char *)&val;
|
||||
|
|
|
@ -213,7 +213,8 @@ struct VaapiEncoder
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CreatePackedBuffer(VABufferID &par, VABufferID &dat, VAEncPackedHeaderType type, const BaseBitstream &buf )
|
||||
template <int maxSize>
|
||||
bool CreatePackedBuffer(VABufferID &par, VABufferID &dat, VAEncPackedHeaderType type, const BaseBitstream<maxSize> &buf )
|
||||
{
|
||||
VAEncPackedHeaderParameterBuffer packed_header;
|
||||
VAStatus status;
|
||||
|
|
|
@ -64,7 +64,7 @@ enum NALUType {
|
|||
MAX_HEVC_NAL_TYPE = 0x3f,
|
||||
};
|
||||
|
||||
struct BaseBitstreamHEVC : BaseBitstream
|
||||
struct BaseBitstreamHEVC : BaseBitstream<16>
|
||||
{
|
||||
inline void NalStartCodePrefix(int nal_unit_type)
|
||||
{
|
||||
|
@ -403,20 +403,18 @@ struct PackedPPSHEVC : BaseBitstreamHEVC
|
|||
End();
|
||||
}
|
||||
};
|
||||
|
||||
template <int slice_type>
|
||||
struct PackedSliceHEVC : BaseBitstreamHEVC
|
||||
{
|
||||
PackedSliceHEVC(int framenum, const VAEncSequenceParameterBufferHEVC *sps, const VAEncSliceParameterBufferHEVC *slice, const VAEncPictureParameterBufferHEVC *pic): BaseBitstreamHEVC()
|
||||
inline PackedSliceHEVC(int framenum, const VAEncSequenceParameterBufferHEVC *sps, const VAEncSliceParameterBufferHEVC *slice, const VAEncPictureParameterBufferHEVC *pic): BaseBitstreamHEVC()
|
||||
{
|
||||
uint8_t nal_unit_type = NALU_TRAIL_R;
|
||||
//int gop_ref_distance = ip_period;
|
||||
int i = 0;
|
||||
bool is_idr = framenum == 0;
|
||||
int slice_type = is_idr?SLICE_I : SLICE_P;
|
||||
int short_term_ref_pic_set_sps_flag = 1; // !is_idr;
|
||||
//int short_term_ref_pic_set_sps_flag = 1; // !is_idr;
|
||||
int slice_qp_delta = slice->slice_qp_delta;
|
||||
int pic_order_cnt_lsb = framenum;
|
||||
if (pic_order_cnt_lsb == 0)
|
||||
if constexpr (slice_type == SLICE_I)
|
||||
nal_unit_type = NALU_IDR_W_DLP;
|
||||
NalStartCodePrefix(nal_unit_type);
|
||||
NalHeader(nal_unit_type);
|
||||
|
@ -546,7 +544,7 @@ struct PackedSliceHEVC : BaseBitstreamHEVC
|
|||
PutUI(slice->slice_fields.bits.slice_sao_chroma_flag, 1);//slice_sao_chroma_flag
|
||||
}
|
||||
|
||||
if (slice_type != SLICE_I) {
|
||||
if constexpr(slice_type != SLICE_I) {
|
||||
PutUI(slice->slice_fields.bits.num_ref_idx_active_override_flag, 1); //num_ref_idx_active_override_flag
|
||||
|
||||
if (slice->slice_fields.bits.num_ref_idx_active_override_flag) {
|
||||
|
@ -800,7 +798,7 @@ struct VaapiEncoderHEVC: VaapiEncoder
|
|||
|
||||
VABufferID pslice[2];
|
||||
CreatePackedBuffer(pslice[0], pslice[1], VAEncPackedHeaderSlice,
|
||||
PackedSliceHEVC(frame_count, &seq, &slice, &pic));
|
||||
PackedSliceHEVC<SLICE_I>(frame_count, &seq, &slice, &pic));
|
||||
VABufferID buffers[] = {seqb, pvps[0],pvps[1],psps[0], psps[1], fpsb, hrdb, rcb, ppps[0], ppps[1], picb, pslice[0], pslice[1], sliceb };
|
||||
vaRenderPicture(dpy, ctx, buffers, sizeof(buffers) / sizeof(buffers[0]) );
|
||||
status = vaEndPicture(dpy, ctx);
|
||||
|
@ -836,7 +834,7 @@ struct VaapiEncoderHEVC: VaapiEncoder
|
|||
VABufferID picb = CreateParamererBuffer(VAEncPictureParameterBufferType, pic);
|
||||
VABufferID pslice[2];
|
||||
CreatePackedBuffer(pslice[0], pslice[1], VAEncPackedHeaderSlice,
|
||||
PackedSliceHEVC(frame_count, &seq, &slice, &pic));
|
||||
PackedSliceHEVC<SLICE_P>(frame_count, &seq, &slice, &pic));
|
||||
VABufferID buffers[] = {picb, pslice[0], pslice[1], sliceb };
|
||||
vaRenderPicture(dpy, ctx, buffers, sizeof(buffers) / sizeof(buffers[0]) );
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue