summaryrefslogtreecommitdiffstats
path: root/audio/decode
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-02-21 18:16:41 +0100
committerwm4 <wm4@nowhere>2016-02-21 18:16:41 +0100
commit1bb1543a88457920caa48cc96cee219cb313840b (patch)
tree95b331a9290a855995e919e67dd602f9dd7bf236 /audio/decode
parent943f76e6ce979ce1e1e7e29e4e20f8ec56682df7 (diff)
downloadmpv-1bb1543a88457920caa48cc96cee219cb313840b.tar.bz2
mpv-1bb1543a88457920caa48cc96cee219cb313840b.tar.xz
audio: move frame clipping to a generic function
Diffstat (limited to 'audio/decode')
-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;