23 #include "libavutil/avassert.h"
24 #include "libavutil/avstring.h"
39 memcpy(sub->
data + old_len, event, len);
55 memcpy(sub->
data, event, len);
67 return s1->
pos > s2->
pos ? 1 : -1;
69 return s1->
pts > s2->
pts ? 1 : -1;
79 return s1->
pts > s2->
pts ? 1 : -1;
81 return s1->
pos > s2->
pos ? 1 : -1;
91 for (i = 0; i < q->
nb_subs; i++)
134 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
139 if (ts < 0 || ts >= q->
nb_subs)
151 for (i = idx; i > 0 && q->
subs[i].
pts > max_ts; i--)
155 ts_selected = q->
subs[idx].
pts;
156 if (ts_selected < min_ts || ts_selected > max_ts)
160 for (i = idx - 1; i >= 0; i--) {
165 if (pts >= min_ts && pts > ts_selected - q->
subs[i].
duration)
176 if (stream_index == -1)
189 for (i = 0; i < q->
nb_subs; i++)
205 end_chr = *c ==
'<' ?
'>' :
'<';
210 }
while (*c != end_chr && *c);
211 if (end_chr ==
'>') {
221 const int len = strlen(attr);
227 in_quotes ^= *s ==
'"';
233 return s + len + 1 + (s[len + 1] ==
'"');
240 return c ==
'\r' || c ==
'\n';
245 char eol_buf[5], last_was_cr = 0;
246 int n = 0, i = 0, nb_eol = 0;
262 nb_eol += c ==
'\n' || last_was_cr;
266 if (i ==
sizeof(eol_buf) - 1)
268 last_was_cr = c ==
'\r';
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
void av_free_packet(AVPacket *pkt)
Free a packet.
int64_t pos
byte position in stream, -1 if unknown
static int cmp_pkt_sub_pos_ts(const void *a, const void *b)
static int search_sub_ts(const FFDemuxSubtitlesQueue *q, int64_t ts)
void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf)
Read a subtitles chunk.
int av_copy_packet(AVPacket *dst, AVPacket *src)
Copy packet, including contents.
void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q)
Remove and destroy all the subtitles packets.
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
int allocated_size
allocated size for subs
AVPacket * ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, const uint8_t *event, int len, int merge)
Insert a new subtitle event.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * ff_smil_get_attr_ptr(const char *s, const char *attr)
SMIL helper to point on the value of an attribute in the given tag.
int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
Generic read_packet() callback for subtitles demuxers using this queue system.
enum sub_sort sort
sort method to use when finalizing subtitles
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static int is_eol(char c)
int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
int flags
A combination of AV_PKT_FLAG values.
Buffer to print data progressively.
static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c)
SMIL helper to load next chunk ("<...>" or untagged content) in buf.
void ff_subtitles_queue_finalize(FFDemuxSubtitlesQueue *q)
Set missing durations and sort subtitles by PTS, and then byte position.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Update current_sub_idx to emulate a seek.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
Merge two consequent lists of equal size depending on bits read.
AVPacket * subs
array of subtitles packets
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
int current_sub_idx
current position for the read packet callback
void av_bprintf(AVBPrint *buf, const char *fmt,...) av_printf_format(2
Append a formatted string to a print buffer.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
This structure stores compressed data.
int nb_subs
number of subtitles packets
sort by timestamps, then position
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...