diff options
author | Sreerenj Balachandran <sreerenj.balachandran@intel.com> | 2017-08-04 12:29:29 -0700 |
---|---|---|
committer | Sreerenj Balachandran <sreerenj.balachandran@intel.com> | 2017-08-04 14:59:12 -0700 |
commit | 97ffb40efc86c4a55d76e982bbab20a082ed5d2c (patch) | |
tree | f4c9280f2e86b38c5c7b3f85dd4033cef01726ee | |
parent | 9e961440e097cdc5a7c3a74c1837f9b29deaacd1 (diff) |
FEI: Code cleaningfei-dev
-- Keep enc and pak abstract class functions as internal methods
-- Conslidate common code in gstvaapiencoder_h264_fei.c
-- Added more comments, and fixed few descriptions
-- only assign the required property values to PAK abstract object
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c | 45 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapifeienc_h264.c | 6 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapifeienc_h264.h | 17 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapifeipak_h264.c | 99 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapifeipak_h264.h | 14 |
5 files changed, 34 insertions, 147 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c index 3d8a6182..9c08ab65 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c @@ -2899,18 +2899,6 @@ gst_vaapi_encoder_h264_fei_get_codec_data (GstVaapiEncoder * base_encoder, GstMapInfo sps_info, pps_info; GstBitWriter bs; GstBuffer *buffer; - GstVaapiEncoderStatus status; - - if ((encoder->fei_mode != GST_VAAPI_FEI_MODE_ENC_PAK) - && (encoder->fei_mode != GST_VAAPI_FEI_MODE_PAK)) { - status = - gst_vaapi_feipak_h264_get_codec_data (encoder->feipak, out_buffer_ptr); - if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) { - GST_ERROR ("failed to get pak codec data"); - return status; - } - return status; - } if (!encoder->sps_data || !encoder->pps_data) return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_HEADER; @@ -3194,9 +3182,8 @@ gst_vaapi_encoder_h264_fei_reconfigure (GstVaapiEncoder * base_encoder) guint mb_width, mb_height; const guint DEFAULT_SURFACES_COUNT = 3; - if ((encoder->fei_mode == GST_VAAPI_FEI_MODE_ENC_PAK) - || (encoder->fei_mode == GST_VAAPI_FEI_MODE_PAK)) { - /* ENC_PAK mode doesn't need to care about ENC and PAK + if (encoder->fei_mode != (GST_VAAPI_FEI_MODE_ENC | GST_VAAPI_FEI_MODE_PAK)) { + /* ENC_PAK, ENC and PAK modes doesn't need to care about ENC and PAK * abstrct objects */ mb_width = (GST_VAAPI_ENCODER_WIDTH (encoder) + 15) / 16; mb_height = (GST_VAAPI_ENCODER_HEIGHT (encoder) + 15) / 16; @@ -3227,8 +3214,8 @@ gst_vaapi_encoder_h264_fei_reconfigure (GstVaapiEncoder * base_encoder) return status; } else { - /* ENC, PAK and ENC+PAK mode requires two separate objects - * for ENC and PAK */ + /* ENC+PAK mode requires two separate objects + for ENC and PAK */ /* Maximum sizes for common headers (in bits) */ enum @@ -3547,7 +3534,7 @@ gst_vaapi_encoder_h264_fei_set_property (GstVaapiEncoder * base_encoder, encoder->fei_mode = GST_VAAPI_FEI_MODE_ENC | GST_VAAPI_FEI_MODE_PAK; } else if (encoder->fei_mode == GST_VAAPI_FEI_MODE_PAK) { g_warning ("============ PAK only mode selected ============ \n" - "This mode can work as expected, only if there is a custom user specific upstream element which provides mb_code and mv_vectors. If you are running the pipeline only for verification, We recommand to use the fei-mod ENC|PAK which will run the ENC operation and generate what ever input needed for PAK \n"); + "This mode can work as expected, only if there is a custom user specific upstream element which provides mb_code and mv_vectors. If you are running the pipeline only for verification, We recommand to use the fei-mod ENC+PAK which will run the ENC operation and generate what ever input needed for PAK \n"); } break; @@ -3559,10 +3546,7 @@ gst_vaapi_encoder_h264_fei_set_property (GstVaapiEncoder * base_encoder, if ((prop_id != GST_VAAPI_ENCODER_H264_PROP_FEI_MODE) && (prop_id != GST_VAAPI_ENCODER_H264_PROP_FEI_DISABLE) && (prop_id != GST_VAAPI_ENCODER_H264_PROP_ENABLE_STATS_OUT)) { - /** - * when new feiencoder, enc_base_encoder is NULL. - * Only need enc class when set input property. - */ + if (enc_base_encoder) { status = gst_vaapi_feienc_h264_set_property (enc_base_encoder, prop_id, value); @@ -3572,12 +3556,17 @@ gst_vaapi_encoder_h264_fei_set_property (GstVaapiEncoder * base_encoder, } } - if (encoder->feipak) { - status = - gst_vaapi_feipak_h264_set_property (encoder->feipak, prop_id, value); - if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) { - GST_ERROR ("failed to set pak property"); - return status; + if ((prop_id == GST_VAAPI_ENCODER_H264_FEI_PROP_MAX_BFRAMES) || + (prop_id == GST_VAAPI_ENCODER_H264_FEI_PROP_VIEW_IDS) || + (prop_id == GST_VAAPI_ENCODER_H264_FEI_PROP_NUM_VIEWS)) { + if (encoder->feipak) { + status = + gst_vaapi_feipak_h264_set_property (encoder->feipak, prop_id, + value); + if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) { + GST_ERROR ("failed to set pak property"); + return status; + } } } } diff --git a/gst-libs/gst/vaapi/gstvaapifeienc_h264.c b/gst-libs/gst/vaapi/gstvaapifeienc_h264.c index 844de0bd..18796482 100644 --- a/gst-libs/gst/vaapi/gstvaapifeienc_h264.c +++ b/gst-libs/gst/vaapi/gstvaapifeienc_h264.c @@ -1477,7 +1477,7 @@ gst_vaapi_feienc_h264_flush (GstVaapiEncoder * base_encoder) } /* Generate "codec-data" buffer */ -GstVaapiEncoderStatus +static GstVaapiEncoderStatus gst_vaapi_feienc_h264_get_codec_data (GstVaapiEncoder * base_encoder, GstBuffer ** out_buffer_ptr) { @@ -1681,7 +1681,7 @@ gst_vaapi_feienc_h264_reconfigure (GstVaapiEncoder * base_encoder) return GST_VAAPI_ENCODER_STATUS_SUCCESS; } -gboolean +static gboolean gst_vaapi_feienc_h264_init (GstVaapiEncoder * base_encoder) { GstVaapiFeiEncH264 *const feienc = GST_VAAPI_FEI_H264_ENC_CAST (base_encoder); @@ -1720,7 +1720,7 @@ gst_vaapi_feienc_h264_init (GstVaapiEncoder * base_encoder) return TRUE; } -void +static void gst_vaapi_feienc_h264_finalize (GstVaapiEncoder * base_encoder) { /*free private buffers */ diff --git a/gst-libs/gst/vaapi/gstvaapifeienc_h264.h b/gst-libs/gst/vaapi/gstvaapifeienc_h264.h index 70ff069c..03766e0d 100644 --- a/gst-libs/gst/vaapi/gstvaapifeienc_h264.h +++ b/gst-libs/gst/vaapi/gstvaapifeienc_h264.h @@ -81,9 +81,11 @@ typedef enum GST_VAAPI_FEI_H264_ENC_PROP_ENABLE_STATS_OUT = -27, } GstVaapiFeiEncH264Prop; -GstVaapiEncoder *gst_vaapi_feienc_h264_new (GstVaapiDisplay * display); +GstVaapiEncoder * +gst_vaapi_feienc_h264_new (GstVaapiDisplay * display); -GPtrArray *gst_vaapi_feienc_h264_get_default_properties (void); +GPtrArray * +gst_vaapi_feienc_h264_get_default_properties (void); gboolean gst_vaapi_feienc_h264_set_max_profile (GstVaapiFeiEncH264 * feienc, @@ -97,7 +99,8 @@ gst_vaapi_feienc_h264_encode (GstVaapiEncoder * base_encoder, GstVaapiEncPicture * picture, GstVaapiSurfaceProxy * reconstruct, GstVaapiCodedBufferProxy * codedbuf_proxy, GstVaapiFeiInfoToPakH264 *info_to_pak); -GstVaapiEncoderStatus gst_vaapi_feienc_h264_flush (GstVaapiEncoder * base_encoder); +GstVaapiEncoderStatus +gst_vaapi_feienc_h264_flush (GstVaapiEncoder * base_encoder); GstVaapiEncoderStatus gst_vaapi_feienc_h264_reordering (GstVaapiEncoder * base_encoder, @@ -106,18 +109,10 @@ gst_vaapi_feienc_h264_reordering (GstVaapiEncoder * base_encoder, GstVaapiEncoderStatus gst_vaapi_feienc_h264_reconfigure (GstVaapiEncoder * base_encoder); -gboolean gst_vaapi_feienc_h264_init (GstVaapiEncoder * base_encoder); - GstVaapiEncoderStatus gst_vaapi_feienc_h264_set_property (GstVaapiEncoder * base_encoder, gint prop_id, const GValue * value); -void gst_vaapi_feienc_h264_finalize (GstVaapiEncoder * base_encoder); - -GstVaapiEncoderStatus -gst_vaapi_feienc_h264_get_codec_data (GstVaapiEncoder * base_encoder, - GstBuffer ** out_buffer_ptr); - gboolean gst_vaapi_feienc_h264_get_profile_and_idc (GstVaapiFeiEncH264 * feienc, GstVaapiProfile * out_profile_ptr, guint8 * out_profile_idc_ptr); diff --git a/gst-libs/gst/vaapi/gstvaapifeipak_h264.c b/gst-libs/gst/vaapi/gstvaapifeipak_h264.c index 726c980b..bce50321 100644 --- a/gst-libs/gst/vaapi/gstvaapifeipak_h264.c +++ b/gst-libs/gst/vaapi/gstvaapifeipak_h264.c @@ -1704,99 +1704,9 @@ error: GstVaapiEncoderStatus gst_vaapi_feipak_h264_flush (GstVaapiFEIPakH264 * feipak) { - return GST_VAAPI_ENCODER_STATUS_SUCCESS; } -/* Generate "codec-data" buffer */ -GstVaapiEncoderStatus -gst_vaapi_feipak_h264_get_codec_data (GstVaapiFEIPakH264 * feipak, - GstBuffer ** out_buffer_ptr) -{ - const guint32 configuration_version = 0x01; - const guint32 nal_length_size = 4; - guint8 profile_idc, profile_comp, level_idc; - GstMapInfo sps_info, pps_info; - GstBitWriter bs; - GstBuffer *buffer; - - if (!feipak->sps_data || !feipak->pps_data) - return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_HEADER; - if (gst_buffer_get_size (feipak->sps_data) < 4) - return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_HEADER; - - if (!gst_buffer_map (feipak->sps_data, &sps_info, GST_MAP_READ)) - goto error_map_sps_buffer; - - if (!gst_buffer_map (feipak->pps_data, &pps_info, GST_MAP_READ)) - goto error_map_pps_buffer; - - /* skip sps_data[0], which is the nal_unit_type */ - profile_idc = sps_info.data[1]; - profile_comp = sps_info.data[2]; - level_idc = sps_info.data[3]; - - /* Header */ - gst_bit_writer_init (&bs, (sps_info.size + pps_info.size + 64) * 8); - WRITE_UINT32 (&bs, configuration_version, 8); - WRITE_UINT32 (&bs, profile_idc, 8); - WRITE_UINT32 (&bs, profile_comp, 8); - WRITE_UINT32 (&bs, level_idc, 8); - WRITE_UINT32 (&bs, 0x3f, 6); /* 111111 */ - WRITE_UINT32 (&bs, nal_length_size - 1, 2); - WRITE_UINT32 (&bs, 0x07, 3); /* 111 */ - - /* Write SPS */ - WRITE_UINT32 (&bs, 1, 5); /* SPS count = 1 */ - g_assert (GST_BIT_WRITER_BIT_SIZE (&bs) % 8 == 0); - WRITE_UINT32 (&bs, sps_info.size, 16); - gst_bit_writer_put_bytes (&bs, sps_info.data, sps_info.size); - - /* Write PPS */ - WRITE_UINT32 (&bs, 1, 8); /* PPS count = 1 */ - WRITE_UINT32 (&bs, pps_info.size, 16); - gst_bit_writer_put_bytes (&bs, pps_info.data, pps_info.size); - - gst_buffer_unmap (feipak->pps_data, &pps_info); - gst_buffer_unmap (feipak->sps_data, &sps_info); - - buffer = gst_buffer_new_wrapped (GST_BIT_WRITER_DATA (&bs), - GST_BIT_WRITER_BIT_SIZE (&bs) / 8); - if (!buffer) - goto error_alloc_buffer; - *out_buffer_ptr = buffer; - - gst_bit_writer_clear (&bs, FALSE); - return GST_VAAPI_ENCODER_STATUS_SUCCESS; - - /* ERRORS */ -bs_error: - { - GST_ERROR ("failed to write codec-data"); - gst_buffer_unmap (feipak->sps_data, &sps_info); - gst_buffer_unmap (feipak->pps_data, &pps_info); - gst_bit_writer_clear (&bs, TRUE); - return FALSE; - } -error_map_sps_buffer: - { - GST_ERROR ("failed to map SPS packed header"); - return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED; - } -error_map_pps_buffer: - { - GST_ERROR ("failed to map PPS packed header"); - gst_buffer_unmap (feipak->sps_data, &sps_info); - return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED; - } -error_alloc_buffer: - { - GST_ERROR ("failed to allocate codec-data buffer"); - gst_bit_writer_clear (&bs, TRUE); - return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED; - } -} - GstVaapiEncoderStatus gst_vaapi_feipak_h264_reconfigure (GstVaapiFEIPakH264 * feipak, VAContextID va_context, GstVaapiProfile profile, @@ -1832,7 +1742,7 @@ gst_vaapi_feipak_h264_reconfigure (GstVaapiFEIPakH264 * feipak, return GST_VAAPI_ENCODER_STATUS_SUCCESS; } -gboolean +static gboolean gst_vaapi_feipak_h264_init (GstVaapiFEIPakH264 * feipak, GstVaapiEncoder * encoder, GstVaapiDisplay * display, VAContextID va_context) @@ -1872,7 +1782,7 @@ gst_vaapi_feipak_h264_init (GstVaapiFEIPakH264 * feipak, return TRUE; } -void +static void gst_vaapi_feipak_h264_finalize (GstVaapiFEIPakH264 * feipak) { GstVaapiFEIPakH264Ref *ref; @@ -1903,6 +1813,9 @@ gst_vaapi_feipak_h264_set_property (GstVaapiFEIPakH264 * feipak, case GST_VAAPI_FEIPAK_H264_PROP_MAX_BFRAMES: feipak->num_bframes = g_value_get_uint (value); break; + case GST_VAAPI_FEIPAK_H264_PROP_NUM_VIEWS: + feipak->num_views = g_value_get_uint (value); + break; case GST_VAAPI_FEIPAK_H264_PROP_VIEW_IDS:{ guint i; GValueArray *view_ids = g_value_get_boxed (value); @@ -1921,7 +1834,7 @@ gst_vaapi_feipak_h264_set_property (GstVaapiFEIPakH264 * feipak, break; } default: - return GST_VAAPI_ENCODER_STATUS_SUCCESS; + return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER; } return GST_VAAPI_ENCODER_STATUS_SUCCESS; } diff --git a/gst-libs/gst/vaapi/gstvaapifeipak_h264.h b/gst-libs/gst/vaapi/gstvaapifeipak_h264.h index 040e1af0..f257becc 100644 --- a/gst-libs/gst/vaapi/gstvaapifeipak_h264.h +++ b/gst-libs/gst/vaapi/gstvaapifeipak_h264.h @@ -64,13 +64,6 @@ typedef enum GST_VAAPI_FEIPAK_H264_PROP_NUM_REF = -10, } GstVaapiFEIPakH264Prop; -gboolean -gst_vaapi_feipak_h264_init (GstVaapiFEIPakH264 * feipak, - GstVaapiEncoder * encoder, GstVaapiDisplay * display, - VAContextID va_context); - -void gst_vaapi_feipak_h264_finalize (GstVaapiFEIPakH264 * feipak); - GstVaapiEncoderStatus gst_vaapi_feipak_h264_reconfigure (GstVaapiFEIPakH264 * feipak, VAContextID va_context, GstVaapiProfile profile, guint8 profile_idc, @@ -82,7 +75,8 @@ gst_vaapi_feipak_h264_encode (GstVaapiFEIPakH264 * feipak, GstVaapiEncPicture * picture, GstVaapiCodedBufferProxy * codedbuf, GstVaapiSurfaceProxy * surface, GstVaapiFeiInfoToPakH264 *info_to_pak); -GstVaapiEncoderStatus gst_vaapi_feipak_h264_flush (GstVaapiFEIPakH264 * feipak); +GstVaapiEncoderStatus +gst_vaapi_feipak_h264_flush (GstVaapiFEIPakH264 * feipak); GstVaapiFEIPakH264 *gst_vaapi_feipak_h264_new (GstVaapiEncoder * encoder, GstVaapiDisplay * display, VAContextID va_context); @@ -91,10 +85,6 @@ GstVaapiEncoderStatus gst_vaapi_feipak_h264_set_property (GstVaapiFEIPakH264 * feipak, gint prop_id, const GValue * value); -GstVaapiEncoderStatus -gst_vaapi_feipak_h264_get_codec_data (GstVaapiFEIPakH264 * feipak, - GstBuffer ** out_buffer_ptr); - gboolean gst_vaapi_feipak_h264_get_ref_pool (GstVaapiFEIPakH264 * feipak, gpointer * ref_pool_ptr); |