FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Functions
seek.c File Reference
#include "seek.h"
#include "libavutil/mathematics.h"
#include "libavutil/mem.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  AVSyncPoint
 helper structure describing keyframe search state of one stream More...
 

Functions

static int64_t ts_distance (int64_t ts_hi, AVRational tb_hi, int64_t ts_lo, AVRational tb_lo)
 Compute a distance between timestamps.
 
static void search_hi_lo_keyframes (AVFormatContext *s, int64_t timestamp, AVRational timebase, int flags, AVSyncPoint *sync, int keyframes_to_find, int *found_lo, int *found_hi, int first_iter)
 Partial search for keyframes in multiple streams.
 
int64_t ff_gen_syncpoint_search (AVFormatContext *s, int stream_index, int64_t pos, int64_t ts_min, int64_t ts, int64_t ts_max, int flags)
 Search for the sync point of all active streams.
 
AVParserStateff_store_parser_state (AVFormatContext *s)
 Store current parser state and file position.
 
void ff_restore_parser_state (AVFormatContext *s, AVParserState *state)
 Restore previously saved parser state and file position.
 
static void free_packet_list (AVPacketList *pktl)
 
void ff_free_parser_state (AVFormatContext *s, AVParserState *state)
 Free previously saved parser state.
 

Function Documentation

static int64_t ts_distance ( int64_t  ts_hi,
AVRational  tb_hi,
int64_t  ts_lo,
AVRational  tb_lo 
)
static

Compute a distance between timestamps.

Distances are only comparable, if same time bases are used for computing distances.

Parameters
ts_hihigh timestamp
tb_hihigh timestamp time base
ts_lolow timestamp
tb_lolow timestamp time base
Returns
representation of distance between high and low timestamps

Definition at line 63 of file seek.c.

Referenced by ff_gen_syncpoint_search().

static void search_hi_lo_keyframes ( AVFormatContext s,
int64_t  timestamp,
AVRational  timebase,
int  flags,
AVSyncPoint sync,
int  keyframes_to_find,
int *  found_lo,
int *  found_hi,
int  first_iter 
)
static

Partial search for keyframes in multiple streams.

This routine searches in each stream for the next lower and the next higher timestamp compared to the given target timestamp. The search starts at the current file position and ends at the file position, where all streams have already been examined (or when all higher key frames are found in the first iteration).

This routine is called iteratively with an exponential backoff to find the lower timestamp.

Parameters
sformat context
timestamptarget timestamp (or position, if AVSEEK_FLAG_BYTE)
timebasetime base for timestamps
flagsseeking flags
syncarray with information per stream
keyframes_to_findcount of keyframes to find in total
found_loptr to the count of already found low timestamp keyframes
found_hiptr to the count of already found high timestamp keyframes
first_iterflag for first iteration

Definition at line 97 of file seek.c.

Referenced by ff_gen_syncpoint_search().

int64_t ff_gen_syncpoint_search ( AVFormatContext s,
int  stream_index,
int64_t  pos,
int64_t  min_ts,
int64_t  ts,
int64_t  max_ts,
int  flags 
)

Search for the sync point of all active streams.

This routine is not supposed to be called directly by a user application, but by demuxers.

A sync point is defined as a point in stream, such that, when decoding start from this point, the decoded output of all streams synchronizes closest to the given timestamp ts. This routine also takes timestamp limits into account. Thus, the output will synchronize no sooner than ts_min and no later than ts_max.

Parameters
stream_indexstream index for time base reference of timestamps
posapproximate position where to start searching for key frames
min_tsminimum allowed timestamp (position, if AVSEEK_FLAG_BYTE set)
tstarget timestamp (or position, if AVSEEK_FLAG_BYTE set in flags)
max_tsmaximum allowed timestamp (position, if AVSEEK_FLAG_BYTE set)
flagsif AVSEEK_FLAG_ANY is set, seek to any frame, otherwise only to a keyframe. If AVSEEK_FLAG_BYTE is set, search by position, not by timestamp.
Returns
-1 if no such sync point could be found, otherwise stream position (stream is repositioned to this position)

Definition at line 244 of file seek.c.

AVParserState* ff_store_parser_state ( AVFormatContext s)

Store current parser state and file position.

This function can be used by demuxers before a destructive seeking algorithm to store the parser state. Depending on the outcome of the seek, either the original state can be restored or the new state kept and the original state freed.

Note
As a side effect, the original parser state is reset, since structures are relinked to the stored state instead of being deeply-copied (for performance reasons and to keep the code simple).
Parameters
scontext from which to save state
Returns
parser state object or NULL if memory could not be allocated

Definition at line 394 of file seek.c.

void ff_restore_parser_state ( AVFormatContext s,
AVParserState state 
)

Restore previously saved parser state and file position.

Saved state will be invalidated and freed by this call, since internal structures will be relinked back to the stored state instead of being deeply-copied.

Parameters
scontext to which to restore state (same as used for storing state)
statestate to restore

Definition at line 444 of file seek.c.

static void free_packet_list ( AVPacketList pktl)
static

Definition at line 478 of file seek.c.

Referenced by ff_free_parser_state().

void ff_free_parser_state ( AVFormatContext s,
AVParserState state 
)

Free previously saved parser state.

Parameters
scontext to which the state belongs (same as used for storing state)
statestate to free

Definition at line 489 of file seek.c.