2 * seek utility functions for use within format handlers
4 * Copyright (c) 2009 Ivan Schreter
6 * This file is part of Libav.
8 * Libav 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.
13 * Libav 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.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef AVFORMAT_SEEK_H
24 #define AVFORMAT_SEEK_H
29 * structure to store parser state of one AVStream
31 typedef struct AVParserStreamState {
32 // saved members of AVStream
33 AVCodecParserContext *parser;
36 int64_t reference_dts;
38 } AVParserStreamState;
41 * structure to store parser state of AVFormat
43 typedef struct AVParserState {
44 int64_t fpos; ///< file position at the time of call
46 // saved members of AVFormatContext
47 AVPacketList *packet_buffer; ///< packet buffer of original state
48 AVPacketList *parse_queue; ///< parse queue of original state
49 AVPacketList *raw_packet_buffer; ///< raw packet buffer of original state
50 int raw_packet_buffer_remaining_size; ///< remaining space in raw_packet_buffer
52 // saved info for streams
53 int nb_streams; ///< number of streams with stored state
54 AVParserStreamState *stream_states; ///< states of individual streams (array)
58 * Search for the sync point of all active streams.
60 * This routine is not supposed to be called directly by a user application,
63 * A sync point is defined as a point in stream, such that, when decoding start
64 * from this point, the decoded output of all streams synchronizes closest
65 * to the given timestamp ts. This routine also takes timestamp limits into account.
66 * Thus, the output will synchronize no sooner than ts_min and no later than ts_max.
68 * @param stream_index stream index for time base reference of timestamps
69 * @param pos approximate position where to start searching for key frames
70 * @param min_ts minimum allowed timestamp (position, if AVSEEK_FLAG_BYTE set)
71 * @param ts target timestamp (or position, if AVSEEK_FLAG_BYTE set in flags)
72 * @param max_ts maximum allowed timestamp (position, if AVSEEK_FLAG_BYTE set)
73 * @param flags if AVSEEK_FLAG_ANY is set, seek to any frame, otherwise only
74 * to a keyframe. If AVSEEK_FLAG_BYTE is set, search by
75 * position, not by timestamp.
76 * @return -1 if no such sync point could be found, otherwise stream position
77 * (stream is repositioned to this position)
79 int64_t ff_gen_syncpoint_search(AVFormatContext *s,
88 * Store current parser state and file position.
90 * This function can be used by demuxers before a destructive seeking algorithm
91 * to store the parser state. Depending on the outcome of the seek, either the original
92 * state can be restored or the new state kept and the original state freed.
94 * @note As a side effect, the original parser state is reset, since structures
95 * are relinked to the stored state instead of being deeply-copied (for
96 * performance reasons and to keep the code simple).
98 * @param s context from which to save state
99 * @return parser state object or NULL if memory could not be allocated
101 AVParserState *ff_store_parser_state(AVFormatContext *s);
104 * Restore previously saved parser state and file position.
106 * Saved state will be invalidated and freed by this call, since internal
107 * structures will be relinked back to the stored state instead of being
110 * @param s context to which to restore state (same as used for storing state)
111 * @param state state to restore
113 void ff_restore_parser_state(AVFormatContext *s, AVParserState *state);
116 * Free previously saved parser state.
118 * @param s context to which the state belongs (same as used for storing state)
119 * @param state state to free
121 void ff_free_parser_state(AVFormatContext *s, AVParserState *state);
123 #endif /* AVFORMAT_SEEK_H */