summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>2009-08-11 13:56:43 +0200
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>2009-08-31 16:50:00 +0200
commit0f900afe1f2b9eaba646909f968c158bdaa93c25 (patch)
tree4211028b21f23195f1361088e34bc297e30b1ebb
parentefb5d1b5452ec34b75dc470dbec83675258142bb (diff)
wavparse: reflow exit, and fix some leaks
-rw-r--r--gst/wavparse/gstwavparse.c80
1 files changed, 46 insertions, 34 deletions
diff --git a/gst/wavparse/gstwavparse.c b/gst/wavparse/gstwavparse.c
index 23e038693..77c980cb0 100644
--- a/gst/wavparse/gstwavparse.c
+++ b/gst/wavparse/gstwavparse.c
@@ -168,6 +168,15 @@ gst_wavparse_reset (GstWavParse * wav)
168 if (wav->tags) 168 if (wav->tags)
169 gst_tag_list_free (wav->tags); 169 gst_tag_list_free (wav->tags);
170 wav->tags = NULL; 170 wav->tags = NULL;
171 if (wav->caps)
172 gst_caps_unref (wav->caps);
173 wav->caps = NULL;
174 if (wav->start_segment)
175 gst_event_unref (wav->start_segment);
176 wav->start_segment = NULL;
177 if (wav->close_segment)
178 gst_event_unref (wav->close_segment);
179 wav->close_segment = NULL;
171} 180}
172 181
173static void 182static void
@@ -1154,12 +1163,12 @@ gst_waveparse_ignore_chunk (GstWavParse * wav, GstBuffer * buf, guint32 tag,
1154static GstFlowReturn 1163static GstFlowReturn
1155gst_wavparse_stream_headers (GstWavParse * wav) 1164gst_wavparse_stream_headers (GstWavParse * wav)
1156{ 1165{
1157 GstFlowReturn res; 1166 GstFlowReturn res = GST_FLOW_OK;
1158 GstBuffer *buf; 1167 GstBuffer *buf;
1159 gst_riff_strf_auds *header = NULL; 1168 gst_riff_strf_auds *header = NULL;
1160 guint32 tag, size; 1169 guint32 tag, size;
1161 gboolean gotdata = FALSE; 1170 gboolean gotdata = FALSE;
1162 GstCaps *caps; 1171 GstCaps *caps = NULL;
1163 gchar *codec_name = NULL; 1172 gchar *codec_name = NULL;
1164 GstEvent **event_p; 1173 GstEvent **event_p;
1165 GstFormat bformat; 1174 GstFormat bformat;
@@ -1172,7 +1181,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1172 /* The header starts with a 'fmt ' tag */ 1181 /* The header starts with a 'fmt ' tag */
1173 if (wav->streaming) { 1182 if (wav->streaming) {
1174 if (!gst_wavparse_peek_chunk (wav, &tag, &size)) 1183 if (!gst_wavparse_peek_chunk (wav, &tag, &size))
1175 return GST_FLOW_OK; 1184 return res;
1176 1185
1177 gst_adapter_flush (wav->adapter, 8); 1186 gst_adapter_flush (wav->adapter, 8);
1178 wav->offset += 8; 1187 wav->offset += 8;
@@ -1314,7 +1323,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1314 while (!gotdata) { 1323 while (!gotdata) {
1315 if (wav->streaming) { 1324 if (wav->streaming) {
1316 if (!gst_wavparse_peek_chunk_info (wav, &tag, &size)) 1325 if (!gst_wavparse_peek_chunk_info (wav, &tag, &size))
1317 return GST_FLOW_OK; 1326 goto exit;
1318 } else { 1327 } else {
1319 if ((res = 1328 if ((res =
1320 gst_pad_pull_range (wav->sinkpad, wav->offset, 8, 1329 gst_pad_pull_range (wav->sinkpad, wav->offset, 8,
@@ -1365,7 +1374,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1365 if (size < data_size) { 1374 if (size < data_size) {
1366 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size)) { 1375 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size)) {
1367 /* need more data */ 1376 /* need more data */
1368 return GST_FLOW_OK; 1377 goto exit;
1369 } 1378 }
1370 GST_DEBUG_OBJECT (wav, "need %d, available %d; ignoring chunk", 1379 GST_DEBUG_OBJECT (wav, "need %d, available %d; ignoring chunk",
1371 data_size, size); 1380 data_size, size);
@@ -1376,7 +1385,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1376 const guint8 *data = NULL; 1385 const guint8 *data = NULL;
1377 1386
1378 if (!gst_wavparse_peek_chunk (wav, &tag, &size)) { 1387 if (!gst_wavparse_peek_chunk (wav, &tag, &size)) {
1379 return GST_FLOW_OK; 1388 goto exit;
1380 } 1389 }
1381 gst_adapter_flush (wav->adapter, 8); 1390 gst_adapter_flush (wav->adapter, 8);
1382 data = gst_adapter_peek (wav->adapter, data_size); 1391 data = gst_adapter_peek (wav->adapter, data_size);
@@ -1397,7 +1406,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1397 } else { 1406 } else {
1398 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size)) { 1407 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size)) {
1399 /* need more data */ 1408 /* need more data */
1400 return GST_FLOW_OK; 1409 goto exit;
1401 } 1410 }
1402 } 1411 }
1403 break; 1412 break;
@@ -1410,7 +1419,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1410 if (size < data_size) { 1419 if (size < data_size) {
1411 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size)) { 1420 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size)) {
1412 /* need more data */ 1421 /* need more data */
1413 return GST_FLOW_OK; 1422 goto exit;
1414 } 1423 }
1415 GST_DEBUG_OBJECT (wav, "need %d, available %d; ignoring chunk", 1424 GST_DEBUG_OBJECT (wav, "need %d, available %d; ignoring chunk",
1416 data_size, size); 1425 data_size, size);
@@ -1418,7 +1427,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1418 } 1427 }
1419 if (wav->streaming) { 1428 if (wav->streaming) {
1420 if (!gst_wavparse_peek_chunk (wav, &tag, &size)) { 1429 if (!gst_wavparse_peek_chunk (wav, &tag, &size)) {
1421 return GST_FLOW_OK; 1430 goto exit;
1422 } 1431 }
1423 gst_adapter_flush (wav->adapter, 8); 1432 gst_adapter_flush (wav->adapter, 8);
1424 acid = (const gst_riff_acid *) gst_adapter_peek (wav->adapter, 1433 acid = (const gst_riff_acid *) gst_adapter_peek (wav->adapter,
@@ -1454,7 +1463,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1454 const guint8 *data = NULL; 1463 const guint8 *data = NULL;
1455 1464
1456 if (gst_adapter_available (wav->adapter) < 12) { 1465 if (gst_adapter_available (wav->adapter) < 12) {
1457 return GST_FLOW_OK; 1466 goto exit;
1458 } 1467 }
1459 data = gst_adapter_peek (wav->adapter, 12); 1468 data = gst_adapter_peek (wav->adapter, 12);
1460 ltag = GST_READ_UINT32_LE (data + 8); 1469 ltag = GST_READ_UINT32_LE (data + 8);
@@ -1474,7 +1483,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1474 GST_INFO_OBJECT (wav, "Have LIST chunk INFO size %u", data_size); 1483 GST_INFO_OBJECT (wav, "Have LIST chunk INFO size %u", data_size);
1475 if (wav->streaming) { 1484 if (wav->streaming) {
1476 if (!gst_wavparse_peek_chunk (wav, &tag, &size)) { 1485 if (!gst_wavparse_peek_chunk (wav, &tag, &size)) {
1477 return GST_FLOW_OK; 1486 goto exit;
1478 } 1487 }
1479 gst_adapter_flush (wav->adapter, 12); 1488 gst_adapter_flush (wav->adapter, 12);
1480 wav->offset += 12; 1489 wav->offset += 12;
@@ -1514,7 +1523,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1514 GST_FOURCC_ARGS (ltag)); 1523 GST_FOURCC_ARGS (ltag));
1515 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size)) 1524 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size))
1516 /* need more data */ 1525 /* need more data */
1517 return GST_FLOW_OK; 1526 goto exit;
1518 break; 1527 break;
1519 } 1528 }
1520 break; 1529 break;
@@ -1522,7 +1531,7 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1522 default: 1531 default:
1523 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size)) 1532 if (!gst_waveparse_ignore_chunk (wav, buf, tag, size))
1524 /* need more data */ 1533 /* need more data */
1525 return GST_FLOW_OK; 1534 goto exit;
1526 break; 1535 break;
1527 } 1536 }
1528 1537
@@ -1570,75 +1579,78 @@ gst_wavparse_stream_headers (GstWavParse * wav)
1570 return GST_FLOW_OK; 1579 return GST_FLOW_OK;
1571 1580
1572 /* ERROR */ 1581 /* ERROR */
1582exit:
1583 {
1584 if (codec_name)
1585 g_free (codec_name);
1586 if (header)
1587 g_free (header);
1588 if (caps)
1589 gst_caps_unref (caps);
1590 return res;
1591 }
1592fail:
1593 {
1594 res = GST_FLOW_ERROR;
1595 goto exit;
1596 }
1573invalid_wav: 1597invalid_wav:
1574 { 1598 {
1575 GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL), 1599 GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL),
1576 ("Invalid WAV header (no fmt at start): %" 1600 ("Invalid WAV header (no fmt at start): %"
1577 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (tag))); 1601 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (tag)));
1578 g_free (codec_name); 1602 goto fail;
1579 return GST_FLOW_ERROR;
1580 } 1603 }
1581parse_header_error: 1604parse_header_error:
1582 { 1605 {
1583 GST_ELEMENT_ERROR (wav, STREAM, DEMUX, (NULL), 1606 GST_ELEMENT_ERROR (wav, STREAM, DEMUX, (NULL),
1584 ("Couldn't parse audio header")); 1607 ("Couldn't parse audio header"));
1585 g_free (codec_name); 1608 goto fail;
1586 return GST_FLOW_ERROR;
1587 } 1609 }
1588no_channels: 1610no_channels:
1589 { 1611 {
1590 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL), 1612 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
1591 ("Stream claims to contain no channels - invalid data")); 1613 ("Stream claims to contain no channels - invalid data"));
1592 g_free (header); 1614 goto fail;
1593 g_free (codec_name);
1594 return GST_FLOW_ERROR;
1595 } 1615 }
1596no_rate: 1616no_rate:
1597 { 1617 {
1598 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL), 1618 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
1599 ("Stream with sample_rate == 0 - invalid data")); 1619 ("Stream with sample_rate == 0 - invalid data"));
1600 g_free (header); 1620 goto fail;
1601 g_free (codec_name);
1602 return GST_FLOW_ERROR;
1603 } 1621 }
1604invalid_blockalign: 1622invalid_blockalign:
1605 { 1623 {
1606 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL), 1624 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
1607 ("Stream claims blockalign = %u, which is more than %u - invalid data", 1625 ("Stream claims blockalign = %u, which is more than %u - invalid data",
1608 wav->blockalign, wav->channels * (guint) ceil (wav->depth / 8.0))); 1626 wav->blockalign, wav->channels * (guint) ceil (wav->depth / 8.0)));
1609 g_free (codec_name); 1627 goto fail;
1610 return GST_FLOW_ERROR;
1611 } 1628 }
1612invalid_bps: 1629invalid_bps:
1613 { 1630 {
1614 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL), 1631 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
1615 ("Stream claims av_bsp = %u, which is more than %u - invalid data", 1632 ("Stream claims av_bsp = %u, which is more than %u - invalid data",
1616 wav->av_bps, wav->blockalign * wav->rate)); 1633 wav->av_bps, wav->blockalign * wav->rate));
1617 g_free (codec_name); 1634 goto fail;
1618 return GST_FLOW_ERROR;
1619 } 1635 }
1620no_bytes_per_sample: 1636no_bytes_per_sample:
1621 { 1637 {
1622 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL), 1638 GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
1623 ("Could not caluclate bytes per sample - invalid data")); 1639 ("Could not caluclate bytes per sample - invalid data"));
1624 g_free (codec_name); 1640 goto fail;
1625 return GST_FLOW_ERROR;
1626 } 1641 }
1627unknown_format: 1642unknown_format:
1628 { 1643 {
1629 GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL), 1644 GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL),
1630 ("No caps found for format 0x%x, %d channels, %d Hz", 1645 ("No caps found for format 0x%x, %d channels, %d Hz",
1631 wav->format, wav->channels, wav->rate)); 1646 wav->format, wav->channels, wav->rate));
1632 g_free (header); 1647 goto fail;
1633 g_free (codec_name);
1634 return GST_FLOW_ERROR;
1635 } 1648 }
1636header_read_error: 1649header_read_error:
1637 { 1650 {
1638 GST_ELEMENT_ERROR (wav, STREAM, DEMUX, (NULL), 1651 GST_ELEMENT_ERROR (wav, STREAM, DEMUX, (NULL),
1639 ("Couldn't read in header %d (%s)", res, gst_flow_get_name (res))); 1652 ("Couldn't read in header %d (%s)", res, gst_flow_get_name (res)));
1640 g_free (codec_name); 1653 goto fail;
1641 return GST_FLOW_ERROR;
1642 } 1654 }
1643} 1655}
1644 1656