flacparse: baseparse takes care of handling leftover pieces

This commit is contained in:
Mark Nauwelaerts 2009-12-18 21:04:12 +01:00 committed by Tim-Philipp Müller
parent 6f3106b603
commit 534e2d7f49

View file

@ -585,47 +585,25 @@ gst_flac_parse_get_frame_size (GstFlacParse * flacparse, GstBuffer * buffer,
need_more_data: need_more_data:
{ {
gint64 upstream_len = flacparse->upstream_length; gint max;
GstFormat fmt;
gboolean first_try = TRUE;
GST_DEBUG_OBJECT (flacparse, "Need more data"); /* not enough, if that was all available, give up on frame */
if (G_UNLIKELY (gst_base_parse_get_drain (GST_BASE_PARSE_CAST (flacparse))))
retry: goto eos;
/* otherwise, ask for some more */
fmt = GST_FORMAT_BYTES; max = flacparse->max_framesize;
if (upstream_len != -1 || if (!max)
(gst_pad_query_peer_duration (GST_BASE_PARSE_SINK_PAD (GST_BASE_PARSE max = 1 << 24;
(flacparse)), &fmt, &upstream_len) flacparse->requested_frame_size
&& fmt == GST_FORMAT_BYTES && upstream_len != -1)) { = MIN (GST_BUFFER_SIZE (buffer) + 4096, max);
flacparse->upstream_length = upstream_len; if (flacparse->requested_frame_size > GST_BUFFER_SIZE (buffer)) {
upstream_len -= GST_BUFFER_OFFSET (buffer);
if (flacparse->max_framesize
&& flacparse->max_framesize > flacparse->requested_frame_size
&& flacparse->max_framesize <= upstream_len) {
flacparse->requested_frame_size = flacparse->max_framesize;
} else if (flacparse->requested_frame_size + 4096 <= upstream_len) {
flacparse->requested_frame_size += 4096;
} else if (flacparse->requested_frame_size <= upstream_len) {
flacparse->requested_frame_size = upstream_len;
} else {
if (first_try) {
upstream_len = -1;
first_try = FALSE;
goto retry;
} else {
goto eos;
}
}
GST_DEBUG_OBJECT (flacparse, "Requesting %u bytes", GST_DEBUG_OBJECT (flacparse, "Requesting %u bytes",
flacparse->requested_frame_size); flacparse->requested_frame_size);
return flacparse->requested_frame_size; return flacparse->requested_frame_size;
} else { } else {
flacparse->requested_frame_size++; GST_DEBUG_OBJECT (flacparse, "Giving up on invalid frame (%d bytes)",
GST_DEBUG_OBJECT (flacparse, "Requesting %u bytes", GST_BUFFER_SIZE (buffer));
flacparse->requested_frame_size); return -1;
return flacparse->requested_frame_size;
} }
} }