Libav
internal.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVFORMAT_INTERNAL_H
22 #define AVFORMAT_INTERNAL_H
23 
24 #include <stdint.h>
25 #include "avformat.h"
26 #include "os_support.h"
27 
28 #define MAX_URL_SIZE 4096
29 
30 #ifdef DEBUG
31 # define hex_dump_debug(class, buf, size) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size)
32 #else
33 # define hex_dump_debug(class, buf, size)
34 #endif
35 
36 typedef struct AVCodecTag {
37  enum AVCodecID id;
38  unsigned int tag;
39 } AVCodecTag;
40 
41 typedef struct CodecMime{
42  char str[32];
43  enum AVCodecID id;
44 } CodecMime;
45 
52 
60 
61  /* av_seek_frame() support */
62  int64_t data_offset;
80 #define RAW_PACKET_BUFFER_SIZE 2500000
82 
87  int64_t offset;
88 
93 
94 #if FF_API_COMPUTE_PKT_FIELDS2
95  int missing_ts_warning;
96 #endif
97 };
98 
104  int reorder;
113 
114  enum AVCodecID orig_codec_id;
115 
116 #if FF_API_LAVF_AVCTX
117  // whether the deprecated stream codec context needs
118  // to be filled from the codec parameters
119  int need_codec_update;
120 #endif
121 };
122 
123 void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
124 
125 #ifdef __GNUC__
126 #define dynarray_add(tab, nb_ptr, elem)\
127 do {\
128  __typeof__(tab) _tab = (tab);\
129  __typeof__(elem) _elem = (elem);\
130  (void)sizeof(**_tab == _elem); /* check that types are compatible */\
131  ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
132 } while(0)
133 #else
134 #define dynarray_add(tab, nb_ptr, elem)\
135 do {\
136  ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
137 } while(0)
138 #endif
139 
140 struct tm *ff_brktimegm(time_t secs, struct tm *tm);
141 
142 char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
143 
152 int ff_hex_to_data(uint8_t *data, const char *p);
153 
154 void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx);
155 
161  int (*compare)(AVFormatContext *, AVPacket *, AVPacket *));
162 
164 
165 #define NTP_OFFSET 2208988800ULL
166 #define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL)
167 
169 uint64_t ff_ntp_time(void);
170 
189 void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
190  const char *dest_addr, const char *dest_type,
191  int port, int ttl, AVFormatContext *fmt);
192 
204 int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
206 
210 int ff_get_v_length(uint64_t val);
211 
215 void ff_put_v(AVIOContext *bc, uint64_t val);
216 
228 int ff_get_line(AVIOContext *s, char *buf, int maxlen);
229 
230 #define SPACE_CHARS " \t\r\n"
231 
242 typedef void (*ff_parse_key_val_cb)(void *context, const char *key,
243  int key_len, char **dest, int *dest_len);
253 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
254  void *context);
255 
260 int ff_find_stream_index(AVFormatContext *s, int id);
261 
265 int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries,
266  int64_t wanted_timestamp, int flags);
267 
271 int ff_add_index_entry(AVIndexEntry **index_entries,
272  int *nb_index_entries,
273  unsigned int *index_entries_allocated_size,
274  int64_t pos, int64_t timestamp, int size, int distance, int flags);
275 
288  int64_t start, int64_t end, const char *title);
289 
295 void ff_reduce_index(AVFormatContext *s, int stream_index);
296 
297 enum AVCodecID ff_guess_image2_codec(const char *filename);
298 
302 int64_t ff_iso8601_to_unix_time(const char *datestr);
303 
311 int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
312  int64_t target_ts, int flags);
313 
322 void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
323 
330 int64_t ff_gen_search(AVFormatContext *s, int stream_index,
331  int64_t target_ts, int64_t pos_min,
332  int64_t pos_max, int64_t pos_limit,
333  int64_t ts_min, int64_t ts_max,
334  int flags, int64_t *ts_ret,
335  int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
336 
349 void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits,
350  unsigned int pts_num, unsigned int pts_den);
351 
356 int ff_add_param_change(AVPacket *pkt, int32_t channels,
357  uint64_t channel_layout, int32_t sample_rate,
359 
365 
374 
391  AVPacket *pkt, int flush);
392 
396 void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st,
397  AVCodecParserContext *pc, AVPacket *pkt);
398 
399 unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id);
400 
401 enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag);
402 
416 enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags);
417 
423 
431 static inline int ff_rename(const char *oldpath, const char *newpath)
432 {
433  if (rename(oldpath, newpath) == -1)
434  return AVERROR(errno);
435  return 0;
436 }
437 
443 
452 int ff_interleaved_peek(AVFormatContext *s, int stream,
453  AVPacket *pkt, int add_offset);
454 
455 #endif /* AVFORMAT_INTERNAL_H */
int ff_framehash_write_header(AVFormatContext *s)
Set the timebase for each stream from the corresponding codec timebase and print it.
Definition: framehash.c:23
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
Definition: aviobuf.c:376
Bytestream IO Context.
Definition: avio.h:104
int ff_interleaved_peek(AVFormatContext *s, int stream, AVPacket *pkt, int add_offset)
Find the next packet in the interleaving queue for the given stream.
Definition: mux.c:619
enum AVCodecID id
Definition: internal.h:37
int size
struct AVPacketList * raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
Definition: internal.h:70
struct AVPacketList * parse_queue_end
Definition: internal.h:76
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:1983
int reorder
Set to 1 if the codec allows reordering, so pts can be different from dts.
Definition: internal.h:104
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:2986
int64_t data_offset
offset of the first packet
Definition: internal.h:62
struct tm * ff_brktimegm(time_t secs, struct tm *tm)
Definition: cutils.c:52
int64_t offset
Offset to remap timestamps to be non-negative.
Definition: internal.h:87
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:1973
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: utils.c:1222
AVChapter * avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition: utils.c:2758
Format I/O context.
Definition: avformat.h:940
void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
Update cur_dts of all streams based on the given timestamp and AVStream.
Definition: utils.c:1137
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
Definition: utils.c:1111
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 dis...
Definition: utils.c:1151
uint8_t
miscellaneous OS support macros and functions.
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
A wrapper around AVFormatContext.io_close that should be used instead of calling the pointer directly...
Definition: utils.c:3317
const char data[16]
Definition: mxf.c:70
void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt)
Return the frame duration in seconds.
Definition: utils.c:514
int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
Interleave a packet per dts in an output media file.
Definition: mux.c:555
static int flags
Definition: log.c:50
struct AVPacketList * packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
Definition: internal.h:58
int raw_packet_buffer_remaining_size
Definition: internal.h:81
uint64_t ff_ntp_time(void)
Get the current time since NTP epoch in microseconds.
Definition: utils.c:2812
static int ff_rename(const char *oldpath, const char *newpath)
Wrap errno on rename() error.
Definition: internal.h:431
#define src
Definition: vp8dsp.c:254
int avctx_inited
1 if avctx has been initialized with the values from the codec parameters
Definition: internal.h:112
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:193
#define AVERROR(e)
Definition: error.h:43
int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int(*compare)(AVFormatContext *, AVPacket *, AVPacket *))
Add packet to AVFormatContext->packet_buffer list, determining its interleaved position using compare...
Definition: mux.c:498
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.
Definition: utils.c:3121
void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx)
void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
Definition: cutils.c:27
static float distance(float x, float y, int band)
int ff_generate_avci_extradata(AVStream *st)
Generate standard extradata for AVC-Intra based on width/height and field order.
Definition: utils.c:3163
int ff_find_stream_index(AVFormatContext *s, int id)
Find stream index based on format-specific stream ID.
Definition: utils.c:3063
void(* ff_parse_key_val_cb)(void *context, const char *key, int key_len, char **dest, int *dest_len)
Callback function type for ff_parse_key_value.
Definition: internal.h:242
int64_t ff_iso8601_to_unix_time(const char *datestr)
Convert a date string in ISO8601 format to Unix timestamp.
Definition: utils.c:3072
int32_t
int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
Read a transport packet from a media file.
Definition: utils.c:416
Stream structure.
Definition: avformat.h:705
static int width
Definition: utils.c:156
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: utils.c:1164
enum AVCodecID ff_guess_image2_codec(const char *filename)
Definition: img2.c:101
main external API structure.
Definition: avcodec.h:1409
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
int nb_interleaved_streams
Number of streams relevant for interleaving.
Definition: internal.h:51
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().
Definition: utils.c:1328
enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
Select a PCM codec based on the given parameters.
Definition: utils.c:1995
rational number numerator/denominator
Definition: rational.h:43
int ff_hex_to_data(uint8_t *data, const char *p)
Parse a string of hexadecimal strings.
Definition: utils.c:2958
void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, void *context)
Parse a string with comma-separated key=value pairs.
Definition: utils.c:3009
unsigned int tag
Definition: internal.h:38
int height
Definition: gxfenc.c:72
struct AVPacketList * parse_queue
Packets split by the parser get queued here.
Definition: internal.h:75
AVRational offset_timebase
Timebase for the timestamp offset.
Definition: internal.h:92
int ff_get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
Definition: aviobuf.c:366
Main libavformat public API header.
void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, const char *dest_addr, const char *dest_type, int port, int ttl, AVFormatContext *fmt)
Append the media-specific SDP fragment for the media stream c to the buffer buff. ...
Definition: sdp.c:810
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
Definition: alsdec.c:1797
int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, AVFormatContext *src)
Write a packet to another muxer than the one the user originally intended.
Definition: mux.c:755
unsigned bps
Definition: movenc.c:855
struct AVPacketList * packet_buffer_end
Definition: internal.h:59
AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
Definition: internal.h:108
FILE * out
Definition: movenc.c:54
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
Definition: aviobuf.c:704
char * ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase)
Definition: utils.c:2937
This structure stores compressed data.
Definition: avcodec.h:1323
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().
Definition: utils.c:1261
struct AVPacketList * raw_packet_buffer_end
Definition: internal.h:71