yading@11: /* yading@11: * copyright (c) 2001 Fabrice Bellard yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVFORMAT_INTERNAL_H yading@11: #define AVFORMAT_INTERNAL_H yading@11: yading@11: #include yading@11: #include "avformat.h" yading@11: yading@11: #define MAX_URL_SIZE 4096 yading@11: yading@11: #ifdef DEBUG yading@11: # define hex_dump_debug(class, buf, size) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size) yading@11: #else yading@11: # define hex_dump_debug(class, buf, size) yading@11: #endif yading@11: yading@11: typedef struct AVCodecTag { yading@11: enum AVCodecID id; yading@11: unsigned int tag; yading@11: } AVCodecTag; yading@11: yading@11: typedef struct CodecMime{ yading@11: char str[32]; yading@11: enum AVCodecID id; yading@11: } CodecMime; yading@11: yading@11: #ifdef __GNUC__ yading@11: #define dynarray_add(tab, nb_ptr, elem)\ yading@11: do {\ yading@11: __typeof__(tab) _tab = (tab);\ yading@11: __typeof__(elem) _elem = (elem);\ yading@11: (void)sizeof(**_tab == _elem); /* check that types are compatible */\ yading@11: av_dynarray_add(_tab, nb_ptr, _elem);\ yading@11: } while(0) yading@11: #else yading@11: #define dynarray_add(tab, nb_ptr, elem)\ yading@11: do {\ yading@11: av_dynarray_add((tab), nb_ptr, (elem));\ yading@11: } while(0) yading@11: #endif yading@11: yading@11: struct tm *ff_brktimegm(time_t secs, struct tm *tm); yading@11: yading@11: char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase); yading@11: yading@11: /** yading@11: * Parse a string of hexadecimal strings. Any space between the hexadecimal yading@11: * digits is ignored. yading@11: * yading@11: * @param data if non-null, the parsed data is written to this pointer yading@11: * @param p the string to parse yading@11: * @return the number of bytes written (or to be written, if data is null) yading@11: */ yading@11: int ff_hex_to_data(uint8_t *data, const char *p); yading@11: yading@11: void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx); yading@11: yading@11: /** yading@11: * Add packet to AVFormatContext->packet_buffer list, determining its yading@11: * interleaved position using compare() function argument. yading@11: * @return 0, or < 0 on error yading@11: */ yading@11: int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, yading@11: int (*compare)(AVFormatContext *, AVPacket *, AVPacket *)); yading@11: yading@11: void ff_read_frame_flush(AVFormatContext *s); yading@11: yading@11: #define NTP_OFFSET 2208988800ULL yading@11: #define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL) yading@11: yading@11: /** Get the current time since NTP epoch in microseconds. */ yading@11: uint64_t ff_ntp_time(void); yading@11: yading@11: /** yading@11: * Assemble a URL string from components. This is the reverse operation yading@11: * of av_url_split. yading@11: * yading@11: * Note, this requires networking to be initialized, so the caller must yading@11: * ensure ff_network_init has been called. yading@11: * yading@11: * @see av_url_split yading@11: * yading@11: * @param str the buffer to fill with the url yading@11: * @param size the size of the str buffer yading@11: * @param proto the protocol identifier, if null, the separator yading@11: * after the identifier is left out, too yading@11: * @param authorization an optional authorization string, may be null. yading@11: * An empty string is treated the same as a null string. yading@11: * @param hostname the host name string yading@11: * @param port the port number, left out from the string if negative yading@11: * @param fmt a generic format string for everything to add after the yading@11: * host/port, may be null yading@11: * @return the number of characters written to the destination buffer yading@11: */ yading@11: int ff_url_join(char *str, int size, const char *proto, yading@11: const char *authorization, const char *hostname, yading@11: int port, const char *fmt, ...) av_printf_format(7, 8); yading@11: yading@11: /** yading@11: * Append the media-specific SDP fragment for the media stream c yading@11: * to the buffer buff. yading@11: * yading@11: * Note, the buffer needs to be initialized, since it is appended to yading@11: * existing content. yading@11: * yading@11: * @param buff the buffer to append the SDP fragment to yading@11: * @param size the size of the buff buffer yading@11: * @param st the AVStream of the media to describe yading@11: * @param idx the global stream index yading@11: * @param dest_addr the destination address of the media stream, may be NULL yading@11: * @param dest_type the destination address type, may be NULL yading@11: * @param port the destination port of the media stream, 0 if unknown yading@11: * @param ttl the time to live of the stream, 0 if not multicast yading@11: * @param fmt the AVFormatContext, which might contain options modifying yading@11: * the generated SDP yading@11: */ yading@11: void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, yading@11: const char *dest_addr, const char *dest_type, yading@11: int port, int ttl, AVFormatContext *fmt); yading@11: yading@11: /** yading@11: * Write a packet to another muxer than the one the user originally yading@11: * intended. Useful when chaining muxers, where one muxer internally yading@11: * writes a received packet to another muxer. yading@11: * yading@11: * @param dst the muxer to write the packet to yading@11: * @param dst_stream the stream index within dst to write the packet to yading@11: * @param pkt the packet to be written yading@11: * @param src the muxer the packet originally was intended for yading@11: * @return the value av_write_frame returned yading@11: */ yading@11: int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, yading@11: AVFormatContext *src); yading@11: yading@11: /** yading@11: * Get the length in bytes which is needed to store val as v. yading@11: */ yading@11: int ff_get_v_length(uint64_t val); yading@11: yading@11: /** yading@11: * Put val using a variable number of bytes. yading@11: */ yading@11: void ff_put_v(AVIOContext *bc, uint64_t val); yading@11: yading@11: /** yading@11: * Read a whole line of text from AVIOContext. Stop reading after reaching yading@11: * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated, yading@11: * and may be truncated if the buffer is too small. yading@11: * yading@11: * @param s the read-only AVIOContext yading@11: * @param buf buffer to store the read line yading@11: * @param maxlen size of the buffer yading@11: * @return the length of the string written in the buffer, not including the yading@11: * final \\0 yading@11: */ yading@11: int ff_get_line(AVIOContext *s, char *buf, int maxlen); yading@11: yading@11: #define SPACE_CHARS " \t\r\n" yading@11: yading@11: /** yading@11: * Callback function type for ff_parse_key_value. yading@11: * yading@11: * @param key a pointer to the key yading@11: * @param key_len the number of bytes that belong to the key, including the '=' yading@11: * char yading@11: * @param dest return the destination pointer for the value in *dest, may yading@11: * be null to ignore the value yading@11: * @param dest_len the length of the *dest buffer yading@11: */ yading@11: typedef void (*ff_parse_key_val_cb)(void *context, const char *key, yading@11: int key_len, char **dest, int *dest_len); yading@11: /** yading@11: * Parse a string with comma-separated key=value pairs. The value strings yading@11: * may be quoted and may contain escaped characters within quoted strings. yading@11: * yading@11: * @param str the string to parse yading@11: * @param callback_get_buf function that returns where to store the yading@11: * unescaped value string. yading@11: * @param context the opaque context pointer to pass to callback_get_buf yading@11: */ yading@11: void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, yading@11: void *context); yading@11: yading@11: /** yading@11: * Find stream index based on format-specific stream ID yading@11: * @return stream index, or < 0 on error yading@11: */ yading@11: int ff_find_stream_index(AVFormatContext *s, int id); yading@11: yading@11: /** yading@11: * Internal version of av_index_search_timestamp yading@11: */ yading@11: int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, yading@11: int64_t wanted_timestamp, int flags); yading@11: yading@11: /** yading@11: * Internal version of av_add_index_entry yading@11: */ yading@11: int ff_add_index_entry(AVIndexEntry **index_entries, yading@11: int *nb_index_entries, yading@11: unsigned int *index_entries_allocated_size, yading@11: int64_t pos, int64_t timestamp, int size, int distance, int flags); yading@11: yading@11: /** yading@11: * Add a new chapter. yading@11: * yading@11: * @param s media file handle yading@11: * @param id unique ID for this chapter yading@11: * @param start chapter start time in time_base units yading@11: * @param end chapter end time in time_base units yading@11: * @param title chapter title yading@11: * yading@11: * @return AVChapter or NULL on error yading@11: */ yading@11: AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, yading@11: int64_t start, int64_t end, const char *title); yading@11: yading@11: /** yading@11: * Ensure the index uses less memory than the maximum specified in yading@11: * AVFormatContext.max_index_size by discarding entries if it grows yading@11: * too large. yading@11: */ yading@11: void ff_reduce_index(AVFormatContext *s, int stream_index); yading@11: yading@11: /** yading@11: * Convert a relative url into an absolute url, given a base url. yading@11: * yading@11: * @param buf the buffer where output absolute url is written yading@11: * @param size the size of buf yading@11: * @param base the base url, may be equal to buf. yading@11: * @param rel the new url, which is interpreted relative to base yading@11: */ yading@11: void ff_make_absolute_url(char *buf, int size, const char *base, yading@11: const char *rel); yading@11: yading@11: enum AVCodecID ff_guess_image2_codec(const char *filename); yading@11: yading@11: /** yading@11: * Convert a date string in ISO8601 format to Unix timestamp. yading@11: */ yading@11: int64_t ff_iso8601_to_unix_time(const char *datestr); yading@11: yading@11: /** yading@11: * Perform a binary search using av_index_search_timestamp() and yading@11: * AVInputFormat.read_timestamp(). yading@11: * yading@11: * @param target_ts target timestamp in the time base of the given stream yading@11: * @param stream_index stream number yading@11: */ yading@11: int ff_seek_frame_binary(AVFormatContext *s, int stream_index, yading@11: int64_t target_ts, int flags); yading@11: yading@11: /** yading@11: * Update cur_dts of all streams based on the given timestamp and AVStream. yading@11: * yading@11: * Stream ref_st unchanged, others set cur_dts in their native time base. yading@11: * Only needed for timestamp wrapping or if (dts not set and pts!=dts). yading@11: * @param timestamp new dts expressed in time_base of param ref_st yading@11: * @param ref_st reference stream giving time_base of param timestamp yading@11: */ yading@11: void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp); yading@11: yading@11: /** yading@11: * Perform a binary search using read_timestamp(). yading@11: * yading@11: * @param target_ts target timestamp in the time base of the given stream yading@11: * @param stream_index stream number yading@11: */ yading@11: int64_t ff_gen_search(AVFormatContext *s, int stream_index, yading@11: int64_t target_ts, int64_t pos_min, yading@11: int64_t pos_max, int64_t pos_limit, yading@11: int64_t ts_min, int64_t ts_max, yading@11: int flags, int64_t *ts_ret, yading@11: int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )); yading@11: yading@11: /** yading@11: * Set the time base and wrapping info for a given stream. This will be used yading@11: * to interpret the stream's timestamps. If the new time base is invalid yading@11: * (numerator or denominator are non-positive), it leaves the stream yading@11: * unchanged. yading@11: * yading@11: * @param s stream yading@11: * @param pts_wrap_bits number of bits effectively used by the pts yading@11: * (used for wrap control) yading@11: * @param pts_num time base numerator yading@11: * @param pts_den time base denominator yading@11: */ yading@11: void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, yading@11: unsigned int pts_num, unsigned int pts_den); yading@11: yading@11: /** yading@11: * Add side data to a packet for changing parameters to the given values. yading@11: * Parameters set to 0 aren't included in the change. yading@11: */ yading@11: int ff_add_param_change(AVPacket *pkt, int32_t channels, yading@11: uint64_t channel_layout, int32_t sample_rate, yading@11: int32_t width, int32_t height); yading@11: yading@11: /** yading@11: * Set the timebase for each stream from the corresponding codec timebase and yading@11: * print it. yading@11: */ yading@11: int ff_framehash_write_header(AVFormatContext *s); yading@11: yading@11: /** yading@11: * Read a transport packet from a media file. yading@11: * yading@11: * @param s media file handle yading@11: * @param pkt is filled yading@11: * @return 0 if OK, AVERROR_xxx on error yading@11: */ yading@11: int ff_read_packet(AVFormatContext *s, AVPacket *pkt); yading@11: yading@11: /** yading@11: * Interleave a packet per dts in an output media file. yading@11: * yading@11: * Packets with pkt->destruct == av_destruct_packet will be freed inside this yading@11: * function, so they cannot be used after it. Note that calling av_free_packet() yading@11: * on them is still safe. yading@11: * yading@11: * @param s media file handle yading@11: * @param out the interleaved packet will be output here yading@11: * @param pkt the input packet yading@11: * @param flush 1 if no further packets are available as input and all yading@11: * remaining packets should be output yading@11: * @return 1 if a packet was output, 0 if no packet could be output, yading@11: * < 0 if an error occurred yading@11: */ yading@11: int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, yading@11: AVPacket *pkt, int flush); yading@11: yading@11: void ff_free_stream(AVFormatContext *s, AVStream *st); yading@11: yading@11: /** yading@11: * Return the frame duration in seconds. Return 0 if not available. yading@11: */ yading@11: void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st, yading@11: AVCodecParserContext *pc, AVPacket *pkt); yading@11: yading@11: int ff_get_audio_frame_size(AVCodecContext *enc, int size, int mux); yading@11: yading@11: unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id); yading@11: yading@11: enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag); yading@11: yading@11: /** yading@11: * Select a PCM codec based on the given parameters. yading@11: * yading@11: * @param bps bits-per-sample yading@11: * @param flt floating-point yading@11: * @param be big-endian yading@11: * @param sflags signed flags. each bit corresponds to one byte of bit depth. yading@11: * e.g. the 1st bit indicates if 8-bit should be signed or yading@11: * unsigned, the 2nd bit indicates if 16-bit should be signed or yading@11: * unsigned, etc... This is useful for formats such as WAVE where yading@11: * only 8-bit is unsigned and all other bit depths are signed. yading@11: * @return a PCM codec id or AV_CODEC_ID_NONE yading@11: */ yading@11: enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags); yading@11: yading@11: /** yading@11: * Chooses a timebase for muxing the specified stream. yading@11: * yading@11: * The choosen timebase allows sample accurate timestamps based yading@11: * on the framerate or sample rate for audio streams. It also is yading@11: * at least as precisse as 1/min_precission would be. yading@11: */ yading@11: AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precission); yading@11: yading@11: /** yading@11: * Generate standard extradata for AVC-Intra based on width/height and field order. yading@11: */ yading@11: void ff_generate_avci_extradata(AVStream *st); yading@11: yading@11: int ff_http_match_no_proxy(const char *no_proxy, const char *hostname); yading@11: yading@11: #endif /* AVFORMAT_INTERNAL_H */