FFmpeg
Macros | Functions | Variables
demux.c File Reference
#include <stdint.h>
#include "config_components.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/dict.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/pixfmt.h"
#include "libavutil/time.h"
#include "libavutil/timestamp.h"
#include "libavcodec/bsf.h"
#include "libavcodec/internal.h"
#include "libavcodec/packet_internal.h"
#include "libavcodec/raw.h"
#include "avformat.h"
#include "avio_internal.h"
#include "demux.h"
#include "id3v2.h"
#include "internal.h"
#include "url.h"

Go to the source code of this file.

Macros

#define DURATION_MAX_READ_SIZE   250000LL
 
#define DURATION_MAX_RETRY   6
 
#define FAIL(errmsg)
 

Functions

static int64_t wrap_timestamp (const AVStream *st, int64_t 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. More...
 
static const AVCodecfind_probe_decoder (AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
 
static int set_codec_from_probe_data (AVFormatContext *s, AVStream *st, AVProbeData *pd)
 
static int init_input (AVFormatContext *s, const char *filename, AVDictionary **options)
 
static int update_stream_avctx (AVFormatContext *s)
 
int avformat_open_input (AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options)
 Open an input stream and read the header. More...
 
void avformat_close_input (AVFormatContext **ps)
 Close an opened input AVFormatContext. More...
 
static void force_codec_ids (AVFormatContext *s, AVStream *st)
 
static int probe_codec (AVFormatContext *s, AVStream *st, const AVPacket *pkt)
 
static int update_wrap_reference (AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt)
 
int ff_read_packet (AVFormatContext *s, AVPacket *pkt)
 Read a transport packet from a media file. More...
 
static void compute_frame_duration (AVFormatContext *s, int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt)
 Return the frame duration in seconds. More...
 
static int has_decode_delay_been_guessed (AVStream *st)
 
static PacketListEntryget_next_pkt (AVFormatContext *s, AVStream *st, PacketListEntry *pktl)
 
static int64_t select_from_pts_buffer (AVStream *st, int64_t *pts_buffer, int64_t dts)
 
static void update_dts_from_pts (AVFormatContext *s, int stream_index, PacketListEntry *pkt_buffer)
 Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts of the packets in a window. More...
 
static void update_initial_timestamps (AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt)
 
static void update_initial_durations (AVFormatContext *s, AVStream *st, int stream_index, int64_t duration)
 
static void compute_pkt_fields (AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt, int64_t next_dts, int64_t next_pts)
 
static int parse_packet (AVFormatContext *s, AVPacket *pkt, int stream_index, int flush)
 Parse a packet, add all split parts to parse_queue. More...
 
static int64_t ts_to_samples (AVStream *st, int64_t ts)
 
static int read_frame_internal (AVFormatContext *s, AVPacket *pkt)
 
int av_read_frame (AVFormatContext *s, AVPacket *pkt)
 Return the next frame of a stream. More...
 
static int has_duration (AVFormatContext *ic)
 Return TRUE if the stream has accurate duration in any stream. More...
 
static void update_stream_timings (AVFormatContext *ic)
 Estimate the stream timings from the one of each components. More...
 
static void fill_all_stream_timings (AVFormatContext *ic)
 
static void estimate_timings_from_bit_rate (AVFormatContext *ic)
 
static void estimate_timings_from_pts (AVFormatContext *ic, int64_t old_offset)
 
static const char * duration_estimate_name (enum AVDurationEstimationMethod method)
 
static void estimate_timings (AVFormatContext *ic, int64_t old_offset)
 
static int determinable_frame_size (const AVCodecContext *avctx)
 
static int has_codec_parameters (const AVStream *st, const char **errmsg_ptr)
 
static int try_decode_frame (AVFormatContext *s, AVStream *st, const AVPacket *avpkt, AVDictionary **options)
 
static int chapter_start_cmp (const void *p1, const void *p2)
 
static int compute_chapters_end (AVFormatContext *s)
 
static int get_std_framerate (int i)
 
static int tb_unreliable (AVCodecContext *c)
 
int ff_rfps_add_frame (AVFormatContext *ic, AVStream *st, int64_t ts)
 add frame for rfps calculation. More...
 
void ff_rfps_calculate (AVFormatContext *ic)
 
static int extract_extradata_check (AVStream *st)
 
static int extract_extradata_init (AVStream *st)
 
static int extract_extradata (FFFormatContext *si, AVStream *st, const AVPacket *pkt)
 
static int add_coded_side_data (AVStream *st, AVCodecContext *avctx)
 
int avformat_find_stream_info (AVFormatContext *ic, AVDictionary **options)
 Read packets of a media file to get stream information. More...
 

Variables

static const char *const duration_name []
 

Macro Definition Documentation

◆ DURATION_MAX_READ_SIZE

#define DURATION_MAX_READ_SIZE   250000LL

Definition at line 1719 of file demux.c.

◆ DURATION_MAX_RETRY

#define DURATION_MAX_RETRY   6

Definition at line 1720 of file demux.c.

◆ FAIL

#define FAIL (   errmsg)
Value:
do { \
if (errmsg_ptr) \
*errmsg_ptr = errmsg; \
return 0; \
} while (0)

Function Documentation

◆ wrap_timestamp()

static int64_t wrap_timestamp ( const AVStream st,
int64_t  timestamp 
)
static

Definition at line 49 of file demux.c.

Referenced by ff_read_packet(), and ff_wrap_timestamp().

◆ 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().

◆ find_probe_decoder()

static const AVCodec* find_probe_decoder ( AVFormatContext s,
const AVStream st,
enum AVCodecID  codec_id 
)
static

Definition at line 69 of file demux.c.

Referenced by avformat_find_stream_info(), and try_decode_frame().

◆ set_codec_from_probe_data()

static int set_codec_from_probe_data ( AVFormatContext s,
AVStream st,
AVProbeData pd 
)
static

Definition at line 99 of file demux.c.

Referenced by probe_codec().

◆ init_input()

static int init_input ( AVFormatContext s,
const char *  filename,
AVDictionary **  options 
)
static

Definition at line 151 of file demux.c.

Referenced by avformat_open_input().

◆ update_stream_avctx()

static int update_stream_avctx ( AVFormatContext s)
static

Definition at line 182 of file demux.c.

Referenced by avformat_open_input().

◆ force_codec_ids()

static void force_codec_ids ( AVFormatContext s,
AVStream st 
)
static

Definition at line 394 of file demux.c.

Referenced by ff_read_packet(), and probe_codec().

◆ probe_codec()

static int probe_codec ( AVFormatContext s,
AVStream st,
const AVPacket pkt 
)
static

Definition at line 416 of file demux.c.

Referenced by ff_read_packet(), and find_probe_decoder().

◆ update_wrap_reference()

static int update_wrap_reference ( AVFormatContext s,
AVStream st,
int  stream_index,
AVPacket pkt 
)
static

Definition at line 469 of file demux.c.

Referenced by ff_read_packet().

◆ 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().

◆ compute_frame_duration()

static void compute_frame_duration ( AVFormatContext s,
int pnum,
int pden,
AVStream st,
AVCodecParserContext pc,
AVPacket pkt 
)
static

Return the frame duration in seconds.

Return 0 if not available.

Definition at line 655 of file demux.c.

Referenced by compute_pkt_fields(), and estimate_timings_from_pts().

◆ has_decode_delay_been_guessed()

static int has_decode_delay_been_guessed ( AVStream st)
static

◆ get_next_pkt()

static PacketListEntry* get_next_pkt ( AVFormatContext s,
AVStream st,
PacketListEntry pktl 
)
static

◆ select_from_pts_buffer()

static int64_t select_from_pts_buffer ( AVStream st,
int64_t *  pts_buffer,
int64_t  dts 
)
static

Definition at line 741 of file demux.c.

Referenced by compute_pkt_fields(), and update_dts_from_pts().

◆ update_dts_from_pts()

static void update_dts_from_pts ( AVFormatContext s,
int  stream_index,
PacketListEntry pkt_buffer 
)
static

Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts of the packets in a window.

Definition at line 788 of file demux.c.

Referenced by avformat_find_stream_info(), and update_initial_timestamps().

◆ update_initial_timestamps()

static void update_initial_timestamps ( AVFormatContext s,
int  stream_index,
int64_t  dts,
int64_t  pts,
AVPacket pkt 
)
static

Definition at line 813 of file demux.c.

Referenced by compute_pkt_fields().

◆ update_initial_durations()

static void update_initial_durations ( AVFormatContext s,
AVStream st,
int  stream_index,
int64_t  duration 
)
static

Definition at line 866 of file demux.c.

Referenced by compute_pkt_fields().

◆ compute_pkt_fields()

static void compute_pkt_fields ( AVFormatContext s,
AVStream st,
AVCodecParserContext pc,
AVPacket pkt,
int64_t  next_dts,
int64_t  next_pts 
)
static

Definition at line 925 of file demux.c.

Referenced by parse_packet(), and read_frame_internal().

◆ parse_packet()

static int parse_packet ( AVFormatContext s,
AVPacket pkt,
int  stream_index,
int  flush 
)
static

Parse a packet, add all split parts to parse_queue.

Parameters
pktPacket to parse; must not be NULL.
flushIndicates whether to flush. If set, pkt must be blank.

Definition at line 1118 of file demux.c.

Referenced by read_frame_internal().

◆ ts_to_samples()

static int64_t ts_to_samples ( AVStream st,
int64_t  ts 
)
static

Definition at line 1228 of file demux.c.

Referenced by read_frame_internal().

◆ read_frame_internal()

static int read_frame_internal ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1233 of file demux.c.

Referenced by av_read_frame(), and avformat_find_stream_info().

◆ has_duration()

static int has_duration ( AVFormatContext ic)
static

Return TRUE if the stream has accurate duration in any stream.

Returns
TRUE if the stream has accurate duration for at least one component.

Definition at line 1538 of file demux.c.

Referenced by estimate_timings().

◆ update_stream_timings()

static void update_stream_timings ( AVFormatContext ic)
static

Estimate the stream timings from the one of each components.

Also computes the global bitrate if possible.

Definition at line 1555 of file demux.c.

Referenced by estimate_timings(), and fill_all_stream_timings().

◆ fill_all_stream_timings()

static void fill_all_stream_timings ( AVFormatContext ic)
static

Definition at line 1649 of file demux.c.

Referenced by estimate_timings(), and estimate_timings_from_pts().

◆ estimate_timings_from_bit_rate()

static void estimate_timings_from_bit_rate ( AVFormatContext ic)
static

Definition at line 1666 of file demux.c.

Referenced by estimate_timings().

◆ estimate_timings_from_pts()

static void estimate_timings_from_pts ( AVFormatContext ic,
int64_t  old_offset 
)
static

Definition at line 1723 of file demux.c.

Referenced by estimate_timings().

◆ duration_estimate_name()

static const char* duration_estimate_name ( enum AVDurationEstimationMethod  method)
static

Definition at line 1869 of file demux.c.

Referenced by estimate_timings().

◆ estimate_timings()

static void estimate_timings ( AVFormatContext ic,
int64_t  old_offset 
)
static

Definition at line 1874 of file demux.c.

Referenced by avformat_find_stream_info().

◆ determinable_frame_size()

static int determinable_frame_size ( const AVCodecContext avctx)
static

Definition at line 1923 of file demux.c.

Referenced by has_codec_parameters().

◆ has_codec_parameters()

static int has_codec_parameters ( const AVStream st,
const char **  errmsg_ptr 
)
static

Definition at line 1936 of file demux.c.

Referenced by avformat_find_stream_info(), and try_decode_frame().

◆ try_decode_frame()

static int try_decode_frame ( AVFormatContext s,
AVStream st,
const AVPacket avpkt,
AVDictionary **  options 
)
static

Definition at line 1985 of file demux.c.

Referenced by avformat_find_stream_info().

◆ chapter_start_cmp()

static int chapter_start_cmp ( const void *  p1,
const void *  p2 
)
static

Definition at line 2087 of file demux.c.

Referenced by compute_chapters_end().

◆ compute_chapters_end()

static int compute_chapters_end ( AVFormatContext s)
static

Definition at line 2097 of file demux.c.

Referenced by avformat_find_stream_info().

◆ get_std_framerate()

static int get_std_framerate ( int  i)
static

Definition at line 2134 of file demux.c.

Referenced by avformat_find_stream_info(), ff_rfps_add_frame(), and ff_rfps_calculate().

◆ tb_unreliable()

static int tb_unreliable ( AVCodecContext c)
static

Definition at line 2158 of file demux.c.

Referenced by avformat_find_stream_info(), and ff_rfps_calculate().

◆ 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().

◆ extract_extradata_check()

static int extract_extradata_check ( AVStream st)
static

Definition at line 2298 of file demux.c.

Referenced by avformat_find_stream_info(), and extract_extradata_init().

◆ extract_extradata_init()

static int extract_extradata_init ( AVStream st)
static

Definition at line 2314 of file demux.c.

Referenced by extract_extradata().

◆ extract_extradata()

static int extract_extradata ( FFFormatContext si,
AVStream st,
const AVPacket pkt 
)
static

Definition at line 2353 of file demux.c.

Referenced by avformat_find_stream_info().

◆ add_coded_side_data()

static int add_coded_side_data ( AVStream st,
AVCodecContext avctx 
)
static

Definition at line 2402 of file demux.c.

Referenced by avformat_find_stream_info().

Variable Documentation

◆ duration_name

const char* const duration_name[]
static
Initial value:

Definition at line 1863 of file demux.c.

Referenced by duration_estimate_name().

AVFMT_DURATION_FROM_BITRATE
@ AVFMT_DURATION_FROM_BITRATE
Duration estimated from bitrate (less accurate)
Definition: avformat.h:1196
AVFMT_DURATION_FROM_PTS
@ AVFMT_DURATION_FROM_PTS
Duration accurately estimated from PTSes.
Definition: avformat.h:1194
AVFMT_DURATION_FROM_STREAM
@ AVFMT_DURATION_FROM_STREAM
Duration estimated from a stream with a known duration.
Definition: avformat.h:1195