mpeg2dec: Store temporary buffers out of the way

When mpeg2dec needs to do cropping (because downstream can't handle it),
we need temporary buffers to decode to.

Use the user_data field to store those, and unify the rest of the code
that needs to touch a buffer (regardless of how/where it was allocated).

https://bugzilla.gnome.org/show_bug.cgi?id=680194
This commit is contained in:
Edward Hervey 2012-07-19 09:56:17 +02:00
parent 090e139048
commit e0a5d6de60

View file

@ -374,9 +374,17 @@ gst_mpeg2dec_crop_buffer (GstMpeg2dec * dec, GstVideoCodecFrame * in_frame,
return GST_FLOW_OK; return GST_FLOW_OK;
} }
static void
frame_user_data_destroy_notify (GstBuffer * buf)
{
GST_DEBUG ("Releasing buffer %p", buf);
if (buf)
gst_buffer_unref (buf);
}
static GstFlowReturn static GstFlowReturn
gst_mpeg2dec_alloc_sized_buf (GstMpeg2dec * mpeg2dec, guint size, gst_mpeg2dec_alloc_sized_buf (GstMpeg2dec * mpeg2dec, guint size,
GstVideoCodecFrame * frame) GstVideoCodecFrame * frame, GstBuffer ** buffer)
{ {
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstVideoCodecState *state; GstVideoCodecState *state;
@ -387,14 +395,13 @@ gst_mpeg2dec_alloc_sized_buf (GstMpeg2dec * mpeg2dec, guint size,
ret = ret =
gst_video_decoder_alloc_output_frame (GST_VIDEO_DECODER (mpeg2dec), gst_video_decoder_alloc_output_frame (GST_VIDEO_DECODER (mpeg2dec),
frame); frame);
if (ret != GST_FLOW_OK) { *buffer = frame->output_buffer;
gst_video_codec_state_unref (state);
return ret;
}
} else { } else {
GstAllocationParams params = { 0, 15, 0, 0 }; GstAllocationParams params = { 0, 15, 0, 0 };
frame->output_buffer = gst_buffer_new_allocate (NULL, size, &params); *buffer = gst_buffer_new_allocate (NULL, size, &params);
gst_video_codec_frame_set_user_data (frame, *buffer,
(GDestroyNotify) frame_user_data_destroy_notify);
} }
gst_video_codec_state_unref (state); gst_video_codec_state_unref (state);
@ -473,12 +480,18 @@ gst_mpeg2dec_get_buffer (GstMpeg2dec * mpeg2dec, gint id)
} }
static GstFlowReturn static GstFlowReturn
gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, GstVideoCodecFrame * frame) gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, GstVideoCodecFrame * frame,
GstBuffer ** buffer)
{ {
GstFlowReturn ret;
GstVideoFrame vframe; GstVideoFrame vframe;
guint8 *buf[3]; guint8 *buf[3];
gst_mpeg2dec_alloc_sized_buf (mpeg2dec, mpeg2dec->decoded_info.size, frame); ret =
gst_mpeg2dec_alloc_sized_buf (mpeg2dec, mpeg2dec->decoded_info.size,
frame, buffer);
if (G_UNLIKELY (ret != GST_FLOW_OK))
goto beach;
if (mpeg2dec->need_cropping && mpeg2dec->has_cropping) { if (mpeg2dec->need_cropping && mpeg2dec->has_cropping) {
GstVideoCropMeta *crop; GstVideoCropMeta *crop;
@ -499,11 +512,9 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, GstVideoCodecFrame * frame)
gst_video_codec_state_unref (state); gst_video_codec_state_unref (state);
} }
if (!gst_video_frame_map (&vframe, &mpeg2dec->decoded_info, if (!gst_video_frame_map (&vframe, &mpeg2dec->decoded_info, *buffer,
frame->output_buffer, GST_MAP_READ | GST_MAP_WRITE)) { GST_MAP_READ | GST_MAP_WRITE))
GST_ERROR_OBJECT (mpeg2dec, "Failed to map frame"); goto map_fail;
return GST_FLOW_ERROR;
}
buf[0] = GST_VIDEO_FRAME_PLANE_DATA (&vframe, 0); buf[0] = GST_VIDEO_FRAME_PLANE_DATA (&vframe, 0);
buf[1] = GST_VIDEO_FRAME_PLANE_DATA (&vframe, 1); buf[1] = GST_VIDEO_FRAME_PLANE_DATA (&vframe, 1);
@ -516,7 +527,14 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, GstVideoCodecFrame * frame)
GINT_TO_POINTER (frame->system_frame_number)); GINT_TO_POINTER (frame->system_frame_number));
gst_mpeg2dec_save_buffer (mpeg2dec, frame->system_frame_number, &vframe); gst_mpeg2dec_save_buffer (mpeg2dec, frame->system_frame_number, &vframe);
return GST_FLOW_OK; beach:
return ret;
map_fail:
{
GST_ERROR_OBJECT (mpeg2dec, "Failed to map frame");
return GST_FLOW_ERROR;
}
} }
static void static void
@ -755,13 +773,14 @@ static GstFlowReturn
handle_picture (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info, handle_picture (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info,
GstVideoCodecFrame * frame) GstVideoCodecFrame * frame)
{ {
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret;
gint type; gint type;
const gchar *type_str = NULL; const gchar *type_str = NULL;
gboolean key_frame = FALSE; gboolean key_frame = FALSE;
const mpeg2_picture_t *picture = info->current_picture; const mpeg2_picture_t *picture = info->current_picture;
GstBuffer *buffer;
ret = gst_mpeg2dec_alloc_buffer (mpeg2dec, frame); ret = gst_mpeg2dec_alloc_buffer (mpeg2dec, frame, &buffer);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
return ret; return ret;
@ -791,12 +810,12 @@ handle_picture (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info,
key_frame ? ", kf," : " ", frame->system_frame_number); key_frame ? ", kf," : " ", frame->system_frame_number);
if (picture->flags & PIC_FLAG_TOP_FIELD_FIRST) { if (picture->flags & PIC_FLAG_TOP_FIELD_FIRST) {
GST_BUFFER_FLAG_SET (frame->output_buffer, GST_VIDEO_BUFFER_FLAG_TFF); GST_BUFFER_FLAG_SET (buffer, GST_VIDEO_BUFFER_FLAG_TFF);
} }
#if MPEG2_RELEASE >= MPEG2_VERSION(0,5,0) #if MPEG2_RELEASE >= MPEG2_VERSION(0,5,0)
/* repeat field introduced in 0.5.0 */ /* repeat field introduced in 0.5.0 */
if (picture->flags & PIC_FLAG_REPEAT_FIRST_FIELD) { if (picture->flags & PIC_FLAG_REPEAT_FIRST_FIELD) {
GST_BUFFER_FLAG_SET (frame->output_buffer, GST_VIDEO_BUFFER_FLAG_RFF); GST_BUFFER_FLAG_SET (buffer, GST_VIDEO_BUFFER_FLAG_RFF);
} }
#endif #endif
@ -818,7 +837,7 @@ handle_picture (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info,
(picture->flags & PIC_FLAG_COMPOSITE_DISPLAY ? "composite" : " "), (picture->flags & PIC_FLAG_COMPOSITE_DISPLAY ? "composite" : " "),
picture->nb_fields, GST_TIME_ARGS (frame->pts)); picture->nb_fields, GST_TIME_ARGS (frame->pts));
return GST_FLOW_OK; return ret;
} }
static GstFlowReturn static GstFlowReturn