mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 17:50:36 +00:00
vorbisenc: Relax overly-tight jitter tolerances in gstvobisenc
vorbisenc currently reacts in a rater draconian fashion if input timestamps are more than 1/2 sample off what it considers ideal. If data is 'too late' it truncates buffers, if it is 'too soon' it completely shuts down encode and restarts it. This is causingvorbisenc to produce corrupt output when encoding data produced by sources with bugs that produce a smple or two of jitter (eg, flacdec)
This commit is contained in:
parent
7d3858a14d
commit
9cbe7c1403
1 changed files with 26 additions and 18 deletions
|
@ -1012,12 +1012,12 @@ gst_vorbis_enc_buffer_check_discontinuous (GstVorbisEnc * vorbisenc,
|
||||||
vorbisenc->expected_ts != GST_CLOCK_TIME_NONE &&
|
vorbisenc->expected_ts != GST_CLOCK_TIME_NONE &&
|
||||||
timestamp + duration != vorbisenc->expected_ts) {
|
timestamp + duration != vorbisenc->expected_ts) {
|
||||||
/* It turns out that a lot of elements don't generate perfect streams due
|
/* It turns out that a lot of elements don't generate perfect streams due
|
||||||
* to rounding errors. So, we permit small errors (< 1/2 a sample) without
|
* to rounding errors. So, we permit small errors (< 3 samples) without
|
||||||
* causing a discont.
|
* causing a discont.
|
||||||
*/
|
*/
|
||||||
int halfsample = GST_SECOND / vorbisenc->frequency / 2;
|
int threesample = GST_SECOND / vorbisenc->frequency * 3;
|
||||||
|
|
||||||
if ((GstClockTimeDiff) (timestamp - vorbisenc->expected_ts) > halfsample) {
|
if ((GstClockTimeDiff) (timestamp - vorbisenc->expected_ts) > threesample) {
|
||||||
GST_DEBUG_OBJECT (vorbisenc, "Expected TS %" GST_TIME_FORMAT
|
GST_DEBUG_OBJECT (vorbisenc, "Expected TS %" GST_TIME_FORMAT
|
||||||
", buffer TS %" GST_TIME_FORMAT,
|
", buffer TS %" GST_TIME_FORMAT,
|
||||||
GST_TIME_ARGS (vorbisenc->expected_ts), GST_TIME_ARGS (timestamp));
|
GST_TIME_ARGS (vorbisenc->expected_ts), GST_TIME_ARGS (timestamp));
|
||||||
|
@ -1135,9 +1135,14 @@ gst_vorbis_enc_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
|
|
||||||
if (vorbisenc->expected_ts != GST_CLOCK_TIME_NONE &&
|
if (vorbisenc->expected_ts != GST_CLOCK_TIME_NONE &&
|
||||||
timestamp < vorbisenc->expected_ts) {
|
timestamp < vorbisenc->expected_ts) {
|
||||||
|
int threesample = GST_SECOND / vorbisenc->frequency * 3;
|
||||||
guint64 diff = vorbisenc->expected_ts - timestamp;
|
guint64 diff = vorbisenc->expected_ts - timestamp;
|
||||||
guint64 diff_bytes;
|
guint64 diff_bytes;
|
||||||
|
|
||||||
|
/* Don't freak out on tiny jitters; use the same < 3 sample
|
||||||
|
tolerance as in the discontinuous detection */
|
||||||
|
if ((GstClockTimeDiff) (vorbisenc->expected_ts - timestamp) > threesample) {
|
||||||
|
|
||||||
GST_WARNING_OBJECT (vorbisenc, "Buffer is older than previous "
|
GST_WARNING_OBJECT (vorbisenc, "Buffer is older than previous "
|
||||||
"timestamp + duration (%" GST_TIME_FORMAT "< %" GST_TIME_FORMAT
|
"timestamp + duration (%" GST_TIME_FORMAT "< %" GST_TIME_FORMAT
|
||||||
"), cannot handle. Clipping buffer.",
|
"), cannot handle. Clipping buffer.",
|
||||||
|
@ -1154,11 +1159,14 @@ gst_vorbis_enc_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
GST_BUFFER_DATA (buffer) += diff_bytes;
|
GST_BUFFER_DATA (buffer) += diff_bytes;
|
||||||
GST_BUFFER_SIZE (buffer) -= diff_bytes;
|
GST_BUFFER_SIZE (buffer) -= diff_bytes;
|
||||||
|
|
||||||
GST_BUFFER_TIMESTAMP (buffer) += diff;
|
|
||||||
if (GST_BUFFER_DURATION_IS_VALID (buffer))
|
if (GST_BUFFER_DURATION_IS_VALID (buffer))
|
||||||
GST_BUFFER_DURATION (buffer) -= diff;
|
GST_BUFFER_DURATION (buffer) -= diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* adjust the input timestamp in either case */
|
||||||
|
GST_BUFFER_TIMESTAMP (buffer) += diff;
|
||||||
|
}
|
||||||
|
|
||||||
if (gst_vorbis_enc_buffer_check_discontinuous (vorbisenc, timestamp,
|
if (gst_vorbis_enc_buffer_check_discontinuous (vorbisenc, timestamp,
|
||||||
GST_BUFFER_DURATION (buffer)) && !first) {
|
GST_BUFFER_DURATION (buffer)) && !first) {
|
||||||
GST_WARNING_OBJECT (vorbisenc,
|
GST_WARNING_OBJECT (vorbisenc,
|
||||||
|
|
Loading…
Reference in a new issue