File: 0004-ip-ffmpeg-skip-samples-only-when-needed.patch

package info (click to toggle)
cmus 2.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,404 kB
  • sloc: ansic: 40,498; sh: 1,642; makefile: 255; python: 157
file content (53 lines) | stat: -rw-r--r-- 2,215 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
From: ihy123 <aladinandreyy@gmail.com>
Date: Fri, 15 Aug 2025 21:42:19 +0300
Subject: ip/ffmpeg: skip samples only when needed

---
 ip/ffmpeg.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/ip/ffmpeg.c b/ip/ffmpeg.c
index ecbf005..5f5a4f3 100644
--- a/ip/ffmpeg.c
+++ b/ip/ffmpeg.c
@@ -393,22 +393,26 @@ static int ffmpeg_fill_buffer(struct input_plugin_data *ip_data, AVFormatContext
 				frame_ts = av_rescale_q(frame_ts, st->time_base, AV_TIME_BASE_Q);
 			else
 				frame_ts = input->prev_frame_end;
-			int64_t frame_dur = av_rescale(frame->nb_samples, AV_TIME_BASE, sf_get_rate(ip_data->sf));
-			int64_t frame_end = frame_ts + frame_dur;
-			input->prev_frame_end = frame_end;
-			d_print("seek_ts: %ld, frame_ts: %ld, frame_end: %ld\n", input->seek_ts, frame_ts, frame_end);
-			if (frame_end <= input->seek_ts)
-				continue;
 
-			/* skip part of this frame */
-			int64_t skip_samples = av_rescale(input->seek_ts - frame_ts, sf_get_rate(ip_data->sf), AV_TIME_BASE);
-			in_count -= skip_samples;
-			if (av_sample_fmt_is_planar(frame->format)) {
-				for (int i = 0; i < cc->channels; i++) {
-					in[i] += skip_samples * sf_get_sample_size(ip_data->sf);
+			if (frame_ts < input->seek_ts) {
+				int64_t frame_dur = av_rescale(frame->nb_samples, AV_TIME_BASE, sf_get_rate(ip_data->sf));
+				int64_t frame_end = frame_ts + frame_dur;
+				input->prev_frame_end = frame_end;
+				d_print("seek_ts: %ld, frame_ts: %ld, frame_end: %ld\n", input->seek_ts, frame_ts, frame_end);
+				if (frame_end <= input->seek_ts)
+					continue;
+
+				/* skip part of this frame */
+				int64_t skip_samples = av_rescale(input->seek_ts - frame_ts, sf_get_rate(ip_data->sf), AV_TIME_BASE);
+				in_count -= skip_samples;
+				if (av_sample_fmt_is_planar(frame->format)) {
+					for (int i = 0; i < cc->channels; i++) {
+						in[i] += skip_samples * sf_get_sample_size(ip_data->sf);
+					}
+				} else {
+					*in += skip_samples * cc->channels * sf_get_sample_size(ip_data->sf);
 				}
-			} else {
-				*in += skip_samples * cc->channels * sf_get_sample_size(ip_data->sf);
+				d_print("skipping %ld samples\n", skip_samples);
 			}
 
 			input->seek_ts = -1;