summaryrefslogtreecommitdiffstats
path: root/audio/decode/dec_audio.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio/decode/dec_audio.c')
-rw-r--r--audio/decode/dec_audio.c36
1 files changed, 3 insertions, 33 deletions
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c
index c2272c5242..e60ebe370f 100644
--- a/audio/decode/dec_audio.c
+++ b/audio/decode/dec_audio.c
@@ -195,38 +195,6 @@ static void fix_audio_pts(struct dec_audio *da)
da->pts += da->current_frame->samples / (double)da->current_frame->rate;
}
-static bool clip_frame(struct mp_audio *f, double start, double end)
-{
- if (f->pts == MP_NOPTS_VALUE)
- return false;
- double f_end = f->pts + f->samples / (double)f->rate;
- bool ended = false;
- if (end != MP_NOPTS_VALUE) {
- if (f_end >= end) {
- if (f->pts >= end) {
- f->samples = 0;
- ended = true;
- } else {
- int new = (end - f->pts) * f->rate;
- f->samples = MPCLAMP(new, 0, f->samples);
- }
- }
- }
- if (start != MP_NOPTS_VALUE) {
- if (f->pts < start) {
- if (f_end <= start) {
- f->samples = 0;
- } else {
- int skip = (start - f->pts) * f->rate;
- skip = MPCLAMP(skip, 0, f->samples);
- mp_audio_skip_samples(f, skip);
- f->pts += skip / (double)f->rate;
- }
- }
- }
- return ended;
-}
-
void audio_work(struct dec_audio *da)
{
if (da->current_frame)
@@ -268,7 +236,9 @@ void audio_work(struct dec_audio *da)
bool segment_end = true;
if (da->current_frame) {
- segment_end = clip_frame(da->current_frame, da->start, da->end);
+ mp_audio_clip_timestamps(da->current_frame, da->start, da->end);
+ if (da->current_frame->pts != MP_NOPTS_VALUE && da->start != MP_NOPTS_VALUE)
+ segment_end = da->current_frame->pts >= da->start;
if (da->current_frame->samples == 0) {
talloc_free(da->current_frame);
da->current_frame = NULL;