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.

98 lines
3.8KB

  1. /*
  2. * Utility functions for seeking for use within FFmpeg 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. /// Opaque structure for parser state.
  26. typedef struct AVParserState AVParserState;
  27. /**
  28. * Search for sync point of all active streams.
  29. *
  30. * This is not supposed to be called directly by a user application,
  31. * but by demuxers.
  32. *
  33. * A sync point is a point in stream, so that decoding from this point,
  34. * output of decoders of all streams synchronizes closest to given timestamp
  35. * ts (but taking timestamp limits into account, i.e., no sooner than ts_min
  36. * and no later than ts_max).
  37. *
  38. * @param stream_index stream index for time base reference of timestamps.
  39. * @param pos approximate position where to start searching for key frames.
  40. * @param min_ts minimum allowed timestamp (position, if AVSEEK_FLAG_BYTE set).
  41. * @param ts target timestamp (or position, if AVSEEK_FLAG_BYTE set in flags).
  42. * @param max_ts maximum allowed timestamp (position, if AVSEEK_FLAG_BYTE set).
  43. * @param flags if AVSEEK_FLAG_ANY is set, seek to any frame, otherwise only
  44. * to a keyframe. If AVSEEK_FLAG_BYTE is set, search by
  45. * position, not by timestamp.
  46. * @return < 0 if no such sync point could be found, otherwise stream position
  47. * (stream is repositioned to this position).
  48. */
  49. int64_t ff_gen_syncpoint_search(AVFormatContext *s,
  50. int stream_index,
  51. int64_t pos,
  52. int64_t min_ts,
  53. int64_t ts,
  54. int64_t max_ts,
  55. int flags);
  56. /**
  57. * Store current parser state and file position.
  58. *
  59. * This function can be used by demuxers before destructive seeking algorithm
  60. * to store parser state. After the seek, depending on outcome, original state
  61. * can be restored or new state kept and original state freed.
  62. *
  63. * @note As a side effect, original parser state is reset, since structures
  64. * are relinked to stored state instead of being deeply-copied (for
  65. * performance reasons and to keep code simple).
  66. *
  67. * @param s context from which to save state.
  68. * @return parser state object or NULL if memory could not be allocated.
  69. */
  70. AVParserState *ff_store_parser_state(AVFormatContext *s);
  71. /**
  72. * Restore previously saved parser state and file position.
  73. *
  74. * Saved state will be invalidated and freed by this call, since internal
  75. * structures will be relinked back to stored state instead of being
  76. * deeply-copied.
  77. *
  78. * @param s context to which to restore state (same as used for storing state).
  79. * @param state state to restore.
  80. */
  81. void ff_restore_parser_state(AVFormatContext *s, AVParserState *state);
  82. /**
  83. * Free previously saved parser state.
  84. *
  85. * @param s context to which the state belongs (same as used for storing state).
  86. * @param state state to free.
  87. */
  88. void ff_free_parser_state(AVFormatContext *s, AVParserState *state);
  89. #endif /* AVFORMAT_SEEK_H */