~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#include "avcodec.h"
29
29
#include "dsputil.h"
30
 
#include "mpegvideo.h"
31
30
#include "integer.h"
32
31
#include "opt.h"
33
32
#include "crc.h"
 
33
#include "imgconvert.h"
34
34
#include <stdarg.h>
35
35
#include <limits.h>
36
36
#include <float.h>
37
 
#ifdef __MINGW32__
 
37
#if !defined(HAVE_MKSTEMP)
38
38
#include <fcntl.h>
39
39
#endif
40
40
 
66
66
 
67
67
    *size= FFMAX(17*min_size/16 + 32, min_size);
68
68
 
69
 
    return av_realloc(ptr, *size);
 
69
    ptr= av_realloc(ptr, *size);
 
70
    if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
 
71
        *size= 0;
 
72
 
 
73
    return ptr;
70
74
}
71
75
 
72
76
static unsigned int last_static = 0;
126
130
/* encoder management */
127
131
AVCodec *first_avcodec = NULL;
128
132
 
 
133
AVCodec *av_codec_next(AVCodec *c){
 
134
    if(c) return c->next;
 
135
    else  return first_avcodec;
 
136
}
 
137
 
129
138
void register_avcodec(AVCodec *format)
130
139
{
131
140
    AVCodec **p;
147
156
    uint8_t *base[4];
148
157
    uint8_t *data[4];
149
158
    int linesize[4];
 
159
    int width, height;
 
160
    enum PixelFormat pix_fmt;
150
161
}InternalBuffer;
151
162
 
152
163
#define INTERNAL_BUFFER_SIZE 32
169
180
    case PIX_FMT_YUVJ420P:
170
181
    case PIX_FMT_YUVJ422P:
171
182
    case PIX_FMT_YUVJ444P:
 
183
    case PIX_FMT_YUVA420P:
172
184
        w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
173
185
        h_align= 16;
174
186
        break;
251
263
    picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack
252
264
    (*picture_number)++;
253
265
 
 
266
    if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
 
267
        for(i=0; i<4; i++){
 
268
            av_freep(&buf->base[i]);
 
269
            buf->data[i]= NULL;
 
270
        }
 
271
    }
 
272
 
254
273
    if(buf->base[0]){
255
274
        pic->age= *picture_number - buf->last_pic_num;
256
275
        buf->last_pic_num= *picture_number;
257
276
    }else{
258
277
        int h_chroma_shift, v_chroma_shift;
259
 
        int pixel_size, size[3];
 
278
        int size[4] = {0};
 
279
        int tmpsize;
260
280
        AVPicture picture;
261
281
 
262
282
        avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
267
287
            w+= EDGE_WIDTH*2;
268
288
            h+= EDGE_WIDTH*2;
269
289
        }
270
 
        avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
271
 
        pixel_size= picture.linesize[0]*8 / w;
272
 
//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", (int)picture.data[1], w, h, s->pix_fmt);
273
 
        assert(pixel_size>=1);
274
 
            //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it
275
 
        if(pixel_size == 3*8)
276
 
            w= ALIGN(w, STRIDE_ALIGN<<h_chroma_shift);
277
 
        else
278
 
            w= ALIGN(pixel_size*w, STRIDE_ALIGN<<(h_chroma_shift+3)) / pixel_size;
279
 
        size[1] = avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
280
 
        size[0] = picture.linesize[0] * h;
281
 
        size[1] -= size[0];
282
 
        if(picture.data[2])
283
 
            size[1]= size[2]= size[1]/2;
284
 
        else
285
 
            size[2]= 0;
 
290
        avcodec_align_dimensions(s, &w, &h);
 
291
 
 
292
        ff_fill_linesize(&picture, s->pix_fmt, w);
 
293
 
 
294
        for (i=0; i<4; i++)
 
295
            picture.linesize[i] = ALIGN(picture.linesize[i], STRIDE_ALIGN);
 
296
 
 
297
        tmpsize = ff_fill_pointer(&picture, NULL, s->pix_fmt, h);
 
298
 
 
299
        for (i=0; i<3 && picture.data[i+1]; i++)
 
300
            size[i] = picture.data[i+1] - picture.data[i];
 
301
        size[i] = tmpsize - (picture.data[i] - picture.data[0]);
286
302
 
287
303
        buf->last_pic_num= -256*256*256*64;
288
304
        memset(buf->base, 0, sizeof(buf->base));
289
305
        memset(buf->data, 0, sizeof(buf->data));
290
306
 
291
 
        for(i=0; i<3 && size[i]; i++){
 
307
        for(i=0; i<4 && size[i]; i++){
292
308
            const int h_shift= i==0 ? 0 : h_chroma_shift;
293
309
            const int v_shift= i==0 ? 0 : v_chroma_shift;
294
310
 
304
320
            else
305
321
                buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN);
306
322
        }
 
323
        buf->width  = s->width;
 
324
        buf->height = s->height;
 
325
        buf->pix_fmt= s->pix_fmt;
307
326
        pic->age= 256*256*256*64;
308
327
    }
309
328
    pic->type= FF_BUFFER_TYPE_INTERNAL;
337
356
 
338
357
    FFSWAP(InternalBuffer, *buf, *last);
339
358
 
340
 
    for(i=0; i<3; i++){
 
359
    for(i=0; i<4; i++){
341
360
        pic->data[i]=NULL;
342
361
//        pic->base[i]=NULL;
343
362
    }
370
389
    if (s->get_buffer(s, pic))
371
390
        return -1;
372
391
    /* Copy image data from old buffer to new buffer */
373
 
    img_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
 
392
    av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
374
393
             s->height);
375
394
    s->release_buffer(s, &temp_pic); // Release old frame
376
395
    return 0;
400
419
}
401
420
 
402
421
#define OFFSET(x) offsetof(AVCodecContext,x)
403
 
#define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C
 
422
#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
404
423
//these names are too long to be readable
405
424
#define V AV_OPT_FLAG_VIDEO_PARAM
406
425
#define A AV_OPT_FLAG_AUDIO_PARAM
411
430
#define AV_CODEC_DEFAULT_BITRATE 200*1000
412
431
 
413
432
static const AVOption options[]={
414
 
{"b", "set video bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|A|E},
 
433
{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|E},
 
434
{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, 64*1000, INT_MIN, INT_MAX, A|E},
415
435
{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE*20, 1, INT_MAX, V|E},
416
 
{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|E|D, "flags"},
 
436
{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, 0, UINT_MAX, V|A|E|D, "flags"},
417
437
{"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
418
438
{"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
419
439
{"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
452
472
{"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"},
453
473
{"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
454
474
{"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"},
 
475
#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
 
476
{"me", "set motion estimation method (deprecated, use me_method instead)", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"},
 
477
#endif
 
478
{"zero", "zero motion estimation (fastest)", 0, FF_OPT_TYPE_CONST, ME_ZERO, INT_MIN, INT_MAX, V|E, "me_method" },
 
479
{"full", "full motion estimation (slowest)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" },
 
480
{"epzs", "EPZS motion estimation (default)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" },
 
481
{"log", "log motion estimation", 0, FF_OPT_TYPE_CONST, ME_LOG, INT_MIN, INT_MAX, V|E, "me_method" },
 
482
{"phods", "phods motion estimation", 0, FF_OPT_TYPE_CONST, ME_PHODS, INT_MIN, INT_MAX, V|E, "me_method" },
 
483
{"x1", "X1 motion estimation", 0, FF_OPT_TYPE_CONST, ME_X1, INT_MIN, INT_MAX, V|E, "me_method" },
 
484
{"hex", "hex motion estimation", 0, FF_OPT_TYPE_CONST, ME_HEX, INT_MIN, INT_MAX, V|E, "me_method" },
 
485
{"umh", "umh motion estimation", 0, FF_OPT_TYPE_CONST, ME_UMH, INT_MIN, INT_MAX, V|E, "me_method" },
 
486
{"iter", "iter motion estimation", 0, FF_OPT_TYPE_CONST, ME_ITER, INT_MIN, INT_MAX, V|E, "me_method" },
455
487
{"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
456
488
{"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
457
489
{"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E},
510
542
{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|E, "strict"},
511
543
{"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|E, "strict"},
512
544
{"inofficial", "allow inofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|E, "strict"},
513
 
{"experimental", "allow non standarized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"},
514
 
{"b_qoffset", "qp offset between p and b frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, FLT_MAX, V|E},
 
545
{"experimental", "allow non standardized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"},
 
546
{"b_qoffset", "qp offset between P and B frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, FLT_MAX, V|E},
515
547
{"er", "set error resilience strategy", OFFSET(error_resilience), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"},
516
548
{"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
517
549
{"compliant", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"},
530
562
{"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
531
563
{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
532
564
{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
533
 
{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
 
565
{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|E},
534
566
{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, 1.0, FLT_MIN, FLT_MAX, V|E},
535
 
{"i_qfactor", "qp factor between p and i frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E},
536
 
{"i_qoffset", "qp offset between p and i frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E},
 
567
{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E},
 
568
{"i_qoffset", "qp offset between P and I frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E},
537
569
{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E},
538
570
{"dct", "DCT algorithm", OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"},
539
571
{"auto", "autoselect a good one (default)", 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"},
566
598
{"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
567
599
{"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
568
600
{"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
 
601
{"faani", "floating point AAN IDCT", 0, FF_OPT_TYPE_CONST, FF_IDCT_FAAN, INT_MIN, INT_MAX, V|D|E, "idct"},
569
602
{"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
570
603
{"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
571
604
{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
635
668
{"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
636
669
{"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
637
670
{"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
 
671
{"raw", "raw (no encoding)", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RAW, INT_MIN, INT_MAX, V|E, "coder"},
 
672
{"rle", "run-length coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RLE, INT_MIN, INT_MAX, V|E, "coder"},
 
673
{"deflate", "deflate-based coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_DEFLATE, INT_MIN, INT_MAX, V|E, "coder"},
638
674
{"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
639
675
{"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
640
676
{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
649
685
{"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
650
686
{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
651
687
{"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
652
 
{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|A|E|D, "flags2"},
 
688
{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR, 0, UINT_MAX, V|A|E|D, "flags2"},
653
689
{"error", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
654
690
{"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"},
655
691
{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"},
666
702
{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
667
703
{"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
668
704
{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
 
705
{"aac_main", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_MAIN, INT_MIN, INT_MAX, A|E, "profile"},
 
706
{"aac_low", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LOW, INT_MIN, INT_MAX, A|E, "profile"},
 
707
{"aac_ssr", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_SSR, INT_MIN, INT_MAX, A|E, "profile"},
 
708
{"aac_ltp", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LTP, INT_MIN, INT_MAX, A|E, "profile"},
669
709
{"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
670
710
{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
671
711
{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D},
690
730
{"bpyramid", "allows B-frames to be used as references for predicting", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BPYRAMID, INT_MIN, INT_MAX, V|E, "flags2"},
691
731
{"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"},
692
732
{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MIXED_REFS, INT_MIN, INT_MAX, V|E, "flags2"},
693
 
{"8x8dct", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
 
733
{"dct8x8", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
694
734
{"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"},
695
735
{"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"},
696
736
{"brdo", "b-frame rate-distortion optimization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BRDO, INT_MIN, INT_MAX, V|E, "flags2"},
697
 
{"skiprd", "RD optimal MB level residual skiping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"},
 
737
{"skiprd", "RD optimal MB level residual skipping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"},
698
738
{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E},
699
739
{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
700
740
{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E},
718
758
{"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
719
759
{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E},
720
760
{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
 
761
{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"},
 
762
{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D},
 
763
{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D},
 
764
{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"},
721
765
{NULL},
722
766
};
723
767
 
728
772
#undef D
729
773
#undef DEFAULT
730
774
 
731
 
static AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
 
775
static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
732
776
 
733
 
void avcodec_get_context_defaults(AVCodecContext *s){
 
777
void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){
 
778
    int flags=0;
734
779
    memset(s, 0, sizeof(AVCodecContext));
735
780
 
736
781
    s->av_class= &av_codec_context_class;
737
782
 
738
 
    av_opt_set_defaults(s);
 
783
    s->codec_type = codec_type;
 
784
    if(codec_type == CODEC_TYPE_AUDIO)
 
785
        flags= AV_OPT_FLAG_AUDIO_PARAM;
 
786
    else if(codec_type == CODEC_TYPE_VIDEO)
 
787
        flags= AV_OPT_FLAG_VIDEO_PARAM;
 
788
    else if(codec_type == CODEC_TYPE_SUBTITLE)
 
789
        flags= AV_OPT_FLAG_SUBTITLE_PARAM;
 
790
    av_opt_set_defaults2(s, flags, flags);
739
791
 
740
792
    s->rc_eq= "tex^qComp";
741
793
    s->time_base= (AVRational){0,1};
751
803
    s->reget_buffer= avcodec_default_reget_buffer;
752
804
}
753
805
 
754
 
AVCodecContext *avcodec_alloc_context(void){
 
806
AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
755
807
    AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
756
808
 
757
809
    if(avctx==NULL) return NULL;
758
810
 
759
 
    avcodec_get_context_defaults(avctx);
 
811
    avcodec_get_context_defaults2(avctx, codec_type);
760
812
 
761
813
    return avctx;
762
814
}
763
815
 
 
816
void avcodec_get_context_defaults(AVCodecContext *s){
 
817
    avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);
 
818
}
 
819
 
 
820
AVCodecContext *avcodec_alloc_context(void){
 
821
    return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);
 
822
}
 
823
 
764
824
void avcodec_get_frame_defaults(AVFrame *pic){
765
825
    memset(pic, 0, sizeof(AVFrame));
766
826
 
778
838
    return pic;
779
839
}
780
840
 
781
 
int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
 
841
int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
782
842
{
783
843
    int ret= -1;
784
844
 
788
848
        goto end;
789
849
    }
790
850
 
791
 
    if(avctx->codec)
 
851
    if(avctx->codec || !codec)
792
852
        goto end;
793
853
 
794
854
    if (codec->priv_data_size > 0) {
795
855
        avctx->priv_data = av_mallocz(codec->priv_data_size);
796
 
        if (!avctx->priv_data)
 
856
        if (!avctx->priv_data) {
 
857
            ret = AVERROR(ENOMEM);
797
858
            goto end;
 
859
        }
798
860
    } else {
799
861
        avctx->priv_data = NULL;
800
862
    }
806
868
 
807
869
    if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){
808
870
        av_freep(&avctx->priv_data);
 
871
        ret = AVERROR(EINVAL);
809
872
        goto end;
810
873
    }
811
874
 
812
875
    avctx->codec = codec;
813
876
    avctx->codec_id = codec->id;
814
877
    avctx->frame_number = 0;
815
 
    ret = avctx->codec->init(avctx);
816
 
    if (ret < 0) {
817
 
        av_freep(&avctx->priv_data);
818
 
        avctx->codec= NULL;
819
 
        goto end;
 
878
    if(avctx->codec->init){
 
879
        ret = avctx->codec->init(avctx);
 
880
        if (ret < 0) {
 
881
            av_freep(&avctx->priv_data);
 
882
            avctx->codec= NULL;
 
883
            goto end;
 
884
        }
820
885
    }
821
886
    ret=0;
822
887
end:
824
889
    return ret;
825
890
}
826
891
 
827
 
int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
 
892
int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
828
893
                         const short *samples)
829
894
{
830
895
    if(buf_size < FF_MIN_BUFFER_SIZE && 0){
839
904
        return 0;
840
905
}
841
906
 
842
 
int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
 
907
int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
843
908
                         const AVFrame *pict)
844
909
{
845
910
    if(buf_size < FF_MIN_BUFFER_SIZE){
867
932
    return ret;
868
933
}
869
934
 
870
 
int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
 
935
int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
871
936
                         int *got_picture_ptr,
872
 
                         uint8_t *buf, int buf_size)
 
937
                         const uint8_t *buf, int buf_size)
873
938
{
874
939
    int ret;
875
940
 
890
955
    return ret;
891
956
}
892
957
 
893
 
int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
 
958
int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
894
959
                         int *frame_size_ptr,
895
 
                         uint8_t *buf, int buf_size)
 
960
                         const uint8_t *buf, int buf_size)
896
961
{
897
962
    int ret;
898
963
 
903
968
            return -1;
904
969
        }
905
970
        if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
906
 
        *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t) ||
907
 
        *frame_size_ptr < buf_size){
 
971
        *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
908
972
            av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
909
973
            return -1;
910
974
        }
922
986
#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
923
987
int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
924
988
                         int *frame_size_ptr,
925
 
                         uint8_t *buf, int buf_size){
 
989
                         const uint8_t *buf, int buf_size){
926
990
    *frame_size_ptr= AVCODEC_MAX_AUDIO_FRAME_SIZE;
927
991
    return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, buf_size);
928
992
}
936
1000
 
937
1001
    *got_sub_ptr = 0;
938
1002
    ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
939
 
                               (uint8_t *)buf, buf_size);
 
1003
                               buf, buf_size);
940
1004
    if (*got_sub_ptr)
941
1005
        avctx->frame_number++;
942
1006
    return ret;
951
1015
        return -1;
952
1016
    }
953
1017
 
 
1018
    if (ENABLE_THREADS && avctx->thread_opaque)
 
1019
        avcodec_thread_free(avctx);
954
1020
    if (avctx->codec->close)
955
1021
        avctx->codec->close(avctx);
956
1022
    avcodec_default_free_buffers(avctx);
1015
1081
    char buf1[32];
1016
1082
    char channels_str[100];
1017
1083
    int bitrate;
 
1084
    AVRational display_aspect_ratio;
1018
1085
 
1019
1086
    if (encode)
1020
1087
        p = avcodec_find_encoder(enc->codec_id);
1065
1132
            snprintf(buf + strlen(buf), buf_size - strlen(buf),
1066
1133
                     ", %dx%d",
1067
1134
                     enc->width, enc->height);
1068
 
            if(av_log_level >= AV_LOG_DEBUG){
 
1135
            if (enc->sample_aspect_ratio.num) {
 
1136
                av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
 
1137
                          enc->width*enc->sample_aspect_ratio.num,
 
1138
                          enc->height*enc->sample_aspect_ratio.den,
 
1139
                          1024*1024);
 
1140
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
 
1141
                         " [PAR %d:%d DAR %d:%d]",
 
1142
                         enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
 
1143
                         display_aspect_ratio.num, display_aspect_ratio.den);
 
1144
            }
 
1145
            if(av_log_get_level() >= AV_LOG_DEBUG){
1069
1146
                int g= ff_gcd(enc->time_base.num, enc->time_base.den);
1070
1147
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
1071
1148
                     ", %d/%d",
1120
1197
            break;
1121
1198
        case CODEC_ID_PCM_S16LE:
1122
1199
        case CODEC_ID_PCM_S16BE:
 
1200
        case CODEC_ID_PCM_S16LE_PLANAR:
1123
1201
        case CODEC_ID_PCM_U16LE:
1124
1202
        case CODEC_ID_PCM_U16BE:
1125
1203
            bitrate = enc->sample_rate * enc->channels * 16;
1143
1221
        snprintf(buf, buf_size, "Subtitle: %s", codec_name);
1144
1222
        bitrate = enc->bit_rate;
1145
1223
        break;
 
1224
    case CODEC_TYPE_ATTACHMENT:
 
1225
        snprintf(buf, buf_size, "Attachment: %s", codec_name);
 
1226
        bitrate = enc->bit_rate;
 
1227
        break;
1146
1228
    default:
1147
1229
        snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
1148
1230
        return;
1171
1253
  return LIBAVCODEC_BUILD;
1172
1254
}
1173
1255
 
1174
 
static void init_crcs(void){
1175
 
    av_crc04C11DB7= av_mallocz_static(sizeof(AVCRC) * 257);
1176
 
    av_crc8005    = av_mallocz_static(sizeof(AVCRC) * 257);
1177
 
    av_crc07      = av_mallocz_static(sizeof(AVCRC) * 257);
1178
 
    av_crc_init(av_crc04C11DB7, 0, 32, 0x04c11db7, sizeof(AVCRC)*257);
1179
 
    av_crc_init(av_crc8005    , 0, 16, 0x8005    , sizeof(AVCRC)*257);
1180
 
    av_crc_init(av_crc07      , 0,  8, 0x07      , sizeof(AVCRC)*257);
1181
 
}
1182
 
 
1183
1256
void avcodec_init(void)
1184
1257
{
1185
 
    static int inited = 0;
 
1258
    static int initialized = 0;
1186
1259
 
1187
 
    if (inited != 0)
 
1260
    if (initialized != 0)
1188
1261
        return;
1189
 
    inited = 1;
 
1262
    initialized = 1;
1190
1263
 
1191
1264
    dsputil_static_init();
1192
 
    init_crcs();
1193
1265
}
1194
1266
 
1195
1267
void avcodec_flush_buffers(AVCodecContext *avctx)
1217
1289
 
1218
1290
char av_get_pict_type_char(int pict_type){
1219
1291
    switch(pict_type){
1220
 
    case I_TYPE: return 'I';
1221
 
    case P_TYPE: return 'P';
1222
 
    case B_TYPE: return 'B';
1223
 
    case S_TYPE: return 'S';
1224
 
    case SI_TYPE:return 'i';
1225
 
    case SP_TYPE:return 'p';
1226
 
    default:     return '?';
 
1292
    case FF_I_TYPE: return 'I';
 
1293
    case FF_P_TYPE: return 'P';
 
1294
    case FF_B_TYPE: return 'B';
 
1295
    case FF_S_TYPE: return 'S';
 
1296
    case FF_SI_TYPE:return 'i';
 
1297
    case FF_SP_TYPE:return 'p';
 
1298
    case FF_BI_TYPE:return 'b';
 
1299
    default:        return '?';
1227
1300
    }
1228
1301
}
1229
1302
 
1243
1316
        return 8;
1244
1317
    case CODEC_ID_PCM_S16BE:
1245
1318
    case CODEC_ID_PCM_S16LE:
 
1319
    case CODEC_ID_PCM_S16LE_PLANAR:
1246
1320
    case CODEC_ID_PCM_U16BE:
1247
1321
    case CODEC_ID_PCM_U16LE:
1248
1322
        return 16;
1262
1336
    }
1263
1337
}
1264
1338
 
 
1339
int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
 
1340
    switch (sample_fmt) {
 
1341
    case SAMPLE_FMT_U8:
 
1342
        return 8;
 
1343
    case SAMPLE_FMT_S16:
 
1344
        return 16;
 
1345
    case SAMPLE_FMT_S24:
 
1346
        return 24;
 
1347
    case SAMPLE_FMT_S32:
 
1348
    case SAMPLE_FMT_FLT:
 
1349
        return 32;
 
1350
    default:
 
1351
        return 0;
 
1352
    }
 
1353
}
 
1354
 
1265
1355
#if !defined(HAVE_THREADS)
1266
1356
int avcodec_thread_init(AVCodecContext *s, int thread_count){
1267
1357
    return -1;
1289
1379
 * and opened file name in **filename. */
1290
1380
int av_tempfile(char *prefix, char **filename) {
1291
1381
    int fd=-1;
1292
 
#ifdef __MINGW32__
 
1382
#if !defined(HAVE_MKSTEMP)
1293
1383
    *filename = tempnam(".", prefix);
1294
1384
#else
1295
1385
    size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
1300
1390
        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
1301
1391
        return -1;
1302
1392
    }
1303
 
#ifdef __MINGW32__
1304
 
    fd = open(*filename, _O_RDWR | _O_BINARY | _O_CREAT, 0444);
 
1393
#if !defined(HAVE_MKSTEMP)
 
1394
    fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
1305
1395
#else
1306
1396
    snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
1307
1397
    fd = mkstemp(*filename);
1317
1407
    }
1318
1408
    return fd; /* success */
1319
1409
}
 
1410
 
 
1411
typedef struct {
 
1412
    const char *abbr;
 
1413
    int width, height;
 
1414
} VideoFrameSizeAbbr;
 
1415
 
 
1416
typedef struct {
 
1417
    const char *abbr;
 
1418
    int rate_num, rate_den;
 
1419
} VideoFrameRateAbbr;
 
1420
 
 
1421
static VideoFrameSizeAbbr video_frame_size_abbrs[] = {
 
1422
    { "ntsc",      720, 480 },
 
1423
    { "pal",       720, 576 },
 
1424
    { "qntsc",     352, 240 }, /* VCD compliant NTSC */
 
1425
    { "qpal",      352, 288 }, /* VCD compliant PAL */
 
1426
    { "sntsc",     640, 480 }, /* square pixel NTSC */
 
1427
    { "spal",      768, 576 }, /* square pixel PAL */
 
1428
    { "film",      352, 240 },
 
1429
    { "ntsc-film", 352, 240 },
 
1430
    { "sqcif",     128,  96 },
 
1431
    { "qcif",      176, 144 },
 
1432
    { "cif",       352, 288 },
 
1433
    { "4cif",      704, 576 },
 
1434
    { "qqvga",     160, 120 },
 
1435
    { "qvga",      320, 240 },
 
1436
    { "vga",       640, 480 },
 
1437
    { "svga",      800, 600 },
 
1438
    { "xga",      1024, 768 },
 
1439
    { "uxga",     1600,1200 },
 
1440
    { "qxga",     2048,1536 },
 
1441
    { "sxga",     1280,1024 },
 
1442
    { "qsxga",    2560,2048 },
 
1443
    { "hsxga",    5120,4096 },
 
1444
    { "wvga",      852, 480 },
 
1445
    { "wxga",     1366, 768 },
 
1446
    { "wsxga",    1600,1024 },
 
1447
    { "wuxga",    1920,1200 },
 
1448
    { "woxga",    2560,1600 },
 
1449
    { "wqsxga",   3200,2048 },
 
1450
    { "wquxga",   3840,2400 },
 
1451
    { "whsxga",   6400,4096 },
 
1452
    { "whuxga",   7680,4800 },
 
1453
    { "cga",       320, 200 },
 
1454
    { "ega",       640, 350 },
 
1455
    { "hd480",     852, 480 },
 
1456
    { "hd720",    1280, 720 },
 
1457
    { "hd1080",   1920,1080 },
 
1458
};
 
1459
 
 
1460
static VideoFrameRateAbbr video_frame_rate_abbrs[]= {
 
1461
    { "ntsc",      30000, 1001 },
 
1462
    { "pal",          25,    1 },
 
1463
    { "qntsc",     30000, 1001 }, /* VCD compliant NTSC */
 
1464
    { "qpal",         25,    1 }, /* VCD compliant PAL */
 
1465
    { "sntsc",     30000, 1001 }, /* square pixel NTSC */
 
1466
    { "spal",         25,    1 }, /* square pixel PAL */
 
1467
    { "film",         24,    1 },
 
1468
    { "ntsc-film", 24000, 1001 },
 
1469
};
 
1470
 
 
1471
int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
 
1472
{
 
1473
    int i;
 
1474
    int n = sizeof(video_frame_size_abbrs) / sizeof(VideoFrameSizeAbbr);
 
1475
    const char *p;
 
1476
    int frame_width = 0, frame_height = 0;
 
1477
 
 
1478
    for(i=0;i<n;i++) {
 
1479
        if (!strcmp(video_frame_size_abbrs[i].abbr, str)) {
 
1480
            frame_width = video_frame_size_abbrs[i].width;
 
1481
            frame_height = video_frame_size_abbrs[i].height;
 
1482
            break;
 
1483
        }
 
1484
    }
 
1485
    if (i == n) {
 
1486
        p = str;
 
1487
        frame_width = strtol(p, (char **)&p, 10);
 
1488
        if (*p)
 
1489
            p++;
 
1490
        frame_height = strtol(p, (char **)&p, 10);
 
1491
    }
 
1492
    if (frame_width <= 0 || frame_height <= 0)
 
1493
        return -1;
 
1494
    *width_ptr = frame_width;
 
1495
    *height_ptr = frame_height;
 
1496
    return 0;
 
1497
}
 
1498
 
 
1499
int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
 
1500
{
 
1501
    int i;
 
1502
    int n = sizeof(video_frame_rate_abbrs) / sizeof(VideoFrameRateAbbr);
 
1503
    char* cp;
 
1504
 
 
1505
    /* First, we check our abbreviation table */
 
1506
    for (i = 0; i < n; ++i)
 
1507
         if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) {
 
1508
             frame_rate->num = video_frame_rate_abbrs[i].rate_num;
 
1509
             frame_rate->den = video_frame_rate_abbrs[i].rate_den;
 
1510
             return 0;
 
1511
         }
 
1512
 
 
1513
    /* Then, we try to parse it as fraction */
 
1514
    cp = strchr(arg, '/');
 
1515
    if (!cp)
 
1516
        cp = strchr(arg, ':');
 
1517
    if (cp) {
 
1518
        char* cpp;
 
1519
        frame_rate->num = strtol(arg, &cpp, 10);
 
1520
        if (cpp != arg || cpp == cp)
 
1521
            frame_rate->den = strtol(cp+1, &cpp, 10);
 
1522
        else
 
1523
           frame_rate->num = 0;
 
1524
    }
 
1525
    else {
 
1526
        /* Finally we give up and parse it as double */
 
1527
        AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
 
1528
        frame_rate->den = time_base.den;
 
1529
        frame_rate->num = time_base.num;
 
1530
    }
 
1531
    if (!frame_rate->num || !frame_rate->den)
 
1532
        return -1;
 
1533
    else
 
1534
        return 0;
 
1535
}