]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cook.c
Add channel layout support to the AC-3 encoder.
[ffmpeg] / libavcodec / cook.c
index 92e2be4c4ccccc2b463bd5008e476fb543749376..b8f74551eb43567f6829ec908df1c494f6ba0aa2 100644 (file)
 #include <stddef.h>
 #include <stdio.h>
 
-#include "libavutil/random.h"
+#include "libavutil/lfg.h"
+#include "libavutil/random_seed.h"
 #include "avcodec.h"
-#include "bitstream.h"
+#include "get_bits.h"
 #include "dsputil.h"
 #include "bytestream.h"
 
@@ -61,6 +62,7 @@
 #define MC_COOK         0x2000000   //multichannel Cook, not supported
 
 #define SUBBAND_SIZE    20
+#define MAX_SUBPACKETS   5
 //#define COOKDEBUG
 
 typedef struct {
@@ -109,7 +111,7 @@ typedef struct cook {
     int                 bits_per_subpacket;
     int                 cookversion;
     /* states */
-    AVRandomState       random_state;
+    AVLFG               random_state;
 
     /* transform data */
     MDCTContext         mdct_ctx;
@@ -301,7 +303,7 @@ static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes)
      *     (int64_t)out[i] = 0x37c511f237c511f2^be2me_64(int64_t)in[i]);
      * Buffer alignment needs to be checked. */
 
-    off = (int)((long)inbuffer & 3);
+    off = (intptr_t)inbuffer & 3;
     buf = (const uint32_t*) (inbuffer - off);
     c = be2me_32((0x37c511f2 >> (off*8)) | (0x37c511f2 << (32-(off*8))));
     bytes += 3 + off;
@@ -540,7 +542,7 @@ static void scalar_dequant_float(COOKContext *q, int index, int quant_index,
         } else {
             /* noise coding if subband_coef_index[i] == 0 */
             f1 = dither_tab[index];
-            if (av_random(&q->random_state) < 0x80000000) f1 = -f1;
+            if (av_lfg_get(&q->random_state) < 0x80000000) f1 = -f1;
         }
         mlt_p[i] = f1 * rootpow2tab[quant_index+63];
     }
@@ -977,7 +979,9 @@ static int decode_subpacket(COOKContext *q, const uint8_t *inbuffer,
 
 static int cook_decode_frame(AVCodecContext *avctx,
             void *data, int *data_size,
-            const uint8_t *buf, int buf_size) {
+            AVPacket *avpkt) {
+    const uint8_t *buf = avpkt->data;
+    int buf_size = avpkt->size;
     COOKContext *q = avctx->priv_data;
 
     if (buf_size < avctx->block_align)
@@ -1017,6 +1021,16 @@ static void dump_cook_context(COOKContext *q)
 }
 #endif
 
+static av_cold int cook_count_channels(unsigned int mask){
+    int i;
+    int channels = 0;
+    for(i = 0;i<32;i++){
+        if(mask & (1<<i))
+            ++channels;
+    }
+    return channels;
+}
+
 /**
  * Cook initialization
  *
@@ -1055,7 +1069,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
     q->bit_rate = avctx->bit_rate;
 
     /* Initialize RNG. */
-    av_random_init(&q->random_state, 1);
+    av_lfg_init(&q->random_state, ff_random_get_seed());
 
     /* Initialize extradata related variables. */
     q->samples_per_channel = q->samples_per_frame / q->nb_channels;