diff options
Diffstat (limited to 'libavformat/internal.h')
-rw-r--r-- | libavformat/internal.h | 190 |
1 files changed, 169 insertions, 21 deletions
diff --git a/libavformat/internal.h b/libavformat/internal.h index ed9893033a..bc6a6c2716 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -1,20 +1,20 @@ /* * copyright (c) 2001 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -27,10 +27,16 @@ #define MAX_URL_SIZE 4096 +/** size of probe buffer, for guessing file type from file contents */ +#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 -# define hex_dump_debug(class, buf, size) +# define hex_dump_debug(class, buf, size) do { if (0) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size); } while(0) #endif typedef struct AVCodecTag { @@ -43,6 +49,18 @@ typedef struct CodecMime{ enum AVCodecID id; } CodecMime; +/*************************************************/ +/* fractional numbers for exact pts handling */ + +/** + * The exact value of the fractional number is: 'val + num / den'. + * num is assumed to be 0 <= num < den. + */ +typedef struct FFFrac { + int64_t val, num, den; +} FFFrac; + + struct AVFormatInternal { /** * Number of streams relevant for interleaving. @@ -83,6 +101,7 @@ struct AVFormatInternal { /** * Offset to remap timestamps to be non-negative. * Expressed in timebase units. + * @see AVStream.mux_ts_offset */ int64_t offset; @@ -94,6 +113,15 @@ struct AVFormatInternal { #if FF_API_COMPUTE_PKT_FIELDS2 int missing_ts_warning; #endif + + int inject_global_side_data; + + int avoid_negative_ts_use_pts; + + /** + * Whether or not a header has already been written + */ + int header_written; }; struct AVStreamInternal { @@ -102,9 +130,19 @@ struct AVStreamInternal { * from dts. */ int reorder; -}; -void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem); + /** + * bitstream filter to run on stream + * - encoding: Set by muxer using ff_stream_add_bitstream_filter + * - decoding: unused + */ + AVBitStreamFilterContext *bsfc; + + /** + * Whether or not check_bitstream should still be run on each packet + */ + int bitstream_checked; +}; #ifdef __GNUC__ #define dynarray_add(tab, nb_ptr, elem)\ @@ -112,12 +150,12 @@ do {\ __typeof__(tab) _tab = (tab);\ __typeof__(elem) _elem = (elem);\ (void)sizeof(**_tab == _elem); /* check that types are compatible */\ - ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\ + av_dynarray_add(_tab, nb_ptr, _elem);\ } while(0) #else #define dynarray_add(tab, nb_ptr, elem)\ do {\ - ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\ + av_dynarray_add((tab), nb_ptr, (elem));\ } while(0) #endif @@ -135,11 +173,10 @@ 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); -void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx); - /** * Add packet to AVFormatContext->packet_buffer list, determining its * interleaved position using compare() function argument. + * @return 0, or < 0 on error */ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, AVPacket *, AVPacket *)); @@ -183,10 +220,11 @@ void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, * @param dst_stream the stream index within dst to write the packet to * @param pkt the packet to be written * @param src the muxer the packet originally was intended for + * @param interleave 0->use av_write_frame, 1->av_interleaved_write_frame * @return the value av_write_frame returned */ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, - AVFormatContext *src); + AVFormatContext *src, int interleave); /** * Get the length in bytes which is needed to store val as v. @@ -257,6 +295,8 @@ int ff_add_index_entry(AVIndexEntry **index_entries, unsigned int *index_entries_allocated_size, int64_t pos, int64_t timestamp, int size, int distance, int flags); +void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance); + /** * Add a new chapter. * @@ -281,11 +321,6 @@ void ff_reduce_index(AVFormatContext *s, int stream_index); enum AVCodecID ff_guess_image2_codec(const char *filename); /** - * Convert a date string in ISO8601 format to Unix timestamp. - */ -int64_t ff_iso8601_to_unix_time(const char *datestr); - -/** * Perform a binary search using av_index_search_timestamp() and * AVInputFormat.read_timestamp(). * @@ -305,6 +340,9 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, */ void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp); +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 )); + /** * Perform a binary search using read_timestamp(). * @@ -374,6 +412,8 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt); int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush); +void ff_free_stream(AVFormatContext *s, AVStream *st); + /** * Return the frame duration in seconds. Return 0 if not available. */ @@ -400,29 +440,137 @@ enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag); enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags); /** + * Chooses a timebase for muxing the specified stream. + * + * The chosen timebase allows sample accurate timestamps based + * on the framerate or sample rate for audio streams. It also is + * at least as precise as 1/min_precision would be. + */ +AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precision); + +/** + * Chooses a timebase for muxing the specified stream. + */ +enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream *st); + +/** * Generate standard extradata for AVC-Intra based on width/height and field * order. */ int ff_generate_avci_extradata(AVStream *st); /** + * Add a bitstream filter to a stream. + * + * @param st output stream to add a filter to + * @param name the name of the filter to add + * @param args filter-specific argument string + * @return >0 on success; + * AVERROR code on failure + */ +int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args); + +/** * Wrap errno on rename() error. * * @param oldpath source path * @param newpath destination path * @return 0 or AVERROR on failure */ -static inline int ff_rename(const char *oldpath, const char *newpath) +static inline int ff_rename(const char *oldpath, const char *newpath, void *logctx) { - if (rename(oldpath, newpath) == -1) - return AVERROR(errno); - return 0; + int ret = 0; + if (rename(oldpath, newpath) == -1) { + ret = AVERROR(errno); + if (logctx) + av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s\n", oldpath, newpath); + } + return ret; } /** + * Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end + * which is always set to 0. + * + * @param size size of extradata + * @return 0 if OK, AVERROR_xxx on error + */ +int ff_alloc_extradata(AVCodecContext *avctx, int size); + +/** + * Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end + * which is always set to 0 and fill it from pb. + * + * @param size size of extradata + * @return >= 0 if OK, AVERROR_xxx on error + */ +int ff_get_extradata(AVCodecContext *avctx, AVIOContext *pb, int size); + +/** + * add frame for rfps calculation. + * + * @param dts timestamp of the i-th frame + * @return 0 if OK, AVERROR_xxx on error + */ +int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t dts); + +void ff_rfps_calculate(AVFormatContext *ic); + +/** + * Flags for AVFormatContext.write_uncoded_frame() + */ +enum AVWriteUncodedFrameFlags { + + /** + * Query whether the feature is possible on this stream. + * The frame argument is ignored. + */ + AV_WRITE_UNCODED_FRAME_QUERY = 0x0001, + +}; + +/** + * Copies the whilelists from one context to the other + */ +int ff_copy_whitelists(AVFormatContext *dst, 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. + */ +#define FFERROR_REDO FFERRTAG('R','E','D','O') + +/* * A wrapper around AVFormatContext.io_close that should be used * intead of calling the pointer directly. */ void ff_format_io_close(AVFormatContext *s, AVIOContext **pb); +/** + * Parse creation_time in AVFormatContext metadata if exists and warn if the + * parsing fails. + * + * @param s AVFormatContext + * @param timestamp parsed timestamp in microseconds, only set on successful parsing + * @param return_seconds set this to get the number of seconds in timestamp instead of microseconds + * @return 1 if OK, 0 if the metadata was not present, AVERROR(EINVAL) on parse error + */ +int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds); + + +#define CONTAINS_PAL 2 +/** + * Reshuffles the lines to use the user specified stride. + * + * @param ppkt input and output packet + * @return negative error code or + * 0 if no new packet was allocated + * non-zero if a new packet was allocated and ppkt has to be freed + * CONTAINS_PAL if in addition to a new packet the old contained a palette + */ +int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *enc, int expected_stride); + #endif /* AVFORMAT_INTERNAL_H */ |