Fix wmv1 encoding if all other msmpeg4-related encoders were disabled.
[ffmpeg.git] / libavcodec / tak.c
index e7fbf6b..ed41ca8 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "tak.h"
 #include "libavutil/crc.h"
 #include "libavutil/intreadwrite.h"
-#include "libavutil/bswap.h"
+#include "tak.h"
 
 static const int64_t tak_channel_layouts[] = {
     0,
@@ -56,12 +55,13 @@ static int tak_get_nb_samples(int sample_rate, enum TAKFrameSizeType type)
 
     if (type <= TAK_FST_250ms) {
         nb_samples     = sample_rate * frame_duration_type_quants[type] >>
-                                       TAK_FRAME_DURATION_QUANT_SHIFT;
+                         TAK_FRAME_DURATION_QUANT_SHIFT;
         max_nb_samples = 16384;
     } else if (type < FF_ARRAY_ELEMS(frame_duration_type_quants)) {
         nb_samples     = frame_duration_type_quants[type];
-        max_nb_samples = sample_rate * frame_duration_type_quants[TAK_FST_250ms] >>
-                                       TAK_FRAME_DURATION_QUANT_SHIFT;
+        max_nb_samples = sample_rate *
+                         frame_duration_type_quants[TAK_FST_250ms] >>
+                         TAK_FRAME_DURATION_QUANT_SHIFT;
     } else {
         return AVERROR_INVALIDDATA;
     }
@@ -72,22 +72,6 @@ static int tak_get_nb_samples(int sample_rate, enum TAKFrameSizeType type)
     return nb_samples;
 }
 
-static int crc_init = 0;
-#if CONFIG_SMALL
-#define CRC_TABLE_SIZE 257
-#else
-#define CRC_TABLE_SIZE 1024
-#endif
-static AVCRC crc_24[CRC_TABLE_SIZE];
-
-av_cold void ff_tak_init_crc(void)
-{
-    if (!crc_init) {
-        av_crc_init(crc_24, 0, 24, 0x864CFBU, sizeof(crc_24));
-        crc_init = 1;
-    }
-}
-
 int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
 {
     uint32_t crc, CRC;
@@ -96,8 +80,8 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size)
         return AVERROR_INVALIDDATA;
     buf_size -= 3;
 
-    CRC = av_bswap32(AV_RL24(buf + buf_size)) >> 8;
-    crc = av_crc(crc_24, 0xCE04B7U, buf, buf_size);
+    CRC = AV_RB24(buf + buf_size);
+    crc = av_crc(av_crc_get_table(AV_CRC_24_IEEE), 0xCE04B7U, buf, buf_size);
     if (CRC != crc)
         return AVERROR_INVALIDDATA;
 
@@ -116,9 +100,12 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
     s->samples = get_bits64(gb, TAK_SIZE_SAMPLES_NUM_BITS);
 
     s->data_type   = get_bits(gb, TAK_FORMAT_DATA_TYPE_BITS);
-    s->sample_rate = get_bits(gb, TAK_FORMAT_SAMPLE_RATE_BITS) + TAK_SAMPLE_RATE_MIN;
-    s->bps         = get_bits(gb, TAK_FORMAT_BPS_BITS) + TAK_BPS_MIN;
-    s->channels    = get_bits(gb, TAK_FORMAT_CHANNEL_BITS) + TAK_CHANNELS_MIN;
+    s->sample_rate = get_bits(gb, TAK_FORMAT_SAMPLE_RATE_BITS) +
+                     TAK_SAMPLE_RATE_MIN;
+    s->bps         = get_bits(gb, TAK_FORMAT_BPS_BITS) +
+                     TAK_BPS_MIN;
+    s->channels    = get_bits(gb, TAK_FORMAT_CHANNEL_BITS) +
+                     TAK_CHANNELS_MIN;
 
     if (get_bits1(gb)) {
         skip_bits(gb, TAK_FORMAT_VALID_BITS);
@@ -136,31 +123,25 @@ void avpriv_tak_parse_streaminfo(GetBitContext *gb, TAKStreamInfo *s)
     s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type);
 }
 
-#define FRAME_IS_LAST       1
-#define FRAME_HAVE_INFO     2
-#define FRAME_HAVE_METADATA 4
-
 int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
                                TAKStreamInfo *ti, int log_level_offset)
 {
-    int flags;
-
     if (get_bits(gb, TAK_FRAME_HEADER_SYNC_ID_BITS) != TAK_FRAME_HEADER_SYNC_ID) {
         av_log(avctx, AV_LOG_ERROR + log_level_offset, "missing sync id\n");
         return AVERROR_INVALIDDATA;
     }
 
-    flags = get_bits(gb, TAK_FRAME_HEADER_FLAGS_BITS);
+    ti->flags     = get_bits(gb, TAK_FRAME_HEADER_FLAGS_BITS);
     ti->frame_num = get_bits(gb, TAK_FRAME_HEADER_NO_BITS);
 
-    if (flags & FRAME_IS_LAST) {
+    if (ti->flags & TAK_FRAME_FLAG_IS_LAST) {
         ti->last_frame_samples = get_bits(gb, TAK_FRAME_HEADER_SAMPLE_COUNT_BITS) + 1;
         skip_bits(gb, 2);
     } else {
         ti->last_frame_samples = 0;
     }
 
-    if (flags & FRAME_HAVE_INFO) {
+    if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) {
         avpriv_tak_parse_streaminfo(gb, ti);
 
         if (get_bits(gb, 6))
@@ -168,7 +149,7 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
         align_get_bits(gb);
     }
 
-    if (flags & FRAME_HAVE_METADATA)
+    if (ti->flags & TAK_FRAME_FLAG_HAS_METADATA)
         return AVERROR_INVALIDDATA;
 
     skip_bits(gb, 24);