mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
basesrc: fix startup position in the ringbuffer
When we start and we need to produce the first sample, go to the next sample that will be written into the ringbuffer instead of trying to go to sample 0. We relied on rather small ringbuffer sizes to correctly go to the current sample, which breaks whith large buffers. Fixes #600945
This commit is contained in:
parent
27034be461
commit
4f3f9a1054
1 changed files with 21 additions and 15 deletions
|
@ -699,33 +699,39 @@ gst_base_audio_src_get_offset (GstBaseAudioSrc * src)
|
|||
|
||||
/* assume we can append to the previous sample */
|
||||
sample = src->next_sample;
|
||||
/* no previous sample, try to read from position 0 */
|
||||
if (sample == -1)
|
||||
sample = 0;
|
||||
|
||||
sps = src->ringbuffer->samples_per_seg;
|
||||
segtotal = src->ringbuffer->spec.segtotal;
|
||||
|
||||
/* figure out the segment and the offset inside the segment where
|
||||
* the sample should be read from. */
|
||||
readseg = sample / sps;
|
||||
|
||||
/* get the currently processed segment */
|
||||
segdone = g_atomic_int_get (&src->ringbuffer->segdone)
|
||||
- src->ringbuffer->segbase;
|
||||
|
||||
GST_DEBUG_OBJECT (src, "reading from %d, we are at %d", readseg, segdone);
|
||||
if (sample != -1) {
|
||||
GST_DEBUG_OBJECT (src, "at sample %" G_GUINT64_FORMAT, segdone, sample);
|
||||
/* figure out the segment and the offset inside the segment where
|
||||
* the sample should be read from. */
|
||||
readseg = sample / sps;
|
||||
|
||||
/* see how far away it is from the read segment, normally segdone (where new
|
||||
* data is written in the ringbuffer) is bigger than readseg (where we are
|
||||
* reading). */
|
||||
diff = segdone - readseg;
|
||||
if (diff >= segtotal) {
|
||||
GST_DEBUG_OBJECT (src, "dropped, align to segment %d", segdone);
|
||||
/* sample would be dropped, position to next playable position */
|
||||
/* see how far away it is from the read segment, normally segdone (where new
|
||||
* data is written in the ringbuffer) is bigger than readseg (where we are
|
||||
* reading). */
|
||||
diff = segdone - readseg;
|
||||
if (diff >= segtotal) {
|
||||
GST_DEBUG_OBJECT (src, "dropped, align to segment %d", segdone);
|
||||
/* sample would be dropped, position to next playable position */
|
||||
sample = ((guint64) (segdone)) * sps;
|
||||
}
|
||||
} else {
|
||||
/* no previous sample, go to the current position */
|
||||
GST_DEBUG_OBJECT (src, "first sample, align to current %d", segdone);
|
||||
sample = ((guint64) (segdone)) * sps;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (src,
|
||||
"reading from %d, we are at %d, sample %" G_GUINT64_FORMAT, readseg,
|
||||
segdone, sample);
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue