mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
audiobuffersplit: Combine two if expressions to reduce indentation
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2780>
This commit is contained in:
parent
0cadd10474
commit
0485c354d2
1 changed files with 62 additions and 66 deletions
|
@ -540,84 +540,80 @@ gst_audio_buffer_split_handle_discont (GstAudioBufferSplit * self,
|
||||||
avail_samples, GST_SECOND, rate * self->in_segment.rate);
|
avail_samples, GST_SECOND, rate * self->in_segment.rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->gapless) {
|
if (self->gapless && self->current_offset != -1) {
|
||||||
if (self->current_offset != -1) {
|
GST_DEBUG_OBJECT (self,
|
||||||
GST_DEBUG_OBJECT (self,
|
"Got discont in gapless mode: Current running time %" GST_TIME_FORMAT
|
||||||
"Got discont in gapless mode: Current running time %" GST_TIME_FORMAT
|
", current end running time %" GST_TIME_FORMAT
|
||||||
", current end running time %" GST_TIME_FORMAT
|
", running time after discont %" GST_TIME_FORMAT,
|
||||||
", running time after discont %" GST_TIME_FORMAT,
|
GST_TIME_ARGS (current_rt),
|
||||||
GST_TIME_ARGS (current_rt),
|
GST_TIME_ARGS (current_rt_end), GST_TIME_ARGS (input_rt));
|
||||||
GST_TIME_ARGS (current_rt_end), GST_TIME_ARGS (input_rt));
|
|
||||||
|
new_offset =
|
||||||
|
gst_util_uint64_scale (current_rt - self->resync_rt,
|
||||||
|
rate * ABS (self->in_segment.rate), GST_SECOND);
|
||||||
|
if (current_rt < self->resync_rt) {
|
||||||
|
guint64 drop_samples;
|
||||||
|
|
||||||
new_offset =
|
new_offset =
|
||||||
gst_util_uint64_scale (current_rt - self->resync_rt,
|
gst_util_uint64_scale (self->resync_rt -
|
||||||
rate * ABS (self->in_segment.rate), GST_SECOND);
|
current_rt, rate * ABS (self->in_segment.rate), GST_SECOND);
|
||||||
if (current_rt < self->resync_rt) {
|
drop_samples = self->current_offset + avail_samples + new_offset;
|
||||||
guint64 drop_samples;
|
|
||||||
|
|
||||||
new_offset =
|
GST_DEBUG_OBJECT (self,
|
||||||
gst_util_uint64_scale (self->resync_rt -
|
"Dropping %" G_GUINT64_FORMAT " samples (%" GST_TIME_FORMAT ")",
|
||||||
current_rt, rate * ABS (self->in_segment.rate), GST_SECOND);
|
drop_samples, GST_TIME_ARGS (gst_util_uint64_scale (drop_samples,
|
||||||
drop_samples = self->current_offset + avail_samples + new_offset;
|
GST_SECOND, rate)));
|
||||||
|
discont = FALSE;
|
||||||
|
} else if (new_offset > self->current_offset + avail_samples) {
|
||||||
|
guint64 silence_samples =
|
||||||
|
new_offset - (self->current_offset + avail_samples);
|
||||||
|
const GstAudioFormatInfo *info = gst_audio_format_get_info (format);
|
||||||
|
GstClockTime silence_time =
|
||||||
|
gst_util_uint64_scale (silence_samples, GST_SECOND, rate);
|
||||||
|
|
||||||
|
if (silence_time > self->max_silence_time) {
|
||||||
GST_DEBUG_OBJECT (self,
|
GST_DEBUG_OBJECT (self,
|
||||||
"Dropping %" G_GUINT64_FORMAT " samples (%" GST_TIME_FORMAT ")",
|
"Not inserting %" G_GUINT64_FORMAT " samples of silence (%"
|
||||||
drop_samples, GST_TIME_ARGS (gst_util_uint64_scale (drop_samples,
|
GST_TIME_FORMAT " exceeds maximum %" GST_TIME_FORMAT ")",
|
||||||
GST_SECOND, rate)));
|
silence_samples, GST_TIME_ARGS (silence_time),
|
||||||
discont = FALSE;
|
GST_TIME_ARGS (self->max_silence_time));
|
||||||
} else if (new_offset > self->current_offset + avail_samples) {
|
} else {
|
||||||
guint64 silence_samples =
|
GST_DEBUG_OBJECT (self,
|
||||||
new_offset - (self->current_offset + avail_samples);
|
"Inserting %" G_GUINT64_FORMAT " samples of silence (%"
|
||||||
const GstAudioFormatInfo *info = gst_audio_format_get_info (format);
|
GST_TIME_FORMAT ")", silence_samples, GST_TIME_ARGS (silence_time));
|
||||||
GstClockTime silence_time =
|
|
||||||
gst_util_uint64_scale (silence_samples, GST_SECOND, rate);
|
|
||||||
|
|
||||||
if (silence_time > self->max_silence_time) {
|
/* Insert silence buffers to fill the gap in 1s chunks */
|
||||||
GST_DEBUG_OBJECT (self,
|
while (silence_samples > 0) {
|
||||||
"Not inserting %" G_GUINT64_FORMAT " samples of silence (%"
|
guint n_samples = MIN (silence_samples, rate);
|
||||||
GST_TIME_FORMAT " exceeds maximum %" GST_TIME_FORMAT ")",
|
GstBuffer *silence;
|
||||||
silence_samples, GST_TIME_ARGS (silence_time),
|
GstMapInfo map;
|
||||||
GST_TIME_ARGS (self->max_silence_time));
|
|
||||||
} else {
|
|
||||||
GST_DEBUG_OBJECT (self,
|
|
||||||
"Inserting %" G_GUINT64_FORMAT " samples of silence (%"
|
|
||||||
GST_TIME_FORMAT ")", silence_samples,
|
|
||||||
GST_TIME_ARGS (silence_time));
|
|
||||||
|
|
||||||
/* Insert silence buffers to fill the gap in 1s chunks */
|
silence = gst_buffer_new_and_alloc (n_samples * bpf);
|
||||||
while (silence_samples > 0) {
|
GST_BUFFER_FLAG_SET (silence, GST_BUFFER_FLAG_GAP);
|
||||||
guint n_samples = MIN (silence_samples, rate);
|
gst_buffer_map (silence, &map, GST_MAP_WRITE);
|
||||||
GstBuffer *silence;
|
gst_audio_format_info_fill_silence (info, map.data, map.size);
|
||||||
GstMapInfo map;
|
gst_buffer_unmap (silence, &map);
|
||||||
|
|
||||||
silence = gst_buffer_new_and_alloc (n_samples * bpf);
|
gst_adapter_push (self->adapter, silence);
|
||||||
GST_BUFFER_FLAG_SET (silence, GST_BUFFER_FLAG_GAP);
|
ret =
|
||||||
gst_buffer_map (silence, &map, GST_MAP_WRITE);
|
gst_audio_buffer_split_output (self, FALSE, rate, bpf,
|
||||||
gst_audio_format_info_fill_silence (info, map.data, map.size);
|
samples_per_buffer);
|
||||||
gst_buffer_unmap (silence, &map);
|
if (ret != GST_FLOW_OK)
|
||||||
|
return ret;
|
||||||
|
|
||||||
gst_adapter_push (self->adapter, silence);
|
silence_samples -= n_samples;
|
||||||
ret =
|
|
||||||
gst_audio_buffer_split_output (self, FALSE, rate, bpf,
|
|
||||||
samples_per_buffer);
|
|
||||||
if (ret != GST_FLOW_OK)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
silence_samples -= n_samples;
|
|
||||||
}
|
|
||||||
discont = FALSE;
|
|
||||||
}
|
}
|
||||||
} else if (new_offset < self->current_offset + avail_samples) {
|
|
||||||
guint64 drop_samples =
|
|
||||||
self->current_offset + avail_samples - new_offset;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (self,
|
|
||||||
"Dropping %" G_GUINT64_FORMAT " samples (%" GST_TIME_FORMAT ")",
|
|
||||||
drop_samples, GST_TIME_ARGS (gst_util_uint64_scale (drop_samples,
|
|
||||||
GST_SECOND, rate)));
|
|
||||||
self->drop_samples = drop_samples;
|
|
||||||
discont = FALSE;
|
discont = FALSE;
|
||||||
}
|
}
|
||||||
|
} else if (new_offset < self->current_offset + avail_samples) {
|
||||||
|
guint64 drop_samples = self->current_offset + avail_samples - new_offset;
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (self,
|
||||||
|
"Dropping %" G_GUINT64_FORMAT " samples (%" GST_TIME_FORMAT ")",
|
||||||
|
drop_samples, GST_TIME_ARGS (gst_util_uint64_scale (drop_samples,
|
||||||
|
GST_SECOND, rate)));
|
||||||
|
self->drop_samples = drop_samples;
|
||||||
|
discont = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue