subtitles.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Clément Bœsch
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVFORMAT_SUBTITLES_H
22 #define AVFORMAT_SUBTITLES_H
23 
24 #include <stdint.h>
25 #include "avformat.h"
26 #include "libavutil/bprint.h"
27 
28 typedef struct {
29  AVPacket *subs; ///< array of subtitles packets
30  int nb_subs; ///< number of subtitles packets
31  int allocated_size; ///< allocated size for subs
32  int current_sub_idx; ///< current position for the read packet callback
34 
35 /**
36  * Insert a new subtitle event.
37  *
38  * @param event the subtitle line, may not be zero terminated
39  * @param len the length of the event (in strlen() sense, so without '\0')
40  * @param merge set to 1 if the current event should be concatenated with the
41  * previous one instead of adding a new entry, 0 otherwise
42  */
44  const uint8_t *event, int len, int merge);
45 
46 /**
47  * Set missing durations and sort subtitles by PTS, and then byte position.
48  */
50 
51 /**
52  * Generic read_packet() callback for subtitles demuxers using this queue
53  * system.
54  */
56 
57 /**
58  * Update current_sub_idx to emulate a seek. Except the first parameter, it
59  * matches AVInputFormat->read_seek2 prototypes.
60  */
62  int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
63 
64 /**
65  * Remove and destroy all the subtitles packets.
66  */
68 
69 /**
70  * SMIL helper to load next chunk ("<...>" or untagged content) in buf.
71  *
72  * @param c cached character, to avoid a backward seek
73  */
75 
76 /**
77  * SMIL helper to point on the value of an attribute in the given tag.
78  *
79  * @param s SMIL tag ("<...>")
80  * @param attr the attribute to look for
81  */
82 const char *ff_smil_get_attr_ptr(const char *s, const char *attr);
83 
84 /**
85  * @brief Read a subtitles chunk.
86  *
87  * A chunk is defined by a multiline "event", ending with a second line break.
88  * The trailing line breaks are trimmed. CRLF are supported.
89  * Example: "foo\r\nbar\r\n\r\nnext" will print "foo\r\nbar" into buf, and pb
90  * will focus on the 'n' of the "next" string.
91  *
92  * @param pb I/O context
93  * @param buf an initialized buf where the chunk is written
94  *
95  * @note buf is cleared before writing into it.
96  */
98 
99 #endif /* AVFORMAT_SUBTITLES_H */
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
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.
Definition: subtitles.c:95
int allocated_size
allocated size for subs
Definition: subtitles.h:31
Format I/O context.
Definition: avformat.h:944
uint8_t
static AVPacket pkt
Definition: demuxing.c:56
void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q)
Remove and destroy all the subtitles packets.
Definition: subtitles.c:134
AVPacket * ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, const uint8_t *event, int len, int merge)
Insert a new subtitle event.
Definition: subtitles.c:26
Buffer to print data progressively.
Definition: bprint.h:75
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.
Definition: subtitles.c:167
void * buf
Definition: avisynth_c.h:594
void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf)
Read a subtitles chunk.
Definition: subtitles.c:192
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 int flags
Definition: cpu.c:23
Main libavformat public API header.
static double c[64]
AVPacket * subs
array of subtitles packets
Definition: subtitles.h:29
int current_sub_idx
current position for the read packet callback
Definition: subtitles.h:32
int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
Generic read_packet() callback for subtitles demuxers using this queue system.
Definition: subtitles.c:82
int len
int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c)
SMIL helper to load next chunk ("<...>" or untagged content) in buf.
Definition: subtitles.c:144
void ff_subtitles_queue_finalize(FFDemuxSubtitlesQueue *q)
Set missing durations and sort subtitles by PTS, and then byte position.
Definition: subtitles.c:72
This structure stores compressed data.
int nb_subs
number of subtitles packets
Definition: subtitles.h:30