FFmpeg
subtitles.h
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 <stddef.h>
26 #include "avformat.h"
27 #include "libavutil/bprint.h"
28 
29 enum sub_sort {
30  SUB_SORT_TS_POS = 0,
31  SUB_SORT_POS_TS,
32 };
33 
34 enum ff_utf_type {
35  FF_UTF_8, // or other 8 bit encodings
36  FF_UTF16LE,
37  FF_UTF16BE,
38 };
39 
40 typedef struct {
41  int type;
42  AVIOContext *pb;
43  unsigned char buf[8];
44  int buf_pos, buf_len;
45  AVIOContext buf_pb;
46 } FFTextReader;
47 
61 void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb);
62 
70 void ff_text_init_buf(FFTextReader *r, void *buf, size_t size);
71 
77 int64_t ff_text_pos(FFTextReader *r);
78 
84 int ff_text_r8(FFTextReader *r);
85 
89 int ff_text_eof(FFTextReader *r);
90 
94 int ff_text_peek_r8(FFTextReader *r);
95 
100 void ff_text_read(FFTextReader *r, char *buf, size_t size);
101 
102 typedef struct {
104  int nb_subs;
107  enum sub_sort sort;
110 
119 AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q,
120  const uint8_t *event, size_t len, int merge);
121 
126 void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q);
127 
132 int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt);
133 
138 int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int stream_index,
139  int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
140 
144 void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q);
145 
151 int ff_smil_extract_next_text_chunk(FFTextReader *tr, AVBPrint *buf, char *c);
152 
159 const char *ff_smil_get_attr_ptr(const char *s, const char *attr);
160 
164 void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf);
165 
179 void ff_subtitles_read_text_chunk(FFTextReader *tr, AVBPrint *buf);
180 
187 static av_always_inline int ff_subtitles_next_line(const char *ptr)
188 {
189  int n = strcspn(ptr, "\r\n");
190  ptr += n;
191  if (*ptr == '\r') {
192  ptr++;
193  n++;
194  }
195  if (*ptr == '\n')
196  n++;
197  return n;
198 }
199 
210 ptrdiff_t ff_subtitles_read_line(FFTextReader *tr, char *buf, size_t size);
211 
212 #endif /* AVFORMAT_SUBTITLES_H */
int keep_duplicates
set to 1 to keep duplicated subtitle events
Definition: subtitles.h:108
Bytestream IO Context.
Definition: avio.h:161
int allocated_size
allocated size for subs
Definition: subtitles.h:105
Format I/O context.
Definition: avformat.h:1342
Definition: subtitles.h:102
Definition: subtitles.h:40
Main libavformat public API header.
AVPacket * subs
array of subtitles packets
Definition: subtitles.h:103
int current_sub_idx
current position for the read packet callback
Definition: subtitles.h:106
This structure stores compressed data.
Definition: avcodec.h:1407
int nb_subs
number of subtitles packets
Definition: subtitles.h:104