Skip to content
Snippets Groups Projects
Commit f5ba67ee authored by Vittorio Giovara's avatar Vittorio Giovara
Browse files

flacenc: Move a scratch buffer to struct used by the function

This avoids allocating/freeing memory at every function call,
checking its return value, and carrying the error around.
parent 5aed1d42
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,7 @@ typedef struct RiceContext { ...@@ -67,6 +67,7 @@ typedef struct RiceContext {
enum CodingMode coding_mode; enum CodingMode coding_mode;
int porder; int porder;
int params[MAX_PARTITIONS]; int params[MAX_PARTITIONS];
uint32_t udata[FLAC_MAX_BLOCKSIZE];
} RiceContext; } RiceContext;
typedef struct FlacSubframe { typedef struct FlacSubframe {
...@@ -616,7 +617,6 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax, ...@@ -616,7 +617,6 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
uint64_t bits[MAX_PARTITION_ORDER+1]; uint64_t bits[MAX_PARTITION_ORDER+1];
int opt_porder; int opt_porder;
RiceContext tmp_rc; RiceContext tmp_rc;
uint32_t *udata;
uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } }; uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } };
assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER); assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);
...@@ -625,11 +625,10 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax, ...@@ -625,11 +625,10 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
tmp_rc.coding_mode = rc->coding_mode; tmp_rc.coding_mode = rc->coding_mode;
udata = av_malloc(n * sizeof(uint32_t));
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
udata[i] = (2*data[i]) ^ (data[i]>>31); rc->udata[i] = (2 * data[i]) ^ (data[i] >> 31);
calc_sums(pmin, pmax, udata, n, pred_order, sums); calc_sums(pmin, pmax, rc->udata, n, pred_order, sums);
opt_porder = pmin; opt_porder = pmin;
bits[pmin] = UINT32_MAX; bits[pmin] = UINT32_MAX;
...@@ -641,7 +640,6 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax, ...@@ -641,7 +640,6 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
} }
} }
av_freep(&udata);
return bits[opt_porder]; return bits[opt_porder];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment