mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
[MOVED FROM BAD 07/28] ext/x264/gstx264enc.c: Try harder not to crash when we get an EOS event but haven't set up the encoder yet (as may ha...
Original commit message from CVS: * ext/x264/gstx264enc.c: (gst_x264_enc_header_buf), (gst_x264_enc_sink_event), (gst_x264_enc_chain), (gst_x264_enc_encode_frame): Try harder not to crash when we get an EOS event but haven't set up the encoder yet (as may happen when upstream errors out with not-negotiated, for example). Also, always push the EOS event downstream.
This commit is contained in:
parent
f5e3152262
commit
9527af6c16
1 changed files with 16 additions and 13 deletions
|
@ -220,6 +220,9 @@ gst_x264_enc_header_buf (GstX264Enc * encoder)
|
||||||
guint8 *buffer, *sps;
|
guint8 *buffer, *sps;
|
||||||
gulong buffer_size;
|
gulong buffer_size;
|
||||||
|
|
||||||
|
if (G_UNLIKELY (encoder->x264enc == NULL))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* Create avcC header. */
|
/* Create avcC header. */
|
||||||
|
|
||||||
header_return = x264_encoder_headers (encoder->x264enc, &nal, &i_nal);
|
header_return = x264_encoder_headers (encoder->x264enc, &nal, &i_nal);
|
||||||
|
@ -681,25 +684,23 @@ gst_x264_enc_sink_event (GstPad * pad, GstEvent * event)
|
||||||
{
|
{
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
GstX264Enc *encoder;
|
GstX264Enc *encoder;
|
||||||
GstFlowReturn flow_ret;
|
|
||||||
int i_nal;
|
|
||||||
|
|
||||||
encoder = GST_X264_ENC (gst_pad_get_parent (pad));
|
encoder = GST_X264_ENC (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_EOS:
|
case GST_EVENT_EOS:{
|
||||||
/* send the rest NAL units */
|
GstFlowReturn flow_ret;
|
||||||
|
int i_nal;
|
||||||
|
|
||||||
|
/* first send the rest NAL units */
|
||||||
do {
|
do {
|
||||||
flow_ret = gst_x264_enc_encode_frame (encoder, NULL, &i_nal);
|
flow_ret = gst_x264_enc_encode_frame (encoder, NULL, &i_nal);
|
||||||
} while (flow_ret == GST_FLOW_OK && i_nal > 0);
|
} while (flow_ret == GST_FLOW_OK && i_nal > 0);
|
||||||
|
|
||||||
/* send EOS */
|
/* then push the EOS downstream */
|
||||||
if (flow_ret == GST_FLOW_OK) {
|
|
||||||
ret = gst_pad_push_event (encoder->srcpad, event);
|
ret = gst_pad_push_event (encoder->srcpad, event);
|
||||||
} else {
|
|
||||||
ret = FALSE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
ret = gst_pad_push_event (encoder->srcpad, event);
|
ret = gst_pad_push_event (encoder->srcpad, event);
|
||||||
break;
|
break;
|
||||||
|
@ -779,10 +780,9 @@ gst_x264_enc_chain (GstPad * pad, GstBuffer * buf)
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
not_inited:
|
not_inited:
|
||||||
{
|
{
|
||||||
GST_ELEMENT_ERROR (encoder, CORE, NEGOTIATION, (NULL),
|
GST_WARNING_OBJECT (encoder, "Got buffer before set_caps was called");
|
||||||
("Got buffer before pads were fully negotiated"));
|
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
}
|
}
|
||||||
wrong_buffer_size:
|
wrong_buffer_size:
|
||||||
{
|
{
|
||||||
|
@ -810,6 +810,9 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in,
|
||||||
GstClockTime timestamp;
|
GstClockTime timestamp;
|
||||||
GstClockTime duration;
|
GstClockTime duration;
|
||||||
|
|
||||||
|
if (G_UNLIKELY (encoder->x264enc == NULL))
|
||||||
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
|
|
||||||
encoder_return = x264_encoder_encode (encoder->x264enc,
|
encoder_return = x264_encoder_encode (encoder->x264enc,
|
||||||
&nal, i_nal, pic_in, &pic_out);
|
&nal, i_nal, pic_in, &pic_out);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue