summaryrefslogtreecommitdiffstats
path: root/demux/demux_subreader.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-07-05 16:45:12 +0200
committerwm4 <wm4@nowhere>2014-07-05 17:07:14 +0200
commite4221f318936aa970eeb1d220d8deae95fb91d98 (patch)
tree92676116524064b02b4610679322978976df3775 /demux/demux_subreader.c
parent18e6d07612030d6163bf5ca08c7e4ed472bcfc5b (diff)
downloadmpv-e4221f318936aa970eeb1d220d8deae95fb91d98.tar.bz2
mpv-e4221f318936aa970eeb1d220d8deae95fb91d98.tar.xz
demux: move packet list functions
Move them to the only place where they are used, demux_subreader.c.
Diffstat (limited to 'demux/demux_subreader.c')
-rw-r--r--demux/demux_subreader.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/demux/demux_subreader.c b/demux/demux_subreader.c
index 6eb58f0033..89e9645f0e 100644
--- a/demux/demux_subreader.c
+++ b/demux/demux_subreader.c
@@ -111,6 +111,55 @@ struct readline_args {
/* Maximal length of line of a subtitle */
#define LINE_LEN 1000
+static double demux_packet_list_duration(struct demux_packet **pkts, int num_pkts)
+{
+ if (num_pkts > 0)
+ return pkts[num_pkts - 1]->pts + pkts[num_pkts - 1]->duration;
+ return 0;
+}
+
+static void demux_packet_list_seek(struct demux_packet **pkts, int num_pkts,
+ int *current, float rel_seek_secs, int flags)
+{
+ double ref_time = 0;
+ if (*current >= 0 && *current < num_pkts) {
+ ref_time = pkts[*current]->pts;
+ } else if (*current == num_pkts && num_pkts > 0) {
+ ref_time = pkts[num_pkts - 1]->pts + pkts[num_pkts - 1]->duration;
+ }
+
+ if (flags & SEEK_ABSOLUTE)
+ ref_time = 0;
+
+ if (flags & SEEK_FACTOR) {
+ ref_time += demux_packet_list_duration(pkts, num_pkts) * rel_seek_secs;
+ } else {
+ ref_time += rel_seek_secs;
+ }
+
+ // Could do binary search, but it's probably not worth the complexity.
+ int last_index = 0;
+ for (int n = 0; n < num_pkts; n++) {
+ if (pkts[n]->pts > ref_time)
+ break;
+ last_index = n;
+ }
+ *current = last_index;
+}
+
+static struct demux_packet *demux_packet_list_fill(struct demux_packet **pkts,
+ int num_pkts, int *current)
+{
+ if (*current < 0)
+ *current = 0;
+ if (*current >= num_pkts)
+ return NULL;
+ struct demux_packet *new = talloc(NULL, struct demux_packet);
+ *new = *pkts[*current];
+ *current += 1;
+ return new;
+}
+
static int eol(char p) {
return p=='\r' || p=='\n' || p=='\0';
}