Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ da24c5e3

History | View | Annotate | Download (16.8 KB)

1
#ifndef AVFORMAT_H
2
#define AVFORMAT_H
3

    
4
#ifdef __cplusplus
5
extern "C" {
6
#endif
7

    
8
#define LIBAVFORMAT_BUILD       4609
9

    
10
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
11
#define LIBAVFORMAT_VERSION     FFMPEG_VERSION
12
#define LIBAVFORMAT_IDENT        "FFmpeg" FFMPEG_VERSION "b" AV_STRINGIFY(LIBAVFORMAT_BUILD)
13

    
14
#include <time.h>
15

    
16
#include "avcodec.h"
17

    
18
#include "avio.h"
19

    
20
/* packet functions */
21

    
22
#ifndef MAXINT64
23
#define MAXINT64 int64_t_C(0x7fffffffffffffff)
24
#endif
25

    
26
#ifndef MININT64
27
#define MININT64 int64_t_C(0x8000000000000000)
28
#endif
29

    
30
#define AV_NOPTS_VALUE MININT64
31
#define AV_TIME_BASE 1000000
32

    
33
typedef struct AVPacket {
34
    int64_t pts; /* presentation time stamp in stream units (set av_set_pts_info) */
35
    uint8_t *data;
36
    int   size;
37
    int   stream_index;
38
    int   flags;
39
    int   duration;
40
    void  (*destruct)(struct AVPacket *);
41
    void  *priv;
42
} AVPacket; 
43
#define PKT_FLAG_KEY   0x0001
44

    
45
/* initialize optional fields of a packet */
46
static inline void av_init_packet(AVPacket *pkt)
47
{
48
    pkt->pts   = AV_NOPTS_VALUE;
49
    pkt->flags = 0;
50
    pkt->stream_index = 0;
51
}
52

    
53
int av_new_packet(AVPacket *pkt, int size);
54

    
55
/**
56
 * Free a packet
57
 *
58
 * @param pkt packet to free
59
 */
60
static inline void av_free_packet(AVPacket *pkt)
61
{
62
    if (pkt && pkt->destruct) {
63
        pkt->destruct(pkt);
64
    }
65
}
66

    
67
/*************************************************/
68
/* fractional numbers for exact pts handling */
69

    
70
/* the exact value of the fractional number is: 'val + num / den'. num
71
   is assumed to be such as 0 <= num < den */
72
typedef struct AVFrac {
73
    int64_t val, num, den; 
74
} AVFrac;
75

    
76
void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
77
void av_frac_add(AVFrac *f, int64_t incr);
78
void av_frac_set(AVFrac *f, int64_t val);
79

    
80
/*************************************************/
81
/* input/output formats */
82

    
83
struct AVFormatContext;
84

    
85
/* this structure contains the data a format has to probe a file */
86
typedef struct AVProbeData {
87
    const char *filename;
88
    unsigned char *buf;
89
    int buf_size;
90
} AVProbeData;
91

    
92
#define AVPROBE_SCORE_MAX 100
93

    
94
typedef struct AVFormatParameters {
95
    int frame_rate;
96
    int frame_rate_base;
97
    int sample_rate;
98
    int channels;
99
    int width;
100
    int height;
101
    enum PixelFormat pix_fmt;
102
    struct AVImageFormat *image_format;
103
    int channel; /* used to select dv channel */
104
    const char *device; /* video4linux, audio or DV device */
105
    const char *standard; /* tv standard, NTSC, PAL, SECAM */
106
    int mpeg2ts_raw:1;  /* force raw MPEG2 transport stream output, if possible */
107
    int mpeg2ts_compute_pcr:1; /* compute exact PCR for each transport
108
                                  stream packet (only meaningful if
109
                                  mpeg2ts_raw is TRUE */
110
} AVFormatParameters;
111

    
112
#define AVFMT_NOFILE        0x0001 /* no file should be opened */
113
#define AVFMT_NEEDNUMBER    0x0002 /* needs '%d' in filename */ 
114
#define AVFMT_SHOW_IDS      0x0008 /* show format stream IDs numbers */
115
#define AVFMT_RAWPICTURE    0x0020 /* format wants AVPicture structure for
116
                                      raw picture data */
117

    
118
typedef struct AVOutputFormat {
119
    const char *name;
120
    const char *long_name;
121
    const char *mime_type;
122
    const char *extensions; /* comma separated extensions */
123
    /* size of private data so that it can be allocated in the wrapper */
124
    int priv_data_size;
125
    /* output support */
126
    enum CodecID audio_codec; /* default audio codec */
127
    enum CodecID video_codec; /* default video codec */
128
    int (*write_header)(struct AVFormatContext *);
129
    int (*write_packet)(struct AVFormatContext *, 
130
                        int stream_index,
131
                        const uint8_t *buf, int size, int64_t pts);
132
    int (*write_trailer)(struct AVFormatContext *);
133
    /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
134
    int flags;
135
    /* currently only used to set pixel format if not YUV420P */
136
    int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
137
    /* private fields */
138
    struct AVOutputFormat *next;
139
} AVOutputFormat;
140

    
141
typedef struct AVInputFormat {
142
    const char *name;
143
    const char *long_name;
144
    /* size of private data so that it can be allocated in the wrapper */
145
    int priv_data_size;
146
    /* tell if a given file has a chance of being parsing by this format */
147
    int (*read_probe)(AVProbeData *);
148
    /* read the format header and initialize the AVFormatContext
149
       structure. Return 0 if OK. 'ap' if non NULL contains
150
       additionnal paramters. Only used in raw format right
151
       now. 'av_new_stream' should be called to create new streams.  */
152
    int (*read_header)(struct AVFormatContext *,
153
                       AVFormatParameters *ap);
154
    /* read one packet and put it in 'pkt'. pts and flags are also
155
       set. 'av_new_stream' can be called only if the flag
156
       AVFMTCTX_NOHEADER is used. */
157
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
158
    /* close the stream. The AVFormatContext and AVStreams are not
159
       freed by this function */
160
    int (*read_close)(struct AVFormatContext *);
161
    /* seek at or before a given pts (given in microsecond). The pts
162
       origin is defined by the stream */
163
    int (*read_seek)(struct AVFormatContext *, int64_t pts);
164
    /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
165
    int flags;
166
    /* if extensions are defined, then no probe is done. You should
167
       usually not use extension format guessing because it is not
168
       reliable enough */
169
    const char *extensions;
170
    /* general purpose read only value that the format can use */
171
    int value;
172
    /* private fields */
173
    struct AVInputFormat *next;
174
} AVInputFormat;
175

    
176
typedef struct AVStream {
177
    int index;    /* stream index in AVFormatContext */
178
    int id;       /* format specific stream id */
179
    AVCodecContext codec; /* codec context */
180
    int r_frame_rate;     /* real frame rate of the stream */
181
    int r_frame_rate_base;/* real frame rate base of the stream */
182
    void *priv_data;
183
    /* internal data used in av_find_stream_info() */
184
    int codec_info_state;     
185
    int codec_info_nb_repeat_frames;
186
    int codec_info_nb_real_frames;
187
    /* encoding: PTS generation when outputing stream */
188
    AVFrac pts;
189
    /* ffmpeg.c private use */
190
    int stream_copy; /* if TRUE, just copy stream */
191
    /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
192
     * MN:dunno if thats the right place, for it */
193
    float quality; 
194
    /* decoding: position of the first frame of the component, in
195
       AV_TIME_BASE fractional seconds. */
196
    int64_t start_time; 
197
    /* decoding: duration of the stream, in AV_TIME_BASE fractional
198
       seconds. */
199
    int64_t duration;
200
} AVStream;
201

    
202
#define AVFMTCTX_NOHEADER      0x0001 /* signal that no header is present
203
                                         (streams are added dynamically) */
204

    
205
#define MAX_STREAMS 20
206

    
207
/* format I/O context */
208
typedef struct AVFormatContext {
209
    /* can only be iformat or oformat, not both at the same time */
210
    struct AVInputFormat *iformat;
211
    struct AVOutputFormat *oformat;
212
    void *priv_data;
213
    ByteIOContext pb;
214
    int nb_streams;
215
    AVStream *streams[MAX_STREAMS];
216
    char filename[1024]; /* input or output filename */
217
    /* stream info */
218
    char title[512];
219
    char author[512];
220
    char copyright[512];
221
    char comment[512];
222
    char album[512];
223
    int year;  /* ID3 year, 0 if none */
224
    int track; /* track number, 0 if none */
225
    char genre[32]; /* ID3 genre */
226

    
227
    int ctx_flags; /* format specific flags, see AVFMTCTX_xx */
228
    /* private data for pts handling (do not modify directly) */
229
    int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
230
    int pts_num, pts_den; /* value to convert to seconds */
231
    /* This buffer is only needed when packets were already buffered but
232
       not decoded, for example to get the codec parameters in mpeg
233
       streams */
234
    struct AVPacketList *packet_buffer;
235

    
236
    /* decoding: position of the first frame of the component, in
237
       AV_TIME_BASE fractional seconds. NEVER set this value directly:
238
       it is deduced from the AVStream values.  */
239
    int64_t start_time; 
240
    /* decoding: duration of the stream, in AV_TIME_BASE fractional
241
       seconds. NEVER set this value directly: it is deduced from the
242
       AVStream values.  */
243
    int64_t duration;
244
    /* decoding: total file size. 0 if unknown */
245
    int64_t file_size;
246
    /* decoding: total stream bitrate in bit/s, 0 if not
247
       available. Never set it directly if the file_size and the
248
       duration are known as ffmpeg can compute it automatically. */
249
    int bit_rate;
250
} AVFormatContext;
251

    
252
typedef struct AVPacketList {
253
    AVPacket pkt;
254
    struct AVPacketList *next;
255
} AVPacketList;
256

    
257
extern AVInputFormat *first_iformat;
258
extern AVOutputFormat *first_oformat;
259

    
260
/* still image support */
261
struct AVInputImageContext;
262
typedef struct AVInputImageContext AVInputImageContext;
263

    
264
typedef struct AVImageInfo {
265
    enum PixelFormat pix_fmt; /* requested pixel format */
266
    int width; /* requested width */
267
    int height; /* requested height */
268
    int interleaved; /* image is interleaved (e.g. interleaved GIF) */
269
    AVPicture pict; /* returned allocated image */
270
} AVImageInfo;
271

    
272
/* AVImageFormat.flags field constants */
273
#define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */
274

    
275
typedef struct AVImageFormat {
276
    const char *name;
277
    const char *extensions;
278
    /* tell if a given file has a chance of being parsing by this format */
279
    int (*img_probe)(AVProbeData *);
280
    /* read a whole image. 'alloc_cb' is called when the image size is
281
       known so that the caller can allocate the image. If 'allo_cb'
282
       returns non zero, then the parsing is aborted. Return '0' if
283
       OK. */
284
    int (*img_read)(ByteIOContext *, 
285
                    int (*alloc_cb)(void *, AVImageInfo *info), void *);
286
    /* write the image */
287
    int supported_pixel_formats; /* mask of supported formats for output */
288
    int (*img_write)(ByteIOContext *, AVImageInfo *);
289
    int flags;
290
    struct AVImageFormat *next;
291
} AVImageFormat;
292

    
293
void av_register_image_format(AVImageFormat *img_fmt);
294
AVImageFormat *av_probe_image_format(AVProbeData *pd);
295
AVImageFormat *guess_image_format(const char *filename);
296
int av_read_image(ByteIOContext *pb, const char *filename,
297
                  AVImageFormat *fmt,
298
                  int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
299
int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
300

    
301
extern AVImageFormat *first_image_format;
302

    
303
extern AVImageFormat pnm_image_format;
304
extern AVImageFormat pbm_image_format;
305
extern AVImageFormat pgm_image_format;
306
extern AVImageFormat ppm_image_format;
307
extern AVImageFormat pam_image_format;
308
extern AVImageFormat pgmyuv_image_format;
309
extern AVImageFormat yuv_image_format;
310
#ifdef CONFIG_ZLIB
311
extern AVImageFormat png_image_format;
312
#endif
313
extern AVImageFormat jpeg_image_format;
314
extern AVImageFormat gif_image_format;
315

    
316
/* XXX: use automatic init with either ELF sections or C file parser */
317
/* modules */
318

    
319
/* mpeg.c */
320
extern AVInputFormat mpegps_demux;
321
int mpegps_init(void);
322

    
323
/* mpegts.c */
324
extern AVInputFormat mpegts_demux;
325
int mpegts_init(void);
326

    
327
/* rm.c */
328
int rm_init(void);
329

    
330
/* crc.c */
331
int crc_init(void);
332

    
333
/* img.c */
334
int img_init(void);
335

    
336
/* asf.c */
337
int asf_init(void);
338

    
339
/* avienc.c */
340
int avienc_init(void);
341

    
342
/* avidec.c */
343
int avidec_init(void);
344

    
345
/* swf.c */
346
int swf_init(void);
347

    
348
/* mov.c */
349
int mov_init(void);
350

    
351
/* movenc.c */
352
int movenc_init(void);
353

    
354
/* flvenc.c */
355
int flvenc_init(void);
356

    
357
/* flvdec.c */
358
int flvdec_init(void);
359

    
360
/* jpeg.c */
361
int jpeg_init(void);
362

    
363
/* gif.c */
364
int gif_init(void);
365

    
366
/* au.c */
367
int au_init(void);
368

    
369
/* amr.c */
370
int amr_init(void);
371

    
372
/* wav.c */
373
int wav_init(void);
374

    
375
/* raw.c */
376
int raw_init(void);
377

    
378
/* mp3.c */
379
int mp3_init(void);
380

    
381
/* yuv4mpeg.c */
382
int yuv4mpeg_init(void);
383

    
384
/* ogg.c */
385
int ogg_init(void);
386

    
387
/* dv.c */
388
int dv_init(void);
389

    
390
/* ffm.c */
391
int ffm_init(void);
392

    
393
/* rtsp.c */
394
extern AVInputFormat redir_demux;
395
int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
396

    
397
/* 4xm.c */
398
int fourxm_init(void);
399

    
400
/* psxstr.c */
401
int str_init(void);
402

    
403
/* idroq.c */
404
int roq_init(void);
405

    
406
/* ipmovie.c */
407
int ipmovie_init(void);
408

    
409
/* nut.c */
410
int nut_init(void);
411

    
412
/* wc3movie.c */
413
int wc3_init(void);
414

    
415
/* westwood.c */
416
int westwood_init(void);
417

    
418
/* segafilm.c */
419
int film_init(void);
420

    
421
/* idcin.c */
422
int idcin_init(void);
423

    
424
#include "rtp.h"
425

    
426
#include "rtsp.h"
427

    
428
/* yuv4mpeg.c */
429
extern AVOutputFormat yuv4mpegpipe_oformat;
430

    
431
/* utils.c */
432
void av_register_input_format(AVInputFormat *format);
433
void av_register_output_format(AVOutputFormat *format);
434
AVOutputFormat *guess_stream_format(const char *short_name, 
435
                                    const char *filename, const char *mime_type);
436
AVOutputFormat *guess_format(const char *short_name, 
437
                             const char *filename, const char *mime_type);
438

    
439
void av_hex_dump(uint8_t *buf, int size);
440

    
441
void av_register_all(void);
442

    
443
typedef struct FifoBuffer {
444
    uint8_t *buffer;
445
    uint8_t *rptr, *wptr, *end;
446
} FifoBuffer;
447

    
448
int fifo_init(FifoBuffer *f, int size);
449
void fifo_free(FifoBuffer *f);
450
int fifo_size(FifoBuffer *f, uint8_t *rptr);
451
int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr);
452
void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr);
453

    
454
/* media file input */
455
AVInputFormat *av_find_input_format(const char *short_name);
456
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
457
int av_open_input_stream(AVFormatContext **ic_ptr, 
458
                         ByteIOContext *pb, const char *filename, 
459
                         AVInputFormat *fmt, AVFormatParameters *ap);
460
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, 
461
                       AVInputFormat *fmt,
462
                       int buf_size,
463
                       AVFormatParameters *ap);
464

    
465
#define AVERROR_UNKNOWN     (-1)  /* unknown error */
466
#define AVERROR_IO          (-2)  /* i/o error */
467
#define AVERROR_NUMEXPECTED (-3)  /* number syntax expected in filename */
468
#define AVERROR_INVALIDDATA (-4)  /* invalid data found */
469
#define AVERROR_NOMEM       (-5)  /* not enough memory */
470
#define AVERROR_NOFMT       (-6)  /* unknown format */
471

    
472
int av_find_stream_info(AVFormatContext *ic);
473
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
474
void av_close_input_file(AVFormatContext *s);
475
AVStream *av_new_stream(AVFormatContext *s, int id);
476
void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
477
                     int pts_num, int pts_den);
478

    
479
/* media file output */
480
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
481
int av_write_header(AVFormatContext *s);
482
int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf, 
483
                   int size);
484
int av_write_trailer(AVFormatContext *s);
485

    
486
void dump_format(AVFormatContext *ic,
487
                 int index, 
488
                 const char *url,
489
                 int is_output);
490
int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
491
int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
492
int64_t parse_date(const char *datestr, int duration);
493

    
494
int64_t av_gettime(void);
495

    
496
/* ffm specific for ffserver */
497
#define FFM_PACKET_SIZE 4096
498
offset_t ffm_read_write_index(int fd);
499
void ffm_write_write_index(int fd, offset_t pos);
500
void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
501

    
502
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
503

    
504
int get_frame_filename(char *buf, int buf_size,
505
                       const char *path, int number);
506
int filename_number_test(const char *filename);
507

    
508
/* grab specific */
509
int video_grab_init(void);
510
int audio_init(void);
511

    
512
/* DV1394 */
513
int dv1394_init(void);
514

    
515
#ifdef HAVE_AV_CONFIG_H
516

    
517
#include "os_support.h"
518

    
519
int strstart(const char *str, const char *val, const char **ptr);
520
int stristart(const char *str, const char *val, const char **ptr);
521
void pstrcpy(char *buf, int buf_size, const char *str);
522
char *pstrcat(char *buf, int buf_size, const char *s);
523

    
524
void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
525

    
526
#ifdef __GNUC__
527
#define dynarray_add(tab, nb_ptr, elem)\
528
do {\
529
    typeof(tab) _tab = (tab);\
530
    typeof(elem) _elem = (elem);\
531
    (void)sizeof(**_tab == _elem); /* check that types are compatible */\
532
    __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
533
} while(0)
534
#else
535
#define dynarray_add(tab, nb_ptr, elem)\
536
do {\
537
    __dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
538
} while(0)
539
#endif
540

    
541
time_t mktimegm(struct tm *tm);
542
const char *small_strptime(const char *p, const char *fmt, 
543
                           struct tm *dt);
544

    
545
struct in_addr;
546
int resolve_host(struct in_addr *sin_addr, const char *hostname);
547

    
548
void url_split(char *proto, int proto_size,
549
               char *hostname, int hostname_size,
550
               int *port_ptr,
551
               char *path, int path_size,
552
               const char *url);
553

    
554
int match_ext(const char *filename, const char *extensions);
555

    
556
#endif /* HAVE_AV_CONFIG_H */
557

    
558
#ifdef __cplusplus
559
}
560
#endif
561

    
562
#endif /* AVFORMAT_H */