Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -27,6 +27,7 @@ · 26 unmodified lines | ||
| 27 | 27 | |
| 28 | 28 | #include "libavutil/avassert.h" |
| 29 | 29 | #include "libavutil/bswap.h" |
| 30 | +#include "libavcodec/bswapdsp.h" | |
| 30 | 31 | #include "libavutil/crc.h" |
| 31 | 32 | #include "libavutil/imgutils.h" |
| 32 | 33 | #include "libavutil/md5.h" |
| @@ -795,15 +796,41 @@ static const int8_t R64T[64][64] = { · 762 unmodified lines | ||
| 795 | 796 | } |
| 796 | 797 | }; |
| 797 | 798 | |
| 798 | −static int verify_plane_md5(struct AVMD5 *ctx, | |
| 799 | − const uint8_t *src, const int w, const int h, const int stride, | |
| 800 | − const uint8_t *expected) | |
| 799 | +struct H274HashContext { | |
| 800 | + int type; | |
| 801 | + struct AVMD5 *ctx; | |
| 802 | + | |
| 803 | +#if HAVE_BIGENDIAN | |
| 804 | + BswapDSPContext bdsp; | |
| 805 | + uint8_t *buf; | |
| 806 | + int buf_size; | |
| 807 | +#endif | |
| 808 | +}; | |
| 809 | + | |
| 810 | +static av_always_inline void bswap16_buf_if_be(H274HashContext *s, const int ps, const uint8_t **src, const int w) | |
| 811 | +{ | |
| 812 | +#if HAVE_BIGENDIAN | |
| 813 | + if (ps) { | |
| 814 | + s->bdsp.bswap16_buf((uint16_t *)s->buf, | |
| 815 | + (const uint16_t *)*src, w); | |
| 816 | + *src = s->buf; | |
| 817 | + } | |
| 818 | +#endif | |
| 819 | +} | |
| 820 | + | |
| 821 | +static int verify_plane_md5(H274HashContext *s, | |
| 822 | + const uint8_t *_src, const int w, const int h, const int stride, | |
| 823 | + const int ps, const uint8_t *expected) | |
| 801 | 824 | { |
| 802 | 825 | #define MD5_SIZE 16 |
| 826 | + struct AVMD5 *ctx = s->ctx; | |
| 803 | 827 | uint8_t md5[MD5_SIZE]; |
| 828 | + | |
| 804 | 829 | av_md5_init(ctx); |
| 805 | 830 | for (int j = 0; j < h; j++) { |
| 806 | − av_md5_update(ctx, src, w); | |
| 831 | + const uint8_t *src = &_src[j * stride]; | |
| 832 | + bswap16_buf_if_be(s, ps, &src, w); | |
| 833 | + av_md5_update(ctx, src, w << ps); | |
| 807 | 834 | src += stride; |
| 808 | 835 | } |
| 809 | 836 | av_md5_final(ctx, md5); |
| @@ -814,15 +841,16 @@ static int verify_plane_md5(struct AVMD5 *ctx, · 4 unmodified lines | ||
| 814 | 841 | return 0; |
| 815 | 842 | } |
| 816 | 843 | |
| 817 | −static int verify_plane_crc(const uint8_t *src, const int w, const int h, const int stride, | |
| 818 | − uint16_t expected) | |
| 844 | +static int verify_plane_crc(H274HashContext *s, const uint8_t *_src, const int w, const int h, const int stride, | |
| 845 | + const int ps, uint16_t expected) | |
| 819 | 846 | { |
| 820 | 847 | uint32_t crc = 0x0F1D; // CRC-16-CCITT-AUG |
| 821 | 848 | const AVCRC *ctx = av_crc_get_table(AV_CRC_16_CCITT); |
| 822 | 849 | |
| 823 | − expected = av_le2ne32(expected); | |
| 824 | 850 | for (int j = 0; j < h; j++) { |
| 825 | − crc = av_crc(ctx, crc, src, w); | |
| 851 | + const uint8_t *src = &_src[j * stride]; | |
| 852 | + bswap16_buf_if_be(s, ps, &src, w); | |
| 853 | + crc = av_crc(ctx, crc, src, w << ps); | |
| 826 | 854 | src += stride; |
| 827 | 855 | } |
| 828 | 856 | crc = av_bswap16(crc); |
| @@ -863,11 +891,6 @@ enum { · 34 unmodified lines | ||
| 863 | 891 | HASH_LAST = HASH_CHECKSUM, |
| 864 | 892 | }; |
| 865 | 893 | |
| 866 | −struct H274HashContext { | |
| 867 | − int type; | |
| 868 | − struct AVMD5 *ctx; | |
| 869 | −}; | |
| 870 | − | |
| 871 | 894 | void ff_h274_hash_freep(H274HashContext **ctx) |
| 872 | 895 | { |
| 873 | 896 | if (*ctx) { |
| @@ -875,6 +898,9 @@ void ff_h274_hash_freep(H274HashContext **ctx) · 1 unmodified line | ||
| 875 | 898 | if (c->ctx) |
| 876 | 899 | av_free(c->ctx); |
| 877 | 900 | av_freep(ctx); |
| 901 | +#if HAVE_BIGENDIAN | |
| 902 | + av_freep(&c->buf); | |
| 903 | +#endif | |
| 878 | 904 | } |
| 879 | 905 | } |
| 880 | 906 | |
| @@ -906,6 +932,10 @@ int ff_h274_hash_init(H274HashContext **ctx, const int type) · 25 unmodified lines | ||
| 906 | 932 | return AVERROR(ENOMEM); |
| 907 | 933 | } |
| 908 | 934 | |
| 935 | +#if HAVE_BIGENDIAN | |
| 936 | + ff_bswapdsp_init(&c->bdsp); | |
| 937 | +#endif | |
| 938 | + | |
| 909 | 939 | return 0; |
| 910 | 940 | } |
| 911 | 941 | |
| @@ -932,10 +962,22 @@ int ff_h274_hash_verify(H274HashContext *c, const H274SEIPictureHash *hash, · 20 unmodified lines | ||
| 932 | 962 | const uint8_t *src = frame->data[i]; |
| 933 | 963 | const int stride = frame->linesize[i]; |
| 934 | 964 | |
| 965 | +#if HAVE_BIGENDIAN | |
| 966 | + if (c->type != HASH_CHECKSUM) { | |
| 967 | + if (ps) { | |
| 968 | + av_fast_malloc(&c->buf, &c->buf_size, | |
| 969 | + FFMAX3(frame->linesize[0], frame->linesize[1], | |
| 970 | + frame->linesize[2])); | |
| 971 | + if (!c->buf) | |
| 972 | + return AVERROR(ENOMEM); | |
| 973 | + } | |
| 974 | + } | |
| 975 | +#endif | |
| 976 | + | |
| 935 | 977 | if (c->type == HASH_MD5SUM) |
| 936 | − err = verify_plane_md5(c->ctx, src, w << ps, h, stride, hash->md5[i]); | |
| 978 | + err = verify_plane_md5(c, src, w, h, stride, ps, hash->md5[i]); | |
| 937 | 979 | else if (c->type == HASH_CRC) |
| 938 | − err = verify_plane_crc(src, w << ps, h, stride, hash->crc[i]); | |
| 980 | + err = verify_plane_crc(c, src, w, h, stride, ps, hash->crc[i]); | |
| 939 | 981 | else if (c->type == HASH_CHECKSUM) |
| 940 | 982 | err = verify_plane_checksum(src, w, h, stride, ps, hash->checksum[i]); |
| 941 | 983 | if (err < 0) |