ref: e3e335f13bd2243f0446576cf46dbd1669d38c21
parent: a31998f01c0a6d5e2c6df6893284aaec3629aab7
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Thu Oct 19 12:23:16 EDT 2017
made DRM to compile, not sure if it really works
--- a/configure.ac
+++ b/configure.ac
@@ -9,9 +9,6 @@
AH_BOTTOM([#endif /* CONFIG_H */])
AC_ARG_ENABLE( drm, [ --enable-drm Digital Radio Mondiale support], enable_drm=$enableval, enable_drm=no)
-if test "x$enable_drm" = "xyes"; then
- AC_MSG_ERROR("DRM not available in this version")
-fi
AC_DEFUN([MY_DEFINE], [ AC_DEFINE($1, 1, [define if needed]) ])
--- a/libfaac/bitstream.c
+++ b/libfaac/bitstream.c
@@ -989,7 +989,7 @@
return tmp_W;
}
-static int WriteReorderedSpectralData(CoderInfo *coderInfo,
+static int WriteReorderedSpectralData(CoderInfo *coder,
BitStream *bitStream,
int writeFlag)
{
@@ -998,13 +998,13 @@
int segmcnt = 0;
long startbitpos;
segment_t segment[FRAME_LEN];
- int* groups = coderInfo->groups.len;
- int* sfb_offset = coderInfo->sfb_offset;
+ int* groups = coder->groups.len;
+ int* sfb_offset = coder->sfb_offset;
cw_info_t cw_info[FRAME_LEN];
cw_info_t cw_info_preso[FRAME_LEN];
- int num_cw = coderInfo->cur_cw;
+ int num_cw = coder->cur_cw;
int window_cw_cnt[MAX_SHORT_WINDOWS] = {0,0,0,0,0,0,0,0};
int presort, set, num_sets;
@@ -1020,9 +1020,7 @@
/* set up local pointers to data and len */
/* data array contains data to be written */
/* len array contains lengths of data words */
- int* data = coderInfo->data;
- int* len = coderInfo->len;
- int* num_data = coderInfo->num_data_cw;
+ int* num_data = coder->num_data_cw;
if (writeFlag) {
/* build offset table */
@@ -1031,7 +1029,7 @@
for (i = 0; i < num_cw; i++) {
cur_cw_len = 0;
for (j = 0; j < num_data[i]; j++) {
- cur_cw_len += len[cur_data++];
+ cur_cw_len += coder->s[cur_data++].len;
}
cw_info[i].num_data = num_data[i];
@@ -1044,7 +1042,7 @@
/* classify codewords first */
sfb_cnt = win_cnt = win_grp_cnt = coeff_cnt = last_sfb = acc_win_cnt = 0;
cur_sfb_len = sfb_offset[1] / groups[0];
- cur_cb = coderInfo->book_vector[0];
+ cur_cb = coder->book[0];
for (i = 0; i < num_cw; i++) {
/* Set codeword info parameters */
cw_info[i].cb = cur_cb;
@@ -1063,7 +1061,7 @@
win_cnt = 0;
sfb_cnt++; /* next sfb */
- if (sfb_cnt == coderInfo->all_sfb) {
+ if (sfb_cnt == coder->all_sfb) {
sfb_cnt = 0;
acc_win_cnt += groups[win_grp_cnt];
@@ -1071,7 +1069,7 @@
}
/* new codebook and sfb length */
- cur_cb = coderInfo->book_vector[sfb_cnt];
+ cur_cb = coder->book[sfb_cnt];
if (last_sfb < FRAME_LEN) {
cur_sfb_len = (sfb_offset[sfb_cnt + 1] - sfb_offset[sfb_cnt])
/ groups[win_grp_cnt];
@@ -1085,7 +1083,7 @@
/* Somehow the second presorting step does not give expected results. Disabling the
following code surprisingly gives good results. TODO: find the bug */
- if (0) {//coderInfo->block_type == ONLY_SHORT_WINDOW) {
+ if (0) {//coder->block_type == ONLY_SHORT_WINDOW) {
for (i = 0; i < MAX_SHORT_WINDOWS; i++)
window_cw_cnt[i] = 0; /* reset all counters */
@@ -1137,12 +1135,12 @@
accsegmsize = 0;
for (i = 0; i < num_cw; i++) {
/* 8.5.3.3.3.2 Derivation of segment width */
- cursegmsize = min(maxCwLen[cw_info[i].cb], coderInfo->iLenLongestCW);
+ cursegmsize = min(maxCwLen[cw_info[i].cb], coder->iLenLongestCW);
- if (accsegmsize + cursegmsize > coderInfo->iLenReordSpData) {
+ if (accsegmsize + cursegmsize > coder->iLenReordSpData) {
/* the last segment is extended until iLenReordSpData */
- segment[segmcnt - 1].right = coderInfo->iLenReordSpData - 1;
- segment[segmcnt - 1].len = coderInfo->iLenReordSpData - segment[segmcnt - 1].left;
+ segment[segmcnt - 1].right = coder->iLenReordSpData - 1;
+ segment[segmcnt - 1].len = coder->iLenReordSpData - segment[segmcnt - 1].left;
break;
}
@@ -1199,34 +1197,34 @@
for (cw_part_cnt = 0; cw_part_cnt < cw_info[codeword_index].num_data; cw_part_cnt++) {
cur_cw_part = cw_info[codeword_index].cw_offset + cw_part_cnt;
- if (len[cur_cw_part] <= tmplen) {
+ if (coder->s[cur_cw_part].len <= tmplen) {
/* write complete data, no partitioning */
if (is_backwards) {
/* write data in reversed bit-order */
- PutBitHcr(bitStream, startbitpos + segment[segment_index].right - len[cur_cw_part] + 1,
- rewind_word(data[cur_cw_part], len[cur_cw_part]), len[cur_cw_part]);
+ PutBitHcr(bitStream, startbitpos + segment[segment_index].right - coder->s[cur_cw_part].len + 1,
+ rewind_word(coder->s[cur_cw_part].data, coder->s[cur_cw_part].len), coder->s[cur_cw_part].len);
- segment[segment_index].right -= len[cur_cw_part];
+ segment[segment_index].right -= coder->s[cur_cw_part].len;
} else {
PutBitHcr(bitStream, startbitpos + segment[segment_index].left,
- data[cur_cw_part], len[cur_cw_part]);
+ coder->s[cur_cw_part].data, coder->s[cur_cw_part].len);
- segment[segment_index].left += len[cur_cw_part];
+ segment[segment_index].left += coder->s[cur_cw_part].len;
}
- tmplen -= len[cur_cw_part];
- len[cur_cw_part] = 0;
+ tmplen -= coder->s[cur_cw_part].len;
+ coder->s[cur_cw_part].len = 0;
} else {
/* codeword part must be partitioned */
/* data must be taken from the left side */
- tmp_data = data[cur_cw_part];
+ tmp_data = coder->s[cur_cw_part].data;
- diff = len[cur_cw_part] - tmplen;
+ diff = coder->s[cur_cw_part].len - tmplen;
tmp_data >>= diff;
/* remove bits which are already used */
- data[cur_cw_part] &= (1 << diff) - 1 /* diff number of ones */;
- len[cur_cw_part] = diff;
+ coder->s[cur_cw_part].data &= (1 << diff) - 1 /* diff number of ones */;
+ coder->s[cur_cw_part].len = diff;
if (is_backwards) {
/* write data in reversed bit-order */
@@ -1256,11 +1254,11 @@
}
/* set parameter for bit stream to current correct position */
- bitStream->currentBit = startbitpos + coderInfo->iLenReordSpData;
+ bitStream->currentBit = startbitpos + coder->iLenReordSpData;
bitStream->numBit = bitStream->currentBit;
}
- return coderInfo->iLenReordSpData;
+ return coder->iLenReordSpData;
}
/*
--- a/libfaac/huff2.c
+++ b/libfaac/huff2.c
@@ -25,6 +25,9 @@
#include "huff2.h"
#include "bitstream.h"
+#ifdef DRM
+static int vcb11;
+#endif
static int escape(int x, int *code)
{
@@ -56,6 +59,14 @@
return (preflen << 1) + 5;
}
+#ifdef DRM
+# define DRMDATA if(coder){coder->num_data_cw[coder->cur_cw++]=1;\
+ coder->iLenReordSpData+=blen;if(coder->iLenLongestCW<blen)\
+ coder->iLenLongestCW=blen;}
+#else
+# define DRMDATA
+#endif
+
static int huffcode(int *qs /* quantized spectrum */,
int len,
int bnum,
@@ -70,6 +81,10 @@
int data;
int idx;
int datacnt;
+#ifdef DRM
+ int drmbits = 0;
+ int maxesc = 0;
+#endif
if (coder)
datacnt = coder->datacnt;
@@ -76,14 +91,21 @@
else
datacnt = 0;
- if ((bnum < 1) || (bnum > 11))
- {
- fprintf(stderr, "%s(%d) book %d out of range\n", __FILE__, __LINE__, bnum);
- return -1;
- }
book = hmap[bnum];
switch (bnum)
{
+ case ZERO_HCB:
+ case INTENSITY_HCB:
+ case INTENSITY_HCB2:
+#ifdef DRM
+ for(ofs = 0; ofs < len; ofs += 4)
+ {
+ coder->s[datacnt].data = 0;
+ coder->s[datacnt++].len = 0;
+ coder->num_data_cw[coder->cur_cw++] = 1;
+ }
+#endif
+ break;
case 1:
case 2:
for(ofs = 0; ofs < len; ofs += 4)
@@ -96,6 +118,7 @@
data = book[idx].data;
coder->s[datacnt].data = data;
coder->s[datacnt++].len = blen;
+ DRMDATA;
}
bits += blen;
}
@@ -130,6 +153,7 @@
}
coder->s[datacnt].data = data;
coder->s[datacnt++].len = blen;
+ DRMDATA;
}
bits += blen;
}
@@ -146,6 +170,7 @@
data = book[idx].data;
coder->s[datacnt].data = data;
coder->s[datacnt++].len = blen;
+ DRMDATA;
}
bits += blen;
}
@@ -178,6 +203,7 @@
}
coder->s[datacnt].data = data;
coder->s[datacnt++].len = blen;
+ DRMDATA;
}
bits += blen;
}
@@ -210,11 +236,12 @@
}
coder->s[datacnt].data = data;
coder->s[datacnt++].len = blen;
+ DRMDATA;
}
bits += blen;
}
break;
- case 11:
+ case ESC_HCB:
for(ofs = 0; ofs < len; ofs += 2)
{
int x0, x1;
@@ -251,6 +278,10 @@
}
coder->s[datacnt].data = data;
coder->s[datacnt++].len = blen;
+#ifdef DRM
+ coder->num_data_cw[coder->cur_cw] = 1;
+ drmbits = blen;
+#endif
}
bits += blen;
@@ -261,6 +292,13 @@
{
coder->s[datacnt].data = data;
coder->s[datacnt++].len = blen;
+#ifdef DRM
+ coder->num_data_cw[coder->cur_cw]++;
+ drmbits += blen;
+
+ if (maxesc < data)
+ maxesc = data;
+#endif
}
bits += blen;
}
@@ -272,11 +310,65 @@
{
coder->s[datacnt].data = data;
coder->s[datacnt++].len = blen;
+#ifdef DRM
+ coder->num_data_cw[coder->cur_cw]++;
+ drmbits += blen;
+
+ if (maxesc < data)
+ maxesc = data;
+#endif
}
bits += blen;
}
+#ifdef DRM
+ coder->iLenReordSpData += drmbits;
+ if (coder->iLenLongestCW < drmbits)
+ coder->iLenLongestCW = drmbits;
+
+ coder->cur_cw++;
+#endif
}
+#ifdef DRM
+ /* VCB11: check which codebook should be used using max escape sequence */
+ /* 8.5.3.1.3, table 157 */
+ if (maxesc <= 15)
+ vcb11 = 16;
+ else if (maxesc <= 31)
+ vcb11 = 17;
+ else if (maxesc <= 47)
+ vcb11 = 18;
+ else if (maxesc <= 63)
+ vcb11 = 19;
+ else if (maxesc <= 95)
+ vcb11 = 20;
+ else if (maxesc <= 127)
+ vcb11 = 21;
+ else if (maxesc <= 159)
+ vcb11 = 22;
+ else if (maxesc <= 191)
+ vcb11 = 23;
+ else if (maxesc <= 223)
+ vcb11 = 24;
+ else if (maxesc <= 255)
+ vcb11 = 25;
+ else if (maxesc <= 319)
+ vcb11 = 26;
+ else if (maxesc <= 383)
+ vcb11 = 27;
+ else if (maxesc <= 511)
+ vcb11 = 28;
+ else if (maxesc <= 767)
+ vcb11 = 29;
+ else if (maxesc <= 1023)
+ vcb11 = 30;
+ else if (maxesc <= 2047)
+ vcb11 = 31;
+ /* else: codebook 11 -> it is already 11 */
+#endif
break;
+ default:
+ fprintf(stderr, "%s(%d) book %d out of range\n", __FILE__, __LINE__, bnum);
+ return -1;
}
if (coder)
@@ -331,12 +423,18 @@
else
{
bookmin = ESC_HCB;
- lenmin = huffcode(qs, len, bookmin, 0);
}
- coder->book[coder->bandcnt] = bookmin;
+#ifdef DRM
+ vcb11 = 0;
+#endif
if (bookmin > ZERO_HCB)
huffcode(qs, len, bookmin, coder);
+#ifdef DRM
+ if (vcb11)
+ bookmin = vcb11;
+#endif
+ coder->book[coder->bandcnt] = bookmin;
return 0;
}
--- a/libfaac/quantize.c
+++ b/libfaac/quantize.c
@@ -256,6 +256,11 @@
coder->bandcnt = 0;
coder->datacnt = 0;
+#ifdef DRM
+ coder->iLenReordSpData = 0; /* init length of reordered spectral data */
+ coder->iLenLongestCW = 0; /* init length of longest codeword */
+ coder->cur_cw = 0; /* init codeword counter */
+#endif
for (cnt = 0; cnt < FRAME_LEN; cnt++)
nonzero += (fabs(xr[cnt]) > 1E-20);