~ubuntu-branches/ubuntu/precise/ffmpeg-debian/precise

« back to all changes in this revision

Viewing changes to libavformat/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-01-20 09:20:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120092053-izz63p40hc98qfgp
Tags: 3:0.svn20090119-1ubuntu1
* merge from debian. LP: #318501
* new version fixes CVE-2008-3230, LP: #253767

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "avformat.h"
22
22
#include "internal.h"
23
23
#include "libavcodec/opt.h"
 
24
#include "metadata.h"
24
25
#include "libavutil/avstring.h"
25
26
#include "riff.h"
26
27
#include <sys/time.h>
152
153
    return 0;
153
154
}
154
155
 
 
156
static int match_format(const char *name, const char *names)
 
157
{
 
158
    const char *p;
 
159
    int len, namelen;
 
160
 
 
161
    if (!name || !names)
 
162
        return 0;
 
163
 
 
164
    namelen = strlen(name);
 
165
    while ((p = strchr(names, ','))) {
 
166
        len = FFMAX(p - names, namelen);
 
167
        if (!strncasecmp(name, names, len))
 
168
            return 1;
 
169
        names = p+1;
 
170
    }
 
171
    return !strcasecmp(name, names);
 
172
}
 
173
 
155
174
AVOutputFormat *guess_format(const char *short_name, const char *filename,
156
175
                             const char *mime_type)
157
176
{
159
178
    int score_max, score;
160
179
 
161
180
    /* specific test for image sequences */
162
 
#ifdef CONFIG_IMAGE2_MUXER
 
181
#if CONFIG_IMAGE2_MUXER
163
182
    if (!short_name && filename &&
164
183
        av_filename_number_test(filename) &&
165
184
        av_guess_image2_codec(filename) != CODEC_ID_NONE) {
213
232
    if(type == CODEC_TYPE_VIDEO){
214
233
        enum CodecID codec_id= CODEC_ID_NONE;
215
234
 
216
 
#ifdef CONFIG_IMAGE2_MUXER
 
235
#if CONFIG_IMAGE2_MUXER
217
236
        if(!strcmp(fmt->name, "image2") || !strcmp(fmt->name, "image2pipe")){
218
237
            codec_id= av_guess_image2_codec(filename);
219
238
        }
231
250
{
232
251
    AVInputFormat *fmt;
233
252
    for(fmt = first_iformat; fmt != NULL; fmt = fmt->next) {
234
 
        if (!strcmp(fmt->name, short_name))
 
253
        if (match_format(short_name, fmt->name))
235
254
            return fmt;
236
255
    }
237
256
    return NULL;
294
313
 
295
314
int av_dup_packet(AVPacket *pkt)
296
315
{
297
 
    if (pkt->destruct != av_destruct_packet) {
 
316
    if (((pkt->destruct == av_destruct_packet_nofree) || (pkt->destruct == NULL)) && pkt->data) {
298
317
        uint8_t *data;
299
318
        /* We duplicate the packet and don't forget to add the padding again. */
300
319
        if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE)
380
399
/**
381
400
 * Open a media file from an IO stream. 'fmt' must be specified.
382
401
 */
383
 
static const char* format_to_name(void* ptr)
384
 
{
385
 
    AVFormatContext* fc = (AVFormatContext*) ptr;
386
 
    if(fc->iformat) return fc->iformat->name;
387
 
    else if(fc->oformat) return fc->oformat->name;
388
 
    else return "NULL";
389
 
}
390
 
 
391
 
#define OFFSET(x) offsetof(AVFormatContext,x)
392
 
#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
393
 
//these names are too long to be readable
394
 
#define E AV_OPT_FLAG_ENCODING_PARAM
395
 
#define D AV_OPT_FLAG_DECODING_PARAM
396
 
 
397
 
static const AVOption options[]={
398
 
{"probesize", NULL, OFFSET(probesize), FF_OPT_TYPE_INT, 32000, 32, INT_MAX, D}, /* 32000 from mpegts.c: 1.0 second at 24Mbit/s */
399
 
{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
400
 
{"packetsize", "set packet size", OFFSET(packet_size), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
401
 
{"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, D|E, "fflags"},
402
 
{"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNIDX, INT_MIN, INT_MAX, D, "fflags"},
403
 
{"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_GENPTS, INT_MIN, INT_MAX, D, "fflags"},
404
 
{"track", " set the track number", OFFSET(track), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E},
405
 
{"year", "set the year", OFFSET(year), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E},
406
 
{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D},
407
 
{"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D},
408
 
{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, 1<<20, 0, INT_MAX, D},
409
 
{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, 3041280, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
410
 
{"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, E|D, "fdebug"},
411
 
{"ts", NULL, 0, FF_OPT_TYPE_CONST, FF_FDEBUG_TS, INT_MIN, INT_MAX, E|D, "fdebug"},
412
 
{NULL},
413
 
};
414
 
 
415
 
#undef E
416
 
#undef D
417
 
#undef DEFAULT
418
 
 
419
 
static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options };
420
 
 
421
 
static void avformat_get_context_defaults(AVFormatContext *s)
422
 
{
423
 
    memset(s, 0, sizeof(AVFormatContext));
424
 
 
425
 
    s->av_class = &av_format_context_class;
426
 
 
427
 
    av_opt_set_defaults(s);
428
 
}
429
 
 
430
 
AVFormatContext *av_alloc_format_context(void)
431
 
{
432
 
    AVFormatContext *ic;
433
 
    ic = av_malloc(sizeof(AVFormatContext));
434
 
    if (!ic) return ic;
435
 
    avformat_get_context_defaults(ic);
436
 
    ic->av_class = &av_format_context_class;
437
 
    return ic;
438
 
}
439
 
 
440
402
int av_open_input_stream(AVFormatContext **ic_ptr,
441
403
                         ByteIOContext *pb, const char *filename,
442
404
                         AVInputFormat *fmt, AVFormatParameters *ap)
484
446
    if (pb && !ic->data_offset)
485
447
        ic->data_offset = url_ftell(ic->pb);
486
448
 
 
449
#if LIBAVFORMAT_VERSION_MAJOR < 53
 
450
    ff_metadata_demux_compat(ic);
 
451
#endif
 
452
 
487
453
    *ic_ptr = ic;
488
454
    return 0;
489
455
 fail:
747
713
        case CODEC_ID_ASV2:
748
714
        case CODEC_ID_VCR1:
749
715
        case CODEC_ID_DNXHD:
 
716
        case CODEC_ID_JPEG2000:
750
717
            return 1;
751
718
        default: break;
752
719
        }
1998
1965
static int tb_unreliable(AVCodecContext *c){
1999
1966
    if(   c->time_base.den >= 101L*c->time_base.num
2000
1967
       || c->time_base.den <    5L*c->time_base.num
2001
 
/*       || c->codec_tag == ff_get_fourcc("DIVX")
2002
 
       || c->codec_tag == ff_get_fourcc("XVID")*/
 
1968
/*       || c->codec_tag == AV_RL32("DIVX")
 
1969
       || c->codec_tag == AV_RL32("XVID")*/
2003
1970
       || c->codec_id == CODEC_ID_MPEG2VIDEO)
2004
1971
        return 1;
2005
1972
    return 0;
2284
2251
        if (st->parser) {
2285
2252
            av_parser_close(st->parser);
2286
2253
        }
 
2254
        av_metadata_free(&st->metadata);
2287
2255
        av_free(st->index_entries);
2288
2256
        av_free(st->codec->extradata);
2289
2257
        av_free(st->codec);
2294
2262
    for(i=s->nb_programs-1; i>=0; i--) {
2295
2263
        av_freep(&s->programs[i]->provider_name);
2296
2264
        av_freep(&s->programs[i]->name);
 
2265
        av_metadata_free(&s->programs[i]->metadata);
2297
2266
        av_freep(&s->programs[i]->stream_index);
2298
2267
        av_freep(&s->programs[i]);
2299
2268
    }
2302
2271
    av_freep(&s->priv_data);
2303
2272
    while(s->nb_chapters--) {
2304
2273
        av_free(s->chapters[s->nb_chapters]->title);
 
2274
        av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
2305
2275
        av_free(s->chapters[s->nb_chapters]);
2306
2276
    }
2307
2277
    av_freep(&s->chapters);
 
2278
    av_metadata_free(&s->metadata);
2308
2279
    av_free(s);
2309
2280
}
2310
2281
 
2492
2463
            return AVERROR(ENOMEM);
2493
2464
    }
2494
2465
 
 
2466
#if LIBAVFORMAT_VERSION_MAJOR < 53
 
2467
    ff_metadata_mux_compat(s);
 
2468
#endif
 
2469
 
2495
2470
    if(s->oformat->write_header){
2496
2471
        ret = s->oformat->write_header(s);
2497
2472
        if (ret < 0)
2771
2746
    char buf[256];
2772
2747
    int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
2773
2748
    AVStream *st = ic->streams[i];
2774
 
    int g = ff_gcd(st->time_base.num, st->time_base.den);
 
2749
    int g = av_gcd(st->time_base.num, st->time_base.den);
2775
2750
    avcodec_string(buf, sizeof(buf), st->codec, is_output);
2776
2751
    av_log(NULL, AV_LOG_INFO, "    Stream #%d.%d", index, i);
2777
2752
    /* the pid is an important information, so we display it */
2849
2824
        dump_stream_format(ic, i, index, is_output);
2850
2825
}
2851
2826
 
 
2827
#if LIBAVFORMAT_VERSION_MAJOR < 53
2852
2828
int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
2853
2829
{
2854
2830
    return av_parse_video_frame_size(width_ptr, height_ptr, str);
2862
2838
    *frame_rate_den= frame_rate.den;
2863
2839
    return ret;
2864
2840
}
 
2841
#endif
2865
2842
 
2866
2843
int64_t av_gettime(void)
2867
2844
{
3234
3211
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
3235
3212
                     int pts_num, int pts_den)
3236
3213
{
3237
 
    unsigned int gcd= ff_gcd(pts_num, pts_den);
 
3214
    unsigned int gcd= av_gcd(pts_num, pts_den);
3238
3215
    s->pts_wrap_bits = pts_wrap_bits;
3239
3216
    s->time_base.num = pts_num/gcd;
3240
3217
    s->time_base.den = pts_den/gcd;