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:
Gwenole Beauchesne 2013-12-04 18:48:35 +01:00
parent fdddf83c71
commit fd9c855f14
4 changed files with 26 additions and 39 deletions

View file

@ -307,18 +307,21 @@ static gboolean
gst_vaapi_encoder_ensure_context (GstVaapiEncoder * encoder)
{
GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder);
GstVaapiContextInfo info;
GstVaapiContextInfo *const cip = &encoder->context_info;
GstVaapiContext *context;
if (GST_VAAPI_ENCODER_CONTEXT (encoder))
return TRUE;
memset (&info, 0, sizeof (info));
if (!klass->get_context_info (encoder, &info))
return FALSE;
cip->profile = GST_VAAPI_PROFILE_UNKNOWN;
cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
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),
&info);
context = gst_vaapi_context_new_full (encoder->display, cip);
if (!context)
return FALSE;
@ -406,7 +409,7 @@ gst_vaapi_encoder_init (GstVaapiEncoder * encoder, GstVaapiDisplay * display)
CHECK_VTABLE_HOOK (encode);
CHECK_VTABLE_HOOK (reordering);
CHECK_VTABLE_HOOK (flush);
CHECK_VTABLE_HOOK (get_context_info);
CHECK_VTABLE_HOOK (set_context_info);
CHECK_VTABLE_HOOK (set_format);
#undef CHECK_VTABLE_HOOK

View file

@ -1585,23 +1585,15 @@ end:
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
}
static gboolean
gst_vaapi_encoder_h264_get_context_info (GstVaapiEncoder * base,
GstVaapiContextInfo * info)
static void
gst_vaapi_encoder_h264_set_context_info (GstVaapiEncoder * base_encoder)
{
GstVaapiEncoderH264 *encoder = GST_VAAPI_ENCODER_H264 (base);
const static guint default_surface_num = 3;
GstVaapiEncoderH264 *const encoder = GST_VAAPI_ENCODER_H264 (base_encoder);
GstVaapiContextInfo *const cip = &base_encoder->context_info;
const guint DEFAULT_SURFACES_COUNT = 3;
g_return_val_if_fail (info, FALSE);
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;
cip->profile = encoder->profile;
cip->ref_frames = (encoder->b_frame_num ? 2 : 1) + DEFAULT_SURFACES_COUNT;
}
static GstCaps *

View file

@ -627,22 +627,14 @@ to_vaapi_profile (guint32 profile)
return p;
}
static gboolean
gst_vaapi_encoder_mpeg2_get_context_info (GstVaapiEncoder * base,
GstVaapiContextInfo * info)
static void
gst_vaapi_encoder_mpeg2_set_context_info (GstVaapiEncoder * base_encoder)
{
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);
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;
cip->profile = to_vaapi_profile (encoder->profile);
cip->ref_frames = 2;
}
static gboolean

View file

@ -80,6 +80,7 @@ struct _GstVaapiEncoder
GstVaapiDisplay *display;
GstVaapiContext *context;
GstVaapiContextInfo context_info;
GstCaps *caps;
VADisplay va_display;
@ -106,8 +107,7 @@ struct _GstVaapiEncoderClass
GstVideoCodecState * in_state,
GstCaps * ref_caps);
gboolean (*get_context_info) (GstVaapiEncoder * encoder,
GstVaapiContextInfo * info);
void (*set_context_info) (GstVaapiEncoder * encoder);
GstVaapiEncoderStatus (*reordering) (GstVaapiEncoder * encoder,
GstVideoCodecFrame * in,
@ -137,7 +137,7 @@ struct _GstVaapiEncoderClass
GST_VAAPI_ENCODER_CLASS_HOOK (codec, init), \
GST_VAAPI_ENCODER_CLASS_HOOK (codec, finalize), \
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, encode), \
GST_VAAPI_ENCODER_CLASS_HOOK (codec, flush)