#define PROBE_BUF_MIN 2048
#define PROBE_BUF_MAX (1 << 20)
-#define MAX_PROBE_PACKETS 2500
-
#ifdef DEBUG
# define hex_dump_debug(class, buf, size) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size)
#else
* not decoded, for example to get the codec parameters in MPEG
* streams.
*/
- struct AVPacketList *packet_buffer;
- struct AVPacketList *packet_buffer_end;
+ struct PacketList *packet_buffer;
+ struct PacketList *packet_buffer_end;
/* av_seek_frame() support */
int64_t data_offset; /**< offset of the first packet */
* be identified, as parsing cannot be done without knowing the
* codec.
*/
- struct AVPacketList *raw_packet_buffer;
- struct AVPacketList *raw_packet_buffer_end;
+ struct PacketList *raw_packet_buffer;
+ struct PacketList *raw_packet_buffer_end;
/**
* Packets split by the parser get queued here.
*/
- struct AVPacketList *parse_queue;
- struct AVPacketList *parse_queue_end;
+ struct PacketList *parse_queue;
+ struct PacketList *parse_queue_end;
+ /**
+ * The generic code uses this as a temporary packet
+ * to parse packets; it may also be used for other means
+ * for short periods that are guaranteed not to overlap
+ * with calls to av_read_frame() (or ff_read_packet())
+ * or with each other.
+ * It may be used by demuxers as a replacement for
+ * stack packets (unless they call one of the aforementioned
+ * functions with their own AVFormatContext).
+ * Every user has to ensure that this packet is blank
+ * after using it.
+ */
+ AVPacket *parse_pkt;
+
+ /**
+ * Used to hold temporary packets.
+ */
+ AVPacket *pkt;
/**
* Remaining size available for raw_packet_buffer, in bytes.
*/
* Prefer the codec framerate for avg_frame_rate computation.
*/
int prefer_codec_framerate;
+
+ /**
+ * Set if chapter ids are strictly monotonic.
+ */
+ int chapter_ids_monotonic;
};
struct AVStreamInternal {
int reorder;
/**
- * bitstream filters to run on stream
+ * bitstream filter to run on stream
* - encoding: Set by muxer using ff_stream_add_bitstream_filter
* - decoding: unused
*/
- AVBSFContext **bsfcs;
- int nb_bsfcs;
+ AVBSFContext *bsfc;
/**
* Whether or not check_bitstream should still be run on each packet
* supported) */
struct {
AVBSFContext *bsf;
- AVPacket *pkt;
int inited;
} extract_extradata;
*/
int need_context_update;
+ int is_intra_only;
+
FFFrac *priv_pts;
+
+#define MAX_STD_TIMEBASES (30*12+30+3+6)
+ /**
+ * Stream information used internally by avformat_find_stream_info()
+ */
+ struct {
+ int64_t last_dts;
+ int64_t duration_gcd;
+ int duration_count;
+ int64_t rfps_duration_sum;
+ double (*duration_error)[2][MAX_STD_TIMEBASES];
+ int64_t codec_info_duration;
+ int64_t codec_info_duration_fields;
+ int frame_delay_evidence;
+
+ /**
+ * 0 -> decoder has not been searched for yet.
+ * >0 -> decoder found
+ * <0 -> decoder with codec_id == -found_decoder has not been found
+ */
+ int found_decoder;
+
+ int64_t last_duration;
+
+ /**
+ * Those are used for average framerate estimation.
+ */
+ int64_t fps_first_dts;
+ int fps_first_dts_idx;
+ int64_t fps_last_dts;
+ int fps_last_dts_idx;
+
+ } *info;
+
+ AVIndexEntry *index_entries; /**< Only used if the format does not
+ support seeking natively. */
+ int nb_index_entries;
+ unsigned int index_entries_allocated_size;
+
+ int64_t interleaver_chunk_size;
+ int64_t interleaver_chunk_duration;
+
+ /**
+ * stream probing state
+ * -1 -> probing finished
+ * 0 -> no probing requested
+ * rest -> perform probing with request_probe being the minimum score to accept.
+ */
+ int request_probe;
+ /**
+ * Indicates that everything up to the next keyframe
+ * should be discarded.
+ */
+ int skip_to_keyframe;
+
+ /**
+ * Number of samples to skip at the start of the frame decoded from the next packet.
+ */
+ int skip_samples;
+
+ /**
+ * If not 0, the number of samples that should be skipped from the start of
+ * the stream (the samples are removed from packets with pts==0, which also
+ * assumes negative timestamps do not happen).
+ * Intended for use with formats such as mp3 with ad-hoc gapless audio
+ * support.
+ */
+ int64_t start_skip_samples;
+
+ /**
+ * If not 0, the first audio sample that should be discarded from the stream.
+ * This is broken by design (needs global sample count), but can't be
+ * avoided for broken by design formats such as mp3 with ad-hoc gapless
+ * audio support.
+ */
+ int64_t first_discard_sample;
+
+ /**
+ * The sample after last sample that is intended to be discarded after
+ * first_discard_sample. Works on frame boundaries only. Used to prevent
+ * early EOF if the gapless info is broken (considered concatenated mp3s).
+ */
+ int64_t last_discard_sample;
+
+ /**
+ * Number of internally decoded frames, used internally in libavformat, do not access
+ * its lifetime differs from info which is why it is not in that structure.
+ */
+ int nb_decoded_frames;
+
+ /**
+ * Timestamp offset added to timestamps before muxing
+ */
+ int64_t mux_ts_offset;
+
+ /**
+ * Internal data to check for wrapping of the time stamp
+ */
+ int64_t pts_wrap_reference;
+
+ /**
+ * Options for behavior, when a wrap is detected.
+ *
+ * Defined by AV_PTS_WRAP_ values.
+ *
+ * If correction is enabled, there are two possibilities:
+ * If the first time stamp is near the wrap point, the wrap offset
+ * will be subtracted, which will create negative time stamps.
+ * Otherwise the offset will be added.
+ */
+ int pts_wrap_behavior;
+
+ /**
+ * Internal data to prevent doing update_initial_durations() twice
+ */
+ int update_initial_durations_done;
+
+#define MAX_REORDER_DELAY 16
+
+ /**
+ * Internal data to generate dts from pts
+ */
+ int64_t pts_reorder_error[MAX_REORDER_DELAY+1];
+ uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1];
+
+ int64_t pts_buffer[MAX_REORDER_DELAY+1];
+
+ /**
+ * Internal data to analyze DTS and detect faulty mpeg streams
+ */
+ int64_t last_dts_for_order_check;
+ uint8_t dts_ordered;
+ uint8_t dts_misordered;
+
+ /**
+ * Internal data to inject global side data
+ */
+ int inject_global_side_data;
+
+ /**
+ * display aspect ratio (0 if unknown)
+ * - encoding: unused
+ * - decoding: Set by libavformat to calculate sample_aspect_ratio internally
+ */
+ AVRational display_aspect_ratio;
+
+ AVProbeData probe_data;
+
+ /**
+ * last packet in packet_buffer for this stream when muxing.
+ */
+ struct PacketList *last_in_packet_buffer;
};
#ifdef __GNUC__
} while(0)
#endif
-struct tm *ff_brktimegm(time_t secs, struct tm *tm);
+/**
+ * Automatically create sub-directories
+ *
+ * @param path will create sub-directories by path
+ * @return 0, or < 0 on error
+ */
+int ff_mkdir_p(const char *path);
char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
int ff_hex_to_data(uint8_t *data, const char *p);
/**
- * Add packet to AVFormatContext->packet_buffer list, determining its
+ * Add packet to an AVFormatContext's packet_buffer list, determining its
* interleaved position using compare() function argument.
- * @return 0, or < 0 on error
+ * @return 0 on success, < 0 on error. pkt will always be blank on return.
*/
int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
- int (*compare)(AVFormatContext *, AVPacket *, AVPacket *));
+ int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *));
void ff_read_frame_flush(AVFormatContext *s);
*/
uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us);
+/**
+ * Parse the NTP time in micro seconds (since NTP epoch).
+ *
+ * @param ntp_ts NTP time stamp formatted as per the RFC-5905.
+ * @return the time in micro seconds (since NTP epoch)
+ */
+uint64_t ff_parse_ntp_time(uint64_t ntp_ts);
+
/**
* Append the media-specific SDP fragment for the media stream c
* to the buffer buff.
int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
AVFormatContext *src, int interleave);
-/**
- * Get the length in bytes which is needed to store val as v.
- */
-int ff_get_v_length(uint64_t val);
-
-/**
- * Put val using a variable number of bytes.
- */
-void ff_put_v(AVIOContext *bc, uint64_t val);
-
/**
* Read a whole line of text from AVIOContext. Stop reading after reaching
* either a \\n, a \\0 or EOF. The returned string is always \\0-terminated,
*
* @return AVChapter or NULL on error
*/
-AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base,
+AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base,
int64_t start, int64_t end, const char *title);
/**
int ff_read_packet(AVFormatContext *s, AVPacket *pkt);
/**
- * Interleave a packet per dts in an output media file.
+ * Add an attached pic to an AVStream.
*
- * Packets with pkt->destruct == av_destruct_packet will be freed inside this
- * function, so they cannot be used after it. Note that calling av_packet_unref()
- * on them is still safe.
+ * @param st if set, the stream to add the attached pic to;
+ * if unset, a new stream will be added to s.
+ * @param pb AVIOContext to read data from if buf is unset.
+ * @param buf if set, it contains the data and size information to be used
+ * for the attached pic; if unset, data is read from pb.
+ * @param size the size of the data to read if buf is unset.
*
- * @param s media file handle
+ * @return 0 on success, < 0 on error. On error, this function removes
+ * the stream it has added (if any).
+ */
+int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
+ AVBufferRef **buf, int size);
+
+/**
+ * Interleave an AVPacket per dts so it can be muxed.
+ *
+ * @param s an AVFormatContext for output. pkt resp. out will be added to
+ * resp. taken from its packet buffer.
* @param out the interleaved packet will be output here
- * @param pkt the input packet
+ * @param pkt the input packet; will be blank on return if not NULL
* @param flush 1 if no further packets are available as input and all
* remaining packets should be output
- * @return 1 if a packet was output, 0 if no packet could be output,
- * < 0 if an error occurred
+ * @return 1 if a packet was output, 0 if no packet could be output
+ * (in which case out may be uninitialized), < 0 if an error occurred
*/
int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
AVPacket *pkt, int flush);
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag);
+int ff_is_intra_only(enum AVCodecID id);
+
/**
* Select a PCM codec based on the given parameters.
*
int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
/**
- * Wrap errno on rename() error.
+ * Wrap avpriv_io_move and log if error happens.
*
- * @param oldpath source path
- * @param newpath destination path
+ * @param url_src source path
+ * @param url_dst destination path
* @return 0 or AVERROR on failure
*/
-static inline int ff_rename(const char *oldpath, const char *newpath, void *logctx)
-{
- int ret = 0;
- if (rename(oldpath, newpath) == -1) {
- ret = AVERROR(errno);
- if (logctx) {
- char err[AV_ERROR_MAX_STRING_SIZE] = {0};
- av_make_error_string(err, AV_ERROR_MAX_STRING_SIZE, ret);
- av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", oldpath, newpath, err);
- }
- }
- return ret;
-}
+int ff_rename(const char *url_src, const char *url_dst, void *logctx);
/**
* Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end
*/
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src);
-int ffio_open2_wrapper(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags,
- const AVIOInterruptCB *int_cb, AVDictionary **options);
-
/**
* Returned by demuxers to indicate that data was consumed but discarded
* (ignored streams or junk data). The framework will re-call the demuxer.
/**
* Find the next packet in the interleaving queue for the given stream.
- * The pkt parameter is filled in with the queued packet, including
- * references to the data (which the caller is not allowed to keep or
- * modify).
*
- * @return 0 if a packet was found, a negative value if no packet was found
+ * @return a pointer to a packet if one was found, NULL otherwise.
*/
-int ff_interleaved_peek(AVFormatContext *s, int stream,
- AVPacket *pkt, int add_offset);
+const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);
+int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset);
int ff_lock_avformat(void);
int ff_unlock_avformat(void);
*/
void ff_format_set_url(AVFormatContext *s, char *url);
-#define FF_PACKETLIST_FLAG_REF_PACKET (1 << 0) /**< Create a new reference for the packet instead of
- transferring the ownership of the existing one to the
- list. */
-
-/**
- * Append an AVPacket to the list.
- *
- * @param head List head element
- * @param tail List tail element
- * @param pkt The packet being appended
- * @param flags Any combination of FF_PACKETLIST_FLAG_* flags
- * @return 0 on success, negative AVERROR value on failure. On failure,
- the list is unchanged
- */
-int ff_packet_list_put(AVPacketList **head, AVPacketList **tail,
- AVPacket *pkt, int flags);
-
-/**
- * Remove the oldest AVPacket in the list and return it.
- *
- * @note The pkt will be overwritten completely. The caller owns the
- * packet and must unref it by itself.
- *
- * @param head List head element
- * @param tail List tail element
- * @param pkt Pointer to an initialized AVPacket struct
- */
-int ff_packet_list_get(AVPacketList **head, AVPacketList **tail,
- AVPacket *pkt);
-
-/**
- * Wipe the list and unref all the packets in it.
- *
- * @param head List head element
- * @param tail List tail element
- */
-void ff_packet_list_free(AVPacketList **head, AVPacketList **tail);
-
void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputFormat * const i[]);
#endif /* AVFORMAT_INTERNAL_H */