mirror of https://github.com/mpv-player/mpv
demux: move packet list functions
Move them to the only place where they are used, demux_subreader.c.
This commit is contained in:
parent
18e6d07612
commit
e4221f3189
|
@ -957,69 +957,3 @@ int demuxer_set_angle(demuxer_t *demuxer, int angle)
|
||||||
|
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int packet_sort_compare(const void *p1, const void *p2)
|
|
||||||
{
|
|
||||||
struct demux_packet *c1 = *(struct demux_packet **)p1;
|
|
||||||
struct demux_packet *c2 = *(struct demux_packet **)p2;
|
|
||||||
|
|
||||||
if (c1->pts > c2->pts)
|
|
||||||
return 1;
|
|
||||||
else if (c1->pts < c2->pts)
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void demux_packet_list_sort(struct demux_packet **pkts, int num_pkts)
|
|
||||||
{
|
|
||||||
qsort(pkts, num_pkts, sizeof(struct demux_packet *), packet_sort_compare);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -280,13 +280,6 @@ struct sh_stream *demuxer_stream_by_demuxer_id(struct demuxer *d,
|
||||||
bool demuxer_stream_is_selected(struct demuxer *d, struct sh_stream *stream);
|
bool demuxer_stream_is_selected(struct demuxer *d, struct sh_stream *stream);
|
||||||
bool demuxer_stream_has_packets_queued(struct demuxer *d, struct sh_stream *stream);
|
bool demuxer_stream_has_packets_queued(struct demuxer *d, struct sh_stream *stream);
|
||||||
|
|
||||||
void demux_packet_list_sort(struct demux_packet **pkts, int num_pkts);
|
|
||||||
void demux_packet_list_seek(struct demux_packet **pkts, int num_pkts,
|
|
||||||
int *current, float rel_seek_secs, int flags);
|
|
||||||
double demux_packet_list_duration(struct demux_packet **pkts, int num_pkts);
|
|
||||||
struct demux_packet *demux_packet_list_fill(struct demux_packet **pkts,
|
|
||||||
int num_pkts, int *current);
|
|
||||||
|
|
||||||
bool demux_matroska_uid_cmp(struct matroska_segment_uid *a,
|
bool demux_matroska_uid_cmp(struct matroska_segment_uid *a,
|
||||||
struct matroska_segment_uid *b);
|
struct matroska_segment_uid *b);
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,55 @@ struct readline_args {
|
||||||
/* Maximal length of line of a subtitle */
|
/* Maximal length of line of a subtitle */
|
||||||
#define LINE_LEN 1000
|
#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) {
|
static int eol(char p) {
|
||||||
return p=='\r' || p=='\n' || p=='\0';
|
return p=='\r' || p=='\n' || p=='\0';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue