You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.4KB

  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. #ifndef AVFORMAT_SUBTITLES_H
  21. #define AVFORMAT_SUBTITLES_H
  22. #include <stdint.h>
  23. #include "avformat.h"
  24. #include "libavutil/bprint.h"
  25. typedef struct {
  26. AVPacket *subs; ///< array of subtitles packets
  27. int nb_subs; ///< number of subtitles packets
  28. int allocated_size; ///< allocated size for subs
  29. int current_sub_idx; ///< current position for the read packet callback
  30. } FFDemuxSubtitlesQueue;
  31. /**
  32. * Insert a new subtitle event.
  33. *
  34. * @param event the subtitle line, may not be zero terminated
  35. * @param len the length of the event (in strlen() sense, so without '\0')
  36. * @param merge set to 1 if the current event should be concatenated with the
  37. * previous one instead of adding a new entry, 0 otherwise
  38. */
  39. AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q,
  40. const uint8_t *event, int len, int merge);
  41. /**
  42. * Set missing durations and sort subtitles by PTS, and then byte position.
  43. */
  44. void ff_subtitles_queue_finalize(FFDemuxSubtitlesQueue *q);
  45. /**
  46. * Generic read_packet() callback for subtitles demuxers using this queue
  47. * system.
  48. */
  49. int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt);
  50. /**
  51. * Update current_sub_idx to emulate a seek. Except the first parameter, it
  52. * matches AVInputFormat->read_seek2 prototypes.
  53. */
  54. int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int stream_index,
  55. int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  56. /**
  57. * Remove and destroy all the subtitles packets.
  58. */
  59. void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q);
  60. /**
  61. * SMIL helper to load next chunk ("<...>" or untagged content) in buf.
  62. *
  63. * @param c cached character, to avoid a backward seek
  64. */
  65. int ff_smil_extract_next_chunk(AVIOContext *pb, AVBPrint *buf, char *c);
  66. /**
  67. * SMIL helper to point on the value of an attribute in the given tag.
  68. *
  69. * @param s SMIL tag ("<...>")
  70. * @param attr the attribute to look for
  71. */
  72. const char *ff_smil_get_attr_ptr(const char *s, const char *attr);
  73. /**
  74. * @brief Read a subtitles chunk.
  75. *
  76. * A chunk is defined by a multiline "event", ending with a second line break.
  77. * The trailing line breaks are trimmed. CRLF are supported.
  78. * Example: "foo\r\nbar\r\n\r\nnext" will print "foo\r\nbar" into buf, and pb
  79. * will focus on the 'n' of the "next" string.
  80. *
  81. * @param pb I/O context
  82. * @param buf an initialized buf where the chunk is written
  83. *
  84. * @note buf is cleared before writing into it.
  85. */
  86. void ff_subtitles_read_chunk(AVIOContext *pb, AVBPrint *buf);
  87. #endif /* AVFORMAT_SUBTITLES_H */