33 for (i = 0; i < 2; i++)
35 if (strncmp(
"\xFF\xFE", r->
buf, 2) == 0) {
38 }
else if (strncmp(
"\xFE\xFF", r->
buf, 2) == 0) {
43 if (strncmp(
"\xEF\xBB\xBF", r->
buf, 3) == 0) {
50 "UTF16 is automatically converted to UTF8, do not specify a character encoding\n");
88 for ( ; size > 0; size--)
124 memcpy(sub->
data + old_len, event, len);
140 memcpy(sub->
data, event, len);
152 return s1->
pos > s2->
pos ? 1 : -1;
154 return s1->
pts > s2->
pts ? 1 : -1;
164 return s1->
pts > s2->
pts ? 1 : -1;
166 return s1->
pos > s2->
pos ? 1 : -1;
176 for (i = 0; i < q->
nb_subs; i++)
219 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
224 if (ts < 0 || ts >= q->
nb_subs)
236 for (i = idx; i > 0 && q->
subs[i].
pts > max_ts; i--)
240 ts_selected = q->
subs[idx].
pts;
241 if (ts_selected < min_ts || ts_selected > max_ts)
245 for (i = idx - 1; i >= 0; i--) {
250 if (pts >= min_ts && pts > ts_selected - q->
subs[i].
duration)
261 if (stream_index == -1)
274 for (i = 0; i < q->
nb_subs; i++)
290 end_chr = *c ==
'<' ?
'>' :
'<';
295 }
while (*c != end_chr && *c);
296 if (end_chr ==
'>') {
306 const size_t len = strlen(attr);
312 in_quotes ^= *s ==
'"';
318 return s + len + 1 + (s[len + 1] ==
'"');
325 return c ==
'\r' || c ==
'\n';
330 char eol_buf[5], last_was_cr = 0;
331 int n = 0, i = 0, nb_eol = 0;
347 nb_eol += c ==
'\n' || last_was_cr;
351 if (i ==
sizeof(eol_buf) - 1)
353 last_was_cr = c ==
'\r';
384 while (cur + 1 < size) {
388 if (c ==
'\r' || c ==
'\n')
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
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)
Same as ff_subtitles_read_text_chunk(), but read from an AVIOContext.
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 ff_text_peek_r8(FFTextReader *r)
Like ff_text_r8(), but don't remove the byte from the buffer.
#define PUT_UTF8(val, tmp, PUT_BYTE)
Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
int allocated_size
allocated size for subs
unsigned int avio_rb16(AVIOContext *s)
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 av_isspace(int c)
Locale-independent conversion of ASCII isspace.
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
#define AVERROR_EOF
End of file.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define GET_UTF16(val, GET_16BIT, ERROR)
Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
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.
static int is_eol(char c)
int ff_text_eof(FFTextReader *r)
Return non-zero if EOF was reached.
ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size)
Read a line of text.
simple assert() macros that are a bit more flexible than ISO C assert().
void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb)
Initialize the FFTextReader from the given AVIOContext.
int flags
A combination of AV_PKT_FLAG values.
int avio_r8(AVIOContext *s)
int64_t ff_text_pos(FFTextReader *r)
Return the byte position of the next byte returned by ff_text_r8().
static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
void ff_subtitles_queue_finalize(FFDemuxSubtitlesQueue *q)
Set missing durations and sort subtitles by PTS, and then byte position.
void ff_text_read(FFTextReader *r, char *buf, size_t size)
Read the given number of bytes (in UTF-8).
int ff_text_r8(FFTextReader *r)
Return the next byte.
#define AV_LOG_INFO
Standard information.
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.
int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c)
SMIL helper to load next chunk ("<...>" or untagged content) in buf.
void ff_subtitles_read_text_chunk(FFTextReader *tr, AVBPrint *buf)
Read a subtitles chunk from FFTextReader.
int av_copy_packet(AVPacket *dst, const AVPacket *src)
Copy packet, including contents.
static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
Merge two consequent lists of equal size depending on bits read.
static int64_t pts
Global timestamp for the audio frames.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
unsigned int avio_rl16(AVIOContext *s)
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
AVPacket * subs
array of subtitles packets
void ff_text_init_buf(FFTextReader *r, void *buf, size_t size)
Similar to ff_text_init_avio(), but sets it up to read from a bounded buffer.
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
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
AVPacket * ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, const uint8_t *event, size_t len, int merge)
Insert a new subtitle event.
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...
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.