ext/mpeg2dec/gstmpeg2dec.c: Forward GstFlowReturn about everywhere.

Original commit message from CVS:
* ext/mpeg2dec/gstmpeg2dec.c: (gst_mpeg2dec_reset),
(gst_mpeg2dec_alloc_buffer), (gst_mpeg2dec_negotiate_format),
(handle_sequence), (handle_picture), (handle_slice),
(gst_mpeg2dec_chain), (gst_mpeg2dec_src_query), (normal_seek),
(gst_mpeg2dec_src_event), (gst_mpeg2dec_change_state):
Forward GstFlowReturn about everywhere.
Handle seeking correctly.
This commit is contained in:
Wim Taymans 2005-10-27 21:50:11 +00:00
parent 65d9a9f173
commit badeda5a53
2 changed files with 90 additions and 60 deletions

View file

@ -1,3 +1,13 @@
2005-10-27 Wim Taymans <wim@fluendo.com>
* ext/mpeg2dec/gstmpeg2dec.c: (gst_mpeg2dec_reset),
(gst_mpeg2dec_alloc_buffer), (gst_mpeg2dec_negotiate_format),
(handle_sequence), (handle_picture), (handle_slice),
(gst_mpeg2dec_chain), (gst_mpeg2dec_src_query), (normal_seek),
(gst_mpeg2dec_src_event), (gst_mpeg2dec_change_state):
Forward GstFlowReturn about everywhere.
Handle seeking correctly.
2005-10-27 Wim Taymans <wim@fluendo.com> 2005-10-27 Wim Taymans <wim@fluendo.com>
* ext/mpeg2dec/gstmpeg2dec.c: (gst_mpeg2dec_negotiate_format), * ext/mpeg2dec/gstmpeg2dec.c: (gst_mpeg2dec_negotiate_format),

View file

@ -318,6 +318,7 @@ gst_mpeg2dec_reset (GstMpeg2dec * mpeg2dec)
mpeg2dec->need_sequence = TRUE; mpeg2dec->need_sequence = TRUE;
mpeg2dec->next_time = 0; mpeg2dec->next_time = 0;
mpeg2dec->offset = 0; mpeg2dec->offset = 0;
mpeg2_reset (mpeg2dec->decoder, 1);
} }
static void static void
@ -408,8 +409,9 @@ crop_buffer (GstMpeg2dec * mpeg2dec, GstBuffer * input)
return outbuf; return outbuf;
} }
static GstBuffer * static GstFlowReturn
gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset) gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset,
GstBuffer ** obuf)
{ {
GstBuffer *outbuf = NULL; GstBuffer *outbuf = NULL;
gint size = mpeg2dec->decoded_width * mpeg2dec->decoded_height; gint size = mpeg2dec->decoded_width * mpeg2dec->decoded_height;
@ -420,11 +422,9 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset)
ret = ret =
gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE, gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE,
size * 2, GST_PAD_CAPS (mpeg2dec->srcpad), &outbuf); size * 2, GST_PAD_CAPS (mpeg2dec->srcpad), &outbuf);
if (ret != GST_FLOW_OK) { if (ret != GST_FLOW_OK)
GST_ELEMENT_ERROR (mpeg2dec, RESOURCE, FAILED, (NULL), goto no_buffer;
("Failed to allocate memory for buffer"));
goto done;
}
out = GST_BUFFER_DATA (outbuf); out = GST_BUFFER_DATA (outbuf);
buf[0] = out; buf[0] = out;
@ -435,11 +435,8 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset)
ret = ret =
gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE, gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE,
(size * 3) / 2, GST_PAD_CAPS (mpeg2dec->srcpad), &outbuf); (size * 3) / 2, GST_PAD_CAPS (mpeg2dec->srcpad), &outbuf);
if (ret != GST_FLOW_OK) { if (ret != GST_FLOW_OK)
GST_ELEMENT_ERROR (mpeg2dec, RESOURCE, FAILED, (NULL), goto no_buffer;
("Failed to allocate memory for buffer"));
goto done;
}
out = GST_BUFFER_DATA (outbuf); out = GST_BUFFER_DATA (outbuf);
@ -467,8 +464,20 @@ done:
above it happens only when gst_pad_alloc_buffer above it happens only when gst_pad_alloc_buffer
fails to alloc outbf */ fails to alloc outbf */
} }
*obuf = outbuf;
return outbuf; return ret;
/* ERRORS */
no_buffer:
{
if (GST_FLOW_IS_FATAL (ret)) {
GST_ELEMENT_ERROR (mpeg2dec, RESOURCE, FAILED, (NULL),
("Failed to allocate memory for buffer, reason %s",
gst_flow_get_name (ret)));
}
goto done;
}
} }
static gboolean static gboolean
@ -509,11 +518,12 @@ gst_mpeg2dec_negotiate_format (GstMpeg2dec * mpeg2dec)
return TRUE; return TRUE;
} }
static gboolean static GstFlowReturn
handle_sequence (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info) handle_sequence (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
{ {
gint i; gint i;
GstBuffer *buf; GstBuffer *buf;
GstFlowReturn ret;
mpeg2dec->width = info->sequence->picture_width; mpeg2dec->width = info->sequence->picture_width;
mpeg2dec->height = info->sequence->picture_height; mpeg2dec->height = info->sequence->picture_height;
@ -546,28 +556,32 @@ handle_sequence (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
mpeg2_custom_fbuf (mpeg2dec->decoder, 1); mpeg2_custom_fbuf (mpeg2dec->decoder, 1);
if (!(buf = gst_mpeg2dec_alloc_buffer (mpeg2dec, mpeg2dec->offset))) ret = gst_mpeg2dec_alloc_buffer (mpeg2dec, mpeg2dec->offset, &buf);
return FALSE; if (ret != GST_FLOW_OK)
goto done;
/* libmpeg2 discards first buffer twice for some reason. */ /* libmpeg2 discards first buffer twice for some reason. */
gst_buffer_ref (buf); gst_buffer_ref (buf);
mpeg2dec->need_sequence = FALSE; mpeg2dec->need_sequence = FALSE;
return TRUE; done:
return ret;
negotiate_failed: negotiate_failed:
{ {
GST_ELEMENT_ERROR (mpeg2dec, CORE, NEGOTIATION, (NULL), (NULL)); GST_ELEMENT_ERROR (mpeg2dec, CORE, NEGOTIATION, (NULL), (NULL));
return FALSE; ret = GST_FLOW_NOT_NEGOTIATED;
goto done;
} }
} }
static gboolean static GstFlowReturn
handle_picture (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info) handle_picture (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
{ {
gboolean key_frame = FALSE; gboolean key_frame = FALSE;
GstBuffer *outbuf; GstBuffer *outbuf;
GstFlowReturn ret;
GST_DEBUG_OBJECT (mpeg2dec, "handle picture"); GST_DEBUG_OBJECT (mpeg2dec, "handle picture");
@ -576,9 +590,9 @@ handle_picture (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
(info->current_picture->flags & PIC_MASK_CODING_TYPE) == (info->current_picture->flags & PIC_MASK_CODING_TYPE) ==
PIC_FLAG_CODING_TYPE_I; PIC_FLAG_CODING_TYPE_I;
} }
outbuf = gst_mpeg2dec_alloc_buffer (mpeg2dec, mpeg2dec->offset); ret = gst_mpeg2dec_alloc_buffer (mpeg2dec, mpeg2dec->offset, &outbuf);
if (!outbuf) if (ret != GST_FLOW_OK)
return FALSE; goto done;
GST_DEBUG_OBJECT (mpeg2dec, "picture %s, outbuf %p, offset %" GST_DEBUG_OBJECT (mpeg2dec, "picture %s, outbuf %p, offset %"
G_GINT64_FORMAT, G_GINT64_FORMAT,
@ -590,13 +604,15 @@ handle_picture (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
mpeg2_skip (mpeg2dec->decoder, 0); mpeg2_skip (mpeg2dec->decoder, 0);
return TRUE; done:
return ret;
} }
static gboolean static GstFlowReturn
handle_slice (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info) handle_slice (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
{ {
GstBuffer *outbuf = NULL; GstBuffer *outbuf = NULL;
GstFlowReturn ret = GST_FLOW_OK;
GST_DEBUG_OBJECT (mpeg2dec, "picture slice/end %p %p %p %p", GST_DEBUG_OBJECT (mpeg2dec, "picture slice/end %p %p %p %p",
info->display_fbuf, info->display_fbuf,
@ -694,7 +710,7 @@ handle_slice (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
outbuf = crop_buffer (mpeg2dec, outbuf); outbuf = crop_buffer (mpeg2dec, outbuf);
gst_buffer_ref (outbuf); gst_buffer_ref (outbuf);
gst_pad_push (mpeg2dec->srcpad, outbuf); ret = gst_pad_push (mpeg2dec->srcpad, outbuf);
} }
} }
@ -704,7 +720,7 @@ handle_slice (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
gst_buffer_unref (discard); gst_buffer_unref (discard);
GST_DEBUG_OBJECT (mpeg2dec, "Discarded buffer %p", discard); GST_DEBUG_OBJECT (mpeg2dec, "Discarded buffer %p", discard);
} }
return TRUE; return ret;
} }
#if 0 #if 0
@ -747,6 +763,7 @@ gst_mpeg2dec_chain (GstPad * pad, GstBuffer * buf)
const mpeg2_info_t *info; const mpeg2_info_t *info;
mpeg2_state_t state; mpeg2_state_t state;
gboolean done = FALSE; gboolean done = FALSE;
GstFlowReturn ret = GST_FLOW_OK;
mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
@ -771,7 +788,7 @@ gst_mpeg2dec_chain (GstPad * pad, GstBuffer * buf)
switch (state) { switch (state) {
case STATE_SEQUENCE: case STATE_SEQUENCE:
handle_sequence (mpeg2dec, info); ret = handle_sequence (mpeg2dec, info);
break; break;
case STATE_SEQUENCE_REPEATED: case STATE_SEQUENCE_REPEATED:
GST_DEBUG_OBJECT (mpeg2dec, "sequence repeated"); GST_DEBUG_OBJECT (mpeg2dec, "sequence repeated");
@ -779,7 +796,7 @@ gst_mpeg2dec_chain (GstPad * pad, GstBuffer * buf)
case STATE_GOP: case STATE_GOP:
break; break;
case STATE_PICTURE: case STATE_PICTURE:
handle_picture (mpeg2dec, info); ret = handle_picture (mpeg2dec, info);
break; break;
case STATE_SLICE_1ST: case STATE_SLICE_1ST:
GST_LOG_OBJECT (mpeg2dec, "1st slice of frame encountered"); GST_LOG_OBJECT (mpeg2dec, "1st slice of frame encountered");
@ -794,7 +811,7 @@ gst_mpeg2dec_chain (GstPad * pad, GstBuffer * buf)
case STATE_END: case STATE_END:
mpeg2dec->need_sequence = TRUE; mpeg2dec->need_sequence = TRUE;
case STATE_SLICE: case STATE_SLICE:
handle_slice (mpeg2dec, info); ret = handle_slice (mpeg2dec, info);
break; break;
case STATE_BUFFER: case STATE_BUFFER:
if (data == NULL) { if (data == NULL) {
@ -846,9 +863,13 @@ gst_mpeg2dec_chain (GstPad * pad, GstBuffer * buf)
} }
#endif #endif
if (ret != GST_FLOW_OK) {
mpeg2_reset (mpeg2dec->decoder, 0);
break;
}
} }
gst_buffer_unref (buf); gst_buffer_unref (buf);
return GST_FLOW_OK; return ret;
exit: exit:
gst_buffer_unref (buf); gst_buffer_unref (buf);
@ -1216,7 +1237,6 @@ index_seek (GstPad * pad, GstEvent * event)
static gboolean static gboolean
normal_seek (GstPad * pad, GstEvent * event) normal_seek (GstPad * pad, GstEvent * event)
{ {
guint flush;
gdouble rate; gdouble rate;
GstFormat format, conv; GstFormat format, conv;
GstSeekFlags flags; GstSeekFlags flags;
@ -1224,39 +1244,34 @@ normal_seek (GstPad * pad, GstEvent * event)
gint64 cur, stop; gint64 cur, stop;
gint64 time_cur, bytes_cur; gint64 time_cur, bytes_cur;
gint64 time_stop, bytes_stop; gint64 time_stop, bytes_stop;
gboolean res;
GstMpeg2dec *mpeg2dec; GstMpeg2dec *mpeg2dec;
GstEvent *peer_event;
mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
/* const GstFormat *peer_formats; */
gboolean res;
GST_DEBUG ("normal seek"); GST_DEBUG ("normal seek");
gst_event_parse_seek (event, &rate, &format, &flags, gst_event_parse_seek (event, &rate, &format, &flags,
&cur_type, &cur, &stop_type, &stop); &cur_type, &cur, &stop_type, &stop);
conv = GST_FORMAT_TIME; conv = GST_FORMAT_TIME;
if (format != GST_FORMAT_TIME) { if (!gst_mpeg2dec_src_convert (pad, format, cur, &conv, &time_cur))
if (!gst_mpeg2dec_src_convert (pad, format, cur, &conv, &time_cur)) goto convert_failed;
goto convert_failed; if (!gst_mpeg2dec_src_convert (pad, format, stop, &conv, &time_stop))
if (!gst_mpeg2dec_src_convert (pad, format, stop, &conv, &time_stop)) goto convert_failed;
goto convert_failed;
} else {
time_cur = cur;
time_stop = stop;
}
GST_DEBUG ("seek to time %" GST_TIME_FORMAT "-%" GST_TIME_FORMAT, GST_DEBUG ("seek to time %" GST_TIME_FORMAT "-%" GST_TIME_FORMAT,
GST_TIME_ARGS (time_cur), GST_TIME_ARGS (time_stop)); GST_TIME_ARGS (time_cur), GST_TIME_ARGS (time_stop));
/* shave off the flush flag, we'll need it later */ peer_event = gst_event_new_seek (rate, GST_FORMAT_TIME, flags,
flush = flags & GST_SEEK_FLAG_FLUSH; cur_type, time_cur, stop_type, time_stop);
/* assume the worst */ /* try seek on time then */
res = FALSE; if ((res = gst_pad_push_event (mpeg2dec->sinkpad, peer_event)))
goto done;
/* else we try to seek on bytes */
conv = GST_FORMAT_BYTES; conv = GST_FORMAT_BYTES;
if (!gst_mpeg2dec_sink_convert (pad, GST_FORMAT_TIME, time_cur, if (!gst_mpeg2dec_sink_convert (pad, GST_FORMAT_TIME, time_cur,
&format, &bytes_cur)) &format, &bytes_cur))
@ -1265,25 +1280,23 @@ normal_seek (GstPad * pad, GstEvent * event)
&format, &bytes_stop)) &format, &bytes_stop))
goto convert_failed; goto convert_failed;
/* conversion succeeded, create the seek */
peer_event =
gst_event_new_seek (rate, GST_FORMAT_BYTES, flags,
cur_type, bytes_cur, stop_type, bytes_stop);
{ /* do the seek */
GstEvent *seek_event; res = gst_pad_push_event (mpeg2dec->sinkpad, peer_event);
/* conversion succeeded, create the seek */ done:
seek_event =
gst_event_new_seek (rate, GST_FORMAT_BYTES, flags,
cur_type, bytes_cur, stop_type, bytes_stop);
/* do the seek */
res = gst_pad_push_event (mpeg2dec->sinkpad, seek_event);
}
return res; return res;
/* ERRORS */ /* ERRORS */
convert_failed: convert_failed:
{ {
/* probably unsupported seek format */ /* probably unsupported seek format */
GST_DEBUG ("failed to convert format %u into GST_FORMAT_TIME", format); GST_DEBUG_OBJECT (mpeg2dec,
"failed to convert format %u into GST_FORMAT_TIME", format);
return FALSE; return FALSE;
} }
} }
@ -1298,7 +1311,7 @@ gst_mpeg2dec_src_event (GstPad * pad, GstEvent * event)
mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
if (mpeg2dec->decoder == NULL) if (mpeg2dec->decoder == NULL)
return FALSE; goto no_decoder;
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
/* the all-formats seek logic */ /* the all-formats seek logic */
@ -1317,6 +1330,13 @@ gst_mpeg2dec_src_event (GstPad * pad, GstEvent * event)
break; break;
} }
return res; return res;
no_decoder:
{
GST_DEBUG_OBJECT (mpeg2dec, "no decoder, cannot handle event");
gst_event_unref (event);
return FALSE;
}
} }
static GstStateChangeReturn static GstStateChangeReturn