~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/vp8.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:
24
24
 
25
25
#include "libavutil/imgutils.h"
26
26
#include "avcodec.h"
 
27
#include "internal.h"
27
28
#include "vp8.h"
28
29
#include "vp8data.h"
29
30
#include "rectangle.h"
33
34
#   include "arm/vp8.h"
34
35
#endif
35
36
 
36
 
static void vp8_decode_flush(AVCodecContext *avctx)
 
37
static void free_buffers(VP8Context *s)
37
38
{
38
 
    VP8Context *s = avctx->priv_data;
39
 
    int i;
40
 
 
41
 
    if (!avctx->is_copy) {
42
 
        for (i = 0; i < 5; i++)
43
 
            if (s->frames[i].data[0])
44
 
                ff_thread_release_buffer(avctx, &s->frames[i]);
45
 
    }
46
 
    memset(s->framep, 0, sizeof(s->framep));
47
 
 
48
39
    av_freep(&s->macroblocks_base);
49
40
    av_freep(&s->filter_strength);
50
41
    av_freep(&s->intra4x4_pred_mode_top);
51
42
    av_freep(&s->top_nnz);
52
43
    av_freep(&s->edge_emu_buffer);
53
44
    av_freep(&s->top_border);
54
 
    av_freep(&s->segmentation_map);
55
 
 
56
 
    s->macroblocks        = NULL;
 
45
 
 
46
    s->macroblocks = NULL;
 
47
}
 
48
 
 
49
static int vp8_alloc_frame(VP8Context *s, AVFrame *f)
 
50
{
 
51
    int ret;
 
52
    if ((ret = ff_thread_get_buffer(s->avctx, f)) < 0)
 
53
        return ret;
 
54
    if (s->num_maps_to_be_freed && !s->maps_are_invalid) {
 
55
        f->ref_index[0] = s->segmentation_maps[--s->num_maps_to_be_freed];
 
56
    } else if (!(f->ref_index[0] = av_mallocz(s->mb_width * s->mb_height))) {
 
57
        ff_thread_release_buffer(s->avctx, f);
 
58
        return AVERROR(ENOMEM);
 
59
    }
 
60
    return 0;
 
61
}
 
62
 
 
63
static void vp8_release_frame(VP8Context *s, AVFrame *f, int prefer_delayed_free, int can_direct_free)
 
64
{
 
65
    if (f->ref_index[0]) {
 
66
        if (prefer_delayed_free) {
 
67
            /* Upon a size change, we want to free the maps but other threads may still
 
68
             * be using them, so queue them. Upon a seek, all threads are inactive so
 
69
             * we want to cache one to prevent re-allocation in the next decoding
 
70
             * iteration, but the rest we can free directly. */
 
71
            int max_queued_maps = can_direct_free ? 1 : FF_ARRAY_ELEMS(s->segmentation_maps);
 
72
            if (s->num_maps_to_be_freed < max_queued_maps) {
 
73
                s->segmentation_maps[s->num_maps_to_be_freed++] = f->ref_index[0];
 
74
            } else if (can_direct_free) /* vp8_decode_flush(), but our queue is full */ {
 
75
                av_free(f->ref_index[0]);
 
76
            } /* else: MEMLEAK (should never happen, but better that than crash) */
 
77
            f->ref_index[0] = NULL;
 
78
        } else /* vp8_decode_free() */ {
 
79
            av_free(f->ref_index[0]);
 
80
        }
 
81
    }
 
82
    ff_thread_release_buffer(s->avctx, f);
 
83
}
 
84
 
 
85
static void vp8_decode_flush_impl(AVCodecContext *avctx,
 
86
                                  int prefer_delayed_free, int can_direct_free, int free_mem)
 
87
{
 
88
    VP8Context *s = avctx->priv_data;
 
89
    int i;
 
90
 
 
91
    if (!avctx->internal->is_copy) {
 
92
        for (i = 0; i < 5; i++)
 
93
            if (s->frames[i].data[0])
 
94
                vp8_release_frame(s, &s->frames[i], prefer_delayed_free, can_direct_free);
 
95
    }
 
96
    memset(s->framep, 0, sizeof(s->framep));
 
97
 
 
98
    if (free_mem) {
 
99
        free_buffers(s);
 
100
        s->maps_are_invalid = 1;
 
101
    }
 
102
}
 
103
 
 
104
static void vp8_decode_flush(AVCodecContext *avctx)
 
105
{
 
106
    vp8_decode_flush_impl(avctx, 1, 1, 0);
57
107
}
58
108
 
59
109
static int update_dimensions(VP8Context *s, int width, int height)
63
113
        if (av_image_check_size(width, height, 0, s->avctx))
64
114
            return AVERROR_INVALIDDATA;
65
115
 
66
 
        vp8_decode_flush(s->avctx);
 
116
        vp8_decode_flush_impl(s->avctx, 1, 0, 1);
67
117
 
68
118
        avcodec_set_dimensions(s->avctx, width, height);
69
119
    }
76
126
    s->intra4x4_pred_mode_top  = av_mallocz(s->mb_width*4);
77
127
    s->top_nnz                 = av_mallocz(s->mb_width*sizeof(*s->top_nnz));
78
128
    s->top_border              = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));
79
 
    s->segmentation_map        = av_mallocz(s->mb_width*s->mb_height);
80
129
 
81
130
    if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_top ||
82
 
        !s->top_nnz || !s->top_border || !s->segmentation_map)
 
131
        !s->top_nnz || !s->top_border)
83
132
        return AVERROR(ENOMEM);
84
133
 
85
134
    s->macroblocks        = s->macroblocks_base + 1;
273
322
 
274
323
    if (!s->macroblocks_base || /* first frame */
275
324
        width != s->avctx->width || height != s->avctx->height) {
276
 
        if ((ret = update_dimensions(s, width, height) < 0))
 
325
        if ((ret = update_dimensions(s, width, height)) < 0)
277
326
            return ret;
278
327
    }
279
328
 
487
536
 
488
537
    AV_ZERO32(&near_mv[0]);
489
538
    AV_ZERO32(&near_mv[1]);
 
539
    AV_ZERO32(&near_mv[2]);
490
540
 
491
541
    /* Process MB on top, left and top-left */
492
542
    #define MV_EDGE_CHECK(n)\
641
691
 * @param block destination for block coefficients
642
692
 * @param probs probabilities to use when reading trees from the bitstream
643
693
 * @param i initial coeff index, 0 unless a separate DC block is coded
644
 
 * @param zero_nhood the initial prediction context for number of surrounding
645
 
 *                   all-zero blocks (only left/top, so 0-2)
646
694
 * @param qmul array holding the dc/ac dequant factor at position 0/1
647
695
 * @return 0 if no coeffs were decoded
648
696
 *         otherwise, the index of the last coeff decoded plus one
701
749
}
702
750
#endif
703
751
 
 
752
/**
 
753
 * @param c arithmetic bitstream reader context
 
754
 * @param block destination for block coefficients
 
755
 * @param probs probabilities to use when reading trees from the bitstream
 
756
 * @param i initial coeff index, 0 unless a separate DC block is coded
 
757
 * @param zero_nhood the initial prediction context for number of surrounding
 
758
 *                   all-zero blocks (only left/top, so 0-2)
 
759
 * @param qmul array holding the dc/ac dequant factor at position 0/1
 
760
 * @return 0 if no coeffs were decoded
 
761
 *         otherwise, the index of the last coeff decoded plus one
 
762
 */
704
763
static av_always_inline
705
764
int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16],
706
765
                        uint8_t probs[16][3][NUM_DCT_TOKENS-1],
910
969
                   int mb_x, int mb_y)
911
970
{
912
971
    AVCodecContext *avctx = s->avctx;
913
 
    int x, y, mode, nnz, tr;
 
972
    int x, y, mode, nnz;
 
973
    uint32_t tr;
914
974
 
915
975
    // for the first row, we need to run xchg_mb_border to init the top edge to 127
916
976
    // otherwise, skip it if we aren't going to deblock
939
999
        // from the top macroblock
940
1000
        if (!(!mb_y && avctx->flags & CODEC_FLAG_EMU_EDGE) &&
941
1001
            mb_x == s->mb_width-1) {
942
 
            tr = tr_right[-1]*0x01010101;
 
1002
            tr = tr_right[-1]*0x01010101u;
943
1003
            tr_right = (uint8_t *)&tr;
944
1004
        }
945
1005
 
1034
1094
};
1035
1095
 
1036
1096
/**
1037
 
 * Generic MC function.
 
1097
 * luma MC function
1038
1098
 *
1039
1099
 * @param s VP8 decoding context
1040
 
 * @param luma 1 for luma (Y) planes, 0 for chroma (Cb/Cr) planes
1041
1100
 * @param dst target buffer for block data at block position
1042
 
 * @param src reference picture buffer at origin (0, 0)
 
1101
 * @param ref reference picture buffer at origin (0, 0)
1043
1102
 * @param mv motion vector (relative to block position) to get pixel data from
1044
1103
 * @param x_off horizontal position of block from origin (0, 0)
1045
1104
 * @param y_off vertical position of block from origin (0, 0)
1083
1142
    }
1084
1143
}
1085
1144
 
 
1145
/**
 
1146
 * chroma MC function
 
1147
 *
 
1148
 * @param s VP8 decoding context
 
1149
 * @param dst1 target buffer for block data at block position (U plane)
 
1150
 * @param dst2 target buffer for block data at block position (V plane)
 
1151
 * @param ref reference picture buffer at origin (0, 0)
 
1152
 * @param mv motion vector (relative to block position) to get pixel data from
 
1153
 * @param x_off horizontal position of block from origin (0, 0)
 
1154
 * @param y_off vertical position of block from origin (0, 0)
 
1155
 * @param block_w width of block (16, 8 or 4)
 
1156
 * @param block_h height of block (always same as block_w)
 
1157
 * @param width width of src/dst plane data
 
1158
 * @param height height of src/dst plane data
 
1159
 * @param linesize size of a single line of plane data, including padding
 
1160
 * @param mc_func motion compensation function pointers (bilinear or sixtap MC)
 
1161
 */
1086
1162
static av_always_inline
1087
1163
void vp8_mc_chroma(VP8Context *s, uint8_t *dst1, uint8_t *dst2, AVFrame *ref,
1088
1164
                   const VP56mv *mv, int x_off, int y_off,
1476
1552
    }
1477
1553
}
1478
1554
 
 
1555
static void release_queued_segmaps(VP8Context *s, int is_close)
 
1556
{
 
1557
    int leave_behind = is_close ? 0 : !s->maps_are_invalid;
 
1558
    while (s->num_maps_to_be_freed > leave_behind)
 
1559
        av_freep(&s->segmentation_maps[--s->num_maps_to_be_freed]);
 
1560
    s->maps_are_invalid = 0;
 
1561
}
 
1562
 
1479
1563
static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
1480
1564
                            AVPacket *avpkt)
1481
1565
{
1482
1566
    VP8Context *s = avctx->priv_data;
1483
1567
    int ret, mb_x, mb_y, i, y, referenced;
1484
1568
    enum AVDiscard skip_thresh;
1485
 
    AVFrame *av_uninit(curframe), *prev_frame = s->framep[VP56_FRAME_CURRENT];
 
1569
    AVFrame *av_uninit(curframe), *prev_frame;
 
1570
 
 
1571
    release_queued_segmaps(s, 0);
1486
1572
 
1487
1573
    if ((ret = decode_frame_header(s, avpkt->data, avpkt->size)) < 0)
1488
1574
        return ret;
1489
1575
 
 
1576
    prev_frame = s->framep[VP56_FRAME_CURRENT];
 
1577
 
1490
1578
    referenced = s->update_last || s->update_golden == VP56_FRAME_CURRENT
1491
1579
                                || s->update_altref == VP56_FRAME_CURRENT;
1492
1580
 
1506
1594
            &s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] &&
1507
1595
            &s->frames[i] != s->framep[VP56_FRAME_GOLDEN] &&
1508
1596
            &s->frames[i] != s->framep[VP56_FRAME_GOLDEN2])
1509
 
            ff_thread_release_buffer(avctx, &s->frames[i]);
 
1597
            vp8_release_frame(s, &s->frames[i], 1, 0);
1510
1598
 
1511
1599
    // find a free buffer
1512
1600
    for (i = 0; i < 5; i++)
1522
1610
        abort();
1523
1611
    }
1524
1612
    if (curframe->data[0])
1525
 
        ff_thread_release_buffer(avctx, curframe);
 
1613
        vp8_release_frame(s, curframe, 1, 0);
1526
1614
 
1527
1615
    curframe->key_frame = s->keyframe;
1528
1616
    curframe->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
1529
1617
    curframe->reference = referenced ? 3 : 0;
1530
 
    curframe->ref_index[0] = s->segmentation_map;
1531
 
    if ((ret = ff_thread_get_buffer(avctx, curframe))) {
 
1618
    if ((ret = vp8_alloc_frame(s, curframe))) {
1532
1619
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed!\n");
1533
1620
        return ret;
1534
1621
    }
1620
1707
            s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4);
1621
1708
            s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1], 2);
1622
1709
 
1623
 
            decode_mb_mode(s, mb, mb_x, mb_y, s->segmentation_map + mb_xy,
1624
 
                           prev_frame ? prev_frame->ref_index[0] + mb_xy : NULL);
 
1710
            decode_mb_mode(s, mb, mb_x, mb_y, curframe->ref_index[0] + mb_xy,
 
1711
                           prev_frame && prev_frame->ref_index[0] ? prev_frame->ref_index[0] + mb_xy : NULL);
1625
1712
 
1626
1713
            prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS);
1627
1714
 
1696
1783
    avctx->pix_fmt = PIX_FMT_YUV420P;
1697
1784
 
1698
1785
    dsputil_init(&s->dsp, avctx);
1699
 
    ff_h264_pred_init(&s->hpc, CODEC_ID_VP8, 8);
 
1786
    ff_h264_pred_init(&s->hpc, CODEC_ID_VP8, 8, 1);
1700
1787
    ff_vp8dsp_init(&s->vp8dsp);
1701
1788
 
1702
1789
    return 0;
1704
1791
 
1705
1792
static av_cold int vp8_decode_free(AVCodecContext *avctx)
1706
1793
{
1707
 
    vp8_decode_flush(avctx);
 
1794
    vp8_decode_flush_impl(avctx, 0, 1, 1);
 
1795
    release_queued_segmaps(avctx->priv_data, 1);
1708
1796
    return 0;
1709
1797
}
1710
1798
 
1724
1812
{
1725
1813
    VP8Context *s = dst->priv_data, *s_src = src->priv_data;
1726
1814
 
 
1815
    if (s->macroblocks_base &&
 
1816
        (s_src->mb_width != s->mb_width || s_src->mb_height != s->mb_height)) {
 
1817
        free_buffers(s);
 
1818
        s->maps_are_invalid = 1;
 
1819
    }
 
1820
 
1727
1821
    s->prob[0] = s_src->prob[!s_src->update_probabilities];
1728
1822
    s->segmentation = s_src->segmentation;
1729
1823
    s->lf_delta = s_src->lf_delta;
1739
1833
}
1740
1834
 
1741
1835
AVCodec ff_vp8_decoder = {
1742
 
    "vp8",
1743
 
    AVMEDIA_TYPE_VIDEO,
1744
 
    CODEC_ID_VP8,
1745
 
    sizeof(VP8Context),
1746
 
    vp8_decode_init,
1747
 
    NULL,
1748
 
    vp8_decode_free,
1749
 
    vp8_decode_frame,
1750
 
    CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
 
1836
    .name           = "vp8",
 
1837
    .type           = AVMEDIA_TYPE_VIDEO,
 
1838
    .id             = CODEC_ID_VP8,
 
1839
    .priv_data_size = sizeof(VP8Context),
 
1840
    .init           = vp8_decode_init,
 
1841
    .close          = vp8_decode_free,
 
1842
    .decode         = vp8_decode_frame,
 
1843
    .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
1751
1844
    .flush = vp8_decode_flush,
1752
1845
    .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"),
1753
1846
    .init_thread_copy      = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy),