[FFmpeg-devel] [PATCH 1/3] avcodec: add avpriv_dca_compute_crc()

foo86 foobaz86 at gmail.com
Mon May 2 22:47:58 CEST 2016


---
 libavcodec/dca.c     | 18 ++++++++++++++++++
 libavcodec/dca.h     |  5 +++++
 libavcodec/dcadec.c  | 20 +-------------------
 libavcodec/version.h |  2 +-
 4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index 714509b..be89d0d 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -71,3 +71,21 @@ int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
         return AVERROR_INVALIDDATA;
     }
 }
+
+int avpriv_dca_compute_crc(const uint8_t *data, int size)
+{
+    static const uint16_t crctab[16] = {
+        0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+        0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+    };
+
+    uint16_t res = 0xffff;
+    int i;
+
+    for (i = 0; i < size; i++) {
+        res = (res << 4) ^ crctab[(data[i] >> 4) ^ (res >> 12)];
+        res = (res << 4) ^ crctab[(data[i] & 15) ^ (res >> 12)];
+    }
+
+    return res;
+}
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index a1ac763..ebf9f32 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -160,4 +160,9 @@ extern av_export const uint32_t avpriv_dca_sample_rates[16];
 int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
                                  int max_size);
 
+/**
+ * Compute DCA-style CRC16 of input data
+ */
+int avpriv_dca_compute_crc(const uint8_t *data, int size);
+
 #endif /* AVCODEC_DCA_H */
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 0f50412..0a58782 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -76,29 +76,11 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask
     return nchannels;
 }
 
-static uint16_t crc16(const uint8_t *data, int size)
-{
-    static const uint16_t crctab[16] = {
-        0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
-        0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
-    };
-
-    uint16_t res = 0xffff;
-    int i;
-
-    for (i = 0; i < size; i++) {
-        res = (res << 4) ^ crctab[(data[i] >> 4) ^ (res >> 12)];
-        res = (res << 4) ^ crctab[(data[i] & 15) ^ (res >> 12)];
-    }
-
-    return res;
-}
-
 int ff_dca_check_crc(GetBitContext *s, int p1, int p2)
 {
     if (((p1 | p2) & 7) || p1 < 0 || p2 > s->size_in_bits || p2 - p1 < 16)
         return -1;
-    if (crc16(s->buffer + p1 / 8, (p2 - p1) / 8))
+    if (avpriv_dca_compute_crc(s->buffer + p1 / 8, (p2 - p1) / 8))
         return -1;
     return 0;
 }
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 084ae55..5840cf6 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  57
-#define LIBAVCODEC_VERSION_MINOR  38
+#define LIBAVCODEC_VERSION_MINOR  39
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.8.1



More information about the ffmpeg-devel mailing list