yading@11: /* yading@11: * seek utility functions for use within format handlers yading@11: * yading@11: * Copyright (c) 2009 Ivan Schreter yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVFORMAT_SEEK_H yading@11: #define AVFORMAT_SEEK_H yading@11: yading@11: #include "avformat.h" yading@11: yading@11: /** yading@11: * structure to store parser state of one AVStream yading@11: */ yading@11: typedef struct AVParserStreamState { yading@11: // saved members of AVStream yading@11: AVCodecParserContext *parser; yading@11: int64_t last_IP_pts; yading@11: int64_t cur_dts; yading@11: int64_t reference_dts; yading@11: int probe_packets; yading@11: } AVParserStreamState; yading@11: yading@11: /** yading@11: * structure to store parser state of AVFormat yading@11: */ yading@11: typedef struct AVParserState { yading@11: int64_t fpos; ///< file position at the time of call yading@11: yading@11: // saved members of AVFormatContext yading@11: AVPacketList *packet_buffer; ///< packet buffer of original state yading@11: AVPacketList *parse_queue; ///< parse queue of original state yading@11: AVPacketList *raw_packet_buffer; ///< raw packet buffer of original state yading@11: int raw_packet_buffer_remaining_size; ///< remaining space in raw_packet_buffer yading@11: yading@11: // saved info for streams yading@11: int nb_streams; ///< number of streams with stored state yading@11: AVParserStreamState *stream_states; ///< states of individual streams (array) yading@11: } AVParserState; yading@11: yading@11: /** yading@11: * Search for the sync point of all active streams. yading@11: * yading@11: * This routine is not supposed to be called directly by a user application, yading@11: * but by demuxers. yading@11: * yading@11: * A sync point is defined as a point in stream, such that, when decoding start yading@11: * from this point, the decoded output of all streams synchronizes closest yading@11: * to the given timestamp ts. This routine also takes timestamp limits into account. yading@11: * Thus, the output will synchronize no sooner than ts_min and no later than ts_max. yading@11: * yading@11: * @param stream_index stream index for time base reference of timestamps yading@11: * @param pos approximate position where to start searching for key frames yading@11: * @param min_ts minimum allowed timestamp (position, if AVSEEK_FLAG_BYTE set) yading@11: * @param ts target timestamp (or position, if AVSEEK_FLAG_BYTE set in flags) yading@11: * @param max_ts maximum allowed timestamp (position, if AVSEEK_FLAG_BYTE set) yading@11: * @param flags if AVSEEK_FLAG_ANY is set, seek to any frame, otherwise only yading@11: * to a keyframe. If AVSEEK_FLAG_BYTE is set, search by yading@11: * position, not by timestamp. yading@11: * @return -1 if no such sync point could be found, otherwise stream position yading@11: * (stream is repositioned to this position) yading@11: */ yading@11: int64_t ff_gen_syncpoint_search(AVFormatContext *s, yading@11: int stream_index, yading@11: int64_t pos, yading@11: int64_t min_ts, yading@11: int64_t ts, yading@11: int64_t max_ts, yading@11: int flags); yading@11: yading@11: /** yading@11: * Store current parser state and file position. yading@11: * yading@11: * This function can be used by demuxers before a destructive seeking algorithm yading@11: * to store the parser state. Depending on the outcome of the seek, either the original yading@11: * state can be restored or the new state kept and the original state freed. yading@11: * yading@11: * @note As a side effect, the original parser state is reset, since structures yading@11: * are relinked to the stored state instead of being deeply-copied (for yading@11: * performance reasons and to keep the code simple). yading@11: * yading@11: * @param s context from which to save state yading@11: * @return parser state object or NULL if memory could not be allocated yading@11: */ yading@11: AVParserState *ff_store_parser_state(AVFormatContext *s); yading@11: yading@11: /** yading@11: * Restore previously saved parser state and file position. yading@11: * yading@11: * Saved state will be invalidated and freed by this call, since internal yading@11: * structures will be relinked back to the stored state instead of being yading@11: * deeply-copied. yading@11: * yading@11: * @param s context to which to restore state (same as used for storing state) yading@11: * @param state state to restore yading@11: */ yading@11: void ff_restore_parser_state(AVFormatContext *s, AVParserState *state); yading@11: yading@11: /** yading@11: * Free previously saved parser state. yading@11: * yading@11: * @param s context to which the state belongs (same as used for storing state) yading@11: * @param state state to free yading@11: */ yading@11: void ff_free_parser_state(AVFormatContext *s, AVParserState *state); yading@11: yading@11: #endif /* AVFORMAT_SEEK_H */