basevideo: Add function to allocate src buffer

This commit is contained in:
David Schleef 2011-03-26 17:43:54 -07:00
parent 12f539c6bb
commit 83d6a5099b
3 changed files with 35 additions and 19 deletions

View file

@ -571,28 +571,18 @@ gst_schro_dec_process (GstSchroDec * schro_dec, gboolean eos)
GstBuffer *outbuf; GstBuffer *outbuf;
GstVideoState *state; GstVideoState *state;
SchroFrame *schro_frame; SchroFrame *schro_frame;
GstFlowReturn flow_ret;
int size;
GST_DEBUG ("need frame"); GST_DEBUG ("need frame");
state = state =
gst_base_video_decoder_get_state (GST_BASE_VIDEO_DECODER gst_base_video_decoder_get_state (GST_BASE_VIDEO_DECODER
(schro_dec)); (schro_dec));
size = outbuf =
gst_video_format_get_size (state->format, state->width, gst_base_video_decoder_alloc_src_buffer (GST_BASE_VIDEO_DECODER
(schro_dec));
schro_frame =
gst_schro_buffer_wrap (outbuf, state->format, state->width,
state->height); state->height);
flow_ret =
gst_pad_alloc_buffer_and_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD
(schro_dec), GST_BUFFER_OFFSET_NONE, size,
GST_PAD_CAPS (GST_BASE_VIDEO_CODEC_SRC_PAD (schro_dec)), &outbuf);
if (flow_ret != GST_FLOW_OK) {
go = FALSE;
ret = flow_ret;
break;
}
schro_frame = gst_schro_buffer_wrap (outbuf,
state->format, state->width, state->height);
schro_decoder_add_output_picture (schro_dec->decoder, schro_frame); schro_decoder_add_output_picture (schro_dec->decoder, schro_frame);
break; break;
} }
@ -642,6 +632,8 @@ gst_schro_dec_process (GstSchroDec * schro_dec, gboolean eos)
GST_DEBUG ("codec error"); GST_DEBUG ("codec error");
ret = GST_FLOW_ERROR; ret = GST_FLOW_ERROR;
break; break;
default:
break;
} }
} }
return ret; return ret;
@ -659,8 +651,6 @@ gst_schro_dec_handle_frame (GstBaseVideoDecoder * base_video_decoder,
GST_DEBUG ("handle frame"); GST_DEBUG ("handle frame");
gst_base_video_decoder_set_src_caps (base_video_decoder);
input_buffer = gst_schro_wrap_gst_buffer (frame->sink_buffer); input_buffer = gst_schro_wrap_gst_buffer (frame->sink_buffer);
frame->sink_buffer = NULL; frame->sink_buffer = NULL;
@ -680,8 +670,6 @@ gst_schro_dec_finish (GstBaseVideoDecoder * base_video_decoder)
GST_DEBUG ("finish"); GST_DEBUG ("finish");
gst_base_video_decoder_set_src_caps (base_video_decoder);
schro_decoder_autoparse_push_end_of_sequence (schro_dec->decoder); schro_decoder_autoparse_push_end_of_sequence (schro_dec->decoder);
return gst_schro_dec_process (schro_dec, TRUE); return gst_schro_dec_process (schro_dec, TRUE);

View file

@ -1468,6 +1468,32 @@ gst_base_video_decoder_set_src_caps (GstBaseVideoDecoder * base_video_decoder)
gst_caps_unref (caps); gst_caps_unref (caps);
} }
GstBuffer *
gst_base_video_decoder_alloc_src_buffer (GstBaseVideoDecoder *
base_video_decoder)
{
GstBuffer *buffer;
GstFlowReturn flow_ret;
int num_bytes;
GstVideoState *state = &GST_BASE_VIDEO_CODEC (base_video_decoder)->state;
num_bytes = gst_video_format_get_size (state->format, state->width,
state->height);
flow_ret =
gst_pad_alloc_buffer_and_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD
(base_video_decoder), GST_BUFFER_OFFSET_NONE, num_bytes,
GST_PAD_CAPS (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_decoder)),
&buffer);
if (flow_ret != GST_FLOW_OK) {
buffer = gst_buffer_new_and_alloc (num_bytes);
gst_buffer_set_caps (buffer,
GST_PAD_CAPS (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_decoder)));
}
return buffer;
}
GstFlowReturn GstFlowReturn
gst_base_video_decoder_alloc_src_frame (GstBaseVideoDecoder * gst_base_video_decoder_alloc_src_frame (GstBaseVideoDecoder *
base_video_decoder, GstVideoFrame * frame) base_video_decoder, GstVideoFrame * frame)

View file

@ -168,6 +168,8 @@ void gst_base_video_decoder_set_sync_point (GstBaseVideoDecoder *base_video_deco
void gst_base_video_decoder_set_src_caps (GstBaseVideoDecoder *base_video_decoder); void gst_base_video_decoder_set_src_caps (GstBaseVideoDecoder *base_video_decoder);
GstBuffer * gst_base_video_decoder_alloc_src_buffer (GstBaseVideoDecoder *
base_video_decoder);
GstFlowReturn gst_base_video_decoder_alloc_src_frame (GstBaseVideoDecoder *base_video_decoder, GstFlowReturn gst_base_video_decoder_alloc_src_frame (GstBaseVideoDecoder *base_video_decoder,
GstVideoFrame *frame); GstVideoFrame *frame);