Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge commit 'ceb754d041f5f6327fd9195a5f43575af9516daa'

* commit 'ceb754d041f5f6327fd9195a5f43575af9516daa':
  lzo: Use AV_COPY*U macros where appropriate
  prepare 9_beta2 release
  dsputil: Replace AV_WNxx(AV_RNxx()) combinations by AV_COPYxxU
  intreadwrite: Add AV_COPYxxU macros for copying to/from unaligned addresses
  dxtory: Replace AV_WN16A(AV_RN16A()) combination by AV_COPY16
  mp3: properly forward mp_decode_frame errors

Conflicts:
	RELEASE
	libavcodec/mpegaudiodec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
  • Loading branch information...
commit 5555d2075a26fc778fb8145473100e94d80a00c8 2 parents f3b8096 + ceb754d
Michael Niedermayer authored October 24, 2012
2  RELEASE
... ...
@@ -1 +1 @@
1  
-1.0.git
  1
+1.0.git
20  libavcodec/dsputil.h
@@ -674,7 +674,7 @@ static inline void copy_block2(uint8_t *dst, const uint8_t *src, int dstStride,
674 674
     int i;
675 675
     for(i=0; i<h; i++)
676 676
     {
677  
-        AV_WN16(dst   , AV_RN16(src   ));
  677
+        AV_COPY16U(dst, src);
678 678
         dst+=dstStride;
679 679
         src+=srcStride;
680 680
     }
@@ -685,7 +685,7 @@ static inline void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride,
685 685
     int i;
686 686
     for(i=0; i<h; i++)
687 687
     {
688  
-        AV_WN32(dst   , AV_RN32(src   ));
  688
+        AV_COPY32U(dst, src);
689 689
         dst+=dstStride;
690 690
         src+=srcStride;
691 691
     }
@@ -696,8 +696,7 @@ static inline void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride,
696 696
     int i;
697 697
     for(i=0; i<h; i++)
698 698
     {
699  
-        AV_WN32(dst   , AV_RN32(src   ));
700  
-        AV_WN32(dst+4 , AV_RN32(src+4 ));
  699
+        AV_COPY64U(dst, src);
701 700
         dst+=dstStride;
702 701
         src+=srcStride;
703 702
     }
@@ -708,8 +707,7 @@ static inline void copy_block9(uint8_t *dst, const uint8_t *src, int dstStride,
708 707
     int i;
709 708
     for(i=0; i<h; i++)
710 709
     {
711  
-        AV_WN32(dst   , AV_RN32(src   ));
712  
-        AV_WN32(dst+4 , AV_RN32(src+4 ));
  710
+        AV_COPY64U(dst, src);
713 711
         dst[8]= src[8];
714 712
         dst+=dstStride;
715 713
         src+=srcStride;
@@ -721,10 +719,7 @@ static inline void copy_block16(uint8_t *dst, const uint8_t *src, int dstStride,
721 719
     int i;
722 720
     for(i=0; i<h; i++)
723 721
     {
724  
-        AV_WN32(dst   , AV_RN32(src   ));
725  
-        AV_WN32(dst+4 , AV_RN32(src+4 ));
726  
-        AV_WN32(dst+8 , AV_RN32(src+8 ));
727  
-        AV_WN32(dst+12, AV_RN32(src+12));
  722
+        AV_COPY128U(dst, src);
728 723
         dst+=dstStride;
729 724
         src+=srcStride;
730 725
     }
@@ -735,10 +730,7 @@ static inline void copy_block17(uint8_t *dst, const uint8_t *src, int dstStride,
735 730
     int i;
736 731
     for(i=0; i<h; i++)
737 732
     {
738  
-        AV_WN32(dst   , AV_RN32(src   ));
739  
-        AV_WN32(dst+4 , AV_RN32(src+4 ));
740  
-        AV_WN32(dst+8 , AV_RN32(src+8 ));
741  
-        AV_WN32(dst+12, AV_RN32(src+12));
  733
+        AV_COPY128U(dst, src);
742 734
         dst[16]= src[16];
743 735
         dst+=dstStride;
744 736
         src+=srcStride;
4  libavcodec/dxtory.c
@@ -70,8 +70,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
70 70
     V  = pic->data[2];
71 71
     for (h = 0; h < avctx->height; h += 2) {
72 72
         for (w = 0; w < avctx->width; w += 2) {
73  
-            AV_WN16A(Y1 + w, AV_RN16A(src));
74  
-            AV_WN16A(Y2 + w, AV_RN16A(src + 2));
  73
+            AV_COPY16(Y1 + w, src);
  74
+            AV_COPY16(Y2 + w, src + 2);
75 75
             U[w >> 1] = src[4] + 0x80;
76 76
             V[w >> 1] = src[5] + 0x80;
77 77
             src += 6;
32  libavcodec/mpegaudiodec.c
@@ -1654,7 +1654,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
1654 1654
     int buf_size        = avpkt->size;
1655 1655
     MPADecodeContext *s = avctx->priv_data;
1656 1656
     uint32_t header;
1657  
-    int out_size;
  1657
+    int ret;
1658 1658
 
1659 1659
     while(buf_size && !*buf){
1660 1660
         buf++;
@@ -1693,21 +1693,22 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
1693 1693
         buf_size= s->frame_size;
1694 1694
     }
1695 1695
 
1696  
-    out_size = mp_decode_frame(s, NULL, buf, buf_size);
1697  
-    if (out_size >= 0) {
  1696
+    ret = mp_decode_frame(s, NULL, buf, buf_size);
  1697
+    if (ret >= 0) {
1698 1698
         *got_frame_ptr   = 1;
1699 1699
         *(AVFrame *)data = s->frame;
1700 1700
         avctx->sample_rate = s->sample_rate;
1701 1701
         //FIXME maybe move the other codec info stuff from above here too
1702 1702
     } else {
1703 1703
         av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");
1704  
-        /* Only return an error if the bad frame makes up the whole packet.
1705  
-           If there is more data in the packet, just consume the bad frame
1706  
-           instead of returning an error, which would discard the whole
1707  
-           packet. */
  1704
+        /* Only return an error if the bad frame makes up the whole packet or
  1705
+         * the error is related to buffer management.
  1706
+         * If there is more data in the packet, just consume the bad frame
  1707
+         * instead of returning an error, which would discard the whole
  1708
+         * packet. */
1708 1709
         *got_frame_ptr = 0;
1709  
-        if (buf_size == avpkt->size)
1710  
-            return out_size;
  1710
+        if (buf_size == avpkt->size || ret != AVERROR_INVALIDDATA)
  1711
+            return ret;
1711 1712
     }
1712 1713
     s->frame_size = 0;
1713 1714
     return buf_size;
@@ -1732,7 +1733,7 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
1732 1733
     int buf_size        = avpkt->size;
1733 1734
     MPADecodeContext *s = avctx->priv_data;
1734 1735
     uint32_t header;
1735  
-    int len;
  1736
+    int len, ret;
1736 1737
     int av_unused out_size;
1737 1738
 
1738 1739
     len = buf_size;
@@ -1764,10 +1765,10 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
1764 1765
 
1765 1766
     s->frame_size = len;
1766 1767
 
1767  
-    out_size = mp_decode_frame(s, NULL, buf, buf_size);
1768  
-    if (out_size < 0) {
  1768
+    ret = mp_decode_frame(s, NULL, buf, buf_size);
  1769
+    if (ret < 0) {
1769 1770
         av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");
1770  
-        return AVERROR_INVALIDDATA;
  1771
+        return ret;
1771 1772
     }
1772 1773
 
1773 1774
     *got_frame_ptr   = 1;
@@ -1972,7 +1973,10 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
1972 1973
         }
1973 1974
         ch += m->nb_channels;
1974 1975
 
1975  
-        out_size += mp_decode_frame(m, outptr, buf, fsize);
  1976
+        if ((ret = mp_decode_frame(m, outptr, buf, fsize)) < 0)
  1977
+            return ret;
  1978
+
  1979
+        out_size += ret;
1976 1980
         buf      += fsize;
1977 1981
         len      -= fsize;
1978 1982
 
27  libavutil/intreadwrite.h
@@ -468,6 +468,33 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
468 468
 #   define AV_WN64A(p, v) AV_WNA(64, p, v)
469 469
 #endif
470 470
 
  471
+/*
  472
+ * The AV_COPYxxU macros are suitable for copying data to/from unaligned
  473
+ * memory locations.
  474
+ */
  475
+
  476
+#define AV_COPYU(n, d, s) AV_WN##n(d, AV_RN##n(s));
  477
+
  478
+#ifndef AV_COPY16U
  479
+#   define AV_COPY16U(d, s) AV_COPYU(16, d, s)
  480
+#endif
  481
+
  482
+#ifndef AV_COPY32U
  483
+#   define AV_COPY32U(d, s) AV_COPYU(32, d, s)
  484
+#endif
  485
+
  486
+#ifndef AV_COPY64U
  487
+#   define AV_COPY64U(d, s) AV_COPYU(64, d, s)
  488
+#endif
  489
+
  490
+#ifndef AV_COPY128U
  491
+#   define AV_COPY128U(d, s)                                    \
  492
+    do {                                                        \
  493
+        AV_COPY64U(d, s);                                       \
  494
+        AV_COPY64U((char *)(d) + 8, (const char *)(s) + 8);     \
  495
+    } while(0)
  496
+#endif
  497
+
471 498
 /* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
472 499
  * naturally aligned. They may be implemented using MMX,
473 500
  * so emms_c() must be called before using any float code
28  libavutil/lzo.c
@@ -23,6 +23,7 @@
23 23
 
24 24
 #include "avutil.h"
25 25
 #include "common.h"
  26
+#include "intreadwrite.h"
26 27
 #include "lzo.h"
27 28
 
28 29
 /// Define if we may write up to 12 bytes beyond the output buffer.
@@ -71,19 +72,6 @@ static inline int get_len(LZOContext *c, int x, int mask)
71 72
     return cnt;
72 73
 }
73 74
 
74  
-//#define UNALIGNED_LOADSTORE
75  
-#define BUILTIN_MEMCPY
76  
-#ifdef UNALIGNED_LOADSTORE
77  
-#define COPY2(d, s) *(uint16_t *)(d) = *(uint16_t *)(s);
78  
-#define COPY4(d, s) *(uint32_t *)(d) = *(uint32_t *)(s);
79  
-#elif defined(BUILTIN_MEMCPY)
80  
-#define COPY2(d, s) memcpy(d, s, 2);
81  
-#define COPY4(d, s) memcpy(d, s, 4);
82  
-#else
83  
-#define COPY2(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1];
84  
-#define COPY4(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; (d)[3] = (s)[3];
85  
-#endif
86  
-
87 75
 /**
88 76
  * @brief Copies bytes from input to output buffer with checking.
89 77
  * @param cnt number of bytes to copy, must be >= 0
@@ -101,7 +89,7 @@ static inline void copy(LZOContext *c, int cnt)
101 89
         c->error |= AV_LZO_OUTPUT_FULL;
102 90
     }
103 91
 #if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
104  
-    COPY4(dst, src);
  92
+    AV_COPY32U(dst, src);
105 93
     src += 4;
106 94
     dst += 4;
107 95
     cnt -= 4;
@@ -145,16 +133,16 @@ static inline void memcpy_backptr(uint8_t *dst, int back, int cnt)
145 133
         memset(dst, *src, cnt);
146 134
     } else {
147 135
 #ifdef OUTBUF_PADDED
148  
-        COPY2(dst, src);
149  
-        COPY2(dst + 2, src + 2);
  136
+        AV_COPY16U(dst,     src);
  137
+        AV_COPY16U(dst + 2, src + 2);
150 138
         src += 4;
151 139
         dst += 4;
152 140
         cnt -= 4;
153 141
         if (cnt > 0) {
154  
-            COPY2(dst, src);
155  
-            COPY2(dst + 2, src + 2);
156  
-            COPY2(dst + 4, src + 4);
157  
-            COPY2(dst + 6, src + 6);
  142
+            AV_COPY16U(dst,     src);
  143
+            AV_COPY16U(dst + 2, src + 2);
  144
+            AV_COPY16U(dst + 4, src + 4);
  145
+            AV_COPY16U(dst + 6, src + 6);
158 146
             src += 8;
159 147
             dst += 8;
160 148
             cnt -= 8;

0 notes on commit 5555d20

Please sign in to comment.
Something went wrong with that request. Please try again.