vorbisdec: detect and report errors better
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 22 May 2009 15:41:50 +0000 (17:41 +0200)
committerWim Taymans <wim@metal.(none)>
Fri, 22 May 2009 15:41:50 +0000 (17:41 +0200)
Check the return values of a couple more libvorbis functions and post an error
when something is wrong instead of continuing and crashing.

ext/vorbis/vorbisdec.c

index 6b3f725..1885be0 100644 (file)
@@ -761,11 +761,16 @@ static GstFlowReturn
 vorbis_handle_type_packet (GstVorbisDec * vd)
 {
   GList *walk;
+  gint res;
 
   g_assert (vd->initialized == FALSE);
 
-  vorbis_synthesis_init (&vd->vd, &vd->vi);
-  vorbis_block_init (&vd->vd, &vd->vb);
+  if (G_UNLIKELY ((res = vorbis_synthesis_init (&vd->vd, &vd->vi))))
+    goto synthesis_init_error;
+
+  if (G_UNLIKELY ((res = vorbis_block_init (&vd->vd, &vd->vb))))
+    goto block_init_error;
+
   vd->initialized = TRUE;
 
   if (vd->pendingevents) {
@@ -780,21 +785,35 @@ vorbis_handle_type_packet (GstVorbisDec * vd)
     gst_pad_push_event (vd->srcpad, gst_event_new_tag (vd->taglist));
     vd->taglist = NULL;
   }
-
   return GST_FLOW_OK;
+
+  /* ERRORS */
+synthesis_init_error:
+  {
+    GST_ELEMENT_ERROR (GST_ELEMENT (vd), STREAM, DECODE,
+        (NULL), ("couldn't initialize synthesis (%d)", res));
+    return GST_FLOW_ERROR;
+  }
+block_init_error:
+  {
+    GST_ELEMENT_ERROR (GST_ELEMENT (vd), STREAM, DECODE,
+        (NULL), ("couldn't initialize block (%d)", res));
+    return GST_FLOW_ERROR;
+  }
 }
 
 static GstFlowReturn
 vorbis_handle_header_packet (GstVorbisDec * vd, ogg_packet * packet)
 {
   GstFlowReturn res;
+  gint ret;
 
   GST_DEBUG_OBJECT (vd, "parsing header packet");
 
   /* Packetno = 0 if the first byte is exactly 0x01 */
   packet->b_o_s = (packet->packet[0] == 0x1) ? 1 : 0;
 
-  if (vorbis_synthesis_headerin (&vd->vi, &vd->vc, packet))
+  if ((ret = vorbis_synthesis_headerin (&vd->vi, &vd->vc, packet)))
     goto header_read_error;
 
   switch (packet->packet[0]) {
@@ -819,7 +838,7 @@ vorbis_handle_header_packet (GstVorbisDec * vd, ogg_packet * packet)
 header_read_error:
   {
     GST_ELEMENT_ERROR (GST_ELEMENT (vd), STREAM, DECODE,
-        (NULL), ("couldn't read header packet"));
+        (NULL), ("couldn't read header packet (%d)", ret));
     return GST_FLOW_ERROR;
   }
 }