Revision da24c5e3

View differences:

libavformat/avformat.h
5 5
extern "C" {
6 6
#endif
7 7

  
8
#define LIBAVFORMAT_BUILD       4608
8
#define LIBAVFORMAT_BUILD       4609
9 9

  
10 10
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
11 11
#define LIBAVFORMAT_VERSION     FFMPEG_VERSION
......
42 42
} AVPacket; 
43 43
#define PKT_FLAG_KEY   0x0001
44 44

  
45
/* initialize optional fields of a packet */
45 46
static inline void av_init_packet(AVPacket *pkt)
46 47
{
47 48
    pkt->pts   = AV_NOPTS_VALUE;
......
102 103
    int channel; /* used to select dv channel */
103 104
    const char *device; /* video4linux, audio or DV device */
104 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 */
105 110
} AVFormatParameters;
106 111

  
107 112
#define AVFMT_NOFILE        0x0001 /* no file should be opened */
108 113
#define AVFMT_NEEDNUMBER    0x0002 /* needs '%d' in filename */ 
109
#define AVFMT_NOHEADER      0x0004 /* signal that no header is present
110
                                      (streams are added dynamically) */
111 114
#define AVFMT_SHOW_IDS      0x0008 /* show format stream IDs numbers */
112 115
#define AVFMT_RAWPICTURE    0x0020 /* format wants AVPicture structure for
113 116
                                      raw picture data */
......
150 153
                       AVFormatParameters *ap);
151 154
    /* read one packet and put it in 'pkt'. pts and flags are also
152 155
       set. 'av_new_stream' can be called only if the flag
153
       AVFMT_NOHEADER is used. */
156
       AVFMTCTX_NOHEADER is used. */
154 157
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
155 158
    /* close the stream. The AVFormatContext and AVStreams are not
156 159
       freed by this function */
......
158 161
    /* seek at or before a given pts (given in microsecond). The pts
159 162
       origin is defined by the stream */
160 163
    int (*read_seek)(struct AVFormatContext *, int64_t pts);
161
    /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
164
    /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
162 165
    int flags;
163 166
    /* if extensions are defined, then no probe is done. You should
164 167
       usually not use extension format guessing because it is not
......
181 184
    int codec_info_state;     
182 185
    int codec_info_nb_repeat_frames;
183 186
    int codec_info_nb_real_frames;
184
    /* PTS generation when outputing stream */
187
    /* encoding: PTS generation when outputing stream */
185 188
    AVFrac pts;
186 189
    /* ffmpeg.c private use */
187 190
    int stream_copy; /* if TRUE, just copy stream */
......
196 199
    int64_t duration;
197 200
} AVStream;
198 201

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

  
199 205
#define MAX_STREAMS 20
200 206

  
201 207
/* format I/O context */
......
218 224
    int track; /* track number, 0 if none */
219 225
    char genre[32]; /* ID3 genre */
220 226

  
221
    int flags; /* format specific flags */
227
    int ctx_flags; /* format specific flags, see AVFMTCTX_xx */
222 228
    /* private data for pts handling (do not modify directly) */
223 229
    int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
224 230
    int pts_num, pts_den; /* value to convert to seconds */
......
448 454
/* media file input */
449 455
AVInputFormat *av_find_input_format(const char *short_name);
450 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);
451 460
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, 
452 461
                       AVInputFormat *fmt,
453 462
                       int buf_size,
libavformat/mpeg.c
479 479
{
480 480
    MpegDemuxContext *m = s->priv_data;
481 481
    m->header_state = 0xff;
482
    s->ctx_flags |= AVFMTCTX_NOHEADER;
483

  
482 484
    /* no need to do more */
483 485
    return 0;
484 486
}
......
705 707
    mpegps_read_header,
706 708
    mpegps_read_packet,
707 709
    mpegps_read_close,
708
    .flags = AVFMT_NOHEADER,
709 710
};
710 711

  
711 712
int mpegps_init(void)
libavformat/utils.c
274 274
/************************************************************/
275 275
/* input media file */
276 276

  
277
/**
278
 * open a media file from an IO stream. 'fmt' must be specified.
279
 */
280
int av_open_input_stream(AVFormatContext **ic_ptr, 
281
                         ByteIOContext *pb, const char *filename, 
282
                         AVInputFormat *fmt, AVFormatParameters *ap)
283
{
284
    int err;
285
    AVFormatContext *ic;
286

  
287
    ic = av_mallocz(sizeof(AVFormatContext));
288
    if (!ic) {
289
        err = AVERROR_NOMEM;
290
        goto fail;
291
    }
292
    ic->iformat = fmt;
293
    if (pb)
294
        ic->pb = *pb;
295
    ic->duration = AV_NOPTS_VALUE;
296
    ic->start_time = AV_NOPTS_VALUE;
297
    pstrcpy(ic->filename, sizeof(ic->filename), filename);
298

  
299
    /* allocate private data */
300
    if (fmt->priv_data_size > 0) {
301
        ic->priv_data = av_mallocz(fmt->priv_data_size);
302
        if (!ic->priv_data) {
303
            err = AVERROR_NOMEM;
304
            goto fail;
305
        }
306
    } else {
307
        ic->priv_data = NULL;
308
    }
309

  
310
    /* default pts settings is MPEG like */
311
    av_set_pts_info(ic, 33, 1, 90000);
312

  
313
    err = ic->iformat->read_header(ic, ap);
314
    if (err < 0)
315
        goto fail;
316
    *ic_ptr = ic;
317
    return 0;
318
 fail:
319
    if (ic) {
320
        av_freep(&ic->priv_data);
321
    }
322
    av_free(ic);
323
    *ic_ptr = NULL;
324
    return err;
325
}
326

  
277 327
#define PROBE_BUF_SIZE 2048
278 328

  
279 329
/**
......
292 342
                       int buf_size,
293 343
                       AVFormatParameters *ap)
294 344
{
295
    AVFormatContext *ic = NULL;
296
    int err, must_open_file;
297
    unsigned char buf[PROBE_BUF_SIZE];
345
    int err, must_open_file, file_opened;
346
    uint8_t buf[PROBE_BUF_SIZE];
298 347
    AVProbeData probe_data, *pd = &probe_data;
299

  
300
    ic = av_mallocz(sizeof(AVFormatContext));
301
    if (!ic) {
302
        err = AVERROR_NOMEM;
303
        goto fail;
304
    }
305
    ic->duration = AV_NOPTS_VALUE;
306
    ic->start_time = AV_NOPTS_VALUE;
307
    pstrcpy(ic->filename, sizeof(ic->filename), filename);
308
    pd->filename = ic->filename;
348
    ByteIOContext pb1, *pb = &pb1;
349
    
350
    file_opened = 0;
351
    pd->filename = "";
352
    if (filename)
353
        pd->filename = filename;
309 354
    pd->buf = buf;
310 355
    pd->buf_size = 0;
311 356

  
......
317 362
    /* do not open file if the format does not need it. XXX: specific
318 363
       hack needed to handle RTSP/TCP */
319 364
    must_open_file = 1;
320
    if ((fmt && (fmt->flags & AVFMT_NOFILE)) 
321
#ifdef CONFIG_NETWORK
322
        || (fmt == &rtp_demux && !strcmp(filename, "null"))
323
#endif
324
        ) {
365
    if (fmt && (fmt->flags & AVFMT_NOFILE)) {
325 366
        must_open_file = 0;
326 367
    }
327 368

  
328 369
    if (!fmt || must_open_file) {
329 370
        /* if no file needed do not try to open one */
330
        if (url_fopen(&ic->pb, filename, URL_RDONLY) < 0) {
371
        if (url_fopen(pb, filename, URL_RDONLY) < 0) {
331 372
            err = AVERROR_IO;
332 373
            goto fail;
333 374
        }
375
        file_opened = 1;
334 376
        if (buf_size > 0) {
335
            url_setbufsize(&ic->pb, buf_size);
377
            url_setbufsize(pb, buf_size);
336 378
        }
337 379
        if (!fmt) {
338 380
            /* read probe data */
339
            pd->buf_size = get_buffer(&ic->pb, buf, PROBE_BUF_SIZE);
340
            url_fseek(&ic->pb, 0, SEEK_SET);
381
            pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
382
            url_fseek(pb, 0, SEEK_SET);
341 383
        }
342 384
    }
343 385
    
......
349 391
    /* if still no format found, error */
350 392
    if (!fmt) {
351 393
        err = AVERROR_NOFMT;
352
        goto fail1;
394
        goto fail;
353 395
    }
354 396
        
355 397
    /* XXX: suppress this hack for redirectors */
356 398
#ifdef CONFIG_NETWORK
357 399
    if (fmt == &redir_demux) {
358
        err = redir_open(ic_ptr, &ic->pb);
359
        url_fclose(&ic->pb);
360
        av_free(ic);
400
        err = redir_open(ic_ptr, pb);
401
        url_fclose(pb);
361 402
        return err;
362 403
    }
363 404
#endif
364 405

  
365
    ic->iformat = fmt;
366

  
367 406
    /* check filename in case of an image number is expected */
368
    if (ic->iformat->flags & AVFMT_NEEDNUMBER) {
369
        if (filename_number_test(ic->filename) < 0) { 
407
    if (fmt->flags & AVFMT_NEEDNUMBER) {
408
        if (filename_number_test(filename) < 0) { 
370 409
            err = AVERROR_NUMEXPECTED;
371
            goto fail1;
410
            goto fail;
372 411
        }
373 412
    }
374
    
375
    /* allocate private data */
376
    if (fmt->priv_data_size > 0) {
377
        ic->priv_data = av_mallocz(fmt->priv_data_size);
378
        if (!ic->priv_data) {
379
            err = AVERROR_NOMEM;
380
        goto fail1;
381
        }
382
    } else
383
        ic->priv_data = NULL;
384

  
385
    /* default pts settings is MPEG like */
386
    av_set_pts_info(ic, 33, 1, 90000);
387

  
388
    err = ic->iformat->read_header(ic, ap);
389
    if (err < 0)
390
        goto fail1;
391
    *ic_ptr = ic;
413
    err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap);
414
    if (err)
415
        goto fail;
392 416
    return 0;
393
 fail1:
394
    if (!fmt || must_open_file) {
395
        url_fclose(&ic->pb);
396
    }
397 417
 fail:
398
    if (ic) {
399
        av_freep(&ic->priv_data);
400
    }
401
    av_free(ic);
418
    if (file_opened)
419
        url_fclose(pb);
402 420
    *ic_ptr = NULL;
403 421
    return err;
422
    
404 423
}
405 424

  
425
/*******************************************************/
426

  
406 427
/**
407
 * Read a packet from a media file
428
 * Read a packet from a media file. Use it only for low level file
429
 * reading. It is almost always better to use av_read_frame().
430
 * 
408 431
 * @param s media file handle
409 432
 * @param pkt is filled 
410
 * @return 0 if OK. AVERROR_xxx if error.
433
 * @return 0 if OK. AVERROR_xxx if error.  
411 434
 */
412 435
int av_read_packet(AVFormatContext *s, AVPacket *pkt)
413 436
{
......
425 448
    }
426 449
}
427 450

  
451
/*******************************************************/
428 452

  
429 453
/* return TRUE if the stream has accurate timings for at least one component */
430 454
static int av_has_timings(AVFormatContext *ic)
......
796 820
            /* NOTE: if the format has no header, then we need to read
797 821
               some packets to get most of the streams, so we cannot
798 822
               stop here */
799
            if (!(ic->iformat->flags & AVFMT_NOHEADER) ||
823
            if (!(ic->ctx_flags & AVFMTCTX_NOHEADER) ||
800 824
                read_size >= min_read_size) {
801 825
                /* if we found the info for all the codecs, we can stop */
802 826
                ret = count;
......
821 845
        ppktl = &pktl->next;
822 846

  
823 847
        /* NOTE: a new stream can be added there if no header in file
824
           (AVFMT_NOHEADER) */
848
           (AVFMTCTX_NOHEADER) */
825 849
        pkt = &pktl->pkt;
826 850
        if (ic->iformat->read_packet(ic, pkt) < 0) {
827 851
            /* EOF or error */
828 852
            ret = -1; /* we could not have all the codec parameters before EOF */
829
            if ((ic->iformat->flags & AVFMT_NOHEADER) &&
853
            if ((ic->ctx_flags & AVFMTCTX_NOHEADER) &&
830 854
                i == ic->nb_streams)
831 855
                ret = 0;
832 856
            break;
......
950 974
void av_close_input_file(AVFormatContext *s)
951 975
{
952 976
    int i, must_open_file;
977
    AVStream *st;
953 978

  
954 979
    if (s->iformat->read_close)
955 980
        s->iformat->read_close(s);
956 981
    for(i=0;i<s->nb_streams;i++) {
957
        av_free(s->streams[i]);
982
        /* free all data in a stream component */
983
        st = s->streams[i];
984
        av_free(st);
958 985
    }
959 986
    if (s->packet_buffer) {
960 987
        AVPacketList *p, *p1;
......
968 995
        s->packet_buffer = NULL;
969 996
    }
970 997
    must_open_file = 1;
971
    if ((s->iformat->flags & AVFMT_NOFILE)
972
#ifdef CONFIG_NETWORK
973
        || (s->iformat == &rtp_demux && !strcmp(s->filename, "null"))
974
#endif
975
        ) {
998
    if (s->iformat->flags & AVFMT_NOFILE) {
976 999
        must_open_file = 0;
977 1000
    }
978 1001
    if (must_open_file) {
......
984 1007

  
985 1008
/**
986 1009
 * Add a new stream to a media file. Can only be called in the
987
 * read_header function. If the flag AVFMT_NOHEADER is in the format
988
 * description, then new streams can be added in read_packet too.
1010
 * read_header function. If the flag AVFMTCTX_NOHEADER is in the
1011
 * format context, then new streams can be added in read_packet too.
989 1012
 *
990 1013
 *
991 1014
 * @param s media file handle
992
 * @param id file format dependent stream id
1015
 * @param id file format dependent stream id 
993 1016
 */
994 1017
AVStream *av_new_stream(AVFormatContext *s, int id)
995 1018
{

Also available in: Unified diff