[MOVED FROM BAD 110/134] vp8enc: Update for GstVideoCodecFrame API changes

This commit is contained in:
Sebastian Dröge 2012-05-16 14:04:28 +02:00
parent 1f65326f67
commit fd598a8e3d

View file

@ -63,7 +63,7 @@ typedef struct
{ {
vpx_image_t *image; vpx_image_t *image;
GList *invisible; GList *invisible;
} GstVP8EncCoderHook; } GstVP8EncUserData;
static void static void
_gst_mini_object_unref0 (GstMiniObject * obj) _gst_mini_object_unref0 (GstMiniObject * obj)
@ -73,14 +73,14 @@ _gst_mini_object_unref0 (GstMiniObject * obj)
} }
static void static void
gst_vp8_enc_coder_hook_free (GstVP8EncCoderHook * hook) gst_vp8_enc_user_data_free (GstVP8EncUserData * user_data)
{ {
if (hook->image) if (user_data->image)
g_slice_free (vpx_image_t, hook->image); g_slice_free (vpx_image_t, user_data->image);
g_list_foreach (hook->invisible, (GFunc) _gst_mini_object_unref0, NULL); g_list_foreach (user_data->invisible, (GFunc) _gst_mini_object_unref0, NULL);
g_list_free (hook->invisible); g_list_free (user_data->invisible);
g_slice_free (GstVP8EncCoderHook, hook); g_slice_free (GstVP8EncUserData, user_data);
} }
#define DEFAULT_BITRATE 0 #define DEFAULT_BITRATE 0
@ -927,7 +927,7 @@ gst_vp8_enc_process (GstVP8Enc * encoder)
vpx_codec_iter_t iter = NULL; vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt; const vpx_codec_cx_pkt_t *pkt;
GstVideoEncoder *video_encoder; GstVideoEncoder *video_encoder;
GstVP8EncCoderHook *hook; GstVP8EncUserData *user_data;
GstVideoCodecFrame *frame; GstVideoCodecFrame *frame;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
@ -971,18 +971,19 @@ gst_vp8_enc_process (GstVP8Enc * encoder)
GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame); GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame);
else else
GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame); GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame);
hook = frame->coder_hook;
user_data = gst_video_codec_frame_get_user_data (frame);
buffer = gst_buffer_new_and_alloc (pkt->data.frame.sz); buffer = gst_buffer_new_and_alloc (pkt->data.frame.sz);
memcpy (GST_BUFFER_DATA (buffer), pkt->data.frame.buf, pkt->data.frame.sz); memcpy (GST_BUFFER_DATA (buffer), pkt->data.frame.buf, pkt->data.frame.sz);
if (hook->image) if (user_data->image)
g_slice_free (vpx_image_t, hook->image); g_slice_free (vpx_image_t, user_data->image);
hook->image = NULL; user_data->image = NULL;
if (invisible) { if (invisible) {
hook->invisible = g_list_append (hook->invisible, buffer); user_data->invisible = g_list_append (user_data->invisible, buffer);
} else { } else {
frame->output_buffer = buffer; frame->output_buffer = buffer;
ret = gst_video_encoder_finish_frame (video_encoder, frame); ret = gst_video_encoder_finish_frame (video_encoder, frame);
@ -1057,7 +1058,7 @@ gst_vp8_enc_handle_frame (GstVideoEncoder * video_encoder,
vpx_codec_err_t status; vpx_codec_err_t status;
int flags = 0; int flags = 0;
vpx_image_t *image; vpx_image_t *image;
GstVP8EncCoderHook *hook; GstVP8EncUserData *user_data;
int quality; int quality;
GST_DEBUG_OBJECT (video_encoder, "handle_frame"); GST_DEBUG_OBJECT (video_encoder, "handle_frame");
@ -1072,11 +1073,10 @@ gst_vp8_enc_handle_frame (GstVideoEncoder * video_encoder,
image = gst_vp8_enc_buffer_to_image (encoder, frame->input_buffer); image = gst_vp8_enc_buffer_to_image (encoder, frame->input_buffer);
hook = g_slice_new0 (GstVP8EncCoderHook); user_data = g_slice_new0 (GstVP8EncUserData);
hook->image = image; user_data->image = image;
frame->coder_hook = hook; gst_video_codec_frame_set_user_data (frame, user_data,
frame->coder_hook_destroy_notify = (GDestroyNotify) gst_vp8_enc_user_data_free);
(GDestroyNotify) gst_vp8_enc_coder_hook_free;
if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame)) { if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame)) {
flags |= VPX_EFLAG_FORCE_KF; flags |= VPX_EFLAG_FORCE_KF;
@ -1089,9 +1089,7 @@ gst_vp8_enc_handle_frame (GstVideoEncoder * video_encoder,
if (status != 0) { if (status != 0) {
GST_ELEMENT_ERROR (encoder, LIBRARY, ENCODE, GST_ELEMENT_ERROR (encoder, LIBRARY, ENCODE,
("Failed to encode frame"), ("%s", gst_vpx_error_name (status))); ("Failed to encode frame"), ("%s", gst_vpx_error_name (status)));
g_slice_free (GstVP8EncCoderHook, hook); gst_video_codec_frame_set_user_data (frame, NULL, NULL);
frame->coder_hook = NULL;
g_slice_free (vpx_image_t, image);
return FALSE; return FALSE;
} }
@ -1117,7 +1115,7 @@ gst_vp8_enc_pre_push (GstVideoEncoder * video_encoder,
GstVP8Enc *encoder; GstVP8Enc *encoder;
GstBuffer *buf; GstBuffer *buf;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstVP8EncCoderHook *hook = frame->coder_hook; GstVP8EncUserData *user_data = gst_video_codec_frame_get_user_data (frame);
GList *l; GList *l;
gint inv_count; gint inv_count;
GstVideoInfo *info; GstVideoInfo *info;
@ -1128,14 +1126,15 @@ gst_vp8_enc_pre_push (GstVideoEncoder * video_encoder,
info = &encoder->input_state->info; info = &encoder->input_state->info;
g_assert (hook != NULL); g_assert (user_data != NULL);
for (inv_count = 0, l = hook->invisible; l; inv_count++, l = l->next) { for (inv_count = 0, l = user_data->invisible; l; inv_count++, l = l->next) {
buf = l->data; buf = l->data;
l->data = NULL; l->data = NULL;
/* FIXME : All of this should have already been handled by base classes, no ? */ /* FIXME : All of this should have already been handled by base classes, no ? */
if (l == hook->invisible && GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) { if (l == user_data->invisible
&& GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) {
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
encoder->keyframe_distance = 0; encoder->keyframe_distance = 0;
} else { } else {
@ -1165,7 +1164,7 @@ gst_vp8_enc_pre_push (GstVideoEncoder * video_encoder,
buf = frame->output_buffer; buf = frame->output_buffer;
/* FIXME : All of this should have already been handled by base classes, no ? */ /* FIXME : All of this should have already been handled by base classes, no ? */
if (!hook->invisible && GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) { if (!user_data->invisible && GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) {
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
encoder->keyframe_distance = 0; encoder->keyframe_distance = 0;
} else { } else {