Go to the documentation of this file.
30 r->buf_pos =
r->buf_len = 0;
32 for (
i = 0;
i < 2;
i++)
34 if (strncmp(
"\xFF\xFE",
r->buf, 2) == 0) {
37 }
else if (strncmp(
"\xFE\xFF",
r->buf, 2) == 0) {
42 if (strncmp(
"\xEF\xBB\xBF",
r->buf, 3) == 0) {
49 "UTF16 is automatically converted to UTF8, do not specify a character encoding\n");
67 if (
r->buf_pos <
r->buf_len)
68 return r->buf[
r->buf_pos++];
81 return r->buf[
r->buf_pos++];
98 if (
r->buf_pos <
r->buf_len)
99 return r->buf[
r->buf_pos];
110 const uint8_t *event,
size_t len,
int merge)
122 memcpy(sub->
data + old_len, event,
len);
149 const AVBPrint *event,
int merge)
160 if (
s1->pts ==
s2->pts)
169 if (
s1->pos ==
s2->pos) {
170 if (
s1->pts ==
s2->pts)
172 return s1->pts >
s2->pts ? 1 : -1;
174 return s1->pos >
s2->pos ? 1 : -1;
182 const int last_id =
i - 1 - drop;
262 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
267 if (ts < 0 || ts >= q->
nb_subs)
279 for (
i = idx;
i > 0 && q->
subs[
i]->
pts > max_ts;
i--)
283 ts_selected = q->
subs[idx]->
pts;
284 if (ts_selected < min_ts || ts_selected > max_ts)
288 for (
i = idx - 1;
i >= 0;
i--) {
304 if (stream_index == -1)
330 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
334 min_ts, ts, max_ts,
flags);
354 end_chr = *
c ==
'<' ?
'>' :
'<';
361 }
while (*
c != end_chr && *
c);
362 if (end_chr ==
'>') {
372 const size_t len = strlen(attr);
378 in_quotes ^= *
s ==
'"';
384 return s +
len + 1 + (
s[
len + 1] ==
'"');
391 return c ==
'\r' ||
c ==
'\n';
396 char eol_buf[5], last_was_cr = 0;
397 int n = 0,
i = 0, nb_eol = 0;
413 nb_eol +=
c ==
'\n' || last_was_cr;
417 if (
i ==
sizeof(eol_buf) - 1)
419 last_was_cr =
c ==
'\r';
452 while (cur + 1 <
size) {
456 if (
c ==
'\r' ||
c ==
'\n')
int ff_subtitles_read_close(AVFormatContext *s)
static int is_eol(char c)
#define AV_LOG_WARNING
Something somehow does not look correct.
int ff_text_r8(FFTextReader *r)
Return the next byte.
#define PUT_UTF8(val, tmp, PUT_BYTE)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c)
SMIL helper to load next chunk ("<...>" or untagged content) in buf.
#define AVERROR_EOF
End of file.
int nb_subs
number of subtitles packets
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
Merge two consequent lists of equal size depending on bits read.
int ff_subtitles_read_text_chunk(FFTextReader *tr, AVBPrint *buf)
Read a subtitles chunk from FFTextReader.
int keep_duplicates
set to 1 to keep duplicated subtitle events
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
void ffio_init_read_context(FFIOContext *s, const uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for reading.
ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size)
Read a line of text.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
int ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf)
Same as ff_subtitles_read_text_chunk(), but read from an AVIOContext.
int current_sub_idx
current position for the read packet callback
static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static double val(void *priv, double ch)
unsigned int avio_rl16(AVIOContext *s)
#define FFDIFFSIGN(x, y)
Comparator.
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_subtitles_read_packet(AVFormatContext *s, AVPacket *pkt)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
Generic read_packet() callback for subtitles demuxers using this queue system.
void ff_text_read(FFTextReader *r, char *buf, size_t size)
Read the given number of bytes (in UTF-8).
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
AVPacket * ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, const uint8_t *event, size_t len, int merge)
Insert a new subtitle event.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb)
Initialize the FFTextReader from the given AVIOContext.
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q)
Set missing durations, sort subtitles by PTS (and then byte position), and drop duplicated events.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int avio_r8(AVIOContext *s)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q)
Remove and destroy all the subtitles packets.
int flags
A combination of AV_PKT_FLAG values.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
#define AV_LOG_INFO
Standard information.
AVPacket * ff_subtitles_queue_insert_bprint(FFDemuxSubtitlesQueue *q, const AVBPrint *event, int merge)
Same as ff_subtitles_queue_insert but takes an AVBPrint input.
static void drop_dups(void *log_ctx, FFDemuxSubtitlesQueue *q)
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
AVPacket ** subs
array of subtitles packets
@ SUB_SORT_TS_POS
sort by timestamps, then position
int64_t ff_text_pos(FFTextReader *r)
Return the byte position of the next byte returned by ff_text_r8().
int ff_subtitles_read_seek(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
#define GET_UTF16(val, GET_16BIT, ERROR)
Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form.
unsigned int avio_rb16(AVIOContext *s)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
int ff_text_peek_r8(FFTextReader *r)
Like ff_text_r8(), but don't remove the byte from the buffer.
static int search_sub_ts(const FFDemuxSubtitlesQueue *q, int64_t ts)
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
void ff_text_init_buf(FFTextReader *r, const void *buf, size_t size)
Similar to ff_text_init_avio(), but sets it up to read from a bounded buffer.
int ff_text_eof(FFTextReader *r)
Return non-zero if EOF was reached.
This structure stores compressed data.
int allocated_size
allocated size for subs
#define flags(name, subs,...)
enum sub_sort sort
sort method to use when finalizing subtitles
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int cmp_pkt_sub_pos_ts(const void *a, const void *b)
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
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 avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.