seek.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * seek utility functions for use within format handlers
  3. *
  4. * Copyright (c) 2009 Ivan Schreter
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVFORMAT_SEEK_H
  23. #define AVFORMAT_SEEK_H
  24. #include "avformat.h"
  25. /**
  26. * structure to store parser state of one AVStream
  27. */
  28. typedef struct AVParserStreamState {
  29. // saved members of AVStream
  30. AVCodecParserContext *parser;
  31. AVPacket cur_pkt;
  32. int64_t last_IP_pts;
  33. int64_t cur_dts;
  34. int64_t reference_dts;
  35. const uint8_t *cur_ptr;
  36. int cur_len;
  37. int probe_packets;
  38. } AVParserStreamState;
  39. /**
  40. * structure to store parser state of AVFormat
  41. */
  42. typedef struct AVParserState {
  43. int64_t fpos; ///< file position at the time of call
  44. // saved members of AVFormatContext
  45. AVStream *cur_st; ///< current stream.
  46. AVPacketList *packet_buffer; ///< packet buffer of original state
  47. AVPacketList *raw_packet_buffer; ///< raw packet buffer of original state
  48. int raw_packet_buffer_remaining_size; ///< remaining space in raw_packet_buffer
  49. // saved info for streams
  50. int nb_streams; ///< number of streams with stored state
  51. AVParserStreamState *stream_states; ///< states of individual streams (array)
  52. } AVParserState;
  53. /**
  54. * Search for the sync point of all active streams.
  55. *
  56. * This routine is not supposed to be called directly by a user application,
  57. * but by demuxers.
  58. *
  59. * A sync point is defined as a point in stream, such that, when decoding start
  60. * from this point, the decoded output of all streams synchronizes closest
  61. * to the given timestamp ts. This routine also takes timestamp limits into account.
  62. * Thus, the output will synchronize no sooner than ts_min and no later than ts_max.
  63. *
  64. * @param stream_index stream index for time base reference of timestamps
  65. * @param pos approximate position where to start searching for key frames
  66. * @param min_ts minimum allowed timestamp (position, if AVSEEK_FLAG_BYTE set)
  67. * @param ts target timestamp (or position, if AVSEEK_FLAG_BYTE set in flags)
  68. * @param max_ts maximum allowed timestamp (position, if AVSEEK_FLAG_BYTE set)
  69. * @param flags if AVSEEK_FLAG_ANY is set, seek to any frame, otherwise only
  70. * to a keyframe. If AVSEEK_FLAG_BYTE is set, search by
  71. * position, not by timestamp.
  72. * @return -1 if no such sync point could be found, otherwise stream position
  73. * (stream is repositioned to this position)
  74. */
  75. int64_t ff_gen_syncpoint_search(AVFormatContext *s,
  76. int stream_index,
  77. int64_t pos,
  78. int64_t min_ts,
  79. int64_t ts,
  80. int64_t max_ts,
  81. int flags);
  82. /**
  83. * Store current parser state and file position.
  84. *
  85. * This function can be used by demuxers before a destructive seeking algorithm
  86. * to store the parser state. Depending on the outcome of the seek, either the original
  87. * state can be restored or the new state kept and the original state freed.
  88. *
  89. * @note As a side effect, the original parser state is reset, since structures
  90. * are relinked to the stored state instead of being deeply-copied (for
  91. * performance reasons and to keep the code simple).
  92. *
  93. * @param s context from which to save state
  94. * @return parser state object or NULL if memory could not be allocated
  95. */
  96. AVParserState *ff_store_parser_state(AVFormatContext *s);
  97. /**
  98. * Restore previously saved parser state and file position.
  99. *
  100. * Saved state will be invalidated and freed by this call, since internal
  101. * structures will be relinked back to the stored state instead of being
  102. * deeply-copied.
  103. *
  104. * @param s context to which to restore state (same as used for storing state)
  105. * @param state state to restore
  106. */
  107. void ff_restore_parser_state(AVFormatContext *s, AVParserState *state);
  108. /**
  109. * Free previously saved parser state.
  110. *
  111. * @param s context to which the state belongs (same as used for storing state)
  112. * @param state state to free
  113. */
  114. void ff_free_parser_state(AVFormatContext *s, AVParserState *state);
  115. #endif /* AVFORMAT_SEEK_H */