yading@11: /* yading@11: * Copyright (c) 2012 Clément Bœsch yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVFORMAT_SUBTITLES_H yading@11: #define AVFORMAT_SUBTITLES_H yading@11: yading@11: #include yading@11: #include "avformat.h" yading@11: #include "libavutil/bprint.h" yading@11: yading@11: typedef struct { yading@11: AVPacket *subs; ///< array of subtitles packets yading@11: int nb_subs; ///< number of subtitles packets yading@11: int allocated_size; ///< allocated size for subs yading@11: int current_sub_idx; ///< current position for the read packet callback yading@11: } FFDemuxSubtitlesQueue; yading@11: yading@11: /** yading@11: * Insert a new subtitle event. yading@11: * yading@11: * @param event the subtitle line, may not be zero terminated yading@11: * @param len the length of the event (in strlen() sense, so without '\0') yading@11: * @param merge set to 1 if the current event should be concatenated with the yading@11: * previous one instead of adding a new entry, 0 otherwise yading@11: */ yading@11: AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, yading@11: const uint8_t *event, int len, int merge); yading@11: yading@11: /** yading@11: * Set missing durations and sort subtitles by PTS, and then byte position. yading@11: */ yading@11: void ff_subtitles_queue_finalize(FFDemuxSubtitlesQueue *q); yading@11: yading@11: /** yading@11: * Generic read_packet() callback for subtitles demuxers using this queue yading@11: * system. yading@11: */ yading@11: int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt); yading@11: yading@11: /** yading@11: * Update current_sub_idx to emulate a seek. Except the first parameter, it yading@11: * matches AVInputFormat->read_seek2 prototypes. yading@11: */ yading@11: int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int stream_index, yading@11: int64_t min_ts, int64_t ts, int64_t max_ts, int flags); yading@11: yading@11: /** yading@11: * Remove and destroy all the subtitles packets. yading@11: */ yading@11: void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q); yading@11: yading@11: /** yading@11: * SMIL helper to load next chunk ("<...>" or untagged content) in buf. yading@11: * yading@11: * @param c cached character, to avoid a backward seek yading@11: */ yading@11: int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c); yading@11: yading@11: /** yading@11: * SMIL helper to point on the value of an attribute in the given tag. yading@11: * yading@11: * @param s SMIL tag ("<...>") yading@11: * @param attr the attribute to look for yading@11: */ yading@11: const char *ff_smil_get_attr_ptr(const char *s, const char *attr); yading@11: yading@11: /** yading@11: * @brief Read a subtitles chunk. yading@11: * yading@11: * A chunk is defined by a multiline "event", ending with a second line break. yading@11: * The trailing line breaks are trimmed. CRLF are supported. yading@11: * Example: "foo\r\nbar\r\n\r\nnext" will print "foo\r\nbar" into buf, and pb yading@11: * will focus on the 'n' of the "next" string. yading@11: * yading@11: * @param pb I/O context yading@11: * @param buf an initialized buf where the chunk is written yading@11: * yading@11: * @note buf is cleared before writing into it. yading@11: */ yading@11: void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf); yading@11: yading@11: #endif /* AVFORMAT_SUBTITLES_H */