mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
encoder: refactor status codes.
Drop obsolete or unused status codes. Align some status codes with the decoder counterparts.
This commit is contained in:
parent
8ecc35ecf2
commit
038149b69b
5 changed files with 45 additions and 48 deletions
|
@ -208,7 +208,7 @@ gst_vaapi_encoder_free_sync_pictures (GstVaapiEncoder * encoder)
|
||||||
GST_VAAPI_ENCODER_UNLOCK (encoder);
|
GST_VAAPI_ENCODER_UNLOCK (encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
gst_vaapi_encoder_push_sync_picture (GstVaapiEncoder * encoder,
|
gst_vaapi_encoder_push_sync_picture (GstVaapiEncoder * encoder,
|
||||||
GstVaapiEncoderSyncPic * sync_pic)
|
GstVaapiEncoderSyncPic * sync_pic)
|
||||||
{
|
{
|
||||||
|
@ -216,7 +216,6 @@ gst_vaapi_encoder_push_sync_picture (GstVaapiEncoder * encoder,
|
||||||
g_queue_push_tail (&encoder->sync_pictures, sync_pic);
|
g_queue_push_tail (&encoder->sync_pictures, sync_pic);
|
||||||
GST_VAAPI_ENCODER_SYNC_SIGNAL (encoder);
|
GST_VAAPI_ENCODER_SYNC_SIGNAL (encoder);
|
||||||
GST_VAAPI_ENCODER_UNLOCK (encoder);
|
GST_VAAPI_ENCODER_UNLOCK (encoder);
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstVaapiEncoderStatus
|
static GstVaapiEncoderStatus
|
||||||
|
@ -233,7 +232,7 @@ gst_vaapi_encoder_pop_sync_picture (GstVaapiEncoder * encoder,
|
||||||
goto timeout;
|
goto timeout;
|
||||||
|
|
||||||
if (g_queue_is_empty (&encoder->sync_pictures)) {
|
if (g_queue_is_empty (&encoder->sync_pictures)) {
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_UNKNOWN_ERR;
|
ret = GST_VAAPI_ENCODER_STATUS_ERROR_UNKNOWN;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +243,7 @@ gst_vaapi_encoder_pop_sync_picture (GstVaapiEncoder * encoder,
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
timeout:
|
timeout:
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_TIMEOUT;
|
ret = GST_VAAPI_ENCODER_STATUS_NO_BUFFER;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
GST_VAAPI_ENCODER_UNLOCK (encoder);
|
GST_VAAPI_ENCODER_UNLOCK (encoder);
|
||||||
|
@ -265,21 +264,14 @@ again:
|
||||||
picture = NULL;
|
picture = NULL;
|
||||||
sync_pic = NULL;
|
sync_pic = NULL;
|
||||||
ret = klass->reordering (encoder, frame, FALSE, &picture);
|
ret = klass->reordering (encoder, frame, FALSE, &picture);
|
||||||
|
if (ret == GST_VAAPI_ENCODER_STATUS_NO_SURFACE)
|
||||||
if (ret == GST_VAAPI_ENCODER_STATUS_FRAME_NOT_READY)
|
|
||||||
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
|
return GST_VAAPI_ENCODER_STATUS_SUCCESS;
|
||||||
|
|
||||||
g_assert (picture);
|
|
||||||
if (ret != GST_VAAPI_ENCODER_STATUS_SUCCESS)
|
if (ret != GST_VAAPI_ENCODER_STATUS_SUCCESS)
|
||||||
goto error;
|
goto error;
|
||||||
if (!picture) {
|
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_PICTURE_ERR;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
coded_buf = gst_vaapi_encoder_create_coded_buffer (encoder);
|
coded_buf = gst_vaapi_encoder_create_coded_buffer (encoder);
|
||||||
if (!coded_buf) {
|
if (!coded_buf) {
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_OBJECT_ERR;
|
ret = GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,11 +283,7 @@ again:
|
||||||
sync_pic = _create_sync_picture (picture, coded_buf);
|
sync_pic = _create_sync_picture (picture, coded_buf);
|
||||||
gst_vaapi_coded_buffer_proxy_replace (&coded_buf, NULL);
|
gst_vaapi_coded_buffer_proxy_replace (&coded_buf, NULL);
|
||||||
gst_vaapi_enc_picture_replace (&picture, NULL);
|
gst_vaapi_enc_picture_replace (&picture, NULL);
|
||||||
|
gst_vaapi_encoder_push_sync_picture (encoder, sync_pic);
|
||||||
if (!gst_vaapi_encoder_push_sync_picture (encoder, sync_pic)) {
|
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_THREAD_ERR;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
frame = NULL;
|
frame = NULL;
|
||||||
goto again;
|
goto again;
|
||||||
|
@ -326,11 +314,11 @@ gst_vaapi_encoder_get_buffer (GstVaapiEncoder * encoder,
|
||||||
picture = sync_pic->picture;
|
picture = sync_pic->picture;
|
||||||
|
|
||||||
if (!picture->surface || !gst_vaapi_surface_sync (picture->surface)) {
|
if (!picture->surface || !gst_vaapi_surface_sync (picture->surface)) {
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_PARAM_ERR;
|
ret = GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (!gst_vaapi_surface_query_status (picture->surface, &surface_status)) {
|
if (!gst_vaapi_surface_query_status (picture->surface, &surface_status)) {
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_PICTURE_ERR;
|
ret = GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_SURFACE;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (frame)
|
if (frame)
|
||||||
|
|
|
@ -27,23 +27,32 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstVaapiEncoderStatus:
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_SUCCESS: Success.
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_ERROR_NO_SURFACE: No surface left to encode.
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_ERROR_NO_BUFFER: No coded buffer left to hold the encoded picture.
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_ERROR_UNKNOWN: Unknown error.
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED: No memory left.
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER: Invalid parameter.
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_BUFFER: Invalid buffer.
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_SURFACE: Invalid surface.
|
||||||
|
* @GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_HEADER: Invalid header.
|
||||||
|
*
|
||||||
|
* Set of #GstVaapiEncoder status codes.
|
||||||
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GST_VAAPI_ENCODER_STATUS_SUCCESS = 0,
|
GST_VAAPI_ENCODER_STATUS_SUCCESS = 0,
|
||||||
GST_VAAPI_ENCODER_STATUS_FRAME_NOT_READY = 1,
|
GST_VAAPI_ENCODER_STATUS_NO_SURFACE = 1,
|
||||||
GST_VAAPI_ENCODER_STATUS_NO_DATA = 2,
|
GST_VAAPI_ENCODER_STATUS_NO_BUFFER = 2,
|
||||||
GST_VAAPI_ENCODER_STATUS_TIMEOUT = 3,
|
|
||||||
GST_VAAPI_ENCODER_STATUS_NOT_READY = 4,
|
|
||||||
GST_VAAPI_ENCODER_STATUS_FRAME_IN_ORDER = 5,
|
|
||||||
|
|
||||||
GST_VAAPI_ENCODER_STATUS_PARAM_ERR = -1,
|
GST_VAAPI_ENCODER_STATUS_ERROR_UNKNOWN = -1,
|
||||||
GST_VAAPI_ENCODER_STATUS_OBJECT_ERR = -2,
|
GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED = -2,
|
||||||
GST_VAAPI_ENCODER_STATUS_PICTURE_ERR = -3,
|
GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER = -100,
|
||||||
GST_VAAPI_ENCODER_STATUS_THREAD_ERR = -4,
|
GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_BUFFER = -101,
|
||||||
GST_VAAPI_ENCODER_STATUS_PROFILE_ERR = -5,
|
GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_SURFACE = -102,
|
||||||
GST_VAAPI_ENCODER_STATUS_FUNC_PTR_ERR = -6,
|
GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_HEADER = -103,
|
||||||
GST_VAAPI_ENCODER_STATUS_MEM_ERROR = -7,
|
|
||||||
GST_VAAPI_ENCODER_STATUS_UNKNOWN_ERR = -8,
|
|
||||||
} GstVaapiEncoderStatus;
|
} GstVaapiEncoderStatus;
|
||||||
|
|
||||||
typedef struct _GstVaapiEncoder GstVaapiEncoder;
|
typedef struct _GstVaapiEncoder GstVaapiEncoder;
|
||||||
|
|
|
@ -1350,7 +1350,7 @@ gst_vaapi_encoder_h264_encode (GstVaapiEncoder * base,
|
||||||
GstVaapiEncPicture * picture, GstVaapiCodedBufferProxy * codedbuf)
|
GstVaapiEncPicture * picture, GstVaapiCodedBufferProxy * codedbuf)
|
||||||
{
|
{
|
||||||
GstVaapiEncoderH264 *encoder = GST_VAAPI_ENCODER_H264_CAST (base);
|
GstVaapiEncoderH264 *encoder = GST_VAAPI_ENCODER_H264_CAST (base);
|
||||||
GstVaapiEncoderStatus ret = GST_VAAPI_ENCODER_STATUS_UNKNOWN_ERR;
|
GstVaapiEncoderStatus ret = GST_VAAPI_ENCODER_STATUS_ERROR_UNKNOWN;
|
||||||
GstVaapiSurfaceProxy *reconstruct = NULL;
|
GstVaapiSurfaceProxy *reconstruct = NULL;
|
||||||
|
|
||||||
reconstruct = gst_vaapi_encoder_create_surface (base);
|
reconstruct = gst_vaapi_encoder_create_surface (base);
|
||||||
|
@ -1412,19 +1412,19 @@ gst_vaapi_encoder_h264_get_avcC_codec_data (GstVaapiEncoderH264 * encoder,
|
||||||
|
|
||||||
g_assert (buffer);
|
g_assert (buffer);
|
||||||
if (!encoder->sps_data || !encoder->pps_data)
|
if (!encoder->sps_data || !encoder->pps_data)
|
||||||
return GST_VAAPI_ENCODER_STATUS_NOT_READY;
|
return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_HEADER;
|
||||||
|
|
||||||
if (!gst_buffer_map (encoder->sps_data, &sps_info, GST_MAP_READ))
|
if (!gst_buffer_map (encoder->sps_data, &sps_info, GST_MAP_READ))
|
||||||
return GST_VAAPI_ENCODER_STATUS_MEM_ERROR;
|
return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED;
|
||||||
|
|
||||||
if (FALSE == _read_sps_attributes (sps_info.data, sps_info.size,
|
if (FALSE == _read_sps_attributes (sps_info.data, sps_info.size,
|
||||||
&profile, &profile_comp, &level_idc)) {
|
&profile, &profile_comp, &level_idc)) {
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_UNKNOWN_ERR;
|
ret = GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_HEADER;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_buffer_map (encoder->pps_data, &pps_info, GST_MAP_READ)) {
|
if (!gst_buffer_map (encoder->pps_data, &pps_info, GST_MAP_READ)) {
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_MEM_ERROR;
|
ret = GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1453,7 +1453,7 @@ gst_vaapi_encoder_h264_get_avcC_codec_data (GstVaapiEncoderH264 * encoder,
|
||||||
GST_BIT_WRITER_BIT_SIZE (&writer) / 8);
|
GST_BIT_WRITER_BIT_SIZE (&writer) / 8);
|
||||||
g_assert (avc_codec);
|
g_assert (avc_codec);
|
||||||
if (!avc_codec) {
|
if (!avc_codec) {
|
||||||
ret = GST_VAAPI_ENCODER_STATUS_MEM_ERROR;
|
ret = GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED;
|
||||||
goto clear_writer;
|
goto clear_writer;
|
||||||
}
|
}
|
||||||
*buffer = avc_codec;
|
*buffer = avc_codec;
|
||||||
|
@ -1498,13 +1498,13 @@ gst_vaapi_encoder_h264_reordering (GstVaapiEncoder * base,
|
||||||
|
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
if (encoder->reorder_state != GST_VAAPI_ENC_H264_REORD_DUMP_FRAMES)
|
if (encoder->reorder_state != GST_VAAPI_ENC_H264_REORD_DUMP_FRAMES)
|
||||||
return GST_VAAPI_ENCODER_STATUS_FRAME_NOT_READY;
|
return GST_VAAPI_ENCODER_STATUS_NO_SURFACE;
|
||||||
|
|
||||||
/* reorder_state = GST_VAAPI_ENC_H264_REORD_DUMP_FRAMES
|
/* reorder_state = GST_VAAPI_ENC_H264_REORD_DUMP_FRAMES
|
||||||
dump B frames from queue, sometime, there may also have P frame or I frame */
|
dump B frames from queue, sometime, there may also have P frame or I frame */
|
||||||
g_assert (encoder->b_frame_num > 0);
|
g_assert (encoder->b_frame_num > 0);
|
||||||
g_return_val_if_fail (!g_queue_is_empty (&encoder->reorder_frame_list),
|
g_return_val_if_fail (!g_queue_is_empty (&encoder->reorder_frame_list),
|
||||||
GST_VAAPI_ENCODER_STATUS_UNKNOWN_ERR);
|
GST_VAAPI_ENCODER_STATUS_ERROR_UNKNOWN);
|
||||||
picture = g_queue_pop_head (&encoder->reorder_frame_list);
|
picture = g_queue_pop_head (&encoder->reorder_frame_list);
|
||||||
g_assert (picture);
|
g_assert (picture);
|
||||||
if (g_queue_is_empty (&encoder->reorder_frame_list)) {
|
if (g_queue_is_empty (&encoder->reorder_frame_list)) {
|
||||||
|
@ -1518,7 +1518,7 @@ gst_vaapi_encoder_h264_reordering (GstVaapiEncoder * base,
|
||||||
if (!picture) {
|
if (!picture) {
|
||||||
GST_WARNING ("create H264 picture failed, frame timestamp:%"
|
GST_WARNING ("create H264 picture failed, frame timestamp:%"
|
||||||
GST_TIME_FORMAT, GST_TIME_ARGS (frame->pts));
|
GST_TIME_FORMAT, GST_TIME_ARGS (frame->pts));
|
||||||
return GST_VAAPI_ENCODER_STATUS_OBJECT_ERR;
|
return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED;
|
||||||
}
|
}
|
||||||
++encoder->cur_present_index;
|
++encoder->cur_present_index;
|
||||||
picture->poc = ((encoder->cur_present_index * 2) %
|
picture->poc = ((encoder->cur_present_index * 2) %
|
||||||
|
@ -1562,7 +1562,7 @@ gst_vaapi_encoder_h264_reordering (GstVaapiEncoder * base,
|
||||||
g_queue_get_length (&encoder->reorder_frame_list) <
|
g_queue_get_length (&encoder->reorder_frame_list) <
|
||||||
encoder->b_frame_num) {
|
encoder->b_frame_num) {
|
||||||
g_queue_push_tail (&encoder->reorder_frame_list, picture);
|
g_queue_push_tail (&encoder->reorder_frame_list, picture);
|
||||||
return GST_VAAPI_ENCODER_STATUS_FRAME_NOT_READY;
|
return GST_VAAPI_ENCODER_STATUS_NO_SURFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
++encoder->cur_frame_num;
|
++encoder->cur_frame_num;
|
||||||
|
|
|
@ -501,7 +501,7 @@ gst_vaapi_encoder_mpeg2_encode (GstVaapiEncoder * base,
|
||||||
GstVaapiEncPicture * picture, GstVaapiCodedBufferProxy * codedbuf)
|
GstVaapiEncPicture * picture, GstVaapiCodedBufferProxy * codedbuf)
|
||||||
{
|
{
|
||||||
GstVaapiEncoderMpeg2 *encoder = GST_VAAPI_ENCODER_MPEG2_CAST (base);
|
GstVaapiEncoderMpeg2 *encoder = GST_VAAPI_ENCODER_MPEG2_CAST (base);
|
||||||
GstVaapiEncoderStatus ret = GST_VAAPI_ENCODER_STATUS_UNKNOWN_ERR;
|
GstVaapiEncoderStatus ret = GST_VAAPI_ENCODER_STATUS_ERROR_UNKNOWN;
|
||||||
GstVaapiSurfaceProxy *reconstruct = NULL;
|
GstVaapiSurfaceProxy *reconstruct = NULL;
|
||||||
|
|
||||||
reconstruct = gst_vaapi_encoder_create_surface (base);
|
reconstruct = gst_vaapi_encoder_create_surface (base);
|
||||||
|
@ -564,7 +564,7 @@ gst_vaapi_encoder_mpeg2_reordering (GstVaapiEncoder * base,
|
||||||
encoder->dump_frames = FALSE;
|
encoder->dump_frames = FALSE;
|
||||||
}
|
}
|
||||||
if (!encoder->dump_frames) {
|
if (!encoder->dump_frames) {
|
||||||
return GST_VAAPI_ENCODER_STATUS_FRAME_NOT_READY;
|
return GST_VAAPI_ENCODER_STATUS_NO_SURFACE;
|
||||||
}
|
}
|
||||||
picture = g_queue_pop_head (&encoder->b_frames);
|
picture = g_queue_pop_head (&encoder->b_frames);
|
||||||
g_assert (picture);
|
g_assert (picture);
|
||||||
|
@ -575,7 +575,7 @@ gst_vaapi_encoder_mpeg2_reordering (GstVaapiEncoder * base,
|
||||||
if (!picture) {
|
if (!picture) {
|
||||||
GST_WARNING ("create MPEG2 picture failed, frame timestamp:%"
|
GST_WARNING ("create MPEG2 picture failed, frame timestamp:%"
|
||||||
GST_TIME_FORMAT, GST_TIME_ARGS (frame->pts));
|
GST_TIME_FORMAT, GST_TIME_ARGS (frame->pts));
|
||||||
return GST_VAAPI_ENCODER_STATUS_OBJECT_ERR;
|
return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoder->frame_num >= encoder->intra_period) {
|
if (encoder->frame_num >= encoder->intra_period) {
|
||||||
|
@ -594,7 +594,7 @@ gst_vaapi_encoder_mpeg2_reordering (GstVaapiEncoder * base,
|
||||||
encoder->dump_frames = TRUE;
|
encoder->dump_frames = TRUE;
|
||||||
} else {
|
} else {
|
||||||
picture->type = GST_VAAPI_PICTURE_TYPE_B;
|
picture->type = GST_VAAPI_PICTURE_TYPE_B;
|
||||||
status = GST_VAAPI_ENCODER_STATUS_FRAME_NOT_READY;
|
status = GST_VAAPI_ENCODER_STATUS_NO_SURFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ gst_vaapiencode_push_frame (GstVaapiEncode * encode, gint64 timeout)
|
||||||
|
|
||||||
status = gst_vaapi_encoder_get_buffer (encode->encoder,
|
status = gst_vaapi_encoder_get_buffer (encode->encoder,
|
||||||
&out_frame, &codedbuf_proxy, timeout);
|
&out_frame, &codedbuf_proxy, timeout);
|
||||||
if (status == GST_VAAPI_ENCODER_STATUS_TIMEOUT)
|
if (status == GST_VAAPI_ENCODER_STATUS_NO_BUFFER)
|
||||||
return GST_VAAPI_ENCODE_FLOW_TIMEOUT;
|
return GST_VAAPI_ENCODE_FLOW_TIMEOUT;
|
||||||
if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS)
|
if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS)
|
||||||
goto error_get_buffer;
|
goto error_get_buffer;
|
||||||
|
|
Loading…
Reference in a new issue