~ubuntu-branches/ubuntu/oneiric/libav/oneiric

« back to all changes in this revision

Viewing changes to libavcodec/mpegvideo.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-30 14:27:42 UTC
  • mfrom: (1.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110430142742-quvblxk1tj6adlh5
Tags: 4:0.7~b1-1ubuntu1
* Merge from debian. Remaining changes:
  - don't build against libfaad, libdirac, librtmp and libopenjpeg
    (all in universe)
  - explicitly --enable-pic on powerpc, cf. LP #654666
  - different arm configure bits that should probably better be
    merged into debian
* Cherry-picked from git: 
  - install doc/APIChanges and refer to them in NEWS.Debian (Closes: #623682)
  - don't try to install non-existing documentation, fixes FTBFS on powerpc

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
7
7
 *
8
 
 * This file is part of FFmpeg.
 
8
 * This file is part of Libav.
9
9
 *
10
 
 * FFmpeg is free software; you can redistribute it and/or
 
10
 * Libav is free software; you can redistribute it and/or
11
11
 * modify it under the terms of the GNU Lesser General Public
12
12
 * License as published by the Free Software Foundation; either
13
13
 * version 2.1 of the License, or (at your option) any later version.
14
14
 *
15
 
 * FFmpeg is distributed in the hope that it will be useful,
 
15
 * Libav is distributed in the hope that it will be useful,
16
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
18
 * Lesser General Public License for more details.
19
19
 *
20
20
 * You should have received a copy of the GNU Lesser General Public
21
 
 * License along with FFmpeg; if not, write to the Free Software
 
21
 * License along with Libav; if not, write to the Free Software
22
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
23
 */
24
24
 
28
28
 */
29
29
 
30
30
#include "libavutil/intmath.h"
 
31
#include "libavutil/imgutils.h"
31
32
#include "avcodec.h"
32
33
#include "dsputil.h"
 
34
#include "internal.h"
33
35
#include "mpegvideo.h"
34
36
#include "mpegvideo_common.h"
35
37
#include "mjpegenc.h"
199
201
}
200
202
 
201
203
/**
202
 
 * Releases a frame buffer
 
204
 * Release a frame buffer
203
205
 */
204
206
static void free_frame_buffer(MpegEncContext *s, Picture *pic)
205
207
{
208
210
}
209
211
 
210
212
/**
211
 
 * Allocates a frame buffer
 
213
 * Allocate a frame buffer
212
214
 */
213
215
static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
214
216
{
355
357
}
356
358
 
357
359
static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){
 
360
    int y_size = s->b8_stride * (2 * s->mb_height + 1);
 
361
    int c_size = s->mb_stride * (s->mb_height + 1);
 
362
    int yc_size = y_size + 2 * c_size;
358
363
    int i;
359
364
 
360
365
    // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)
380
385
    for(i=0;i<12;i++){
381
386
        s->pblocks[i] = &s->block[i];
382
387
    }
 
388
 
 
389
    if (s->out_format == FMT_H263) {
 
390
        /* ac values */
 
391
        FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail);
 
392
        s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
 
393
        s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
 
394
        s->ac_val[2] = s->ac_val[1] + c_size;
 
395
    }
 
396
 
383
397
    return 0;
384
398
fail:
385
399
    return -1; //free() through MPV_common_end()
399
413
    av_freep(&s->me.map);
400
414
    av_freep(&s->me.score_map);
401
415
    av_freep(&s->blocks);
 
416
    av_freep(&s->ac_val_base);
402
417
    s->block= NULL;
403
418
}
404
419
 
422
437
    COPY(dct_error_sum);
423
438
    COPY(dct_count[0]);
424
439
    COPY(dct_count[1]);
 
440
    COPY(ac_val_base);
 
441
    COPY(ac_val[0]);
 
442
    COPY(ac_val[1]);
 
443
    COPY(ac_val[2]);
425
444
#undef COPY
426
445
}
427
446
 
479
498
 
480
499
    if(s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
481
500
        s->mb_height = (s->height + 31) / 32 * 2;
482
 
    else
 
501
    else if (s->codec_id != CODEC_ID_H264)
483
502
        s->mb_height = (s->height + 15) / 16;
484
503
 
485
504
    if(s->avctx->pix_fmt == PIX_FMT_NONE){
492
511
        return -1;
493
512
    }
494
513
 
495
 
    if((s->width || s->height) && avcodec_check_dimensions(s->avctx, s->width, s->height))
 
514
    if((s->width || s->height) && av_image_check_size(s->width, s->height, 0, s->avctx))
496
515
        return -1;
497
516
 
498
517
    dsputil_init(&s->dsp, s->avctx);
530
549
    yc_size = y_size + 2 * c_size;
531
550
 
532
551
    /* convert fourcc to upper case */
533
 
    s->codec_tag=          toupper( s->avctx->codec_tag     &0xFF)
534
 
                        + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 )
535
 
                        + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16)
536
 
                        + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24);
 
552
    s->codec_tag = ff_toupper4(s->avctx->codec_tag);
537
553
 
538
 
    s->stream_codec_tag=          toupper( s->avctx->stream_codec_tag     &0xFF)
539
 
                               + (toupper((s->avctx->stream_codec_tag>>8 )&0xFF)<<8 )
540
 
                               + (toupper((s->avctx->stream_codec_tag>>16)&0xFF)<<16)
541
 
                               + (toupper((s->avctx->stream_codec_tag>>24)&0xFF)<<24);
 
554
    s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag);
542
555
 
543
556
    s->avctx->coded_frame= (AVFrame*)&s->current_picture;
544
557
 
610
623
            }
611
624
    }
612
625
    if (s->out_format == FMT_H263) {
613
 
        /* ac values */
614
 
        FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail);
615
 
        s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
616
 
        s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
617
 
        s->ac_val[2] = s->ac_val[1] + c_size;
618
 
 
619
626
        /* cbp values */
620
627
        FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);
621
628
        s->coded_block= s->coded_block_base + s->b8_stride + 1;
717
724
    }
718
725
 
719
726
    av_freep(&s->dc_val_base);
720
 
    av_freep(&s->ac_val_base);
721
727
    av_freep(&s->coded_block_base);
722
728
    av_freep(&s->mbintra_table);
723
729
    av_freep(&s->cbp_table);
957
963
            return -1;
958
964
 
959
965
        s->current_picture_ptr= pic;
960
 
        s->current_picture_ptr->top_field_first= s->top_field_first; //FIXME use only the vars from current_pic
 
966
        //FIXME use only the vars from current_pic
 
967
        s->current_picture_ptr->top_field_first= s->top_field_first;
 
968
        if(s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) {
 
969
            if(s->picture_structure != PICT_FRAME)
 
970
                s->current_picture_ptr->top_field_first= (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
 
971
        }
961
972
        s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence;
962
973
    }
963
974
 
1014
1025
        }
1015
1026
    }
1016
1027
 
 
1028
#if FF_API_HURRY_UP
1017
1029
    s->hurry_up= s->avctx->hurry_up;
 
1030
#endif
1018
1031
    s->error_recognition= avctx->error_recognition;
1019
1032
 
1020
1033
    /* set dequantizer, we can't do it during init as it might change for mpeg4
1056
1069
       && s->current_picture.reference
1057
1070
       && !s->intra_only
1058
1071
       && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
1059
 
            s->dsp.draw_edges(s->current_picture.data[0], s->linesize  , s->h_edge_pos   , s->v_edge_pos   , EDGE_WIDTH  );
1060
 
            s->dsp.draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
1061
 
            s->dsp.draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
 
1072
            s->dsp.draw_edges(s->current_picture.data[0], s->linesize  ,
 
1073
                              s->h_edge_pos   , s->v_edge_pos   ,
 
1074
                              EDGE_WIDTH  , EDGE_TOP | EDGE_BOTTOM);
 
1075
            s->dsp.draw_edges(s->current_picture.data[1], s->uvlinesize,
 
1076
                              s->h_edge_pos>>1, s->v_edge_pos>>1,
 
1077
                              EDGE_WIDTH/2, EDGE_TOP | EDGE_BOTTOM);
 
1078
            s->dsp.draw_edges(s->current_picture.data[2], s->uvlinesize,
 
1079
                              s->h_edge_pos>>1, s->v_edge_pos>>1,
 
1080
                              EDGE_WIDTH/2, EDGE_TOP | EDGE_BOTTOM);
1062
1081
    }
1063
1082
    emms_c();
1064
1083
 
1249
1268
                        av_log(s->avctx, AV_LOG_DEBUG, "?");
1250
1269
 
1251
1270
 
1252
 
                    if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264)
 
1271
                    if(IS_INTERLACED(mb_type))
1253
1272
                        av_log(s->avctx, AV_LOG_DEBUG, "=");
1254
1273
                    else
1255
1274
                        av_log(s->avctx, AV_LOG_DEBUG, " ");
1468
1487
 
1469
1488
    if(   (unsigned)src_x > h_edge_pos                 - (!!sx) - w
1470
1489
       || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){
1471
 
        ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
 
1490
        s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
1472
1491
                            src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
1473
1492
        src= s->edge_emu_buffer;
1474
1493
        emu=1;
1541
1560
 
1542
1561
    if(   (unsigned)src_x > h_edge_pos                 - (!!sx) - 2*block_s
1543
1562
       || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){
1544
 
            ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
 
1563
            s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
1545
1564
                             src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
1546
1565
            ptr_y = s->edge_emu_buffer;
1547
1566
            if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
1548
1567
                uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
1549
 
                ff_emulated_edge_mc(uvbuf  , ptr_cb, s->uvlinesize, 9, 9+field_based,
 
1568
                s->dsp.emulated_edge_mc(uvbuf  , ptr_cb, s->uvlinesize, 9, 9+field_based,
1550
1569
                                 uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
1551
 
                ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
 
1570
                s->dsp.emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based,
1552
1571
                                 uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
1553
1572
                ptr_cb= uvbuf;
1554
1573
                ptr_cr= uvbuf+16;
1614
1633
    if(s->flags&CODEC_FLAG_EMU_EDGE){
1615
1634
        if(   (unsigned)src_x > h_edge_pos - (!!sx) - block_s
1616
1635
           || (unsigned)src_y > v_edge_pos - (!!sy) - block_s){
1617
 
            ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
 
1636
            s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
1618
1637
            ptr= s->edge_emu_buffer;
1619
1638
            emu=1;
1620
1639
        }
1625
1644
 
1626
1645
    ptr = ref_picture[2] + offset;
1627
1646
    if(emu){
1628
 
        ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
 
1647
        s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
1629
1648
        ptr= s->edge_emu_buffer;
1630
1649
    }
1631
1650
    pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy);
1639
1658
 * @param dest_cr chroma cr/v destination pointer
1640
1659
 * @param dir direction (0->forward, 1->backward)
1641
1660
 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
1642
 
 * @param pic_op halfpel motion compensation function (average or put normally)
 
1661
 * @param pix_op halfpel motion compensation function (average or put normally)
1643
1662
 * the motion vectors are taken from s->mv and the MV type from s->mv_type
1644
1663
 */
1645
1664
static inline void MPV_motion_lowres(MpegEncContext *s,
1945
1964
            }
1946
1965
 
1947
1966
            /* skip dequant / idct if we are really late ;) */
 
1967
#if FF_API_HURRY_UP
1948
1968
            if(s->hurry_up>1) goto skip_idct;
 
1969
#endif
1949
1970
            if(s->avctx->skip_idct){
1950
1971
                if(  (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == FF_B_TYPE)
1951
1972
                   ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != FF_I_TYPE)