mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 04:31:06 +00:00
encoder: fix computation of max coded buffer size (again).
The previous fix was only valid to express the maximum size of the macroblock layer, i.e. without any headers. Now, also account for the slice headers and top picture header, but also any other header we might stuff into the VA coded buffer, e.g. sequence headers.
This commit is contained in:
parent
b864d1f71a
commit
2940a74ea4
2 changed files with 44 additions and 0 deletions
|
@ -1592,6 +1592,15 @@ gst_vaapi_encoder_h264_set_context_info (GstVaapiEncoder * base_encoder)
|
|||
GstVaapiContextInfo *const cip = &base_encoder->context_info;
|
||||
const guint DEFAULT_SURFACES_COUNT = 3;
|
||||
|
||||
/* Maximum sizes for common headers (in bits) */
|
||||
enum {
|
||||
MAX_SPS_HDR_SIZE = 16473,
|
||||
MAX_VUI_PARAMS_SIZE = 210,
|
||||
MAX_HRD_PARAMS_SIZE = 4103,
|
||||
MAX_PPS_HDR_SIZE = 101,
|
||||
MAX_SLICE_HDR_SIZE = 397 + 2572 + 6670 + 2402,
|
||||
};
|
||||
|
||||
cip->profile = encoder->profile;
|
||||
cip->ref_frames = (encoder->b_frame_num ? 2 : 1) + DEFAULT_SURFACES_COUNT;
|
||||
|
||||
|
@ -1600,6 +1609,19 @@ gst_vaapi_encoder_h264_set_context_info (GstVaapiEncoder * base_encoder)
|
|||
/* XXX: check profile and compute RawMbBits */
|
||||
base_encoder->codedbuf_size = (GST_ROUND_UP_16 (cip->width) *
|
||||
GST_ROUND_UP_16 (cip->height) / 256) * 400;
|
||||
|
||||
/* Account for SPS header */
|
||||
/* XXX: exclude scaling lists, MVC/SVC extensions */
|
||||
base_encoder->codedbuf_size += 4 + GST_ROUND_UP_8 (MAX_SPS_HDR_SIZE +
|
||||
MAX_VUI_PARAMS_SIZE + 2 * MAX_HRD_PARAMS_SIZE) / 8;
|
||||
|
||||
/* Account for PPS header */
|
||||
/* XXX: exclude slice groups, scaling lists, MVC/SVC extensions */
|
||||
base_encoder->codedbuf_size += 4 + GST_ROUND_UP_8 (MAX_PPS_HDR_SIZE) / 8;
|
||||
|
||||
/* Account for slice header. At most 200 slices are supported */
|
||||
base_encoder->codedbuf_size += 200 * (4 +
|
||||
GST_ROUND_UP_8 (MAX_SLICE_HDR_SIZE) / 8);
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
|
|
|
@ -633,6 +633,16 @@ gst_vaapi_encoder_mpeg2_set_context_info (GstVaapiEncoder * base_encoder)
|
|||
GstVaapiEncoderMpeg2 *const encoder = GST_VAAPI_ENCODER_MPEG2 (base_encoder);
|
||||
GstVaapiContextInfo *const cip = &base_encoder->context_info;
|
||||
|
||||
/* Maximum sizes for common headers (in bytes) */
|
||||
enum {
|
||||
MAX_SEQ_HDR_SIZE = 140,
|
||||
MAX_SEQ_EXT_SIZE = 10,
|
||||
MAX_GOP_SIZE = 8,
|
||||
MAX_PIC_HDR_SIZE = 10,
|
||||
MAX_PIC_EXT_SIZE = 11,
|
||||
MAX_SLICE_HDR_SIZE = 8,
|
||||
};
|
||||
|
||||
cip->profile = to_vaapi_profile (encoder->profile);
|
||||
cip->ref_frames = 2;
|
||||
|
||||
|
@ -640,6 +650,18 @@ gst_vaapi_encoder_mpeg2_set_context_info (GstVaapiEncoder * base_encoder)
|
|||
have a limit of 4608 bits per macroblock. */
|
||||
base_encoder->codedbuf_size = (GST_ROUND_UP_16 (cip->width) *
|
||||
GST_ROUND_UP_16 (cip->height) / 256) * 576;
|
||||
|
||||
/* Account for Sequence, GOP, and Picture headers */
|
||||
/* XXX: exclude unused Sequence Display Extension, Sequence Scalable
|
||||
Extension, Quantization Matrix Extension, Picture Display Extension,
|
||||
Picture Temporal Scalable Extension, Picture Spatial Scalable
|
||||
Extension */
|
||||
base_encoder->codedbuf_size += MAX_SEQ_HDR_SIZE + MAX_SEQ_EXT_SIZE +
|
||||
MAX_GOP_SIZE + MAX_PIC_HDR_SIZE + MAX_PIC_EXT_SIZE;
|
||||
|
||||
/* Account for Slice headers. We use one slice per line of macroblock */
|
||||
base_encoder->codedbuf_size += (GST_ROUND_UP_16 (cip->height) / 16) *
|
||||
MAX_SLICE_HDR_SIZE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
Loading…
Reference in a new issue