~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/mpeg4videoenc.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
21
 */
22
22
 
 
23
#include "libavutil/log.h"
 
24
#include "libavutil/opt.h"
23
25
#include "mpegvideo.h"
24
26
#include "h263.h"
25
27
#include "mpeg4video.h"
124
126
{
125
127
    int score= 0;
126
128
    int i, n;
127
 
    int8_t * const qscale_table= s->current_picture.qscale_table;
 
129
    int8_t * const qscale_table = s->current_picture.f.qscale_table;
128
130
 
129
131
    memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6);
130
132
 
201
203
 */
202
204
void ff_clean_mpeg4_qscales(MpegEncContext *s){
203
205
    int i;
204
 
    int8_t * const qscale_table= s->current_picture.qscale_table;
 
206
    int8_t * const qscale_table = s->current_picture.f.qscale_table;
205
207
 
206
208
    ff_clean_h263_qscales(s);
207
209
 
236
238
 
237
239
 
238
240
/**
239
 
 * encodes the dc value.
 
241
 * Encode the dc value.
240
242
 * @param n block index (0-3 are luma, 4-5 are chroma)
241
243
 */
242
244
static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n)
289
291
}
290
292
 
291
293
/**
292
 
 * encodes a 8x8 block
 
294
 * Encode an 8x8 block.
293
295
 * @param n block index (0-3 are luma, 4-5 are chroma)
294
296
 */
295
297
static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc,
296
298
                               uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
297
299
{
298
300
    int i, last_non_zero;
299
 
#if 0 //variables for the outcommented version
300
 
    int code, sign, last;
301
 
#endif
302
 
    const RLTable *rl;
303
301
    uint32_t *bits_tab;
304
302
    uint8_t *len_tab;
305
303
    const int last_index = s->block_last_index[n];
309
307
        mpeg4_encode_dc(dc_pb, intra_dc, n);
310
308
        if(last_index<1) return;
311
309
        i = 1;
312
 
        rl = &ff_mpeg4_rl_intra;
313
310
        bits_tab= uni_mpeg4_intra_rl_bits;
314
311
        len_tab = uni_mpeg4_intra_rl_len;
315
312
    } else {
316
313
        if(last_index<0) return;
317
314
        i = 0;
318
 
        rl = &ff_h263_rl_inter;
319
315
        bits_tab= uni_mpeg4_inter_rl_bits;
320
316
        len_tab = uni_mpeg4_inter_rl_len;
321
317
    }
322
318
 
323
319
    /* AC coefs */
324
320
    last_non_zero = i - 1;
325
 
#if 1
326
321
    for (; i < last_index; i++) {
327
322
        int level = block[ scan_table[i] ];
328
323
        if (level) {
348
343
            put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
349
344
        }
350
345
    }
351
 
#else
352
 
    for (; i <= last_index; i++) {
353
 
        const int slevel = block[ scan_table[i] ];
354
 
        if (slevel) {
355
 
            int level;
356
 
            int run = i - last_non_zero - 1;
357
 
            last = (i == last_index);
358
 
            sign = 0;
359
 
            level = slevel;
360
 
            if (level < 0) {
361
 
                sign = 1;
362
 
                level = -level;
363
 
            }
364
 
            code = get_rl_index(rl, last, run, level);
365
 
            put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
366
 
            if (code == rl->n) {
367
 
                int level1, run1;
368
 
                level1 = level - rl->max_level[last][run];
369
 
                if (level1 < 1)
370
 
                    goto esc2;
371
 
                code = get_rl_index(rl, last, run, level1);
372
 
                if (code == rl->n) {
373
 
                esc2:
374
 
                    put_bits(ac_pb, 1, 1);
375
 
                    if (level > MAX_LEVEL)
376
 
                        goto esc3;
377
 
                    run1 = run - rl->max_run[last][level] - 1;
378
 
                    if (run1 < 0)
379
 
                        goto esc3;
380
 
                    code = get_rl_index(rl, last, run1, level);
381
 
                    if (code == rl->n) {
382
 
                    esc3:
383
 
                        /* third escape */
384
 
                        put_bits(ac_pb, 1, 1);
385
 
                        put_bits(ac_pb, 1, last);
386
 
                        put_bits(ac_pb, 6, run);
387
 
                        put_bits(ac_pb, 1, 1);
388
 
                        put_sbits(ac_pb, 12, slevel);
389
 
                        put_bits(ac_pb, 1, 1);
390
 
                    } else {
391
 
                        /* second escape */
392
 
                        put_bits(ac_pb, 1, 0);
393
 
                        put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
394
 
                        put_bits(ac_pb, 1, sign);
395
 
                    }
396
 
                } else {
397
 
                    /* first escape */
398
 
                    put_bits(ac_pb, 1, 0);
399
 
                    put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
400
 
                    put_bits(ac_pb, 1, sign);
401
 
                }
402
 
            } else {
403
 
                put_bits(ac_pb, 1, sign);
404
 
            }
405
 
            last_non_zero = i;
406
 
        }
407
 
    }
408
 
#endif
409
346
}
410
347
 
411
348
static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc,
488
425
    }
489
426
}
490
427
 
 
428
static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64],
 
429
                            int motion_x, int motion_y, int mb_type)
 
430
{
 
431
    int cbp = 0, i;
 
432
 
 
433
    if (s->flags & CODEC_FLAG_CBP_RD) {
 
434
        int score = 0;
 
435
        const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
 
436
 
 
437
        for (i = 0; i < 6; i++)
 
438
            if (s->coded_score[i] < 0) {
 
439
                score += s->coded_score[i];
 
440
                cbp   |= 1 << (5 - i);
 
441
            }
 
442
 
 
443
        if (cbp) {
 
444
            int zero_score = -6;
 
445
            if ((motion_x | motion_y | s->dquant | mb_type) == 0)
 
446
                zero_score -= 4; //2*MV + mb_type + cbp bit
 
447
 
 
448
            zero_score *= lambda;
 
449
            if (zero_score <= score)
 
450
                cbp = 0;
 
451
        }
 
452
 
 
453
        for (i = 0; i < 6; i++) {
 
454
            if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i)) & 1) == 0) {
 
455
                s->block_last_index[i] = -1;
 
456
                s->dsp.clear_block(s->block[i]);
 
457
            }
 
458
        }
 
459
    } else {
 
460
        for (i = 0; i < 6; i++) {
 
461
            if (s->block_last_index[i] >= 0)
 
462
                cbp |= 1 << (5 - i);
 
463
        }
 
464
    }
 
465
    return cbp;
 
466
}
 
467
 
491
468
//FIXME this is duplicated to h263.c
492
469
static const int dquant_code[5]= {1,0,9,2,3};
493
470
 
522
499
            assert(mb_type>=0);
523
500
 
524
501
            /* nothing to do if this MB was skipped in the next P Frame */
525
 
            if(s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]){ //FIXME avoid DCT & ...
 
502
            if (s->next_picture.f.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]) { //FIXME avoid DCT & ...
526
503
                s->skip_count++;
527
504
                s->mv[0][0][0]=
528
505
                s->mv[0][0][1]=
654
631
                    if(y+16 > s->height) y= s->height-16;
655
632
 
656
633
                    offset= x + y*s->linesize;
657
 
                    p_pic= s->new_picture.data[0] + offset;
 
634
                    p_pic = s->new_picture.f.data[0] + offset;
658
635
 
659
636
                    s->mb_skipped=1;
660
637
                    for(i=0; i<s->max_b_frames; i++){
662
639
                        int diff;
663
640
                        Picture *pic= s->reordered_input_picture[i+1];
664
641
 
665
 
                        if(pic==NULL || pic->pict_type!=AV_PICTURE_TYPE_B) break;
 
642
                        if (pic == NULL || pic->f.pict_type != AV_PICTURE_TYPE_B)
 
643
                            break;
666
644
 
667
 
                        b_pic= pic->data[0] + offset;
668
 
                        if(pic->type != FF_BUFFER_TYPE_SHARED)
 
645
                        b_pic = pic->f.data[0] + offset;
 
646
                        if (pic->f.type != FF_BUFFER_TYPE_SHARED)
669
647
                            b_pic+= INPLACE_OFFSET;
670
648
                        diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
671
649
                        if(diff>s->qscale*70){ //FIXME check that 70 is optimal
769
747
                    /* motion vectors: 8x8 mode*/
770
748
                    h263_pred_motion(s, i, 0, &pred_x, &pred_y);
771
749
 
772
 
                    ff_h263_encode_motion_vector(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x,
773
 
                                                    s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
 
750
                    ff_h263_encode_motion_vector(s, s->current_picture.f.motion_val[0][ s->block_index[i] ][0] - pred_x,
 
751
                                                    s->current_picture.f.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
774
752
                }
775
753
            }
776
754
 
879
857
    put_bits(&s->pb, 16, 0);
880
858
    put_bits(&s->pb, 16, GOP_STARTCODE);
881
859
 
882
 
    time= s->current_picture_ptr->pts;
 
860
    time = s->current_picture_ptr->f.pts;
883
861
    if(s->reordered_input_picture[1])
884
 
        time= FFMIN(time, s->reordered_input_picture[1]->pts);
 
862
        time = FFMIN(time, s->reordered_input_picture[1]->f.pts);
885
863
    time= time*s->avctx->time_base.num;
886
864
 
887
865
    seconds= time/s->avctx->time_base.den;
1091
1069
    }
1092
1070
    put_bits(&s->pb, 3, 0);     /* intra dc VLC threshold */
1093
1071
    if(!s->progressive_sequence){
1094
 
         put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);
 
1072
         put_bits(&s->pb, 1, s->current_picture_ptr->f.top_field_first);
1095
1073
         put_bits(&s->pb, 1, s->alternate_scan);
1096
1074
    }
1097
1075
    //FIXME sprite stuff
1265
1243
    s->inter_ac_vlc_length     = uni_mpeg4_inter_rl_len;
1266
1244
    s->inter_ac_vlc_last_length= uni_mpeg4_inter_rl_len + 128*64;
1267
1245
    s->luma_dc_vlc_length= uni_DCtab_lum_len;
1268
 
    s->chroma_dc_vlc_length= uni_DCtab_chrom_len;
1269
1246
    s->ac_esc_length= 7+2+1+6+1+12+1;
1270
1247
    s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
1271
1248
    s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
1320
1297
    flush_put_bits(&s->tex_pb);
1321
1298
 
1322
1299
    set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf);
1323
 
    ff_copy_bits(&s->pb, s->pb2.buf   , pb2_len);
1324
 
    ff_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
 
1300
    avpriv_copy_bits(&s->pb, s->pb2.buf   , pb2_len);
 
1301
    avpriv_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
1325
1302
    s->last_bits= put_bits_count(&s->pb);
1326
1303
}
1327
1304
 
1338
1315
    put_bits(&s->pb, 1, 0); /* no HEC */
1339
1316
}
1340
1317
 
 
1318
#define OFFSET(x) offsetof(MpegEncContext, x)
 
1319
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 
1320
static const AVOption options[] = {
 
1321
    { "data_partitioning",       "Use data partitioning.",      OFFSET(data_partitioning), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
 
1322
    { "alternate_scan",          "Enable alternate scantable.", OFFSET(alternate_scan),    AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
 
1323
    { NULL },
 
1324
};
 
1325
 
 
1326
static const AVClass mpeg4enc_class = {
 
1327
    .class_name = "MPEG4 encoder",
 
1328
    .item_name  = av_default_item_name,
 
1329
    .option     = options,
 
1330
    .version    = LIBAVUTIL_VERSION_INT,
 
1331
};
 
1332
 
1341
1333
AVCodec ff_mpeg4_encoder = {
1342
 
    "mpeg4",
1343
 
    AVMEDIA_TYPE_VIDEO,
1344
 
    CODEC_ID_MPEG4,
1345
 
    sizeof(MpegEncContext),
1346
 
    encode_init,
1347
 
    MPV_encode_picture,
1348
 
    MPV_encode_end,
 
1334
    .name           = "mpeg4",
 
1335
    .type           = AVMEDIA_TYPE_VIDEO,
 
1336
    .id             = CODEC_ID_MPEG4,
 
1337
    .priv_data_size = sizeof(MpegEncContext),
 
1338
    .init           = encode_init,
 
1339
    .encode         = MPV_encode_picture,
 
1340
    .close          = MPV_encode_end,
1349
1341
    .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
1350
1342
    .capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
1351
1343
    .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
 
1344
    .priv_class     = &mpeg4enc_class,
1352
1345
};