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.

123 lines
4.9KB

  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. int64_t last_IP_pts;
  32. int64_t cur_dts;
  33. int probe_packets;
  34. } AVParserStreamState;
  35. /**
  36. * structure to store parser state of AVFormat
  37. */
  38. typedef struct AVParserState {
  39. int64_t fpos; ///< file position at the time of call
  40. // saved members of AVFormatContext
  41. AVPacketList *packet_buffer; ///< packet buffer of original state
  42. AVPacketList *parse_queue; ///< parse queue of original state
  43. AVPacketList *raw_packet_buffer; ///< raw packet buffer of original state
  44. int raw_packet_buffer_remaining_size; ///< remaining space in raw_packet_buffer
  45. // saved info for streams
  46. int nb_streams; ///< number of streams with stored state
  47. AVParserStreamState *stream_states; ///< states of individual streams (array)
  48. } AVParserState;
  49. /**
  50. * Search for the sync point of all active streams.
  51. *
  52. * This routine is not supposed to be called directly by a user application,
  53. * but by demuxers.
  54. *
  55. * A sync point is defined as a point in stream, such that, when decoding start
  56. * from this point, the decoded output of all streams synchronizes closest
  57. * to the given timestamp ts. This routine also takes timestamp limits into account.
  58. * Thus, the output will synchronize no sooner than ts_min and no later than ts_max.
  59. *
  60. * @param stream_index stream index for time base reference of timestamps
  61. * @param pos approximate position where to start searching for key frames
  62. * @param min_ts minimum allowed timestamp (position, if AVSEEK_FLAG_BYTE set)
  63. * @param ts target timestamp (or position, if AVSEEK_FLAG_BYTE set in flags)
  64. * @param max_ts maximum allowed timestamp (position, if AVSEEK_FLAG_BYTE set)
  65. * @param flags if AVSEEK_FLAG_ANY is set, seek to any frame, otherwise only
  66. * to a keyframe. If AVSEEK_FLAG_BYTE is set, search by
  67. * position, not by timestamp.
  68. * @return -1 if no such sync point could be found, otherwise stream position
  69. * (stream is repositioned to this position)
  70. */
  71. int64_t ff_gen_syncpoint_search(AVFormatContext *s,
  72. int stream_index,
  73. int64_t pos,
  74. int64_t min_ts,
  75. int64_t ts,
  76. int64_t max_ts,
  77. int flags);
  78. /**
  79. * Store current parser state and file position.
  80. *
  81. * This function can be used by demuxers before a destructive seeking algorithm
  82. * to store the parser state. Depending on the outcome of the seek, either the original
  83. * state can be restored or the new state kept and the original state freed.
  84. *
  85. * @note As a side effect, the original parser state is reset, since structures
  86. * are relinked to the stored state instead of being deeply-copied (for
  87. * performance reasons and to keep the code simple).
  88. *
  89. * @param s context from which to save state
  90. * @return parser state object or NULL if memory could not be allocated
  91. */
  92. AVParserState *ff_store_parser_state(AVFormatContext *s);
  93. /**
  94. * Restore previously saved parser state and file position.
  95. *
  96. * Saved state will be invalidated and freed by this call, since internal
  97. * structures will be relinked back to the stored state instead of being
  98. * deeply-copied.
  99. *
  100. * @param s context to which to restore state (same as used for storing state)
  101. * @param state state to restore
  102. */
  103. void ff_restore_parser_state(AVFormatContext *s, AVParserState *state);
  104. /**
  105. * Free previously saved parser state.
  106. *
  107. * @param s context to which the state belongs (same as used for storing state)
  108. * @param state state to free
  109. */
  110. void ff_free_parser_state(AVFormatContext *s, AVParserState *state);
  111. #endif /* AVFORMAT_SEEK_H */