FFmpeg
Data Structures | Macros | Functions
demux.h File Reference
#include <stdint.h>
#include "libavutil/rational.h"
#include "libavcodec/packet.h"
#include "avformat.h"

Go to the source code of this file.

Data Structures

struct  FFStreamInfo
 

Macros

#define MAX_STD_TIMEBASES   (30*12+30+3+6)
 
#define FFERROR_REDO   FFERRTAG('R','E','D','O')
 Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data). More...
 
#define RELATIVE_TS_BASE   (INT64_MAX - (1LL << 48))
 

Functions

static av_always_inline int is_relative (int64_t ts)
 
int64_t ff_wrap_timestamp (const AVStream *st, int64_t timestamp)
 Wrap a given time stamp, if there is an indication for an overflow. More...
 
int ff_read_packet (AVFormatContext *s, AVPacket *pkt)
 Read a transport packet from a media file. More...
 
void ff_read_frame_flush (AVFormatContext *s)
 Flush the frame reader. More...
 
int ff_seek_frame_binary (AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
 Perform a binary search using av_index_search_timestamp() and AVInputFormat.read_timestamp(). More...
 
void avpriv_update_cur_dts (AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
 Update cur_dts of all streams based on the given timestamp and AVStream. More...
 
int ff_find_last_ts (AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
 
int64_t ff_gen_search (AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
 Perform a binary search using read_timestamp(). More...
 
int ff_index_search_timestamp (const AVIndexEntry *entries, int nb_entries, int64_t wanted_timestamp, int flags)
 Internal version of av_index_search_timestamp. More...
 
int ff_add_index_entry (AVIndexEntry **index_entries, int *nb_index_entries, unsigned int *index_entries_allocated_size, int64_t pos, int64_t timestamp, int size, int distance, int flags)
 Internal version of av_add_index_entry. More...
 
void ff_configure_buffers_for_index (AVFormatContext *s, int64_t time_tolerance)
 
void ff_reduce_index (AVFormatContext *s, int stream_index)
 Ensure the index uses less memory than the maximum specified in AVFormatContext.max_index_size by discarding entries if it grows too large. More...
 
int ff_rfps_add_frame (AVFormatContext *ic, AVStream *st, int64_t dts)
 add frame for rfps calculation. More...
 
void ff_rfps_calculate (AVFormatContext *ic)
 
void ff_rescale_interval (AVRational tb_in, AVRational tb_out, int64_t *min_ts, int64_t *ts, int64_t *max_ts)
 Rescales a timestamp and the endpoints of an interval to which the temstamp belongs, from a timebase tb_in to a timebase tb_out. More...
 
void avpriv_stream_set_need_parsing (AVStream *st, enum AVStreamParseType type)
 
AVChapteravpriv_new_chapter (AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
 Add a new chapter. More...
 
int ff_add_attached_pic (AVFormatContext *s, AVStream *st, AVIOContext *pb, AVBufferRef **buf, int size)
 Add an attached pic to an AVStream. More...
 
int ff_add_param_change (AVPacket *pkt, int32_t channels, uint64_t channel_layout, int32_t sample_rate, int32_t width, int32_t height)
 Add side data to a packet for changing parameters to the given values. More...
 
int ff_generate_avci_extradata (AVStream *st)
 Generate standard extradata for AVC-Intra based on width/height and field order. More...
 
int ff_get_extradata (void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
 Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and fill it from pb. More...
 
int ff_find_stream_index (const AVFormatContext *s, int id)
 Find stream index based on format-specific stream ID. More...
 

Macro Definition Documentation

◆ MAX_STD_TIMEBASES

#define MAX_STD_TIMEBASES   (30*12+30+3+6)

Definition at line 29 of file demux.h.

◆ FFERROR_REDO

#define FFERROR_REDO   FFERRTAG('R','E','D','O')

Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).

The framework will re-call the demuxer.

Definition at line 62 of file demux.h.

◆ RELATIVE_TS_BASE

#define RELATIVE_TS_BASE   (INT64_MAX - (1LL << 48))

Definition at line 64 of file demux.h.

Function Documentation

◆ is_relative()

static av_always_inline int is_relative ( int64_t  ts)
static

◆ ff_wrap_timestamp()

int64_t ff_wrap_timestamp ( const AVStream st,
int64_t  timestamp 
)

Wrap a given time stamp, if there is an indication for an overflow.

Parameters
ststream
timestampthe time stamp to wrap
Returns
resulting time stamp

Definition at line 64 of file demux.c.

Referenced by av_add_index_entry(), and read_timestamp().

◆ ff_read_packet()

int ff_read_packet ( AVFormatContext s,
AVPacket pkt 
)

Read a transport packet from a media file.

Parameters
smedia file handle
pktis filled
Returns
0 if OK, AVERROR_xxx on error

Definition at line 537 of file demux.c.

Referenced by asfrtp_parse_packet(), estimate_timings_from_pts(), get_subtitle_pkt(), read_frame_internal(), read_gab2_sub(), and seek_subtitle().

◆ ff_read_frame_flush()

void ff_read_frame_flush ( AVFormatContext s)

◆ ff_seek_frame_binary()

int ff_seek_frame_binary ( AVFormatContext s,
int  stream_index,
int64_t  target_ts,
int  flags 
)

Perform a binary search using av_index_search_timestamp() and AVInputFormat.read_timestamp().

Parameters
target_tstarget timestamp in the time base of the given stream
stream_indexstream number

Definition at line 283 of file seek.c.

Referenced by asf_read_seek(), ogg_read_seek(), rm_read_seek(), and seek_frame_internal().

◆ avpriv_update_cur_dts()

void avpriv_update_cur_dts ( AVFormatContext s,
AVStream ref_st,
int64_t  timestamp 
)

Update cur_dts of all streams based on the given timestamp and AVStream.

Stream ref_st unchanged, others set cur_dts in their native time base. Only needed for timestamp wrapping or if (dts not set and pts!=dts).

Parameters
timestampnew dts expressed in time_base of param ref_st
ref_streference stream giving time_base of param timestamp

Definition at line 33 of file seek.c.

Referenced by aa_read_header(), aa_read_seek(), ff_seek_frame_binary(), idcin_read_seek(), mp3_seek(), mpc8_read_seek(), mxf_read_seek(), read_seek(), seek_frame_generic(), and vpk_read_seek().

◆ ff_find_last_ts()

int ff_find_last_ts ( AVFormatContext s,
int  stream_index,
int64_t *  ts,
int64_t *  pos,
int64_t(*)(struct AVFormatContext *, int, int64_t *, int64_t)  read_timestamp 
)

Definition at line 353 of file seek.c.

Referenced by ff_gen_search(), and find_duration().

◆ ff_gen_search()

int64_t ff_gen_search ( AVFormatContext s,
int  stream_index,
int64_t  target_ts,
int64_t  pos_min,
int64_t  pos_max,
int64_t  pos_limit,
int64_t  ts_min,
int64_t  ts_max,
int  flags,
int64_t *  ts_ret,
int64_t(*)(struct AVFormatContext *, int, int64_t *, int64_t)  read_timestamp 
)

Perform a binary search using read_timestamp().

Parameters
target_tstarget timestamp in the time base of the given stream
stream_indexstream number

Definition at line 391 of file seek.c.

Referenced by ff_seek_frame_binary(), and read_seek().

◆ ff_index_search_timestamp()

int ff_index_search_timestamp ( const AVIndexEntry entries,
int  nb_entries,
int64_t  wanted_timestamp,
int  flags 
)

Internal version of av_index_search_timestamp.

Definition at line 128 of file seek.c.

Referenced by av_index_search_timestamp(), avformat_index_get_entry_from_timestamp(), ff_add_index_entry(), mxf_read_seek(), and read_seek().

◆ ff_add_index_entry()

int ff_add_index_entry ( AVIndexEntry **  index_entries,
int nb_index_entries,
unsigned int index_entries_allocated_size,
int64_t  pos,
int64_t  timestamp,
int  size,
int  distance,
int  flags 
)

Internal version of av_add_index_entry.

Definition at line 60 of file seek.c.

Referenced by av_add_index_entry(), read_header(), and scan_file().

◆ ff_configure_buffers_for_index()

void ff_configure_buffers_for_index ( AVFormatContext s,
int64_t  time_tolerance 
)

Definition at line 171 of file seek.c.

Referenced by mov_read_header().

◆ ff_reduce_index()

void ff_reduce_index ( AVFormatContext s,
int  stream_index 
)

Ensure the index uses less memory than the maximum specified in AVFormatContext.max_index_size by discarding entries if it grows too large.

Definition at line 46 of file seek.c.

Referenced by av_read_frame(), mpegps_read_pes_header(), mpegts_get_dts(), and read_frame_internal().

◆ ff_rfps_add_frame()

int ff_rfps_add_frame ( AVFormatContext ic,
AVStream st,
int64_t  dts 
)

add frame for rfps calculation.

Parameters
dtstimestamp of the i-th frame
Returns
0 if OK, AVERROR_xxx on error

Definition at line 2173 of file demux.c.

Referenced by avformat_find_stream_info(), and mov_build_index().

◆ ff_rfps_calculate()

void ff_rfps_calculate ( AVFormatContext ic)

Definition at line 2234 of file demux.c.

Referenced by avformat_find_stream_info(), and mov_read_header().

◆ ff_rescale_interval()

void ff_rescale_interval ( AVRational  tb_in,
AVRational  tb_out,
int64_t *  min_ts,
int64_t *  ts,
int64_t *  max_ts 
)

Rescales a timestamp and the endpoints of an interval to which the temstamp belongs, from a timebase tb_in to a timebase tb_out.

The upper (lower) bound of the output interval is rounded up (down) such that the output interval always falls within the intput interval. The timestamp is rounded to the nearest integer and halfway cases away from zero, and can therefore fall outside of the output interval.

Useful to simplify the rescaling of the arguments of AVInputFormat::read_seek2()

Parameters
[in]tb_inTimebase of the input min_ts, ts and max_ts
[in]tb_outTimebase of the ouput min_ts, ts and max_ts
[in,out]min_tsLower bound of the interval
[in,out]tsTimestamp
[in,out]max_tsUpper bound of the interval

Definition at line 756 of file seek.c.

Referenced by imf_seek(), main(), real_seek(), and try_seek().

◆ avpriv_stream_set_need_parsing()

void avpriv_stream_set_need_parsing ( AVStream st,
enum AVStreamParseType  type 
)

Definition at line 37 of file demux_utils.c.

Referenced by v4l2_read_header().

◆ avpriv_new_chapter()

AVChapter* avpriv_new_chapter ( AVFormatContext s,
int64_t  id,
AVRational  time_base,
int64_t  start,
int64_t  end,
const char *  title 
)

Add a new chapter.

Parameters
smedia file handle
idunique ID for this chapter
startchapter start time in time_base units
endchapter end time in time_base units
titlechapter title
Returns
AVChapter or NULL on error

Definition at line 42 of file demux_utils.c.

Referenced by aa_read_header(), asf_read_marker(), concat_parse_script(), decode_info_header(), ff_id3v2_parse_chapters(), flac_read_header(), mov_metadata_hmmt(), mov_read_chapters(), mov_read_chpl(), ogm_chapter(), read_chapter(), and read_header().

◆ ff_add_attached_pic()

int ff_add_attached_pic ( AVFormatContext s,
AVStream st,
AVIOContext pb,
AVBufferRef **  buf,
int  size 
)

Add an attached pic to an AVStream.

Parameters
stif set, the stream to add the attached pic to; if unset, a new stream will be added to s.
pbAVIOContext to read data from if buf is unset.
bufif set, it contains the data and size information to be used for the attached pic; if unset, data is read from pb.
sizethe size of the data to read if buf is unset.
Returns
0 on success, < 0 on error. On error, this function removes the stream it has added (if any).

Definition at line 116 of file demux_utils.c.

Referenced by ape_tag_read_field(), asf_read_picture(), ff_flac_parse_picture(), ff_id3v2_parse_apic(), get_attachment(), mov_read_chapters(), and mov_read_covr().

◆ ff_add_param_change()

int ff_add_param_change ( AVPacket pkt,
int32_t  channels,
uint64_t  channel_layout,
int32_t  sample_rate,
int32_t  width,
int32_t  height 
)

Add side data to a packet for changing parameters to the given values.

Parameters set to 0 aren't included in the change.

Definition at line 151 of file demux_utils.c.

Referenced by flv_read_packet(), load_ipmovie_packet(), and swf_read_packet().

◆ ff_generate_avci_extradata()

int ff_generate_avci_extradata ( AVStream st)

Generate standard extradata for AVC-Intra based on width/height and field order.

Definition at line 220 of file demux_utils.c.

Referenced by mov_read_trak(), and mxf_parse_structural_metadata().

◆ ff_get_extradata()

int ff_get_extradata ( void *  logctx,
AVCodecParameters par,
AVIOContext pb,
int  size 
)

◆ ff_find_stream_index()

int ff_find_stream_index ( const AVFormatContext s,
int  id 
)

Find stream index based on format-specific stream ID.

Returns
stream index, or < 0 on error

Definition at line 371 of file demux_utils.c.

Referenced by get_sindex(), parse_chunks(), pmt_cb(), and scte_data_cb().