mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 06:58:56 +00:00
encoder: simplify VA context initialization process.
Change get_context_info() into a set_context_info() function that initializes common defaults into the base class, thus allowing the subclasses to specialize the context info further on. The set_context_info() hook is also the location where additional context specific data could be initialized. At this point, we are guaranteed to have valid video resolution size and framerate. i.e. gst_vaapi_encoder_set_format() was called beforehand.
This commit is contained in:
parent
fdddf83c71
commit
fd9c855f14
4 changed files with 26 additions and 39 deletions
|
@ -307,18 +307,21 @@ static gboolean
|
||||||
gst_vaapi_encoder_ensure_context (GstVaapiEncoder * encoder)
|
gst_vaapi_encoder_ensure_context (GstVaapiEncoder * encoder)
|
||||||
{
|
{
|
||||||
GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder);
|
GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder);
|
||||||
GstVaapiContextInfo info;
|
GstVaapiContextInfo *const cip = &encoder->context_info;
|
||||||
GstVaapiContext *context;
|
GstVaapiContext *context;
|
||||||
|
|
||||||
if (GST_VAAPI_ENCODER_CONTEXT (encoder))
|
if (GST_VAAPI_ENCODER_CONTEXT (encoder))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
memset (&info, 0, sizeof (info));
|
cip->profile = GST_VAAPI_PROFILE_UNKNOWN;
|
||||||
if (!klass->get_context_info (encoder, &info))
|
cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
|
||||||
return FALSE;
|
cip->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);
|
||||||
|
cip->width = GST_VAAPI_ENCODER_WIDTH (encoder);
|
||||||
|
cip->height = GST_VAAPI_ENCODER_HEIGHT (encoder);
|
||||||
|
cip->ref_frames = 0;
|
||||||
|
klass->set_context_info (encoder);
|
||||||
|
|
||||||
context = gst_vaapi_context_new_full (GST_VAAPI_ENCODER_DISPLAY (encoder),
|
context = gst_vaapi_context_new_full (encoder->display, cip);
|
||||||
&info);
|
|
||||||
if (!context)
|
if (!context)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -406,7 +409,7 @@ gst_vaapi_encoder_init (GstVaapiEncoder * encoder, GstVaapiDisplay * display)
|
||||||
CHECK_VTABLE_HOOK (encode);
|
CHECK_VTABLE_HOOK (encode);
|
||||||
CHECK_VTABLE_HOOK (reordering);
|
CHECK_VTABLE_HOOK (reordering);
|
||||||
CHECK_VTABLE_HOOK (flush);
|
CHECK_VTABLE_HOOK (flush);
|
||||||
CHECK_VTABLE_HOOK (get_context_info);
|
CHECK_VTABLE_HOOK (set_context_info);
|
||||||
CHECK_VTABLE_HOOK (set_format);
|
CHECK_VTABLE_HOOK (set_format);
|
||||||
|
|
||||||
#undef CHECK_VTABLE_HOOK
|
#undef CHECK_VTABLE_HOOK
|
||||||
|
|
|
@ -1585,23 +1585,15 @@ end:
|
||||||
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
|
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gst_vaapi_encoder_h264_get_context_info (GstVaapiEncoder * base,
|
gst_vaapi_encoder_h264_set_context_info (GstVaapiEncoder * base_encoder)
|
||||||
GstVaapiContextInfo * info)
|
|
||||||
{
|
{
|
||||||
GstVaapiEncoderH264 *encoder = GST_VAAPI_ENCODER_H264 (base);
|
GstVaapiEncoderH264 *const encoder = GST_VAAPI_ENCODER_H264 (base_encoder);
|
||||||
const static guint default_surface_num = 3;
|
GstVaapiContextInfo *const cip = &base_encoder->context_info;
|
||||||
|
const guint DEFAULT_SURFACES_COUNT = 3;
|
||||||
|
|
||||||
g_return_val_if_fail (info, FALSE);
|
cip->profile = encoder->profile;
|
||||||
|
cip->ref_frames = (encoder->b_frame_num ? 2 : 1) + DEFAULT_SURFACES_COUNT;
|
||||||
info->profile = encoder->profile;
|
|
||||||
info->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
|
|
||||||
info->width = GST_VAAPI_ENCODER_WIDTH (encoder);
|
|
||||||
info->height = GST_VAAPI_ENCODER_HEIGHT (encoder);
|
|
||||||
info->ref_frames = (encoder->b_frame_num ? 2 : 1) + default_surface_num;
|
|
||||||
info->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
|
|
|
@ -627,22 +627,14 @@ to_vaapi_profile (guint32 profile)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gst_vaapi_encoder_mpeg2_get_context_info (GstVaapiEncoder * base,
|
gst_vaapi_encoder_mpeg2_set_context_info (GstVaapiEncoder * base_encoder)
|
||||||
GstVaapiContextInfo * info)
|
|
||||||
{
|
{
|
||||||
GstVaapiEncoderMpeg2 *encoder = GST_VAAPI_ENCODER_MPEG2 (base);
|
GstVaapiEncoderMpeg2 *const encoder = GST_VAAPI_ENCODER_MPEG2 (base_encoder);
|
||||||
|
GstVaapiContextInfo *const cip = &base_encoder->context_info;
|
||||||
|
|
||||||
g_return_val_if_fail (info, FALSE);
|
cip->profile = to_vaapi_profile (encoder->profile);
|
||||||
|
cip->ref_frames = 2;
|
||||||
info->profile = to_vaapi_profile (encoder->profile);
|
|
||||||
info->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
|
|
||||||
info->width = GST_VAAPI_ENCODER_WIDTH (encoder);
|
|
||||||
info->height = GST_VAAPI_ENCODER_HEIGHT (encoder);
|
|
||||||
info->ref_frames = 2;
|
|
||||||
info->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
@ -80,6 +80,7 @@ struct _GstVaapiEncoder
|
||||||
|
|
||||||
GstVaapiDisplay *display;
|
GstVaapiDisplay *display;
|
||||||
GstVaapiContext *context;
|
GstVaapiContext *context;
|
||||||
|
GstVaapiContextInfo context_info;
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
|
||||||
VADisplay va_display;
|
VADisplay va_display;
|
||||||
|
@ -106,8 +107,7 @@ struct _GstVaapiEncoderClass
|
||||||
GstVideoCodecState * in_state,
|
GstVideoCodecState * in_state,
|
||||||
GstCaps * ref_caps);
|
GstCaps * ref_caps);
|
||||||
|
|
||||||
gboolean (*get_context_info) (GstVaapiEncoder * encoder,
|
void (*set_context_info) (GstVaapiEncoder * encoder);
|
||||||
GstVaapiContextInfo * info);
|
|
||||||
|
|
||||||
GstVaapiEncoderStatus (*reordering) (GstVaapiEncoder * encoder,
|
GstVaapiEncoderStatus (*reordering) (GstVaapiEncoder * encoder,
|
||||||
GstVideoCodecFrame * in,
|
GstVideoCodecFrame * in,
|
||||||
|
@ -137,7 +137,7 @@ struct _GstVaapiEncoderClass
|
||||||
GST_VAAPI_ENCODER_CLASS_HOOK (codec, init), \
|
GST_VAAPI_ENCODER_CLASS_HOOK (codec, init), \
|
||||||
GST_VAAPI_ENCODER_CLASS_HOOK (codec, finalize), \
|
GST_VAAPI_ENCODER_CLASS_HOOK (codec, finalize), \
|
||||||
GST_VAAPI_ENCODER_CLASS_HOOK (codec, set_format), \
|
GST_VAAPI_ENCODER_CLASS_HOOK (codec, set_format), \
|
||||||
GST_VAAPI_ENCODER_CLASS_HOOK (codec, get_context_info), \
|
GST_VAAPI_ENCODER_CLASS_HOOK (codec, set_context_info), \
|
||||||
GST_VAAPI_ENCODER_CLASS_HOOK (codec, reordering), \
|
GST_VAAPI_ENCODER_CLASS_HOOK (codec, reordering), \
|
||||||
GST_VAAPI_ENCODER_CLASS_HOOK (codec, encode), \
|
GST_VAAPI_ENCODER_CLASS_HOOK (codec, encode), \
|
||||||
GST_VAAPI_ENCODER_CLASS_HOOK (codec, flush)
|
GST_VAAPI_ENCODER_CLASS_HOOK (codec, flush)
|
||||||
|
|
Loading…
Reference in a new issue