aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/flacenc.c
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2015-04-28 15:50:39 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2015-04-28 16:25:09 +0100
commitf5ba67ee1342b7741200ff637fc3ea3387b68a1b (patch)
treec1118a5b276065d6e5be85c7df65f3f2bb638a78 /libavcodec/flacenc.c
parent5aed1d4240d411533c102eec6944aa925b7f4964 (diff)
downloadffmpeg-f5ba67ee1342b7741200ff637fc3ea3387b68a1b.tar.gz
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.
Diffstat (limited to 'libavcodec/flacenc.c')
-rw-r--r--libavcodec/flacenc.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index 2277cf3f5f..804333d5e9 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -67,6 +67,7 @@ typedef struct RiceContext {
enum CodingMode coding_mode;
int porder;
int params[MAX_PARTITIONS];
+ uint32_t udata[FLAC_MAX_BLOCKSIZE];
} RiceContext;
typedef struct FlacSubframe {
@@ -616,7 +617,6 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
uint64_t bits[MAX_PARTITION_ORDER+1];
int opt_porder;
RiceContext tmp_rc;
- uint32_t *udata;
uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } };
assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);
@@ -625,11 +625,10 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
tmp_rc.coding_mode = rc->coding_mode;
- udata = av_malloc(n * sizeof(uint32_t));
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;
bits[pmin] = UINT32_MAX;
@@ -641,7 +640,6 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
}
}
- av_freep(&udata);
return bits[opt_porder];
}